Skip to content

Commit

Permalink
Fixed type error for ceval_if_constant generated values
Browse files Browse the repository at this point in the history
git-svn-id: https://openmodelica.org/svn/OpenModelica/trunk@1609 f25d12d1-65f4-0310-ae8a-bbce733d8d8e
  • Loading branch information
levsa committed Mar 22, 2005
1 parent cbb663d commit 4205fb3
Show file tree
Hide file tree
Showing 4 changed files with 33 additions and 20 deletions.
3 changes: 2 additions & 1 deletion modeq/simcodegen.rml
Expand Up @@ -401,7 +401,8 @@ relation generate_functions: (DAE.DAElist, DAELow.DAELow, Absyn.Path, string) =>
(*debug*) Util.string_delimit_list(debugpathstrs, ", ") => debugpathstr &
(*debug*) Debug.fprintln("info", debugpathstr) &
Util.list_map_1(funcpaths, DAE.get_named_function, elements) => funcelems &
Util.list_flatten(funcelems) => funcelems &
Util.list_flatten(funcelems) => funcelems &
Print.get_string => debugstr &
Print.clear_buf &
Codegen.generate_functions(DAE.DAE(funcelems)) &
Print.write_buf(filename)
Expand Down
43 changes: 25 additions & 18 deletions modeq/staticexp.rml
Expand Up @@ -252,19 +252,21 @@ end
** This relation calls Ceval.ceval if the boolean parameter is true
** on the expression.
**)
relation ceval_if_constant: (Exp.Exp,bool (* constant *), bool (* impl *), Env.Env) => Exp.Exp =
relation ceval_if_constant: (Exp.Exp, Types.Properties, bool (* constant *), bool (* impl *), Env.Env)
=> (Exp.Exp, Types.Properties) =

axiom ceval_if_constant(e,cnst as false,_,_) => e
axiom ceval_if_constant(e,prop,cnst as false,_,_) => (e, prop)

axiom ceval_if_constant(e,cnst as true ,impl as true,_) => e
axiom ceval_if_constant(e,prop,cnst as true ,impl as true,_) => (e, prop)


rule Ceval.ceval(env,e,impl,NONE,NONE) => (v,_) &
value_exp(v) => e'
value_exp(v) => e' &
value_type(v) => vt
---------------------------------
ceval_if_constant(e,cnst as true,impl (*as false*),env) => e'
ceval_if_constant(e,prop,cnst as true,impl (*as false*),env) => (e',Types.PROP(vt,true(*const*)))

axiom ceval_if_constant(e,_,_,_) => e
axiom ceval_if_constant(e,prop,const,impl,env) => (e,prop)

end

Expand Down Expand Up @@ -309,19 +311,21 @@ relation elab_exp : (Env.Env, Absyn.Exp, bool, Interactive.InteractiveSymbolTabl
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' &
ceval_if_constant(exp',c,impl,env) => exp''
let prop = Types.PROP(rtype,c) &
ceval_if_constant(exp',prop,c,impl,env) => (exp'',prop')
---------------------------------------------
elab_exp (env,exp as Absyn.BINARY(e1,op,e2),impl,st)
=> (exp'',Types.PROP(rtype,c),st'')
=> (exp'',prop',st'')

rule 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' &
ceval_if_constant(exp',c,impl,env) => exp''
let prop = Types.PROP(rtype,c) &
ceval_if_constant(exp',prop,c,impl,env) => (exp'',prop')
---------------------------------------------------------
elab_exp (env,exp as Absyn.UNARY(op,e),impl, st)
=> (exp'', Types.PROP(rtype,c),st')
=> (exp'',prop',st')

rule (* Logical binary expressions *)
elab_exp (env,e1,impl,st) => (e1', Types.PROP(t1, c1),st') &
Expand All @@ -330,20 +334,22 @@ relation elab_exp : (Env.Env, Absyn.Exp, bool, Interactive.InteractiveSymbolTabl
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' &
ceval_if_constant(exp',c,impl,env) => exp''
let prop = Types.PROP(rtype,c) &
ceval_if_constant(exp',prop,c,impl,env) => (exp'',prop')
-----------------------------------------------------------------
elab_exp (env,exp as Absyn.LBINARY(e1,op,e2),impl,st)
=> (exp'', Types.PROP(rtype,c),st'')
=> (exp'',prop',st'')

rule (* Logical unary expressions *)
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' &
ceval_if_constant(exp',c,impl,env) => exp''
let prop = Types.PROP(rtype,c) &
ceval_if_constant(exp',prop,c,impl,env) => (exp'',prop')
----------------------------------------------------------
elab_exp (env,exp as Absyn.LUNARY(op,e),impl,st)
=> (exp'',Types.PROP(rtype,c),st')
=> (exp'',prop',st')

rule (* Relations, e.g. a < b *)
elab_exp (env,e1,impl,st) => (e1', Types.PROP(t1, c1),st') &
Expand All @@ -352,10 +358,11 @@ relation elab_exp : (Env.Env, Absyn.Exp, bool, Interactive.InteractiveSymbolTabl
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' &
ceval_if_constant(exp',c,impl,env) => exp''
let prop = Types.PROP(rtype,c) &
ceval_if_constant(exp',prop,c,impl,env) => (exp'',prop')
-----------------------------------------------------------------
elab_exp (env,exp as Absyn.RELATION(e1,op,e2),impl,st)
=> (exp'', Types.PROP(rtype,c),st'')
=> (exp'',prop',st'')

(** Conditional expressions *)

Expand All @@ -373,11 +380,11 @@ relation elab_exp : (Env.Env, Absyn.Exp, bool, Interactive.InteractiveSymbolTabl
(** TODO: Implement elaboration of named arguments. *)
Debug.fprintln("sei", "elab_exp CALL...") &
elab_call(env,fn,args,nargs,impl,st) => (e,prop as Types.PROP(t,c),st') &
ceval_if_constant(e,c,impl,env) => e'
ceval_if_constant(e,prop,c,impl,env) => (e',prop')
& Debug.fprintln("sei", "elab_exp CALL done")
--------------------------------------
elab_exp (env,Absyn.CALL(fn,Absyn.FUNCTIONARGS(args,nargs)),impl,st)
=> (e',prop,st')
=> (e',prop',st')


(*PR. Get the properties for each expression in the tuple.
Expand Down
4 changes: 4 additions & 0 deletions modeq/test_codegen/misc_bubblesort.mo
Expand Up @@ -22,4 +22,8 @@ algorithm
end misc_bubblesort;

model mo
parameter Real a[8] = { 9,3,7,5,6,8,2,0 };
Real b[8];
equation
b=misc_bubblesort(a);
end mo;
3 changes: 2 additions & 1 deletion modeq/types.rml
Expand Up @@ -939,7 +939,8 @@ relation unparse_type: Type => string =
--------------------------------------
unparse_type((T_COMPLEX(ci_state,vs),_)) => res

axiom unparse_type(_) => "not implemented yet\n"
axiom unparse_type(_) => "unparse_type: not implemented yet\n"

end

(** relation: print_type
Expand Down

0 comments on commit 4205fb3

Please sign in to comment.