Skip to content

Commit

Permalink
Oops! Fixed static scoping.
Browse files Browse the repository at this point in the history
git-svn-id: https://openmodelica.org/svn/OpenModelica/trunk@467 f25d12d1-65f4-0310-ae8a-bbce733d8d8e
  • Loading branch information
x97davka committed Oct 1, 1998
1 parent 199979a commit 002531b
Show file tree
Hide file tree
Showing 4 changed files with 45 additions and 34 deletions.
6 changes: 3 additions & 3 deletions modeq/env.rml
Expand Up @@ -23,7 +23,7 @@ module Env:
datatype Frame = FRAME of (Ident * Item) list

datatype Item = VAR of Types.Var
| CLASS of SCode.Class
| CLASS of SCode.Class * Env
| TYPE of Types.Type

type Env = Frame list
Expand Down Expand Up @@ -64,8 +64,8 @@ end

relation extend_frame_c : (Env, SCode.Class) => Env =

axiom extend_frame_c(FRAME(items)::fs,c as SCode.CLASS(n,_,_,_))
=> ((FRAME((n,CLASS(c))::items)::fs))
axiom extend_frame_c(env as (FRAME(items)::fs),c as SCode.CLASS(n,_,_,_))
=> ((FRAME((n,CLASS(c,env))::items)::fs))

end

