Skip to content

Commit

Permalink
- Moved the getBuiltinAttribute functions to ModelicaBuiltin.mo
Browse files Browse the repository at this point in the history
- Enabled the mosfiles-nosim/attributes, which still fails
  - This is due to CevalScript.getBuiltinAttribute apparently not working correctly


git-svn-id: https://openmodelica.org/svn/OpenModelica/trunk@8011 f25d12d1-65f4-0310-ae8a-bbce733d8d8e
  • Loading branch information
sjoelund committed Feb 25, 2011
1 parent 41928da commit 1738ca1
Show file tree
Hide file tree
Showing 4 changed files with 93 additions and 155 deletions.
2 changes: 2 additions & 0 deletions Compiler/FrontEnd/Expression.mo
Expand Up @@ -3786,6 +3786,8 @@ algorithm
res = rel((e,ext_arg));
then res;

case (e as DAE.CODE(code = _),rel,ext_arg) then ((e,ext_arg));

case (e,rel,ext_arg)
equation
str = ExpressionDump.printExpStr(e);
Expand Down
71 changes: 71 additions & 0 deletions Compiler/FrontEnd/ModelicaBuiltin.mo
Expand Up @@ -1166,5 +1166,76 @@ function plotParametric2 "Plots the y-variables as a function of the x-variable.
external "builtin";
end plotParametric2;

function getBuiltinAttribute
input String attribute;
input VariableName var;
input TypeName cl;
output String value;
external "builtin";
end getBuiltinAttribute;

function getUnit
input VariableName var;
input TypeName cl;
output String unit;
external "builtin" unit=getBuiltinAttribute("unit",cl,var);
end getUnit;

function getQuantity
input VariableName var;
input TypeName cl;
output String quantity;
external "builtin" quantity=getBuiltinAttribute("quantity",cl,var);
end getQuantity;

function getDisplayUnit
input VariableName var;
input TypeName cl;
output String displayUnit;
external "builtin" displayUnit=getBuiltinAttribute("displayUnit",cl,var);
end getDisplayUnit;

function getMin
input VariableName var;
input TypeName cl;
output String min;
external "builtin" min=getBuiltinAttribute("min",cl,var);
end getMin;

function getMax
input VariableName var;
input TypeName cl;
output String max;
external "builtin" max=getBuiltinAttribute("max",cl,var);
end getMax;

function getStart
input VariableName var;
input TypeName cl;
output String start;
external "builtin" start=getBuiltinAttribute("start",cl,var);
end getStart;

function getFixed
input VariableName var;
input TypeName cl;
output String fixed; // Boolean?
external "builtin" fixed=getBuiltinAttribute("fixed",cl,var);
end getFixed;

function getNominal
input VariableName var;
input TypeName cl;
output String nominal; // Real?
external "builtin" nominal=getBuiltinAttribute("nominal",cl,var);
end getNominal;

function getStateSelect
input VariableName var;
input TypeName cl;
output String stateSelect; // StateSelect output?
external "builtin" stateSelect=getBuiltinAttribute("stateSelect",cl,var);
end getStateSelect;

end Scripting;
end OpenModelica;
83 changes: 1 addition & 82 deletions Compiler/FrontEnd/Static.mo
Expand Up @@ -6887,88 +6887,7 @@ protected function elabCallInteractive "function: elabCallInteractive
then
(cache,Expression.makeBuiltinCall("timing",{exp_1},DAE.ET_REAL()),DAE.PROP(DAE.T_REAL_DEFAULT,DAE.C_VAR()),st_1);

case (cache,env,Absyn.CREF_IDENT(name = "getUnit"),{Absyn.CREF(componentRef = cr),Absyn.CREF(componentRef = cr2)},{},impl,SOME(st),pre,_)
equation
(cache,cr_1) = elabUntypedCref(cache,env,cr,impl,pre,info);
(cache,cr2_1) = elabUntypedCref(cache,env,cr2,impl,pre,info);
crefExp1 = Expression.crefExp(cr_1);
crefExp2 = Expression.crefExp(cr2_1);
then
(cache,Expression.makeBuiltinCall("getUnit",{crefExp1,crefExp2},DAE.ET_STRING()),DAE.PROP(DAE.T_STRING_DEFAULT,DAE.C_VAR()),SOME(st));

