Skip to content
Snippets Groups Projects
Commit e50f33f4 authored by Virgile Prevosto's avatar Virgile Prevosto
Browse files

[crowbar] catch exception if pretty-printed code is not re-parsable

parent 4688e55b
No related branches found
No related tags found
No related merge requests found
...@@ -512,12 +512,18 @@ let check_file (env, file) = ...@@ -512,12 +512,18 @@ let check_file (env, file) =
let prj2 = Project.create "copy" in let prj2 = Project.create "copy" in
Project.set_current prj2; Project.set_current prj2;
Kernel.Files.set [ Filepath.Normalized.of_string file_name ]; Kernel.Files.set [ Filepath.Normalized.of_string file_name ];
File.init_from_cmdline (); let parse_success =
let copy_buf = Buffer.create 150 in try
let fmt = Format.formatter_of_buffer copy_buf in File.init_from_cmdline (); true
let f = Globals.Functions.find_by_name "f" in with
Kernel_function.pretty fmt f; Log.AbortError _ -> ignore_deferred_errors (); false
if Buffer.contents norm_buf <> Buffer.contents copy_buf then begin in
if parse_success then begin
let copy_buf = Buffer.create 150 in
let fmt = Format.formatter_of_buffer copy_buf in
let f = Globals.Functions.find_by_name "f" in
Kernel_function.pretty fmt f;
if Buffer.contents norm_buf <> Buffer.contents copy_buf then begin
let norm = open_out (file_name ^ ".norm.c") in let norm = open_out (file_name ^ ".norm.c") in
Buffer.output_buffer norm norm_buf; Buffer.output_buffer norm norm_buf;
flush norm; flush norm;
...@@ -528,6 +534,9 @@ let check_file (env, file) = ...@@ -528,6 +534,9 @@ let check_file (env, file) =
close_out copy; close_out copy;
report file_name "Found ghost code not well pretty-printed" report file_name "Found ghost code not well pretty-printed"
end else true end else true
end else begin
report file_name "Error during re-parsing of pretty-printed code"
end
end end
else else
report file_name "Found ghost code that should have been accepted" report file_name "Found ghost code that should have been accepted"
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment