From a555b419904c3619f417f9698b9234d9084c65e5 Mon Sep 17 00:00:00 2001 From: Akim Demaille Date: Sun, 12 Apr 2020 08:39:20 +0200 Subject: [PATCH] diagnostics: replace "user token number" by "token code" Yet, don't change the structure identifier to avoid introducing conflicts in Vincent Imbimbo's PR (which, amusingly enough, is about conflicts). * src/symtab.c: here. * tests/diagnostics.at, tests/input.at: Adjust. --- TODO | 16 +--------------- src/symtab.c | 18 +++++++++--------- tests/diagnostics.at | 2 +- tests/input.at | 18 +++++++++--------- 4 files changed, 20 insertions(+), 34 deletions(-) diff --git a/TODO b/TODO index 55e7c996..88ccc743 100644 --- a/TODO +++ b/TODO @@ -5,6 +5,7 @@ - YYERRCODE, YYUNDEF, YYEOF - i18n in Java - symbol.type_get should be kind_get, and it's not documented. +- token code instead of token user number etc. ** User token number, internal symbol number, external token number, etc. There is some confusion over these terms, which is even a problem for @@ -28,21 +29,6 @@ The token numbered as 0. Therefore each time the scanner returns an (external) token number, it must be mapped to the (internal) symbol number. - -*** The code -uses "user token number" in most places. - - if (sym->content->class != token_sym) - complain (&loc, complaint, - _("nonterminals cannot be given an explicit number")); - else if (*user_token_numberp != USER_NUMBER_UNDEFINED - && *user_token_numberp != user_token_number) - complain (&loc, complaint, _("redefining user token number of %s"), - sym->tag); - else if (user_token_number == INT_MAX) - complain (&loc, complaint, _("user token number of %s too large"), - sym->tag); - *** M4 Make it consistent with the rest (it uses "user_number" and "number"). diff --git a/src/symtab.c b/src/symtab.c index b236fc36..d817d7c8 100644 --- a/src/symtab.c +++ b/src/symtab.c @@ -166,9 +166,9 @@ symbol_free (void *ptr) /* If needed, swap first and second so that first has the earliest location (according to location_cmp). - Many symbol features (e.g., user token numbers) are not assigned - during the parsing, but in a second step, via a traversal of the - symbol table sorted on tag. + Many symbol features (e.g., token codes) are not assigned during + parsing, but in a second step, via a traversal of the symbol table + sorted on tag. However, error messages make more sense if we keep the first declaration first. @@ -576,13 +576,13 @@ symbol_user_token_number_set (symbol *sym, int user_token_number, location loc) int *user_token_numberp = &sym->content->user_token_number; if (sym->content->class != token_sym) complain (&loc, complaint, - _("nonterminals cannot be given an explicit number")); + _("nonterminals cannot be given a token code")); else if (*user_token_numberp != USER_NUMBER_UNDEFINED && *user_token_numberp != user_token_number) - complain (&loc, complaint, _("redefining user token number of %s"), + complain (&loc, complaint, _("redefining code of token %s"), sym->tag); else if (user_token_number == INT_MAX) - complain (&loc, complaint, _("user token number of %s too large"), + complain (&loc, complaint, _("code of token %s too large"), sym->tag); else { @@ -739,7 +739,7 @@ complain_user_token_number_redeclared (int num, symbol *first, symbol *second) { symbols_sort (&first, &second); complain (&second->location, complaint, - _("user token number %d redeclaration for %s"), + _("code %d reassigned to token %s"), num, second->tag); subcomplain (&first->location, complaint, _("previous declaration for %s"), @@ -1044,8 +1044,8 @@ symbols_token_translations_init (void) { bool num_256_available_p = true; - /* Find the highest user token number, and whether 256, the POSIX - preferred user token number for the error token, is used. */ + /* Find the highest token code, and whether 256, the POSIX preferred + token code for the error token, is used. */ max_user_token_number = 0; for (int i = 0; i < ntokens; ++i) { diff --git a/tests/diagnostics.at b/tests/diagnostics.at index 0724f88a..df6b0c81 100644 --- a/tests/diagnostics.at +++ b/tests/diagnostics.at @@ -181,7 +181,7 @@ exp: input.y:12.8-10: note: previous declaration 12 | %token foo 123123 | ^~~ -input.y:13.12-17: error: redefining user token number of foo +input.y:13.12-17: error: redefining code of token foo 13 | %token foo 123 | ^~~~~~ input.y:14.8-10: warning: symbol foo redeclared [-Wother] diff --git a/tests/input.at b/tests/input.at index 2250406d..7cf2eccb 100644 --- a/tests/input.at +++ b/tests/input.at @@ -269,10 +269,10 @@ AT_BISON_CHECK([-fcaret input.y], [1], [], [[input.y:1.13-24: error: nonterminals cannot be given a string alias 1 | %nterm expr "expression"; | ^~~~~~~~~~~~ -input.y:2.13-15: error: nonterminals cannot be given an explicit number +input.y:2.13-15: error: nonterminals cannot be given a token code 2 | %nterm term 123; | ^~~ -input.y:3.13-15: error: nonterminals cannot be given an explicit number +input.y:3.13-15: error: nonterminals cannot be given a token code 3 | %nterm fact 124 "factor"; | ^~~ input.y:3.17-24: error: nonterminals cannot be given a string alias @@ -322,7 +322,7 @@ AT_BISON_CHECK([-fcaret input.y], [1], [], input.y:1.8-12: note: previous declaration 1 | %token error 123 | ^~~~~ -input.y:2.14-16: error: redefining user token number of error +input.y:2.14-16: error: redefining code of token error 2 | %token error 124 | ^~~ ]]) @@ -1194,7 +1194,7 @@ AT_BISON_CHECK([-fcaret input.y], [1], [], [[input.y:2.17-21: warning: symbol "foo" used more than once as a literal string [-Wother] 2 | BAR 42 "foo" | ^~~~~ -input.y:2.10-12: error: user token number 42 redeclaration for BAR +input.y:2.10-12: error: code 42 reassigned to token BAR 2 | BAR 42 "foo" | ^~~ input.y:1.15-19: note: previous declaration for "foo" @@ -1544,7 +1544,7 @@ AT_CHECK_REQUIRE(100.0, 63) AT_SETUP([String aliases for character tokens]) # Bison once thought a character token and its alias were different -# symbols with the same user token number. +# symbols with the same code. AT_BISON_OPTION_PUSHDEFS AT_DATA_GRAMMAR([input.y], @@ -1643,9 +1643,9 @@ start: DECIMAL_1 HEXADECIMAL_2; ]]) AT_BISON_CHECK([redecl.y], [1], [], -[[redecl.y:10.10-22: error: user token number 11259375 redeclaration for HEXADECIMAL_1 +[[redecl.y:10.10-22: error: code 11259375 reassigned to token HEXADECIMAL_1 redecl.y:9.8-16: note: previous declaration for DECIMAL_1 -redecl.y:12.10-18: error: user token number 16702650 redeclaration for DECIMAL_2 +redecl.y:12.10-18: error: code 16702650 reassigned to token DECIMAL_2 redecl.y:11.10-22: note: previous declaration for HEXADECIMAL_2 ]]) @@ -1659,9 +1659,9 @@ start: TOO_LARGE_DEC TOO_LARGE_HEX AT_BISON_CHECK([too-large.y], [1], [], [[too-large.y:9.22-42: error: integer out of range: '999999999999999999999' -too-large.y:9.22-42: error: user token number of TOO_LARGE_DEC too large +too-large.y:9.22-42: error: code of token TOO_LARGE_DEC too large too-large.y:10.24-44: error: integer out of range: '0xFFFFFFFFFFFFFFFFFFF' -too-large.y:10.24-44: error: user token number of TOO_LARGE_HEX too large +too-large.y:10.24-44: error: code of token TOO_LARGE_HEX too large ]]) AT_BISON_OPTION_POPDEFS