This repository has been archived by the owner on Jun 4, 2019. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 205
/
main.ml
190 lines (149 loc) · 5.48 KB
/
main.ml
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
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
(*
* Please imagine a long and boring gnu-style copyright notice
* appearing just here.
*)
open Common
(*****************************************************************************)
(* Purpose *)
(*****************************************************************************)
(*
* A "driver" for the different parsers in pfff.
*)
(*****************************************************************************)
(* Flags *)
(*****************************************************************************)
(* In addition to flags that can be tweaked via -xxx options (cf the
* full list of options in the "the options" section below), this
* program also depends on external files ?
*)
let verbose = ref false
let lang = ref "c"
(* action mode *)
let action = ref ""
(*****************************************************************************)
(* Some debugging functions *)
(*****************************************************************************)
(*****************************************************************************)
(* Helpers *)
(*****************************************************************************)
(*****************************************************************************)
(* Main action *)
(*****************************************************************************)
let main_action _xs =
raise Todo
(*****************************************************************************)
(* Extra Actions *)
(*****************************************************************************)
let test_json_pretty_printer file =
let json = Json_in.load_json file in
let s = Json_io.string_of_json json in
pr s
(* ---------------------------------------------------------------------- *)
let pfff_extra_actions () = [
"-dump_json", " <file>",
Common.mk_action_1_arg test_json_pretty_printer;
"-json_pp", " <file>",
Common.mk_action_1_arg test_json_pretty_printer;
"-layer_stat", " <file>",
Common.mk_action_1_arg Test_program_lang.layer_stat;
]
(*****************************************************************************)
(* The options *)
(*****************************************************************************)
let all_actions () =
pfff_extra_actions() @
Test_parsing_ml.actions()@
Test_parsing_php.actions()@
Test_parsing_js.actions()@
Test_parsing_c.actions()@
Test_parsing_cpp.actions()@
Test_parsing_clang.actions()@
Test_mini.actions()@
(*
Test_parsing_bytecode.actions()++
*)
Test_parsing_java.actions()@
Test_parsing_nw.actions()@
Test_parsing_lisp.actions()@
Test_parsing_hs.actions()@
Test_parsing_python.actions()@
Test_parsing_csharp.actions()@
Test_parsing_rust.actions()@
Test_parsing_erlang.actions()@
Test_parsing_text.actions()@
Test_parsing_html.actions()@
Test_parsing_css.actions()@
Test_parsing_web.actions()@
Test_parsing_opa.actions()@
Test_parsing_sql.actions()@
(*
Test_analyze_cpp.actions () ++
Test_analyze_php.actions () ++
Test_analyze_ml.actions () ++
Test_analyze_clang.actions () ++
Test_analyze_c.actions() ++
*)
[]
let options () = [
"-verbose", Arg.Set verbose,
" ";
"-lang", Arg.Set_string lang,
(spf " <str> choose language (default = %s)" !lang);
] @
Flag_parsing_php.cmdline_flags_verbose () @
Flag_parsing_cpp.cmdline_flags_verbose () @
Flag_parsing_php.cmdline_flags_debugging () @
Flag_parsing_cpp.cmdline_flags_debugging () @
Flag_parsing_php.cmdline_flags_pp () @
Flag_parsing_cpp.cmdline_flags_macrofile () @
Common.options_of_actions action (all_actions()) @
Common2.cmdline_flags_devel () @
Common2.cmdline_flags_other () @
[
"-version", Arg.Unit (fun () ->
pr2 (spf "pfff version: %s" Config_pfff.version);
exit 0;
), " guess what";
]
(*****************************************************************************)
(* Main entry point *)
(*****************************************************************************)
let main () =
Gc.set {(Gc.get ()) with Gc.stack_limit = 1000 * 1024 * 1024};
(* Common_extra.set_link();
let argv = Features.Distribution.mpi_adjust_argv Sys.argv in
*)
let usage_msg =
"Usage: " ^ Common2.basename Sys.argv.(0) ^
" [options] <file or dir> " ^ "\n" ^ "Options are:"
in
(* does side effect on many global flags *)
let args = Common.parse_options (options()) usage_msg Sys.argv in
(* must be done after Arg.parse, because Common.profile is set by it *)
Common.profile_code "Main total" (fun () ->
(match args with
(* --------------------------------------------------------- *)
(* actions, useful to debug subpart *)
(* --------------------------------------------------------- *)
| xs when List.mem !action (Common.action_list (all_actions())) ->
Common.do_action !action xs (all_actions())
| _ when not (Common.null_string !action) ->
failwith ("unrecognized action or wrong params: " ^ !action)
(* --------------------------------------------------------- *)
(* main entry *)
(* --------------------------------------------------------- *)
| x::xs ->
main_action (x::xs)
(* --------------------------------------------------------- *)
(* empty entry *)
(* --------------------------------------------------------- *)
| [] ->
Common.usage usage_msg (options());
failwith "too few arguments"
)
)
(*****************************************************************************)
let _ =
Common.main_boilerplate (fun () ->
main ();
)