Commit 4fb800c2 authored by POTTIER Francois's avatar POTTIER Francois
Browse files

Refactoring. Fuse the two loops in [compare_errors].

This changes the order in which errors are produced.
The new order should now respect the order of the left-hand file.
parent 2fe6be9b
......@@ -674,37 +674,37 @@ let compare_errors filename1 filename2 =
(* Convert the right-hand file to a table for quick lookup. *)
let table2 = message_table false runs2 in
(* There is no need to convert the left-hand file. In fact, not
converting it to a table allows us to produce error messages
in an order that respects the left-hand file. *)
let table2 = message_table false runs2 in
in an order that respects the left-hand file. Indeed, the
left-hand file is processed by the following loop: *)
(* Check that the domain of [table1] is a subset of the domain of
[table2]. *)
Error.with_new_category (fun c ->
Error.with_new_category begin fun c ->
foreach_targeted_sentence begin fun () (sentence1, target1) message1 ->
foreach_targeted_sentence (fun () (sentence1, target1) _message1 ->
let s = target2state target1 in
if not (Lr1.NodeMap.mem s table2) then
(* 1. Check that the target state [s] appears in [table2]. *)
if not (Lr1.NodeMap.mem s table2) then begin
let poss1 = fst sentence1 in
Error.signal c poss1
"this sentence leads to an error in state %d.\n\
No sentence that leads to this state exists in \"%s\"."
(Lr1.number s) filename2
) () runs1;
(* Check that [table1] is a subset of [table2], that is, for every state
[s] in the domain of [table1], [s] is mapped by [table1] and [table2]
to the same error message. As an exception, if the message found in
[table1] is the default message, then no comparison takes place. This
allows using [--list-errors] and [--compare-errors] in conjunction to
ensure that a [.messages] file is complete, without seeing warnings
about different messages. *)
foreach_targeted_sentence (fun () (sentence1, target1) message1 ->
if message1 <> default_message then
end;
(* 2. Check that [s] is mapped by [table1] and [table2] to the same
error message. As an exception, if the message found in [table1] is
the default message, then no comparison takes place. This allows
using [--list-errors] and [--compare-errors] in conjunction to ensure
that a [.messages] file is complete, without seeing warnings about
different messages. *)
if message1 <> default_message then begin
try
let s = target2state target1 in
let sentence2, message2 = Lr1.NodeMap.find s table2 in
if message1 <> message2 then
let poss1 = fst sentence1
......@@ -715,9 +715,10 @@ let compare_errors filename1 filename2 =
(Lr1.number s) filename1 filename2
with Not_found ->
()
) () runs1
end
)
end () runs1
end
let () =
Settings.compare_errors |> Option.iter (fun (filename1, filename2) ->
......
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