m4-patches
[Top][All Lists]
Advanced

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

FYI: 2-gary-input-tidyup.patch


From: Gary V. Vaughan
Subject: FYI: 2-gary-input-tidyup.patch
Date: Wed, 04 Jun 2003 11:57:02 +0100
User-agent: Mozilla/5.0 (Macintosh; U; PPC Mac OS X Mach-O; en-US; rv:1.3) Gecko/20030312

Just applied to HEAD.

Cheers,
        Gary.
--
  ())_. Gary V. Vaughan     gary@(oranda.demon.co.uk|gnu.org)
  ( '/  Research Scientist  http://www.oranda.demon.co.uk       ,_())____
  / )=  GNU Hacker          http://www.gnu.org/software/libtool  \'      `&
`(_~)_  Tech' Author        http://sources.redhat.com/autobook   =`---d__/
Index: ChangeLog
from  Gary V. Vaughan  <address@hidden>

        * m4/input.c: Updated various bitrotted comments.
        (m4_push_builtin): Just pass the whole m4_token, rather than
        extracting all the fields in the caller.  This also allows us to
        check the token type for consistency.
        (macro_funcs, macro_peek, macro_read, m4_push_macro, CHAR_MACRO):
        Renamed to builtin_funcs, builtin_peek, builtin_read,
        m4_push_builtin and CHAR_BUILTIN for consistency with the rest of
        the code.  Changed all callers.
        (struct input_block): Similarly renamed u_m member to u_b, and
        changed all callers.
        (m4_next_token): Use bzero to initialise the data fields.
        * m4/m4module (m4_push_macro): Renamed to m4_push_builtin.

Index: m4/input.c
===================================================================
RCS file: /cvsroot/m4/m4/m4/input.c,v
retrieving revision 1.21
diff -u -p -u -r1.21 input.c
--- m4/input.c 29 May 2002 18:06:42 -0000 1.21
+++ m4/input.c 4 Jun 2003 10:50:59 -0000
@@ -29,7 +29,7 @@
 /*
    Unread input can be either files, that should be read (eg. included
    files), strings, which should be rescanned (eg. macro expansion
-   text), single characters or quoted macro definitions (as returned by
+   text), single characters or quoted builtin definitions (as returned by
    the builtin "defn").  Unread input are organised in a stack,
    implemented with an obstack.  Each input source is described by a
    "struct input_block".  The obstack is "input_stack".  The top of the
@@ -50,15 +50,15 @@
    are done through a pointer "current_input", which points to either
    "input_stack" or "wrapup_stack".
 
-   Pushing new input on the input stack is done by push_file (),
-   push_string (), push_single () or push_wrapup () (for wrapup text),
-   and push_macro () (for macro definitions).  Because macro expansion
-   needs direct access to the current input obstack (for optimisation),
-   push_string () are split in two functions, push_string_init (), which
-   returns a pointer to the current input stack, and push_string_finish
-   (), which return a pointer to the final text.  The input_block *next
-   is used to manage the coordination between the different push
-   routines.
+   Pushing new input on the input stack is done by m4_push_file (),
+   m4_push_string (), m4_push_single () or m4_push_wrapup () (for wrapup
+   text), and m4_push_builtin () (for builtin definitions).  Because
+   macro expansion needs direct access to the current input obstack (for
+   optimisation), m4_push_string () are split in two functions,
+   push_string_init (), which returns a pointer to the current input
+   stack, and push_string_finish (), which return a pointer to the final
+   text.  The input_block *next is used to manage the coordination
+   between the different push routines.
 
    The current file and line number are stored in two global variables,
    for use by the error handling functions in m4.c.  Whenever a file
@@ -71,8 +71,8 @@ static        int   file_read                 (void);
 static void  file_unget                (int ch);
 static void  file_clean                (void);
 static void  init_builtin_token        (m4_token *td);
-static int   macro_peek                (void);
-static int   macro_read                (void);
+static int   builtin_peek              (void);
+static int   builtin_read              (void);
 static int   match_input               (const unsigned char *s);
 static int   next_char                 (void);
 static void  pop_input                 (void);
@@ -121,14 +121,15 @@ struct input_block
       u_f;
       struct
        {
-         m4_builtin_func *func;/* pointer to macros function */
-         lt_dlhandle handle;   /* originating module */
-         int flags;            /* flags associated with the builtin */
+         m4_builtin_func *func;  /* pointer to builtins function. */
+         lt_dlhandle handle;     /* originating module. */
+         int flags;              /* flags associated with the builtin. */
+         m4_hash *arg_signature; /* argument signature for builtin.  */
          int min_args, max_args; /* argv maxima and minima for the builtin. */
