Skip to content

Commit

Permalink
Added connection annotations to parser and absyn.
Browse files Browse the repository at this point in the history
git-svn-id: https://openmodelica.org/svn/OpenModelica/trunk@801 f25d12d1-65f4-0310-ae8a-bbce733d8d8e
  • Loading branch information
Peter Aronsson committed May 30, 2002
1 parent 2a9b9bf commit a8094ce
Show file tree
Hide file tree
Showing 7 changed files with 99 additions and 30 deletions.
17 changes: 10 additions & 7 deletions modeq/absyn.rml
Expand Up @@ -73,7 +73,7 @@ module Absyn:

datatype ClassPart = PUBLIC of ElementItem list
| PROTECTED of ElementItem list
| EQUATIONS of Equation list
| EQUATIONS of EquationItem list
| ALGORITHMS of Algorithm list
(** A class definition contains several parts. There are public and *)
(** protected component declarations, type definitions and `extends' *)
Expand Down Expand Up @@ -127,15 +127,18 @@ module Absyn:
(** `ElementSpec' by writing them on the same line in the source. *)
(** This type contains the information specific to one component. *)

datatype EquationItem = EQUATIONITEM of Equation
* Annotation option

datatype Equation = EQ_EXPR of Exp (* more later? *)
| EQ_IF of Exp
* Equation list (* true branch *)
* (Exp * Equation list) list (* elseif branches *)
* Equation list (* else branch *)
* EquationItem list (* true branch *)
* (Exp * EquationItem list) list (* elseif branches *)
* EquationItem list (* else branch *)
| EQ_EQUALS of Exp * Exp
| EQ_CONNECT of ComponentRef * ComponentRef
| EQ_FOR of Ident * Exp * Equation list
| EQ_WHEN_E of Exp * Equation list (*1.1*)
| EQ_CONNECT of ComponentRef * ComponentRef
| EQ_FOR of Ident * Exp * EquationItem list
| EQ_WHEN_E of Exp * EquationItem list (*1.1*)
| EQ_ASSERT of Assert

(** The `Equation' type describes one equation in an equation *)
Expand Down
24 changes: 18 additions & 6 deletions modeq/absyn_builder/walker.g
Expand Up @@ -706,13 +706,16 @@ component_clause1 returns [void* ast]
equation_clause returns [void* ast]
{
l_stack el_stack;
void* e;
void* ann;
void *e=0;
}
:
#(EQUATION
(e = equation { el_stack.push(e); }
| ann = annotation
(
(e = equation | annotation)
{
el_stack.push(e);

}
)*
)
{
Expand All @@ -738,7 +741,11 @@ algorithm_clause returns [void* ast]
}
;

equation returns [void* ast]
equation returns [void* ast]
{
void *ann=0;

}
:
#(EQUATION_STATEMENT
( ast = equality_equation
Expand All @@ -748,7 +755,12 @@ equation returns [void* ast]
| ast = connect_clause
| ast = assert_clause
)
comment
ann = comment
{
if (!ann) ann=mk_none();
else ann=mk_some(ann);
ast = Absyn__EQUATIONITEM(ast,ann);
}
)
;

Expand Down
27 changes: 21 additions & 6 deletions modeq/dump.rml
Expand Up @@ -191,7 +191,7 @@ relation print_class_part: Absyn.ClassPart => () =
print_class_part(Absyn.PROTECTED(el))

rule print "EQUATIONS(" &
print_list_debug("print_class_part",eqs,print_equation,",") &
print_list_debug("print_class_part",eqs,print_equationitem,",") &
print ")"
--------------------------------------
print_class_part(Absyn.EQUATIONS(eqs))
Expand Down Expand Up @@ -479,9 +479,9 @@ relation print_equation: Absyn.Equation => () =
print_equation(Absyn.EQ_EXPR(e))

rule print "IF (" & print_exp(e) & print ") THEN " &
print_list_debug("print_equation",tb, print_equation, ";") &
print_list_debug("print_equation",tb, print_equationitem, ";") &
print_list_debug("print_equation",eb, print_eq_elseif, " ") &
print " ELSE " & print_list_debug("print_equation",fb, print_equation, ";")
print " ELSE " & print_list_debug("print_equation",fb, print_equationitem, ";")
----------------------------------------------------
print_equation(Absyn.EQ_IF(e,tb,eb,fb))

Expand All @@ -496,7 +496,7 @@ relation print_equation: Absyn.Equation => () =
print_equation(Absyn.EQ_CONNECT(e1,e2))

rule print "FOR " & print i & print " in " & print_exp(e) &
print " {" & print_list_debug("print_equation",el, print_equation, ";") & print "}"
print " {" & print_list_debug("print_equation",el, print_equationitem, ";") & print "}"
----------------------------------------------------------
print_equation Absyn.EQ_FOR(i,e,el)

Expand All @@ -506,12 +506,27 @@ relation print_equation: Absyn.Equation => () =

end

relation print_equationitem: Absyn.EquationItem => () =
rule print "EQUATIONITEM(" &
print_equation eq &
print ", " &
print_annotation ann &
print ")\n"
--------------
print_equationitem Absyn.EQUATIONITEM(eq,SOME(ann))

rule print "EQUATIONITEM(" &
print_equation eq &
print ",NONE)\n"
--------------
print_equationitem Absyn.EQUATIONITEM(eq,NONE)
end
(**)

relation print_eq_elseif : (Absyn.Exp * Absyn.Equation list) => () =
relation print_eq_elseif : (Absyn.Exp * Absyn.EquationItem list) => () =

rule print " ELSEIF " & print_exp e & print " THEN " &
print_list_debug("print_eq_elseif",el, print_equation, ";")
print_list_debug("print_eq_elseif",el, print_equationitem, ";")
-----------------------------------
print_eq_elseif((e,el))

Expand Down
6 changes: 3 additions & 3 deletions modeq/dumpgraphviz.rml
Expand Up @@ -257,14 +257,14 @@ relation print_componentitem: Absyn.ComponentItem => Node =
end


relation print_equations: Absyn.Equation list => Node list =
relation print_equations: Absyn.EquationItem list => Node list =

axiom print_equations [] => []

rule print_equation e => node &
rule print_equation eq => node &
print_equations el => nl
--------------------------
print_equations e::el => node::nl
print_equations Absyn.EQUATIONITEM(eq,ann)::el => node::nl

end

Expand Down
6 changes: 3 additions & 3 deletions modeq/explode.rml
Expand Up @@ -386,14 +386,14 @@ end
** equation.
**)

relation elab_equations : Absyn.Equation list => Equation list =
relation elab_equations : Absyn.EquationItem list => Equation list =

axiom elab_equations [] => []

rule elab_equation e => e' &
elab_equations es => es'
------------------------
elab_equations e::es => e'::es'
elab_equations Absyn.EQUATIONITEM(e,ann)::es => e'::es'

end

Expand All @@ -415,7 +415,7 @@ relation elab_equation : Absyn.Equation => Equation =
------------------------
elab_equation Absyn.EQ_IF(e,tb,[],fb) => EQ_IF(e,tb',fb')

rule elab_equation Absyn.EQ_IF(e,tb,[],[Absyn.EQ_IF(ee,ei,eis,fb)]) => eq
rule elab_equation Absyn.EQ_IF(e,tb,[],[Absyn.EQUATIONITEM(Absyn.EQ_IF(ee,ei,eis,fb),NONE)]) => eq
------------------------------------------------------------------
elab_equation Absyn.EQ_IF(e,tb,(ee,ei)::eis,fb) => eq

Expand Down
35 changes: 30 additions & 5 deletions modeq/interactive.rml
Expand Up @@ -188,6 +188,16 @@ relation evaluate_graphical_api: (InteractiveStmts, InteractiveSymbolTable) =>
Absyn.FUNCTIONARGS([Absyn.CREF(cr),Absyn.INTEGER(n)],_)))]
),
st as SYMBOLTABLE(p,s,ic,iv)) => (resstr,st)

rule get_nth_connection_annotation(cr,p,n) => s1 &
string_append(s1,"\n") => resstr
-----------------------
evaluate_graphical_api(
ISTMTS([IEXP(Absyn.CALL(
Absyn.CREF_IDENT("getNthConnectionAnnotation",_),
Absyn.FUNCTIONARGS([Absyn.CREF(cr),Absyn.INTEGER(n)],_)))]
),
st as SYMBOLTABLE(p,s,ic,iv)) => (resstr,st)
end

relation componentref_to_path: Absyn.ComponentRef => Absyn.Path =
Expand Down Expand Up @@ -373,6 +383,21 @@ relation get_nth_connection: (Absyn.ComponentRef, Absyn.Program, int) => string
axiom get_nth_connection(_,_,_) => "-1"
end

(** relation: get_nth_connection_annotation
** This relation takes a `ComponentRef' and a `Program' and an int and
** returns a comma separated string of values for the annotation of the the nth connection.
**)
relation get_nth_connection_annotation: (Absyn.ComponentRef, Absyn.Program, int) => string =

rule Absyn.cref_to_path(model) => modelpath &
get_pathed_class_in_program(modelpath,p) => cdef &
let str = "Not finished"
--------------
get_nth_connection_annotation(model,p,n) => str

axiom get_nth_connection_annotation(_,_,_) => "-1"
end

(**relation: get_nth_connection_in_class
** This relation takes a `Class'�and an int ane returns the nth connection
** in that class.
Expand Down Expand Up @@ -414,14 +439,14 @@ end
** returns the nth connection as an `Equation'. If the number is larger than the number of connections
** in the list, the relation fails.
**)
relation get_nth_connection_in_equations: (Absyn.Equation list, int) => Absyn.Equation =
relation get_nth_connection_in_equations: (Absyn.EquationItem list, int) => Absyn.Equation =

axiom get_nth_connection_in_equations ((eq as Absyn.EQ_CONNECT(_,_))::xs,1) => eq
axiom get_nth_connection_in_equations ((Absyn.EQUATIONITEM((eq as Absyn.EQ_CONNECT(_,_)),_))::xs,1) => eq

rule int_sub (n,1) => newn &
get_nth_connection_in_equations (xs,newn) => eq
-----------------------------------------------
get_nth_connection_in_equations (Absyn.EQ_CONNECT(_,_)::xs,n) => eq
get_nth_connection_in_equations (Absyn.EQUATIONITEM(Absyn.EQ_CONNECT(_,_),_)::xs,n) => eq

rule get_nth_connection_in_equations (xs,n) => eq
--------------------------------------------
Expand Down Expand Up @@ -478,12 +503,12 @@ end
** This relation takes an `Equation' list and returns an int
** with the number of connect statements in that list.
**)
relation count_connections_in_equations: Absyn.Equation list => int =
relation count_connections_in_equations: Absyn.EquationItem list => int =

rule count_connections_in_equations(xs) => r1 &
int_add(r1,1) => res
---------------------
count_connections_in_equations(Absyn.EQ_CONNECT(_,_)::xs) => res
count_connections_in_equations(Absyn.EQUATIONITEM(Absyn.EQ_CONNECT(_,_),_)::xs) => res

rule count_connections_in_equations(xs) => res
-----------------------------------------
Expand Down
14 changes: 14 additions & 0 deletions modeq/interactive_api.txt
Expand Up @@ -117,3 +117,17 @@ record Placement
Boolean iconTransformation.flipVertical=false;
Real iconTransformation.rotation=0;
end Placement;

Connection annotations are modifications of the following (flattened)
Modelica record:

record Line
Real points[2][:];
Integer color[3]={0,0,0};
enumeration(None,Solid,Dash,Dot,DashDot,DashDotDot) pattern = Solid;
Real thickness=0.25;
enumeration(None,Open,Filled,Half) arrow[2] = {None, None};
Real arrowSize=3.0;
Boolean smooth=false;
end Line;

0 comments on commit a8094ce

Please sign in to comment.