From a762e609e70d246018e91b366670ba66184b6173 Mon Sep 17 00:00:00 2001 From: Akim Demaille Date: Thu, 25 Jul 2002 17:32:34 +0000 Subject: [PATCH] * 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. --- ChangeLog | 8 ++++++ data/c.m4 | 44 ++++++++++++++++++++------------ data/glr.c | 35 +++++++++++++------------ data/lalr1.cc | 62 ++++++++++++++++++++++----------------------- data/yacc.c | 28 ++++++++++---------- tests/regression.at | 10 ++++---- 6 files changed, 105 insertions(+), 82 deletions(-) diff --git a/ChangeLog b/ChangeLog index 1b40024d..c1c1afcb 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,11 @@ +2002-07-25 Akim Demaille + + * 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 * src/gram.h (TIEM_NUMBER_MAX): New. diff --git a/data/c.m4 b/data/c.m4 index 0405d979..7a516e1c 100644 --- a/data/c.m4 +++ b/data/c.m4 @@ -56,23 +56,35 @@ m4_define([b4_copyright], ## 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)]) ## ------------------------- ## diff --git a/data/glr.c b/data/glr.c index 94e61bfc..660a2243 100644 --- a/data/glr.c +++ b/data/glr.c @@ -241,7 +241,7 @@ static YYLTYPE yyloc_default; ((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[ }; @@ -249,19 +249,19 @@ static const ]b4_uint_type(b4_translate_max)[ yytranslate[] = #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[ }; @@ -279,25 +279,25 @@ static const char *const yytname[] = #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[ }; @@ -305,13 +305,13 @@ static const short yymerger[] = /* 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[ }; @@ -319,13 +319,13 @@ static const short yydefgoto[] = /* 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[ }; @@ -334,7 +334,7 @@ static const short yypgoto[] = 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[ }; @@ -343,19 +343,22 @@ static const ]b4_sint_type(b4_table_max)[ yytable[] = 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[ }; diff --git a/data/lalr1.cc b/data/lalr1.cc index 1a547001..8527c5e9 100644 --- a/data/lalr1.cc +++ b/data/lalr1.cc @@ -167,8 +167,8 @@ namespace yy 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; @@ -223,16 +223,16 @@ namespace yy 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_[[]]; @@ -241,10 +241,10 @@ namespace yy /* 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. */ @@ -436,7 +436,7 @@ yy::b4_name::parse () { 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; @@ -629,8 +629,8 @@ yy::b4_name::lex_ () /* 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 @@ -639,21 +639,21 @@ yy::b4_name::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 @@ -662,15 +662,15 @@ yy::b4_name::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 @@ -679,7 +679,7 @@ yy::b4_name::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 @@ -687,7 +687,7 @@ yy::b4_name::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 @@ -695,14 +695,14 @@ yy::b4_name::token_number_[[]] = #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 @@ -728,14 +728,14 @@ yy::b4_name::rhs_[[]] = /* 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 diff --git a/data/yacc.c b/data/yacc.c index b2d4cc53..ed541c80 100644 --- a/data/yacc.c +++ b/data/yacc.c @@ -323,7 +323,7 @@ b4_location_if( ((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 }; @@ -331,19 +331,19 @@ static const b4_uint_type(b4_translate_max) yytranslate[[]] = #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 }; @@ -360,19 +360,19 @@ static const char *const yytname[[]] = /* 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 }; @@ -380,13 +380,13 @@ static const b4_uint_type(b4_r2_max) yyr2[[]] = /* 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 }; @@ -394,13 +394,13 @@ static const short yydefgoto[[]] = /* 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 }; @@ -409,19 +409,19 @@ static const short yypgoto[[]] = 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 }; diff --git a/tests/regression.at b/tests/regression.at index 489cc29c..468610e5 100644 --- a/tests/regression.at +++ b/tests/regression.at @@ -599,12 +599,12 @@ static const unsigned char yyr2[] = { 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 }; @@ -613,15 +613,15 @@ static const signed char yypact[] = -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 }; -- 2.47.2