-         boolean traced;       /* TRUE iff builtin is traced */
-         boolean read;         /* TRUE iff block has been read */
+         boolean traced;         /* TRUE iff builtin is traced. */
+         boolean read;           /* TRUE iff block has been read. */
        }
-      u_m;
+      u_b;
     }
   u;
 };
@@ -163,21 +164,21 @@ static input_block *isp;
 /* Pointer to top of wrapup_stack.  */
 static input_block *wsp;
 
-/* Aux. for handling split push_string ().  */
+/* Aux. for handling split m4_push_string ().  */
 static input_block *next;
 
 /* Flag for next_char () to increment m4_current_line.  */
 static boolean start_of_input_line;
 
 #define CHAR_EOF       256     /* character return on EOF */
-#define CHAR_MACRO     257     /* character return for MACRO token */
+#define CHAR_BUILTIN   257     /* character return for BUILTIN token */
 #define CHAR_RETRY     258     /* character return for end of input block */
 
 
 
-/* push_file () pushes an input file on the input stack, saving the
+/* m4_push_file () pushes an input file on the input stack, saving the
   current file name and line number.  If next is non-NULL, this push
-  invalidates a call to push_string_init (), whose storage are
+  invalidates a call to m4_push_string_init (), whose storage are
   consequentely released.
 
   file_read () manages line numbers for error messages, so they do not
@@ -278,38 +279,40 @@ m4_push_file (FILE *fp, const char *titl
   isp = i;
 }
 
-/* push_macro () pushes a builtin macros definition on the input stack.  If
-   next is non-NULL, this push invalidates a call to push_string_init (),
+/* m4_push_builtin () pushes a builtins definition on the input stack.  If
+   next is non-NULL, this push invalidates a call to m4_push_string_init (),
    whose storage are consequentely released.  */
 static int
-macro_peek (void)
+builtin_peek (void)
 {
-  if (isp->u.u_m.read == TRUE)
+  if (isp->u.u_b.read == TRUE)
     return CHAR_RETRY;
 
-  return CHAR_MACRO;
+  return CHAR_BUILTIN;
 }
 
 static int
-macro_read (void)
+builtin_read (void)
 {
-  if (isp->u.u_m.read == TRUE)
+  if (isp->u.u_b.read == TRUE)
     return CHAR_RETRY;
 
-  isp->u.u_m.read = TRUE;
-  return CHAR_MACRO;
+  isp->u.u_b.read = TRUE;
+  return CHAR_BUILTIN;
 }
 
