mirror of
https://git.savannah.gnu.org/git/bison.git
synced 2026-03-09 20:33:03 +00:00
Prefer signed to unsigned integers
This patch contains more fixes to prefer signed to unsigned integer types, as modern tools like 'gcc -fsanitize=undefined' can check for signed integer overflow but not unsigned overflow. * NEWS: Document the API change. * boostrap.conf (gnulib_modules): Add intprops. * data/skeletons/glr.c: Include stddef.h and stdint.h, since this skeleton can assume C99 or later. (YYSIZEMAX): Now signed, and the minimum of SIZE_MAX and PTRDIFF_MAX. (yybool) [!__cplusplus]: Now signed (which is how bool behaves). (YYTRANSLATE): Avoid use of unsigned, and make the macro safe even for values greater than UINT_MAX. (yytnamerr, struct yyGLRState, struct yyGLRStateSet, struct yyGLRStack) (yyaddDeferredAction, yyinitStateSet, yyinitGLRStack) (yyexpandGLRStack, yymarkStackDeleted, yyremoveDeletes) (yyglrShift, yyglrShiftDefer, yy_reduce_print, yydoAction) (yyglrReduce, yysplitStack, yyreportTree, yycompressStack) (yyprocessOneStack, yyreportSyntaxError, yyrecoverSyntaxError) (yyparse, yy_yypstack, yypstack, yypdumpstack): * tests/input.at (Torturing the Scanner): Prefer ptrdiff_t to size_t. * data/skeletons/c++.m4 (b4_yytranslate_define): * src/AnnotationList.c (AnnotationList__computePredecessorAnnotations): * src/AnnotationList.h (AnnotationIndex): * src/InadequacyList.h (InadequacyListNodeCount): * src/closure.c (closure_new): * src/complain.c (error_message, complains, complain_indent) (complain_args, duplicate_directive, duplicate_rule_directive): * src/gram.c (nritems, ritem_print, grammar_dump): * src/ielr.c (ielr_compute_ritem_sees_lookahead_set) (ielr_item_has_lookahead, ielr_compute_annotation_lists) (ielr_compute_lookaheads): * src/location.c (columns, boundary_print, location_print): * src/muscle-tab.c (muscle_percent_define_insert) (muscle_percent_define_check_values): * src/output.c (prepare_rules, prepare_actions): * src/parse-gram.y (id, handle_require): * src/reader.c (record_merge_function_type, packgram): * src/reduce.c (nuseless_productions, nuseless_nonterminals) (inaccessable_symbols): * src/relation.c (relation_print): * src/scan-code.l (variant, variant_table_size, variant_count) (variant_add, get_at_spec, show_sub_message, show_sub_messages) (parse_ref): * src/scan-gram.l (<SC_ESCAPED_STRING,SC_ESCAPED_CHARACTER>) (scan_integer, convert_ucn_to_byte, handle_syncline): * src/scan-skel.l (at_complain): * src/symtab.c (complain_symbol_redeclared) (complain_semantic_type_redeclared, complain_class_redeclared) (symbol_class_set, complain_user_token_number_redeclared): * src/tables.c (conflict_tos, conflrow, conflict_table) (conflict_list, save_row, pack_vector): * tests/local.at (AT_YYLEX_DEFINE(c)): Prefer signed to unsigned integer. * data/skeletons/lalr1.cc (yy_lac_check_): * tests/actions.at (_AT_CHECK_PRINTER_AND_DESTRUCTOR): * tests/local.at (AT_YYLEX_DEFINE(c)): Omit now-unnecessary casts. * data/skeletons/location.cc (b4_location_define): * doc/bison.texi (Mfcalc Lexer, C++ position, C++ location): Prefer int to unsigned for line and column numbers. Change example to abort explicitly on memory exhaustion, and fix an off-by-one bug that led to undefined behavior. * data/skeletons/stack.hh (stack::operator[]): Also allow ptrdiff_t indexes. (stack::pop, slice::slice, slice::operator[]): Index arg is now ptrdiff_t, not int. (stack::ssize): New method. (slice::range_): Now ptrdiff_t, not int. * data/skeletons/yacc.c (b4_state_num_type): Remove. All uses replaced by b4_int_type. (YY_CONVERT_INT_BEGIN, YY_CONVERT_INT_END): New macros. (yylac, yyparse): Use them around conversions that -Wconversion would give false alarms about. Omit unnecessary casts. (yy_stack_print): Use int rather than unsigned, and omit a cast that doesn’t seem to be needed here any more. * examples/c++/variant.yy (yylex): * examples/c++/variant-11.yy (yylex): Omit no-longer-needed conversions to unsigned. * src/InadequacyList.c (InadequacyList__new_conflict): Don’t assume *node_count is unsigned. * src/output.c (muscle_insert_unsigned_table): Remove; no longer used.
This commit is contained in:
@@ -269,7 +269,7 @@ AnnotationList__computePredecessorAnnotations (
|
||||
if (item_number_is_rule_number (ritem[s->items[self_item]
|
||||
- 2]))
|
||||
{
|
||||
unsigned rulei;
|
||||
int rulei;
|
||||
for (rulei = s->items[self_item];
|
||||
!item_number_is_rule_number (ritem[rulei]);
|
||||
++rulei)
|
||||
|
||||
@@ -25,7 +25,7 @@
|
||||
# include "InadequacyList.h"
|
||||
# include "state.h"
|
||||
|
||||
typedef unsigned AnnotationIndex;
|
||||
typedef int AnnotationIndex;
|
||||
|
||||
/**
|
||||
* A node in a list of annotations on a particular LR(0) state. Each
|
||||
|
||||
@@ -22,6 +22,8 @@
|
||||
|
||||
#include "InadequacyList.h"
|
||||
|
||||
#include <intprops.h>
|
||||
|
||||
ContributionIndex const ContributionIndex__none = -1;
|
||||
ContributionIndex const ContributionIndex__error_action = -2;
|
||||
|
||||
@@ -31,8 +33,9 @@ InadequacyList__new_conflict (state *manifesting_state, symbol *token,
|
||||
InadequacyListNodeCount *node_count)
|
||||
{
|
||||
InadequacyList *result = xmalloc (sizeof *result);
|
||||
result->id = (*node_count)++;
|
||||
aver (*node_count != 0);
|
||||
result->id = *node_count;
|
||||
if (INT_ADD_WRAPV (*node_count, 1, node_count))
|
||||
aver (false);
|
||||
result->next = NULL;
|
||||
result->manifestingState = manifesting_state;
|
||||
result->contributionCount = bitset_count (actions);
|
||||
|
||||
@@ -27,11 +27,8 @@
|
||||
|
||||
/**
|
||||
* A unique ID assigned to every \c InadequacyList node.
|
||||
*
|
||||
* This must remain unsigned so that the overflow check in
|
||||
* \c InadequacyList__new_conflict works properly.
|
||||
*/
|
||||
typedef unsigned long long InadequacyListNodeCount;
|
||||
typedef long long InadequacyListNodeCount;
|
||||
|
||||
/**
|
||||
* For a conflict, each rule in the grammar can have at most one contributing
|
||||
|
||||
@@ -170,7 +170,7 @@ set_fderives (void)
|
||||
|
||||
|
||||
void
|
||||
closure_new (unsigned n)
|
||||
closure_new (int n)
|
||||
{
|
||||
itemset = xnmalloc (n, sizeof *itemset);
|
||||
|
||||
|
||||
@@ -27,7 +27,7 @@
|
||||
data so that closure can be called. n is the number of elements to
|
||||
allocate for itemset. */
|
||||
|
||||
void closure_new (unsigned n);
|
||||
void closure_new (int n);
|
||||
|
||||
|
||||
/* Given the kernel (aka core) of a state (a sorted vector of item numbers
|
||||
|
||||
@@ -417,10 +417,10 @@ warnings_print_categories (warnings warn_flags, FILE *out)
|
||||
*/
|
||||
static
|
||||
void
|
||||
error_message (const location *loc, unsigned *indent, warnings flags,
|
||||
error_message (const location *loc, int *indent, warnings flags,
|
||||
severity sever, const char *message, va_list args)
|
||||
{
|
||||
unsigned pos = 0;
|
||||
int pos = 0;
|
||||
|
||||
if (loc)
|
||||
pos += location_print (*loc, stderr);
|
||||
@@ -470,7 +470,7 @@ error_message (const location *loc, unsigned *indent, warnings flags,
|
||||
/** Raise a complaint (fatal error, error or just warning). */
|
||||
|
||||
static void
|
||||
complains (const location *loc, unsigned *indent, warnings flags,
|
||||
complains (const location *loc, int *indent, warnings flags,
|
||||
const char *message, va_list args)
|
||||
{
|
||||
severity s = warning_severity (flags);
|
||||
@@ -498,7 +498,7 @@ complain (location const *loc, warnings flags, const char *message, ...)
|
||||
}
|
||||
|
||||
void
|
||||
complain_indent (location const *loc, warnings flags, unsigned *indent,
|
||||
complain_indent (location const *loc, warnings flags, int *indent,
|
||||
const char *message, ...)
|
||||
{
|
||||
va_list args;
|
||||
@@ -508,7 +508,7 @@ complain_indent (location const *loc, warnings flags, unsigned *indent,
|
||||
}
|
||||
|
||||
void
|
||||
complain_args (location const *loc, warnings w, unsigned *indent,
|
||||
complain_args (location const *loc, warnings w, int *indent,
|
||||
int argc, char *argv[])
|
||||
{
|
||||
switch (argc)
|
||||
@@ -563,7 +563,7 @@ void
|
||||
duplicate_directive (char const *directive,
|
||||
location first, location second)
|
||||
{
|
||||
unsigned i = 0;
|
||||
int i = 0;
|
||||
if (feature_flag & feature_caret)
|
||||
complain_indent (&second, Wother, &i, _("duplicate directive"));
|
||||
else
|
||||
@@ -577,7 +577,7 @@ void
|
||||
duplicate_rule_directive (char const *directive,
|
||||
location first, location second)
|
||||
{
|
||||
unsigned i = 0;
|
||||
int i = 0;
|
||||
complain_indent (&second, complaint, &i,
|
||||
_("only one %s allowed per rule"), directive);
|
||||
i += SUB_INDENT;
|
||||
|
||||
@@ -133,11 +133,11 @@ void complain (location const *loc, warnings flags, char const *message, ...)
|
||||
__attribute__ ((__format__ (__printf__, 3, 4)));
|
||||
|
||||
/** Likewise, but with an \a argc/argv interface. */
|
||||
void complain_args (location const *loc, warnings w, unsigned *indent,
|
||||
void complain_args (location const *loc, warnings w, int *indent,
|
||||
int argc, char *arg[]);
|
||||
|
||||
/** Make a complaint with location and some indentation. */
|
||||
void complain_indent (location const *loc, warnings flags, unsigned *indent,
|
||||
void complain_indent (location const *loc, warnings flags, int *indent,
|
||||
char const *message, ...)
|
||||
__attribute__ ((__format__ (__printf__, 4, 5)));
|
||||
|
||||
|
||||
@@ -32,7 +32,7 @@
|
||||
/* Comments for these variables are in gram.h. */
|
||||
|
||||
item_number *ritem = NULL;
|
||||
unsigned nritems = 0;
|
||||
int nritems = 0;
|
||||
|
||||
rule *rules = NULL;
|
||||
rule_number nrules = 0;
|
||||
@@ -165,7 +165,7 @@ void
|
||||
ritem_print (FILE *out)
|
||||
{
|
||||
fputs ("RITEM\n", out);
|
||||
for (unsigned i = 0; i < nritems; ++i)
|
||||
for (int i = 0; i < nritems; ++i)
|
||||
if (ritem[i] >= 0)
|
||||
fprintf (out, " %s", symbols[ritem[i]]->tag);
|
||||
else
|
||||
@@ -280,8 +280,8 @@ grammar_dump (FILE *out, const char *title)
|
||||
for (rule_number i = 0; i < nrules + nuseless_productions; ++i)
|
||||
{
|
||||
rule const *rule_i = &rules[i];
|
||||
unsigned const rhs_itemno = rule_i->rhs - ritem;
|
||||
unsigned length = rule_rhs_length (rule_i);
|
||||
int const rhs_itemno = rule_i->rhs - ritem;
|
||||
int length = rule_rhs_length (rule_i);
|
||||
aver (item_number_as_rule_number (rule_i->rhs[length] == i));
|
||||
fprintf (out, "%3d (%2d, %2d, %2s, %2s) %2d -> (%2u-%2u)",
|
||||
i,
|
||||
|
||||
@@ -115,7 +115,7 @@ extern int nvars;
|
||||
typedef int item_number;
|
||||
# define ITEM_NUMBER_MAX INT_MAX
|
||||
extern item_number *ritem;
|
||||
extern unsigned nritems;
|
||||
extern int nritems;
|
||||
|
||||
/* There is weird relationship between OT1H item_number and OTOH
|
||||
symbol_number and rule_number: we store the latter in
|
||||
|
||||
@@ -78,7 +78,7 @@ static bitset
|
||||
ielr_compute_ritem_sees_lookahead_set (void)
|
||||
{
|
||||
bitset result = bitset_create (nritems, BITSET_FIXED);
|
||||
unsigned i = nritems-1;
|
||||
int i = nritems-1;
|
||||
while (0 < i)
|
||||
{
|
||||
--i;
|
||||
@@ -418,7 +418,7 @@ ielr_item_has_lookahead (state *s, symbol_number lhs, size_t item,
|
||||
top-level invocation), go get it. */
|
||||
if (!lhs)
|
||||
{
|
||||
unsigned i;
|
||||
int i;
|
||||
for (i = s->items[item];
|
||||
!item_number_is_rule_number (ritem[i]);
|
||||
++i)
|
||||
@@ -496,7 +496,7 @@ ielr_compute_annotation_lists (bitsetv follow_kernel_items,
|
||||
AnnotationIndex *annotation_counts =
|
||||
xnmalloc (nstates, sizeof *annotation_counts);
|
||||
ContributionIndex max_contributions = 0;
|
||||
unsigned total_annotations = 0;
|
||||
int total_annotations = 0;
|
||||
|
||||
*inadequacy_listsp = xnmalloc (nstates, sizeof **inadequacy_listsp);
|
||||
*annotation_listsp = xnmalloc (nstates, sizeof **annotation_listsp);
|
||||
@@ -633,7 +633,7 @@ ielr_compute_lookaheads (bitsetv follow_kernel_items, bitsetv always_follows,
|
||||
{
|
||||
if (item_number_is_rule_number (ritem[t->items[t_item] - 2]))
|
||||
{
|
||||
unsigned rule_item;
|
||||
int rule_item;
|
||||
for (rule_item = t->items[t_item];
|
||||
!item_number_is_rule_number (ritem[rule_item]);
|
||||
++rule_item)
|
||||
|
||||
@@ -60,8 +60,8 @@ columns (void)
|
||||
int res = 80;
|
||||
if (cp && *cp)
|
||||
{
|
||||
unsigned long ul = strtoul (cp, NULL, 10);
|
||||
res = ul < INT_MAX ? ul : INT_MAX;
|
||||
long l = strtol (cp, NULL, 10);
|
||||
res = 0 <= l && l <= INT_MAX ? l : INT_MAX;
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -149,7 +149,7 @@ location_compute (location *loc, boundary *cur, char const *token, size_t size)
|
||||
complain (loc, Wother, _("byte number overflow"));
|
||||
}
|
||||
|
||||
static unsigned
|
||||
static int
|
||||
boundary_print (boundary const *b, FILE *out)
|
||||
{
|
||||
return fprintf (out, "%s:%d.%d@%d",
|
||||
@@ -157,10 +157,10 @@ boundary_print (boundary const *b, FILE *out)
|
||||
b->line, b->column, b->byte);
|
||||
}
|
||||
|
||||
unsigned
|
||||
int
|
||||
location_print (location loc, FILE *out)
|
||||
{
|
||||
unsigned res = 0;
|
||||
int res = 0;
|
||||
if (trace_flag & trace_locations)
|
||||
{
|
||||
res += boundary_print (&loc.start, out);
|
||||
|
||||
@@ -112,7 +112,7 @@ void location_compute (location *loc,
|
||||
/* Print location to file.
|
||||
Return number of actually printed characters.
|
||||
Warning: uses quotearg's slot 3. */
|
||||
unsigned location_print (location loc, FILE *out);
|
||||
int location_print (location loc, FILE *out);
|
||||
|
||||
/* Prepare the use of location_caret. */
|
||||
void caret_init (void);
|
||||
|
||||
@@ -525,7 +525,7 @@ muscle_percent_define_insert (char const *var, location variable_loc,
|
||||
= atoi (muscle_find_const (how_name));
|
||||
if (how_old == MUSCLE_PERCENT_DEFINE_F)
|
||||
goto end;
|
||||
unsigned i = 0;
|
||||
int i = 0;
|
||||
/* If assigning the same value, make it a warning. */
|
||||
warnings warn = STREQ (value, current_value) ? Wother : complaint;
|
||||
complain_indent (&variable_loc, warn, &i,
|
||||
@@ -739,7 +739,7 @@ muscle_percent_define_check_values (char const * const *values)
|
||||
if (!*values)
|
||||
{
|
||||
location loc = muscle_percent_define_get_loc (*variablep);
|
||||
unsigned i = 0;
|
||||
int i = 0;
|
||||
complain_indent (&loc, complaint, &i,
|
||||
_("invalid value for %%define variable %s: %s"),
|
||||
quote (*variablep), quote_n (1, value));
|
||||
|
||||
23
src/output.c
23
src/output.c
@@ -91,7 +91,6 @@ Name (char const *name, Type *table_data, Type first, \
|
||||
MUSCLE_INSERT_LONG_INT (obstack_finish0 (&format_obstack), lmax); \
|
||||
}
|
||||
|
||||
GENERATE_MUSCLE_INSERT_TABLE (muscle_insert_unsigned_table, unsigned)
|
||||
GENERATE_MUSCLE_INSERT_TABLE (muscle_insert_int_table, int)
|
||||
GENERATE_MUSCLE_INSERT_TABLE (muscle_insert_base_table, base_number)
|
||||
GENERATE_MUSCLE_INSERT_TABLE (muscle_insert_rule_number_table, rule_number)
|
||||
@@ -214,17 +213,17 @@ prepare_symbols (void)
|
||||
static void
|
||||
prepare_rules (void)
|
||||
{
|
||||
unsigned *prhs = xnmalloc (nrules, sizeof *prhs);
|
||||
int *prhs = xnmalloc (nrules, sizeof *prhs);
|
||||
item_number *rhs = xnmalloc (nritems, sizeof *rhs);
|
||||
unsigned *rline = xnmalloc (nrules, sizeof *rline);
|
||||
int *rline = xnmalloc (nrules, sizeof *rline);
|
||||
symbol_number *r1 = xnmalloc (nrules, sizeof *r1);
|
||||
unsigned *r2 = xnmalloc (nrules, sizeof *r2);
|
||||
int *r2 = xnmalloc (nrules, sizeof *r2);
|
||||
int *dprec = xnmalloc (nrules, sizeof *dprec);
|
||||
int *merger = xnmalloc (nrules, sizeof *merger);
|
||||
int *immediate = xnmalloc (nrules, sizeof *immediate);
|
||||
|
||||
/* Index in RHS. */
|
||||
unsigned i = 0;
|
||||
int i = 0;
|
||||
for (rule_number r = 0; r < nrules; ++r)
|
||||
{
|
||||
/* Index of rule R in RHS. */
|
||||
@@ -251,10 +250,10 @@ prepare_rules (void)
|
||||
aver (i == nritems);
|
||||
|
||||
muscle_insert_item_number_table ("rhs", rhs, ritem[0], 1, nritems);
|
||||
muscle_insert_unsigned_table ("prhs", prhs, 0, 0, nrules);
|
||||
muscle_insert_unsigned_table ("rline", rline, 0, 0, nrules);
|
||||
muscle_insert_int_table ("prhs", prhs, 0, 0, nrules);
|
||||
muscle_insert_int_table ("rline", rline, 0, 0, nrules);
|
||||
muscle_insert_symbol_number_table ("r1", r1, 0, 0, nrules);
|
||||
muscle_insert_unsigned_table ("r2", r2, 0, 0, nrules);
|
||||
muscle_insert_int_table ("r2", r2, 0, 0, nrules);
|
||||
muscle_insert_int_table ("dprec", dprec, 0, 0, nrules);
|
||||
muscle_insert_int_table ("merger", merger, 0, 0, nrules);
|
||||
muscle_insert_int_table ("immediate", immediate, 0, 0, nrules);
|
||||
@@ -542,10 +541,10 @@ prepare_actions (void)
|
||||
parser, so we could avoid accidents by not writing them out in
|
||||
that case. Nevertheless, it seems even better to be able to use
|
||||
the GLR skeletons even without the non-deterministic tables. */
|
||||
muscle_insert_unsigned_table ("conflict_list_heads", conflict_table,
|
||||
conflict_table[0], 1, high + 1);
|
||||
muscle_insert_unsigned_table ("conflicting_rules", conflict_list,
|
||||
0, 1, conflict_list_cnt);
|
||||
muscle_insert_int_table ("conflict_list_heads", conflict_table,
|
||||
conflict_table[0], 1, high + 1);
|
||||
muscle_insert_int_table ("conflicting_rules", conflict_list,
|
||||
0, 1, conflict_list_cnt);
|
||||
}
|
||||
|
||||
|
||||
|
||||
@@ -743,7 +743,7 @@ id:
|
||||
}
|
||||
if (muscle_percent_define_ifdef (var))
|
||||
{
|
||||
unsigned indent = 0;
|
||||
int indent = 0;
|
||||
complain_indent (&@1, complaint, &indent,
|
||||
_("character literals cannot be used together"
|
||||
" with %s"), var);
|
||||
@@ -981,7 +981,7 @@ handle_require (location const *loc, char const *version)
|
||||
is the same as "3.0". */
|
||||
errno = 0;
|
||||
char* cp = NULL;
|
||||
unsigned long major = strtoul (version, &cp, 10);
|
||||
long major = strtol (version, &cp, 10);
|
||||
if (errno || *cp != '.')
|
||||
{
|
||||
complain (loc, complaint, _("invalid version requirement: %s"),
|
||||
@@ -989,7 +989,7 @@ handle_require (location const *loc, char const *version)
|
||||
return;
|
||||
}
|
||||
++cp;
|
||||
unsigned long minor = strtoul (cp, NULL, 10);
|
||||
long minor = strtol (cp, NULL, 10);
|
||||
if (errno)
|
||||
{
|
||||
complain (loc, complaint, _("invalid version requirement: %s"),
|
||||
|
||||
@@ -124,7 +124,7 @@ record_merge_function_type (int merger, uniqstr type, location declaration_loc)
|
||||
aver (merge_function != NULL && merger_find == merger);
|
||||
if (merge_function->type != NULL && !UNIQSTR_EQ (merge_function->type, type))
|
||||
{
|
||||
unsigned indent = 0;
|
||||
int indent = 0;
|
||||
complain_indent (&declaration_loc, complaint, &indent,
|
||||
_("result type clash on merge function %s: "
|
||||
"<%s> != <%s>"),
|
||||
@@ -611,7 +611,7 @@ grammar_current_rule_expect_rr (int count, location loc)
|
||||
static void
|
||||
packgram (void)
|
||||
{
|
||||
unsigned itemno = 0;
|
||||
int itemno = 0;
|
||||
ritem = xnmalloc (nritems + 1, sizeof *ritem);
|
||||
/* This sentinel is used by build_relations in gram.c. */
|
||||
*ritem++ = 0;
|
||||
|
||||
@@ -52,8 +52,8 @@ static bitset V;
|
||||
'useless', but no warning should be issued). */
|
||||
static bitset V1;
|
||||
|
||||
unsigned nuseless_productions;
|
||||
unsigned nuseless_nonterminals;
|
||||
int nuseless_productions;
|
||||
int nuseless_nonterminals;
|
||||
|
||||
#define bitset_swap(Lhs, Rhs) \
|
||||
do { \
|
||||
@@ -195,10 +195,10 @@ inaccessable_symbols (void)
|
||||
bitset_free (P);
|
||||
P = Pp;
|
||||
|
||||
unsigned nuseful_productions = bitset_count (P);
|
||||
int nuseful_productions = bitset_count (P);
|
||||
nuseless_productions = nrules - nuseful_productions;
|
||||
|
||||
unsigned nuseful_nonterminals = 0;
|
||||
int nuseful_nonterminals = 0;
|
||||
for (symbol_number i = ntokens; i < nsyms; ++i)
|
||||
nuseful_nonterminals += bitset_test (V, i);
|
||||
nuseless_nonterminals = nvars - nuseful_nonterminals;
|
||||
|
||||
@@ -36,7 +36,7 @@ void reduce_free (void);
|
||||
* reduce_grammar. Size nvars + nuseless_nonterminals. */
|
||||
extern symbol_number *nterm_map;
|
||||
|
||||
extern unsigned nuseless_nonterminals;
|
||||
extern unsigned nuseless_productions;
|
||||
extern int nuseless_nonterminals;
|
||||
extern int nuseless_productions;
|
||||
|
||||
#endif /* !REDUCE_H_ */
|
||||
|
||||
@@ -33,14 +33,14 @@ relation_print (const char *title,
|
||||
{
|
||||
if (title)
|
||||
fprintf (out, "%s:\n", title);
|
||||
for (size_t i = 0; i < size; ++i)
|
||||
for (relation_node i = 0; i < size; ++i)
|
||||
if (r[i])
|
||||
{
|
||||
fputs (" ", out);
|
||||
if (print)
|
||||
print (i, out);
|
||||
else
|
||||
fprintf (out, "%3lu", (unsigned long) i);
|
||||
fprintf (out, "%3ld", (long) i);
|
||||
fputc (':', out);
|
||||
for (relation_node j = 0; r[i][j] != END_NODE; ++j)
|
||||
{
|
||||
@@ -48,7 +48,7 @@ relation_print (const char *title,
|
||||
if (print)
|
||||
print (r[i][j], out);
|
||||
else
|
||||
fprintf (out, "%3lu", (unsigned long) r[i][j]);
|
||||
fprintf (out, "%3ld", (long) r[i][j]);
|
||||
}
|
||||
fputc ('\n', out);
|
||||
}
|
||||
|
||||
@@ -223,7 +223,7 @@ contains_dot_or_dash (const char* p)
|
||||
typedef struct
|
||||
{
|
||||
/* Index in symbol list. */
|
||||
unsigned symbol_index;
|
||||
int symbol_index;
|
||||
|
||||
/* Matched symbol id and loc. */
|
||||
uniqstr id;
|
||||
@@ -250,8 +250,8 @@ typedef struct
|
||||
#define VARIANT_NOT_VISIBLE_FROM_MIDRULE (1 << 2)
|
||||
|
||||
static variant *variant_table = NULL;
|
||||
static unsigned variant_table_size = 0;
|
||||
static unsigned variant_count = 0;
|
||||
static int variant_table_size = 0;
|
||||
static int variant_count = 0;
|
||||
|
||||
static variant *
|
||||
variant_table_grow (void)
|
||||
@@ -286,7 +286,7 @@ find_prefix_end (char const *prefix, char const *cp, char const *end)
|
||||
}
|
||||
|
||||
static variant *
|
||||
variant_add (uniqstr id, location id_loc, unsigned symbol_index,
|
||||
variant_add (uniqstr id, location id_loc, int symbol_index,
|
||||
char const *cp, char const *cp_end, bool explicit_bracketing)
|
||||
{
|
||||
char const *prefix_end = find_prefix_end (id, cp, cp_end);
|
||||
@@ -307,7 +307,7 @@ variant_add (uniqstr id, location id_loc, unsigned symbol_index,
|
||||
}
|
||||
|
||||
static const char *
|
||||
get_at_spec(unsigned symbol_index)
|
||||
get_at_spec(int symbol_index)
|
||||
{
|
||||
static char at_buf[20];
|
||||
if (symbol_index == 0)
|
||||
@@ -321,7 +321,7 @@ static void
|
||||
show_sub_message (warnings warning,
|
||||
const char* cp, bool explicit_bracketing,
|
||||
int midrule_rhs_index, char dollar_or_at,
|
||||
unsigned indent, const variant *var)
|
||||
int indent, const variant *var)
|
||||
{
|
||||
const char *at_spec = get_at_spec (var->symbol_index);
|
||||
|
||||
@@ -385,9 +385,9 @@ static void
|
||||
show_sub_messages (warnings warning,
|
||||
const char* cp, bool explicit_bracketing,
|
||||
int midrule_rhs_index, char dollar_or_at,
|
||||
unsigned indent)
|
||||
int indent)
|
||||
{
|
||||
for (unsigned i = 0; i < variant_count; ++i)
|
||||
for (int i = 0; i < variant_count; ++i)
|
||||
show_sub_message (warning | silent,
|
||||
cp, explicit_bracketing,
|
||||
midrule_rhs_index, dollar_or_at,
|
||||
@@ -437,7 +437,7 @@ parse_ref (char *cp, symbol_list *rule, int rule_length,
|
||||
|
||||
/* Add all relevant variants. */
|
||||
{
|
||||
unsigned symbol_index;
|
||||
int symbol_index;
|
||||
symbol_list *l;
|
||||
variant_count = 0;
|
||||
for (symbol_index = 0, l = rule; !symbol_list_null (l);
|
||||
@@ -459,12 +459,12 @@ parse_ref (char *cp, symbol_list *rule, int rule_length,
|
||||
}
|
||||
|
||||
/* Check errors. */
|
||||
unsigned valid_variants = 0;
|
||||
unsigned valid_variant_index = 0;
|
||||
for (unsigned i = 0; i < variant_count; ++i)
|
||||
int valid_variants = 0;
|
||||
int valid_variant_index = 0;
|
||||
for (int i = 0; i < variant_count; ++i)
|
||||
{
|
||||
variant *var = &variant_table[i];
|
||||
unsigned symbol_index = var->symbol_index;
|
||||
int symbol_index = var->symbol_index;
|
||||
|
||||
/* Check visibility from midrule actions. */
|
||||
if (midrule_rhs_index != 0
|
||||
@@ -490,9 +490,9 @@ parse_ref (char *cp, symbol_list *rule, int rule_length,
|
||||
{
|
||||
case 0:
|
||||
{
|
||||
unsigned len = (explicit_bracketing || !ref_tail_fields) ?
|
||||
int len = (explicit_bracketing || !ref_tail_fields) ?
|
||||
cp_end - cp : ref_tail_fields - cp;
|
||||
unsigned indent = 0;
|
||||
int indent = 0;
|
||||
|
||||
complain_indent (text_loc, complaint, &indent,
|
||||
_("invalid reference: %s"), quote (text));
|
||||
@@ -525,7 +525,7 @@ parse_ref (char *cp, symbol_list *rule, int rule_length,
|
||||
}
|
||||
case 1:
|
||||
{
|
||||
unsigned indent = 0;
|
||||
int indent = 0;
|
||||
if (variant_count > 1)
|
||||
{
|
||||
complain_indent (text_loc, Wother, &indent,
|
||||
@@ -535,7 +535,7 @@ parse_ref (char *cp, symbol_list *rule, int rule_length,
|
||||
dollar_or_at, indent + SUB_INDENT);
|
||||
}
|
||||
{
|
||||
unsigned symbol_index =
|
||||
int symbol_index =
|
||||
variant_table[valid_variant_index].symbol_index;
|
||||
return (symbol_index == midrule_rhs_index) ? LHS_REF : symbol_index;
|
||||
}
|
||||
@@ -543,7 +543,7 @@ parse_ref (char *cp, symbol_list *rule, int rule_length,
|
||||
case 2:
|
||||
default:
|
||||
{
|
||||
unsigned indent = 0;
|
||||
int indent = 0;
|
||||
complain_indent (text_loc, complaint, &indent,
|
||||
_("ambiguous reference: %s"), quote (text));
|
||||
show_sub_messages (complaint,
|
||||
|
||||
@@ -97,7 +97,7 @@ gram_scanner_last_string_free (void)
|
||||
}
|
||||
|
||||
static void handle_syncline (char *, location);
|
||||
static unsigned long scan_integer (char const *p, int base, location loc);
|
||||
static int scan_integer (char const *p, int base, location loc);
|
||||
static int convert_ucn_to_byte (char const *hex_text);
|
||||
static void unexpected_eof (boundary, char const *);
|
||||
static void unexpected_newline (boundary, char const *);
|
||||
@@ -600,22 +600,22 @@ eqopt ({sp}=)?
|
||||
{
|
||||
\\[0-7]{1,3} {
|
||||
verify (UCHAR_MAX < ULONG_MAX);
|
||||
unsigned long c = strtoul (yytext + 1, NULL, 8);
|
||||
if (!c || UCHAR_MAX < c)
|
||||
long c = strtol (yytext + 1, NULL, 8);
|
||||
if (0 < c && c <= UCHAR_MAX)
|
||||
obstack_1grow (&obstack_for_string, c);
|
||||
else
|
||||
complain (loc, complaint, _("invalid number after \\-escape: %s"),
|
||||
yytext+1);
|
||||
else
|
||||
obstack_1grow (&obstack_for_string, c);
|
||||
}
|
||||
|
||||
\\x[0-9abcdefABCDEF]+ {
|
||||
verify (UCHAR_MAX < ULONG_MAX);
|
||||
unsigned long c = strtoul (yytext + 2, NULL, 16);
|
||||
if (!c || UCHAR_MAX < c)
|
||||
long c = strtol (yytext + 2, NULL, 16);
|
||||
if (0 < c && c <= UCHAR_MAX)
|
||||
obstack_1grow (&obstack_for_string, c);
|
||||
else
|
||||
complain (loc, complaint, _("invalid number after \\-escape: %s"),
|
||||
yytext+1);
|
||||
else
|
||||
obstack_1grow (&obstack_for_string, c);
|
||||
}
|
||||
|
||||
\\a obstack_1grow (&obstack_for_string, '\a');
|
||||
@@ -810,7 +810,7 @@ eqopt ({sp}=)?
|
||||
| Scan NUMBER for a base-BASE integer at location LOC. |
|
||||
`------------------------------------------------------*/
|
||||
|
||||
static unsigned long
|
||||
static int
|
||||
scan_integer (char const *number, int base, location loc)
|
||||
{
|
||||
verify (INT_MAX < ULONG_MAX);
|
||||
@@ -818,9 +818,9 @@ scan_integer (char const *number, int base, location loc)
|
||||
complain (&loc, Wyacc,
|
||||
_("POSIX Yacc does not support hexadecimal literals"));
|
||||
|
||||
unsigned long num = strtoul (number, NULL, base);
|
||||
long num = strtol (number, NULL, base);
|
||||
|
||||
if (INT_MAX < num)
|
||||
if (! (0 <= num && num <= INT_MAX))
|
||||
{
|
||||
complain (&loc, complaint, _("integer out of range: %s"),
|
||||
quote (number));
|
||||
@@ -841,7 +841,7 @@ static int
|
||||
convert_ucn_to_byte (char const *ucn)
|
||||
{
|
||||
verify (UCHAR_MAX <= INT_MAX);
|
||||
unsigned long code = strtoul (ucn + 2, NULL, 16);
|
||||
long code = strtol (ucn + 2, NULL, 16);
|
||||
|
||||
/* FIXME: Currently we assume Unicode-compatible unibyte characters
|
||||
on ASCII hosts (i.e., Latin-1 on hosts with 8-bit bytes). On
|
||||
@@ -849,7 +849,7 @@ convert_ucn_to_byte (char const *ucn)
|
||||
These limitations should be removed once we add support for
|
||||
multibyte characters. */
|
||||
|
||||
if (UCHAR_MAX < code)
|
||||
if (! (0 <= code && code <= UCHAR_MAX))
|
||||
return -1;
|
||||
|
||||
#if ! ('$' == 0x24 && '@' == 0x40 && '`' == 0x60 && '~' == 0x7e)
|
||||
@@ -896,8 +896,8 @@ static void
|
||||
handle_syncline (char *args, location loc)
|
||||
{
|
||||
char *file;
|
||||
unsigned long lineno = strtoul (args, &file, 10);
|
||||
if (INT_MAX <= lineno)
|
||||
long lineno = strtol (args, &file, 10);
|
||||
if (! (0 <= lineno && lineno <= INT_MAX))
|
||||
{
|
||||
complain (&loc, Wother, _("line number overflow"));
|
||||
lineno = INT_MAX;
|
||||
|
||||
@@ -209,7 +209,7 @@ at_basename (int argc, char *argv[], char **out_namep, int *out_linenop)
|
||||
static void
|
||||
at_complain (int argc, char *argv[], char **out_namep, int *out_linenop)
|
||||
{
|
||||
static unsigned indent;
|
||||
static int indent;
|
||||
warnings w = flag (argv[1]);
|
||||
location loc;
|
||||
location *locp = NULL;
|
||||
|
||||
10
src/symtab.c
10
src/symtab.c
@@ -279,7 +279,7 @@ static void
|
||||
complain_symbol_redeclared (symbol *s, const char *what, location first,
|
||||
location second)
|
||||
{
|
||||
unsigned i = 0;
|
||||
int i = 0;
|
||||
locations_sort (&first, &second);
|
||||
complain_indent (&second, complaint, &i,
|
||||
_("%s redeclaration for %s"), what, s->tag);
|
||||
@@ -292,7 +292,7 @@ static void
|
||||
complain_semantic_type_redeclared (semantic_type *s, const char *what, location first,
|
||||
location second)
|
||||
{
|
||||
unsigned i = 0;
|
||||
int i = 0;
|
||||
locations_sort (&first, &second);
|
||||
complain_indent (&second, complaint, &i,
|
||||
_("%s redeclaration for <%s>"), what, s->tag);
|
||||
@@ -304,7 +304,7 @@ complain_semantic_type_redeclared (semantic_type *s, const char *what, location
|
||||
static void
|
||||
complain_class_redeclared (symbol *sym, symbol_class class, location second)
|
||||
{
|
||||
unsigned i = 0;
|
||||
int i = 0;
|
||||
complain_indent (&second, complaint, &i,
|
||||
class == token_sym
|
||||
? _("symbol %s redeclared as a token")
|
||||
@@ -463,7 +463,7 @@ symbol_class_set (symbol *sym, symbol_class class, location loc, bool declaring)
|
||||
{
|
||||
if (s->status == declared)
|
||||
{
|
||||
unsigned i = 0;
|
||||
int i = 0;
|
||||
complain_indent (&loc, Wother, &i,
|
||||
_("symbol %s redeclared"), sym->tag);
|
||||
i += SUB_INDENT;
|
||||
@@ -668,7 +668,7 @@ symbol_pack_processor (void *this, void *null ATTRIBUTE_UNUSED)
|
||||
static void
|
||||
complain_user_token_number_redeclared (int num, symbol *first, symbol *second)
|
||||
{
|
||||
unsigned i = 0;
|
||||
int i = 0;
|
||||
symbols_sort (&first, &second);
|
||||
complain_indent (&second->location, complaint, &i,
|
||||
_("user token number %d redeclaration for %s"),
|
||||
|
||||
12
src/tables.c
12
src/tables.c
@@ -84,7 +84,7 @@ int nvectors;
|
||||
|
||||
static base_number **froms;
|
||||
static base_number **tos;
|
||||
static unsigned **conflict_tos;
|
||||
static int **conflict_tos;
|
||||
static size_t *tally;
|
||||
static base_number *width;
|
||||
|
||||
@@ -115,9 +115,9 @@ base_number base_ninf = 0;
|
||||
-nstates..table_size (as an upper bound) */
|
||||
static bitset pos_set = NULL;
|
||||
|
||||
static unsigned *conflrow;
|
||||
unsigned *conflict_table;
|
||||
unsigned *conflict_list;
|
||||
static int *conflrow;
|
||||
int *conflict_table;
|
||||
int *conflict_list;
|
||||
int conflict_list_cnt;
|
||||
static int conflict_list_free;
|
||||
|
||||
@@ -391,7 +391,7 @@ save_row (state_number s)
|
||||
/* Allocate non defaulted actions. */
|
||||
base_number *sp1 = froms[s] = xnmalloc (count, sizeof *sp1);
|
||||
base_number *sp2 = tos[s] = xnmalloc (count, sizeof *sp2);
|
||||
unsigned *sp3 = conflict_tos[s] =
|
||||
int *sp3 = conflict_tos[s] =
|
||||
nondeterministic_parser ? xnmalloc (count, sizeof *sp3) : NULL;
|
||||
|
||||
/* Store non defaulted actions. */
|
||||
@@ -646,7 +646,7 @@ pack_vector (vector_number vector)
|
||||
size_t t = tally[i];
|
||||
base_number *from = froms[i];
|
||||
base_number *to = tos[i];
|
||||
unsigned *conflict_to = conflict_tos[i];
|
||||
int *conflict_to = conflict_tos[i];
|
||||
|
||||
aver (t != 0);
|
||||
|
||||
|
||||
@@ -122,8 +122,8 @@ extern base_number *base;
|
||||
keep parser tables small. */
|
||||
extern base_number base_ninf;
|
||||
|
||||
extern unsigned *conflict_table;
|
||||
extern unsigned *conflict_list;
|
||||
extern int *conflict_table;
|
||||
extern int *conflict_list;
|
||||
extern int conflict_list_cnt;
|
||||
|
||||
extern base_number *table;
|
||||
|
||||
Reference in New Issue
Block a user