Skip to content

Commit

Permalink
- Moved getParameterValue to ModelicaBuiltin.mo.
Browse files Browse the repository at this point in the history
- updated getParameterValue to scripting API.

git-svn-id: https://openmodelica.org/svn/OpenModelica/trunk@24484 f25d12d1-65f4-0310-ae8a-bbce733d8d8e
  • Loading branch information
adeas31 committed Feb 9, 2015
1 parent 4a54438 commit 1c86e21
Show file tree
Hide file tree
Showing 3 changed files with 31 additions and 28 deletions.
12 changes: 12 additions & 0 deletions Compiler/FrontEnd/ModelicaBuiltin.mo
Expand Up @@ -2727,6 +2727,18 @@ annotation(
preferredView="text");
end getParameterNames;

function getParameterValue
input TypeName class_;
input String parameterName;
output String parameterValue;
external "builtin";
annotation(
Documentation(info="<html>
Returns the value of the parameter of the class.
</html>"),
preferredView="text");
end getParameterValue;

function getAlgorithmCount "Counts the number of Algorithm sections in a class."
input TypeName class_;
output Integer count;
Expand Down
6 changes: 6 additions & 0 deletions Compiler/Script/CevalScript.mo
Expand Up @@ -3197,6 +3197,12 @@ algorithm
then
(cache,v,st);

case (cache,_,"getParameterValue",{Values.CODE(Absyn.C_TYPENAME(path)),Values.STRING(str1)},(st as GlobalScript.SYMBOLTABLE(ast = p)),_)
equation
str2 = Interactive.getComponentBinding(path, str1, p);
then
(cache,Values.STRING(str2),st);

case (cache,_,"getAlgorithmCount",{Values.CODE(Absyn.C_TYPENAME(path))},(st as GlobalScript.SYMBOLTABLE(ast = p)),_)
equation
absynClass = Interactive.getPathedClassInProgram(path, p);
Expand Down
41 changes: 13 additions & 28 deletions Compiler/Script/Interactive.mo
Expand Up @@ -1034,12 +1034,6 @@ algorithm
then
outResult;

case "getParameterValue"
algorithm
{Absyn.CREF(componentRef = class_), Absyn.CREF(componentRef = crident)} := args;
then
getComponentBinding(class_, crident, p);

case "setParameterValue"
algorithm
{Absyn.CREF(componentRef = class_), Absyn.CREF(componentRef = crident), exp} := args;
Expand Down Expand Up @@ -1518,7 +1512,7 @@ algorithm

if Absyn.crefIsIdent(cr) then
Absyn.CREF_IDENT(name = name) := cr;
outResult := getComponentBinding(class_, Absyn.CREF_IDENT(name, {}), p);
outResult := getComponentBinding(Absyn.crefToPath(class_), name, p);
else
name := Absyn.crefFirstIdent(cr);
subident := Absyn.crefStripFirst(cr);
Expand Down Expand Up @@ -6051,24 +6045,19 @@ algorithm
end matchcontinue;
end getModificationNames;

protected function getComponentBinding
public function getComponentBinding
" Returns the value of a component in a class.
For example, the component
Real x=1;
returns 1.
This can be used for both parameters, constants and variables.
inputs: (Absyn.ComponentRef, /* class */
Absyn.ComponentRef, /* variable name */
Absyn.Program)
outputs: string"
input Absyn.ComponentRef inComponentRef1;
input Absyn.ComponentRef inComponentRef2;
This can be used for both parameters, constants and variables."
input Absyn.Path path;
input String parameterName;
input Absyn.Program inProgram3;
output String outString;
algorithm
outString := matchcontinue (inComponentRef1,inComponentRef2,inProgram3)
outString := matchcontinue (path,parameterName,inProgram3)
local
Absyn.Path p_class;
String name,res;
Absyn.Class cdef;
list<Absyn.Element> comps;
Expand All @@ -6079,36 +6068,32 @@ algorithm
Absyn.ComponentRef class_,crname;
Absyn.Program p;

case (class_,crname,p)
case (_,_,p)
equation
p_class = Absyn.crefToPath(class_);
Absyn.IDENT(name) = Absyn.crefToPath(crname);
cdef = getPathedClassInProgram(p_class, p);
cdef = getPathedClassInProgram(path, p);
comps = getComponentsInClass(cdef);
compelts = List.map(comps, getComponentitemsInElement);
compelts_1 = List.flatten(compelts);
{compitem} = List.select1(compelts_1, componentitemNamed, name);
{compitem} = List.select1(compelts_1, componentitemNamed, parameterName);
exp = getVariableBindingInComponentitem(compitem);
res = Dump.printExpStr(exp);
then
res;

case (class_,crname,p)
case (_,_,p)
equation
p_class = Absyn.crefToPath(class_);
Absyn.IDENT(name) = Absyn.crefToPath(crname);
cdef = getPathedClassInProgram(p_class, p);
cdef = getPathedClassInProgram(path, p);
comps = getComponentsInClass(cdef);
compelts = List.map(comps, getComponentitemsInElement);
compelts_1 = List.flatten(compelts);
{compitem} = List.select1(compelts_1, componentitemNamed, name);
{compitem} = List.select1(compelts_1, componentitemNamed, parameterName);
failure(_ = getVariableBindingInComponentitem(compitem));
then
"";

case (_,_,_)
then
"Error";
"";
end matchcontinue;
end getComponentBinding;

Expand Down

0 comments on commit 1c86e21

Please sign in to comment.