@@ -64,6 +64,7 @@ import NFFunction.Function;
6464import Global ;
6565import BuiltinCall = NFBuiltinCall ;
6666import ComplexType = NFComplexType ;
67+ import ExpandExp = NFExpandExp ;
6768
6869constant Expression EQ_ASSERT_STR =
6970 Expression . STRING ("Connected constants/parameters must be equal" );
@@ -101,13 +102,48 @@ algorithm
101102end generateEquations;
102103
103104function evaluateOperators
104- input output Expression exp;
105+ input Expression exp;
105106 input ConnectionSets . Sets sets;
106107 input array< list< Connector >> setsArray;
107108 input CardinalityTable . Table ctable;
109+ output Expression evalExp;
108110algorithm
109- exp := Expression . map(exp,
110- function evaluateOperatorExp(sets = sets, setsArray = setsArray, ctable = ctable));
111+ evalExp := match exp
112+ local
113+ Call call;
114+ Boolean expanded;
115+
116+ case Expression . CALL (call = call)
117+ then match call
118+ case Call . TYPED_CALL ()
119+ then match Function . name(call. fn)
120+ case Absyn . IDENT ("inStream" )
121+ then evaluateInStream(Expression . toCref(listHead(call. arguments)), sets, setsArray, ctable);
122+ case Absyn . IDENT ("actualStream" )
123+ then evaluateActualStream(Expression . toCref(listHead(call. arguments)), sets, setsArray, ctable);
124+ case Absyn . IDENT ("cardinality" )
125+ then CardinalityTable . evaluateCardinality(listHead(call. arguments), ctable);
126+ else Expression . mapShallow(exp,
127+ function evaluateOperators(sets = sets, setsArray = setsArray, ctable = ctable));
128+ end match;
129+
130+ // inStream/actualStream can't handle non-literal subscripts, so reductions and array
131+ // constructors containing such calls needs to expanded to get rid of the iterators.
132+ case Call . TYPED_REDUCTION ()
133+ guard Expression . contains(call. exp, isStreamCall)
134+ then evaluateOperatorIteratorExp(exp, sets, setsArray, ctable);
135+
136+ case Call . TYPED_ARRAY_CONSTRUCTOR ()
137+ guard Expression . contains(call. exp, isStreamCall)
138+ then evaluateOperatorIteratorExp(exp, sets, setsArray, ctable);
139+
140+ else Expression . mapShallow(exp,
141+ function evaluateOperators(sets = sets, setsArray = setsArray, ctable = ctable));
142+ end match;
143+
144+ else Expression . mapShallow(exp,
145+ function evaluateOperators(sets = sets, setsArray = setsArray, ctable = ctable));
146+ end match;
111147end evaluateOperators;
112148
113149protected
@@ -545,31 +581,44 @@ algorithm
545581 setGlobalRoot(Global . isInStream, SOME (true ));
546582end makePositiveMaxCall;
547583
548- function evaluateOperatorExp
584+ function isStreamCall
585+ input Expression exp;
586+ output Boolean streamCall;
587+ algorithm
588+ streamCall := match exp
589+ local
590+ String name;
591+
592+ case Expression . CALL ()
593+ then match Function . name(Call . typedFunction(exp. call))
594+ case Absyn . IDENT ("inStream" ) then true ;
595+ case Absyn . IDENT ("actualStream" ) then true ;
596+ else false ;
597+ end match;
598+
599+ else false ;
600+ end match;
601+ end isStreamCall;
602+
603+ function evaluateOperatorIteratorExp
549604 input Expression exp;
550605 input ConnectionSets . Sets sets;
551606 input array< list< Connector >> setsArray;
552607 input CardinalityTable . Table ctable;
553608 output Expression evalExp;
609+ protected
610+ Boolean expanded;
554611algorithm
555- evalExp := match exp
556- local
557- Call call;
612+ (evalExp, expanded) := ExpandExp . expand(exp);
558613
559- case Expression . CALL (call = call as Call . TYPED_CALL ())
560- then match Function . name(call. fn)
561- case Absyn . IDENT ("inStream" )
562- then evaluateInStream(Expression . toCref(listHead(call. arguments)), sets, setsArray, ctable);
563- case Absyn . IDENT ("actualStream" )
564- then evaluateActualStream(Expression . toCref(listHead(call. arguments)), sets, setsArray, ctable);
565- case Absyn . IDENT ("cardinality" )
566- then CardinalityTable . evaluateCardinality(listHead(call. arguments), ctable);
567- else exp;
568- end match;
614+ if not expanded then
615+ Error . addInternalError(getInstanceName() +
616+ " failed to expand call containing stream operator: " +
617+ Expression . toString(exp), sourceInfo());
618+ end if ;
569619
570- else exp;
571- end match;
572- end evaluateOperatorExp;
620+ evalExp := evaluateOperators(evalExp, sets, setsArray, ctable);
621+ end evaluateOperatorIteratorExp;
573622
574623function evaluateInStream
575624 "Evaluates the inStream operator with the given cref as argument."
0 commit comments