From 3f0005dba1893bb9c4dbea4c190efadf1e7958ab Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?C=C3=A9dric=20Pasteur?= Date: Wed, 28 Jul 2010 10:44:32 +0200 Subject: [PATCH] Open modules during scoping We need to open Modules during scoping so that we can resolve consts given without a module name. --- compiler/heptagon/analysis/typing.ml | 1 - compiler/heptagon/parsing/hept_scoping.ml | 9 ++++++--- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/compiler/heptagon/analysis/typing.ml b/compiler/heptagon/analysis/typing.ml index 374de39..a35c794 100644 --- a/compiler/heptagon/analysis/typing.ml +++ b/compiler/heptagon/analysis/typing.ml @@ -1118,7 +1118,6 @@ let typing_const_dec cd = let program ({ p_opened = opened; p_types = p_type_list; p_nodes = p_node_list; p_consts = p_consts_list } as p) = - List.iter open_module opened; let typed_cd_list = List.map typing_const_dec p_consts_list in List.iter deftype p_type_list; let typed_node_list = List.map node p_node_list in diff --git a/compiler/heptagon/parsing/hept_scoping.ml b/compiler/heptagon/parsing/hept_scoping.ml index 0f1d7c8..c907945 100644 --- a/compiler/heptagon/parsing/hept_scoping.ml +++ b/compiler/heptagon/parsing/hept_scoping.ml @@ -9,6 +9,7 @@ open Idents open Format open Printf open Static +open Modules module Error = struct @@ -109,7 +110,10 @@ let rec static_exp_of_exp const_env e = if NamesEnv.mem n const_env then Svar (Name n) else - raise Not_static + (try + let { qualid = q } = find_const (Name n) in + Svar (Modname q) + with Not_found -> raise Not_static) | Econst se -> se.se_desc | Eapp({ a_op = Earray_fill; a_params = [n] }, [e]) -> Sarray_power (static_exp_of_exp const_env e, @@ -156,8 +160,6 @@ and translate_desc loc const_env env = function | Evar x -> if Rename.mem x env then (* defined var *) Heptagon.Evar (Rename.name loc env x) - else if NamesEnv.mem x const_env then (* defined as const var *) - Heptagon.Econst (mk_static_exp (Svar (Modules.longname x))) else (* undefined var *) Error.message loc (Error.Evar x) | Elast x -> Heptagon.Elast (Rename.name loc env x) @@ -316,6 +318,7 @@ let translate_const_dec const_env cd = Heptagon.c_loc = cd.c_loc; }, build_cd const_env cd let translate_program p = + List.iter open_module p.p_opened; let p_consts, const_env = Misc.mapfold translate_const_dec NamesEnv.empty p.p_consts in { Heptagon.p_modname = p.p_modname;