Skip to content

Commit

Permalink
- fixes for DynamicSelect in annotations (return the first and consta…
Browse files Browse the repository at this point in the history
…nt part)

- faster retrieval of annotations.
- fixes for the interactive simulation test and small fixes to the client.


git-svn-id: https://openmodelica.org/svn/OpenModelica/trunk@7490 f25d12d1-65f4-0310-ae8a-bbce733d8d8e
  • Loading branch information
adrpo committed Dec 19, 2010
1 parent dc1e0b6 commit e95a240
Show file tree
Hide file tree
Showing 4 changed files with 101 additions and 35 deletions.
70 changes: 52 additions & 18 deletions Compiler/FrontEnd/Absyn.mo
Expand Up @@ -4461,28 +4461,27 @@ algorithm

case ({}) then true;

// search return false if we have DynamicSelect, OnMouse*
case (MODIFICATION(componentRef = CREF_IDENT(name,_)) :: rest)
// skip "interaction" annotation!
case (MODIFICATION(componentRef = CREF_IDENT(name = "interaction")) :: rest)
equation
b1 = stringEq(name, "DynamicSelect");
b2 = (0 == System.strncmp("OnMouse", name, 7));
true = boolOr(b1, b2);
b = onlyLiteralsInAnnotationMod(rest);
then
false;
b;


// search inside, some(exp)
case (MODIFICATION(modification = SOME(CLASSMOD(dive, expOpt))) :: rest)
equation
b1 = onlyLiteralsInExpOpt(expOpt);
b2 = onlyLiteralsInAnnotationMod(dive);
b3 = onlyLiteralsInAnnotationMod(rest);
b = boolAnd(b1, boolAnd(b2, b3));
b1 = onlyLiteralsInExpOpt(expOpt);
b2 = onlyLiteralsInAnnotationMod(dive);
b3 = onlyLiteralsInAnnotationMod(rest);
b = boolAnd(b1, boolAnd(b2, b3));
then
b;

case (_ :: rest)
equation
b = onlyLiteralsInAnnotationMod(rest);
b = onlyLiteralsInAnnotationMod(rest);
then
b;

Expand All @@ -4501,35 +4500,70 @@ algorithm
onlyLiterals := matchcontinue(inExpOpt)
local
Exp exp;
list<Exp> lst;
Boolean b;

case (NONE()) then true;

// DynamicSelect returns true!
case (SOME(CALL(function_ = CREF_IDENT(name = "DynamicSelect")))) then true;

// search inside, some(exp)
case (SOME(exp))
equation
((_, b)) = traverseExp(exp, onlyLiteralsInExp, true);
((_, lst)) = traverseExp(exp, onlyLiteralsInExp, {});
// if list is empty (no crefs were added)
b = Util.isListEmpty(lst);
// debugging:
// print("Crefs in annotations: (" +& Util.stringDelimitList(Util.listMap(inAnnotationMod, Dump.printExpStr), ", ") +& ")\n");
then
b;
end matchcontinue;
end onlyLiteralsInExpOpt;

protected function onlyLiteralsInExp
"@author: adrpo
Visitor function for checking if Absyn.Exp contains only literals, NO CREFS!"
input tuple<Exp, Boolean> tpl;
output tuple<Exp, Boolean> outTpl;
Visitor function for checking if Absyn.Exp contains only literals, NO CREFS!
It returns an empty list if it doesn't contain any crefs!"
input tuple<Exp, list<Exp>> tpl;
output tuple<Exp, list<Exp>> outTpl;
algorithm
outTpl := matchcontinue(tpl)
local
Option<Path> optPath;
Path cname,path,usesName,cname2;
Exp e;
ComponentRef cr;
Boolean b;
list<Exp> lst, lstArgs;
String name;
FunctionArgs fargs;

// first handle DynamicSelect
case ((e as CALL(function_ = CREF_IDENT(name = "DynamicSelect"), functionArgs = fargs), lst))
equation
((_, lstArgs)) = traverseExpFunctionArgs(fargs, onlyLiteralsInExp, {});
// if the lst is the same as the one got from args, return nothing
equality(lst = lstArgs);
then
((e, {}));

