bison-patches
[Top][All Lists]
Advanced

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

09-use-parse-param.patch


From: Akim Demaille
Subject: 09-use-parse-param.patch
Date: Mon, 21 Oct 2002 09:24:00 +0200

Index: ChangeLog
from  Akim Demaille  <address@hidden>
        * data/c.m4 (b4_c_ansi_args): Recognize functions with no
        arguments and output `void'.
        (b4_c_function): Rename as...
        (b4_c_function_def): this.
        (b4_c_function_decl, b4_c_ansi_function_def)
        (b4_c_ansi_function_decl): New.
        Change the interpretation of the arguments: before `int, foo', now
        `int foo, foo'.
        * data/yacc.c (yyparse): Prototype and define thanks to these.
        Adjust b4_c_function_def uses.
        * data/glr.c (yyparse): Likewise, but ANSI only.
        
        
Index: data/yacc.c
--- data/yacc.c Sun, 20 Oct 2002 13:37:27 +0200 akim
+++ data/yacc.c Sun, 20 Oct 2002 14:42:45 +0200 akim
@@ -40,6 +40,12 @@ m4_define([b4_lex_param],
 b4_location_if([, [[YYLTYPE *], [&yylloc]]])])dnl
 m4_ifdef([b4_lex_param], [, ]b4_lex_param)))
 
+# Yes, this is quite ugly...
+m4_define_default([b4_parse_param])
+m4_ifdef([b4_parse_param],
+[m4_define([b4_parse_param],
+          b4_parse_param)])
+
 
 ## ----------------- ##
 ## Semantic Values.  ##
@@ -625,12 +631,12 @@ m4_define([b4_symbol_actions],
 | Print this symbol on YYOUT.  |
 `-----------------------------*/
 
