From fec13ce2db675d18afb887e3c98f347a2b3de31e Mon Sep 17 00:00:00 2001 From: Akim Demaille Date: Wed, 2 Oct 2019 08:57:58 +0200 Subject: diagnostics: sort symbols per location Because the checking of the grammar is made by phases after the whole grammar was read, we sometimes have diagnostics that look weird. In some case, within one type of checking, the entities are not checked in the order in which they appear in the file. For instance, checking symbols is done on the list of symbols sorted by tag: foo.y:1.20-22: warning: symbol BAR is used, but is not defined as a token and has no rules [-Wother] 1 | %destructor {} QUX BAR | ^~~ foo.y:1.16-18: warning: symbol QUX is used, but is not defined as a token and has no rules [-Wother] 1 | %destructor {} QUX BAR | ^~~ Let's sort them by location instead: foo.y:1.16-18: warning: symbol 'QUX' is used, but is not defined as a token and has no rules [-Wother] 1 | %destructor {} QUX BAR | ^~~ foo.y:1.20-22: warning: symbol 'BAR' is used, but is not defined as a token and has no rules [-Wother] 1 | %destructor {} QUX BAR | ^~~ * src/location.h (location_cmp): Be robust to empty file names. * src/symtab.c (symbol_cmp): Sort by location. * tests/input.at: Adjust expectations. --- tests/diagnostics.at | 8 ++++---- tests/input.at | 16 ++++++++-------- 2 files changed, 12 insertions(+), 12 deletions(-) (limited to 'tests') diff --git a/tests/diagnostics.at b/tests/diagnostics.at index bd01c15d..deac06ff 100644 --- a/tests/diagnostics.at +++ b/tests/diagnostics.at @@ -427,16 +427,16 @@ res: QUX baz bar: QUUX ]], [1], -[[input.y:11.6-9: error: symbol 'QUUX' is used, but is not defined as a token and has no rules - 11 | bar: QUUX - | ^~~~ -input.y:10.6-8: error: symbol 'QUX' is used, but is not defined as a token and has no rules +[[input.y:10.6-8: error: symbol 'QUX' is used, but is not defined as a token and has no rules 10 | res: QUX baz | ^~~ input.y:10.10-12: error: symbol 'baz' is used, but is not defined as a token and has no rules; did you mean 'bar'? 10 | res: QUX baz | ^~~ | bar +input.y:11.6-9: error: symbol 'QUUX' is used, but is not defined as a token and has no rules + 11 | bar: QUUX + | ^~~~ ]]) diff --git a/tests/input.at b/tests/input.at index e5d7666b..976e5395 100644 --- a/tests/input.at +++ b/tests/input.at @@ -822,15 +822,15 @@ exp: bar; ]]) AT_BISON_CHECK([-fcaret input.y], [1], [], -[[input.y:2.16-18: error: symbol 'bar' is used, but is not defined as a token and has no rules - 2 | %destructor {} bar - | ^~~ +[[input.y:1.13-15: warning: symbol 'foo' is used, but is not defined as a token and has no rules [-Wother] + 1 | %printer {} foo baz + | ^~~ input.y:1.17-19: warning: symbol 'baz' is used, but is not defined as a token and has no rules [-Wother] 1 | %printer {} foo baz | ^~~ -input.y:1.13-15: warning: symbol 'foo' is used, but is not defined as a token and has no rules [-Wother] - 1 | %printer {} foo baz - | ^~~ +input.y:2.16-18: error: symbol 'bar' is used, but is not defined as a token and has no rules + 2 | %destructor {} bar + | ^~~ input.y:3.13-15: warning: symbol 'qux' is used, but is not defined as a token and has no rules [-Wother] 3 | %type qux | ^~~ @@ -1061,9 +1061,9 @@ AT_BISON_CHECK([-fcaret input.y], [1], [], input.y:2.10-12: error: user token number 42 redeclaration for BAR 2 | BAR 42 "foo" | ^~~ -input.y:1.8-10: previous declaration for FOO +input.y:1.15-19: previous declaration for "foo" 1 | %token FOO 42 "foo" - | ^~~ + | ^~~~~ ]]) AT_CLEANUP -- cgit v1.2.1