1999-12-16 04:25:11 -08:00
|
|
|
(*************************************************************************)
|
|
|
|
(* *)
|
|
|
|
(* Objective Caml LablTk library *)
|
|
|
|
(* *)
|
|
|
|
(* Francois Rouaix, Francois Pessaux and Jun Furuse *)
|
|
|
|
(* projet Cristal, INRIA Rocquencourt *)
|
|
|
|
(* Jacques Garrigue, Kyoto University RIMS *)
|
|
|
|
(* *)
|
|
|
|
(* Copyright 1999 Institut National de Recherche en Informatique et *)
|
|
|
|
(* en Automatique and Kyoto University. All rights reserved. *)
|
|
|
|
(* This file is distributed under the terms of the GNU Library *)
|
|
|
|
(* General Public License. *)
|
|
|
|
(* *)
|
|
|
|
(*************************************************************************)
|
|
|
|
|
1999-11-30 06:59:39 -08:00
|
|
|
(* $Id$ *)
|
|
|
|
|
|
|
|
(* Write .mli for widgets *)
|
|
|
|
|
|
|
|
open Tables
|
|
|
|
open Compile
|
|
|
|
|
2000-04-11 20:43:25 -07:00
|
|
|
let write_create_p ~w wname =
|
1999-11-30 06:59:39 -08:00
|
|
|
w "val create :\n ?name:string ->\n";
|
|
|
|
begin
|
|
|
|
try
|
2000-04-02 18:57:52 -07:00
|
|
|
let option = Hashtbl.find types_table "options" in
|
|
|
|
let classdefs = List.assoc wname option.subtypes in
|
2000-04-11 20:43:25 -07:00
|
|
|
let tklabels = List.map ~f:gettklabel classdefs in
|
|
|
|
let l = List.map classdefs ~f:
|
1999-11-30 06:59:39 -08:00
|
|
|
begin fun fc ->
|
|
|
|
begin let p = gettklabel fc in
|
2000-04-11 20:43:25 -07:00
|
|
|
if count ~item:p tklabels > 1 then small fc.ml_name else p
|
|
|
|
end,
|
|
|
|
fc.template
|
1999-11-30 06:59:39 -08:00
|
|
|
end in
|
2000-04-11 20:43:25 -07:00
|
|
|
w (String.concat ~sep:" ->\n"
|
|
|
|
(List.map l ~f:
|
2000-02-17 08:52:32 -08:00
|
|
|
begin fun (s, t) ->
|
1999-11-30 06:59:39 -08:00
|
|
|
" ?" ^ s ^ ":"
|
|
|
|
^(ppMLtype
|
|
|
|
(match types_of_template t with
|
2000-04-11 20:43:25 -07:00
|
|
|
| [t] -> labeloff t ~at:"write_create_p"
|
2000-02-17 08:52:32 -08:00
|
|
|
| [] -> fatal_error "multiple"
|
2000-04-11 20:43:25 -07:00
|
|
|
| l -> Product (List.map ~f:(labeloff ~at:"write_create_p") l)))
|
1999-11-30 06:59:39 -08:00
|
|
|
end))
|
|
|
|
with Not_found -> fatal_error "in write_create_p"
|
|
|
|
end;
|
2000-02-17 08:52:32 -08:00
|
|
|
w (" ->\n 'a widget -> " ^ wname ^ " widget\n");
|
1999-11-30 06:59:39 -08:00
|
|
|
w " (* [create p options ?name] creates a new widget with\n";
|
|
|
|
w " parent p and new patch component name.\n";
|
|
|
|
w " Options are restricted to the widget class subset,\n";
|
|
|
|
w " and checked dynamically. *)\n"
|
|
|
|
|
|
|
|
(* Unsafe: write special comment *)
|
2000-04-11 20:43:25 -07:00
|
|
|
let write_function_type ~w def =
|
1999-11-30 06:59:39 -08:00
|
|
|
if not def.safe then w "(* unsafe *)\n";
|
|
|
|
w "val "; w def.ml_name; w " : ";
|
|
|
|
let us, ls, os =
|
|
|
|
let tys = types_of_template def.template in
|
2000-04-11 20:43:25 -07:00
|
|
|
let rec replace_args ~u ~l ~o = function
|
1999-11-30 06:59:39 -08:00
|
|
|
[] -> u, l, o
|
2000-02-17 08:52:32 -08:00
|
|
|
| (_, List(Subtype _) as x)::ls ->
|
2000-04-11 20:43:25 -07:00
|
|
|
replace_args ~u ~l ~o:(x::o) ls
|
2000-02-17 08:52:32 -08:00
|
|
|
| ("", _ as x)::ls ->
|
2000-04-11 20:43:25 -07:00
|
|
|
replace_args ~u:(x::u) ~l ~o ls
|
2000-02-17 08:52:32 -08:00
|
|
|
| (p, _ as x)::ls when p.[0] = '?' ->
|
2000-04-11 20:43:25 -07:00
|
|
|
replace_args ~u ~l ~o:(x::o) ls
|
1999-11-30 06:59:39 -08:00
|
|
|
| x::ls ->
|
2000-04-11 20:43:25 -07:00
|
|
|
replace_args ~u ~l:(x::l) ~o ls
|
1999-11-30 06:59:39 -08:00
|
|
|
in
|
2000-04-11 20:43:25 -07:00
|
|
|
replace_args ~u:[] ~l:[] ~o:[] (List.rev tys)
|
1999-11-30 06:59:39 -08:00
|
|
|
in
|
|
|
|
let counter = ref 0 in
|
2000-04-11 20:43:25 -07:00
|
|
|
List.iter (ls @ os @ us) ~f:
|
|
|
|
begin fun (l, t) ->
|
|
|
|
if l <> "" then w (l ^ ":");
|
|
|
|
w (ppMLtype t ~counter);
|
|
|
|
w " -> "
|
|
|
|
end;
|
1999-11-30 06:59:39 -08:00
|
|
|
if (os <> [] || ls = []) && us = [] then w "unit -> ";
|
2000-04-11 20:43:25 -07:00
|
|
|
w (ppMLtype ~any:true ~return:true def.result); (* RETURN TYPE !!! *)
|
1999-11-30 06:59:39 -08:00
|
|
|
w " \n";
|
|
|
|
(* w "(* tk invocation: "; w (doc_of_template def.template); w " *)"; *)
|
|
|
|
if def.safe then w "\n\n"
|
|
|
|
else w "\n(* /unsafe *)\n\n"
|
|
|
|
|
2000-04-11 20:43:25 -07:00
|
|
|
let write_external_type ~w def =
|
1999-11-30 06:59:39 -08:00
|
|
|
match def.template with
|
2000-02-15 02:11:12 -08:00
|
|
|
| StringArg fname ->
|
1999-11-30 06:59:39 -08:00
|
|
|
begin try
|
2000-02-15 02:11:12 -08:00
|
|
|
let realname = find_in_path !search_path (fname ^ ".mli") in
|
|
|
|
let ic = open_in_bin realname in
|
|
|
|
if not def.safe then w "(* unsafe *)\n";
|
|
|
|
begin try
|
|
|
|
while true do
|
|
|
|
w (input_line ic);
|
|
|
|
w "\n"
|
|
|
|
done
|
|
|
|
with
|
|
|
|
| End_of_file ->
|
|
|
|
close_in ic;
|
|
|
|
if def.safe then w "\n\n"
|
|
|
|
else w "\n(* /unsafe *)\n\n"
|
|
|
|
end
|
|
|
|
with
|
|
|
|
| Not_found ->
|
|
|
|
raise (Compiler_Error ("can't find external file: " ^ fname))
|
1999-11-30 06:59:39 -08:00
|
|
|
end
|
|
|
|
| _ -> raise (Compiler_Error "invalid external definition")
|