mirror of
https://sourceware.org/git/binutils-gdb.git
synced 2024-12-27 04:52:05 +08:00
adda0248ed
As Iain reported, my change broke the case when one has bison >= 3, but make decides there is no reason to regenerate plural.c, unfortunately that seems to be a scenario I haven't tested. The problem is that the pregenerated plural.c has been generated with bison 1.35, but when config.h says HAVE_BISON3, the code assumes it is the bison3 variant. What used to work fine is when one has bison >= 3 and plural.c has been regenerated (e.g. do touch intl/plural.y and it will work), or when one doesn't have any bison (then nothing is regenerated, but HAVE_BISON3 isn't defined either), or when one has bison < 3 and doesn't need to regenerate, or when one has bison < 3 and it is regenerated. The following patch fixes this, by killing the HAVE_BISON3 macro from config.h, and instead remembering the fact whether plural.c has been created with bison < 3 or bison >= 3 in a separate new plural-config.h header. The way this works: - user doesn't have bison - user has bison >= 3, but intl/{plural-config.h,plural.c} aren't older than intl/plural.y - user has bison < 3, but intl/{plural-config.h,plural.c} aren't older than intl/plural.y pregenerated !USE_BISON3 plural.c and plural-config.h from source dir is used, nothing in the objdir - user has bison >= 3 and intl/plural.y is newer Makefile generates plural.c and USE_BISON3 plural-config.h in the objdir, which is then used in preference to srcdir copies - user has bison < 3 and intl/plural.y is newer Makefile generates plural.c and !USE_BISON3 plural-config.h in the objdir, which is then used in preference to srcdir copies I have tested all these cases and make all-yes worked in all the cases. If one uses the unsupported ./configure where srcdir == objdir, I guess (though haven't tested) that it should still work, just it would be nice if such people didn't try to check in the plural{.c,-config.h} they have regenerated. What doesn't work, but didn't work before either (just tested gcc-9 branch too) is when one doesn't have bison and plural.y is newer than plural.c. Don't do that ;) intl/ChangeLog 2020-04-16 Jakub Jelinek <jakub@redhat.com> PR bootstrap/92008 * configure.ac: Remove HAVE_BISON3 AC_DEFINE. * Makefile.in (HEADERS): Add plural-config.h. (.y.c): Also create plural-config.h. (dcigettext.o loadmsgcat.o plural.o plural-exp.o): Also depend on plural-config.h. (plural-config.h): Depend on plural.c. * plural-exp.h: Include plural-config.h. Use USE_BISON3 instead of HAVE_BISON3. * plural.y: Use USE_BISON3 instead of HAVE_BISON3. * configure: Regenerated. * plural.c: Regenerated. * config.h.in: Regenerated. * plural-config.h: Generated.
133 lines
4.3 KiB
C
133 lines
4.3 KiB
C
/* Expression parsing and evaluation for plural form selection.
|
|
Copyright (C) 2000-2020 Free Software Foundation, Inc.
|
|
Written by Ulrich Drepper <drepper@cygnus.com>, 2000.
|
|
|
|
This program is free software; you can redistribute it and/or modify it
|
|
under the terms of the GNU Library General Public License as published
|
|
by the Free Software Foundation; either version 2, or (at your option)
|
|
any later version.
|
|
|
|
This program is distributed in the hope that it will be useful,
|
|
but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
|
|
Library General Public License for more details.
|
|
|
|
You should have received a copy of the GNU Library General Public
|
|
License along with this program; if not, write to the Free Software
|
|
Foundation, Inc., 51 Franklin Street - Fifth Floor, Boston, MA 02110-1301,
|
|
USA. */
|
|
|
|
#ifndef _PLURAL_EXP_H
|
|
#define _PLURAL_EXP_H
|
|
|
|
#include <plural-config.h>
|
|
|
|
#ifndef PARAMS
|
|
# if __STDC__ || defined __GNUC__ || defined __SUNPRO_C || defined __cplusplus || __PROTOTYPES
|
|
# define PARAMS(args) args
|
|
# else
|
|
# define PARAMS(args) ()
|
|
# endif
|
|
#endif
|
|
|
|
#ifndef internal_function
|
|
# define internal_function
|
|
#endif
|
|
|
|
#ifndef attribute_hidden
|
|
# define attribute_hidden
|
|
#endif
|
|
|
|
|
|
/* This is the representation of the expressions to determine the
|
|
plural form. */
|
|
struct expression
|
|
{
|
|
int nargs; /* Number of arguments. */
|
|
enum operator
|
|
{
|
|
/* Without arguments: */
|
|
var, /* The variable "n". */
|
|
num, /* Decimal number. */
|
|
/* Unary operators: */
|
|
lnot, /* Logical NOT. */
|
|
/* Binary operators: */
|
|
mult, /* Multiplication. */
|
|
divide, /* Division. */
|
|
module, /* Modulo operation. */
|
|
plus, /* Addition. */
|
|
minus, /* Subtraction. */
|
|
less_than, /* Comparison. */
|
|
greater_than, /* Comparison. */
|
|
less_or_equal, /* Comparison. */
|
|
greater_or_equal, /* Comparison. */
|
|
equal, /* Comparison for equality. */
|
|
not_equal, /* Comparison for inequality. */
|
|
land, /* Logical AND. */
|
|
lor, /* Logical OR. */
|
|
/* Ternary operators: */
|
|
qmop /* Question mark operator. */
|
|
} operation;
|
|
union
|
|
{
|
|
unsigned long int num; /* Number value for `num'. */
|
|
struct expression *args[3]; /* Up to three arguments. */
|
|
} val;
|
|
};
|
|
|
|
/* This is the data structure to pass information to the parser and get
|
|
the result in a thread-safe way. */
|
|
struct parse_args
|
|
{
|
|
const char *cp;
|
|
struct expression *res;
|
|
};
|
|
|
|
|
|
/* Names for the libintl functions are a problem. This source code is used
|
|
1. in the GNU C Library library,
|
|
2. in the GNU libintl library,
|
|
3. in the GNU gettext tools.
|
|
The function names in each situation must be different, to allow for
|
|
binary incompatible changes in 'struct expression'. Furthermore,
|
|
1. in the GNU C Library library, the names have a __ prefix,
|
|
2.+3. in the GNU libintl library and in the GNU gettext tools, the names
|
|
must follow ANSI C and not start with __.
|
|
So we have to distinguish the three cases. */
|
|
#ifdef _LIBC
|
|
# define FREE_EXPRESSION __gettext_free_exp
|
|
# define PLURAL_PARSE __gettextparse
|
|
# define GERMANIC_PLURAL __gettext_germanic_plural
|
|
# define EXTRACT_PLURAL_EXPRESSION __gettext_extract_plural
|
|
#elif defined (IN_LIBINTL)
|
|
# define FREE_EXPRESSION libintl_gettext_free_exp
|
|
# define PLURAL_PARSE libintl_gettextparse
|
|
# define GERMANIC_PLURAL libintl_gettext_germanic_plural
|
|
# define EXTRACT_PLURAL_EXPRESSION libintl_gettext_extract_plural
|
|
#else
|
|
# define FREE_EXPRESSION free_plural_expression
|
|
# define PLURAL_PARSE parse_plural_expression
|
|
# define GERMANIC_PLURAL germanic_plural
|
|
# define EXTRACT_PLURAL_EXPRESSION extract_plural_expression
|
|
#endif
|
|
|
|
extern void FREE_EXPRESSION PARAMS ((struct expression *exp))
|
|
internal_function;
|
|
#ifdef USE_BISON3
|
|
extern int PLURAL_PARSE PARAMS ((struct parse_args *arg));
|
|
#else
|
|
extern int PLURAL_PARSE PARAMS ((void *arg));
|
|
#endif
|
|
extern struct expression GERMANIC_PLURAL attribute_hidden;
|
|
extern void EXTRACT_PLURAL_EXPRESSION PARAMS ((const char *nullentry,
|
|
struct expression **pluralp,
|
|
unsigned long int *npluralsp))
|
|
internal_function;
|
|
|
|
#if !defined (_LIBC) && !defined (IN_LIBINTL)
|
|
extern unsigned long int plural_eval PARAMS ((struct expression *pexp,
|
|
unsigned long int n));
|
|
#endif
|
|
|
|
#endif /* _PLURAL_EXP_H */
|