Skip to content

Commit 25d0c02

Browse files
author
x02lucpo
committed
corrected an error in symplify: x+x+x+x+x (integers) became 5.0*x which made subscripts with exp not working. now it returns 5*x
git-svn-id: https://openmodelica.org/svn/OpenModelica/trunk@2409 f25d12d1-65f4-0310-ae8a-bbce733d8d8e
1 parent 34a0616 commit 25d0c02

File tree

2 files changed

+55
-8
lines changed

2 files changed

+55
-8
lines changed

Compiler/Dump.mo

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3573,6 +3573,10 @@ algorithm
35733573
end matchcontinue;
35743574
end printExp;
35753575

3576+
3577+
3578+
3579+
35763580
protected function printFunctionArgs "function: printFunctionArgs
35773581
35783582
Prints FunctionArgs to Print buffer.

Compiler/Exp.mo

Lines changed: 51 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -381,6 +381,29 @@ protected import OpenModelica.Compiler.Debug;
381381

382382
protected constant Exp rconstone=RCONST(1.0);
383383

384+
385+
public function dumpExpWithTitle
386+
input String title;
387+
input Exp exp;
388+
protected String str;
389+
algorithm
390+
str := dumpExpStr(exp,0);
391+
print(title);
392+
print(str);
393+
print("\n");
394+
end dumpExpWithTitle;
395+
396+
397+
public function dumpExp
398+
input Exp exp;
399+
protected String str;
400+
algorithm
401+
str := dumpExpStr(exp,0);
402+
print(str);
403+
print("--------------------\n");
404+
end dumpExp;
405+
406+
384407
public function crefToPath "function: crefToPath
385408
386409
This function converts a `ComponentRef\' to a `Path\', if possible.
@@ -1171,6 +1194,7 @@ algorithm
11711194
ComponentRef c_1;
11721195
Operator op;
11731196
String before, after;
1197+
11741198
case (CAST(ty = REAL(),exp = RCONST(real = v))) then RCONST(v);
11751199
case (CAST(ty = REAL(),exp = e))
11761200
local Integer v;
@@ -1657,6 +1681,8 @@ algorithm
16571681
list<Exp> e_lst,e_lst_1,const_es1,notconst_es1,const_es1_1,e_lst_2;
16581682
Exp res,e,e1,e2;
16591683
Type tp;
1684+
String str;
1685+
16601686
case ((e as BINARY(exp1 = e1,operator = MUL(ty = tp),exp2 = e2)))
16611687
equation
16621688
e_lst = factors(e);
@@ -1789,12 +1815,14 @@ algorithm
17891815
local
17901816
Exp e,e_1,e1;
17911817
list<Exp> es;
1818+
Type tp;
17921819
case ({}) then {};
17931820
case ({e}) then {e};
17941821
case ((e1 :: es))
17951822
equation
17961823
{e} = simplifyBinaryMulConstants(es);
1797-
e_1 = simplifyBinaryConst(MUL(REAL()), e1, e);
1824+
tp = typeof(e);
1825+
e_1 = simplifyBinaryConst(MUL(tp), e1, e);
17981826
then
17991827
{e_1};
18001828
end matchcontinue;
@@ -1807,13 +1835,13 @@ protected function simplifyMul "function: simplifyMul
18071835
"
18081836
input list<Exp> expl;
18091837
output list<Exp> expl_1;
1810-
list<Ident> sl;
1811-
Ident s;
1838+
// list<Ident> sl;
1839+
// Ident s;
18121840
list<tuple<Exp, Real>> exp_const,exp_const_1;
18131841
list<Exp> expl_1;
18141842
algorithm
1815-
sl := Util.listMap(expl, printExpStr);
1816-
s := Util.stringDelimitList(sl, ", ");
1843+
// sl := Util.listMap(expl, printExpStr);
1844+
// s := Util.stringDelimitList(sl, ", ");
18171845
exp_const := simplifyMul2(expl);
18181846
exp_const_1 := simplifyMulJoinFactors(exp_const);
18191847
expl_1 := simplifyMulMakePow(exp_const_1);
@@ -1927,6 +1955,7 @@ algorithm
19271955
Exp e;
19281956
Real r;
19291957
list<tuple<Exp, Real>> xs;
1958+
Type tp;
19301959
case ({}) then {};
19311960
case (((e,r) :: xs))
19321961
equation
@@ -1937,8 +1966,9 @@ algorithm
19371966
case (((e,r) :: xs))
19381967
equation
19391968
res = simplifyMulMakePow(xs);
1969+
tp = typeof(e);
19401970
then
1941-
(BINARY(e,POW(REAL()),RCONST(r)) :: res);
1971+
(BINARY(e,POW(tp),RCONST(r)) :: res);
19421972
end matchcontinue;
19431973
end simplifyMulMakePow;
19441974

@@ -2074,13 +2104,22 @@ algorithm
20742104
Exp e;
20752105
Real r;
20762106
list<tuple<Exp, Real>> xs;
2107+
Type tp;
20772108
case ({}) then {};
20782109
case (((e,r) :: xs))
20792110
equation
20802111
(r ==. 1.0) = true;
20812112
res = simplifyAddMakeMul(xs);
20822113
then
20832114
(e :: res);
2115+
case (((e,r) :: xs))
2116+
local Integer tmpInt;
2117+
equation
2118+
INT() = typeof(e);
2119+
res = simplifyAddMakeMul(xs);
2120+
tmpInt = realInt(r);
2121+
then
2122+
(BINARY(ICONST(tmpInt),MUL(INT()),e) :: res);
20842123
case (((e,r) :: xs))
20852124
equation
20862125
res = simplifyAddMakeMul(xs);
@@ -6190,15 +6229,19 @@ algorithm
61906229
res_str = Util.stringAppendList({gen_str,"CREF ",s,"\n"});
61916230
then
61926231
res_str;
6193-
case (BINARY(exp1 = e1,operator = op,exp2 = e2),level) /* Graphviz.LNODE(\"BINARY\",{sym},{},{lt,rt}) */
6232+
case (exp as BINARY(exp1 = e1,operator = op,exp2 = e2),level) /* Graphviz.LNODE(\"BINARY\",{sym},{},{lt,rt}) */
6233+
local String str;
6234+
Type tp;
61946235
equation
61956236
gen_str = genStringNTime(" |", level);
61966237
new_level1 = level + 1;
61976238
new_level2 = level + 1;
61986239
sym = binopSymbol(op);
6240+
tp = typeof(exp);
6241+
str = typeString(tp);
61996242
lt = dumpExpStr(e1, new_level1);
62006243
rt = dumpExpStr(e2, new_level2);
6201-
res_str = Util.stringAppendList({gen_str,"BINARY ",sym,"\n",lt,rt,""});
6244+
res_str = Util.stringAppendList({gen_str,"BINARY ",sym," ",str,"\n",lt,rt,""});
62026245
then
62036246
res_str;
62046247
case (UNARY(operator = op,exp = e),level) /* Graphviz.LNODE(\"UNARY\",{sym},{},{ct}) */

0 commit comments

Comments
 (0)