Skip to content

Commit

Permalink
Address another fixme
Browse files Browse the repository at this point in the history
  • Loading branch information
lhstrh committed Jun 30, 2024
1 parent f2b80e6 commit d1501dc
Show file tree
Hide file tree
Showing 2 changed files with 23 additions and 33 deletions.
36 changes: 23 additions & 13 deletions core/src/main/java/org/lflang/generator/GeneratorBase.java
Original file line number Diff line number Diff line change
Expand Up @@ -78,18 +78,12 @@
*/
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 MessageReporter messageReporter;

////////////////////////////////////////////
//// Protected fields.

/** The current target configuration. */
protected final TargetConfig targetConfig;

Expand Down Expand Up @@ -142,9 +136,6 @@ public Instantiation getMainDef() {
/** 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<AstTransformation> astTransformations = new ArrayList<>();

Expand All @@ -165,8 +156,26 @@ protected void registerTransformation(AstTransformation transformation) {
astTransformations.add(transformation);
}

// //////////////////////////////////////////
// // Code generation functions to override for a concrete code generator.
/**
* If the given reactor is defined in another file, process its target properties so that they are
* reflected in the target configuration.
*/
private void loadTargetProperties(Resource resource) {
var mainFileConfig = this.context.getFileConfig();
if (resource != mainFileConfig.resource) {
this.context
.getTargetConfig()
.mergeImportedConfig(
LFGenerator.createFileConfig(
resource,
mainFileConfig.getSrcGenBasePath(),
mainFileConfig.useHierarchicalBin)
.resource,
mainFileConfig.resource,
p -> p.loadFromImport(),
this.messageReporter);
}
}

/**
* Generate code from the Lingua Franca model contained by the specified resource.
Expand Down Expand Up @@ -225,8 +234,9 @@ public void doGenerate(Resource resource, LFGeneratorContext context) {
getTarget().setsKeepAliveOptionAutomatically(),
targetConfig,
messageReporter);
// FIXME: Should the GeneratorBase pull in {@code files} from imported
// resources?

// Load target properties for all resources.
allResources.forEach(r -> loadTargetProperties(r));

for (AstTransformation transformation : astTransformations) {
transformation.applyTransformation(reactors);
Expand Down
20 changes: 0 additions & 20 deletions core/src/main/java/org/lflang/generator/c/CGenerator.java
Original file line number Diff line number Diff line change
Expand Up @@ -59,7 +59,6 @@
import org.lflang.generator.GeneratorBase;
import org.lflang.generator.GeneratorResult;
import org.lflang.generator.GeneratorUtils;
import org.lflang.generator.LFGenerator;
import org.lflang.generator.LFGeneratorContext;
import org.lflang.generator.ParameterInstance;
import org.lflang.generator.PortInstance;
Expand Down Expand Up @@ -691,24 +690,6 @@ private boolean hasDeadlines(List<Reactor> reactors) {
return false;
}

/**
* If the given reactor is defined in another file, process its target properties so that they are
* reflected in the target configuration.
*/
private void loadTargetProperties(Resource resource) {
if (resource != this.fileConfig.resource) {
this.context
.getTargetConfig()
.mergeImportedConfig(
LFGenerator.createFileConfig(
resource, fileConfig.getSrcGenBasePath(), fileConfig.useHierarchicalBin)
.resource,
this.fileConfig.resource,
p -> p.loadFromImport(),
this.messageReporter);
}
}

/**
* 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
Expand Down Expand Up @@ -826,7 +807,6 @@ private void generateReactorChildren(
if (r.reactorDeclaration != null && !generatedReactors.contains(newTpr)) {
generatedReactors.add(newTpr);
generateReactorChildren(r, generatedReactors);
loadTargetProperties(r.reactorDeclaration.eResource());
generateReactorClass(newTpr);
}
}
Expand Down

0 comments on commit d1501dc

Please sign in to comment.