Skip to content

Commit

Permalink
- Merging (except Interactive.mo)
Browse files Browse the repository at this point in the history
  • Loading branch information
sjoelund committed Nov 4, 2010
2 parents a7d7649 + eb028e2 commit 502b665
Show file tree
Hide file tree
Showing 14 changed files with 472 additions and 98 deletions.
81 changes: 81 additions & 0 deletions Compiler/Absyn.mo
Expand Up @@ -4479,4 +4479,85 @@ algorithm
end matchcontinue;
end canonIfExp;

public function onlyLiteralsInAnnotationMod
"@author: adrpo
This function checks if a modification only contains literal expressions"
input list<ElementArg> inMod;
output Boolean onlyLiterals;
algorithm
onlyLiterals := matchcontinue(inMod)
local
Modification mod;
list<ElementArg> dive, rest;
Option<Exp> expOpt;
Boolean b1, b2, b3, b;

case ({}) then true;

// search inside, some(exp)
case (MODIFICATION(modification = SOME(CLASSMOD(dive, expOpt))) :: rest)
equation
b1 = onlyLiteralsInExpOpt(expOpt);
b2 = onlyLiteralsInAnnotationMod(dive);
b3 = onlyLiteralsInAnnotationMod(rest);
b = boolAnd(b1, boolAnd(b2, b3));
then
b;

case (_ :: rest)
equation
b = onlyLiteralsInAnnotationMod(rest);
then
b;

// failed above, return false
case (_) then false;

end matchcontinue;
end onlyLiteralsInAnnotationMod;

protected function onlyLiteralsInExpOpt
"@author: adrpo
This function checks if an optional expression only contains literal expressions"
input Option<Exp> inExpOpt;
output Boolean onlyLiterals;
algorithm
onlyLiterals := matchcontinue(inExpOpt)
local
Exp exp;
Boolean b;

case (NONE()) then true;

// search inside, some(exp)
case (SOME(exp))
equation
((_, b)) = traverseExp(exp, onlyLiteralsInExp, true);
then
b;
end matchcontinue;
end onlyLiteralsInExpOpt;

protected function onlyLiteralsInExp
"@author: adrpo
Visitor function for checking if Absyn.Exp contains only literals, NO CREFS!"
input tuple<Exp, Boolean> tpl;
output tuple<Exp, Boolean> outTpl;
algorithm
outTpl := matchcontinue(tpl)
local
Option<Path> optPath;
Path cname,path,usesName,cname2;
Exp e;
ComponentRef cr;
Boolean b;

// crefs, return false
case((e as CREF(cr), _)) then ((e,false));
// anything else, return the same!
case(tpl) then tpl;

end matchcontinue;
end onlyLiteralsInExp;

end Absyn;
13 changes: 10 additions & 3 deletions Compiler/Builtin.mo
Expand Up @@ -386,9 +386,13 @@ protected constant DAE.Type int2int=(
DAE.T_FUNCTION({("x",DAE.T_INTEGER_DEFAULT)},
DAE.T_INTEGER_DEFAULT,DAE.NO_INLINE()),NONE());

protected constant DAE.Type enumeration2int=(
DAE.T_FUNCTION({("x",(DAE.T_ENUMERATION(NONE(), Absyn.IDENT(""), {}, {}, {}),NONE()))},
DAE.T_INTEGER_DEFAULT,DAE.NO_INLINE()),NONE());
protected constant tuple<DAE.TType, Option<Type_a>> int2bool=(
DAE.T_FUNCTION({("x",DAE.T_INTEGER_DEFAULT)},
DAE.T_BOOL_DEFAULT,DAE.NO_INLINE),NONE);

protected constant tuple<DAE.TType, Option<Type_a>> enumeration2int=(
DAE.T_FUNCTION({("x",(DAE.T_ENUMERATION(NONE, Absyn.IDENT(""), {}, {}, {}),NONE))},
DAE.T_INTEGER_DEFAULT,DAE.NO_INLINE),NONE);

