Skip to content

Commit 3a3a62e

Browse files
author
Vadim Engelson
committed
Encapsulated messages added
git-svn-id: https://openmodelica.org/svn/OpenModelica/trunk@896 f25d12d1-65f4-0310-ae8a-bbce733d8d8e
1 parent c25c041 commit 3a3a62e

File tree

6 files changed

+221
-105
lines changed

6 files changed

+221
-105
lines changed

modeq/builtin.rml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -485,7 +485,7 @@ val array_array2int
485485
relation initial_env =
486486

487487
rule Debug.fprint ("insttr","Creating initial env.\n") &
488-
Env.open_scope(Env.empty_env) => env1 &
488+
Env.open_scope(Env.empty_env,false) => env1 &
489489
Env.extend_frame_c(env1, rl_type) => env2 &
490490
Env.extend_frame_c(env2, int_type) => env3 &
491491
Env.extend_frame_c(env3, str_type) => env4 &

modeq/builtin_safe.rml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -484,7 +484,7 @@ val array_array2int
484484

485485
relation initial_env =
486486

487-
rule Env.open_scope(Env.empty_env) => env1 &
487+
rule Env.open_scope(Env.empty_env,false) => env1 &
488488
Env.extend_frame_c(env1, rl_type) => env2 &
489489
Env.extend_frame_c(env2, int_type) => env3
490490

modeq/env.rml

Lines changed: 43 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -41,7 +41,10 @@ module Env:
4141

4242
type Ident = string
4343

44-
datatype Frame = FRAME of (Ident * Item) list
44+
datatype Frame = FRAME of (Ident * Item) list * bool
45+
(* bool=true means that FRAME is created due to encapsulated class *)
46+
47+
4548

4649
datatype Item = VAR of Types.Var * SCode.Element option * bool
4750
| CLASS of SCode.Class * Env
@@ -50,10 +53,13 @@ module Env:
5053

5154
type Env = Frame list
5255

53-
val empty_frame : Frame
56+
val empty_not_encapsulated_frame : Frame
57+
val empty_encapsulated_frame : Frame
58+
59+
5460
val empty_env : Env
5561

56-
relation open_scope : Env => Env
62+
relation open_scope : (Env,bool) => Env
5763
relation extend_frame_c : (Env, SCode.Class) => Env
5864
relation extend_frame_classes : (Env, SCode.Program) => Env
5965
relation extend_frame_v : (Env, Types.Var,SCode.Element option,bool) => Env
@@ -78,7 +84,8 @@ with "print.rml"
7884

7985
(** - Values *)
8086

81-
val empty_frame = FRAME([])
87+
val empty_not_encapsulated_frame = FRAME([],false)
88+
val empty_encapsulated_frame = FRAME([],true)
8289
val empty_env = []
8390

8491
(** - Relations *)
@@ -89,14 +96,14 @@ val empty_env = []
8996
** top of the stack of frames.
9097
**)
9198

92-
relation open_scope: Env => Env =
99+
relation open_scope: (Env,bool) => Env =
93100

94-
axiom open_scope(env) => empty_frame::env
101+
axiom open_scope(env,encflag) => FRAME([],encflag)::env
95102

96103
(* rule
97104
Print.print_buf "\nOpens scope."
98105
-----------
99-
open_scope(env) => empty_frame::env
106+
open_scope(env,encflag) => FRAME([],encflag)::env
100107
*)
101108
end
102109

@@ -113,15 +120,15 @@ relation extend_frame_c : (Env, SCode.Class) => Env =
113120
Print.print_buf " + " &
114121
Print.print_buf n &
115122
Print.print_buf " = " &
116-
print_env ((FRAME((n,CLASS(c,env))::items)::fs)) &
123+
print_env ((FRAME((n,CLASS(c,env))::items,encflag)::fs)) &
117124
Print.print_buf "\n"
118125
----------------
119-
extend_frame_c(env as (FRAME(items)::fs),c as SCode.CLASS(n,_,_,_))
120-
=> ((FRAME((n,CLASS(c,env))::items)::fs))
126+
extend_frame_c(env as (FRAME(items,encflag)::fs),c as SCode.CLASS(n,_,_,_))
127+
=> ((FRAME((n,CLASS(c,env))::items,encflag)::fs))
121128
*)
122129

123-
axiom extend_frame_c(env as (FRAME(items)::fs),c as SCode.CLASS(n,_,_,_,_))
124-
=> ((FRAME((n,CLASS(c,env))::items)::fs))
130+
axiom extend_frame_c(env as (FRAME(items,encflag)::fs),c as SCode.CLASS(n,_,_,_,_))
131+
=> ((FRAME((n,CLASS(c,env))::items,encflag)::fs))
125132

126133
end
127134

