Skip to content

Commit 59f2594

Browse files
committed
- Refactored DAE.mo to DAE.mo (AST) and DAEUtil.mo (functions)
- Fixed bug that r4481 introduced (mosfiles/simulation3.mos failed) git-svn-id: https://openmodelica.org/svn/OpenModelica/trunk@4483 f25d12d1-65f4-0310-ae8a-bbce733d8d8e
1 parent b2fe2b8 commit 59f2594

17 files changed

+6208
-6122
lines changed

Compiler/CevalScript.mo

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -71,6 +71,7 @@ protected import Codegen;
7171
protected import Settings;
7272
protected import SCode;
7373
protected import DAE;
74+
protected import DAEUtil;
7475
protected import Util;
7576
protected import ModUtil;
7677
protected import RTOpts;
@@ -250,7 +251,7 @@ algorithm
250251
p_1 = SCode.elaborate(ptot);
251252
(cache,env,_, dae as DAE.DAE(dael)) =
252253
Inst.instantiateClass(cache,InstanceHierarchy.emptyInstanceHierarchy,p_1, path);
253-
((dae as DAE.DAE(dael))) = DAE.transformIfEqToExpr(dae);
254+
((dae as DAE.DAE(dael))) = DAEUtil.transformIfEqToExpr(dae);
254255
ic_1 = Interactive.addInstantiatedClass(ic, Interactive.INSTCLASS(path,dael,env));
255256
/*((daelow as DAELow.DAELOW(orderedVars=vars,orderedEqs=eqnarr,complexEqns = DAELow.COMPLEX_EQUATIONS(arrayEqs=ae,ifEqns=ifeqns)))) = DAELow.lower(dae, false, true) "no dummy state" ;*/
256257
((daelow as DAELow.DAELOW(vars,_,_,eqnarr,_,_,ae,_,_,_))) = DAELow.lower(dae, false, true) "no dummy state" ;
@@ -648,9 +649,9 @@ algorithm
648649
p_1 = SCode.elaborate(ptot);
649650
(cache,env,_,(dae as DAE.DAE(dael))) =
650651
Inst.instantiateClass(cache,InstanceHierarchy.emptyInstanceHierarchy,p_1,className);
651-
// ((dae as DAE.DAE(dael))) = DAE.transformIfEqToExpr(dael);
652+
// ((dae as DAE.DAE(dael))) = DAEUtil.transformIfEqToExpr(dael);
652653
ic_1 = Interactive.addInstantiatedClass(ic, Interactive.INSTCLASS(className,dael,env));
653-
str = DAE.dumpStr(dae);
654+
str = DAEUtil.dumpStr(dae);
654655
then
655656
(cache,Values.STRING(str),Interactive.SYMBOLTABLE(p,aDep,sp,ic_1,iv,cf,lf));
656657