protected constant DAE.Type intInt2int=(
DAE.T_FUNCTION(
Expand Down Expand Up @@ -2461,6 +2465,9 @@ algorithm
env = Env.extendFrameT(env, "rem", intInt2int);
env = Env.extendFrameT(env, "ceil", real2real);
envb = Env.extendFrameT(env, "floor", real2real);
env = Env.extendFrameT(envb, "boolean", bool2bool);
env = Env.extendFrameT(envb, "boolean", real2bool);
env = Env.extendFrameT(envb, "boolean", int2bool);
env = Env.extendFrameT(envb, "integer", real2int);
env = Env.extendFrameT(env, "Integer", enumeration2int);
env = Env.extendFrameT(env, "abs", real2real) "differentiable functions" ;
Expand Down
52 changes: 52 additions & 0 deletions Compiler/Ceval.mo
Expand Up @@ -1051,6 +1051,7 @@ algorithm
case "arccos" then cevalBuiltinAcos;
case "arctan" then cevalBuiltinAtan;
case "integer" then cevalBuiltinInteger;
case "boolean" then cevalBuiltinBoolean;
case "mod" then cevalBuiltinMod;
case "max" then cevalBuiltinMax;
case "min" then cevalBuiltinMin;
Expand Down Expand Up @@ -4044,6 +4045,57 @@ algorithm
end matchcontinue;
end cevalBuiltinInteger;

protected function cevalBuiltinBoolean "function cevalBuiltinBoolean
@author: adrpo
Evaluates the builtin boolean operator"
input Env.Cache inCache;
input Env.Env inEnv;
input list<DAE.Exp> inExpExpLst;
input Boolean inBoolean;
input Option<Interactive.InteractiveSymbolTable> inInteractiveInteractiveSymbolTableOption;
input Msg inMsg;
output Env.Cache outCache;
output Values.Value outValue;
output Option<Interactive.InteractiveSymbolTable> outInteractiveInteractiveSymbolTableOption;
algorithm
(outCache,outValue,outInteractiveInteractiveSymbolTableOption):=
matchcontinue (inCache,inEnv,inExpExpLst,inBoolean,inInteractiveInteractiveSymbolTableOption,inMsg)
local
Real rv;
Integer iv;
Boolean bv;
list<Env.Frame> env;
DAE.Exp exp;
Boolean impl;
Option<Interactive.InteractiveSymbolTable> st;
Msg msg;
Env.Cache cache;

// real -> bool
case (cache,env,{exp},impl,st,msg)
equation
(cache,Values.REAL(rv),_) = ceval(cache, env, exp, impl, st, NONE, msg);
bv = Util.if_(realEq(rv, 0.0), false, true);
then
(cache,Values.BOOL(bv),st);

// integer -> bool
case (cache,env,{exp},impl,st,msg)
equation
(cache,Values.INTEGER(iv),_) = ceval(cache, env, exp, impl, st, NONE, msg);
bv = Util.if_(intEq(iv, 0), false, true);
then
(cache,Values.BOOL(bv),st);

// bool -> bool
case (cache,env,{exp},impl,st,msg)
equation
(cache,Values.BOOL(bv),_) = ceval(cache, env, exp, impl, st, NONE, msg);
then
(cache,Values.BOOL(bv),st);
end matchcontinue;
end cevalBuiltinBoolean;

protected function cevalBuiltinRooted
"function cevalBuiltinRooted
author: adrpo
Expand Down
64 changes: 32 additions & 32 deletions Compiler/Constants.mo
Expand Up @@ -173,22 +173,22 @@ public constant String annotationsModelica_3_x = "
package GraphicalAnnotationsProgram____ end GraphicalAnnotationsProgram____;
// type DrawingUnit = Real(final unit=\"mm\");
// type DrawingUnit = Real/*(final unit=\"mm\")*/;
// type Point = DrawingUnit[2] \"{x, y}\";
// type Extent = Point[2] \"Defines a rectangular area {{x1, y1}, {x2, y2}}\";
//partial
record GraphicItem
Boolean visible = true;
Real origin[2](each final unit=\"mm\") = {0.0, 0.0};
Real origin[2]/*(each final unit=\"mm\")*/ = {0.0, 0.0};
Real rotation(quantity=\"angle\", unit=\"deg\")=0;
end GraphicItem;
record CoordinateSystem
Real extent[2,2](each final unit=\"mm\");
Real extent[2,2]/*(each final unit=\"mm\")*/;
Boolean preserveAspectRatio=true;
Real initialScale = 0.1;
Real grid[2](each final unit=\"mm\") = {1.0, 1.0};
Real grid[2]/*(each final unit=\"mm\")*/ = {1.0, 1.0};
end CoordinateSystem;
// example
Expand Down Expand Up @@ -226,9 +226,9 @@ record FilledShape \"Style attributes for filled shapes\"
end FilledShape;
record Transformation
Real origin[2](each final unit=\"mm\") = {0.0, 0.0};
Real extent[2,2](each final unit=\"mm\");
Real rotation(quantity=\"angle\", unit=\"deg\")=0;
Real origin[2]/*(each final unit=\"mm\")*/ = {0.0, 0.0};
Real extent[2,2]/*(each final unit=\"mm\")*/;
Real rotation/*(quantity=\"angle\", unit=\"deg\")*/=0;
end Transformation;
record Placement
Expand All @@ -238,36 +238,36 @@ record Placement
end Placement;
record IconMap
Real extent[2,2](each final unit=\"mm\") = {{0, 0}, {0, 0}};
Real extent[2,2]/*(each final unit=\"mm\")*/ = {{0, 0}, {0, 0}};
Boolean primitivesVisible = true;
end IconMap;
record DiagramMap
Real extent[2,2](each final unit=\"mm\") = {{0, 0}, {0, 0}};
Real extent[2,2]/*(each final unit=\"mm\")*/ = {{0, 0}, {0, 0}};
Boolean primitivesVisible = true;
end DiagramMap;
record Line
//extends GraphicItem;
Boolean visible = true;
Real origin[2](each final unit=\"mm\") = {0.0, 0.0};
Real rotation(quantity=\"angle\", unit=\"deg\")=0;
Real origin[2]/*(each final unit=\"mm\")*/ = {0.0, 0.0};
Real rotation/*(quantity=\"angle\", unit=\"deg\")*/ = 0;
// end GraphicItem
Real points[2,:](each final unit=\"mm\");
Real points[2,:]/*(each final unit=\"mm\")*/;
Integer color[3] = {0, 0, 0};
LinePattern pattern = LinePattern.Solid;
Real thickness(final unit=\"mm\") = 0.25;
Real thickness/*(final unit=\"mm\")*/ = 0.25;
Arrow arrow[2] = {Arrow.None, Arrow.None} \"{start arrow, end arrow}\";
Real arrowSize(final unit=\"mm\")=3;
Real arrowSize/*(final unit=\"mm\")*/ = 3;
Smooth smooth = Smooth.None \"Spline\";
end Line;
record Polygon
//extends GraphicItem;
Boolean visible = true;
Real origin[2](each final unit=\"mm\") = {0.0, 0.0};
Real rotation(quantity=\"angle\", unit=\"deg\")=0;
Real origin[2]/*(each final unit=\"mm\")*/ = {0.0, 0.0};
Real rotation/*(quantity=\"angle\", unit=\"deg\")*/ = 0;
// end GraphicItem
//extends FilledShape;
Expand All @@ -278,15 +278,15 @@ record Polygon
Real lineThickness = 0.25 \"Line thickness\";
// end FilledShape
Real points[2,:](each final unit=\"mm\");
Real points[2,:]/*(each final unit=\"mm\")*/;
Smooth smooth = Smooth.None \"Spline outline\";
end Polygon;
record Rectangle
//extends GraphicItem;
Boolean visible = true;
Real origin[2](each final unit=\"mm\") = {0.0, 0.0};
Real rotation(quantity=\"angle\", unit=\"deg\")=0;
Real origin[2]/*(each final unit=\"mm\")*/ = {0.0, 0.0};
Real rotation/*(quantity=\"angle\", unit=\"deg\")*/ = 0;
// end GraphicItem
//extends FilledShape;
Expand All @@ -298,15 +298,15 @@ record Rectangle
// end FilledShape
BorderPattern borderPattern = BorderPattern.None;
Real extent[2,2](each final unit=\"mm\");
Real radius(final unit=\"mm\") = 0 \"Corner radius\";
Real extent[2,2]/*(each final unit=\"mm\")*/;
Real radius/*(final unit=\"mm\")*/ = 0 \"Corner radius\";
end Rectangle;
record Ellipse
//extends GraphicItem;
Boolean visible = true;
Real origin[2](each final unit=\"mm\") = {0.0, 0.0};
Real rotation(quantity=\"angle\", unit=\"deg\")=0;
Real origin[2]/*(each final unit=\"mm\")*/ = {0.0, 0.0};
Real rotation/*(quantity=\"angle\", unit=\"deg\")*/=0;
// end GraphicItem
//extends FilledShape;
Expand All @@ -317,16 +317,16 @@ record Ellipse
Real lineThickness = 0.25 \"Line thickness\";
// end FilledShape
Real extent[2,2](each final unit=\"mm\");
Real startAngle(quantity=\"angle\", unit=\"deg\")=0;
Real endAngle(quantity=\"angle\", unit=\"deg\")=360;
Real extent[2,2]/*(each final unit=\"mm\")*/;
Real startAngle/*(quantity=\"angle\", unit=\"deg\")*/ = 0;
Real endAngle/*(quantity=\"angle\", unit=\"deg\")*/ = 360;
end Ellipse;
record Text
//extends GraphicItem;
Boolean visible = true;
Real origin[2](each final unit=\"mm\") = {0.0, 0.0};
Real rotation(quantity=\"angle\", unit=\"deg\")=0;
Real origin[2]/*(each final unit=\"mm\")*/ = {0.0, 0.0};
Real rotation/*(quantity=\"angle\", unit=\"deg\")*/ = 0;
// end GraphicItem
//extends FilledShape;
Expand All @@ -337,7 +337,7 @@ record Text
Real lineThickness = 0.25 \"Line thickness\";
// end FilledShape
Real extent[2,2](each final unit=\"mm\");
Real extent[2,2]/*(each final unit=\"mm\")*/;
String textString;
Real fontSize = 0 \"unit pt\";
String fontName;
Expand All @@ -348,11 +348,11 @@ end Text;
record Bitmap
//extends GraphicItem;
Boolean visible = true;
Real origin[2](each final unit=\"mm\") = {0.0, 0.0};
Real rotation(quantity=\"angle\", unit=\"deg\")=0;
Real origin[2]/*(each final unit=\"mm\")*/ = {0.0, 0.0};
Real rotation/*(quantity=\"angle\", unit=\"deg\")*/=0;
// end GraphicItem
Real extent[2,2](each final unit=\"mm\");
Real extent[2,2]/*(each final unit=\"mm\")*/;
String fileName \"Name of bitmap file\";
String imageSource \"Base64 representation of bitmap\";
end Bitmap;
Expand Down
9 changes: 3 additions & 6 deletions Compiler/Dump.mo
Expand Up @@ -2197,15 +2197,12 @@ algorithm
end matchcontinue;
end unparseComponentStr;

protected function unparseComponentitemStr "function: unparseComponentitemStr

Prettyprints a ComponentItem to a string.
"
public function unparseComponentitemStr "function: unparseComponentitemStr
Prettyprints a ComponentItem to a string."
input Absyn.ComponentItem inComponentItem;
output String outString;
algorithm
outString:=
matchcontinue (inComponentItem)
outString := matchcontinue (inComponentItem)
local
Ident s1,s3,s2,str;
Absyn.Component c;
Expand Down
1 change: 1 addition & 0 deletions Compiler/Inst.mo
Expand Up @@ -929,6 +929,7 @@ algorithm
(cache,env_2,ih,dae);

case (cache,env,ih,{},_) then (cache,env,ih,DAEUtil.emptyDae);

case (_,_,ih,_,ref)
equation
print("Inst.instClassDecls failed\n ref =" +& Absyn.pathString(ref) +& "\n");
Expand Down
14 changes: 14 additions & 0 deletions Compiler/RTOpts.mo
Expand Up @@ -225,5 +225,19 @@ public function getRunningTestsuite
external "C" runningTestsuite = RTOpts_getRunningTestsuite() annotation(Library = "omcruntime");
end getRunningTestsuite;

public function getEvaluateParametersInAnnotations
"@author: adrpo
flag to tell us if we should evaluate parameters in annotations"
output Boolean shouldEvaluate;
external "C";
end getEvaluateParametersInAnnotations;

public function setEvaluateParametersInAnnotations
"@author: adrpo
flag to tell us if we should evaluate parameters in annotations"
input Boolean shouldEvaluate;
external "C";
end setEvaluateParametersInAnnotations;

end RTOpts;

0 comments on commit 502b665

Please sign in to comment.