diff options
author | Neil Booth <neil@daikokuya.demon.co.uk> | 2001-09-24 22:53:12 +0000 |
---|---|---|
committer | Neil Booth <neil@gcc.gnu.org> | 2001-09-24 22:53:12 +0000 |
commit | 4ed5bcfb1ed415c32bdd8735b2cd0ea0ed37e8b6 (patch) | |
tree | f2b5dd04bb961bbe8dac8d988d52d574f0cb2b47 /gcc/cppmain.c | |
parent | ad43d46f3abe6f4d9b41f5b1d7b46a0c320efda8 (diff) | |
download | gcc-4ed5bcfb1ed415c32bdd8735b2cd0ea0ed37e8b6.zip gcc-4ed5bcfb1ed415c32bdd8735b2cd0ea0ed37e8b6.tar.gz gcc-4ed5bcfb1ed415c32bdd8735b2cd0ea0ed37e8b6.tar.bz2 |
c-lex.c (cb_def_pragma): Update.
* 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.
From-SVN: r45793
Diffstat (limited to 'gcc/cppmain.c')
-rw-r--r-- | gcc/cppmain.c | 44 |
1 files changed, 34 insertions, 10 deletions
diff --git a/gcc/cppmain.c b/gcc/cppmain.c index 5451ccc..a1b8b67 100644 --- a/gcc/cppmain.c +++ b/gcc/cppmain.c @@ -32,6 +32,7 @@ struct printer { FILE *outf; /* Stream to write to. */ const struct line_map *map; /* Logical to physical line mappings. */ + const cpp_token *prev; /* Previous token. */ unsigned int line; /* Line currently being written. */ unsigned char printed; /* Nonzero if something output at line. */ }; @@ -43,7 +44,7 @@ static void setup_callbacks PARAMS ((void)); /* General output routines. */ static void scan_translation_unit PARAMS ((cpp_reader *)); -static void check_multiline_token PARAMS ((cpp_string *)); +static void check_multiline_token PARAMS ((const cpp_string *)); static int dump_macro PARAMS ((cpp_reader *, cpp_hashnode *, void *)); static void print_line PARAMS ((const struct line_map *, unsigned int, @@ -144,6 +145,7 @@ do_preprocessing (argc, argv) cause a linemarker to be output by maybe_print_line. */ print.line = (unsigned int) -1; print.printed = 0; + print.prev = 0; print.map = 0; /* Open the output now. We must do so even if no_output is on, @@ -219,22 +221,43 @@ static void scan_translation_unit (pfile) cpp_reader *pfile; { - unsigned int index; - cpp_token tokens[2], *token; + bool avoid_paste = false; + const cpp_token *source = NULL; - for (index = 0;; index = 1 - index) + for (;;) { - token = &tokens[index]; - cpp_get_token (pfile, token); + const cpp_token *token = cpp_get_token (pfile); + + if (token->type == CPP_PADDING) + { + avoid_paste = true; + if (source == NULL + || (!(source->flags & PREV_WHITE) && token->val.source == NULL)) + source = token->val.source; + continue; + } if (token->type == CPP_EOF) break; - if ((token->flags & (PREV_WHITE | AVOID_LPASTE | BOL)) == AVOID_LPASTE - && cpp_avoid_paste (pfile, &tokens[1 - index], token)) - token->flags |= PREV_WHITE; + /* Subtle logic to output a space if and only if necessary. */ + if (avoid_paste) + { + if (source == NULL) + source = token; + if (source->flags & PREV_WHITE + || (print.prev && cpp_avoid_paste (pfile, print.prev, token)) + || (print.prev == NULL && token->type == CPP_HASH)) + putc (' ', print.outf); + } + else if (token->flags & PREV_WHITE) + putc (' ', print.outf); + avoid_paste = false; + source = NULL; + print.prev = token; cpp_output_token (token, print.outf); + if (token->type == CPP_STRING || token->type == CPP_WSTRING || token->type == CPP_COMMENT) check_multiline_token (&token->val.str); @@ -244,7 +267,7 @@ scan_translation_unit (pfile) /* Adjust print.line for newlines embedded in tokens. */ static void check_multiline_token (str) - cpp_string *str; + const cpp_string *str; { unsigned int i; @@ -324,6 +347,7 @@ cb_line_change (pfile, token, parsing_args) maybe_print_line (print.map, token->line); print.printed = 1; + print.prev = 0; /* Supply enough spaces to put this token in its original column, one space per column greater than 2, since scan_translation_unit |