@@ -2250,15 +2251,15 @@ algorithm
22502251
p_1 = SCode.elaborate(p);
22512252
(cache,env,_,dae_1) =
22522253
Inst.instantiateClass(cache,InstanceHierarchy.emptyInstanceHierarchy,p_1,className);
2253-
((dae as DAE.DAE(dael))) = DAE.transformIfEqToExpr(dae_1);
2254+
((dae as DAE.DAE(dael))) = DAEUtil.transformIfEqToExpr(dae_1);
22542255
ic_1 = Interactive.addInstantiatedClass(ic, Interactive.INSTCLASS(className,dael,env));
22552256
a_cref = Absyn.pathToCref(className);
22562257
file_dir = getFileDir(a_cref, p);
22572258
elimLevel = RTOpts.eliminationLevel();
22582259
RTOpts.setEliminationLevel(0); // No variable eliminiation
22592260
dlow = DAELow.lower(dae, false, false);
22602261
RTOpts.setEliminationLevel(elimLevel); // Reset elimination level
2261-
flatModelicaStr = DAE.dumpStr(dae);
2262+
flatModelicaStr = DAEUtil.dumpStr(dae);
22622263
flatModelicaStr = stringAppend("OldEqStr={'", flatModelicaStr);
22632264
flatModelicaStr = System.stringReplace(flatModelicaStr, "\n", "%##%");
22642265
flatModelicaStr = System.stringReplace(flatModelicaStr, "%##%", "','");
@@ -2321,7 +2322,7 @@ algorithm
23212322
p_1 = SCode.elaborate(ptot);
23222323
(cache,env,_,dae as DAE.DAE(dael)) =
23232324
Inst.instantiateClass(cache,InstanceHierarchy.emptyInstanceHierarchy,p_1,className);
2324-
((dae as DAE.DAE(dael))) = DAE.transformIfEqToExpr(dae);
2325+
((dae as DAE.DAE(dael))) = DAEUtil.transformIfEqToExpr(dae);
23252326
ic_1 = Interactive.addInstantiatedClass(ic, Interactive.INSTCLASS(className,dael,env));
23262327
dlow = DAELow.lower(dae, addDummy, true);
23272328
Debug.fprint("bltdump", "Lowered DAE:\n");
@@ -3280,7 +3281,7 @@ algorithm
32803281

32813282
(cache, env, _, dae as DAE.DAE(dael)) =
32823283
Inst.instantiateClass(inCache, InstanceHierarchy.emptyInstanceHierarchy, p_1, className);
3283-
((dae as DAE.DAE(dael))) = DAE.transformIfEqToExpr(dae);
3284+
((dae as DAE.DAE(dael))) = DAEUtil.transformIfEqToExpr(dae);
32843285
ic_1 = Interactive.addInstantiatedClass(ic, Interactive.INSTCLASS(className,dael,env));
32853286
elimLevel = RTOpts.eliminationLevel();
32863287
RTOpts.setEliminationLevel(0); // No variable elimination
@@ -3627,7 +3628,7 @@ algorithm
36273628
cname_str = Absyn.pathString(classname);
36283629
p_1 = SCode.elaborate(p);
36293630
(cache,env,_,dae_1) = Inst.instantiateClass(cache, InstanceHierarchy.emptyInstanceHierarchy, p_1, classname);
3630-
((dae as DAE.DAE(dael))) = DAE.transformIfEqToExpr(dae_1);
3631+
((dae as DAE.DAE(dael))) = DAEUtil.transformIfEqToExpr(dae_1);
36313632
ic_1 = Interactive.addInstantiatedClass(ic, Interactive.INSTCLASS(classname,dael,env));
36323633
dlow = DAELow.lower(dae, true, true);
36333634
m = DAELow.incidenceMatrix(dlow);
@@ -3670,7 +3671,7 @@ algorithm
36703671
cname_str = Absyn.pathString(classname);
36713672
p_1 = SCode.elaborate(p);
36723673
(cache,env,_,dae_1) = Inst.instantiateClass(cache, InstanceHierarchy.emptyInstanceHierarchy, p_1, classname);
3673-
((dae as DAE.DAE(dael))) = DAE.transformIfEqToExpr(dae_1);
3674+
((dae as DAE.DAE(dael))) = DAEUtil.transformIfEqToExpr(dae_1);
36743675
ic_1 = Interactive.addInstantiatedClass(ic, Interactive.INSTCLASS(classname,dael,env));
36753676
dlow = DAELow.lower(dae, true, true);
36763677
m = DAELow.incidenceMatrix(dlow);

Compiler/Codegen.mo

Lines changed: 36 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -130,6 +130,7 @@ protected import Inst;
130130
protected import Interactive;
131131
protected import System;
132132
protected import Error;
133+
protected import DAEUtil;
133134

134135
public constant CFunction cEmptyFunction=CFUNCTION("","",{},{},{},{},{},{}) " empty function ";
135136

