Skip to content

Commit

Permalink
Changed lookup implementation. Now looks in inherited classes implici…
Browse files Browse the repository at this point in the history
…tly, throug an extra list of inherited classes in Env

git-svn-id: https://openmodelica.org/svn/OpenModelica/trunk@1036 f25d12d1-65f4-0310-ae8a-bbce733d8d8e
  • Loading branch information
Peter Aronsson committed Nov 25, 2003
1 parent 40e33ec commit a3b8b47
Show file tree
Hide file tree
Showing 9 changed files with 346 additions and 236 deletions.
13 changes: 8 additions & 5 deletions modeq/ceval.rml
Expand Up @@ -1067,9 +1067,9 @@ relation ceval_cref : (Env.Env, Exp.ComponentRef) => Values.Value =

(* Uncomment this when struct params work *)
(* rule (* Parameters should not be evaluated. Exception: structural parameters *)
Lookup.lookup_var (env, c) => (Types.ATTR(_,_,SCode.PARAM,_),_,binding)
-------------------------------------
ceval_cref (env,c) => fail *)
Lookup.lookup_var (env, c) => (Types.ATTR(_,_,SCode.PARAM,_),_,binding)
-------------------------------------
ceval_cref (env,c) => fail *)

rule Lookup.lookup_var (env, c) => (_,_,binding) &
ceval_cref_binding (env,c,binding) => v
Expand All @@ -1092,13 +1092,16 @@ relation ceval_cref_binding : (Env.Env, Exp.ComponentRef,Types.Binding) => Value
ceval_cref_binding (env,Exp.CREF_IDENT(_,subsc),Types.VALBOUND(v))
=> res


rule Print.print_buf "- ceval_cref_binding failed (UNBOUND)\n"
-------------------------------------
ceval_cref_binding (env,_,Types.UNBOUND) => fail

rule ceval (env,exp,false,NONE) => (v,_)
rule ceval (env,exp,false,NONE) => (v,_) &
ceval_subscript_value(env,subsc,v) => res
------------------------
ceval_cref_binding (env,Exp.CREF_IDENT(_,[]),Types.EQBOUND(exp,true)) => v
ceval_cref_binding (env,Exp.CREF_IDENT(_,subsc),Types.EQBOUND(exp,true))
=> res

rule Print.print_buf "- ceval_cref__binding failed (nonconstant EQBOUND(" &
Exp.print_exp exp & Print.print_buf ")\n"
Expand Down
65 changes: 42 additions & 23 deletions modeq/env.rml
Expand Up @@ -45,6 +45,7 @@ module Env:
HashTable * (* List of classes and variables which must be uniquely named*)
HashTable * (* List of types, which DOES NOT be uniquely named, eg. size have several types*)
Item list * (* list of unnamed items (imports)**)
Absyn.Path list * (* list of inherited classes *)
bool (* encapsulated *)
(* bool=true means that FRAME is created due to encapsulated class *)

Expand Down Expand Up @@ -75,6 +76,7 @@ module Env:
relation new_frame : (bool,int) => Frame
relation open_scope : (Env,bool) => Env
relation name_scope: (Env,Ident) => Env
relation add_inherits: (Env,Absyn.Path) => Env
relation extend_frame_c : (Env, SCode.Class) => Env
relation extend_frame_classes : (Env, SCode.Program) => Env
relation extend_frame_v : (Env, Types.Var,(SCode.Element*Types.Mod) option,bool) => Env
Expand Down Expand Up @@ -119,7 +121,7 @@ relation new_frame: (bool, int) => Frame =
rule hash_new(size) => ht &
hash_new(size) => httypes
--------------------
new_frame(enc,size) => FRAME(NONE,ht,httypes,[],enc)
new_frame(enc,size) => FRAME(NONE,ht,httypes,[],[],enc)
end

