/
BackendDAECreate.mo
3292 lines (3036 loc) · 139 KB
/
BackendDAECreate.mo
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
/*
* This file is part of OpenModelica.
*
* Copyright (c) 1998-CurrentYear, Linköping University,
* Department of Computer and Information Science,
* SE-58183 Linköping, Sweden.
*
* All rights reserved.
*
* THIS PROGRAM IS PROVIDED UNDER THE TERMS OF GPL VERSION 3
* AND THIS OSMC PUBLIC LICENSE (OSMC-PL).
* ANY USE, REPRODUCTION OR DISTRIBUTION OF THIS PROGRAM CONSTITUTES RECIPIENT'S
* ACCEPTANCE OF THE OSMC PUBLIC LICENSE.
*
* The OpenModelica software and the Open Source Modelica
* Consortium (OSMC) Public License (OSMC-PL) are obtained
* from Linköping University, either from the above address,
* from the URLs: http://www.ida.liu.se/projects/OpenModelica or
* http://www.openmodelica.org, and in the OpenModelica distribution.
* GNU version 3 is obtained from: http://www.gnu.org/copyleft/gpl.html.
*
* This program is distributed WITHOUT ANY WARRANTY; without
* even the implied warranty of MERCHANTABILITY or FITNESS
* FOR A PARTICULAR PURPOSE, EXCEPT AS EXPRESSLY SET FORTH
* IN THE BY RECIPIENT SELECTED SUBSIDIARY LICENSE CONDITIONS
* OF OSMC-PL.
*
* See the full OSMC Public License conditions for more details.
*
*/
encapsulated package BackendDAECreate
" file: BackendDAECreate.mo
package: BackendDAECreate
description: This file contains all functions for transforming the DAE structure to the BackendDAE.
RCS: $Id$
"
public import Absyn;
public import Algorithm;
public import BackendDAE;
public import DAE;
public import Env;
protected import BackendDAEUtil;
protected import BackendEquation;
protected import BackendVariable;
protected import BaseHashTable;
protected import CheckModel;
protected import ComponentReference;
protected import ClassInf;
protected import DAEDump;
protected import DAEUtil;
protected import Debug;
protected import Derive;
protected import Error;
protected import Expression;
protected import ExpressionSimplify;
protected import ExpressionDump;
protected import Flags;
protected import HashTableExpToIndex;
protected import HashTable;
protected import Inline;
protected import List;
protected import SCode;
protected import System;
protected import Util;
public function lower
"function: lower
This function translates a DAE, which is the result from instantiating a
class, into a more precise form, called BackendDAE.BackendDAE defined in this module.
The BackendDAE.BackendDAE representation splits the DAE into equations and variables
and further divides variables into known and unknown variables and the
equations into simple and nonsimple equations.
The variables are inserted into a hash table. This gives a lookup cost of
O(1) for finding a variable. The equations are put in an expandable
array. Where adding a new equation can be done in O(1) time if space
is available.
inputs: daeList: DAE.DAElist, simplify: bool)
outputs: BackendDAE.BackendDAE"
input DAE.DAElist lst;
input Env.Cache inCache;
input Env.Env inEnv;
input Boolean addDummyDerivativeIfNeeded;
output BackendDAE.BackendDAE outBackendDAE;
protected
BackendDAE.BinTree s;
BackendDAE.Variables vars,knvars,vars_1,extVars;
BackendDAE.AliasVariables aliasVars "hash table with alias vars' replacements (a=b or a=-b)";
list<BackendDAE.Equation> eqns,reqns,ieqns,algeqns,algeqns1,ialgeqns,multidimeqns,imultidimeqns,eqns_1,ceeqns,iceeqns;
list<DAE.Constraint> constrs;
list<DAE.ClassAttributes> clsAttrs;
list<BackendDAE.WhenClause> whenclauses,whenclauses_1;
BackendDAE.EquationArray eqnarr,reqnarr,ieqnarr;
array<DAE.Constraint> constrarra;
array<DAE.ClassAttributes> clsattrsarra;
BackendDAE.ExternalObjectClasses extObjCls;
BackendDAE.SymbolicJacobians symjacs;
Boolean daeContainsNoStates, shouldAddDummyDerivative;
BackendDAE.EventInfo einfo;
list<DAE.Element> elems;
list<BackendDAE.ZeroCrossing> zero_crossings;
DAE.FunctionTree functionTree;
algorithm
System.realtimeTick(BackendDAE.RT_CLOCK_EXECSTAT_BACKEND_MODULES);
functionTree := Env.getFunctionTree(inCache);
(DAE.DAE(elems),functionTree) := processDelayExpressions(lst,functionTree);
s := states(elems, BackendDAE.emptyBintree);
vars := BackendDAEUtil.emptyVars();
knvars := BackendDAEUtil.emptyVars();
extVars := BackendDAEUtil.emptyVars();
(vars,knvars,extVars,eqns,reqns,ieqns,constrs,clsAttrs,whenclauses,extObjCls,s) := lower2(listReverse(elems), functionTree, vars, knvars, extVars, {}, {}, {}, {}, {}, {}, {}, s);
daeContainsNoStates := hasNoStates(s); // check if the DAE has states
// adrpo: add the dummy derivative state ONLY IF the DAE contains
// no states AND ONLY if addDummyDerivative is set to true!
shouldAddDummyDerivative := boolAnd(addDummyDerivativeIfNeeded, daeContainsNoStates);
(vars,eqns) := addDummyState(vars, eqns, shouldAddDummyDerivative);
whenclauses_1 := listReverse(whenclauses);
vars_1 := detectImplicitDiscrete(vars,knvars,eqns);
eqnarr := BackendDAEUtil.listEquation(eqns);
reqnarr := BackendDAEUtil.listEquation(reqns);
ieqnarr := BackendDAEUtil.listEquation(ieqns);
constrarra := listArray(constrs);
clsattrsarra := listArray(clsAttrs);
einfo := BackendDAE.EVENT_INFO(whenclauses_1,{});
aliasVars := BackendDAEUtil.emptyAliasVariables();
outBackendDAE := BackendDAE.DAE(BackendDAE.EQSYSTEM(vars_1,eqnarr,NONE(),NONE(),BackendDAE.NO_MATCHING())::{},BackendDAE.SHARED(knvars,extVars,aliasVars,ieqnarr,reqnarr,constrarra,clsattrsarra,inCache,inEnv,functionTree,einfo,extObjCls,BackendDAE.SIMULATION(),{}));
BackendDAEUtil.checkBackendDAEWithErrorMsg(outBackendDAE);
Debug.fcall(Flags.DUMP_BACKENDDAE_INFO,print,"No. of Equations: " +& intString(BackendDAEUtil.equationSize(eqnarr)) +& "\nNo. of Variables: " +& intString(BackendVariable.varsSize(vars_1)) +& "\n");
Debug.execStat("generate Backend Data Structur",BackendDAE.RT_CLOCK_EXECSTAT_BACKEND_MODULES);
end lower;
protected function lower2
"Helper function to lower."
input list<DAE.Element> inElements "input is in reverse order. this is faster than reversing all accumulators at the end";
input DAE.FunctionTree functionTree;
input BackendDAE.Variables inVars "The time depend Variables";
input BackendDAE.Variables inKnVars "The time independend Variables";
input BackendDAE.Variables inExVars "The external Variables";
input list<BackendDAE.Equation> inEqnsLst "The dynamic Equations/Algoritms";
input list<BackendDAE.Equation> inREqnsLst "The algebraic Equations";
input list<BackendDAE.Equation> inIEqnsLst "The initial Equations";
input list<DAE.Constraint> inConstraintLst;
input list<DAE.ClassAttributes> inClassAttributeLst;
input list<BackendDAE.WhenClause> inWhenClauseLst;
input BackendDAE.ExternalObjectClasses inExtObjClasses;
input BackendDAE.BinTree inStates;
output BackendDAE.Variables outVariables;
output BackendDAE.Variables outKnownVariables;
output BackendDAE.Variables outExternalVariables;
output list<BackendDAE.Equation> oEqnsLst;
output list<BackendDAE.Equation> oREqnsLst;
output list<BackendDAE.Equation> oIEqnsLst;
output list<DAE.Constraint> outConstraintLst;
output list<DAE.ClassAttributes> outClassAttributeLst;
output list<BackendDAE.WhenClause> outWhenClauseLst;
output BackendDAE.ExternalObjectClasses outExtObjClasses;
output BackendDAE.BinTree outStatesBinTree;
algorithm
(outVariables,outKnownVariables,outExternalVariables,oEqnsLst,oREqnsLst,oIEqnsLst,
outConstraintLst,outClassAttributeLst,outWhenClauseLst,outExtObjClasses,outStatesBinTree):=
match (inElements,functionTree,inVars,inKnVars,inExVars,inEqnsLst,inREqnsLst,inIEqnsLst,
inConstraintLst,inClassAttributeLst,inWhenClauseLst,inExtObjClasses,inStates)
local
BackendDAE.Variables vars,knvars,extVars;
list<BackendDAE.WhenClause> whenclauses;
list<BackendDAE.Equation> eqns,reqns,ieqns;
list<DAE.Constraint> constrs;
list<DAE.ClassAttributes> clsAttrs;
BackendDAE.ExternalObjectClasses extObjCls;
DAE.Element daeEl;
list<DAE.Element> daeLstRest;
BackendDAE.BinTree states;
// the empty case
case ({},_,_,_,_,_,_,_,_,_,_,_,_)
then
(inVars,inKnVars,inExVars,inEqnsLst,inREqnsLst,inIEqnsLst,inConstraintLst,inClassAttributeLst,inWhenClauseLst,inExtObjClasses,inStates);
case (daeEl::daeLstRest,_,_,_,_,_,_,_,_,_,_,_,_)
equation
(vars,knvars,extVars,eqns,reqns,ieqns,constrs,clsAttrs,whenclauses,extObjCls,states) =
lower3(daeEl,functionTree,inVars,inKnVars,inExVars,inEqnsLst,inREqnsLst,inIEqnsLst,inConstraintLst,inClassAttributeLst,inWhenClauseLst,inExtObjClasses,inStates);
(vars,knvars,extVars,eqns,reqns,ieqns,constrs,clsAttrs,whenclauses,extObjCls,states) =
lower2(daeLstRest,functionTree,vars,knvars,extVars,eqns,reqns,ieqns,constrs,clsAttrs,whenclauses,extObjCls,states);
then
(vars,knvars,extVars,eqns,reqns,ieqns,constrs,clsAttrs,whenclauses,extObjCls,states);
end match;
end lower2;
protected function lower3
"Helper function to lower."
input DAE.Element inElement "input is in reverse order. this is faster than reversing all accumulators at the end";
input DAE.FunctionTree functionTree;
input BackendDAE.Variables inVars "The time depend Variables";
input BackendDAE.Variables inKnVars "The time independend Variables";
input BackendDAE.Variables inExVars "The external Variables";
input list<BackendDAE.Equation> inEqnsLst "The dynamic Equations/Algoritms";
input list<BackendDAE.Equation> inREqnsLst "The algebraic Equations";
input list<BackendDAE.Equation> inIEqnsLst "The initial Equations";
input list<DAE.Constraint> inConstraintLst;
input list<DAE.ClassAttributes> inClassAttributeLst;
input list<BackendDAE.WhenClause> inWhenClauseLst;
input BackendDAE.ExternalObjectClasses inExtObjClasses;
input BackendDAE.BinTree inStates;
output BackendDAE.Variables outVariables;
output BackendDAE.Variables outKnownVariables;
output BackendDAE.Variables outExternalVariables;
output list<BackendDAE.Equation> oEqnsLst;
output list<BackendDAE.Equation> oREqnsLst;
output list<BackendDAE.Equation> oIEqnsLst;
output list<DAE.Constraint> outConstraintLst;
output list<DAE.ClassAttributes> outClassAttributeLst;
output list<BackendDAE.WhenClause> outWhenClauseLst;
output BackendDAE.ExternalObjectClasses outExtObjClasses;
output BackendDAE.BinTree outStatesBinTree;
algorithm
(outVariables,outKnownVariables,outExternalVariables,oEqnsLst,oREqnsLst,oIEqnsLst,
outConstraintLst,outClassAttributeLst,outWhenClauseLst,outExtObjClasses,outStatesBinTree):=
match (inElement,functionTree,inVars,inKnVars,inExVars,inEqnsLst,inREqnsLst,inIEqnsLst,
inConstraintLst,inClassAttributeLst,inWhenClauseLst,inExtObjClasses,inStates)
local
list<DAE.Element> daeElts;
DAE.Constraint cons_1;
list<DAE.Constraint> constrs;
list<DAE.ClassAttributes> clsAttrs;
Absyn.Path path;
BackendDAE.Variables vars,knvars,extVars;
BackendDAE.ExternalObjectClasses extObjCls;
BackendDAE.ExternalObjectClass extObjCl;
list<BackendDAE.Equation> eqns,reqns,ieqns;
list<BackendDAE.WhenClause> whenclauses;
BackendDAE.BinTree states;
DAE.ElementSource source;
list<DAE.Exp> explst;
DAE.Exp e2;
// adrpo: should we ignore OUTER vars?!
//case (((v as DAE.VAR(innerOuter=io)) :: xs),states,vars,knvars,extVars,whenclauses)
// equation
// DAEUtil.isOuterVar(v);
// (vars,knvars,extVars,eqns,reqns,ieqns,aeqns,algs,whenclauses_1,extObjCls) =
// lower2(xs, states, vars, knvars, extVars, whenclauses);
// then
// (vars,knvars,extVars,eqns,reqns,ieqns,aeqns,algs,whenclauses_1,extObjCls);
// class for external object
case (DAE.EXTOBJECTCLASS(path,source),_,_,_,_,_,_,_,_,_,_,_,_)
equation
extObjCl = BackendDAE.EXTOBJCLASS(path,source);
then
(inVars,inKnVars,inExVars,inEqnsLst,inREqnsLst,inIEqnsLst,inConstraintLst,inClassAttributeLst,inWhenClauseLst,extObjCl::inExtObjClasses,inStates);
// variables
case (DAE.VAR(componentRef = _),_,_,_,_,_,_,_,_,_,_,_,_)
equation
(vars,knvars,extVars,eqns,states) = lowerVar(inElement,functionTree,inVars,inKnVars,inExVars,inEqnsLst,inStates);
then
(vars,knvars,extVars,eqns,inREqnsLst,inIEqnsLst,inConstraintLst,inClassAttributeLst,inWhenClauseLst,inExtObjClasses,states);
/* Only succeds for tuple equations, i.e. (a,b,c) = foo(x,y,z) or foo(x,y,z) = (a,b,c) */
case(DAE.EQUATION(DAE.TUPLE(explst),e2 as DAE.CALL(path =_),source),_,_,_,_,_,_,_,_,_,_,_,_)
equation
(eqns,reqns,ieqns) = lowerAlgorithm(DAE.ALGORITHM(DAE.ALGORITHM_STMTS({DAE.STMT_TUPLE_ASSIGN(DAE.T_UNKNOWN_DEFAULT,explst,e2,source)}),source),functionTree,inEqnsLst,inREqnsLst,inIEqnsLst);
then
(inVars,inKnVars,inExVars,eqns,reqns,ieqns,inConstraintLst,inClassAttributeLst,inWhenClauseLst,inExtObjClasses,inStates);
case(DAE.EQUATION(e2 as DAE.CALL(path =_),DAE.TUPLE(explst),source),_,_,_,_,_,_,_,_,_,_,_,_)
equation
(eqns,reqns,ieqns) = lowerAlgorithm(DAE.ALGORITHM(DAE.ALGORITHM_STMTS({DAE.STMT_TUPLE_ASSIGN(DAE.T_UNKNOWN_DEFAULT,explst,e2,source)}),source),functionTree,inEqnsLst,inREqnsLst,inIEqnsLst);
then
(inVars,inKnVars,inExVars,eqns,reqns,ieqns,inConstraintLst,inClassAttributeLst,inWhenClauseLst,inExtObjClasses,inStates);
// scalar equations
case (DAE.EQUATION(exp = _),_,_,_,_,_,_,_,_,_,_,_,_)
equation
eqns = lowerEqn(inElement,functionTree,inEqnsLst);
then
(inVars,inKnVars,inExVars,eqns,inREqnsLst,inIEqnsLst,inConstraintLst,inClassAttributeLst,inWhenClauseLst,inExtObjClasses,inStates);
// initial equations
case (DAE.INITIALEQUATION(exp1 = _),_,_,_,_,_,_,_,_,_,_,_,_)
equation
ieqns = lowerEqn(inElement,functionTree,inIEqnsLst);
then
(inVars,inKnVars,inExVars,inEqnsLst,inREqnsLst,ieqns,inConstraintLst,inClassAttributeLst,inWhenClauseLst,inExtObjClasses,inStates);
// effort variable equality equations
case (DAE.EQUEQUATION(cr1 = _),_,_,_,_,_,_,_,_,_,_,_,_)
equation
eqns = lowerEqn(inElement,functionTree,inEqnsLst);
then
(inVars,inKnVars,inExVars,eqns,inREqnsLst,inIEqnsLst,inConstraintLst,inClassAttributeLst,inWhenClauseLst,inExtObjClasses,inStates);
// a solved equation
case (DAE.DEFINE(componentRef = _),_,_,_,_,_,_,_,_,_,_,_,_)
equation
eqns = lowerEqn(inElement,functionTree,inEqnsLst);
then
(inVars,inKnVars,inExVars,eqns,inREqnsLst,inIEqnsLst,inConstraintLst,inClassAttributeLst,inWhenClauseLst,inExtObjClasses,inStates);
// complex equations
case (DAE.COMPLEX_EQUATION(lhs = _),_,_,_,_,_,_,_,_,_,_,_,_)
equation
eqns = lowerEqn(inElement,functionTree,inEqnsLst);
then
(inVars,inKnVars,inExVars,eqns,inREqnsLst,inIEqnsLst,inConstraintLst,inClassAttributeLst,inWhenClauseLst,inExtObjClasses,inStates);
// complex initial equations
case (DAE.INITIAL_COMPLEX_EQUATION(lhs = _),_,_,_,_,_,_,_,_,_,_,_,_)
equation
ieqns = lowerEqn(inElement,functionTree,inIEqnsLst);
then
(inVars,inKnVars,inExVars,inEqnsLst,inREqnsLst,ieqns,inConstraintLst,inClassAttributeLst,inWhenClauseLst,inExtObjClasses,inStates);
// array equations
case (DAE.ARRAY_EQUATION(exp = _),_,_,_,_,_,_,_,_,_,_,_,_)
equation
eqns = lowerEqn(inElement,functionTree,inEqnsLst);
then
(inVars,inKnVars,inExVars,eqns,inREqnsLst,inIEqnsLst,inConstraintLst,inClassAttributeLst,inWhenClauseLst,inExtObjClasses,inStates);
// initial array equations
case (DAE.INITIAL_ARRAY_EQUATION(exp = _),_,_,_,_,_,_,_,_,_,_,_,_)
equation
ieqns = lowerEqn(inElement,functionTree,inIEqnsLst);
then
(inVars,inKnVars,inExVars,inEqnsLst,inREqnsLst,ieqns,inConstraintLst,inClassAttributeLst,inWhenClauseLst,inExtObjClasses,inStates);
// when equations
case (DAE.WHEN_EQUATION(condition = _),_,_,_,_,_,_,_,_,_,_,_,_)
equation
(eqns,whenclauses) = lowerWhenEqn(inElement,functionTree,inEqnsLst,inWhenClauseLst);
then
(inVars,inKnVars,inExVars,eqns,inREqnsLst,inIEqnsLst,inConstraintLst,inClassAttributeLst,whenclauses,inExtObjClasses,inStates);
// if equation that cannot be translated to if expression but have initial() as condition
case (DAE.IF_EQUATION(condition1 = {DAE.CALL(path=Absyn.IDENT("initial"))},equations2=_::{},equations3={}),_,_,_,_,_,_,_,_,_,_,_,_)
equation
ieqns = lowerEqn(inElement,functionTree,inIEqnsLst);
then
(inVars,inKnVars,inExVars,inEqnsLst,inREqnsLst,ieqns,inConstraintLst,inClassAttributeLst,inWhenClauseLst,inExtObjClasses,inStates);
// if equation
case (DAE.IF_EQUATION(condition1 = _),_,_,_,_,_,_,_,_,_,_,_,_)
equation
eqns = lowerEqn(inElement,functionTree,inEqnsLst);
then
(inVars,inKnVars,inExVars,eqns,inREqnsLst,inIEqnsLst,inConstraintLst,inClassAttributeLst,inWhenClauseLst,inExtObjClasses,inStates);
// initial if equation
case (DAE.INITIAL_IF_EQUATION(condition1 = _),_,_,_,_,_,_,_,_,_,_,_,_)
equation
ieqns = lowerEqn(inElement,functionTree,inIEqnsLst);
then
(inVars,inKnVars,inExVars,inEqnsLst,inREqnsLst,ieqns,inConstraintLst,inClassAttributeLst,inWhenClauseLst,inExtObjClasses,inStates);
// algorithm
case (DAE.ALGORITHM(algorithm_ = _),_,_,_,_,_,_,_,_,_,_,_,_)
equation
(eqns,reqns,ieqns) = lowerAlgorithm(inElement,functionTree,inEqnsLst,inREqnsLst,inIEqnsLst);
then
(inVars,inKnVars,inExVars,eqns,reqns,ieqns,inConstraintLst,inClassAttributeLst,inWhenClauseLst,inExtObjClasses,inStates);
// initial algorithm
case (DAE.INITIALALGORITHM(algorithm_ = _),_,_,_,_,_,_,_,_,_,_,_,_)
equation
(eqns,reqns,ieqns) = lowerAlgorithm(inElement,functionTree,inEqnsLst,inREqnsLst,inIEqnsLst);
then
(inVars,inKnVars,inExVars,inEqnsLst,inREqnsLst,ieqns,inConstraintLst,inClassAttributeLst,inWhenClauseLst,inExtObjClasses,inStates);
// flat class / COMP
case (DAE.COMP(dAElist = daeElts),_,_,_,_,_,_,_,_,_,_,_,_)
equation
(vars,knvars,extVars,eqns,reqns,ieqns,constrs,clsAttrs,whenclauses,extObjCls,states) = lower2(listReverse(daeElts),functionTree,inVars,inKnVars,inExVars,inEqnsLst,inREqnsLst,inIEqnsLst,inConstraintLst,inClassAttributeLst,inWhenClauseLst,inExtObjClasses,inStates);
then
(vars,knvars,extVars,eqns,reqns,ieqns,constrs,clsAttrs,whenclauses,extObjCls,states);
// assert in equation section is converted to ALGORITHM
case (DAE.ASSERT(condition = _),_,_,_,_,_,_,_,_,_,_,_,_)
equation
(eqns,reqns,ieqns) = lowerAlgorithm(inElement,functionTree,inEqnsLst,inREqnsLst,inIEqnsLst);
then
(inVars,inKnVars,inExVars,eqns,reqns,ieqns,inConstraintLst,inClassAttributeLst,inWhenClauseLst,inExtObjClasses,inStates);
// terminate in equation section is converted to ALGORITHM
case (DAE.TERMINATE(message = _),_,_,_,_,_,_,_,_,_,_,_,_)
equation
(eqns,reqns,ieqns) = lowerAlgorithm(inElement,functionTree,inEqnsLst,inREqnsLst,inIEqnsLst);
then
(inVars,inKnVars,inExVars,eqns,reqns,ieqns,inConstraintLst,inClassAttributeLst,inWhenClauseLst,inExtObjClasses,inStates);
case (DAE.NORETCALL(functionName = _),_,_,_,_,_,_,_,_,_,_,_,_)
equation
(eqns,reqns,ieqns) = lowerAlgorithm(inElement,functionTree,inEqnsLst,inREqnsLst,inIEqnsLst);
then
(inVars,inKnVars,inExVars,eqns,reqns,ieqns,inConstraintLst,inClassAttributeLst,inWhenClauseLst,inExtObjClasses,inStates);
// constraint (Optimica) Just pass the constraints for now. Should anything more be done here?
case (DAE.CONSTRAINT(constraints = cons_1),_,_,_,_,_,_,_,_,_,_,_,_)
then
(inVars,inKnVars,inExVars,inEqnsLst,inREqnsLst,inIEqnsLst,cons_1::inConstraintLst,inClassAttributeLst,inWhenClauseLst,inExtObjClasses,inStates);
case (_,_,_,_,_,_,_,_,_,_,_,_,_)
equation
// show only on failtrace!
true = Flags.isSet(Flags.FAILTRACE);
Debug.traceln("- BackendDAECreate.lower3 failed on: " +& DAEDump.dumpElementsStr({inElement}));
then
fail();
end match;
end lower3;
/*
* lower all variables
*/
protected function lowerVar
"function: lowerVar
Transforms a DAE variable to DAE variable.
Includes changing the ComponentRef name to a simpler form
\'a\'.\'b\'{2}\'c\'{5} becomes
\'a.b{2}.c\' (as CREF_IDENT(\"a.b.c\",{2}) )
inputs: (DAE.Element, BackendDAE.BinTree /* states */)
outputs: Var"
input DAE.Element inElement;
input DAE.FunctionTree functionTree;
input BackendDAE.Variables inVars "The time depend Variables";
input BackendDAE.Variables inKnVars "The time independend Variables";
input BackendDAE.Variables inExVars "The external Variables";
input list<BackendDAE.Equation> inEqnsLst "The dynamic Equations/Algoritms";
input BackendDAE.BinTree inStates;
output BackendDAE.Variables outVariables;
output BackendDAE.Variables outKnownVariables;
output BackendDAE.Variables outExternalVariables;
output list<BackendDAE.Equation> oEqnsLst;
output BackendDAE.BinTree outStates;
algorithm
(outVariables,outKnownVariables,outExternalVariables,oEqnsLst,outStates) :=
matchcontinue (inElement,functionTree,inVars,inKnVars,inExVars,inEqnsLst,inStates)
local
DAE.ComponentRef cr;
DAE.ElementSource source;
BackendDAE.Var backendVar1,backendVar2;
DAE.Exp e1,e2;
BackendDAE.BinTree states;
BackendDAE.Variables vars,knvars,extvars;
String str;
// external object variables
case (DAE.VAR(ty = DAE.T_COMPLEX(complexClassType = ClassInf.EXTERNAL_OBJ(path=_))),_,_,_,_,_,_)
equation
backendVar1 = lowerExtObjVar(inElement);
backendVar2 = Inline.inlineVar(backendVar1,(SOME(functionTree),{DAE.NORM_INLINE()}));
extvars = BackendVariable.addVar(backendVar2, inExVars);
then
(inVars,inKnVars,extvars,inEqnsLst,inStates);
// variables: states and algebraic variables with binding equation
case (DAE.VAR(componentRef = cr,binding=SOME(e2), source = source),_,_,_,_,_,_)
equation
// adrpo 2009-09-07 - according to MathCore
// add the binding as an equation and remove the binding from variable!
true = isStateOrAlgvar(inElement);
(backendVar1,states) = lowerDynamicVar(inElement, inStates);
backendVar2 = Inline.inlineVar(backendVar1,(SOME(functionTree),{DAE.NORM_INLINE()}));
(e2,source) = Inline.inlineExp(e2,(SOME(functionTree),{DAE.NORM_INLINE()}),source);
vars = BackendVariable.addVar(backendVar2, inVars);
e1 = Expression.crefExp(cr);
then
(vars,inKnVars,inExVars,BackendDAE.EQUATION(e1, e2, source)::inEqnsLst,states);
// variables: states and algebraic variables with NO binding equation
case (DAE.VAR(binding=NONE(), source = source),_,_,_,_,_,_)
equation
true = isStateOrAlgvar(inElement);
(backendVar1,states) = lowerDynamicVar(inElement, inStates);
backendVar2 = Inline.inlineVar(backendVar1,(SOME(functionTree),{DAE.NORM_INLINE()}));
vars = BackendVariable.addVar(backendVar2, inVars);
then
(vars,inKnVars,inExVars,inEqnsLst,states);
// known variables: parameters and constants
case (DAE.VAR(componentRef = _),_,_,_,_,_,_)
equation
backendVar1 = lowerKnownVar(inElement) "in previous rule, lower_var failed." ;
backendVar2 = Inline.inlineVar(backendVar1,(SOME(functionTree),{DAE.NORM_INLINE()}));
knvars = BackendVariable.addVar(backendVar2, inKnVars);
then
(inVars,knvars,inExVars,inEqnsLst,inStates);
case (_,_,_,_,_,_,_)
equation
str = "BackendDAECreate.lowerVar failed for " +& DAEDump.dumpElementsStr({inElement});
Error.addMessage(Error.INTERNAL_ERROR, {str});
then fail();
end matchcontinue;
end lowerVar;
protected function isStateOrAlgvar
"@author adrpo
check if this variable is a state or algebraic"
input DAE.Element e;
output Boolean out;
algorithm
out := match (e)
case (DAE.VAR(kind = DAE.VARIABLE())) then true;
case (DAE.VAR(kind = DAE.DISCRETE())) then true;
else false;
end match;
end isStateOrAlgvar;
protected function lowerDynamicVar
"function: lowerDynamicVar
Transforms a DAE variable to DAE variable.
Includes changing the ComponentRef name to a simpler form
\'a\'.\'b\'{2}\'c\'{5} becomes
\'a.b{2}.c\' (as CREF_IDENT(\"a.b.c\",{2}) )
inputs: (DAE.Element, BackendDAE.BinTree /* states */)
outputs: Var"
input DAE.Element inElement;
input BackendDAE.BinTree istates;
output BackendDAE.Var outVar;
output BackendDAE.BinTree ostates;
algorithm
(outVar,ostates) := match (inElement,istates)
local
list<DAE.Subscript> dims;
DAE.ComponentRef name;
BackendDAE.VarKind kind_1;
DAE.VarKind kind;
DAE.VarDirection dir;
DAE.VarParallelism prl;
BackendDAE.Type tp;
DAE.ConnectorType ct;
DAE.ElementSource source "origin of equation";
Option<DAE.VariableAttributes> dae_var_attr;
Option<SCode.Comment> comment;
BackendDAE.BinTree states;
DAE.Type t;
DAE.VarVisibility protection;
Boolean b;
case (DAE.VAR(componentRef = name,
kind = kind,
direction = dir,
parallelism = prl,
protection = protection,
ty = t,
dims = dims,
connectorType = ct,
source = source,
variableAttributesOption = dae_var_attr,
absynCommentOption = comment),_)
equation
(kind_1,states) = lowerVarkind(kind, t, name, dir, ct, istates, dae_var_attr);
tp = lowerType(t);
b = DAEUtil.boolVarVisibility(protection);
dae_var_attr = DAEUtil.setProtectedAttr(dae_var_attr,b);
dae_var_attr = setMinMaxFromEnumeration(t,dae_var_attr);
_ = BackendVariable.getMinMaxAsserts(dae_var_attr,name,source,kind_1,tp);
_ = BackendVariable.getNominalAssert(dae_var_attr,name,source,kind_1,tp);
then
(BackendDAE.VAR(name,kind_1,dir,prl,tp,NONE(),NONE(),dims,-1,source,dae_var_attr,comment,ct), states);
end match;
end lowerDynamicVar;
protected function lowerKnownVar
"function: lowerKnownVar
Helper function to lower2"
input DAE.Element inElement;
output BackendDAE.Var outVar;
algorithm
outVar := matchcontinue (inElement)
local
list<DAE.Subscript> dims;
DAE.ComponentRef name;
BackendDAE.VarKind kind_1;
Option<DAE.Exp> bind;
DAE.VarKind kind;
DAE.VarDirection dir;
DAE.VarParallelism prl;
BackendDAE.Type tp;
DAE.ConnectorType ct;
DAE.ElementSource source "origin of equation";
Option<DAE.VariableAttributes> dae_var_attr;
Option<SCode.Comment> comment;
DAE.Type t;
DAE.VarVisibility protection;
Boolean b;
String str;
case (DAE.VAR(componentRef = name,
kind = kind,
direction = dir,
parallelism = prl,
protection = protection,
ty = t,
binding = bind,
dims = dims,
connectorType = ct,
source = source,
variableAttributesOption = dae_var_attr,
absynCommentOption = comment))
equation
kind_1 = lowerKnownVarkind(kind, name, dir, ct);
bind = fixParameterStartBinding(bind,dae_var_attr,kind_1);
tp = lowerType(t);
b = DAEUtil.boolVarVisibility(protection);
dae_var_attr = DAEUtil.setProtectedAttr(dae_var_attr,b);
dae_var_attr = setMinMaxFromEnumeration(t,dae_var_attr);
_ = BackendVariable.getMinMaxAsserts(dae_var_attr,name,source,kind_1,tp);
_ = BackendVariable.getNominalAssert(dae_var_attr,name,source,kind_1,tp);
then
BackendDAE.VAR(name,kind_1,dir,prl,tp,bind,NONE(),dims,-1,source,dae_var_attr,comment,ct);
case (_)
equation
str = "BackendDAECreate.lowerKnownVar failed for " +& DAEDump.dumpElementsStr({inElement});
Error.addMessage(Error.INTERNAL_ERROR, {str});
then fail();
end matchcontinue;
end lowerKnownVar;
protected function setMinMaxFromEnumeration
input DAE.Type inType;
input Option<DAE.VariableAttributes> inVarAttr;
output Option<DAE.VariableAttributes> outVarAttr;
algorithm
outVarAttr := matchcontinue (inType,inVarAttr)
local
Option<DAE.Exp> min,max;
list<String> names;
Absyn.Path path;
case (DAE.T_ENUMERATION(path=path,names = names),_)
equation
(min,max) = DAEUtil.getMinMaxValues(inVarAttr);
then
setMinMaxFromEnumeration1(min,max,inVarAttr,path,names);
else inVarAttr;
end matchcontinue;
end setMinMaxFromEnumeration;
protected function setMinMaxFromEnumeration1
input Option<DAE.Exp> inMin;
input Option<DAE.Exp> inMax;
input Option<DAE.VariableAttributes> inVarAttr;
input Absyn.Path inPath;
input list<String> inNames;
output Option<DAE.VariableAttributes> outVarAttr;
algorithm
outVarAttr := matchcontinue (inMin,inMax,inVarAttr,inPath,inNames)
local
Integer i;
Absyn.Path namee1,nameen;
String s1,sn;
DAE.Exp e;
case (NONE(),NONE(),_,_,_)
equation
i = listLength(inNames);
s1 = listGet(inNames,1);
namee1 = Absyn.joinPaths(inPath,Absyn.IDENT(s1));
sn = listGet(inNames,i);
nameen = Absyn.joinPaths(inPath,Absyn.IDENT(sn));
then
DAEUtil.setMinMax(inVarAttr,(SOME(DAE.ENUM_LITERAL(namee1,1)),SOME(DAE.ENUM_LITERAL(nameen,i))));
case (NONE(),SOME(e),_,_,_)
equation
i = listLength(inNames);
s1 = listGet(inNames,1);
namee1 = Absyn.joinPaths(inPath,Absyn.IDENT(s1));
then
DAEUtil.setMinMax(inVarAttr,(SOME(DAE.ENUM_LITERAL(namee1,1)),SOME(e)));
case (SOME(e),NONE(),_,_,_)
equation
i = listLength(inNames);
sn = listGet(inNames,i);
nameen = Absyn.joinPaths(inPath,Absyn.IDENT(sn));
then
DAEUtil.setMinMax(inVarAttr,(SOME(e),SOME(DAE.ENUM_LITERAL(nameen,i))));
else inVarAttr;
end matchcontinue;
end setMinMaxFromEnumeration1;
protected function fixParameterStartBinding
input Option<DAE.Exp> bind;
input Option<DAE.VariableAttributes> attr;
input BackendDAE.VarKind kind;
output Option<DAE.Exp> outBind;
algorithm
outBind := matchcontinue (bind,attr,kind)
local
DAE.Exp exp;
case (NONE(),_,BackendDAE.PARAM())
equation
exp = DAEUtil.getStartAttr(attr);
then SOME(exp);
else bind;
end matchcontinue;
end fixParameterStartBinding;
protected function lowerVarkind
"function: lowerVarkind
Helper function to lowerVar.
inputs: (DAE.VarKind,
Type,
DAE.ComponentRef,
DAE.VarDirection, /* input/output/bidir */
DAE.ConnectorType,
BackendDAE.BinTree /* states */)
outputs VarKind
NOTE: Fails for not states that are not algebraic
variables, e.g. parameters and constants"
input DAE.VarKind inVarKind;
input DAE.Type inType;
input DAE.ComponentRef inComponentRef;
input DAE.VarDirection inVarDirection;
input DAE.ConnectorType inConnectorType;
input BackendDAE.BinTree inStates;
input Option<DAE.VariableAttributes> daeAttr;
output BackendDAE.VarKind outVarKind;
output BackendDAE.BinTree outBinTree;
algorithm
(outVarKind,outBinTree) := matchcontinue (inVarKind,inType,inComponentRef,inVarDirection,inConnectorType,inStates,daeAttr)
local
BackendDAE.BinTree states;
// States appear differentiated among equations
case (DAE.VARIABLE(),_,_,_,_,_,_)
equation
_ = BackendDAEUtil.treeGet(inStates, inComponentRef);
then
(BackendDAE.STATE(),inStates);
// Or states have StateSelect.always
case (DAE.VARIABLE(),_,_,_,_,_,SOME(DAE.VAR_ATTR_REAL(stateSelectOption = SOME(DAE.ALWAYS()))))
equation
states = BackendDAEUtil.treeAdd(inStates, inComponentRef, 0);
then (BackendDAE.STATE(),states);
// Or states have StateSelect.prefer
case (DAE.VARIABLE(),_,_,_,_,_,SOME(DAE.VAR_ATTR_REAL(stateSelectOption = SOME(DAE.PREFER()))))
equation
states = BackendDAEUtil.treeAdd(inStates, inComponentRef, 0);
then (BackendDAE.STATE(),states);
case (DAE.VARIABLE(),DAE.T_BOOL(varLst = _),_,_,_,_,_)
equation
failure(BackendVariable.topLevelInput(inComponentRef, inVarDirection, inConnectorType));
then
(BackendDAE.DISCRETE(),inStates);
case (DAE.DISCRETE(),DAE.T_BOOL(varLst = _),_,_,_,_,_)
equation
failure(BackendVariable.topLevelInput(inComponentRef, inVarDirection, inConnectorType));
then
(BackendDAE.DISCRETE(),inStates);
case (DAE.VARIABLE(),DAE.T_INTEGER(varLst = _),_,_,_,_,_)
equation
failure(BackendVariable.topLevelInput(inComponentRef, inVarDirection, inConnectorType));
then
(BackendDAE.DISCRETE(),inStates);
case (DAE.DISCRETE(),DAE.T_INTEGER(varLst = _),_,_,_,_,_)
equation
failure(BackendVariable.topLevelInput(inComponentRef, inVarDirection, inConnectorType));
then
(BackendDAE.DISCRETE(),inStates);
case (DAE.VARIABLE(),DAE.T_ENUMERATION(names = _),_,_,_,_,_)
equation
failure(BackendVariable.topLevelInput(inComponentRef, inVarDirection, inConnectorType));
then
(BackendDAE.DISCRETE(),inStates);
case (DAE.DISCRETE(),DAE.T_ENUMERATION(names = _),_,_,_,_,_)
equation
failure(BackendVariable.topLevelInput(inComponentRef, inVarDirection, inConnectorType));
then
(BackendDAE.DISCRETE(),inStates);
case (DAE.VARIABLE(),_,_,_,_,_,_)
equation
failure(BackendVariable.topLevelInput(inComponentRef, inVarDirection, inConnectorType));
then
(BackendDAE.VARIABLE(),inStates);
case (DAE.DISCRETE(),_,_,_,_,_,_)
equation
failure(BackendVariable.topLevelInput(inComponentRef, inVarDirection, inConnectorType));
then
(BackendDAE.DISCRETE(),inStates);
end matchcontinue;
end lowerVarkind;
protected function lowerKnownVarkind
"function: lowerKnownVarkind
Helper function to lowerKnownVar.
NOTE: Fails for everything but parameters and constants and top level inputs"
input DAE.VarKind inVarKind;
input DAE.ComponentRef inComponentRef;
input DAE.VarDirection inVarDirection;
input DAE.ConnectorType inConnectorType;
output BackendDAE.VarKind outVarKind;
algorithm
outVarKind := matchcontinue (inVarKind,inComponentRef,inVarDirection,inConnectorType)
case (DAE.PARAM(),_,_,_) then BackendDAE.PARAM();
case (DAE.CONST(),_,_,_) then BackendDAE.CONST();
case (DAE.VARIABLE(),_,_,_)
equation
BackendVariable.topLevelInput(inComponentRef,inVarDirection,inConnectorType);
then
BackendDAE.VARIABLE();
// adrpo: topLevelInput might fail!
// case (DAE.VARIABLE(),cr,dir,flowPrefix)
// then
// BackendDAE.VARIABLE();
case (_,_,_,_)
equation
print("lowerKnownVarkind failed\n");
then
fail();
end matchcontinue;
end lowerKnownVarkind;
protected function lowerType
"Transforms a DAE.Type to Type"
input DAE.Type inType;
output BackendDAE.Type outType;
algorithm
outType := matchcontinue(inType)
local
case (DAE.T_REAL(varLst = _)) then DAE.T_REAL_DEFAULT;
case (DAE.T_INTEGER(varLst = _)) then DAE.T_INTEGER_DEFAULT;
case (DAE.T_BOOL(varLst = _)) then DAE.T_BOOL_DEFAULT;
case (DAE.T_STRING(varLst = _)) then DAE.T_STRING_DEFAULT;
case (DAE.T_ENUMERATION(names = _)) then inType;
case (DAE.T_COMPLEX(complexClassType = ClassInf.EXTERNAL_OBJ(path=_)))
then inType;
else equation print("lowerType failed\n"); then fail();
end matchcontinue;
end lowerType;
protected function lowerExtObjVar
" Helper function to lower2
Fails for all variables except external object instances."
input DAE.Element inElement;
output BackendDAE.Var outVar;
algorithm
outVar:=
match (inElement)
local
list<DAE.Subscript> dims;
DAE.ComponentRef name;
BackendDAE.VarKind kind_1;
Option<DAE.Exp> bind;
DAE.VarKind kind;
DAE.VarDirection dir;
DAE.VarParallelism prl;
BackendDAE.Type tp;
DAE.ConnectorType ct;
DAE.ElementSource source;
Option<DAE.VariableAttributes> dae_var_attr;
Option<SCode.Comment> comment;
DAE.Type t;
case (DAE.VAR(componentRef = name,
kind = kind,
direction = dir,
parallelism = prl,
ty = t,
binding = bind,
dims = dims,
connectorType = ct,
source = source,
variableAttributesOption = dae_var_attr,
absynCommentOption = comment))
equation
kind_1 = lowerExtObjVarkind(t);
tp = lowerType(t);
then
BackendDAE.VAR(name,kind_1,dir,prl,tp,bind,NONE(),dims,-1,source,dae_var_attr,comment,ct);
end match;
end lowerExtObjVar;
protected function lowerExtObjVarkind
" Helper function to lowerExtObjVar.
NOTE: Fails for everything but External objects"
input DAE.Type inType;
output BackendDAE.VarKind outVarKind;
algorithm
outVarKind :=
match (inType)
local Absyn.Path path;
case DAE.T_COMPLEX(complexClassType = ClassInf.EXTERNAL_OBJ(path=path)) then BackendDAE.EXTOBJ(path);
end match;
end lowerExtObjVarkind;
/*
* lower all equation types
*/
protected function lowerEqn
"function: lowerEqn
Helper function to lower2.
Transforms a DAE.Element to Equation."
input DAE.Element inElement;
input DAE.FunctionTree functionTree;
input list<BackendDAE.Equation> inEqns;
output list<BackendDAE.Equation> outEqns;
algorithm
outEqns := match (inElement,functionTree,inEqns)
local
DAE.Exp e1,e2,cond,msg;
DAE.ComponentRef cr1,cr2;
DAE.ElementSource source;
Boolean b1;
Integer size;
DAE.Dimensions dims;
list<DAE.Exp> explst,explst1;
list<list<DAE.Element>> eqnslstlst;
list<DAE.Element> eqnslst;
list<Boolean> blst;
String s;
DAE.Algorithm alg;
// tuple-tuple assignments are split into one equation for each tuple
// element, i.e. (i1, i2) = (4, 6) => i1 = 4; i2 = 6;
case (DAE.EQUATION(DAE.TUPLE(explst), DAE.TUPLE(explst1), source = source),_,_)
then
lowerTupleAssignment(explst,explst1,source,functionTree,inEqns);
case (DAE.EQUATION(exp = e1,scalar = e2,source = source),_,_)
equation
(e1,source) = Inline.inlineExp(e1, (SOME(functionTree),{DAE.NORM_INLINE()}), source);
(e2,source) = Inline.inlineExp(e2, (SOME(functionTree),{DAE.NORM_INLINE()}), source);
then
BackendDAE.EQUATION(e1,e2,source)::inEqns;
case (DAE.INITIALEQUATION(exp1 = e1,exp2 = e2,source = source),_,_)
equation
(e1,source) = Inline.inlineExp(e1, (SOME(functionTree),{DAE.NORM_INLINE()}), source);
(e2,source) = Inline.inlineExp(e2, (SOME(functionTree),{DAE.NORM_INLINE()}), source);
then
BackendDAE.EQUATION(e1,e2,source)::inEqns;
case (DAE.EQUEQUATION(cr1 = cr1, cr2 = cr2,source = source),_,_)
equation
e1 = Expression.crefExp(cr1);
e2 = Expression.crefExp(cr2);
then
BackendDAE.EQUATION(e1,e2,source)::inEqns;
case (DAE.DEFINE(componentRef = cr1, exp = e2, source = source),_,_)
equation
(e2,source) = Inline.inlineExp(e2, (SOME(functionTree),{DAE.NORM_INLINE()}), source);
e1 = Expression.crefExp(cr1);
then
BackendDAE.EQUATION(e1,e2,source)::inEqns;
case (DAE.INITIALDEFINE(componentRef = cr1, exp = e2, source = source),_,_)
equation
e1 = Expression.crefExp(cr1);
(e2,source) = Inline.inlineExp(e2, (SOME(functionTree),{DAE.NORM_INLINE()}), source);
then
BackendDAE.EQUATION(e1,e2,source)::inEqns;
case (DAE.COMPLEX_EQUATION(lhs = e1,rhs = e2,source = source),_,_)
equation
//(e1,source) = Inline.inlineExp(e1, (SOME(functionTree),{DAE.NORM_INLINE()}), source);
//(e2,source) = Inline.inlineExp(e2, (SOME(functionTree),{DAE.NORM_INLINE()}), source);
(e1,source,_) = Inline.forceInlineExp(e1,(SOME(functionTree),{DAE.NORM_INLINE(),DAE.NO_INLINE()}),source);
(e2,source,_) = Inline.forceInlineExp(e2,(SOME(functionTree),{DAE.NORM_INLINE(),DAE.NO_INLINE()}),source);
then
lowerextendedRecordEqn(e1,e2,source,functionTree,inEqns);
case (DAE.INITIAL_COMPLEX_EQUATION(lhs = e1,rhs = e2,source = source),_,_)
equation
(e1,source) = Inline.inlineExp(e1, (SOME(functionTree),{DAE.NORM_INLINE()}), source);
(e2,source) = Inline.inlineExp(e2, (SOME(functionTree),{DAE.NORM_INLINE()}), source);
size = Expression.sizeOf(Expression.typeof(e1));
then
BackendDAE.COMPLEX_EQUATION(size,e1,e2,source)::inEqns;
case (DAE.ARRAY_EQUATION(dimension=dims,exp = e1,array = e2,source = source),_,_)
equation
(e1,source) = Inline.inlineExp(e1, (SOME(functionTree),{DAE.NORM_INLINE()}), source);
(e2,source) = Inline.inlineExp(e2, (SOME(functionTree),{DAE.NORM_INLINE()}), source);
then
lowerArrayEqn(dims,e1,e2,source,inEqns);
case (DAE.INITIAL_ARRAY_EQUATION(dimension=dims,exp = e1,array = e2,source = source),_,_)
equation
(e1,source) = Inline.inlineExp(e1, (SOME(functionTree),{DAE.NORM_INLINE()}), source);
(e2,source) = Inline.inlineExp(e2, (SOME(functionTree),{DAE.NORM_INLINE()}), source);