Skip to content

Commit

Permalink
Added new API addTransition.
Browse files Browse the repository at this point in the history
  • Loading branch information
adeas31 authored and OpenModelica-Hudson committed Aug 17, 2016
1 parent 974a19c commit 0735a9d
Show file tree
Hide file tree
Showing 3 changed files with 110 additions and 2 deletions.
18 changes: 17 additions & 1 deletion Compiler/FrontEnd/ModelicaBuiltin.mo
Expand Up @@ -2829,7 +2829,6 @@ and the annotation to set.</p>
</html>"));
end addClassAnnotation;


function getParameterNames
input TypeName class_;
output String[:] parameters;
Expand Down Expand Up @@ -3712,6 +3711,23 @@ annotation(
</html>"), preferredView="text");
end getTransitions;

function addTransition
input TypeName cl;
input String from;
input String to;
input String condition;
input Boolean immediate = true;
input Boolean reset = true;
input Boolean synchronize = false;
input Integer priority = 1;
input ExpressionOrModification annotate;
output Boolean bool;
external "builtin";
annotation(preferredView="text",Documentation(info="<html>
<p>Adds the transition to the class.</p>
</html>"));
end addTransition;

function generateScriptingAPI
input TypeName cl;
input String name;
Expand Down
23 changes: 23 additions & 0 deletions Compiler/Script/CevalScriptBackend.mo
Expand Up @@ -861,6 +861,29 @@ algorithm
case (cache,_,"getTransitions",_,st,_)
then (cache, Values.ARRAY({},{}), st);

case (cache,_,"addTransition",{Values.CODE(Absyn.C_TYPENAME(classpath)), Values.STRING(str1), Values.STRING(str2), Values.STRING(str3),
Values.BOOL(b), Values.BOOL(b1), Values.BOOL(b2), Values.INTEGER(i), Values.CODE(Absyn.C_EXPRESSION(aexp))},
st as GlobalScript.SYMBOLTABLE(ast=p),_)
equation
(bval, p) = Interactive.addTransition(Absyn.pathToCref(classpath), str1, str2, str3, b, b1, b2, i, Absyn.NAMEDARG("annotate",aexp)::{}, p);
st = GlobalScriptUtil.setSymbolTableAST(st, p);
then
(cache,Values.BOOL(bval),st);

case (cache,_,"addTransition",{Values.CODE(Absyn.C_TYPENAME(classpath)), Values.STRING(str1), Values.STRING(str2), Values.STRING(str3),
Values.BOOL(b), Values.BOOL(b1), Values.BOOL(b2), Values.INTEGER(i),
Values.CODE(Absyn.C_MODIFICATION(Absyn.CLASSMOD(elementArgLst=eltargs,eqMod=Absyn.NOMOD())))},
st as GlobalScript.SYMBOLTABLE(ast=p),_)
equation
(bval, p) = Interactive.addTransitionWithAnnotation(Absyn.pathToCref(classpath), str1, str2, str3, b, b1, b2, i, Absyn.ANNOTATION(eltargs), p);
st = GlobalScriptUtil.setSymbolTableAST(st, p);
then
(cache,Values.BOOL(true),st);

case (cache,_,"addTransition",{_,_,_,_,_,_,_,_,v},st as GlobalScript.SYMBOLTABLE(),_)
then
(cache,Values.BOOL(false),st);

case (cache,_,"diffModelicaFileListings",{Values.STRING(s1),Values.STRING(s2),Values.ENUM_LITERAL(name=path)},(st as GlobalScript.SYMBOLTABLE(ast = p)),_)
algorithm
ExecStat.execStatReset();
Expand Down
71 changes: 70 additions & 1 deletion Compiler/Script/Interactive.mo
Expand Up @@ -10358,6 +10358,75 @@ algorithm
end match;
end deleteEquationInEqlist;

public function addTransition
"Adds a transition to the model, i.e., transition(state1, state2, i > 10)"
input Absyn.ComponentRef inComponentRef;
input String from;
input String to;
input String condition;
input Boolean immediate;
input Boolean reset;
input Boolean synchronize;
input Integer priority;
input list<Absyn.NamedArg> inAbsynNamedArgLst;
input Absyn.Program inProgram;
output Boolean b;
output Absyn.Program outProgram;
algorithm
(b,outProgram) := addTransitionWithAnnotation(inComponentRef, from, to, condition, immediate, reset, synchronize, priority, annotationListToAbsyn(inAbsynNamedArgLst), inProgram);
end addTransition;

public function addTransitionWithAnnotation
"Adds a transition to the model, i.e., transition(state1, state2, i > 10)"
input Absyn.ComponentRef inComponentRef;
input String from;
input String to;
input String condition;
input Boolean immediate;
input Boolean reset;
input Boolean synchronize;
input Integer priority;
input Absyn.Annotation inAnnotation;
input Absyn.Program inProgram;
output Boolean b;
output Absyn.Program outProgram;
algorithm
(b,outProgram) := match (inComponentRef, from, to, condition, immediate, reset, synchronize, priority, inAnnotation, inProgram)
local
Absyn.Path modelpath,package_;
Absyn.Class cdef,newcdef;
Absyn.Program newp,p;
Absyn.ComponentRef model_;
String from_, to_, condition_;
Boolean immediate_, reset_, synchronize_;
Integer priority_;
Absyn.Within w;
Absyn.Annotation ann;
Option<Absyn.Comment> cmt;

case ((model_ as Absyn.CREF_IDENT()), from_, to_, condition_, immediate_, reset_, synchronize_, priority_, ann,(p as Absyn.PROGRAM()))
equation
modelpath = Absyn.crefToPath(model_);
cdef = getPathedClassInProgram(modelpath, p);
cmt = SOME(Absyn.COMMENT(SOME(ann), NONE()));
newcdef = addToEquation(cdef, Absyn.EQUATIONITEM(Absyn.EQ_NORETCALL(Absyn.CREF_IDENT("transition", {}), Absyn.FUNCTIONARGS({Absyn.CREF(Absyn.CREF_IDENT(from_, {})), Absyn.CREF(Absyn.CREF_IDENT(to_, {})), Absyn.CREF(Absyn.CREF_IDENT(condition_, {})), Absyn.BOOL(immediate_), Absyn.BOOL(reset_), Absyn.BOOL(synchronize_), Absyn.INTEGER(priority_)}, {})), cmt, Absyn.dummyInfo));
newp = updateProgram(Absyn.PROGRAM({newcdef},p.within_), p);
then
(true, newp);

case ((model_ as Absyn.CREF_QUAL()), from_, to_, condition_, immediate_, reset_, synchronize_, priority_, ann,(p as Absyn.PROGRAM()))
equation
modelpath = Absyn.crefToPath(model_);
cdef = getPathedClassInProgram(modelpath, p);
package_ = Absyn.stripLast(modelpath);
cmt = SOME(Absyn.COMMENT(SOME(ann), NONE()));
newcdef = addToEquation(cdef, Absyn.EQUATIONITEM(Absyn.EQ_NORETCALL(Absyn.CREF_IDENT("transition", {}), Absyn.FUNCTIONARGS({Absyn.CREF(Absyn.CREF_IDENT(from_, {})), Absyn.CREF(Absyn.CREF_IDENT(to_, {})), Absyn.CREF(Absyn.CREF_IDENT(condition_, {})), Absyn.BOOL(immediate_), Absyn.BOOL(reset_), Absyn.BOOL(synchronize_), Absyn.INTEGER(priority_)}, {})), cmt, Absyn.dummyInfo));
newp = updateProgram(Absyn.PROGRAM({newcdef},Absyn.WITHIN(package_)), p);
then
(true, newp);
end match;
end addTransitionWithAnnotation;

protected function getComponentComment
"Get the component commment."
input Absyn.ComponentRef inComponentRef1;
Expand Down Expand Up @@ -12630,7 +12699,7 @@ algorithm
end createFuncargsFromElementargs;

protected function getNthConnectionitemInClass
" This function takes a Class and an int ane returns the nth
" This function takes a Class and an int ane returns the nth
`EquationItem\' containing a connect statement in that class."
input Absyn.Class inClass;
input Integer inInteger;
Expand Down

0 comments on commit 0735a9d

Please sign in to comment.