case (cache,env,Absyn.CREF_IDENT(name = "getQuantity"),{Absyn.CREF(componentRef = cr),Absyn.CREF(componentRef = cr2)},{},impl,SOME(st),pre,_)
equation
(cache,cr_1) = elabUntypedCref(cache,env,cr,impl,pre,info);
(cache,cr2_1) = elabUntypedCref(cache,env,cr2,impl,pre,info);
crefExp1 = Expression.crefExp(cr_1);
crefExp2 = Expression.crefExp(cr2_1);
then
(cache,Expression.makeBuiltinCall("getQuantity",{crefExp1,crefExp2},DAE.ET_STRING()),DAE.PROP(DAE.T_STRING_DEFAULT,DAE.C_VAR()),SOME(st));

case (cache,env,Absyn.CREF_IDENT(name = "getDisplayUnit"),{Absyn.CREF(componentRef = cr),Absyn.CREF(componentRef = cr2)},{},impl,SOME(st),pre,_)
equation
(cache,cr_1) = elabUntypedCref(cache,env,cr,impl,pre,info);
(cache,cr2_1) = elabUntypedCref(cache,env,cr2,impl,pre,info);
crefExp1 = Expression.crefExp(cr_1);
crefExp2 = Expression.crefExp(cr2_1);
then
(cache,Expression.makeBuiltinCall("getDisplayUnit",{crefExp1,crefExp2},DAE.ET_STRING()),DAE.PROP(DAE.T_STRING_DEFAULT,DAE.C_VAR()),SOME(st));

case (cache,env,Absyn.CREF_IDENT(name = "getMin"),{Absyn.CREF(componentRef = cr),Absyn.CREF(componentRef = cr2)},{},impl,SOME(st),pre,_)
equation
(cache,cr_1) = elabUntypedCref(cache,env,cr,impl,pre,info);
(cache,cr2_1) = elabUntypedCref(cache,env,cr2,impl,pre,info);
crefExp1 = Expression.crefExp(cr_1);
crefExp2 = Expression.crefExp(cr2_1);
then
(cache,Expression.makeBuiltinCall("getMin",{crefExp1,crefExp2},DAE.ET_STRING()),DAE.PROP(DAE.T_REAL_DEFAULT,DAE.C_VAR()),SOME(st));

case (cache,env,Absyn.CREF_IDENT(name = "getMax"),{Absyn.CREF(componentRef = cr),Absyn.CREF(componentRef = cr2)},{},impl,SOME(st),pre,_)
equation
(cache,cr_1) = elabUntypedCref(cache,env,cr,impl,pre,info);
(cache,cr2_1) = elabUntypedCref(cache,env,cr2,impl,pre,info);
crefExp1 = Expression.crefExp(cr_1);
crefExp2 = Expression.crefExp(cr2_1);
then
(cache,Expression.makeBuiltinCall("getMax",{crefExp1,crefExp2},DAE.ET_STRING()),DAE.PROP(DAE.T_REAL_DEFAULT,DAE.C_VAR()),SOME(st));

case (cache,env,Absyn.CREF_IDENT(name = "getStart"),{Absyn.CREF(componentRef = cr),Absyn.CREF(componentRef = cr2)},{},impl,SOME(st),pre,_)
equation
(cache,cr_1) = elabUntypedCref(cache,env,cr,impl,pre,info);
(cache,cr2_1) = elabUntypedCref(cache,env,cr2,impl,pre,info);
crefExp1 = Expression.crefExp(cr_1);
crefExp2 = Expression.crefExp(cr2_1);
then
(cache,Expression.makeBuiltinCall("getStart",{crefExp1,crefExp2},DAE.ET_STRING()),DAE.PROP(DAE.T_REAL_DEFAULT,DAE.C_VAR()),SOME(st));

case (cache,env,Absyn.CREF_IDENT(name = "getFixed"),{Absyn.CREF(componentRef = cr),Absyn.CREF(componentRef = cr2)},{},impl,SOME(st),pre,_)
equation
(cache,cr_1) = elabUntypedCref(cache,env,cr,impl,pre,info);
(cache,cr2_1) = elabUntypedCref(cache,env,cr2,impl,pre,info);
crefExp1 = Expression.crefExp(cr_1);
crefExp2 = Expression.crefExp(cr2_1);
then
(cache,Expression.makeBuiltinCall("getFixed",{crefExp1,crefExp2},DAE.ET_STRING()),DAE.PROP(DAE.T_BOOL_DEFAULT,DAE.C_VAR()),SOME(st));