@@ -981,8 +982,8 @@ protected function generateFunctionsElist
981982
algorithm
982983
Debug.fprintln("cgtr", "generate_functions_elist");
983984
Debug.fprintln("cgtrdumpdae", "Dumping DAE:");
984-
Debug.fcall("cgtrdumpdae", DAE.dump2, DAE.DAE(els));
985-
fns := Util.listFilter(els, DAE.isFunction);
985+
Debug.fcall("cgtrdumpdae", DAEUtil.dump2, DAE.DAE(els));
986+
fns := Util.listFilter(els, DAEUtil.isFunction);
986987
(cfns,rt_1) := generateFunctionsElist2(fns,rt);
987988
end generateFunctionsElist;
988989

@@ -1058,14 +1059,14 @@ algorithm
10581059
fn_name_str = stringAppend("_", fn_name_str);
10591060
Debug.fprintl("cgtr", {"generating function ",fn_name_str,"\n"});
10601061
Debug.fprintln("cgtrdumpdae3", "Dumping DAE:");
1061-
Debug.fcall("cgtrdumpdae3", DAE.dump2, DAE.DAE(dae));
1062-
outvars = DAE.getOutputVars(dae);
1063-
invars = DAE.getInputVars(dae);
1062+
Debug.fcall("cgtrdumpdae3", DAEUtil.dump2, DAE.DAE(dae));
1063+
outvars = DAEUtil.getOutputVars(dae);
1064+
invars = DAEUtil.getInputVars(dae);
10641065
(struct_strs,rt_1) = generateStructsForRecords(dae, rt);
10651066
struct_strs_1 = generateResultStruct(outvars, fpath);
10661067
struct_strs = listAppend(struct_strs, struct_strs_1);
10671068
/*-- MetaModelica Partial Function. sjoelund --*/
1068-
funrefs = Util.listSelect(invars, DAE.isFunctionRefVar);
1069+
funrefs = Util.listSelect(invars, DAEUtil.isFunctionRefVar);
10691070
struct_funrefs = Util.listFlatten(Util.listMap(funrefs, generateFunctionRefReturnStruct));
10701071
/*-- --*/
10711072
retstr = generateReturnType(fpath);
@@ -1139,9 +1140,9 @@ algorithm
11391140
fn_name_str = stringAppend("_", fn_name_str);
11401141
DAE.EXTERNALDECL(ident = extfnname, external_ = extargs,parameters = extretarg, returnType = lang, language = ann) = extdecl;
11411142
dae = Inst.initVarsModelicaOutput(orgdae);
1142-
outvars = DAE.getOutputVars(dae);
1143-
invars = DAE.getInputVars(dae);
1144-
bivars = DAE.getBidirVars(dae);
1143+
outvars = DAEUtil.getOutputVars(dae);
1144+
invars = DAEUtil.getInputVars(dae);
1145+
bivars = DAEUtil.getBidirVars(dae);
11451146
(struct_strs,rt_1) = generateStructsForRecords(dae,rt);
11461147
struct_strs_1 = generateResultStruct(outvars, fpath);
11471148
struct_strs = listAppend(struct_strs, struct_strs_1);
@@ -1166,13 +1167,13 @@ algorithm
11661167
Debug.fprintl("cgtr", {"generating external function ",fn_name_str,"\n"});
11671168
DAE.EXTERNALDECL(ident = extfnname,external_ = extargs,parameters = extretarg,returnType = lang,language = ann) = extdecl;
11681169
Debug.fprintln("cgtrdumpdae1", "Dumping DAE:");
1169-
Debug.fcall("cgtrdumpdae1", DAE.dump2, DAE.DAE(orgdae));
1170+
Debug.fcall("cgtrdumpdae1", DAEUtil.dump2, DAE.DAE(orgdae));
11701171
dae = Inst.initVarsModelicaOutput(orgdae);
11711172
Debug.fprintln("cgtrdumpdae2", "Dumping DAE:");
1172-
Debug.fcall("cgtrdumpdae2", DAE.dump2, DAE.DAE(dae));
1173-
outvars = DAE.getOutputVars(dae);
1174-
invars = DAE.getInputVars(dae);
1175-
bivars = DAE.getBidirVars(dae);
1173+
Debug.fcall("cgtrdumpdae2", DAEUtil.dump2, DAE.DAE(dae));
1174+
outvars = DAEUtil.getOutputVars(dae);
1175+
invars = DAEUtil.getInputVars(dae);
1176+
bivars = DAEUtil.getBidirVars(dae);
11761177
(struct_strs,rt_1) = generateStructsForRecords(dae, rt);
11771178
struct_strs_1 = generateResultStruct(outvars, fpath);
11781179
struct_strs = listAppend(struct_strs, struct_strs_1);
@@ -1782,7 +1783,7 @@ algorithm
17821783
absynCommentOption = comment)))
17831784
17841785
equation
1785-
Debug.fcall("isarrdb", DAE.dump2, DAE.DAE({el}));
1786+
Debug.fcall("isarrdb", DAEUtil.dump2, DAE.DAE({el}));
17861787
then
17871788
false;
17881789
@@ -1797,13 +1798,13 @@ algorithm
17971798
variableAttributesOption = dae_var_attr,
17981799
absynCommentOption = comment)))
17991800
equation
1800-
Debug.fcall("isarrdb", DAE.dump2, DAE.DAE({el}));
1801+
Debug.fcall("isarrdb", DAEUtil.dump2, DAE.DAE({el}));
18011802
then
18021803
true;
18031804
18041805
case el
18051806
equation
1806-
Debug.fprint("failtrace", "-Codegen.isArray failed\n");
1807+
Debug.fprint("failtrace", "- Codegen.isArray failed\n");
18071808
then
18081809
fail();
18091810
end matchcontinue;
@@ -2530,7 +2531,7 @@ algorithm
25302531
ret_type_str := generateReturnType(fpath);
25312532
(ret_decl,ret_var,tnr_ret_1) := generateTempDecl(ret_type_str, tnr);
25322533
ret_stmt := Util.stringAppendList({"return ",ret_var,";"});
2533-
outvars := DAE.getOutputVars(dae);
2534+
outvars := DAEUtil.getOutputVars(dae);
25342535
(out_fn,tnr_ret) := generateAllocOutvars(outvars, ret_decl, ret_var, 1,tnr_ret_1, funContext);
25352536
(mem_decl,mem_var,tnr_mem) := generateTempDecl("state", tnr_ret);
25362537
mem_stmt1 := Util.stringAppendList({mem_var," = get_memory_state();"});
@@ -2787,7 +2788,7 @@ algorithm
27872788
case (e,_,_,tnr,context)
27882789
local DAE.Element e;
27892790
equation
2790-
failure(DAE.isVar(e));
2791+
failure(DAEUtil.isVar(e));
27912792
then
27922793
(cEmptyFunction,tnr);
27932794

