Skip to content

Commit

Permalink
- fixed more problems with annotations.
Browse files Browse the repository at this point in the history
- now if we fail to instantiate an annotation we return it as it is:
  { annotation(...) }
- if an annotation is not present at all we return {} instead of empty string.
- moved interactive tests to testsuite/interactive
- Lookup.lookupVar2 now only prints an error message if +d=lookup is present (not on +d=failtrace).
- added all extra tests into testsuite/interactive/interactive_api_annotations.mos

git-svn-id: https://openmodelica.org/svn/OpenModelica/trunk@7052 f25d12d1-65f4-0310-ae8a-bbce733d8d8e
  • Loading branch information
adrpo committed Nov 17, 2010
1 parent c747844 commit ccd240d
Show file tree
Hide file tree
Showing 5 changed files with 138 additions and 47 deletions.
11 changes: 11 additions & 0 deletions Compiler/Absyn.mo
Expand Up @@ -4498,9 +4498,20 @@ algorithm
list<ElementArg> dive, rest;
Option<Exp> expOpt;
Boolean b1, b2, b3, b;
String name;

case ({}) then true;

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

// search inside, some(exp)
case (MODIFICATION(modification = SOME(CLASSMOD(dive, expOpt))) :: rest)
equation
Expand Down
54 changes: 29 additions & 25 deletions Compiler/Constants.mo
Expand Up @@ -366,34 +366,38 @@ end Bitmap;
// );
// events & interaction
// record OnMouseDownSetBoolean
// Boolean variable \"Name of variable to change when mouse button pressed\";
// Boolean value \"Assigned value\";
// end OnMouseDown;
record OnMouseDownSetBoolean
Boolean variable \"Name of variable to change when mouse button pressed\";
Boolean value \"Assigned value\";
end OnMouseDownSetBoolean;
// interaction={OnMouseDown(on, true), OnMouseUp(on, false)};
// record OnMouseMoveXSetReal
// Real xVariable \"Name of variable to change when cursor moved in x direction\";
// Real minValue;
// Real maxValue;
// end OnMouseMoveXSetReal;
//
// record OnMouseMoveYSetReal
// Real yVariable \"Name of variable to change when cursor moved in y direction\";
// Real minValue;
// Real maxValue;
// end OnMouseMoveYSetReal;
//
// record OnMouseDownEditInteger
// Integer variable \"Name of variable to change\";
// end OnMouseDownEditInteger;
record OnMouseMoveXSetReal
Real xVariable \"Name of variable to change when cursor moved in x direction\";
Real minValue;
Real maxValue;
end OnMouseMoveXSetReal;
//
// record OnMouseDownEditReal
// Real variable \"Name of variable to change\";
// end OnMouseDownEditReal;
record OnMouseMoveYSetReal
Real yVariable \"Name of variable to change when cursor moved in y direction\";
Real minValue;
Real maxValue;
end OnMouseMoveYSetReal;
record OnMouseDownEditInteger
Integer variable \"Name of variable to change\";
end OnMouseDownEditInteger;
record OnMouseDownEditReal
Real variable \"Name of variable to change\";
end OnMouseDownEditReal;
//
// record OnMouseDownEditString
// String variable \"Name of variable to change\";
// end OnMouseDownEditString;
record OnMouseDownEditString
String variable \"Name of variable to change\";
end OnMouseDownEditString;
//
// annotation(defaultComponentName = \"name\")
// annotation(missingInnerMessage = \"message\")
Expand Down
105 changes: 90 additions & 15 deletions Compiler/Interactive.mo
Expand Up @@ -11858,7 +11858,9 @@ algorithm
str = getAnnotationInClass(cdef, DIAGRAM_ANNOTATION(), p, modelpath);
then
str;
case (_,_) then "get_diagram_annotation failed!";
case (_,_)
then
"{}";
end matchcontinue;
end getDiagramAnnotation;

Expand All @@ -11883,13 +11885,19 @@ algorithm
String str;
Absyn.Path modelpath;
Absyn.Program p;

case (modelpath,p,id,f)
equation
cdef = getPathedClassInProgram(modelpath, p);
str = getNamedAnnotationInClass(cdef,id,f);
// fail if is empty!
false = stringEq(str, "");
then
str;
case (_,_,_,_) then "";

case (_,_,_,_)
then
"{}";
end matchcontinue;
end getNamedAnnotation;

