bug-bison
[Top][All Lists]
Advanced

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

Re: Bison fast questions


From: Paul Eggert
Subject: Re: Bison fast questions
Date: Wed, 04 Jan 2006 15:43:13 -0800
User-agent: Gnus/5.1007 (Gnus v5.10.7) Emacs/21.4 (gnu/linux)

"Cenzato Marco" <address@hidden> writes:

> The MS Visual Studio 2005 compiler doesn't define __C99__FUNC__....
> You can find a full list of the predefined macros in MS VS 2005 C/C++ 
> compiler at
> <http://msdn2.microsoft.com/en-us/library/b0084kay.aspx>

Thanks for mentioning that.  I installed this patch.

One of these days we should drop support for K&R C.....

2006-01-04  Paul Eggert  <address@hidden>

        * data/c.m4 (b4_c_modern): New macro, with a new provision for
        _MSC_VER.  Problem reported by Cenzato Marco.
        (b4_c_function_def): Use it.
        * data/yacc.c (YYMODERN_C): Remove.  All uses replaced by
        b4_c_modern.
        (yystrlen, yystpcpy, yyparse): Use b4_c_function... macros rather
        than rolling our own.

Index: data/c.m4
===================================================================
RCS file: /cvsroot/bison/bison/data/c.m4,v
retrieving revision 1.46
retrieving revision 1.50
diff -p -u -r1.46 -r1.50
--- data/c.m4   3 Jan 2006 19:12:55 -0000       1.46
+++ data/c.m4   4 Jan 2006 23:42:53 -0000       1.50
@@ -248,11 +248,25 @@ m4_define([b4_token_enums_defines],
 ## --------------------------------------------- ##
 
 
+# b4_modern_c
+# -----------
+# A predicate useful in #if to determine whether C is ancient or modern.
+#
+# If __STDC__ is defined, the compiler is modern.  IBM xlc 7.0 when run
+# as 'cc' doesn't define __STDC__ (or __STDC_VERSION__) for pedantic
+# reasons, but it defines __C99__FUNC__ so check that as well.
+# Microsoft C normally doesn't define these macros, but it defines _MSC_VER.
+# Consider a C++ compiler to be modern if it defines __cplusplus.
+#
+m4_define([b4_c_modern],
+  [[(defined (__STDC__) || defined (__C99__FUNC__) \
+     || defined (__cplusplus) || defined (_MSC_VER))]])
+
 # b4_c_function_def(NAME, RETURN-VALUE, [DECL1, NAME1], ...)
 # ----------------------------------------------------------
 # Declare the function NAME.
 m4_define([b4_c_function_def],
-[#if defined (__STDC__) || defined (__C99__FUNC__) || defined (__cplusplus)
+[#if b4_c_modern
 b4_c_ansi_function_def($@)
 #else
 $2
Index: data/yacc.c
===================================================================
RCS file: /cvsroot/bison/bison/data/yacc.c,v
retrieving revision 1.128
retrieving revision 1.129
diff -p -u -r1.128 -r1.129
--- data/yacc.c 3 Jan 2006 20:25:54 -0000       1.128
+++ data/yacc.c 4 Jan 2006 23:35:43 -0000       1.129
@@ -220,25 +220,12 @@ typedef struct YYLTYPE
 /* Line __line__ of yacc.c.  */
 b4_syncline(address@hidden@], address@hidden@])[
 
-/* Define YYMODERN_C if this compiler supports C89 or better.  If
-   __STDC__ is defined, the compiler is modern.  IBM xlc 7.0 when run
-   as 'cc' doesn't define __STDC__ (or __STDC_VERSION__) for pedantic
-   reasons, but it defines __C99__FUNC__ so check that as well.
-   Consider a C++ compiler to be modern if it defines __cplusplus.  */
-#ifndef YYMODERN_C
-# if defined (__STDC__) || defined (__C99__FUNC__) || defined (__cplusplus)
-#  define YYMODERN_C 1
-# else
-#  define YYMODERN_C 0
-# endif
-#endif
-
 #ifndef YYSIZE_T
 # if defined (__SIZE_TYPE__)
 #  define YYSIZE_T __SIZE_TYPE__
 # elif defined (size_t)
 #  define YYSIZE_T size_t
-# elif ! defined (YYSIZE_T) && YYMODERN_C
+# elif ! defined (YYSIZE_T) && ]b4_c_modern[
 #  include <stddef.h> /* INFRINGES ON USER NAME SPACE */
 #  define YYSIZE_T size_t
 # else
@@ -294,7 +281,7 @@ b4_syncline(address@hidden@], address@hidden@])[
 #    define alloca _alloca
 #   else
 #    define YYSTACK_ALLOC alloca
-#    if ! defined (_ALLOCA_H) && ! defined (_STDLIB_H) && YYMODERN_C
+#    if ! defined (_ALLOCA_H) && ! defined (_STDLIB_H) && ]b4_c_modern[
 #     include <stdlib.h> /* INFRINGES ON USER NAME SPACE */
 #     ifndef _STDLIB_H
 #      define _STDLIB_H 1
@@ -325,13 +312,13 @@ extern "C" {
 #  endif
 #  ifndef YYMALLOC
 #   define YYMALLOC malloc
-#   if ! defined (malloc) && ! defined (_STDLIB_H) && YYMODERN_C
+#   if ! defined (malloc) && ! defined (_STDLIB_H) && ]b4_c_modern[
 void *malloc (YYSIZE_T); /* INFRINGES ON USER NAME SPACE */
 #   endif
 #  endif
 #  ifndef YYFREE
 #   define YYFREE free
-#   if ! defined (free) && ! defined (_STDLIB_H)  && YYMODERN_C
+#   if ! defined (free) && ! defined (_STDLIB_H) && ]b4_c_modern[
 void free (void *); /* INFRINGES ON USER NAME SPACE */
 #   endif
 #  endif
@@ -405,7 +392,7 @@ union yyalloc
 
 #endif
 
-#if YYMODERN_C
+#if ]b4_c_modern[
    typedef signed char yysigned_char;
 #else
    typedef short int yysigned_char;
@@ -747,13 +734,8 @@ int yydebug;
 #   define yystrlen strlen
 #  else
 /* Return the length of YYSTR.  */
-static YYSIZE_T
-#   if YYMODERN_C
-yystrlen (const char *yystr)
-#   else
-yystrlen (yystr)
-     const char *yystr;
-#   endif
+]b4_c_function_def([yystrlen], [static YYSIZE_T],
+   [[const char *yystr], [yystr]])[
 {
   YYSIZE_T yylen;
   for (yylen = 0; yystr[yylen]; yylen++)
@@ -769,14 +751,8 @@ yystrlen (yystr)
 #  else
 /* Copy YYSRC to YYDEST, returning the address of the terminating '\0' in
    YYDEST.  */
-static char *
-#   if YYMODERN_C
-yystpcpy (char *yydest, const char *yysrc)
-#   else
-yystpcpy (yydest, yysrc)
-     char *yydest;
-     const char *yysrc;
-#   endif
+]b4_c_function_def([yystpcpy], [static char *],
+   [[char *yydest], [yydest]], [[const char *yysrc], [yysrc]])[
 {
   char *yyd = yydest;
   const char *yys = yysrc;
@@ -953,11 +929,8 @@ yysyntax_error (char *yyresult, int yyst
 /* Prevent warnings from -Wmissing-prototypes.  */
 
 #ifdef YYPARSE_PARAM
-# if YYMODERN_C
-int yyparse (void *YYPARSE_PARAM);
-# else
-int yyparse ();
-# endif
+]b4_c_function_decl([yyparse], [int],
+   [[void *YYPARSE_PARAM], [YYPARSE_PARAM]])[
 #else /* ! YYPARSE_PARAM */
 ]b4_c_function_decl([yyparse], [int], b4_parse_param)[
 #endif /* ! YYPARSE_PARAM */
@@ -991,12 +964,7 @@ b4_pure_if([],
 `----------*/
 
 #ifdef YYPARSE_PARAM
-# if YYMODERN_C
-int yyparse (void *YYPARSE_PARAM)
-# else
-int yyparse (YYPARSE_PARAM)
-  void *YYPARSE_PARAM;
-# endif
+b4_c_function_def([yyparse], [int], [[void *YYPARSE_PARAM], [YYPARSE_PARAM]])
 #else /* ! YYPARSE_PARAM */
 b4_c_function_def([yyparse], [int], b4_parse_param)
 #endif




reply via email to

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