diff --git a/core/src/main/java/org/lflang/generator/GeneratorBase.java b/core/src/main/java/org/lflang/generator/GeneratorBase.java index d8b3d2d7d4..0713b863be 100644 --- a/core/src/main/java/org/lflang/generator/GeneratorBase.java +++ b/core/src/main/java/org/lflang/generator/GeneratorBase.java @@ -34,6 +34,7 @@ import java.util.List; import java.util.Map; import java.util.Optional; +import java.util.Set; import java.util.stream.Collectors; import org.eclipse.core.resources.IMarker; import org.eclipse.emf.ecore.EObject; @@ -227,7 +228,7 @@ public void doGenerate(Resource resource, LFGeneratorContext context) { // to validate, which happens in setResources(). setReactorsAndInstantiationGraph(context.getMode()); - List allResources = GeneratorUtils.getResources(reactors); + Set allResources = GeneratorUtils.getResources(reactors); GeneratorUtils.accommodatePhysicalActionsIfPresent( allResources, @@ -413,7 +414,7 @@ protected void checkWatchdogSupport(boolean 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(List resources) { + private void transformConflictingConnectionsInModalReactors(Set resources) { for (Resource r : resources) { var transform = ASTUtils.findConflictingConnectionsInModalReactors(r); if (!transform.isEmpty()) { diff --git a/core/src/main/java/org/lflang/generator/GeneratorUtils.java b/core/src/main/java/org/lflang/generator/GeneratorUtils.java index 77240613e6..bda5a5cf2e 100644 --- a/core/src/main/java/org/lflang/generator/GeneratorUtils.java +++ b/core/src/main/java/org/lflang/generator/GeneratorUtils.java @@ -1,8 +1,7 @@ package org.lflang.generator; -import java.util.ArrayList; -import java.util.HashSet; -import java.util.List; +import java.util.LinkedHashSet; +import java.util.Set; import org.eclipse.core.resources.IResource; import org.eclipse.core.resources.ResourcesPlugin; import org.eclipse.core.runtime.CoreException; @@ -13,6 +12,7 @@ import org.lflang.generator.LFGeneratorContext.Mode; import org.lflang.lf.Action; import org.lflang.lf.ActionOrigin; +import org.lflang.lf.ImportedReactor; import org.lflang.lf.Instantiation; import org.lflang.lf.Reactor; import org.lflang.lf.TargetDecl; @@ -40,7 +40,7 @@ public static TargetDecl findTargetDecl(Resource resource) { * targetConfig}. This is a helper function for setTargetConfig. It should not be used elsewhere. */ public static void accommodatePhysicalActionsIfPresent( - List resources, + Set resources, boolean setsKeepAliveOptionAutomatically, TargetConfig targetConfig, MessageReporter messageReporter) { @@ -79,22 +79,33 @@ public static Iterable findAll(Resource resource, Class nodeType) { } /** - * Return the resources that provide the given reactors. + * Return the resources that provide the given reactors and their ancestors. * * @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<>(); + public static Set getResources(Iterable reactors) { + Set visited = new LinkedHashSet<>(); for (Reactor r : reactors) { - Resource resource = r.eResource(); - if (!visited.contains(resource)) { - visited.add(resource); - resources.add(resource); + if (!visited.contains(r.eResource())) { + addInheritedResources(r, visited); + } + } + return visited; + } + + /** Collect all resources associated with reactor through class inheritance. */ + private static void addInheritedResources(Reactor reactor, Set resources) { + resources.add(reactor.eResource()); + for (var s : reactor.getSuperClasses()) { + if (!resources.contains(s)) { + if (s instanceof ImportedReactor i) { + addInheritedResources(i.getReactorClass(), resources); + } else if (s instanceof Reactor r) { + addInheritedResources(r, resources); + } } } - return resources; } /** diff --git a/test/C/src/target/ImportedCMakeInclude.lf b/test/C/src/target/ImportedCMakeInclude.lf new file mode 100644 index 0000000000..bc922d7429 --- /dev/null +++ b/test/C/src/target/ImportedCMakeInclude.lf @@ -0,0 +1,12 @@ +target C { + timeout: 1 ms +} + +import Foo from "./CMakeInclude.lf" + +reactor Bar extends Foo { +} + +main reactor { + r = new Foo() +}