replace...
(b4_sint_type, b4_uint_type): these.
* data/yacc.c, data/glr.c, data/lalr1.cc: Use b4_int_type_for.
* tests/regression.at (Web2c Actions): Adjust.
+2002-07-25 Akim Demaille <akim@epita.fr>
+
+ * data/c.m4 (b4_ints_in, b4_int_type, b4_int_type_for): New,
+ replace...
+ (b4_sint_type, b4_uint_type): these.
+ * data/yacc.c, data/glr.c, data/lalr1.cc: Use b4_int_type_for.
+ * tests/regression.at (Web2c Actions): Adjust.
+
2002-07-25 Akim Demaille <akim@epita.fr>
* src/gram.h (TIEM_NUMBER_MAX): New.
## Data Types. ##
## ------------ ##
-# b4_sint_type(MAX)
-# -----------------
-# Return the smallest signed int type able to handle the number MAX.
-m4_define([b4_sint_type],
-[m4_if(m4_eval([$1 <= 127]), [1], [signed char],
- m4_eval([$1 <= 32767]), [1], [signed short],
- [signed int])])
-
-
-# b4_uint_type(MAX)
-# -----------------
-# Return the smallest unsigned int type able to handle the number MAX.
-m4_define([b4_uint_type],
-[m4_if(m4_eval([$1 <= 255]), [1], [unsigned char],
- m4_eval([$1 <= 65535]), [1], [unsigned short],
- [unsigned int])])
+# b4_ints_in(INT1, INT2, LOW, HIGH)
+# ---------------------------------
+# Return 1 iff both INT1 and INT2 are in [LOW, HIGH], 0 otherwise.
+m4_define([b4_ints_in],
+[m4_eval([$3 <= $1 && $1 <= $4 && $3 <= $2 && $2 <= $4])])
+
+
+# b4_int_type(MIN, MAX)
+# ---------------------
+# Return the smallest int type able to handle numbers ranging from
+# MIN to MAX (included).
+m4_define([b4_int_type],
+[m4_if(b4_ints_in($@, [0], [255]), [1], [unsigned char],
+ b4_ints_in($@, [-128], [128]), [1], [signed char],
+
+ b4_ints_in($@, [0], [65535]), [1], [unsigned short],
+ b4_ints_in($@, [-32768], [32767]), [1], [short],
+
+ m4_eval([0 <= $1]), [1], [unsigned int],
+
+ [int])])
+
+# b4_int_type_for(NAME)
+# ---------------------
+# Return the smallest int type able to handle numbers ranging from
+# `NAME_min' to `NAME_max' (included).
+m4_define([b4_int_type_for],
+[b4_int_type($1_min, $1_max)])
## ------------------------- ##
((unsigned)(YYX) <= YYMAXUTOK ? yytranslate[YYX] : YYUNDEFTOK)
/* YYTRANSLATE[YYLEX] -- Bison symbol number corresponding to YYLEX. */
-static const ]b4_uint_type(b4_translate_max)[ yytranslate[] =
+static const ]b4_int_type_for([b4_translate])[ yytranslate[] =
{
]b4_translate[
};
#if YYDEBUG
/* YYPRHS[YYN] -- Index of the first RHS symbol of rule number YYN in
YYRHS. */
-static const ]b4_uint_type(b4_prhs_max)[ yyprhs[] =
+static const ]b4_int_type_for([b4_prhs])[ yyprhs[] =
{
]b4_prhs[
};
/* YYRHS -- A `-1'-separated list of the rules' RHS. */
-static const ]b4_sint_type(b4_rhs_max)[ yyrhs[] =
+static const ]b4_int_type_for([b4_rhs])[ yyrhs[] =
{
]b4_rhs[
};
/* YYRLINE[YYN] -- source line where rule number YYN was defined. */
-static const ]b4_uint_type(b4_rline_max)[ yyrline[] =
+static const ]b4_int_type_for([b4_rline])[ yyrline[] =
{
]b4_rline[
};
#endif
/* YYR1[YYN] -- Symbol number of symbol that rule YYN derives. */
-static const ]b4_uint_type(b4_r1_max)[ yyr1[] =
+static const ]b4_int_type_for([b4_r1])[ yyr1[] =
{
]b4_r1[
};
/* YYR2[YYN] -- Number of symbols composing right hand side of rule YYN. */
-static const ]b4_uint_type(b4_r2_max)[ yyr2[] =
+static const ]b4_int_type_for([b4_r2])[ yyr2[] =
{
]b4_r2[
};
/* YYDPREC[RULE-NUM] -- Dynamic precedence of rule #RULE-NUM (0 if none). */
-static const short yydprec[] =
+static const ]b4_int_type_for([b4_dprec])[ yydprec[] =
{
]b4_dprec[
};
/* YYMERGER[RULE-NUM] -- Index of merging function for rule #RULE-NUM. */
-static const short yymerger[] =
+static const ]b4_int_type_for([b4_merger])[ yymerger[] =
{
]b4_merger[
};
/* YYDEFACT[S] -- default rule to reduce with in state S when YYTABLE
doesn't specify something else to do. Zero means the default is an
error. */
-static const short yydefact[] =
+static const ]b4_int_type_for([b4_defact])[ yydefact[] =
{
]b4_defact[
};
/* YYPDEFGOTO[NTERM-NUM]. */
-static const short yydefgoto[] =
+static const ]b4_int_type_for([b4_defgoto])[ yydefgoto[] =
{
]b4_defgoto[
};
/* YYPACT[STATE-NUM] -- Index in YYTABLE of the portion describing
STATE-NUM. */
#define YYPACT_NINF ]b4_pact_ninf[
-static const ]b4_sint_type(b4_pact_max)[ yypact[] =
+static const ]b4_int_type_for([b4_pact])[ yypact[] =
{
]b4_pact[
};
/* YYPGOTO[NTERM-NUM]. */
-static const short yypgoto[] =
+static const ]b4_int_type_for([b4_pgoto])[ yypgoto[] =
{
]b4_pgoto[
};
positive, shift that token. If negative, reduce the rule which
number is the opposite. If zero, do what YYDEFACT says. */
#define YYTABLE_NINF ]b4_table_ninf[
-static const ]b4_sint_type(b4_table_max)[ yytable[] =
+static const ]b4_int_type_for([b4_table])[ yytable[] =
{
]b4_table[
};
of conflicting reductions corresponding to action entry for state
STATE-NUM in yytable. 0 means no conflicts. The list in yyconfl
is terminated by a rule number of 0. */
-static const short yyconflp[] =
+static const ]b4_int_type_for([b4_conflict_list_heads])[ yyconflp[] =
{
]b4_conflict_list_heads[
};
/* YYCONFL[I] -- lists of conflicting rule numbers, each terminated
by 0, pointed into by YYCONFLP. */
-static const short yyconfl[] =
+]dnl Do not use b4_int_type_for here, since there are places where
+dnl pointers onto yyconfl are taken, which type is "short *".
+dnl We probably ought to introduce a type for confl.
+[static const short yyconfl[] =
{
]b4_conflicting_rules[
};
-static const short yycheck[] =
+static const ]b4_int_type_for([b4_check])[ yycheck[] =
{
]b4_check[
};
template < >
struct Traits< b4_name >
{
- typedef b4_uint_type(b4_translate_max) TokenNumberType;
- typedef b4_sint_type(b4_rhs_max) RhsNumberType;
+ typedef b4_int_type_for([b4_translate]) TokenNumberType;
+ typedef b4_int_type_for([b4_rhs]) RhsNumberType;
typedef int StateType;
typedef yystype SemanticType;
typedef b4_ltype LocationType;
LocationStack location_stack_;
/* Tables. */
- static const b4_sint_type(b4_pact_max) pact_[[]];
- static const b4_sint_type(b4_pact_max) pact_ninf_;
- static const short defact_[[]];
- static const short pgoto_[[]];
- static const short defgoto_[[]];
- static const b4_sint_type(b4_table_max) table_[[]];
- static const b4_sint_type(b4_table_max) table_ninf_;
- static const short check_[[]];
- static const b4_uint_type(b4_r1_max) r1_[[]];
- static const b4_uint_type(b4_r2_max) r2_[[]];
+ static const b4_int_type_for([b4_pact]) pact_[[]];
+ static const b4_int_type_for([b4_pact]) pact_ninf_;
+ static const b4_int_type_for([b4_defact]) defact_[[]];
+ static const b4_int_type_for([b4_pgoto]) pgoto_[[]];
+ static const b4_int_type_for([b4_defgoto]) defgoto_[[]];
+ static const b4_int_type_for([b4_table]) table_[[]];
+ static const b4_int_type_for([b4_table]) table_ninf_;
+ static const b4_int_type_for([b4_check]) check_[[]];
+ static const b4_int_type_for([b4_r1]) r1_[[]];
+ static const b4_int_type_for([b4_r2]) r2_[[]];
#if YYDEBUG || YYERROR_VERBOSE
static const char* const name_[[]];
/* More tables, for debugging. */
#if YYDEBUG
static const RhsNumberType rhs_[[]];
- static const b4_uint_type(b4_prhs_max) prhs_[[]];
- static const b4_uint_type(b4_rline_max) rline_[[]];
- static const b4_uint_type(b4_stos_max) stos_[[]];
- static const short token_number_[[]];
+ static const b4_int_type_for([b4_prhs]) prhs_[[]];
+ static const b4_int_type_for([b4_rline]) rline_[[]];
+ static const b4_int_type_for([b4_stos]) stos_[[]];
+ static const b4_int_type_for([b4_toknum]) token_number_[[]];
#endif
/* Even more tables. */
{
YYCDEBUG << "Reducing via rule " << n_ - 1
<< " (line " << rline_[[n_]] << "), ";
- for (b4_uint_type(b4_prhs_max) i = prhs_[[n_]];
+ for (b4_int_type_for([b4_prhs]) i = prhs_[[n_]];
rhs_[[i]] >= 0; ++i)
YYCDEBUG << name_[[rhs_[i]]] << ' ';
YYCDEBUG << "-> " << name_[[r1_[n_]]] << std::endl;
/* YYPACT[[STATE-NUM]] -- Index in YYTABLE of the portion describing
STATE-NUM. */
-const b4_sint_type(b4_pact_max) yy::b4_name::pact_ninf_ = b4_pact_ninf;
-const b4_sint_type(b4_pact_max)
+const b4_int_type_for([b4_pact]) yy::b4_name::pact_ninf_ = b4_pact_ninf;
+const b4_int_type_for([b4_pact])
yy::b4_name::pact_[[]] =
{
b4_pact
/* YYDEFACT[[S]] -- default rule to reduce with in state S when YYTABLE
doesn't specify something else to do. Zero means the default is an
error. */
-const short
+const b4_int_type_for([b4_defact])
yy::b4_name::defact_[[]] =
{
b4_defact
};
/* YYPGOTO[[NTERM-NUM]]. */
-const short
+const b4_int_type_for([b4_pgoto])
yy::b4_name::pgoto_[[]] =
{
b4_pgoto
};
/* YYDEFGOTO[[NTERM-NUM]]. */
-const short
+const b4_int_type_for([b4_defgoto])
yy::b4_name::defgoto_[[]] =
{
b4_defgoto
/* YYTABLE[[YYPACT[STATE-NUM]]]. What to do in state STATE-NUM. If
positive, shift that token. If negative, reduce the rule which
number is the opposite. If zero, do what YYDEFACT says. */
-const b4_sint_type(b4_table_max) yy::b4_name::table_ninf_ = b4_table_ninf;
-const b4_sint_type(b4_table_max)
+const b4_int_type_for([b4_table]) yy::b4_name::table_ninf_ = b4_table_ninf;
+const b4_int_type_for([b4_table])
yy::b4_name::table_[[]] =
{
b4_table
};
/* YYCHECK. */
-const short
+const b4_int_type_for([b4_check])
yy::b4_name::check_[[]] =
{
b4_check
#if YYDEBUG
/* STOS_[[STATE-NUM]] -- The (internal number of the) accessing
symbol of state STATE-NUM. */
-const b4_uint_type(b4_stos_max)
+const b4_int_type_for([b4_stos])
yy::b4_name::stos_[[]] =
{
b4_stos
/* TOKEN_NUMBER_[[YYLEX-NUM]] -- Internal token number corresponding
to YYLEX-NUM. */
-const short
+const b4_int_type_for([b4_toknum])
yy::b4_name::token_number_[[]] =
{
b4_toknum
#endif
/* YYR1[[YYN]] -- Symbol number of symbol that rule YYN derives. */
-const b4_uint_type(b4_r1_max)
+const b4_int_type_for([b4_r1])
yy::b4_name::r1_[[]] =
{
b4_r1
};
/* YYR2[[YYN]] -- Number of symbols composing right hand side of rule YYN. */
-const b4_uint_type(b4_r2_max)
+const b4_int_type_for([b4_r2])
yy::b4_name::r2_[[]] =
{
b4_r2
/* YYPRHS[[YYN]] -- Index of the first RHS symbol of rule number YYN in
YYRHS. */
-const b4_uint_type(b4_prhs_max)
+const b4_int_type_for([b4_prhs])
yy::b4_name::prhs_[[]] =
{
b4_prhs
};
/* YYRLINE[[YYN]] -- source line where rule number YYN was defined. */
-const b4_uint_type(b4_rline_max)
+const b4_int_type_for([b4_rline])
yy::b4_name::rline_[[]] =
{
b4_rline
((unsigned)(X) <= YYMAXUTOK ? yytranslate[[X]] : YYUNDEFTOK)
/* YYTRANSLATE[[YYLEX]] -- Bison symbol number corresponding to YYLEX. */
-static const b4_uint_type(b4_translate_max) yytranslate[[]] =
+static const b4_int_type_for([b4_translate]) yytranslate[[]] =
{
b4_translate
};
#if YYDEBUG
/* YYPRHS[[YYN]] -- Index of the first RHS symbol of rule number YYN in
YYRHS. */
-static const b4_uint_type(b4_prhs_max) yyprhs[[]] =
+static const b4_int_type_for([b4_prhs]) yyprhs[[]] =
{
b4_prhs
};
/* YYRHS -- A `-1'-separated list of the rules' RHS. */
-static const b4_sint_type(b4_rhs_max) yyrhs[[]] =
+static const b4_int_type_for([b4_rhs]) yyrhs[[]] =
{
b4_rhs
};
/* YYRLINE[[YYN]] -- source line where rule number YYN was defined. */
-static const b4_uint_type(b4_rline_max) yyrline[[]] =
+static const b4_int_type_for([b4_rline]) yyrline[[]] =
{
b4_rline
};
/* YYTOKNUM[[YYLEX-NUM]] -- Internal token number corresponding to
token YYLEX-NUM. */
-static const short yytoknum[[]] =
+static const b4_int_type_for([b4_toknum]) yytoknum[[]] =
{
b4_toknum
};
/* YYR1[[YYN]] -- Symbol number of symbol that rule YYN derives. */
-static const b4_uint_type(b4_r1_max) yyr1[[]] =
+static const b4_int_type_for([b4_r1]) yyr1[[]] =
{
b4_r1
};
/* YYR2[[YYN]] -- Number of symbols composing right hand side of rule YYN. */
-static const b4_uint_type(b4_r2_max) yyr2[[]] =
+static const b4_int_type_for([b4_r2]) yyr2[[]] =
{
b4_r2
};
/* YYDEFACT[[STATE-NAME]] -- Default rule to reduce with in state
STATE-NUM when YYTABLE doesn't specify something else to do. Zero
means the default is an error. */
-static const short yydefact[[]] =
+static const b4_int_type_for([b4_defact]) yydefact[[]] =
{
b4_defact
};
/* YYDEFGOTO[[NTERM-NUM]]. */
-static const short yydefgoto[[]] =
+static const b4_int_type_for([b4_defgoto]) yydefgoto[[]] =
{
b4_defgoto
};
/* YYPACT[[STATE-NUM]] -- Index in YYTABLE of the portion describing
STATE-NUM. */
#define YYPACT_NINF b4_pact_ninf
-static const b4_sint_type(b4_pact_max) yypact[[]] =
+static const b4_int_type_for([b4_pact]) yypact[[]] =
{
b4_pact
};
/* YYPGOTO[[NTERM-NUM]]. */
-static const short yypgoto[[]] =
+static const b4_int_type_for([b4_pgoto]) yypgoto[[]] =
{
b4_pgoto
};
positive, shift that token. If negative, reduce the rule which
number is the opposite. If zero, do what YYDEFACT says. */
#define YYTABLE_NINF b4_table_ninf
-static const b4_sint_type(b4_table_max) yytable[[]] =
+static const b4_int_type_for([b4_table]) yytable[[]] =
{
b4_table
};
-static const short yycheck[[]] =
+static const b4_int_type_for([b4_check]) yycheck[[]] =
{
b4_check
};
/* YYSTOS[[STATE-NUM]] -- The (internal number of the) accessing
symbol of state STATE-NUM. */
-static const b4_uint_type(b4_stos_max) yystos[[]] =
+static const b4_int_type_for([b4_stos]) yystos[[]] =
{
b4_stos
};
{
0, 2, 1, 0, 2, 4, 2
};
-static const short yydefact[] =
+static const unsigned char yydefact[] =
{
3, 0, 0, 2, 0, 0, 0, 3, 4, 3,
6, 5
};
-static const short yydefgoto[] =
+static const signed char yydefgoto[] =
{
-1, 2, 3, 4, 8
};
-2, -1, 4, -8, 0, 2, -8, -2, -8, -2,
-8, -8
};
-static const short yypgoto[] =
+static const signed char yypgoto[] =
{
-8, -7, -8, -8, -8
};
-static const signed char yytable[] =
+static const unsigned char yytable[] =
{
10, 1, 11, 5, 6, 0, 7, 9
};
-static const short yycheck[] =
+static const signed char yycheck[] =
{
7, 3, 9, 4, 0, -1, 6, 5
};