case (cache,env,Absyn.CREF_IDENT(name = "getNominal"),{Absyn.CREF(componentRef = cr),Absyn.CREF(componentRef = cr2)},{},impl,SOME(st),pre,_)
equation
(cache,cr_1) = elabUntypedCref(cache,env,cr,impl,pre,info);
(cache,cr2_1) = elabUntypedCref(cache,env,cr2,impl,pre,info);
crefExp1 = Expression.crefExp(cr_1);
crefExp2 = Expression.crefExp(cr2_1);
then
(cache,Expression.makeBuiltinCall("getNominal",{crefExp1,crefExp2},DAE.ET_STRING()),DAE.PROP(DAE.T_REAL_DEFAULT,DAE.C_VAR()),SOME(st));

case (cache,env,Absyn.CREF_IDENT(name = "getStateSelect"),{Absyn.CREF(componentRef = cr),Absyn.CREF(componentRef = cr2)},{},impl,SOME(st),pre,_)
equation
(cache,cr_1) = elabUntypedCref(cache,env,cr,impl,pre,info);
(cache,cr2_1) = elabUntypedCref(cache,env,cr2,impl,pre,info);
crefExp1 = Expression.crefExp(cr_1);
crefExp2 = Expression.crefExp(cr2_1);
then
(cache,Expression.makeBuiltinCall("getStateSelect",{crefExp1,crefExp2},DAE.ET_STRING()),DAE.PROP(
(DAE.T_ENUMERATION(NONE(),Absyn.IDENT(""),{"never","avoid","default","prefer","always"},{},{}),NONE()),DAE.C_VAR()),SOME(st));

// MathCore-specific. Should not be in MathCoreBuiltin.mo :p
case (cache,env,Absyn.CREF_IDENT(name = "checkExamplePackages"),{},args,impl,SOME(st),pre,_)
equation
excludeList = getOptionalNamedArgExpList("exclude", args);
Expand Down
92 changes: 19 additions & 73 deletions Compiler/Script/CevalScript.mo
Expand Up @@ -1412,6 +1412,14 @@ algorithm
Values.STRING(confcmd)};
then (cache,Values.RECORD(Absyn.IDENT("OpenModelica.Scripting.CheckSettingsResult"),vals,vars_1,-1),st);

case (cache,env,"getBuiltinAttribute",{Values.STRING(str),Values.CODE(Absyn.C_VARIABLENAME(cr_1)),Values.CODE(Absyn.C_TYPENAME(path))},st,msg)
equation
(cache,v,st_1) = getBuiltinAttribute(cache,path,ComponentReference.toExpCref(cr_1),str,st);
then
(cache,v,st_1);
case (cache,env,_,_,st,msg)
then
(cache,Values.META_FAIL(),st);
end matchcontinue;
end cevalInteractiveFunctions2;

Expand Down Expand Up @@ -1729,67 +1737,10 @@ algorithm
case (cache,env,DAE.CALL(path = Absyn.IDENT(name = "enableSendData"),expLst = {DAE.BCONST(bool = b)}),
(st as Interactive.SYMBOLTABLE(ast = p,explodedAst = sp,instClsLst = ic,lstVarVal = iv,compiledFunctions = cf)),msg)
equation
// print("enableSendData\n");
// print(boolString(b));
// print("\n");
System.enableSendData(b);
then
(cache,Values.BOOL(true),st);

case (cache,env,DAE.CALL(path = Absyn.IDENT(name = "getUnit"),expLst = {DAE.CREF(componentRef = cref),DAE.CREF(componentRef = classname)}),st,msg)
equation
(cache,v,st_1) = getBuiltinAttribute(cache,classname, cref, "unit", st);
then
(cache,v,st_1);

case (cache,env,DAE.CALL(path = Absyn.IDENT(name = "getQuantity"),expLst = {DAE.CREF(componentRef = cref),DAE.CREF(componentRef = classname)}),st,msg)
equation
(cache,v,st_1) = getBuiltinAttribute(cache,classname, cref, "quantity", st);
then
(cache,v,st_1);

case (cache,env,DAE.CALL(path = Absyn.IDENT(name = "getDisplayUnit"),expLst = {DAE.CREF(componentRef = cref),DAE.CREF(componentRef = classname)}),st,msg)
equation
(cache,v,st_1) = getBuiltinAttribute(cache,classname, cref, "displayUnit", st);
then
(cache,v,st_1);

case (cache,env,DAE.CALL(path = Absyn.IDENT(name = "getMin"),expLst = {DAE.CREF(componentRef = cref),DAE.CREF(componentRef = classname)}),st,msg)
equation
(cache,v,st_1) = getBuiltinAttribute(cache,classname, cref, "min", st);
then
(cache,v,st_1);

