use of org.lflang.lf.Parameter in project lingua-franca by lf-lang.
the class PortInstance method setInitialWidth.
/**
* Set the initial multiport width, if this is a multiport, from the widthSpec
* in the definition. This will be set to -1 if the width cannot be determined.
* @param errorReporter For reporting errors.
*/
private void setInitialWidth(ErrorReporter errorReporter) {
// If this is a multiport, determine the width.
WidthSpec widthSpec = definition.getWidthSpec();
if (widthSpec != null) {
if (widthSpec.isOfVariableLength()) {
errorReporter.reportError(definition, "Variable-width multiports not supported (yet): " + definition.getName());
} else {
isMultiport = true;
// Determine the initial width, if possible.
// The width may be given by a parameter or even sum of parameters.
width = 0;
for (WidthTerm term : widthSpec.getTerms()) {
Parameter parameter = term.getParameter();
if (parameter != null) {
Integer parameterValue = parent.initialIntParameterValue(parameter);
// Only a Literal is supported.
if (parameterValue != null) {
width += parameterValue;
} else {
width = -1;
return;
}
} else if (term.getWidth() != 0) {
width += term.getWidth();
} else {
width = -1;
return;
}
}
}
}
}
use of org.lflang.lf.Parameter in project lingua-franca by lf-lang.
the class PythonParameterGenerator method generatePythonGetters.
/**
* Generate Python code getters for parameters of reactor 'decl'.
*
* @param decl The reactor declaration
* @return The generated code as a StringBuilder
*/
public static String generatePythonGetters(ReactorDecl decl) {
List<String> lines = new ArrayList<>();
for (Parameter param : getAllParameters(decl)) {
if (!param.getName().equals("bank_index")) {
lines.addAll(List.of("@property", "def " + param.getName() + "(self):", " return self._" + param.getName() + " # pylint: disable=no-member", ""));
}
}
// Create a special property for bank_index
lines.addAll(List.of("@property", "def bank_index(self):", " return self._bank_index # pylint: disable=no-member", ""));
return String.join("\n", lines);
}
use of org.lflang.lf.Parameter in project lingua-franca by lf-lang.
the class CGeneratorExtension method getNetworkDelayLiteral.
/**
* Given a connection 'delay' predicate, return a string that represents the
* interval_t value of the additional delay that needs to be applied to the
* outgoing message.
*
* The returned additional delay in absence of after on network connection
* (i.e., if delay is passed as a null) is NEVER. This has a special
* meaning in C library functions that send network messages that carry
* timestamps (@see send_timed_message and send_port_absent_to_federate
* in lib/core/federate.c). In this case, the sender will send its current
* tag as the timestamp of the outgoing message without adding a microstep delay.
* If the user has assigned an after delay to the network connection (that
* can be zero) either as a time value (e.g., 200 msec) or as a literal
* (e.g., a parameter), that delay in nsec will be returned.
*
* @param delay
* @param generator
* @return
*/
public static String getNetworkDelayLiteral(Delay delay) {
String additionalDelayString = "NEVER";
if (delay != null) {
Parameter p = delay.getParameter();
TimeValue tv;
if (delay.getParameter() != null) {
// The parameter has to be parameter of the main reactor.
// And that value has to be a Time.
tv = ASTUtils.getDefaultAsTimeValue(p);
} else {
tv = ASTUtils.toTimeValue(delay.getTime());
}
additionalDelayString = Long.toString(tv.toNanoSeconds());
}
return additionalDelayString;
}
use of org.lflang.lf.Parameter in project lingua-franca by lf-lang.
the class ValueGenerator method getInitializerList.
/**
* Create a list of parameter initializers in target code in the context
* of an reactor instantiation.
*
* This respects the parameter assignments given in the reactor
* instantiation and falls back to the reactors default initializers
* if no value is assigned to it.
*
* @param param The parameter to create initializers for
* @return A list of initializers in target code
*/
public List<String> getInitializerList(Parameter param, Instantiation i) {
List<Assignment> assignments = i.getParameters().stream().filter(it -> it.getLhs() == param).collect(Collectors.toList());
if (// Case 0: The parameter was not overwritten in the instantiation
assignments.isEmpty())
return getInitializerList(param);
// Case 1: The parameter was overwritten in the instantiation
List<String> list = new ArrayList<>();
if (assignments.get(0) == null)
return list;
for (Value init : assignments.get(0).getRhs()) list.add(getTargetValue(init, ASTUtils.isOfTimeType(param)));
return list;
}
Aggregations