Skip to content

Commit

Permalink
Change Absyn.REAL to store a String instead of a Real in order to unp…
Browse files Browse the repository at this point in the history
…arse without changes

git-svn-id: https://openmodelica.org/svn/OpenModelica/trunk@20744 f25d12d1-65f4-0310-ae8a-bbce733d8d8e
  • Loading branch information
sjoelund committed May 21, 2014
1 parent 269695c commit 5285279
Show file tree
Hide file tree
Showing 21 changed files with 2,794 additions and 2,593 deletions.
19 changes: 9 additions & 10 deletions Compiler/FrontEnd/Absyn.mo
Expand Up @@ -700,7 +700,7 @@ uniontype Exp "The Exp uniontype is the container of a Modelica expression.
end INTEGER;

record REAL
Real value;
String value "String representation of a Real, in order to unparse without changing the user's display preference";
end REAL;

record CREF
Expand Down Expand Up @@ -4229,25 +4229,24 @@ public function expEqual "Returns true if two expressions are equal"
algorithm
equal := matchcontinue(exp1,exp2)
local
Boolean b;
Exp x, y;
Integer i; Real r;
Integer i;
String r;

// real vs. integer
case (INTEGER(i), REAL(r))
equation
true = realEq(intReal(i), r);
then
true;
b = realEq(intReal(i), System.stringReal(r));
then b;

case (REAL(r), INTEGER(i))
equation
true = realEq(intReal(i), r);
then
true;
b = realEq(intReal(i), System.stringReal(r));
then b;

// anything else, exact match!
case (x, y) equation equality(x = y); then true;
case (x, y) equation failure(equality(x = y)); then false;
case (x, y) then valueEq(x,y);
end matchcontinue;
end expEqual;

Expand Down
6 changes: 3 additions & 3 deletions Compiler/FrontEnd/Builtin.mo
Expand Up @@ -172,19 +172,19 @@ protected constant SCode.Element displayUnit = SCode.COMPONENT("displayUnit",com

protected constant SCode.Element min = SCode.COMPONENT("min",commonPrefixes,
attrParam,Absyn.TPATH(Absyn.IDENT("RealType"),NONE()),
SCode.MOD(SCode.NOT_FINAL(),SCode.NOT_EACH(),{},SOME((Absyn.REAL(-1e+099),false)), Absyn.dummyInfo),SCode.noComment,NONE(),Absyn.dummyInfo);
SCode.MOD(SCode.NOT_FINAL(),SCode.NOT_EACH(),{},SOME((Absyn.REAL("-1e+099"),false)), Absyn.dummyInfo),SCode.noComment,NONE(),Absyn.dummyInfo);

protected constant SCode.Element max = SCode.COMPONENT("max",commonPrefixes,
attrParam,Absyn.TPATH(Absyn.IDENT("RealType"),NONE()),
SCode.MOD(SCode.NOT_FINAL(),SCode.NOT_EACH(),{},SOME((Absyn.REAL(1e+099),false)), Absyn.dummyInfo),SCode.noComment,NONE(),Absyn.dummyInfo);
SCode.MOD(SCode.NOT_FINAL(),SCode.NOT_EACH(),{},SOME((Absyn.REAL("1e+099"),false)), Absyn.dummyInfo),SCode.noComment,NONE(),Absyn.dummyInfo);

protected constant SCode.Element startOrigin = SCode.COMPONENT("startOrigin",commonPrefixes,
attrParam,Absyn.TPATH(Absyn.IDENT("StringType"),NONE()),
SCode.MOD(SCode.NOT_FINAL(),SCode.NOT_EACH(),{},SOME((Absyn.STRING("undefined"),false)), Absyn.dummyInfo),SCode.noComment,NONE(),Absyn.dummyInfo);

protected constant SCode.Element realStart = SCode.COMPONENT("start",commonPrefixes,
attrParam,Absyn.TPATH(Absyn.IDENT("RealType"),NONE()),
SCode.MOD(SCode.NOT_FINAL(),SCode.NOT_EACH(),{},SOME((Absyn.REAL(0.0),false)), Absyn.dummyInfo),SCode.noComment,NONE(),Absyn.dummyInfo);
SCode.MOD(SCode.NOT_FINAL(),SCode.NOT_EACH(),{},SOME((Absyn.REAL("0.0"),false)), Absyn.dummyInfo),SCode.noComment,NONE(),Absyn.dummyInfo);

