return true;
}
- /* The first 'n_call' tokens starting at 'middle' will be replaced by a
+ /* Now expand the macro.
+
+ We temporarily add the macro call's tokens to the source in case the macro
+ expansion calls msg() to report an error and error processing tries to get
+ the location of the error with, e.g. lex_get_first_line_number(), which
+ would re-enter this code. This is a kluge; it might be cleaner to pass
+ the line number into macro_expander_get_expansion(). */
+ src->middle += n_call;
+ struct macro_tokens expansion = { .n = 0 };
+ macro_expander_get_expansion (me, src->reader->syntax, &expansion);
+ macro_expander_destroy (me);
+ src->middle -= n_call;
+
+ /* Convert the macro expansion into syntax for possible error messages later. */
+ size_t *ofs = xnmalloc (expansion.n, sizeof *ofs);
+ size_t *len = xnmalloc (expansion.n, sizeof *len);
+ struct string s = DS_EMPTY_INITIALIZER;
+ macro_tokens_to_representation (&expansion, &s, ofs, len);
+
+ if (settings_get_mprint ())
+ output_item_submit (text_item_create (TEXT_ITEM_LOG, ds_cstr (&s),
+ _("Macro Expansion")));
+
+ /* The first 'n_call' tokens starting at 'middle' will be replaced by the
macro expansion. There might be more tokens after that, up to 'front'.
Figure out the boundary of the macro call in the syntax, to go into the
& (src->capacity - 1)];
src->front = src->middle;
- /* Now expand the macro. */
- struct macro_tokens expansion = { .n = 0 };
- macro_expander_get_expansion (me, src->reader->syntax, &expansion);
- macro_expander_destroy (me);
-
- /* Convert the macro expansion into syntax for possible error messages later. */
- size_t *ofs = xnmalloc (expansion.n, sizeof *ofs);
- size_t *len = xnmalloc (expansion.n, sizeof *len);
- struct string s = DS_EMPTY_INITIALIZER;
- macro_tokens_to_representation (&expansion, &s, ofs, len);
-
- if (settings_get_mprint ())
- output_item_submit (text_item_create (TEXT_ITEM_LOG, ds_cstr (&s),
- _("Macro Expansion")));
-
/* Append the macro expansion tokens to the lookahead. */
char *macro_rep = ds_steal_cstr (&s);
size_t *ref_cnt = xmalloc (sizeof *ref_cnt);