-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.ml
More file actions
98 lines (72 loc) · 2.32 KB
/
main.ml
File metadata and controls
98 lines (72 loc) · 2.32 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
let cmt_list = ref []
let filename = ref ""
let dirname = ref ""
let print_flag = ref false
let test_flag = ref false
let elim_flag = ref false
let parse_arg_list = Str.split (Str.regexp "[ \t]+")
(* Function that recurcivly list all the .cmt in dirname *)
let rec iter_dir dirname =
if dirname = ""
then ()
else
let files = Sys.readdir dirname in
Array.iter (fun file ->
let file = Filename.concat dirname file in
if (Sys.file_exists file)
then
begin
if Sys.is_directory file then iter_dir file;
if Filename.check_suffix file ".cmt"
then cmt_list := file::!cmt_list
end
) files
let usage = "usage: " ^ Sys.argv.(0) ^ " [cmt1 cmt2 cmt3 ...] [-elim cmt_file] [-print cmt_file] [-elim-project rep]"
let speclist = [
(* ("-elim", Arg.String (fun s -> cmt_list := parse_arg_list s;elim_flag := true), *)
(* ": detect dead code in source file giving the cmt files"); *)
("-short", Arg.Unit (fun () -> Utils.short_flag := true),
": print rapport in short version");
("-print", Arg.String (fun s -> filename := s;print_flag := true),
": print the typedtree giving the cmt file");
("-d", Arg.String (fun s -> dirname := s; test_flag := true),
": detect dead code in source files giving a directory containing cmt files");
]
let _ =
Arg.parse
speclist
(fun x ->
if Filename.check_suffix x ".cmt"
then
begin
cmt_list := x::(!cmt_list);
test_flag := true
end
else
raise (Arg.Bad ("Bad argument : " ^ x)))
usage;
let fn = !filename in
let ppf = Format.std_formatter in
if (!elim_flag)
then
begin
let syst =
List.map (fun x -> (Utils.get_modname x,Deps.calc x)) !cmt_list in
let used = Deps.calc_inter_live syst in
List.iter (fun (fn,(idl,opn,args)) ->
ignore (Clean.soft_clean fn idl opn args)) used
end
else
if (!test_flag)
then
begin
iter_dir !dirname;
let syst =
List.map (fun x -> (Utils.get_modname x,Deps.calc x)) !cmt_list in
(* Utils.debug "@.inter@."; *)
let used = Deps.calc_inter_live syst in
List.iter (fun (fn,(idl,opn,args)) ->
ignore (Clean.soft_clean fn idl opn args)) used
end
else
Printer.dttree ppf fn