Skip to content

Commit

Permalink
- Added OpenModelica.Code.VariableNames since the type system cannot …
Browse files Browse the repository at this point in the history
…handle arrays of Code expressions or vectorization of these

- Added readSimulationResult to ModelicaBuiltin.mo instead of using a special handler


git-svn-id: https://openmodelica.org/svn/OpenModelica/trunk@8003 f25d12d1-65f4-0310-ae8a-bbce733d8d8e
  • Loading branch information
sjoelund committed Feb 24, 2011
1 parent f452c9a commit bf39adc
Show file tree
Hide file tree
Showing 6 changed files with 24 additions and 16 deletions.
1 change: 0 additions & 1 deletion Compiler/BackEnd/Derive.mo
Expand Up @@ -46,7 +46,6 @@ encapsulated package Derive
// public imports
public import Absyn;
public import BackendDAE;
public import Builtin;
public import DAE;
public import DAEUtil;
public import RTOpts;
Expand Down
3 changes: 3 additions & 0 deletions Compiler/FrontEnd/DAE.mo
Expand Up @@ -759,6 +759,9 @@ public uniontype CodeType

record C_VARIABLENAME
end C_VARIABLENAME;

record C_VARIABLENAMES "Array of VariableName"
end C_VARIABLENAMES;
end CodeType;

public constant FunctionAttributes FUNCTION_ATTRIBUTES_BUILTIN = FUNCTION_ATTRIBUTES(NO_INLINE(),true,FUNCTION_BUILTIN(NONE()));
Expand Down
3 changes: 2 additions & 1 deletion Compiler/FrontEnd/Inst.mo
Expand Up @@ -1289,7 +1289,8 @@ algorithm
case ((_,SOME(Absyn.FULLYQUALIFIED(Absyn.QUALIFIED("OpenModelica",Absyn.QUALIFIED("Code",Absyn.IDENT(name)))))),_)
then Util.assoc(name,{
("TypeName",(DAE.T_CODE(DAE.C_TYPENAME()),NONE())),
("VariableName",(DAE.T_CODE(DAE.C_VARIABLENAME()),NONE()))
("VariableName",(DAE.T_CODE(DAE.C_VARIABLENAME()),NONE())),
("VariableNames",(DAE.T_CODE(DAE.C_VARIABLENAMES()),NONE()))
});
case (ty,false) then ty;
case (ty,true) then Types.makeFunctionPolymorphicReference(ty);
Expand Down
10 changes: 10 additions & 0 deletions Compiler/FrontEnd/ModelicaBuiltin.mo
Expand Up @@ -418,13 +418,15 @@ Besides, it has special semantics."

type TypeName "A path, for example the name of a class, e.g. A.B.C or .A.B" end TypeName;
type VariableName "A variable name, e.g. a.b or a[1].b[3].c" end VariableName;
type VariableNames "An array of variable names, e.g. {a.b,a[1].b[3].c}" end VariableNames;

end Code;

package Scripting

import OpenModelica.Code.TypeName;
import OpenModelica.Code.VariableName;
import OpenModelica.Code.VariableNames;

record CheckSettingsResult
String OPENMODELICAHOME,OPENMODELICALIBRARY,OMC_PATH;
Expand Down Expand Up @@ -954,6 +956,14 @@ function translateGraphics
external "builtin";
end translateGraphics;

function readSimulationResult "Reads a result file, returning a matrix corresponding to the variables and size given."
input String filename;
input VariableNames variables;
input Integer size := 0 "0=read any size... If the size is not the same as the result-file, this function fails";
output Real result[:,:];
external "builtin";
end readSimulationResult;

function readSimulationResultSize "The number of intervals that are present in the output file"
input String fileName;
output Integer sz;
Expand Down
22 changes: 8 additions & 14 deletions Compiler/FrontEnd/Static.mo
Expand Up @@ -6891,18 +6891,6 @@ protected function elabCallInteractive "function: elabCallInteractive
then
(cache,Expression.makeBuiltinCall("jacobian",{crefExp},DAE.ET_STRING()),DAE.PROP(DAE.T_STRING_DEFAULT,DAE.C_VAR()),SOME(st));

