bison-patches
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

b4_int_type_for


From: Akim Demaille
Subject: b4_int_type_for
Date: 25 Jul 2002 17:17:51 +0200
User-agent: Gnus/5.0808 (Gnus v5.8.8) XEmacs/21.4 (Honest Recruiter)

This is cleaning up some of the issues we would have met sooner or
later with int types.  It should make us quite robust.

diff=^[ \t]*// /tmp/bison-1.49b/ChangeLog 
/home/lrde/prof/akim/src/bison-1.49b/./ChangeLog
--- /tmp/bison-1.49b/ChangeLog  Thu Jul 25 12:36:45 2002
+++ /home/lrde/prof/akim/src/bison-1.49b/./ChangeLog    Thu Jul 25 17:01:32 2002
@@ -1,5 +1,13 @@
 2002-07-25  Akim Demaille  <address@hidden>
 
+       * 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  <address@hidden>
+
        * src/gram.h (TIEM_NUMBER_MAX): New.
        (item_number_of_rule_number, rule_number_of_item_number): Rename
        as...
diff=^[ \t]*// /tmp/bison-1.49b/data/c.m4 
/home/lrde/prof/akim/src/bison-1.49b/./data/c.m4
--- /tmp/bison-1.49b/data/c.m4  Tue Jul 23 20:16:11 2002
+++ /home/lrde/prof/akim/src/bison-1.49b/./data/c.m4    Thu Jul 25 16:34:55 2002
@@ -56,23 +56,35 @@
 ## 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=^[ \t]*// /tmp/bison-1.49b/data/glr.c 
/home/lrde/prof/akim/src/bison-1.49b/./data/glr.c
--- /tmp/bison-1.49b/data/glr.c Thu Jul 25 12:36:25 2002
+++ /home/lrde/prof/akim/src/bison-1.49b/./data/glr.c   Thu Jul 25 16:57:38 2002
@@ -241,7 +241,7 @@
   ((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 @@
 #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 @@
 #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 @@
 /* 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 @@
 /* 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 @@
    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 @@
    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=^[ \t]*// /tmp/bison-1.49b/data/lalr1.cc 
/home/lrde/prof/akim/src/bison-1.49b/./data/lalr1.cc
--- /tmp/bison-1.49b/data/lalr1.cc      Thu Jul 25 12:36:01 2002
+++ /home/lrde/prof/akim/src/bison-1.49b/./data/lalr1.cc        Thu Jul 25 
16:38:28 2002
@@ -167,8 +167,8 @@
   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 @@
     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 @@
     /* 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 @@
     {
       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 @@
 
 /* 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 @@
 /* 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 @@
 /* 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 @@
 #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 @@
 
 /* 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 @@
 #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 @@
 
 /* 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=^[ \t]*// /tmp/bison-1.49b/data/yacc.c 
/home/lrde/prof/akim/src/bison-1.49b/./data/yacc.c
--- /tmp/bison-1.49b/data/yacc.c        Thu Jul 25 12:36:36 2002
+++ /home/lrde/prof/akim/src/bison-1.49b/./data/yacc.c  Thu Jul 25 16:18:49 2002
@@ -323,7 +323,7 @@
   ((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 @@
 #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 @@
 
 /* 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 @@
 /* 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 @@
 /* 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 @@
    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=^[ \t]*// /tmp/bison-1.49b/tests/regression.at 
/home/lrde/prof/akim/src/bison-1.49b/./tests/regression.at
--- /tmp/bison-1.49b/tests/regression.at        Thu Jul 25 12:40:28 2002
+++ /home/lrde/prof/akim/src/bison-1.49b/./tests/regression.at  Thu Jul 25 
16:35:51 2002
@@ -599,12 +599,12 @@
 {
        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 @@
       -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
 };



reply via email to

[Prev in Thread] Current Thread [Next in Thread]