Skip to content

Commit

Permalink
enumeration function Integer, works only for Enumeration types not fo…
Browse files Browse the repository at this point in the history
…r variables

git-svn-id: https://openmodelica.org/svn/OpenModelica/trunk@4526 f25d12d1-65f4-0310-ae8a-bbce733d8d8e
  • Loading branch information
Jens Frenkel committed Nov 16, 2009
1 parent f4f0918 commit ee86faa
Show file tree
Hide file tree
Showing 4 changed files with 85 additions and 0 deletions.
5 changes: 5 additions & 0 deletions Compiler/Builtin.mo
Expand Up @@ -294,6 +294,10 @@ protected constant tuple<Types.TType, Option<Type_a>> int2int=(
DAE.T_FUNCTION({("x",(DAE.T_INTEGER({}),NONE))},
(DAE.T_INTEGER({}),NONE)),NONE);

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

protected constant tuple<Types.TType, Option<Type_a>> intInt2int=(
DAE.T_FUNCTION(
{("x",(DAE.T_INTEGER({}),NONE)),
Expand Down Expand Up @@ -3009,6 +3013,7 @@ algorithm
env = Env.extendFrameT(env, "ceil", real2real);
envb = Env.extendFrameT(env, "floor", real2int);
env = Env.extendFrameT(envb, "integer", real2int);
env = Env.extendFrameT(env, "Integer", enumeration2int);
env = Env.extendFrameT(env, "abs", real2real) "differentiable functions" ;
env = Env.extendFrameT(env, "abs", int2int) "differentiable functions" ;
env = Env.extendFrameT(env, "sign", real2real);
Expand Down
34 changes: 34 additions & 0 deletions Compiler/Ceval.mo
Expand Up @@ -1012,6 +1012,7 @@ algorithm
case "promote" then cevalBuiltinPromote;
case "String" then cevalBuiltinString;
case "linspace" then cevalBuiltinLinspace;
case "Integer" then cevalBuiltinIntegerEnumeration;
case "print" equation true = RTOpts.acceptMetaModelicaGrammar(); then cevalBuiltinPrint;
// MetaModelica type conversions
case "intReal" equation true = RTOpts.acceptMetaModelicaGrammar(); then cevalIntReal;
Expand Down Expand Up @@ -3716,6 +3717,39 @@ algorithm
end matchcontinue;
end cevalBuiltinInteger;


protected function cevalBuiltinIntegerEnumeration "function cevalBuiltinIntegerEnumeration
author: LP
Evaluates the builtin Integer operator"
input Env.Cache inCache;
input Env.Env inEnv;
input list<Exp.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 ri;
list<Env.Frame> env;
Exp.Exp exp;
Boolean impl;
Option<Interactive.InteractiveSymbolTable> st;
Msg msg;
Env.Cache cache;
case (cache,env,{exp},impl,st,msg)
equation
(cache,Values.ENUM(ri,_,_),_) = ceval(cache,env, exp, impl, st, NONE, msg);
then
(cache,Values.INTEGER(ri),st);
end matchcontinue;
end cevalBuiltinIntegerEnumeration;

protected function cevalBuiltinDiagonal "function cevalBuiltinDiagonal
This function generates a matrix{n,n} (A) of the vector {a,b,...,n}
where the diagonal of A is the vector {a,b,...,n}
Expand Down
32 changes: 32 additions & 0 deletions Compiler/Static.mo
Expand Up @@ -4706,6 +4706,37 @@ algorithm
end matchcontinue;
end elabBuiltinInteger;

protected function elabBuiltinIntegerEnum
"function: elabBuiltinIntegerEnum
This function elaborates on the builtin operator Integer for Enumerations, which extracts
the Integer value of a Enumeration element."
input Env.Cache inCache;
input Env.Env inEnv;
input list<Absyn.Exp> inAbsynExpLst;
input list<Absyn.NamedArg> inNamedArg;
input Boolean inBoolean;
output Env.Cache outCache;
output Exp.Exp outExp;
output Types.Properties outProperties;
algorithm
(outCache,outExp,outProperties):=
matchcontinue (inCache,inEnv,inAbsynExpLst,inNamedArg,inBoolean)
local
Exp.Exp s1_1;
Types.Const c;
list<Env.Frame> env;
Absyn.Exp s1;
Boolean impl;
Env.Cache cache;
Types.Properties prop;
case (cache,env,{s1},_,impl)
equation
(cache,s1_1,prop) = verifyBuiltInHandlerType(cache,env,{s1},impl,Types.isEnumeration,"Integer");
then
(cache,s1_1,prop);
end matchcontinue;
end elabBuiltinIntegerEnum;

protected function elabBuiltinDiagonal "function: elabBuiltinDiagonal
This function elaborates on the builtin operator diagonal, creating a
Expand Down Expand Up @@ -6106,6 +6137,7 @@ algorithm
case "String" then elabBuiltinString;
case "rooted" then elabBuiltinRooted;
case "linspace" then elabBuiltinLinspace;
case "Integer" then elabBuiltinIntegerEnum;
case "mmc_get_field" equation true = RTOpts.acceptMetaModelicaGrammar(); then elabBuiltinMMCGetField;
case "mmc_uniontype_metarecord_typedef_equal" equation true = RTOpts.acceptMetaModelicaGrammar(); then elabBuiltinMMC_Uniontype_MetaRecord_Typedefs_Equal;
case "if_exp" equation true = RTOpts.acceptMetaModelicaGrammar(); then elabBuiltinIfExp;
Expand Down
14 changes: 14 additions & 0 deletions Compiler/Types.mo
Expand Up @@ -656,6 +656,20 @@ algorithm
end matchcontinue;
end isString;

public function isEnumeration "function: isEnumeration
Return true if Type is the builtin String type.
"
input Type inType;
output Boolean outBoolean;
algorithm
outBoolean:=
matchcontinue (inType)
case ((DAE.T_ENUMERATION(_, _, _, _),_)) then true;
case ((_,_)) then false;
end matchcontinue;
end isEnumeration;

public function isArrayOrString "function: isArrayOrString
Return true if Type is array or the builtin String type.
Expand Down

0 comments on commit ee86faa

Please sign in to comment.