diff options
Diffstat (limited to 'cparser')
-rw-r--r-- | cparser/Cerrors.ml | 69 | ||||
-rw-r--r-- | cparser/Elab.mli | 9 |
2 files changed, 70 insertions, 8 deletions
diff --git a/cparser/Cerrors.ml b/cparser/Cerrors.ml index c7b791e0..dffd9c14 100644 --- a/cparser/Cerrors.ml +++ b/cparser/Cerrors.ml @@ -18,8 +18,15 @@ open Format open Commandline +(* Should errors be treated as fatal *) let error_fatal = ref false +(* Maximum number of errors, 0 means unlimited *) +let max_error = ref 0 + +(* Whether [-Woption] should be printed *) +let diagnostics_show_option = ref true + (* Test if color diagnostics are available by testing if stderr is a tty and if the environment varibale TERM is set *) @@ -33,6 +40,11 @@ let color_diagnostics = let num_errors = ref 0 let num_warnings = ref 0 + +let error_limit_reached () = + let max_err = !max_error in + max_err <> 0 && !num_errors >= max_err - 1 + let reset () = num_errors := 0; num_warnings := 0 exception Abort @@ -169,6 +181,9 @@ let wall () = Inline_asm_sdump; ] +let wnothing () = + active_warnings :=[] + (* Make all warnings an error *) let werror () = error_warnings:=[ @@ -198,12 +213,19 @@ let werror () = let key_of_warning w = match w with | Unnamed -> None - | _ -> Some ("-W"^(string_of_warning w)) + | _ -> if !diagnostics_show_option then + Some ("-W"^(string_of_warning w)) + else + None (* Add -Werror to the printed keys *) -let key_add_werror = function - | None -> Some ("-Werror") - | Some s -> Some ("-Werror,"^s) +let key_add_werror w = + if !diagnostics_show_option then + match w with + | None -> Some ("-Werror") + | Some s -> Some ("-Werror,"^s) + else + None (* Lookup how to print the warning *) let classify_warning w = @@ -250,10 +272,31 @@ let pp_key key fmt = | Some s -> " ["^s^"]" in fprintf fmt "%s%t@." key rsc +(* Different loc output formats *) +type loc_format = + | Default + | MSVC + | Vi + +let diagnostics_format : loc_format ref = ref Default + +(* Parse the option string *) +let parse_loc_format s = + let s = String.sub s 21 ((String.length s) - 21) in + let loc_fmt = match s with + | "ccomp" -> Default + | "msvc" -> MSVC + | "vi" -> Vi + | s -> Printf.eprintf "Invalid value '%s' in '-fdiagnostics-format=%s'\n" s s; exit 2 in + diagnostics_format := loc_fmt + (* Print the location or ccomp for the case of unknown loc *) let pp_loc fmt (filename,lineno) = if filename <> "" && lineno <> -10 && filename <> "cabs loc unknown" then - fprintf fmt "%t%s:%d:%t " bc filename lineno rsc + match !diagnostics_format with + | Default -> fprintf fmt "%t%s:%d:%t " bc filename lineno rsc + | MSVC -> fprintf fmt "%t%s(%d):%t " bc filename lineno rsc + | Vi -> fprintf fmt "%t%s +%d:%t " bc filename lineno rsc else fprintf fmt "%tccomp:%t " bc rsc @@ -282,7 +325,7 @@ let warning loc ty fmt = | SuppressedMsg -> ifprintf err_formatter fmt let error loc fmt = - if !error_fatal then + if !error_fatal || error_limit_reached ()then fatal_error None loc fmt else error None loc fmt @@ -301,7 +344,7 @@ let error_option w = let key = string_of_warning w in [Exact ("-W"^key), Unit (activate_warning w); Exact ("-Wno-"^key), Unit (deactivate_warning w); - Exact ("-Werror="^key), Unit ( warning_as_error w); + Exact ("-Werror="^key), Unit (warning_as_error w); Exact ("-Wno-error="^key), Unit ( warning_not_as_error w)] let warning_options = @@ -329,7 +372,13 @@ let warning_options = Exact ("-fdiagnostics-color"), Ignore; (* Either output supports it or no color *) Exact ("-fno-diagnostics-color"), Unset color_diagnostics; Exact ("-Werror"), Unit werror; - Exact ("-Wall"), Unit wall;] + Exact ("-Wall"), Unit wall; + Exact ("-w"), Unit wnothing; + longopt_int ("-fmax-errors") ((:=) max_error); + Exact("-fno-diagnostics-show-option"),Unset diagnostics_show_option; + Exact("-fdiagnostics-show-option"),Set diagnostics_show_option; + _Regexp("-fdiagnostics-format=\\(ccomp\\|msvc\\|vi\\)"),Self parse_loc_format; + ] let warning_help = {|Diagnostic options: -Wall Enable all warnings @@ -342,6 +391,10 @@ let warning_help = {|Diagnostic options: -Wfatal-errors Turn all errors into fatal errors aborting the compilation -fdiagnostics-color Turn on colored diagnostics -fno-diagnostics-color Turn of colored diagnostics + -fmax-errors=<n> Maximum number of errors to report + -fdiagnostics-show-option Print the option name with mappable diagnostics + -fno-diagnostics-show-option Turn of printing of options with mappable + diagnostics |} let raise_on_errors () = diff --git a/cparser/Elab.mli b/cparser/Elab.mli index 7eee4a08..f701e8c5 100644 --- a/cparser/Elab.mli +++ b/cparser/Elab.mli @@ -14,3 +14,12 @@ (* *********************************************************************) val elab_file : Cabs.definition list -> C.program + (* This is the main entry point. It transforms a list of toplevel + definitions as produced by the parser into a program in C abstract + syntax. *) + +val elab_int_constant : Cabs.cabsloc -> string -> int64 * C.ikind +val elab_float_constant : Cabs.floatInfo -> C.float_cst * C.fkind +val elab_char_constant : Cabs.cabsloc -> bool -> int64 list -> int64 + (* These auxiliary functions are exported so that they can be reused + in other projects that deal with C-style source languages. *) |