Skip to content

Commit f27058c

Browse files
committed
#2294 Simplify sign(constant)
git-svn-id: https://openmodelica.org/svn/OpenModelica/trunk@16739 f25d12d1-65f4-0310-ae8a-bbce733d8d8e
1 parent aa1c089 commit f27058c

File tree

1 file changed

+30
-24
lines changed

1 file changed

+30
-24
lines changed

Compiler/FrontEnd/ExpressionSimplify.mo

Lines changed: 30 additions & 24 deletions
Original file line numberDiff line numberDiff line change
@@ -287,10 +287,10 @@ algorithm
287287
((e,(b or b2,options)));
288288

289289
// normal (pure) call
290-
case ((e as DAE.CALL(expLst=expl, attr=DAE.CALL_ATTR(isImpure=false)),(_,options)))
290+
case ((e as DAE.CALL(path=Absyn.IDENT(idn),expLst=expl, attr=DAE.CALL_ATTR(isImpure=false)),(_,options)))
291291
equation
292292
true = Expression.isConstWorkList(expl, true);
293-
e2 = simplifyBuiltinConstantCalls(e);
293+
e2 = simplifyBuiltinConstantCalls(idn,e);
294294
then
295295
((e2,(true,options)));
296296

@@ -1373,146 +1373,152 @@ algorithm
13731373
end simplifyStringAppendList;
13741374

13751375
protected function simplifyBuiltinConstantCalls "simplifies some builtin calls if constant arguments"
1376+
input String name;
13761377
input DAE.Exp exp "assumes already simplified call arguments";
13771378
output DAE.Exp outExp;
13781379
algorithm
1379-
outExp := matchcontinue exp
1380+
outExp := matchcontinue (name,exp)
13801381
local
13811382
Real r,v1,v2;
13821383
Integer i, j;
13831384
DAE.Exp e,e1,e2;
13841385

13851386
// der(constant) ==> 0
1386-
case (DAE.CALL(path=Absyn.IDENT("der"),expLst ={e}))
1387+
case ("der",DAE.CALL(expLst ={e}))
13871388
equation
13881389
e1 = simplifyBuiltinConstantDer(e);
13891390
then e1;
13901391

13911392
// pre(constant) ==> constant
1392-
case (DAE.CALL(path=Absyn.IDENT("pre"),expLst ={e}))
1393+
case ("pre",DAE.CALL(expLst ={e}))
13931394
then e;
13941395

13951396
// edge(constant) ==> false
1396-
case (DAE.CALL(path=Absyn.IDENT("edge"),expLst ={e}))
1397+
case ("edge",DAE.CALL(expLst ={e}))
13971398
then DAE.BCONST(false);
13981399

13991400
// change(constant) ==> false
1400-
case (DAE.CALL(path=Absyn.IDENT("change"),expLst ={e}))
1401+
case ("change",DAE.CALL(expLst ={e}))
14011402
then DAE.BCONST(false);
14021403

14031404
// sqrt function
1404-
case(DAE.CALL(path=Absyn.IDENT("sqrt"),expLst={e}))
1405+
case("sqrt",DAE.CALL(expLst={e}))
14051406
equation
14061407
r = realSqrt(Expression.getRealConst(e));
14071408
then
14081409
DAE.RCONST(r);
14091410

14101411
// abs on real
1411-
case(DAE.CALL(path=Absyn.IDENT("abs"),expLst={DAE.RCONST(r)}))
1412+
case("abs",DAE.CALL(expLst={DAE.RCONST(r)}))
14121413
equation
14131414
r = realAbs(r);
14141415
then
14151416
DAE.RCONST(r);
14161417

14171418
// abs on integer
1418-
case(DAE.CALL(path=Absyn.IDENT("abs"),expLst={DAE.ICONST(i)}))
1419+
case("abs",DAE.CALL(expLst={DAE.ICONST(i)}))
14191420
equation
14201421
i = intAbs(i);
14211422
then
14221423
DAE.ICONST(i);
14231424

14241425
// sin function
1425-
case(DAE.CALL(path=Absyn.IDENT("sin"),expLst={e}))
1426+
case("sin",DAE.CALL(expLst={e}))
14261427
equation
14271428
r = realSin(Expression.getRealConst(e));
14281429
then DAE.RCONST(r);
14291430

14301431
// cos function
1431-
case(DAE.CALL(path=Absyn.IDENT("cos"),expLst={e}))
1432+
case("cos",DAE.CALL(expLst={e}))
14321433
equation
14331434
r = realCos(Expression.getRealConst(e));
14341435
then DAE.RCONST(r);
14351436

14361437
// sin function
1437-
case(DAE.CALL(path=Absyn.IDENT("asin"),expLst={e}))
1438+
case("asin",DAE.CALL(expLst={e}))
14381439
equation
14391440
r = realAsin(Expression.getRealConst(e));
14401441
then DAE.RCONST(r);
14411442

