Skip to content

Commit

Permalink
ticket:4674: add new api to retrieve instantiated parameters
Browse files Browse the repository at this point in the history
  • Loading branch information
adrpo authored and OpenModelica-Hudson committed Feb 1, 2018
1 parent 047c5a8 commit 3395121
Show file tree
Hide file tree
Showing 5 changed files with 83 additions and 1 deletion.
2 changes: 1 addition & 1 deletion Compiler/FrontEnd/DAEDump.mo
Expand Up @@ -3318,7 +3318,7 @@ algorithm
print("tuple_: "+boolString(tpl)+" builtin: "+boolString(bi)+" impure: "+boolString(impure_)+"\n\n");
end dumpCallAttr;

protected function dumpVarBindingStr
public function dumpVarBindingStr
input Option<DAE.Exp> inBinding;
output String outString;
algorithm
Expand Down
30 changes: 30 additions & 0 deletions Compiler/FrontEnd/DAEUtil.mo
Expand Up @@ -6525,6 +6525,36 @@ algorithm
end match;
end moveElementToInitialSection;

public function getParameters
input list<DAE.Element> elts;
input list<DAE.Element> acc;
output list<DAE.Element> params;
algorithm
(params) := match (elts,acc)
local
DAE.Element e;
list<DAE.Element> rest, celts, a;

case ({},_) then acc;

case ((e as DAE.COMP(dAElist = celts))::rest,_)
algorithm
a := getParameters(celts, acc);
a := getParameters(rest, a);
then
a;

case ((e as DAE.VAR())::rest,_)
then if isParameterOrConstant(e)
then e::getParameters(rest, acc)
else getParameters(rest, acc);

case (_::rest,_)
then getParameters(rest, acc);

end match;
end getParameters;

annotation(__OpenModelica_Interface="frontend");
end DAEUtil;

11 changes: 11 additions & 0 deletions Compiler/FrontEnd/ModelicaBuiltin.mo
Expand Up @@ -3037,6 +3037,17 @@ annotation(
preferredView="text");
end getComponentModifierValues;

function getInstantiatedParametersAndValues
input TypeName cls;
output String[:] values;
external "builtin";
annotation(
Documentation(info="<html>
<p>Returns the parameter names and values from the DAE.</p>
</html>"),
preferredView="text");
end getInstantiatedParametersAndValues;

function removeComponentModifiers
input TypeName class_;
input String componentName;
Expand Down
16 changes: 16 additions & 0 deletions Compiler/Script/CevalScriptBackend.mo
Expand Up @@ -2532,6 +2532,22 @@ algorithm
then
(cache,Values.BOOL(b));

case (cache,env,"getInstantiatedParametersAndValues",{Values.CODE(Absyn.C_TYPENAME(className))},_)
equation
(cache,env,odae) = runFrontEnd(cache,env,className,true);
strings = Interactive.getInstantiatedParametersAndValues(odae);
vals = List.map(strings, ValuesUtil.makeString);
v = ValuesUtil.makeArray(vals);
then
(cache,v);

case (cache,_,"getInstantiatedParametersAndValues",_,_)
equation
Error.addCompilerWarning("getInstantiatedParametersAndValues failed to instantiate the model.");
v = ValuesUtil.makeArray({});
then
(cache,v);

case (cache,_,"getConnectionCount",{Values.CODE(Absyn.C_TYPENAME(path))},_)
equation
absynClass = Interactive.getPathedClassInProgram(path, SymbolTable.getAbsyn());
Expand Down
25 changes: 25 additions & 0 deletions Compiler/Script/Interactive.mo
Expand Up @@ -68,6 +68,7 @@ import ClockIndexes;
import Config;
import Connect;
import Constants;
import DAEDump;
import DAEUtil;
import Debug;
import DoubleEndedList;
Expand Down Expand Up @@ -18061,5 +18062,29 @@ algorithm
end matchcontinue;
end excludeElementsFromFile;

public function getInstantiatedParametersAndValues
input Option<DAE.DAElist> odae;
output list<String> parametersAndValues = {};
protected
list<DAE.Element> els, params;
list<String> strs = {};
String s;
Option<DAE.Exp> oe;
algorithm
parametersAndValues := match(odae)
case SOME(DAE.DAE(els))
algorithm
params := DAEUtil.getParameters(els, {});
for p in params loop
DAE.VAR(binding=oe) := p;
s := DAEUtil.varName(p) + DAEDump.dumpVarBindingStr(oe);
strs := s::strs;
end for;
then
listReverse(strs);
else strs;
end match;
end getInstantiatedParametersAndValues;

annotation(__OpenModelica_Interface="backend");
end Interactive;

0 comments on commit 3395121

Please sign in to comment.