Skip to content
This repository has been archived by the owner on May 18, 2019. It is now read-only.

Commit

Permalink
ticket:3680 & 4296 Look for connect equation within for loop equation.
Browse files Browse the repository at this point in the history
Moved getNthConnection to ModelicaBuiltin.mo.
  • Loading branch information
adeas31 authored and OpenModelica-Hudson committed Mar 7, 2017
1 parent 8f1fd56 commit 8777f9a
Show file tree
Hide file tree
Showing 3 changed files with 57 additions and 37 deletions.
10 changes: 10 additions & 0 deletions Compiler/FrontEnd/ModelicaBuiltin.mo
Original file line number Diff line number Diff line change
Expand Up @@ -3070,6 +3070,16 @@ annotation(
preferredView="text");
end removeExtendsModifiers;

function getNthConnection "Returns the Nth connection.
Example command:
getNthConnection(A) => {\"from\", \"to\", \"comment\"}"
input TypeName className;
input Integer index;
output String[:] result;
external "builtin";
annotation(preferredView="text");
end getNthConnection;

function getAlgorithmCount "Counts the number of Algorithm sections in a class."
input TypeName class_;
output Integer count;
Expand Down
16 changes: 12 additions & 4 deletions Compiler/Script/CevalScriptBackend.mo
Original file line number Diff line number Diff line change
Expand Up @@ -2333,6 +2333,14 @@ algorithm
then
(cache,Values.BOOL(b),st);

case (cache,_,"getNthConnection",{Values.CODE(Absyn.C_TYPENAME(path)),Values.INTEGER(n)},(st as GlobalScript.SYMBOLTABLE(ast = p)),_)
equation
vals = Interactive.getNthConnection(Absyn.pathToCref(path), p, n);
then
(cache,ValuesUtil.makeArray(vals),st);

case (cache,_,"getNthConnection",_,st,_) then (cache,ValuesUtil.makeArray({}),st);

case (cache,_,"getAlgorithmCount",{Values.CODE(Absyn.C_TYPENAME(path))},(st as GlobalScript.SYMBOLTABLE(ast = p)),_)
equation
absynClass = Interactive.getPathedClassInProgram(path, p);
Expand Down Expand Up @@ -6890,13 +6898,13 @@ algorithm
Option<Absyn.Comment> cmt;
case (Absyn.PARTS(comment = SOME(str))) then str;
case (Absyn.DERIVED(comment = cmt))
then Interactive.getStringComment2(cmt);
then Interactive.getStringComment(cmt);
case (Absyn.ENUMERATION(comment = cmt))
then Interactive.getStringComment2(cmt);
then Interactive.getStringComment(cmt);
case (Absyn.ENUMERATION(comment = cmt))
then Interactive.getStringComment2(cmt);
then Interactive.getStringComment(cmt);
case (Absyn.OVERLOAD(comment = cmt))
then Interactive.getStringComment2(cmt);
then Interactive.getStringComment(cmt);
case (Absyn.CLASS_EXTENDS(comment = SOME(str))) then str;
else "";
end matchcontinue;
Expand Down
68 changes: 35 additions & 33 deletions Compiler/Script/Interactive.mo
Original file line number Diff line number Diff line change
Expand Up @@ -1180,12 +1180,6 @@ algorithm
then
getConnectionCount(cr, p);

case "getNthConnection"
algorithm
{Absyn.CREF(componentRef = cr), Absyn.INTEGER(value = n)} := args;
then
getNthConnection(cr, p, n);

case "setConnectionComment"
algorithm
{Absyn.CREF(componentRef = cr),
Expand Down Expand Up @@ -10275,23 +10269,24 @@ algorithm
end matchcontinue;
end getConnectionCount;

protected function getNthConnection "
public function getNthConnection "
This function takes a `ComponentRef\' and a `Program\' and an int and
returns a comma separated string for the nth connection, e.g. \"R1.n,C.p\".
"
input Absyn.ComponentRef inComponentRef;
input Absyn.Program inProgram;
input Integer inInteger;
output String outString;
output list<Values.Value> outValue;
algorithm
outString:=
outValue:=
matchcontinue (inComponentRef,inProgram,inInteger)
local
Absyn.Path modelpath;
Absyn.Class cdef;
Absyn.Equation eq;
Option<Absyn.Comment> cmt;
String str2,str,res;
list<Values.Value> vals;
String str,s1,s2;
Absyn.ComponentRef model_;
Absyn.Program p;
Integer n;
Expand All @@ -10300,28 +10295,16 @@ algorithm
modelpath = Absyn.crefToPath(model_);
cdef = getPathedClassInProgram(modelpath, p);
Absyn.EQUATIONITEM(equation_ = eq, comment = cmt) = getNthConnectionitemInClass(cdef, n);
str2 = getStringComment(cmt);
str = getConnectionStr(eq);
res = stringAppendList({"{",str,", ",str2,"}"});
str = getStringComment(cmt);
(s1, s2) = getConnectionStr(eq);
vals = {Values.STRING(s1), Values.STRING(s2), Values.STRING(str)};
then
res;
else "Error";
vals;
else {};
end matchcontinue;
end getNthConnection;

protected function getStringComment "
Returns the string comment or empty string from a Comment option.
"
input Option<Absyn.Comment> cmt;
output String res;
protected
String s;
algorithm
s := getStringComment2(cmt);
res := stringAppendList({"\"",s,"\""});
end getStringComment;

public function getStringComment2
public function getStringComment
input Option<Absyn.Comment> inAbsynCommentOption;
output String outString;
algorithm
Expand All @@ -10331,7 +10314,7 @@ algorithm
case (SOME(Absyn.COMMENT(_,SOME(str)))) then str;
else "";
end match;
end getStringComment2;
end getStringComment;

protected function addConnection "
Adds a connect equation to the model, i..e connect(c1,c2)
Expand Down Expand Up @@ -13207,6 +13190,7 @@ algorithm
local
Absyn.EquationItem eq;
list<Absyn.EquationItem> xs;
list<Absyn.EquationItem> forEqList;
Integer newn,n;

case (((eq as Absyn.EQUATIONITEM(equation_ = Absyn.EQ_CONNECT())) :: _),1) then eq;
Expand All @@ -13218,6 +13202,17 @@ algorithm
then
eq;

case ((Absyn.EQUATIONITEM(equation_ = Absyn.EQ_FOR(forEquations = forEqList)) :: xs), n)
algorithm
try
eq := getNthConnectionitemInEquations(forEqList, n);
else
newn := n - listLength(forEqList);
eq := getNthConnectionitemInEquations(xs, newn);
end try;
then
eq;

case ((_ :: xs),n)
equation
eq = getNthConnectionitemInEquations(xs, n);
Expand All @@ -13234,9 +13229,10 @@ protected function getConnectionStr
returns a comma separated string of componentreferences, e.g \"R1.n,C.p\"
for connect(R1.n,C.p)."
input Absyn.Equation inEquation;
output String outString;
output String outFromString;
output String outToString;
algorithm
outString := match (inEquation)
(outFromString, outToString) := match (inEquation)
local
String s1,s2,str;
Absyn.ComponentRef cr1,cr2;
Expand All @@ -13245,9 +13241,8 @@ algorithm
equation
s1 = Dump.printComponentRefStr(cr1);
s2 = Dump.printComponentRefStr(cr2);
str = stringAppendList({s1,",",s2});
then
str;
(s1, s2);
end match;
end getConnectionStr;

Expand Down Expand Up @@ -13321,11 +13316,18 @@ algorithm
local
Integer r1,res;
list<Absyn.EquationItem> xs;
list<Absyn.EquationItem> forEqList;

case ((Absyn.EQUATIONITEM(equation_ = Absyn.EQ_CONNECT()) :: xs))
then
countConnectionsInEquations(xs, inInteger + 1);

case ((Absyn.EQUATIONITEM(equation_ = Absyn.EQ_FOR(forEquations = forEqList)) :: xs))
equation
outInteger = countConnectionsInEquations(forEqList, inInteger);
then
countConnectionsInEquations(xs, outInteger);

case ((_ :: xs))
then
countConnectionsInEquations(xs, inInteger);
Expand Down

0 comments on commit 8777f9a

Please sign in to comment.