@@ -148,15 +155,15 @@ relation extend_frame_v : (Env,Types.Var,SCode.Element option,bool) => Env =
148155
Print.print_buf " + " &
149156
Print.print_buf n &
150157
Print.print_buf " = " &
151-
print_env (FRAME((n,VAR(v))::items)::fs) &
158+
print_env (FRAME((n,VAR(v))::items,encflag)::fs) &
152159
Print.print_buf "\n"
153160
----------------
154-
extend_frame_v(env as (FRAME(items)::fs),v as Types.VAR(n,_,_,_,_))
155-
=> (FRAME((n,VAR(v))::items)::fs)
161+
extend_frame_v(env as (FRAME(items,encflag)::fs),v as Types.VAR(n,_,_,_,_))
162+
=> (FRAME((n,VAR(v))::items,encflag)::fs)
156163
*)
157164

158-
axiom extend_frame_v(FRAME(items)::fs,v as Types.VAR(n,_,_,_,_),c,i)
159-
=> (FRAME((n,VAR(v,c,i))::items)::fs)
165+
axiom extend_frame_v(FRAME(items,encflag)::fs,v as Types.VAR(n,_,_,_,_),c,i)
166+
=> (FRAME((n,VAR(v,c,i))::items,encflag)::fs)
160167

161168
end
162169

@@ -172,17 +179,17 @@ relation update_frame_v : (Env,Types.Var,bool) => Env =
172179

173180
rule v = n
174181
---------------------------
175-
update_frame_v(FRAME((id,VAR(Types.VAR(v,_,_,_,_),c,_))::rest)::rest2,v2 as Types.VAR(n,_,_,_,_),i)
176-
=> (FRAME((id,VAR(v2,NONE,i))::rest)::rest2)
182+
update_frame_v(FRAME((id,VAR(Types.VAR(v,_,_,_,_),c,_))::rest,encflag)::rest2,v2 as Types.VAR(n,_,_,_,_),i)
183+
=> (FRAME((id,VAR(v2,NONE,i))::rest,encflag)::rest2)
177184
rule not v = n &
178-
update_frame_v(FRAME(rest)::rest2,v2,i) => FRAME(res)::reslst
185+
update_frame_v(FRAME(rest,encflag)::rest2,v2,i) => FRAME(res,encflag)::reslst
179186
-------------------------------------------
180-
update_frame_v(FRAME((id,VAR(v1 as Types.VAR(v,_,_,_,_),c,i1))::rest)::rest2,v2 as Types.VAR(n,_,_,_,_),i)
181-
=> FRAME((id,VAR(v1,c,i1))::res)::reslst
187+
update_frame_v(FRAME((id,VAR(v1 as Types.VAR(v,_,_,_,_),c,i1))::rest,encflag)::rest2,v2 as Types.VAR(n,_,_,_,_),i)
188+
=> FRAME((id,VAR(v1,c,i1))::res,encflag)::reslst
182189

183190

184-
axiom update_frame_v(FRAME([])::fs,v as Types.VAR(n,_,_,_,_),_)
185-
=> (FRAME([])::fs)
191+
axiom update_frame_v(FRAME([],encflag)::fs,v as Types.VAR(n,_,_,_,_),_)
192+
=> (FRAME([],encflag)::fs)
186193
end
187194

188195
(** relation: extend_frame_t
@@ -202,22 +209,22 @@ relation extend_frame_t : (Env,Ident,Types.Type) => Env =
202209
Print.print_buf " + " &
203210
Print.print_buf n &
204211
Print.print_buf " = " &
205-
print_env (FRAME((n,TYPE(t))::items)::fs) &
212+
print_env (FRAME((n,TYPE(t))::items,encflag)::fs) &
206213
Print.print_buf "\n"
207214
----------------
208-
extend_frame_t(env as (FRAME(items)::fs), n, t)
209-
=> (FRAME((n,TYPE(t))::items)::fs)
215+
extend_frame_t(env as (FRAME(items,encflag)::fs), n, t)
216+
=> (FRAME((n,TYPE(t))::items,encflag)::fs)
210217
*)
211218

212-
axiom extend_frame_t(FRAME(items)::fs, n, t)
213-
=> (FRAME((n,TYPE(t))::items)::fs)
219+
axiom extend_frame_t(FRAME(items,encflag)::fs, n, t)
220+
=> (FRAME((n,TYPE(t))::items,encflag)::fs)
214221

215222
end
216223

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

219-
axiom extend_frame_i(FRAME(items)::fs,imp)
220-
=> (FRAME(("",IMPORT(imp))::items)::fs)
226+
axiom extend_frame_i(FRAME(items,encflag)::fs,imp)
227+
=> (FRAME(("",IMPORT(imp))::items,encflag)::fs)
221228
end
222229

223230
relation top_frame : Env => Frame =
@@ -243,11 +250,13 @@ end
243250

