Search in sources :

Example 11 with Value

use of org.lflang.lf.Value 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;
}
Also used : Assignment(org.lflang.lf.Assignment) Delay(org.lflang.lf.Delay) Time(org.lflang.lf.Time) Collectors(java.util.stream.Collectors) ArrayList(java.util.ArrayList) StateVar(org.lflang.lf.StateVar) Parameter(org.lflang.lf.Parameter) List(java.util.List) Value(org.lflang.lf.Value) Assignment(org.lflang.lf.Assignment) Instantiation(org.lflang.lf.Instantiation) TimeValue(org.lflang.TimeValue) TimeUnit(org.lflang.TimeUnit) ASTUtils(org.lflang.ASTUtils) ArrayList(java.util.ArrayList) Value(org.lflang.lf.Value) TimeValue(org.lflang.TimeValue)

Aggregations

Value (org.lflang.lf.Value)11 TimeValue (org.lflang.TimeValue)5 Assignment (org.lflang.lf.Assignment)5 Instantiation (org.lflang.lf.Instantiation)5 ArrayList (java.util.ArrayList)4 LinkedList (java.util.LinkedList)4 Delay (org.lflang.lf.Delay)4 Parameter (org.lflang.lf.Parameter)4 Reactor (org.lflang.lf.Reactor)4 VarRef (org.lflang.lf.VarRef)4 List (java.util.List)3 Collectors (java.util.stream.Collectors)3 ASTUtils (org.lflang.ASTUtils)3 Action (org.lflang.lf.Action)3 Reaction (org.lflang.lf.Reaction)3 Collections (java.util.Collections)2 Objects (java.util.Objects)2 Optional (java.util.Optional)2 EcoreUtil (org.eclipse.emf.ecore.util.EcoreUtil)2 Check (org.eclipse.xtext.validation.Check)2