From 8b562dacc1fbc48e43756efcf9de9d083d6f356c Mon Sep 17 00:00:00 2001 From: zack Date: Sat, 18 Aug 2001 20:46:45 +0000 Subject: [PATCH] include: * ansidecl.h: Reorganize for readability, remove documentation of obsolete macros, document PARAMS and VPARAMS. Add new macros VA_OPEN, VA_CLOSE, and VA_FIXEDARG for nicer variadic function implementation. gcc: * cpperror.c: Use VA_OPEN/VA_CLOSE/VA_FIXEDARG throughout. git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@45011 138bc75d-0d04-0410-961f-82ee72b054a4 --- gcc/ChangeLog | 4 + gcc/cpperror.c | 181 +++++++++--------------------- include/ChangeLog | 7 ++ include/ansidecl.h | 316 ++++++++++++++++++++++++++++++----------------------- 4 files changed, 242 insertions(+), 266 deletions(-) diff --git a/gcc/ChangeLog b/gcc/ChangeLog index 8ada2d2393f..274f22bc2a2 100644 --- a/gcc/ChangeLog +++ b/gcc/ChangeLog @@ -1,5 +1,9 @@ 2001-08-18 Zack Weinberg + * cpperror.c: Use VA_OPEN/VA_CLOSE/VA_FIXEDARG throughout. + +2001-08-18 Zack Weinberg + * haifa-sched.c: Convert to target hooks. Macros replaced are ISSUE_RATE, ADJUST_COST, ADJUST_PRIORITY, MD_SCHED_INIT, MD_SCHED_REORDER, MD_SCHED_REORDER2, MD_SCHED_VARIABLE_ISSUE, diff --git a/gcc/cpperror.c b/gcc/cpperror.c index 84d1c837e23..6b137abcd75 100644 --- a/gcc/cpperror.c +++ b/gcc/cpperror.c @@ -142,22 +142,14 @@ _cpp_begin_message (pfile, code, pos) void cpp_ice VPARAMS ((cpp_reader *pfile, const char *msgid, ...)) { -#ifndef ANSI_PROTOTYPES - cpp_reader *pfile; - const char *msgid; -#endif - va_list ap; - - VA_START (ap, msgid); - -#ifndef ANSI_PROTOTYPES - pfile = va_arg (ap, cpp_reader *); - msgid = va_arg (ap, const char *); -#endif + VA_OPEN (ap, msgid); + VA_FIXEDARG (ap, cpp_reader *, pfile); + VA_FIXEDARG (ap, const char *, msgid); if (_cpp_begin_message (pfile, ICE, 0)) v_message (msgid, ap); - va_end(ap); + + VA_CLOSE (ap); } /* Same as cpp_error, except we consider the error to be "fatal", @@ -169,72 +161,47 @@ cpp_ice VPARAMS ((cpp_reader *pfile, const char *msgid, ...)) void cpp_fatal VPARAMS ((cpp_reader *pfile, const char *msgid, ...)) { -#ifndef ANSI_PROTOTYPES - cpp_reader *pfile; - const char *msgid; -#endif - va_list ap; - - VA_START (ap, msgid); - -#ifndef ANSI_PROTOTYPES - pfile = va_arg (ap, cpp_reader *); - msgid = va_arg (ap, const char *); -#endif + VA_OPEN (ap, msgid); + VA_FIXEDARG (ap, cpp_reader *, pfile); + VA_FIXEDARG (ap, const char *, msgid); if (_cpp_begin_message (pfile, FATAL, 0)) v_message (msgid, ap); - va_end(ap); + + VA_CLOSE (ap); } void cpp_error VPARAMS ((cpp_reader * pfile, const char *msgid, ...)) { -#ifndef ANSI_PROTOTYPES - cpp_reader *pfile; - const char *msgid; -#endif - va_list ap; - - VA_START(ap, msgid); - -#ifndef ANSI_PROTOTYPES - pfile = va_arg (ap, cpp_reader *); - msgid = va_arg (ap, const char *); -#endif + VA_OPEN (ap, msgid); + VA_FIXEDARG (ap, cpp_reader *, pfile); + VA_FIXEDARG (ap, const char *, msgid); if (_cpp_begin_message (pfile, ERROR, 0)) v_message (msgid, ap); - va_end(ap); + + VA_CLOSE (ap); } void cpp_error_with_line VPARAMS ((cpp_reader *pfile, int line, int column, const char *msgid, ...)) { -#ifndef ANSI_PROTOTYPES - cpp_reader *pfile; - int line; - int column; - const char *msgid; -#endif - va_list ap; cpp_lexer_pos pos; - VA_START (ap, msgid); - -#ifndef ANSI_PROTOTYPES - pfile = va_arg (ap, cpp_reader *); - line = va_arg (ap, int); - column = va_arg (ap, int); - msgid = va_arg (ap, const char *); -#endif + VA_OPEN (ap, msgid); + VA_FIXEDARG (ap, cpp_reader *, pfile); + VA_FIXEDARG (ap, int, line); + VA_FIXEDARG (ap, int, column); + VA_FIXEDARG (ap, const char *, msgid); pos.line = line; pos.col = column; if (_cpp_begin_message (pfile, ERROR, &pos)) v_message (msgid, ap); - va_end(ap); + + VA_CLOSE (ap); } /* Error including a message from `errno'. */ @@ -249,127 +216,83 @@ cpp_error_from_errno (pfile, name) void cpp_warning VPARAMS ((cpp_reader * pfile, const char *msgid, ...)) { -#ifndef ANSI_PROTOTYPES - cpp_reader *pfile; - const char *msgid; -#endif - va_list ap; - - VA_START (ap, msgid); - -#ifndef ANSI_PROTOTYPES - pfile = va_arg (ap, cpp_reader *); - msgid = va_arg (ap, const char *); -#endif + VA_OPEN (ap, msgid); + VA_FIXEDARG (ap, cpp_reader *, pfile); + VA_FIXEDARG (ap, const char *, msgid); if (_cpp_begin_message (pfile, WARNING, 0)) v_message (msgid, ap); - va_end(ap); + + VA_CLOSE (ap); } void cpp_warning_with_line VPARAMS ((cpp_reader * pfile, int line, int column, const char *msgid, ...)) { -#ifndef ANSI_PROTOTYPES - cpp_reader *pfile; - int line; - int column; - const char *msgid; -#endif - va_list ap; cpp_lexer_pos pos; - - VA_START (ap, msgid); - -#ifndef ANSI_PROTOTYPES - pfile = va_arg (ap, cpp_reader *); - line = va_arg (ap, int); - column = va_arg (ap, int); - msgid = va_arg (ap, const char *); -#endif + + VA_OPEN (ap, msgid); + VA_FIXEDARG (ap, cpp_reader *, pfile); + VA_FIXEDARG (ap, int, line); + VA_FIXEDARG (ap, int, column); + VA_FIXEDARG (ap, const char *, msgid); pos.line = line; pos.col = column; if (_cpp_begin_message (pfile, WARNING, &pos)) v_message (msgid, ap); - va_end(ap); + + VA_CLOSE (ap); } void cpp_pedwarn VPARAMS ((cpp_reader * pfile, const char *msgid, ...)) { -#ifndef ANSI_PROTOTYPES - cpp_reader *pfile; - const char *msgid; -#endif - va_list ap; - - VA_START (ap, msgid); - -#ifndef ANSI_PROTOTYPES - pfile = va_arg (ap, cpp_reader *); - msgid = va_arg (ap, const char *); -#endif + VA_OPEN (ap, msgid); + VA_FIXEDARG (ap, cpp_reader *, pfile); + VA_FIXEDARG (ap, const char *, msgid); if (_cpp_begin_message (pfile, PEDWARN, 0)) v_message (msgid, ap); - va_end(ap); + + VA_CLOSE (ap); } void cpp_pedwarn_with_line VPARAMS ((cpp_reader * pfile, int line, int column, const char *msgid, ...)) { -#ifndef ANSI_PROTOTYPES - cpp_reader *pfile; - int line; - int column; - const char *msgid; -#endif - va_list ap; cpp_lexer_pos pos; - VA_START (ap, msgid); - -#ifndef ANSI_PROTOTYPES - pfile = va_arg (ap, cpp_reader *); - line = va_arg (ap, int); - column = va_arg (ap, int); - msgid = va_arg (ap, const char *); -#endif + VA_OPEN (ap, msgid); + VA_FIXEDARG (ap, cpp_reader *, pfile); + VA_FIXEDARG (ap, int, line); + VA_FIXEDARG (ap, int, column); + VA_FIXEDARG (ap, const char *, msgid); pos.line = line; pos.col = column; if (_cpp_begin_message (pfile, PEDWARN, &pos)) v_message (msgid, ap); - va_end(ap); + + VA_CLOSE (ap); } /* Print an error message not associated with a file. */ void cpp_notice VPARAMS ((cpp_reader *pfile, const char *msgid, ...)) { -#ifndef ANSI_PROTOTYPES - cpp_reader *pfile; - const char *msgid; -#endif - va_list ap; - - VA_START (ap, msgid); - -#ifndef ANSI_PROTOTYPES - pfile = va_arg (ap, cpp_reader *); - msgid = va_arg (ap, const char *); -#endif + VA_OPEN (ap, msgid); + VA_FIXEDARG (ap, cpp_reader *, pfile); + VA_FIXEDARG (ap, const char *, msgid); if (pfile->errors < CPP_FATAL_LIMIT) pfile->errors++; - vfprintf (stderr, _(msgid), ap); - putc('\n', stderr); + v_message (msgid, ap); - va_end(ap); + VA_CLOSE (ap); } void diff --git a/include/ChangeLog b/include/ChangeLog index 9d0b4e6c98c..ed435beb78f 100644 --- a/include/ChangeLog +++ b/include/ChangeLog @@ -1,3 +1,10 @@ +2001-08-18 Zack Weinberg + + * ansidecl.h: Reorganize for readability, remove documentation + of obsolete macros, document PARAMS and VPARAMS. Add new + macros VA_OPEN, VA_CLOSE, and VA_FIXEDARG for nicer variadic + function implementation. + 2001-08-16 Richard Henderson * hashtab.h (htab_hash_string): Declare. diff --git a/include/ansidecl.h b/include/ansidecl.h index 4ef6db80b75..b7c4c40abff 100644 --- a/include/ansidecl.h +++ b/include/ansidecl.h @@ -1,5 +1,5 @@ /* ANSI and traditional C compatability macros - Copyright 1991, 1992, 1993, 1994, 1995, 1996, 1998, 1999, 2000 + Copyright 1991, 1992, 1993, 1994, 1995, 1996, 1998, 1999, 2000, 2001 Free Software Foundation, Inc. This file is part of the GNU C Library. @@ -21,164 +21,214 @@ Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ ANSI C is assumed if __STDC__ is #defined. - Macro ANSI C definition Traditional C definition - ----- ---- - ---------- ----------- - ---------- - PTR `void *' `char *' - LONG_DOUBLE `long double' `double' - VOLATILE `volatile' `' - SIGNED `signed' `' - PTRCONST `void *const' `char *' - ANSI_PROTOTYPES 1 not defined - - CONST is also defined, but is obsolete. Just use const. - - obsolete -- DEFUN (name, arglist, args) - - Defines function NAME. - - ARGLIST lists the arguments, separated by commas and enclosed in - parentheses. ARGLIST becomes the argument list in traditional C. - - ARGS list the arguments with their types. It becomes a prototype in - ANSI C, and the type declarations in traditional C. Arguments should - be separated with `AND'. For functions with a variable number of - arguments, the last thing listed should be `DOTS'. - - obsolete -- DEFUN_VOID (name) - - Defines a function NAME, which takes no arguments. - - obsolete -- EXFUN (name, (prototype)) -- obsolete. - - Replaced by PARAMS. Do not use; will disappear someday soon. - Was used in external function declarations. - In ANSI C it is `NAME PROTOTYPE' (so PROTOTYPE should be enclosed in - parentheses). In traditional C it is `NAME()'. - For a function that takes no arguments, PROTOTYPE should be `(void)'. - - obsolete -- PROTO (type, name, (prototype) -- obsolete. - - This one has also been replaced by PARAMS. Do not use. - - PARAMS ((args)) - - We could use the EXFUN macro to handle prototype declarations, but - the name is misleading and the result is ugly. So we just define a - simple macro to handle the parameter lists, as in: - - static int foo PARAMS ((int, char)); - - This produces: `static int foo();' or `static int foo (int, char);' - - EXFUN would have done it like this: - - static int EXFUN (foo, (int, char)); - - but the function is not external...and it's hard to visually parse - the function name out of the mess. EXFUN should be considered - obsolete; new code should be written to use PARAMS. - - DOTS is also obsolete. - - Examples: - - extern int printf PARAMS ((const char *format, ...)); -*/ + Macro ANSI C definition Traditional C definition + ----- ---- - ---------- ----------- - ---------- + ANSI_PROTOTYPES 1 not defined + PTR `void *' `char *' + PTRCONST `void *const' `char *' + LONG_DOUBLE `long double' `double' + const not defined `' + volatile not defined `' + signed not defined `' + VA_START(ap, var) va_start(ap, var) va_start(ap) + + Note that it is safe to write "void foo();" indicating a function + with no return value, in all K+R compilers we have been able to test. + + For declaring functions with prototypes, we also provide these: + + PARAMS ((prototype)) + -- for functions which take a fixed number of arguments. Use this + when declaring the function. When defining the function, write a + K+R style argument list. For example: + + char *strcpy PARAMS ((char *dest, char *source)); + ... + char * + strcpy (dest, source) + char *dest; + char *source; + { ... } + + + VPARAMS ((prototype, ...)) + -- for functions which take a variable number of arguments. Use + PARAMS to declare the function, VPARAMS to define it. For example: + + int printf PARAMS ((const char *format, ...)); + ... + int + printf VPARAMS ((const char *format, ...)) + { + ... + } + + For writing functions which take variable numbers of arguments, we + also provide the VA_OPEN, VA_CLOSE, and VA_FIXEDARG macros. These + hide the differences between K+R and C89 more + thoroughly than the simple VA_START() macro mentioned above. + + VA_OPEN and VA_CLOSE are used *instead of* va_start and va_end. + Immediately after VA_OPEN, put a sequence of VA_FIXEDARG calls + corresponding to the list of fixed arguments. Then use va_arg + normally to get the variable arguments, or pass your va_list object + around. You do not declare the va_list yourself; VA_OPEN does it + for you. + + Here is a complete example: + + int + printf VPARAMS ((const char *format, ...)) + { + int result; + + VA_OPEN (ap, format); + VA_FIXEDARG (ap, const char *, format); + + result = vfprintf (stdout, format, ap); + VA_CLOSE (ap); + + return result; + } + + + You can declare variables either before or after the VA_OPEN, + VA_FIXEDARG sequence. You can _not_ put statements before VA_OPEN. + Also, VA_OPEN and VA_CLOSE are the beginning and end of a block. + They must appear at the same nesting level, and any variables + declared after VA_OPEN go out of scope at VA_CLOSE. Unfortunately, + with a K+R compiler, that includes the argument list. + + For ease of writing code which uses GCC extensions but needs to be + portable to other compilers, we provide the GCC_VERSION macro that + simplifies testing __GNUC__ and __GNUC_MINOR__ together, and various + wrappers around __attribute__. Also, __extension__ will be #defined + to nothing if it doesn't work. See below. + + This header also defines a lot of obsolete macros: + CONST, VOLATILE, SIGNED, PROTO, EXFUN, DEFUN, DEFUN_VOID, + AND, DOTS, NOARGS. Don't use them. */ #ifndef _ANSIDECL_H - -#define _ANSIDECL_H 1 - +#define _ANSIDECL_H 1 /* Every source file includes this file, so they will all get the switch for lint. */ /* LINTLIBRARY */ +/* Using MACRO(x,y) in cpp #if conditionals does not work with some + older preprocessors. Thus we can't define something like this: + +#define HAVE_GCC_VERSION(MAJOR, MINOR) \ + (__GNUC__ > (MAJOR) || (__GNUC__ == (MAJOR) && __GNUC_MINOR__ >= (MINOR))) + +and then test "#if HAVE_GCC_VERSION(2,7)". + +So instead we use the macro below and test it against specific values. */ + +/* This macro simplifies testing whether we are using gcc, and if it + is of a particular minimum version. (Both major & minor numbers are + significant.) This macro will evaluate to 0 if we are not using + gcc at all. */ +#ifndef GCC_VERSION +#define GCC_VERSION (__GNUC__ * 1000 + __GNUC_MINOR__) +#endif /* GCC_VERSION */ #if defined (__STDC__) || defined (_AIX) || (defined (__mips) && defined (_SYSTYPE_SVR4)) || defined(_WIN32) /* All known AIX compilers implement these things (but don't always define __STDC__). The RISC/OS MIPS compiler defines these things in SVR4 mode, but does not define __STDC__. */ -#define PTR void * -#define PTRCONST void *CONST -#define LONG_DOUBLE long double - -#ifndef IN_GCC -#define AND , -#define NOARGS void -#define VOLATILE volatile -#define SIGNED signed -#endif /* ! IN_GCC */ - -#define PARAMS(paramlist) paramlist -#define ANSI_PROTOTYPES 1 - -#define VPARAMS(ARGS) ARGS -#define VA_START(va_list,var) va_start(va_list,var) +#define ANSI_PROTOTYPES 1 +#define PTR void * +#define PTRCONST void *const +#define LONG_DOUBLE long double + +#define PARAMS(ARGS) ARGS +#define VPARAMS(ARGS) ARGS +#define VA_START(VA_LIST, VAR) va_start(VA_LIST, VAR) + +/* variadic function helper macros */ +/* "struct Qdmy" swallows the semicolon after VA_OPEN/VA_FIXEDARG's + use without inhibiting further decls and without declaring an + actual variable. */ +#define VA_OPEN(AP, VAR) va_list AP; va_start(AP, VAR); { struct Qdmy +#define VA_CLOSE(AP) } va_end(AP) +#define VA_FIXEDARG(AP, T, N) struct Qdmy + +#undef const +#undef volatile +#undef signed + +/* inline requires special treatment; it's in C99, and GCC >=2.7 supports + it too, but it's not in C89. */ +#undef inline +#if __STDC_VERSION__ > 199901L +/* it's a keyword */ +#else +# if GCC_VERSION >= 2007 +# define inline __inline__ /* __inline__ prevents -pedantic warnings */ +# else +# define inline /* nothing */ +# endif +#endif /* These are obsolete. Do not use. */ #ifndef IN_GCC -#define CONST const -#define DOTS , ... +#define CONST const +#define VOLATILE volatile +#define SIGNED signed + #define PROTO(type, name, arglist) type name arglist #define EXFUN(name, proto) name proto #define DEFUN(name, arglist, args) name(args) #define DEFUN_VOID(name) name(void) +#define AND , +#define DOTS , ... +#define NOARGS void #endif /* ! IN_GCC */ #else /* Not ANSI C. */ -#define PTR char * -#define PTRCONST PTR -#define LONG_DOUBLE double +#undef ANSI_PROTOTYPES +#define PTR char * +#define PTRCONST PTR +#define LONG_DOUBLE double + +#define PARAMS(args) () +#define VPARAMS(args) (va_alist) va_dcl +#define VA_START(va_list, var) va_start(va_list) + +#define VA_OPEN(AP, VAR) va_list AP; va_start(AP); { struct Qdmy +#define VA_CLOSE(AP) } va_end(AP) +#define VA_FIXEDARG(AP, TYPE, NAME) TYPE NAME = va_arg(AP, TYPE) + +/* some systems define these in header files for non-ansi mode */ +#undef const +#undef volatile +#undef signed +#undef inline +#define const +#define volatile +#define signed +#define inline #ifndef IN_GCC -#define AND ; -#define NOARGS -#define VOLATILE -#define SIGNED -#endif /* !IN_GCC */ - -#ifndef const /* some systems define it in header files for non-ansi mode */ -#define const -#endif - -#define PARAMS(paramlist) () - -#define VPARAMS(ARGS) (va_alist) va_dcl -#define VA_START(va_list,var) va_start(va_list) - -/* These are obsolete. Do not use. */ -#ifndef IN_GCC #define CONST -#define DOTS +#define VOLATILE +#define SIGNED + #define PROTO(type, name, arglist) type name () #define EXFUN(name, proto) name() #define DEFUN(name, arglist, args) name arglist args; #define DEFUN_VOID(name) name() +#define AND ; +#define DOTS +#define NOARGS #endif /* ! IN_GCC */ #endif /* ANSI C. */ -/* Using MACRO(x,y) in cpp #if conditionals does not work with some - older preprocessors. Thus we can't define something like this: - -#define HAVE_GCC_VERSION(MAJOR, MINOR) \ - (__GNUC__ > (MAJOR) || (__GNUC__ == (MAJOR) && __GNUC_MINOR__ >= (MINOR))) - -and then test "#if HAVE_GCC_VERSION(2,7)". - -So instead we use the macro below and test it against specific values. */ - -/* This macro simplifies testing whether we are using gcc, and if it - is of a particular minimum version. (Both major & minor numbers are - significant.) This macro will evaluate to 0 if we are not using - gcc at all. */ -#ifndef GCC_VERSION -#define GCC_VERSION (__GNUC__ * 1000 + __GNUC_MINOR__) -#endif /* GCC_VERSION */ - /* Define macros for some gcc attributes. This permits us to use the macros freely, and know that they will come into play for the version of gcc in which they are supported. */ @@ -229,20 +279,12 @@ So instead we use the macro below and test it against specific values. */ #define __extension__ #endif -/* Bootstrap support: Autoconf will possibly define the `inline' or - `const' keywords as macros, however this is only valid for the - stage1 compiler. If we detect a modern version of gcc, - unconditionally reset the values. This makes sure the right thing - happens in stage2 and later. We need to do this very early; - i.e. before any header files that might use these keywords. - Otherwise conflicts might occur. */ - +/* Bootstrap support: Adjust certain macros defined by Autoconf, + which are only valid for the stage1 compiler. If we detect + a modern version of GCC, we are probably in stage2 or beyond, + so unconditionally reset the values. Note that const, inline, + etc. have been dealt with above. */ #if (GCC_VERSION >= 2007) -# ifdef __STDC__ -# undef const -# endif -# undef inline -# define inline __inline__ /* __inline__ prevents -pedantic warnings */ # ifndef HAVE_LONG_DOUBLE # define HAVE_LONG_DOUBLE 1 # endif -- 2.11.0