Skip to content

Commit

Permalink
Improved some dumping. Some enum bugs. Added correct builtin attributes.
Browse files Browse the repository at this point in the history
git-svn-id: https://openmodelica.org/svn/OpenModelica/trunk@879 f25d12d1-65f4-0310-ae8a-bbce733d8d8e
  • Loading branch information
Peter Aronsson committed Dec 3, 2002
1 parent 825d203 commit 6577426
Show file tree
Hide file tree
Showing 7 changed files with 209 additions and 27 deletions.
8 changes: 8 additions & 0 deletions modeq/dae.rml
Expand Up @@ -109,6 +109,7 @@ with "rtopts.rml"
with "graphviz.rml"
with "dump.rml"
with "print.rml"
with "util.rml"

(** relation: dump
**
Expand Down Expand Up @@ -464,6 +465,13 @@ relation dump_type_str =

axiom dump_type_str STRING => "String "

axiom dump_type_str ENUM => "Enum "

rule Util.string_delimit_list(l,", ") => s1 &
string_append("enumeration(",s1) => s2 &
string_append(s2,") ") => str
----------------------------
dump_type_str ENUMERATION(l) => str
end

relation dump_var : Element => () =
Expand Down
36 changes: 28 additions & 8 deletions modeq/dump.rml
Expand Up @@ -123,7 +123,7 @@ relation unparse_class_str: Absyn.Class => string =
string_append(s5,"\n") => s6 &
get_string_list (parts,unparse_class_part_str,"") => s7 &
string_append(s6,s7) => s8 &
string_append(s8, "\n end ") => s9 &
string_append(s8, "\nend ") => s9 &
string_append(s9,n) => s10 &
string_append(s10,";\n") => str
-----------------------------
Expand All @@ -150,7 +150,7 @@ relation unparse_class_str: Absyn.Class => string =
string_append(s3," ") => s4 &
string_append(s4,n) => s5 &
string_append(s5,"= enumeration(") => s6 &
stringlist_append (l) => s7 &
Util.string_delimit_list(l,", ") => s7 &
string_append(s6,s7) => s8 &
string_append(s8,");\n") => str
-------------------------------
Expand Down Expand Up @@ -275,7 +275,7 @@ relation print_element_arg =
Print.print_buf ")"
-------------------------------------------
print_element_arg(Absyn.MODIFICATION(f,r,m))

rule Print.print_buf "REDECLARATION(" &
print_select(f,"FINAL,",",") &
print_elementspec spec &
Expand Down Expand Up @@ -535,8 +535,7 @@ relation unparse_elementspec_str: Absyn.ElementSpec => string =
string_append(s1,s2) => s3 &
string_append(s3," ") => s4 &
get_string_list(cs, unparse_componentitem_str, ",") => s5 &
string_append(s4,s5) => s6 &
string_append(s6,";") => str
string_append(s4,s5) => str
------------------------------------------
unparse_elementspec_str(Absyn.COMPONENTS(attr,t,cs)) => str

Expand Down Expand Up @@ -1279,6 +1278,21 @@ relation print_function_args: Absyn.FunctionArgs => () =
print_function_args Absyn.FUNCTIONARGS(expargs,nargs)
end

relation print_function_args_str: Absyn.FunctionArgs => string =

rule print_list_str(expargs,print_exp_str,", ") => s1 &
string_append(s1,", ") => s2 &
print_list_str(nargs,print_named_arg_str,", ") => s3 &
string_append(s2,s3) => str
---------------------------
print_function_args_str Absyn.FUNCTIONARGS(expargs,nargs as _::_) => str

rule print_list_str(expargs,print_exp_str,", ") => str
---------------------------------------------
print_function_args_str Absyn.FUNCTIONARGS(expargs,[]) => str

end

relation print_named_arg: Absyn.NamedArg => () =
rule Print.print_buf ident &
Print.print_buf "=" &
Expand All @@ -1287,7 +1301,13 @@ relation print_named_arg: Absyn.NamedArg => () =
print_named_arg Absyn.NAMEDARG(ident,e)
end


relation print_named_arg_str: Absyn.NamedArg => string =
rule string_append(ident,"=") => s1 &
print_exp_str(e) => s2 &
string_append(s1,s2) => str
---------------------------
print_named_arg_str Absyn.NAMEDARG(ident,e) => str
end

(**)

Expand Down Expand Up @@ -1377,9 +1397,9 @@ relation print_exp_str : Absyn.Exp => string =
print_exp_str(Absyn.IFEXP(c,t,f)) => s''''

rule print_component_ref_str(fcn) => fs &
let argstr = "not implemented yet" &
print_function_args_str(args) => argsstr &
string_append(fs, "(") => s &
string_append(s, argstr) => s' &
string_append(s, argsstr) => s' &
string_append(s', ")") => s''
---------------------------------------------
print_exp_str(Absyn.CALL(fcn, args)) => s''
Expand Down
13 changes: 10 additions & 3 deletions modeq/exp.rml
Expand Up @@ -530,6 +530,13 @@ relation print_exp2 : (Exp,int) => () =
-------------------------
print_exp2 (RANGE(_,start,SOME(step),stop),pri1)

rule RTOpts.modelica_output => false &
int_real(i) => r &
real_string(r) => rstr &
Print.print_buf rstr
---------------------------------------
print_exp2 (CAST(REAL,ICONST(i)),_)

rule RTOpts.modelica_output => false &
Print.print_buf "Real(" & print_exp e & Print.print_buf ")"
---------------------------------------
Expand Down Expand Up @@ -1021,9 +1028,9 @@ 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''
rule print_list_str(es, print_row_str, "},{") => s &
string_append ("{{",s) => s' &
string_append (s',"}}") => s''
-----------------------------
print_exp2_str (MATRIX(_,_,es),_) => s''

Expand Down
9 changes: 8 additions & 1 deletion modeq/inst.rml
Expand Up @@ -2168,12 +2168,19 @@ relation inst_eq_equation : (Exp.Exp, Types.Properties,
(* An assignment to a varaible of T_ENUMERATION type is an explicit
assignment to the value componnent of the enumeration, i.e. having a type T_ENUM*)

rule Debug.fprint ("insttr", "Found assignment to T_ENUMERATION type. Rhs type must be T_ENUM.\n") &
rule Debug.fprint ("insttr", "Found assignment to T_ENUMERATION type. Rhs type must be T_ENUM or T_ENUMERATION.\n") &
inst_eq_equation_2(e1,e2,t) => dae
----------------------
inst_eq_equation(e1 as Exp.CREF(_,_),Types.PROP(Types.T_ENUMERATION(_),_),
e2,Types.PROP(t as Types.T_ENUM,_)) => dae

rule Debug.fprint ("insttr", "Found assignment to T_ENUMERATION type. Rhs type must be T_ENUM or T_ENUMERATION.\n") &
inst_eq_equation_2(e1,e2,t) => dae
----------------------
inst_eq_equation(e1 as Exp.CREF(_,_),Types.PROP(Types.T_ENUMERATION(_),_),
e2,Types.PROP(t as Types.T_ENUMERATION(_),_)) => dae


rule (* Types.equivtypes(t1,t2) => false & *)
Print.print_buf "# Illegal types in equation\n"&
Print.print_buf " lhs: " & Exp.print_exp e1 &
Expand Down
10 changes: 6 additions & 4 deletions modeq/interactive.rml
Expand Up @@ -111,10 +111,12 @@ relation evaluate: (InteractiveStmts, InteractiveSymbolTable) => (string,Intera
Inst.instantiate_class(p',path) => dae &
DAE.dump_debug dae &
Print.print_buf "dumped dae:\n" &
DAE.dump_str (dae) => str
DAE.dump_str (dae) => str &
Print.get_string => s2 &
string_append(s2,str) => str'
--------------------------------------
evaluate(ISTMTS([IEXP(Absyn.CALL(Absyn.CREF_IDENT("translateClass",_),Absyn.FUNCTIONARGS([ Absyn.CREF(cr)],[])))]),st as SYMBOLTABLE(p,_,_,_,_))
=> (str,st)
=> (str',st)

rule Print.get_string() => s1 &
string_append("#Error instanitating class\n",s1) => str
Expand Down Expand Up @@ -1056,8 +1058,8 @@ end
relation get_top_models: (Absyn.Program) => string =

rule get_top_models_in_program(p) => strlist &
Print.print_buf "program =" &
Dump.dump p & Print.print_buf "\n" &
(* Print.print_buf "program =" &
Dump.dump p & Print.print_buf "\n" &*)
Util.string_delimit_list(strlist,",") => str &
string_append("{",str) => s1 &
string_append(s1,"}") => res
Expand Down
158 changes: 148 additions & 10 deletions modeq/types.rml
Expand Up @@ -186,9 +186,10 @@ relation basic_type : Type => bool =
axiom basic_type T_REAL => true
axiom basic_type T_STRING => true
axiom basic_type T_BOOL => true
axiom basic_type T_ENUM => true
axiom basic_type T_ARRAY(_,_) => false
axiom basic_type T_COMPLEX(_,_) => false

axiom basic_type T_ENUMERATION(_) => false
end

(** relation: equivtypes
Expand Down Expand Up @@ -224,6 +225,13 @@ relation subtype : (Type, Type) => bool =
axiom subtype (T_BOOL,T_BOOL) => true
axiom subtype (T_ENUM,T_ENUM) => true

rule l2 = l1 &
subtype(T_ENUMERATION(rest1),T_ENUMERATION(rest2)) => res
----------------------------------------------------------
subtype (T_ENUMERATION(l1::rest1),T_ENUMERATION(l2::rest2)) => res

axiom subtype (T_ENUMERATION([]),T_ENUMERATION(_)) => true

rule subtype (t1,t2) => true
-----------------------
subtype(T_ARRAY(_,t1),T_ARRAY(DIM(NONE),t2)) => true
Expand Down Expand Up @@ -369,29 +377,159 @@ end
**)

relation lookup_in_builtin : (Type,Ident) => Var =
(* PA: covers Modelica 2.0 spec.*)
(* Real *)
axiom lookup_in_builtin(T_REAL,"quantity")
=> VAR("quantity",
ATTR(false, SCode.RW, Absyn.PARAM, Absyn.BIDIR),
false, T_STRING, VALBOUND(Values.STRING("")))

axiom lookup_in_builtin(T_REAL,"unit")
=> VAR("unit",
ATTR(false, SCode.RW, Absyn.PARAM, Absyn.BIDIR),
false, T_STRING, VALBOUND(Values.STRING("")))

axiom lookup_in_builtin(T_REAL,"displayUnit")
=> VAR("displayUnit",
ATTR(false, SCode.RW, Absyn.PARAM, Absyn.BIDIR),
false, T_STRING, VALBOUND(Values.STRING("")))

axiom lookup_in_builtin(T_REAL,"min")
=> VAR("min",
ATTR(false, SCode.RW, Absyn.PARAM, Absyn.BIDIR),
false, T_REAL, UNBOUND)

axiom lookup_in_builtin(T_REAL,"max")
=> VAR("max",
ATTR(false, SCode.RW, Absyn.PARAM, Absyn.BIDIR),
false, T_REAL, UNBOUND)

axiom lookup_in_builtin(T_REAL,"start")
=> VAR("start",
ATTR(false, SCode.RW, Absyn.PARAM, Absyn.BIDIR),
false, T_REAL, VALBOUND(Values.REAL(0.0)))

axiom lookup_in_builtin(T_REAL,"fixed")
=> VAR("fixed",
ATTR(false, SCode.RW, Absyn.PARAM, Absyn.BIDIR),
false, T_BOOL, UNBOUND) (* Needs to be set to true/false higher up the call chain
depending on variability of instance*)
axiom lookup_in_builtin(T_REAL,"enable")
=> VAR("enable",
ATTR(false, SCode.RW, Absyn.PARAM, Absyn.BIDIR),
false, T_BOOL, VALBOUND(Values.BOOL(true)))

axiom lookup_in_builtin(T_REAL,"nominal")
=> VAR("nominal",
ATTR(false, SCode.RW, Absyn.PARAM, Absyn.BIDIR),
false, T_REAL, UNBOUND)

axiom lookup_in_builtin(t,"start")
axiom lookup_in_builtin(T_REAL,"stateSelect")
=> VAR("stateSelect",
ATTR(false, SCode.RW, Absyn.PARAM, Absyn.BIDIR),
false, T_ENUMERATION(["never","avoid","default","prefer","always"]),
VALBOUND(Values.ENUM("default")))
(* optimized away looking up the builtin enumeration type 'stateSelect' *)

(* Integer *)
axiom lookup_in_builtin(T_INTEGER,"quantity")
=> VAR("quantity",
ATTR(false, SCode.RW, Absyn.PARAM, Absyn.BIDIR),
false, T_STRING, VALBOUND(Values.STRING("")))

axiom lookup_in_builtin(T_INTEGER,"min")
=> VAR("min",
ATTR(false, SCode.RW, Absyn.PARAM, Absyn.BIDIR),
false, T_INTEGER, UNBOUND)

axiom lookup_in_builtin(T_INTEGER,"max")
=> VAR("max",
ATTR(false, SCode.RW, Absyn.PARAM, Absyn.BIDIR),
false, T_INTEGER, UNBOUND)

axiom lookup_in_builtin(T_INTEGER,"start")
=> VAR("start",
ATTR(false, SCode.RW, Absyn.PARAM, Absyn.BIDIR),
false, t, UNBOUND)
false, T_REAL, VALBOUND(Values.INTEGER(0)))

axiom lookup_in_builtin(T_INTEGER,"unit")
=> VAR("unit",
axiom lookup_in_builtin(T_INTEGER,"fixed")
=> VAR("fixed",
ATTR(false, SCode.RW, Absyn.PARAM, Absyn.BIDIR),
false, T_BOOL, UNBOUND) (* Needs to be set to true/false higher up the call chain
depending on variability of instance*)
axiom lookup_in_builtin(T_INTEGER,"enable")
=> VAR("enable",
ATTR(false, SCode.RW, Absyn.PARAM, Absyn.BIDIR),
false, T_STRING, UNBOUND)
false, T_BOOL, VALBOUND(Values.BOOL(true)))

axiom lookup_in_builtin(T_REAL,"unit")
=> VAR("unit",
(* Boolean *)
axiom lookup_in_builtin(T_BOOL,"quantity")
=> VAR("quantity",
ATTR(false, SCode.RW, Absyn.PARAM, Absyn.BIDIR),
false, T_STRING, VALBOUND(Values.STRING("")))

axiom lookup_in_builtin(T_BOOL,"start")
=> VAR("start",
ATTR(false, SCode.RW, Absyn.PARAM, Absyn.BIDIR),
false, T_STRING, UNBOUND)
false, T_BOOL, VALBOUND(Values.BOOL(false)))

(* The rest of them should also be added *)
axiom lookup_in_builtin(T_BOOL,"fixed")
=> VAR("fixed",
ATTR(false, SCode.RW, Absyn.PARAM, Absyn.BIDIR),
false, T_BOOL, UNBOUND) (* Needs to be set to true/false higher up the call chain
depending on variability of instance*)
axiom lookup_in_builtin(T_BOOL,"enable")
=> VAR("enable",
ATTR(false, SCode.RW, Absyn.PARAM, Absyn.BIDIR),
false, T_BOOL, VALBOUND(Values.BOOL(true)))

(* String *)
axiom lookup_in_builtin(T_STRING,"quantity")
=> VAR("quantity",
ATTR(false, SCode.RW, Absyn.PARAM, Absyn.BIDIR),
false, T_STRING, VALBOUND(Values.STRING("")))

axiom lookup_in_builtin(T_STRING,"start")
=> VAR("start",
ATTR(false, SCode.RW, Absyn.PARAM, Absyn.BIDIR),
false, T_STRING, VALBOUND(Values.STRING("")))

axiom lookup_in_builtin(T_STRING,"enable")
=> VAR("enable",
ATTR(false, SCode.RW, Absyn.PARAM, Absyn.BIDIR),
false, T_BOOL, VALBOUND(Values.BOOL(true)))

(* Enumeration ( type E in spec) *)
axiom lookup_in_builtin(T_ENUM,"quantity")
=> VAR("quantity",
ATTR(false, SCode.RW, Absyn.PARAM, Absyn.BIDIR),
false, T_STRING, VALBOUND(Values.STRING("")))

axiom lookup_in_builtin(T_ENUM,"min")
=> VAR("min",
ATTR(false, SCode.RW, Absyn.PARAM, Absyn.BIDIR),
false, T_ENUM, UNBOUND) (* Should be bound to the first element of
T_ENUMERATION list higher up in the call chain *)
axiom lookup_in_builtin(T_ENUM,"max")
=> VAR("max",
ATTR(false, SCode.RW, Absyn.PARAM, Absyn.BIDIR),
false, T_ENUM, UNBOUND) (* Should be bound to the last element of
T_ENUMERATION list higher up in the call chain *)
axiom lookup_in_builtin(T_ENUM,"start")
=> VAR("start",
ATTR(false, SCode.RW, Absyn.PARAM, Absyn.BIDIR),
false, T_BOOL, UNBOUND) (* Should be bound to the last element of
T_ENUMERATION list higher up in the call chain *)

axiom lookup_in_builtin(T_ENUM,"fixed")
=> VAR("fixed",
ATTR(false, SCode.RW, Absyn.PARAM, Absyn.BIDIR),
false, T_BOOL, UNBOUND) (* Needs to be set to true/false higher up the call chain
depending on variability of instance*)
axiom lookup_in_builtin(T_ENUM,"enable")
=> VAR("enable",
ATTR(false, SCode.RW, Absyn.PARAM, Absyn.BIDIR),
false, T_BOOL, VALBOUND(Values.BOOL(true)))
end

(** relation: lookup_component2
Expand Down
2 changes: 1 addition & 1 deletion modeq/values.rml
Expand Up @@ -41,9 +41,9 @@ with "exp.rml"
| REAL of real
| STRING of string
| BOOL of bool
| ENUM of string
| ARRAY of Value list
| TUPLE of Value list

relation val_string : Value => string
relation print_val : Value => ()
relation add_elementwise_arrayelt: (Value list, Value list) => Value list
Expand Down

0 comments on commit 6577426

Please sign in to comment.