Skip to content

Commit

Permalink
getIconAnnotation now works.
Browse files Browse the repository at this point in the history
git-svn-id: https://openmodelica.org/svn/OpenModelica/trunk@825 f25d12d1-65f4-0310-ae8a-bbce733d8d8e
  • Loading branch information
Peter Aronsson committed Aug 1, 2002
1 parent f6a2954 commit c1ffb8e
Show file tree
Hide file tree
Showing 8 changed files with 308 additions and 62 deletions.
13 changes: 12 additions & 1 deletion modeq/dae.rml
Expand Up @@ -314,6 +314,17 @@ relation dump_equations_str: Element list => string =
-------------------------------
dump_equations_str( EQUATION(e1,e2)::xs) => str

rule Exp.print_component_ref_str c => s1 &
string_append(" ",s1) => s2 &
string_append(s2," := ") => s3 &
Exp.print_exp_str e => s4 &
string_append(s3,s4) => s4' &
string_append(s4',";\n") => s5 &
dump_equations_str(xs) => s6 &
string_append(s5,s6) => str
-------------------------------
dump_equations_str( DEFINE(c,e)::xs) => str

rule dump_equations_str(xs) => str
-----------------------------
dump_equations_str(_::xs) => str
Expand Down Expand Up @@ -520,7 +531,7 @@ relation dump_equation_str : Element => string =
--------------------------------------
dump_equation_str(EQUATION(e1, e2)) => str

rule print " " & Exp.print_component_ref_str c => s1 &
rule Exp.print_component_ref_str c => s1 &
string_append(" ",s1) => s2 &
string_append(" ::= ",s2) => s3 &
Exp.print_exp_str e => s4 &
Expand Down
12 changes: 6 additions & 6 deletions modeq/exp.rml
Expand Up @@ -1008,8 +1008,8 @@ relation print_exp2_str : (Exp,int) => string =
print_exp2_str(CALL(fcn, args,_,_),_) => s''

rule print_list_str(es, print_exp_str, ",") => s &
string_append ("[",s) => s' &
string_append (s',"]") => s''
string_append ("{",s) => s' &
string_append (s',"}") => s''
-----------------------------
print_exp2_str (ARRAY(_,_,es),_) => s''

Expand All @@ -1020,8 +1020,8 @@ relation print_exp2_str : (Exp,int) => string =
print_exp2_str (TUPLE(es),_) => s''

rule print_list_str(es, print_row_str, ";") => s &
string_append ("[",s) => s' &
string_append (s',"]") => s''
string_append ("{",s) => s' &
string_append (s',"}") => s''
-----------------------------
print_exp2_str (MATRIX(_,_,es),_) => s''

Expand Down Expand Up @@ -1072,9 +1072,9 @@ relation print_exp2_str : (Exp,int) => string =
int_string i => s4 &
string_append (s1, s2) => s &
string_append (s, s3) => s' &
string_append (s', "[") => s'' &
string_append (s', "{") => s'' &
string_append (s'', s4) => s''' &
string_append (s''', "]") => s''''
string_append (s''', "}") => s''''
---------------------------------------
print_exp2_str (ASUB(e,i),pri1) => s''''

Expand Down
33 changes: 33 additions & 0 deletions modeq/explode.rml
Expand Up @@ -128,6 +128,7 @@ module SCode :
relation elaborate : Absyn.Program => Program
relation elab_class: Absyn.Class => Class
relation build_mod : (Absyn.Modification option, bool) => Mod
relation get_element_named: (Ident, Class) => Element
relation print_mod : Mod => ()
relation print_element : Element => ()

Expand Down Expand Up @@ -523,6 +524,38 @@ relation build_sub_sub : (Subscript list, Mod) => Mod =

end

relation get_element_named: (Ident, Class) => Element =

rule get_element_named_from_elts(id,elts) => elt
----------------------------------------
get_element_named(id,CLASS(_,_,_,PARTS(elts,_,_))) => elt
end

relation get_element_named_from_elts: (Ident, Element list) => Element =

rule not id1 = id2 &
get_element_named_from_elts(id2,xs) => elt
---------------------------
get_element_named_from_elts(id2,COMPONENT(id1,_,_,_,_,_)::xs) => elt

rule not id1 = id2 &
get_element_named_from_elts(id2,xs) => elt
---------------------------
get_element_named_from_elts(id2,CLASSDEF(id1,_,_,_)::xs) => elt

rule get_element_named_from_elts(id2,xs) => elt
---------------------------
get_element_named_from_elts(id2,EXTENDS(_,_)::xs) => elt

rule id1 = id2
--------------------
get_element_named_from_elts(id2,(comp as COMPONENT(id1,_,_,_,_,_))::_) => comp

rule id1 = id2
--------------------
get_element_named_from_elts(id2,(cdef as CLASSDEF(id1,_,_,_))::_) => cdef

end
(** relation: print_mod
**
** This relation prints a modification. The code is excluded from
Expand Down
33 changes: 25 additions & 8 deletions modeq/inst.rml
Expand Up @@ -1724,8 +1724,12 @@ relation inst_eq_equation_2 : (Exp.Exp, Exp.Exp, Types.Type)
axiom inst_eq_equation_2(e1,e2,Types.T_BOOL)
=> [DAE.EQUATION(e1,e2)]

axiom inst_eq_equation_2(e1,e2,Types.T_ENUM)
=> [DAE.EQUATION(e1,e2)]
axiom inst_eq_equation_2(Exp.CREF(cr,t),e2,Types.T_ENUM)
=> [DAE.DEFINE(cr,e2)]

axiom inst_eq_equation_2(Exp.CREF(cr,t),e2,Types.T_ENUMERATION(_))
=> [DAE.DEFINE(cr,e2)]


rule RTOpts.split_arrays => true &
(* For debugging.
Expand Down Expand Up @@ -1794,9 +1798,15 @@ relation inst_eq_equation_2 : (Exp.Exp, Exp.Exp, Types.Type)
-------------------------------------------------------------
inst_eq_equation_2(e1, e2, t as Types.T_COMPLEX(_,_)) => dae

rule print "- inst_eq_equation_2 failed\n"
rule print "- inst_eq_equation_2 failed\n exp1=" &
Exp.print_exp e1 &
print " exp2=" &
Exp.print_exp e2 &
print " type =" &
Types.print_type t &
print "\n"
-------------------------------------
inst_eq_equation_2(_,_,_) => fail
inst_eq_equation_2(e1,e2,t) => fail

end

Expand Down Expand Up @@ -2517,22 +2527,29 @@ end
relation inst_record_constructor_elt : (Env.Env,SCode.Element) =>
Types.Var =

rule elab_arraydim(env,dim,NONE) => dimexp &
rule Debug.fprint ("recconst", "inst_record_constructor_elt called\n") &
elab_arraydim(env,dim,NONE) => dimexp &
Debug.fprint ("recconst", "elaborated arraydim\n") &
Lookup.lookup_class(env,t) => (cl,cenv) &
Debug.fprint ("recconst", "looked up class\n") &
Mod.elab_mod(env,Prefix.NOPRE,mod) => mod' &

elab_arraydim(env,dim,NONE) => dimexp &
Debug.fprint ("recconst", "calling inst_var\n") &
inst_var(cenv,mod',Prefix.NOPRE,[],id,cl,attr,dimexp,[],[]) => (_,_,tp') &
Debug.fprint ("recconst", "Type of argument:") &
Debug.fcall ("recconst",Types.print_type,tp') &
Debug.fprint ("recconst","\n") &
Debug.fprint ("recconst","\nMod=") &
Debug.fcall ("recconst",Mod.print_mod,mod') &
Mod.mod_equation mod' => eq &
make_binding(env,attr,eq) => bind
---------------------------------------
inst_record_constructor_elt (env,SCode.COMPONENT(id,_,prot,attr as SCode.ATTR(dim,f,acc,var,dir),t,mod))
=> Types.VAR(id,Types.ATTR(f,acc,var,Absyn.INPUT),prot,tp',bind)

rule print "#Error, inst_record_constructor_elt failed\n"
rule print "#Error, inst_record_constructor_elt failed\n element =" &
SCode.print_element elt &
print "\n"
------------------
inst_record_constructor_elt(_,_) => fail
inst_record_constructor_elt(env,elt) => fail
end
84 changes: 41 additions & 43 deletions modeq/interactive.rml
Expand Up @@ -26,6 +26,8 @@ module Interactive:
with "inst.rml"
with "explode.rml"
with "dae.rml"
with "staticexp.rml"
with "exp.rml"
datatype InteractiveStmt = IALG of Absyn.Algorithm
| IEXP of Absyn.Exp
datatype InteractiveStmts = ISTMTS of InteractiveStmt list
Expand Down Expand Up @@ -64,8 +66,7 @@ val Line_records = "type LinePattern=enumeration(None,Solid,Dash,Dot,DashDot,Das
val Icon_records = "record GraphicItem Boolean visible=true; end GraphicItem; record CoordinateSystem Real extent[2,2]; end CoordinateSystem; record Icon CoordinateSystem coordinateSystem(extent ={{-10.0, -10.0}, {10.0, 10.0}}); GraphicItem graphics[:]; end Icon;"

(* This variable contains all records needed for the graphical primitives, such as Line, Ellipse, etc. *)
(* PA. Only Line for now... *)
val Graphics_records = "type LinePattern=enumeration(None,Solid,Dash,Dot,DashDot,DashDotDot); type Arrow=enumeration(None,Open,Filled,Half); record Line Boolean visible=true; Real points[2,:]; Integer color[3]={0,0,0}; LinePattern pattern = LinePattern.Solid; Real thickness=0.25; Arrow arrow[2]={Arrow.None,Arrow.None}; Real arrowSize = 3.0; Boolean smooth=false; end Line;"
val Graphics_records = "type LinePattern=enumeration(None,Solid,Dash,Dot,DashDot,DashDotDot); type Arrow=enumeration(None,Open,Filled,Half); type FillPattern=enumeration(None,Solid,Horizontal,Vertical,Cross,Forward,Backward,CrossDiag,HorizontalCylinder,VerticalCylinder,Sphere); type BorderPattern=enumeration(None,Raised,Sunken,Engraved); type TextStyle=enumeration(Bold,Italic,Underline); record Line Boolean visible=true; Real points[2,:]; Integer color[3]={0,0,0}; LinePattern pattern = LinePattern.Solid; Real thickness=0.25; Arrow arrow[2]={Arrow.None,Arrow.None}; Real arrowSize = 3.0; Boolean smooth=false; end Line; record Polygon Boolean visible=true;Integer lineColor[3]={0,0,0};Integer fillColor[3]={0,0,0}; LinePattern pattern=LinePattern.Solid; FillPattern fillPattern=FillPattern.None; Real lineThickness=0.25; Real points[:]; Boolean smooth=false; end Polygon; record Rectangle Boolean visible=true;Integer lineColor[3]={0,0,0};Integer fillColor[3]={0,0,0}; LinePattern pattern=LinePattern.Solid; FillPattern fillPattern=FillPattern.None; Real lineThickness=0.25; BorderPattern borderPattern=BorderPattern.None; Real extent[2,2]; Real radius=0.0; end Rectangle; record Ellipse Boolean visible=true;Integer lineColor[3]={0,0,0};Integer fillColor[3]={0,0,0}; LinePattern pattern=LinePattern.Solid; FillPattern fillPattern=FillPattern.None; Real lineThickness=0.25; Real extent[2,2]; end Ellipse; record Text Boolean visible=true;Integer lineColor[3]={0,0,0};Integer fillColor[3]={0,0,0}; LinePattern pattern=LinePattern.Solid; FillPattern fillPattern=FillPattern.None; Real lineThickness=0.25; Real extent[2,2]; String textString; Real fontSize; String fontName; TextStyle textStyle[:]; end Text;"


(** relation: evaluate
Expand Down Expand Up @@ -528,15 +529,7 @@ end
relation get_icon_annotation_str: (Absyn.ElementArg list) => string =

rule string_append(Icon_records,Graphics_records) => records &
get_annotation_string (records,Absyn.ANNOTATION([ann])) => s1 &
get_graphics_constructors_str(mod) => s2 &
string_append(s1,",") => s3 &
string_append(s3,s2) => str
-----------------------------------------------
get_icon_annotation_str ( (ann as Absyn.MODIFICATION(_,Absyn.CREF_IDENT("Icon",_),mod))::_) => str

(* Rule above failed, no graphics elements*)
rule get_annotation_string (Icon_records,Absyn.ANNOTATION([ann])) => str
get_annotation_string (records,Absyn.ANNOTATION([ann])) => str
-----------------------------------------------
get_icon_annotation_str ( (ann as Absyn.MODIFICATION(_,Absyn.CREF_IDENT("Icon",_),mod))::_) => str

Expand All @@ -545,37 +538,6 @@ relation get_icon_annotation_str: (Absyn.ElementArg list) => string =
get_icon_annotation_str( _::xs) => str
end

(** relation: get_graphics_constructors_str
** This relation takes a Modification and extracts the modification of the graphics component
** and makes a list of record constructors for each element of the graphics component.
** This information is then sent to clients as a representation of graphics objects.
**)
relation get_graphics_constructors_str: (Absyn.Modification) => string =

rule get_graphics_constructors_from_modification(mod) => str
-------------------------------------------------------
get_graphics_constructors_str(Absyn.CLASSMOD(Absyn.MODIFICATION(_,Absyn.CREF_IDENT("graphics",_),mod)::_,_)) => str

rule get_graphics_constructors_str(Absyn.CLASSMOD(xs,b)) => str
----------------------------------------
get_graphics_constructors_str(Absyn.CLASSMOD(_::xs,b)) => str
rule print "get_graphics_constructors_str FAILED!\n"
---------
get_graphics_constructors_str(_) => fail
end

relation get_graphics_constructors_from_modification: (Absyn.Modification) => string =

rule get_graphics_constructors_from_modification(Absyn.CLASSMOD(xs,b)) => s1 &
get_annotation_string(Line_records,Absyn.ANNOTATION([ann])) => s2 &
string_append(s1,s2) => str
---------------------------
get_graphics_constructors_from_modification(Absyn.CLASSMOD((ann as Absyn.MODIFICATION(_,Absyn.CREF_IDENT("Line",_),_))::xs,b)) => str

axiom get_graphics_constructors_from_modification(Absyn.CLASSMOD([],_)) => ""

end

relation get_nth_public_connector_str: (Env.Env, Absyn.Class, int) => string =

rule get_nth_connector_str (env, elt, n) => res
Expand Down Expand Up @@ -860,6 +822,27 @@ end

relation get_annotation_string: (string,Absyn.Annotation) => string =

rule strip_graphics_modification(mod) => (stripmod,[Absyn.MODIFICATION(_,_,Absyn.CLASSMOD(_,SOME(graphicexp)))]) &
SCode.build_mod(SOME(Absyn.CLASSMOD(stripmod,NONE)),false) => mod' &

Parser.parsestring totstring => p &
SCode.elaborate(p) => p' &
Inst.make_env_from_program(p',Absyn.IDENT("Icon")) => env &
get_class_in_program("Icon",p) => placementc &
SCode.elab_class(placementc) => placementclass &
Mod.elab_mod (env,Prefix.NOPRE,mod') => mod'' &
Inst.inst_class(env,mod'',Prefix.NOPRE,[],placementclass,[]) => (dae,cs,t,state) &
(* Put bindings of variables as expressions inside variable elements of the dae instead of equations *)
Inst.init_vars_modelica_output dae => dae' &
DAE.get_variable_bindings_str dae' => str &

Static.elab_exp(env,graphicexp) => (graphicexp2,prop) &
Exp.print_exp_str(graphicexp2) => gexpstr &
string_append(str,",") => s1 &
string_append(s1,gexpstr) => totstr
---------------
get_annotation_string(totstring,Absyn.ANNOTATION([(Absyn.MODIFICATION(_,Absyn.CREF_IDENT("Icon",_),Absyn.CLASSMOD(mod,_)))])) => totstr

rule SCode.build_mod(SOME(Absyn.CLASSMOD(mod,NONE)),false) => mod' &

Parser.parsestring totstring => p &
Expand All @@ -876,13 +859,28 @@ relation get_annotation_string: (string,Absyn.Annotation) => string =
Debug.fprint ("interactivedump","Mod =") &
Debug.fcall ("interactivedump",SCode.print_mod, mod') &
DAE.get_variable_bindings_str dae' => str
---------------------------
-----------------------------------------
get_annotation_string(totstring, Absyn.ANNOTATION([(Absyn.MODIFICATION(_,Absyn.CREF_IDENT(anncname,_),Absyn.CLASSMOD(mod,_)))])) => str

rule print "get_annotation_string failed!\n"
---------------------------------------
get_annotation_string(_,_) => fail
end

(** relation: strip_graphics_modification
** This relation 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
**)
relation strip_graphics_modification: (Absyn.ElementArg list) => (Absyn.ElementArg list, Absyn.ElementArg list) =

axiom strip_graphics_modification((mod as Absyn.MODIFICATION(_,Absyn.CREF_IDENT("graphics",_),_))::rest) => (rest, [mod])

rule strip_graphics_modification(rest) => (l1,l2)
------------------------------------------
strip_graphics_modification((mod as Absyn.MODIFICATION(_,_,_))::rest) => (mod::l1,l2)

axiom strip_graphics_modification([]) => ([],[])
end

relation get_nth_public_component_in_class: (Absyn.Class,int) => Absyn.Element =

Expand Down

0 comments on commit c1ffb8e

Please sign in to comment.