-/* Deal with the expansion caused by the DEF_VEC_x macros. */
-
-typedef struct macro
-{
- const char *name;
- const char *expansion;
- struct macro *next;
-} macro_t;
-
-static const macro_t macro_defs[] =
-{
-#define IN_GENGTYPE 1
-#include "vec.h"
- {NULL, NULL, NULL}
-};
-
-/* Chain of macro expansions to do at end of scanning. */
-static macro_t *macro_expns;
-
-/* Push macro NAME (NAME_LEN) with argument ARG (ARG_LEN) onto the
- expansion queue. We ensure NAME is known at this point. */
-
-static void
-push_macro_expansion (const char *name, unsigned name_len,
- const char *arg, unsigned arg_len)
-{
- unsigned ix;
-
- for (ix = 0; macro_defs[ix].name; ix++)
- if (strlen (macro_defs[ix].name) == name_len
- && !memcmp (name, macro_defs[ix].name, name_len))
- {
- macro_t *expansion = xmalloc (sizeof (*expansion));
-
- expansion->next = macro_expns;
- expansion->name = xmemdup (arg, arg_len, arg_len+1);
- expansion->expansion = macro_defs[ix].expansion;
- macro_expns = expansion;
- return;
- }
- error_at_line (&lexer_line, "unrecognized macro `%.*s(%.*s)'",
- name_len, name, arg_len, arg);
-}
-
-/* Attempt to read some input. Use fread until we're at the end of
- file. At end of file expand the next queued macro. We presume the
- buffer is large enough for the entire expansion. */
-
-static unsigned
-macro_input (char *buffer, unsigned size)
-{
- unsigned result;
-
- result = fread (buffer, 1, size, yyin);
- if (result)
- /*NOP*/;
- else if (ferror (yyin))
- YY_FATAL_ERROR ("read of source file failed");
- else if (macro_expns)
- {
- const char *expn;
- unsigned len;
-
- for (expn = macro_expns->expansion; *expn; expn++)
- {
- if (*expn == '#')
- {
- if (buffer[result-1] == ' ' && buffer[result-2] == '_')
- result--;
- len = strlen (macro_expns->name);
- memcpy (&buffer[result], macro_expns->name, len);
- result += len;
- }
- else
- {
- buffer[result++] = *expn;
- if (*expn == ';' || *expn == '{')
- buffer[result++] = '\n';
- }
- }
- if (result > size)
- YY_FATAL_ERROR ("buffer too small to expand macro");
- macro_expns = macro_expns->next;
- }
- return result;
-}
-