From d1501dcbf42b093aac6c53ab3aeb5c4b4c67f1af Mon Sep 17 00:00:00 2001 From: Marten Lohstroh Date: Sun, 30 Jun 2024 06:51:29 -0700 Subject: [PATCH] Address another fixme --- .../org/lflang/generator/GeneratorBase.java | 36 ++++++++++++------- .../org/lflang/generator/c/CGenerator.java | 20 ----------- 2 files changed, 23 insertions(+), 33 deletions(-) diff --git a/core/src/main/java/org/lflang/generator/GeneratorBase.java b/core/src/main/java/org/lflang/generator/GeneratorBase.java index 74cb6f8233..d8b3d2d7d4 100644 --- a/core/src/main/java/org/lflang/generator/GeneratorBase.java +++ b/core/src/main/java/org/lflang/generator/GeneratorBase.java @@ -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; @@ -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 astTransformations = new ArrayList<>(); @@ -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. @@ -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); 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 97091472a1..be0d544352 100644 --- a/core/src/main/java/org/lflang/generator/c/CGenerator.java +++ b/core/src/main/java/org/lflang/generator/c/CGenerator.java @@ -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; @@ -691,24 +690,6 @@ private boolean hasDeadlines(List 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 @@ -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); } }