Skip to content

Commit

Permalink
Fixed elab_exp so that numerical constant values are calculated.
Browse files Browse the repository at this point in the history
git-svn-id: https://openmodelica.org/svn/OpenModelica/trunk@1381 f25d12d1-65f4-0310-ae8a-bbce733d8d8e
  • Loading branch information
Peter Aronsson committed Jan 11, 2005
1 parent 3750f1b commit 102b24b
Show file tree
Hide file tree
Showing 2 changed files with 42 additions and 62 deletions.
44 changes: 4 additions & 40 deletions modeq/inst.rml
Expand Up @@ -3430,29 +3430,13 @@ relation inst_equation_common : (Env,Mod, Prefix, Connect.Sets, ClassInf.State,
rule Lookup.lookup_ident_local(env,n)
=> (Types.VAR(_,_,_,_,Types.EQBOUND(_,_)),_,_) &
inst_equation_common_ci_trans (ci_state, initial) => ci_state'
& print "discarding equation\n"
------------------------------------------------------
inst_equation_common(env,mods,pre,csets,ci_state,
SCode.EQ_EQUALS(Absyn.CREF(Absyn.CREF_IDENT(n,[])), e2),
initial)
=> ([],env,csets,ci_state')

(* PR. This is probably where type checking of functions happen.*)
rule (*PR. propx contains the type/types(for functions) of the
resulting expression. But why are e1', e2' needed? They are
used to generate the dae's. Probably their type may have been
modified. *)
(* Debug.print("\n Expressions matched in inst equation:") &*)

(* Absyn.print_absyn_exp(e1) &
*)
(* Debug.print(", ") &*)

(* Absyn.print_absyn_exp(e2) &
*)
(* Debug.print("\n") &*)

(*
rule (*
Do static analysis and constant evaluation of expressions.
Gives expression and properties
(Type * bool | (Type * Const as (bool | Const list))).
Expand All @@ -3464,17 +3448,9 @@ relation inst_equation_common : (Env,Mod, Prefix, Connect.Sets, ClassInf.State,
Returns the output parameters from the funktion.
*)

Static.elab_exp(env,e1,false,NONE) => (e1',prop1,_) &
Static.elab_exp(env,e1,false,NONE) => (e1',prop1,c1) &
Static.elab_exp(env,e2,false,NONE) => (e2',prop2,c2) &

(* Debug.print("\nDebug: did left elab.") &*)
Static.elab_exp(env,e2,false,NONE) => (e2',prop2,_) &
(* Debug.print("\nDebug: did right elab.") &*)
(* Exp.print_exp(e1') & *)
(* Debug.print(", ") &*)
(* Exp.print_exp(e2') & *)
(* Debug.print("\n") &*)


Prefix.prefix_exp(env,e1',pre) => e1'' &
Prefix.prefix_exp(env,e2',pre) => e2'' &
(* Debug.print("\nDebug: did prefixes.") &*)
Expand All @@ -3487,20 +3463,7 @@ relation inst_equation_common : (Env,Mod, Prefix, Connect.Sets, ClassInf.State,
*)
(*PR. Check that the lefthandside and the righthandside get along. *)
inst_eq_equation(e1'',prop1,e2'',prop2,initial) => dae &
(* Debug.print("\nDebug: did inst_eq_equation.") &*)
inst_equation_common_ci_trans (ci_state, initial) => ci_state'
(* & Debug.print("\nDebug: did ClassInf trans.") &*)
(* Prefix.print_prefix_str pre => prestr &
Exp.print_exp_str e1' => e1str &
Exp.print_exp_str e2' => e2str &
string_append (prestr, ": ") => debugstr &
string_append (debugstr, e1str) => debugstr2 &
string_append (debugstr2, " = ") => debugstr3 &
string_append (debugstr3, e2str) => debugstr4 *)
(* & Debug.fcall ("expenvgraph", Env.print_env_graphviz, (env,debugstr4)) &
Debug.fprintl ("expenvprint", ["------------ ", debugstr4, "\n"]) &
Debug.fcall ("expenvprint", Env.print_env, env) &
Debug.fprintl ("expenvprint", ["------------ /", debugstr4, "\n"])*)
--------------------------------------------------------------
inst_equation_common(env, mods, pre, csets, ci_state,
SCode.EQ_EQUALS(e1,e2),
Expand Down Expand Up @@ -3651,6 +3614,7 @@ relation inst_equation_common : (Env,Mod, Prefix, Connect.Sets, ClassInf.State,
inst_equation_common(_,_,_,_,_,_,_) => fail
end


(** LS & ELN **)
relation inst_equation_common_ci_trans : (ClassInf.State, Initial)
=> ClassInf.State =
Expand Down
60 changes: 38 additions & 22 deletions modeq/staticexp.rml
Expand Up @@ -163,6 +163,20 @@ relation elab_exp_list_list : (Env.Env, Absyn.Exp list list, bool
elab_exp_list_list (env, e::rest,impl,st) => (exp::exps, p::props,st'')
end

(** relation: ceval_if_constant
** This relation calls Ceval.ceval if the boolean parameter is true
** on the expression.
**)
relation ceval_if_constant: (Exp.Exp,bool (* constant *),Env.Env) => Exp.Exp =

axiom ceval_if_constant(e,false,_) => e

rule Ceval.ceval(env,e,false,NONE,NONE) => (v,_) &
value_exp(v) => e'
---------------------------------
ceval_if_constant(e,true,env) => e'
end

(** relation: elab_exp
**
** Static analysis of expressions means finding out the properties of
Expand Down Expand Up @@ -199,62 +213,60 @@ relation elab_exp : (Env.Env, Absyn.Exp, bool, Interactive.InteractiveSymbolTabl

(** Binary and unary operations *)

rule (*Debug.fprintln("setr", "elab_exp_binary") &*)
elab_exp (env,e1,impl,st) => (e1', Types.PROP(t1, c1),st') &
rule elab_exp (env,e1,impl,st) => (e1', Types.PROP(t1, c1),st') &
elab_exp (env,e2,impl,st') => (e2', Types.PROP(t2, c2),st'') &
(*Debug.fprintln("eexpbin","types of binary exp t1:") &
Debug.fcall("eexpbin",Types.print_type,t1) &
Debug.fprintln("eexpbin","\nt2:") &
Debug.fcall("eexpbin",Types.print_type,t2) & *)
bool_and (c1,c2) => c &
operators(op, env, t1, t2) => ops &
deoverload (ops, [(e1',t1),(e2',t2)], exp) => (op',[e1'',e2''],rtype) &
replace_operator_with_fcall(Exp.BINARY(e1'',op',e2''),c) => exp'
(*& Debug.fprintln("eexpbin", "operator deoverloaded, resulting type:") &
Debug.fcall("eexpbin",Types.print_type,rtype) *)
replace_operator_with_fcall(Exp.BINARY(e1'',op',e2''),c) => exp' &
ceval_if_constant(exp',c,env) => exp''
---------------------------------------------
elab_exp (env,exp as Absyn.BINARY(e1,op,e2),impl,st)
=> (exp',Types.PROP(rtype,c),st'')
=> (exp'',Types.PROP(rtype,c),st'')

rule (*Debug.fprintln("setr", "elab_exp_unary") &*)
elab_exp (env,e,impl,st) => (e',Types.PROP(t,c),st') &
operators(op, env, t, (Types.T_NOTYPE,NONE)) => ops &
deoverload (ops, [(e',t)], exp) => (op', [e''], rtype) &
replace_operator_with_fcall(Exp.UNARY(op',e''),c) => exp'
replace_operator_with_fcall(Exp.UNARY(op',e''),c) => exp' &
ceval_if_constant(exp',c,env) => exp''
---------------------------------------------------------
elab_exp (env,exp as Absyn.UNARY(op,e),impl, st)
=> (exp', Types.PROP(rtype,c),st')
=> (exp'', Types.PROP(rtype,c),st')

rule (*Debug.fprintln("setr", "elab_exp_lbinary") &*)
elab_exp (env,e1,impl,st) => (e1', Types.PROP(t1, c1),st') &
elab_exp (env,e2,impl,st') => (e2', Types.PROP(t2, c2),st'') &
bool_and (c1,c2) => c &
operators(op, env, t1, t2) => ops &
deoverload (ops, [(e1',t1),(e2',t2)], exp) => (op',[e1'',e2''],rtype) &
replace_operator_with_fcall(Exp.LBINARY(e1'',op',e2''),c) => exp'
replace_operator_with_fcall(Exp.LBINARY(e1'',op',e2''),c) => exp' &
ceval_if_constant(exp',c,env) => exp''
-----------------------------------------------------------------
elab_exp (env,exp as Absyn.LBINARY(e1,op,e2),impl,st)
=> (exp', Types.PROP(rtype,c),st'')
=> (exp'', Types.PROP(rtype,c),st'')

rule (*Debug.fprintln("setr", "elab_exp_lunary") &*)
elab_exp (env,e,impl,st) => (e',Types.PROP(t,c),st') &
operators(op, env, t, (Types.T_NOTYPE,NONE)) => ops &
deoverload (ops, [(e',t)], exp) => (op', [e''], rtype) &
replace_operator_with_fcall(Exp.LUNARY(op',e''),c) => exp'
replace_operator_with_fcall(Exp.LUNARY(op',e''),c) => exp' &
ceval_if_constant(exp',c,env) => exp''
----------------------------------------------------------
elab_exp (env,exp as Absyn.LUNARY(op,e),impl,st)
=> (exp',Types.PROP(rtype,c),st')
=> (exp'',Types.PROP(rtype,c),st')

rule (*Debug.fprintln("setr", "elab_exp_relation") &*)
elab_exp (env,e1,impl,st) => (e1', Types.PROP(t1, c1),st') &
elab_exp (env,e2,impl,st') => (e2', Types.PROP(t2, c2),st'') &
bool_and (c1,c2) => c &
operators(op, env, t1, t2) => ops &
deoverload (ops, [(e1',t1),(e2',t2)], exp) => (op',[e1'',e2''],rtype) &
replace_operator_with_fcall(Exp.RELATION(e1'',op',e2''),c) => exp'
replace_operator_with_fcall(Exp.RELATION(e1'',op',e2''),c) => exp' &
ceval_if_constant(exp',c,env) => exp''
-----------------------------------------------------------------
elab_exp (env,exp as Absyn.RELATION(e1,op,e2),impl,st)
=> (exp', Types.PROP(rtype,c),st'')
=> (exp'', Types.PROP(rtype,c),st'')

(** Conditional expressions *)

Expand Down Expand Up @@ -2915,6 +2927,10 @@ end
** This relation check whether the component reference found in
** `elab_cref' has a binding, and if that binding is constant. If
** the binding is a `VALBOUND' binding, the value is substituted.
** Constant values are e.g.: 1+5, c1+c2, ps1*2 ,where c1 and c2 are modelica constants,
** ps1 and ps2 are structural parameters.
** Non Constant values are e.g. : p1+p2, x1*x2 ,where p1,p2 are modelica parameters,
** x1,x2 modelica variables.
**)

relation elab_cref2 : (Env.Env,
Expand All @@ -2925,12 +2941,12 @@ relation elab_cref2 : (Env.Env,

rule Types.elab_type tt => t &
fill_cref_subscripts (cr,tt) => cr'
-----------------
-----------------------------------
elab_cref2 (_,cr, acc, SCode.VAR, tt,_) => (Exp.CREF(cr',t),false, acc)

rule Types.elab_type tt => t &
fill_cref_subscripts (cr,tt) => cr'
------------------
-----------------------------------
elab_cref2 (_,cr, acc, SCode.DISCRETE,tt,_)
=>(Exp.CREF(cr',t),false,acc)

Expand All @@ -2941,8 +2957,8 @@ relation elab_cref2 : (Env.Env,
rule Types.elab_type tt => t &
fill_cref_subscripts (cr,tt) => cr' &
cref_vectorize(Exp.CREF(cr',t),tt) => e'
----------------
elab_cref2 (env,cr,acc,SCode.PARAM,tt, Types.VALBOUND(v)) => (e',true,acc)
---------------
elab_cref2 (env,cr,acc,SCode.PARAM,tt, Types.VALBOUND(v)) => (e',false,acc)

rule Types.elab_type tt => t &
fill_cref_subscripts (cr,tt) => cr' &
Expand Down

0 comments on commit 102b24b

Please sign in to comment.