case (cache,env,DAE.CALL(path = Absyn.IDENT(name = "getMax"),expLst = {DAE.CREF(componentRef = cref),DAE.CREF(componentRef = classname)}),st,msg)
equation
(cache,v,st_1) = getBuiltinAttribute(cache,classname, cref, "max", st);
then
(cache,v,st_1);

case (cache,env,DAE.CALL(path = Absyn.IDENT(name = "getStart"),expLst = {DAE.CREF(componentRef = cref),DAE.CREF(componentRef = classname)}),st,msg)
equation
(cache,v,st_1) = getBuiltinAttribute(cache,classname, cref, "start", st);
then
(cache,v,st_1);

case (cache,env,DAE.CALL(path = Absyn.IDENT(name = "getFixed"),expLst = {DAE.CREF(componentRef = cref),DAE.CREF(componentRef = classname)}),st,msg)
equation
(cache,v,st_1) = getBuiltinAttribute(cache,classname, cref, "fixed", st);
then
(cache,v,st_1);

case (cache,env,DAE.CALL(path = Absyn.IDENT(name = "getNominal"),expLst = {DAE.CREF(componentRef = cref),DAE.CREF(componentRef = classname)}),st,msg)
equation
(cache,v,st_1) = getBuiltinAttribute(cache,classname, cref, "nominal", st);
then
(cache,v,st_1);

case (cache,env,DAE.CALL(path = Absyn.IDENT(name = "getStateSelect"),expLst = {DAE.CREF(componentRef = cref),DAE.CREF(componentRef = classname)}),st,msg)
equation
(cache,v,st_1) = getBuiltinAttribute(cache,classname, cref, "stateSelect", st);
then
(cache,v,st_1);

