+2000-10-02 Akim Demaille <akim@epita.fr>
+
+ Use the more standard files `xalloc.h' and `xmalloc.c' instead of
+ Bison's `allocate.c' and `alloc.h'. This patch was surprisingly
+ difficult and introduced a lot of core dump. It turns out that
+ Bison used an implementation of `xmalloc' based on `calloc', and
+ at various places it does depend upon the initialization to 0. I
+ have not tried to isolate the pertinent places, and all the former
+ calls to Bison's `xmalloc' are now using `XCALLOC'. Someday,
+ someone should address this issue.
+
+ * src/allocate.c, src/alloc.h, m4/bison-decl.m4: Remove.
+ * lib/xmalloc.c, lib/xalloc.h, m4/malloc.m4, m4/realloc.m4: New
+ files.
+ Adjust dependencies.
+ * src/warshall.h: New file.
+ Propagate.
+
2000-10-02 Akim Demaille <akim@epita.fr>
Various anti-`extern in *.c' changes.
* src/system.h: Include `assert.h'.
-
+
2000-10-02 Akim Demaille <akim@epita.fr>
* src/state.h (nstates, final_state, first_state, first_shift)
Remove a lot of now useless `extern' statements in most files.
-
+
2000-10-02 Akim Demaille <akim@epita.fr>
* src/LR0.h: New file.
Propagate its use.
-
+
2000-10-02 Akim Demaille <akim@epita.fr>
* src/print.h: New file.
(print_results): this new function.
Adjust dependencies.
-
+
2000-10-02 Akim Demaille <akim@epita.fr>
* src/conflicts.c (conflict_report): New function.
* src/conflicts.h: New file.
Propagate its inclusion.
-
+
2000-10-02 Akim Demaille <akim@epita.fr>
* src/nullable.h: New file.
Propagate its inclusion.
* src/nullable.c: Formatting changes.
-
+
2000-10-02 Akim Demaille <akim@epita.fr>
* src/reduce.h: New file.
# Checks for library functions.
AC_FUNC_ALLOCA
AC_CHECK_FUNCS(mkstemp setlocale)
-BISON_NEED_DECLARATIONS(calloc realloc)
+jm_FUNC_MALLOC
+jm_FUNC_REALLOC
ALL_LINGUAS="de es et fr ja nl ru"
AM_GNU_GETTEXT
INCLUDES = -I.. -I$(srcdir) -I../intl
-libbison_a_SOURCES = getopt.c getopt1.c
-noinst_HEADERS = getopt.h
+libbison_a_SOURCES = getopt.c getopt1.c xmalloc.c
+noinst_HEADERS = getopt.h xalloc.h
libbison_a_LIBADD = @LIBOBJS@ @ALLOCA@
libbison_a_DEPENDENCIES = $(libbison_a_LIBADD)
--- /dev/null
+/* xalloc.h -- malloc with out-of-memory checking
+ Copyright (C) 1990-1998, 1999 Free Software Foundation, Inc.
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU 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 General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software Foundation,
+ Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
+
+#ifndef XALLOC_H_
+# define XALLOC_H_
+
+# ifndef PARAMS
+# if defined PROTOTYPES || (defined __STDC__ && __STDC__)
+# define PARAMS(Args) Args
+# else
+# define PARAMS(Args) ()
+# endif
+# endif
+
+# ifndef __attribute__
+# if __GNUC__ < 2 || (__GNUC__ == 2 && __GNUC_MINOR__ < 8) || __STRICT_ANSI__
+# define __attribute__(x)
+# endif
+# endif
+
+# ifndef ATTRIBUTE_NORETURN
+# define ATTRIBUTE_NORETURN __attribute__ ((__noreturn__))
+# endif
+
+/* Exit value when the requested amount of memory is not available.
+ It is initialized to EXIT_FAILURE, but the caller may set it to
+ some other value. */
+extern int xalloc_exit_failure;
+
+/* If this pointer is non-zero, run the specified function upon each
+ allocation failure. It is initialized to zero. */
+extern void (*xalloc_fail_func) PARAMS ((void));
+
+/* If XALLOC_FAIL_FUNC is undefined or a function that returns, this
+ message must be non-NULL. It is translated via gettext.
+ The default value is "Memory exhausted". */
+extern char *const xalloc_msg_memory_exhausted;
+
+/* This function is always triggered when memory is exhausted. It is
+ in charge of honoring the three previous items. This is the
+ function to call when one wants the program to die because of a
+ memory allocation failure. */
+extern void xalloc_die PARAMS ((void)) ATTRIBUTE_NORETURN;
+
+void *xmalloc PARAMS ((size_t n));
+void *xcalloc PARAMS ((size_t n, size_t s));
+void *xrealloc PARAMS ((void *p, size_t n));
+char *xstrdup PARAMS ((const char *str));
+
+# define XMALLOC(Type, N_items) ((Type *) xmalloc (sizeof (Type) * (N_items)))
+# define XCALLOC(Type, N_items) ((Type *) xcalloc (sizeof (Type), (N_items)))
+# define XREALLOC(Ptr, Type, N_items) \
+ ((Type *) xrealloc ((void *) (Ptr), sizeof (Type) * (N_items)))
+
+/* Declare and alloc memory for VAR of type TYPE. */
+# define NEW(Type, Var) Type *(Var) = XMALLOC (Type, 1)
+
+/* Free VAR only if non NULL. */
+# define XFREE(Var) \
+ do { \
+ if (Var) \
+ free (Var); \
+ } while (0)
+
+/* Return a pointer to a malloc'ed copy of the array SRC of NUM elements. */
+# define CCLONE(Src, Num) \
+ (memcpy (xmalloc (sizeof (*Src) * (Num)), (Src), sizeof (*Src) * (Num)))
+
+/* Return a malloc'ed copy of SRC. */
+# define CLONE(Src) CCLONE (Src, 1)
+
+
+#endif /* !XALLOC_H_ */
--- /dev/null
+/* xmalloc.c -- malloc with out of memory checking
+ Copyright (C) 1990-1997, 98, 99 Free Software Foundation, Inc.
+
+ This program is free software; you can redistribute it and/or modify
+ it under the terms of the GNU 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 General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with this program; if not, write to the Free Software Foundation,
+ Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */
+
+#if HAVE_CONFIG_H
+# include <config.h>
+#endif
+
+#include <sys/types.h>
+
+#if STDC_HEADERS
+# include <stdlib.h>
+#else
+void *calloc ();
+void *malloc ();
+void *realloc ();
+void free ();
+#endif
+
+#if ENABLE_NLS
+# include <libintl.h>
+# define _(Text) gettext (Text)
+#else
+# define textdomain(Domain)
+# define _(Text) Text
+#endif
+#define N_(Text) Text
+
+#include "error.h"
+#include "xalloc.h"
+
+#ifndef EXIT_FAILURE
+# define EXIT_FAILURE 1
+#endif
+
+#ifndef HAVE_DONE_WORKING_MALLOC_CHECK
+you must run the autoconf test for a properly working malloc -- see malloc.m4
+#endif
+
+#ifndef HAVE_DONE_WORKING_REALLOC_CHECK
+you must run the autoconf test for a properly working realloc -- see realloc.m4
+#endif
+
+/* Exit value when the requested amount of memory is not available.
+ The caller may set it to some other value. */
+int xalloc_exit_failure = EXIT_FAILURE;
+
+/* If non NULL, call this function when memory is exhausted. */
+void (*xalloc_fail_func) PARAMS ((void)) = 0;
+
+/* If XALLOC_FAIL_FUNC is NULL, or does return, display this message
+ before exiting when memory is exhausted. Goes through gettext. */
+char *const xalloc_msg_memory_exhausted = N_("Memory exhausted");
+
+void
+xalloc_die (void)
+{
+ if (xalloc_fail_func)
+ (*xalloc_fail_func) ();
+ error (xalloc_exit_failure, 0, "%s", _(xalloc_msg_memory_exhausted));
+ /* The `noreturn' cannot be given to error, since it may return if
+ its first argument is 0. To help compilers understand the
+ xalloc_die does terminate, call exit. */
+ exit (EXIT_FAILURE);
+}
+
+/* Allocate N bytes of memory dynamically, with error checking. */
+
+void *
+xmalloc (size_t n)
+{
+ void *p;
+
+ p = malloc (n);
+ if (p == 0)
+ xalloc_die ();
+ return p;
+}
+
+/* Change the size of an allocated block of memory P to N bytes,
+ with error checking.
+ If P is NULL, run xmalloc. */
+
+void *
+xrealloc (void *p, size_t n)
+{
+ p = realloc (p, n);
+ if (p == 0)
+ xalloc_die ();
+ return p;
+}
+
+/* Allocate memory for N elements of S bytes, with error checking. */
+
+void *
+xcalloc (size_t n, size_t s)
+{
+ void *p;
+
+ p = calloc (n, s);
+ if (p == 0)
+ xalloc_die ();
+ return p;
+}
## Process this file with automake to produce Makefile.in -*-Makefile-*-
EXTRA_DIST = \
atconfig.m4 \
-bison-decl.m4 \
error.m4 \
gettext.m4 \
lcmessage.m4 \
m4.m4 \
+malloc.m4 \
progtest.m4 \
+realloc.m4 \
warning.m4
-dnl FIXME: This should be soon obsoleted by AC_CHECK_DECL.
-
-dnl See whether we need a declaration for a function.
-dnl BISON_NEED_DECLARATION(FUNCTION [, EXTRA-HEADER-FILES])
-AC_DEFUN(BISON_NEED_DECLARATION,
-[AC_MSG_CHECKING([whether $1 must be declared])
-AC_CACHE_VAL(bison_cv_decl_needed_$1,
-[AC_TRY_COMPILE([
-#include <stdio.h>
-#ifdef HAVE_STRING_H
-#include <string.h>
-#else
-#ifdef HAVE_STRINGS_H
-#include <strings.h>
-#endif
-#endif
-#ifdef HAVE_STDLIB_H
-#include <stdlib.h>
-#endif
-#ifdef HAVE_UNISTD_H
-#include <unistd.h>
-#endif
-#ifndef HAVE_RINDEX
-#define rindex strrchr
-#endif
-#ifndef HAVE_INDEX
-#define index strchr
-#endif
-$2],
-[char *(*pfn) = (char *(*)) $1],
-eval "bison_cv_decl_needed_$1=no", eval "bison_cv_decl_needed_$1=yes")])
-if eval "test \"`echo '$bison_cv_decl_needed_'$1`\" = yes"; then
- AC_MSG_RESULT(yes)
- bison_tr_decl=NEED_DECLARATION_`echo $1 | tr 'abcdefghijklmnopqrstuvwxyz' 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'`
- AC_DEFINE_UNQUOTED($bison_tr_decl)
-else
- AC_MSG_RESULT(no)
-fi
-])dnl
-
-dnl Check multiple functions to see whether each needs a declaration.
-dnl BISON_NEED_DECLARATIONS(FUNCTION... [, EXTRA-HEADER-FILES])
-AC_DEFUN(BISON_NEED_DECLARATIONS,
-[for ac_func in $1
-do
-BISON_NEED_DECLARATION($ac_func, $2)
-done
-])
--- /dev/null
+#serial 3
+
+dnl From Jim Meyering.
+dnl Determine whether malloc accepts 0 as its argument.
+dnl If it doesn't, arrange to use the replacement function.
+dnl
+
+AC_DEFUN(jm_FUNC_MALLOC,
+[
+ dnl xmalloc.c requires that this symbol be defined so it doesn't
+ dnl mistakenly use a broken malloc -- as it might if this test were omitted.
+ AC_DEFINE_UNQUOTED(HAVE_DONE_WORKING_MALLOC_CHECK, 1,
+ [Define if the malloc check has been performed. ])
+
+ AC_CACHE_CHECK([for working malloc], jm_cv_func_working_malloc,
+ [AC_TRY_RUN([
+ char *malloc ();
+ int
+ main ()
+ {
+ exit (malloc (0) ? 0 : 1);
+ }
+ ],
+ jm_cv_func_working_malloc=yes,
+ jm_cv_func_working_malloc=no,
+ dnl When crosscompiling, assume malloc is broken.
+ jm_cv_func_working_malloc=no)
+ ])
+ if test $jm_cv_func_working_malloc = no; then
+ AC_SUBST(LIBOBJS)
+ LIBOBJS="$LIBOBJS malloc.$ac_objext"
+ AC_DEFINE_UNQUOTED(malloc, rpl_malloc,
+ [Define to rpl_malloc if the replacement function should be used.])
+ fi
+])
--- /dev/null
+#serial 3
+
+dnl From Jim Meyering.
+dnl Determine whether realloc works when both arguments are 0.
+dnl If it doesn't, arrange to use the replacement function.
+dnl
+
+AC_DEFUN(jm_FUNC_REALLOC,
+[
+ dnl xmalloc.c requires that this symbol be defined so it doesn't
+ dnl mistakenly use a broken realloc -- as it might if this test were omitted.
+ AC_DEFINE_UNQUOTED(HAVE_DONE_WORKING_REALLOC_CHECK, 1,
+ [Define if the realloc check has been performed. ])
+
+ AC_CACHE_CHECK([for working realloc], jm_cv_func_working_realloc,
+ [AC_TRY_RUN([
+ char *realloc ();
+ int
+ main ()
+ {
+ exit (realloc (0, 0) ? 0 : 1);
+ }
+ ],
+ jm_cv_func_working_realloc=yes,
+ jm_cv_func_working_realloc=no,
+ dnl When crosscompiling, assume realloc is broken.
+ jm_cv_func_working_realloc=no)
+ ])
+ if test $jm_cv_func_working_realloc = no; then
+ AC_SUBST(LIBOBJS)
+ LIBOBJS="$LIBOBJS realloc.$ac_objext"
+ AC_DEFINE_UNQUOTED(realloc, rpl_realloc,
+ [Define to rpl_realloc if the replacement function should be used.])
+ fi
+])
The entry point is generate_states. */
#include "system.h"
-#include "alloc.h"
+#include "xalloc.h"
#include "gram.h"
#include "state.h"
#include "complain.h"
short *symbol_count;
count = 0;
- symbol_count = NEW2 (nsyms, short);
+ symbol_count = XCALLOC (short, nsyms);
itemp = ritem;
symbol = *itemp++;
appears as an item, which is symbol_count[symbol].
We allocate that much space for each symbol. */
- kernel_base = NEW2 (nsyms, short *);
- kernel_items = NEW2 (count, short);
+ kernel_base = XCALLOC (short *, nsyms);
+ kernel_items = XCALLOC (short, count);
count = 0;
for (i = 0; i < nsyms; i++)
}
shift_symbol = symbol_count;
- kernel_end = NEW2 (nsyms, short *);
+ kernel_end = XCALLOC (short *, nsyms);
}
{
allocate_itemsets ();
- shiftset = NEW2 (nsyms, short);
- redset = NEW2 (nrules + 1, short);
- state_table = NEW2 (STATE_TABLE_SIZE, core *);
+ shiftset = XCALLOC (short, nsyms);
+ redset = XCALLOC (short, nrules + 1);
+ state_table = XCALLOC (core *, STATE_TABLE_SIZE);
}
static void
free_storage (void)
{
- FREE (shift_symbol);
- FREE (redset);
- FREE (shiftset);
- FREE (kernel_base);
- FREE (kernel_end);
- FREE (kernel_items);
- FREE (state_table);
+ XFREE (shift_symbol);
+ XFREE (redset);
+ XFREE (shiftset);
+ XFREE (kernel_base);
+ XFREE (kernel_end);
+ XFREE (kernel_items);
+ XFREE (state_table);
}
n = iend - isp1;
p =
- (core *) xmalloc ((unsigned) (sizeof (core) + (n - 1) * sizeof (short)));
+ (core *) xcalloc ((unsigned) (sizeof (core) + (n - 1) * sizeof (short)), 1);
p->accessing_symbol = symbol;
p->number = nstates;
p->nitems = n;
{
core *p;
- p = (core *) xmalloc ((unsigned) (sizeof (core) - sizeof (short)));
+ p = (core *) xcalloc ((unsigned) (sizeof (core) - sizeof (short)), 1);
first_state = last_state = this_state = p;
nstates = 1;
}
short *sp2;
short *send;
- p = (shifts *) xmalloc ((unsigned) (sizeof (shifts) +
- (nshifts - 1) * sizeof (short)));
+ p = (shifts *) xcalloc ((unsigned) (sizeof (shifts) +
+ (nshifts - 1) * sizeof (short)), 1);
p->number = this_state->number;
p->nshifts = nshifts;
core *statep;
shifts *sp;
- statep = (core *) xmalloc ((unsigned) (sizeof (core) - sizeof (short)));
+ statep = (core *) xcalloc ((unsigned) (sizeof (core) - sizeof (short)), 1);
statep->number = nstates;
statep->accessing_symbol = start_symbol;
last_state = statep;
/* Make a shift from this state to (what will be) the final state. */
- sp = NEW (shifts);
+ sp = XCALLOC (shifts, 1);
sp->number = nstates++;
sp->nshifts = 1;
sp->shifts[0] = nstates;
if (sp && sp->number == k)
{
- sp2 = (shifts *) xmalloc ((unsigned) (sizeof (shifts)
+ sp2 = (shifts *) xcalloc ((unsigned) (sizeof (shifts)
+
sp->nshifts *
- sizeof (short)));
+ sizeof (short)), 1);
sp2->number = k;
sp2->nshifts = sp->nshifts + 1;
sp2->shifts[0] = nstates;
sp1->next = sp2;
if (sp == last_shift)
last_shift = sp2;
- FREE (sp);
+ XFREE (sp);
}
else
{
- sp2 = NEW (shifts);
+ sp2 = XCALLOC (shifts, 1);
sp2->number = k;
sp2->nshifts = 1;
sp2->shifts[0] = nstates;
going to the next-to-final state (yet to be made). */
sp = first_shift;
- sp2 = (shifts *) xmalloc (sizeof (shifts)
- + sp->nshifts * sizeof (short));
+ sp2 = (shifts *) xcalloc (sizeof (shifts)
+ + sp->nshifts * sizeof (short), 1);
sp2->nshifts = sp->nshifts + 1;
/* Stick this shift into the vector at the proper place. */
if (last_shift == sp)
last_shift = sp2;
- FREE (sp);
+ XFREE (sp);
/* Create the next-to-final state, with shift to
what will be the final state. */
{
/* The initial state didn't even have any shifts.
Give it one shift, to the next-to-final state. */
- sp = NEW (shifts);
+ sp = XCALLOC (shifts, 1);
sp->nshifts = 1;
sp->shifts[0] = nstates;
/* There are no shifts for any state.
Make one shift, from the initial state to the next-to-final state. */
- sp = NEW (shifts);
+ sp = XCALLOC (shifts, 1);
sp->nshifts = 1;
sp->shifts[0] = nstates;
/* Make the final state--the one that follows a shift from the
next-to-final state.
The symbol for that shift is 0 (end-of-file). */
- statep = (core *) xmalloc ((unsigned) (sizeof (core) - sizeof (short)));
+ statep = (core *) xcalloc ((unsigned) (sizeof (core) - sizeof (short)), 1);
statep->number = nstates;
last_state->next = statep;
last_state = statep;
/* Make the shift from the final state to the termination state. */
- sp = NEW (shifts);
+ sp = XCALLOC (shifts, 1);
sp->number = nstates++;
sp->nshifts = 1;
sp->shifts[0] = nstates;
final_state = nstates;
/* Make the termination state. */
- statep = (core *) xmalloc ((unsigned) (sizeof (core) - sizeof (short)));
+ statep = (core *) xcalloc ((unsigned) (sizeof (core) - sizeof (short)), 1);
statep->number = nstates++;
last_state->next = statep;
last_state = statep;
if (count)
{
- p = (reductions *) xmalloc ((unsigned) (sizeof (reductions) +
- (count - 1) * sizeof (short)));
+ p = (reductions *) xcalloc ((unsigned) (sizeof (reductions) +
+ (count - 1) * sizeof (short)), 1);
p->number = this_state->number;
p->nreds = count;
bin_PROGRAMS = bison
-bison_SOURCES = LR0.c allocate.c closure.c complain.c conflicts.c \
+bison_SOURCES = LR0.c closure.c complain.c conflicts.c \
derives.c \
files.c getargs.c gram.c lalr.c lex.c main.c nullable.c \
output.c \
EXTRA_bison_SOURCES = vmsgetargs.c
-noinst_HEADERS = LR0.h alloc.h closure.h complain.h conflicts.h \
+noinst_HEADERS = LR0.h closure.h complain.h conflicts.h \
derives.h \
files.h getargs.h gram.h lalr.h lex.h nullable.h \
output.h state.h \
- print.h reader.h reduce.h symtab.h system.h types.h
+ print.h reader.h reduce.h symtab.h warshall.h system.h types.h
data_DATA = bison.simple bison.hairy
-/* Storage allocation interface for bison,
- Copyright (C) 1984, 1989 Free Software Foundation, Inc.
-
-This file is part of Bison, the GNU Compiler Compiler.
-
-Bison is free software; you can redistribute it and/or modify
-it under the terms of the GNU General Public License as published by
-the Free Software Foundation; either version 2, or (at your option)
-any later version.
-
-Bison 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 General Public License for more details.
-
-You should have received a copy of the GNU General Public License
-along with Bison; see the file COPYING. If not, write to
-the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
-Boston, MA 02111-1307, USA. */
-
-
-#ifdef HAVE_CONFIG_H
-#include "config.h"
-#endif
-
-#define NEW(t) ((t *) xmalloc((unsigned) sizeof(t)))
-#define NEW2(n, t) ((t *) xmalloc((unsigned) ((n) * sizeof(t))))
-
-#ifdef __STDC__
-#define FREE(x) (x ? (void) free((char *) (x)) : (void)0)
-#else
-#define FREE(x) ((x) != 0 && (free ((char *) (x)), 0))
-#endif
-
-extern char *xmalloc PARAMS((register unsigned));
-extern char *xrealloc PARAMS((register char *, register unsigned));
-/* Allocate and clear storage for bison,
- Copyright (C) 1984, 1989 Free Software Foundation, Inc.
-
-This file is part of Bison, the GNU Compiler Compiler.
-
-Bison is free software; you can redistribute it and/or modify
-it under the terms of the GNU General Public License as published by
-the Free Software Foundation; either version 2, or (at your option)
-any later version.
-
-Bison 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 General Public License for more details.
-
-You should have received a copy of the GNU General Public License
-along with Bison; see the file COPYING. If not, write to
-the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
-Boston, MA 02111-1307, USA. */
-
-
-#include "system.h"
-
-#ifdef NEED_DECLARATION_CALLOC
-#if defined (__STDC__) || defined (_MSC_VER)
-extern void *calloc ();
-#else
-extern char *calloc ();
-#endif
-#endif /* NEED_DECLARATION_CALLOC */
-
-#ifdef NEED_DECLARATION_REALLOC
-#if defined (__STDC__) || defined (_MSC_VER)
-extern void *realloc ();
-#else
-extern char *realloc ();
-#endif
-#endif /* NEED_DECLARATION_REALLOC */
-
-extern char *xmalloc PARAMS((register unsigned));
-extern char *xrealloc PARAMS((register char *, register unsigned));
-
-extern void done PARAMS((int));
-
-extern char *program_name;
-
-char *
-xmalloc (register unsigned n)
-{
- register char *block;
-
- /* Avoid uncertainty about what an arg of 0 will do. */
- if (n == 0)
- n = 1;
- block = calloc (n, 1);
- if (block == NULL)
- {
- fprintf (stderr, _("%s: memory exhausted\n"), program_name);
- done (1);
- }
-
- return block;
-}
-
-char *
-xrealloc (register char *block, register unsigned n)
-{
- /* Avoid uncertainty about what an arg of 0 will do. */
- if (n == 0)
- n = 1;
- block = realloc (block, n);
- if (block == NULL)
- {
- fprintf (stderr, _("%s: memory exhausted\n"), program_name);
- done (1);
- }
-
- return block;
-}
02111-1307, USA. */
#include "system.h"
-#include "alloc.h"
+#include "xalloc.h"
#include "gram.h"
#include "closure.h"
#include "derives.h"
+#include "warshall.h"
short *itemset;
short *itemsetend;
varsetsize = rowsize = WORDSIZE (nvars);
- firsts = NEW2 (nvars * rowsize, unsigned);
+ firsts = XCALLOC (unsigned, nvars * rowsize);
row = firsts;
for (i = ntokens; i < nsyms; i++)
int ruleno;
int i;
- fderives = NEW2 (nvars * rulesetsize, unsigned) - ntokens * rulesetsize;
+ fderives = XCALLOC (unsigned, nvars * rulesetsize) - ntokens * rulesetsize;
set_firsts ();
print_fderives ();
#endif
- FREE (firsts);
+ XFREE (firsts);
}
\f
void
new_closure (int n)
{
- itemset = NEW2 (n, short);
+ itemset = XCALLOC (short, n);
rulesetsize = WORDSIZE (nrules + 1);
- ruleset = NEW2 (rulesetsize, unsigned);
+ ruleset = XCALLOC (unsigned, rulesetsize);
set_fderives ();
}
void
free_closure (void)
{
- FREE (itemset);
- FREE (ruleset);
- FREE (fderives + ntokens * rulesetsize);
+ XFREE (itemset);
+ XFREE (ruleset);
+ XFREE (fderives + ntokens * rulesetsize);
}
#include "system.h"
#include "getargs.h"
-#include "alloc.h"
+#include "xalloc.h"
#include "files.h"
#include "gram.h"
#include "state.h"
unsigned *fp1;
unsigned *fp2;
int redprec;
- errs *errp = (errs *) xmalloc (sizeof (errs) + ntokens * sizeof (short));
+ errs *errp = (errs *) xcalloc (sizeof (errs) + ntokens * sizeof (short), 1);
short *errtokens = errp->errs;
/* find the rule to reduce by to get precedence of reduction */
/* Some tokens have been explicitly made errors. Allocate
a permanent errs structure for this state, to record them. */
i = (char *) errtokens - (char *) errp;
- err_table[state] = (errs *) xmalloc ((unsigned int) i);
+ err_table[state] = (errs *) xcalloc ((unsigned int) i, 1);
bcopy (errp, err_table[state], i);
}
else
{
int i;
- conflicts = NEW2 (nstates, char);
- shiftset = NEW2 (tokensetsize, unsigned);
- lookaheadset = NEW2 (tokensetsize, unsigned);
+ conflicts = XCALLOC (char, nstates);
+ shiftset = XCALLOC (unsigned, tokensetsize);
+ lookaheadset = XCALLOC (unsigned, tokensetsize);
- err_table = NEW2 (nstates, errs *);
+ err_table = XCALLOC (errs *, nstates);
any_conflicts = 0;
void
finalize_conflicts (void)
{
- FREE (conflicts);
- FREE (shiftset);
- FREE (lookaheadset);
+ XFREE (conflicts);
+ XFREE (shiftset);
+ XFREE (lookaheadset);
}
*/
#include "system.h"
-#include "alloc.h"
+#include "xalloc.h"
#include "types.h"
#include "gram.h"
#include "derives.h"
static void
print_derives (void)
{
- register int i;
- register short *sp;
+ int i;
+ short *sp;
printf (_("\n\n\nDERIVES\n\n"));
void
set_derives (void)
{
- register int i;
- register int lhs;
- register shorts *p;
- register short *q;
- register shorts **dset;
- register shorts *delts;
+ int i;
+ int lhs;
+ shorts *p;
+ short *q;
+ shorts **dset;
+ shorts *delts;
- dset = NEW2 (nvars, shorts *) - ntokens;
- delts = NEW2 (nrules + 1, shorts);
+ dset = XCALLOC (shorts *, nvars) - ntokens;
+ delts = XCALLOC (shorts, nrules + 1);
p = delts;
for (i = nrules; i > 0; i--)
}
}
- derives = NEW2 (nvars, short *) - ntokens;
- q = NEW2 (nvars + nrules, short);
+ derives = XCALLOC (short *, nvars) - ntokens;
+ q = XCALLOC (short, nvars + nrules);
for (i = ntokens; i < nsyms; i++)
{
print_derives ();
#endif
- FREE (dset + ntokens);
- FREE (delts);
+ XFREE (dset + ntokens);
+ XFREE (delts);
}
void
free_derives (void)
{
- FREE (derives[ntokens]);
- FREE (derives + ntokens);
+ XFREE (derives[ntokens]);
+ XFREE (derives + ntokens);
}
#include "getargs.h"
#include "files.h"
-#include "alloc.h"
+#include "xalloc.h"
#include "gram.h"
#include "complain.h"
while (*cp1++)
i++;
- ostring = NEW2 (i + end1 + 1, char);
+ ostring = XCALLOC (char, i + end1 + 1);
cp = ostring;
cp1 = string1;
short_base_length = strlen (spec_file_prefix);
/* Count room for `.tab'. */
base_length = short_base_length + 4;
- name_base = (char *) xmalloc (base_length + 1);
+ name_base = XMALLOC (char, base_length + 1);
/* Append `.tab'. */
strcpy (name_base, spec_file_prefix);
#ifdef VMS
cp = getenv ("INIT");
if (filename == 0 && cp != NULL)
{
- filename = xmalloc (strlen (cp) + strlen (PFILE) + 2);
+ filename = XMALLOC (char, strlen (cp) + strlen (PFILE) + 2);
strcpy (filename, cp);
cp = filename + strlen (filename);
*cp++ = '/';
cp = getenv ("INIT");
if (filename == 0 && cp != NULL)
{
- filename = xmalloc (strlen (cp) + strlen (PFILE1) + 2);
+ filename = XMALLOC (char, strlen (cp) + strlen (PFILE1) + 2);
strcpy (filename, cp);
cp = filename + strlen (filename);
*cp++ = '/';
#include "system.h"
#include "types.h"
#include "LR0.h"
-#include "alloc.h"
+#include "xalloc.h"
#include "gram.h"
#include "complain.h"
#include "lalr.h"
int i;
infinity = ngotos + 2;
- INDEX = NEW2 (ngotos + 1, short);
- VERTICES = NEW2 (ngotos + 1, short);
+ INDEX = XCALLOC (short, ngotos + 1);
+ VERTICES = XCALLOC (short, ngotos + 1);
top = 0;
R = relation;
traverse (i);
}
- FREE (INDEX);
- FREE (VERTICES);
+ XFREE (INDEX);
+ XFREE (VERTICES);
}
static void
{
core *sp;
- state_table = NEW2 (nstates, core *);
+ state_table = XCALLOC (core *, nstates);
for (sp = first_state; sp; sp = sp->next)
state_table[sp->number] = sp;
{
core *sp;
- accessing_symbol = NEW2 (nstates, short);
+ accessing_symbol = XCALLOC (short, nstates);
for (sp = first_state; sp; sp = sp->next)
accessing_symbol[sp->number] = sp->accessing_symbol;
{
shifts *sp;
- shift_table = NEW2 (nstates, shifts *);
+ shift_table = XCALLOC (shifts *, nstates);
for (sp = first_shift; sp; sp = sp->next)
shift_table[sp->number] = sp;
{
reductions *rp;
- reduction_table = NEW2 (nstates, reductions *);
+ reduction_table = XCALLOC (reductions *, nstates);
for (rp = first_reduction; rp; rp = rp->next)
reduction_table[rp->number] = rp;
shifts *sp;
short *np;
- consistent = NEW2 (nstates, char);
- lookaheads = NEW2 (nstates + 1, short);
+ consistent = XCALLOC (char, nstates);
+ lookaheads = XCALLOC (short, nstates + 1);
count = 0;
for (i = 0; i < nstates; i++)
if (count == 0)
{
- LA = NEW2 (1 * tokensetsize, unsigned);
- LAruleno = NEW2 (1, short);
- lookback = NEW2 (1, shorts *);
+ LA = XCALLOC (unsigned, 1 * tokensetsize);
+ LAruleno = XCALLOC (short, 1);
+ lookback = XCALLOC (shorts *, 1);
}
else
{
- LA = NEW2 (count * tokensetsize, unsigned);
- LAruleno = NEW2 (count, short);
- lookback = NEW2 (count, shorts *);
+ LA = XCALLOC (unsigned, count * tokensetsize);
+ LAruleno = XCALLOC (short, count);
+ lookback = XCALLOC (shorts *, count);
}
np = LAruleno;
int state2;
int state1;
- goto_map = NEW2 (nvars + 1, short) - ntokens;
- temp_map = NEW2 (nvars + 1, short) - ntokens;
+ goto_map = XCALLOC (short, nvars + 1) - ntokens;
+ temp_map = XCALLOC (short, nvars + 1) - ntokens;
ngotos = 0;
for (sp = first_shift; sp; sp = sp->next)
goto_map[nsyms] = ngotos;
temp_map[nsyms] = ngotos;
- from_state = NEW2 (ngotos, short);
- to_state = NEW2 (ngotos, short);
+ from_state = XCALLOC (short, ngotos);
+ to_state = XCALLOC (short, ngotos);
for (sp = first_shift; sp; sp = sp->next)
{
}
}
- FREE (temp_map + ntokens);
+ XFREE (temp_map + ntokens);
}
int nwords;
nwords = ngotos * tokensetsize;
- F = NEW2 (nwords, unsigned);
+ F = XCALLOC (unsigned, nwords);
- reads = NEW2 (ngotos, short *);
- edge = NEW2 (ngotos + 1, short);
+ reads = XCALLOC (short *, ngotos);
+ edge = XCALLOC (short, ngotos + 1);
nedges = 0;
rowp = F;
if (nedges)
{
- reads[i] = rp = NEW2 (nedges + 1, short);
+ reads[i] = rp = XCALLOC (short, nedges + 1);
for (j = 0; j < nedges; j++)
rp[j] = edge[j];
for (i = 0; i < ngotos; i++)
{
if (reads[i])
- FREE (reads[i]);
+ XFREE (reads[i]);
}
- FREE (reads);
- FREE (edge);
+ XFREE (reads);
+ XFREE (edge);
}
assert (found);
- sp = NEW (shorts);
+ sp = XCALLOC (shorts, 1);
sp->next = lookback[i];
sp->value = gotono;
lookback[i] = sp;
int i;
int k;
- nedges = NEW2 (n, short);
+ nedges = XCALLOC (short, n);
for (i = 0; i < n; i++)
{
}
}
- new_R = NEW2 (n, short *);
- temp_R = NEW2 (n, short *);
+ new_R = XCALLOC (short *, n);
+ temp_R = XCALLOC (short *, n);
for (i = 0; i < n; i++)
{
k = nedges[i];
if (k > 0)
{
- sp = NEW2 (k + 1, short);
+ sp = XCALLOC (short, k + 1);
new_R[i] = sp;
temp_R[i] = sp;
sp[k] = -1;
}
}
- FREE (nedges);
+ XFREE (nedges);
for (i = 0; i < n; i++)
{
}
}
- FREE (temp_R);
+ XFREE (temp_R);
return new_R;
}
short *states;
short **new_includes;
- includes = NEW2 (ngotos, short *);
- edge = NEW2 (ngotos + 1, short);
- states = NEW2 (maxrhs + 1, short);
+ includes = XCALLOC (short *, ngotos);
+ edge = XCALLOC (short, ngotos + 1);
+ states = XCALLOC (short, maxrhs + 1);
for (i = 0; i < ngotos; i++)
{
if (nedges)
{
- includes[i] = shortp = NEW2 (nedges + 1, short);
+ includes[i] = shortp = XCALLOC (short, nedges + 1);
for (j = 0; j < nedges; j++)
shortp[j] = edge[j];
shortp[nedges] = -1;
for (i = 0; i < ngotos; i++)
if (includes[i])
- FREE (includes[i]);
+ XFREE (includes[i]);
- FREE (includes);
+ XFREE (includes);
includes = new_includes;
- FREE (edge);
- FREE (states);
+ XFREE (edge);
+ XFREE (states);
}
for (i = 0; i < ngotos; i++)
{
if (includes[i])
- FREE (includes[i]);
+ XFREE (includes[i]);
}
- FREE (includes);
+ XFREE (includes);
}
for (sp = lookback[i]; sp; sp = sptmp)
{
sptmp = sp->next;
- FREE (sp);
+ XFREE (sp);
}
}
- FREE (lookback);
- FREE (F);
+ XFREE (lookback);
+ XFREE (F);
}
#include "getopt.h" /* for optarg */
#include "symtab.h"
#include "lex.h"
-#include "alloc.h"
+#include "xalloc.h"
#include "complain.h"
#include "gram.h"
init_lex (void)
{
maxtoken = 100;
- token_buffer = NEW2 (maxtoken + 1, char);
+ token_buffer = XCALLOC (char, maxtoken + 1);
unlexed = -1;
}
{
int offset = p - token_buffer;
maxtoken *= 2;
- token_buffer = (char *) xrealloc (token_buffer, maxtoken + 1);
+ token_buffer = XREALLOC (token_buffer, char, maxtoken + 1);
return token_buffer + offset;
}
#include "nullable.h"
#include "print.h"
#include "LR0.h"
+#include "conflicts.h"
/* The name this program was run with, for messages. */
char *program_name;
#include "system.h"
#include "types.h"
#include "gram.h"
-#include "alloc.h"
+#include "xalloc.h"
#include "nullable.h"
char *nullable = NULL;
fprintf (stderr, _("Entering set_nullable"));
#endif
- nullable = NEW2 (nvars, char) - ntokens;
+ nullable = XCALLOC (char, nvars) - ntokens;
- squeue = NEW2 (nvars, short);
+ squeue = XCALLOC (short, nvars);
s1 = s2 = squeue;
- rcount = NEW2 (nrules + 1, short);
- rsets = NEW2 (nvars, shorts *) - ntokens;
+ rcount = XCALLOC (short, nrules + 1);
+ rsets = XCALLOC (shorts *, nvars) - ntokens;
/* This is said to be more elements than we actually use.
Supposedly nitems - nrules is enough.
But why take the risk? */
- relts = NEW2 (nitems + nvars + 1, shorts);
+ relts = XCALLOC (shorts, nitems + nvars + 1);
p = relts;
r = ritem;
}
}
- FREE (squeue);
- FREE (rcount);
- FREE (rsets + ntokens);
- FREE (relts);
+ XFREE (squeue);
+ XFREE (rcount);
+ XFREE (rsets + ntokens);
+ XFREE (relts);
}
void
free_nullable (void)
{
- FREE (nullable + ntokens);
+ XFREE (nullable + ntokens);
}
#include "system.h"
#include "getargs.h"
-#include "alloc.h"
+#include "xalloc.h"
#include "files.h"
#include "gram.h"
#include "LR0.h"
output_short_table (ftable, "yyr1", rlhs,
0, 1, nrules + 1);
- FREE (rlhs + 1);
+ XFREE (rlhs + 1);
putc ('\n', ftable);
putc ('\n', ftable);
fprintf (ftable, "%6d\n};\n", nitems - rrhs[nrules] - 1);
- FREE (rrhs + 1);
+ XFREE (rrhs + 1);
}
if (count == 0)
return;
- froms[state] = sp1 = sp = NEW2 (count, short);
- tos[state] = sp2 = NEW2 (count, short);
+ froms[state] = sp1 = sp = XCALLOC (short, count);
+ tos[state] = sp2 = XCALLOC (short, count);
for (i = 0; i < ntokens; i++)
{
token_actions (void)
{
int i;
- short *yydefact = NEW2 (nstates, short);
+ short *yydefact = XCALLOC (short, nstates);
- actrow = NEW2 (ntokens, short);
+ actrow = XCALLOC (short, ntokens);
for (i = 0; i < nstates; ++i)
{
yydefact[i] = action_row (i);
save_row (i);
}
- FREE (actrow);
+ XFREE (actrow);
output_short_table (ftable, "yydefact", yydefact,
yydefact[0], 1, nstates);
- FREE (yydefact);
+ XFREE (yydefact);
}
{
shifts *sp, *sptmp; /* JF derefrenced freed ptr */
- FREE (shift_table);
+ XFREE (shift_table);
for (sp = first_shift; sp; sp = sptmp)
{
sptmp = sp->next;
- FREE (sp);
+ XFREE (sp);
}
}
{
reductions *rp, *rptmp; /* JF fixed freed ptr */
- FREE (reduction_table);
+ XFREE (reduction_table);
for (rp = first_reduction; rp; rp = rptmp)
{
rptmp = rp->next;
- FREE (rp);
+ XFREE (rp);
}
}
symno = symbol - ntokens + nstates;
- froms[symno] = sp1 = sp = NEW2 (count, short);
- tos[symno] = sp2 = NEW2 (count, short);
+ froms[symno] = sp1 = sp = XCALLOC (short, count);
+ tos[symno] = sp2 = XCALLOC (short, count);
for (i = m; i < n; i++)
{
{
int i, j, k;
- state_count = NEW2 (nstates, short);
+ state_count = XCALLOC (short, nstates);
k = default_goto (ntokens);
fprintf (ftable, "\nstatic const short yydefgoto[] = {%6d", k);
}
fprintf (ftable, "\n};\n");
- FREE (state_count);
+ XFREE (state_count);
}
int t;
int w;
- order = NEW2 (nvectors, short);
+ order = XCALLOC (short, nvectors);
nentries = 0;
for (i = 0; i < nvectors; i++)
int place;
int state;
- base = NEW2 (nvectors, short);
- pos = NEW2 (nentries, short);
- table = NEW2 (MAXTABLE, short);
- check = NEW2 (MAXTABLE, short);
+ base = XCALLOC (short, nvectors);
+ pos = XCALLOC (short, nentries);
+ table = XCALLOC (short, MAXTABLE);
+ check = XCALLOC (short, MAXTABLE);
lowzero = 0;
high = 0;
for (i = 0; i < nvectors; i++)
{
if (froms[i])
- FREE (froms[i]);
+ XFREE (froms[i]);
if (tos[i])
- FREE (tos[i]);
+ XFREE (tos[i]);
}
- FREE (froms);
- FREE (tos);
- FREE (pos);
+ XFREE (froms);
+ XFREE (tos);
+ XFREE (pos);
}
/* the following functions output yytable, yycheck
output_short_table (ftable, "yypgoto", base,
base[nstates], nstates + 1, nvectors);
- FREE (base);
+ XFREE (base);
}
fprintf (ftable, "\n\n#define\tYYLAST\t\t%d\n\n\n", high);
output_short_table (ftable, "yytable", table,
table[0], 1, high + 1);
- FREE (table);
+ XFREE (table);
}
{
output_short_table (ftable, "yycheck", check,
check[0], 1, high + 1);
- FREE (check);
+ XFREE (check);
}
/* compute and output yydefact, yydefgoto, yypact, yypgoto, yytable
{
nvectors = nstates + nvars;
- froms = NEW2 (nvectors, short *);
- tos = NEW2 (nvectors, short *);
- tally = NEW2 (nvectors, short);
- width = NEW2 (nvectors, short);
+ froms = XCALLOC (short *, nvectors);
+ tos = XCALLOC (short *, nvectors);
+ tally = XCALLOC (short, nvectors);
+ width = XCALLOC (short, nvectors);
token_actions ();
free_shifts ();
free_reductions ();
- FREE (lookaheads);
- FREE (LA);
- FREE (LAruleno);
- FREE (accessing_symbol);
+ XFREE (lookaheads);
+ XFREE (LA);
+ XFREE (LAruleno);
+ XFREE (accessing_symbol);
goto_actions ();
- FREE (goto_map + ntokens);
- FREE (from_state);
- FREE (to_state);
+ XFREE (goto_map + ntokens);
+ XFREE (from_state);
+ XFREE (to_state);
sort_actions ();
pack_table ();
{
core *cp, *cptmp;
- FREE (state_table);
+ XFREE (state_table);
for (cp = first_state; cp; cp = cptmp)
{
cptmp = cp->next;
- FREE (cp);
+ XFREE (cp);
}
}
/* if (semantic_parser) */
/* This is now unconditional because debugging printouts can use it. */
output_gram ();
- FREE (ritem);
+ XFREE (ritem);
if (semantic_parser)
output_stos ();
output_rule_data ();
#include "system.h"
-#include "alloc.h"
+#include "xalloc.h"
#include "files.h"
#include "gram.h"
#include "LR0.h"
#include "getargs.h"
#include "state.h"
#include "reader.h"
-
+#include "print.h"
#if 0
static void
#include "system.h"
#include "getargs.h"
#include "files.h"
-#include "alloc.h"
+#include "xalloc.h"
#include "symtab.h"
#include "lex.h"
#include "gram.h"
if (token == TYPENAME)
{
k = strlen (token_buffer);
- typename = NEW2 (k + 1, char);
+ typename = XCALLOC (char, k + 1);
strcpy (typename, token_buffer);
value_components_used = 1;
symbol = NULL;
}
k = strlen (token_buffer);
- name = NEW2 (k + 1, char);
+ name = XCALLOC (char, k + 1);
strcpy (name, token_buffer);
for (;;)
case TYPENAME:
k = strlen (token_buffer);
- name = NEW2 (k + 1, char);
+ name = XCALLOC (char, k + 1);
strcpy (name, token_buffer);
break;
if (token == TYPENAME)
{
k = strlen (token_buffer);
- typename = NEW2 (k + 1, char);
+ typename = XCALLOC (char, k + 1);
strcpy (typename, token_buffer);
value_components_used = 1;
token = lex (); /* fetch first token */
if (nrules >= rline_allocated)
{
rline_allocated = nrules * 2;
- rline = (short *) xrealloc ((char *) rline,
- rline_allocated * sizeof (short));
+ rline = XREALLOC (rline, short, rline_allocated);
}
rline[nrules] = lineno;
}
}
k = strlen (token_buffer);
- name = NEW2 (k + 1, char);
+ name = XCALLOC (char, k + 1);
strcpy (name, token_buffer);
for (;;)
record_rule_line ();
- p = NEW (symbol_list);
+ p = XCALLOC (symbol_list, 1);
p->sym = lhs;
crule1 = p1;
nrules++;
nitems++;
record_rule_line ();
- p = NEW (symbol_list);
+ p = XCALLOC (symbol_list, 1);
if (crule1)
crule1->next = p;
else
grammar = p;
p->sym = sdummy;
- crule1 = NEW (symbol_list);
+ crule1 = XCALLOC (symbol_list, 1);
p->next = crule1;
crule1->next = crule;
/* insert the dummy generated by that rule into this rule. */
nitems++;
- p = NEW (symbol_list);
+ p = XCALLOC (symbol_list, 1);
p->sym = sdummy;
p1->next = p;
p1 = p;
if (t == IDENTIFIER)
{
nitems++;
- p = NEW (symbol_list);
+ p = XCALLOC (symbol_list, 1);
p->sym = symval;
p1->next = p;
p1 = p;
} /* end of read rhs of rule */
/* Put an empty link in the list to mark the end of this rule */
- p = NEW (symbol_list);
+ p = XCALLOC (symbol_list, 1);
p1->next = p;
p1 = p;
/* int lossage = 0; JF set but not used */
- tags = NEW2 (nsyms + 1, char *);
+ tags = XCALLOC (char *, nsyms + 1);
tags[0] = DOLLAR;
- user_toknums = NEW2 (nsyms + 1, short);
+ user_toknums = XCALLOC (short, nsyms + 1);
user_toknums[0] = 0;
- sprec = NEW2 (nsyms, short);
- sassoc = NEW2 (nsyms, short);
+ sprec = XCALLOC (short, nsyms);
+ sassoc = XCALLOC (short, nsyms);
max_user_token_number = 256;
last_user_token_number = 256;
{
int j;
- token_translations = NEW2 (max_user_token_number + 1, short);
+ token_translations = XCALLOC (short, max_user_token_number + 1);
/* initialize all entries for literal tokens to 2, the internal
token number for $undefined., which represents all invalid
bucket *ruleprec;
- ritem = NEW2 (nitems + 1, short);
- rlhs = NEW2 (nrules, short) - 1;
- rrhs = NEW2 (nrules, short) - 1;
- rprec = NEW2 (nrules, short) - 1;
- rprecsym = NEW2 (nrules, short) - 1;
- rassoc = NEW2 (nrules, short) - 1;
+ ritem = XCALLOC (short, nitems + 1);
+ rlhs = XCALLOC (short, nrules) - 1;
+ rrhs = XCALLOC (short, nrules) - 1;
+ rprec = XCALLOC (short, nrules) - 1;
+ rprecsym = XCALLOC (short, nrules) - 1;
+ rassoc = XCALLOC (short, nrules) - 1;
itemno = 0;
ruleno = 1;
nrules = 0;
nitems = 0;
rline_allocated = 10;
- rline = NEW2 (rline_allocated, short);
+ rline = XCALLOC (short, rline_allocated);
typed = 0;
lastprec = 0;
#include "getargs.h"
#include "files.h"
#include "gram.h"
-#include "alloc.h"
+#include "xalloc.h"
#include "complain.h"
#include "reduce.h"
#include "reader.h"
/* N is set as built. Np is set being built this iteration. P is
set of all productions which have a RHS all in N. */
- Np = NEW2 (WORDSIZE (nvars), unsigned);
+ Np = XCALLOC (unsigned, WORDSIZE (nvars));
/* The set being computed is a set of nonterminals which can derive
the empty string or strings consisting of all terminals. At each
Np = N;
N = Ns;
}
- FREE (N);
+ XFREE (N);
N = Np;
}
terminals are printed (if running in verbose mode) so that the
user can know. */
- Vp = NEW2 (WORDSIZE (nsyms), unsigned);
- Pp = NEW2 (WORDSIZE (nrules + 1), unsigned);
+ Vp = XCALLOC (unsigned, WORDSIZE (nsyms));
+ Pp = XCALLOC (unsigned, WORDSIZE (nrules + 1));
/* If the start symbol isn't useful, then nothing will be useful. */
if (!BITISSET (N, start_symbol - ntokens))
}
end_iteration:
- FREE (V);
+ XFREE (V);
V = Vp;
/* Tokens 0, 1, and 2 are internal to Bison. Consider them useful. */
SETBIT (V, 1); /* error token */
SETBIT (V, 2); /* some undefined token */
- FREE (P);
+ XFREE (P);
P = Pp;
nuseful_productions = bits_size (P, WORDSIZE (nrules + 1));
number. -1 in the map means it was useless and is being
eliminated. */
- nontermmap = NEW2 (nvars, short) - ntokens;
+ nontermmap = XCALLOC (short, nvars) - ntokens;
for (i = ntokens; i < nsyms; i++)
nontermmap[i] = -1;
/* Allocate the global sets used to compute the reduced grammar */
- N = NEW2 (WORDSIZE (nvars), unsigned);
- P = NEW2 (WORDSIZE (nrules + 1), unsigned);
- V = NEW2 (WORDSIZE (nsyms), unsigned);
- V1 = NEW2 (WORDSIZE (nsyms), unsigned);
+ N = XCALLOC (unsigned, WORDSIZE (nvars));
+ P = XCALLOC (unsigned, WORDSIZE (nrules + 1));
+ V = XCALLOC (unsigned, WORDSIZE (nsyms));
+ V1 = XCALLOC (unsigned, WORDSIZE (nsyms));
useless_nonterminals ();
inaccessable_symbols ();
done_reducing:
/* Free the global sets used to compute the reduced grammar */
- FREE (N);
- FREE (V);
- FREE (P);
+ XFREE (N);
+ XFREE (V);
+ XFREE (P);
}
#include "system.h"
-#include "alloc.h"
+#include "xalloc.h"
#include "symtab.h"
#include "gram.h"
for (cp = s; *cp; cp++)
i++;
- result = xmalloc((unsigned int)i);
+ result = XMALLOC(char, i);
strcpy(result, s);
return result;
}
{
/* register int i; JF unused */
- symtab = NEW2(TABSIZE, bucket *);
+ symtab = XCALLOC (bucket *, TABSIZE);
firstsymbol = NULL;
lastsymbol = NULL;
{
nsyms++;
- bp = NEW(bucket);
+ bp = XCALLOC (bucket, 1);
bp->link = symtab[hashval];
bp->next = NULL;
bp->tag = copys(key);
bptmp = bp->link;
#if 0 /* This causes crashes because one string can appear more than once. */
if (bp->type_name)
- FREE(bp->type_name);
+ XFREE(bp->type_name);
#endif
- FREE(bp);
+ XFREE(bp);
bp = bptmp;
}
}
- FREE(symtab);
+ XFREE(symtab);
}
/* Generate transitive closure of a matrix,
- Copyright (C) 1984, 1989 Free Software Foundation, Inc.
+ Copyright (C) 1984, 1989, 2000 Free Software Foundation, Inc.
-This file is part of Bison, the GNU Compiler Compiler.
+ This file is part of Bison, the GNU Compiler Compiler.
-Bison is free software; you can redistribute it and/or modify
-it under the terms of the GNU General Public License as published by
-the Free Software Foundation; either version 2, or (at your option)
-any later version.
+ Bison is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2, or (at your option)
+ any later version.
-Bison 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 General Public License for more details.
+ Bison 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 General Public License for more details.
-You should have received a copy of the GNU General Public License
-along with Bison; see the file COPYING. If not, write to
-the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
-Boston, MA 02111-1307, USA. */
+ You should have received a copy of the GNU General Public License
+ along with Bison; see the file COPYING. If not, write to
+ the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA. */
#include "system.h"
+#include "warshall.h"
-void RTC PARAMS((unsigned *, int));
-
-
-/* given n by n matrix of bits R, modify its contents
- to be the transive closure of what was given. */
+/* Given n by n matrix of bits R, modify its contents to be the
+ transive closure of what was given. */
static void
TC (unsigned *R, int n)
{
- register int rowsize;
- register unsigned mask;
- register unsigned *rowj;
- register unsigned *rp;
- register unsigned *rend;
- register unsigned *ccol;
+ int rowsize;
+ unsigned mask;
+ unsigned *rowj;
+ unsigned *rp;
+ unsigned *rend;
+ unsigned *ccol;
unsigned *relend;
unsigned *cword;
void
RTC (unsigned *R, int n)
{
- register int rowsize;
- register unsigned mask;
- register unsigned *rp;
- register unsigned *relend;
+ int rowsize;
+ unsigned mask;
+ unsigned *rp;
+ unsigned *relend;
TC(R, n);
--- /dev/null
+/* Generate transitive closure of a matrix,
+ Copyright (C) 1984, 1989, 2000 Free Software Foundation, Inc.
+
+ This file is part of Bison, the GNU Compiler Compiler.
+
+ Bison is free software; you can redistribute it and/or modify
+ it under the terms of the GNU General Public License as published by
+ the Free Software Foundation; either version 2, or (at your option)
+ any later version.
+
+ Bison 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 General Public License for more details.
+
+ You should have received a copy of the GNU General Public License
+ along with Bison; see the file COPYING. If not, write to
+ the Free Software Foundation, Inc., 59 Temple Place - Suite 330,
+ Boston, MA 02111-1307, USA. */
+
+#ifndef WARSHALL_H_
+# define WARSHALL_H_
+
+void RTC PARAMS ((unsigned *, int));
+#endif /* !WARSHALL_H_ */