Skip to content
Snippets Groups Projects
Commit 1aab41bf authored by Erwan Jahier's avatar Erwan Jahier
Browse files

Add an include directive.

Also, in verbose mode, print the full path of the openned files.
parent ea7cd07d
No related branches found
No related tags found
No related merge requests found
(** Time-stamp: <modified the 28/05/2008 (at 14:09) by Erwan Jahier> *) (** Time-stamp: <modified the 30/05/2008 (at 15:42) by Erwan Jahier> *)
(** Common to lus2lic and lic2loc *) (** Common to lus2lic and lic2loc *)
...@@ -78,4 +78,10 @@ let make ( lexbuf ) = ( ...@@ -78,4 +78,10 @@ let make ( lexbuf ) = (
) )
let make_string ( lexbuf ) =
let lxm = make lexbuf in
{ lxm with _str = String.sub lxm._str 1 ((String.length lxm._str)-2) }
let last_made () = !last_lexeme let last_made () = !last_lexeme
(** Time-stamp: <modified the 14/04/2008 (at 17:53) by Erwan Jahier> *) (** Time-stamp: <modified the 30/05/2008 (at 15:42) by Erwan Jahier> *)
(** Common to lus2lic and lic2loc *) (** Common to lus2lic and lic2loc *)
...@@ -28,6 +28,8 @@ val cend : t -> int ...@@ -28,6 +28,8 @@ val cend : t -> int
val make : Lexing.lexbuf -> t val make : Lexing.lexbuf -> t
val new_line : Lexing.lexbuf -> unit val new_line : Lexing.lexbuf -> unit
(* remove the quotes from the string *)
val make_string: Lexing.lexbuf -> t
(** compiler interface *) (** compiler interface *)
......
(** Time-stamp: <modified the 28/05/2008 (at 14:30) by Erwan Jahier> *) (** Time-stamp: <modified the 30/05/2008 (at 15:37) by Erwan Jahier> *)
(** Here follows a description of the different modules used by this lus2lic compiler. (** Here follows a description of the different modules used by this lus2lic compiler.
...@@ -159,15 +159,16 @@ type maybe_packed = ...@@ -159,15 +159,16 @@ type maybe_packed =
let (get_source_list : string list -> SyntaxTree.pack_or_model list) = let (get_source_list : string list -> SyntaxTree.pack_or_model list) =
fun infile_list -> fun infile_list ->
let (get_one_source : string -> maybe_packed) = let (get_one_source : string -> string list * maybe_packed) =
fun infile -> fun infile ->
let inchannel = open_in infile in let inchannel =
Verbose.print_string ~level:3
("Opening file " ^ (Sys.getcwd ()) ^ infile ^ "\n");
open_in infile in
let lexbuf = Lexing.from_channel inchannel in let lexbuf = Lexing.from_channel inchannel in
Verbose.print_string ~level:3 ("Opening file " ^ infile ^ "\n");
Global.vars.current_file <- infile; Global.vars.current_file <- infile;
match (lus_load lexbuf) with match (lus_load lexbuf) with
| PRPackBody pbdy -> | PRPackBody(incl_files, pbdy) ->
let nme = let nme =
try Filename.chop_extension (Filename.basename infile) try Filename.chop_extension (Filename.basename infile)
with _ -> print_string ("*** '"^infile^"': Bad file name\n"); exit 1 with _ -> print_string ("*** '"^infile^"': Bad file name\n"); exit 1
...@@ -175,27 +176,38 @@ let (get_source_list : string list -> SyntaxTree.pack_or_model list) = ...@@ -175,27 +176,38 @@ let (get_source_list : string list -> SyntaxTree.pack_or_model list) =
let pi = let pi =
SyntaxTree.give_pack_this_name (Ident.pack_name_of_string nme) pbdy SyntaxTree.give_pack_this_name (Ident.pack_name_of_string nme) pbdy
in in
Unpacked (NSPack (Lxm.flagit pi (Lxm.dummy nme))) incl_files, Unpacked (NSPack (Lxm.flagit pi (Lxm.dummy nme)))
| PRPack_or_models nsl -> Packed nsl | PRPack_or_models(incl_files, nsl) -> incl_files, Packed nsl
in in
let (get_remaining_source_list : maybe_packed -> string -> maybe_packed) = let rec (get_remaining_source_list : maybe_packed * string list * string list ->
fun acc infile -> maybe_packed * string list * string list) =
match acc, get_one_source infile with fun (maybe_pack, compiled, to_be_compiled) ->
| Unpacked _, _ match to_be_compiled with
| _, Unpacked _ -> | [] -> (maybe_pack, compiled, [])
print_string ("old-style (un-packaged) lustre files can " ^ | infile::tail ->
" not be mixed with packages, nor be " ^ if List.mem infile compiled then
" defined in more than 1 file."); get_remaining_source_list (maybe_pack, compiled, tail)
exit 1 else
| Packed l1, Packed l2 -> Packed (l1@l2) let included_files, pack = get_one_source infile in
let new_maybe_pack =
match maybe_pack, pack with
| Unpacked _, _
| _, Unpacked _ ->
print_string ("old-style (un-packaged) lustre files can " ^
" not be mixed with packages, nor be " ^
" defined in more than 1 file.");
exit 1
| Packed l1, Packed l2 -> Packed (l1@l2)
in
get_remaining_source_list(
new_maybe_pack,
infile::compiled,
tail@included_files)
in in
let pack_list = let first_file = assert (infile_list <> []); List.hd infile_list in
assert (infile_list <> []); let included_files, first_pack = get_one_source first_file in
List.fold_left let (pack_list,_,_) = get_remaining_source_list
get_remaining_source_list (first_pack, [first_file], (List.tl infile_list) @ included_files)
(get_one_source (List.hd infile_list))
(List.tl infile_list)
in in
match pack_list with match pack_list with
| Packed l -> l | Packed l -> l
......
...@@ -306,7 +306,6 @@ let (treat_external_node : bool -> Lxm.t -> ...@@ -306,7 +306,6 @@ let (treat_external_node : bool -> Lxm.t ->
add_info node_table "(extern) node" ext_nodelxm ninfo ; add_info node_table "(extern) node" ext_nodelxm ninfo ;
def_list := (NodeItem (Lxm.id (ext_nodelxm),statics)) :: !def_list def_list := (NodeItem (Lxm.id (ext_nodelxm),statics)) :: !def_list
(**********************************************************************************) (**********************************************************************************)
(**********************************************************************************) (**********************************************************************************)
(**********************************************************************************) (**********************************************************************************)
...@@ -395,6 +394,9 @@ let (treat_external_node : bool -> Lxm.t -> ...@@ -395,6 +394,9 @@ let (treat_external_node : bool -> Lxm.t ->
%token <Lxm.t> TK_IS %token <Lxm.t> TK_IS
%token <Lxm.t> TK_BODY %token <Lxm.t> TK_BODY
%token <Lxm.t> TK_END %token <Lxm.t> TK_END
%token <Lxm.t> TK_INCLUDE
%token <Lxm.t> TK_STRING
/* %token <Lxm.t> TK_QUOTE */
/* Priorities */ /* Priorities */
...@@ -448,13 +450,13 @@ or a list of pack/model declaration ...@@ -448,13 +450,13 @@ or a list of pack/model declaration
sxLusFile: sxLusFile:
/* WARNING ! il faut remettre la liste l'endroit */ /* WARNING ! il faut remettre la liste l'endroit */
sxPackBody TK_EOF sxIncludeList sxPackBody TK_EOF
{ {
SyntaxTree.PRPackBody $1 SyntaxTree.PRPackBody($1, $2)
} }
| sxPackList TK_EOF | sxIncludeList sxPackList TK_EOF
{ {
SyntaxTree.PRPack_or_models (List.rev $1) SyntaxTree.PRPack_or_models ($1, List.rev $2)
} }
; ;
...@@ -474,9 +476,20 @@ sxOnePack: ...@@ -474,9 +476,20 @@ sxOnePack:
{ SyntaxTree.NSPack $1 } { SyntaxTree.NSPack $1 }
; ;
sxInclude:
TK_INCLUDE TK_STRING
{ (Lxm.str $2) }
;
sxIncludeList:
{ [] }
| sxInclude sxIncludeList
{ $1::$2 }
;
/* /*
Pour les provides, on rend des decls, bien Pour les provides, on rend des decls, bien
que synataxiquement, on n'autorise pas n'importe quoi ... que syntaxiquement, on n'autorise pas n'importe quoi ...
*/ */
sxProvides: sxProvides:
......
(** Time-stamp: <modified the 10/03/2008 (at 11:07) by Erwan Jahier> *) (** Time-stamp: <modified the 30/05/2008 (at 10:26) by Erwan Jahier> *)
(** (Raw) Abstract syntax tree of source programs. (** (Raw) Abstract syntax tree of source programs.
...@@ -23,8 +23,8 @@ type 'a error = ...@@ -23,8 +23,8 @@ type 'a error =
(**********************************************************************************) (**********************************************************************************)
type t = type t =
PRPackBody of packbody PRPackBody of string list * packbody
| PRPack_or_models of pack_or_model list | PRPack_or_models of string list * pack_or_model list
and and
pack_or_model = pack_or_model =
NSPack of pack_info srcflagged NSPack of pack_info srcflagged
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment