Skip to content
This repository was archived by the owner on May 18, 2019. It is now read-only.

Commit 1599277

Browse files
lochelOpenModelica-Hudson
authored andcommitted
Add missing cases to unit checking
1 parent 343d155 commit 1599277

File tree

2 files changed

+171
-232
lines changed

2 files changed

+171
-232
lines changed

Compiler/BackEnd/UnitCheck.mo

Lines changed: 29 additions & 50 deletions
Original file line numberDiff line numberDiff line change
@@ -289,6 +289,7 @@ algorithm
289289
HashTableUnitToString.HashTable HtU2S;
290290
list<list<tuple<DAE.Exp, Unit.Unit>>> expList;
291291
DAE.ComponentRef cr;
292+
list<BackendDAE.WhenOperator> whenStmtLst;
292293

293294
case (BackendDAE.EQUATION(exp=lhs, scalar=rhs), HtCr2U, HtS2U, HtU2S) equation
294295
temp = DAE.BINARY(rhs, DAE.SUB(DAE.T_REAL_DEFAULT), lhs);
@@ -328,9 +329,21 @@ algorithm
328329
//Error.addCompilerWarning("ALGORITHM, these types of equations are not yet supported\n");
329330
then (inHtCr2U, inHtS2U, inHtU2S, {});
330331

331-
case (BackendDAE.WHEN_EQUATION(), _, _, _) equation
332-
//Error.addCompilerWarning("WHEN_EQUATION, these types of equations are not yet supported\n");
333-
then (inHtCr2U, inHtS2U, inHtU2S, {});
332+
case (BackendDAE.WHEN_EQUATION(whenEquation=BackendDAE.WHEN_STMTS(whenStmtLst=whenStmtLst)), HtCr2U, HtS2U, HtU2S) algorithm
333+
for whenStmt in whenStmtLst loop
334+
_ := match whenStmt
335+
case BackendDAE.ASSIGN(left=lhs, right=rhs) equation
336+
temp = DAE.BINARY(rhs, DAE.SUB(DAE.T_REAL_DEFAULT), lhs);
337+
if Flags.isSet(Flags.DUMP_EQ_UNIT_STRUCT) then
338+
ExpressionDump.dumpExp(temp);
339+
end if;
340+
(_, (HtCr2U, HtS2U, HtU2S), expList)=insertUnitInEquation(temp, (HtCr2U, HtS2U, HtU2S), Unit.MASTER({}));
341+
then ();
342+
343+
else then ();
344+
end match;
345+
end for;
346+
then (HtCr2U, HtS2U, HtU2S, expList);
334347

335348
case (BackendDAE.COMPLEX_EQUATION(left=lhs, right=rhs), HtCr2U, HtS2U, HtU2S) equation
336349
temp = DAE.BINARY(rhs, DAE.SUB(DAE.T_REAL_DEFAULT), lhs);
@@ -721,6 +734,11 @@ algorithm
721734
(_, (HtCr2U, HtS2U, HtU2S), expListList) = insertUnitInEquation(exp1, (HtCr2U, HtS2U, HtU2S), Unit.MASTER({}));
722735
then (Unit.MASTER({}), (HtCr2U, HtS2U, HtU2S), expListList);
723736

737+
//PRE
738+
case (DAE.CALL(path = Absyn.IDENT(name = "pre"), expLst = {exp1}), (HtCr2U, HtS2U, HtU2S), _) equation
739+
(ut, (HtCr2U, HtS2U, HtU2S), expListList) = insertUnitInEquation(exp1, (HtCr2U, HtS2U, HtU2S), inUt);
740+
then (ut, (HtCr2U, HtS2U, HtU2S), expListList);
741+
724742
//DER
725743
case (DAE.CALL(path = Absyn.IDENT(name = "der"), expLst = {exp1}), (HtCr2U, HtS2U, HtU2S), Unit.UNIT()) equation
726744
(Unit.MASTER(lcr), (HtCr2U, HtS2U, HtU2S), expListList) = insertUnitInEquation(exp1, (HtCr2U, HtS2U, HtU2S), Unit.MASTER({}));
@@ -767,21 +785,23 @@ algorithm
767785

768786
//IFEXP
769787
case (DAE.IFEXP(exp1, exp2, exp3), (HtCr2U, HtS2U, HtU2S), _) equation
770-
(_, (HtCr2U, HtS2U, HtU2S), expListList) = insertUnitInEquation(exp1, (HtCr2U, HtS2U, HtU2S), Unit.MASTER({}));
788+
//(_, (HtCr2U, HtS2U, HtU2S), expListList) = insertUnitInEquation(exp1, (HtCr2U, HtS2U, HtU2S), Unit.MASTER({}));
771789
(ut, (HtCr2U, HtS2U, HtU2S), expListList2) = insertUnitInEquation(exp2, (HtCr2U, HtS2U, HtU2S), inUt);
772790
(ut2, (HtCr2U, HtS2U, HtU2S), expListList3) = insertUnitInEquation(exp3, (HtCr2U, HtS2U, HtU2S), ut);
773791
(true, ut, HtCr2U) = UnitTypesEqual(ut, ut2, HtCr2U);
774-
expListList = listAppend(expListList, expListList2);
775-
expListList = listAppend(expListList, expListList3);
792+
//expListList = listAppend(expListList, expListList2);
793+
//expListList = listAppend(expListList, expListList3);
794+
expListList = listAppend(expListList2, expListList3);
776795
then (ut, (HtCr2U, HtS2U, HtU2S), expListList);
777796