@@ -2940,7 +2941,7 @@ algorithm
29402941
case (e,_,_,tnr)
29412942
local DAE.Element e;
29422943
equation
2943-
failure(DAE.isVar(e));
2944+
failure(DAEUtil.isVar(e));
29442945
then
29452946
(cEmptyFunction,tnr);
29462947

@@ -3047,7 +3048,7 @@ algorithm
30473048
Context context;
30483049
case (els,tnr,context)
30493050
equation
3050-
algs = Util.listFilter(els, DAE.isAlgorithm);
3051+
algs = Util.listFilter(els, DAEUtil.isAlgorithm);
30513052
(cfn,tnr_1) = generateAlgorithms2(algs, tnr, context);
30523053
then
30533054
(cfn,tnr_1);
@@ -7185,8 +7186,8 @@ algorithm
71857186
Option<Absyn.Annotation> ann;
71867187
case (vars,(extdecl as DAE.EXTERNALDECL(ident = n,external_ = arglist,parameters = retarg,returnType = lang,language = ann)),tnr)
71877188
equation
7188-
Debug.fcall("cgtrdumpdaeextcall", DAE.dump2, DAE.DAE(vars));
7189-
extdeclstr = DAE.dumpExtDeclStr(extdecl);
7189+
Debug.fcall("cgtrdumpdaeextcall", DAEUtil.dump2, DAE.DAE(vars));
7190+
extdeclstr = DAEUtil.dumpExtDeclStr(extdecl);
71907191
Debug.fprintln("cgtrdumpdaeextcall", extdeclstr);
71917192
(argdecls,arglist_1,tnr_1) = generateExtcallVardecls(vars, arglist, retarg, lang, 1,tnr);
71927193
lang2 = getJavaCallMappingFromAnn(lang, ann);
@@ -7296,7 +7297,7 @@ algorithm
72967297
case ((var :: rest),i,tnr)
72977298
equation
72987299
Debug.fprint("cgtr", "#--Ignoring: ");
7299-
Debug.fcall("cgtr", DAE.dump2, DAE.DAE({var}));
7300+
Debug.fcall("cgtr", DAEUtil.dump2, DAE.DAE({var}));
73007301
Debug.fprintln("cgtr", "");
73017302
(fn,tnr_1) = generateExtcallCopydeclsF77(rest,i, tnr);
73027303
then
@@ -8992,7 +8993,7 @@ algorithm
89928993
local
89938994
DAE.Element el;
89948995
equation
8995-
failure(DAE.isVar(el));
8996+
failure(DAEUtil.isVar(el));
89968997
cfn = generateWriteOutvars(r,i);
89978998
then
89988999
cfn;
@@ -9009,7 +9010,7 @@ protected function isOutput "Returns true if variable is output"
90099010
algorithm
90109011
isOutput := matchcontinue(e)
90119012
case(e) equation
9012-
DAE.isOutputVar(e);
9013+
DAEUtil.isOutputVar(e);
90139014
then true;
90149015
case(_) then false;
90159016
end matchcontinue;
@@ -9020,26 +9021,26 @@ protected function isRcwOutput "function: isRcwOutput
90209021
"
90219022
input DAE.Element e;
90229023
algorithm
9023-
DAE.isVar(e);
9024-
DAE.isOutputVar(e);
9024+
DAEUtil.isVar(e);
9025+
DAEUtil.isOutputVar(e);
90259026
end isRcwOutput;
90269027

