From ea7cd07d07051f8d943170bf81736a1604a1d039 Mon Sep 17 00:00:00 2001 From: Erwan Jahier <jahier@imag.fr> Date: Thu, 29 May 2008 15:10:30 +0200 Subject: [PATCH] =?UTF-8?q?Automatically=20declare=20=20as=20=ABused=BB=20?= =?UTF-8?q?in=20=20an=20model=20instance,=20=20the=20packages=20that=20are?= =?UTF-8?q?=20used=20to=20instantiate=20the=20model.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Indeed, the current parser forbids the use of "uses" statements in a model instanciation. I could have changed the syntax, but I was not able to find a satisfying way to do it. For instance, in order to declare that package Toto uses packege Util, should we write package Toto uses Util; = M(int, int, Util::foo); ? The semicolon is really ugly. And it is so easy to realise that package Util should be used... --- src/expandPack.ml | 23 ++++++++++++++++++++--- src/test/test.res.exp | 21 +++++++++++++++++++-- 2 files changed, 39 insertions(+), 5 deletions(-) diff --git a/src/expandPack.ml b/src/expandPack.ml index 90ccf26d..9b2c3af1 100644 --- a/src/expandPack.ml +++ b/src/expandPack.ml @@ -1,4 +1,4 @@ -(** Time-stamp: <modified the 29/05/2008 (at 14:17) by Erwan Jahier> *) +(** Time-stamp: <modified the 29/05/2008 (at 15:01) by Erwan Jahier> *) open Lxm open SyntaxTree @@ -104,6 +104,23 @@ let (doit: ) (* check_arg *) in + let (sargs_pack : Ident.pack_name srcflagged list) = + List.fold_left + (fun acc arg -> + (match arg.it with + | StaticArgIdent(idref) -> + (match Ident.pack_of_idref idref with + | None -> acc + | Some p -> + let p_flagged = Lxm.flagit p arg.src in + if List.mem p_flagged acc then acc else p_flagged::acc + ) + | _ -> acc + ) + ) + [] + args + in let pars_nb = string_of_int (List.length pars) and args_nb = string_of_int (List.length args) in try ( @@ -135,8 +152,8 @@ let (doit: | None -> None in let pg = { - (* les uses du modèle ... *) - pg_uses = mi.it.mo_uses ; + (* les uses du modèle + les packages utilisés par les arg statiques *) + pg_uses = mi.it.mo_uses @ sargs_pack; pg_provides = prov ; pg_body = body ; } in diff --git a/src/test/test.res.exp b/src/test/test.res.exp index 4a3f52ee..0364ea0a 100644 --- a/src/test/test.res.exp +++ b/src/test/test.res.exp @@ -13193,8 +13193,25 @@ type TestCondact__t1 = int; type TestCondact__t2 = int; Exported constants: Exported nodes: -*** Error in file "should_work/packEnvTest/Condact.lus", line 21, col 42 to 52, token 'Util::carre': unknown node (carre) - +node TestCondact__n(e:int) returns (s:int); +let + s = Util__carre(e); +tel +-- end of node TestCondact__n +node TestCondact__C(c:bool; d:int; x:int) returns (y:int); +let + y = if (c) then (current (TestCondact__n(x))) else (d -> pre(y)); +tel +-- end of node TestCondact__C + * package Main + Exported types: + Exported constants: + Exported nodes: +node Main__Condact(c:bool; d:int; x:int) returns (y:int); +let + y = TestCondact__C(c, d, x); +tel +-- end of node Main__Condact ---------------------------------------------------------------------- ====> ../lus2lic -vl 3 --compile-all-items should_work/packEnvTest/contractForElementSelectionInArray/contractForElementSelectionInArray.lus -- GitLab