-static struct input_funcs macro_funcs = {
-  macro_peek, macro_read, NULL, NULL
+static struct input_funcs builtin_funcs = {
+  builtin_peek, builtin_read, NULL, NULL
 };
 
 void
-m4_push_macro (m4_builtin_func *func, lt_dlhandle handle,
-              int min, int max, int flags)
+m4_push_builtin (m4_token *td)
 {
   input_block *i;
 
+  /* Make sure we were passed a builtin function type token.  */
+  assert (TOKEN_TYPE (td) == M4_TOKEN_FUNC);
+
   if (next != NULL)
     {
       obstack_free (current_input, next);
@@ -318,14 +321,14 @@ m4_push_macro (m4_builtin_func *func, lt
 
   i = (input_block *) obstack_alloc (current_input,
                                     sizeof (struct input_block));
-  i->funcs = &macro_funcs;
+  i->funcs = &builtin_funcs;
 
-  i->u.u_m.func                = func;
-  i->u.u_m.handle      = handle;
-  i->u.u_m.min_args    = min;
-  i->u.u_m.max_args    = max;
-  i->u.u_m.flags       = flags;
-  i->u.u_m.read                = FALSE;
+  i->u.u_b.func                = TOKEN_FUNC (td);
+  i->u.u_b.handle      = TOKEN_HANDLE (td);
+  i->u.u_b.min_args    = TOKEN_MIN_ARGS (td);
+  i->u.u_b.max_args    = TOKEN_MAX_ARGS (td);
+  i->u.u_b.flags       = TOKEN_FLAGS (td);
+  i->u.u_b.read                = FALSE;
 
   i->prev = isp;
   isp = i;
@@ -375,7 +378,7 @@ m4_push_single (int ch)
   isp = i;
 }
 
-/* First half of push_string ().  The pointer next points to the new
+/* First half of m4_push_string ().  The pointer next points to the new
    input_block.  */
 static int
 string_peek (void)
@@ -413,7 +416,7 @@ m4_push_string_init (void)
   if (next != NULL)
     {
       M4ERROR ((warning_status, 0,
-               "INTERNAL ERROR: Recursive push_string!"));
+               "INTERNAL ERROR: Recursive m4_push_string!"));
       abort ();
     }
 
@@ -424,12 +427,13 @@ m4_push_string_init (void)
   return current_input;
 }
 
-/* Last half of push_string ().  If next is now NULL, a call to push_file
-   () has invalidated the previous call to push_string_init (), so we just
-   give up.  If the new object is void, we do not push it.  The function
-   push_string_finish () returns a pointer to the finished object.  This
-   pointer is only for temporary use, since reading the next token might
-   release the memory used for the object.  */
+/* Last half of m4_push_string ().  If next is now NULL, a call to
+   m4_push_file () has invalidated the previous call to
+   m4_push_string_init (), so we just give up.  If the new object is
+   void, we do not push it.  The function m4_push_string_finish ()
+   returns a pointer to the finished object.  This pointer is only for
+   temporary use, since reading the next token might release the memory
+   used for the object.  */
 
 const char *
 m4_push_string_finish (void)
@@ -454,11 +458,12 @@ m4_push_string_finish (void)
   return ret;
 }
 
-/* The function push_wrapup () pushes a string on the wrapup stack.  When
-   the normal input stack gets empty, the wrapup stack will become the input
-   stack, and push_string () and push_file () will operate on wrapup_stack.
-   Push_wrapup should be done as push_string (), but this will suffice, as
-   long as arguments to m4_m4wrap () are moderate in size.  */
+/* The function m4_push_wrapup () pushes a string on the wrapup stack.
+   When the normal input stack gets empty, the wrapup stack will become
+   the input stack, and m4_push_string () and m4_push_file () will
+   operate on wrapup_stack.  M4_push_wrapup should be done as
+   m4_push_string (), but this will suffice, as long as arguments to
+   m4_m4wrap () are moderate in size.  */
 void
 m4_push_wrapup (const char *s)
 {
@@ -488,7 +493,7 @@ pop_input (void)
     (*isp->funcs->clean_func)();
 
   obstack_free (current_input, isp);
-  next = NULL;                 /* might be set in push_string_init () */
+  next = NULL;                 /* might be set in m4_push_string_init () */
 
   isp = tmp;
 }
@@ -509,24 +514,24 @@ m4_pop_wrapup (void)
   return TRUE;
 }
 
