2002-04-26 05:16:26 -07:00
|
|
|
(***********************************************************************)
|
|
|
|
(* *)
|
|
|
|
(* MLTk, Tcl/Tk interface of Objective Caml *)
|
|
|
|
(* *)
|
|
|
|
(* Francois Rouaix, Francois Pessaux, Jun Furuse and Pierre Weis *)
|
|
|
|
(* projet Cristal, INRIA Rocquencourt *)
|
|
|
|
(* Jacques Garrigue, Kyoto University RIMS *)
|
|
|
|
(* *)
|
|
|
|
(* Copyright 2002 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, with the special exception on linking *)
|
|
|
|
(* described in file LICENSE found in the Objective Caml source tree. *)
|
|
|
|
(* *)
|
|
|
|
(***********************************************************************)
|
|
|
|
|
|
|
|
open Code
|
|
|
|
|
|
|
|
let debug = ref false
|
|
|
|
let defined = ref []
|
|
|
|
let linenum = ref 1
|
|
|
|
|
|
|
|
let rec nop = function
|
|
|
|
| Line _ -> incr linenum
|
|
|
|
| Ifdef (_, _, c1, c2o) ->
|
|
|
|
List.iter nop c1;
|
|
|
|
begin match c2o with
|
2002-07-23 07:12:03 -07:00
|
|
|
| Some c2 -> List.iter nop c2
|
|
|
|
| None -> ()
|
2002-04-26 05:16:26 -07:00
|
|
|
end
|
|
|
|
| _ -> ()
|
|
|
|
;;
|
|
|
|
|
|
|
|
let rec exec lp f = function
|
2010-01-22 04:48:24 -08:00
|
|
|
| Line line ->
|
|
|
|
if !debug then
|
|
|
|
prerr_endline (Printf.sprintf "%03d: %s" !linenum
|
2002-07-23 07:12:03 -07:00
|
|
|
(String.sub line 0 ((String.length line) - 1)));
|
2002-04-26 05:16:26 -07:00
|
|
|
f line; incr linenum
|
|
|
|
| Ifdef (sw, k, c1, c2o) ->
|
|
|
|
if List.mem k !defined = sw then begin
|
2002-07-23 07:12:03 -07:00
|
|
|
List.iter (exec lp f) c1;
|
|
|
|
begin match c2o with
|
|
|
|
| Some c2 -> List.iter nop c2
|
|
|
|
| None -> ()
|
|
|
|
end;
|
|
|
|
lp !linenum
|
2002-04-26 05:16:26 -07:00
|
|
|
end else begin
|
2002-07-23 07:12:03 -07:00
|
|
|
List.iter nop c1;
|
|
|
|
match c2o with
|
2010-01-22 04:48:24 -08:00
|
|
|
| Some c2 ->
|
2002-07-23 07:12:03 -07:00
|
|
|
lp !linenum;
|
|
|
|
List.iter (exec lp f) c2
|
|
|
|
| None -> ()
|
2002-04-26 05:16:26 -07:00
|
|
|
end
|
|
|
|
| Define k -> defined := k :: !defined
|
2010-01-22 04:48:24 -08:00
|
|
|
| Undef k ->
|
2002-04-26 05:16:26 -07:00
|
|
|
defined := List.fold_right (fun k' s ->
|
2002-07-23 07:12:03 -07:00
|
|
|
if k = k' then s else k' :: s) [] !defined
|
2002-04-26 05:16:26 -07:00
|
|
|
;;
|