1 (*****************************************************************************)
2 (* convenient globals. *)
3 (*****************************************************************************)
5 (try (Sys.getenv
"YACFE_HOME")
6 with Not_found
-> "/home/pad/c-yacfe"
9 (*****************************************************************************)
11 (*****************************************************************************)
13 let macro_dir = "config/macros/"
14 let mk_macro_path ~cocci_path file
=
15 Filename.concat cocci_path
(macro_dir ^ file
)
18 (* to pass to parse_c.init_defs *)
19 let std_h = ref (mk_macro_path ~cocci_path
:!path "standard.h")
20 let common_h = ref (mk_macro_path ~cocci_path
:!path "common_macros.h")
23 let cmdline_flags_macrofile () =
25 "--macro-file-builtins", Arg.Set_string
std_h,
26 " <file> (default=" ^
!std_h ^
")";
30 (*****************************************************************************)
31 (* used only by cpp_ast_c, not by the parser *)
32 (*****************************************************************************)
33 let cpp_i_opts = ref []
34 let cpp_d_opts = ref []
36 let cmdline_flags_cpp () = [
37 "-D", Arg.String
(fun s
-> Common.push2 s
cpp_d_opts),
39 "-I", Arg.String
(fun s
-> Common.push2 s
cpp_i_opts),
43 (*****************************************************************************)
45 (*****************************************************************************)
46 let std_envir = ref (Filename.concat
!path "config/envos/environment_splint.h")
48 let cmdline_flags_envfile () =
50 "--env-file", Arg.Set_string
std_envir,
51 " <file> (default=" ^
!std_envir ^
")";
54 (*****************************************************************************)
56 (*****************************************************************************)
58 let show_parsing_error = ref true
60 (*****************************************************************************)
62 (*****************************************************************************)
64 let verbose_lexing = ref true
65 let verbose_parsing = ref true
66 let verbose_type = ref true
67 let verbose_cfg = ref true
68 let verbose_annotater = ref true
69 let verbose_unparsing = ref true
70 let verbose_visit = ref true
71 let verbose_cpp_ast = ref true
73 let filter_msg = ref false
74 let filter_msg_define_error = ref false
76 let filter_define_error = ref false
78 let filter_passed_level = ref 0
80 let pretty_print_type_info = ref false
81 let pretty_print_comment_info = ref false
82 let pretty_print_typedef_value = ref false
85 let show_flow_labels = ref true
88 let cmdline_flags_verbose () =
90 "--no-verbose-parsing", Arg.Clear
verbose_parsing , " ";
91 "--no-verbose-lexing", Arg.Clear
verbose_lexing , " ";
92 "--no-verbose-annotater", Arg.Clear
verbose_annotater , " ";
94 "--no-parse-error-msg", Arg.Clear
verbose_parsing, " ";
95 "--no-type-error-msg", Arg.Clear
verbose_type, " ";
98 "--filter-msg", Arg.Set
filter_msg ,
99 " filter some cpp message when the macro is a \"known\" cpp construct";
100 "--filter-msg-define-error",Arg.Set
filter_msg_define_error,
101 " filter the error msg";
103 "--filter-define-error",Arg.Set
filter_define_error,
104 " filter the error, which will not be added in the stat";
105 "--filter-passed-level",Arg.Set_int
filter_passed_level," ";
109 (*****************************************************************************)
111 (*****************************************************************************)
113 let debug_lexer = ref false
114 let debug_etdt = ref false
115 let debug_typedef = ref false
116 let debug_cpp = ref false
118 let debug_cpp_ast = ref false
120 let debug_unparsing = ref false
122 let debug_cfg = ref false
124 (* "debug C parsing/unparsing", "" *)
125 let cmdline_flags_debugging () =
127 "--debug-cpp", Arg.Set
debug_cpp, " ";
128 "--debug-lexer", Arg.Set
debug_lexer , " ";
129 "--debug-etdt", Arg.Set
debug_etdt , " ";
130 "--debug-typedef", Arg.Set
debug_typedef, " ";
132 "--debug-cfg", Arg.Set
debug_cfg , " ";
133 "--debug-unparsing", Arg.Set
debug_unparsing, " ";
136 (*****************************************************************************)
138 (*****************************************************************************)
140 let check_annotater = ref true
141 let cmdline_flags_checks () =
143 "--disable-check-annotater", Arg.Clear
check_annotater, " ";
144 "--enable-check-annotater", Arg.Set
check_annotater, " ";
147 (*****************************************************************************)
149 (*****************************************************************************)
152 let label_strategy_2 = ref false
154 let cmdline_flags_algos () =
156 "--l1", Arg.Clear
label_strategy_2, " ";
159 (*****************************************************************************)
160 (* Disable parsing feature (for CC09 and also to see if useful) *)
161 (*****************************************************************************)
163 let cpp_directive_passing = ref false
164 let ifdef_directive_passing = ref false
166 let disable_multi_pass = ref false
167 let disable_add_typedef = ref false
169 let if0_passing = ref true
170 let add_typedef_root = ref true
172 let cmdline_flags_parsing_algos () = [
174 "--directive-passing", Arg.Set
cpp_directive_passing,
175 " pass most cpp directives, especially when inside function";
176 "--ifdef-passing", Arg.Set
ifdef_directive_passing,
177 " pass ifdef directives ";
179 "--noif0-passing", Arg.Clear
if0_passing,
181 "--noadd-typedef-root", Arg.Clear
add_typedef_root, " ";
182 "--noadd-typedef", Arg.Set
disable_add_typedef, " ";
184 "--disable-multi-pass", Arg.Set
disable_multi_pass, " ";
187 (*****************************************************************************)
189 (*****************************************************************************)
192 let diff_lines = ref (None
: string option) (* number of lines of context *)
195 let use_cache = ref false
196 let cache_prefix = ref (None
: string option)
197 let cache_limit = ref (None
: int option)
199 let cmdline_flags_other () =
201 "-U", Arg.Int
(fun n
-> diff_lines := Some
(Common.i_to_s n
)),
202 " set number of diff context lines";
204 "--use-cache", Arg.Set
use_cache,
205 " use .ast_raw pre-parsed cached C file";
208 (*****************************************************************************)
209 (* for lexing of integer constants *)
210 (*****************************************************************************)
214 (int (*int_sz*) * int (*long_sz*) *
215 Big_int.big_int
(*uint threshold*) *
216 Big_int.big_int
(*long threshold*) *
217 Big_int.big_int
(*ulong threshold*)) option)
220 match !int_thresholds with
222 (*assume long is 2*int; this can be corrected by a subsequent long_bits*)
223 let uint_threshold = Big_int.power_int_positive_int
2 (n
-1) in
224 let long_threshold = Big_int.power_int_positive_int
2 n
in
225 let ulong_threshold = Big_int.power_int_positive_int
2 ((2*n
)-1) in
227 Some
(n
,2*n
,uint_threshold,long_threshold,ulong_threshold)
228 | Some
(int_sz
,long_sz
,uint_threshold,long_threshold,ulong_threshold) ->
229 let uint_threshold = Big_int.power_int_positive_int
2 (n
-1) in
230 let long_threshold = Big_int.power_int_positive_int
2 n
in
232 Some
(n
,long_sz
,uint_threshold,long_threshold,ulong_threshold)
234 let set_long_bits n
=
235 match !int_thresholds with
237 (*assume int is 1/2*int; this can be corrected by a subsequent int_bits*)
239 | Some
(int_sz
,long_sz
,uint_threshold,long_threshold,ulong_threshold) ->
240 let ulong_threshold = Big_int.power_int_positive_int
2 (n
-1) in
242 Some
(int_sz
,n
,uint_threshold,long_threshold,ulong_threshold)
244 (*****************************************************************************)
245 (* unparsing strategy *)
246 (*****************************************************************************)
248 type spacing
= LINUX
| SMPL
249 let spacing = ref LINUX
251 let set_linux_spacing _
= spacing := LINUX
(*follow the conventions of Linux*)
252 let set_smpl_spacing _
= spacing := SMPL
(*use spacing from the SP*)
256 (*****************************************************************************)
258 (* drop back edges made by proper loop constructs -
259 unsafe but more efficient *)
260 let no_loops = ref false
261 let no_gotos = ref false
263 let keep_comments = ref false (* unparsing *)