-/* When a MACRO token is seen, next_token () uses init_builtin_token
+/* When a BUILTIN token is seen, next_token () uses init_builtin_token
    to retrieve the value of the function pointer.  */
 static void
 init_builtin_token (m4_token *td)
 {
-  if (isp->funcs->read_func != macro_read)
+  if (isp->funcs->read_func != builtin_read)
     {
       M4ERROR ((warning_status, 0,
                "INTERNAL ERROR: Bad call to init_builtin_token ()"));
       abort ();
     }
 
-  TOKEN_TYPE (td)      = M4_TOKEN_FUNC;
-  TOKEN_FUNC (td)      = isp->u.u_m.func;
-  TOKEN_HANDLE (td)    = isp->u.u_m.handle;
-  TOKEN_FLAGS (td)     = isp->u.u_m.flags;
-  TOKEN_MIN_ARGS (td)  = isp->u.u_m.min_args;
-  TOKEN_MAX_ARGS (td)  = isp->u.u_m.max_args;
+  TOKEN_TYPE (td)              = M4_TOKEN_FUNC;
+  TOKEN_FUNC (td)              = isp->u.u_b.func;
+  TOKEN_HANDLE (td)            = isp->u.u_b.handle;
+  TOKEN_FLAGS (td)             = isp->u.u_b.flags;
+  TOKEN_MIN_ARGS (td)          = isp->u.u_b.min_args;
+  TOKEN_MAX_ARGS (td)          = isp->u.u_b.max_args;
 }
 
 
@@ -756,7 +761,7 @@ m4_next_token (m4_token *td)
        return M4_TOKEN_EOF;
       }
 