90279028
protected function isRcwInput "function: isRcwInput
90289029
90299030
"
90309031
input DAE.Element e;
90319032
algorithm
9032-
DAE.isVar(e);
9033-
DAE.isInputVar(e);
9033+
DAEUtil.isVar(e);
9034+
DAEUtil.isInputVar(e);
90349035
end isRcwInput;
90359036

90369037
protected function isRcwBidir "function: isRcwBidir
90379038
90389039
"
90399040
input DAE.Element e;
90409041
algorithm
9041-
DAE.isVar(e);
9042-
DAE.isBidirVar(e);
9042+
DAEUtil.isVar(e);
9043+
DAEUtil.isBidirVar(e);
90439044
end isRcwBidir;
90449045

90459046
protected function generateJavaSignature
@@ -9704,7 +9705,7 @@ algorithm
97049705
ld2 = Convert.fromExpElemsToDAEElems(ld,{});
97059706
body2 = Convert.fromExpElemToDAEElem(body);
97069707
ld2 = body2 :: ld2;
9707-
exps = DAE.getAllExps(ld2);
9708+
exps = DAEUtil.getAllExps(ld2);
97089709
res = getMatchingExpsList(resE::exps,matchValueblock);
97099710
then e::res;
97109711
end matchcontinue;
@@ -9893,7 +9894,7 @@ algorithm
98939894
ld2 = Convert.fromExpElemsToDAEElems(ld,{});
98949895
body2 = Convert.fromExpElemToDAEElem(body);
98959896
ld2 = body2 :: ld2;
9896-
exps = DAE.getAllExps(ld2);
9897+
exps = DAEUtil.getAllExps(ld2);
98979898
res = getMatchingExpsList(e::exps,fn);
98989899
then res;
98999900

