use of org.lflang.lf.TargetDecl in project lingua-franca by lf-lang.
the class LFValidator method checkKeyValuePair.
/**
* Check target parameters, which are key-value pairs.
*/
@Check(CheckType.FAST)
public void checkKeyValuePair(KeyValuePair param) {
// Check only if the container's container is a Target.
if (param.eContainer().eContainer() instanceof TargetDecl) {
TargetProperty prop = TargetProperty.forName(param.getName());
// Make sure the key is valid.
if (prop == null) {
String options = TargetProperty.getOptions().stream().map(p -> p.description).sorted().collect(Collectors.joining(", "));
warning("Unrecognized target parameter: " + param.getName() + ". Recognized parameters are: " + options, Literals.KEY_VALUE_PAIR__NAME);
} else {
// Check whether the property is supported by the target.
if (!prop.supportedBy.contains(this.target)) {
warning("The target parameter: " + param.getName() + " is not supported by the " + this.target + " target and will thus be ignored.", Literals.KEY_VALUE_PAIR__NAME);
}
// Report problem with the assigned value.
prop.type.check(param.getValue(), param.getName(), this);
}
for (String it : targetPropertyErrors) {
error(it, Literals.KEY_VALUE_PAIR__VALUE);
}
targetPropertyErrors.clear();
for (String it : targetPropertyWarnings) {
error(it, Literals.KEY_VALUE_PAIR__VALUE);
}
targetPropertyWarnings.clear();
}
}
use of org.lflang.lf.TargetDecl 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