// first handle all graphic enumerations!
// FillPattern.*, Smooth.*, TextAlignment.*, etc!
case ((e as CREF(cr as CREF_QUAL(name=name)), lst))
equation
true = listMember(name,{
"LinePattern",
"Arrow",
"FillPattern",
"BorderPattern",
"TextStyle",
"Smooth",
"TextAlignment"});
then
((e, lst));

// crefs, return false
case((e as CREF(cr), _)) then ((e,false));
// crefs, add to list
case ((e as CREF(cr), lst)) then ((e,e::lst));
// anything else, return the same!
case(tpl) then tpl;

Expand Down
7 changes: 7 additions & 0 deletions Compiler/FrontEnd/Static.mo
Expand Up @@ -376,6 +376,13 @@ algorithm
then
(cache,e_1,prop,st_3);

// adrpo: deal with DynamicSelect(literalExp, dynamicExp) by returning literalExp only!
case (cache,env,Absyn.CALL(function_ = Absyn.CREF_IDENT("DynamicSelect",_),functionArgs = Absyn.FUNCTIONARGS(args = (e1 :: _),argNames = _)),impl,st,doVect,pre,info)
equation
(cache,e_1,prop,st_1) = elabExp(cache,env, e1, impl, st, doVect, pre, info);
then
(cache,e_1,prop,st_1);

/*--------------------------------*/
/* Part of MetaModelica extension. KS */
case (cache,env,Absyn.CALL(function_ = Absyn.CREF_IDENT("SOME",_),functionArgs = Absyn.FUNCTIONARGS(args = (e1 :: _),argNames = _)),impl,st,doVect,pre,info)
Expand Down
48 changes: 33 additions & 15 deletions Compiler/Script/Interactive.mo
Expand Up @@ -14469,14 +14469,19 @@ algorithm
graphicProgram = modelicaAnnotationProgram(RTOpts.getAnnotationVersion());
graphicProgram = updateProgram(graphicProgram, inFullProgram);
graphicProgramSCode = SCodeUtil.translateAbsyn2SCode(graphicProgram);

// debugging
// print("Get annotation via full instantiation of: " +& Absyn.pathString(inModelPath) +& "\n");
// print("Annotation to get: (" +& Util.stringDelimitList(Util.listMap(inAnnotationMod, Dump.unparseElementArgStr), ", ") +& ")\n");
// print("Annotation class: " +& inAnnotationClass +& "\n");

// fully instantiate the class that contains the annotation!
// set check model on so that partial classes can be instantiated!
// set check model on so that partial classes can be instantiated!
b1 = OptManager.getOption("checkModel");
b2 = RTOpts.getEvaluateParametersInAnnotations();
OptManager.setOption("checkModel", true);
RTOpts.setEvaluateParametersInAnnotations(true); // set to evaluate the parameters!
(cache,env,_,_) = Inst.instantiateClass(Env.emptyCache(),InnerOuter.emptyInstHierarchy,graphicProgramSCode,inModelPath);

RTOpts.setEvaluateParametersInAnnotations(b2);
OptManager.setOption("checkModel", b1);
then
Expand All @@ -14486,6 +14491,12 @@ algorithm
case (inFullProgram, inModelPath, inAnnotationMod, inAnnotationClass)
equation
true = Absyn.onlyLiteralsInAnnotationMod(inAnnotationMod);

// debugging
// print("Get annotation via small instantiation of: " +& Absyn.pathString(inModelPath) +& "\n");
// print("Annotation to get: (" +& Util.stringDelimitList(Util.listMap(inAnnotationMod, Dump.unparseElementArgStr), ", ") +& ")\n");
// print("Annotation class: " +& inAnnotationClass +& "\n");