778797
case (DAE.IFEXP(exp1, exp2, exp3), (HtCr2U, HtS2U, HtU2S), _) equation
779-
(_, (HtCr2U, HtS2U, HtU2S), expListList) = insertUnitInEquation(exp1, (HtCr2U, HtS2U, HtU2S), Unit.MASTER({}));
798+
//(_, (HtCr2U, HtS2U, HtU2S), expListList) = insertUnitInEquation(exp1, (HtCr2U, HtS2U, HtU2S), Unit.MASTER({}));
780799
(ut, (HtCr2U, HtS2U, HtU2S), expListList2) = insertUnitInEquation(exp2, (HtCr2U, HtS2U, HtU2S), inUt);
781800
(ut2, (HtCr2U, HtS2U, HtU2S), expListList3) = insertUnitInEquation(exp3, (HtCr2U, HtS2U, HtU2S), ut);
782801
(false, _, _) = UnitTypesEqual(ut, ut2, HtCr2U);
783-
expListList = listAppend(expListList, expListList2);
784-
expListList = listAppend(expListList, expListList3);
802+
//expListList = listAppend(expListList, expListList2);
803+
//expListList = listAppend(expListList, expListList3);
804+
expListList = listAppend(expListList2, expListList3);
785805
expListList = {(exp2, ut), (exp3, ut2)}::expListList;
786806
then (Unit.MASTER({}), (HtCr2U, HtS2U, HtU2S), expListList);
787807

@@ -801,26 +821,6 @@ algorithm
801821
expListList = {(exp1, ut), (exp2, ut2)}::expListList;
802822
then (Unit.MASTER({}), (HtCr2U, HtS2U, HtU2S), expListList);
803823

804-
//all other BINARIES
805-
case (DAE.BINARY(), (HtCr2U, HtS2U, HtU2S), _)
806-
then (Unit.MASTER({}), (HtCr2U, HtS2U, HtU2S), {});
807-
808-
//LBINARY
809-
case (DAE.LBINARY(), (HtCr2U, HtS2U, HtU2S), _)
810-
then (Unit.MASTER({}), (HtCr2U, HtS2U, HtU2S), {});
811-
812-
//LUNARY
813-
case (DAE.LUNARY(), (HtCr2U, HtS2U, HtU2S), _)
814-
then (Unit.MASTER({}), (HtCr2U, HtS2U, HtU2S), {});
815-
816-
//MATRIX
817-
case (DAE.MATRIX(), (HtCr2U, HtS2U, HtU2S), _)
818-
then (Unit.MASTER({}), (HtCr2U, HtS2U, HtU2S), {});
819-
820-
//ARRAY
821-
case (DAE.ARRAY(), (HtCr2U, HtS2U, HtU2S), _)
822-
then (Unit.MASTER({}), (HtCr2U, HtS2U, HtU2S), {});
823-
824824
//CALL
825825
case (DAE.CALL(expLst=ExpList), (HtCr2U, HtS2U, HtU2S), _) equation
826826
(HtCr2U, HtS2U, HtU2S, expListList) = foldCallArg(ExpList, HtCr2U, HtS2U, HtU2S);
@@ -831,22 +831,6 @@ algorithm
831831
(ut, (HtCr2U, HtS2U, HtU2S), expListList) = insertUnitInEquation(exp1, (HtCr2U, HtS2U, HtU2S), inUt);
832832
then (ut, (HtCr2U, HtS2U, HtU2S), expListList);
833833

834-
//ICONST
835-
case (DAE.ICONST(), (HtCr2U, HtS2U, HtU2S), _)
836-
then (Unit.MASTER({}), (HtCr2U, HtS2U, HtU2S) , {});
837-
838-
//BCONST
839-
case (DAE.BCONST(), (HtCr2U, HtS2U, HtU2S), _)
840-
then (Unit.MASTER({}), (HtCr2U, HtS2U, HtU2S) , {});
841-
842-
//SCONST
843-
case (DAE.SCONST(), (HtCr2U, HtS2U, HtU2S), _)
844-
then (Unit.MASTER({}), (HtCr2U, HtS2U, HtU2S) , {});
845-
846-
//RCONST
847-
case (DAE.RCONST(), (HtCr2U, HtS2U, HtU2S), _)
848-
then (Unit.MASTER({}), (HtCr2U, HtS2U, HtU2S) , {});
849-
850834
//"time"
851835
case (DAE.CREF(componentRef=cr), (HtCr2U, HtS2U, HtU2S), _) equation
852836
true = ComponentReference.crefEqual(cr, DAE.crefTime);
@@ -860,14 +844,9 @@ algorithm
860844
ut = BaseHashTable.get(cr, HtCr2U);
861845
then (ut, inTpl, {});
862846

863-
//NO UNIT IN EQUATION
864-
case (DAE.CREF(), _, _)
865-
then (Unit.MASTER({}), inTpl, {});
866-
867847
// all unhandled expressions, e.g. DAE.CAST, DAE.TUPLE, ...
868848
else
869849
//Error.addInternalError("./Compiler/BackEnd/UnitCheck.mo: function insertUnitInEquation failed for " + ExpressionDump.printExpStr(inEq), sourceInfo());
870-
//then fail();
871850
then (Unit.MASTER({}), inTpl, {});
872851
end matchcontinue;
873852
end insertUnitInEquation;

0 commit comments

Comments
 (0)