Expand Down
19 changes: 10 additions & 9 deletions modeq/inst.rml
Expand Up @@ -216,13 +216,13 @@ relation inst_classdef: (Env, Mod, Prefix, Connect.Sets, ClassInf.State,
(** This rule describes how to instantiate a derived class *)
(** definition *)

rule Lookup.lookup_class(env,cn) => (c as SCode.CLASS(cn2,_,r,_)) &
rule Lookup.lookup_class(env,cn) => (c as SCode.CLASS(cn2,_,r,_), cenv) &
Mod.lookup_modification_p(mods,cn) => m &
Mod.elab_mod(env,pre,mod) => mod' &
ClassInf.start(r, cn2) => new_ci_state &
Mod.merge(mods,m) => mods' &
Mod.merge(mods',mod') => mods'' &
inst_class_in(env, mods'', pre, csets, new_ci_state, c, prot)
inst_class_in(cenv, mods'', pre, csets, new_ci_state, c, prot)
=> (dae,env, csets', ci_state', tys) &

(* Check for restriction violations *)
Expand All @@ -236,7 +236,7 @@ relation inst_classdef: (Env, Mod, Prefix, Connect.Sets, ClassInf.State,
(** found in the environment, this rule prints an error *)
(** message. *)

rule not Lookup.lookup_class(env,cn) => _ &
rule not Lookup.lookup_class(env,cn) => (_,_) &
Absyn.path_string(cn) => cns &
print "# unknown class: " & print cns & print "\n"
----------------------------------------
Expand Down Expand Up @@ -299,7 +299,8 @@ relation inst_element : (Env, Mod, Prefix, Connect.Sets, ClassInf.State,

rule Absyn.path_string(cn) => cns &

Lookup.lookup_class(env,cn) => (c as SCode.CLASS(cn2,_,restr,def)) &
Lookup.lookup_class(env,cn) => (c as SCode.CLASS(cn2,_,restr,def),
cenv) &
Mod.lookup_modification_p(mods,cn) => classmod &
Mod.elab_mod(env,pre,m) => m' &

Expand All @@ -311,7 +312,7 @@ relation inst_element : (Env, Mod, Prefix, Connect.Sets, ClassInf.State,
Mod.merge(mods',m') => mods'' &

(* Can't use inst_class, as that creates a new frame *)
inst_class_in(env,mods'',pre,csets,ci_state,c,false)
inst_class_in(cenv,mods'',pre,csets,ci_state,c,false)
=> (dae,env',csets',ci_state',vars)
----------------------------------
inst_element(env,mods,pre,csets, ci_state, SCode.EXTENDS(cn,m))
Expand All @@ -336,7 +337,7 @@ relation inst_element : (Env, Mod, Prefix, Connect.Sets, ClassInf.State,
SCode.CLASSDEF(n,_,_,_))
=> fail

rule Lookup.lookup_class(env,Absyn.IDENT(n)) => v &
rule Lookup.lookup_class(env,Absyn.IDENT(n)) => (_,_) &
print "# Trying to redeclare the variable " & print n &
print " as a class\n"
---------------------
Expand Down Expand Up @@ -380,7 +381,7 @@ relation inst_element : (Env, Mod, Prefix, Connect.Sets, ClassInf.State,
(** `m'. All of these are merged so that the correct *)
(** precedence rules are followed. *)

Lookup.lookup_class(env,t) => cl &
Lookup.lookup_class(env,t) => (cl,cenv) &
Mod.lookup_modification_p(mods,t) => classmod &
Mod.lookup_comp_modification(mods,n) => mm &
Mod.elab_mod(env,pre,m) => m' &
Expand All @@ -400,7 +401,7 @@ relation inst_element : (Env, Mod, Prefix, Connect.Sets, ClassInf.State,
elab_arraydim(env,ad,eq) => dims &

(** Instantiate the component *)
inst_var(env,mod',pre,csets,n,cl,attr,dims,[])
inst_var(cenv,mod',pre,csets,n,cl,attr,dims,[])
=> (dae1,csets',ty) &

(** The environment is extended with the new variable *)
Expand Down Expand Up @@ -432,7 +433,7 @@ relation inst_element : (Env, Mod, Prefix, Connect.Sets, ClassInf.State,
**)

(** Failure *)
rule not Lookup.lookup_class(env,t) => cl &
rule not Lookup.lookup_class(env,t) => (cl,cenv) &
Absyn.path_string(t) => s &
print "# unknown class '" & print s & print "' while instantiating " &
Prefix.prefix_path(Absyn.IDENT(n),pre) => n' &
Expand Down
49 changes: 27 additions & 22 deletions modeq/lookup.rml
Expand Up @@ -17,7 +17,7 @@ module Lookup:
with "explode.rml"

relation lookup_type : (Env.Env, Absyn.Path) => (Types.Type)
relation lookup_class : (Env.Env, Absyn.Path) => (SCode.Class)
relation lookup_class : (Env.Env, Absyn.Path) => (SCode.Class, Env.Env)
relation lookup_var : (Env.Env,Exp.ComponentRef)
=> (Types.Attributes,Types.Type,Types.Binding)
relation lookup_var_local : (Env.Env,Exp.ComponentRef)
Expand Down Expand Up @@ -55,15 +55,15 @@ end
(** relation: lookup_class
**)

relation lookup_class: (Env.Env,Absyn.Path) => SCode.Class =
relation lookup_class: (Env.Env,Absyn.Path) => (SCode.Class, Env.Env) =

rule lookup_class_in_env(env,path) => c
rule lookup_class_in_env(env,path) => (c, env)
--------------------------------------
lookup_class(env, path) => c
lookup_class(env, path) => (c, env)

rule lookup_package_class (env,pack,path) => c
rule lookup_package_class (env,pack,path) => (c, env)
--------------------------------------
lookup_class(env, Absyn.QUALIFIED(pack,path)) => c
lookup_class(env, Absyn.QUALIFIED(pack,path)) => (c, env)

end

Expand Down Expand Up @@ -160,27 +160,27 @@ end

(** Class lookup *)

relation lookup_class_in_env: (Env.Env,Absyn.Path) => (SCode.Class) =
relation lookup_class_in_env: (Env.Env,Absyn.Path) => (SCode.Class, Env.Env) =

rule lookup_class_in_frame(items,id) => c
rule lookup_class_in_frame(items,id) => (c, env)
---------------------
lookup_class_in_env(Env.FRAME(items)::fs,Absyn.IDENT(id)) => c
lookup_class_in_env(Env.FRAME(items)::fs,Absyn.IDENT(id)) => (c, env)

rule lookup_class_in_env(fs,id) => c
rule lookup_class_in_env(fs,id) => (c, env)
---------------------
lookup_class_in_env(f::fs,id) => c
lookup_class_in_env(f::fs,id) => (c, env)

end
(**)
relation lookup_class_in_frame: ((SCode.Ident * Env.Item) list,
SCode.Ident)
=> SCode.Class =
=> (SCode.Class, Env.Env) =

rule (* print " lookup_class_in_frame(" & print id & print "): " &
print n & print "\n" & *)
id = n
---------------------------------------------------------
lookup_class_in_frame((n,Env.CLASS(c))::_, id) => c
lookup_class_in_frame((n,Env.CLASS(c, env))::_, id) => (c, env)

(*
rule id = n & print "# Error while looking up class " &
Expand All @@ -189,19 +189,19 @@ relation lookup_class_in_frame: ((SCode.Ident * Env.Item) list,
lookup_class_in_frame((n,Env.VAR(_))::_,id) => fail
*)

rule lookup_class_in_frame(fs,id) => c
rule lookup_class_in_frame(fs,id) => (c, env)
------------------------------
lookup_class_in_frame(_::fs,id) => c
lookup_class_in_frame(_::fs,id) => (c, env)

end
(**)
relation lookup_package_class : (Env.Env, string, Absyn.Path)
=> SCode.Class =
=> (SCode.Class, Env.Env) =

rule locate_package (env,packname) => pack &
lookup_class_in_package (pack, path) => c
lookup_class_in_package (pack, path) => (c, env)
-------------------------------------
lookup_package_class (env, packname, path) => c
lookup_package_class (env, packname, path) => (c, env)

end
(**)
Expand Down Expand Up @@ -330,7 +330,7 @@ end

relation locate_package : (Env.Env, string) => SCode.Class =

rule lookup_class(env, Absyn.IDENT(pack)) => c &
rule lookup_class(env, Absyn.IDENT(pack)) => (c, env) &
assert_package c
----------------
locate_package (env, pack) => c
Expand Down Expand Up @@ -363,15 +363,20 @@ end
**
** This relation searches a class definition for a named class
** definition.
**
** The class is returned together with an empty environment, which
** might cause problems. This should be solved using implicit
** instantiation, but that is future work.
**)

relation lookup_class_in_package : (SCode.Class, Absyn.Path) => SCode.Class =
relation lookup_class_in_package : (SCode.Class, Absyn.Path)
=> (SCode.Class, Env.Env) =

rule lookup_class_in_elements (els, path) => c
-----------------------------------------
lookup_class_in_package (SCode.CLASS(_,_,_,
SCode.PARTS(els,_,_)),
path) => c
path) => (c, Env.empty_env)

end
(** relation: lookup_class_in_elements
Expand All @@ -390,7 +395,7 @@ relation lookup_class_in_elements : (SCode.Element list, Absyn.Path)

rule n1 = n2 &
assert_package c &
lookup_class_in_package (c, path) => c'
lookup_class_in_package (c, path) => (c', env)
----------------------------
lookup_class_in_elements (SCode.CLASSDEF(n1,_,_,c)::_,
Absyn.QUALIFIED(n2, path))
Expand Down
5 changes: 5 additions & 0 deletions modeq/staticexp.rml
Expand Up @@ -448,6 +448,11 @@ relation elab_cref : (Env.Env, Absyn.ComponentRef)
---------------------------------
elab_cref(env, c) => (exp, PROP(t, const), acc')

rule elab_cref_subs (env,c) => (c', const) &
print "# Unknown component: " & Dump.print_component_ref c & print "\n"
-----------------------------------------------------
elab_cref(env, c) => fail

rule print "- elab_cref failed\n"
------------------------------
elab_cref (_,_) => fail
Expand Down

0 comments on commit 002531b

Please sign in to comment.