Skip to content

Commit

Permalink
Fixed bug with extending functions not yet declared (use before declare)
Browse files Browse the repository at this point in the history
git-svn-id: https://openmodelica.org/svn/OpenModelica/trunk@957 f25d12d1-65f4-0310-ae8a-bbce733d8d8e
  • Loading branch information
Peter Aronsson committed Apr 7, 2003
1 parent ca31df7 commit bd30451
Show file tree
Hide file tree
Showing 4 changed files with 58 additions and 22 deletions.
2 changes: 1 addition & 1 deletion modeq/env.rml
Expand Up @@ -416,7 +416,7 @@ relation print_frame_element: (Ident * Item) => () =
-------
print_frame_element ((n,CLASS(_,_)))

rule Print.print_buf "t:" & Print.print_buf n
rule (*Print.print_buf "t:" & Print.print_buf n*)
-------
print_frame_element ((n,TYPE(_)))

Expand Down
5 changes: 4 additions & 1 deletion modeq/explode.rml
Expand Up @@ -794,7 +794,10 @@ relation print_element : Element => () =
print_element CLASSDEF(n,final,repl,cl)

rule Print.print_buf "COMPONENT(" & Print.print_buf n &
Print.print_buf "mod:" & print_mod mod & Print.print_buf ")"
Print.print_buf ",mod:" & print_mod mod &
Print.print_buf ",tp:" & Absyn.path_string typath => s &
Print.print_buf s &
Print.print_buf ")"
----------------------------------------
print_element COMPONENT(n,final,repl,prot,attr,typath,mod)

