Skip to content

Commit

Permalink
Dignify the "empty list of all reactors" hack.
Browse files Browse the repository at this point in the history
  • Loading branch information
petervdonovan committed Jun 4, 2023
1 parent e5c178d commit 79fe178
Show file tree
Hide file tree
Showing 7 changed files with 26 additions and 29 deletions.
13 changes: 2 additions & 11 deletions core/src/main/java/org/lflang/ModelInfo.java
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<>()));
Expand All @@ -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,
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
21 changes: 15 additions & 6 deletions core/src/main/java/org/lflang/generator/ReactorInstance.java
Original file line number Diff line number Diff line change
Expand Up @@ -91,6 +91,17 @@ public class ReactorInstance extends NamedInstance<Instantiation> {
*/
public ReactorInstance(Reactor reactor, ErrorReporter reporter, List<Reactor> 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());
}

/**
Expand All @@ -101,9 +112,8 @@ public ReactorInstance(Reactor reactor, ErrorReporter reporter, List<Reactor> 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<Reactor> 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());
}

/**
Expand All @@ -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<Reactor> 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());
}

//////////////////////////////////////////////////////
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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("_"));
}

Expand Down

0 comments on commit 79fe178

Please sign in to comment.