[Top][All Lists]
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]
FYI: 10-gary-finish-symbol-lookup-specialisations.patch
From: |
Gary V. Vaughan |
Subject: |
FYI: 10-gary-finish-symbol-lookup-specialisations.patch |
Date: |
Sat, 8 Sep 2001 02:47:43 +0100 |
User-agent: |
Mutt/1.3.22.1i |
Index: ChangeLog
from Gary V. Vaughan <address@hidden>
Get rid of m4_symbol_lookup_t entirely. With Akim's earlier
commits, the m4_lookup_symbol dispatch function is split into
specialised functions that must be called directly.
* m4/m4module.h (m4_symbol_lookup_t): Removed.
* m4/symtab.c (m4_lookup_symbol): Removed.
(m4_symbol_builtin, m4_symbol_macro): New functions.
* m4/builtin.c (m4_builtin_define): Split into...
(m4_builtin_pushdef, m4_builtin_insert): ...these.
(m4_macro_define): Split into...
(m4_macro_pushdef, m4_macro_insert): ...these.
* src/main.c (main): Set command line macros from `-D' parameters
using `m4_macro_define'.
Index: m4/builtin.c
===================================================================
RCS file: /cvsroot/m4/m4/m4/builtin.c,v
retrieving revision 1.10
diff -u -p -u -r1.10 builtin.c
--- m4/builtin.c 2001/09/05 07:27:00 1.10
+++ m4/builtin.c 2001/09/08 01:39:37
@@ -70,83 +70,110 @@ m4_builtin_find_by_func (const m4_builti
return NULL;
}
+m4_symbol *
+m4_builtin_pushdef (const char *name, lt_dlhandle handle,
+ const m4_builtin *bp)
+{
+ m4_symbol *symbol;
-/* Install a builtin macro with name NAME, bound to the C function given in
- BP. MODE is M4_SYMBOL_INSERT or M4_SYMBOL_PUSHDEF. TRACED defines whether
- NAME is to be traced. */
-void
-m4_builtin_define (const lt_dlhandle handle, const char *name,
- const m4_builtin *bp, m4_symbol_lookup_t mode,
- boolean traced)
+ assert (name);
+ assert (handle);
+ assert (bp);
+
+ symbol = m4_symbol_pushdef (name);
+
+ if (symbol)
+ m4_symbol_builtin (symbol, handle, bp);
+
+ return symbol;
+}
+
+m4_symbol *
+m4_builtin_insert (const char *name, lt_dlhandle handle,
+ const m4_builtin *bp)
{
m4_symbol *symbol;
- symbol = m4_lookup_symbol (name, mode);
+ assert (name);
+ assert (handle);
+ assert (bp);
+
+ symbol = m4_symbol_insert (name);
+
if (symbol)
- {
- if (M4_SYMBOL_TYPE (symbol) == M4_TOKEN_TEXT)
- xfree (M4_SYMBOL_TEXT (symbol));
+ m4_symbol_builtin (symbol, handle, bp);
- M4_SYMBOL_HANDLE (symbol) = handle;
- M4_SYMBOL_TYPE (symbol) = M4_TOKEN_FUNC;
- M4_SYMBOL_MACRO_ARGS (symbol) = bp->groks_macro_args;
- M4_SYMBOL_BLIND_NO_ARGS (symbol) = bp->blind_if_no_args;
- M4_SYMBOL_FUNC (symbol) = bp->func;
- M4_SYMBOL_TRACED (symbol) = traced;
- }
+ return symbol;
}
void
-m4_builtin_table_install (const lt_dlhandle handle,
- const m4_builtin *table)
+m4_builtin_table_install (lt_dlhandle handle, const m4_builtin *table)
{
const m4_builtin *bp;
- char *string;
+ assert (handle);
+ assert (table);
+
for (bp = table; bp->name != NULL; bp++)
- if (prefix_all_builtins)
- {
- string = (char *) xmalloc (strlen (bp->name) + 4);
- strcpy (string, "m4_");
- strcat (string, bp->name);
- m4_builtin_define (handle, string, bp, M4_SYMBOL_PUSHDEF, FALSE);
- free (string);
- }
- else
- m4_builtin_define (handle, bp->name, bp, M4_SYMBOL_PUSHDEF, FALSE);
+ {
+ char *key;
+
+ if (prefix_all_builtins)
+ {
+ static const char prefix[] = "m4_";
+ size_t len = strlen (prefix) + strlen (bp->name);
+
+ key = (char *) xmalloc (1+ len);
+ snprintf (key, 1+ len, "%s%s", prefix, bp->name);
+ }
+ else
+ key = (char *) bp->name;
+
+ m4_builtin_pushdef (key, handle, bp);
+
+ if (prefix_all_builtins)
+ xfree (key);
+ }
}
-/* Define a predefined or user-defined macro, with name NAME, and expansion
- TEXT. MODE destinguishes between the "define" and the "pushdef" case.
- It is also used from main (). */
-void
-m4_macro_define (const lt_dlhandle handle, const char *name,
- const char *text, m4_symbol_lookup_t mode)
+m4_symbol *
+m4_macro_pushdef (const char *name, lt_dlhandle handle, const char *text)
{
m4_symbol *symbol;
+
+ assert (name);
+ assert (text);
+
+ symbol = m4_symbol_pushdef (name);
- symbol = m4_lookup_symbol (name, mode);
if (symbol)
- {
- if (M4_SYMBOL_TYPE (symbol) == M4_TOKEN_TEXT)
- xfree (M4_SYMBOL_TEXT (symbol));
+ m4_symbol_macro (symbol, handle, text);
- M4_SYMBOL_HANDLE (symbol) = handle;
- M4_SYMBOL_TYPE (symbol) = M4_TOKEN_TEXT;
- M4_SYMBOL_MACRO_ARGS (symbol) = FALSE;
- M4_SYMBOL_BLIND_NO_ARGS (symbol) = FALSE;
- M4_SYMBOL_TEXT (symbol) = xstrdup (text);
- /* Do not reset M4_SYMBOL_TRACED as it means that --trace would be
- usable only for existing macros. m4_lookup_symbol takes care
- of its proper initialization. */
- }
+ return symbol;
}
+m4_symbol *
+m4_macro_insert (const char *name, lt_dlhandle handle, const char *text)
+{
+ m4_symbol *symbol;
+
+ assert (name);
+ assert (text);
+
+ symbol = m4_symbol_insert (name);
+
+ if (symbol)
+ m4_symbol_macro (symbol, handle, text);
+
+ return symbol;
+}
+
+
void
-m4_macro_table_install (const lt_dlhandle handle, const m4_macro *table)
+m4_macro_table_install (lt_dlhandle handle, const m4_macro *table)
{
const m4_macro *mp;
for (mp = table; mp->name != NULL; mp++)
- m4_macro_define (handle, mp->name, mp->value, M4_SYMBOL_PUSHDEF);
+ m4_macro_pushdef (mp->name, handle, mp->value);
}
Index: m4/m4module.h
===================================================================
RCS file: /cvsroot/m4/m4/m4/m4module.h,v
retrieving revision 1.25
diff -u -p -u -r1.25 m4module.h
--- m4/m4module.h 2001/09/07 23:47:28 1.25
+++ m4/m4module.h 2001/09/08 01:39:39
@@ -43,13 +43,6 @@ typedef struct {
size_t length; /* length of the string */
} m4_string;
-/* Operation modes for m4_lookup_symbol (). */
-typedef enum
-{
- M4_SYMBOL_INSERT,
- M4_SYMBOL_PUSHDEF
-} m4_symbol_lookup_t;
-
typedef struct {
const char *name;
const char *value;
@@ -77,16 +70,19 @@ extern m4_macro *m4_module_macros (
extern lt_dlhandle m4_module_find_by_builtin (const m4_builtin*);
-extern void m4_macro_define (const lt_dlhandle,
- const char *, const char *, m4_symbol_lookup_t);
-extern void m4_macro_table_install (
- const lt_dlhandle, const m4_macro *);
-
-extern void m4_builtin_define (const lt_dlhandle,
- const char *, const m4_builtin *,
- m4_symbol_lookup_t, boolean);
-extern void m4_builtin_table_install (
- const lt_dlhandle, const m4_builtin *);
+extern m4_symbol *m4_macro_pushdef (const char *name, lt_dlhandle handle,
+ const char *text);
+extern m4_symbol *m4_macro_insert (const char *name, lt_dlhandle handle,
+ const char *text);
+extern void m4_macro_table_install (lt_dlhandle handle,
+ const m4_macro *table);
+
+extern m4_symbol *m4_builtin_pushdef (const char *name, lt_dlhandle handle,
+ const m4_builtin *bp);
+extern m4_symbol *m4_builtin_insert (const char *name, lt_dlhandle handle,
+ const m4_builtin *bp);
+extern void m4_builtin_table_install (lt_dlhandle handle,
+ const m4_builtin *table);
extern const m4_builtin *m4_builtin_find_by_name (
const m4_builtin *, const char *);
@@ -94,16 +90,20 @@ extern const m4_builtin *m4_builtin_find
const m4_builtin *, m4_builtin_func *);
extern m4_hash *m4_symtab;
+
+extern void m4_symtab_init (void);
+extern int m4_symtab_apply (m4_symtab_apply_func *, void *);
+extern void m4_symtab_remove_module_references (lt_dlhandle);
-extern void m4_symtab_init (void);
-extern m4_symbol *m4_lookup_symbol (const char *, m4_symbol_lookup_t);
extern m4_symbol *m4_symbol_lookup (const char *);
extern m4_symbol *m4_symbol_pushdef (const char *);
extern m4_symbol *m4_symbol_insert (const char *);
extern void m4_symbol_popdef (const char *);
extern void m4_symbol_delete (const char *);
-extern int m4_symtab_apply (m4_symtab_apply_func *, void *);
-extern void m4_symtab_remove_module_references (lt_dlhandle);
+extern void m4_symbol_builtin (m4_symbol *symbol, lt_dlhandle handle,
+ const m4_builtin *bp);
+extern void m4_symbol_macro (m4_symbol *symbol, lt_dlhandle handle,
+ const char *text);
/* Various different token types. */
Index: m4/symtab.c
===================================================================
RCS file: /cvsroot/m4/m4/m4/symtab.c,v
retrieving revision 1.19
diff -u -p -u -r1.19 symtab.c
--- m4/symtab.c 2001/09/07 23:47:28 1.19
+++ m4/symtab.c 2001/09/08 01:39:40
@@ -19,15 +19,12 @@
*/
/* This file handles all the low level work around the symbol table. The
- symbol table is a simple chained hash table. Each symbol is described
- by a struct symbol, which is placed in the hash table based upon the
- symbol name. Symbols that hash to the same entry in the table are
- kept on a list, sorted by name. As a special case, to facilitate the
- "pushdef" and "popdef" builtins, a symbol can be several times in the
- symbol table, one for each definition. Since the name is the same,
- all the entries for the symbol will be on the same list, and will
- also, because the list is sorted, be adjacent. All the entries for a
- name are simply ordered on the list by age. The current definition
+ symbol table is an abstract hash table type implemented in hash.c. Each
+ symbol is represented by `struct m4_symbol', which is stored in the hash
+ table keyed by the symbol name. As a special case, to facilitate the
+ "pushdef" and "popdef" builtins, the value stored against each key us a
+ stack of `struct m4_symbol'. All the value entries for a symbol name are
+ simply ordered on the stack by age. The most recently pushed definition
will then always be the first found. */
#include "m4private.h"
@@ -124,36 +121,7 @@ m4_symbol_del (m4_symbol *symbol)
}
-/* Dispatch on all the following 5 functions.
-
- Search in, and manipulation of the symbol table, are all done by
- m4_lookup_symbol (). It basically hashes NAME to a list in the
- symbol table, and searched this list for the first occurence of a
- symbol with the name.
-
- The MODE parameter determines what m4_lookup_symbol () will do. It
- can either just do a lookup, do a lookup and insert if not present,
- do an insertion even if the name is already in the list, delete the
- first occurrence of the name on the list or delete all occurences
- of the name on the list. */
-m4_symbol *
-m4_lookup_symbol (const char *name, m4_symbol_lookup_t mode)
-{
- switch (mode)
- {
- case M4_SYMBOL_INSERT:
- return m4_symbol_insert (name);
-
- case M4_SYMBOL_PUSHDEF:
- return m4_symbol_pushdef (name);
- }
-
- assert (0);
- /*NOTREACHED*/
- return 0;
-}
-
-
+
/* Return the symbol associated to NAME, or else NULL. */
m4_symbol *
m4_symbol_lookup (const char *name)
@@ -236,6 +204,45 @@ m4_symbol_delete (const char *name)
m4_symbol_del (*psymbol);
}
+
+void
+m4_symbol_builtin (m4_symbol *symbol, lt_dlhandle handle,
+ const m4_builtin *bp)
+{
+ assert (symbol);
+ assert (handle);
+ assert (bp);
+
+ if (M4_SYMBOL_TYPE (symbol) == M4_TOKEN_TEXT)
+ xfree (M4_SYMBOL_TEXT (symbol));
+
+ M4_SYMBOL_HANDLE (symbol) = handle;
+ M4_SYMBOL_TYPE (symbol) = M4_TOKEN_FUNC;
+ M4_SYMBOL_MACRO_ARGS (symbol) = bp->groks_macro_args;
+ M4_SYMBOL_BLIND_NO_ARGS (symbol) = bp->blind_if_no_args;
+ M4_SYMBOL_FUNC (symbol) = bp->func;
+ /* Do not reset M4_SYMBOL_TRACED as it means that --trace would be
+ usable only for existing macros. m4_symbol_lookup takes care
+ of its proper initialisation. */
+}
+
+void
+m4_symbol_macro (m4_symbol *symbol, lt_dlhandle handle, const char *text)
+{
+ assert (symbol);
+
+ if (M4_SYMBOL_TYPE (symbol) == M4_TOKEN_TEXT)
+ xfree (M4_SYMBOL_TEXT (symbol));
+
+ M4_SYMBOL_HANDLE (symbol) = handle;
+ M4_SYMBOL_TYPE (symbol) = M4_TOKEN_TEXT;
+ M4_SYMBOL_MACRO_ARGS (symbol) = FALSE;
+ M4_SYMBOL_BLIND_NO_ARGS (symbol) = FALSE;
+ M4_SYMBOL_TEXT (symbol) = xstrdup (text);
+ /* Do not reset M4_SYMBOL_TRACED as it means that --trace would be
+ usable only for existing macros. m4_symbol_lookup takes care
+ of its proper initialisation. */
+}
/* Remove every symbol that references the given module handle from
the symbol table. */
Index: modules/m4.c
===================================================================
RCS file: /cvsroot/m4/m4/modules/m4.c,v
retrieving revision 1.18
diff -u -p -u -r1.18 m4.c
--- modules/m4.c 2001/09/07 10:46:33 1.18
+++ modules/m4.c 2001/09/08 01:39:41
@@ -126,12 +126,7 @@ M4INIT_HANDLER (m4)
individual arguments to the macro. Please note that in general
argv[argc] != NULL. */
-/* The function macro_install is common for the builtins "define" and
- "pushdef". ARGC and ARGV is as for the caller, and MODE argument
- determines how the macro name is entered into the symbol table. */
-
-static void
-macro_install (int argc, m4_token_data **argv, m4_symbol_lookup_t mode)
+M4BUILTIN_HANDLER (define)
{
if (m4_bad_argc (argv[0], argc, 2, 3))
return;
@@ -141,15 +136,15 @@ macro_install (int argc, m4_token_data *
if (argc == 2)
{
- m4_macro_define (NULL, M4ARG (1), "", mode);
+ m4_macro_insert (M4ARG (1), NULL, "");
return;
}
switch (M4_TOKEN_DATA_TYPE (argv[2]))
{
case M4_TOKEN_TEXT:
- m4_macro_define (NULL, M4ARG (1), M4ARG (2), mode);
- break;
+ m4_macro_insert (M4ARG (1), NULL, M4ARG (2));
+ return;
case M4_TOKEN_FUNC:
{
@@ -163,22 +158,13 @@ macro_install (int argc, m4_token_data *
builtin = m4_builtin_find_by_func (m4_module_builtins (handle),
M4_TOKEN_DATA_FUNC (argv[2]));
- m4_builtin_define (handle, M4ARG (1), builtin, mode,
- M4_TOKEN_DATA_FUNC_TRACED (argv[2]));
+ m4_builtin_insert (M4ARG (1), handle, builtin);
}
- break;
-
- default:
- M4ERROR ((warning_status, 0,
- _("INTERNAL ERROR: Bad token data type in install_macro ()")));
- abort ();
+ return;
}
- return;
-}
-M4BUILTIN_HANDLER (define)
-{
- macro_install (argc, argv, M4_SYMBOL_INSERT);
+ /*NOTREACHED*/
+ assert (0);
}
M4BUILTIN_HANDLER (undefine)
@@ -195,7 +181,43 @@ M4BUILTIN_HANDLER (undefine)
M4BUILTIN_HANDLER (pushdef)
{
- macro_install (argc, argv, M4_SYMBOL_PUSHDEF);
+ if (m4_bad_argc (argv[0], argc, 2, 3))
+ return;
+
+ if (M4_TOKEN_DATA_TYPE (argv[1]) != M4_TOKEN_TEXT)
+ return;
+
+ if (argc == 2)
+ {
+ m4_macro_pushdef (M4ARG (1), NULL, "");
+ return;
+ }
+
+ switch (M4_TOKEN_DATA_TYPE (argv[2]))
+ {
+ case M4_TOKEN_TEXT:
+ m4_macro_pushdef (M4ARG (1), NULL, M4ARG (2));
+ return;
+
+ case M4_TOKEN_FUNC:
+ {
+ lt_dlhandle handle = M4_TOKEN_DATA_HANDLE (argv[2]);
+ const m4_builtin *builtin = 0;
+
+ /* If we find a TOKEN_FUNC with no defining module, then
+ somewhere along the way we have lost the module handle. */
+ assert (handle);
+
+ builtin = m4_builtin_find_by_func (m4_module_builtins (handle),
+ M4_TOKEN_DATA_FUNC (argv[2]));
+
+ m4_builtin_pushdef (M4ARG (1), handle, builtin);
+ }
+ return;
+ }
+
+ /*NOTREACHED*/
+ assert (0);
}
M4BUILTIN_HANDLER (popdef)
@@ -209,9 +231,11 @@ M4BUILTIN_HANDLER (popdef)
m4_symbol_popdef (M4ARG (1));
}
-
+
+
/* --- CONDITIONALS OF M4 --- */
+
M4BUILTIN_HANDLER (ifdef)
{
Index: src/freeze.c
===================================================================
RCS file: /cvsroot/m4/m4/src/freeze.c,v
retrieving revision 1.15
diff -u -p -u -r1.15 freeze.c
--- src/freeze.c 2001/09/07 23:42:24 1.15
+++ src/freeze.c 2001/09/08 01:39:42
@@ -472,7 +472,7 @@ reload_frozen_state (const char *name)
bp = m4_builtin_find_by_name (bt, string[1]);
if (bp)
- m4_builtin_define (handle, string[0], bp, M4_SYMBOL_PUSHDEF, 0);
+ m4_builtin_pushdef (string[0], handle, bp);
else
M4ERROR ((warning_status, 0,
_("`%s' from frozen file not found in builtin table!"),
@@ -647,7 +647,7 @@ reload_frozen_state (const char *name)
if (strcmp (m4_module_name (handle), string[2]) == 0)
break;
- m4_macro_define (handle, string[0], string[1], M4_SYMBOL_PUSHDEF);
+ m4_macro_pushdef (string[0], handle, string[1]);
}
break;
Index: src/main.c
===================================================================
RCS file: /cvsroot/m4/m4/src/main.c,v
retrieving revision 1.22
diff -u -p -u -r1.22 main.c
--- src/main.c 2001/09/07 10:46:33 1.22
+++ src/main.c 2001/09/08 01:39:44
@@ -435,7 +435,7 @@ warranty; not even for MERCHANTABILITY o
macro_value = "";
else
*macro_value++ = '\0';
- m4_macro_define (NULL, defines->macro, macro_value, M4_SYMBOL_INSERT);
+ m4_macro_insert (defines->macro, NULL, macro_value);
break;
case 'U':
--
())_. 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__/
[Prev in Thread] |
Current Thread |
[Next in Thread] |
- FYI: 10-gary-finish-symbol-lookup-specialisations.patch,
Gary V. Vaughan <=