Expand All @@ -11914,7 +11922,9 @@ algorithm
str = getAnnotationInClass(cdef, ICON_ANNOTATION(), p, modelpath);
then
str;
case (_,_) then "";
case (_,_)
then
"{}";
end matchcontinue;
end getIconAnnotation;

Expand Down Expand Up @@ -13222,7 +13232,10 @@ algorithm
then
s;

case (_) then "";
// adrpo: fail if we don't find it!
// case (_)
// then
// "";
end matchcontinue;
end getDocumentationAnnotationString;

Expand Down Expand Up @@ -14287,8 +14300,11 @@ algorithm
inModelPath)
equation
// print(Dump.unparseStr(graphicProgram, false));
// print("Annotation(Icon): " +& Dump.unparseMod1Str(mod) +& "\n");
(stripmod,{Absyn.MODIFICATION(_,_,_,SOME(Absyn.CLASSMOD(_,SOME(graphicexp))),_)}) = stripGraphicsModification(mod);
// print("Annotation(Icon) 1: " +& Dump.unparseMod1Str(mod) +& "\n");
(stripmod,{Absyn.MODIFICATION(modification = SOME(Absyn.CLASSMOD(_,SOME(graphicexp))))}) = stripGraphicsModification(mod);

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

mod_1 = SCodeUtil.translateMod(SOME(Absyn.CLASSMOD(stripmod,NONE())), false, Absyn.NON_EACH());

(cache, env, graphicProgram) = buildEnvForGraphicProgram(inFullProgram, inModelPath, mod, "Icon");
Expand Down Expand Up @@ -14320,9 +14336,11 @@ algorithm
// print("Annotation(Icon): " +& Dump.unparseMod1Str(mod) +& "\n");
(stripmod,gxmods) = stripGraphicsModification(mod);
mod_1 = SCodeUtil.translateMod(SOME(Absyn.CLASSMOD(stripmod,NONE())), false, Absyn.NON_EACH());


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

(cache, env, graphicProgram) = buildEnvForGraphicProgram(inFullProgram, inModelPath, mod, "Icon");

placementc = getClassInProgram("Icon", graphicProgram);
placementclass = SCodeUtil.translateClass(placementc);
(cache,mod_2) = Mod.elabMod(cache, env, InnerOuter.emptyInstHierarchy, Prefix.NOPRE(), mod_1, true, Absyn.dummyInfo);
Expand All @@ -14345,6 +14363,8 @@ algorithm
// print("Annotation(Diagram): " +& Dump.unparseMod1Str(mod) +& "\n");
(stripmod,{Absyn.MODIFICATION(_,_,_,SOME(Absyn.CLASSMOD(_,SOME(graphicexp))),_)}) = stripGraphicsModification(mod);
mod_1 = SCodeUtil.translateMod(SOME(Absyn.CLASSMOD(stripmod,NONE())), false, Absyn.NON_EACH());

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

(cache, env, graphicProgram) = buildEnvForGraphicProgram(inFullProgram, inModelPath, mod, "Diagram");

Expand All @@ -14363,14 +14383,45 @@ algorithm
then
totstr;

// First line in the first rule above fails if return value from stripGraphicsModification 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);
mod_1 = SCodeUtil.translateMod(SOME(Absyn.CLASSMOD(stripmod,NONE())), false, Absyn.NON_EACH());

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

(cache, env, graphicProgram) = buildEnvForGraphicProgram(inFullProgram, inModelPath, mod, "Diagram");

placementc = getClassInProgram("Icon", graphicProgram);
placementclass = SCodeUtil.translateClass(placementc);
(cache,mod_2) = Mod.elabMod(cache, env, InnerOuter.emptyInstHierarchy, Prefix.NOPRE(), mod_1, true, Absyn.dummyInfo);
(cache,_,_,_,dae,cs,t,state,_,_) =
Inst.instClass(cache, env, InnerOuter.emptyInstHierarchy, UnitAbsyn.noStore,
mod_2, Prefix.NOPRE(), Connect.emptySet,
placementclass, {}, false, Inst.TOP_CALL(),
ConnectionGraph.EMPTY);
str = DAEUtil.getVariableBindingsStr(DAEUtil.daeElements(dae));
Print.clearErrorBuf() "this is to clear the error-msg generated by the annotations." ;
then
str;

