File tree Expand file tree Collapse file tree
Expand file tree Collapse file tree Original file line number Diff line number Diff line change @@ -2580,7 +2580,7 @@ let elab_expr ctx loc env a =
25802580
25812581let elab_attrib_expr loc env a =
25822582 let (b, env') = elab_expr ctx_constexp loc env a in
2583- if env' != env then
2583+ if not ( Env. same_types env' env) then
25842584 fatal_error loc " cannot define new types within attributes" ;
25852585 b
25862586
Original file line number Diff line number Diff line change @@ -53,6 +53,15 @@ module IdentMap = struct
5353 let add id data m =
5454 let l = try StringMap. find id.name m with Not_found -> [] in
5555 StringMap. add id.name ((id, data) :: l) m
56+
57+ (* Comparison *)
58+ let compare m1 m2 =
59+ if m1 == m2 then 0 else StringMap. compare Stdlib. compare m1 m2
60+
61+ let compare_named m1 m2 =
62+ if m1 == m2 then 0 else
63+ StringMap. compare Stdlib. compare
64+ (StringMap. remove " " m1) (StringMap. remove " " m2)
5665end
5766
5867let gensym = ref 0
@@ -320,6 +329,18 @@ let set_builtins blt =
320329let is_builtin name =
321330 ident_is_bound ! Init. env name
322331
332+ (* Do two environments define the same struct/union/enum types? *)
333+
334+ let same_types env1 env2 =
335+ env1 == env2
336+ || (IdentMap. compare env1.env_tag env2.env_tag = 0
337+ && IdentMap. compare env1.env_enum env2.env_enum = 0 )
338+
339+ let same_named_types env1 env2 =
340+ env1 == env2
341+ || (IdentMap. compare_named env1.env_tag env2.env_tag = 0
342+ && IdentMap. compare_named env1.env_enum env2.env_enum = 0 )
343+
323344(* Error reporting *)
324345
325346open Printf
Original file line number Diff line number Diff line change @@ -86,3 +86,10 @@ val initial_identifiers: unit -> C.ident list
8686val initial_declarations : unit -> C .globdecl list
8787val set_builtins : C .builtins -> unit
8888val is_builtin : string -> bool
89+
90+ (* Comparing two environments. One of the environments is assumed
91+ to have been obtained from the other environment by a sequence
92+ of zero, one or several [add_*] operations. *)
93+
94+ val same_types : t -> t -> bool
95+ val same_named_types : t -> t -> bool
You can’t perform that action at this time.
0 commit comments