@@ -9929,7 +9930,7 @@ algorithm
99299930
equation
99309931
true = RTOpts.acceptMetaModelicaGrammar();
99319932
paths1 = getUniontypePaths2(elements);
9932-
exps = DAE.getAllExps(elements);
9933+
exps = DAEUtil.getAllExps(elements);
99339934
exps = getMatchingExpsList(exps, matchValueblock);
99349935
els = getDAEDeclsFromValueblocks(exps);
99359936
paths2 = getUniontypePaths2(els);

Compiler/ConnectionGraph.mo

Lines changed: 12 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -55,11 +55,12 @@ package ConnectionGraph
5555
that the model is valid.
5656
"
5757

58-
public import HashTableCG;
58+
public import Absyn;
59+
public import DAE;
5960
public import Exp;
61+
public import HashTableCG;
6062
public import Util;
61-
public import DAE;
62-
public import Absyn;
63+
public import DAEUtil;
6364

6465
/* A list of edges
6566
*/
@@ -81,6 +82,13 @@ uniontype ConnectionGraph
8182
end GRAPH;
8283
end ConnectionGraph;
8384

85+
/* Initial connection graph with no edges in it.
86+
*/
87+
public constant ConnectionGraph EMPTY = GRAPH( true, {}, {}, {}, {} );
88+
/* Initial connection graph with updateGraph set to false.
89+
*/
90+
public constant ConnectionGraph NOUPDATE_EMPTY = GRAPH( false, {}, {}, {}, {} );
91+
8492
function printEdges
8593
"Prints a list of edges to stdout."
8694
input Edges inEdges;
@@ -147,13 +155,6 @@ algorithm
147155
end matchcontinue;
148156
end printConnectionGraph;
149157

150-
/* Initial connection graph with no edges in it.
151-
*/
152-
constant ConnectionGraph EMPTY = GRAPH( true, {}, {}, {}, {} );
153-
/* Initial connection graph with updateGraph set to false.
154-
*/
155-
constant ConnectionGraph NOUPDATE_EMPTY = GRAPH( false, {}, {}, {}, {} );
156-
157158
function getDefiniteRoots
158159
"Accessor for ConnectionGraph.definititeRoots."
159160
input ConnectionGraph inGraph;
@@ -588,7 +589,7 @@ function evalIsRoot
588589
input list<DAE.Element> inDae;
589590
output list<DAE.Element> outDae;
590591
algorithm
591-
(outDae, _) := DAE.traverseDAE(inDae, evalIsRootHelper, inRoots);
592+
(outDae, _) := DAEUtil.traverseDAE(inDae, evalIsRootHelper, inRoots);
592593
end evalIsRoot;
593594

594595
function evalIsRootHelper

Compiler/Convert.mo

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ public import Util;
4848
public import SCode;
4949
public import ClassInf;
5050
public import Debug;
51+
protected import DAEUtil;
5152
type Ident = String;
5253

5354
//---------------------------------------------------------
@@ -251,7 +252,7 @@ algorithm
251252
local
252253
String str;
253254
equation
254-
str = DAE.dumpElementsStr({daeElem});
255+
str = DAEUtil.dumpElementsStr({daeElem});
255256
Debug.fprintln("failtrace", "- Convert.fromDAEElemToExpElem failed" +& str);
256257
then fail();
257258
end matchcontinue;

0 commit comments

Comments
 (0)