diff --git a/compiler/global/modules.ml b/compiler/global/modules.ml index 7a72408..c9b1c4a 100644 --- a/compiler/global/modules.ml +++ b/compiler/global/modules.ml @@ -164,6 +164,8 @@ let add_const f v = (** Same as add_value but without checking for redefinition *) let replace_value f v = g_env.values <- QualEnv.add f v g_env.values +let replace_type f v = + g_env.types <- QualEnv.add f v g_env.types (** { 3 Find functions look in the global environement, nothing more } *) diff --git a/compiler/heptagon/analysis/typing.ml b/compiler/heptagon/analysis/typing.ml index fbd3854..a24d88a 100644 --- a/compiler/heptagon/analysis/typing.ml +++ b/compiler/heptagon/analysis/typing.ml @@ -1096,10 +1096,28 @@ let typing_const_dec cd = let se = expect_static_exp QualEnv.empty ty cd.c_value in { cd with c_value = se; c_type = ty } +let typing_typedec td = + let tydesc = match td.t_desc with + | Type_abs -> Type_abs + | Type_enum(tag_list) -> Type_enum tag_list + | Type_alias t -> + let t = check_type QualEnv.empty t in + replace_type td.t_name (Talias t); + Type_alias t + | Type_struct(field_ty_list) -> + let typing_field { f_name = f; f_type = ty } = + { f_name = f; f_type = check_type QualEnv.empty ty } + in + let field_ty_list = List.map typing_field field_ty_list in + replace_type td.t_name (Tstruct field_ty_list); + Type_struct field_ty_list + in + { td with t_desc = tydesc } + let program p = let program_desc pd = match pd with | Pnode n -> Pnode (node n) | Pconst c -> Pconst (typing_const_dec c) - | _ -> pd + | Ptype t -> Ptype (typing_typedec t) in { p with p_desc = List.map program_desc p.p_desc }