case (cache,env,DAE.CALL(path = Absyn.IDENT(name = "echo"),expLst = {bool_exp}),st,msg)
equation
(cache,(v as Values.BOOL(bval)),SOME(st_1)) = Ceval.ceval(cache,env, bool_exp, true, SOME(st),NONE(), msg);
Expand Down Expand Up @@ -3164,7 +3115,7 @@ protected function getBuiltinAttribute "function: getBuiltinAttribute
Retrieves a builtin attribute of a variable in a class by instantiating
the class and retrieving the attribute value from the flat variable."
input Env.Cache inCache;
input DAE.ComponentRef inComponentRef1;
input Absyn.Path classname;
input DAE.ComponentRef inComponentRef2;
input String inString3;
input Interactive.InteractiveSymbolTable inInteractiveSymbolTable4;
Expand All @@ -3173,12 +3124,11 @@ protected function getBuiltinAttribute "function: getBuiltinAttribute
output Interactive.InteractiveSymbolTable outInteractiveSymbolTable;
algorithm
(outCache,outValue,outInteractiveSymbolTable):=
matchcontinue (inCache,inComponentRef1,inComponentRef2,inString3,inInteractiveSymbolTable4)
matchcontinue (inCache,classname,inComponentRef2,inString3,inInteractiveSymbolTable4)
local
Absyn.Path classname_1;
DAE.DAElist dae,dae1;
list<Env.Frame> env,env_1,env3,env4;
DAE.ComponentRef cref_1,classname,cref;
DAE.ComponentRef cref_1,cref;
DAE.Attributes attr;
tuple<DAE.TType, Option<Absyn.Path>> ty;
DAE.Exp exp;
Expand Down Expand Up @@ -3207,8 +3157,7 @@ algorithm
lstVarVal = vars,
compiledFunctions = cf)))
equation
classname_1 = Static.componentRefToPath(classname) "Check cached instantiated class" ;
Interactive.INSTCLASS(_,dae,env) = Interactive.getInstantiatedClass(ic, classname_1);
Interactive.INSTCLASS(_,dae,env) = Interactive.getInstantiatedClass(ic, classname);
cref_1 = ComponentReference.joinCrefs(cref, ComponentReference.makeCrefIdent("stateSelect",DAE.ET_OTHER(),{}));
(cache,attr,ty,DAE.EQBOUND(exp,_,_,_),_,_,_,_,_) = Lookup.lookupVar(cache, env, cref_1);
str = ExpressionDump.printExpStr(exp);
Expand All @@ -3225,18 +3174,17 @@ algorithm
compiledFunctions = cf,
loadedFiles = lf))
equation
classname_1 = Static.componentRefToPath(classname);
ptot = Dependency.getTotalProgram(classname_1,p);
ptot = Dependency.getTotalProgram(classname,p);
p_1 = SCodeUtil.translateAbsyn2SCode(ptot);
(cache,env) = Inst.makeEnvFromProgram(cache,p_1, Absyn.IDENT(""));
(cache,(c as SCode.CLASS(name=n,encapsulatedPrefix=encflag,restriction=r)),env_1) = Lookup.lookupClass(cache,env, classname_1, true);
(cache,(c as SCode.CLASS(name=n,encapsulatedPrefix=encflag,restriction=r)),env_1) = Lookup.lookupClass(cache,env,classname,true);
env3 = Env.openScope(env_1, encflag, SOME(n), SOME(Env.CLASS_SCOPE()));
ci_state = ClassInf.start(r, Env.getEnvName(env3));
(cache,env4,_,_,dae1,csets_1,ci_state_1,tys,_,_,_,_) = Inst.instClassIn(cache,env3, InnerOuter.emptyInstHierarchy,UnitAbsyn.noStore,DAE.NOMOD(), Prefix.NOPRE(), Connect.emptySet,
ci_state, c, false, {}, false, Inst.INNER_CALL(), ConnectionGraph.EMPTY,NONE());
cref_1 = ComponentReference.crefPrependIdent(cref, "stateSelect",{},DAE.ET_OTHER());
(cache,attr,ty,DAE.EQBOUND(exp,_,_,_),_,_,_,_,_) = Lookup.lookupVar(cache, env4, cref_1);
ic_1 = Interactive.addInstantiatedClass(ic, Interactive.INSTCLASS(classname_1,dae1,env4));
ic_1 = Interactive.addInstantiatedClass(ic, Interactive.INSTCLASS(classname,dae1,env4));
str = ExpressionDump.printExpStr(exp);
then
(cache,Values.STRING(str),Interactive.SYMBOLTABLE(p,aDep,sp,ic_1,vars,cf,lf));
Expand All @@ -3249,8 +3197,7 @@ algorithm
lstVarVal = vars,
compiledFunctions = cf)))
equation
classname_1 = Static.componentRefToPath(classname);
Interactive.INSTCLASS(_,dae,env) = Interactive.getInstantiatedClass(ic, classname_1);
Interactive.INSTCLASS(_,dae,env) = Interactive.getInstantiatedClass(ic, classname);
cref_1 = ComponentReference.crefPrependIdent(cref, attribute,{},DAE.ET_OTHER());
(cache,attr,ty,DAE.VALBOUND(v,_),_,_,_,_,_) = Lookup.lookupVar(cache, env, cref_1);
then
Expand All @@ -3266,18 +3213,17 @@ algorithm
compiledFunctions = cf,
loadedFiles = lf)))
equation
classname_1 = Static.componentRefToPath(classname);
ptot = Dependency.getTotalProgram(classname_1,p);
ptot = Dependency.getTotalProgram(classname,p);
p_1 = SCodeUtil.translateAbsyn2SCode(ptot);
(cache,env) = Inst.makeEnvFromProgram(cache,p_1, Absyn.IDENT(""));
(cache,(c as SCode.CLASS(name=n,encapsulatedPrefix=encflag,restriction=r)),env_1) = Lookup.lookupClass(cache,env, classname_1, true);
(cache,(c as SCode.CLASS(name=n,encapsulatedPrefix=encflag,restriction=r)),env_1) = Lookup.lookupClass(cache,env,classname,true);
env3 = Env.openScope(env_1, encflag, SOME(n), SOME(Env.CLASS_SCOPE()));
ci_state = ClassInf.start(r, Env.getEnvName(env3));
(cache,env4,_,_,dae1,csets_1,ci_state_1,tys,_,_,_,_) = Inst.instClassIn(cache,env3, InnerOuter.emptyInstHierarchy, UnitAbsyn.noStore,DAE.NOMOD(), Prefix.NOPRE(), Connect.emptySet,
ci_state, c, false, {}, false, Inst.INNER_CALL(), ConnectionGraph.EMPTY,NONE());
cref_1 = ComponentReference.crefPrependIdent(cref,attribute,{},DAE.ET_OTHER());
(cache,attr,ty,DAE.VALBOUND(v,_),_,_,_,_,_) = Lookup.lookupVar(cache, env4, cref_1);
ic_1 = Interactive.addInstantiatedClass(ic, Interactive.INSTCLASS(classname_1,dae1,env4));
ic_1 = Interactive.addInstantiatedClass(ic, Interactive.INSTCLASS(classname,dae1,env4));
then
(cache,v,Interactive.SYMBOLTABLE(p,aDep,sp,ic_1,vars,cf,lf));

Expand Down

0 comments on commit 1738ca1

Please sign in to comment.