summaryrefslogtreecommitdiff
path: root/gcc/cpplex.c
diff options
context:
space:
mode:
authorneil <neil@138bc75d-0d04-0410-961f-82ee72b054a4>2001-09-24 22:53:12 +0000
committerneil <neil@138bc75d-0d04-0410-961f-82ee72b054a4>2001-09-24 22:53:12 +0000
commitf9b5f7426b95ed5809c2ef8257b962306844f87b (patch)
treef2b5dd04bb961bbe8dac8d988d52d574f0cb2b47 /gcc/cpplex.c
parent0be2ebc785cd4b366423534d0bfdce0499483e80 (diff)
downloadgcc-f9b5f7426b95ed5809c2ef8257b962306844f87b.tar.gz
* c-lex.c (cb_def_pragma): Update.
(c_lex): Update, and skip padding. * cppexp.c (lex, parse_defined): Update, remove unused variable. * cpphash.h (struct toklist): Delete. (union utoken): New. (struct cpp_context): Update. (struct cpp_reader): New members eof, avoid_paste. (_cpp_temp_token): New. * cppinit.c (cpp_create_reader): Update. * cpplex.c (_cpp_temp_token): New. (_cpp_lex_direct): Add PREV_WHITE when parsing args. (cpp_output_token): Don't print leading whitespace. (cpp_output_line): Update. * cpplib.c (glue_header_name, parse_include, get__Pragma_string, do_include_common, do_line, do_ident, do_pragma, do_pragma_dependency, _cpp_do__Pragma, parse_answer, parse_assertion): Update. (get_token_no_padding): New. * cpplib.h (CPP_PADDING): New. (AVOID_LPASTE): Delete. (struct cpp_token): New union member source. (cpp_get_token): Update. * cppmacro.c (macro_arg): Convert to use pointers to const tokens. (builtin_macro, paste_all_tokens, paste_tokens, funlike_invocation_p, replace_args, quote_string, stringify_arg, parse_arg, next_context, enter_macro_context, expand_arg, _cpp_pop_context, cpp_scan_nooutput, _cpp_backup_tokens, _cpp_create_definition): Update. (push_arg_context): Delete. (padding_token, push_token_context, push_ptoken_context): New. (make_string_token, make_number_token): Update, rename. (cpp_get_token): Update to handle tokens as pointers to const, and insert padding appropriately. * cppmain.c (struct printer): New member prev. (check_multiline_token): Constify. (do_preprocessing, cb_line_change): Update. (scan_translation_unit): Update to handle spacing. * scan-decls.c (get_a_token): New. (skip_to_closing_brace, scan_decls): Update. * fix-header.c (read_scan_file): Update. * doc/cpp.texi: Update. * gcc.dg/cpp/macro10.c: New test. * gcc.dg/cpp/strify3.c: New test. * gcc.dg/cpp/spacing1.c: Add tests. * gcc.dg/cpp/19990703-1.c: Remove bogus test. * gcc.dg/cpp/20000625-2.c: Fudge to pass. git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@45793 138bc75d-0d04-0410-961f-82ee72b054a4
Diffstat (limited to 'gcc/cpplex.c')
-rw-r--r--gcc/cpplex.c50
1 files changed, 37 insertions, 13 deletions
diff --git a/gcc/cpplex.c b/gcc/cpplex.c
index e734f4021b2..e822ba57719 100644
--- a/gcc/cpplex.c
+++ b/gcc/cpplex.c
@@ -931,6 +931,29 @@ next_tokenrun (run)
return run->next;
}
+/* Allocate a single token that is invalidated at the same time as the
+ rest of the tokens on the line. Has its line and col set to the
+ same as the last lexed token, so that diagnostics appear in the
+ right place. */
+cpp_token *
+_cpp_temp_token (pfile)
+ cpp_reader *pfile;
+{
+ cpp_token *old, *result;
+
+ old = pfile->cur_token - 1;
+ if (pfile->cur_token == pfile->cur_run->limit)
+ {
+ pfile->cur_run = next_tokenrun (pfile->cur_run);
+ pfile->cur_token = pfile->cur_run->base;
+ }
+
+ result = pfile->cur_token++;
+ result->line = old->line;
+ result->col = old->col;
+ return result;
+}
+
/* Lex a token into RESULT (external interface). Takes care of issues
like directive handling, token lookahead, multiple include
opimisation and skipping. */
@@ -1057,6 +1080,8 @@ _cpp_lex_direct (pfile)
buffer->saved_flags = BOL;
if (! pfile->state.in_directive)
{
+ if (pfile->state.parsing_args == 2)
+ buffer->saved_flags |= PREV_WHITE;
if (!pfile->keep_tokens)
{
pfile->cur_run = &pfile->base_run;
@@ -1476,17 +1501,14 @@ cpp_type2name (type)
return (const char *) token_spellings[type].name;
}
-/* Writes the spelling of token to FP. Separate from cpp_spell_token
- for efficiency - to avoid double-buffering. Also, outputs a space
- if PREV_WHITE is flagged. */
+/* Writes the spelling of token to FP, without any preceding space.
+ Separated from cpp_spell_token for efficiency - to avoid stdio
+ double-buffering. */
void
cpp_output_token (token, fp)
const cpp_token *token;
FILE *fp;
{
- if (token->flags & PREV_WHITE)
- putc (' ', fp);
-
switch (TOKEN_SPELL (token))
{
case SPELL_OPERATOR:
@@ -1729,20 +1751,22 @@ cpp_avoid_paste (pfile, token1, token2)
}
/* Output all the remaining tokens on the current line, and a newline
- character, to FP. Leading whitespace is removed. */
+ character, to FP. Leading whitespace is removed. If there are
+ macros, special token padding is not performed. */
void
cpp_output_line (pfile, fp)
cpp_reader *pfile;
FILE *fp;
{
- cpp_token token;
+ const cpp_token *token;
- cpp_get_token (pfile, &token);
- token.flags &= ~PREV_WHITE;
- while (token.type != CPP_EOF)
+ token = cpp_get_token (pfile);
+ while (token->type != CPP_EOF)
{
- cpp_output_token (&token, fp);
- cpp_get_token (pfile, &token);
+ cpp_output_token (token, fp);
+ token = cpp_get_token (pfile);
+ if (token->flags & PREV_WHITE)
+ putc (' ', fp);
}
putc ('\n', fp);