Skip to content

Commit c1ffb8e

Browse files
author
Peter Aronsson
committed
getIconAnnotation now works.
git-svn-id: https://openmodelica.org/svn/OpenModelica/trunk@825 f25d12d1-65f4-0310-ae8a-bbce733d8d8e
1 parent f6a2954 commit c1ffb8e

File tree

8 files changed

+308
-62
lines changed

8 files changed

+308
-62
lines changed

modeq/dae.rml

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -314,6 +314,17 @@ relation dump_equations_str: Element list => string =
314314
-------------------------------
315315
dump_equations_str( EQUATION(e1,e2)::xs) => str
316316

317+
rule Exp.print_component_ref_str c => s1 &
318+
string_append(" ",s1) => s2 &
319+
string_append(s2," := ") => s3 &
320+
Exp.print_exp_str e => s4 &
321+
string_append(s3,s4) => s4' &
322+
string_append(s4',";\n") => s5 &
323+
dump_equations_str(xs) => s6 &
324+
string_append(s5,s6) => str
325+
-------------------------------
326+
dump_equations_str( DEFINE(c,e)::xs) => str
327+
317328
rule dump_equations_str(xs) => str
318329
-----------------------------
319330
dump_equations_str(_::xs) => str
@@ -520,7 +531,7 @@ relation dump_equation_str : Element => string =
520531
--------------------------------------
521532
dump_equation_str(EQUATION(e1, e2)) => str
522533

523-
rule print " " & Exp.print_component_ref_str c => s1 &
534+
rule Exp.print_component_ref_str c => s1 &
524535
string_append(" ",s1) => s2 &
525536
string_append(" ::= ",s2) => s3 &
526537
Exp.print_exp_str e => s4 &

modeq/exp.rml

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1008,8 +1008,8 @@ relation print_exp2_str : (Exp,int) => string =
10081008
print_exp2_str(CALL(fcn, args,_,_),_) => s''
10091009

10101010
rule print_list_str(es, print_exp_str, ",") => s &
1011-
string_append ("[",s) => s' &
1012-
string_append (s',"]") => s''
1011+
string_append ("{",s) => s' &
1012+
string_append (s',"}") => s''
10131013
-----------------------------
10141014
print_exp2_str (ARRAY(_,_,es),_) => s''
10151015

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

10221022
rule print_list_str(es, print_row_str, ";") => s &
1023-
string_append ("[",s) => s' &
1024-
string_append (s',"]") => s''
1023+
string_append ("{",s) => s' &
1024+
string_append (s',"}") => s''
10251025
-----------------------------
10261026
print_exp2_str (MATRIX(_,_,es),_) => s''
10271027

@@ -1072,9 +1072,9 @@ relation print_exp2_str : (Exp,int) => string =
10721072
int_string i => s4 &
10731073
string_append (s1, s2) => s &
10741074
string_append (s, s3) => s' &
1075-
string_append (s', "[") => s'' &
1075+
string_append (s', "{") => s'' &
10761076
string_append (s'', s4) => s''' &
1077-
string_append (s''', "]") => s''''
1077+
string_append (s''', "}") => s''''
10781078
---------------------------------------
10791079
print_exp2_str (ASUB(e,i),pri1) => s''''
10801080

modeq/explode.rml

Lines changed: 33 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -128,6 +128,7 @@ module SCode :
128128
relation elaborate : Absyn.Program => Program
129129
relation elab_class: Absyn.Class => Class
130130
relation build_mod : (Absyn.Modification option, bool) => Mod
131+
relation get_element_named: (Ident, Class) => Element
131132
relation print_mod : Mod => ()
132133
relation print_element : Element => ()
133134

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

524525
end
525526

527+
relation get_element_named: (Ident, Class) => Element =
528+
529+
rule get_element_named_from_elts(id,elts) => elt
530+
----------------------------------------
531+
get_element_named(id,CLASS(_,_,_,PARTS(elts,_,_))) => elt
532+
end
533+
534+
relation get_element_named_from_elts: (Ident, Element list) => Element =
535+
536+
rule not id1 = id2 &
537+
get_element_named_from_elts(id2,xs) => elt
538+
---------------------------
539+
get_element_named_from_elts(id2,COMPONENT(id1,_,_,_,_,_)::xs) => elt
540+
541+
rule not id1 = id2 &
542+
get_element_named_from_elts(id2,xs) => elt
543+
---------------------------
544+
get_element_named_from_elts(id2,CLASSDEF(id1,_,_,_)::xs) => elt
545+
546+
rule get_element_named_from_elts(id2,xs) => elt
547+
---------------------------
548+
get_element_named_from_elts(id2,EXTENDS(_,_)::xs) => elt
549+
550+
rule id1 = id2
551+
--------------------
552+
get_element_named_from_elts(id2,(comp as COMPONENT(id1,_,_,_,_,_))::_) => comp
553+
554+
rule id1 = id2
555+
--------------------
556+
get_element_named_from_elts(id2,(cdef as CLASSDEF(id1,_,_,_))::_) => cdef
557+
558+
end
526559
(** relation: print_mod
527560
**
528561
** This relation prints a modification. The code is excluded from

modeq/inst.rml

Lines changed: 25 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -1724,8 +1724,12 @@ relation inst_eq_equation_2 : (Exp.Exp, Exp.Exp, Types.Type)
17241724
axiom inst_eq_equation_2(e1,e2,Types.T_BOOL)
17251725
=> [DAE.EQUATION(e1,e2)]
17261726

1727-
axiom inst_eq_equation_2(e1,e2,Types.T_ENUM)
1728-
=> [DAE.EQUATION(e1,e2)]
1727+
axiom inst_eq_equation_2(Exp.CREF(cr,t),e2,Types.T_ENUM)
1728+
=> [DAE.DEFINE(cr,e2)]
1729+
1730+
axiom inst_eq_equation_2(Exp.CREF(cr,t),e2,Types.T_ENUMERATION(_))
1731+
=> [DAE.DEFINE(cr,e2)]
1732+
17291733

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

1797-
rule print "- inst_eq_equation_2 failed\n"
1801+
rule print "- inst_eq_equation_2 failed\n exp1=" &
1802+
Exp.print_exp e1 &
1803+
print " exp2=" &
1804+
Exp.print_exp e2 &
1805+
print " type =" &
1806+
Types.print_type t &
1807+
print "\n"
17981808
-------------------------------------
1799-
inst_eq_equation_2(_,_,_) => fail
1809+
inst_eq_equation_2(e1,e2,t) => fail
18001810

18011811
end
18021812

@@ -2517,22 +2527,29 @@ end
25172527
relation inst_record_constructor_elt : (Env.Env,SCode.Element) =>
25182528
Types.Var =
25192529

2520-
rule elab_arraydim(env,dim,NONE) => dimexp &
2530+
rule Debug.fprint ("recconst", "inst_record_constructor_elt called\n") &
2531+
elab_arraydim(env,dim,NONE) => dimexp &
2532+
Debug.fprint ("recconst", "elaborated arraydim\n") &
25212533
Lookup.lookup_class(env,t) => (cl,cenv) &
2534+
Debug.fprint ("recconst", "looked up class\n") &
25222535
Mod.elab_mod(env,Prefix.NOPRE,mod) => mod' &
25232536

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

2535-
rule print "#Error, inst_record_constructor_elt failed\n"
2550+
rule print "#Error, inst_record_constructor_elt failed\n element =" &
2551+
SCode.print_element elt &
2552+
print "\n"
25362553
------------------
2537-
inst_record_constructor_elt(_,_) => fail
2554+
inst_record_constructor_elt(env,elt) => fail
25382555
end

modeq/interactive.rml

Lines changed: 41 additions & 43 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,8 @@ module Interactive:
2626
with "inst.rml"
2727
with "explode.rml"
2828
with "dae.rml"
29+
with "staticexp.rml"
30+
with "exp.rml"
2931
datatype InteractiveStmt = IALG of Absyn.Algorithm
3032
| IEXP of Absyn.Exp
3133
datatype InteractiveStmts = ISTMTS of InteractiveStmt list
@@ -64,8 +66,7 @@ val Line_records = "type LinePattern=enumeration(None,Solid,Dash,Dot,DashDot,Das
6466
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;"
6567

6668
(* This variable contains all records needed for the graphical primitives, such as Line, Ellipse, etc. *)
67-
(* PA. Only Line for now... *)
68-
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;"
69+
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;"
6970

7071

7172
(** relation: evaluate
@@ -528,15 +529,7 @@ end
528529
relation get_icon_annotation_str: (Absyn.ElementArg list) => string =
529530

530531
rule string_append(Icon_records,Graphics_records) => records &
531-
get_annotation_string (records,Absyn.ANNOTATION([ann])) => s1 &
532-
get_graphics_constructors_str(mod) => s2 &
533-
string_append(s1,",") => s3 &
534-
string_append(s3,s2) => str
535-
-----------------------------------------------
536-
get_icon_annotation_str ( (ann as Absyn.MODIFICATION(_,Absyn.CREF_IDENT("Icon",_),mod))::_) => str
537-
538-
(* Rule above failed, no graphics elements*)
539-
rule get_annotation_string (Icon_records,Absyn.ANNOTATION([ann])) => str
532+
get_annotation_string (records,Absyn.ANNOTATION([ann])) => str
540533
-----------------------------------------------
541534
get_icon_annotation_str ( (ann as Absyn.MODIFICATION(_,Absyn.CREF_IDENT("Icon",_),mod))::_) => str
542535

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

548-
(** relation: get_graphics_constructors_str
549-
** This relation takes a Modification and extracts the modification of the graphics component
550-
** and makes a list of record constructors for each element of the graphics component.
551-
** This information is then sent to clients as a representation of graphics objects.
552-
**)
553-
relation get_graphics_constructors_str: (Absyn.Modification) => string =
554-
555-
rule get_graphics_constructors_from_modification(mod) => str
556-
-------------------------------------------------------
557-
get_graphics_constructors_str(Absyn.CLASSMOD(Absyn.MODIFICATION(_,Absyn.CREF_IDENT("graphics",_),mod)::_,_)) => str
558-
559-
rule get_graphics_constructors_str(Absyn.CLASSMOD(xs,b)) => str
560-
----------------------------------------
561-
get_graphics_constructors_str(Absyn.CLASSMOD(_::xs,b)) => str
562-
rule print "get_graphics_constructors_str FAILED!\n"
563-
---------
564-
get_graphics_constructors_str(_) => fail
565-
end
566-
567-
relation get_graphics_constructors_from_modification: (Absyn.Modification) => string =
568-
569-
rule get_graphics_constructors_from_modification(Absyn.CLASSMOD(xs,b)) => s1 &
570-
get_annotation_string(Line_records,Absyn.ANNOTATION([ann])) => s2 &
571-
string_append(s1,s2) => str
572-
---------------------------
573-
get_graphics_constructors_from_modification(Absyn.CLASSMOD((ann as Absyn.MODIFICATION(_,Absyn.CREF_IDENT("Line",_),_))::xs,b)) => str
574-
575-
axiom get_graphics_constructors_from_modification(Absyn.CLASSMOD([],_)) => ""
576-
577-
end
578-
579541
relation get_nth_public_connector_str: (Env.Env, Absyn.Class, int) => string =
580542

581543
rule get_nth_connector_str (env, elt, n) => res
@@ -860,6 +822,27 @@ end
860822

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

825+
rule strip_graphics_modification(mod) => (stripmod,[Absyn.MODIFICATION(_,_,Absyn.CLASSMOD(_,SOME(graphicexp)))]) &
826+
SCode.build_mod(SOME(Absyn.CLASSMOD(stripmod,NONE)),false) => mod' &
827+
828+
Parser.parsestring totstring => p &
829+
SCode.elaborate(p) => p' &
830+
Inst.make_env_from_program(p',Absyn.IDENT("Icon")) => env &
831+
get_class_in_program("Icon",p) => placementc &
832+
SCode.elab_class(placementc) => placementclass &
833+
Mod.elab_mod (env,Prefix.NOPRE,mod') => mod'' &
834+
Inst.inst_class(env,mod'',Prefix.NOPRE,[],placementclass,[]) => (dae,cs,t,state) &
835+
(* Put bindings of variables as expressions inside variable elements of the dae instead of equations *)
836+
Inst.init_vars_modelica_output dae => dae' &
837+
DAE.get_variable_bindings_str dae' => str &
838+
839+
Static.elab_exp(env,graphicexp) => (graphicexp2,prop) &
840+
Exp.print_exp_str(graphicexp2) => gexpstr &
841+
string_append(str,",") => s1 &
842+
string_append(s1,gexpstr) => totstr
843+
---------------
844+
get_annotation_string(totstring,Absyn.ANNOTATION([(Absyn.MODIFICATION(_,Absyn.CREF_IDENT("Icon",_),Absyn.CLASSMOD(mod,_)))])) => totstr
845+
863846
rule SCode.build_mod(SOME(Absyn.CLASSMOD(mod,NONE)),false) => mod' &
864847

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

882865
rule print "get_annotation_string failed!\n"
883866
---------------------------------------
884867
get_annotation_string(_,_) => fail
885868
end
869+
870+
(** relation: strip_graphics_modification
871+
** This relation strips out the `graphics' modification from an ElementArg list and return
872+
** two lists, one with the other modifications and the second with the `graphics' modification
873+
**)
874+
relation strip_graphics_modification: (Absyn.ElementArg list) => (Absyn.ElementArg list, Absyn.ElementArg list) =
875+
876+
axiom strip_graphics_modification((mod as Absyn.MODIFICATION(_,Absyn.CREF_IDENT("graphics",_),_))::rest) => (rest, [mod])
877+
878+
rule strip_graphics_modification(rest) => (l1,l2)
879+
------------------------------------------
880+
strip_graphics_modification((mod as Absyn.MODIFICATION(_,_,_))::rest) => (mod::l1,l2)
881+
882+
axiom strip_graphics_modification([]) => ([],[])
883+
end
886884

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

0 commit comments

Comments
 (0)