Skip to content

Commit

Permalink
- listVariables now part of ModelicaBuiltin.mo
Browse files Browse the repository at this point in the history
git-svn-id: https://openmodelica.org/svn/OpenModelica/trunk@10186 f25d12d1-65f4-0310-ae8a-bbce733d8d8e
  • Loading branch information
sjoelund committed Oct 21, 2011
1 parent 563c838 commit 8e14aeb
Show file tree
Hide file tree
Showing 3 changed files with 38 additions and 62 deletions.
14 changes: 14 additions & 0 deletions Compiler/FrontEnd/ValuesUtil.mo
Expand Up @@ -2032,6 +2032,8 @@ algorithm
Absyn.CodeNode c;
Absyn.Path p, recordPath;
list<String> ids;
Absyn.ComponentRef cr;
Absyn.Path path;

case Values.INTEGER(integer = n)
equation
Expand Down Expand Up @@ -2121,6 +2123,18 @@ algorithm
then
();

case (Values.CODE(A = Absyn.C_TYPENAME(path)))
equation
Print.printBuf(Absyn.pathString(path));
then
();

case (Values.CODE(A = Absyn.C_VARIABLENAME(cr)))
equation
Print.printBuf(Absyn.printComponentRefStr(cr));
then
();

case (Values.CODE(A = c))
equation
Print.printBuf("Code(");
Expand Down
24 changes: 24 additions & 0 deletions Compiler/Script/CevalScript.mo
Expand Up @@ -872,6 +872,12 @@ algorithm

case (cache,env,"list",_,st,msg) then (cache,Values.STRING(""),st);

case (cache,env,"listVariables",{},st as Interactive.SYMBOLTABLE(lstVarVal = iv),msg)
equation
v = ValuesUtil.makeArray(getVariableNames(iv,{}));
then
(cache,v,st);

case (cache,env,"jacobian",{Values.CODE(Absyn.C_TYPENAME(path))},
(st as Interactive.SYMBOLTABLE(
ast = p,depends=aDep,explodedAst = fp,instClsLst = ic,
Expand Down Expand Up @@ -4191,4 +4197,22 @@ algorithm
end match;
end errorLevelToValue;

protected function getVariableNames
input list<Interactive.Variable> vars;
input list<Values.Value> acc;
output list<Values.Value> ovars;
algorithm
ovars := match (vars,acc)
local
list<Values.Value> res;
list<Interactive.Variable> vs;
String p;
case ({},acc) then listReverse(acc);
case (Interactive.IVAR(varIdent = "$echo") :: vs,acc)
then getVariableNames(vs,acc);
case (Interactive.IVAR(varIdent = p) :: vs,acc)
then getVariableNames(vs,Values.CODE(Absyn.C_VARIABLENAME(Absyn.CREF_IDENT(p,{})))::acc);
end match;
end getVariableNames;

end CevalScript;
62 changes: 0 additions & 62 deletions Compiler/Script/Interactive.mo
Expand Up @@ -458,29 +458,7 @@ algorithm
Boolean outres;
Absyn.Exp exp;
list<Variable> vars;
/* intercept getVersion() */
case
(ISTMTS(interactiveStmtLst =
{IEXP(exp = Absyn.CALL(function_ = Absyn.CREF_IDENT(name = "getVersion"),
functionArgs = Absyn.FUNCTIONARGS(args = {},argNames = {})))}),
(st as SYMBOLTABLE(lstVarVal = vars)))
equation
str = Settings.getVersionNr();
str = "\"" +& str +& "\"";
then
(str,st);

case
(ISTMTS(
interactiveStmtLst =
{IEXP(exp = Absyn.CALL(function_ = Absyn.CREF_IDENT(name = "listVariables"),
functionArgs = Absyn.FUNCTIONARGS(args = {},argNames = {})))}),
(st as SYMBOLTABLE(lstVarVal = vars)))
equation
varsStr = getVariableNames(vars);
str = stringAppend(varsStr, "\n");
then
(str,st);
case ((stmts as ISTMTS(interactiveStmtLst = {IEXP(exp = Absyn.CALL(function_ = _))})),st)
equation
(str,newst) = evaluateGraphicalApi(stmts, st);
Expand Down Expand Up @@ -1011,46 +989,6 @@ algorithm
end matchcontinue;
end getIdentFromTupleCrefexp;

protected function getVariableNames
"function: getVariableNames
Return a string containing a comma separated list of variables."
input list<Variable> vars;
output String res;
protected
list<String> strlst;
String str;
algorithm
strlst := getVariableListStr(vars);
str := stringDelimitList(strlst, ", ");
res := stringAppendList({"{",str,"}"});
end getVariableNames;

protected function getVariableListStr
"function: getVariableListStr
Helper function to getVariableNames"
input list<Variable> inVariableLst;
output list<String> outStringLst;
algorithm
outStringLst:=
matchcontinue (inVariableLst)
local
list<String> res;
list<Variable> vs;
String p;
case ({}) then {};
case ((IVAR(varIdent = "$echo") :: vs))
equation
res = getVariableListStr(vs);
then
res;
case ((IVAR(varIdent = p) :: vs))
equation
res = getVariableListStr(vs);
then
(p :: res);
end matchcontinue;
end getVariableListStr;

public function getTypeOfVariable
"function: getTypeOfVariables
Return the type of an interactive variable,
Expand Down

0 comments on commit 8e14aeb

Please sign in to comment.