-b4_c_function([yysymprint],
-             [static void],
-             [[FILE*],   [yyout]],
-             [[int],     [yytype]],
-             [[YYSTYPE], [yyvalue]]b4_location_if([,
-             [[YYLTYPE], [yylocation]]]))
+b4_c_function_def([yysymprint],
+                 [static void],
+                 [[FILE *yyout],        [yyout]],
+                 [[int yytype],         [yytype]],
+                 [[YYSTYPE yyvalue],    [yyvalue]]b4_location_if([,
+                 [[YYLTYPE yylocation], [yylocation]]]))
 {
   /* Pacify ``unused variable'' warnings.  */
   (void) yyvalue;
@@ -662,11 +668,11 @@ m4_define([b4_symbol_actions],
 | Release the memory associated to this symbol.  |
 `-----------------------------------------------*/
 
-b4_c_function([yydestruct],
-             [static void],
-             [[int],     [yytype]],
-             [[YYSTYPE], [yyvalue]]b4_location_if([,
-             [[YYLTYPE], [yylocation]]]))
+b4_c_function_def([yydestruct],
+                 [static void],
+                 [[int yytype],         [yytype]],
+                 [[YYSTYPE yyvalue],    [yyvalue]]b4_location_if([,
+                 [[YYLTYPE yylocation], [yylocation]]]))
 {
   /* Pacify ``unused variable'' warnings.  */
   (void) yyvalue;
@@ -683,39 +689,24 @@ m4_define([b4_symbol_actions],
 
 
 
-/* The user can define YYPARSE_PARAM as the name of an argument to be passed
-   into yyparse.  The argument should have type void *.
-   It should actually point to an object.
-   Grammar actions can access the variable by casting it
-   to the proper pointer type.  */
+/* Prevent warnings from -Wmissing-prototypes.  */
 
 #ifdef YYPARSE_PARAM
 # if defined (__STDC__) || defined (__cplusplus)
-#  define YYPARSE_PARAM_ARG void *YYPARSE_PARAM
-#  define YYPARSE_PARAM_DECL
-# else
-#  define YYPARSE_PARAM_ARG YYPARSE_PARAM
-#  define YYPARSE_PARAM_DECL void *YYPARSE_PARAM;
-# endif
-#else /* !YYPARSE_PARAM */
-# define YYPARSE_PARAM_ARG
-# define YYPARSE_PARAM_DECL
-#endif /* !YYPARSE_PARAM */
-
-/* Prevent warning if -Wstrict-prototypes.  */
-#ifdef __GNUC__
-# ifdef YYPARSE_PARAM
-int yyparse (void *);
+int yyparse (void *YYPARSE_PARAM);
 # else
-int yyparse (void);
+int yyparse ();
 # endif
+#else /* ! YYPARSE_PARAM */
+b4_c_function_decl([yyparse], [int], b4_parse_param)
 #endif
 
+
 m4_divert_push([KILL])# ======================== M4 code.
 # b4_declare_parser_variables
 # ---------------------------
 # Declare the variables that are global, or local to YYPARSE if
-#  pure-parser
+# pure-parser.
 m4_define([b4_declare_parser_variables],
 [/* The lookahead symbol.  */
 int yychar;
@@ -733,9 +724,21 @@ m4_define([b4_declare_parser_variables],
 b4_pure_if([],
            [b4_declare_parser_variables])
 
-int
-yyparse (YYPARSE_PARAM_ARG)
-     YYPARSE_PARAM_DECL
+
+/*----------.
+| yyparse.  |
+`----------*/
+
+#ifdef YYPARSE_PARAM
+# if defined (__STDC__) || defined (__cplusplus)
+int yyparse (void *YYPARSE_PARAM)
+# else
+int yyparse (YYPARSE_PARAM)
+  void *YYPARSE_PARAM;
+# endif
+#else /* ! YYPARSE_PARAM */
+b4_c_function_def([yyparse], [int], b4_parse_param)
+#endif
 {[
   ]b4_pure_if([b4_declare_parser_variables])[
   register int yystate;
Index: data/c.m4
--- data/c.m4 Sun, 20 Oct 2002 13:37:27 +0200 akim
+++ data/c.m4 Sun, 20 Oct 2002 14:26:31 +0200 akim
@@ -82,6 +82,30 @@ m4_define([b4_int_type_for],
 [b4_int_type($1_min, $1_max)])
 
 
+## ------------------ ##
+## Decoding options.  ##
+## ------------------ ##
+
+
+# b4_location_if(IF-TRUE, IF-FALSE)
+# ---------------------------------
+# Expand IF-TRUE, if locations are used, IF-FALSE otherwise.
+m4_define([b4_location_if],
+[m4_if(b4_locations_flag, [1],
+       [$1],
+       [$2])])
+
+
+# b4_pure_if(IF-TRUE, IF-FALSE)
+# -----------------------------
+# Expand IF-TRUE, if %pure-parser, IF-FALSE otherwise.
+m4_define([b4_pure_if],
+[m4_if(b4_pure, [1],
+       [$1],
+       [$2])])
+
+
+
 ## ------------------------- ##
 ## Assigning token numbers.  ##
 ## ------------------------- ##
@@ -122,100 +146,117 @@ m4_define([b4_token_defines],
 ])
 
 
-## --------------------- ##
-## Calling C functions.  ##
-## --------------------- ##
-
-
-# b4_c_function_call(NAME, RETURN-VALUE, [TYPE1, NAME1], ...)
-# -----------------------------------------------------------
-# Call the function NAME with arguments NAME1, NAME2 etc.
-m4_define([b4_c_function_call],
-[$1 (b4_c_args(m4_shiftn(2, $@)))[]dnl
-])
-
-
-# b4_c_args([TYPE1, NAME1], ...)
-# ------------------------------
-# Output the arguments NAME1, NAME2...
-m4_define([b4_c_args],
-[m4_map_sep([b4_c_arg], [, ], address@hidden)])
-
-m4_define([b4_c_arg],
-[$2])
-
 
-## ---------------------------------------------- ##
-## Declaring C functions in both K&R and ANSI-C.  ##
-## ---------------------------------------------- ##
+## --------------------------------------------- ##
+## Defining C functions in both K&R and ANSI-C.  ##
+## --------------------------------------------- ##
 
 
-# b4_c_function(NAME, RETURN-VALUE, [TYPE1, NAME1], ...)
-# ------------------------------------------------------
+# b4_c_function_def(NAME, RETURN-VALUE, [DECL1, NAME1], ...)
+# ----------------------------------------------------------
 # Declare the function NAME.
-m4_define([b4_c_function],
-[$2
-#if defined (__STDC__) || defined (__cplusplus)
-$1 (b4_c_ansi_args(m4_shiftn(2, $@)))
+m4_define([b4_c_function_def],
+[#if defined (__STDC__) || defined (__cplusplus)
+b4_c_ansi_function_def($@)
 #else
-$1 (b4_c_knr_arg_names(m4_shiftn(2, $@)))
-b4_c_knr_arg_decls(m4_shiftn(2, $@))
+$2
+$1 (b4_c_knr_formal_names(m4_shiftn(2, $@)))
+b4_c_knr_formal_decls(m4_shiftn(2, $@))
 #endif[]dnl
 ])
 
 
-# b4_c_ansi_args([TYPE1, NAME1], ...)
-# -----------------------------------
+# b4_c_ansi_function_def(NAME, RETURN-VALUE, [DECL1, NAME1], ...)
+# ---------------------------------------------------------------
+# Declare the function NAME in ANSI.
+m4_define([b4_c_ansi_function_def],
+[$2
+$1 (b4_c_ansi_formals(m4_shiftn(2, $@)))[]dnl
+])
+
+
+# b4_c_ansi_formals([DECL1, NAME1], ...)
+# --------------------------------------
 # Output the arguments ANSI-C definition.
-m4_define([b4_c_ansi_args],
-[m4_map_sep([b4_c_ansi_arg], [, ], address@hidden)])
+m4_define([b4_c_ansi_formals],
+[m4_case(address@hidden,
+         [],   [void],
+         [[]], [void],
+               [m4_map_sep([b4_c_ansi_formal], [, ], address@hidden)])])
 
-m4_define([b4_c_ansi_arg],
-[$1 $2])
+m4_define([b4_c_ansi_formal],
+[$1])
 
 
-# b4_c_knr_args([TYPE1, NAME1], ...)
-# ----------------------------------
+# b4_c_knr_formal_names([DECL1, NAME1], ...)
+# ------------------------------------------
 # Output the argument names.
-m4_define([b4_c_knr_arg_names],
-[m4_map_sep([b4_c_knr_arg_name], [, ], address@hidden)])
+m4_define([b4_c_knr_formal_names],
+[m4_map_sep([b4_c_knr_formal_name], [, ], address@hidden)])
 
-m4_define([b4_c_knr_arg_name],
+m4_define([b4_c_knr_formal_name],
 [$2])
 
 
-# b4_c_knr_args([TYPE1, NAME1], ...)
-# ----------------------------------
+# b4_c_knr_formal_decls([DECL1, NAME1], ...)
+# ------------------------------------------
 # Output the K&R argument declarations.
-m4_define([b4_c_knr_arg_decls],
-[m4_map_sep([b4_c_knr_arg_decl],
+m4_define([b4_c_knr_formal_decls],
+[m4_map_sep([b4_c_knr_formal_decl],
             [
 ],
             address@hidden)])
 
-m4_define([b4_c_knr_arg_decl],
-[    $1 $2;])
+m4_define([b4_c_knr_formal_decl],
+[    $1;])
 
 
 
-## ------------------ ##
-## Decoding options.  ##
-## ------------------ ##
+## ------------------------------------------------------------ ##
+## Declaring (prototyping) C functions in both K&R and ANSI-C.  ##
+## ------------------------------------------------------------ ##
 
 
-# b4_location_if(IF-TRUE, IF-FALSE)
-# ---------------------------------
-# Expand IF-TRUE, if locations are used, IF-FALSE otherwise.
-m4_define([b4_location_if],
-[m4_if(b4_locations_flag, [1],
-       [$1],
-       [$2])])
+# b4_c_function_decl(NAME, RETURN-VALUE, [DECL1, NAME1], ...)
+# -----------------------------------------------------------
+# Declare the function NAME.
+m4_define([b4_c_function_decl],
+[#if defined (__STDC__) || defined (__cplusplus)
+b4_c_ansi_function_decl($@)
+#else
+$2 $1 ();
+#endif[]dnl
+])
 
 
-# b4_pure_if(IF-TRUE, IF-FALSE)
-# -----------------------------
-# Expand IF-TRUE, if %pure-parser, IF-FALSE otherwise.
-m4_define([b4_pure_if],
-[m4_if(b4_pure, [1],
-       [$1],
-       [$2])])
+# b4_c_ansi_function_decl(NAME, RETURN-VALUE, [DECL1, NAME1], ...)
+# ----------------------------------------------------------------
+# Declare the function NAME.
+m4_define([b4_c_ansi_function_decl],
+[$2 $1 (b4_c_ansi_formals(m4_shiftn(2, $@)));[]dnl
+])
+
+
+
+
+## --------------------- ##
+## Calling C functions.  ##
+## --------------------- ##
+
+
+# b4_c_function_call(NAME, RETURN-VALUE, [DECL1, NAME1], ...)
+# -----------------------------------------------------------
+# Call the function NAME with arguments NAME1, NAME2 etc.
+m4_define([b4_c_function_call],
+[$1 (b4_c_args(m4_shiftn(2, $@)))[]dnl
+])
+
+
+# b4_c_args([DECL1, NAME1], ...)
+# ------------------------------
+# Output the arguments NAME1, NAME2...
+m4_define([b4_c_args],
+[m4_map_sep([b4_c_arg], [, ], address@hidden)])
+
+m4_define([b4_c_arg],
+[$2])
Index: data/glr.c
--- data/glr.c Sun, 20 Oct 2002 13:37:27 +0200 akim
+++ data/glr.c Sun, 20 Oct 2002 14:39:09 +0200 akim
@@ -38,7 +38,12 @@ m4_define([b4_lex_param],
 b4_location_if([, [[YYLTYPE *], [yyllocp]]])])dnl
 m4_ifdef([b4_lex_param], [, ]b4_lex_param)))
 
-m4_define_default([b4_parse_param])
+# Yes, this is quite ugly...
+  m4_define_default([b4_parse_param])
+m4_ifdef([b4_parse_param],
+[m4_define([b4_parse_param],
+          b4_parse_param)])
+
 
 
 ## ----------------- ##
@@ -377,26 +382,8 @@ m4_define_default([b4_header_guard],
 };
 
 
-/* The user can define YYPARSE_PARAM as the name of an argument to be passed
-   into yyparse.  The argument should have type void *.
-   It should actually point to an object.
-   Grammar actions can access the variable by casting it
-   to the proper pointer type.  */
-
-#ifdef YYPARSE_PARAM
-#  define YYPARSE_PARAM_ARG void *YYPARSE_PARAM
-#else /* !YYPARSE_PARAM */
-# define YYPARSE_PARAM_ARG void
-#endif /* !YYPARSE_PARAM */
-
-/* Prevent warning if -Wstrict-prototypes.  */
-#ifdef __GNUC__
-# ifdef YYPARSE_PARAM
-int yyparse (void *);
-# else
-int yyparse (void);
-# endif
-#endif
+/* Prevent warning if -Wmissing-prototypes.  */
+]b4_c_ansi_function_decl([yyparse], [int], b4_parse_param)[
 
 /* Error token number */
 #define YYTERROR 1
@@ -1660,8 +1647,12 @@ m4_define_default([b4_header_guard],
     }                                                                       \
   } while (0)
 
-int
-yyparse (YYPARSE_PARAM_ARG)
+
+/*----------.
+| yyparse.  |
+`----------*/
+
+]b4_c_ansi_function_def([yyparse], [int], b4_parse_param)[
 {
   yySymbol yytoken;
   yyGLRStack yystack;




reply via email to

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