From f02f00a01b598567f70e138c144d9581973802e6 Mon Sep 17 00:00:00 2001 From: Bernhard Schommer Date: Thu, 8 Feb 2018 16:38:54 +0100 Subject: Refactor the handling of errors and warnings (#44) * Module Cerrors is now called Diagnostic and can be used in parts of CompCert other than cparser/ * Replaced eprintf error. Instead of having eprintf msg; exit 2 use the functions from the Diagnostics module. * Raise on error before calling external tools. * Added diagnostics to clightgen. * Fix error handling of AsmToJson. * Cleanup error handling of Elab and C2C. *The implementation of location printing (file & line) is simplified and correctly prints valid filenames with invalid lines. --- cparser/Parse.ml | 15 ++++++--------- 1 file changed, 6 insertions(+), 9 deletions(-) (limited to 'cparser/Parse.ml') diff --git a/cparser/Parse.ml b/cparser/Parse.ml index ecd13332..8665e158 100644 --- a/cparser/Parse.ml +++ b/cparser/Parse.ml @@ -46,7 +46,7 @@ let read_file sourcefile = text let preprocessed_file transfs name sourcefile = - Cerrors.reset(); + Diagnostics.reset(); (* Reading the whole file at once may seem costly, but seems to be the simplest / most robust way of accessing the text underlying a range of positions. This is used when printing an error message. @@ -55,7 +55,6 @@ let preprocessed_file transfs name sourcefile = on my machine. *) let text = read_file sourcefile in let p = - try let t = parse_transformations transfs in let rec inf = Datatypes.S inf in let ast : Cabs.definition list = @@ -70,13 +69,11 @@ let preprocessed_file transfs name sourcefile = | Parser.Parser.Inter.Fail_pr -> (* Theoretically impossible : implies inconsistencies between grammars. *) - Cerrors.fatal_error Cutil.no_loc "Internal error while parsing" + Diagnostics.fatal_error Diagnostics.no_loc "Internal error while parsing" | Parser.Parser.Inter.Timeout_pr -> assert false | Parser.Parser.Inter.Parsed_pr (ast, _ ) -> ast) in let p1 = Timing.time "Elaboration" Elab.elab_file ast in - Cerrors.raise_on_errors (); - Timing.time2 "Emulations" transform_program t p1 name - with - | Cerrors.Abort -> - [] in - if Cerrors.check_errors() then None else Some p + Diagnostics.check_errors (); + Timing.time2 "Emulations" transform_program t p1 name in + Diagnostics.check_errors(); + p -- cgit