@@ -60,6 +60,7 @@ protected import Global;
6060protected import HashSet ;
6161protected import List ;
6262protected import MetaModelica.Dangerous ;
63+ protected import StringUtil ;
6364protected import System ;
6465protected import Util ;
6566protected import Types ;
@@ -1733,8 +1734,8 @@ algorithm
17331734 outAsserts := matchcontinue(inVar)
17341735 local
17351736 DAE . Exp e, cond, msg;
1736- list < Option < DAE . Exp >> minmax ;
1737- String str, format;
1737+ Option < DAE . Exp > min, max ;
1738+ String str, varStr, format;
17381739 DAE . Type tp;
17391740 DAE . ComponentRef name;
17401741 Option < DAE . VariableAttributes > attr;
@@ -1745,17 +1746,20 @@ algorithm
17451746 then inAsserts;
17461747
17471748 case BackendDAE . VAR (varName= name, values= attr, varType= varType, source= source) equation
1748- minmax = DAEUtil . getMinMax(attr);
1749+ (min, max) = DAEUtil . getMinMaxValues(attr);
1750+ if isNone(min) and isNone(max) then
1751+ fail();
1752+ end if ;
17491753 e = Expression . crefExp(name);
1754+ varStr = ComponentReference . printComponentRefStr(name);
17501755 tp = BackendDAEUtil . makeExpType(varType);
17511756
17521757 // do not add if const true
1753- cond = getMinMaxAsserts1(minmax , e, tp);
1758+ cond = getMinMaxAsserts1(min, max , e, tp);
17541759 (cond, _) = ExpressionSimplify . simplify(cond);
17551760 false = Expression . isConstTrue(cond);
1761+ str = getMinMaxAsserts1Str(min, max, ComponentReference . printComponentRefStr(name));
17561762
1757- str = "Variable " + ComponentReference . printComponentRefStr(name) + " out of [min, max] interval: " ;
1758- str = str + ExpressionDump . printExpStr(cond) + " has value: " ;
17591763 // if is real use %g otherwise use %d (ints and enums)
17601764 format = if Types . isRealOrSubTypeReal(tp) then "g" else "d" ;
17611765 msg = DAE . BINARY (DAE . SCONST (str), DAE . ADD (DAE . T_STRING_DEFAULT ), DAE . CALL (Absyn . IDENT ("String" ), {e, DAE . SCONST (format)}, DAE . callAttrBuiltinString));
@@ -1767,26 +1771,49 @@ algorithm
17671771end getMinMaxAsserts;
17681772
17691773protected function getMinMaxAsserts1 "author: Frenkel TUD 2011-03"
1770- input list < Option < DAE . Exp >> ominmax ;
1774+ input Option < DAE . Exp > omin,omax ;
17711775 input DAE . Exp e;
17721776 input DAE . Type tp;
17731777 output DAE . Exp cond;
17741778algorithm
1775- cond := match ominmax
1779+ cond := match (omin,omax)
17761780 local
17771781 DAE . Exp min, max;
17781782
1779- case SOME (min)::( SOME (max)::{} )
1783+ case ( SOME (min), SOME (max))
17801784 then DAE . LBINARY (DAE . RELATION (e, DAE . GREATEREQ (tp), min, -1 , NONE ()), DAE . AND (DAE . T_BOOL_DEFAULT ), DAE . RELATION (e, DAE . LESSEQ (tp), max, -1 , NONE ()));
17811785
1782- case SOME (min)::( NONE ()::{} )
1786+ case ( SOME (min), NONE ())
17831787 then DAE . RELATION (e, DAE . GREATEREQ (tp), min, -1 , NONE ());
17841788
1785- case NONE ()::( SOME (max)::{} )
1789+ case ( NONE (), SOME (max))
17861790 then DAE . RELATION (e, DAE . LESSEQ (tp), max, -1 , NONE ());
17871791 end match;
17881792end getMinMaxAsserts1;
17891793
1794+ protected function getMinMaxAsserts1Str "author: Frenkel TUD 2011-03"
1795+ input Option < DAE . Exp > omin,omax;
1796+ input String varStr;
1797+ input Boolean nominal= false ;
1798+ output String msg;
1799+ protected
1800+ String vstr = if nominal then "Nominal variable " else "Variable " ;
1801+ algorithm
1802+ msg := match (omin,omax)
1803+ local
1804+ DAE . Exp min, max;
1805+
1806+ case (SOME (min),SOME (max))
1807+ then StringUtil . stringAppend9(vstr,"violating min/max constraint: " ,ExpressionDump . printExpStr(min)," <= " ,varStr," <= " ,ExpressionDump . printExpStr(max),", has value: " );
1808+
1809+ case (SOME (min),NONE ())
1810+ then StringUtil . stringAppend9(vstr,"violating min constraint: " ,ExpressionDump . printExpStr(min)," <= " ,varStr,", has value: " );
1811+
1812+ case (NONE (),SOME (max))
1813+ then StringUtil . stringAppend9(vstr,"violating max constraint: " ,varStr," <= " ,ExpressionDump . printExpStr(max),", has value: " );
1814+ end match;
1815+ end getMinMaxAsserts1Str;
1816+
17901817public function getNominalAssert "author: Frenkel TUD 2011-03"
17911818 input BackendDAE . Var inVar;
17921819 input list< DAE . Algorithm > inAsserts;
@@ -1796,8 +1823,8 @@ algorithm
17961823 outAsserts := matchcontinue(inVar)
17971824 local
17981825 DAE . Exp e, cond, msg;
1799- list < Option < DAE . Exp >> minmax ;
1800- String str, format;
1826+ Option < DAE . Exp > min, max ;
1827+ String str, varStr, format;
18011828 DAE . Type tp;
18021829 DAE . ComponentRef name;
18031830 Option < DAE . VariableAttributes > attr;
@@ -1808,16 +1835,15 @@ algorithm
18081835 then inAsserts;
18091836
18101837 case BackendDAE . VAR (varName= name, values= attr as SOME (DAE . VAR_ATTR_REAL (nominal= SOME (e))), varType= varType, source= source) equation
1811- minmax = DAEUtil . getMinMax (attr);
1838+ (min, max) = DAEUtil . getMinMaxValues (attr);
18121839 tp = BackendDAEUtil . makeExpType(varType);
18131840
18141841 // do not add if const true
1815- cond = getMinMaxAsserts1(minmax , e, tp);
1842+ cond = getMinMaxAsserts1(min, max , e, tp);
18161843 (cond, _) = ExpressionSimplify . simplify(cond);
18171844 false = Expression . isConstTrue(cond);
1818-
1819- str = "Nominal " + ComponentReference . printComponentRefStr(name) + " out of [min, max] interval: " ;
1820- str = str + ExpressionDump . printExpStr(cond) + " has value: " ;
1845+ varStr = ComponentReference . printComponentRefStr(name);
1846+ str = getMinMaxAsserts1Str(min, max, ComponentReference . printComponentRefStr(name), nominal= true );
18211847 // if is real use %g otherwise use %d (ints and enums)
18221848 format = if Types . isRealOrSubTypeReal(tp) then "g" else "d" ;
18231849 msg = DAE . BINARY (DAE . SCONST (str), DAE . ADD (DAE . T_STRING_DEFAULT ), DAE . CALL (Absyn . IDENT ("String" ), {e, DAE . SCONST (format)}, DAE . callAttrBuiltinString));
0 commit comments