graphicProgram = modelicaAnnotationProgram(RTOpts.getAnnotationVersion());
graphicProgramSCode = SCodeUtil.translateAbsyn2SCode(graphicProgram);
(cache,env) = Inst.makeSimpleEnvFromProgram(Env.emptyCache(), graphicProgramSCode, Absyn.IDENT(inAnnotationClass));
Expand Down Expand Up @@ -14537,7 +14548,7 @@ algorithm
equation
// print(Dump.unparseStr(graphicProgram, false));
// print("Annotation(Icon) 1: " +& Dump.unparseMod1Str(mod) +& "\n");
(stripmod,{Absyn.MODIFICATION(modification = SOME(Absyn.CLASSMOD(_,SOME(graphicexp))))}) = stripGraphicsModification(mod);
(stripmod,{Absyn.MODIFICATION(modification = SOME(Absyn.CLASSMOD(_,SOME(graphicexp))))}) = stripGraphicsAndInteractionModification(mod);

// print("Annotation(Icon) 1: " +& Dump.unparseMod1Str(stripmod) +& "\n");

Expand Down Expand Up @@ -14565,15 +14576,15 @@ algorithm
then
totstr;

// First line in the first rule above fails if return value from stripGraphicsModification doesn't match the lhs
// First line in the first rule above fails if return value from stripGraphicsAndInteractionModification doesn't match the lhs
case (Absyn.ANNOTATION(elementArgs = {Absyn.MODIFICATION(componentRef = Absyn.CREF_IDENT(name = "Icon"),modification = SOME(Absyn.CLASSMOD(mod,_)))}),
inClass,
inFullProgram,
inModelPath)
equation
// print(Dump.unparseStr(p, false));
// print("Annotation(Icon): " +& Dump.unparseMod1Str(mod) +& "\n");
(stripmod,gxmods) = stripGraphicsModification(mod);
(stripmod,gxmods) = stripGraphicsAndInteractionModification(mod);
mod_1 = SCodeUtil.translateMod(SOME(Absyn.CLASSMOD(stripmod,NONE())), false, Absyn.NON_EACH());

// print("Annotation(Icon) 2: " +& Dump.unparseMod1Str(stripmod) +& "\n");
Expand All @@ -14600,7 +14611,7 @@ algorithm
equation
// print(Dump.unparseStr(p, false));
// print("Annotation(Diagram): " +& Dump.unparseMod1Str(mod) +& "\n");
(stripmod,{Absyn.MODIFICATION(_,_,_,SOME(Absyn.CLASSMOD(_,SOME(graphicexp))),_)}) = stripGraphicsModification(mod);
(stripmod,{Absyn.MODIFICATION(_,_,_,SOME(Absyn.CLASSMOD(_,SOME(graphicexp))),_)}) = stripGraphicsAndInteractionModification(mod);
mod_1 = SCodeUtil.translateMod(SOME(Absyn.CLASSMOD(stripmod,NONE())), false, Absyn.NON_EACH());

// print("Annotation(Diagram) 1: " +& Dump.unparseMod1Str(stripmod) +& "\n");
Expand All @@ -14625,15 +14636,15 @@ algorithm
then
totstr;

// First line in the first rule above fails if return value from stripGraphicsModification doesn't match the lhs
// First line in the first rule above fails if return value from stripGraphicsAndInteractionModification doesn't match the lhs
case (Absyn.ANNOTATION(elementArgs = {Absyn.MODIFICATION(componentRef = Absyn.CREF_IDENT(name = "Diagram"),modification = SOME(Absyn.CLASSMOD(mod,_)))}),
inClass,
inFullProgram,
inModelPath)
equation
// print(Dump.unparseStr(p, false));
// print("Annotation(Icon): " +& Dump.unparseMod1Str(mod) +& "\n");
(stripmod,gxmods) = stripGraphicsModification(mod);
(stripmod,gxmods) = stripGraphicsAndInteractionModification(mod);
mod_1 = SCodeUtil.translateMod(SOME(Absyn.CLASSMOD(stripmod,NONE())), false, Absyn.NON_EACH());