-    if (ch == CHAR_MACRO)              /* MACRO TOKEN */
+    if (ch == CHAR_BUILTIN)            /* BUILTIN TOKEN */
       {
        init_builtin_token (td);
        (void) next_char ();
@@ -932,10 +937,10 @@ m4_next_token (m4_token *td)
 
   obstack_1grow (&token_stack, '\0');
 
+  bzero (td, sizeof (m4_token));
+
   TOKEN_TYPE (td)      = M4_TOKEN_TEXT;
   TOKEN_TEXT (td)      = obstack_finish (&token_stack);
-  TOKEN_HANDLE (td)    = NULL;
-  TOKEN_FLAGS (td)     = 0x0;
   TOKEN_MIN_ARGS (td)  = -1;
   TOKEN_MAX_ARGS (td)  = -1;
 
@@ -985,7 +990,7 @@ m4_print_token (const char *s, m4_token_
       break;
 
     case M4_TOKEN_MACDEF:
-      fprintf (stderr, "macro 0x%x\n",         (int) TOKEN_FUNC (td));
+      fprintf (stderr, "builtin 0x%x\n",       (int) TOKEN_FUNC (td));
       break;
 
     case M4_TOKEN_EOF:
Index: m4/m4module.h
===================================================================
RCS file: /cvsroot/m4/m4/m4/m4module.h,v
retrieving revision 1.39
diff -u -p -u -r1.39 m4module.h
--- m4/m4module.h 30 May 2003 15:13:32 -0000 1.39
+++ m4/m4module.h 4 Jun 2003 10:50:59 -0000
@@ -417,7 +417,7 @@ extern      void    m4_skip_line    (void);
 
 extern void    m4_push_file    (FILE *, const char *);
 extern void    m4_push_single  (int ch);
-extern void    m4_push_macro   (m4_builtin_func *, lt_dlhandle, int, int, int);
+extern void    m4_push_builtin (m4_token *);
 extern struct obstack *m4_push_string_init (void);
 extern const char *m4_push_string_finish (void);
 extern void    m4_push_wrapup  (const char *);
Index: m4/m4private.h
===================================================================
RCS file: /cvsroot/m4/m4/m4/m4private.h,v
retrieving revision 1.15
diff -u -p -u -r1.15 m4private.h
--- m4/m4private.h 29 May 2002 18:06:42 -0000 1.15
+++ m4/m4private.h 4 Jun 2003 10:50:59 -0000
@@ -41,13 +41,6 @@ struct m4_module_data {
   m4_macro         *mp;        /* `m4_macro_table' address */
 };
 
-
-/* m4_token.flags bit masks:  */
-
-#define TOKEN_MACRO_ARGS_BIT           (1 << 0)
-#define TOKEN_BLIND_ARGS_BIT           (1 << 1)
-
-
 struct m4_token {
   m4_token *   next;
   lt_dlhandle          handle;
@@ -70,6 +63,11 @@ struct m4_token {
 #define TOKEN_TEXT(T)          ((T)->u.text)
 #define TOKEN_FUNC(T)          ((T)->u.func)
 
+/* m4_token.flags bit masks:  */
+
+#define TOKEN_MACRO_ARGS_BIT           (1 << 0)
+#define TOKEN_BLIND_ARGS_BIT           (1 << 1)
+
 #define BIT_TEST(flags, bit)   (((flags) & (bit)) == (bit))
 #define BIT_SET(flags, bit)    ((flags) |= (bit))
 #define BIT_RESET(flags, bit)  ((flags) &= ~(bit))
@@ -90,14 +88,14 @@ struct m4_symbol
 #define SYMBOL_TRACED(S)       ((S)->traced)
 #define SYMBOL_TOKEN(S)                ((S)->token)
 
-#define SYMBOL_NEXT(S)         (TOKEN_NEXT     (SYMBOL_TOKEN (S)))
-#define SYMBOL_HANDLE(S)       (TOKEN_HANDLE   (SYMBOL_TOKEN (S)))
-#define SYMBOL_FLAGS(S)                (TOKEN_FLAGS    (SYMBOL_TOKEN (S)))
-#define SYMBOL_MIN_ARGS(S)     (TOKEN_MIN_ARGS (SYMBOL_TOKEN (S)))
-#define SYMBOL_MAX_ARGS(S)     (TOKEN_MAX_ARGS (SYMBOL_TOKEN (S)))
-#define SYMBOL_TYPE(S)         (TOKEN_TYPE     (SYMBOL_TOKEN (S)))
-#define SYMBOL_TEXT(S)         (TOKEN_TEXT     (SYMBOL_TOKEN (S)))
-#define SYMBOL_FUNC(S)         (TOKEN_FUNC     (SYMBOL_TOKEN (S)))
+#define SYMBOL_NEXT(S)         (TOKEN_NEXT          (SYMBOL_TOKEN (S)))
+#define SYMBOL_HANDLE(S)       (TOKEN_HANDLE        (SYMBOL_TOKEN (S)))
+#define SYMBOL_FLAGS(S)                (TOKEN_FLAGS         (SYMBOL_TOKEN (S)))
+#define SYMBOL_MIN_ARGS(S)     (TOKEN_MIN_ARGS      (SYMBOL_TOKEN (S)))
+#define SYMBOL_MAX_ARGS(S)     (TOKEN_MAX_ARGS      (SYMBOL_TOKEN (S)))
+#define SYMBOL_TYPE(S)         (TOKEN_TYPE          (SYMBOL_TOKEN (S)))
+#define SYMBOL_TEXT(S)         (TOKEN_TEXT          (SYMBOL_TOKEN (S)))
+#define SYMBOL_FUNC(S)         (TOKEN_FUNC          (SYMBOL_TOKEN (S)))
 
 
 
Index: modules/m4.c
===================================================================
RCS file: /cvsroot/m4/m4/modules/m4.c,v
retrieving revision 1.32
diff -u -p -u -r1.32 m4.c
--- modules/m4.c 18 Oct 2001 21:27:36 -0000 1.32
+++ modules/m4.c 4 Jun 2003 10:50:59 -0000
@@ -355,9 +355,7 @@ M4BUILTIN_HANDLER (defn)
       return;
 
     case M4_TOKEN_FUNC:
-      m4_push_macro (SYMBOL_FUNC (symbol), SYMBOL_HANDLE (symbol),
-                    SYMBOL_MIN_ARGS (symbol), SYMBOL_MAX_ARGS (symbol),
-                    SYMBOL_FLAGS (symbol));
+      m4_push_builtin (SYMBOL_TOKEN (symbol));
       return;
 
     case M4_TOKEN_VOID:

reply via email to

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