case (Absyn.ANNOTATION(elementArgs = {Absyn.MODIFICATION(componentRef = Absyn.CREF_IDENT(name = anncname),modification = SOME(Absyn.CLASSMOD(mod,_)))}),
inClass,
inFullProgram,
inModelPath)
equation
// print(Dump.unparseStr(p, false));
// print("Annotation(" +& anncname +& "): " +& Dump.unparseMod1Str(mod) +& "\n");
mod_1 = SCodeUtil.translateMod(SOME(Absyn.CLASSMOD(mod,NONE())), false, Absyn.NON_EACH());
// print("Annotation(" +& anncname +& "): " +& Dump.unparseMod1Str(mod) +& "\n");
(stripmod,gxmods) = stripGraphicsModification(mod);
mod_1 = SCodeUtil.translateMod(SOME(Absyn.CLASSMOD(stripmod,NONE())), false, Absyn.NON_EACH());

// print("ANY Annotation(" +& anncname +& ") : " +& Dump.unparseMod1Str(mod) +& "\n");

(cache, env, graphicProgram) = buildEnvForGraphicProgram(inFullProgram, inModelPath, mod, anncname);

Expand All @@ -14387,7 +14438,14 @@ algorithm
then
str;

case (inAnnotation, inClass, inFullProgram,inModelPath)
// if we fail, just return the annotation as it is
case (inAnnotation, inClass, inFullProgram, inModelPath)
equation
str = Dump.unparseAnnotationOption(0, SOME(inAnnotation)) +& " ";
then
str;

case (inAnnotation, inClass, inFullProgram, inModelPath)
equation
true = RTOpts.debugFlag("failtrace");
Debug.fprintln("failtrace",
Expand All @@ -14407,18 +14465,35 @@ protected function stripGraphicsModification
output list<Absyn.ElementArg> outAbsynElementArgLst1;
output list<Absyn.ElementArg> outAbsynElementArgLst2;
algorithm
(outAbsynElementArgLst1,outAbsynElementArgLst2):=
matchcontinue (inAbsynElementArgLst)
(outAbsynElementArgLst1,outAbsynElementArgLst2) := matchcontinue (inAbsynElementArgLst)
local
Absyn.ElementArg mod;
list<Absyn.ElementArg> rest,l1,l2;
case (((mod as Absyn.MODIFICATION(componentRef = Absyn.CREF_IDENT(name = "graphics"))) :: rest)) then (rest,{mod});

// handle empty
case ({}) then ({},{});

// 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);
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);
then
(l1,mod::l2);

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

end matchcontinue;
end stripGraphicsModification;

Expand Down
2 changes: 1 addition & 1 deletion Compiler/Lookup.mo
Expand Up @@ -2354,7 +2354,7 @@ algorithm
fail();*/
case (cache,ht,id)
equation
true = RTOpts.debugFlag("failtrace");
true = RTOpts.debugFlag("lookup");
false = RTOpts.acceptMetaModelicaGrammar(); // MetaModelica function references generate too much failtrace...
Env.CLASS(SCode.CLASS(name = name, restriction = r), env) = Env.avlTreeGet(ht, id);
name = id +& " = " +& Env.printEnvPathStr(env) +& "." +& name;
Expand Down
13 changes: 7 additions & 6 deletions Compiler/Static.mo
Expand Up @@ -1483,14 +1483,15 @@ algorithm
case (cache,_,Absyn.BOOL(value = b),impl,_,info)
then
(cache,DAE.BCONST(b),DAE.PROP(DAE.T_BOOL_DEFAULT,DAE.C_CONST()));
// adrpo: 2010-11-17 this is now fixed!
// adrpo, if we have useHeatPort, return false.
// this is a workaround for handling Modelica.Electrical.Analog.Basic.Resistor
case (cache,env,Absyn.CREF(componentRef = cr as Absyn.CREF_IDENT("useHeatPort", _)),impl,pre,info)
equation
dexp = DAE.BCONST(false);
prop = DAE.PROP(DAE.T_BOOL_DEFAULT, DAE.C_CONST());
then
(cache,dexp,prop);
// case (cache,env,Absyn.CREF(componentRef = cr as Absyn.CREF_IDENT("useHeatPort", _)),impl,pre,info)
// equation
// dexp = DAE.BCONST(false);
// prop = DAE.PROP(DAE.T_BOOL_DEFAULT, DAE.C_CONST());
// then
// (cache,dexp,prop);
case (cache,env,Absyn.CREF(componentRef = cr),impl,pre,info)
equation
Debug.fprint("tcvt","before Static.elabCref in elabGraphicsExp\n");
Expand Down

0 comments on commit ccd240d

Please sign in to comment.