Commit a610b3f7 authored by David Hauzar's avatar David Hauzar

Merge branch 'counter-examples'

parents aff46e8d d92706f7
...@@ -290,12 +290,21 @@ let interleave_with_source ...@@ -290,12 +290,21 @@ let interleave_with_source
~source_code = ~source_code =
try try
let model_file = StringMap.find filename model.model_files in let model_file = StringMap.find filename model.model_files in
let lines = Str.split (Str.regexp "^") source_code in let src_lines_up_to_last_cntexmp_el source_code model_file =
let (last_cntexmp_line, _) = IntMap.max_binding model_file in
let lines = Str.bounded_split (Str.regexp "^") source_code (last_cntexmp_line+1) in
let remove_last_element list =
let list_rev = List.rev list in
match list_rev with
| _ :: tail -> List.rev tail
| _ -> List.rev list_rev
in
remove_last_element lines in
let (source_code, _) = List.fold_left let (source_code, _) = List.fold_left
(interleave_line (interleave_line
start_comment end_comment me_name_trans model_file) start_comment end_comment me_name_trans model_file)
("", 1) ("", 1)
lines in (src_lines_up_to_last_cntexmp_el source_code model_file) in
source_code source_code
with Not_found -> with Not_found ->
source_code source_code
......
...@@ -33,6 +33,9 @@ let () = reset_gc () ...@@ -33,6 +33,9 @@ let () = reset_gc ()
let debug = Debug.lookup_flag "ide_info" let debug = Debug.lookup_flag "ide_info"
let debug_show_text_cntexmp = Debug.register_info_flag "show_text_cntexmp"
~desc:"Print@ textual@ counterexample@ before@ printing@ counterexample@ interleaved@ with@ cource@ code."
(************************) (************************)
(* parsing command line *) (* parsing command line *)
(************************) (************************)
...@@ -644,13 +647,19 @@ let update_tabs a = ...@@ -644,13 +647,19 @@ let update_tabs a =
match a.S.proof_state with match a.S.proof_state with
| S.Done r -> | S.Done r ->
if not (Model_parser.is_model_empty r.Call_provers.pr_model) then begin if not (Model_parser.is_model_empty r.Call_provers.pr_model) then begin
let cntexample_text =
if Debug.test_flag debug_show_text_cntexmp then
"Counterexample:\n" ^ "Counterexample:\n" ^
(Model_parser.model_to_string r.Call_provers.pr_model) ^ (Model_parser.model_to_string r.Call_provers.pr_model) ^
"\n\nSource code interleaved with counterexample:" ^ "\n\nSource code interleaved with counterexample:"
else
"" in
let cntexample_text = cntexample_text ^
(Model_parser.interleave_with_source (Model_parser.interleave_with_source
r.Call_provers.pr_model r.Call_provers.pr_model
~filename:!current_file ~filename:!current_file
~source_code:(Sysutil.file_contents !current_file)) ~source_code:(Sysutil.file_contents !current_file)) in
cntexample_text
end else end else
"" ""
| _ -> "" | _ -> ""
...@@ -671,6 +680,7 @@ let update_tabs a = ...@@ -671,6 +680,7 @@ let update_tabs a =
edited_view#scroll_to_mark `INSERT; edited_view#scroll_to_mark `INSERT;
output_view#source_buffer#set_text output_text; output_view#source_buffer#set_text output_text;
counterexample_view#source_buffer#set_text counterexample_text; counterexample_view#source_buffer#set_text counterexample_text;
counterexample_view#scroll_to_mark `INSERT;
......
...@@ -194,16 +194,27 @@ let () = Trans.register_transform "intro_vc_vars_counterexmp" ...@@ -194,16 +194,27 @@ let () = Trans.register_transform "intro_vc_vars_counterexmp"
intro_vc_vars_counterexmp intro_vc_vars_counterexmp
~desc:"Introduce." ~desc:"Introduce."
let rec string_join sep l =
match l with
| [] -> ""
| [x] -> x
| x :: rest -> x ^ sep ^ string_join sep rest
let get_location_of_vc task = let get_location_of_vc task =
let meta_args = Task.on_meta_excl meta_vc_location task in let meta_args = Task.on_meta_excl meta_vc_location task in
match meta_args with match meta_args with
| Some [Theory.MAstr loc_str] -> | Some [Theory.MAstr loc_str] ->
let splitted = Strings.bounded_split ':' loc_str 4 in (* There may be colons in the file name. We still split on the colon, look at
let loc = match splitted with the last three elements, and put the remaining ones back together to form the
| [filename; line; col1; col2] -> file name. We may lose colons at the beginning or end of the filename, but
even on windows that's not allowed. *)
let split = Strings.rev_split ':' loc_str in
let loc = match split with
| col2 :: col1 :: line :: ((_ :: _) as rest) ->
let line = int_of_string line in let line = int_of_string line in
let col1 = int_of_string col1 in let col1 = int_of_string col1 in
let col2 = int_of_string col2 in let col2 = int_of_string col2 in
let filename = string_join ":" (List.rev rest) in
Some (Loc.user_position filename line col1 col2) Some (Loc.user_position filename line col1 col2)
| _ -> None in | _ -> None in
loc loc
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment