The next in the series. I hope I got everything correct on the head
- the
addition of changesyntax made porting this patch more interesting,
because
there were more corner cases to think about. In general, this patch
adds
some timing overhead, and has little impact on memory (on head, it
actually uses slightly less memory).
The idea behind this patch is as follows. Since m4 allows
redefining the
behavior of the input engine on the fly (changequote, changecom,
changeword, changesyntax), we must ensure correct reparse in those
corner
cases. Our goal is to reparse text as few times as possible - once
text
has been parsed, we know what quoting rules it follows, so we cache
that
information alongside each string of parsed text. Then when
reparsing, we
can see if the quote age remains the same, in which case we don't
have to
waste time parsing that string, but can use the entire string as is.
Setting quote_age to be hardcoded to 0 will produce the same
results, but
without the benefit of reparsing.
2007-12-07 Eric Blake <address@hidden>
Stage 5: add notion of quote age.
* src/input.c: Comment cleanups.
(current_quote_age): New global variable.
(set_quote_age): New helper function.
(input_init, set_word_regexp): Use it.
(set_quotes, set_comment): Likewise, and detect no-op changes.
(quote_age, safe_quotes): New functions.
(next_token): Track quote age.
* src/m4.h (struct token_data): Add quote_age member.
(TOKEN_DATA_QUOTE_AGE, quote_age, safe_quotes): New prototypes.
* src/macro.c (struct macro_arguments): Add quote_age member.
(expand_token): Alter signature and track quote age.
(expand_input, expand_argument): All callers changed.
(collect_arguments, make_argv_ref): Track quote age.
(arg_text, arg_len, arg_func): Detect type mismatch.
* doc/m4.texinfo (Ifelse, Changequote): Add more tests.
(Incompatibilities): Fix typo.
* examples/wraplifo.m4: New file.
* examples/Makefile.am (EXTRA_DIST): Distribute it.