case (cache,env,Absyn.CREF_IDENT(name = "readSimulationResult"),{Absyn.STRING(value = filename),Absyn.ARRAY(arrayExp = vars),size_absyn},args,impl,SOME(st),pre,_)
equation
vars_1 = elabVariablenames(vars);
(cache,size_exp,ptop,st_1) = elabExp(cache,env, size_absyn, false, SOME(st),true,pre,info);
(cache,Values.INTEGER(size),_) = Ceval.ceval(cache,env, size_exp, false, st_1,NONE(), Ceval.MSG());
var_len = listLength(vars);
then
(cache,Expression.makeBuiltinCall("readSimulationResult",{DAE.SCONST(filename),DAE.ARRAY(DAE.ET_OTHER(),false,vars_1),size_exp},
DAE.ET_ARRAY(DAE.ET_REAL(),{DAE.DIM_INTEGER(var_len),DAE.DIM_INTEGER(size)})),DAE.PROP(
(DAE.T_ARRAY(DAE.DIM_INTEGER(var_len),
(DAE.T_ARRAY(DAE.DIM_INTEGER(size),DAE.T_REAL_DEFAULT),NONE())),NONE()),DAE.C_VAR()),SOME(st));

case (cache,env,Absyn.CREF_IDENT(name = "plot2"),{e1},{},impl,SOME(st),_,_)
equation
vars_1 = elabVariablenames({e1});
Expand Down Expand Up @@ -13274,17 +13262,23 @@ protected function elabCodeExp
input Absyn.Info info;
output DAE.Exp outExp;
algorithm
outExp := match (exp,ct,info)
outExp := matchcontinue (exp,ct,info)
local
String s1,s2;
Absyn.ComponentRef cr;
Absyn.Path path;
list<DAE.Exp> es_1;
list<Absyn.Exp> es;
case (Absyn.CREF(componentRef=cr),DAE.C_TYPENAME(),_)
equation
path = Absyn.crefToPath(cr);
then DAE.CODE(Absyn.C_TYPENAME(path),DAE.ET_OTHER());
case (Absyn.CREF(componentRef=cr),DAE.C_VARIABLENAME(),_)
then DAE.CODE(Absyn.C_VARIABLENAME(cr),DAE.ET_OTHER());
case (Absyn.ARRAY(es),DAE.C_VARIABLENAMES(),info)
equation
es_1 = Util.listMap2(es,elabCodeExp,DAE.C_VARIABLENAME(),info);
then DAE.ARRAY(DAE.ET_OTHER(),false,es_1);
case (Absyn.CALL(Absyn.CREF_IDENT("der",{}),Absyn.FUNCTIONARGS(args={Absyn.CREF(componentRef=cr)},argNames={})),DAE.C_VARIABLENAME(),_)
then DAE.CODE(Absyn.C_EXPRESSION(exp),DAE.ET_OTHER());
case (exp,ct,info)
Expand All @@ -13293,7 +13287,7 @@ algorithm
s2 = Types.printCodeTypeStr(ct);
Error.addSourceMessage(Error.ELAB_CODE_EXP_FAILED, {s1,s2}, info);
then fail();
end match;
end matchcontinue;
end elabCodeExp;

end Static;
1 change: 1 addition & 0 deletions Compiler/FrontEnd/Types.mo
Expand Up @@ -6587,6 +6587,7 @@ algorithm
str := match ct
case DAE.C_TYPENAME() then "OpenModelica.Code.TypeName";
case DAE.C_VARIABLENAME() then "OpenModelica.Code.VariableName";
case DAE.C_VARIABLENAMES() then "OpenModelica.Code.VariableNames";
else "Types.printCodeTypeStr failed";
end match;
end printCodeTypeStr;
Expand Down

0 comments on commit bf39adc

Please sign in to comment.