From f02ff3f47143a8135f859017b3285ab551558924 Mon Sep 17 00:00:00 2001 From: Marten Lohstroh Date: Sun, 15 Oct 2023 15:07:20 -0700 Subject: [PATCH] Address immutability exceptions --- .../org/lflang/cli/LfcIssueReportingTest.kt | 17 +-------- .../main/java/org/lflang/ast/ASTUtils.java | 10 +++--- .../org/lflang/generator/c/CGenerator.java | 36 +++++++------------ .../generator/c/CPreambleGenerator.java | 18 +++++----- 4 files changed, 28 insertions(+), 53 deletions(-) diff --git a/cli/lfc/src/test/kotlin/org/lflang/cli/LfcIssueReportingTest.kt b/cli/lfc/src/test/kotlin/org/lflang/cli/LfcIssueReportingTest.kt index 21cdaf3043..8589cddc8a 100644 --- a/cli/lfc/src/test/kotlin/org/lflang/cli/LfcIssueReportingTest.kt +++ b/cli/lfc/src/test/kotlin/org/lflang/cli/LfcIssueReportingTest.kt @@ -47,22 +47,7 @@ class SpyPrintStream { class LfcIssueReportingTest { - /* - Note: when executing these tests in Intellij, I get the following error: - - java.lang.SecurityException: class "org.eclipse.core.runtime.IPath"'s - signer information does not match signer information of other classes - in the same package - - To fix this: - - Go into File > Project Structure (CTRL+MAJ+S) - - Open the "Modules" tab - - Select the module org.lflang/lfc/test in the tree view - - Open the "Dependencies" tab - - Remove the dependency org.eclipse.platform:org.eclipse.equinox.common (it will have Provided scope) - */ - - + @Test fun testSimpleWarning() { doTest(fileBaseName = "simpleWarning") diff --git a/core/src/main/java/org/lflang/ast/ASTUtils.java b/core/src/main/java/org/lflang/ast/ASTUtils.java index 59189f1d24..472ce87d88 100644 --- a/core/src/main/java/org/lflang/ast/ASTUtils.java +++ b/core/src/main/java/org/lflang/ast/ASTUtils.java @@ -615,10 +615,12 @@ public static ReactorInstance createMainReactorInstance( if (breadth == 0) { messageReporter.nowhere().warning("The program has no reactions"); } else { - // FIXME: not marking the property as set! - targetConfig - .get(new CompileDefinitionsProperty()) - .put("LF_REACTION_GRAPH_BREADTH", String.valueOf(reactionInstanceGraph.getBreadth())); + new CompileDefinitionsProperty() + .update( + targetConfig, + Map.of( + "LF_REACTION_GRAPH_BREADTH", + String.valueOf(reactionInstanceGraph.getBreadth()))); } return main; } 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 46e584656f..93925abc8b 100644 --- a/core/src/main/java/org/lflang/generator/c/CGenerator.java +++ b/core/src/main/java/org/lflang/generator/c/CGenerator.java @@ -41,8 +41,10 @@ import java.nio.file.Files; import java.nio.file.Path; import java.util.ArrayList; +import java.util.HashMap; import java.util.LinkedHashSet; import java.util.List; +import java.util.Map; import java.util.regex.Pattern; import java.util.stream.Collectors; import java.util.stream.Stream; @@ -1976,23 +1978,18 @@ protected DockerGenerator getDockerGenerator(LFGeneratorContext context) { // Perform set up that does not generate code protected void setUpGeneralParameters() { accommodatePhysicalActionsIfPresent(); - targetConfig - .get(new CompileDefinitionsProperty()) - .put( - "LOG_LEVEL", - String.valueOf( - targetConfig - .get(new LoggingProperty()) - .ordinal())); // FIXME: put without marking as set + new CompileDefinitionsProperty() + .update( + targetConfig, + Map.of("LOG_LEVEL", String.valueOf(targetConfig.get(new LoggingProperty()).ordinal()))); + targetConfig.compileAdditionalSources.addAll(CCoreFilesUtils.getCTargetSrc()); // Create the main reactor instance if there is a main reactor. this.main = ASTUtils.createMainReactorInstance(mainDef, reactors, messageReporter, targetConfig); if (hasModalReactors) { // So that each separate compile knows about modal reactors, do this: - targetConfig - .get(new CompileDefinitionsProperty()) - .put("MODAL_REACTORS", "TRUE"); // FIXME: put without marking as set + new CompileDefinitionsProperty().update(targetConfig, Map.of("MODAL_REACTORS", "TRUE")); } final var platformOptions = targetConfig.get(new PlatformProperty()); if (targetConfig.get(new ThreadingProperty()) @@ -2037,19 +2034,10 @@ protected void setUpGeneralParameters() { if (targetConfig.get(new ThreadingProperty())) { // FIXME: This logic is duplicated in CMake pickScheduler(); // FIXME: this and pickScheduler should be combined. - targetConfig - .get(new CompileDefinitionsProperty()) - .put( - "SCHEDULER", - targetConfig - .get(new SchedulerProperty()) - .name()); // FIXME: put without marking as set - targetConfig - .get(new CompileDefinitionsProperty()) - .put( - "NUMBER_OF_WORKERS", - String.valueOf( - targetConfig.get(new WorkersProperty()))); // FIXME: put without marking as set + var map = new HashMap(); + map.put("SCHEDULER", targetConfig.get(new SchedulerProperty()).name()); + map.put("NUMBER_OF_WORKERS", String.valueOf(targetConfig.get(new WorkersProperty()))); + new CompileDefinitionsProperty().update(targetConfig, map); } pickCompilePlatform(); } diff --git a/core/src/main/java/org/lflang/generator/c/CPreambleGenerator.java b/core/src/main/java/org/lflang/generator/c/CPreambleGenerator.java index 18c783a4f5..d4b084d6bb 100644 --- a/core/src/main/java/org/lflang/generator/c/CPreambleGenerator.java +++ b/core/src/main/java/org/lflang/generator/c/CPreambleGenerator.java @@ -3,6 +3,7 @@ import static org.lflang.util.StringUtil.addDoubleQuotes; import java.nio.file.Path; +import java.util.HashMap; import org.lflang.generator.CodeBuilder; import org.lflang.target.TargetConfig; import org.lflang.target.property.CompileDefinitionsProperty; @@ -72,11 +73,9 @@ public static String generateDefineDirectives(TargetConfig targetConfig, Path sr // TODO: Get rid of all of these code.pr("#define LOG_LEVEL " + logLevel); code.pr("#define TARGET_FILES_DIRECTORY " + addDoubleQuotes(srcGenPath.toString())); - + final var definitions = new HashMap(); if (tracing.isEnabled()) { - targetConfig - .get(new CompileDefinitionsProperty()) - .put("LF_TRACE", tracing.traceFileName); // FIXME: put without marking as set + definitions.put("LF_TRACE", tracing.traceFileName); } // if (clockSyncIsOn) { // code.pr(generateClockSyncDefineDirective( @@ -84,17 +83,18 @@ public static String generateDefineDirectives(TargetConfig targetConfig, Path sr // targetConfig.clockSyncOptions // )); // } - final var defs = targetConfig.get(new CompileDefinitionsProperty()); + if (targetConfig.get(new ThreadingProperty())) { - defs.put("LF_THREADED", "1"); + definitions.put("LF_THREADED", "1"); } else { - defs.put("LF_UNTHREADED", "1"); + definitions.put("LF_UNTHREADED", "1"); } if (targetConfig.get(new ThreadingProperty())) { - defs.put("LF_THREADED", "1"); + definitions.put("LF_THREADED", "1"); } else { - defs.put("LF_UNTHREADED", "1"); + definitions.put("LF_UNTHREADED", "1"); } + new CompileDefinitionsProperty().update(targetConfig, definitions); code.newLine(); return code.toString(); }