From mboxrd@z Thu Jan 1 00:00:00 1970 Received: by pauillac.inria.fr; Mon, 14 Nov 94 10:37:25 +0100 Received: from concorde.inria.fr by pauillac.inria.fr; Fri, 11 Nov 94 20:18:55 +0100 Received: from uu3.psi.com (uu3.psi.com [38.145.250.2]) by concorde.inria.fr (8.6.9/8.6.9) with SMTP id UAA19634 for ; Fri, 11 Nov 1994 20:18:42 +0100 Received: from port6.manchester.nh.pub-ip.psi.net by uu3.psi.com (5.65b/4.0.071791-PSI/PSINet) via SMTP; id AA22284 for Pierre.Weis@inria.fr; Fri, 11 Nov 94 14:17:54 -0500 Message-Id: <9411111917.AA22284@uu3.psi.com> X-Sender: popfti@uu2.psi.com Mime-Version: 1.0 Content-Type: text/plain; charset="iso-8859-1" Content-Transfer-Encoding: binary Date: Fri, 11 Nov 1994 14:18:28 -0500 To: Judicael.Courant@lip.ens-lyon.fr (Judicael Courant) From: e@flavors.com (Doug Currie, Flavors Technology, Inc.) Subject: Re: Dead code removal / cross references Cc: Pierre.Weis@inria.fr Sender: weis@pauillac.inria.fr >called/used ? which modules are used by this one ? is this #open >really necessary ?) and detect and remove the useless #open and the >dead code. Does such a tool exists ? Here is a small piece of what you need... (* usedmodu.ml *) (* Copyright ) e, 1994. All rights reserved. This code may be freely distributed as long as this notice remains. *) (* To read a file, and return the list of the modules used *) let letter_p c = let x = int_of_char c in ((x > 0x40) & (x < 0x5b)) or ((x > 0x60) & (x < 0x7b)) ;; let identchp c = let x = int_of_char c in ((x > 0x40) & (x < 0x5b)) or ((x > 0x60) & (x < 0x7b)) or ((x > 0x2f) & (x < 0x3a)) ;; let sm ic = let buf = create_string 1024 in let mds = ref [] in let addm i = let m = (sub_string buf 0 i) in if mem m !mds then () else mds := (m :: !mds) in let rec s0 () = (* eat whitespace *) while (* match input_char ic with ` ` | `\n` | `\r` | `\t` -> true | c -> set_nth_char buf 0 c; false *) let c = input_char ic in if (letter_p c) or (c = `#`) then begin set_nth_char buf 0 c; false end else true do () done; s1 1 and s1 i = (* get token *) match input_char ic with (* ` ` | `\n` | `\r` | `\t` -> s5 i | *) `_` -> begin match input_char ic with `_` -> s2 i | c -> let j = (succ i) in set_nth_char buf i `_`; set_nth_char buf j c; s1 (succ j) end | c -> if identchp c then begin set_nth_char buf i c; s1 (succ i) end else s5 i and s2 i = (* record module, eat non-whsp *) addm i; while match input_char ic with ` ` | `\n` | `\r` | `\t` -> false | c -> true do () done; s0 () and s5 i = (* look for #open *) if (i = 5) & ((nth_char buf 0) = `#`) & ((nth_char buf 1) = `o`) & ((nth_char buf 2) = `p`) & ((nth_char buf 3) = `e`) & ((nth_char buf 4) = `n`) then begin while (input_char ic) != `"` do () done; let rec f i = let c = input_char ic in if c = `"` then addm i else begin set_nth_char buf i c; f (succ i) end in f 0; s0 () end else s0 () in try s0 () with End_of_file -> rev !mds ;; let modules_used_by_file filename = let ic = open_in filename in let res = sm ic in close_in ic; res ;; (* ********************************************* *)