14421443
// cos function
1443-
case(DAE.CALL(path=Absyn.IDENT("acos"),expLst={e}))
1444+
case("acos",DAE.CALL(expLst={e}))
14441445
equation
14451446
r = realAcos(Expression.getRealConst(e));
14461447
then DAE.RCONST(r);
14471448

14481449
// tangent function
1449-
case(DAE.CALL(path=Absyn.IDENT("tan"),expLst={e}))
1450+
case("tan",DAE.CALL(expLst={e}))
14501451
equation
14511452
v1 = realSin(Expression.getRealConst(e));
14521453
v2 = realCos(Expression.getRealConst(e));
14531454
r = v1 /. v2;
14541455
then DAE.RCONST(r);
14551456

14561457
// DAE.Exp function
1457-
case(DAE.CALL(path=Absyn.IDENT("exp"),expLst={e}))
1458+
case("exp",DAE.CALL(expLst={e}))
14581459
equation
14591460
r = realExp(Expression.getRealConst(e));
14601461
then DAE.RCONST(r);
14611462

14621463
// log function
1463-
case(DAE.CALL(path=Absyn.IDENT("log"),expLst={e}))
1464+
case("log",DAE.CALL(expLst={e}))
14641465
equation
14651466
r = realLn(Expression.getRealConst(e));
14661467
then
14671468
DAE.RCONST(r);
14681469

14691470
// log10 function
1470-
case(DAE.CALL(path=Absyn.IDENT("log10"),expLst={e}))
1471+
case("log10",DAE.CALL(expLst={e}))
14711472
equation
14721473
r = realLog10(Expression.getRealConst(e));
14731474
then
14741475
DAE.RCONST(r);
14751476

14761477
// min function on integers
1477-
case(DAE.CALL(path=Absyn.IDENT("min"),expLst={DAE.ICONST(i), DAE.ICONST(j)}))
1478+
case("min",DAE.CALL(expLst={DAE.ICONST(i), DAE.ICONST(j)}))
14781479
equation
14791480
i = intMin(i, j);
14801481
then DAE.ICONST(i);
14811482

14821483
// min function on reals
1483-
case(DAE.CALL(path=Absyn.IDENT("min"),expLst={e, e1},attr=DAE.CALL_ATTR(ty=DAE.T_REAL(source=_))))
1484+
case("min",DAE.CALL(expLst={e, e1},attr=DAE.CALL_ATTR(ty=DAE.T_REAL(source=_))))
14841485
equation
14851486
v1 = Expression.getRealConst(e);
14861487
v2 = Expression.getRealConst(e1);
14871488
r = realMin(v1, v2);
14881489
then DAE.RCONST(r);
14891490

14901491
// min function on enumerations
1491-
case(DAE.CALL(path=Absyn.IDENT("min"),expLst={e as DAE.ENUM_LITERAL(index=i), e1 as DAE.ENUM_LITERAL(index=j)}))
1492+
case("min",DAE.CALL(expLst={e as DAE.ENUM_LITERAL(index=i), e1 as DAE.ENUM_LITERAL(index=j)}))
14921493
equation
14931494
e2 = Util.if_(intLt(i,j),e,e1);
14941495
then e2;
14951496

14961497
// max function on integers
1497-
case(DAE.CALL(path=Absyn.IDENT("max"),expLst={DAE.ICONST(i), DAE.ICONST(j)}))
1498+
case("max",DAE.CALL(expLst={DAE.ICONST(i), DAE.ICONST(j)}))
14981499
equation
14991500
i = intMax(i, j);
15001501
then DAE.ICONST(i);
15011502

15021503
// max function on reals
1503-
case(DAE.CALL(path=Absyn.IDENT("max"),expLst={e, e1},attr=DAE.CALL_ATTR(ty=DAE.T_REAL(source=_))))
1504+
case("max",DAE.CALL(expLst={e, e1},attr=DAE.CALL_ATTR(ty=DAE.T_REAL(source=_))))
15041505
equation
15051506
v1 = Expression.getRealConst(e);
15061507
v2 = Expression.getRealConst(e1);
15071508
r = realMax(v1, v2);
15081509
then DAE.RCONST(r);
15091510

15101511
// max function on enumerations
1511-
case(DAE.CALL(path=Absyn.IDENT("max"),expLst={e as DAE.ENUM_LITERAL(index=i), e1 as DAE.ENUM_LITERAL(index=j)}))
1512+
case("max",DAE.CALL(expLst={e as DAE.ENUM_LITERAL(index=i), e1 as DAE.ENUM_LITERAL(index=j)}))
15121513
equation
15131514
e2 = Util.if_(intGt(i,j),e,e1);
15141515
then e2;
15151516

1517+
case("sign",DAE.CALL(expLst={DAE.RCONST(r)}))
1518+
equation
1519+
i = Util.if_(realEq(r,0.0), 0, Util.if_(realGt(r,0.0), 1, -1));
1520+
then DAE.ICONST(i);
1521+
15161522
end matchcontinue;
15171523
end simplifyBuiltinConstantCalls;
15181524

0 commit comments

Comments
 (0)