|
67 | 67 |
|
68 | 68 | // New Backend imports |
69 | 69 | import DetectStates = NBDetectStates; |
| 70 | + import NBResizable.EvalOrder; |
70 | 71 | import Evaluation = NBEvaluation; |
71 | 72 | import Inline = NBInline; |
72 | 73 | import Replacements = NBReplacements; |
@@ -875,6 +876,61 @@ public |
875 | 876 | end match; |
876 | 877 | end adaptArray; |
877 | 878 |
|
| 879 | + function applyOrder |
| 880 | + input output Iterator iter; |
| 881 | + input UnorderedMap<ComponentRef, EvalOrder> order; |
| 882 | + function applySingleOrder |
| 883 | + input ComponentRef name; |
| 884 | + input output Expression range; |
| 885 | + input UnorderedMap<ComponentRef, EvalOrder> order; |
| 886 | + protected |
| 887 | + EvalOrder eo = UnorderedMap.getOrDefault(name, order, NBResizable.EvalOrder.INDEPENDENT); |
| 888 | + Expression step, res; |
| 889 | + list<Integer> elements; |
| 890 | + algorithm |
| 891 | + range := match range |
| 892 | + |
| 893 | + // revert a range if needed |
| 894 | + case Expression.RANGE() algorithm |
| 895 | + step := Util.getOptionOrDefault(range.step, Expression.INTEGER(1)); |
| 896 | + if (Expression.isNegative(step) and eo == NBResizable.EvalOrder.FORWARD) or (Expression.isPositive(step) and eo == NBResizable.EvalOrder.BACKWARD) then |
| 897 | + res := Expression.revertRange(range); |
| 898 | + else |
| 899 | + res := range; |
| 900 | + end if; |
| 901 | + then res; |
| 902 | + |
| 903 | + // revert an array/list if needed |
| 904 | + case Expression.ARRAY(literal = true) algorithm |
| 905 | + if eo == NBResizable.EvalOrder.FORWARD then |
| 906 | + elements := list(Expression.getInteger(e) for e in range.elements); |
| 907 | + range.elements := listArray(list(Expression.INTEGER(e) for e in List.sort(elements, intGt))); |
| 908 | + elseif eo == NBResizable.EvalOrder.BACKWARD then |
| 909 | + elements := list(Expression.getInteger(e) for e in range.elements); |
| 910 | + range.elements := listArray(list(Expression.INTEGER(e) for e in List.sort(elements, intLt))); |
| 911 | + end if; |
| 912 | + then range; |
| 913 | + |
| 914 | + // no other allowed |
| 915 | + else algorithm |
| 916 | + Error.addMessage(Error.INTERNAL_ERROR,{getInstanceName() + " failed for unhandled range expression: " + Expression.toString(range)}); |
| 917 | + then fail(); |
| 918 | + end match; |
| 919 | + end applySingleOrder; |
| 920 | + algorithm |
| 921 | + iter := match iter |
| 922 | + case SINGLE() algorithm |
| 923 | + iter.range := applySingleOrder(iter.name, iter.range, order); |
| 924 | + then iter; |
| 925 | + case NESTED() algorithm |
| 926 | + for i in 1:arrayLength(iter.names) loop |
| 927 | + iter.ranges[i] := applySingleOrder(iter.names[i], iter.ranges[i], order); |
| 928 | + end for; |
| 929 | + then iter; |
| 930 | + else iter; |
| 931 | + end match; |
| 932 | + end applyOrder; |
| 933 | + |
878 | 934 | function toString |
879 | 935 | input Iterator iter; |
880 | 936 | output String str = ""; |
@@ -2069,6 +2125,18 @@ public |
2069 | 2125 | end match; |
2070 | 2126 | end getForFrames; |
2071 | 2127 |
|
| 2128 | + function applyForOrder |
| 2129 | + input output Equation eqn; |
| 2130 | + input UnorderedMap<ComponentRef, EvalOrder> order; |
| 2131 | + algorithm |
| 2132 | + eqn := match eqn |
| 2133 | + case FOR_EQUATION() algorithm |
| 2134 | + eqn.iter := Iterator.applyOrder(eqn.iter, order); |
| 2135 | + then eqn; |
| 2136 | + else eqn; |
| 2137 | + end match; |
| 2138 | + end applyForOrder; |
| 2139 | + |
2072 | 2140 | function isDummy |
2073 | 2141 | input Equation eqn; |
2074 | 2142 | output Boolean b; |
|
0 commit comments