244251
relation print_frame : Frame => () =
245252

246-
rule Print.print_buf "FRAME: " &
253+
rule Print.print_buf "FRAME: (enc=" &
254+
Dump.print_bool encflag &
255+
Print.print_buf ") " &
247256
print_frame_contents cont &
248257
Print.print_buf "\n"
249258
--------------------------------------------
250-
print_frame FRAME(cont)
259+
print_frame FRAME(cont,encflag)
251260

252261
end
253262

@@ -335,7 +344,7 @@ relation build_frame_graphviz : Frame => Graphviz.Node =
335344
build_item_listnode (itemlist, is_type_item,"TYPES") => typesnode &
336345
let nodelist = [varsnode,classesnode,typesnode]
337346
-------------------------------------------
338-
build_frame_graphviz FRAME(itemlist) => Graphviz.NODE("FRAME",[],nodelist)
347+
build_frame_graphviz FRAME(itemlist,encflag) => Graphviz.NODE("FRAME",[],nodelist)
339348
end
340349

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

modeq/inst.rml

Lines changed: 14 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -198,7 +198,7 @@ relation instantiate_class : (SCode.Program, SCode.Path) => DAE.DAElist =
198198

199199
rule Builtin.initial_env => env &
200200
inst_class_decls(env,cdecls,path)=> (env',_) &
201-
Lookup.lookup_class(env',path) => (cdef, env'') &
201+
Lookup.lookup_class(env',path,true) => (cdef, env'') &
202202
inst_class(env'',Mod.NOMOD,Prefix.NOPRE,[],cdef,[],false) => (dae,_,_,_) &
203203
Absyn.path_string path => pathstr
204204
--------------------------------------------
@@ -356,15 +356,15 @@ relation inst_class : (Env, Mod, Prefix, Connect.Sets, SCode.Class, InstDims,boo
356356
------------------------------------------------------
357357
inst_class(env,mod,pre, csets, SCode.CLASS(n,true,_,_,_),_,false) => fail
358358

359-
rule Env.open_scope(env) => env' &
359+
rule Env.open_scope(env,encflag) => env' &
360360
ClassInf.start(r,n) => ci_state &
361361
inst_class_in(env', mod, pre, csets, ci_state, c, false,inst_dims,impl)
362362
=> (dae1,_,csets',ci_state', tys) &
363363
Connect.equations csets' => dae2 &
364364
list_append(dae1, dae2) => dae &
365365
mktype(ci_state',tys) => ty
366366
-------------------------------------------
367-
inst_class(env, mod, pre, csets, c as SCode.CLASS(n,_,_,r,_),inst_dims,impl)
367+
inst_class(env, mod, pre, csets, c as SCode.CLASS(n,_,encflag,r,_),inst_dims,impl)
368368
=> (dae, [], ty,ci_state')
369369

370370
rule Print.print_buf "- inst_class " & Print.print_buf n & Print.print_buf " failed\n"
@@ -446,7 +446,7 @@ relation inst_classdef: (Env, Mod, Prefix, Connect.Sets, ClassInf.State,
446446
rule Prefix.print_prefix_str pre => prestr &
447447
Absyn.path_string cn => cnstr &
448448
Debug.fprintl ("insttr", ["inst_class derived: ", cnstr, ", pre=",prestr,"\n"]) &
449-
Lookup.lookup_class(env,cn) => (c as SCode.CLASS(cn2,_,_,r,_), cenv) &
449+
Lookup.lookup_class(env,cn,true) => (c as SCode.CLASS(cn2,_,_,r,_), cenv) &
450450
Mod.lookup_modification_p(mods,cn) => m &
451451
Mod.elab_mod(env,pre,mod) => mod' &
452452
ClassInf.start(r, cn2) => new_ci_state &
@@ -466,7 +466,7 @@ relation inst_classdef: (Env, Mod, Prefix, Connect.Sets, ClassInf.State,
466466
(** found in the environment, this rule prints an error *)
467467
(** message. *)
468468

469-
rule not Lookup.lookup_class(env,cn) => (_,_) &
469+
rule not Lookup.lookup_class(env,cn,false) => (_,_) &
470470
Absyn.path_string(cn) => cns &
471471
Print.print_buf "# unknown class: " & Print.print_buf cns & Print.print_buf "\n"
472472
----------------------------------------
@@ -573,7 +573,7 @@ relation extend_components_to_env : (Env, Mod, Prefix, Connect.Sets, ClassInf.St
573573
SCode.Element list, InstDims, bool)
574574
=> (Env) =
575575

576-
rule Lookup.lookup_class(env,t) => (cl,cenv) &
576+
rule Lookup.lookup_class(env,t,true) => (cl,cenv) &
577577
Debug.fprint ("decl", "got class \n") &
578578

579579
(** PA: PROBLEM, Modifiers should be merged in this phase, but
@@ -659,7 +659,7 @@ relation inst_element : (Env, Mod, Prefix, Connect.Sets, ClassInf.State,
659659

660660
rule Absyn.path_string(cn) => cns &
661661
Debug.fprintln ("insttr", "Looking for base class") &
662-
Lookup.lookup_class(env,cn) => (c as SCode.CLASS(cn2,_,_,restr,def), cenv) &
662+
Lookup.lookup_class(env,cn,true) => (c as SCode.CLASS(cn2,_,_,restr,def), cenv) &
663663
Debug.fprintln ("insttr", "Base class found") &
664664
Mod.lookup_modification_p(mods,cn) => classmod &
665665
Debug.fprintln ("insttr", "Modifications fetched") &
@@ -705,7 +705,7 @@ relation inst_element : (Env, Mod, Prefix, Connect.Sets, ClassInf.State,
705705
SCode.CLASSDEF(n,_,_,_),_,_)
706706
=> fail
707707

708-
rule Lookup.lookup_class(env,Absyn.IDENT(n)) => (_,_) &
708+
rule Lookup.lookup_class(env,Absyn.IDENT(n),false) => (_,_) &
709709
Print.print_buf "# Trying to redeclare the variable " & Print.print_buf n &
710710
Print.print_buf " as a class\n"
711711
---------------------
@@ -772,7 +772,7 @@ relation inst_element : (Env, Mod, Prefix, Connect.Sets, ClassInf.State,
772772
Debug.fcall("insttr",Env.print_env,env) &
773773
Debug.fprint("insttr"," \n") &
774774

775-
Lookup.lookup_class(env,t) => (cl,cenv) &
775+
Lookup.lookup_class(env,t,true) => (cl,cenv) &
776776

777777
Debug.fprintl ("insttr", ["found type for: ", n, "\n"]) &
778778
Debug.fprintln ("insttr", "Looking up class modifications") &
@@ -848,7 +848,7 @@ relation inst_element : (Env, Mod, Prefix, Connect.Sets, ClassInf.State,
848848
**)
849849

850850
(** Failure *)
851-
rule not Lookup.lookup_class(env,t) => (cl,cenv) &
851+
rule not Lookup.lookup_class(env,t,false) => (cl,cenv) &
852852
Absyn.path_string(t) => s &
853853
Print.print_buf "# unknown class '" & Print.print_buf s & Print.print_buf "' while instantiating " &
854854
Prefix.prefix_add(n,[],pre) => pre' &
@@ -1105,7 +1105,7 @@ relation update_variable_in_env: (Mod.Mod,Absyn.ComponentRef, Env.Env, bool)
11051105
attr as SCode.ATTR(ad,flow,acc,param,dir),
11061106
t,m)),_) &
11071107

1108-
Lookup.lookup_class(env,t) => (cl,cenv) &
1108+
Lookup.lookup_class(env,t,false) => (cl,cenv) &
11091109

11101110
get_cref_from_mod(m) => crefs &
11111111
update_variables_in_env(mods,crefs,env,impl) => env2' &
@@ -2046,7 +2046,7 @@ end
20462046
(** HJ: **)
20472047
relation add_for_loop_scope : (Env.Env, Ident, Types.Type) => Env.Env =
20482048

2049-
rule Env.open_scope env => env' &
2049+
rule Env.open_scope (env,false) => env' &
20502050
Env.extend_frame_v(env',
20512051
Types.VAR(i,
20522052
Types.ATTR(false,
@@ -2414,7 +2414,7 @@ relation unroll : (Env, Mod, Prefix, Connect.Sets, ClassInf.State,
24142414

24152415
axiom unroll (_,_,_,csets,_,_,Values.ARRAY([]),_) => ([], csets)
24162416

2417-
rule Env.open_scope env => env' &
2417+
rule Env.open_scope (env,false) => env' &
24182418
Env.extend_frame_v (env',
24192419
Types.VAR(i, Types.ATTR(false,
24202420
SCode.RO,
@@ -3061,7 +3061,7 @@ relation inst_record_constructor_elt : (Env.Env,SCode.Element) =>
30613061
rule Debug.fprint ("recconst", "inst_record_constructor_elt called\n") &
30623062
elab_arraydim(env,dim,NONE,true,NONE) => dimexp &
30633063
Debug.fprint ("recconst", "elaborated arraydim\n") &
3064-
Lookup.lookup_class(env,t) => (cl,cenv) &
3064+
Lookup.lookup_class(env,t,true) => (cl,cenv) &
30653065
Debug.fprint ("recconst", "looked up class\n") &
30663066
Mod.elab_mod(env,Prefix.NOPRE,mod) => mod' &
30673067

0 commit comments

Comments
 (0)