// print("Annotation(Diagram) 2: " +& Dump.unparseMod1Str(stripmod) +& "\n");
Expand All @@ -14660,7 +14671,7 @@ algorithm
equation
// print(Dump.unparseStr(p, false));
// print("Annotation(" +& anncname +& "): " +& Dump.unparseMod1Str(mod) +& "\n");
(stripmod,gxmods) = stripGraphicsModification(mod);
(stripmod,gxmods) = stripGraphicsAndInteractionModification(mod);
mod_1 = SCodeUtil.translateMod(SOME(Absyn.CLASSMOD(stripmod,NONE())), false, Absyn.NON_EACH());

// print("ANY Annotation(" +& anncname +& ") : " +& Dump.unparseMod1Str(mod) +& "\n");
Expand Down Expand Up @@ -14698,8 +14709,8 @@ algorithm
end matchcontinue;
end getAnnotationString;

protected function stripGraphicsModification
"function: stripGraphicsModification
protected function stripGraphicsAndInteractionModification
"function: stripGraphicsAndInteractionModification
This function strips out the `graphics\' modification from an ElementArg
list and return two lists, one with the other modifications and the
second with the `graphics\' modification"
Expand All @@ -14715,29 +14726,36 @@ algorithm
// handle empty
case ({}) then ({},{});

// adrpo: remove interaction annotations as we don't handle them currently
case (((mod as Absyn.MODIFICATION(modification = _, componentRef = Absyn.CREF_IDENT(name = "interaction"))) :: rest))
equation
(l1,l2) = stripGraphicsAndInteractionModification(rest);
then
(l1,l2);

// adrpo: remove empty annotations, to handle bad Dymola annotations, for example: Diagram(graphics)
case (((mod as Absyn.MODIFICATION(modification = NONE(), componentRef = Absyn.CREF_IDENT(name = "graphics"))) :: rest))
equation
(l1,l2) = stripGraphicsModification(rest);
(l1,l2) = stripGraphicsAndInteractionModification(rest);
then
(l1,l2);

// add graphics to the second tuple
case (((mod as Absyn.MODIFICATION(modification = SOME(_), componentRef = Absyn.CREF_IDENT(name = "graphics"))) :: rest))
equation
(l1,l2) = stripGraphicsModification(rest);
(l1,l2) = stripGraphicsAndInteractionModification(rest);
then
(l1,mod::l2);

// collect in the first tuple
case (((mod as Absyn.MODIFICATION(finalItem = _)) :: rest))
equation
(l1,l2) = stripGraphicsModification(rest);
(l1,l2) = stripGraphicsAndInteractionModification(rest);
then
((mod :: l1),l2);

end matchcontinue;
end stripGraphicsModification;
end stripGraphicsAndInteractionModification;

public function getComponentsInClass
"function: getComponentsInClass
Expand Down
11 changes: 9 additions & 2 deletions c_runtime/interactive/client.cpp
Expand Up @@ -156,6 +156,13 @@ THREAD_RET_TYPE threadControlClient(void*)
{
cout << "Message to be send: " << message << endl; fflush(stdout);

// set the shutDownInProgress flag so we don't get failure on receive messages
// from the transfer thread and server control thread
if(message.compare(0, 8, "shutdown") == 0)
{
shutDownInProgress = 1;
}

if(!s1.send(message))
{
cout << "Failed to send message!" << endl; fflush(stdout);
Expand All @@ -164,9 +171,9 @@ THREAD_RET_TYPE threadControlClient(void*)

if(message.compare(0, 8, "shutdown") == 0)
{
cout << "Shuting down in 3 seconds .... due to shutdown message: " << message << endl; fflush(stdout);
cout << "Shuting down in 2 seconds .... due to shutdown message: " << message << endl; fflush(stdout);
shutDownInProgress = 1;
delay(3000);
delay(2000);
break;
}
}
Expand Down

0 comments on commit e95a240

Please sign in to comment.