Make gnulib a git submodule.
[m4.git] / m4 / m4private.h
blobb0cbe963ea4cf9ab4155b4a0b2ad6fa3dc440531
1 /* GNU m4 -- A simple macro processor
2 Copyright (C) 1989, 1990, 1991, 1992, 1993, 1994, 1998, 1999, 2004,
3 2005, 2006, 2007, 2008, 2009 Free Software Foundation, Inc.
5 This file is part of GNU M4.
7 GNU M4 is free software: you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation, either version 3 of the License, or
10 (at your option) any later version.
12 GNU M4 is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program. If not, see <http://www.gnu.org/licenses/>.
21 #ifndef M4PRIVATE_H
22 #define M4PRIVATE_H 1
24 #include <m4/m4module.h>
25 #include <ltdl.h>
27 #include "cloexec.h"
28 #include "quotearg.h"
29 #include "xmemdup0.h"
31 typedef struct m4__search_path_info m4__search_path_info;
32 typedef struct m4__macro_arg_stacks m4__macro_arg_stacks;
33 typedef struct m4__symbol_chain m4__symbol_chain;
35 typedef enum {
36 M4_SYMBOL_VOID, /* Traced but undefined, u is invalid. */
37 M4_SYMBOL_TEXT, /* Plain text, u.u_t is valid. */
38 M4_SYMBOL_FUNC, /* Builtin function, u.func is valid. */
39 M4_SYMBOL_PLACEHOLDER, /* Placeholder for unknown builtin from -R. */
40 M4_SYMBOL_COMP /* Composite symbol, u.u_c.c is valid. */
41 } m4__symbol_type;
43 #define BIT_TEST(flags, bit) (((flags) & (bit)) == (bit))
44 #define BIT_SET(flags, bit) ((flags) |= (bit))
45 #define BIT_RESET(flags, bit) ((flags) &= ~(bit))
47 /* Gnulib's stdbool doesn't work with bool bitfields. For nicer
48 debugging, use bool when we know it works, but use the more
49 portable unsigned int elsewhere. */
50 #if __GNUC__ > 2
51 typedef bool bool_bitfield;
52 #else
53 typedef unsigned int bool_bitfield;
54 #endif /* !__GNUC__ */
57 /* --- CONTEXT MANAGEMENT --- */
59 struct m4 {
60 m4_symbol_table * symtab;
61 m4_syntax_table * syntax;
63 const char * current_file; /* Current input file. */
64 int current_line; /* Current input line. */
65 int output_line; /* Current output line. */
67 FILE * debug_file; /* File for debugging output. */
68 m4_obstack trace_messages;
69 int exit_status; /* Cumulative exit status. */
70 int current_diversion; /* Current output diversion. */
72 /* Option flags (set in src/main.c). */
73 size_t nesting_limit; /* -L */
74 int debug_level; /* -d */
75 size_t max_debug_arg_length; /* -l */
76 int regexp_syntax; /* -r */
77 int opt_flags;
79 /* __PRIVATE__: */
80 m4__search_path_info *search_path; /* The list of path directories. */
81 m4__macro_arg_stacks *arg_stacks; /* Array of current argv refs. */
82 size_t stacks_count; /* Size of arg_stacks. */
83 size_t expansion_level;/* Macro call nesting level. */
86 #define M4_OPT_PREFIX_BUILTINS_BIT (1 << 0) /* -P */
87 #define M4_OPT_SUPPRESS_WARN_BIT (1 << 1) /* -Q */
88 #define M4_OPT_DISCARD_COMMENTS_BIT (1 << 2) /* -c */
89 #define M4_OPT_INTERACTIVE_BIT (1 << 3) /* -e */
90 #define M4_OPT_SYNCOUTPUT_BIT (1 << 4) /* -s */
91 #define M4_OPT_POSIXLY_CORRECT_BIT (1 << 5) /* -G/POSIXLY_CORRECT */
92 #define M4_OPT_FATAL_WARN_BIT (1 << 6) /* -E once */
93 #define M4_OPT_WARN_EXIT_BIT (1 << 7) /* -E twice */
94 #define M4_OPT_SAFER_BIT (1 << 8) /* --safer */
96 /* Fast macro versions of accessor functions for public fields of m4,
97 that also have an identically named function exported in m4module.h. */
98 #ifdef NDEBUG
99 # define m4_get_symbol_table(C) ((C)->symtab)
100 # define m4_set_symbol_table(C, V) ((C)->symtab = (V))
101 # define m4_get_syntax_table(C) ((C)->syntax)
102 # define m4_set_syntax_table(C, V) ((C)->syntax = (V))
103 # define m4_get_current_file(C) ((C)->current_file)
104 # define m4_set_current_file(C, V) ((C)->current_file = (V))
105 # define m4_get_current_line(C) ((C)->current_line)
106 # define m4_set_current_line(C, V) ((C)->current_line = (V))
107 # define m4_get_output_line(C) ((C)->output_line)
108 # define m4_set_output_line(C, V) ((C)->output_line = (V))
109 # define m4_get_debug_file(C) ((C)->debug_file)
110 # define m4_set_debug_file(C, V) ((C)->debug_file = (V))
111 # define m4_get_trace_messages(C) ((C)->trace_messages)
112 # define m4_set_trace_messages(C, V) ((C)->trace_messages = (V))
113 # define m4_get_exit_status(C) ((C)->exit_status)
114 # define m4_set_exit_status(C, V) ((C)->exit_status = (V))
115 # define m4_get_current_diversion(C) ((C)->current_diversion)
116 # define m4_set_current_diversion(C, V) ((C)->current_diversion = (V))
117 # define m4_get_nesting_limit_opt(C) ((C)->nesting_limit)
118 # define m4_set_nesting_limit_opt(C, V) ((C)->nesting_limit = (V))
119 # define m4_get_debug_level_opt(C) ((C)->debug_level)
120 # define m4_set_debug_level_opt(C, V) ((C)->debug_level = (V))
121 # define m4_get_max_debug_arg_length_opt(C) ((C)->max_debug_arg_length)
122 # define m4_set_max_debug_arg_length_opt(C, V) ((C)->max_debug_arg_length=(V))
123 # define m4_get_regexp_syntax_opt(C) ((C)->regexp_syntax)
124 # define m4_set_regexp_syntax_opt(C, V) ((C)->regexp_syntax = (V))
126 # define m4_get_prefix_builtins_opt(C) \
127 (BIT_TEST((C)->opt_flags, M4_OPT_PREFIX_BUILTINS_BIT))
128 # define m4_get_suppress_warnings_opt(C) \
129 (BIT_TEST((C)->opt_flags, M4_OPT_SUPPRESS_WARN_BIT))
130 # define m4_get_discard_comments_opt(C) \
131 (BIT_TEST((C)->opt_flags, M4_OPT_DISCARD_COMMENTS_BIT))
132 # define m4_get_interactive_opt(C) \
133 (BIT_TEST((C)->opt_flags, M4_OPT_INTERACTIVE_BIT))
134 # define m4_get_syncoutput_opt(C) \
135 (BIT_TEST((C)->opt_flags, M4_OPT_SYNCOUTPUT_BIT))
136 # define m4_get_posixly_correct_opt(C) \
137 (BIT_TEST((C)->opt_flags, M4_OPT_POSIXLY_CORRECT_BIT))
138 # define m4_get_fatal_warnings_opt(C) \
139 (BIT_TEST((C)->opt_flags, M4_OPT_FATAL_WARN_BIT))
140 # define m4_get_warnings_exit_opt(C) \
141 (BIT_TEST((C)->opt_flags, M4_OPT_WARN_EXIT_BIT))
142 # define m4_get_safer_opt(C) \
143 (BIT_TEST((C)->opt_flags, M4_OPT_SAFER_BIT))
145 /* No fast opt bit set macros, as they would need to evaluate their
146 arguments more than once, which would subtly change their semantics. */
147 #endif
149 /* Accessors for private fields of m4, which have no function version
150 exported in m4module.h. */
151 #define m4__get_search_path(C) ((C)->search_path)
154 /* --- BUILTIN MANAGEMENT --- */
156 /* Internal representation of loaded builtins. */
157 struct m4__builtin
159 /* Copied from module's BUILTIN_SYMBOL table, although builtin.flags
160 can be used for additional bits beyond what is allowed for
161 modules. */
162 m4_builtin builtin;
163 m4_module *module; /* Module that owns this builtin. */
165 typedef struct m4__builtin m4__builtin;
167 extern void m4__set_symbol_value_builtin (m4_symbol_value *,
168 const m4__builtin *);
169 extern void m4__builtin_print (m4_obstack *, const m4__builtin *, bool,
170 m4__symbol_chain **, const m4_string_pair *,
171 bool);
174 /* --- MODULE MANAGEMENT --- */
176 #define USER_MODULE_PATH_ENV "M4MODPATH"
177 #define BUILTIN_SYMBOL "m4_builtin_table"
178 #define MACRO_SYMBOL "m4_macro_table"
179 #define INIT_SYMBOL "m4_init_module"
180 #define FINISH_SYMBOL "m4_finish_module"
182 /* Representation of a loaded m4 module. */
183 struct m4_module
185 lt_dlhandle handle; /* All ltdl module information. */
186 int refcount; /* Count of loads not matched by unload. */
187 m4__builtin *builtins; /* Sorted array of builtins. */
188 size_t builtins_len; /* Number of builtins. */
191 extern void m4__module_init (m4 *context);
192 extern m4_module * m4__module_open (m4 *context, const char *name,
193 m4_obstack *obs);
194 extern void m4__module_exit (m4 *context);
195 extern m4_module * m4__module_next (m4_module *);
196 extern m4_module * m4__module_find (const char *name);
198 /* Fast macro versions of symbol table accessor functions, that also
199 have an identically named function exported in m4module.h. */
200 #ifdef NDEBUG
201 # define m4_module_refcount(M) ((M)->refcount)
202 #endif
205 /* --- SYMBOL TABLE MANAGEMENT --- */
207 struct m4_symbol
209 bool traced; /* True if this symbol is traced. */
210 m4_symbol_value *value; /* Linked list of pushdef'd values. */
213 /* Type of a link in a symbol chain. */
214 enum m4__symbol_chain_type
216 M4__CHAIN_STR, /* Link contains a string, u.u_s is valid. */
217 M4__CHAIN_FUNC, /* Link contains builtin token, u.builtin is valid. */
218 M4__CHAIN_ARGV, /* Link contains a $@ reference, u.u_a is valid. */
219 M4__CHAIN_LOC /* Link contains m4wrap location, u.u_l is valid. */
222 /* Composite symbols are built of a linked list of chain objects. */
223 struct m4__symbol_chain
225 m4__symbol_chain *next; /* Pointer to next link of chain. */
226 enum m4__symbol_chain_type type; /* Type of this link. */
227 unsigned int quote_age; /* Quote_age of this link, or 0. */
228 union
230 struct
232 const char *str; /* Pointer to text. */
233 size_t len; /* Remaining length of str. */
234 size_t level; /* Expansion level of content, or SIZE_MAX. */
235 } u_s; /* M4__CHAIN_STR. */
236 const m4__builtin *builtin; /* M4__CHAIN_FUNC. */
237 struct
239 m4_macro_args *argv; /* Reference to earlier $@. */
240 size_t index; /* Argument index within argv. */
241 bool_bitfield flatten : 1; /* True to treat builtins as text. */
242 bool_bitfield comma : 1; /* True when `,' is next input. */
243 bool_bitfield skip_last : 1; /* True if last argument omitted. */
244 bool_bitfield has_func : 1; /* True if argv includes func. */
245 const m4_string_pair *quotes; /* NULL for $*, quotes for $@. */
246 } u_a; /* M4__CHAIN_ARGV. */
247 struct
249 const char *file; /* File where subsequent links originate. */
250 int line; /* Line where subsequent links originate. */
251 } u_l; /* M4__CHAIN_LOC. */
252 } u;
255 /* A symbol value is used both for values associated with a macro
256 name, and for arguments to a macro invocation. */
257 struct m4_symbol_value
259 m4_symbol_value * next;
260 m4_module * module;
261 unsigned int flags;
263 m4_hash * arg_signature;
264 size_t min_args;
265 size_t max_args;
266 size_t pending_expansions;
268 m4__symbol_type type;
269 union
271 struct
273 size_t len; /* Length of string. */
274 const char * text; /* String contents. */
275 /* Quote age when this string was built, or zero to force a
276 rescan of the string. Ignored for 0 len. */
277 unsigned int quote_age;
278 } u_t; /* Valid when type is TEXT, PLACEHOLDER. */
279 const m4__builtin * builtin;/* Valid when type is FUNC. */
280 struct
282 m4__symbol_chain *chain; /* First link of the chain. */
283 m4__symbol_chain *end; /* Last link of the chain. */
284 bool_bitfield wrapper : 1; /* True if this is a $@ ref. */
285 bool_bitfield has_func : 1; /* True if chain includes func. */
286 } u_c; /* Valid when type is COMP. */
287 } u;
290 /* Structure describing all arguments to a macro, including the macro
291 name at index 0. */
292 struct m4_macro_args
294 /* One more than the highest actual argument. May be larger than
295 arraylen since the array can refer to multiple arguments via a
296 single $@ reference. */
297 size_t argc;
298 /* False unless the macro expansion refers to $@; determines whether
299 this object can be freed at end of macro expansion or must wait
300 until all references have been rescanned. */
301 bool_bitfield inuse : 1;
302 /* False if all arguments are just text or func, true if this argv
303 refers to another one. */
304 bool_bitfield wrapper : 1;
305 /* False if all arguments belong to this argv, true if some of them
306 include references to another. */
307 bool_bitfield has_ref : 1;
308 /* True to flatten builtins contained in references. */
309 bool_bitfield flatten : 1;
310 /* True if any token contains builtins. */
311 bool_bitfield has_func : 1;
312 /* The value of quote_age for all tokens, or 0 if quote_age changed
313 during parsing or any token is potentially unsafe and requires a
314 rescan. */
315 unsigned int quote_age;
316 /* The context of the macro call during expansion, and NULL in a
317 back-reference. */
318 m4_call_info *info;
319 size_t level; /* Which obstack owns this argv. */
320 size_t arraylen; /* True length of allocated elements in array. */
321 /* Used as a variable-length array, storing information about each
322 argument. */
323 m4_symbol_value *array[FLEXIBLE_ARRAY_MEMBER];
326 /* Internal structure for managing multiple argv references. See
327 macro.c for a much more detailed comment on usage. */
328 struct m4__macro_arg_stacks
330 size_t refcount; /* Number of active $@ references at this level. */
331 size_t argcount; /* Number of argv at this level. */
332 m4_obstack *args; /* Content of arguments. */
333 m4_obstack *argv; /* Argv pointers into args. */
334 void *args_base; /* Location for clearing the args obstack. */
335 void *argv_base; /* Location for clearing the argv obstack. */
338 /* Opaque structure for managing call context information. Contains
339 the context used in tracing and error messages that was valid at
340 the start of the macro expansion, even if argument collection
341 changes global context in the meantime. */
342 struct m4_call_info
344 const char *file; /* The file containing the macro invocation. */
345 int line; /* The line the macro was called on. */
346 size_t call_id; /* The unique sequence call id of the macro. */
347 int trace : 1; /* True to trace this macro. */
348 int debug_level : 31; /* The debug level for tracing the macro call. */
349 const char *name; /* The macro name. */
350 size_t name_len; /* The length of name. */
353 extern size_t m4__adjust_refcount (m4 *, size_t, bool);
354 extern bool m4__arg_adjust_refcount (m4 *, m4_macro_args *, bool);
355 extern void m4__push_arg_quote (m4 *, m4_obstack *, m4_macro_args *,
356 size_t, const m4_string_pair *);
357 extern bool m4__arg_print (m4 *, m4_obstack *, m4_macro_args *,
358 size_t, const m4_string_pair *, bool,
359 m4__symbol_chain **, const char *,
360 size_t *, bool, bool);
362 #define VALUE_NEXT(T) ((T)->next)
363 #define VALUE_MODULE(T) ((T)->module)
364 #define VALUE_FLAGS(T) ((T)->flags)
365 #define VALUE_ARG_SIGNATURE(T) ((T)->arg_signature)
366 #define VALUE_MIN_ARGS(T) ((T)->min_args)
367 #define VALUE_MAX_ARGS(T) ((T)->max_args)
368 #define VALUE_PENDING(T) ((T)->pending_expansions)
370 #define SYMBOL_NEXT(S) (VALUE_NEXT ((S)->value))
371 #define SYMBOL_MODULE(S) (VALUE_MODULE ((S)->value))
372 #define SYMBOL_FLAGS(S) (VALUE_FLAGS ((S)->value))
373 #define SYMBOL_ARG_SIGNATURE(S) (VALUE_ARG_SIGNATURE ((S)->value))
374 #define SYMBOL_MIN_ARGS(S) (VALUE_MIN_ARGS ((S)->value))
375 #define SYMBOL_MAX_ARGS(S) (VALUE_MAX_ARGS ((S)->value))
376 #define SYMBOL_PENDING(S) (VALUE_PENDING ((S)->value))
378 /* Fast macro versions of symbol table accessor functions,
379 that also have an identically named function exported in m4module.h. */
380 #ifdef NDEBUG
381 # define m4_get_symbol_traced(S) ((S)->traced)
382 # define m4_get_symbol_value(S) ((S)->value)
383 # define m4_set_symbol_value(S, V) ((S)->value = (V))
385 /* m4_symbol_value_{create,delete} are too complex for a simple macro. */
387 # define m4_is_symbol_value_text(V) ((V)->type == M4_SYMBOL_TEXT)
388 # define m4_is_symbol_value_func(V) ((V)->type == M4_SYMBOL_FUNC)
389 # define m4_is_symbol_value_void(V) ((V)->type == M4_SYMBOL_VOID)
390 # define m4_is_symbol_value_placeholder(V) \
391 ((V)->type == M4_SYMBOL_PLACEHOLDER)
392 # define m4_get_symbol_value_text(V) ((V)->u.u_t.text)
393 # define m4_get_symbol_value_len(V) ((V)->u.u_t.len)
394 # define m4_get_symbol_value_quote_age(V) ((V)->u.u_t.quote_age)
395 # define m4_get_symbol_value_func(V) ((V)->u.builtin->builtin.func)
396 # define m4_get_symbol_value_builtin(V) (&(V)->u.builtin->builtin)
397 # define m4_get_symbol_value_placeholder(V) \
398 ((V)->u.u_t.text)
399 # define m4_symbol_value_flatten_args(V) \
400 (BIT_TEST ((V)->flags, VALUE_FLATTEN_ARGS_BIT))
402 # define m4_set_symbol_value_text(V, T, L, A) \
403 ((V)->type = M4_SYMBOL_TEXT, (V)->u.u_t.text = (T), \
404 (V)->u.u_t.len = (L), (V)->u.u_t.quote_age = (A))
405 # define m4_set_symbol_value_placeholder(V, T) \
406 ((V)->type = M4_SYMBOL_PLACEHOLDER, (V)->u.u_t.text = (T))
407 # define m4__set_symbol_value_builtin(V, B) \
408 ((V)->type = M4_SYMBOL_FUNC, (V)->u.builtin = (B), \
409 VALUE_MODULE (V) = (B)->module, \
410 VALUE_FLAGS (V) = (B)->builtin.flags, \
411 VALUE_MIN_ARGS (V) = (B)->builtin.min_args, \
412 VALUE_MAX_ARGS (V) = (B)->builtin.max_args)
413 #endif
417 /* m4_symbol_value.flags bit masks. Be sure these are a consistent
418 superset of the M4_BUILTIN_* bit masks, so we can copy
419 m4_builtin.flags to m4_symbol_arg.flags. We can use additional
420 bits for private use. */
422 #define VALUE_FLATTEN_ARGS_BIT (1 << 0)
423 #define VALUE_BLIND_ARGS_BIT (1 << 1)
424 #define VALUE_SIDE_EFFECT_ARGS_BIT (1 << 2)
425 #define VALUE_DELETED_BIT (1 << 3)
428 struct m4_symbol_arg {
429 int index;
430 int flags;
431 char * default_val;
434 #define SYMBOL_ARG_INDEX(A) ((A)->index)
435 #define SYMBOL_ARG_FLAGS(A) ((A)->flags)
436 #define SYMBOL_ARG_DEFAULT(A) ((A)->default_val)
438 /* m4_symbol_arg.flags bit masks: */
440 #define SYMBOL_ARG_REST_BIT (1 << 0)
441 #define SYMBOL_ARG_KEY_BIT (1 << 1)
443 extern void m4__symtab_remove_module_references (m4_symbol_table *,
444 m4_module *);
445 extern bool m4__symbol_value_print (m4 *, m4_symbol_value *, m4_obstack *,
446 const m4_string_pair *, bool,
447 m4__symbol_chain **, size_t *, bool);
451 /* --- SYNTAX TABLE MANAGEMENT --- */
453 /* CHAR_RETRY must be last, because we size the syntax table to hold
454 all other characters and sentinels. */
455 #define CHAR_EOF (UCHAR_MAX + 1) /* Return on EOF. */
456 #define CHAR_BUILTIN (UCHAR_MAX + 2) /* Return for BUILTIN token. */
457 #define CHAR_QUOTE (UCHAR_MAX + 3) /* Return for quoted string. */
458 #define CHAR_ARGV (UCHAR_MAX + 4) /* Return for $@ reference. */
459 #define CHAR_RETRY (UCHAR_MAX + 5) /* Return for end of input block. */
461 #define DEF_LQUOTE "`" /* Default left quote delimiter. */
462 #define DEF_RQUOTE "\'" /* Default right quote delimiter. */
463 #define DEF_BCOMM "#" /* Default begin comment delimiter. */
464 #define DEF_ECOMM "\n" /* Default end comment delimiter. */
466 struct m4_syntax_table {
467 /* Please read the comment at the top of input.c for details. table
468 holds the current syntax, and orig holds the default syntax. */
469 unsigned short table[CHAR_RETRY];
470 unsigned short orig[CHAR_RETRY];
472 m4_string_pair quote; /* Quote delimiters. */
473 m4_string_pair comm; /* Comment delimiters. */
475 char dollar; /* Dollar character, if is_single_dollar. */
477 /* True iff only one start and end quote delimiter exist. */
478 bool_bitfield is_single_quotes : 1;
480 /* True iff only one start and end comment delimiter exist. */
481 bool_bitfield is_single_comments : 1;
483 /* True iff only one byte has M4_SYNTAX_DOLLAR. */
484 bool_bitfield is_single_dollar : 1;
486 /* True iff some character has M4_SYNTAX_ESCAPE. */
487 bool_bitfield is_macro_escaped : 1;
489 /* True iff a changesyntax call has impacted something that requires
490 cleanup at the end. */
491 bool_bitfield suspect : 1;
493 /* Track the number of changesyntax calls. This saturates at
494 0xffff, so the idea is that most users won't be changing the
495 syntax that frequently; perhaps in the future we will cache
496 frequently used syntax schemes by index. */
497 unsigned short syntax_age;
499 /* Track the current quote age, determined by all significant
500 changequote, changecom, and changesyntax calls, since any of
501 these can alter the rescan of a prior parameter in a quoted
502 context. */
503 unsigned int quote_age;
505 /* Track a cached quote pair on the input obstack. */
506 m4_string_pair *cached_quote;
508 /* Storage for a simple cached quote that can be recreated on the fly. */
509 char cached_lquote[2];
510 char cached_rquote[2];
511 m4_string_pair cached_simple;
514 /* Fast macro versions of syntax table accessor functions,
515 that also have an identically named function exported in m4module.h. */
516 #ifdef NDEBUG
517 # define m4_get_syntax_lquote(S) ((S)->quote.str1)
518 # define m4_get_syntax_rquote(S) ((S)->quote.str2)
519 # define m4_get_syntax_bcomm(S) ((S)->comm.str1)
520 # define m4_get_syntax_ecomm(S) ((S)->comm.str2)
521 # define m4_get_syntax_quotes(S) (&(S)->quote)
522 # define m4_get_syntax_comments(S) (&(S)->comm)
524 # define m4_is_syntax_single_quotes(S) ((S)->is_single_quotes)
525 # define m4_is_syntax_single_comments(S) ((S)->is_single_comments)
526 # define m4_is_syntax_single_dollar(S) ((S)->is_single_dollar)
527 # define m4_is_syntax_macro_escaped(S) ((S)->is_macro_escaped)
528 #endif
530 /* Return the current quote age. */
531 #define m4__quote_age(S) ((S)->quote_age)
533 /* Return true if the current quote age guarantees that parsing the
534 current token in the context of a quoted string of the same quote
535 age will give the same parse. */
536 #define m4__safe_quotes(S) (((S)->quote_age & 0xffff) != 0)
538 /* Set or refresh the cached quote. */
539 extern const m4_string_pair *m4__quote_cache (m4_syntax_table *,
540 m4_obstack *obs, unsigned int,
541 const m4_string_pair *);
543 /* Clear the cached quote. */
544 #define m4__quote_uncache(S) ((S)->cached_quote = NULL)
547 /* --- MACRO MANAGEMENT --- */
549 /* Various different token types. */
550 typedef enum {
551 M4_TOKEN_EOF, /* End of file, M4_SYMBOL_VOID. */
552 M4_TOKEN_NONE, /* Discardable token, M4_SYMBOL_VOID. */
553 M4_TOKEN_STRING, /* Quoted string, M4_SYMBOL_TEXT or M4_SYMBOL_COMP. */
554 M4_TOKEN_COMMENT, /* Comment, M4_SYMBOL_TEXT or M4_SYMBOL_COMP. */
555 M4_TOKEN_SPACE, /* Whitespace, M4_SYMBOL_TEXT. */
556 M4_TOKEN_WORD, /* An identifier, M4_SYMBOL_TEXT. */
557 M4_TOKEN_OPEN, /* Argument list start, M4_SYMBOL_TEXT. */
558 M4_TOKEN_COMMA, /* Argument separator, M4_SYMBOL_TEXT. */
559 M4_TOKEN_CLOSE, /* Argument list end, M4_SYMBOL_TEXT. */
560 M4_TOKEN_SIMPLE, /* Single character, M4_SYMBOL_TEXT. */
561 M4_TOKEN_MACDEF, /* Builtin token, M4_SYMBOL_FUNC or M4_SYMBOL_COMP. */
562 M4_TOKEN_ARGV /* A series of parameters, M4_SYMBOL_COMP. */
563 } m4__token_type;
565 extern void m4__make_text_link (m4_obstack *, m4__symbol_chain **,
566 m4__symbol_chain **);
567 extern void m4__append_builtin (m4_obstack *, const m4__builtin *,
568 m4__symbol_chain **,
569 m4__symbol_chain **);
570 extern bool m4__push_symbol (m4 *, m4_symbol_value *, size_t,
571 bool);
572 extern m4_obstack *m4__push_wrapup_init (m4 *, const m4_call_info *,
573 m4__symbol_chain ***);
574 extern void m4__push_wrapup_finish (void);
575 extern m4__token_type m4__next_token (m4 *, m4_symbol_value *, int *,
576 m4_obstack *, bool,
577 const m4_call_info *);
578 extern bool m4__next_token_is_open (m4 *);
580 /* Fast macro versions of macro argv accessor functions,
581 that also have an identically named function exported in m4module.h. */
582 #ifdef NDEBUG
583 # define m4_arg_argc(A) (A)->argc
584 # define m4_arg_info(A) (A)->info
585 # define m4_arg_scratch(C) \
586 ((C)->arg_stacks[(C)->expansion_level - 1].argv)
587 #endif /* NDEBUG */
590 /* --- PATH MANAGEMENT --- */
592 typedef struct m4__search_path m4__search_path;
594 struct m4__search_path {
595 m4__search_path *next; /* next directory to search */
596 const char *dir; /* directory */
597 int len;
600 struct m4__search_path_info {
601 m4__search_path *list; /* the list of path directories */
602 m4__search_path *list_end; /* the end of same */
603 int max_length; /* length of longest directory name */
606 extern void m4__include_init (m4 *);
609 /* Debugging the memory allocator. */
611 #if WITH_DMALLOC
612 # define DMALLOC_FUNC_CHECK
613 # include <dmalloc.h>
614 #endif /* WITH_DMALLOC */
618 /* Convenience macro to zero a variable after freeing it. */
619 #define DELETE(Expr) ((Expr) = (free ((void *) Expr), (void *) 0))
622 #if DEBUG
623 # define DEBUG_INCL 1
624 # define DEBUG_INPUT 1
625 # define DEBUG_MACRO 1
626 # define DEBUG_MODULES 1
627 # define DEBUG_OUTPUT 1
628 # define DEBUG_STKOVF 1
629 # define DEBUG_SYM 1
630 # define DEBUG_SYNTAX 1
631 #endif
633 #endif /* m4private.h */