protected constant SCode.Element integerStart = SCode.COMPONENT("start",commonPrefixes,
attrParam,Absyn.TPATH(Absyn.IDENT("IntegerType"),NONE()),
Expand Down
7 changes: 3 additions & 4 deletions Compiler/FrontEnd/Dump.mo
Expand Up @@ -1924,9 +1924,8 @@ algorithm
then
();

case (Absyn.REAL(value = r))
case (Absyn.REAL(value = s))
equation
s = realString(r);
Print.printBuf("Absyn.REAL(");
Print.printBuf(s);
Print.printBuf(")");
Expand Down Expand Up @@ -4514,10 +4513,10 @@ algorithm
Print.printBuf(intString(i));
Print.printBuf(" end Absyn.INTEGER;");
then ();
case Absyn.REAL(value = r)
case Absyn.REAL(value = s)
equation
Print.printBuf("record Absyn.REAL value = ");
Print.printBuf(realString(r));
Print.printBuf(s);
Print.printBuf(" end Absyn.REAL;");
then ();
case Absyn.CREF(componentRef)
Expand Down
15 changes: 11 additions & 4 deletions Compiler/FrontEnd/Expression.mo
Expand Up @@ -75,6 +75,7 @@ protected import List;
protected import Patternm;
protected import Prefix;
protected import Static;
protected import System; // stringReal
protected import Types;
protected import Util;

Expand Down Expand Up @@ -168,7 +169,10 @@ algorithm
DAE.Dimensions dims;

case (DAE.ICONST(integer = i)) then Absyn.INTEGER(i);
case (DAE.RCONST(real = r)) then Absyn.REAL(r);
case (DAE.RCONST(real = r))
equation
s = realString(r);
then Absyn.REAL(s);
case (DAE.SCONST(string = s)) then Absyn.STRING(s);
case (DAE.BCONST(bool = b)) then Absyn.BOOL(b);
case (DAE.ENUM_LITERAL(name = path))
Expand Down Expand Up @@ -356,8 +360,8 @@ algorithm
case DAE.T_BOOL(source=_) then Absyn.BOOL(false);
case DAE.T_STRING(source=_) then Absyn.STRING("");
case DAE.T_INTEGER(source=_) then Absyn.INTEGER(0);
case DAE.T_REAL(source=_) then Absyn.REAL(0.0);
case DAE.T_UNKNOWN(source=_) then Absyn.REAL(0.0); /* Look at the crap unelabMod needs... */
case DAE.T_REAL(source=_) then Absyn.REAL("0.0");
case DAE.T_UNKNOWN(source=_) then Absyn.REAL("0.0"); /* Look at the crap unelabMod needs... */
end match;
end unleabZeroExpFromType;

Expand Down Expand Up @@ -10526,7 +10530,10 @@ algorithm
Option<DAE.Exp> oe;

case (Absyn.INTEGER(i)) then DAE.ICONST(i);
case (Absyn.REAL(r)) then DAE.RCONST(r);
case (Absyn.REAL(s))
equation
r = System.stringReal(s);
then DAE.RCONST(r);
case (Absyn.BOOL(b)) then DAE.BCONST(b);
case (Absyn.STRING(s)) then DAE.SCONST(s);

Expand Down
4 changes: 3 additions & 1 deletion Compiler/FrontEnd/NFInst.mo
Expand Up @@ -1921,7 +1921,9 @@ algorithm
Option<DAE.Exp> odexp;
Globals globals;

case (Absyn.REAL(value = rval), _, _, globals)
case (Absyn.REAL(value = sval), _, _, globals)
equation
rval = System.stringReal(sval);
then (DAE.RCONST(rval), globals);

case (Absyn.INTEGER(value = ival), _, _, globals)
Expand Down
6 changes: 4 additions & 2 deletions Compiler/FrontEnd/Patternm.mo
Expand Up @@ -203,9 +203,10 @@ algorithm
et = validPatternType(ty,DAE.T_INTEGER_DEFAULT,inLhs,info);
then (cache,DAE.PAT_CONSTANT(et,DAE.ICONST(i)));

case (cache,_,Absyn.REAL(r),_,_,_)
case (cache,_,Absyn.REAL(str),_,_,_)
equation
et = validPatternType(ty,DAE.T_REAL_DEFAULT,inLhs,info);
r = System.stringReal(str);
then (cache,DAE.PAT_CONSTANT(et,DAE.RCONST(r)));

case (cache,_,Absyn.UNARY(Absyn.UMINUS(),Absyn.INTEGER(i)),_,_,_)
Expand All @@ -214,9 +215,10 @@ algorithm
i = -i;
then (cache,DAE.PAT_CONSTANT(et,DAE.ICONST(i)));

case (cache,_,Absyn.UNARY(Absyn.UMINUS(),Absyn.REAL(r)),_,_,_)
case (cache,_,Absyn.UNARY(Absyn.UMINUS(),Absyn.REAL(str)),_,_,_)
equation
et = validPatternType(ty,DAE.T_REAL_DEFAULT,inLhs,info);
r = System.stringReal(str);
r = realNeg(r);
then (cache,DAE.PAT_CONSTANT(et,DAE.RCONST(r)));

Expand Down
11 changes: 7 additions & 4 deletions Compiler/FrontEnd/SCodeUtil.mo
Expand Up @@ -1072,12 +1072,15 @@ protected function translateDefineunitParam2 " help function to translateElement
algorithm
weightOpt := matchcontinue(inArgs,inArg)
local
String name, arg; Real r;
String name, arg, s;
Real r;
list<Absyn.NamedArg> args;

case(Absyn.NAMEDARG(name,Absyn.REAL(r))::_,arg) equation
true = name ==& arg;
then SOME(r);
case(Absyn.NAMEDARG(name,Absyn.REAL(s))::_,arg)
equation
true = name ==& arg;
r = System.stringReal(s);
then SOME(r);
case({},_) then NONE();
case(_::args,arg) then translateDefineunitParam2(args,arg);
end matchcontinue;
Expand Down
11 changes: 7 additions & 4 deletions Compiler/FrontEnd/Static.mo
Expand Up @@ -579,9 +579,10 @@ algorithm
case (cache,_,Absyn.INTEGER(value = i),_,st,_,_,_,_)
then (cache,DAE.ICONST(i),DAE.PROP(DAE.T_INTEGER_DEFAULT,DAE.C_CONST()),st);

case (cache,_,Absyn.REAL(value = r),_,st,_,_,_,_)
then
(cache,DAE.RCONST(r),DAE.PROP(DAE.T_REAL_DEFAULT,DAE.C_CONST()),st);
case (cache,_,Absyn.REAL(value = s),_,st,_,_,_,_)
equation
r = System.stringReal(s);
then (cache,DAE.RCONST(r),DAE.PROP(DAE.T_REAL_DEFAULT,DAE.C_CONST()),st);

case (cache,_,Absyn.STRING(value = s),_,st,_,_,_,_)
equation
Expand Down Expand Up @@ -1817,7 +1818,9 @@ algorithm

case (cache,_,Absyn.INTEGER(value = i),_,_,_) then (cache,DAE.ICONST(i),DAE.PROP(DAE.T_INTEGER_DEFAULT,DAE.C_CONST())); /* impl */

case (cache,_,Absyn.REAL(value = r),_,_,_)
case (cache,_,Absyn.REAL(value = s),_,_,_)
equation
r = System.stringReal(s);
then
(cache,DAE.RCONST(r),DAE.PROP(DAE.T_REAL_DEFAULT,DAE.C_CONST()));

Expand Down
4 changes: 2 additions & 2 deletions Compiler/FrontEnd/UnitAbsynBuilder.mo
Expand Up @@ -214,7 +214,7 @@ algorithm
Absyn.DEFINEUNIT("cd",{}),
Absyn.DEFINEUNIT("rad",{Absyn.NAMEDARG("exp",Absyn.STRING("m/m"))}),
Absyn.DEFINEUNIT("sr",{Absyn.NAMEDARG("exp",Absyn.STRING("m2/m2"))}),
Absyn.DEFINEUNIT("Hz",{Absyn.NAMEDARG("exp",Absyn.STRING("s-1")),Absyn.NAMEDARG("weight",Absyn.REAL(0.8))}),
Absyn.DEFINEUNIT("Hz",{Absyn.NAMEDARG("exp",Absyn.STRING("s-1")),Absyn.NAMEDARG("weight",Absyn.REAL("0.8"))}),
Absyn.DEFINEUNIT("N",{Absyn.NAMEDARG("exp",Absyn.STRING("m.kg.s-2"))}),
Absyn.DEFINEUNIT("Pa",{Absyn.NAMEDARG("exp",Absyn.STRING("N/m2"))}),
Absyn.DEFINEUNIT("W",{Absyn.NAMEDARG("exp",Absyn.STRING("J/s"))}),
Expand All @@ -229,7 +229,7 @@ algorithm
Absyn.DEFINEUNIT("H",{Absyn.NAMEDARG("exp",Absyn.STRING("Wb/A"))}),
Absyn.DEFINEUNIT("lm",{Absyn.NAMEDARG("exp",Absyn.STRING("cd.sr"))}),
Absyn.DEFINEUNIT("lx",{Absyn.NAMEDARG("exp",Absyn.STRING("lm/m2"))}),
Absyn.DEFINEUNIT("Bq",{Absyn.NAMEDARG("exp",Absyn.STRING("s-1")),Absyn.NAMEDARG("weight",Absyn.REAL(0.8))}),
Absyn.DEFINEUNIT("Bq",{Absyn.NAMEDARG("exp",Absyn.STRING("s-1")),Absyn.NAMEDARG("weight",Absyn.REAL("0.8"))}),
Absyn.DEFINEUNIT("Gy",{Absyn.NAMEDARG("exp",Absyn.STRING("J/kg"))}),
Absyn.DEFINEUNIT("Sv",{Absyn.NAMEDARG("exp",Absyn.STRING("cd.sr"))}),
Absyn.DEFINEUNIT("kat",{Absyn.NAMEDARG("exp",Absyn.STRING("s-1.mol"))})
Expand Down
5 changes: 3 additions & 2 deletions Compiler/Script/CevalScript.mo
Expand Up @@ -493,7 +493,8 @@ protected function getConst
algorithm
outExp := matchcontinue(inAbsynExp, inExpType)
local
Integer i; Real r;
Integer i;
Real r;
Absyn.Exp exp;
String str;

Expand All @@ -512,7 +513,7 @@ algorithm
DAE.RCONST(r);

case (Absyn.INTEGER(i), DAE.T_INTEGER(source = _)) then DAE.ICONST(i);
case (Absyn.REAL(r), DAE.T_REAL(source = _)) then DAE.RCONST(r);
case (Absyn.REAL(str), DAE.T_REAL(source = _)) equation r = System.stringReal(str); then DAE.RCONST(r);
case (Absyn.INTEGER(i), DAE.T_REAL(source = _)) equation r = intReal(i); then DAE.RCONST(r);

case (exp, _)
Expand Down
8 changes: 4 additions & 4 deletions Compiler/Script/Interactive.mo
Expand Up @@ -3071,15 +3071,15 @@ algorithm
list<Absyn.Exp> exp_list_1,exp_list;
list<list<Absyn.Exp>> exp_list_list_1,exp_list_list;
Absyn.CodeNode code_1,code;
case (Absyn.INTEGER(value = i),_,_) then Absyn.INTEGER(i);
case (Absyn.REAL(value = r),_,_) then Absyn.REAL(r);
case (Absyn.INTEGER(value = _),_,_) then inExp1;
case (Absyn.REAL(value = _),_,_) then inExp1;
case (Absyn.CREF(componentRef = cr),old_comp,new_comp)
equation
cr_1 = replaceStartInComponentRef(cr, old_comp, new_comp);
then
Absyn.CREF(cr_1);
case (Absyn.STRING(value = s),_,_) then Absyn.STRING(s);
case (Absyn.BOOL(value = b),_,_) then Absyn.BOOL(b);
case (Absyn.STRING(value = _),_,_) then inExp1;
case (Absyn.BOOL(value = _),_,_) then inExp1;
case (Absyn.BINARY(exp1 = exp1,op = op,exp2 = exp2),old_comp,new_comp)
equation
exp1_1 = renameComponentInExp(exp1, old_comp, new_comp);
Expand Down

0 comments on commit 5285279

Please sign in to comment.