use of org.lflang.lf.KeyValuePair in project lingua-franca by lf-lang.
the class LFValidator method checkTargetProperties.
/**
* Check for consistency of the target properties, which are
* defined as KeyValuePairs.
*
* @param targetProperties The target properties defined
* in the current Lingua Franca program.
*/
@Check(CheckType.EXPENSIVE)
public void checkTargetProperties(KeyValuePairs targetProperties) {
EList<KeyValuePair> fastTargetProperties = new BasicEList<>(targetProperties.getPairs());
fastTargetProperties.removeIf(pair -> TargetProperty.forName(pair.getName()) != TargetProperty.FAST);
KeyValuePair fastTargetProperty = fastTargetProperties.size() > 0 ? fastTargetProperties.get(0) : null;
if (fastTargetProperty != null) {
// Check for federated
for (Reactor reactor : info.model.getReactors()) {
// Check to see if the program has a federated reactor
if (reactor.isFederated()) {
error("The fast target property is incompatible with federated programs.", fastTargetProperty, Literals.KEY_VALUE_PAIR__NAME);
break;
}
}
// Check for physical actions
for (Reactor reactor : info.model.getReactors()) {
// Check to see if the program has a physical action in a reactor
for (Action action : reactor.getActions()) {
if (action.getOrigin().equals(ActionOrigin.PHYSICAL)) {
error("The fast target property is incompatible with physical actions.", fastTargetProperty, Literals.KEY_VALUE_PAIR__NAME);
break;
}
}
}
}
EList<KeyValuePair> clockSyncTargetProperties = new BasicEList<>(targetProperties.getPairs());
// Check to see if clock-sync is defined
clockSyncTargetProperties.removeIf(pair -> TargetProperty.forName(pair.getName()) != TargetProperty.CLOCK_SYNC);
KeyValuePair clockSyncTargetProperty = clockSyncTargetProperties.size() > 0 ? clockSyncTargetProperties.get(0) : null;
if (clockSyncTargetProperty != null) {
boolean federatedExists = false;
for (Reactor reactor : info.model.getReactors()) {
if (reactor.isFederated()) {
federatedExists = true;
}
}
if (!federatedExists) {
warning("The clock-sync target property is incompatible with non-federated programs.", clockSyncTargetProperty, Literals.KEY_VALUE_PAIR__NAME);
}
}
EList<KeyValuePair> schedulerTargetProperties = new BasicEList<>(targetProperties.getPairs());
schedulerTargetProperties.removeIf(pair -> TargetProperty.forName(pair.getName()) != TargetProperty.SCHEDULER);
KeyValuePair schedulerTargetProperty = schedulerTargetProperties.size() > 0 ? schedulerTargetProperties.get(0) : null;
if (schedulerTargetProperty != null) {
String schedulerName = schedulerTargetProperty.getValue().getId();
if (!TargetProperty.SchedulerOption.valueOf(schedulerName).prioritizesDeadline()) {
// Check if a deadline is assigned to any reaction
if (info.model.getReactors().stream().filter(reactor -> {
// has a deadline handler.
return ASTUtils.allReactions(reactor).stream().filter(reaction -> {
return reaction.getDeadline() != null;
}).count() > 0;
}).count() > 0) {
warning("This program contains deadlines, but the chosen " + schedulerName + " scheduler does not prioritize reaction execution " + "based on deadlines. This might result in a sub-optimal " + "scheduling.", schedulerTargetProperty, Literals.KEY_VALUE_PAIR__VALUE);
}
}
}
}
use of org.lflang.lf.KeyValuePair in project lingua-franca by lf-lang.
the class GeneratorUtils method getLFResource.
/**
* Return the {@code LFResource} representation of the
* given resource.
* @param resource The {@code Resource} to be
* represented as an {@code LFResource}
* @param srcGenBasePath The root directory for any
* generated sources associated with the resource.
* @param context The generator invocation context.
* @param errorReporter An error message acceptor.
* @return the {@code LFResource} representation of the
* given resource.
*/
public static LFResource getLFResource(Resource resource, Path srcGenBasePath, LFGeneratorContext context, ErrorReporter errorReporter) {
TargetDecl target = GeneratorUtils.findTarget(resource);
KeyValuePairs config = target.getConfig();
var targetConfig = new TargetConfig();
if (config != null) {
List<KeyValuePair> pairs = config.getPairs();
TargetProperty.set(targetConfig, pairs != null ? pairs : List.of(), errorReporter);
}
try {
FileConfig fc = new FileConfig(resource, srcGenBasePath, context.useHierarchicalBin());
return new LFResource(resource, fc, targetConfig);
} catch (IOException e) {
throw new RuntimeException("Failed to instantiate an imported resource because an I/O error " + "occurred.");
}
}
Aggregations