Expand Down
52 changes: 39 additions & 13 deletions modeq/inst.rml
Expand Up @@ -437,20 +437,22 @@ relation inst_classdef: (Env, Mod, Prefix, Connect.Sets, ClassInf.State,
component_elts(els) => compelts &
extends_elts(els) => extendselts &
(* 1. CLASSDEF & IMPORT nodes and COMPONENT nodes(add to env)*)
inst_element_list2(env,mods,pre,csets,ci_state,cdefelts,inst_dims, impl)
=> (_,env1,csets',ci_state',tys) &

(* inst_element_list2(env,mods,pre,csets,ci_state,cdefelts,inst_dims, impl)
=> (_,env1,csets',ci_state',tys) &*)
add_classdefs_to_env(env,cdefelts,impl) => env1 &

(*2. EXTENDS Nodes*)
(* inst_extends_list only flatten inhteritance structure. *)
(* It does not perform component instantiations. *)
inst_extends_list(env1,mods,extendselts,impl)
=> (env2,emods,extcomps,eqs2,initeqs2,alg2,initalg2) &

list_append(extcomps,compelts) => compelts' &

Util.list_flatten([extcomps,compelts,cdefelts]) => compelts' &
(* Add variables to env, wihtout type and binding, *)
(* which will be added later in inst_element_list *)
(* (where update_variable is called) *)
extend_components_to_env(env2,emods,pre,csets,ci_state,compelts',inst_dims,impl) => env3 &
add_components_to_env(env2,emods,pre,csets,ci_state,compelts',inst_dims,impl) => env3 &
(* Add components from base classes to be instantiated in 3 as well. *)
list_append(eqs,eqs2) => eqs' &
list_append(initeqs,initeqs2) => initeqs' &
Expand Down Expand Up @@ -561,6 +563,11 @@ relation inst_extends_list:(Env.Env, Mod.Mod, SCode.Element list, bool)
inst_extends_list(env, mod, SCode.EXTENDS(tp,emod)::rest, impl)
=> (env', mods',compelts3, eq, ieq, alg, ialg)

rule print "Failed inst_extends_list on EXTENDS\n"
------------------------------------------------
inst_extends_list(env, mod, SCode.EXTENDS(tp,emod)::rest, impl)
=> fail

rule inst_extends_list(env, mod, rest, impl)
=> (env', mods, compelts2, eq2, initeq2, alg2, ialg2)
------------------------------------------------
Expand Down Expand Up @@ -595,6 +602,10 @@ relation update_components: (SCode.Element list, Mod.Mod) => SCode.Element list
--------------------------------
update_components(c::xs,mod)
=> c::res

rule print "-update_components failed\n"
----------------------
update_components(_,_) => fail
end


Expand Down Expand Up @@ -742,7 +753,22 @@ relation component_elts: (SCode.Element list) => (SCode.Element list) =
component_elts(_::xs) => res
end

relation extend_components_to_env : (Env, Mod, Prefix, Connect.Sets, ClassInf.State,
relation add_classdefs_to_env : (Env, SCode.Element list, bool) => (Env) =

axiom add_classdefs_to_env(env,[],_) => env

rule Env.extend_frame_c(env,cl) => env' &
add_classdefs_to_env(env',xs,impl) => env''
------------------
add_classdefs_to_env(env,(SCode.CLASSDEF(_,_,_,cl))::xs,impl) => env''

rule Env.extend_frame_i(env,imp) => env' &
add_classdefs_to_env(env',xs,impl) => env''
-------------------------
add_classdefs_to_env(env,(SCode.IMPORT(imp))::xs,impl) => env
end

relation add_components_to_env : (Env, Mod, Prefix, Connect.Sets, ClassInf.State,
SCode.Element list, InstDims, bool)
=> (Env) =

Expand All @@ -761,28 +787,28 @@ relation extend_components_to_env : (Env, Mod, Prefix, Connect.Sets, ClassInf.St
modifications (e.g. when instanitating a partial class that must be redeclared through a modification)*)
Env.extend_frame_v(env,Types.VAR(n,Types.ATTR(flow,acc,param,dir),
prot,Types.T_NOTYPE,Types.UNBOUND),SOME(comp),false) => env' &
extend_components_to_env(env',mods,pre,csets,ci_state,xs,inst_dims,impl) => env'' &
add_components_to_env(env',mods,pre,csets,ci_state,xs,inst_dims,impl) => env'' &
Debug.fprint("decl", " updated env :") &
Debug.fcall ("decl", Env.print_env, env'')
-----------------
extend_components_to_env(env,mods,pre,csets,ci_state,
add_components_to_env(env,mods,pre,csets,ci_state,
(comp as SCode.COMPONENT(n,final,repl,prot,
attr as SCode.ATTR(ad,flow,acc,param,dir),
t,m))::xs,inst_dims,impl) => env''

rule extend_components_to_env(env,mods,pre,csets,ci_state,
rule add_components_to_env(env,mods,pre,csets,ci_state,
xs,inst_dims,impl) => env'
-----------------
extend_components_to_env(env,mods,pre,csets,ci_state,
add_components_to_env(env,mods,pre,csets,ci_state,
nocomp::xs,inst_dims,impl) => env'


axiom extend_components_to_env(env,_,_,_,_,[],_,_) => env
axiom add_components_to_env(env,_,_,_,_,[],_,_) => env

rule Print.print_buf "- extend_components_to_env failed\n" &
rule Print.print_buf "- add_components_to_env failed\n" &
Print.print_buf " - env: \n" & Env.print_env env & Print.print_buf "\n"
--------------------
extend_components_to_env(env,_,_,_,_,_,_,_) => fail
add_components_to_env(env,_,_,_,_,_,_,_) => fail
end

relation inst_element_list2 : (Env, Mod, Prefix, Connect.Sets, ClassInf.State,
Expand Down
21 changes: 14 additions & 7 deletions modeq/lookup.rml
Expand Up @@ -208,11 +208,18 @@ rule Debug.fprint ("lotr","TRIES lookup_class(5)\n") &
--------------------------------------
lookup_class(env, p as Absyn.QUALIFIED(pack,path),msgflag) => (c', env5)

(* rule Print.print_buf "- lookup_class failed\n" &
rule Print.print_buf "- lookup_class failed\n" &
Print.print_buf " - looked for " & Absyn.path_string path => s &
Print.print_buf s & Print.print_buf "\n"
Print.print_buf s & Print.print_buf "\n" &
print "- lookup_class failed looked for " & print s &
print "envpath =" & Env.get_env_path env => p1 &
Absyn.path_string p1 => s1 &
print s1 & print "\nenv:" & Print.get_string() => str &
Print.clear_buf & Env.print_env env & Print.get_string() => envstr &
Print.clear_buf & Print.print_buf str &
print envstr
--------------
lookup_class(_,path,_)=> fail *)
lookup_class(env,path,true)=> fail
end

relation lookup_qualified_imported_class_in_env:(Env.Env,Env.Env,Absyn.Path) => (SCode.Class, Env.Env) =
Expand Down Expand Up @@ -365,7 +372,7 @@ relation complete_path: (Env.Env, Absyn.Path) => Absyn.Path =
rule lookup_class(env,(*Absyn.IDENT(pack)*)path,true)
=> (SCode.CLASS(id,_,_,_,_),env') &
Env.get_env_path(env') => path1 &
Absyn.join_paths(path1,path) => path'
Absyn.join_paths(path1,Absyn.IDENT(id)) => path'

(* & Print.print_buf "Qualified completed to "
& Absyn.path_string path' => s1 & Print.print_buf s1 &
Expand Down Expand Up @@ -986,12 +993,12 @@ relation lookup_class_in_frame: ((SCode.Ident * Env.Item) list,
---------------------------------------------------------
lookup_class_in_frame((n,Env.CLASS(c, env))::_, id,_) => (c, env)

(*

rule id = n & Print.print_buf "# Error while looking up class " &
Print.print_buf id & Print.print_buf ": found a component\n"
------------------------------------
lookup_class_in_frame((n,Env.VAR(_))::_,id) => fail
*)
lookup_class_in_frame((n,Env.VAR(_,_,_))::_,id,true) => fail


rule lookup_class_in_frame(fs,id,msg) => (c, env)
------------------------------
Expand Down

0 comments on commit bd30451

Please sign in to comment.