Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix for handling of target properties in imported files accessed through reactor class inheritance #2340

Merged
merged 3 commits into from
Jun 30, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
5 changes: 3 additions & 2 deletions core/src/main/java/org/lflang/generator/GeneratorBase.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -227,7 +228,7 @@ public void doGenerate(Resource resource, LFGeneratorContext context) {
// to validate, which happens in setResources().
setReactorsAndInstantiationGraph(context.getMode());

List<Resource> allResources = GeneratorUtils.getResources(reactors);
Set<Resource> allResources = GeneratorUtils.getResources(reactors);

GeneratorUtils.accommodatePhysicalActionsIfPresent(
allResources,
Expand Down Expand Up @@ -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<Resource> resources) {
private void transformConflictingConnectionsInModalReactors(Set<Resource> resources) {
for (Resource r : resources) {
var transform = ASTUtils.findConflictingConnectionsInModalReactors(r);
if (!transform.isEmpty()) {
Expand Down
37 changes: 24 additions & 13 deletions core/src/main/java/org/lflang/generator/GeneratorUtils.java
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -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;
Expand Down Expand Up @@ -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<Resource> resources,
Set<Resource> resources,
boolean setsKeepAliveOptionAutomatically,
TargetConfig targetConfig,
MessageReporter messageReporter) {
Expand Down Expand Up @@ -79,22 +79,33 @@ public static <T> Iterable<T> findAll(Resource resource, Class<T> 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<Resource> getResources(Iterable<Reactor> reactors) {
HashSet<Resource> visited = new HashSet<>();
List<Resource> resources = new ArrayList<>();
public static Set<Resource> getResources(Iterable<Reactor> reactors) {
Set<Resource> 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<Resource> 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;
}

/**
Expand Down
12 changes: 12 additions & 0 deletions test/C/src/target/ImportedCMakeInclude.lf
Original file line number Diff line number Diff line change
@@ -0,0 +1,12 @@
target C {
timeout: 1 ms
}

import Foo from "./CMakeInclude.lf"

reactor Bar extends Foo {
}

main reactor {
r = new Foo()
}
Loading