-
Notifications
You must be signed in to change notification settings - Fork 298
/
InteractiveUtil.mo
16659 lines (15449 loc) · 583 KB
/
InteractiveUtil.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-2014, Open Source Modelica Consortium (OSMC),
* c/o Linköpings universitet, 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 LICENSE OR
* THIS OSMC PUBLIC LICENSE (OSMC-PL) VERSION 1.2.
* ANY USE, REPRODUCTION OR DISTRIBUTION OF THIS PROGRAM CONSTITUTES
* RECIPIENT'S ACCEPTANCE OF THE OSMC PUBLIC LICENSE OR THE GPL VERSION 3,
* ACCORDING TO RECIPIENTS CHOICE.
*
* The OpenModelica software and the Open Source Modelica
* Consortium (OSMC) Public License (OSMC-PL) are obtained
* from OSMC, 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 InteractiveUtil
" file: InteractiveUtil.mo
package: InteractiveUtil
description: This module contain functionality for model management,
expression evaluation, etc. in the interactive environment.
$Id: InteractiveUtil.mo 25580 2015-04-16 14:04:16Z jansilar $
This module contains utility functions for Interactive.mo"
//public imports
import Absyn;
import AbsynToSCode;
import AbsynUtil;
import ConnectionGraph;
import DAE;
import FCore;
import Global;
import Interactive;
import SCode;
import Values;
// protected imports
protected
import Ceval;
import ClassInf;
import Config;
import DAE.Connect;
import Constants;
import DAEUtil;
import Debug;
import DoubleEnded;
import Dump;
import Error;
import ErrorExt;
import ExpressionDump;
import ExpressionSimplify;
import FBuiltin;
import FGraph;
import Flags;
import FlagsUtil;
import GlobalScriptDump;
import InnerOuter;
import Inst;
import InstTypes;
import InstUtil;
import List;
import Lookup;
import MetaUtil;
import Mod;
import NFApi;
import Parser;
import Print;
import SCodeUtil;
import Static;
import StaticScript;
import StringUtil;
import SymbolTable;
import System;
import Testsuite;
import Types;
import UnitAbsyn;
import Util;
import MetaModelica.Dangerous;
public
type GraphicEnvCache = Interactive.GraphicEnvCache;
type AnnotationType = Interactive.AnnotationType;
public function getTypeOfVariable
"Return the type of an interactive variable,
given a list of variables and a variable identifier."
input Absyn.Ident inIdent;
input list<GlobalScript.Variable> inVariableLst;
output DAE.Type outType;
protected
String id;
DAE.Type tp;
algorithm
for var in inVariableLst loop
GlobalScript.IVAR(varIdent = id,type_ = tp) := var;
if stringEq(inIdent, id) then
outType := tp;
return;
end if;
end for;
// did not find a type
fail();
end getTypeOfVariable;
protected function getApiFunctionNameInfo
"Returns the name of the called API function."
input GlobalScript.Statement inStmt;
output String outName;
output SourceInfo outInfo;
algorithm
GlobalScript.IEXP(
exp = Absyn.CALL(function_ = Absyn.CREF_IDENT(name = outName)),
info = outInfo
) := inStmt;
end getApiFunctionNameInfo;
protected function getApiFunctionArgs
"Returns a list of arguments to the function in the interactive statement list."
input GlobalScript.Statement inStmt;
output list<Absyn.Exp> outArgs;
algorithm
outArgs := match(inStmt)
local
list<Absyn.Exp> args;
case GlobalScript.IEXP(exp = Absyn.CALL(functionArgs =
Absyn.FUNCTIONARGS(args = args))) then args;
else {};
end match;
end getApiFunctionArgs;
protected function getApiFunctionNamedArgs
"Returns a list of named arguments to the function in the interactive statement list."
input GlobalScript.Statement inStmt;
output list<Absyn.NamedArg> outArgs;
algorithm
GlobalScript.IEXP(exp = Absyn.CALL(functionArgs = Absyn.FUNCTIONARGS(argNames = outArgs))) := inStmt;
end getApiFunctionNamedArgs;
protected function listClass
"Unparse a class definition and return it in a String"
input Absyn.ComponentRef cr "Class name as a ComponentRef";
input Absyn.Program p "AST - Program";
output String classStr "Class defintition";
protected
Absyn.Path path;
Absyn.Class cl;
algorithm
path := AbsynUtil.crefToPath(cr);
cl := getPathedClassInProgram(path, p);
classStr := Dump.unparseStr(Absyn.PROGRAM({cl},Absyn.TOP()),false);
end listClass;
protected function extractAllComponentreplacements
"author: x02lucpo
extracts all the componentreplacementrules from program.
This is done by extracting all the components and then
extracting the rules"
input Absyn.Program p;
input Absyn.ComponentRef class_;
input Absyn.ComponentRef cref1;
input Absyn.ComponentRef cref2;
output GlobalScript.ComponentReplacementRules comp_reps;
algorithm
comp_reps := matchcontinue(p,class_,cref1,cref2)
local
GlobalScript.Components comps;
Absyn.Path class_path;
GlobalScript.ComponentReplacementRules comp_repsrules;
case(_,_,_,_)
equation
ErrorExt.setCheckpoint("InteractiveUtil.extractAllComponentreplacements");
comps = extractAllComponents(p, AbsynUtil.crefToPath(class_)) "class in package" ;
// rollback errors if we succeed
ErrorExt.rollBack("InteractiveUtil.extractAllComponentreplacements");
false = isClassReadOnly(getPathedClassInProgram(AbsynUtil.crefToPath(class_),p));
class_path = AbsynUtil.crefToPath(class_);
comp_repsrules = GlobalScript.COMPONENTREPLACEMENTRULES({GlobalScript.COMPONENTREPLACEMENT(class_path,cref1,cref2)},1);
comp_reps = getComponentreplacementsrules(comps, comp_repsrules, 0);
then comp_reps;
else
equation
// keep errors if we fail!
ErrorExt.delCheckpoint("InteractiveUtil.extractAllComponentreplacements");
then
fail();
end matchcontinue;
end extractAllComponentreplacements;
protected function isClassReadOnly
"Returns the readonly attribute of a class."
input Absyn.Class cl;
output Boolean readOnly;
algorithm
readOnly := match(cl)
case(Absyn.CLASS(info = SOURCEINFO(isReadOnly=readOnly))) then readOnly;
end match;
end isClassReadOnly;
protected function renameComponent
"author: x02lucpo
This function renames a component in a class
inputs: (Absyn.Program,
Absyn.ComponentRef, /* old class as qualified name */
Absyn.ComponentRef) /* new class, as identifier */
outputs: Absyn.Program"
input Absyn.Program inProgram1;
input Absyn.ComponentRef inComponentRef2;
input Absyn.ComponentRef inComponentRef3;
input Absyn.ComponentRef inComponentRef4;
output String outString;
output Absyn.Program outProgram;
algorithm
(outString,outProgram) := matchcontinue (inProgram1,inComponentRef2,inComponentRef3,inComponentRef4)
local
Absyn.Path class_path;
GlobalScript.ComponentReplacementRules comp_reps;
Absyn.Program p_1,p;
list<String> paths;
String paths_1,paths_2;
Absyn.ComponentRef class_,old_comp,new_comp;
Absyn.Path model_path;
String str;
case (p,class_,_,_)
equation
model_path = AbsynUtil.crefToPath(class_);
true = isClassReadOnly(getPathedClassInProgram(model_path,p));
str = AbsynUtil.pathString(model_path);
str = "Error: class: " + str + " is in a read only file!";
then
(str, p);
case (p,class_,old_comp,new_comp)
equation
comp_reps = extractAllComponentreplacements(p, class_, old_comp, new_comp);
p_1 = renameComponentFromComponentreplacements(p, comp_reps);
paths = extractRenamedClassesAsStringList(comp_reps);
paths_1 = stringDelimitList(paths, ",");
paths_2 = stringAppendList({"{",paths_1,"}"});
then
(paths_2,p_1);
else
equation
if Flags.isSet(Flags.FAILTRACE) then
Debug.trace("rename_component failed\n");
end if;
then
("Error",inProgram1);
end matchcontinue;
end renameComponent;
protected function renameComponentOnlyInClass
"@author: adrpo
This function renames a component ONLY in the given class"
input Absyn.Program inProgram1;
input Absyn.ComponentRef inComponentRef2;
input Absyn.ComponentRef inComponentRef3;
input Absyn.ComponentRef inComponentRef4;
output String outString;
output Absyn.Program outProgram;
algorithm
(outString,outProgram) := matchcontinue (inProgram1,inComponentRef2,inComponentRef3,inComponentRef4)
local
Absyn.Program p;
String paths_2;
Absyn.ComponentRef class_,old_comp,new_comp;
Absyn.Class cl;
Absyn.Path model_path;
String str;
Absyn.Within w;
case (p,class_,_,_)
equation
model_path = AbsynUtil.crefToPath(class_);
true = isClassReadOnly(getPathedClassInProgram(model_path,p));
str = AbsynUtil.pathString(model_path);
str = "Error: class: " + str + " is in a read only file!";
then
(str, p);
case (p,class_,old_comp,new_comp)
equation
model_path = AbsynUtil.crefToPath(class_) "class in package" ;
cl = getPathedClassInProgram(model_path, p);
cl = renameComponentInClass(cl, old_comp, new_comp);
w = buildWithin(AbsynUtil.makeFullyQualified(model_path));
p = updateProgram(Absyn.PROGRAM({cl}, w), p);
str = AbsynUtil.pathString(model_path);
paths_2 = stringAppendList({"{",str,"}"});
then
(paths_2,p);
else
equation
if Flags.isSet(Flags.FAILTRACE) then
Debug.trace("renameComponentOnlyInClass failed\n");
end if;
then
("Error",inProgram1);
end matchcontinue;
end renameComponentOnlyInClass;
protected function extractRenamedClassesAsStringList
"author: x02lucpo
this iterates through the Componentreplacementrules and
returns the string list with all the changed classes"
input GlobalScript.ComponentReplacementRules inComponentReplacementRules;
output list<String> outStringLst;
algorithm
outStringLst:=
matchcontinue (inComponentReplacementRules)
local
GlobalScript.ComponentReplacementRules comp_reps,res;
Absyn.Path path;
String path_str;
list<String> res_1,res_2;
case (comp_reps)
equation
true = emptyComponentReplacementRules(comp_reps);
then
{};
case (comp_reps)
equation
GlobalScript.COMPONENTREPLACEMENT(path,_,_) = firstComponentReplacement(comp_reps);
path_str = AbsynUtil.pathString(path);
res = restComponentReplacementRules(comp_reps);
res_1 = extractRenamedClassesAsStringList(res);
res_2 = List.union({path_str}, res_1);
then
res_2;
else
equation
print("-extract_renamed_classes_as_string_list failed\n");
then
fail();
end matchcontinue;
end extractRenamedClassesAsStringList;
protected function renameComponentFromComponentreplacements
"author: x02lucpo
this iterates through the Componentreplacementrules and
renames the componentes by traversing all the classes"
input Absyn.Program inProgram;
input GlobalScript.ComponentReplacementRules inComponentReplacementRules;
output Absyn.Program outProgram;
algorithm
outProgram:=
matchcontinue (inProgram,inComponentReplacementRules)
local
Absyn.Program p,p_1,p_2;
GlobalScript.ComponentReplacementRules comp_reps,res;
GlobalScript.ComponentReplacement comp_rep;
case (p,comp_reps)
equation
true = emptyComponentReplacementRules(comp_reps);
then
p;
case (p,comp_reps)
equation
comp_rep = firstComponentReplacement(comp_reps);
((p_1,_,_)) = AbsynUtil.traverseClasses(p,NONE(), renameComponentVisitor, comp_rep, true) "traverse protected" ;
res = restComponentReplacementRules(comp_reps);
p_2 = renameComponentFromComponentreplacements(p_1, res);
then
p_2;
else
equation
print("-rename_component_from_componentreplacements failed\n");
then
fail();
end matchcontinue;
end renameComponentFromComponentreplacements;
protected function renameComponentVisitor
"author: x02lucpo
this is a visitor for traverse class in rename components"
input tuple<Absyn.Class, Option<Absyn.Path>, GlobalScript.ComponentReplacement> inTplAbsynClassAbsynPathOptionComponentReplacement;
output tuple<Absyn.Class, Option<Absyn.Path>, GlobalScript.ComponentReplacement> outTplAbsynClassAbsynPathOptionComponentReplacement;
algorithm
outTplAbsynClassAbsynPathOptionComponentReplacement:=
matchcontinue (inTplAbsynClassAbsynPathOptionComponentReplacement)
local
Absyn.Path path_1,pa,class_id;
Absyn.Class class_1,class_;
String id;
Boolean a,b,c;
Absyn.Restriction d;
Absyn.ClassDef e;
SourceInfo file_info;
Absyn.ComponentRef old_comp,new_comp;
GlobalScript.ComponentReplacement args;
Option<Absyn.Path> opath;
case (((class_ as Absyn.CLASS(name = id)),SOME(pa),GlobalScript.COMPONENTREPLACEMENT(which1 = class_id,the2 = old_comp,the3 = new_comp)))
equation
path_1 = AbsynUtil.joinPaths(pa, Absyn.IDENT(id));
true = AbsynUtil.pathEqual(class_id, path_1);
class_1 = renameComponentInClass(class_, old_comp, new_comp);
then
((class_1,SOME(pa),
GlobalScript.COMPONENTREPLACEMENT(class_id,old_comp,new_comp)));
case (((class_ as Absyn.CLASS(name = id)),NONE(),GlobalScript.COMPONENTREPLACEMENT(which1 = class_id,the2 = old_comp,the3 = new_comp)))
equation
path_1 = Absyn.IDENT(id);
true = AbsynUtil.pathEqual(class_id, path_1);
class_1 = renameComponentInClass(class_, old_comp, new_comp);
then
((class_1,NONE(),
GlobalScript.COMPONENTREPLACEMENT(class_id,old_comp,new_comp)));
case ((class_,opath,args)) then ((class_,opath,args));
end matchcontinue;
end renameComponentVisitor;
protected function renameComponentInClass
"author: x02lucpo
helper function to renameComponentVisitor"
input Absyn.Class inClass1;
input Absyn.ComponentRef inComponentRef2;
input Absyn.ComponentRef inComponentRef3;
output Absyn.Class outClass;
algorithm
outClass:=
matchcontinue (inClass1,inComponentRef2,inComponentRef3)
local
list<Absyn.ClassPart> parts_1,parts;
String name,baseClassName;
Boolean partialPrefix,finalPrefix,encapsulatedPrefix;
Absyn.Restriction restriction;
Option<String> a,c;
SourceInfo file_info;
Absyn.ComponentRef old_comp,new_comp;
list<Absyn.ElementArg> b;
Absyn.Class class_;
list<String> typeVars;
list<Absyn.NamedArg> classAttrs;
list<Absyn.Annotation> ann;
/* the class with the component the old name for the component */
case (Absyn.CLASS(name = name,partialPrefix = partialPrefix,finalPrefix = finalPrefix,encapsulatedPrefix = encapsulatedPrefix,restriction = restriction,
body = Absyn.PARTS(typeVars = typeVars,classAttrs = classAttrs,classParts = parts,ann=ann,comment = a),info = file_info),old_comp,new_comp)
equation
parts_1 = renameComponentInParts(parts, old_comp, new_comp);
then
Absyn.CLASS(name,partialPrefix,finalPrefix,encapsulatedPrefix,restriction,Absyn.PARTS(typeVars,classAttrs,parts_1,ann,a),file_info);
/* the class with the component the old name for the component for model extends X end X; */
case (Absyn.CLASS(name = name,partialPrefix = partialPrefix,finalPrefix = finalPrefix,encapsulatedPrefix = encapsulatedPrefix,restriction = restriction,
body = Absyn.CLASS_EXTENDS(baseClassName = baseClassName,modifications = b,comment = c,parts = parts,ann=ann),
info = file_info),old_comp,new_comp)
equation
parts_1 = renameComponentInParts(parts, old_comp, new_comp);
then
Absyn.CLASS(name,partialPrefix,finalPrefix,encapsulatedPrefix,restriction, Absyn.CLASS_EXTENDS(baseClassName,b,c,parts_1,ann),file_info);
else inClass1;
end matchcontinue;
end renameComponentInClass;
protected function renameComponentInParts
"author: x02lucpo
helper function to renameComponentVisitor"
input list<Absyn.ClassPart> inAbsynClassPartLst1;
input Absyn.ComponentRef inComponentRef2;
input Absyn.ComponentRef inComponentRef3;
output list<Absyn.ClassPart> outAbsynClassPartLst;
algorithm
outAbsynClassPartLst:=
matchcontinue (inAbsynClassPartLst1,inComponentRef2,inComponentRef3)
local
list<Absyn.ClassPart> res_1,res;
list<Absyn.ElementItem> elements_1,elements;
Absyn.ComponentRef old_comp,new_comp;
list<Absyn.EquationItem> equations_1,equations;
list<Absyn.AlgorithmItem> algorithms_1,algorithms;
Absyn.ExternalDecl external_decl_1,external_decl;
Option<Absyn.Annotation> ano;
Absyn.ClassPart a;
case ({},_,_) then {}; /* the old name for the component */
case ((Absyn.PUBLIC(contents = elements) :: res),old_comp,new_comp)
equation
res_1 = renameComponentInParts(res, old_comp, new_comp);
elements_1 = renameComponentInElements(elements, old_comp, new_comp);
then
(Absyn.PUBLIC(elements_1) :: res_1);
case ((Absyn.PROTECTED(contents = elements) :: res),old_comp,new_comp)
equation
res_1 = renameComponentInParts(res, old_comp, new_comp);
elements_1 = renameComponentInElements(elements, old_comp, new_comp);
then
(Absyn.PROTECTED(elements_1) :: res_1);
case ((Absyn.EQUATIONS(contents = equations) :: res),old_comp,new_comp)
equation
res_1 = renameComponentInParts(res, old_comp, new_comp);
equations_1 = renameComponentInEquationList(equations, old_comp, new_comp);
then
(Absyn.EQUATIONS(equations_1) :: res_1);
case ((Absyn.INITIALEQUATIONS(contents = equations) :: res),old_comp,new_comp)
equation
res_1 = renameComponentInParts(res, old_comp, new_comp);
equations_1 = renameComponentInEquationList(equations, old_comp, new_comp);
then
(Absyn.INITIALEQUATIONS(equations_1) :: res_1);
case ((Absyn.ALGORITHMS(contents = algorithms) :: res),old_comp,new_comp)
equation
res_1 = renameComponentInParts(res, old_comp, new_comp);
algorithms_1 = renameComponentInAlgorithms(algorithms, old_comp, new_comp);
then
(Absyn.ALGORITHMS(algorithms_1) :: res_1);
case ((Absyn.INITIALALGORITHMS(contents = algorithms) :: res),old_comp,new_comp)
equation
res_1 = renameComponentInParts(res, old_comp, new_comp);
algorithms_1 = renameComponentInAlgorithms(algorithms, old_comp, new_comp);
then
(Absyn.INITIALALGORITHMS(algorithms_1) :: res_1);
case ((Absyn.EXTERNAL(externalDecl = external_decl,annotation_ = ano) :: res),old_comp,new_comp)
equation
res_1 = renameComponentInParts(res, old_comp, new_comp);
external_decl_1 = renameComponentInExternalDecl(external_decl, old_comp, new_comp);
then
(Absyn.EXTERNAL(external_decl_1,ano) :: res_1);
case ((a :: res),old_comp,new_comp)
equation
res_1 = renameComponentInParts(res, old_comp, new_comp);
then
(a :: res_1);
end matchcontinue;
end renameComponentInParts;
protected function renameComponentInElements
"author: x02lucpo
helper function to renameComponentVisitor"
input list<Absyn.ElementItem> inAbsynElementItemLst1;
input Absyn.ComponentRef inComponentRef2;
input Absyn.ComponentRef inComponentRef3;
output list<Absyn.ElementItem> outAbsynElementItemLst;
algorithm
outAbsynElementItemLst := matchcontinue (inAbsynElementItemLst1,inComponentRef2,inComponentRef3)
local
list<Absyn.ElementItem> res_1,res;
Absyn.ElementSpec elementspec_1,elementspec;
Absyn.ElementItem element_1,element;
Boolean finalPrefix;
Option<Absyn.RedeclareKeywords> redeclare_;
Absyn.InnerOuter inner_outer;
SourceInfo info;
Option<Absyn.ConstrainClass> constrainClass;
Absyn.ComponentRef old_comp,new_comp;
case ({},_,_) then {}; /* the old name for the component */
case ((Absyn.ELEMENTITEM(element =
Absyn.ELEMENT(finalPrefix = finalPrefix,redeclareKeywords = redeclare_,innerOuter = inner_outer,
specification = elementspec,info = info,constrainClass = constrainClass)) :: res),old_comp,new_comp)
equation
res_1 = renameComponentInElements(res, old_comp, new_comp);
elementspec_1 = renameComponentInElementSpec(elementspec, old_comp, new_comp);
element_1 = Absyn.ELEMENTITEM(
Absyn.ELEMENT(finalPrefix,redeclare_,inner_outer,elementspec_1,info,
constrainClass));
then
(element_1 :: res_1);
case ((element :: res),old_comp,new_comp)
equation
res_1 = renameComponentInElements(res, old_comp, new_comp);
element_1 = element;
then
(element_1 :: res_1);
end matchcontinue;
end renameComponentInElements;
protected function renameComponentInElementSpec
"author: x02lucpo
helper function to renameComponentVisitor"
input Absyn.ElementSpec inElementSpec1;
input Absyn.ComponentRef inComponentRef2;
input Absyn.ComponentRef inComponentRef3;
output Absyn.ElementSpec outElementSpec;
algorithm
outElementSpec := matchcontinue (inElementSpec1,inComponentRef2,inComponentRef3)
local
list<Absyn.ComponentItem> comps_1,comps;
Absyn.ElementAttributes attr;
Absyn.TypeSpec path;
Absyn.ComponentRef old_comp,new_comp;
Absyn.ElementSpec elementspec;
case (Absyn.COMPONENTS(attributes = attr,typeSpec = path,components = comps),old_comp,new_comp) /* the old name for the component */
equation
comps_1 = renameComponentInComponentitems(comps, old_comp, new_comp);
then
Absyn.COMPONENTS(attr,path,comps_1);
else inElementSpec1;
end matchcontinue;
end renameComponentInElementSpec;
protected function renameComponentInComponentitems
"author: x02lucpo
helper function to renameComponentVisitor"
input list<Absyn.ComponentItem> inAbsynComponentItemLst1;
input Absyn.ComponentRef inComponentRef2;
input Absyn.ComponentRef inComponentRef3;
output list<Absyn.ComponentItem> outAbsynComponentItemLst;
algorithm
outAbsynComponentItemLst := matchcontinue (inAbsynComponentItemLst1,inComponentRef2,inComponentRef3)
local
Absyn.Path old_comp_path,new_comp_path;
String old_comp_string,new_comp_string,name;
list<Absyn.ComponentItem> res_1,res;
Absyn.ComponentItem comp_1,comp;
list<Absyn.Subscript> arrayDim;
Option<Absyn.Modification> mod;
Option<Absyn.Exp> cond;
Option<Absyn.Comment> comment;
Absyn.ComponentRef old_comp,new_comp;
case ({},_,_) then {}; /* the old name for the component */
case (((Absyn.COMPONENTITEM(component =
Absyn.COMPONENT(name = name,arrayDim = arrayDim,modification = mod),condition = cond,comment = comment)) :: res),old_comp,new_comp)
equation
old_comp_path = AbsynUtil.crefToPath(old_comp);
old_comp_string = AbsynUtil.pathString(old_comp_path);
true = stringEq(name, old_comp_string);
new_comp_path = AbsynUtil.crefToPath(new_comp);
new_comp_string = AbsynUtil.pathString(new_comp_path);
res_1 = renameComponentInComponentitems(res, old_comp, new_comp);
comp_1 = Absyn.COMPONENTITEM(Absyn.COMPONENT(new_comp_string,arrayDim,mod),cond,comment);
then
(comp_1 :: res_1);
case (((comp as Absyn.COMPONENTITEM(component =
Absyn.COMPONENT())) :: res),old_comp,new_comp)
equation
res_1 = renameComponentInComponentitems(res, old_comp, new_comp);
then
(comp :: res_1);
else
equation
print("-InteractiveUtil.renameComponentInComponentitems failed\n");
then
fail();
end matchcontinue;
end renameComponentInComponentitems;
protected function renameComponentInEquationList
"author: x02lucpo
helper function to renameComponentVisitor"
input list<Absyn.EquationItem> inAbsynEquationItemLst1;
input Absyn.ComponentRef inComponentRef2;
input Absyn.ComponentRef inComponentRef3;
output list<Absyn.EquationItem> outAbsynEquationItemLst;
algorithm
outAbsynEquationItemLst := matchcontinue (inAbsynEquationItemLst1,inComponentRef2,inComponentRef3)
local
list<Absyn.EquationItem> res_1,res;
Absyn.Equation equation_1,equation_;
Option<Absyn.Comment> cmt;
SourceInfo info;
Absyn.ComponentRef old_comp,new_comp;
Absyn.EquationItem equation_item;
case ({},_,_) then {}; /* the old name for the component */
case ((Absyn.EQUATIONITEM(equation_ = equation_,comment = cmt,info=info) :: res),old_comp,new_comp)
equation
res_1 = renameComponentInEquationList(res, old_comp, new_comp);
equation_1 = renameComponentInEquation(equation_, old_comp, new_comp);
then
(Absyn.EQUATIONITEM(equation_1,cmt,info) :: res_1);
case ((equation_item :: res),old_comp,new_comp)
equation
res_1 = renameComponentInEquationList(res, old_comp, new_comp);
then
(equation_item :: res_1);
end matchcontinue;
end renameComponentInEquationList;
protected function renameComponentInExpEquationitemList
"author: x02lucpo
helper function to renameComponentVisitor"
input list<tuple<Absyn.Exp, list<Absyn.EquationItem>>> inTplAbsynExpAbsynEquationItemLstLst1;
input Absyn.ComponentRef inComponentRef2;
input Absyn.ComponentRef inComponentRef3;
output list<tuple<Absyn.Exp, list<Absyn.EquationItem>>> outTplAbsynExpAbsynEquationItemLstLst;
algorithm
outTplAbsynExpAbsynEquationItemLstLst := matchcontinue (inTplAbsynExpAbsynEquationItemLstLst1,inComponentRef2,inComponentRef3)
local
Absyn.Exp exp1_1,exp1;
list<Absyn.EquationItem> eqn_item_1,eqn_item;
list<tuple<Absyn.Exp, list<Absyn.EquationItem>>> res_1,res;
Absyn.ComponentRef old_comp,new_comp;
case ({},_,_) then {};
case (((exp1,eqn_item) :: res),old_comp,new_comp)
equation
exp1_1 = renameComponentInExp(exp1, old_comp, new_comp);
eqn_item_1 = renameComponentInEquationList(eqn_item, old_comp, new_comp);
res_1 = renameComponentInExpEquationitemList(res, old_comp, new_comp);
then
((exp1_1,eqn_item_1) :: res_1);
else
equation
print("-rename_component_in_exp_equationitem_list failed\n");
then
fail();
end matchcontinue;
end renameComponentInExpEquationitemList;
protected function renameComponentInEquation
"author: x02lucpo
helper function to renameComponentVisitor"
input Absyn.Equation inEquation1;
input Absyn.ComponentRef inComponentRef2;
input Absyn.ComponentRef inComponentRef3;
output Absyn.Equation outEquation;
algorithm
outEquation := matchcontinue (inEquation1,inComponentRef2,inComponentRef3)
local
Absyn.Exp exp_1,exp,exp1_1,exp2_1,exp1,exp2;
list<Absyn.EquationItem> true_items_1,elses_1,true_items,elses,equations_1,equations;
list<tuple<Absyn.Exp, list<Absyn.EquationItem>>> exp_elseifs_1,exp_elseifs,exp_equations_1,exp_equations;
Absyn.ComponentRef old_comp,new_comp,cref1_1,cref2_1,cref1,cref2,cref;
String ident;
Absyn.FunctionArgs function_args;
/* the old name for the component */
case (Absyn.EQ_IF(ifExp = exp,equationTrueItems = true_items,elseIfBranches = exp_elseifs,equationElseItems = elses),old_comp,new_comp)
equation
exp_1 = renameComponentInExp(exp, old_comp, new_comp);
true_items_1 = renameComponentInEquationList(true_items, old_comp, new_comp);
exp_elseifs_1 = renameComponentInExpEquationitemList(exp_elseifs, old_comp, new_comp);
elses_1 = renameComponentInEquationList(elses, old_comp, new_comp);
then
Absyn.EQ_IF(exp_1,true_items_1,exp_elseifs_1,elses_1);
case (Absyn.EQ_EQUALS(leftSide = exp1,rightSide = exp2),old_comp,new_comp)
equation
exp1_1 = renameComponentInExp(exp1, old_comp, new_comp);
exp2_1 = renameComponentInExp(exp2, old_comp, new_comp);
then
Absyn.EQ_EQUALS(exp1_1,exp2_1);
case (Absyn.EQ_PDE(leftSide = exp1,rightSide = exp2,domain = cref1),old_comp,new_comp)
equation
exp1_1 = renameComponentInExp(exp1, old_comp, new_comp);
exp2_1 = renameComponentInExp(exp2, old_comp, new_comp);
cref1_1 = replaceStartInComponentRef(cref1, old_comp, new_comp);
then
Absyn.EQ_PDE(exp1_1,exp2_1,cref1_1);
case (Absyn.EQ_CONNECT(connector1 = cref1,connector2 = cref2),old_comp,new_comp)
equation
cref1_1 = replaceStartInComponentRef(cref1, old_comp, new_comp);
cref2_1 = replaceStartInComponentRef(cref2, old_comp, new_comp) "print \"-rename_component_in_equation EQ_CONNECT not implemented yet\\n\"" ;
then
Absyn.EQ_CONNECT(cref1_1,cref2_1);
case (Absyn.EQ_FOR(iterators = {Absyn.ITERATOR(ident,NONE(),SOME(exp))},forEquations = equations),old_comp,new_comp)
equation
exp_1 = renameComponentInExp(exp, old_comp, new_comp);
equations_1 = renameComponentInEquationList(equations, old_comp, new_comp);
then
Absyn.EQ_FOR({Absyn.ITERATOR(ident,NONE(),SOME(exp_1))},equations_1);
case (Absyn.EQ_WHEN_E(whenExp = exp,whenEquations = equations,elseWhenEquations = exp_equations),old_comp,new_comp)
equation
exp_1 = renameComponentInExp(exp, old_comp, new_comp);
equations_1 = renameComponentInEquationList(equations, old_comp, new_comp);
exp_equations_1 = renameComponentInExpEquationitemList(exp_equations, old_comp, new_comp);
then
Absyn.EQ_WHEN_E(exp_1,equations_1,exp_equations_1);
case (Absyn.EQ_NORETCALL(functionName = cref,functionArgs = function_args),_,_)
equation
print("-rename_component_in_equation EQ_NORETCALL not implemented yet\n");
then
Absyn.EQ_NORETCALL(cref,function_args);
else
equation
print("-rename_component_in_equation failed\n");
then
fail();
end matchcontinue;
end renameComponentInEquation;
protected function renameComponentInExpList
"author: x02lucpo
helper function to renameComponentVisitor"
input list<Absyn.Exp> inAbsynExpLst1;
input Absyn.ComponentRef inComponentRef2;
input Absyn.ComponentRef inComponentRef3;
output list<Absyn.Exp> outAbsynExpLst;
algorithm
outAbsynExpLst := matchcontinue (inAbsynExpLst1,inComponentRef2,inComponentRef3)
local
Absyn.Exp exp_1,exp;
list<Absyn.Exp> res_1,res;
Absyn.ComponentRef old_comp,new_comp;
case ({},_,_) then {}; /* the old name for the component */
case ((exp :: res),old_comp,new_comp)
equation
exp_1 = renameComponentInExp(exp, old_comp, new_comp);
res_1 = renameComponentInExpList(res, old_comp, new_comp);
then
(exp_1 :: res_1);
else
equation
print("-rename_component_in_exp_list failed\n");
then
fail();
end matchcontinue;
end renameComponentInExpList;
protected function renameComponentInExpListList
"author: x02lucpo
helper function to renameComponentVisitor"
input list<list<Absyn.Exp>> inAbsynExpLstLst1;
input Absyn.ComponentRef inComponentRef2;
input Absyn.ComponentRef inComponentRef3;
output list<list<Absyn.Exp>> outAbsynExpLstLst;
algorithm
outAbsynExpLstLst := matchcontinue (inAbsynExpLstLst1,inComponentRef2,inComponentRef3)
local
list<Absyn.Exp> exp_1,exp;
list<list<Absyn.Exp>> res_1,res;
Absyn.ComponentRef old_comp,new_comp;
case ({},_,_) then {}; /* the old name for the component */
case ((exp :: res),old_comp,new_comp)
equation
exp_1 = renameComponentInExpList(exp, old_comp, new_comp);
res_1 = renameComponentInExpListList(res, old_comp, new_comp);
then
(exp_1 :: res_1);
else
equation
print("-rename_component_in_exp_list_list failed\n");
then
fail();
end matchcontinue;
end renameComponentInExpListList;
protected function renameComponentInExpTupleList
"author: x02lucpo
helper function to renameComponentVisitor"
input list<tuple<Absyn.Exp, Absyn.Exp>> inTplAbsynExpAbsynExpLst1;
input Absyn.ComponentRef inComponentRef2;
input Absyn.ComponentRef inComponentRef3;
output list<tuple<Absyn.Exp, Absyn.Exp>> outTplAbsynExpAbsynExpLst;
algorithm
outTplAbsynExpAbsynExpLst := matchcontinue (inTplAbsynExpAbsynExpLst1,inComponentRef2,inComponentRef3)
local
Absyn.Exp exp1_1,exp2_1,exp1,exp2;
list<tuple<Absyn.Exp, Absyn.Exp>> res_1,res;
Absyn.ComponentRef old_comp,new_comp;
case ({},_,_) then {};
case (((exp1,exp2) :: res),old_comp,new_comp)
equation
exp1_1 = renameComponentInExp(exp1, old_comp, new_comp);
exp2_1 = renameComponentInExp(exp2, old_comp, new_comp);
res_1 = renameComponentInExpTupleList(res, old_comp, new_comp);
then
((exp1_1,exp2_1) :: res_1);
else
equation
print("-rename_component_in_exp_tuple_list failed\n");
then
fail();
end matchcontinue;
end renameComponentInExpTupleList;
protected function renameComponentInElementArgList
"author: x02lucpo
helper function to renameComponentVisitor"
input list<Absyn.ElementArg> inAbsynElementArgLst1;
input Absyn.ComponentRef inComponentRef2;
input Absyn.ComponentRef inComponentRef3;
output list<Absyn.ElementArg> outAbsynElementArgLst;
algorithm
outAbsynElementArgLst := matchcontinue (inAbsynElementArgLst1,inComponentRef2,inComponentRef3)
local
Absyn.ElementArg element_arg_1,element_arg;
list<Absyn.ElementArg> res_1,res;
Absyn.ComponentRef old_comp,new_comp;
case ({},_,_) then {}; /* the old name for the component */
case ((element_arg :: res),old_comp,new_comp)
equation
element_arg_1 = renameComponentInElementArg(element_arg, old_comp, new_comp);
res_1 = renameComponentInElementArgList(res, old_comp, new_comp);
then
(element_arg_1 :: res_1);
else
equation
print("-rename_component_in_element_arg_list failed\n");
then
fail();
end matchcontinue;
end renameComponentInElementArgList;
protected function renameComponentInElementArg
"author: x02lucpo
helper function to renameComponentVisitor"
input Absyn.ElementArg inElementArg1;
input Absyn.ComponentRef inComponentRef2;
input Absyn.ComponentRef inComponentRef3;
output Absyn.ElementArg outElementArg;
algorithm
outElementArg := match (inElementArg1,inComponentRef2,inComponentRef3)
local
Absyn.ComponentRef old_comp,new_comp;
Absyn.Path p,p_1;
Absyn.Exp exp_1,exp;
list<Absyn.ElementArg> element_args_1,element_args;
Boolean b;
Absyn.Each each_;
Option<String> str;
Absyn.ElementSpec element_spec_1,element_spec2_1,element_spec,element_spec2;
Absyn.RedeclareKeywords redecl;
Option<Absyn.Comment> c;
SourceInfo info, mod_info;
/* the old name for the component */
case (Absyn.MODIFICATION(finalPrefix = b,eachPrefix = each_,path = p,modification = SOME(Absyn.CLASSMOD(element_args,Absyn.EQMOD(exp,info))),comment = str,info = mod_info),old_comp,new_comp)
equation
p_1 = AbsynUtil.crefToPath(replaceStartInComponentRef(AbsynUtil.pathToCref(p), old_comp, new_comp));
exp_1 = renameComponentInExp(exp, old_comp, new_comp);
element_args_1 = renameComponentInElementArgList(element_args, old_comp, new_comp);
then
Absyn.MODIFICATION(b,each_,p_1,
SOME(Absyn.CLASSMOD(element_args_1,Absyn.EQMOD(exp_1,info))),str,mod_info);
case (Absyn.MODIFICATION(finalPrefix = b,eachPrefix = each_,path = p,modification = SOME(Absyn.CLASSMOD(element_args,Absyn.NOMOD())),comment = str, info = mod_info),old_comp,new_comp)
equation
p_1 = AbsynUtil.crefToPath(replaceStartInComponentRef(AbsynUtil.pathToCref(p), old_comp, new_comp));
element_args_1 = renameComponentInElementArgList(element_args, old_comp, new_comp);
then
Absyn.MODIFICATION(b,each_,p_1,SOME(Absyn.CLASSMOD(element_args_1,Absyn.NOMOD())),str,mod_info);
case (Absyn.MODIFICATION(finalPrefix = b,eachPrefix = each_,path = p,modification = NONE(),comment = str, info = mod_info),old_comp,new_comp)
equation
p_1 = AbsynUtil.crefToPath(replaceStartInComponentRef(AbsynUtil.pathToCref(p), old_comp, new_comp));
then
Absyn.MODIFICATION(b,each_,p_1,NONE(),str,mod_info);
case (Absyn.REDECLARATION(finalPrefix = b,redeclareKeywords = redecl,eachPrefix = each_,elementSpec = element_spec,constrainClass = SOME(Absyn.CONSTRAINCLASS(element_spec2,c)),info = info),old_comp,new_comp)
equation
element_spec_1 = renameComponentInElementSpec(element_spec, old_comp, new_comp);
element_spec2_1 = renameComponentInElementSpec(element_spec2, old_comp, new_comp);
then
Absyn.REDECLARATION(b,redecl,each_,element_spec_1,
SOME(Absyn.CONSTRAINCLASS(element_spec2_1,c)),info);
case (Absyn.REDECLARATION(finalPrefix = b,redeclareKeywords = redecl,eachPrefix = each_,elementSpec = element_spec,constrainClass = NONE(),info=info),old_comp,new_comp)
equation
element_spec_1 = renameComponentInElementSpec(element_spec, old_comp, new_comp);
then
Absyn.REDECLARATION(b,redecl,each_,element_spec_1,NONE(),info);
end match;
end renameComponentInElementArg;
protected function renameComponentInCode
"author: x02lucpo
helper function to renameComponentVisitor"
input Absyn.CodeNode inCode1;
input Absyn.ComponentRef inComponentRef2;
input Absyn.ComponentRef inComponentRef3;
output Absyn.CodeNode outCode;
algorithm
outCode := match (inCode1,inComponentRef2,inComponentRef3)
local
Absyn.Path path;
Absyn.ComponentRef old_comp,new_comp,cr_1,cr;
list<Absyn.EquationItem> eqn_items_1,eqn_items;
Boolean b,finalPrefix;
list<Absyn.AlgorithmItem> algs_1,algs;
Absyn.ElementSpec elementspec_1,elementspec;
Option<Absyn.RedeclareKeywords> redeclare_;
Absyn.InnerOuter inner_outer;
SourceInfo info;
Option<Absyn.ConstrainClass> constrainClass;
Absyn.Exp exp_1,exp;
list<Absyn.ElementArg> element_args_1,element_args;
case (Absyn.C_TYPENAME(path = path),_,_) then Absyn.C_TYPENAME(path); /* the old name for the component */
case (Absyn.C_VARIABLENAME(componentRef = cr),old_comp,new_comp)
equation
cr_1 = replaceStartInComponentRef(cr, old_comp, new_comp);
then
Absyn.C_VARIABLENAME(cr_1);
case (Absyn.C_EQUATIONSECTION(boolean = b,equationItemLst = eqn_items),old_comp,new_comp)
equation
eqn_items_1 = renameComponentInEquationList(eqn_items, old_comp, new_comp);