diff options
author | Zack Weinberg <zack@gcc.gnu.org> | 2000-07-04 01:58:21 +0000 |
---|---|---|
committer | Zack Weinberg <zack@gcc.gnu.org> | 2000-07-04 01:58:21 +0000 |
commit | 041c31944c94d5ee089bd569c4361fbc3d2acaea (patch) | |
tree | 1c91fa44eb386dd706e44d139ed980ea94f05cae /gcc/cppinit.c | |
parent | 4f647814cefff8ee95ac918a8484d5da8c415825 (diff) | |
download | gcc-041c31944c94d5ee089bd569c4361fbc3d2acaea.zip gcc-041c31944c94d5ee089bd569c4361fbc3d2acaea.tar.gz gcc-041c31944c94d5ee089bd569c4361fbc3d2acaea.tar.bz2 |
top level:
2000-07-03 Zack Weinberg <zack@wolery.cumb.org>
* fix-header.c (struct partial_proto): Remove unnecessary fields.
(recognized_extern, recognized_function, read_scan_file):
Update for new scheme.
(check_protection): It's still a multiple include guard even
if it doesn't always trigger.
* scan-decls.c (skip_to_closing_brace, scan_decls): Update for
new scheme.
* scan.h: Declare struct cpp_token. Update prototypes.
2000-07-03 Neil Booth <neilb@earthling.net>
Zack Weinberg <zack@wolery.cumb.org>
Complete overhaul of the lexer and macro expander.
* cpphash.c (object_defn, funct_defn, push_macro_expansion,
arg, arglist, argdata, reflist, collect_objlike_expansion,
collect_funlike_expansion, collect_params,
warn_trad_stringify, trad_stringify, duplicate_arg_p, add_pat,
unsafe_chars, macarg, compare_defs, special_symbol,
scan_arguments, stringify, funlike_macroexpand,
_cpp_quote_string, monthnames): Delete.
(cpp_lookup, _cpp_free_definition, dump_funlike_macro,
_cpp_create_definition, _cpp_dump_definition,
dump_hash_helper): Adjust.
(find_param, count_params, parse_define, var_args_str,
check_macro_redefinition, save_expansion): New.
* cpplex.c (skip_block_comment, skip_line_comment, parse_name,
parse_string, output_line_command, trigraph_replace,
lex_line, cpp_push_buffer, cpp_pop_buffer, cpp_output_tokens,
cpp_scan_buffer_nooutput, cpp_scan_buffer, cpp_free_toklist,
cpp_idcmp, _cpp_get_directive_token, _cpp_init_input_buffer,
_cpp_skip_rest_of_line): Modify.
(maybe_macroexpand, skip_comment, copy_comment, skip_string,
find_position, null_warning, bump_column, expand_name_space,
pedantic_whitespace, _cpp_output_list, _cpp_slice_toklist,
_cpp_squeeze_toklist, _cpp_scan_until, _cpp_skip_hspace,
_cpp_parse_name, _cpp_lex_token, cpp_get_non_space_token,
_cpp_prescan): Delete.
(dump_param_spelling, process_directive, lex_next,
is_macro_disabled, stringify_arg, expand_context_stack,
output_token, make_string_token, alloc_number_token,
special_symbol, duplicate_token, maybe_paste_with_next,
can_paste, prevent_macro_expansion, restore_macro_expansion,
get_temp_token, release_temp_tokens, quote_string,
token_names, token_spellings, _cpp_expand_name_space,
_cpp_glue_header_name, _cpp_reserve_name_space,
digraph_spellings, trigraph_ok, skip_whitespace, save_comment,
placemarker_token, eof_token, cpp_context, macro_args,
get_raw_token, parse_arg, parse_args, save_token,
push_arg_context, push_macro_context, pop_context,
do_pop_context, free_macro_args, _cpp_get_line,
_cpp_run_directive): New.
* cpplib.c (validate_else, parse_include, push_conditional,
pass_thru_directive, read_line_number, parse_ifdef,
detect_if_not_defined, _cpp_check_directive, do_define,
do_undef, do_include, do_import, do_include_next, do_error,
do_warning, do_ident, do_pragma, pragma_dispatch, gcc_pragmas,
top_pragmas, do_pragma_gcc, do_pragma_implementation,
do_pragma_poison, do_pragma_system_header,
do_pragma_dependency, do_sccs, do_ifdef, do_ifndef, do_else,
dl_elif, do_endif, _cpp_unwind_if_stack, do_assert,
do_unassert, cpp_define, cpp_undef, cpp_assert, cpp_unassert,
cpp_defined): Update for new scheme.
(strtoul_for_line, get_define_node, dump_macro_name,
_cpp_check_linemarker, _cpp_parse_assertion): New.
(_cpp_handle_directive, do_pragma_default): Delete.
* cpphash.h (struct predicate): Now struct answer.
(enum spell_type, struct token_spelling, struct directive,
directive_handler): New.
Update prototypes. Remove unused macros.
* cpplib.h: Update prototypes. Remove unused macros,
structure definitions, and fields.
* cpperror.c (print_containing_files, v_message): Adjust.
* cppexp.c (parse_assertion, lex, parse_escape,
_cpp_parse_expr): Adjust.
* cppfiles.c (open_include_file, _cpp_execute_include,
_cpp_compare_file_date, cpp_read_file, read_include_file):
Adjust.
* cppinit.c (dump_special_to_buffer): Delete.
(append_include_chain, merge_include_chains, cpp_reader_init,
cpp_cleanup, initialize_builtins, builtin_array, cpp_start_read,
cpp_finish, handle_option, print_help): Adjust.
* cppmain.c (main): Adjust.
testsuite:
2000-07-03 Zack Weinberg <zack@wolery.cumb.org>
* testsuite/gcc.dg/cpp/19951025-1.c: Adjust regexps.
* testsuite/gcc.dg/cpp/19990703-1.c: Likewise.
* testsuite/gcc.dg/cpp/20000625-1.c: Likewise.
* testsuite/gcc.dg/cpp/20000625-2.c: Likewise.
* testsuite/gcc.dg/cpp/macro1.c,
testsuite/gcc.dg/cpp/paste1.c, testsuite/gcc.dg/cpp/paste2.c,
testsuite/gcc.dg/cpp/paste3.c, testsuite/gcc.dg/cpp/paste4.c,
testsuite/gcc.dg/cpp/strify1.c,
testsuite/gcc.dg/cpp/strify2.c: New tests.
From-SVN: r34859
Diffstat (limited to 'gcc/cppinit.c')
-rw-r--r-- | gcc/cppinit.c | 151 |
1 files changed, 80 insertions, 71 deletions
diff --git a/gcc/cppinit.c b/gcc/cppinit.c index 320dfdb..f50bcc1f 100644 --- a/gcc/cppinit.c +++ b/gcc/cppinit.c @@ -215,8 +215,6 @@ static void append_include_chain PARAMS ((cpp_reader *, char *, int, int)); static void merge_include_chains PARAMS ((cpp_reader *)); -static void dump_special_to_buffer PARAMS ((cpp_reader *, const U_CHAR *, - size_t)); static void initialize_dependency_output PARAMS ((cpp_reader *)); static void initialize_standard_includes PARAMS ((cpp_reader *)); static void new_pending_directive PARAMS ((struct cpp_pending *, @@ -345,7 +343,7 @@ append_include_chain (pfile, pend, dir, path, cxx_aware) if (errno != ENOENT) cpp_notice_from_errno (pfile, dir); else if (CPP_OPTION (pfile, verbose)) - fprintf (stderr, _("ignoring nonexistent directory `%s'\n"), dir); + fprintf (stderr, _("ignoring nonexistent directory \"%s\"\n"), dir); return; } @@ -442,7 +440,7 @@ merge_include_chains (pfile) && cur->dev == other->dev) { if (CPP_OPTION (pfile, verbose)) - fprintf (stderr, _("ignoring duplicate directory `%s'\n"), + fprintf (stderr, _("ignoring duplicate directory \"%s\"\n"), cur->name); prev->next = cur->next; @@ -462,7 +460,7 @@ merge_include_chains (pfile) && cur->dev == other->dev) { if (CPP_OPTION (pfile, verbose)) - fprintf (stderr, _("ignoring duplicate directory `%s'\n"), + fprintf (stderr, _("ignoring duplicate directory \"%s\"\n"), cur->name); prev->next = cur->next; @@ -481,7 +479,7 @@ merge_include_chains (pfile) if (quote == qtail) { if (CPP_OPTION (pfile, verbose)) - fprintf (stderr, _("ignoring duplicate directory `%s'\n"), + fprintf (stderr, _("ignoring duplicate directory \"%s\"\n"), quote->name); free (quote->name); @@ -495,7 +493,7 @@ merge_include_chains (pfile) cur = cur->next; cur->next = brack; if (CPP_OPTION (pfile, verbose)) - fprintf (stderr, _("ignoring duplicate directory `%s'\n"), + fprintf (stderr, _("ignoring duplicate directory \"%s\"\n"), qtail->name); free (qtail->name); @@ -513,24 +511,6 @@ merge_include_chains (pfile) } -/* Write out a #define command for the special named MACRO_NAME - to PFILE's token_buffer. */ - -static void -dump_special_to_buffer (pfile, macro_name, macro_len) - cpp_reader *pfile; - const U_CHAR *macro_name; - size_t macro_len; -{ - static const char define_directive[] = "#define "; - CPP_RESERVE (pfile, sizeof(define_directive) + macro_len); - CPP_PUTS_Q (pfile, define_directive, sizeof(define_directive)-1); - CPP_PUTS_Q (pfile, macro_name, macro_len); - CPP_PUTC_Q (pfile, ' '); - _cpp_expand_to_buffer (pfile, macro_name, macro_len); - CPP_PUTC (pfile, '\n'); -} - /* Initialize a cpp_reader structure. */ void cpp_reader_init (pfile) @@ -545,6 +525,7 @@ cpp_reader_init (pfile) CPP_OPTION (pfile, dollars_in_ident) = 1; CPP_OPTION (pfile, cplusplus_comments) = 1; CPP_OPTION (pfile, warn_import) = 1; + CPP_OPTION (pfile, warn_paste) = 1; CPP_OPTION (pfile, discard_comments) = 1; CPP_OPTION (pfile, show_column) = 1; CPP_OPTION (pfile, tabstop) = 8; @@ -596,25 +577,19 @@ cpp_cleanup (pfile) pfile->token_buffer = NULL; } - if (pfile->input_buffer) - { - free (pfile->input_buffer); - pfile->input_buffer = NULL; - pfile->input_buffer_len = 0; - } - if (pfile->deps) deps_free (pfile->deps); htab_delete (pfile->hashtab); splay_tree_delete (pfile->all_include_files); + _cpp_free_temp_tokens (pfile); } /* This structure defines one built-in macro. A node of type TYPE will be entered in the macro hash table under the name NAME, with value - VALUE (if any). FLAGS tweaks the behavior a little: - DUMP write debug info for this macro + VALUE (if any). Two values are not compile time constants, so we tag + them in the FLAGS field instead: VERS value is the global version_string, quoted ULP value is the global user_label_prefix */ @@ -622,18 +597,17 @@ cpp_cleanup (pfile) struct builtin { const U_CHAR *name; - const U_CHAR *value; + const char *value; unsigned short type; unsigned short flags; unsigned int len; }; -#define DUMP 0x01 -#define VERS 0x02 -#define ULP 0x04 +#define VERS 0x01 +#define ULP 0x02 -#define B(n, t) { U n, 0, t, 0, sizeof n - 1 } -#define C(n, v) { U n, U v, T_CONST, DUMP, sizeof n - 1 } -#define X(n, v, t, f) { U n, U v, t, DUMP|f, sizeof n - 1 } +#define B(n, t) { U n, 0, t, 0, sizeof n - 1 } +#define C(n, v) { U n, v, T_MACRO, 0, sizeof n - 1 } +#define X(n, f) { U n, 0, T_MACRO, f, sizeof n - 1 } static const struct builtin builtin_array[] = { B("__TIME__", T_TIME), @@ -642,10 +616,10 @@ static const struct builtin builtin_array[] = B("__BASE_FILE__", T_BASE_FILE), B("__LINE__", T_SPECLINE), B("__INCLUDE_LEVEL__", T_INCLUDE_LEVEL), + B("__STDC__", T_STDC), - X("__VERSION__", 0, T_XCONST, VERS), - X("__USER_LABEL_PREFIX__", 0, T_CONST, ULP), - X("__STDC__", "1", T_STDC, 0), + X("__VERSION__", VERS), + X("__USER_LABEL_PREFIX__", ULP), C("__REGISTER_PREFIX__", REGISTER_PREFIX), C("__HAVE_BUILTIN_SETJMP__", "1"), #ifndef NO_BUILTIN_SIZE_TYPE @@ -671,35 +645,47 @@ initialize_builtins (pfile) cpp_reader *pfile; { const struct builtin *b; - const U_CHAR *val; - cpp_hashnode *hp; for(b = builtin_array; b < builtin_array_end; b++) { - if (b->type == T_STDC && CPP_TRADITIONAL (pfile)) - continue; - - if (b->flags & ULP) - val = (const U_CHAR *) user_label_prefix; - else if (b->flags & VERS) + if (b->type == T_MACRO) { - val = (const U_CHAR *) xmalloc (strlen (version_string) + 3); - sprintf ((char *)val, "\"%s\"", version_string); + const char *val; + char *str; + + if (b->flags & VERS) + { + /* Allocate enough space for 'name="value"\0'. */ + str = xmalloc (b->len + strlen (version_string) + 4); + sprintf (str, "%s=\"%s\"", b->name, version_string); + } + else + { + if (b->flags & ULP) + val = user_label_prefix; + else + val = b->value; + + /* Allocate enough space for "name=value\0". */ + str = xmalloc (b->len + strlen (val) + 2); + sprintf(str, "%s=%s", b->name, val); + } + cpp_define (pfile, str); } else - val = b->value; - - hp = cpp_lookup (pfile, b->name, b->len); - hp->value.cpval = val; - hp->type = b->type; + { + cpp_hashnode *hp; + + if (b->type == T_STDC && CPP_TRADITIONAL (pfile)) + continue; - if ((b->flags & DUMP) && CPP_OPTION (pfile, debug_output)) - dump_special_to_buffer (pfile, b->name, b->len); + hp = cpp_lookup (pfile, b->name, b->len); + hp->type = b->type; + } } } -#undef DUMP -#undef STDC #undef VERS #undef ULP +#undef builtin_array_end /* Another subroutine of cpp_start_read. This one sets up to do dependency-file output. */ @@ -889,6 +875,13 @@ cpp_start_read (pfile, print, fname) if (CPP_OPTION (pfile, cplusplus)) CPP_OPTION (pfile, warn_traditional) = 0; + /* Do not warn about illegal token pasting if -traditional, + -lang-fortran, or -lang-asm. */ + if (CPP_OPTION (pfile, traditional) + || CPP_OPTION (pfile, lang_fortran) + || CPP_OPTION (pfile, lang_asm)) + CPP_OPTION (pfile, warn_paste) = 0; + /* Set this if it hasn't been set already. */ if (user_label_prefix == NULL) user_label_prefix = USER_LABEL_PREFIX; @@ -898,6 +891,16 @@ cpp_start_read (pfile, print, fname) if (CPP_OPTION (pfile, preprocessed)) pfile->no_macro_expand++; + /* Figure out if we need to save function macro parameter spellings. + We don't use CPP_PEDANTIC() here because that depends on whether + or not the current file is a system header, and there is no + current file yet. */ + pfile->save_parameter_spellings = + CPP_OPTION (pfile, pedantic) + || CPP_OPTION (pfile, debug_output) + || CPP_OPTION (pfile, dump_macros) == dump_definitions + || CPP_OPTION (pfile, dump_macros) == dump_only; + /* Set up the IStable. This doesn't do anything if we were compiled with a compiler that supports C99 designated initializers. */ init_IStable (); @@ -946,13 +949,12 @@ cpp_start_read (pfile, print, fname) as line 0. */ CPP_BUFFER (pfile)->lineno = 0; - if (print) { - print->lineno = 0; print->last_fname = CPP_BUFFER (pfile)->nominal_fname; print->last_id = pfile->include_depth; print->written = CPP_WRITTEN (pfile); + print->lineno = 0; } /* Install __LINE__, etc. */ @@ -968,10 +970,13 @@ cpp_start_read (pfile, print, fname) p = q; } pfile->done_initializing = 1; - pfile->only_seen_white = 2; + + /* Now flush any output recorded during initialization, and advance + to line 1 of the main input file. */ CPP_BUFFER (pfile)->lineno = 1; + if (print && ! CPP_OPTION (pfile, no_output)) - cpp_output_tokens (pfile, print); + cpp_output_tokens (pfile, print, 1); /* The -imacros files can be scanned now, but the -include files have to be pushed onto the include stack and processed later, @@ -992,7 +997,7 @@ cpp_start_read (pfile, print, fname) { if (cpp_read_file (pfile, p->arg) && print && ! CPP_OPTION (pfile, no_output)) - cpp_output_tokens (pfile, print); + cpp_output_tokens (pfile, print, 1); /* record entry to file */ q = p->next; free (p); p = q; @@ -1073,7 +1078,7 @@ cpp_finish (pfile, print) /* Flush any pending output. */ if (print) { - cpp_output_tokens (pfile, print); + cpp_output_tokens (pfile, print, print->lineno); if (ferror (print->outf) || fclose (print->outf)) cpp_notice_from_errno (pfile, CPP_OPTION (pfile, out_fname)); } @@ -1753,6 +1758,8 @@ handle_option (pfile, argc, argv) CPP_OPTION (pfile, warn_undef) = 1; else if (!strcmp (argv[i], "-Wimport")) CPP_OPTION (pfile, warn_import) = 1; + else if (!strcmp (argv[i], "-Wpaste")) + CPP_OPTION (pfile, warn_paste) = 1; else if (!strcmp (argv[i], "-Werror")) CPP_OPTION (pfile, warnings_are_errors) = 1; else if (!strcmp (argv[i], "-Wno-traditional")) @@ -1767,6 +1774,8 @@ handle_option (pfile, argc, argv) CPP_OPTION (pfile, warn_undef) = 0; else if (!strcmp (argv[i], "-Wno-import")) CPP_OPTION (pfile, warn_import) = 0; + else if (!strcmp (argv[i], "-Wno-paste")) + CPP_OPTION (pfile, warn_paste) = 0; else if (!strcmp (argv[i], "-Wno-error")) CPP_OPTION (pfile, warnings_are_errors) = 0; break; @@ -1836,10 +1845,10 @@ Switches:\n\ (dirs specified with -isystem will still be used)\n\ -nostdinc++ Do not search system include directories for C++\n\ -o <file> Put output into <file>\n\ - -pedantic Issue all warnings demanded by strict ANSI C\n\ + -pedantic Issue all warnings demanded by strict ISO C\n\ -pedantic-errors Issue -pedantic warnings as errors instead\n\ -traditional Follow K&R pre-processor behaviour\n\ - -trigraphs Support ANSI C trigraphs\n\ + -trigraphs Support ISO C trigraphs\n\ -lang-c Assume that the input sources are in C\n\ -lang-c89 Assume that the input sources are in C89\n\ -lang-c++ Assume that the input sources are in C++\n\ |