(** relation: open_scope
Expand Down Expand Up @@ -153,10 +155,22 @@ end

relation name_scope: (Env,Ident) => Env =

axiom name_scope(FRAME(_,ht,httypes,imps,encflag)::res,id) => FRAME(SOME(id),ht,httypes,imps,encflag)::res
axiom name_scope(FRAME(_,ht,httypes,imps,inh,encflag)::res,id) => FRAME(SOME(id),ht,httypes,imps,inh,encflag)::res

end

(** relation: add_inherits
** This relation adds a Absyn.Path to the inherits list of a scope. It is used
** for lookup though the inherited classes of a class.
**)
relation add_inherits: (Env,Absyn.Path) => Env =

(* TODO: Should probably check if it is allready in the list *)
axiom add_inherits (FRAME(id,ht,httypes,imps,inh,encflag)::res,path)

=> FRAME(id,ht,httypes,imps,path::inh,encflag)::res
end

(** relation: extend_frame_c
**
** This relation adds a class definition to the environment.
Expand All @@ -179,8 +193,8 @@ relation extend_frame_c : (Env, SCode.Class) => Env =

rule hash_add(ht,n,CLASS(c,env),myhash) => (ht',retval)
--------------------------
extend_frame_c(env as (FRAME(id,ht,httypes,imps,encflag)::fs),c as SCode.CLASS(n,_,_,_,_))
=> ((FRAME(id,ht',httypes,imps,encflag)::fs))
extend_frame_c(env as (FRAME(id,ht,httypes,imps,inh,encflag)::fs),c as SCode.CLASS(n,_,_,_,_))
=> ((FRAME(id,ht',httypes,imps,inh,encflag)::fs))

end

Expand Down Expand Up @@ -215,8 +229,8 @@ relation extend_frame_v : (Env,Types.Var,(SCode.Element*Types.Mod) option,bool)
*)
rule hash_add(ht,n,VAR(v,c,i),myhash) => (ht',retval)
---------------------------------------
extend_frame_v(FRAME(id,ht,httypes,imps,encflag)::fs,v as Types.VAR(n,_,_,_,_),c,i)
=> (FRAME(id,ht',httypes,imps,encflag)::fs)
extend_frame_v(FRAME(id,ht,httypes,imps,inh,encflag)::fs,v as Types.VAR(n,_,_,_,_),c,i)
=> (FRAME(id,ht',httypes,imps,inh,encflag)::fs)

end

Expand All @@ -234,21 +248,21 @@ relation update_frame_v : (Env,Types.Var,bool) => Env =
rule hash_get(ht,n,myhash) => VAR(_,c,_) &
hash_add(ht,n,VAR(v,c,i),myhash) => (ht',UPDATED)
------------------------
update_frame_v (FRAME(sid,ht,httypes,imps,encflag)::fs, v as Types.VAR(n,_,_,_,_),i)
=> (FRAME(sid,ht',httypes,imps,encflag)::fs)
update_frame_v (FRAME(sid,ht,httypes,imps,inh,encflag)::fs, v as Types.VAR(n,_,_,_,_),i)
=> (FRAME(sid,ht',httypes,imps,inh,encflag)::fs)

rule (* Also check frames above, e.g. when variable is in base class *)
update_frame_v(fs,v,i) => frames
--------------
update_frame_v(FRAME(sid,ht,httypes,imps,encflag)::fs,v as Types.VAR(n,_,_,_,_),i)
=> (FRAME(sid,ht,httypes,imps,encflag)::frames)
update_frame_v(FRAME(sid,ht,httypes,imps,inh,encflag)::fs,v as Types.VAR(n,_,_,_,_),i)
=> (FRAME(sid,ht,httypes,imps,inh,encflag)::frames)

rule Print.print_buf "- update_frame_v, variable " & Print.print_buf n &
Print.print_buf " not found\n rest of env:" &
print_env fs & Print.print_buf "\n"
--------------
update_frame_v(FRAME(sid,ht,httypes,imps,encflag)::fs, Types.VAR(n,_,_,_,_),_)
=> (FRAME(sid,ht,httypes,imps,encflag)::fs)
update_frame_v(FRAME(sid,ht,httypes,imps,inh,encflag)::fs, Types.VAR(n,_,_,_,_),_)
=> (FRAME(sid,ht,httypes,imps,inh,encflag)::fs)

rule Print.print_buf "- update_frame_v failed\n" &
Print.print_buf " - variable: " & Types.print_var v &
Expand Down Expand Up @@ -286,21 +300,21 @@ relation extend_frame_t : (Env,Ident,Types.Type) => Env =
hash_get(httypes,n,myhash) => TYPE(tps) &
hash_add(httypes,n,TYPE(t::tps),myhash) => (httypes',retval)
-----------------------------
extend_frame_t(FRAME(sid,ht,httypes,imps,encflag)::fs, n, t)
=> (FRAME(sid,ht,httypes',imps,encflag)::fs)
extend_frame_t(FRAME(sid,ht,httypes,imps,inh,encflag)::fs, n, t)
=> (FRAME(sid,ht,httypes',imps,inh,encflag)::fs)

rule (* No other types exists *)
not hash_get(httypes,n,myhash) => TYPE(_) &
hash_add(httypes,n,TYPE([t]),myhash) => (httypes',retval)
-----------------------------
extend_frame_t(FRAME(sid,ht,httypes,imps,encflag)::fs, n, t)
=> (FRAME(sid,ht,httypes',imps,encflag)::fs)
extend_frame_t(FRAME(sid,ht,httypes,imps,inh,encflag)::fs, n, t)
=> (FRAME(sid,ht,httypes',imps,inh,encflag)::fs)
end

relation extend_frame_i : (Env,Absyn.Import) => Env =

axiom extend_frame_i(FRAME(sid,ht,httypes,imps,encflag)::fs,imp)
=> (FRAME(sid,ht,httypes, IMPORT(imp)::imps,encflag)::fs)
axiom extend_frame_i(FRAME(sid,ht,httypes,imps,inh,encflag)::fs,imp)
=> (FRAME(sid,ht,httypes, IMPORT(imp)::imps,inh,encflag)::fs)
end

relation top_frame : Env => Frame =
Expand All @@ -318,12 +332,12 @@ end
**)
relation get_env_path: Env => Absyn.Path option =

axiom get_env_path ([FRAME(SOME(id),_,_,_,_),FRAME(NONE,_,_,_,_)]) => SOME(Absyn.IDENT(id))
axiom get_env_path ([FRAME(SOME(id),_,_,_,_,_),FRAME(NONE,_,_,_,_,_)]) => SOME(Absyn.IDENT(id))

rule get_env_path(rest) => SOME(path) &
Absyn.join_paths(path,Absyn.IDENT(id)) => path'
----------------------------------------------
get_env_path(FRAME(SOME(id),_,_,_,_)::rest) =>SOME(path')
get_env_path(FRAME(SOME(id),_,_,_,_,_)::rest) =>SOME(path')

axiom get_env_path(_) => NONE
end
Expand Down Expand Up @@ -367,9 +381,11 @@ relation print_frame : Frame => () =
print_hashtable httypes &
Print.print_buf " Imports:" &
print_imports imps &
Print.print_buf " Inherits:" &
Dump.print_list(inh,Dump.print_path,", ") &
Print.print_buf "\n"
--------------------------------------------
print_frame FRAME(SOME(sid),ht,httypes,imps,encflag)
print_frame FRAME(SOME(sid),ht,httypes,imps,inh,encflag)

rule Print.print_buf "FRAME: " &
Print.print_buf "unnamed" &
Expand All @@ -381,9 +397,11 @@ relation print_frame : Frame => () =
print_hashtable httypes &
Print.print_buf " Imports:" &
print_imports imps &
Print.print_buf " Inherits:" &
Dump.print_list(inh,Dump.print_path,", ") &
Print.print_buf "\n"
--------------------------------------------
print_frame FRAME(NONE,ht,httypes,imps,encflag)
print_frame FRAME(NONE,ht,httypes,imps,inh,encflag)

end

Expand Down Expand Up @@ -491,7 +509,8 @@ end

relation build_frame_graphviz : Frame => Graphviz.Node =

axiom build_frame_graphviz FRAME(sid,ht,httypes,imps,encflag) => Graphviz.NODE("FRAME",[],[])
axiom build_frame_graphviz FRAME(sid,ht,httypes,imps,inh,encflag)
=> Graphviz.NODE("FRAME",[],[])
end

relation build_item_listnode : ((Ident * Item) list, (Ident * Item) => (), string)
Expand Down

0 comments on commit a3b8b47

Please sign in to comment.