Skip to content

Commit

Permalink
Comments and minor changes
Browse files Browse the repository at this point in the history
  • Loading branch information
lhstrh committed Oct 1, 2023
1 parent c1b2ff7 commit 764bde2
Show file tree
Hide file tree
Showing 31 changed files with 59 additions and 55 deletions.
4 changes: 1 addition & 3 deletions core/src/main/java/org/lflang/AbstractTargetProperty.java
Original file line number Diff line number Diff line change
Expand Up @@ -180,9 +180,7 @@ public T get() {
*/
protected abstract T fromString(String string, MessageReporter reporter);

/**
* Return a list of targets that support this target property.
*/
/** Return a list of targets that support this target property. */
public abstract List<Target> supportedTargets();

/**
Expand Down
33 changes: 19 additions & 14 deletions core/src/main/java/org/lflang/TargetProperty.java
Original file line number Diff line number Diff line change
Expand Up @@ -78,7 +78,6 @@
import org.lflang.target.property.TimeOutProperty;
import org.lflang.target.property.TracingProperty;
import org.lflang.target.property.WorkersProperty;
import org.lflang.target.property.type.TargetPropertyType;
import org.lflang.target.property.type.VerifyProperty;
import org.lflang.validation.ValidatorMessageReporter;

Expand Down Expand Up @@ -360,7 +359,7 @@ public static List<TargetProperty> loaded(TargetConfig config) {
}

/**
* Constructs a TargetDecl by extracting the fields of the given TargetConfig.
* Constructs a {@code TargetDecl} by extracting the fields of the given {@code TargetConfig}.
*
* @param target The target to generate for.
* @param config The TargetConfig to extract from.
Expand All @@ -377,8 +376,15 @@ public static TargetDecl extractTargetDecl(Target target, TargetConfig config) {
return decl;
}

private static KeyValuePair getKeyValuePair(
KeyValuePairs targetProperties, TargetProperty property) {
/**
* Retrieve a key-value pair from the given AST that matches the given target property.
*
* @param ast The AST retrieve the key-value pair from.
* @param property The target property of interest.
* @return The found key-value pair, or {@code null} if no matching pair could be found.
*/
public static KeyValuePair getKeyValuePair(Model ast, TargetProperty property) {
var targetProperties = ast.getTarget().getConfig();
List<KeyValuePair> properties =
targetProperties.getPairs().stream()
.filter(pair -> pair.getName().equals(property.toString()))
Expand All @@ -387,15 +393,19 @@ private static KeyValuePair getKeyValuePair(
return properties.size() > 0 ? properties.get(0) : null;
}

public static KeyValuePair getKeyValuePair(Model ast, TargetProperty property) {
return getKeyValuePair(ast.getTarget().getConfig(), property);
}

/** Return a list containing the keys of all properties */
public static List<String> getPropertyKeys() {
return Arrays.stream(TargetProperty.values()).map(TargetProperty::getKey).toList();
return Arrays.stream(TargetProperty.values()).map(TargetProperty::toString).toList();
}

/**
* Validate the given key-value pairs and report issues via the given reporter.
*
* @param pairs The key-value pairs to validate.
* @param ast The root node of the AST from which the key-value pairs were taken.
* @param config A target configuration used to retrieve the corresponding target properties.
* @param reporter A reporter to report errors and warnings through.
*/
public static void validate(
KeyValuePairs pairs, Model ast, TargetConfig config, ValidatorMessageReporter reporter) {
pairs.getPairs().stream()
Expand Down Expand Up @@ -487,9 +497,4 @@ public String toString() {
}
return this.name().toLowerCase().replaceAll("_", "-");
}

/** Interface for dictionary elements. It associates an entry with a type. */
public interface DictionaryElement {
TargetPropertyType getType();
}
}
2 changes: 1 addition & 1 deletion core/src/main/java/org/lflang/ast/ASTUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -61,7 +61,6 @@
import org.lflang.InferredType;
import org.lflang.MessageReporter;
import org.lflang.Target;
import org.lflang.target.TargetConfig;
import org.lflang.TimeUnit;
import org.lflang.TimeValue;
import org.lflang.generator.CodeMap;
Expand Down Expand Up @@ -102,6 +101,7 @@
import org.lflang.lf.Watchdog;
import org.lflang.lf.WidthSpec;
import org.lflang.lf.WidthTerm;
import org.lflang.target.TargetConfig;
import org.lflang.util.StringUtil;

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -31,7 +31,6 @@
import org.lflang.LFStandaloneSetup;
import org.lflang.MessageReporter;
import org.lflang.Target;
import org.lflang.target.TargetConfig;
import org.lflang.ast.ASTUtils;
import org.lflang.federated.launcher.FedLauncherGenerator;
import org.lflang.federated.launcher.RtiConfig;
Expand All @@ -58,6 +57,7 @@
import org.lflang.lf.Reactor;
import org.lflang.lf.TargetDecl;
import org.lflang.lf.VarRef;
import org.lflang.target.TargetConfig;
import org.lflang.target.property.CoordinationProperty.CoordinationMode;
import org.lflang.util.Averager;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,10 +5,10 @@
import java.nio.file.Path;
import org.eclipse.emf.ecore.resource.Resource;
import org.lflang.MessageReporter;
import org.lflang.target.TargetConfig;
import org.lflang.TargetProperty;
import org.lflang.generator.GeneratorUtils;
import org.lflang.generator.LFGeneratorContext;
import org.lflang.target.TargetConfig;
import org.lflang.util.FileUtil;

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -37,7 +37,6 @@
import java.util.stream.Collectors;
import java.util.stream.Stream;
import org.lflang.MessageReporter;
import org.lflang.target.TargetConfig;
import org.lflang.TimeValue;
import org.lflang.ast.ASTUtils;
import org.lflang.federated.serialization.SupportedSerializers;
Expand All @@ -64,6 +63,7 @@
import org.lflang.lf.TriggerRef;
import org.lflang.lf.VarRef;
import org.lflang.lf.Variable;
import org.lflang.target.TargetConfig;

/**
* Class that represents an instance of a federate, i.e., a reactor that is instantiated at the top
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -34,9 +34,9 @@
import java.util.ArrayList;
import java.util.List;
import org.lflang.MessageReporter;
import org.lflang.target.TargetConfig;
import org.lflang.federated.generator.FedFileConfig;
import org.lflang.federated.generator.FederateInstance;
import org.lflang.target.TargetConfig;
import org.lflang.target.property.ClockSyncModeProperty.ClockSyncMode;

/**
Expand Down
2 changes: 1 addition & 1 deletion core/src/main/java/org/lflang/generator/GeneratorBase.java
Original file line number Diff line number Diff line change
Expand Up @@ -43,12 +43,12 @@
import org.lflang.MainConflictChecker;
import org.lflang.MessageReporter;
import org.lflang.Target;
import org.lflang.target.TargetConfig;
import org.lflang.analyses.uclid.UclidGenerator;
import org.lflang.ast.ASTUtils;
import org.lflang.ast.AstTransformation;
import org.lflang.graph.InstantiationGraph;
import org.lflang.lf.*;
import org.lflang.target.TargetConfig;
import org.lflang.util.FileUtil;
import org.lflang.validation.AbstractLFValidator;

Expand Down
5 changes: 3 additions & 2 deletions core/src/main/java/org/lflang/generator/GeneratorUtils.java
Original file line number Diff line number Diff line change
Expand Up @@ -12,7 +12,7 @@
import org.eclipse.xtext.xbase.lib.IteratorExtensions;
import org.lflang.FileConfig;
import org.lflang.MessageReporter;
import org.lflang.target.TargetConfig;
import org.lflang.Target;
import org.lflang.TargetProperty;
import org.lflang.ast.ASTUtils;
import org.lflang.generator.LFGeneratorContext.Mode;
Expand All @@ -23,6 +23,7 @@
import org.lflang.lf.KeyValuePairs;
import org.lflang.lf.Reactor;
import org.lflang.lf.TargetDecl;
import org.lflang.target.TargetConfig;

/**
* A helper class with functions that may be useful for code generators. This is created to ease our
Expand Down Expand Up @@ -118,7 +119,7 @@ public static LFResource getLFResource(
MessageReporter messageReporter) {
var target = ASTUtils.targetDecl(resource);
KeyValuePairs config = target.getConfig();
var targetConfig = new TargetConfig(target);
var targetConfig = new TargetConfig(Target.fromDecl(target));
if (config != null) {
List<KeyValuePair> pairs = config.getPairs();
TargetProperty.load(targetConfig, pairs != null ? pairs : List.of(), messageReporter);
Expand Down
2 changes: 1 addition & 1 deletion core/src/main/java/org/lflang/generator/MainContext.java
Original file line number Diff line number Diff line change
Expand Up @@ -11,8 +11,8 @@
import org.lflang.DefaultMessageReporter;
import org.lflang.FileConfig;
import org.lflang.MessageReporter;
import org.lflang.target.TargetConfig;
import org.lflang.generator.IntegratedBuilder.ReportProgress;
import org.lflang.target.TargetConfig;

/**
* A {@code MainContext} is an {@code LFGeneratorContext} that is not nested in any other generator
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -33,8 +33,8 @@
import java.util.stream.Stream;
import org.lflang.FileConfig;
import org.lflang.MessageReporter;
import org.lflang.target.TargetConfig;
import org.lflang.generator.CodeBuilder;
import org.lflang.target.TargetConfig;
import org.lflang.target.property.PlatformProperty.Platform;
import org.lflang.util.FileUtil;

Expand Down
2 changes: 1 addition & 1 deletion core/src/main/java/org/lflang/generator/c/CCompiler.java
Original file line number Diff line number Diff line change
Expand Up @@ -35,11 +35,11 @@
import java.util.stream.Stream;
import org.lflang.FileConfig;
import org.lflang.MessageReporter;
import org.lflang.target.TargetConfig;
import org.lflang.generator.GeneratorBase;
import org.lflang.generator.GeneratorCommandFactory;
import org.lflang.generator.GeneratorUtils;
import org.lflang.generator.LFGeneratorContext;
import org.lflang.target.TargetConfig;
import org.lflang.target.property.BuildTypeProperty;
import org.lflang.target.property.PlatformProperty.Platform;
import org.lflang.util.FileUtil;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,9 +2,9 @@

import java.util.ArrayList;
import java.util.List;
import org.lflang.target.TargetConfig;
import org.lflang.generator.CodeBuilder;
import org.lflang.generator.ReactorInstance;
import org.lflang.target.TargetConfig;

/**
* This class is in charge of code generating functions and global variables related to the
Expand Down
2 changes: 1 addition & 1 deletion core/src/main/java/org/lflang/generator/c/CGenerator.java
Original file line number Diff line number Diff line change
Expand Up @@ -52,7 +52,6 @@
import org.eclipse.xtext.xbase.lib.StringExtensions;
import org.lflang.FileConfig;
import org.lflang.Target;
import org.lflang.target.TargetConfig;
import org.lflang.ast.ASTUtils;
import org.lflang.ast.DelayedConnectionTransformation;
import org.lflang.federated.extensions.CExtensionUtils;
Expand Down Expand Up @@ -86,6 +85,7 @@
import org.lflang.lf.ReactorDecl;
import org.lflang.lf.StateVar;
import org.lflang.lf.Variable;
import org.lflang.target.TargetConfig;
import org.lflang.target.property.PlatformProperty.Platform;
import org.lflang.target.property.PlatformProperty.PlatformOption;
import org.lflang.target.property.SchedulerProperty.SchedulerOption;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -2,8 +2,8 @@

import java.util.ArrayList;
import java.util.List;
import org.lflang.target.TargetConfig;
import org.lflang.generator.CodeBuilder;
import org.lflang.target.TargetConfig;
import org.lflang.target.property.PlatformProperty.Platform;
import org.lflang.util.StringUtil;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
import static org.lflang.util.StringUtil.addDoubleQuotes;

import java.nio.file.Path;
import org.lflang.target.TargetConfig;
import org.lflang.generator.CodeBuilder;
import org.lflang.target.TargetConfig;
import org.lflang.target.property.PlatformProperty.Platform;
import org.lflang.util.StringUtil;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -11,7 +11,6 @@
import java.util.Set;
import org.lflang.InferredType;
import org.lflang.MessageReporter;
import org.lflang.target.TargetConfig;
import org.lflang.ast.ASTUtils;
import org.lflang.federated.extensions.CExtensionUtils;
import org.lflang.generator.CodeBuilder;
Expand All @@ -33,6 +32,7 @@
import org.lflang.lf.VarRef;
import org.lflang.lf.Variable;
import org.lflang.lf.Watchdog;
import org.lflang.target.TargetConfig;
import org.lflang.util.StringUtil;

public class CReactionGenerator {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@
import java.util.HashSet;
import java.util.stream.Collectors;
import org.lflang.AttributeUtils;
import org.lflang.target.TargetConfig;
import org.lflang.ast.ASTUtils;
import org.lflang.federated.extensions.CExtensionUtils;
import org.lflang.generator.CodeBuilder;
Expand All @@ -23,6 +22,7 @@
import org.lflang.generator.ReactorInstance;
import org.lflang.generator.RuntimeRange;
import org.lflang.generator.SendRange;
import org.lflang.target.TargetConfig;
import org.lflang.target.property.LoggingProperty.LogLevel;

/**
Expand Down
2 changes: 1 addition & 1 deletion core/src/main/java/org/lflang/generator/c/CUtil.java
Original file line number Diff line number Diff line change
Expand Up @@ -39,7 +39,6 @@
import org.lflang.FileConfig;
import org.lflang.InferredType;
import org.lflang.MessageReporter;
import org.lflang.target.TargetConfig;
import org.lflang.ast.ASTUtils;
import org.lflang.generator.ActionInstance;
import org.lflang.generator.GeneratorCommandFactory;
Expand All @@ -54,6 +53,7 @@
import org.lflang.lf.VarRef;
import org.lflang.lf.Variable;
import org.lflang.lf.WidthTerm;
import org.lflang.target.TargetConfig;
import org.lflang.util.FileUtil;
import org.lflang.util.LFCommand;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,11 +3,11 @@
import java.nio.file.Path;
import java.util.ArrayList;
import java.util.List;
import org.lflang.target.TargetConfig;
import org.lflang.ast.ASTUtils;
import org.lflang.generator.CodeBuilder;
import org.lflang.generator.c.CPreambleGenerator;
import org.lflang.lf.Preamble;
import org.lflang.target.TargetConfig;

/**
* Generates user-defined preambles and #define and #include directives for the Python target.
Expand Down
7 changes: 3 additions & 4 deletions core/src/main/java/org/lflang/target/TargetConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -27,7 +27,6 @@
import java.util.ArrayList;
import java.util.List;
import java.util.Properties;

import org.lflang.MessageReporter;
import org.lflang.Target;
import org.lflang.TargetProperty;
Expand Down Expand Up @@ -87,8 +86,8 @@ public class TargetConfig {
*
* @param target AST node of a target declaration.
*/
public TargetConfig(TargetDecl target) { // FIXME: eliminate this constructor if we can
this.target = Target.fromDecl(target);
public TargetConfig(Target target) {
this.target = target;
}

/**
Expand All @@ -100,7 +99,7 @@ public TargetConfig(TargetDecl target) { // FIXME: eliminate this constructor if
* @param messageReporter An error reporter to report problems.
*/
public TargetConfig(Properties cliArgs, TargetDecl target, MessageReporter messageReporter) {
this(target);
this(Target.fromDecl(target));
if (target.getConfig() != null) {
List<KeyValuePair> pairs = target.getConfig().getPairs();
TargetProperty.load(this, pairs, messageReporter);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,7 +5,6 @@
import org.lflang.AbstractTargetProperty;
import org.lflang.MessageReporter;
import org.lflang.Target;
import org.lflang.TargetProperty.DictionaryElement;
import org.lflang.TimeUnit;
import org.lflang.TimeValue;
import org.lflang.ast.ASTUtils;
Expand All @@ -15,6 +14,7 @@
import org.lflang.lf.LfFactory;
import org.lflang.target.property.ClockSyncOptionsProperty.ClockSyncOptions;
import org.lflang.target.property.type.DictionaryType;
import org.lflang.target.property.type.DictionaryType.DictionaryElement;
import org.lflang.target.property.type.PrimitiveType;
import org.lflang.target.property.type.TargetPropertyType;

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -6,7 +6,6 @@
import org.lflang.AbstractTargetProperty;
import org.lflang.MessageReporter;
import org.lflang.Target;
import org.lflang.TargetProperty.DictionaryElement;
import org.lflang.TimeValue;
import org.lflang.ast.ASTUtils;
import org.lflang.lf.Element;
Expand All @@ -15,6 +14,7 @@
import org.lflang.lf.LfFactory;
import org.lflang.target.property.CoordinationOptionsProperty.CoordinationOptions;
import org.lflang.target.property.type.DictionaryType;
import org.lflang.target.property.type.DictionaryType.DictionaryElement;
import org.lflang.target.property.type.PrimitiveType;
import org.lflang.target.property.type.TargetPropertyType;

Expand Down
Loading

0 comments on commit 764bde2

Please sign in to comment.