gcc/gcc/c-family/c-ppoutput.c

717 lines
20 KiB
C
Raw Normal View History

/* Preprocess only, using cpplib.
Copyright (C) 1995-2017 Free Software Foundation, Inc.
1995-03-16 22:59:07 +01:00
Written by Per Bothner, 1994-95.
This program is free software; you can redistribute it and/or modify it
under the terms of the GNU General Public License as published by the
Free Software Foundation; either version 3, or (at your option) any
later version.
1995-03-16 22:59:07 +01:00
This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
GNU General Public License for more details.
1995-03-16 22:59:07 +01:00
You should have received a copy of the GNU General Public License
along with this program; see the file COPYING3. If not see
<http://www.gnu.org/licenses/>. */
1995-03-16 22:59:07 +01:00
#include "config.h"
#include "system.h"
#include "coretypes.h"
decl.c: Reorder #include's and remove duplicates. ada 2015-10-29 Andrew MacLeod <amacleod@redhat.com> * gcc-interface/decl.c: Reorder #include's and remove duplicates. * gcc-interface/misc.c: Likewise. * gcc-interface/targtyps.c: Likewise. * gcc-interface/trans.c: Likewise. * gcc-interface/utils.c: Likewise. c 2015-10-29 Andrew MacLeod <amacleod@redhat.com> * c-array-notation.c: Reorder #include's and remove duplicates. * c-aux-info.c: Likewise. * c-convert.c: Likewise. * c-decl.c: Likewise. * c-errors.c: Likewise. * c-lang.c: Likewise. * c-objc-common.c: Likewise. * c-parser.c: Likewise. * c-typeck.c: Likewise. c-family 2015-10-29 Andrew MacLeod <amacleod@redhat.com> * array-notation-common.c: Reorder #include's and remove duplicates. * c-ada-spec.c: Likewise. * c-cilkplus.c: Likewise. * c-common.c: Likewise. * c-cppbuiltin.c: Likewise. * c-dump.c: Likewise. * c-format.c: Likewise. * c-gimplify.c: Likewise. * c-indentation.c: Likewise. * c-lex.c: Likewise. * c-omp.c: Likewise. * c-opts.c: Likewise. * c-pch.c: Likewise. * c-ppoutput.c: Likewise. * c-pragma.c: Likewise. * c-pretty-print.c: Likewise. * c-semantics.c: Likewise. * c-ubsan.c: Likewise. * cilk.c: Likewise. * stub-objc.c: Likewise. cp 2015-10-29 Andrew MacLeod <amacleod@redhat.com> * call.c: Reorder #include's and remove duplicates. * class.c: Likewise. * constexpr.c: Likewise. * cp-array-notation.c: Likewise. * cp-cilkplus.c: Likewise. * cp-gimplify.c: Likewise. * cp-lang.c: Likewise. * cp-objcp-common.c: Likewise. * cp-ubsan.c: Likewise. * cvt.c: Likewise. * cxx-pretty-print.c: Likewise. * decl.c: Likewise. * decl2.c: Likewise. * dump.c: Likewise. * error.c: Likewise. * except.c: Likewise. * expr.c: Likewise. * friend.c: Likewise. * init.c: Likewise. * lambda.c: Likewise. * lex.c: Likewise. * mangle.c: Likewise. * method.c: Likewise. * name-lookup.c: Likewise. * optimize.c: Likewise. * parser.c: Likewise. * pt.c: Likewise. * ptree.c: Likewise. * repo.c: Likewise. * rtti.c: Likewise. * search.c: Likewise. * semantics.c: Likewise. * tree.c: Likewise. * typeck.c: Likewise. * typeck2.c: Likewise. * vtable-class-hierarchy.c: Likewise. fortran 2015-10-29 Andrew MacLeod <amacleod@redhat.com> * array.c: Reorder #include's and remove duplicates. * convert.c: Likewise. * cpp.c: Likewise. * decl.c: Likewise. * f95-lang.c: Likewise. * frontend-passes.c: Likewise. * iresolve.c: Likewise. * match.c: Likewise. * module.c: Likewise. * options.c: Likewise. * parse.c: Likewise. * resolve.c: Likewise. * simplify.c: Likewise. * target-memory.c: Likewise. * trans-array.c: Likewise. * trans-common.c: Likewise. * trans-const.c: Likewise. * trans-decl.c: Likewise. * trans-expr.c: Likewise. * trans-intrinsic.c: Likewise. * trans-io.c: Likewise. * trans-openmp.c: Likewise. * trans-stmt.c: Likewise. * trans-types.c: Likewise. * trans.c: Likewise. go 2015-10-29 Andrew MacLeod <amacleod@redhat.com> * go-backend.c: Reorder #include's and remove duplicates. * go-lang.c: Likewise. java 2015-10-29 Andrew MacLeod <amacleod@redhat.com> * boehm.c: Reorder #include's and remove duplicates. * builtins.c: Likewise. * class.c: Likewise. * constants.c: Likewise. * decl.c: Likewise. * except.c: Likewise. * expr.c: Likewise. * java-gimplify.c: Likewise. * jcf-dump.c: Likewise. * jcf-io.c: Likewise. * jcf-parse.c: Likewise. * jvgenmain.c: Likewise. * lang.c: Likewise. * mangle.c: Likewise. * mangle_name.c: Likewise. * resource.c: Likewise. * typeck.c: Likewise. * verify-glue.c: Likewise. * verify-impl.c: Likewise. jit 2015-10-29 Andrew MacLeod <amacleod@redhat.com> * dummy-frontend.c: Reorder #include's and remove duplicates. * jit-builtins.c: Likewise. * jit-playback.c: Likewise. * jit-recording.c: Likewise. * libgccjit.c: Likewise. lto 2015-10-29 Andrew MacLeod <amacleod@redhat.com> * lto-lang.c: Reorder #include's and remove duplicates. * lto-object.c: Likewise. * lto-partition.c: Likewise. * lto-symtab.c: Likewise. * lto.c: Likewise. objc 2015-10-29 Andrew MacLeod <amacleod@redhat.com> * objc-lang.c: Reorder #include's and remove duplicates. * objc-map.c: Likewise. objcp 2015-10-29 Andrew MacLeod <amacleod@redhat.com> * objcp-decl.c: Reorder #include's and remove duplicates. * objcp-lang.c: Likewise. From-SVN: r229533
2015-10-29 16:27:20 +01:00
#include "c-common.h" /* For flags. */
Makefile.def (host_modules): add libcpp. ChangeLog: 2004-05-23 Paolo Bonzini <bonzini@gnu.org> * Makefile.def (host_modules): add libcpp. * Makefile.tpl: Add dependencies on and for libcpp. * Makefile.in: Regenerate. * configure.in: Add libcpp host module. * configure: Regenerate. config/ChangeLog: 2004-05-23 Paolo Bonzini <bonzini@gnu.org> * acx.m4 (ACX_HEADER_STDBOOL, ACX_HEADER_STRING): From gcc. gcc/ChangeLog: 2004-05-23 Paolo Bonzini <bonzini@gnu.org> Move libcpp to the toplevel. * Makefile.in: Remove references to libcpp files, use CPPLIBS instead of libcpp.a. Define SYMTAB_H and change hashtable.h to that. * aclocal.m4 (gcc_AC_HEADER_STDBOOL, gcc_AC_HEADER_STRING, gcc_AC_C__BOOL): Remove. * configure.ac (gcc_AC_C__BOOL, HAVE_UCHAR): Remove tests. * configure: Regenerate. * config.in: Regenerate. * c-ppoutput.c: Include ../libcpp/internal.h instead of cpphash.h. * cppcharset.c: Removed. * cpperror.c: Removed. * cppexp.c: Removed. * cppfiles.c: Removed. * cpphash.c: Removed. * cpphash.h: Removed. * cppinit.c: Removed. * cpplex.c: Removed. * cpplib.c: Removed. * cpplib.h: Removed. * cppmacro.c: Removed. * cpppch.c: Removed. * cpptrad.c: Removed. * cppucnid.h: Removed. * cppucnid.pl: Removed. * cppucnid.tab: Removed. * hashtable.c: Removed. * hashtable.h: Removed. * line-map.c: Removed. * line-map.h: Removed. * mkdeps.c: Removed. * mkdeps.h: Removed. * stringpool.h: Include symtab.h instead of hashtable.h. * tree.h: Include symtab.h instead of hashtable.h. * system.h (O_NONBLOCK, O_NOCTTY): Do not define. gcc/cp/ChangeLog: 2004-05-23 Paolo Bonzini <bonzini@gnu.org> * Make-lang.in: No need to specify $(LIBCPP). gcc/java/ChangeLog: 2004-05-23 Paolo Bonzini <bonzini@gnu.org> * Make-lang.in: Link in $(LIBCPP) instead of mkdeps.o. libcpp/ChangeLog: 2004-05-23 Paolo Bonzini <bonzini@gnu.org> Moved libcpp from the gcc subdirectory to the toplevel. * Makefile.am: New file. * Makefile.in: Regenerate. * configure.ac: New file. * configure: Regenerate. * config.in: Regenerate. * charset.c: Moved from gcc/cppcharset.c. Add note about brokenness of input charset detection. Adjust for change in name of cppucnid.h. * errors.c: Moved from gcc/cpperror.c. Do not include intl.h. * expr.c: Moved from gcc/cppexp.c. * files.c: Moved from gcc/cppfiles.c. Do not include intl.h. Remove #define of O_BINARY, it is in system.h. * identifiers.c: Moved from gcc/cpphash.c. * internal.h: Moved from gcc/cpphash.h. Change header guard name. All other files adjusted to match name change. * init.c: Moved from gcc/cppinit.c. (init_library) [ENABLE_NLS]: Call bindtextdomain. * lex.c: Moved from gcc/cpplex.c. * directives.c: Moved from gcc/cpplib.c. * macro.c: Moved from gcc/cppmacro.c. * pch.c: Moved from gcc/cpppch.c. Do not include intl.h. * traditional.c: Moved from gcc/cpptrad.c. * ucnid.h: Moved from gcc/cppucnid.h. Change header guard name. * ucnid.pl: Moved from gcc/cppucnid.pl. * ucnid.tab: Moved from gcc/cppucnid.tab. Change header guard name. * symtab.c: Moved from gcc/hashtable.c. * line-map.c: Moved from gcc. Do not include intl.h. * mkdeps.c: Moved from gcc. * system.h: New file. libcpp/include/ChangeLog: 2004-05-23 Paolo Bonzini <bonzini@gnu.org> * cpplib.h: Moved from gcc. Change header guard name. * line-map.h: Moved from gcc. Change header guard name. * mkdeps.h: Moved from gcc. Change header guard name. * symtab.h: Moved from gcc/hashtable.h. Change header guard name. libcpp/po/ChangeLog: 2004-05-23 Paolo Bonzini <bonzini@gnu.org> * be.po: Extracted from gcc/po/be.po. * ca.po: Extracted from gcc/po/ca.po. * da.po: Extracted from gcc/po/da.po. * de.po: Extracted from gcc/po/de.po. * el.po: Extracted from gcc/po/el.po. * es.po: Extracted from gcc/po/es.po. * fr.po: Extracted from gcc/po/fr.po. * ja.po: Extracted from gcc/po/ja.po. * nl.po: Extracted from gcc/po/nl.po. * sv.po: Extracted from gcc/po/sv.po. * tr.po: Extracted from gcc/po/tr.po. From-SVN: r82199
2004-05-24 12:50:45 +02:00
#include "../libcpp/internal.h"
#include "c-pragma.h" /* For parse_in. */
/* Encapsulates state used to convert a stream of tokens into a text
file. */
static struct
{
FILE *outf; /* Stream to write to. */
const cpp_token *prev; /* Previous token. */
const cpp_token *source; /* Source token for spacing. */
Represent column numbers using line-map's source_location. The "next available source_location" is now managed internally by line-maps.c rather than by clients. * line-map.h (struct line_map): New field column_bits. <from_line>: Rename field to start_location. (struct line_maps): New fields highest_location and max_column_hint. (linemap_check_files_exited): New declaration. (linemap_line_start): New declaration. (linemap_add): Remove from_line parameter; use highest_location field. (SOURCE_LINE, LAST_SOURCE_LINE): Modify to use column_bits. (SOURCE_COLUMN, LAST_SOURCE_LINE_LOCATION): New macros. (CURRENT_LINE_MAP): Remove macro. (linemap_position_for_column): New inline function. * line-map.c (linemap_init): Clear new fields. (linemap_check_files_exited): New function, extracted from ... (linemap_free): Use linemap_check_files_exited. (linemap_add): Remove from_line parameter. Various updates. (linemap_line_start): New function. (linemap_lookeup): Update for new field names. * cpphash.h (struct cpp_reader) <map>: Field removed. Because linemap_position_for_column may unpredictably change the current map, it is cleaner and simpler for us to not cache it in cpp_reader. (struct cpp_buffer): New sysp field. Changed warned_cplusplus_comments and from_stage3 to bitfields. * cppinit.c (cpp_read_min_file): pfile->map no longer exists. * cpplib.c (do_line, do_linemarker, _cpp_do_file_change): Get current map using linemap_lookup. (do_linemarker): Also set buffer's sysp field. (destringize_and_run): No longer need to decrement current line. * cppfiles.c (_cpp_stack_file): Set sysp from and in buffer. (search_path_head, open_file_failed): Use buffer's sysp. (cpp_make_system_header): Get current map using linemap_lookup. Also set buffer's sysp flag. * cppmacro.c (_cpp_builtin_macro_text): Likewise use linemap_lookup. * cpphash.h (CPP_INCREMENT_LINE): New macro. (struct cpp_buffer): Moved fields saved_cur, saved_rlimit to ... (struct cpp_reader): ... and adding saved_line_base field. * cpptrad.c (_cpp_overlay_buffer, _cpp_remove_overlay): Update accordingly. Don't adjust line. (_cpp_scan_out_logical_line): Use CPP_INCREMENT_LINE. * cpphash.c (CPP_IN_SYSTEM_HEADER): Replaced macro by ... (cpp_in_system_header): ... new inline function, using buffer's sysp. * cpperror.c (_cpp_begin_message): Update to use cpp_in_system_header. * cpplex.c (_cpp_lex_direct): Likewise. * cppmacro.c (_cpp_builtin_macro_text): Likewise. * cppmacro.c (_cpp_create_definition): Use buffer's sysp field. * cpplib.h (struct cpp_token): Rename line field to src_loc. Remove col field as it is now subsumed by src_loc. * cpperror.c: Update various field, parameter, and macro names. (print_location): If col==0, try SOURCE_COLUMN of line. (cpp_error): Use cur_token's src_loc field, rather than line+col. * cpplib.c (do_diagnostic): Token's src_loc fields replaces line+col. * cpplex.c (_cpp_process_line_notes, _cpp_lex_direct, _cpp_skip_block_comment): Use CPP_INCREMENT_LINE. (_cpp_temp_token): Replace cpp_token's line+col fields by src_loc. (_cpp_get_fresh_line): Don't need to adjust line for missing newline. (_cpp_lex_direct): Use linemap_position_for_column. * c-ppoutput.c (maybe_print_line, print_line): Don't take map parameter. Instead get it from the line_table global. Adjust callers. (print): Remove map field. Replace line field to src_line. (init_pp_output, account_for_newlines, maybe_print_line): Adjust. (cb_line_change): Use SOURCE_COLUMN. Minor optimizations. (pp_file_change): Use MAIN_FILE_P since we cannot checked print.map. Use LAST_SOURCE_LINE_LOCATION to "catch up" after #include. * cpptrad.c (copy_comment): Rename variable. * c-lex.c (map): Remove static variable, for same reason we removed cpp_reader's map field. (cb_line_change, cb_def_pragma, cb_define, cb_undef): Hence we need to call linemap_lookup. (cb_line_change): Token's line field replaced by src_loc. (fe_file_change): Use MAINFILE_P and LAST_SOURCE_LINE macros. Don't save new_map. * cpphash.h, cpperror.c, cpplib.h: Some renames of fileline to source_location. From-SVN: r77663
2004-02-11 16:29:30 +01:00
int src_line; /* Line number currently being written. */
bool printed; /* True if something output at line. */
bool first_time; /* pp_file_change hasn't been called yet. */
PR preprocessor/60723 - missing system-ness marks for macro tokens When a system macro is expanded in a non-system file during out-of-line preprocessing, it can happen that the preprocessor forgets to emit line markers to express the system-ness status of tokens that come after the expansion of the macro. That can lead to situations where the entire non-system file can be considered as being a system file and thus have its warnings be discarded during the compilation of the resulting preprocessed file. My understanding is that this is due to the preprocessor not systematically detecting (and reporting) the change in system-ness of tokens. And this is what this patch does. Each time the system-ness of a given token is different from the previous token that was emitted by the preprocessor, it emits a line marker for the sole purpose of marking the new system-ness of the subsequent tokens to come. Bootstrapped and tested on x86_64-unknown-linux-gnu against trunk. gcc/c-family/ChangeLog: * c-ppoutput.c (struct print::prev_was_system_token): New data member. (init_pp_output): Initialize it. (maybe_print_line_1, maybe_print_line, print_line_1, print_line) (do_line_change): Return a flag saying if a line marker was emitted or not. (scan_translation_unit): Detect if the system-ness of the token we are about to emit is different from the one of the previously emitted token. If so, emit a line marker. Avoid emitting useless adjacent line markers. Avoid emitting line markers for tokens originating from the expansion of built-in macros. (scan_translation_unit_directives_only): Adjust. gcc/testsuite/ChangeLog: * gcc.dg/cpp/syshdr{4,5}.{c,h}: New test files. Signed-off-by: Dodji Seketeli <dodji@redhat.com> Signed-off-by: Dodji Seketeli <dodji@redhat.com> From-SVN: r212638
2014-07-16 12:33:36 +02:00
bool prev_was_system_token; /* True if the previous token was a
system token.*/
const char *src_file; /* Current source file. */
} print;
1995-03-16 22:59:07 +01:00
/* Defined and undefined macros being queued for output with -dU at
the next newline. */
remove more useless typedefs gcc/c-family/ChangeLog: 2015-08-18 Trevor Saunders <tbsaunde@tbsaunde.org> * c-ada-spec.h, c-common.c, c-common.h, c-format.c, c-format.h, c-objc.h, c-ppoutput.c, c-pragma.c, c-pragma.h: Remove useless typedefs. gcc/c/ChangeLog: 2015-08-18 Trevor Saunders <tbsaunde@tbsaunde.org> * c-aux-info.c, c-parser.c, c-tree.h: Remove useless typedefs. gcc/cp/ChangeLog: 2015-08-18 Trevor Saunders <tbsaunde@tbsaunde.org> * call.c, class.c, cp-tree.h, decl.c, except.c, mangle.c, method.c, name-lookup.h, parser.c, parser.h, rtti.c, semantics.c, typeck2.c: Remove useless typedefs. gcc/fortran/ChangeLog: 2015-08-18 Trevor Saunders <tbsaunde@tbsaunde.org> * dependency.c, dependency.h, gfortran.h, io.c, module.c, parse.h, resolve.c, trans-types.h, trans.h: remove useless typedefs. gcc/lto/ChangeLog: 2015-08-18 Trevor Saunders <tbsaunde@tbsaunde.org> * lto.h: Remove useless typedefs. gcc/objc/ChangeLog: 2015-08-18 Trevor Saunders <tbsaunde@tbsaunde.org> * objc-act.h, objc-next-runtime-abi-02.c, objc-runtime-hooks.h: Remove useless typedefs. gcc/ChangeLog: 2015-08-18 Trevor Saunders <tbsaunde@tbsaunde.org> * bb-reorder.c, cfgloop.h, collect2.c, combine.c, dse.c, dwarf2cfi.c, gcse-common.h, genopinit.c, ggc-page.c, machmode.h, mcf.c, modulo-sched.c, omp-low.c, read-rtl.c, sched-rgn.c, signop.h, tree-call-cdce.c, tree-dfa.c, tree-diagnostic.c, tree-inline.h, tree-scalar-evolution.c, tree-ssa-address.c, tree-ssa-loop-niter.c, tree-ssa-loop.h, tree-ssa-pre.c, tree-ssa-reassoc.c, tree-ssa-sccvn.h, tree-ssa-structalias.c, tree-ssa-uninit.c, tree-ssa.h, tree-vect-loop-manip.c, tree-vectorizer.h, tree-vrp.c, var-tracking.c: Remove useless typedefs. From-SVN: r227001
2015-08-19 04:48:48 +02:00
struct macro_queue
{
struct macro_queue *next; /* Next macro in the list. */
char *macro; /* The name of the macro if not
defined, the full definition if
defined. */
remove more useless typedefs gcc/c-family/ChangeLog: 2015-08-18 Trevor Saunders <tbsaunde@tbsaunde.org> * c-ada-spec.h, c-common.c, c-common.h, c-format.c, c-format.h, c-objc.h, c-ppoutput.c, c-pragma.c, c-pragma.h: Remove useless typedefs. gcc/c/ChangeLog: 2015-08-18 Trevor Saunders <tbsaunde@tbsaunde.org> * c-aux-info.c, c-parser.c, c-tree.h: Remove useless typedefs. gcc/cp/ChangeLog: 2015-08-18 Trevor Saunders <tbsaunde@tbsaunde.org> * call.c, class.c, cp-tree.h, decl.c, except.c, mangle.c, method.c, name-lookup.h, parser.c, parser.h, rtti.c, semantics.c, typeck2.c: Remove useless typedefs. gcc/fortran/ChangeLog: 2015-08-18 Trevor Saunders <tbsaunde@tbsaunde.org> * dependency.c, dependency.h, gfortran.h, io.c, module.c, parse.h, resolve.c, trans-types.h, trans.h: remove useless typedefs. gcc/lto/ChangeLog: 2015-08-18 Trevor Saunders <tbsaunde@tbsaunde.org> * lto.h: Remove useless typedefs. gcc/objc/ChangeLog: 2015-08-18 Trevor Saunders <tbsaunde@tbsaunde.org> * objc-act.h, objc-next-runtime-abi-02.c, objc-runtime-hooks.h: Remove useless typedefs. gcc/ChangeLog: 2015-08-18 Trevor Saunders <tbsaunde@tbsaunde.org> * bb-reorder.c, cfgloop.h, collect2.c, combine.c, dse.c, dwarf2cfi.c, gcse-common.h, genopinit.c, ggc-page.c, machmode.h, mcf.c, modulo-sched.c, omp-low.c, read-rtl.c, sched-rgn.c, signop.h, tree-call-cdce.c, tree-dfa.c, tree-diagnostic.c, tree-inline.h, tree-scalar-evolution.c, tree-ssa-address.c, tree-ssa-loop-niter.c, tree-ssa-loop.h, tree-ssa-pre.c, tree-ssa-reassoc.c, tree-ssa-sccvn.h, tree-ssa-structalias.c, tree-ssa-uninit.c, tree-ssa.h, tree-vect-loop-manip.c, tree-vectorizer.h, tree-vrp.c, var-tracking.c: Remove useless typedefs. From-SVN: r227001
2015-08-19 04:48:48 +02:00
};
static macro_queue *define_queue, *undef_queue;
New macro expander. 2000-10-28 Neil Booth <neilb@earthling.net> New macro expander. * cpplib.c (struct answer): New. (struct if_stack): Use cpp_lexer_pos rather than line and col. Rename cmacro mi_cmacro. (struct directive, KANDR, STDC89, EXTENSION, COND, IF_COND, INCL, IN_I): New directive and flags. (skip_rest_of_line, check_eol, run_directive, glue_header_name, parse_answer, parse_assertion, find_answer): New functions. (parse_ifdef, detect_if_not_defined, validate_else): Remove. (lex_macro_node): New function to replace parse_ifdef and get_define_node. (_cpp_handle_directive): New function, combines _cpp_check_directive and _cpp_check_linemarker. (do_define, do_undef, parse_include, do_include, do_import, do_include_next, read_line_number, do_line, do_ident, do_pragma, do_pragma_once, do_pragma_poison, do_pragma_dependency): Update for new token getting interface. (do_ifdef, do_ifndef, do_if, do_else, do_endif, push_conditional) : Update for new multiple-include optimisation technique. (do_elif): Don't forget to invalidate controlling macros. (unwind_if_stack, cpp_defined, cpp_push_buffer, cpp_pop_buffer): Update. (parse_assertion, parse_answer, find_answer, _cpp_test_assertion): Functions to handle assertions with the new token interface. (do_assert, do_unassert): Use them. (cpp_define, _cpp_define_builtin, cpp_undef, cpp_assert, cpp_unassert): Use run_directive. (_cpp_init_stacks): Register directive names. Don't register special nodes. * cpperror.c (print_containing_files, _cpp_begin_message): Update to new position recording regime. (cpp_ice, cpp_fatal, cpp_error, cpp_error_with_line, cpp_warning, cpp_warning_with_line, cpp_pedwarn, cpp_pedwarn_with_line, cpp_pedwarn_with_file_and_line): Update for _cpp_begin_message changes. (cpp_type2name): Move to cpplex.c. * cppexp.c (parse_charconst): spec_nodes is no longer a pointer. (parse_defined): Update to handle new multiple include optimisation method. Remove poisoned identifier warning. (parse_assertion, TYPE_NAME): Delete. (lex): Update for multiple include optimisation, removal of CPP_DEFINED, to use _cpp_test_assertion for assertions and cpp_token_as_text. (_cpp_parse_expr): Update for MI optimisation, and to use op_as_text. (op_as_text): New function, to wrap cpp_token_as_text. * cppfiles.c (stack_include_file, _cpp_pop_file_buffer): Update for MI optimisation. (_cpp_execute_include): Take a token rather than 3 arguments. Fix segfault on diagnostic. (_cpp_compare_file_date): Take a token rather than 3 args. (cpp_read_file): Work correctly for zero-length files. * cpphash.c (_cpp_init_macros, _cpp_cleanup_macros): Rename _cpp_init_hashtable and _cpp_cleanup_hashtable. (cpp_lookup): Place identifiers at front of identifier pool for _cpp_lookup_with_hash. (_cpp_lookup_with_hash): Require identifiers to be at the front of the identifier pool. Commit the memory if not already in the hash table. * cppinit.c (cpp_reader_init): Move cpp_init_completed test to top. Initialise various members of cpp_reader, memory pools, and the special nodes. (cpp_printer_init): Delete. (cpp_cleanup): Update. (struct builtin, builtin_array, initialize_builtins): Update for new hashnode definition and builtin handling. (cpp_start_read, cpp_finish): Don't take or initialise a printer. Update. * cpplib.h (cpp_printer, cpp_toklist, CPP_DEFINED, BOL, PASTED, VAR_ARGS, BEG_OF_FILE, IN_DIRECTIVE, KNOWN_DIRECTIVE, T_VOID, T_SPECLINE, T_DATE, T_FILE, T_BASE_FILE, T_INCLUDE_LEVEL, T_TIME, T_STDC, T_OPERATOR, T_POISON, T_MACRO, T_ASSERTION): Delete. (struct cpp_pool, struct cpp_macro, struct cpp_lexer_pos, struct cpp_lookahead, CPP_DHASH, enum mi_state, enum mi_ind, NO_EXPAND, VARARGS_FIRST, struct cpp_token_with_pos, struct toklist, struct cpp_context, struct specnodes, TOKEN_LOOKAHEAD, TOKEN_BUFFSIZE, NODE_OPERATOR, NODE_POISONED, NODE_BUILTIN, NODE_DIAGNOSTIC, NT_VOID, NT_MACRO, NT_ASSERTION, enum builtin_type, cpp_can_paste): New. (struct cpp_token): Delete line and col members. (struct cpp_buffer): New member output_lineno. (struct lexer_state): Delete indented, in_lex_line, seen_dot. Add va_args_ok, poisoned_ok, prevent_expansion, parsing_args. (struct cpp_reader): New members lexer_pos, macro_pos, directive_pos, ident_pool, temp_string_pool, macro_pool, argument_pool, string_pool, base_context, context, directive, mi_state, mi_if_not_defined, mi_lexed, mi_cmacro, mi_ind_cmacro, la_read, la_write, la_unused, mlstring_pos, macro_buffer, macro_buffer_len. Delete members mls_line, mls_column, token_list, potential_control_macro, temp_tokens, temp_cap, temp_alloced, temp_used, first_directive_token, context_cap, cur_context, no_expand_level, paste_level, contexts, args, save_parameter_spellings, need_newline, . Change type of date, time and spec_nodes members. Change prototypes for include and ident callbacks. (struct cpp_hashnode): Change type of name. Remove union members expansion and code. Add members macro, operator and builtin. (cpp_token_len, cpp_token_as_text, cpp_spell_token, cpp_start_read, cpp_finish, cpp_avoid_paste, cpp_get_token, cpp_get_line, cpp_get_output_line, cpp_macro_definition, cpp_start_lookahead, cpp_stop_lookahead): New prototypes. (cpp_printer_init, cpp_dump_definition): Delete prototypes. (U_CHAR, U, ustrcmp, ustrncmp, ustrlen, uxstrdup, ustrchr, ufputs): Move from cpphash.h. * cpphash.h (U_CHAR, U, ustrcmp, ustrncmp, ustrlen, uxstrdup, ustrchr, ufputs): Move to cpplib.h. (enum spell_type, struct token_spelling, _cpp_token_spellings, TOKEN_SPELL, TOKEN_NAME, struct answer, FREE_ANSWER, KANDR, STDC89, EXTENSION, COND, EXPAND, INCL, COMMENTS, IN_I, struct directive, directive_handler, struct spec_nodes, _cpp_digraph_spellings, _cpp_free_temp_tokens, _cpp_init_input_buffer, _cpp_grow_token_buffer, _cpp_init_toklist, _cpp_clear_toklist, _cpp_expand_token_space, _cpp_expand_name_space, _cpp_equiv_tokens, _cpp_equiv_toklists, _cpp_process_directive, _cpp_run_directive, _cpp_get_line, _cpp_get_raw_token, _cpp_glue_header_name, _cpp_can_paste, _cpp_check_directive, _cpp_check_linemarker, _cpp_parse_assertion, _cpp_find_answer): Delete. (VALID_SIGN, ALIGN, POOL_FRONT, POOL_LIMIT, POOL_BASE, POOL_SIZE, POOL_USED, POOL_COMMIT, struct cpp_chunk, _cpp_lex_token, _cpp_init_pool, _cpp_free_pool, _cpp_pool_reserve, _cpp_pool_alloc, _cpp_next_chunk, _cpp_lock_pool, _cpp_unlock_pool, _cpp_test_assertion, _cpp_handle_directive, DSC): New. (struct include_file): New member defined. (DO_NOT_REREAD, _cpp_begin_message, _cpp_execute_include, _cpp_compare_file_date): Update. (_cpp_pop_context, _cpp_get_token, _cpp_free_lookaheads, _cpp_push_token): New. (_cpp_init_macros, _cpp_cleanup_macros): Rename to _cpp_init_hashtable, _cpp_cleanup_hashtable. * Makefile.in: Remove cppoutput.c. * cppoutput.c: Delete * fixheader.c (read_scan_file): Update for new cpp_get_token prototype. (recognized_function): New argument LINE. * scan-decls.c (skip_to_closing_brace, scan_decls): Update for new cpp_get_token prototype. * scan.h (recognized_function): Update prototype. * po/POTFILES.in: Remove cppoutput.c. From-SVN: r37098
2000-10-28 19:59:06 +02:00
/* General output routines. */
static void scan_translation_unit (cpp_reader *);
directives-only.c: New file. libcpp/ * directives-only.c: New file. * internal.h (struct _cpp_dir_only_callbacks): New. (_cpp_preprocess_dir_only): New function. * directives.c (_cpp_handle_directive): Check directives_only before disabling execution of indented directives. * files.c (_cpp_stack_file): Add directives_only check. * include/cpplib.h (struct cpp_options): Add directives_only. (cpp_init_special_builtins): New function. * init.c (cpp_init_special_builtins): New function. (cpp_init_builtins): Move builtin_array initialization to cpp_init_special_builtins. (post_options): Check directives_only before setting pfile->state.prevent_expansion = 1. * macro.c (_cpp_builtin_macro_text): Print an error if __COUNTER__ is expanded inside a directive while -fdirectives-only is enabled. * Makefile.in (libcpp_a_OBJS): Add directives-only.o. (libcpp_a_SOURCES): Add directives-only.c. gcc/ * c-ppoutput.c (print_lines_directives_only): New function. (scan_translation_unit_directives_only): New function. (preprocess_file): Add call to scan_translation_unit_directives_only. * c-opts.c (c_common_handle_option): Add OPT_fdirectives_only. (sanitize_cpp_opts): Add default flag_dump_macros setting for -fdirectives-only. Add errors for -fdirectives-only conflict with -Wunused-macros and -traditional. (finish_options): Add builtin macro initialization for -fdirectives-only + -fpreprocessed. * c.opt (fdirectives-only): New. * doc/cppopts.texi (fdirectives-only): New. gcc/testsuite/ * gcc.dg/cpp/counter-2.c: New test. * gcc.dg/cpp/counter-3.c: New test. * gcc.dg/cpp/dir-only-1.c: New test. * gcc.dg/cpp/dir-only-1.h: New file. * gcc.dg/cpp/dir-only-2.c: New test. * gcc.dg/cpp/dir-only-3.c: New test. * gcc.dg/cpp/dir-only-3a.h: New file. * gcc.dg/cpp/dir-only-3b.h: New file. * gcc.dg/cpp/dir-only-4.c: New test. * gcc.dg/cpp/dir-only-5.c: New test. * gcc.dg/cpp/dir-only-6.c: New test. From-SVN: r127066
2007-07-30 20:29:20 +02:00
static void print_lines_directives_only (int, const void *, size_t);
static void scan_translation_unit_directives_only (cpp_reader *);
static void scan_translation_unit_trad (cpp_reader *);
static void account_for_newlines (const unsigned char *, size_t);
static int dump_macro (cpp_reader *, cpp_hashnode *, void *);
static void dump_queued_macros (cpp_reader *);
New macro expander. 2000-10-28 Neil Booth <neilb@earthling.net> New macro expander. * cpplib.c (struct answer): New. (struct if_stack): Use cpp_lexer_pos rather than line and col. Rename cmacro mi_cmacro. (struct directive, KANDR, STDC89, EXTENSION, COND, IF_COND, INCL, IN_I): New directive and flags. (skip_rest_of_line, check_eol, run_directive, glue_header_name, parse_answer, parse_assertion, find_answer): New functions. (parse_ifdef, detect_if_not_defined, validate_else): Remove. (lex_macro_node): New function to replace parse_ifdef and get_define_node. (_cpp_handle_directive): New function, combines _cpp_check_directive and _cpp_check_linemarker. (do_define, do_undef, parse_include, do_include, do_import, do_include_next, read_line_number, do_line, do_ident, do_pragma, do_pragma_once, do_pragma_poison, do_pragma_dependency): Update for new token getting interface. (do_ifdef, do_ifndef, do_if, do_else, do_endif, push_conditional) : Update for new multiple-include optimisation technique. (do_elif): Don't forget to invalidate controlling macros. (unwind_if_stack, cpp_defined, cpp_push_buffer, cpp_pop_buffer): Update. (parse_assertion, parse_answer, find_answer, _cpp_test_assertion): Functions to handle assertions with the new token interface. (do_assert, do_unassert): Use them. (cpp_define, _cpp_define_builtin, cpp_undef, cpp_assert, cpp_unassert): Use run_directive. (_cpp_init_stacks): Register directive names. Don't register special nodes. * cpperror.c (print_containing_files, _cpp_begin_message): Update to new position recording regime. (cpp_ice, cpp_fatal, cpp_error, cpp_error_with_line, cpp_warning, cpp_warning_with_line, cpp_pedwarn, cpp_pedwarn_with_line, cpp_pedwarn_with_file_and_line): Update for _cpp_begin_message changes. (cpp_type2name): Move to cpplex.c. * cppexp.c (parse_charconst): spec_nodes is no longer a pointer. (parse_defined): Update to handle new multiple include optimisation method. Remove poisoned identifier warning. (parse_assertion, TYPE_NAME): Delete. (lex): Update for multiple include optimisation, removal of CPP_DEFINED, to use _cpp_test_assertion for assertions and cpp_token_as_text. (_cpp_parse_expr): Update for MI optimisation, and to use op_as_text. (op_as_text): New function, to wrap cpp_token_as_text. * cppfiles.c (stack_include_file, _cpp_pop_file_buffer): Update for MI optimisation. (_cpp_execute_include): Take a token rather than 3 arguments. Fix segfault on diagnostic. (_cpp_compare_file_date): Take a token rather than 3 args. (cpp_read_file): Work correctly for zero-length files. * cpphash.c (_cpp_init_macros, _cpp_cleanup_macros): Rename _cpp_init_hashtable and _cpp_cleanup_hashtable. (cpp_lookup): Place identifiers at front of identifier pool for _cpp_lookup_with_hash. (_cpp_lookup_with_hash): Require identifiers to be at the front of the identifier pool. Commit the memory if not already in the hash table. * cppinit.c (cpp_reader_init): Move cpp_init_completed test to top. Initialise various members of cpp_reader, memory pools, and the special nodes. (cpp_printer_init): Delete. (cpp_cleanup): Update. (struct builtin, builtin_array, initialize_builtins): Update for new hashnode definition and builtin handling. (cpp_start_read, cpp_finish): Don't take or initialise a printer. Update. * cpplib.h (cpp_printer, cpp_toklist, CPP_DEFINED, BOL, PASTED, VAR_ARGS, BEG_OF_FILE, IN_DIRECTIVE, KNOWN_DIRECTIVE, T_VOID, T_SPECLINE, T_DATE, T_FILE, T_BASE_FILE, T_INCLUDE_LEVEL, T_TIME, T_STDC, T_OPERATOR, T_POISON, T_MACRO, T_ASSERTION): Delete. (struct cpp_pool, struct cpp_macro, struct cpp_lexer_pos, struct cpp_lookahead, CPP_DHASH, enum mi_state, enum mi_ind, NO_EXPAND, VARARGS_FIRST, struct cpp_token_with_pos, struct toklist, struct cpp_context, struct specnodes, TOKEN_LOOKAHEAD, TOKEN_BUFFSIZE, NODE_OPERATOR, NODE_POISONED, NODE_BUILTIN, NODE_DIAGNOSTIC, NT_VOID, NT_MACRO, NT_ASSERTION, enum builtin_type, cpp_can_paste): New. (struct cpp_token): Delete line and col members. (struct cpp_buffer): New member output_lineno. (struct lexer_state): Delete indented, in_lex_line, seen_dot. Add va_args_ok, poisoned_ok, prevent_expansion, parsing_args. (struct cpp_reader): New members lexer_pos, macro_pos, directive_pos, ident_pool, temp_string_pool, macro_pool, argument_pool, string_pool, base_context, context, directive, mi_state, mi_if_not_defined, mi_lexed, mi_cmacro, mi_ind_cmacro, la_read, la_write, la_unused, mlstring_pos, macro_buffer, macro_buffer_len. Delete members mls_line, mls_column, token_list, potential_control_macro, temp_tokens, temp_cap, temp_alloced, temp_used, first_directive_token, context_cap, cur_context, no_expand_level, paste_level, contexts, args, save_parameter_spellings, need_newline, . Change type of date, time and spec_nodes members. Change prototypes for include and ident callbacks. (struct cpp_hashnode): Change type of name. Remove union members expansion and code. Add members macro, operator and builtin. (cpp_token_len, cpp_token_as_text, cpp_spell_token, cpp_start_read, cpp_finish, cpp_avoid_paste, cpp_get_token, cpp_get_line, cpp_get_output_line, cpp_macro_definition, cpp_start_lookahead, cpp_stop_lookahead): New prototypes. (cpp_printer_init, cpp_dump_definition): Delete prototypes. (U_CHAR, U, ustrcmp, ustrncmp, ustrlen, uxstrdup, ustrchr, ufputs): Move from cpphash.h. * cpphash.h (U_CHAR, U, ustrcmp, ustrncmp, ustrlen, uxstrdup, ustrchr, ufputs): Move to cpplib.h. (enum spell_type, struct token_spelling, _cpp_token_spellings, TOKEN_SPELL, TOKEN_NAME, struct answer, FREE_ANSWER, KANDR, STDC89, EXTENSION, COND, EXPAND, INCL, COMMENTS, IN_I, struct directive, directive_handler, struct spec_nodes, _cpp_digraph_spellings, _cpp_free_temp_tokens, _cpp_init_input_buffer, _cpp_grow_token_buffer, _cpp_init_toklist, _cpp_clear_toklist, _cpp_expand_token_space, _cpp_expand_name_space, _cpp_equiv_tokens, _cpp_equiv_toklists, _cpp_process_directive, _cpp_run_directive, _cpp_get_line, _cpp_get_raw_token, _cpp_glue_header_name, _cpp_can_paste, _cpp_check_directive, _cpp_check_linemarker, _cpp_parse_assertion, _cpp_find_answer): Delete. (VALID_SIGN, ALIGN, POOL_FRONT, POOL_LIMIT, POOL_BASE, POOL_SIZE, POOL_USED, POOL_COMMIT, struct cpp_chunk, _cpp_lex_token, _cpp_init_pool, _cpp_free_pool, _cpp_pool_reserve, _cpp_pool_alloc, _cpp_next_chunk, _cpp_lock_pool, _cpp_unlock_pool, _cpp_test_assertion, _cpp_handle_directive, DSC): New. (struct include_file): New member defined. (DO_NOT_REREAD, _cpp_begin_message, _cpp_execute_include, _cpp_compare_file_date): Update. (_cpp_pop_context, _cpp_get_token, _cpp_free_lookaheads, _cpp_push_token): New. (_cpp_init_macros, _cpp_cleanup_macros): Rename to _cpp_init_hashtable, _cpp_cleanup_hashtable. * Makefile.in: Remove cppoutput.c. * cppoutput.c: Delete * fixheader.c (read_scan_file): Update for new cpp_get_token prototype. (recognized_function): New argument LINE. * scan-decls.c (skip_to_closing_brace, scan_decls): Update for new cpp_get_token prototype. * scan.h (recognized_function): Update prototype. * po/POTFILES.in: Remove cppoutput.c. From-SVN: r37098
2000-10-28 19:59:06 +02:00
PR preprocessor/60723 - missing system-ness marks for macro tokens When a system macro is expanded in a non-system file during out-of-line preprocessing, it can happen that the preprocessor forgets to emit line markers to express the system-ness status of tokens that come after the expansion of the macro. That can lead to situations where the entire non-system file can be considered as being a system file and thus have its warnings be discarded during the compilation of the resulting preprocessed file. My understanding is that this is due to the preprocessor not systematically detecting (and reporting) the change in system-ness of tokens. And this is what this patch does. Each time the system-ness of a given token is different from the previous token that was emitted by the preprocessor, it emits a line marker for the sole purpose of marking the new system-ness of the subsequent tokens to come. Bootstrapped and tested on x86_64-unknown-linux-gnu against trunk. gcc/c-family/ChangeLog: * c-ppoutput.c (struct print::prev_was_system_token): New data member. (init_pp_output): Initialize it. (maybe_print_line_1, maybe_print_line, print_line_1, print_line) (do_line_change): Return a flag saying if a line marker was emitted or not. (scan_translation_unit): Detect if the system-ness of the token we are about to emit is different from the one of the previously emitted token. If so, emit a line marker. Avoid emitting useless adjacent line markers. Avoid emitting line markers for tokens originating from the expansion of built-in macros. (scan_translation_unit_directives_only): Adjust. gcc/testsuite/ChangeLog: * gcc.dg/cpp/syshdr{4,5}.{c,h}: New test files. Signed-off-by: Dodji Seketeli <dodji@redhat.com> Signed-off-by: Dodji Seketeli <dodji@redhat.com> From-SVN: r212638
2014-07-16 12:33:36 +02:00
static bool print_line_1 (source_location, const char*, FILE *);
static bool print_line (source_location, const char *);
static bool maybe_print_line_1 (source_location, FILE *);
static bool maybe_print_line (source_location);
static bool do_line_change (cpp_reader *, const cpp_token *,
source_location, int);
New macro expander. 2000-10-28 Neil Booth <neilb@earthling.net> New macro expander. * cpplib.c (struct answer): New. (struct if_stack): Use cpp_lexer_pos rather than line and col. Rename cmacro mi_cmacro. (struct directive, KANDR, STDC89, EXTENSION, COND, IF_COND, INCL, IN_I): New directive and flags. (skip_rest_of_line, check_eol, run_directive, glue_header_name, parse_answer, parse_assertion, find_answer): New functions. (parse_ifdef, detect_if_not_defined, validate_else): Remove. (lex_macro_node): New function to replace parse_ifdef and get_define_node. (_cpp_handle_directive): New function, combines _cpp_check_directive and _cpp_check_linemarker. (do_define, do_undef, parse_include, do_include, do_import, do_include_next, read_line_number, do_line, do_ident, do_pragma, do_pragma_once, do_pragma_poison, do_pragma_dependency): Update for new token getting interface. (do_ifdef, do_ifndef, do_if, do_else, do_endif, push_conditional) : Update for new multiple-include optimisation technique. (do_elif): Don't forget to invalidate controlling macros. (unwind_if_stack, cpp_defined, cpp_push_buffer, cpp_pop_buffer): Update. (parse_assertion, parse_answer, find_answer, _cpp_test_assertion): Functions to handle assertions with the new token interface. (do_assert, do_unassert): Use them. (cpp_define, _cpp_define_builtin, cpp_undef, cpp_assert, cpp_unassert): Use run_directive. (_cpp_init_stacks): Register directive names. Don't register special nodes. * cpperror.c (print_containing_files, _cpp_begin_message): Update to new position recording regime. (cpp_ice, cpp_fatal, cpp_error, cpp_error_with_line, cpp_warning, cpp_warning_with_line, cpp_pedwarn, cpp_pedwarn_with_line, cpp_pedwarn_with_file_and_line): Update for _cpp_begin_message changes. (cpp_type2name): Move to cpplex.c. * cppexp.c (parse_charconst): spec_nodes is no longer a pointer. (parse_defined): Update to handle new multiple include optimisation method. Remove poisoned identifier warning. (parse_assertion, TYPE_NAME): Delete. (lex): Update for multiple include optimisation, removal of CPP_DEFINED, to use _cpp_test_assertion for assertions and cpp_token_as_text. (_cpp_parse_expr): Update for MI optimisation, and to use op_as_text. (op_as_text): New function, to wrap cpp_token_as_text. * cppfiles.c (stack_include_file, _cpp_pop_file_buffer): Update for MI optimisation. (_cpp_execute_include): Take a token rather than 3 arguments. Fix segfault on diagnostic. (_cpp_compare_file_date): Take a token rather than 3 args. (cpp_read_file): Work correctly for zero-length files. * cpphash.c (_cpp_init_macros, _cpp_cleanup_macros): Rename _cpp_init_hashtable and _cpp_cleanup_hashtable. (cpp_lookup): Place identifiers at front of identifier pool for _cpp_lookup_with_hash. (_cpp_lookup_with_hash): Require identifiers to be at the front of the identifier pool. Commit the memory if not already in the hash table. * cppinit.c (cpp_reader_init): Move cpp_init_completed test to top. Initialise various members of cpp_reader, memory pools, and the special nodes. (cpp_printer_init): Delete. (cpp_cleanup): Update. (struct builtin, builtin_array, initialize_builtins): Update for new hashnode definition and builtin handling. (cpp_start_read, cpp_finish): Don't take or initialise a printer. Update. * cpplib.h (cpp_printer, cpp_toklist, CPP_DEFINED, BOL, PASTED, VAR_ARGS, BEG_OF_FILE, IN_DIRECTIVE, KNOWN_DIRECTIVE, T_VOID, T_SPECLINE, T_DATE, T_FILE, T_BASE_FILE, T_INCLUDE_LEVEL, T_TIME, T_STDC, T_OPERATOR, T_POISON, T_MACRO, T_ASSERTION): Delete. (struct cpp_pool, struct cpp_macro, struct cpp_lexer_pos, struct cpp_lookahead, CPP_DHASH, enum mi_state, enum mi_ind, NO_EXPAND, VARARGS_FIRST, struct cpp_token_with_pos, struct toklist, struct cpp_context, struct specnodes, TOKEN_LOOKAHEAD, TOKEN_BUFFSIZE, NODE_OPERATOR, NODE_POISONED, NODE_BUILTIN, NODE_DIAGNOSTIC, NT_VOID, NT_MACRO, NT_ASSERTION, enum builtin_type, cpp_can_paste): New. (struct cpp_token): Delete line and col members. (struct cpp_buffer): New member output_lineno. (struct lexer_state): Delete indented, in_lex_line, seen_dot. Add va_args_ok, poisoned_ok, prevent_expansion, parsing_args. (struct cpp_reader): New members lexer_pos, macro_pos, directive_pos, ident_pool, temp_string_pool, macro_pool, argument_pool, string_pool, base_context, context, directive, mi_state, mi_if_not_defined, mi_lexed, mi_cmacro, mi_ind_cmacro, la_read, la_write, la_unused, mlstring_pos, macro_buffer, macro_buffer_len. Delete members mls_line, mls_column, token_list, potential_control_macro, temp_tokens, temp_cap, temp_alloced, temp_used, first_directive_token, context_cap, cur_context, no_expand_level, paste_level, contexts, args, save_parameter_spellings, need_newline, . Change type of date, time and spec_nodes members. Change prototypes for include and ident callbacks. (struct cpp_hashnode): Change type of name. Remove union members expansion and code. Add members macro, operator and builtin. (cpp_token_len, cpp_token_as_text, cpp_spell_token, cpp_start_read, cpp_finish, cpp_avoid_paste, cpp_get_token, cpp_get_line, cpp_get_output_line, cpp_macro_definition, cpp_start_lookahead, cpp_stop_lookahead): New prototypes. (cpp_printer_init, cpp_dump_definition): Delete prototypes. (U_CHAR, U, ustrcmp, ustrncmp, ustrlen, uxstrdup, ustrchr, ufputs): Move from cpphash.h. * cpphash.h (U_CHAR, U, ustrcmp, ustrncmp, ustrlen, uxstrdup, ustrchr, ufputs): Move to cpplib.h. (enum spell_type, struct token_spelling, _cpp_token_spellings, TOKEN_SPELL, TOKEN_NAME, struct answer, FREE_ANSWER, KANDR, STDC89, EXTENSION, COND, EXPAND, INCL, COMMENTS, IN_I, struct directive, directive_handler, struct spec_nodes, _cpp_digraph_spellings, _cpp_free_temp_tokens, _cpp_init_input_buffer, _cpp_grow_token_buffer, _cpp_init_toklist, _cpp_clear_toklist, _cpp_expand_token_space, _cpp_expand_name_space, _cpp_equiv_tokens, _cpp_equiv_toklists, _cpp_process_directive, _cpp_run_directive, _cpp_get_line, _cpp_get_raw_token, _cpp_glue_header_name, _cpp_can_paste, _cpp_check_directive, _cpp_check_linemarker, _cpp_parse_assertion, _cpp_find_answer): Delete. (VALID_SIGN, ALIGN, POOL_FRONT, POOL_LIMIT, POOL_BASE, POOL_SIZE, POOL_USED, POOL_COMMIT, struct cpp_chunk, _cpp_lex_token, _cpp_init_pool, _cpp_free_pool, _cpp_pool_reserve, _cpp_pool_alloc, _cpp_next_chunk, _cpp_lock_pool, _cpp_unlock_pool, _cpp_test_assertion, _cpp_handle_directive, DSC): New. (struct include_file): New member defined. (DO_NOT_REREAD, _cpp_begin_message, _cpp_execute_include, _cpp_compare_file_date): Update. (_cpp_pop_context, _cpp_get_token, _cpp_free_lookaheads, _cpp_push_token): New. (_cpp_init_macros, _cpp_cleanup_macros): Rename to _cpp_init_hashtable, _cpp_cleanup_hashtable. * Makefile.in: Remove cppoutput.c. * cppoutput.c: Delete * fixheader.c (read_scan_file): Update for new cpp_get_token prototype. (recognized_function): New argument LINE. * scan-decls.c (skip_to_closing_brace, scan_decls): Update for new cpp_get_token prototype. * scan.h (recognized_function): Update prototype. * po/POTFILES.in: Remove cppoutput.c. From-SVN: r37098
2000-10-28 19:59:06 +02:00
cpperror.c (v_message): Split into _cpp_begin_message and v_message macro. * cpperror.c (v_message): Split into _cpp_begin_message and v_message macro. All callers updated. (_cpp_begin_message): Do inhibit_errors/inhibit_warnings checks here. * cppfiles.c (cpp_syshdr_flags): New function. (read_include_file): Don't call cpp_output_tokens. Call enter_file hook. * cppinit.c (dump_macros_helper): Moved to cppmain.c. (cpp_reader_init): Don't initialize token_buffer. Call _cpp_init_internal_pragmas. (cpp_cleanup): Don't clear token_buffer. (cpp_start_read): Don't worry about output from -D processing. Don't call cpp_output_tokens. (cpp_finish): Don't dump macros here. Don't call cpp_output_tokens. * cppmacro.c (_cpp_dump_definition): Rename cpp_dump_definition. Write directly to a FILE *. (dump_funlike_macro): Delete. (dump_macro_args): New. * cpplex.c (TOKEN_LEN): Convert to inline function. (_cpp_grow_token_buffer, safe_fwrite, cpp_output_tokens, cpp_scan_line, _cpp_dump_list): Delete. (cpp_printf, cpp_output_list): New. (output_line_command): Don't worry about entering or leaving files. (cpp_scan_buffer): Just output each token as we hit it. (process_directive): Don't call cpp_output_tokens. (_cpp_glue_header_name): Don't use token_buffer. (output_token, dump_param_spelling): Write directly to a FILE *. * cpplib.c (pass_thru_directive, dump_macro_name, pragma_dispatch, do_pragma_gcc): Delete. (do_define, do_undef, parse_include, do_line, do_ident, do_pragma, do_pragma_poison, cpp_pop_buffer): Call the appropriate hook functions. (do_error, do_warning, pragma_dependency): Call _cpp_begin_message, then cpp_output_list. (cpp_register_pragma, cpp_register_pragma_space, _cpp_init_internal_pragmas): New. (do_pragma): Walk the pragmas table here. (do_pragma_once, do_pragma_poison, do_pragma_system_header, do_pragma_dependency): Return void. (do_pragma_implementation): Moved to cppmain.c. * cpplib.h: Update prototypes. (struct cpp_reader): Remove printer, token_buffer, token_buffer_size, and limit. Add struct cb, and pragmas. (struct cpp_printer): Remove last_id and written. (CPP_WRITTEN, CPP_PWRITTEN, CPP_SET_WRITTEN, CPP_ADJUST_WRITTEN): Delete. * cpphash.h: Update prototypes. (ufputs): New wrapper. * cppmain.c (cb_define, cb_undef, cb_include, cb_ident, cb_enter_file, cb_leave_file, cb_def_pragma): New functions. (main): Set up callbacks. Register #pragma implementation. Dump macros from here. From-SVN: r35415
2000-08-02 03:13:45 +02:00
/* Callback routines for the parser. Most of these are active only
in specific modes. */
static void cb_line_change (cpp_reader *, const cpp_token *, int);
static void cb_define (cpp_reader *, source_location, cpp_hashnode *);
static void cb_undef (cpp_reader *, source_location, cpp_hashnode *);
static void cb_used_define (cpp_reader *, source_location, cpp_hashnode *);
static void cb_used_undef (cpp_reader *, source_location, cpp_hashnode *);
static void cb_include (cpp_reader *, source_location, const unsigned char *,
const char *, int, const cpp_token **);
static void cb_ident (cpp_reader *, source_location, const cpp_string *);
static void cb_def_pragma (cpp_reader *, source_location);
static void cb_read_pch (cpp_reader *pfile, const char *name,
int fd, const char *orig_name);
New macro expander. 2000-10-28 Neil Booth <neilb@earthling.net> New macro expander. * cpplib.c (struct answer): New. (struct if_stack): Use cpp_lexer_pos rather than line and col. Rename cmacro mi_cmacro. (struct directive, KANDR, STDC89, EXTENSION, COND, IF_COND, INCL, IN_I): New directive and flags. (skip_rest_of_line, check_eol, run_directive, glue_header_name, parse_answer, parse_assertion, find_answer): New functions. (parse_ifdef, detect_if_not_defined, validate_else): Remove. (lex_macro_node): New function to replace parse_ifdef and get_define_node. (_cpp_handle_directive): New function, combines _cpp_check_directive and _cpp_check_linemarker. (do_define, do_undef, parse_include, do_include, do_import, do_include_next, read_line_number, do_line, do_ident, do_pragma, do_pragma_once, do_pragma_poison, do_pragma_dependency): Update for new token getting interface. (do_ifdef, do_ifndef, do_if, do_else, do_endif, push_conditional) : Update for new multiple-include optimisation technique. (do_elif): Don't forget to invalidate controlling macros. (unwind_if_stack, cpp_defined, cpp_push_buffer, cpp_pop_buffer): Update. (parse_assertion, parse_answer, find_answer, _cpp_test_assertion): Functions to handle assertions with the new token interface. (do_assert, do_unassert): Use them. (cpp_define, _cpp_define_builtin, cpp_undef, cpp_assert, cpp_unassert): Use run_directive. (_cpp_init_stacks): Register directive names. Don't register special nodes. * cpperror.c (print_containing_files, _cpp_begin_message): Update to new position recording regime. (cpp_ice, cpp_fatal, cpp_error, cpp_error_with_line, cpp_warning, cpp_warning_with_line, cpp_pedwarn, cpp_pedwarn_with_line, cpp_pedwarn_with_file_and_line): Update for _cpp_begin_message changes. (cpp_type2name): Move to cpplex.c. * cppexp.c (parse_charconst): spec_nodes is no longer a pointer. (parse_defined): Update to handle new multiple include optimisation method. Remove poisoned identifier warning. (parse_assertion, TYPE_NAME): Delete. (lex): Update for multiple include optimisation, removal of CPP_DEFINED, to use _cpp_test_assertion for assertions and cpp_token_as_text. (_cpp_parse_expr): Update for MI optimisation, and to use op_as_text. (op_as_text): New function, to wrap cpp_token_as_text. * cppfiles.c (stack_include_file, _cpp_pop_file_buffer): Update for MI optimisation. (_cpp_execute_include): Take a token rather than 3 arguments. Fix segfault on diagnostic. (_cpp_compare_file_date): Take a token rather than 3 args. (cpp_read_file): Work correctly for zero-length files. * cpphash.c (_cpp_init_macros, _cpp_cleanup_macros): Rename _cpp_init_hashtable and _cpp_cleanup_hashtable. (cpp_lookup): Place identifiers at front of identifier pool for _cpp_lookup_with_hash. (_cpp_lookup_with_hash): Require identifiers to be at the front of the identifier pool. Commit the memory if not already in the hash table. * cppinit.c (cpp_reader_init): Move cpp_init_completed test to top. Initialise various members of cpp_reader, memory pools, and the special nodes. (cpp_printer_init): Delete. (cpp_cleanup): Update. (struct builtin, builtin_array, initialize_builtins): Update for new hashnode definition and builtin handling. (cpp_start_read, cpp_finish): Don't take or initialise a printer. Update. * cpplib.h (cpp_printer, cpp_toklist, CPP_DEFINED, BOL, PASTED, VAR_ARGS, BEG_OF_FILE, IN_DIRECTIVE, KNOWN_DIRECTIVE, T_VOID, T_SPECLINE, T_DATE, T_FILE, T_BASE_FILE, T_INCLUDE_LEVEL, T_TIME, T_STDC, T_OPERATOR, T_POISON, T_MACRO, T_ASSERTION): Delete. (struct cpp_pool, struct cpp_macro, struct cpp_lexer_pos, struct cpp_lookahead, CPP_DHASH, enum mi_state, enum mi_ind, NO_EXPAND, VARARGS_FIRST, struct cpp_token_with_pos, struct toklist, struct cpp_context, struct specnodes, TOKEN_LOOKAHEAD, TOKEN_BUFFSIZE, NODE_OPERATOR, NODE_POISONED, NODE_BUILTIN, NODE_DIAGNOSTIC, NT_VOID, NT_MACRO, NT_ASSERTION, enum builtin_type, cpp_can_paste): New. (struct cpp_token): Delete line and col members. (struct cpp_buffer): New member output_lineno. (struct lexer_state): Delete indented, in_lex_line, seen_dot. Add va_args_ok, poisoned_ok, prevent_expansion, parsing_args. (struct cpp_reader): New members lexer_pos, macro_pos, directive_pos, ident_pool, temp_string_pool, macro_pool, argument_pool, string_pool, base_context, context, directive, mi_state, mi_if_not_defined, mi_lexed, mi_cmacro, mi_ind_cmacro, la_read, la_write, la_unused, mlstring_pos, macro_buffer, macro_buffer_len. Delete members mls_line, mls_column, token_list, potential_control_macro, temp_tokens, temp_cap, temp_alloced, temp_used, first_directive_token, context_cap, cur_context, no_expand_level, paste_level, contexts, args, save_parameter_spellings, need_newline, . Change type of date, time and spec_nodes members. Change prototypes for include and ident callbacks. (struct cpp_hashnode): Change type of name. Remove union members expansion and code. Add members macro, operator and builtin. (cpp_token_len, cpp_token_as_text, cpp_spell_token, cpp_start_read, cpp_finish, cpp_avoid_paste, cpp_get_token, cpp_get_line, cpp_get_output_line, cpp_macro_definition, cpp_start_lookahead, cpp_stop_lookahead): New prototypes. (cpp_printer_init, cpp_dump_definition): Delete prototypes. (U_CHAR, U, ustrcmp, ustrncmp, ustrlen, uxstrdup, ustrchr, ufputs): Move from cpphash.h. * cpphash.h (U_CHAR, U, ustrcmp, ustrncmp, ustrlen, uxstrdup, ustrchr, ufputs): Move to cpplib.h. (enum spell_type, struct token_spelling, _cpp_token_spellings, TOKEN_SPELL, TOKEN_NAME, struct answer, FREE_ANSWER, KANDR, STDC89, EXTENSION, COND, EXPAND, INCL, COMMENTS, IN_I, struct directive, directive_handler, struct spec_nodes, _cpp_digraph_spellings, _cpp_free_temp_tokens, _cpp_init_input_buffer, _cpp_grow_token_buffer, _cpp_init_toklist, _cpp_clear_toklist, _cpp_expand_token_space, _cpp_expand_name_space, _cpp_equiv_tokens, _cpp_equiv_toklists, _cpp_process_directive, _cpp_run_directive, _cpp_get_line, _cpp_get_raw_token, _cpp_glue_header_name, _cpp_can_paste, _cpp_check_directive, _cpp_check_linemarker, _cpp_parse_assertion, _cpp_find_answer): Delete. (VALID_SIGN, ALIGN, POOL_FRONT, POOL_LIMIT, POOL_BASE, POOL_SIZE, POOL_USED, POOL_COMMIT, struct cpp_chunk, _cpp_lex_token, _cpp_init_pool, _cpp_free_pool, _cpp_pool_reserve, _cpp_pool_alloc, _cpp_next_chunk, _cpp_lock_pool, _cpp_unlock_pool, _cpp_test_assertion, _cpp_handle_directive, DSC): New. (struct include_file): New member defined. (DO_NOT_REREAD, _cpp_begin_message, _cpp_execute_include, _cpp_compare_file_date): Update. (_cpp_pop_context, _cpp_get_token, _cpp_free_lookaheads, _cpp_push_token): New. (_cpp_init_macros, _cpp_cleanup_macros): Rename to _cpp_init_hashtable, _cpp_cleanup_hashtable. * Makefile.in: Remove cppoutput.c. * cppoutput.c: Delete * fixheader.c (read_scan_file): Update for new cpp_get_token prototype. (recognized_function): New argument LINE. * scan-decls.c (skip_to_closing_brace, scan_decls): Update for new cpp_get_token prototype. * scan.h (recognized_function): Update prototype. * po/POTFILES.in: Remove cppoutput.c. From-SVN: r37098
2000-10-28 19:59:06 +02:00
/* Preprocess and output. */
void
preprocess_file (cpp_reader *pfile)
1995-03-16 22:59:07 +01:00
{
/* A successful cpp_read_main_file guarantees that we can call
cpp_scan_nooutput or cpp_get_token next. */
if (flag_no_output && pfile->buffer)
{
/* Scan -included buffers, then the main file. */
while (pfile->buffer->prev)
cpp_scan_nooutput (pfile);
cpp_scan_nooutput (pfile);
}
else if (cpp_get_options (pfile)->traditional)
scan_translation_unit_trad (pfile);
directives-only.c: New file. libcpp/ * directives-only.c: New file. * internal.h (struct _cpp_dir_only_callbacks): New. (_cpp_preprocess_dir_only): New function. * directives.c (_cpp_handle_directive): Check directives_only before disabling execution of indented directives. * files.c (_cpp_stack_file): Add directives_only check. * include/cpplib.h (struct cpp_options): Add directives_only. (cpp_init_special_builtins): New function. * init.c (cpp_init_special_builtins): New function. (cpp_init_builtins): Move builtin_array initialization to cpp_init_special_builtins. (post_options): Check directives_only before setting pfile->state.prevent_expansion = 1. * macro.c (_cpp_builtin_macro_text): Print an error if __COUNTER__ is expanded inside a directive while -fdirectives-only is enabled. * Makefile.in (libcpp_a_OBJS): Add directives-only.o. (libcpp_a_SOURCES): Add directives-only.c. gcc/ * c-ppoutput.c (print_lines_directives_only): New function. (scan_translation_unit_directives_only): New function. (preprocess_file): Add call to scan_translation_unit_directives_only. * c-opts.c (c_common_handle_option): Add OPT_fdirectives_only. (sanitize_cpp_opts): Add default flag_dump_macros setting for -fdirectives-only. Add errors for -fdirectives-only conflict with -Wunused-macros and -traditional. (finish_options): Add builtin macro initialization for -fdirectives-only + -fpreprocessed. * c.opt (fdirectives-only): New. * doc/cppopts.texi (fdirectives-only): New. gcc/testsuite/ * gcc.dg/cpp/counter-2.c: New test. * gcc.dg/cpp/counter-3.c: New test. * gcc.dg/cpp/dir-only-1.c: New test. * gcc.dg/cpp/dir-only-1.h: New file. * gcc.dg/cpp/dir-only-2.c: New test. * gcc.dg/cpp/dir-only-3.c: New test. * gcc.dg/cpp/dir-only-3a.h: New file. * gcc.dg/cpp/dir-only-3b.h: New file. * gcc.dg/cpp/dir-only-4.c: New test. * gcc.dg/cpp/dir-only-5.c: New test. * gcc.dg/cpp/dir-only-6.c: New test. From-SVN: r127066
2007-07-30 20:29:20 +02:00
else if (cpp_get_options (pfile)->directives_only
&& !cpp_get_options (pfile)->preprocessed)
scan_translation_unit_directives_only (pfile);
else
scan_translation_unit (pfile);
/* -dM command line option. Should this be elsewhere? */
if (flag_dump_macros == 'M')
cpp_forall_identifiers (pfile, dump_macro, NULL);
/* Flush any pending output. */
if (print.printed)
putc ('\n', print.outf);
}
/* Set up the callbacks as appropriate. */
void
init_pp_output (FILE *out_stream)
{
cpp_callbacks *cb = cpp_get_callbacks (parse_in);
if (!flag_no_output)
{
cb->line_change = cb_line_change;
/* Don't emit #pragma or #ident directives if we are processing
assembly language; the assembler may choke on them. */
if (cpp_get_options (parse_in)->lang != CLK_ASM)
{
cb->ident = cb_ident;
cb->def_pragma = cb_def_pragma;
}
}
if (flag_dump_includes)
cb->include = cb_include;
if (flag_pch_preprocess)
{
cb->valid_pch = c_common_valid_pch;
cb->read_pch = cb_read_pch;
}
if (flag_dump_macros == 'N' || flag_dump_macros == 'D')
{
cb->define = cb_define;
cb->undef = cb_undef;
}
if (flag_dump_macros == 'U')
{
cb->before_define = dump_queued_macros;
cb->used_define = cb_used_define;
cb->used_undef = cb_used_undef;
}
re PR preprocessor/63831 (r217292 causes segfaults with -MM) PR preprocessor/63831 * c-cppbuiltin.c (c_cpp_builtins): Don't define __has_attribute and __has_cpp_attribute here. * c-ppoutput.c (init_pp_output): Set cb->has_attribute to c_common_has_attribute. * c-common.h (c_common_has_attribute): New prototype. * c-lex.c (init_c_lex): Set cb->has_attribute to c_common_has_attribute instead of cb_has_attribute. (get_token_no_padding): New function. (cb_has_attribute): Renamed to ... (c_common_has_attribute): ... this. No longer static. Use get_token_no_padding, require ()s, don't build TREE_LIST unnecessarily, fix up formatting, adjust diagnostics, call init_attributes. * directives.c (lex_macro_node): Remove __has_attribute__ handling. * internal.h (struct spec_node): Remove n__has_attribute__ field. (struct lexer_state): Remove in__has_attribute__ field. * macro.c (_cpp_builtin_macro_text): Handle BT_HAS_ATTRIBUTE. * identifiers.c (_cpp_init_hashtable): Remove __has_attribute__ handling. * init.c (builtin_array): Add __has_attribute and __has_cpp_attribute. (cpp_init_special_builtins): Don't initialize __has_attribute or __has_cpp_attribute if CLK_ASM or pfile->cb.has_attribute is NULL. * traditional.c (enum ls): Remove ls_has_attribute, ls_has_attribute_close. (_cpp_scan_out_logical_line): Remove __has_attribute__ handling. * include/cpplib.h (enum cpp_builtin_type): Add BT_HAS_ATTRIBUTE. * pch.c (cpp_read_state): Remove __has_attribute__ handling. * expr.c (eval_token): Likewise. (parse_has_attribute): Removed. * c-c++-common/cpp/pr63831-1.c: New test. * c-c++-common/cpp/pr63831-2.c: New test. From-SVN: r218948
2014-12-19 13:20:58 +01:00
cb->has_attribute = c_common_has_attribute;
cb->get_source_date_epoch = cb_get_source_date_epoch;
re PR preprocessor/63831 (r217292 causes segfaults with -MM) PR preprocessor/63831 * c-cppbuiltin.c (c_cpp_builtins): Don't define __has_attribute and __has_cpp_attribute here. * c-ppoutput.c (init_pp_output): Set cb->has_attribute to c_common_has_attribute. * c-common.h (c_common_has_attribute): New prototype. * c-lex.c (init_c_lex): Set cb->has_attribute to c_common_has_attribute instead of cb_has_attribute. (get_token_no_padding): New function. (cb_has_attribute): Renamed to ... (c_common_has_attribute): ... this. No longer static. Use get_token_no_padding, require ()s, don't build TREE_LIST unnecessarily, fix up formatting, adjust diagnostics, call init_attributes. * directives.c (lex_macro_node): Remove __has_attribute__ handling. * internal.h (struct spec_node): Remove n__has_attribute__ field. (struct lexer_state): Remove in__has_attribute__ field. * macro.c (_cpp_builtin_macro_text): Handle BT_HAS_ATTRIBUTE. * identifiers.c (_cpp_init_hashtable): Remove __has_attribute__ handling. * init.c (builtin_array): Add __has_attribute and __has_cpp_attribute. (cpp_init_special_builtins): Don't initialize __has_attribute or __has_cpp_attribute if CLK_ASM or pfile->cb.has_attribute is NULL. * traditional.c (enum ls): Remove ls_has_attribute, ls_has_attribute_close. (_cpp_scan_out_logical_line): Remove __has_attribute__ handling. * include/cpplib.h (enum cpp_builtin_type): Add BT_HAS_ATTRIBUTE. * pch.c (cpp_read_state): Remove __has_attribute__ handling. * expr.c (eval_token): Likewise. (parse_has_attribute): Removed. * c-c++-common/cpp/pr63831-1.c: New test. * c-c++-common/cpp/pr63831-2.c: New test. From-SVN: r218948
2014-12-19 13:20:58 +01:00
/* Initialize the print structure. */
print.src_line = 1;
print.printed = false;
print.prev = 0;
print.outf = out_stream;
print.first_time = 1;
print.src_file = "";
PR preprocessor/60723 - missing system-ness marks for macro tokens When a system macro is expanded in a non-system file during out-of-line preprocessing, it can happen that the preprocessor forgets to emit line markers to express the system-ness status of tokens that come after the expansion of the macro. That can lead to situations where the entire non-system file can be considered as being a system file and thus have its warnings be discarded during the compilation of the resulting preprocessed file. My understanding is that this is due to the preprocessor not systematically detecting (and reporting) the change in system-ness of tokens. And this is what this patch does. Each time the system-ness of a given token is different from the previous token that was emitted by the preprocessor, it emits a line marker for the sole purpose of marking the new system-ness of the subsequent tokens to come. Bootstrapped and tested on x86_64-unknown-linux-gnu against trunk. gcc/c-family/ChangeLog: * c-ppoutput.c (struct print::prev_was_system_token): New data member. (init_pp_output): Initialize it. (maybe_print_line_1, maybe_print_line, print_line_1, print_line) (do_line_change): Return a flag saying if a line marker was emitted or not. (scan_translation_unit): Detect if the system-ness of the token we are about to emit is different from the one of the previously emitted token. If so, emit a line marker. Avoid emitting useless adjacent line markers. Avoid emitting line markers for tokens originating from the expansion of built-in macros. (scan_translation_unit_directives_only): Adjust. gcc/testsuite/ChangeLog: * gcc.dg/cpp/syshdr{4,5}.{c,h}: New test files. Signed-off-by: Dodji Seketeli <dodji@redhat.com> Signed-off-by: Dodji Seketeli <dodji@redhat.com> From-SVN: r212638
2014-07-16 12:33:36 +02:00
print.prev_was_system_token = false;
}
/* Writes out the preprocessed file, handling spacing and paste
avoidance issues. */
New macro expander. 2000-10-28 Neil Booth <neilb@earthling.net> New macro expander. * cpplib.c (struct answer): New. (struct if_stack): Use cpp_lexer_pos rather than line and col. Rename cmacro mi_cmacro. (struct directive, KANDR, STDC89, EXTENSION, COND, IF_COND, INCL, IN_I): New directive and flags. (skip_rest_of_line, check_eol, run_directive, glue_header_name, parse_answer, parse_assertion, find_answer): New functions. (parse_ifdef, detect_if_not_defined, validate_else): Remove. (lex_macro_node): New function to replace parse_ifdef and get_define_node. (_cpp_handle_directive): New function, combines _cpp_check_directive and _cpp_check_linemarker. (do_define, do_undef, parse_include, do_include, do_import, do_include_next, read_line_number, do_line, do_ident, do_pragma, do_pragma_once, do_pragma_poison, do_pragma_dependency): Update for new token getting interface. (do_ifdef, do_ifndef, do_if, do_else, do_endif, push_conditional) : Update for new multiple-include optimisation technique. (do_elif): Don't forget to invalidate controlling macros. (unwind_if_stack, cpp_defined, cpp_push_buffer, cpp_pop_buffer): Update. (parse_assertion, parse_answer, find_answer, _cpp_test_assertion): Functions to handle assertions with the new token interface. (do_assert, do_unassert): Use them. (cpp_define, _cpp_define_builtin, cpp_undef, cpp_assert, cpp_unassert): Use run_directive. (_cpp_init_stacks): Register directive names. Don't register special nodes. * cpperror.c (print_containing_files, _cpp_begin_message): Update to new position recording regime. (cpp_ice, cpp_fatal, cpp_error, cpp_error_with_line, cpp_warning, cpp_warning_with_line, cpp_pedwarn, cpp_pedwarn_with_line, cpp_pedwarn_with_file_and_line): Update for _cpp_begin_message changes. (cpp_type2name): Move to cpplex.c. * cppexp.c (parse_charconst): spec_nodes is no longer a pointer. (parse_defined): Update to handle new multiple include optimisation method. Remove poisoned identifier warning. (parse_assertion, TYPE_NAME): Delete. (lex): Update for multiple include optimisation, removal of CPP_DEFINED, to use _cpp_test_assertion for assertions and cpp_token_as_text. (_cpp_parse_expr): Update for MI optimisation, and to use op_as_text. (op_as_text): New function, to wrap cpp_token_as_text. * cppfiles.c (stack_include_file, _cpp_pop_file_buffer): Update for MI optimisation. (_cpp_execute_include): Take a token rather than 3 arguments. Fix segfault on diagnostic. (_cpp_compare_file_date): Take a token rather than 3 args. (cpp_read_file): Work correctly for zero-length files. * cpphash.c (_cpp_init_macros, _cpp_cleanup_macros): Rename _cpp_init_hashtable and _cpp_cleanup_hashtable. (cpp_lookup): Place identifiers at front of identifier pool for _cpp_lookup_with_hash. (_cpp_lookup_with_hash): Require identifiers to be at the front of the identifier pool. Commit the memory if not already in the hash table. * cppinit.c (cpp_reader_init): Move cpp_init_completed test to top. Initialise various members of cpp_reader, memory pools, and the special nodes. (cpp_printer_init): Delete. (cpp_cleanup): Update. (struct builtin, builtin_array, initialize_builtins): Update for new hashnode definition and builtin handling. (cpp_start_read, cpp_finish): Don't take or initialise a printer. Update. * cpplib.h (cpp_printer, cpp_toklist, CPP_DEFINED, BOL, PASTED, VAR_ARGS, BEG_OF_FILE, IN_DIRECTIVE, KNOWN_DIRECTIVE, T_VOID, T_SPECLINE, T_DATE, T_FILE, T_BASE_FILE, T_INCLUDE_LEVEL, T_TIME, T_STDC, T_OPERATOR, T_POISON, T_MACRO, T_ASSERTION): Delete. (struct cpp_pool, struct cpp_macro, struct cpp_lexer_pos, struct cpp_lookahead, CPP_DHASH, enum mi_state, enum mi_ind, NO_EXPAND, VARARGS_FIRST, struct cpp_token_with_pos, struct toklist, struct cpp_context, struct specnodes, TOKEN_LOOKAHEAD, TOKEN_BUFFSIZE, NODE_OPERATOR, NODE_POISONED, NODE_BUILTIN, NODE_DIAGNOSTIC, NT_VOID, NT_MACRO, NT_ASSERTION, enum builtin_type, cpp_can_paste): New. (struct cpp_token): Delete line and col members. (struct cpp_buffer): New member output_lineno. (struct lexer_state): Delete indented, in_lex_line, seen_dot. Add va_args_ok, poisoned_ok, prevent_expansion, parsing_args. (struct cpp_reader): New members lexer_pos, macro_pos, directive_pos, ident_pool, temp_string_pool, macro_pool, argument_pool, string_pool, base_context, context, directive, mi_state, mi_if_not_defined, mi_lexed, mi_cmacro, mi_ind_cmacro, la_read, la_write, la_unused, mlstring_pos, macro_buffer, macro_buffer_len. Delete members mls_line, mls_column, token_list, potential_control_macro, temp_tokens, temp_cap, temp_alloced, temp_used, first_directive_token, context_cap, cur_context, no_expand_level, paste_level, contexts, args, save_parameter_spellings, need_newline, . Change type of date, time and spec_nodes members. Change prototypes for include and ident callbacks. (struct cpp_hashnode): Change type of name. Remove union members expansion and code. Add members macro, operator and builtin. (cpp_token_len, cpp_token_as_text, cpp_spell_token, cpp_start_read, cpp_finish, cpp_avoid_paste, cpp_get_token, cpp_get_line, cpp_get_output_line, cpp_macro_definition, cpp_start_lookahead, cpp_stop_lookahead): New prototypes. (cpp_printer_init, cpp_dump_definition): Delete prototypes. (U_CHAR, U, ustrcmp, ustrncmp, ustrlen, uxstrdup, ustrchr, ufputs): Move from cpphash.h. * cpphash.h (U_CHAR, U, ustrcmp, ustrncmp, ustrlen, uxstrdup, ustrchr, ufputs): Move to cpplib.h. (enum spell_type, struct token_spelling, _cpp_token_spellings, TOKEN_SPELL, TOKEN_NAME, struct answer, FREE_ANSWER, KANDR, STDC89, EXTENSION, COND, EXPAND, INCL, COMMENTS, IN_I, struct directive, directive_handler, struct spec_nodes, _cpp_digraph_spellings, _cpp_free_temp_tokens, _cpp_init_input_buffer, _cpp_grow_token_buffer, _cpp_init_toklist, _cpp_clear_toklist, _cpp_expand_token_space, _cpp_expand_name_space, _cpp_equiv_tokens, _cpp_equiv_toklists, _cpp_process_directive, _cpp_run_directive, _cpp_get_line, _cpp_get_raw_token, _cpp_glue_header_name, _cpp_can_paste, _cpp_check_directive, _cpp_check_linemarker, _cpp_parse_assertion, _cpp_find_answer): Delete. (VALID_SIGN, ALIGN, POOL_FRONT, POOL_LIMIT, POOL_BASE, POOL_SIZE, POOL_USED, POOL_COMMIT, struct cpp_chunk, _cpp_lex_token, _cpp_init_pool, _cpp_free_pool, _cpp_pool_reserve, _cpp_pool_alloc, _cpp_next_chunk, _cpp_lock_pool, _cpp_unlock_pool, _cpp_test_assertion, _cpp_handle_directive, DSC): New. (struct include_file): New member defined. (DO_NOT_REREAD, _cpp_begin_message, _cpp_execute_include, _cpp_compare_file_date): Update. (_cpp_pop_context, _cpp_get_token, _cpp_free_lookaheads, _cpp_push_token): New. (_cpp_init_macros, _cpp_cleanup_macros): Rename to _cpp_init_hashtable, _cpp_cleanup_hashtable. * Makefile.in: Remove cppoutput.c. * cppoutput.c: Delete * fixheader.c (read_scan_file): Update for new cpp_get_token prototype. (recognized_function): New argument LINE. * scan-decls.c (skip_to_closing_brace, scan_decls): Update for new cpp_get_token prototype. * scan.h (recognized_function): Update prototype. * po/POTFILES.in: Remove cppoutput.c. From-SVN: r37098
2000-10-28 19:59:06 +02:00
static void
scan_translation_unit (cpp_reader *pfile)
New macro expander. 2000-10-28 Neil Booth <neilb@earthling.net> New macro expander. * cpplib.c (struct answer): New. (struct if_stack): Use cpp_lexer_pos rather than line and col. Rename cmacro mi_cmacro. (struct directive, KANDR, STDC89, EXTENSION, COND, IF_COND, INCL, IN_I): New directive and flags. (skip_rest_of_line, check_eol, run_directive, glue_header_name, parse_answer, parse_assertion, find_answer): New functions. (parse_ifdef, detect_if_not_defined, validate_else): Remove. (lex_macro_node): New function to replace parse_ifdef and get_define_node. (_cpp_handle_directive): New function, combines _cpp_check_directive and _cpp_check_linemarker. (do_define, do_undef, parse_include, do_include, do_import, do_include_next, read_line_number, do_line, do_ident, do_pragma, do_pragma_once, do_pragma_poison, do_pragma_dependency): Update for new token getting interface. (do_ifdef, do_ifndef, do_if, do_else, do_endif, push_conditional) : Update for new multiple-include optimisation technique. (do_elif): Don't forget to invalidate controlling macros. (unwind_if_stack, cpp_defined, cpp_push_buffer, cpp_pop_buffer): Update. (parse_assertion, parse_answer, find_answer, _cpp_test_assertion): Functions to handle assertions with the new token interface. (do_assert, do_unassert): Use them. (cpp_define, _cpp_define_builtin, cpp_undef, cpp_assert, cpp_unassert): Use run_directive. (_cpp_init_stacks): Register directive names. Don't register special nodes. * cpperror.c (print_containing_files, _cpp_begin_message): Update to new position recording regime. (cpp_ice, cpp_fatal, cpp_error, cpp_error_with_line, cpp_warning, cpp_warning_with_line, cpp_pedwarn, cpp_pedwarn_with_line, cpp_pedwarn_with_file_and_line): Update for _cpp_begin_message changes. (cpp_type2name): Move to cpplex.c. * cppexp.c (parse_charconst): spec_nodes is no longer a pointer. (parse_defined): Update to handle new multiple include optimisation method. Remove poisoned identifier warning. (parse_assertion, TYPE_NAME): Delete. (lex): Update for multiple include optimisation, removal of CPP_DEFINED, to use _cpp_test_assertion for assertions and cpp_token_as_text. (_cpp_parse_expr): Update for MI optimisation, and to use op_as_text. (op_as_text): New function, to wrap cpp_token_as_text. * cppfiles.c (stack_include_file, _cpp_pop_file_buffer): Update for MI optimisation. (_cpp_execute_include): Take a token rather than 3 arguments. Fix segfault on diagnostic. (_cpp_compare_file_date): Take a token rather than 3 args. (cpp_read_file): Work correctly for zero-length files. * cpphash.c (_cpp_init_macros, _cpp_cleanup_macros): Rename _cpp_init_hashtable and _cpp_cleanup_hashtable. (cpp_lookup): Place identifiers at front of identifier pool for _cpp_lookup_with_hash. (_cpp_lookup_with_hash): Require identifiers to be at the front of the identifier pool. Commit the memory if not already in the hash table. * cppinit.c (cpp_reader_init): Move cpp_init_completed test to top. Initialise various members of cpp_reader, memory pools, and the special nodes. (cpp_printer_init): Delete. (cpp_cleanup): Update. (struct builtin, builtin_array, initialize_builtins): Update for new hashnode definition and builtin handling. (cpp_start_read, cpp_finish): Don't take or initialise a printer. Update. * cpplib.h (cpp_printer, cpp_toklist, CPP_DEFINED, BOL, PASTED, VAR_ARGS, BEG_OF_FILE, IN_DIRECTIVE, KNOWN_DIRECTIVE, T_VOID, T_SPECLINE, T_DATE, T_FILE, T_BASE_FILE, T_INCLUDE_LEVEL, T_TIME, T_STDC, T_OPERATOR, T_POISON, T_MACRO, T_ASSERTION): Delete. (struct cpp_pool, struct cpp_macro, struct cpp_lexer_pos, struct cpp_lookahead, CPP_DHASH, enum mi_state, enum mi_ind, NO_EXPAND, VARARGS_FIRST, struct cpp_token_with_pos, struct toklist, struct cpp_context, struct specnodes, TOKEN_LOOKAHEAD, TOKEN_BUFFSIZE, NODE_OPERATOR, NODE_POISONED, NODE_BUILTIN, NODE_DIAGNOSTIC, NT_VOID, NT_MACRO, NT_ASSERTION, enum builtin_type, cpp_can_paste): New. (struct cpp_token): Delete line and col members. (struct cpp_buffer): New member output_lineno. (struct lexer_state): Delete indented, in_lex_line, seen_dot. Add va_args_ok, poisoned_ok, prevent_expansion, parsing_args. (struct cpp_reader): New members lexer_pos, macro_pos, directive_pos, ident_pool, temp_string_pool, macro_pool, argument_pool, string_pool, base_context, context, directive, mi_state, mi_if_not_defined, mi_lexed, mi_cmacro, mi_ind_cmacro, la_read, la_write, la_unused, mlstring_pos, macro_buffer, macro_buffer_len. Delete members mls_line, mls_column, token_list, potential_control_macro, temp_tokens, temp_cap, temp_alloced, temp_used, first_directive_token, context_cap, cur_context, no_expand_level, paste_level, contexts, args, save_parameter_spellings, need_newline, . Change type of date, time and spec_nodes members. Change prototypes for include and ident callbacks. (struct cpp_hashnode): Change type of name. Remove union members expansion and code. Add members macro, operator and builtin. (cpp_token_len, cpp_token_as_text, cpp_spell_token, cpp_start_read, cpp_finish, cpp_avoid_paste, cpp_get_token, cpp_get_line, cpp_get_output_line, cpp_macro_definition, cpp_start_lookahead, cpp_stop_lookahead): New prototypes. (cpp_printer_init, cpp_dump_definition): Delete prototypes. (U_CHAR, U, ustrcmp, ustrncmp, ustrlen, uxstrdup, ustrchr, ufputs): Move from cpphash.h. * cpphash.h (U_CHAR, U, ustrcmp, ustrncmp, ustrlen, uxstrdup, ustrchr, ufputs): Move to cpplib.h. (enum spell_type, struct token_spelling, _cpp_token_spellings, TOKEN_SPELL, TOKEN_NAME, struct answer, FREE_ANSWER, KANDR, STDC89, EXTENSION, COND, EXPAND, INCL, COMMENTS, IN_I, struct directive, directive_handler, struct spec_nodes, _cpp_digraph_spellings, _cpp_free_temp_tokens, _cpp_init_input_buffer, _cpp_grow_token_buffer, _cpp_init_toklist, _cpp_clear_toklist, _cpp_expand_token_space, _cpp_expand_name_space, _cpp_equiv_tokens, _cpp_equiv_toklists, _cpp_process_directive, _cpp_run_directive, _cpp_get_line, _cpp_get_raw_token, _cpp_glue_header_name, _cpp_can_paste, _cpp_check_directive, _cpp_check_linemarker, _cpp_parse_assertion, _cpp_find_answer): Delete. (VALID_SIGN, ALIGN, POOL_FRONT, POOL_LIMIT, POOL_BASE, POOL_SIZE, POOL_USED, POOL_COMMIT, struct cpp_chunk, _cpp_lex_token, _cpp_init_pool, _cpp_free_pool, _cpp_pool_reserve, _cpp_pool_alloc, _cpp_next_chunk, _cpp_lock_pool, _cpp_unlock_pool, _cpp_test_assertion, _cpp_handle_directive, DSC): New. (struct include_file): New member defined. (DO_NOT_REREAD, _cpp_begin_message, _cpp_execute_include, _cpp_compare_file_date): Update. (_cpp_pop_context, _cpp_get_token, _cpp_free_lookaheads, _cpp_push_token): New. (_cpp_init_macros, _cpp_cleanup_macros): Rename to _cpp_init_hashtable, _cpp_cleanup_hashtable. * Makefile.in: Remove cppoutput.c. * cppoutput.c: Delete * fixheader.c (read_scan_file): Update for new cpp_get_token prototype. (recognized_function): New argument LINE. * scan-decls.c (skip_to_closing_brace, scan_decls): Update for new cpp_get_token prototype. * scan.h (recognized_function): Update prototype. * po/POTFILES.in: Remove cppoutput.c. From-SVN: r37098
2000-10-28 19:59:06 +02:00
{
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
2001-09-25 00:53:12 +02:00
bool avoid_paste = false;
bool do_line_adjustments
= cpp_get_options (parse_in)->lang != CLK_ASM
&& !flag_no_line_commands;
bool in_pragma = false;
PR preprocessor/60723 - missing system-ness marks for macro tokens When a system macro is expanded in a non-system file during out-of-line preprocessing, it can happen that the preprocessor forgets to emit line markers to express the system-ness status of tokens that come after the expansion of the macro. That can lead to situations where the entire non-system file can be considered as being a system file and thus have its warnings be discarded during the compilation of the resulting preprocessed file. My understanding is that this is due to the preprocessor not systematically detecting (and reporting) the change in system-ness of tokens. And this is what this patch does. Each time the system-ness of a given token is different from the previous token that was emitted by the preprocessor, it emits a line marker for the sole purpose of marking the new system-ness of the subsequent tokens to come. Bootstrapped and tested on x86_64-unknown-linux-gnu against trunk. gcc/c-family/ChangeLog: * c-ppoutput.c (struct print::prev_was_system_token): New data member. (init_pp_output): Initialize it. (maybe_print_line_1, maybe_print_line, print_line_1, print_line) (do_line_change): Return a flag saying if a line marker was emitted or not. (scan_translation_unit): Detect if the system-ness of the token we are about to emit is different from the one of the previously emitted token. If so, emit a line marker. Avoid emitting useless adjacent line markers. Avoid emitting line markers for tokens originating from the expansion of built-in macros. (scan_translation_unit_directives_only): Adjust. gcc/testsuite/ChangeLog: * gcc.dg/cpp/syshdr{4,5}.{c,h}: New test files. Signed-off-by: Dodji Seketeli <dodji@redhat.com> Signed-off-by: Dodji Seketeli <dodji@redhat.com> From-SVN: r212638
2014-07-16 12:33:36 +02:00
bool line_marker_emitted = false;
cpperror.c (v_message): Split into _cpp_begin_message and v_message macro. * cpperror.c (v_message): Split into _cpp_begin_message and v_message macro. All callers updated. (_cpp_begin_message): Do inhibit_errors/inhibit_warnings checks here. * cppfiles.c (cpp_syshdr_flags): New function. (read_include_file): Don't call cpp_output_tokens. Call enter_file hook. * cppinit.c (dump_macros_helper): Moved to cppmain.c. (cpp_reader_init): Don't initialize token_buffer. Call _cpp_init_internal_pragmas. (cpp_cleanup): Don't clear token_buffer. (cpp_start_read): Don't worry about output from -D processing. Don't call cpp_output_tokens. (cpp_finish): Don't dump macros here. Don't call cpp_output_tokens. * cppmacro.c (_cpp_dump_definition): Rename cpp_dump_definition. Write directly to a FILE *. (dump_funlike_macro): Delete. (dump_macro_args): New. * cpplex.c (TOKEN_LEN): Convert to inline function. (_cpp_grow_token_buffer, safe_fwrite, cpp_output_tokens, cpp_scan_line, _cpp_dump_list): Delete. (cpp_printf, cpp_output_list): New. (output_line_command): Don't worry about entering or leaving files. (cpp_scan_buffer): Just output each token as we hit it. (process_directive): Don't call cpp_output_tokens. (_cpp_glue_header_name): Don't use token_buffer. (output_token, dump_param_spelling): Write directly to a FILE *. * cpplib.c (pass_thru_directive, dump_macro_name, pragma_dispatch, do_pragma_gcc): Delete. (do_define, do_undef, parse_include, do_line, do_ident, do_pragma, do_pragma_poison, cpp_pop_buffer): Call the appropriate hook functions. (do_error, do_warning, pragma_dependency): Call _cpp_begin_message, then cpp_output_list. (cpp_register_pragma, cpp_register_pragma_space, _cpp_init_internal_pragmas): New. (do_pragma): Walk the pragmas table here. (do_pragma_once, do_pragma_poison, do_pragma_system_header, do_pragma_dependency): Return void. (do_pragma_implementation): Moved to cppmain.c. * cpplib.h: Update prototypes. (struct cpp_reader): Remove printer, token_buffer, token_buffer_size, and limit. Add struct cb, and pragmas. (struct cpp_printer): Remove last_id and written. (CPP_WRITTEN, CPP_PWRITTEN, CPP_SET_WRITTEN, CPP_ADJUST_WRITTEN): Delete. * cpphash.h: Update prototypes. (ufputs): New wrapper. * cppmain.c (cb_define, cb_undef, cb_include, cb_ident, cb_enter_file, cb_leave_file, cb_def_pragma): New functions. (main): Set up callbacks. Register #pragma implementation. Dump macros from here. From-SVN: r35415
2000-08-02 03:13:45 +02:00
print.source = NULL;
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
2001-09-25 00:53:12 +02:00
for (;;)
New macro expander. 2000-10-28 Neil Booth <neilb@earthling.net> New macro expander. * cpplib.c (struct answer): New. (struct if_stack): Use cpp_lexer_pos rather than line and col. Rename cmacro mi_cmacro. (struct directive, KANDR, STDC89, EXTENSION, COND, IF_COND, INCL, IN_I): New directive and flags. (skip_rest_of_line, check_eol, run_directive, glue_header_name, parse_answer, parse_assertion, find_answer): New functions. (parse_ifdef, detect_if_not_defined, validate_else): Remove. (lex_macro_node): New function to replace parse_ifdef and get_define_node. (_cpp_handle_directive): New function, combines _cpp_check_directive and _cpp_check_linemarker. (do_define, do_undef, parse_include, do_include, do_import, do_include_next, read_line_number, do_line, do_ident, do_pragma, do_pragma_once, do_pragma_poison, do_pragma_dependency): Update for new token getting interface. (do_ifdef, do_ifndef, do_if, do_else, do_endif, push_conditional) : Update for new multiple-include optimisation technique. (do_elif): Don't forget to invalidate controlling macros. (unwind_if_stack, cpp_defined, cpp_push_buffer, cpp_pop_buffer): Update. (parse_assertion, parse_answer, find_answer, _cpp_test_assertion): Functions to handle assertions with the new token interface. (do_assert, do_unassert): Use them. (cpp_define, _cpp_define_builtin, cpp_undef, cpp_assert, cpp_unassert): Use run_directive. (_cpp_init_stacks): Register directive names. Don't register special nodes. * cpperror.c (print_containing_files, _cpp_begin_message): Update to new position recording regime. (cpp_ice, cpp_fatal, cpp_error, cpp_error_with_line, cpp_warning, cpp_warning_with_line, cpp_pedwarn, cpp_pedwarn_with_line, cpp_pedwarn_with_file_and_line): Update for _cpp_begin_message changes. (cpp_type2name): Move to cpplex.c. * cppexp.c (parse_charconst): spec_nodes is no longer a pointer. (parse_defined): Update to handle new multiple include optimisation method. Remove poisoned identifier warning. (parse_assertion, TYPE_NAME): Delete. (lex): Update for multiple include optimisation, removal of CPP_DEFINED, to use _cpp_test_assertion for assertions and cpp_token_as_text. (_cpp_parse_expr): Update for MI optimisation, and to use op_as_text. (op_as_text): New function, to wrap cpp_token_as_text. * cppfiles.c (stack_include_file, _cpp_pop_file_buffer): Update for MI optimisation. (_cpp_execute_include): Take a token rather than 3 arguments. Fix segfault on diagnostic. (_cpp_compare_file_date): Take a token rather than 3 args. (cpp_read_file): Work correctly for zero-length files. * cpphash.c (_cpp_init_macros, _cpp_cleanup_macros): Rename _cpp_init_hashtable and _cpp_cleanup_hashtable. (cpp_lookup): Place identifiers at front of identifier pool for _cpp_lookup_with_hash. (_cpp_lookup_with_hash): Require identifiers to be at the front of the identifier pool. Commit the memory if not already in the hash table. * cppinit.c (cpp_reader_init): Move cpp_init_completed test to top. Initialise various members of cpp_reader, memory pools, and the special nodes. (cpp_printer_init): Delete. (cpp_cleanup): Update. (struct builtin, builtin_array, initialize_builtins): Update for new hashnode definition and builtin handling. (cpp_start_read, cpp_finish): Don't take or initialise a printer. Update. * cpplib.h (cpp_printer, cpp_toklist, CPP_DEFINED, BOL, PASTED, VAR_ARGS, BEG_OF_FILE, IN_DIRECTIVE, KNOWN_DIRECTIVE, T_VOID, T_SPECLINE, T_DATE, T_FILE, T_BASE_FILE, T_INCLUDE_LEVEL, T_TIME, T_STDC, T_OPERATOR, T_POISON, T_MACRO, T_ASSERTION): Delete. (struct cpp_pool, struct cpp_macro, struct cpp_lexer_pos, struct cpp_lookahead, CPP_DHASH, enum mi_state, enum mi_ind, NO_EXPAND, VARARGS_FIRST, struct cpp_token_with_pos, struct toklist, struct cpp_context, struct specnodes, TOKEN_LOOKAHEAD, TOKEN_BUFFSIZE, NODE_OPERATOR, NODE_POISONED, NODE_BUILTIN, NODE_DIAGNOSTIC, NT_VOID, NT_MACRO, NT_ASSERTION, enum builtin_type, cpp_can_paste): New. (struct cpp_token): Delete line and col members. (struct cpp_buffer): New member output_lineno. (struct lexer_state): Delete indented, in_lex_line, seen_dot. Add va_args_ok, poisoned_ok, prevent_expansion, parsing_args. (struct cpp_reader): New members lexer_pos, macro_pos, directive_pos, ident_pool, temp_string_pool, macro_pool, argument_pool, string_pool, base_context, context, directive, mi_state, mi_if_not_defined, mi_lexed, mi_cmacro, mi_ind_cmacro, la_read, la_write, la_unused, mlstring_pos, macro_buffer, macro_buffer_len. Delete members mls_line, mls_column, token_list, potential_control_macro, temp_tokens, temp_cap, temp_alloced, temp_used, first_directive_token, context_cap, cur_context, no_expand_level, paste_level, contexts, args, save_parameter_spellings, need_newline, . Change type of date, time and spec_nodes members. Change prototypes for include and ident callbacks. (struct cpp_hashnode): Change type of name. Remove union members expansion and code. Add members macro, operator and builtin. (cpp_token_len, cpp_token_as_text, cpp_spell_token, cpp_start_read, cpp_finish, cpp_avoid_paste, cpp_get_token, cpp_get_line, cpp_get_output_line, cpp_macro_definition, cpp_start_lookahead, cpp_stop_lookahead): New prototypes. (cpp_printer_init, cpp_dump_definition): Delete prototypes. (U_CHAR, U, ustrcmp, ustrncmp, ustrlen, uxstrdup, ustrchr, ufputs): Move from cpphash.h. * cpphash.h (U_CHAR, U, ustrcmp, ustrncmp, ustrlen, uxstrdup, ustrchr, ufputs): Move to cpplib.h. (enum spell_type, struct token_spelling, _cpp_token_spellings, TOKEN_SPELL, TOKEN_NAME, struct answer, FREE_ANSWER, KANDR, STDC89, EXTENSION, COND, EXPAND, INCL, COMMENTS, IN_I, struct directive, directive_handler, struct spec_nodes, _cpp_digraph_spellings, _cpp_free_temp_tokens, _cpp_init_input_buffer, _cpp_grow_token_buffer, _cpp_init_toklist, _cpp_clear_toklist, _cpp_expand_token_space, _cpp_expand_name_space, _cpp_equiv_tokens, _cpp_equiv_toklists, _cpp_process_directive, _cpp_run_directive, _cpp_get_line, _cpp_get_raw_token, _cpp_glue_header_name, _cpp_can_paste, _cpp_check_directive, _cpp_check_linemarker, _cpp_parse_assertion, _cpp_find_answer): Delete. (VALID_SIGN, ALIGN, POOL_FRONT, POOL_LIMIT, POOL_BASE, POOL_SIZE, POOL_USED, POOL_COMMIT, struct cpp_chunk, _cpp_lex_token, _cpp_init_pool, _cpp_free_pool, _cpp_pool_reserve, _cpp_pool_alloc, _cpp_next_chunk, _cpp_lock_pool, _cpp_unlock_pool, _cpp_test_assertion, _cpp_handle_directive, DSC): New. (struct include_file): New member defined. (DO_NOT_REREAD, _cpp_begin_message, _cpp_execute_include, _cpp_compare_file_date): Update. (_cpp_pop_context, _cpp_get_token, _cpp_free_lookaheads, _cpp_push_token): New. (_cpp_init_macros, _cpp_cleanup_macros): Rename to _cpp_init_hashtable, _cpp_cleanup_hashtable. * Makefile.in: Remove cppoutput.c. * cppoutput.c: Delete * fixheader.c (read_scan_file): Update for new cpp_get_token prototype. (recognized_function): New argument LINE. * scan-decls.c (skip_to_closing_brace, scan_decls): Update for new cpp_get_token prototype. * scan.h (recognized_function): Update prototype. * po/POTFILES.in: Remove cppoutput.c. From-SVN: r37098
2000-10-28 19:59:06 +02:00
{
source_location loc;
const cpp_token *token = cpp_get_token_with_location (pfile, &loc);
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
2001-09-25 00:53:12 +02:00
if (token->type == CPP_PADDING)
{
avoid_paste = true;
if (print.source == NULL
|| (!(print.source->flags & PREV_WHITE)
&& token->val.source == NULL))
print.source = token->val.source;
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
2001-09-25 00:53:12 +02:00
continue;
}
New macro expander. 2000-10-28 Neil Booth <neilb@earthling.net> New macro expander. * cpplib.c (struct answer): New. (struct if_stack): Use cpp_lexer_pos rather than line and col. Rename cmacro mi_cmacro. (struct directive, KANDR, STDC89, EXTENSION, COND, IF_COND, INCL, IN_I): New directive and flags. (skip_rest_of_line, check_eol, run_directive, glue_header_name, parse_answer, parse_assertion, find_answer): New functions. (parse_ifdef, detect_if_not_defined, validate_else): Remove. (lex_macro_node): New function to replace parse_ifdef and get_define_node. (_cpp_handle_directive): New function, combines _cpp_check_directive and _cpp_check_linemarker. (do_define, do_undef, parse_include, do_include, do_import, do_include_next, read_line_number, do_line, do_ident, do_pragma, do_pragma_once, do_pragma_poison, do_pragma_dependency): Update for new token getting interface. (do_ifdef, do_ifndef, do_if, do_else, do_endif, push_conditional) : Update for new multiple-include optimisation technique. (do_elif): Don't forget to invalidate controlling macros. (unwind_if_stack, cpp_defined, cpp_push_buffer, cpp_pop_buffer): Update. (parse_assertion, parse_answer, find_answer, _cpp_test_assertion): Functions to handle assertions with the new token interface. (do_assert, do_unassert): Use them. (cpp_define, _cpp_define_builtin, cpp_undef, cpp_assert, cpp_unassert): Use run_directive. (_cpp_init_stacks): Register directive names. Don't register special nodes. * cpperror.c (print_containing_files, _cpp_begin_message): Update to new position recording regime. (cpp_ice, cpp_fatal, cpp_error, cpp_error_with_line, cpp_warning, cpp_warning_with_line, cpp_pedwarn, cpp_pedwarn_with_line, cpp_pedwarn_with_file_and_line): Update for _cpp_begin_message changes. (cpp_type2name): Move to cpplex.c. * cppexp.c (parse_charconst): spec_nodes is no longer a pointer. (parse_defined): Update to handle new multiple include optimisation method. Remove poisoned identifier warning. (parse_assertion, TYPE_NAME): Delete. (lex): Update for multiple include optimisation, removal of CPP_DEFINED, to use _cpp_test_assertion for assertions and cpp_token_as_text. (_cpp_parse_expr): Update for MI optimisation, and to use op_as_text. (op_as_text): New function, to wrap cpp_token_as_text. * cppfiles.c (stack_include_file, _cpp_pop_file_buffer): Update for MI optimisation. (_cpp_execute_include): Take a token rather than 3 arguments. Fix segfault on diagnostic. (_cpp_compare_file_date): Take a token rather than 3 args. (cpp_read_file): Work correctly for zero-length files. * cpphash.c (_cpp_init_macros, _cpp_cleanup_macros): Rename _cpp_init_hashtable and _cpp_cleanup_hashtable. (cpp_lookup): Place identifiers at front of identifier pool for _cpp_lookup_with_hash. (_cpp_lookup_with_hash): Require identifiers to be at the front of the identifier pool. Commit the memory if not already in the hash table. * cppinit.c (cpp_reader_init): Move cpp_init_completed test to top. Initialise various members of cpp_reader, memory pools, and the special nodes. (cpp_printer_init): Delete. (cpp_cleanup): Update. (struct builtin, builtin_array, initialize_builtins): Update for new hashnode definition and builtin handling. (cpp_start_read, cpp_finish): Don't take or initialise a printer. Update. * cpplib.h (cpp_printer, cpp_toklist, CPP_DEFINED, BOL, PASTED, VAR_ARGS, BEG_OF_FILE, IN_DIRECTIVE, KNOWN_DIRECTIVE, T_VOID, T_SPECLINE, T_DATE, T_FILE, T_BASE_FILE, T_INCLUDE_LEVEL, T_TIME, T_STDC, T_OPERATOR, T_POISON, T_MACRO, T_ASSERTION): Delete. (struct cpp_pool, struct cpp_macro, struct cpp_lexer_pos, struct cpp_lookahead, CPP_DHASH, enum mi_state, enum mi_ind, NO_EXPAND, VARARGS_FIRST, struct cpp_token_with_pos, struct toklist, struct cpp_context, struct specnodes, TOKEN_LOOKAHEAD, TOKEN_BUFFSIZE, NODE_OPERATOR, NODE_POISONED, NODE_BUILTIN, NODE_DIAGNOSTIC, NT_VOID, NT_MACRO, NT_ASSERTION, enum builtin_type, cpp_can_paste): New. (struct cpp_token): Delete line and col members. (struct cpp_buffer): New member output_lineno. (struct lexer_state): Delete indented, in_lex_line, seen_dot. Add va_args_ok, poisoned_ok, prevent_expansion, parsing_args. (struct cpp_reader): New members lexer_pos, macro_pos, directive_pos, ident_pool, temp_string_pool, macro_pool, argument_pool, string_pool, base_context, context, directive, mi_state, mi_if_not_defined, mi_lexed, mi_cmacro, mi_ind_cmacro, la_read, la_write, la_unused, mlstring_pos, macro_buffer, macro_buffer_len. Delete members mls_line, mls_column, token_list, potential_control_macro, temp_tokens, temp_cap, temp_alloced, temp_used, first_directive_token, context_cap, cur_context, no_expand_level, paste_level, contexts, args, save_parameter_spellings, need_newline, . Change type of date, time and spec_nodes members. Change prototypes for include and ident callbacks. (struct cpp_hashnode): Change type of name. Remove union members expansion and code. Add members macro, operator and builtin. (cpp_token_len, cpp_token_as_text, cpp_spell_token, cpp_start_read, cpp_finish, cpp_avoid_paste, cpp_get_token, cpp_get_line, cpp_get_output_line, cpp_macro_definition, cpp_start_lookahead, cpp_stop_lookahead): New prototypes. (cpp_printer_init, cpp_dump_definition): Delete prototypes. (U_CHAR, U, ustrcmp, ustrncmp, ustrlen, uxstrdup, ustrchr, ufputs): Move from cpphash.h. * cpphash.h (U_CHAR, U, ustrcmp, ustrncmp, ustrlen, uxstrdup, ustrchr, ufputs): Move to cpplib.h. (enum spell_type, struct token_spelling, _cpp_token_spellings, TOKEN_SPELL, TOKEN_NAME, struct answer, FREE_ANSWER, KANDR, STDC89, EXTENSION, COND, EXPAND, INCL, COMMENTS, IN_I, struct directive, directive_handler, struct spec_nodes, _cpp_digraph_spellings, _cpp_free_temp_tokens, _cpp_init_input_buffer, _cpp_grow_token_buffer, _cpp_init_toklist, _cpp_clear_toklist, _cpp_expand_token_space, _cpp_expand_name_space, _cpp_equiv_tokens, _cpp_equiv_toklists, _cpp_process_directive, _cpp_run_directive, _cpp_get_line, _cpp_get_raw_token, _cpp_glue_header_name, _cpp_can_paste, _cpp_check_directive, _cpp_check_linemarker, _cpp_parse_assertion, _cpp_find_answer): Delete. (VALID_SIGN, ALIGN, POOL_FRONT, POOL_LIMIT, POOL_BASE, POOL_SIZE, POOL_USED, POOL_COMMIT, struct cpp_chunk, _cpp_lex_token, _cpp_init_pool, _cpp_free_pool, _cpp_pool_reserve, _cpp_pool_alloc, _cpp_next_chunk, _cpp_lock_pool, _cpp_unlock_pool, _cpp_test_assertion, _cpp_handle_directive, DSC): New. (struct include_file): New member defined. (DO_NOT_REREAD, _cpp_begin_message, _cpp_execute_include, _cpp_compare_file_date): Update. (_cpp_pop_context, _cpp_get_token, _cpp_free_lookaheads, _cpp_push_token): New. (_cpp_init_macros, _cpp_cleanup_macros): Rename to _cpp_init_hashtable, _cpp_cleanup_hashtable. * Makefile.in: Remove cppoutput.c. * cppoutput.c: Delete * fixheader.c (read_scan_file): Update for new cpp_get_token prototype. (recognized_function): New argument LINE. * scan-decls.c (skip_to_closing_brace, scan_decls): Update for new cpp_get_token prototype. * scan.h (recognized_function): Update prototype. * po/POTFILES.in: Remove cppoutput.c. From-SVN: r37098
2000-10-28 19:59:06 +02:00
if (token->type == CPP_EOF)
break;
New macro expander. 2000-10-28 Neil Booth <neilb@earthling.net> New macro expander. * cpplib.c (struct answer): New. (struct if_stack): Use cpp_lexer_pos rather than line and col. Rename cmacro mi_cmacro. (struct directive, KANDR, STDC89, EXTENSION, COND, IF_COND, INCL, IN_I): New directive and flags. (skip_rest_of_line, check_eol, run_directive, glue_header_name, parse_answer, parse_assertion, find_answer): New functions. (parse_ifdef, detect_if_not_defined, validate_else): Remove. (lex_macro_node): New function to replace parse_ifdef and get_define_node. (_cpp_handle_directive): New function, combines _cpp_check_directive and _cpp_check_linemarker. (do_define, do_undef, parse_include, do_include, do_import, do_include_next, read_line_number, do_line, do_ident, do_pragma, do_pragma_once, do_pragma_poison, do_pragma_dependency): Update for new token getting interface. (do_ifdef, do_ifndef, do_if, do_else, do_endif, push_conditional) : Update for new multiple-include optimisation technique. (do_elif): Don't forget to invalidate controlling macros. (unwind_if_stack, cpp_defined, cpp_push_buffer, cpp_pop_buffer): Update. (parse_assertion, parse_answer, find_answer, _cpp_test_assertion): Functions to handle assertions with the new token interface. (do_assert, do_unassert): Use them. (cpp_define, _cpp_define_builtin, cpp_undef, cpp_assert, cpp_unassert): Use run_directive. (_cpp_init_stacks): Register directive names. Don't register special nodes. * cpperror.c (print_containing_files, _cpp_begin_message): Update to new position recording regime. (cpp_ice, cpp_fatal, cpp_error, cpp_error_with_line, cpp_warning, cpp_warning_with_line, cpp_pedwarn, cpp_pedwarn_with_line, cpp_pedwarn_with_file_and_line): Update for _cpp_begin_message changes. (cpp_type2name): Move to cpplex.c. * cppexp.c (parse_charconst): spec_nodes is no longer a pointer. (parse_defined): Update to handle new multiple include optimisation method. Remove poisoned identifier warning. (parse_assertion, TYPE_NAME): Delete. (lex): Update for multiple include optimisation, removal of CPP_DEFINED, to use _cpp_test_assertion for assertions and cpp_token_as_text. (_cpp_parse_expr): Update for MI optimisation, and to use op_as_text. (op_as_text): New function, to wrap cpp_token_as_text. * cppfiles.c (stack_include_file, _cpp_pop_file_buffer): Update for MI optimisation. (_cpp_execute_include): Take a token rather than 3 arguments. Fix segfault on diagnostic. (_cpp_compare_file_date): Take a token rather than 3 args. (cpp_read_file): Work correctly for zero-length files. * cpphash.c (_cpp_init_macros, _cpp_cleanup_macros): Rename _cpp_init_hashtable and _cpp_cleanup_hashtable. (cpp_lookup): Place identifiers at front of identifier pool for _cpp_lookup_with_hash. (_cpp_lookup_with_hash): Require identifiers to be at the front of the identifier pool. Commit the memory if not already in the hash table. * cppinit.c (cpp_reader_init): Move cpp_init_completed test to top. Initialise various members of cpp_reader, memory pools, and the special nodes. (cpp_printer_init): Delete. (cpp_cleanup): Update. (struct builtin, builtin_array, initialize_builtins): Update for new hashnode definition and builtin handling. (cpp_start_read, cpp_finish): Don't take or initialise a printer. Update. * cpplib.h (cpp_printer, cpp_toklist, CPP_DEFINED, BOL, PASTED, VAR_ARGS, BEG_OF_FILE, IN_DIRECTIVE, KNOWN_DIRECTIVE, T_VOID, T_SPECLINE, T_DATE, T_FILE, T_BASE_FILE, T_INCLUDE_LEVEL, T_TIME, T_STDC, T_OPERATOR, T_POISON, T_MACRO, T_ASSERTION): Delete. (struct cpp_pool, struct cpp_macro, struct cpp_lexer_pos, struct cpp_lookahead, CPP_DHASH, enum mi_state, enum mi_ind, NO_EXPAND, VARARGS_FIRST, struct cpp_token_with_pos, struct toklist, struct cpp_context, struct specnodes, TOKEN_LOOKAHEAD, TOKEN_BUFFSIZE, NODE_OPERATOR, NODE_POISONED, NODE_BUILTIN, NODE_DIAGNOSTIC, NT_VOID, NT_MACRO, NT_ASSERTION, enum builtin_type, cpp_can_paste): New. (struct cpp_token): Delete line and col members. (struct cpp_buffer): New member output_lineno. (struct lexer_state): Delete indented, in_lex_line, seen_dot. Add va_args_ok, poisoned_ok, prevent_expansion, parsing_args. (struct cpp_reader): New members lexer_pos, macro_pos, directive_pos, ident_pool, temp_string_pool, macro_pool, argument_pool, string_pool, base_context, context, directive, mi_state, mi_if_not_defined, mi_lexed, mi_cmacro, mi_ind_cmacro, la_read, la_write, la_unused, mlstring_pos, macro_buffer, macro_buffer_len. Delete members mls_line, mls_column, token_list, potential_control_macro, temp_tokens, temp_cap, temp_alloced, temp_used, first_directive_token, context_cap, cur_context, no_expand_level, paste_level, contexts, args, save_parameter_spellings, need_newline, . Change type of date, time and spec_nodes members. Change prototypes for include and ident callbacks. (struct cpp_hashnode): Change type of name. Remove union members expansion and code. Add members macro, operator and builtin. (cpp_token_len, cpp_token_as_text, cpp_spell_token, cpp_start_read, cpp_finish, cpp_avoid_paste, cpp_get_token, cpp_get_line, cpp_get_output_line, cpp_macro_definition, cpp_start_lookahead, cpp_stop_lookahead): New prototypes. (cpp_printer_init, cpp_dump_definition): Delete prototypes. (U_CHAR, U, ustrcmp, ustrncmp, ustrlen, uxstrdup, ustrchr, ufputs): Move from cpphash.h. * cpphash.h (U_CHAR, U, ustrcmp, ustrncmp, ustrlen, uxstrdup, ustrchr, ufputs): Move to cpplib.h. (enum spell_type, struct token_spelling, _cpp_token_spellings, TOKEN_SPELL, TOKEN_NAME, struct answer, FREE_ANSWER, KANDR, STDC89, EXTENSION, COND, EXPAND, INCL, COMMENTS, IN_I, struct directive, directive_handler, struct spec_nodes, _cpp_digraph_spellings, _cpp_free_temp_tokens, _cpp_init_input_buffer, _cpp_grow_token_buffer, _cpp_init_toklist, _cpp_clear_toklist, _cpp_expand_token_space, _cpp_expand_name_space, _cpp_equiv_tokens, _cpp_equiv_toklists, _cpp_process_directive, _cpp_run_directive, _cpp_get_line, _cpp_get_raw_token, _cpp_glue_header_name, _cpp_can_paste, _cpp_check_directive, _cpp_check_linemarker, _cpp_parse_assertion, _cpp_find_answer): Delete. (VALID_SIGN, ALIGN, POOL_FRONT, POOL_LIMIT, POOL_BASE, POOL_SIZE, POOL_USED, POOL_COMMIT, struct cpp_chunk, _cpp_lex_token, _cpp_init_pool, _cpp_free_pool, _cpp_pool_reserve, _cpp_pool_alloc, _cpp_next_chunk, _cpp_lock_pool, _cpp_unlock_pool, _cpp_test_assertion, _cpp_handle_directive, DSC): New. (struct include_file): New member defined. (DO_NOT_REREAD, _cpp_begin_message, _cpp_execute_include, _cpp_compare_file_date): Update. (_cpp_pop_context, _cpp_get_token, _cpp_free_lookaheads, _cpp_push_token): New. (_cpp_init_macros, _cpp_cleanup_macros): Rename to _cpp_init_hashtable, _cpp_cleanup_hashtable. * Makefile.in: Remove cppoutput.c. * cppoutput.c: Delete * fixheader.c (read_scan_file): Update for new cpp_get_token prototype. (recognized_function): New argument LINE. * scan-decls.c (skip_to_closing_brace, scan_decls): Update for new cpp_get_token prototype. * scan.h (recognized_function): Update prototype. * po/POTFILES.in: Remove cppoutput.c. From-SVN: r37098
2000-10-28 19:59:06 +02:00
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
2001-09-25 00:53:12 +02:00
/* Subtle logic to output a space if and only if necessary. */
if (avoid_paste)
{
Linemap infrastructure for virtual locations This is the first instalment of a set which goal is to track locations of tokens across macro expansions. Tom Tromey did the original work and attached the patch to PR preprocessor/7263. This opus is a derivative of that original work. This patch modifies the linemap module of libcpp to add virtual locations support. A virtual location is a mapped location that can resolve to several different physical locations. It can always resolve to the spelling location of a token. For tokens resulting from macro expansion it can resolve to: - either the location of the expansion point of the macro. - or the location of the token in the definition of the macro - or, if the token is an argument of a function-like macro, the location of the use of the matching macro parameter in the definition of the macro The patch creates a new type of line map called a macro map. For every single macro expansion, there is a macro map that generates a virtual location for every single resulting token of the expansion. The good old type of line map we all know is now called an ordinary map. That one still encodes spelling locations as it has always had. As a result linemap_lookup as been extended to return a macro map when given a virtual location resulting from a macro expansion. The layout of structs line_map has changed to support this new type of map. So did the layout of struct line_maps. Accessor macros have been introduced to avoid messing with the implementation details of these datastructures directly. This helped already as we have been testing different ways of arranging these datastructure. Having to constantly adjust client code that is too tied with the internals of line_map and line_maps would have been even more painful. Of course, many new public functions have been added to the linemap module to handle the resolution of virtual locations. This patch introduces the infrastructure but no part of the compiler uses virtual locations yet. However the client code of the linemap data structures has been adjusted as per the changes. E.g, it's not anymore reliable for a client code to manipulate struct line_map directly if it just wants to deal with spelling locations, because struct line_map can now represent a macro map as well. In that case, it's better to use the convenient API to resolve the initial (possibly virtual) location to a spelling location (or to an ordinary map) and use that. This is the reason why the patch adjusts the Java, Ada and Fortran front ends. Also, note that virtual locations are not supposed to be ordered for relations '<' and '>' anymore. To test if a virtual location appears "before" another one, one has to use a new operator exposed by the line map interface. The patch updates the only spot (in the diagnostics module) I have found that was making the assumption that locations were ordered for these relations. This is the only change that introduces a use of the new line map API in this patch, so I am adding a regression test for it only. From-SVN: r180081
2011-10-17 11:58:56 +02:00
int src_line = LOCATION_LINE (loc);
if (print.source == NULL)
print.source = token;
if (src_line != print.src_line
&& do_line_adjustments
&& !in_pragma)
{
PR preprocessor/60723 - missing system-ness marks for macro tokens When a system macro is expanded in a non-system file during out-of-line preprocessing, it can happen that the preprocessor forgets to emit line markers to express the system-ness status of tokens that come after the expansion of the macro. That can lead to situations where the entire non-system file can be considered as being a system file and thus have its warnings be discarded during the compilation of the resulting preprocessed file. My understanding is that this is due to the preprocessor not systematically detecting (and reporting) the change in system-ness of tokens. And this is what this patch does. Each time the system-ness of a given token is different from the previous token that was emitted by the preprocessor, it emits a line marker for the sole purpose of marking the new system-ness of the subsequent tokens to come. Bootstrapped and tested on x86_64-unknown-linux-gnu against trunk. gcc/c-family/ChangeLog: * c-ppoutput.c (struct print::prev_was_system_token): New data member. (init_pp_output): Initialize it. (maybe_print_line_1, maybe_print_line, print_line_1, print_line) (do_line_change): Return a flag saying if a line marker was emitted or not. (scan_translation_unit): Detect if the system-ness of the token we are about to emit is different from the one of the previously emitted token. If so, emit a line marker. Avoid emitting useless adjacent line markers. Avoid emitting line markers for tokens originating from the expansion of built-in macros. (scan_translation_unit_directives_only): Adjust. gcc/testsuite/ChangeLog: * gcc.dg/cpp/syshdr{4,5}.{c,h}: New test files. Signed-off-by: Dodji Seketeli <dodji@redhat.com> Signed-off-by: Dodji Seketeli <dodji@redhat.com> From-SVN: r212638
2014-07-16 12:33:36 +02:00
line_marker_emitted = do_line_change (pfile, token, loc, false);
putc (' ', print.outf);
print.printed = true;
}
else if (print.source->flags & PREV_WHITE
|| (print.prev
&& cpp_avoid_paste (pfile, print.prev, token))
|| (print.prev == NULL && token->type == CPP_HASH))
{
putc (' ', print.outf);
print.printed = true;
}
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
2001-09-25 00:53:12 +02:00
}
else if (token->flags & PREV_WHITE)
{
Linemap infrastructure for virtual locations This is the first instalment of a set which goal is to track locations of tokens across macro expansions. Tom Tromey did the original work and attached the patch to PR preprocessor/7263. This opus is a derivative of that original work. This patch modifies the linemap module of libcpp to add virtual locations support. A virtual location is a mapped location that can resolve to several different physical locations. It can always resolve to the spelling location of a token. For tokens resulting from macro expansion it can resolve to: - either the location of the expansion point of the macro. - or the location of the token in the definition of the macro - or, if the token is an argument of a function-like macro, the location of the use of the matching macro parameter in the definition of the macro The patch creates a new type of line map called a macro map. For every single macro expansion, there is a macro map that generates a virtual location for every single resulting token of the expansion. The good old type of line map we all know is now called an ordinary map. That one still encodes spelling locations as it has always had. As a result linemap_lookup as been extended to return a macro map when given a virtual location resulting from a macro expansion. The layout of structs line_map has changed to support this new type of map. So did the layout of struct line_maps. Accessor macros have been introduced to avoid messing with the implementation details of these datastructures directly. This helped already as we have been testing different ways of arranging these datastructure. Having to constantly adjust client code that is too tied with the internals of line_map and line_maps would have been even more painful. Of course, many new public functions have been added to the linemap module to handle the resolution of virtual locations. This patch introduces the infrastructure but no part of the compiler uses virtual locations yet. However the client code of the linemap data structures has been adjusted as per the changes. E.g, it's not anymore reliable for a client code to manipulate struct line_map directly if it just wants to deal with spelling locations, because struct line_map can now represent a macro map as well. In that case, it's better to use the convenient API to resolve the initial (possibly virtual) location to a spelling location (or to an ordinary map) and use that. This is the reason why the patch adjusts the Java, Ada and Fortran front ends. Also, note that virtual locations are not supposed to be ordered for relations '<' and '>' anymore. To test if a virtual location appears "before" another one, one has to use a new operator exposed by the line map interface. The patch updates the only spot (in the diagnostics module) I have found that was making the assumption that locations were ordered for these relations. This is the only change that introduces a use of the new line map API in this patch, so I am adding a regression test for it only. From-SVN: r180081
2011-10-17 11:58:56 +02:00
int src_line = LOCATION_LINE (loc);
if (src_line != print.src_line
&& do_line_adjustments
&& !in_pragma)
PR preprocessor/60723 - missing system-ness marks for macro tokens When a system macro is expanded in a non-system file during out-of-line preprocessing, it can happen that the preprocessor forgets to emit line markers to express the system-ness status of tokens that come after the expansion of the macro. That can lead to situations where the entire non-system file can be considered as being a system file and thus have its warnings be discarded during the compilation of the resulting preprocessed file. My understanding is that this is due to the preprocessor not systematically detecting (and reporting) the change in system-ness of tokens. And this is what this patch does. Each time the system-ness of a given token is different from the previous token that was emitted by the preprocessor, it emits a line marker for the sole purpose of marking the new system-ness of the subsequent tokens to come. Bootstrapped and tested on x86_64-unknown-linux-gnu against trunk. gcc/c-family/ChangeLog: * c-ppoutput.c (struct print::prev_was_system_token): New data member. (init_pp_output): Initialize it. (maybe_print_line_1, maybe_print_line, print_line_1, print_line) (do_line_change): Return a flag saying if a line marker was emitted or not. (scan_translation_unit): Detect if the system-ness of the token we are about to emit is different from the one of the previously emitted token. If so, emit a line marker. Avoid emitting useless adjacent line markers. Avoid emitting line markers for tokens originating from the expansion of built-in macros. (scan_translation_unit_directives_only): Adjust. gcc/testsuite/ChangeLog: * gcc.dg/cpp/syshdr{4,5}.{c,h}: New test files. Signed-off-by: Dodji Seketeli <dodji@redhat.com> Signed-off-by: Dodji Seketeli <dodji@redhat.com> From-SVN: r212638
2014-07-16 12:33:36 +02:00
line_marker_emitted = do_line_change (pfile, token, loc, false);
putc (' ', print.outf);
print.printed = true;
}
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
2001-09-25 00:53:12 +02:00
avoid_paste = false;
print.source = NULL;
print.prev = token;
if (token->type == CPP_PRAGMA)
{
const char *space;
const char *name;
PR preprocessor/60723 - missing system-ness marks for macro tokens When a system macro is expanded in a non-system file during out-of-line preprocessing, it can happen that the preprocessor forgets to emit line markers to express the system-ness status of tokens that come after the expansion of the macro. That can lead to situations where the entire non-system file can be considered as being a system file and thus have its warnings be discarded during the compilation of the resulting preprocessed file. My understanding is that this is due to the preprocessor not systematically detecting (and reporting) the change in system-ness of tokens. And this is what this patch does. Each time the system-ness of a given token is different from the previous token that was emitted by the preprocessor, it emits a line marker for the sole purpose of marking the new system-ness of the subsequent tokens to come. Bootstrapped and tested on x86_64-unknown-linux-gnu against trunk. gcc/c-family/ChangeLog: * c-ppoutput.c (struct print::prev_was_system_token): New data member. (init_pp_output): Initialize it. (maybe_print_line_1, maybe_print_line, print_line_1, print_line) (do_line_change): Return a flag saying if a line marker was emitted or not. (scan_translation_unit): Detect if the system-ness of the token we are about to emit is different from the one of the previously emitted token. If so, emit a line marker. Avoid emitting useless adjacent line markers. Avoid emitting line markers for tokens originating from the expansion of built-in macros. (scan_translation_unit_directives_only): Adjust. gcc/testsuite/ChangeLog: * gcc.dg/cpp/syshdr{4,5}.{c,h}: New test files. Signed-off-by: Dodji Seketeli <dodji@redhat.com> Signed-off-by: Dodji Seketeli <dodji@redhat.com> From-SVN: r212638
2014-07-16 12:33:36 +02:00
line_marker_emitted = maybe_print_line (token->src_loc);
fputs ("#pragma ", print.outf);
c_pp_lookup_pragma (token->val.pragma, &space, &name);
if (space)
fprintf (print.outf, "%s %s", space, name);
else
fprintf (print.outf, "%s", name);
print.printed = true;
in_pragma = true;
}
else if (token->type == CPP_PRAGMA_EOL)
{
maybe_print_line (token->src_loc);
in_pragma = false;
}
else
{
if (cpp_get_options (parse_in)->debug)
linemap_dump_location (line_table, token->src_loc, print.outf);
PR preprocessor/60723 - missing system-ness marks for macro tokens When a system macro is expanded in a non-system file during out-of-line preprocessing, it can happen that the preprocessor forgets to emit line markers to express the system-ness status of tokens that come after the expansion of the macro. That can lead to situations where the entire non-system file can be considered as being a system file and thus have its warnings be discarded during the compilation of the resulting preprocessed file. My understanding is that this is due to the preprocessor not systematically detecting (and reporting) the change in system-ness of tokens. And this is what this patch does. Each time the system-ness of a given token is different from the previous token that was emitted by the preprocessor, it emits a line marker for the sole purpose of marking the new system-ness of the subsequent tokens to come. Bootstrapped and tested on x86_64-unknown-linux-gnu against trunk. gcc/c-family/ChangeLog: * c-ppoutput.c (struct print::prev_was_system_token): New data member. (init_pp_output): Initialize it. (maybe_print_line_1, maybe_print_line, print_line_1, print_line) (do_line_change): Return a flag saying if a line marker was emitted or not. (scan_translation_unit): Detect if the system-ness of the token we are about to emit is different from the one of the previously emitted token. If so, emit a line marker. Avoid emitting useless adjacent line markers. Avoid emitting line markers for tokens originating from the expansion of built-in macros. (scan_translation_unit_directives_only): Adjust. gcc/testsuite/ChangeLog: * gcc.dg/cpp/syshdr{4,5}.{c,h}: New test files. Signed-off-by: Dodji Seketeli <dodji@redhat.com> Signed-off-by: Dodji Seketeli <dodji@redhat.com> From-SVN: r212638
2014-07-16 12:33:36 +02:00
if (do_line_adjustments
&& !in_pragma
&& !line_marker_emitted
&& print.prev_was_system_token != !!in_system_header_at (loc)
PR preprocessor/60723 - missing system-ness marks for macro tokens When a system macro is expanded in a non-system file during out-of-line preprocessing, it can happen that the preprocessor forgets to emit line markers to express the system-ness status of tokens that come after the expansion of the macro. That can lead to situations where the entire non-system file can be considered as being a system file and thus have its warnings be discarded during the compilation of the resulting preprocessed file. My understanding is that this is due to the preprocessor not systematically detecting (and reporting) the change in system-ness of tokens. And this is what this patch does. Each time the system-ness of a given token is different from the previous token that was emitted by the preprocessor, it emits a line marker for the sole purpose of marking the new system-ness of the subsequent tokens to come. Bootstrapped and tested on x86_64-unknown-linux-gnu against trunk. gcc/c-family/ChangeLog: * c-ppoutput.c (struct print::prev_was_system_token): New data member. (init_pp_output): Initialize it. (maybe_print_line_1, maybe_print_line, print_line_1, print_line) (do_line_change): Return a flag saying if a line marker was emitted or not. (scan_translation_unit): Detect if the system-ness of the token we are about to emit is different from the one of the previously emitted token. If so, emit a line marker. Avoid emitting useless adjacent line markers. Avoid emitting line markers for tokens originating from the expansion of built-in macros. (scan_translation_unit_directives_only): Adjust. gcc/testsuite/ChangeLog: * gcc.dg/cpp/syshdr{4,5}.{c,h}: New test files. Signed-off-by: Dodji Seketeli <dodji@redhat.com> Signed-off-by: Dodji Seketeli <dodji@redhat.com> From-SVN: r212638
2014-07-16 12:33:36 +02:00
&& !is_location_from_builtin_token (loc))
/* The system-ness of this token is different from the one
of the previous token. Let's emit a line change to
mark the new system-ness before we emit the token. */
{
do_line_change (pfile, token, loc, false);
print.prev_was_system_token = !!in_system_header_at (loc);
PR preprocessor/60723 - missing system-ness marks for macro tokens When a system macro is expanded in a non-system file during out-of-line preprocessing, it can happen that the preprocessor forgets to emit line markers to express the system-ness status of tokens that come after the expansion of the macro. That can lead to situations where the entire non-system file can be considered as being a system file and thus have its warnings be discarded during the compilation of the resulting preprocessed file. My understanding is that this is due to the preprocessor not systematically detecting (and reporting) the change in system-ness of tokens. And this is what this patch does. Each time the system-ness of a given token is different from the previous token that was emitted by the preprocessor, it emits a line marker for the sole purpose of marking the new system-ness of the subsequent tokens to come. Bootstrapped and tested on x86_64-unknown-linux-gnu against trunk. gcc/c-family/ChangeLog: * c-ppoutput.c (struct print::prev_was_system_token): New data member. (init_pp_output): Initialize it. (maybe_print_line_1, maybe_print_line, print_line_1, print_line) (do_line_change): Return a flag saying if a line marker was emitted or not. (scan_translation_unit): Detect if the system-ness of the token we are about to emit is different from the one of the previously emitted token. If so, emit a line marker. Avoid emitting useless adjacent line markers. Avoid emitting line markers for tokens originating from the expansion of built-in macros. (scan_translation_unit_directives_only): Adjust. gcc/testsuite/ChangeLog: * gcc.dg/cpp/syshdr{4,5}.{c,h}: New test files. Signed-off-by: Dodji Seketeli <dodji@redhat.com> Signed-off-by: Dodji Seketeli <dodji@redhat.com> From-SVN: r212638
2014-07-16 12:33:36 +02:00
}
cpp_output_token (token, print.outf);
PR preprocessor/60723 - missing system-ness marks for macro tokens When a system macro is expanded in a non-system file during out-of-line preprocessing, it can happen that the preprocessor forgets to emit line markers to express the system-ness status of tokens that come after the expansion of the macro. That can lead to situations where the entire non-system file can be considered as being a system file and thus have its warnings be discarded during the compilation of the resulting preprocessed file. My understanding is that this is due to the preprocessor not systematically detecting (and reporting) the change in system-ness of tokens. And this is what this patch does. Each time the system-ness of a given token is different from the previous token that was emitted by the preprocessor, it emits a line marker for the sole purpose of marking the new system-ness of the subsequent tokens to come. Bootstrapped and tested on x86_64-unknown-linux-gnu against trunk. gcc/c-family/ChangeLog: * c-ppoutput.c (struct print::prev_was_system_token): New data member. (init_pp_output): Initialize it. (maybe_print_line_1, maybe_print_line, print_line_1, print_line) (do_line_change): Return a flag saying if a line marker was emitted or not. (scan_translation_unit): Detect if the system-ness of the token we are about to emit is different from the one of the previously emitted token. If so, emit a line marker. Avoid emitting useless adjacent line markers. Avoid emitting line markers for tokens originating from the expansion of built-in macros. (scan_translation_unit_directives_only): Adjust. gcc/testsuite/ChangeLog: * gcc.dg/cpp/syshdr{4,5}.{c,h}: New test files. Signed-off-by: Dodji Seketeli <dodji@redhat.com> Signed-off-by: Dodji Seketeli <dodji@redhat.com> From-SVN: r212638
2014-07-16 12:33:36 +02:00
line_marker_emitted = false;
print.printed = true;
}
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
2001-09-25 00:53:12 +02:00
/* CPP_COMMENT tokens and raw-string literal tokens can
have embedded new-line characters. Rather than enumerating
all the possible token types just check if token uses
val.str union member. */
if (cpp_token_val_index (token) == CPP_TOKEN_FLD_STR)
account_for_newlines (token->val.str.text, token->val.str.len);
New macro expander. 2000-10-28 Neil Booth <neilb@earthling.net> New macro expander. * cpplib.c (struct answer): New. (struct if_stack): Use cpp_lexer_pos rather than line and col. Rename cmacro mi_cmacro. (struct directive, KANDR, STDC89, EXTENSION, COND, IF_COND, INCL, IN_I): New directive and flags. (skip_rest_of_line, check_eol, run_directive, glue_header_name, parse_answer, parse_assertion, find_answer): New functions. (parse_ifdef, detect_if_not_defined, validate_else): Remove. (lex_macro_node): New function to replace parse_ifdef and get_define_node. (_cpp_handle_directive): New function, combines _cpp_check_directive and _cpp_check_linemarker. (do_define, do_undef, parse_include, do_include, do_import, do_include_next, read_line_number, do_line, do_ident, do_pragma, do_pragma_once, do_pragma_poison, do_pragma_dependency): Update for new token getting interface. (do_ifdef, do_ifndef, do_if, do_else, do_endif, push_conditional) : Update for new multiple-include optimisation technique. (do_elif): Don't forget to invalidate controlling macros. (unwind_if_stack, cpp_defined, cpp_push_buffer, cpp_pop_buffer): Update. (parse_assertion, parse_answer, find_answer, _cpp_test_assertion): Functions to handle assertions with the new token interface. (do_assert, do_unassert): Use them. (cpp_define, _cpp_define_builtin, cpp_undef, cpp_assert, cpp_unassert): Use run_directive. (_cpp_init_stacks): Register directive names. Don't register special nodes. * cpperror.c (print_containing_files, _cpp_begin_message): Update to new position recording regime. (cpp_ice, cpp_fatal, cpp_error, cpp_error_with_line, cpp_warning, cpp_warning_with_line, cpp_pedwarn, cpp_pedwarn_with_line, cpp_pedwarn_with_file_and_line): Update for _cpp_begin_message changes. (cpp_type2name): Move to cpplex.c. * cppexp.c (parse_charconst): spec_nodes is no longer a pointer. (parse_defined): Update to handle new multiple include optimisation method. Remove poisoned identifier warning. (parse_assertion, TYPE_NAME): Delete. (lex): Update for multiple include optimisation, removal of CPP_DEFINED, to use _cpp_test_assertion for assertions and cpp_token_as_text. (_cpp_parse_expr): Update for MI optimisation, and to use op_as_text. (op_as_text): New function, to wrap cpp_token_as_text. * cppfiles.c (stack_include_file, _cpp_pop_file_buffer): Update for MI optimisation. (_cpp_execute_include): Take a token rather than 3 arguments. Fix segfault on diagnostic. (_cpp_compare_file_date): Take a token rather than 3 args. (cpp_read_file): Work correctly for zero-length files. * cpphash.c (_cpp_init_macros, _cpp_cleanup_macros): Rename _cpp_init_hashtable and _cpp_cleanup_hashtable. (cpp_lookup): Place identifiers at front of identifier pool for _cpp_lookup_with_hash. (_cpp_lookup_with_hash): Require identifiers to be at the front of the identifier pool. Commit the memory if not already in the hash table. * cppinit.c (cpp_reader_init): Move cpp_init_completed test to top. Initialise various members of cpp_reader, memory pools, and the special nodes. (cpp_printer_init): Delete. (cpp_cleanup): Update. (struct builtin, builtin_array, initialize_builtins): Update for new hashnode definition and builtin handling. (cpp_start_read, cpp_finish): Don't take or initialise a printer. Update. * cpplib.h (cpp_printer, cpp_toklist, CPP_DEFINED, BOL, PASTED, VAR_ARGS, BEG_OF_FILE, IN_DIRECTIVE, KNOWN_DIRECTIVE, T_VOID, T_SPECLINE, T_DATE, T_FILE, T_BASE_FILE, T_INCLUDE_LEVEL, T_TIME, T_STDC, T_OPERATOR, T_POISON, T_MACRO, T_ASSERTION): Delete. (struct cpp_pool, struct cpp_macro, struct cpp_lexer_pos, struct cpp_lookahead, CPP_DHASH, enum mi_state, enum mi_ind, NO_EXPAND, VARARGS_FIRST, struct cpp_token_with_pos, struct toklist, struct cpp_context, struct specnodes, TOKEN_LOOKAHEAD, TOKEN_BUFFSIZE, NODE_OPERATOR, NODE_POISONED, NODE_BUILTIN, NODE_DIAGNOSTIC, NT_VOID, NT_MACRO, NT_ASSERTION, enum builtin_type, cpp_can_paste): New. (struct cpp_token): Delete line and col members. (struct cpp_buffer): New member output_lineno. (struct lexer_state): Delete indented, in_lex_line, seen_dot. Add va_args_ok, poisoned_ok, prevent_expansion, parsing_args. (struct cpp_reader): New members lexer_pos, macro_pos, directive_pos, ident_pool, temp_string_pool, macro_pool, argument_pool, string_pool, base_context, context, directive, mi_state, mi_if_not_defined, mi_lexed, mi_cmacro, mi_ind_cmacro, la_read, la_write, la_unused, mlstring_pos, macro_buffer, macro_buffer_len. Delete members mls_line, mls_column, token_list, potential_control_macro, temp_tokens, temp_cap, temp_alloced, temp_used, first_directive_token, context_cap, cur_context, no_expand_level, paste_level, contexts, args, save_parameter_spellings, need_newline, . Change type of date, time and spec_nodes members. Change prototypes for include and ident callbacks. (struct cpp_hashnode): Change type of name. Remove union members expansion and code. Add members macro, operator and builtin. (cpp_token_len, cpp_token_as_text, cpp_spell_token, cpp_start_read, cpp_finish, cpp_avoid_paste, cpp_get_token, cpp_get_line, cpp_get_output_line, cpp_macro_definition, cpp_start_lookahead, cpp_stop_lookahead): New prototypes. (cpp_printer_init, cpp_dump_definition): Delete prototypes. (U_CHAR, U, ustrcmp, ustrncmp, ustrlen, uxstrdup, ustrchr, ufputs): Move from cpphash.h. * cpphash.h (U_CHAR, U, ustrcmp, ustrncmp, ustrlen, uxstrdup, ustrchr, ufputs): Move to cpplib.h. (enum spell_type, struct token_spelling, _cpp_token_spellings, TOKEN_SPELL, TOKEN_NAME, struct answer, FREE_ANSWER, KANDR, STDC89, EXTENSION, COND, EXPAND, INCL, COMMENTS, IN_I, struct directive, directive_handler, struct spec_nodes, _cpp_digraph_spellings, _cpp_free_temp_tokens, _cpp_init_input_buffer, _cpp_grow_token_buffer, _cpp_init_toklist, _cpp_clear_toklist, _cpp_expand_token_space, _cpp_expand_name_space, _cpp_equiv_tokens, _cpp_equiv_toklists, _cpp_process_directive, _cpp_run_directive, _cpp_get_line, _cpp_get_raw_token, _cpp_glue_header_name, _cpp_can_paste, _cpp_check_directive, _cpp_check_linemarker, _cpp_parse_assertion, _cpp_find_answer): Delete. (VALID_SIGN, ALIGN, POOL_FRONT, POOL_LIMIT, POOL_BASE, POOL_SIZE, POOL_USED, POOL_COMMIT, struct cpp_chunk, _cpp_lex_token, _cpp_init_pool, _cpp_free_pool, _cpp_pool_reserve, _cpp_pool_alloc, _cpp_next_chunk, _cpp_lock_pool, _cpp_unlock_pool, _cpp_test_assertion, _cpp_handle_directive, DSC): New. (struct include_file): New member defined. (DO_NOT_REREAD, _cpp_begin_message, _cpp_execute_include, _cpp_compare_file_date): Update. (_cpp_pop_context, _cpp_get_token, _cpp_free_lookaheads, _cpp_push_token): New. (_cpp_init_macros, _cpp_cleanup_macros): Rename to _cpp_init_hashtable, _cpp_cleanup_hashtable. * Makefile.in: Remove cppoutput.c. * cppoutput.c: Delete * fixheader.c (read_scan_file): Update for new cpp_get_token prototype. (recognized_function): New argument LINE. * scan-decls.c (skip_to_closing_brace, scan_decls): Update for new cpp_get_token prototype. * scan.h (recognized_function): Update prototype. * po/POTFILES.in: Remove cppoutput.c. From-SVN: r37098
2000-10-28 19:59:06 +02:00
}
}
directives-only.c: New file. libcpp/ * directives-only.c: New file. * internal.h (struct _cpp_dir_only_callbacks): New. (_cpp_preprocess_dir_only): New function. * directives.c (_cpp_handle_directive): Check directives_only before disabling execution of indented directives. * files.c (_cpp_stack_file): Add directives_only check. * include/cpplib.h (struct cpp_options): Add directives_only. (cpp_init_special_builtins): New function. * init.c (cpp_init_special_builtins): New function. (cpp_init_builtins): Move builtin_array initialization to cpp_init_special_builtins. (post_options): Check directives_only before setting pfile->state.prevent_expansion = 1. * macro.c (_cpp_builtin_macro_text): Print an error if __COUNTER__ is expanded inside a directive while -fdirectives-only is enabled. * Makefile.in (libcpp_a_OBJS): Add directives-only.o. (libcpp_a_SOURCES): Add directives-only.c. gcc/ * c-ppoutput.c (print_lines_directives_only): New function. (scan_translation_unit_directives_only): New function. (preprocess_file): Add call to scan_translation_unit_directives_only. * c-opts.c (c_common_handle_option): Add OPT_fdirectives_only. (sanitize_cpp_opts): Add default flag_dump_macros setting for -fdirectives-only. Add errors for -fdirectives-only conflict with -Wunused-macros and -traditional. (finish_options): Add builtin macro initialization for -fdirectives-only + -fpreprocessed. * c.opt (fdirectives-only): New. * doc/cppopts.texi (fdirectives-only): New. gcc/testsuite/ * gcc.dg/cpp/counter-2.c: New test. * gcc.dg/cpp/counter-3.c: New test. * gcc.dg/cpp/dir-only-1.c: New test. * gcc.dg/cpp/dir-only-1.h: New file. * gcc.dg/cpp/dir-only-2.c: New test. * gcc.dg/cpp/dir-only-3.c: New test. * gcc.dg/cpp/dir-only-3a.h: New file. * gcc.dg/cpp/dir-only-3b.h: New file. * gcc.dg/cpp/dir-only-4.c: New test. * gcc.dg/cpp/dir-only-5.c: New test. * gcc.dg/cpp/dir-only-6.c: New test. From-SVN: r127066
2007-07-30 20:29:20 +02:00
static void
print_lines_directives_only (int lines, const void *buf, size_t size)
{
print.src_line += lines;
fwrite (buf, 1, size, print.outf);
}
/* Writes out the preprocessed file, handling spacing and paste
avoidance issues. */
static void
scan_translation_unit_directives_only (cpp_reader *pfile)
{
struct _cpp_dir_only_callbacks cb;
cb.print_lines = print_lines_directives_only;
PR preprocessor/60723 - missing system-ness marks for macro tokens When a system macro is expanded in a non-system file during out-of-line preprocessing, it can happen that the preprocessor forgets to emit line markers to express the system-ness status of tokens that come after the expansion of the macro. That can lead to situations where the entire non-system file can be considered as being a system file and thus have its warnings be discarded during the compilation of the resulting preprocessed file. My understanding is that this is due to the preprocessor not systematically detecting (and reporting) the change in system-ness of tokens. And this is what this patch does. Each time the system-ness of a given token is different from the previous token that was emitted by the preprocessor, it emits a line marker for the sole purpose of marking the new system-ness of the subsequent tokens to come. Bootstrapped and tested on x86_64-unknown-linux-gnu against trunk. gcc/c-family/ChangeLog: * c-ppoutput.c (struct print::prev_was_system_token): New data member. (init_pp_output): Initialize it. (maybe_print_line_1, maybe_print_line, print_line_1, print_line) (do_line_change): Return a flag saying if a line marker was emitted or not. (scan_translation_unit): Detect if the system-ness of the token we are about to emit is different from the one of the previously emitted token. If so, emit a line marker. Avoid emitting useless adjacent line markers. Avoid emitting line markers for tokens originating from the expansion of built-in macros. (scan_translation_unit_directives_only): Adjust. gcc/testsuite/ChangeLog: * gcc.dg/cpp/syshdr{4,5}.{c,h}: New test files. Signed-off-by: Dodji Seketeli <dodji@redhat.com> Signed-off-by: Dodji Seketeli <dodji@redhat.com> From-SVN: r212638
2014-07-16 12:33:36 +02:00
cb.maybe_print_line = (void (*) (source_location)) maybe_print_line;
directives-only.c: New file. libcpp/ * directives-only.c: New file. * internal.h (struct _cpp_dir_only_callbacks): New. (_cpp_preprocess_dir_only): New function. * directives.c (_cpp_handle_directive): Check directives_only before disabling execution of indented directives. * files.c (_cpp_stack_file): Add directives_only check. * include/cpplib.h (struct cpp_options): Add directives_only. (cpp_init_special_builtins): New function. * init.c (cpp_init_special_builtins): New function. (cpp_init_builtins): Move builtin_array initialization to cpp_init_special_builtins. (post_options): Check directives_only before setting pfile->state.prevent_expansion = 1. * macro.c (_cpp_builtin_macro_text): Print an error if __COUNTER__ is expanded inside a directive while -fdirectives-only is enabled. * Makefile.in (libcpp_a_OBJS): Add directives-only.o. (libcpp_a_SOURCES): Add directives-only.c. gcc/ * c-ppoutput.c (print_lines_directives_only): New function. (scan_translation_unit_directives_only): New function. (preprocess_file): Add call to scan_translation_unit_directives_only. * c-opts.c (c_common_handle_option): Add OPT_fdirectives_only. (sanitize_cpp_opts): Add default flag_dump_macros setting for -fdirectives-only. Add errors for -fdirectives-only conflict with -Wunused-macros and -traditional. (finish_options): Add builtin macro initialization for -fdirectives-only + -fpreprocessed. * c.opt (fdirectives-only): New. * doc/cppopts.texi (fdirectives-only): New. gcc/testsuite/ * gcc.dg/cpp/counter-2.c: New test. * gcc.dg/cpp/counter-3.c: New test. * gcc.dg/cpp/dir-only-1.c: New test. * gcc.dg/cpp/dir-only-1.h: New file. * gcc.dg/cpp/dir-only-2.c: New test. * gcc.dg/cpp/dir-only-3.c: New test. * gcc.dg/cpp/dir-only-3a.h: New file. * gcc.dg/cpp/dir-only-3b.h: New file. * gcc.dg/cpp/dir-only-4.c: New test. * gcc.dg/cpp/dir-only-5.c: New test. * gcc.dg/cpp/dir-only-6.c: New test. From-SVN: r127066
2007-07-30 20:29:20 +02:00
_cpp_preprocess_dir_only (pfile, &cb);
}
Represent column numbers using line-map's source_location. The "next available source_location" is now managed internally by line-maps.c rather than by clients. * line-map.h (struct line_map): New field column_bits. <from_line>: Rename field to start_location. (struct line_maps): New fields highest_location and max_column_hint. (linemap_check_files_exited): New declaration. (linemap_line_start): New declaration. (linemap_add): Remove from_line parameter; use highest_location field. (SOURCE_LINE, LAST_SOURCE_LINE): Modify to use column_bits. (SOURCE_COLUMN, LAST_SOURCE_LINE_LOCATION): New macros. (CURRENT_LINE_MAP): Remove macro. (linemap_position_for_column): New inline function. * line-map.c (linemap_init): Clear new fields. (linemap_check_files_exited): New function, extracted from ... (linemap_free): Use linemap_check_files_exited. (linemap_add): Remove from_line parameter. Various updates. (linemap_line_start): New function. (linemap_lookeup): Update for new field names. * cpphash.h (struct cpp_reader) <map>: Field removed. Because linemap_position_for_column may unpredictably change the current map, it is cleaner and simpler for us to not cache it in cpp_reader. (struct cpp_buffer): New sysp field. Changed warned_cplusplus_comments and from_stage3 to bitfields. * cppinit.c (cpp_read_min_file): pfile->map no longer exists. * cpplib.c (do_line, do_linemarker, _cpp_do_file_change): Get current map using linemap_lookup. (do_linemarker): Also set buffer's sysp field. (destringize_and_run): No longer need to decrement current line. * cppfiles.c (_cpp_stack_file): Set sysp from and in buffer. (search_path_head, open_file_failed): Use buffer's sysp. (cpp_make_system_header): Get current map using linemap_lookup. Also set buffer's sysp flag. * cppmacro.c (_cpp_builtin_macro_text): Likewise use linemap_lookup. * cpphash.h (CPP_INCREMENT_LINE): New macro. (struct cpp_buffer): Moved fields saved_cur, saved_rlimit to ... (struct cpp_reader): ... and adding saved_line_base field. * cpptrad.c (_cpp_overlay_buffer, _cpp_remove_overlay): Update accordingly. Don't adjust line. (_cpp_scan_out_logical_line): Use CPP_INCREMENT_LINE. * cpphash.c (CPP_IN_SYSTEM_HEADER): Replaced macro by ... (cpp_in_system_header): ... new inline function, using buffer's sysp. * cpperror.c (_cpp_begin_message): Update to use cpp_in_system_header. * cpplex.c (_cpp_lex_direct): Likewise. * cppmacro.c (_cpp_builtin_macro_text): Likewise. * cppmacro.c (_cpp_create_definition): Use buffer's sysp field. * cpplib.h (struct cpp_token): Rename line field to src_loc. Remove col field as it is now subsumed by src_loc. * cpperror.c: Update various field, parameter, and macro names. (print_location): If col==0, try SOURCE_COLUMN of line. (cpp_error): Use cur_token's src_loc field, rather than line+col. * cpplib.c (do_diagnostic): Token's src_loc fields replaces line+col. * cpplex.c (_cpp_process_line_notes, _cpp_lex_direct, _cpp_skip_block_comment): Use CPP_INCREMENT_LINE. (_cpp_temp_token): Replace cpp_token's line+col fields by src_loc. (_cpp_get_fresh_line): Don't need to adjust line for missing newline. (_cpp_lex_direct): Use linemap_position_for_column. * c-ppoutput.c (maybe_print_line, print_line): Don't take map parameter. Instead get it from the line_table global. Adjust callers. (print): Remove map field. Replace line field to src_line. (init_pp_output, account_for_newlines, maybe_print_line): Adjust. (cb_line_change): Use SOURCE_COLUMN. Minor optimizations. (pp_file_change): Use MAIN_FILE_P since we cannot checked print.map. Use LAST_SOURCE_LINE_LOCATION to "catch up" after #include. * cpptrad.c (copy_comment): Rename variable. * c-lex.c (map): Remove static variable, for same reason we removed cpp_reader's map field. (cb_line_change, cb_def_pragma, cb_define, cb_undef): Hence we need to call linemap_lookup. (cb_line_change): Token's line field replaced by src_loc. (fe_file_change): Use MAINFILE_P and LAST_SOURCE_LINE macros. Don't save new_map. * cpphash.h, cpperror.c, cpplib.h: Some renames of fileline to source_location. From-SVN: r77663
2004-02-11 16:29:30 +01:00
/* Adjust print.src_line for newlines embedded in output. */
static void
account_for_newlines (const unsigned char *str, size_t len)
{
while (len--)
if (*str++ == '\n')
Represent column numbers using line-map's source_location. The "next available source_location" is now managed internally by line-maps.c rather than by clients. * line-map.h (struct line_map): New field column_bits. <from_line>: Rename field to start_location. (struct line_maps): New fields highest_location and max_column_hint. (linemap_check_files_exited): New declaration. (linemap_line_start): New declaration. (linemap_add): Remove from_line parameter; use highest_location field. (SOURCE_LINE, LAST_SOURCE_LINE): Modify to use column_bits. (SOURCE_COLUMN, LAST_SOURCE_LINE_LOCATION): New macros. (CURRENT_LINE_MAP): Remove macro. (linemap_position_for_column): New inline function. * line-map.c (linemap_init): Clear new fields. (linemap_check_files_exited): New function, extracted from ... (linemap_free): Use linemap_check_files_exited. (linemap_add): Remove from_line parameter. Various updates. (linemap_line_start): New function. (linemap_lookeup): Update for new field names. * cpphash.h (struct cpp_reader) <map>: Field removed. Because linemap_position_for_column may unpredictably change the current map, it is cleaner and simpler for us to not cache it in cpp_reader. (struct cpp_buffer): New sysp field. Changed warned_cplusplus_comments and from_stage3 to bitfields. * cppinit.c (cpp_read_min_file): pfile->map no longer exists. * cpplib.c (do_line, do_linemarker, _cpp_do_file_change): Get current map using linemap_lookup. (do_linemarker): Also set buffer's sysp field. (destringize_and_run): No longer need to decrement current line. * cppfiles.c (_cpp_stack_file): Set sysp from and in buffer. (search_path_head, open_file_failed): Use buffer's sysp. (cpp_make_system_header): Get current map using linemap_lookup. Also set buffer's sysp flag. * cppmacro.c (_cpp_builtin_macro_text): Likewise use linemap_lookup. * cpphash.h (CPP_INCREMENT_LINE): New macro. (struct cpp_buffer): Moved fields saved_cur, saved_rlimit to ... (struct cpp_reader): ... and adding saved_line_base field. * cpptrad.c (_cpp_overlay_buffer, _cpp_remove_overlay): Update accordingly. Don't adjust line. (_cpp_scan_out_logical_line): Use CPP_INCREMENT_LINE. * cpphash.c (CPP_IN_SYSTEM_HEADER): Replaced macro by ... (cpp_in_system_header): ... new inline function, using buffer's sysp. * cpperror.c (_cpp_begin_message): Update to use cpp_in_system_header. * cpplex.c (_cpp_lex_direct): Likewise. * cppmacro.c (_cpp_builtin_macro_text): Likewise. * cppmacro.c (_cpp_create_definition): Use buffer's sysp field. * cpplib.h (struct cpp_token): Rename line field to src_loc. Remove col field as it is now subsumed by src_loc. * cpperror.c: Update various field, parameter, and macro names. (print_location): If col==0, try SOURCE_COLUMN of line. (cpp_error): Use cur_token's src_loc field, rather than line+col. * cpplib.c (do_diagnostic): Token's src_loc fields replaces line+col. * cpplex.c (_cpp_process_line_notes, _cpp_lex_direct, _cpp_skip_block_comment): Use CPP_INCREMENT_LINE. (_cpp_temp_token): Replace cpp_token's line+col fields by src_loc. (_cpp_get_fresh_line): Don't need to adjust line for missing newline. (_cpp_lex_direct): Use linemap_position_for_column. * c-ppoutput.c (maybe_print_line, print_line): Don't take map parameter. Instead get it from the line_table global. Adjust callers. (print): Remove map field. Replace line field to src_line. (init_pp_output, account_for_newlines, maybe_print_line): Adjust. (cb_line_change): Use SOURCE_COLUMN. Minor optimizations. (pp_file_change): Use MAIN_FILE_P since we cannot checked print.map. Use LAST_SOURCE_LINE_LOCATION to "catch up" after #include. * cpptrad.c (copy_comment): Rename variable. * c-lex.c (map): Remove static variable, for same reason we removed cpp_reader's map field. (cb_line_change, cb_def_pragma, cb_define, cb_undef): Hence we need to call linemap_lookup. (cb_line_change): Token's line field replaced by src_loc. (fe_file_change): Use MAINFILE_P and LAST_SOURCE_LINE macros. Don't save new_map. * cpphash.h, cpperror.c, cpplib.h: Some renames of fileline to source_location. From-SVN: r77663
2004-02-11 16:29:30 +01:00
print.src_line++;
}
/* Writes out a traditionally preprocessed file. */
static void
scan_translation_unit_trad (cpp_reader *pfile)
{
while (_cpp_read_logical_line_trad (pfile))
{
size_t len = pfile->out.cur - pfile->out.base;
Represent column numbers using line-map's source_location. The "next available source_location" is now managed internally by line-maps.c rather than by clients. * line-map.h (struct line_map): New field column_bits. <from_line>: Rename field to start_location. (struct line_maps): New fields highest_location and max_column_hint. (linemap_check_files_exited): New declaration. (linemap_line_start): New declaration. (linemap_add): Remove from_line parameter; use highest_location field. (SOURCE_LINE, LAST_SOURCE_LINE): Modify to use column_bits. (SOURCE_COLUMN, LAST_SOURCE_LINE_LOCATION): New macros. (CURRENT_LINE_MAP): Remove macro. (linemap_position_for_column): New inline function. * line-map.c (linemap_init): Clear new fields. (linemap_check_files_exited): New function, extracted from ... (linemap_free): Use linemap_check_files_exited. (linemap_add): Remove from_line parameter. Various updates. (linemap_line_start): New function. (linemap_lookeup): Update for new field names. * cpphash.h (struct cpp_reader) <map>: Field removed. Because linemap_position_for_column may unpredictably change the current map, it is cleaner and simpler for us to not cache it in cpp_reader. (struct cpp_buffer): New sysp field. Changed warned_cplusplus_comments and from_stage3 to bitfields. * cppinit.c (cpp_read_min_file): pfile->map no longer exists. * cpplib.c (do_line, do_linemarker, _cpp_do_file_change): Get current map using linemap_lookup. (do_linemarker): Also set buffer's sysp field. (destringize_and_run): No longer need to decrement current line. * cppfiles.c (_cpp_stack_file): Set sysp from and in buffer. (search_path_head, open_file_failed): Use buffer's sysp. (cpp_make_system_header): Get current map using linemap_lookup. Also set buffer's sysp flag. * cppmacro.c (_cpp_builtin_macro_text): Likewise use linemap_lookup. * cpphash.h (CPP_INCREMENT_LINE): New macro. (struct cpp_buffer): Moved fields saved_cur, saved_rlimit to ... (struct cpp_reader): ... and adding saved_line_base field. * cpptrad.c (_cpp_overlay_buffer, _cpp_remove_overlay): Update accordingly. Don't adjust line. (_cpp_scan_out_logical_line): Use CPP_INCREMENT_LINE. * cpphash.c (CPP_IN_SYSTEM_HEADER): Replaced macro by ... (cpp_in_system_header): ... new inline function, using buffer's sysp. * cpperror.c (_cpp_begin_message): Update to use cpp_in_system_header. * cpplex.c (_cpp_lex_direct): Likewise. * cppmacro.c (_cpp_builtin_macro_text): Likewise. * cppmacro.c (_cpp_create_definition): Use buffer's sysp field. * cpplib.h (struct cpp_token): Rename line field to src_loc. Remove col field as it is now subsumed by src_loc. * cpperror.c: Update various field, parameter, and macro names. (print_location): If col==0, try SOURCE_COLUMN of line. (cpp_error): Use cur_token's src_loc field, rather than line+col. * cpplib.c (do_diagnostic): Token's src_loc fields replaces line+col. * cpplex.c (_cpp_process_line_notes, _cpp_lex_direct, _cpp_skip_block_comment): Use CPP_INCREMENT_LINE. (_cpp_temp_token): Replace cpp_token's line+col fields by src_loc. (_cpp_get_fresh_line): Don't need to adjust line for missing newline. (_cpp_lex_direct): Use linemap_position_for_column. * c-ppoutput.c (maybe_print_line, print_line): Don't take map parameter. Instead get it from the line_table global. Adjust callers. (print): Remove map field. Replace line field to src_line. (init_pp_output, account_for_newlines, maybe_print_line): Adjust. (cb_line_change): Use SOURCE_COLUMN. Minor optimizations. (pp_file_change): Use MAIN_FILE_P since we cannot checked print.map. Use LAST_SOURCE_LINE_LOCATION to "catch up" after #include. * cpptrad.c (copy_comment): Rename variable. * c-lex.c (map): Remove static variable, for same reason we removed cpp_reader's map field. (cb_line_change, cb_def_pragma, cb_define, cb_undef): Hence we need to call linemap_lookup. (cb_line_change): Token's line field replaced by src_loc. (fe_file_change): Use MAINFILE_P and LAST_SOURCE_LINE macros. Don't save new_map. * cpphash.h, cpperror.c, cpplib.h: Some renames of fileline to source_location. From-SVN: r77663
2004-02-11 16:29:30 +01:00
maybe_print_line (pfile->out.first_line);
fwrite (pfile->out.base, 1, len, print.outf);
print.printed = true;
if (!CPP_OPTION (pfile, discard_comments))
account_for_newlines (pfile->out.base, len);
}
}
re PR preprocessor/3081 (Preprocessor merges 2 first lines when -imacros is being used) PR preprocessor/3081 * c-lex.c (map): New. (cb_file_change): Update map and use it. (cb_def_pragma, cb_define, cb_undef): Use map and line. (c_lex): Update to use map. * cpperror.c (print_location): Move to using logical line numbers. * cppfiles.c (stack_include_file): Update for new _cpp_do_file_change. (cpp_make_system_header): Similarly. (_cpp_execute_include): Stop line numbering hacks. Store the line we will return to. * cpphash.h (CPP_BUF_LINE): Remove. (struct cpp_buffer): Remove lineno and pseudo_newlines. Add map and return_to_line. (_cpp_do_file_change): Update. * cppinit.c (cpp_start_read): Update line kludge. * cpplex.c (handle_newline): Don't update lineno and pseudo_newlines. (trigraph_ok): Use logical line numbers for diagnostics. (skip_block_comment): Likewise. (skip_whitespace): Likewise. (skip_line_comment): Use pfile->line instead. (_cpp_lex_token): Update to use logical line numbering exclusively. Handle BOL locally. Accept new lines in directives, but keep pfile->line decremented. Diagnostics use logical lines. Update directive handling. * cpplib.c (SEEN_EOL): New. (skip_rest_of_line, check_eol): Use it. (end_directive): Increase line number when accepting the newline at the end of a directive. (run_directive): Simplify. (do_line): Bad LC_LEAVEs become LC_RENAMEs. Update. (_cpp_do_file_change): Update to take buffer line number as an argument, and store the current map in the cpp_reader. Remove line number kludges. (_cpp_do__Pragma): Restore output position after a _Pragma. (cpp_push_buffer): Don't set output line or lineno. (_cpp_pop_buffer): Transfer more info from a faked buffer. Remove line kludge. Set output_line. * cppmacro.c (builtin_macro): Update handling of __LINE__. (parse_arg): Use logical lines. (save_lookahead_token): Save EOFs too now. * cppmain.c (struct printer): Fix comments. (printer_init): Simplify, let caller do errors. (scan_translation_unit, check_multiline_token, dump_macro): Update. (maybe_print_line): Simplify. (print_line): Don't print a linemarker if -P. (cb_define, cb_undef, cb_def_pragma, cb_ident, cb_include): Update. (cb_file_change): Simplify. * line-map.h (LAST_SOURCE_LINE): Fix. (CURRENT_LINE_MAP): New. * gcc.dg/cpp/19951025-1.c: Revert. * gcc.dg/cpp/directiv.c: We no longer process directives that interrupt macro arguments. From-SVN: r44650
2001-08-05 19:31:25 +02:00
/* If the token read on logical line LINE needs to be output on a
different line to the current one, output the required newlines or
PR preprocessor/60723 - missing system-ness marks for macro tokens When a system macro is expanded in a non-system file during out-of-line preprocessing, it can happen that the preprocessor forgets to emit line markers to express the system-ness status of tokens that come after the expansion of the macro. That can lead to situations where the entire non-system file can be considered as being a system file and thus have its warnings be discarded during the compilation of the resulting preprocessed file. My understanding is that this is due to the preprocessor not systematically detecting (and reporting) the change in system-ness of tokens. And this is what this patch does. Each time the system-ness of a given token is different from the previous token that was emitted by the preprocessor, it emits a line marker for the sole purpose of marking the new system-ness of the subsequent tokens to come. Bootstrapped and tested on x86_64-unknown-linux-gnu against trunk. gcc/c-family/ChangeLog: * c-ppoutput.c (struct print::prev_was_system_token): New data member. (init_pp_output): Initialize it. (maybe_print_line_1, maybe_print_line, print_line_1, print_line) (do_line_change): Return a flag saying if a line marker was emitted or not. (scan_translation_unit): Detect if the system-ness of the token we are about to emit is different from the one of the previously emitted token. If so, emit a line marker. Avoid emitting useless adjacent line markers. Avoid emitting line markers for tokens originating from the expansion of built-in macros. (scan_translation_unit_directives_only): Adjust. gcc/testsuite/ChangeLog: * gcc.dg/cpp/syshdr{4,5}.{c,h}: New test files. Signed-off-by: Dodji Seketeli <dodji@redhat.com> Signed-off-by: Dodji Seketeli <dodji@redhat.com> From-SVN: r212638
2014-07-16 12:33:36 +02:00
a line marker. If a line marker was emitted, return TRUE otherwise
return FALSE. */
PR preprocessor/60723 - missing system-ness marks for macro tokens When a system macro is expanded in a non-system file during out-of-line preprocessing, it can happen that the preprocessor forgets to emit line markers to express the system-ness status of tokens that come after the expansion of the macro. That can lead to situations where the entire non-system file can be considered as being a system file and thus have its warnings be discarded during the compilation of the resulting preprocessed file. My understanding is that this is due to the preprocessor not systematically detecting (and reporting) the change in system-ness of tokens. And this is what this patch does. Each time the system-ness of a given token is different from the previous token that was emitted by the preprocessor, it emits a line marker for the sole purpose of marking the new system-ness of the subsequent tokens to come. Bootstrapped and tested on x86_64-unknown-linux-gnu against trunk. gcc/c-family/ChangeLog: * c-ppoutput.c (struct print::prev_was_system_token): New data member. (init_pp_output): Initialize it. (maybe_print_line_1, maybe_print_line, print_line_1, print_line) (do_line_change): Return a flag saying if a line marker was emitted or not. (scan_translation_unit): Detect if the system-ness of the token we are about to emit is different from the one of the previously emitted token. If so, emit a line marker. Avoid emitting useless adjacent line markers. Avoid emitting line markers for tokens originating from the expansion of built-in macros. (scan_translation_unit_directives_only): Adjust. gcc/testsuite/ChangeLog: * gcc.dg/cpp/syshdr{4,5}.{c,h}: New test files. Signed-off-by: Dodji Seketeli <dodji@redhat.com> Signed-off-by: Dodji Seketeli <dodji@redhat.com> From-SVN: r212638
2014-07-16 12:33:36 +02:00
static bool
maybe_print_line_1 (source_location src_loc, FILE *stream)
New macro expander. 2000-10-28 Neil Booth <neilb@earthling.net> New macro expander. * cpplib.c (struct answer): New. (struct if_stack): Use cpp_lexer_pos rather than line and col. Rename cmacro mi_cmacro. (struct directive, KANDR, STDC89, EXTENSION, COND, IF_COND, INCL, IN_I): New directive and flags. (skip_rest_of_line, check_eol, run_directive, glue_header_name, parse_answer, parse_assertion, find_answer): New functions. (parse_ifdef, detect_if_not_defined, validate_else): Remove. (lex_macro_node): New function to replace parse_ifdef and get_define_node. (_cpp_handle_directive): New function, combines _cpp_check_directive and _cpp_check_linemarker. (do_define, do_undef, parse_include, do_include, do_import, do_include_next, read_line_number, do_line, do_ident, do_pragma, do_pragma_once, do_pragma_poison, do_pragma_dependency): Update for new token getting interface. (do_ifdef, do_ifndef, do_if, do_else, do_endif, push_conditional) : Update for new multiple-include optimisation technique. (do_elif): Don't forget to invalidate controlling macros. (unwind_if_stack, cpp_defined, cpp_push_buffer, cpp_pop_buffer): Update. (parse_assertion, parse_answer, find_answer, _cpp_test_assertion): Functions to handle assertions with the new token interface. (do_assert, do_unassert): Use them. (cpp_define, _cpp_define_builtin, cpp_undef, cpp_assert, cpp_unassert): Use run_directive. (_cpp_init_stacks): Register directive names. Don't register special nodes. * cpperror.c (print_containing_files, _cpp_begin_message): Update to new position recording regime. (cpp_ice, cpp_fatal, cpp_error, cpp_error_with_line, cpp_warning, cpp_warning_with_line, cpp_pedwarn, cpp_pedwarn_with_line, cpp_pedwarn_with_file_and_line): Update for _cpp_begin_message changes. (cpp_type2name): Move to cpplex.c. * cppexp.c (parse_charconst): spec_nodes is no longer a pointer. (parse_defined): Update to handle new multiple include optimisation method. Remove poisoned identifier warning. (parse_assertion, TYPE_NAME): Delete. (lex): Update for multiple include optimisation, removal of CPP_DEFINED, to use _cpp_test_assertion for assertions and cpp_token_as_text. (_cpp_parse_expr): Update for MI optimisation, and to use op_as_text. (op_as_text): New function, to wrap cpp_token_as_text. * cppfiles.c (stack_include_file, _cpp_pop_file_buffer): Update for MI optimisation. (_cpp_execute_include): Take a token rather than 3 arguments. Fix segfault on diagnostic. (_cpp_compare_file_date): Take a token rather than 3 args. (cpp_read_file): Work correctly for zero-length files. * cpphash.c (_cpp_init_macros, _cpp_cleanup_macros): Rename _cpp_init_hashtable and _cpp_cleanup_hashtable. (cpp_lookup): Place identifiers at front of identifier pool for _cpp_lookup_with_hash. (_cpp_lookup_with_hash): Require identifiers to be at the front of the identifier pool. Commit the memory if not already in the hash table. * cppinit.c (cpp_reader_init): Move cpp_init_completed test to top. Initialise various members of cpp_reader, memory pools, and the special nodes. (cpp_printer_init): Delete. (cpp_cleanup): Update. (struct builtin, builtin_array, initialize_builtins): Update for new hashnode definition and builtin handling. (cpp_start_read, cpp_finish): Don't take or initialise a printer. Update. * cpplib.h (cpp_printer, cpp_toklist, CPP_DEFINED, BOL, PASTED, VAR_ARGS, BEG_OF_FILE, IN_DIRECTIVE, KNOWN_DIRECTIVE, T_VOID, T_SPECLINE, T_DATE, T_FILE, T_BASE_FILE, T_INCLUDE_LEVEL, T_TIME, T_STDC, T_OPERATOR, T_POISON, T_MACRO, T_ASSERTION): Delete. (struct cpp_pool, struct cpp_macro, struct cpp_lexer_pos, struct cpp_lookahead, CPP_DHASH, enum mi_state, enum mi_ind, NO_EXPAND, VARARGS_FIRST, struct cpp_token_with_pos, struct toklist, struct cpp_context, struct specnodes, TOKEN_LOOKAHEAD, TOKEN_BUFFSIZE, NODE_OPERATOR, NODE_POISONED, NODE_BUILTIN, NODE_DIAGNOSTIC, NT_VOID, NT_MACRO, NT_ASSERTION, enum builtin_type, cpp_can_paste): New. (struct cpp_token): Delete line and col members. (struct cpp_buffer): New member output_lineno. (struct lexer_state): Delete indented, in_lex_line, seen_dot. Add va_args_ok, poisoned_ok, prevent_expansion, parsing_args. (struct cpp_reader): New members lexer_pos, macro_pos, directive_pos, ident_pool, temp_string_pool, macro_pool, argument_pool, string_pool, base_context, context, directive, mi_state, mi_if_not_defined, mi_lexed, mi_cmacro, mi_ind_cmacro, la_read, la_write, la_unused, mlstring_pos, macro_buffer, macro_buffer_len. Delete members mls_line, mls_column, token_list, potential_control_macro, temp_tokens, temp_cap, temp_alloced, temp_used, first_directive_token, context_cap, cur_context, no_expand_level, paste_level, contexts, args, save_parameter_spellings, need_newline, . Change type of date, time and spec_nodes members. Change prototypes for include and ident callbacks. (struct cpp_hashnode): Change type of name. Remove union members expansion and code. Add members macro, operator and builtin. (cpp_token_len, cpp_token_as_text, cpp_spell_token, cpp_start_read, cpp_finish, cpp_avoid_paste, cpp_get_token, cpp_get_line, cpp_get_output_line, cpp_macro_definition, cpp_start_lookahead, cpp_stop_lookahead): New prototypes. (cpp_printer_init, cpp_dump_definition): Delete prototypes. (U_CHAR, U, ustrcmp, ustrncmp, ustrlen, uxstrdup, ustrchr, ufputs): Move from cpphash.h. * cpphash.h (U_CHAR, U, ustrcmp, ustrncmp, ustrlen, uxstrdup, ustrchr, ufputs): Move to cpplib.h. (enum spell_type, struct token_spelling, _cpp_token_spellings, TOKEN_SPELL, TOKEN_NAME, struct answer, FREE_ANSWER, KANDR, STDC89, EXTENSION, COND, EXPAND, INCL, COMMENTS, IN_I, struct directive, directive_handler, struct spec_nodes, _cpp_digraph_spellings, _cpp_free_temp_tokens, _cpp_init_input_buffer, _cpp_grow_token_buffer, _cpp_init_toklist, _cpp_clear_toklist, _cpp_expand_token_space, _cpp_expand_name_space, _cpp_equiv_tokens, _cpp_equiv_toklists, _cpp_process_directive, _cpp_run_directive, _cpp_get_line, _cpp_get_raw_token, _cpp_glue_header_name, _cpp_can_paste, _cpp_check_directive, _cpp_check_linemarker, _cpp_parse_assertion, _cpp_find_answer): Delete. (VALID_SIGN, ALIGN, POOL_FRONT, POOL_LIMIT, POOL_BASE, POOL_SIZE, POOL_USED, POOL_COMMIT, struct cpp_chunk, _cpp_lex_token, _cpp_init_pool, _cpp_free_pool, _cpp_pool_reserve, _cpp_pool_alloc, _cpp_next_chunk, _cpp_lock_pool, _cpp_unlock_pool, _cpp_test_assertion, _cpp_handle_directive, DSC): New. (struct include_file): New member defined. (DO_NOT_REREAD, _cpp_begin_message, _cpp_execute_include, _cpp_compare_file_date): Update. (_cpp_pop_context, _cpp_get_token, _cpp_free_lookaheads, _cpp_push_token): New. (_cpp_init_macros, _cpp_cleanup_macros): Rename to _cpp_init_hashtable, _cpp_cleanup_hashtable. * Makefile.in: Remove cppoutput.c. * cppoutput.c: Delete * fixheader.c (read_scan_file): Update for new cpp_get_token prototype. (recognized_function): New argument LINE. * scan-decls.c (skip_to_closing_brace, scan_decls): Update for new cpp_get_token prototype. * scan.h (recognized_function): Update prototype. * po/POTFILES.in: Remove cppoutput.c. From-SVN: r37098
2000-10-28 19:59:06 +02:00
{
PR preprocessor/60723 - missing system-ness marks for macro tokens When a system macro is expanded in a non-system file during out-of-line preprocessing, it can happen that the preprocessor forgets to emit line markers to express the system-ness status of tokens that come after the expansion of the macro. That can lead to situations where the entire non-system file can be considered as being a system file and thus have its warnings be discarded during the compilation of the resulting preprocessed file. My understanding is that this is due to the preprocessor not systematically detecting (and reporting) the change in system-ness of tokens. And this is what this patch does. Each time the system-ness of a given token is different from the previous token that was emitted by the preprocessor, it emits a line marker for the sole purpose of marking the new system-ness of the subsequent tokens to come. Bootstrapped and tested on x86_64-unknown-linux-gnu against trunk. gcc/c-family/ChangeLog: * c-ppoutput.c (struct print::prev_was_system_token): New data member. (init_pp_output): Initialize it. (maybe_print_line_1, maybe_print_line, print_line_1, print_line) (do_line_change): Return a flag saying if a line marker was emitted or not. (scan_translation_unit): Detect if the system-ness of the token we are about to emit is different from the one of the previously emitted token. If so, emit a line marker. Avoid emitting useless adjacent line markers. Avoid emitting line markers for tokens originating from the expansion of built-in macros. (scan_translation_unit_directives_only): Adjust. gcc/testsuite/ChangeLog: * gcc.dg/cpp/syshdr{4,5}.{c,h}: New test files. Signed-off-by: Dodji Seketeli <dodji@redhat.com> Signed-off-by: Dodji Seketeli <dodji@redhat.com> From-SVN: r212638
2014-07-16 12:33:36 +02:00
bool emitted_line_marker = false;
Linemap infrastructure for virtual locations This is the first instalment of a set which goal is to track locations of tokens across macro expansions. Tom Tromey did the original work and attached the patch to PR preprocessor/7263. This opus is a derivative of that original work. This patch modifies the linemap module of libcpp to add virtual locations support. A virtual location is a mapped location that can resolve to several different physical locations. It can always resolve to the spelling location of a token. For tokens resulting from macro expansion it can resolve to: - either the location of the expansion point of the macro. - or the location of the token in the definition of the macro - or, if the token is an argument of a function-like macro, the location of the use of the matching macro parameter in the definition of the macro The patch creates a new type of line map called a macro map. For every single macro expansion, there is a macro map that generates a virtual location for every single resulting token of the expansion. The good old type of line map we all know is now called an ordinary map. That one still encodes spelling locations as it has always had. As a result linemap_lookup as been extended to return a macro map when given a virtual location resulting from a macro expansion. The layout of structs line_map has changed to support this new type of map. So did the layout of struct line_maps. Accessor macros have been introduced to avoid messing with the implementation details of these datastructures directly. This helped already as we have been testing different ways of arranging these datastructure. Having to constantly adjust client code that is too tied with the internals of line_map and line_maps would have been even more painful. Of course, many new public functions have been added to the linemap module to handle the resolution of virtual locations. This patch introduces the infrastructure but no part of the compiler uses virtual locations yet. However the client code of the linemap data structures has been adjusted as per the changes. E.g, it's not anymore reliable for a client code to manipulate struct line_map directly if it just wants to deal with spelling locations, because struct line_map can now represent a macro map as well. In that case, it's better to use the convenient API to resolve the initial (possibly virtual) location to a spelling location (or to an ordinary map) and use that. This is the reason why the patch adjusts the Java, Ada and Fortran front ends. Also, note that virtual locations are not supposed to be ordered for relations '<' and '>' anymore. To test if a virtual location appears "before" another one, one has to use a new operator exposed by the line map interface. The patch updates the only spot (in the diagnostics module) I have found that was making the assumption that locations were ordered for these relations. This is the only change that introduces a use of the new line map API in this patch, so I am adding a regression test for it only. From-SVN: r180081
2011-10-17 11:58:56 +02:00
int src_line = LOCATION_LINE (src_loc);
const char *src_file = LOCATION_FILE (src_loc);
re PR preprocessor/3081 (Preprocessor merges 2 first lines when -imacros is being used) PR preprocessor/3081 * c-lex.c (map): New. (cb_file_change): Update map and use it. (cb_def_pragma, cb_define, cb_undef): Use map and line. (c_lex): Update to use map. * cpperror.c (print_location): Move to using logical line numbers. * cppfiles.c (stack_include_file): Update for new _cpp_do_file_change. (cpp_make_system_header): Similarly. (_cpp_execute_include): Stop line numbering hacks. Store the line we will return to. * cpphash.h (CPP_BUF_LINE): Remove. (struct cpp_buffer): Remove lineno and pseudo_newlines. Add map and return_to_line. (_cpp_do_file_change): Update. * cppinit.c (cpp_start_read): Update line kludge. * cpplex.c (handle_newline): Don't update lineno and pseudo_newlines. (trigraph_ok): Use logical line numbers for diagnostics. (skip_block_comment): Likewise. (skip_whitespace): Likewise. (skip_line_comment): Use pfile->line instead. (_cpp_lex_token): Update to use logical line numbering exclusively. Handle BOL locally. Accept new lines in directives, but keep pfile->line decremented. Diagnostics use logical lines. Update directive handling. * cpplib.c (SEEN_EOL): New. (skip_rest_of_line, check_eol): Use it. (end_directive): Increase line number when accepting the newline at the end of a directive. (run_directive): Simplify. (do_line): Bad LC_LEAVEs become LC_RENAMEs. Update. (_cpp_do_file_change): Update to take buffer line number as an argument, and store the current map in the cpp_reader. Remove line number kludges. (_cpp_do__Pragma): Restore output position after a _Pragma. (cpp_push_buffer): Don't set output line or lineno. (_cpp_pop_buffer): Transfer more info from a faked buffer. Remove line kludge. Set output_line. * cppmacro.c (builtin_macro): Update handling of __LINE__. (parse_arg): Use logical lines. (save_lookahead_token): Save EOFs too now. * cppmain.c (struct printer): Fix comments. (printer_init): Simplify, let caller do errors. (scan_translation_unit, check_multiline_token, dump_macro): Update. (maybe_print_line): Simplify. (print_line): Don't print a linemarker if -P. (cb_define, cb_undef, cb_def_pragma, cb_ident, cb_include): Update. (cb_file_change): Simplify. * line-map.h (LAST_SOURCE_LINE): Fix. (CURRENT_LINE_MAP): New. * gcc.dg/cpp/19951025-1.c: Revert. * gcc.dg/cpp/directiv.c: We no longer process directives that interrupt macro arguments. From-SVN: r44650
2001-08-05 19:31:25 +02:00
/* End the previous line of text. */
if (print.printed)
New macro expander. 2000-10-28 Neil Booth <neilb@earthling.net> New macro expander. * cpplib.c (struct answer): New. (struct if_stack): Use cpp_lexer_pos rather than line and col. Rename cmacro mi_cmacro. (struct directive, KANDR, STDC89, EXTENSION, COND, IF_COND, INCL, IN_I): New directive and flags. (skip_rest_of_line, check_eol, run_directive, glue_header_name, parse_answer, parse_assertion, find_answer): New functions. (parse_ifdef, detect_if_not_defined, validate_else): Remove. (lex_macro_node): New function to replace parse_ifdef and get_define_node. (_cpp_handle_directive): New function, combines _cpp_check_directive and _cpp_check_linemarker. (do_define, do_undef, parse_include, do_include, do_import, do_include_next, read_line_number, do_line, do_ident, do_pragma, do_pragma_once, do_pragma_poison, do_pragma_dependency): Update for new token getting interface. (do_ifdef, do_ifndef, do_if, do_else, do_endif, push_conditional) : Update for new multiple-include optimisation technique. (do_elif): Don't forget to invalidate controlling macros. (unwind_if_stack, cpp_defined, cpp_push_buffer, cpp_pop_buffer): Update. (parse_assertion, parse_answer, find_answer, _cpp_test_assertion): Functions to handle assertions with the new token interface. (do_assert, do_unassert): Use them. (cpp_define, _cpp_define_builtin, cpp_undef, cpp_assert, cpp_unassert): Use run_directive. (_cpp_init_stacks): Register directive names. Don't register special nodes. * cpperror.c (print_containing_files, _cpp_begin_message): Update to new position recording regime. (cpp_ice, cpp_fatal, cpp_error, cpp_error_with_line, cpp_warning, cpp_warning_with_line, cpp_pedwarn, cpp_pedwarn_with_line, cpp_pedwarn_with_file_and_line): Update for _cpp_begin_message changes. (cpp_type2name): Move to cpplex.c. * cppexp.c (parse_charconst): spec_nodes is no longer a pointer. (parse_defined): Update to handle new multiple include optimisation method. Remove poisoned identifier warning. (parse_assertion, TYPE_NAME): Delete. (lex): Update for multiple include optimisation, removal of CPP_DEFINED, to use _cpp_test_assertion for assertions and cpp_token_as_text. (_cpp_parse_expr): Update for MI optimisation, and to use op_as_text. (op_as_text): New function, to wrap cpp_token_as_text. * cppfiles.c (stack_include_file, _cpp_pop_file_buffer): Update for MI optimisation. (_cpp_execute_include): Take a token rather than 3 arguments. Fix segfault on diagnostic. (_cpp_compare_file_date): Take a token rather than 3 args. (cpp_read_file): Work correctly for zero-length files. * cpphash.c (_cpp_init_macros, _cpp_cleanup_macros): Rename _cpp_init_hashtable and _cpp_cleanup_hashtable. (cpp_lookup): Place identifiers at front of identifier pool for _cpp_lookup_with_hash. (_cpp_lookup_with_hash): Require identifiers to be at the front of the identifier pool. Commit the memory if not already in the hash table. * cppinit.c (cpp_reader_init): Move cpp_init_completed test to top. Initialise various members of cpp_reader, memory pools, and the special nodes. (cpp_printer_init): Delete. (cpp_cleanup): Update. (struct builtin, builtin_array, initialize_builtins): Update for new hashnode definition and builtin handling. (cpp_start_read, cpp_finish): Don't take or initialise a printer. Update. * cpplib.h (cpp_printer, cpp_toklist, CPP_DEFINED, BOL, PASTED, VAR_ARGS, BEG_OF_FILE, IN_DIRECTIVE, KNOWN_DIRECTIVE, T_VOID, T_SPECLINE, T_DATE, T_FILE, T_BASE_FILE, T_INCLUDE_LEVEL, T_TIME, T_STDC, T_OPERATOR, T_POISON, T_MACRO, T_ASSERTION): Delete. (struct cpp_pool, struct cpp_macro, struct cpp_lexer_pos, struct cpp_lookahead, CPP_DHASH, enum mi_state, enum mi_ind, NO_EXPAND, VARARGS_FIRST, struct cpp_token_with_pos, struct toklist, struct cpp_context, struct specnodes, TOKEN_LOOKAHEAD, TOKEN_BUFFSIZE, NODE_OPERATOR, NODE_POISONED, NODE_BUILTIN, NODE_DIAGNOSTIC, NT_VOID, NT_MACRO, NT_ASSERTION, enum builtin_type, cpp_can_paste): New. (struct cpp_token): Delete line and col members. (struct cpp_buffer): New member output_lineno. (struct lexer_state): Delete indented, in_lex_line, seen_dot. Add va_args_ok, poisoned_ok, prevent_expansion, parsing_args. (struct cpp_reader): New members lexer_pos, macro_pos, directive_pos, ident_pool, temp_string_pool, macro_pool, argument_pool, string_pool, base_context, context, directive, mi_state, mi_if_not_defined, mi_lexed, mi_cmacro, mi_ind_cmacro, la_read, la_write, la_unused, mlstring_pos, macro_buffer, macro_buffer_len. Delete members mls_line, mls_column, token_list, potential_control_macro, temp_tokens, temp_cap, temp_alloced, temp_used, first_directive_token, context_cap, cur_context, no_expand_level, paste_level, contexts, args, save_parameter_spellings, need_newline, . Change type of date, time and spec_nodes members. Change prototypes for include and ident callbacks. (struct cpp_hashnode): Change type of name. Remove union members expansion and code. Add members macro, operator and builtin. (cpp_token_len, cpp_token_as_text, cpp_spell_token, cpp_start_read, cpp_finish, cpp_avoid_paste, cpp_get_token, cpp_get_line, cpp_get_output_line, cpp_macro_definition, cpp_start_lookahead, cpp_stop_lookahead): New prototypes. (cpp_printer_init, cpp_dump_definition): Delete prototypes. (U_CHAR, U, ustrcmp, ustrncmp, ustrlen, uxstrdup, ustrchr, ufputs): Move from cpphash.h. * cpphash.h (U_CHAR, U, ustrcmp, ustrncmp, ustrlen, uxstrdup, ustrchr, ufputs): Move to cpplib.h. (enum spell_type, struct token_spelling, _cpp_token_spellings, TOKEN_SPELL, TOKEN_NAME, struct answer, FREE_ANSWER, KANDR, STDC89, EXTENSION, COND, EXPAND, INCL, COMMENTS, IN_I, struct directive, directive_handler, struct spec_nodes, _cpp_digraph_spellings, _cpp_free_temp_tokens, _cpp_init_input_buffer, _cpp_grow_token_buffer, _cpp_init_toklist, _cpp_clear_toklist, _cpp_expand_token_space, _cpp_expand_name_space, _cpp_equiv_tokens, _cpp_equiv_toklists, _cpp_process_directive, _cpp_run_directive, _cpp_get_line, _cpp_get_raw_token, _cpp_glue_header_name, _cpp_can_paste, _cpp_check_directive, _cpp_check_linemarker, _cpp_parse_assertion, _cpp_find_answer): Delete. (VALID_SIGN, ALIGN, POOL_FRONT, POOL_LIMIT, POOL_BASE, POOL_SIZE, POOL_USED, POOL_COMMIT, struct cpp_chunk, _cpp_lex_token, _cpp_init_pool, _cpp_free_pool, _cpp_pool_reserve, _cpp_pool_alloc, _cpp_next_chunk, _cpp_lock_pool, _cpp_unlock_pool, _cpp_test_assertion, _cpp_handle_directive, DSC): New. (struct include_file): New member defined. (DO_NOT_REREAD, _cpp_begin_message, _cpp_execute_include, _cpp_compare_file_date): Update. (_cpp_pop_context, _cpp_get_token, _cpp_free_lookaheads, _cpp_push_token): New. (_cpp_init_macros, _cpp_cleanup_macros): Rename to _cpp_init_hashtable, _cpp_cleanup_hashtable. * Makefile.in: Remove cppoutput.c. * cppoutput.c: Delete * fixheader.c (read_scan_file): Update for new cpp_get_token prototype. (recognized_function): New argument LINE. * scan-decls.c (skip_to_closing_brace, scan_decls): Update for new cpp_get_token prototype. * scan.h (recognized_function): Update prototype. * po/POTFILES.in: Remove cppoutput.c. From-SVN: r37098
2000-10-28 19:59:06 +02:00
{
putc ('\n', stream);
Represent column numbers using line-map's source_location. The "next available source_location" is now managed internally by line-maps.c rather than by clients. * line-map.h (struct line_map): New field column_bits. <from_line>: Rename field to start_location. (struct line_maps): New fields highest_location and max_column_hint. (linemap_check_files_exited): New declaration. (linemap_line_start): New declaration. (linemap_add): Remove from_line parameter; use highest_location field. (SOURCE_LINE, LAST_SOURCE_LINE): Modify to use column_bits. (SOURCE_COLUMN, LAST_SOURCE_LINE_LOCATION): New macros. (CURRENT_LINE_MAP): Remove macro. (linemap_position_for_column): New inline function. * line-map.c (linemap_init): Clear new fields. (linemap_check_files_exited): New function, extracted from ... (linemap_free): Use linemap_check_files_exited. (linemap_add): Remove from_line parameter. Various updates. (linemap_line_start): New function. (linemap_lookeup): Update for new field names. * cpphash.h (struct cpp_reader) <map>: Field removed. Because linemap_position_for_column may unpredictably change the current map, it is cleaner and simpler for us to not cache it in cpp_reader. (struct cpp_buffer): New sysp field. Changed warned_cplusplus_comments and from_stage3 to bitfields. * cppinit.c (cpp_read_min_file): pfile->map no longer exists. * cpplib.c (do_line, do_linemarker, _cpp_do_file_change): Get current map using linemap_lookup. (do_linemarker): Also set buffer's sysp field. (destringize_and_run): No longer need to decrement current line. * cppfiles.c (_cpp_stack_file): Set sysp from and in buffer. (search_path_head, open_file_failed): Use buffer's sysp. (cpp_make_system_header): Get current map using linemap_lookup. Also set buffer's sysp flag. * cppmacro.c (_cpp_builtin_macro_text): Likewise use linemap_lookup. * cpphash.h (CPP_INCREMENT_LINE): New macro. (struct cpp_buffer): Moved fields saved_cur, saved_rlimit to ... (struct cpp_reader): ... and adding saved_line_base field. * cpptrad.c (_cpp_overlay_buffer, _cpp_remove_overlay): Update accordingly. Don't adjust line. (_cpp_scan_out_logical_line): Use CPP_INCREMENT_LINE. * cpphash.c (CPP_IN_SYSTEM_HEADER): Replaced macro by ... (cpp_in_system_header): ... new inline function, using buffer's sysp. * cpperror.c (_cpp_begin_message): Update to use cpp_in_system_header. * cpplex.c (_cpp_lex_direct): Likewise. * cppmacro.c (_cpp_builtin_macro_text): Likewise. * cppmacro.c (_cpp_create_definition): Use buffer's sysp field. * cpplib.h (struct cpp_token): Rename line field to src_loc. Remove col field as it is now subsumed by src_loc. * cpperror.c: Update various field, parameter, and macro names. (print_location): If col==0, try SOURCE_COLUMN of line. (cpp_error): Use cur_token's src_loc field, rather than line+col. * cpplib.c (do_diagnostic): Token's src_loc fields replaces line+col. * cpplex.c (_cpp_process_line_notes, _cpp_lex_direct, _cpp_skip_block_comment): Use CPP_INCREMENT_LINE. (_cpp_temp_token): Replace cpp_token's line+col fields by src_loc. (_cpp_get_fresh_line): Don't need to adjust line for missing newline. (_cpp_lex_direct): Use linemap_position_for_column. * c-ppoutput.c (maybe_print_line, print_line): Don't take map parameter. Instead get it from the line_table global. Adjust callers. (print): Remove map field. Replace line field to src_line. (init_pp_output, account_for_newlines, maybe_print_line): Adjust. (cb_line_change): Use SOURCE_COLUMN. Minor optimizations. (pp_file_change): Use MAIN_FILE_P since we cannot checked print.map. Use LAST_SOURCE_LINE_LOCATION to "catch up" after #include. * cpptrad.c (copy_comment): Rename variable. * c-lex.c (map): Remove static variable, for same reason we removed cpp_reader's map field. (cb_line_change, cb_def_pragma, cb_define, cb_undef): Hence we need to call linemap_lookup. (cb_line_change): Token's line field replaced by src_loc. (fe_file_change): Use MAINFILE_P and LAST_SOURCE_LINE macros. Don't save new_map. * cpphash.h, cpperror.c, cpplib.h: Some renames of fileline to source_location. From-SVN: r77663
2004-02-11 16:29:30 +01:00
print.src_line++;
print.printed = false;
New macro expander. 2000-10-28 Neil Booth <neilb@earthling.net> New macro expander. * cpplib.c (struct answer): New. (struct if_stack): Use cpp_lexer_pos rather than line and col. Rename cmacro mi_cmacro. (struct directive, KANDR, STDC89, EXTENSION, COND, IF_COND, INCL, IN_I): New directive and flags. (skip_rest_of_line, check_eol, run_directive, glue_header_name, parse_answer, parse_assertion, find_answer): New functions. (parse_ifdef, detect_if_not_defined, validate_else): Remove. (lex_macro_node): New function to replace parse_ifdef and get_define_node. (_cpp_handle_directive): New function, combines _cpp_check_directive and _cpp_check_linemarker. (do_define, do_undef, parse_include, do_include, do_import, do_include_next, read_line_number, do_line, do_ident, do_pragma, do_pragma_once, do_pragma_poison, do_pragma_dependency): Update for new token getting interface. (do_ifdef, do_ifndef, do_if, do_else, do_endif, push_conditional) : Update for new multiple-include optimisation technique. (do_elif): Don't forget to invalidate controlling macros. (unwind_if_stack, cpp_defined, cpp_push_buffer, cpp_pop_buffer): Update. (parse_assertion, parse_answer, find_answer, _cpp_test_assertion): Functions to handle assertions with the new token interface. (do_assert, do_unassert): Use them. (cpp_define, _cpp_define_builtin, cpp_undef, cpp_assert, cpp_unassert): Use run_directive. (_cpp_init_stacks): Register directive names. Don't register special nodes. * cpperror.c (print_containing_files, _cpp_begin_message): Update to new position recording regime. (cpp_ice, cpp_fatal, cpp_error, cpp_error_with_line, cpp_warning, cpp_warning_with_line, cpp_pedwarn, cpp_pedwarn_with_line, cpp_pedwarn_with_file_and_line): Update for _cpp_begin_message changes. (cpp_type2name): Move to cpplex.c. * cppexp.c (parse_charconst): spec_nodes is no longer a pointer. (parse_defined): Update to handle new multiple include optimisation method. Remove poisoned identifier warning. (parse_assertion, TYPE_NAME): Delete. (lex): Update for multiple include optimisation, removal of CPP_DEFINED, to use _cpp_test_assertion for assertions and cpp_token_as_text. (_cpp_parse_expr): Update for MI optimisation, and to use op_as_text. (op_as_text): New function, to wrap cpp_token_as_text. * cppfiles.c (stack_include_file, _cpp_pop_file_buffer): Update for MI optimisation. (_cpp_execute_include): Take a token rather than 3 arguments. Fix segfault on diagnostic. (_cpp_compare_file_date): Take a token rather than 3 args. (cpp_read_file): Work correctly for zero-length files. * cpphash.c (_cpp_init_macros, _cpp_cleanup_macros): Rename _cpp_init_hashtable and _cpp_cleanup_hashtable. (cpp_lookup): Place identifiers at front of identifier pool for _cpp_lookup_with_hash. (_cpp_lookup_with_hash): Require identifiers to be at the front of the identifier pool. Commit the memory if not already in the hash table. * cppinit.c (cpp_reader_init): Move cpp_init_completed test to top. Initialise various members of cpp_reader, memory pools, and the special nodes. (cpp_printer_init): Delete. (cpp_cleanup): Update. (struct builtin, builtin_array, initialize_builtins): Update for new hashnode definition and builtin handling. (cpp_start_read, cpp_finish): Don't take or initialise a printer. Update. * cpplib.h (cpp_printer, cpp_toklist, CPP_DEFINED, BOL, PASTED, VAR_ARGS, BEG_OF_FILE, IN_DIRECTIVE, KNOWN_DIRECTIVE, T_VOID, T_SPECLINE, T_DATE, T_FILE, T_BASE_FILE, T_INCLUDE_LEVEL, T_TIME, T_STDC, T_OPERATOR, T_POISON, T_MACRO, T_ASSERTION): Delete. (struct cpp_pool, struct cpp_macro, struct cpp_lexer_pos, struct cpp_lookahead, CPP_DHASH, enum mi_state, enum mi_ind, NO_EXPAND, VARARGS_FIRST, struct cpp_token_with_pos, struct toklist, struct cpp_context, struct specnodes, TOKEN_LOOKAHEAD, TOKEN_BUFFSIZE, NODE_OPERATOR, NODE_POISONED, NODE_BUILTIN, NODE_DIAGNOSTIC, NT_VOID, NT_MACRO, NT_ASSERTION, enum builtin_type, cpp_can_paste): New. (struct cpp_token): Delete line and col members. (struct cpp_buffer): New member output_lineno. (struct lexer_state): Delete indented, in_lex_line, seen_dot. Add va_args_ok, poisoned_ok, prevent_expansion, parsing_args. (struct cpp_reader): New members lexer_pos, macro_pos, directive_pos, ident_pool, temp_string_pool, macro_pool, argument_pool, string_pool, base_context, context, directive, mi_state, mi_if_not_defined, mi_lexed, mi_cmacro, mi_ind_cmacro, la_read, la_write, la_unused, mlstring_pos, macro_buffer, macro_buffer_len. Delete members mls_line, mls_column, token_list, potential_control_macro, temp_tokens, temp_cap, temp_alloced, temp_used, first_directive_token, context_cap, cur_context, no_expand_level, paste_level, contexts, args, save_parameter_spellings, need_newline, . Change type of date, time and spec_nodes members. Change prototypes for include and ident callbacks. (struct cpp_hashnode): Change type of name. Remove union members expansion and code. Add members macro, operator and builtin. (cpp_token_len, cpp_token_as_text, cpp_spell_token, cpp_start_read, cpp_finish, cpp_avoid_paste, cpp_get_token, cpp_get_line, cpp_get_output_line, cpp_macro_definition, cpp_start_lookahead, cpp_stop_lookahead): New prototypes. (cpp_printer_init, cpp_dump_definition): Delete prototypes. (U_CHAR, U, ustrcmp, ustrncmp, ustrlen, uxstrdup, ustrchr, ufputs): Move from cpphash.h. * cpphash.h (U_CHAR, U, ustrcmp, ustrncmp, ustrlen, uxstrdup, ustrchr, ufputs): Move to cpplib.h. (enum spell_type, struct token_spelling, _cpp_token_spellings, TOKEN_SPELL, TOKEN_NAME, struct answer, FREE_ANSWER, KANDR, STDC89, EXTENSION, COND, EXPAND, INCL, COMMENTS, IN_I, struct directive, directive_handler, struct spec_nodes, _cpp_digraph_spellings, _cpp_free_temp_tokens, _cpp_init_input_buffer, _cpp_grow_token_buffer, _cpp_init_toklist, _cpp_clear_toklist, _cpp_expand_token_space, _cpp_expand_name_space, _cpp_equiv_tokens, _cpp_equiv_toklists, _cpp_process_directive, _cpp_run_directive, _cpp_get_line, _cpp_get_raw_token, _cpp_glue_header_name, _cpp_can_paste, _cpp_check_directive, _cpp_check_linemarker, _cpp_parse_assertion, _cpp_find_answer): Delete. (VALID_SIGN, ALIGN, POOL_FRONT, POOL_LIMIT, POOL_BASE, POOL_SIZE, POOL_USED, POOL_COMMIT, struct cpp_chunk, _cpp_lex_token, _cpp_init_pool, _cpp_free_pool, _cpp_pool_reserve, _cpp_pool_alloc, _cpp_next_chunk, _cpp_lock_pool, _cpp_unlock_pool, _cpp_test_assertion, _cpp_handle_directive, DSC): New. (struct include_file): New member defined. (DO_NOT_REREAD, _cpp_begin_message, _cpp_execute_include, _cpp_compare_file_date): Update. (_cpp_pop_context, _cpp_get_token, _cpp_free_lookaheads, _cpp_push_token): New. (_cpp_init_macros, _cpp_cleanup_macros): Rename to _cpp_init_hashtable, _cpp_cleanup_hashtable. * Makefile.in: Remove cppoutput.c. * cppoutput.c: Delete * fixheader.c (read_scan_file): Update for new cpp_get_token prototype. (recognized_function): New argument LINE. * scan-decls.c (skip_to_closing_brace, scan_decls): Update for new cpp_get_token prototype. * scan.h (recognized_function): Update prototype. * po/POTFILES.in: Remove cppoutput.c. From-SVN: r37098
2000-10-28 19:59:06 +02:00
}
if (!flag_no_line_commands
&& src_line >= print.src_line
&& src_line < print.src_line + 8
Linemap infrastructure for virtual locations This is the first instalment of a set which goal is to track locations of tokens across macro expansions. Tom Tromey did the original work and attached the patch to PR preprocessor/7263. This opus is a derivative of that original work. This patch modifies the linemap module of libcpp to add virtual locations support. A virtual location is a mapped location that can resolve to several different physical locations. It can always resolve to the spelling location of a token. For tokens resulting from macro expansion it can resolve to: - either the location of the expansion point of the macro. - or the location of the token in the definition of the macro - or, if the token is an argument of a function-like macro, the location of the use of the matching macro parameter in the definition of the macro The patch creates a new type of line map called a macro map. For every single macro expansion, there is a macro map that generates a virtual location for every single resulting token of the expansion. The good old type of line map we all know is now called an ordinary map. That one still encodes spelling locations as it has always had. As a result linemap_lookup as been extended to return a macro map when given a virtual location resulting from a macro expansion. The layout of structs line_map has changed to support this new type of map. So did the layout of struct line_maps. Accessor macros have been introduced to avoid messing with the implementation details of these datastructures directly. This helped already as we have been testing different ways of arranging these datastructure. Having to constantly adjust client code that is too tied with the internals of line_map and line_maps would have been even more painful. Of course, many new public functions have been added to the linemap module to handle the resolution of virtual locations. This patch introduces the infrastructure but no part of the compiler uses virtual locations yet. However the client code of the linemap data structures has been adjusted as per the changes. E.g, it's not anymore reliable for a client code to manipulate struct line_map directly if it just wants to deal with spelling locations, because struct line_map can now represent a macro map as well. In that case, it's better to use the convenient API to resolve the initial (possibly virtual) location to a spelling location (or to an ordinary map) and use that. This is the reason why the patch adjusts the Java, Ada and Fortran front ends. Also, note that virtual locations are not supposed to be ordered for relations '<' and '>' anymore. To test if a virtual location appears "before" another one, one has to use a new operator exposed by the line map interface. The patch updates the only spot (in the diagnostics module) I have found that was making the assumption that locations were ordered for these relations. This is the only change that introduces a use of the new line map API in this patch, so I am adding a regression test for it only. From-SVN: r180081
2011-10-17 11:58:56 +02:00
&& strcmp (src_file, print.src_file) == 0)
{
Represent column numbers using line-map's source_location. The "next available source_location" is now managed internally by line-maps.c rather than by clients. * line-map.h (struct line_map): New field column_bits. <from_line>: Rename field to start_location. (struct line_maps): New fields highest_location and max_column_hint. (linemap_check_files_exited): New declaration. (linemap_line_start): New declaration. (linemap_add): Remove from_line parameter; use highest_location field. (SOURCE_LINE, LAST_SOURCE_LINE): Modify to use column_bits. (SOURCE_COLUMN, LAST_SOURCE_LINE_LOCATION): New macros. (CURRENT_LINE_MAP): Remove macro. (linemap_position_for_column): New inline function. * line-map.c (linemap_init): Clear new fields. (linemap_check_files_exited): New function, extracted from ... (linemap_free): Use linemap_check_files_exited. (linemap_add): Remove from_line parameter. Various updates. (linemap_line_start): New function. (linemap_lookeup): Update for new field names. * cpphash.h (struct cpp_reader) <map>: Field removed. Because linemap_position_for_column may unpredictably change the current map, it is cleaner and simpler for us to not cache it in cpp_reader. (struct cpp_buffer): New sysp field. Changed warned_cplusplus_comments and from_stage3 to bitfields. * cppinit.c (cpp_read_min_file): pfile->map no longer exists. * cpplib.c (do_line, do_linemarker, _cpp_do_file_change): Get current map using linemap_lookup. (do_linemarker): Also set buffer's sysp field. (destringize_and_run): No longer need to decrement current line. * cppfiles.c (_cpp_stack_file): Set sysp from and in buffer. (search_path_head, open_file_failed): Use buffer's sysp. (cpp_make_system_header): Get current map using linemap_lookup. Also set buffer's sysp flag. * cppmacro.c (_cpp_builtin_macro_text): Likewise use linemap_lookup. * cpphash.h (CPP_INCREMENT_LINE): New macro. (struct cpp_buffer): Moved fields saved_cur, saved_rlimit to ... (struct cpp_reader): ... and adding saved_line_base field. * cpptrad.c (_cpp_overlay_buffer, _cpp_remove_overlay): Update accordingly. Don't adjust line. (_cpp_scan_out_logical_line): Use CPP_INCREMENT_LINE. * cpphash.c (CPP_IN_SYSTEM_HEADER): Replaced macro by ... (cpp_in_system_header): ... new inline function, using buffer's sysp. * cpperror.c (_cpp_begin_message): Update to use cpp_in_system_header. * cpplex.c (_cpp_lex_direct): Likewise. * cppmacro.c (_cpp_builtin_macro_text): Likewise. * cppmacro.c (_cpp_create_definition): Use buffer's sysp field. * cpplib.h (struct cpp_token): Rename line field to src_loc. Remove col field as it is now subsumed by src_loc. * cpperror.c: Update various field, parameter, and macro names. (print_location): If col==0, try SOURCE_COLUMN of line. (cpp_error): Use cur_token's src_loc field, rather than line+col. * cpplib.c (do_diagnostic): Token's src_loc fields replaces line+col. * cpplex.c (_cpp_process_line_notes, _cpp_lex_direct, _cpp_skip_block_comment): Use CPP_INCREMENT_LINE. (_cpp_temp_token): Replace cpp_token's line+col fields by src_loc. (_cpp_get_fresh_line): Don't need to adjust line for missing newline. (_cpp_lex_direct): Use linemap_position_for_column. * c-ppoutput.c (maybe_print_line, print_line): Don't take map parameter. Instead get it from the line_table global. Adjust callers. (print): Remove map field. Replace line field to src_line. (init_pp_output, account_for_newlines, maybe_print_line): Adjust. (cb_line_change): Use SOURCE_COLUMN. Minor optimizations. (pp_file_change): Use MAIN_FILE_P since we cannot checked print.map. Use LAST_SOURCE_LINE_LOCATION to "catch up" after #include. * cpptrad.c (copy_comment): Rename variable. * c-lex.c (map): Remove static variable, for same reason we removed cpp_reader's map field. (cb_line_change, cb_def_pragma, cb_define, cb_undef): Hence we need to call linemap_lookup. (cb_line_change): Token's line field replaced by src_loc. (fe_file_change): Use MAINFILE_P and LAST_SOURCE_LINE macros. Don't save new_map. * cpphash.h, cpperror.c, cpplib.h: Some renames of fileline to source_location. From-SVN: r77663
2004-02-11 16:29:30 +01:00
while (src_line > print.src_line)
New macro expander. 2000-10-28 Neil Booth <neilb@earthling.net> New macro expander. * cpplib.c (struct answer): New. (struct if_stack): Use cpp_lexer_pos rather than line and col. Rename cmacro mi_cmacro. (struct directive, KANDR, STDC89, EXTENSION, COND, IF_COND, INCL, IN_I): New directive and flags. (skip_rest_of_line, check_eol, run_directive, glue_header_name, parse_answer, parse_assertion, find_answer): New functions. (parse_ifdef, detect_if_not_defined, validate_else): Remove. (lex_macro_node): New function to replace parse_ifdef and get_define_node. (_cpp_handle_directive): New function, combines _cpp_check_directive and _cpp_check_linemarker. (do_define, do_undef, parse_include, do_include, do_import, do_include_next, read_line_number, do_line, do_ident, do_pragma, do_pragma_once, do_pragma_poison, do_pragma_dependency): Update for new token getting interface. (do_ifdef, do_ifndef, do_if, do_else, do_endif, push_conditional) : Update for new multiple-include optimisation technique. (do_elif): Don't forget to invalidate controlling macros. (unwind_if_stack, cpp_defined, cpp_push_buffer, cpp_pop_buffer): Update. (parse_assertion, parse_answer, find_answer, _cpp_test_assertion): Functions to handle assertions with the new token interface. (do_assert, do_unassert): Use them. (cpp_define, _cpp_define_builtin, cpp_undef, cpp_assert, cpp_unassert): Use run_directive. (_cpp_init_stacks): Register directive names. Don't register special nodes. * cpperror.c (print_containing_files, _cpp_begin_message): Update to new position recording regime. (cpp_ice, cpp_fatal, cpp_error, cpp_error_with_line, cpp_warning, cpp_warning_with_line, cpp_pedwarn, cpp_pedwarn_with_line, cpp_pedwarn_with_file_and_line): Update for _cpp_begin_message changes. (cpp_type2name): Move to cpplex.c. * cppexp.c (parse_charconst): spec_nodes is no longer a pointer. (parse_defined): Update to handle new multiple include optimisation method. Remove poisoned identifier warning. (parse_assertion, TYPE_NAME): Delete. (lex): Update for multiple include optimisation, removal of CPP_DEFINED, to use _cpp_test_assertion for assertions and cpp_token_as_text. (_cpp_parse_expr): Update for MI optimisation, and to use op_as_text. (op_as_text): New function, to wrap cpp_token_as_text. * cppfiles.c (stack_include_file, _cpp_pop_file_buffer): Update for MI optimisation. (_cpp_execute_include): Take a token rather than 3 arguments. Fix segfault on diagnostic. (_cpp_compare_file_date): Take a token rather than 3 args. (cpp_read_file): Work correctly for zero-length files. * cpphash.c (_cpp_init_macros, _cpp_cleanup_macros): Rename _cpp_init_hashtable and _cpp_cleanup_hashtable. (cpp_lookup): Place identifiers at front of identifier pool for _cpp_lookup_with_hash. (_cpp_lookup_with_hash): Require identifiers to be at the front of the identifier pool. Commit the memory if not already in the hash table. * cppinit.c (cpp_reader_init): Move cpp_init_completed test to top. Initialise various members of cpp_reader, memory pools, and the special nodes. (cpp_printer_init): Delete. (cpp_cleanup): Update. (struct builtin, builtin_array, initialize_builtins): Update for new hashnode definition and builtin handling. (cpp_start_read, cpp_finish): Don't take or initialise a printer. Update. * cpplib.h (cpp_printer, cpp_toklist, CPP_DEFINED, BOL, PASTED, VAR_ARGS, BEG_OF_FILE, IN_DIRECTIVE, KNOWN_DIRECTIVE, T_VOID, T_SPECLINE, T_DATE, T_FILE, T_BASE_FILE, T_INCLUDE_LEVEL, T_TIME, T_STDC, T_OPERATOR, T_POISON, T_MACRO, T_ASSERTION): Delete. (struct cpp_pool, struct cpp_macro, struct cpp_lexer_pos, struct cpp_lookahead, CPP_DHASH, enum mi_state, enum mi_ind, NO_EXPAND, VARARGS_FIRST, struct cpp_token_with_pos, struct toklist, struct cpp_context, struct specnodes, TOKEN_LOOKAHEAD, TOKEN_BUFFSIZE, NODE_OPERATOR, NODE_POISONED, NODE_BUILTIN, NODE_DIAGNOSTIC, NT_VOID, NT_MACRO, NT_ASSERTION, enum builtin_type, cpp_can_paste): New. (struct cpp_token): Delete line and col members. (struct cpp_buffer): New member output_lineno. (struct lexer_state): Delete indented, in_lex_line, seen_dot. Add va_args_ok, poisoned_ok, prevent_expansion, parsing_args. (struct cpp_reader): New members lexer_pos, macro_pos, directive_pos, ident_pool, temp_string_pool, macro_pool, argument_pool, string_pool, base_context, context, directive, mi_state, mi_if_not_defined, mi_lexed, mi_cmacro, mi_ind_cmacro, la_read, la_write, la_unused, mlstring_pos, macro_buffer, macro_buffer_len. Delete members mls_line, mls_column, token_list, potential_control_macro, temp_tokens, temp_cap, temp_alloced, temp_used, first_directive_token, context_cap, cur_context, no_expand_level, paste_level, contexts, args, save_parameter_spellings, need_newline, . Change type of date, time and spec_nodes members. Change prototypes for include and ident callbacks. (struct cpp_hashnode): Change type of name. Remove union members expansion and code. Add members macro, operator and builtin. (cpp_token_len, cpp_token_as_text, cpp_spell_token, cpp_start_read, cpp_finish, cpp_avoid_paste, cpp_get_token, cpp_get_line, cpp_get_output_line, cpp_macro_definition, cpp_start_lookahead, cpp_stop_lookahead): New prototypes. (cpp_printer_init, cpp_dump_definition): Delete prototypes. (U_CHAR, U, ustrcmp, ustrncmp, ustrlen, uxstrdup, ustrchr, ufputs): Move from cpphash.h. * cpphash.h (U_CHAR, U, ustrcmp, ustrncmp, ustrlen, uxstrdup, ustrchr, ufputs): Move to cpplib.h. (enum spell_type, struct token_spelling, _cpp_token_spellings, TOKEN_SPELL, TOKEN_NAME, struct answer, FREE_ANSWER, KANDR, STDC89, EXTENSION, COND, EXPAND, INCL, COMMENTS, IN_I, struct directive, directive_handler, struct spec_nodes, _cpp_digraph_spellings, _cpp_free_temp_tokens, _cpp_init_input_buffer, _cpp_grow_token_buffer, _cpp_init_toklist, _cpp_clear_toklist, _cpp_expand_token_space, _cpp_expand_name_space, _cpp_equiv_tokens, _cpp_equiv_toklists, _cpp_process_directive, _cpp_run_directive, _cpp_get_line, _cpp_get_raw_token, _cpp_glue_header_name, _cpp_can_paste, _cpp_check_directive, _cpp_check_linemarker, _cpp_parse_assertion, _cpp_find_answer): Delete. (VALID_SIGN, ALIGN, POOL_FRONT, POOL_LIMIT, POOL_BASE, POOL_SIZE, POOL_USED, POOL_COMMIT, struct cpp_chunk, _cpp_lex_token, _cpp_init_pool, _cpp_free_pool, _cpp_pool_reserve, _cpp_pool_alloc, _cpp_next_chunk, _cpp_lock_pool, _cpp_unlock_pool, _cpp_test_assertion, _cpp_handle_directive, DSC): New. (struct include_file): New member defined. (DO_NOT_REREAD, _cpp_begin_message, _cpp_execute_include, _cpp_compare_file_date): Update. (_cpp_pop_context, _cpp_get_token, _cpp_free_lookaheads, _cpp_push_token): New. (_cpp_init_macros, _cpp_cleanup_macros): Rename to _cpp_init_hashtable, _cpp_cleanup_hashtable. * Makefile.in: Remove cppoutput.c. * cppoutput.c: Delete * fixheader.c (read_scan_file): Update for new cpp_get_token prototype. (recognized_function): New argument LINE. * scan-decls.c (skip_to_closing_brace, scan_decls): Update for new cpp_get_token prototype. * scan.h (recognized_function): Update prototype. * po/POTFILES.in: Remove cppoutput.c. From-SVN: r37098
2000-10-28 19:59:06 +02:00
{
putc ('\n', stream);
Represent column numbers using line-map's source_location. The "next available source_location" is now managed internally by line-maps.c rather than by clients. * line-map.h (struct line_map): New field column_bits. <from_line>: Rename field to start_location. (struct line_maps): New fields highest_location and max_column_hint. (linemap_check_files_exited): New declaration. (linemap_line_start): New declaration. (linemap_add): Remove from_line parameter; use highest_location field. (SOURCE_LINE, LAST_SOURCE_LINE): Modify to use column_bits. (SOURCE_COLUMN, LAST_SOURCE_LINE_LOCATION): New macros. (CURRENT_LINE_MAP): Remove macro. (linemap_position_for_column): New inline function. * line-map.c (linemap_init): Clear new fields. (linemap_check_files_exited): New function, extracted from ... (linemap_free): Use linemap_check_files_exited. (linemap_add): Remove from_line parameter. Various updates. (linemap_line_start): New function. (linemap_lookeup): Update for new field names. * cpphash.h (struct cpp_reader) <map>: Field removed. Because linemap_position_for_column may unpredictably change the current map, it is cleaner and simpler for us to not cache it in cpp_reader. (struct cpp_buffer): New sysp field. Changed warned_cplusplus_comments and from_stage3 to bitfields. * cppinit.c (cpp_read_min_file): pfile->map no longer exists. * cpplib.c (do_line, do_linemarker, _cpp_do_file_change): Get current map using linemap_lookup. (do_linemarker): Also set buffer's sysp field. (destringize_and_run): No longer need to decrement current line. * cppfiles.c (_cpp_stack_file): Set sysp from and in buffer. (search_path_head, open_file_failed): Use buffer's sysp. (cpp_make_system_header): Get current map using linemap_lookup. Also set buffer's sysp flag. * cppmacro.c (_cpp_builtin_macro_text): Likewise use linemap_lookup. * cpphash.h (CPP_INCREMENT_LINE): New macro. (struct cpp_buffer): Moved fields saved_cur, saved_rlimit to ... (struct cpp_reader): ... and adding saved_line_base field. * cpptrad.c (_cpp_overlay_buffer, _cpp_remove_overlay): Update accordingly. Don't adjust line. (_cpp_scan_out_logical_line): Use CPP_INCREMENT_LINE. * cpphash.c (CPP_IN_SYSTEM_HEADER): Replaced macro by ... (cpp_in_system_header): ... new inline function, using buffer's sysp. * cpperror.c (_cpp_begin_message): Update to use cpp_in_system_header. * cpplex.c (_cpp_lex_direct): Likewise. * cppmacro.c (_cpp_builtin_macro_text): Likewise. * cppmacro.c (_cpp_create_definition): Use buffer's sysp field. * cpplib.h (struct cpp_token): Rename line field to src_loc. Remove col field as it is now subsumed by src_loc. * cpperror.c: Update various field, parameter, and macro names. (print_location): If col==0, try SOURCE_COLUMN of line. (cpp_error): Use cur_token's src_loc field, rather than line+col. * cpplib.c (do_diagnostic): Token's src_loc fields replaces line+col. * cpplex.c (_cpp_process_line_notes, _cpp_lex_direct, _cpp_skip_block_comment): Use CPP_INCREMENT_LINE. (_cpp_temp_token): Replace cpp_token's line+col fields by src_loc. (_cpp_get_fresh_line): Don't need to adjust line for missing newline. (_cpp_lex_direct): Use linemap_position_for_column. * c-ppoutput.c (maybe_print_line, print_line): Don't take map parameter. Instead get it from the line_table global. Adjust callers. (print): Remove map field. Replace line field to src_line. (init_pp_output, account_for_newlines, maybe_print_line): Adjust. (cb_line_change): Use SOURCE_COLUMN. Minor optimizations. (pp_file_change): Use MAIN_FILE_P since we cannot checked print.map. Use LAST_SOURCE_LINE_LOCATION to "catch up" after #include. * cpptrad.c (copy_comment): Rename variable. * c-lex.c (map): Remove static variable, for same reason we removed cpp_reader's map field. (cb_line_change, cb_def_pragma, cb_define, cb_undef): Hence we need to call linemap_lookup. (cb_line_change): Token's line field replaced by src_loc. (fe_file_change): Use MAINFILE_P and LAST_SOURCE_LINE macros. Don't save new_map. * cpphash.h, cpperror.c, cpplib.h: Some renames of fileline to source_location. From-SVN: r77663
2004-02-11 16:29:30 +01:00
print.src_line++;
New macro expander. 2000-10-28 Neil Booth <neilb@earthling.net> New macro expander. * cpplib.c (struct answer): New. (struct if_stack): Use cpp_lexer_pos rather than line and col. Rename cmacro mi_cmacro. (struct directive, KANDR, STDC89, EXTENSION, COND, IF_COND, INCL, IN_I): New directive and flags. (skip_rest_of_line, check_eol, run_directive, glue_header_name, parse_answer, parse_assertion, find_answer): New functions. (parse_ifdef, detect_if_not_defined, validate_else): Remove. (lex_macro_node): New function to replace parse_ifdef and get_define_node. (_cpp_handle_directive): New function, combines _cpp_check_directive and _cpp_check_linemarker. (do_define, do_undef, parse_include, do_include, do_import, do_include_next, read_line_number, do_line, do_ident, do_pragma, do_pragma_once, do_pragma_poison, do_pragma_dependency): Update for new token getting interface. (do_ifdef, do_ifndef, do_if, do_else, do_endif, push_conditional) : Update for new multiple-include optimisation technique. (do_elif): Don't forget to invalidate controlling macros. (unwind_if_stack, cpp_defined, cpp_push_buffer, cpp_pop_buffer): Update. (parse_assertion, parse_answer, find_answer, _cpp_test_assertion): Functions to handle assertions with the new token interface. (do_assert, do_unassert): Use them. (cpp_define, _cpp_define_builtin, cpp_undef, cpp_assert, cpp_unassert): Use run_directive. (_cpp_init_stacks): Register directive names. Don't register special nodes. * cpperror.c (print_containing_files, _cpp_begin_message): Update to new position recording regime. (cpp_ice, cpp_fatal, cpp_error, cpp_error_with_line, cpp_warning, cpp_warning_with_line, cpp_pedwarn, cpp_pedwarn_with_line, cpp_pedwarn_with_file_and_line): Update for _cpp_begin_message changes. (cpp_type2name): Move to cpplex.c. * cppexp.c (parse_charconst): spec_nodes is no longer a pointer. (parse_defined): Update to handle new multiple include optimisation method. Remove poisoned identifier warning. (parse_assertion, TYPE_NAME): Delete. (lex): Update for multiple include optimisation, removal of CPP_DEFINED, to use _cpp_test_assertion for assertions and cpp_token_as_text. (_cpp_parse_expr): Update for MI optimisation, and to use op_as_text. (op_as_text): New function, to wrap cpp_token_as_text. * cppfiles.c (stack_include_file, _cpp_pop_file_buffer): Update for MI optimisation. (_cpp_execute_include): Take a token rather than 3 arguments. Fix segfault on diagnostic. (_cpp_compare_file_date): Take a token rather than 3 args. (cpp_read_file): Work correctly for zero-length files. * cpphash.c (_cpp_init_macros, _cpp_cleanup_macros): Rename _cpp_init_hashtable and _cpp_cleanup_hashtable. (cpp_lookup): Place identifiers at front of identifier pool for _cpp_lookup_with_hash. (_cpp_lookup_with_hash): Require identifiers to be at the front of the identifier pool. Commit the memory if not already in the hash table. * cppinit.c (cpp_reader_init): Move cpp_init_completed test to top. Initialise various members of cpp_reader, memory pools, and the special nodes. (cpp_printer_init): Delete. (cpp_cleanup): Update. (struct builtin, builtin_array, initialize_builtins): Update for new hashnode definition and builtin handling. (cpp_start_read, cpp_finish): Don't take or initialise a printer. Update. * cpplib.h (cpp_printer, cpp_toklist, CPP_DEFINED, BOL, PASTED, VAR_ARGS, BEG_OF_FILE, IN_DIRECTIVE, KNOWN_DIRECTIVE, T_VOID, T_SPECLINE, T_DATE, T_FILE, T_BASE_FILE, T_INCLUDE_LEVEL, T_TIME, T_STDC, T_OPERATOR, T_POISON, T_MACRO, T_ASSERTION): Delete. (struct cpp_pool, struct cpp_macro, struct cpp_lexer_pos, struct cpp_lookahead, CPP_DHASH, enum mi_state, enum mi_ind, NO_EXPAND, VARARGS_FIRST, struct cpp_token_with_pos, struct toklist, struct cpp_context, struct specnodes, TOKEN_LOOKAHEAD, TOKEN_BUFFSIZE, NODE_OPERATOR, NODE_POISONED, NODE_BUILTIN, NODE_DIAGNOSTIC, NT_VOID, NT_MACRO, NT_ASSERTION, enum builtin_type, cpp_can_paste): New. (struct cpp_token): Delete line and col members. (struct cpp_buffer): New member output_lineno. (struct lexer_state): Delete indented, in_lex_line, seen_dot. Add va_args_ok, poisoned_ok, prevent_expansion, parsing_args. (struct cpp_reader): New members lexer_pos, macro_pos, directive_pos, ident_pool, temp_string_pool, macro_pool, argument_pool, string_pool, base_context, context, directive, mi_state, mi_if_not_defined, mi_lexed, mi_cmacro, mi_ind_cmacro, la_read, la_write, la_unused, mlstring_pos, macro_buffer, macro_buffer_len. Delete members mls_line, mls_column, token_list, potential_control_macro, temp_tokens, temp_cap, temp_alloced, temp_used, first_directive_token, context_cap, cur_context, no_expand_level, paste_level, contexts, args, save_parameter_spellings, need_newline, . Change type of date, time and spec_nodes members. Change prototypes for include and ident callbacks. (struct cpp_hashnode): Change type of name. Remove union members expansion and code. Add members macro, operator and builtin. (cpp_token_len, cpp_token_as_text, cpp_spell_token, cpp_start_read, cpp_finish, cpp_avoid_paste, cpp_get_token, cpp_get_line, cpp_get_output_line, cpp_macro_definition, cpp_start_lookahead, cpp_stop_lookahead): New prototypes. (cpp_printer_init, cpp_dump_definition): Delete prototypes. (U_CHAR, U, ustrcmp, ustrncmp, ustrlen, uxstrdup, ustrchr, ufputs): Move from cpphash.h. * cpphash.h (U_CHAR, U, ustrcmp, ustrncmp, ustrlen, uxstrdup, ustrchr, ufputs): Move to cpplib.h. (enum spell_type, struct token_spelling, _cpp_token_spellings, TOKEN_SPELL, TOKEN_NAME, struct answer, FREE_ANSWER, KANDR, STDC89, EXTENSION, COND, EXPAND, INCL, COMMENTS, IN_I, struct directive, directive_handler, struct spec_nodes, _cpp_digraph_spellings, _cpp_free_temp_tokens, _cpp_init_input_buffer, _cpp_grow_token_buffer, _cpp_init_toklist, _cpp_clear_toklist, _cpp_expand_token_space, _cpp_expand_name_space, _cpp_equiv_tokens, _cpp_equiv_toklists, _cpp_process_directive, _cpp_run_directive, _cpp_get_line, _cpp_get_raw_token, _cpp_glue_header_name, _cpp_can_paste, _cpp_check_directive, _cpp_check_linemarker, _cpp_parse_assertion, _cpp_find_answer): Delete. (VALID_SIGN, ALIGN, POOL_FRONT, POOL_LIMIT, POOL_BASE, POOL_SIZE, POOL_USED, POOL_COMMIT, struct cpp_chunk, _cpp_lex_token, _cpp_init_pool, _cpp_free_pool, _cpp_pool_reserve, _cpp_pool_alloc, _cpp_next_chunk, _cpp_lock_pool, _cpp_unlock_pool, _cpp_test_assertion, _cpp_handle_directive, DSC): New. (struct include_file): New member defined. (DO_NOT_REREAD, _cpp_begin_message, _cpp_execute_include, _cpp_compare_file_date): Update. (_cpp_pop_context, _cpp_get_token, _cpp_free_lookaheads, _cpp_push_token): New. (_cpp_init_macros, _cpp_cleanup_macros): Rename to _cpp_init_hashtable, _cpp_cleanup_hashtable. * Makefile.in: Remove cppoutput.c. * cppoutput.c: Delete * fixheader.c (read_scan_file): Update for new cpp_get_token prototype. (recognized_function): New argument LINE. * scan-decls.c (skip_to_closing_brace, scan_decls): Update for new cpp_get_token prototype. * scan.h (recognized_function): Update prototype. * po/POTFILES.in: Remove cppoutput.c. From-SVN: r37098
2000-10-28 19:59:06 +02:00
}
}
else
PR preprocessor/60723 - missing system-ness marks for macro tokens When a system macro is expanded in a non-system file during out-of-line preprocessing, it can happen that the preprocessor forgets to emit line markers to express the system-ness status of tokens that come after the expansion of the macro. That can lead to situations where the entire non-system file can be considered as being a system file and thus have its warnings be discarded during the compilation of the resulting preprocessed file. My understanding is that this is due to the preprocessor not systematically detecting (and reporting) the change in system-ness of tokens. And this is what this patch does. Each time the system-ness of a given token is different from the previous token that was emitted by the preprocessor, it emits a line marker for the sole purpose of marking the new system-ness of the subsequent tokens to come. Bootstrapped and tested on x86_64-unknown-linux-gnu against trunk. gcc/c-family/ChangeLog: * c-ppoutput.c (struct print::prev_was_system_token): New data member. (init_pp_output): Initialize it. (maybe_print_line_1, maybe_print_line, print_line_1, print_line) (do_line_change): Return a flag saying if a line marker was emitted or not. (scan_translation_unit): Detect if the system-ness of the token we are about to emit is different from the one of the previously emitted token. If so, emit a line marker. Avoid emitting useless adjacent line markers. Avoid emitting line markers for tokens originating from the expansion of built-in macros. (scan_translation_unit_directives_only): Adjust. gcc/testsuite/ChangeLog: * gcc.dg/cpp/syshdr{4,5}.{c,h}: New test files. Signed-off-by: Dodji Seketeli <dodji@redhat.com> Signed-off-by: Dodji Seketeli <dodji@redhat.com> From-SVN: r212638
2014-07-16 12:33:36 +02:00
emitted_line_marker = print_line_1 (src_loc, "", stream);
PR preprocessor/60723 - missing system-ness marks for macro tokens When a system macro is expanded in a non-system file during out-of-line preprocessing, it can happen that the preprocessor forgets to emit line markers to express the system-ness status of tokens that come after the expansion of the macro. That can lead to situations where the entire non-system file can be considered as being a system file and thus have its warnings be discarded during the compilation of the resulting preprocessed file. My understanding is that this is due to the preprocessor not systematically detecting (and reporting) the change in system-ness of tokens. And this is what this patch does. Each time the system-ness of a given token is different from the previous token that was emitted by the preprocessor, it emits a line marker for the sole purpose of marking the new system-ness of the subsequent tokens to come. Bootstrapped and tested on x86_64-unknown-linux-gnu against trunk. gcc/c-family/ChangeLog: * c-ppoutput.c (struct print::prev_was_system_token): New data member. (init_pp_output): Initialize it. (maybe_print_line_1, maybe_print_line, print_line_1, print_line) (do_line_change): Return a flag saying if a line marker was emitted or not. (scan_translation_unit): Detect if the system-ness of the token we are about to emit is different from the one of the previously emitted token. If so, emit a line marker. Avoid emitting useless adjacent line markers. Avoid emitting line markers for tokens originating from the expansion of built-in macros. (scan_translation_unit_directives_only): Adjust. gcc/testsuite/ChangeLog: * gcc.dg/cpp/syshdr{4,5}.{c,h}: New test files. Signed-off-by: Dodji Seketeli <dodji@redhat.com> Signed-off-by: Dodji Seketeli <dodji@redhat.com> From-SVN: r212638
2014-07-16 12:33:36 +02:00
return emitted_line_marker;
}
/* If the token read on logical line LINE needs to be output on a
different line to the current one, output the required newlines or
PR preprocessor/60723 - missing system-ness marks for macro tokens When a system macro is expanded in a non-system file during out-of-line preprocessing, it can happen that the preprocessor forgets to emit line markers to express the system-ness status of tokens that come after the expansion of the macro. That can lead to situations where the entire non-system file can be considered as being a system file and thus have its warnings be discarded during the compilation of the resulting preprocessed file. My understanding is that this is due to the preprocessor not systematically detecting (and reporting) the change in system-ness of tokens. And this is what this patch does. Each time the system-ness of a given token is different from the previous token that was emitted by the preprocessor, it emits a line marker for the sole purpose of marking the new system-ness of the subsequent tokens to come. Bootstrapped and tested on x86_64-unknown-linux-gnu against trunk. gcc/c-family/ChangeLog: * c-ppoutput.c (struct print::prev_was_system_token): New data member. (init_pp_output): Initialize it. (maybe_print_line_1, maybe_print_line, print_line_1, print_line) (do_line_change): Return a flag saying if a line marker was emitted or not. (scan_translation_unit): Detect if the system-ness of the token we are about to emit is different from the one of the previously emitted token. If so, emit a line marker. Avoid emitting useless adjacent line markers. Avoid emitting line markers for tokens originating from the expansion of built-in macros. (scan_translation_unit_directives_only): Adjust. gcc/testsuite/ChangeLog: * gcc.dg/cpp/syshdr{4,5}.{c,h}: New test files. Signed-off-by: Dodji Seketeli <dodji@redhat.com> Signed-off-by: Dodji Seketeli <dodji@redhat.com> From-SVN: r212638
2014-07-16 12:33:36 +02:00
a line marker. If a line marker was emitted, return TRUE otherwise
return FALSE. */
PR preprocessor/60723 - missing system-ness marks for macro tokens When a system macro is expanded in a non-system file during out-of-line preprocessing, it can happen that the preprocessor forgets to emit line markers to express the system-ness status of tokens that come after the expansion of the macro. That can lead to situations where the entire non-system file can be considered as being a system file and thus have its warnings be discarded during the compilation of the resulting preprocessed file. My understanding is that this is due to the preprocessor not systematically detecting (and reporting) the change in system-ness of tokens. And this is what this patch does. Each time the system-ness of a given token is different from the previous token that was emitted by the preprocessor, it emits a line marker for the sole purpose of marking the new system-ness of the subsequent tokens to come. Bootstrapped and tested on x86_64-unknown-linux-gnu against trunk. gcc/c-family/ChangeLog: * c-ppoutput.c (struct print::prev_was_system_token): New data member. (init_pp_output): Initialize it. (maybe_print_line_1, maybe_print_line, print_line_1, print_line) (do_line_change): Return a flag saying if a line marker was emitted or not. (scan_translation_unit): Detect if the system-ness of the token we are about to emit is different from the one of the previously emitted token. If so, emit a line marker. Avoid emitting useless adjacent line markers. Avoid emitting line markers for tokens originating from the expansion of built-in macros. (scan_translation_unit_directives_only): Adjust. gcc/testsuite/ChangeLog: * gcc.dg/cpp/syshdr{4,5}.{c,h}: New test files. Signed-off-by: Dodji Seketeli <dodji@redhat.com> Signed-off-by: Dodji Seketeli <dodji@redhat.com> From-SVN: r212638
2014-07-16 12:33:36 +02:00
static bool
maybe_print_line (source_location src_loc)
{
if (cpp_get_options (parse_in)->debug)
linemap_dump_location (line_table, src_loc,
print.outf);
PR preprocessor/60723 - missing system-ness marks for macro tokens When a system macro is expanded in a non-system file during out-of-line preprocessing, it can happen that the preprocessor forgets to emit line markers to express the system-ness status of tokens that come after the expansion of the macro. That can lead to situations where the entire non-system file can be considered as being a system file and thus have its warnings be discarded during the compilation of the resulting preprocessed file. My understanding is that this is due to the preprocessor not systematically detecting (and reporting) the change in system-ness of tokens. And this is what this patch does. Each time the system-ness of a given token is different from the previous token that was emitted by the preprocessor, it emits a line marker for the sole purpose of marking the new system-ness of the subsequent tokens to come. Bootstrapped and tested on x86_64-unknown-linux-gnu against trunk. gcc/c-family/ChangeLog: * c-ppoutput.c (struct print::prev_was_system_token): New data member. (init_pp_output): Initialize it. (maybe_print_line_1, maybe_print_line, print_line_1, print_line) (do_line_change): Return a flag saying if a line marker was emitted or not. (scan_translation_unit): Detect if the system-ness of the token we are about to emit is different from the one of the previously emitted token. If so, emit a line marker. Avoid emitting useless adjacent line markers. Avoid emitting line markers for tokens originating from the expansion of built-in macros. (scan_translation_unit_directives_only): Adjust. gcc/testsuite/ChangeLog: * gcc.dg/cpp/syshdr{4,5}.{c,h}: New test files. Signed-off-by: Dodji Seketeli <dodji@redhat.com> Signed-off-by: Dodji Seketeli <dodji@redhat.com> From-SVN: r212638
2014-07-16 12:33:36 +02:00
return maybe_print_line_1 (src_loc, print.outf);
New macro expander. 2000-10-28 Neil Booth <neilb@earthling.net> New macro expander. * cpplib.c (struct answer): New. (struct if_stack): Use cpp_lexer_pos rather than line and col. Rename cmacro mi_cmacro. (struct directive, KANDR, STDC89, EXTENSION, COND, IF_COND, INCL, IN_I): New directive and flags. (skip_rest_of_line, check_eol, run_directive, glue_header_name, parse_answer, parse_assertion, find_answer): New functions. (parse_ifdef, detect_if_not_defined, validate_else): Remove. (lex_macro_node): New function to replace parse_ifdef and get_define_node. (_cpp_handle_directive): New function, combines _cpp_check_directive and _cpp_check_linemarker. (do_define, do_undef, parse_include, do_include, do_import, do_include_next, read_line_number, do_line, do_ident, do_pragma, do_pragma_once, do_pragma_poison, do_pragma_dependency): Update for new token getting interface. (do_ifdef, do_ifndef, do_if, do_else, do_endif, push_conditional) : Update for new multiple-include optimisation technique. (do_elif): Don't forget to invalidate controlling macros. (unwind_if_stack, cpp_defined, cpp_push_buffer, cpp_pop_buffer): Update. (parse_assertion, parse_answer, find_answer, _cpp_test_assertion): Functions to handle assertions with the new token interface. (do_assert, do_unassert): Use them. (cpp_define, _cpp_define_builtin, cpp_undef, cpp_assert, cpp_unassert): Use run_directive. (_cpp_init_stacks): Register directive names. Don't register special nodes. * cpperror.c (print_containing_files, _cpp_begin_message): Update to new position recording regime. (cpp_ice, cpp_fatal, cpp_error, cpp_error_with_line, cpp_warning, cpp_warning_with_line, cpp_pedwarn, cpp_pedwarn_with_line, cpp_pedwarn_with_file_and_line): Update for _cpp_begin_message changes. (cpp_type2name): Move to cpplex.c. * cppexp.c (parse_charconst): spec_nodes is no longer a pointer. (parse_defined): Update to handle new multiple include optimisation method. Remove poisoned identifier warning. (parse_assertion, TYPE_NAME): Delete. (lex): Update for multiple include optimisation, removal of CPP_DEFINED, to use _cpp_test_assertion for assertions and cpp_token_as_text. (_cpp_parse_expr): Update for MI optimisation, and to use op_as_text. (op_as_text): New function, to wrap cpp_token_as_text. * cppfiles.c (stack_include_file, _cpp_pop_file_buffer): Update for MI optimisation. (_cpp_execute_include): Take a token rather than 3 arguments. Fix segfault on diagnostic. (_cpp_compare_file_date): Take a token rather than 3 args. (cpp_read_file): Work correctly for zero-length files. * cpphash.c (_cpp_init_macros, _cpp_cleanup_macros): Rename _cpp_init_hashtable and _cpp_cleanup_hashtable. (cpp_lookup): Place identifiers at front of identifier pool for _cpp_lookup_with_hash. (_cpp_lookup_with_hash): Require identifiers to be at the front of the identifier pool. Commit the memory if not already in the hash table. * cppinit.c (cpp_reader_init): Move cpp_init_completed test to top. Initialise various members of cpp_reader, memory pools, and the special nodes. (cpp_printer_init): Delete. (cpp_cleanup): Update. (struct builtin, builtin_array, initialize_builtins): Update for new hashnode definition and builtin handling. (cpp_start_read, cpp_finish): Don't take or initialise a printer. Update. * cpplib.h (cpp_printer, cpp_toklist, CPP_DEFINED, BOL, PASTED, VAR_ARGS, BEG_OF_FILE, IN_DIRECTIVE, KNOWN_DIRECTIVE, T_VOID, T_SPECLINE, T_DATE, T_FILE, T_BASE_FILE, T_INCLUDE_LEVEL, T_TIME, T_STDC, T_OPERATOR, T_POISON, T_MACRO, T_ASSERTION): Delete. (struct cpp_pool, struct cpp_macro, struct cpp_lexer_pos, struct cpp_lookahead, CPP_DHASH, enum mi_state, enum mi_ind, NO_EXPAND, VARARGS_FIRST, struct cpp_token_with_pos, struct toklist, struct cpp_context, struct specnodes, TOKEN_LOOKAHEAD, TOKEN_BUFFSIZE, NODE_OPERATOR, NODE_POISONED, NODE_BUILTIN, NODE_DIAGNOSTIC, NT_VOID, NT_MACRO, NT_ASSERTION, enum builtin_type, cpp_can_paste): New. (struct cpp_token): Delete line and col members. (struct cpp_buffer): New member output_lineno. (struct lexer_state): Delete indented, in_lex_line, seen_dot. Add va_args_ok, poisoned_ok, prevent_expansion, parsing_args. (struct cpp_reader): New members lexer_pos, macro_pos, directive_pos, ident_pool, temp_string_pool, macro_pool, argument_pool, string_pool, base_context, context, directive, mi_state, mi_if_not_defined, mi_lexed, mi_cmacro, mi_ind_cmacro, la_read, la_write, la_unused, mlstring_pos, macro_buffer, macro_buffer_len. Delete members mls_line, mls_column, token_list, potential_control_macro, temp_tokens, temp_cap, temp_alloced, temp_used, first_directive_token, context_cap, cur_context, no_expand_level, paste_level, contexts, args, save_parameter_spellings, need_newline, . Change type of date, time and spec_nodes members. Change prototypes for include and ident callbacks. (struct cpp_hashnode): Change type of name. Remove union members expansion and code. Add members macro, operator and builtin. (cpp_token_len, cpp_token_as_text, cpp_spell_token, cpp_start_read, cpp_finish, cpp_avoid_paste, cpp_get_token, cpp_get_line, cpp_get_output_line, cpp_macro_definition, cpp_start_lookahead, cpp_stop_lookahead): New prototypes. (cpp_printer_init, cpp_dump_definition): Delete prototypes. (U_CHAR, U, ustrcmp, ustrncmp, ustrlen, uxstrdup, ustrchr, ufputs): Move from cpphash.h. * cpphash.h (U_CHAR, U, ustrcmp, ustrncmp, ustrlen, uxstrdup, ustrchr, ufputs): Move to cpplib.h. (enum spell_type, struct token_spelling, _cpp_token_spellings, TOKEN_SPELL, TOKEN_NAME, struct answer, FREE_ANSWER, KANDR, STDC89, EXTENSION, COND, EXPAND, INCL, COMMENTS, IN_I, struct directive, directive_handler, struct spec_nodes, _cpp_digraph_spellings, _cpp_free_temp_tokens, _cpp_init_input_buffer, _cpp_grow_token_buffer, _cpp_init_toklist, _cpp_clear_toklist, _cpp_expand_token_space, _cpp_expand_name_space, _cpp_equiv_tokens, _cpp_equiv_toklists, _cpp_process_directive, _cpp_run_directive, _cpp_get_line, _cpp_get_raw_token, _cpp_glue_header_name, _cpp_can_paste, _cpp_check_directive, _cpp_check_linemarker, _cpp_parse_assertion, _cpp_find_answer): Delete. (VALID_SIGN, ALIGN, POOL_FRONT, POOL_LIMIT, POOL_BASE, POOL_SIZE, POOL_USED, POOL_COMMIT, struct cpp_chunk, _cpp_lex_token, _cpp_init_pool, _cpp_free_pool, _cpp_pool_reserve, _cpp_pool_alloc, _cpp_next_chunk, _cpp_lock_pool, _cpp_unlock_pool, _cpp_test_assertion, _cpp_handle_directive, DSC): New. (struct include_file): New member defined. (DO_NOT_REREAD, _cpp_begin_message, _cpp_execute_include, _cpp_compare_file_date): Update. (_cpp_pop_context, _cpp_get_token, _cpp_free_lookaheads, _cpp_push_token): New. (_cpp_init_macros, _cpp_cleanup_macros): Rename to _cpp_init_hashtable, _cpp_cleanup_hashtable. * Makefile.in: Remove cppoutput.c. * cppoutput.c: Delete * fixheader.c (read_scan_file): Update for new cpp_get_token prototype. (recognized_function): New argument LINE. * scan-decls.c (skip_to_closing_brace, scan_decls): Update for new cpp_get_token prototype. * scan.h (recognized_function): Update prototype. * po/POTFILES.in: Remove cppoutput.c. From-SVN: r37098
2000-10-28 19:59:06 +02:00
}
c-lex.c (map): Make const. * c-lex.c (map): Make const. (cb_file_change): Update for callback passing a line map. Don't assume we have a previous map. Remove sanity check about popping too many files. * cpperror.c (print_location): Make map const. * cppfiles.c (stack_include_file): Update; line maps now hold sysp. (cpp_make_system_header): Similarly. (search_from): Similarly. (_cpp_execute_include): Don't remember where we came from. * cpphash.h (struct cpp_buffer): Remove return_to_line, sysp. (struct cpp_reader): Make map const. (CPP_IN_SYSTEM_HEADER, _cpp_do_file_change): Update. * cpplib.c (do_line): Update; line maps now hold sysp. (cpp_push_buffer): Similarly. (_cpp_do_file_change): Similarly; callback with map instead. (cpp_get_line_maps): Constify return value. (_cpp_pop_buffer): Update. * cpplib.h (struct cpp_file_change): Remove. (struct cpp_callbacks): Update. (cpp_get_line_maps): Constify return value. * cppmacro.c (_cpp_create_definition): Update. * cppmain.c (struct printer): Constify map. (maybe_print_line): Similarly. (print_line): Similarly. Deduce flags 1 and 2 here. (cb_file_change): Update. * line-map.c (free_line_maps): Warn regardless. (add_line_map): Return pointer to const. When passed NULL to_file with LC_LEAVE, use the obvious values for the return point so the caller doesn't have to figure them out. (lookup_line): Return pointer to const. (print_containing_files): Take pointer to const. * line-map.h (struct line_map): New members reason, sysp. (add_line_map): Return pointer to const. (lookup_line): Similarly. (print_containing_files): Take pointer to const. From-SVN: r44789
2001-08-11 09:33:39 +02:00
/* Output a line marker for logical line LINE. Special flags are "1"
PR preprocessor/60723 - missing system-ness marks for macro tokens When a system macro is expanded in a non-system file during out-of-line preprocessing, it can happen that the preprocessor forgets to emit line markers to express the system-ness status of tokens that come after the expansion of the macro. That can lead to situations where the entire non-system file can be considered as being a system file and thus have its warnings be discarded during the compilation of the resulting preprocessed file. My understanding is that this is due to the preprocessor not systematically detecting (and reporting) the change in system-ness of tokens. And this is what this patch does. Each time the system-ness of a given token is different from the previous token that was emitted by the preprocessor, it emits a line marker for the sole purpose of marking the new system-ness of the subsequent tokens to come. Bootstrapped and tested on x86_64-unknown-linux-gnu against trunk. gcc/c-family/ChangeLog: * c-ppoutput.c (struct print::prev_was_system_token): New data member. (init_pp_output): Initialize it. (maybe_print_line_1, maybe_print_line, print_line_1, print_line) (do_line_change): Return a flag saying if a line marker was emitted or not. (scan_translation_unit): Detect if the system-ness of the token we are about to emit is different from the one of the previously emitted token. If so, emit a line marker. Avoid emitting useless adjacent line markers. Avoid emitting line markers for tokens originating from the expansion of built-in macros. (scan_translation_unit_directives_only): Adjust. gcc/testsuite/ChangeLog: * gcc.dg/cpp/syshdr{4,5}.{c,h}: New test files. Signed-off-by: Dodji Seketeli <dodji@redhat.com> Signed-off-by: Dodji Seketeli <dodji@redhat.com> From-SVN: r212638
2014-07-16 12:33:36 +02:00
or "2" indicating entering or leaving a file. If the line marker
was effectively emitted, return TRUE otherwise return FALSE. */
PR preprocessor/60723 - missing system-ness marks for macro tokens When a system macro is expanded in a non-system file during out-of-line preprocessing, it can happen that the preprocessor forgets to emit line markers to express the system-ness status of tokens that come after the expansion of the macro. That can lead to situations where the entire non-system file can be considered as being a system file and thus have its warnings be discarded during the compilation of the resulting preprocessed file. My understanding is that this is due to the preprocessor not systematically detecting (and reporting) the change in system-ness of tokens. And this is what this patch does. Each time the system-ness of a given token is different from the previous token that was emitted by the preprocessor, it emits a line marker for the sole purpose of marking the new system-ness of the subsequent tokens to come. Bootstrapped and tested on x86_64-unknown-linux-gnu against trunk. gcc/c-family/ChangeLog: * c-ppoutput.c (struct print::prev_was_system_token): New data member. (init_pp_output): Initialize it. (maybe_print_line_1, maybe_print_line, print_line_1, print_line) (do_line_change): Return a flag saying if a line marker was emitted or not. (scan_translation_unit): Detect if the system-ness of the token we are about to emit is different from the one of the previously emitted token. If so, emit a line marker. Avoid emitting useless adjacent line markers. Avoid emitting line markers for tokens originating from the expansion of built-in macros. (scan_translation_unit_directives_only): Adjust. gcc/testsuite/ChangeLog: * gcc.dg/cpp/syshdr{4,5}.{c,h}: New test files. Signed-off-by: Dodji Seketeli <dodji@redhat.com> Signed-off-by: Dodji Seketeli <dodji@redhat.com> From-SVN: r212638
2014-07-16 12:33:36 +02:00
static bool
print_line_1 (source_location src_loc, const char *special_flags, FILE *stream)
New macro expander. 2000-10-28 Neil Booth <neilb@earthling.net> New macro expander. * cpplib.c (struct answer): New. (struct if_stack): Use cpp_lexer_pos rather than line and col. Rename cmacro mi_cmacro. (struct directive, KANDR, STDC89, EXTENSION, COND, IF_COND, INCL, IN_I): New directive and flags. (skip_rest_of_line, check_eol, run_directive, glue_header_name, parse_answer, parse_assertion, find_answer): New functions. (parse_ifdef, detect_if_not_defined, validate_else): Remove. (lex_macro_node): New function to replace parse_ifdef and get_define_node. (_cpp_handle_directive): New function, combines _cpp_check_directive and _cpp_check_linemarker. (do_define, do_undef, parse_include, do_include, do_import, do_include_next, read_line_number, do_line, do_ident, do_pragma, do_pragma_once, do_pragma_poison, do_pragma_dependency): Update for new token getting interface. (do_ifdef, do_ifndef, do_if, do_else, do_endif, push_conditional) : Update for new multiple-include optimisation technique. (do_elif): Don't forget to invalidate controlling macros. (unwind_if_stack, cpp_defined, cpp_push_buffer, cpp_pop_buffer): Update. (parse_assertion, parse_answer, find_answer, _cpp_test_assertion): Functions to handle assertions with the new token interface. (do_assert, do_unassert): Use them. (cpp_define, _cpp_define_builtin, cpp_undef, cpp_assert, cpp_unassert): Use run_directive. (_cpp_init_stacks): Register directive names. Don't register special nodes. * cpperror.c (print_containing_files, _cpp_begin_message): Update to new position recording regime. (cpp_ice, cpp_fatal, cpp_error, cpp_error_with_line, cpp_warning, cpp_warning_with_line, cpp_pedwarn, cpp_pedwarn_with_line, cpp_pedwarn_with_file_and_line): Update for _cpp_begin_message changes. (cpp_type2name): Move to cpplex.c. * cppexp.c (parse_charconst): spec_nodes is no longer a pointer. (parse_defined): Update to handle new multiple include optimisation method. Remove poisoned identifier warning. (parse_assertion, TYPE_NAME): Delete. (lex): Update for multiple include optimisation, removal of CPP_DEFINED, to use _cpp_test_assertion for assertions and cpp_token_as_text. (_cpp_parse_expr): Update for MI optimisation, and to use op_as_text. (op_as_text): New function, to wrap cpp_token_as_text. * cppfiles.c (stack_include_file, _cpp_pop_file_buffer): Update for MI optimisation. (_cpp_execute_include): Take a token rather than 3 arguments. Fix segfault on diagnostic. (_cpp_compare_file_date): Take a token rather than 3 args. (cpp_read_file): Work correctly for zero-length files. * cpphash.c (_cpp_init_macros, _cpp_cleanup_macros): Rename _cpp_init_hashtable and _cpp_cleanup_hashtable. (cpp_lookup): Place identifiers at front of identifier pool for _cpp_lookup_with_hash. (_cpp_lookup_with_hash): Require identifiers to be at the front of the identifier pool. Commit the memory if not already in the hash table. * cppinit.c (cpp_reader_init): Move cpp_init_completed test to top. Initialise various members of cpp_reader, memory pools, and the special nodes. (cpp_printer_init): Delete. (cpp_cleanup): Update. (struct builtin, builtin_array, initialize_builtins): Update for new hashnode definition and builtin handling. (cpp_start_read, cpp_finish): Don't take or initialise a printer. Update. * cpplib.h (cpp_printer, cpp_toklist, CPP_DEFINED, BOL, PASTED, VAR_ARGS, BEG_OF_FILE, IN_DIRECTIVE, KNOWN_DIRECTIVE, T_VOID, T_SPECLINE, T_DATE, T_FILE, T_BASE_FILE, T_INCLUDE_LEVEL, T_TIME, T_STDC, T_OPERATOR, T_POISON, T_MACRO, T_ASSERTION): Delete. (struct cpp_pool, struct cpp_macro, struct cpp_lexer_pos, struct cpp_lookahead, CPP_DHASH, enum mi_state, enum mi_ind, NO_EXPAND, VARARGS_FIRST, struct cpp_token_with_pos, struct toklist, struct cpp_context, struct specnodes, TOKEN_LOOKAHEAD, TOKEN_BUFFSIZE, NODE_OPERATOR, NODE_POISONED, NODE_BUILTIN, NODE_DIAGNOSTIC, NT_VOID, NT_MACRO, NT_ASSERTION, enum builtin_type, cpp_can_paste): New. (struct cpp_token): Delete line and col members. (struct cpp_buffer): New member output_lineno. (struct lexer_state): Delete indented, in_lex_line, seen_dot. Add va_args_ok, poisoned_ok, prevent_expansion, parsing_args. (struct cpp_reader): New members lexer_pos, macro_pos, directive_pos, ident_pool, temp_string_pool, macro_pool, argument_pool, string_pool, base_context, context, directive, mi_state, mi_if_not_defined, mi_lexed, mi_cmacro, mi_ind_cmacro, la_read, la_write, la_unused, mlstring_pos, macro_buffer, macro_buffer_len. Delete members mls_line, mls_column, token_list, potential_control_macro, temp_tokens, temp_cap, temp_alloced, temp_used, first_directive_token, context_cap, cur_context, no_expand_level, paste_level, contexts, args, save_parameter_spellings, need_newline, . Change type of date, time and spec_nodes members. Change prototypes for include and ident callbacks. (struct cpp_hashnode): Change type of name. Remove union members expansion and code. Add members macro, operator and builtin. (cpp_token_len, cpp_token_as_text, cpp_spell_token, cpp_start_read, cpp_finish, cpp_avoid_paste, cpp_get_token, cpp_get_line, cpp_get_output_line, cpp_macro_definition, cpp_start_lookahead, cpp_stop_lookahead): New prototypes. (cpp_printer_init, cpp_dump_definition): Delete prototypes. (U_CHAR, U, ustrcmp, ustrncmp, ustrlen, uxstrdup, ustrchr, ufputs): Move from cpphash.h. * cpphash.h (U_CHAR, U, ustrcmp, ustrncmp, ustrlen, uxstrdup, ustrchr, ufputs): Move to cpplib.h. (enum spell_type, struct token_spelling, _cpp_token_spellings, TOKEN_SPELL, TOKEN_NAME, struct answer, FREE_ANSWER, KANDR, STDC89, EXTENSION, COND, EXPAND, INCL, COMMENTS, IN_I, struct directive, directive_handler, struct spec_nodes, _cpp_digraph_spellings, _cpp_free_temp_tokens, _cpp_init_input_buffer, _cpp_grow_token_buffer, _cpp_init_toklist, _cpp_clear_toklist, _cpp_expand_token_space, _cpp_expand_name_space, _cpp_equiv_tokens, _cpp_equiv_toklists, _cpp_process_directive, _cpp_run_directive, _cpp_get_line, _cpp_get_raw_token, _cpp_glue_header_name, _cpp_can_paste, _cpp_check_directive, _cpp_check_linemarker, _cpp_parse_assertion, _cpp_find_answer): Delete. (VALID_SIGN, ALIGN, POOL_FRONT, POOL_LIMIT, POOL_BASE, POOL_SIZE, POOL_USED, POOL_COMMIT, struct cpp_chunk, _cpp_lex_token, _cpp_init_pool, _cpp_free_pool, _cpp_pool_reserve, _cpp_pool_alloc, _cpp_next_chunk, _cpp_lock_pool, _cpp_unlock_pool, _cpp_test_assertion, _cpp_handle_directive, DSC): New. (struct include_file): New member defined. (DO_NOT_REREAD, _cpp_begin_message, _cpp_execute_include, _cpp_compare_file_date): Update. (_cpp_pop_context, _cpp_get_token, _cpp_free_lookaheads, _cpp_push_token): New. (_cpp_init_macros, _cpp_cleanup_macros): Rename to _cpp_init_hashtable, _cpp_cleanup_hashtable. * Makefile.in: Remove cppoutput.c. * cppoutput.c: Delete * fixheader.c (read_scan_file): Update for new cpp_get_token prototype. (recognized_function): New argument LINE. * scan-decls.c (skip_to_closing_brace, scan_decls): Update for new cpp_get_token prototype. * scan.h (recognized_function): Update prototype. * po/POTFILES.in: Remove cppoutput.c. From-SVN: r37098
2000-10-28 19:59:06 +02:00
{
PR preprocessor/60723 - missing system-ness marks for macro tokens When a system macro is expanded in a non-system file during out-of-line preprocessing, it can happen that the preprocessor forgets to emit line markers to express the system-ness status of tokens that come after the expansion of the macro. That can lead to situations where the entire non-system file can be considered as being a system file and thus have its warnings be discarded during the compilation of the resulting preprocessed file. My understanding is that this is due to the preprocessor not systematically detecting (and reporting) the change in system-ness of tokens. And this is what this patch does. Each time the system-ness of a given token is different from the previous token that was emitted by the preprocessor, it emits a line marker for the sole purpose of marking the new system-ness of the subsequent tokens to come. Bootstrapped and tested on x86_64-unknown-linux-gnu against trunk. gcc/c-family/ChangeLog: * c-ppoutput.c (struct print::prev_was_system_token): New data member. (init_pp_output): Initialize it. (maybe_print_line_1, maybe_print_line, print_line_1, print_line) (do_line_change): Return a flag saying if a line marker was emitted or not. (scan_translation_unit): Detect if the system-ness of the token we are about to emit is different from the one of the previously emitted token. If so, emit a line marker. Avoid emitting useless adjacent line markers. Avoid emitting line markers for tokens originating from the expansion of built-in macros. (scan_translation_unit_directives_only): Adjust. gcc/testsuite/ChangeLog: * gcc.dg/cpp/syshdr{4,5}.{c,h}: New test files. Signed-off-by: Dodji Seketeli <dodji@redhat.com> Signed-off-by: Dodji Seketeli <dodji@redhat.com> From-SVN: r212638
2014-07-16 12:33:36 +02:00
bool emitted_line_marker = false;
New macro expander. 2000-10-28 Neil Booth <neilb@earthling.net> New macro expander. * cpplib.c (struct answer): New. (struct if_stack): Use cpp_lexer_pos rather than line and col. Rename cmacro mi_cmacro. (struct directive, KANDR, STDC89, EXTENSION, COND, IF_COND, INCL, IN_I): New directive and flags. (skip_rest_of_line, check_eol, run_directive, glue_header_name, parse_answer, parse_assertion, find_answer): New functions. (parse_ifdef, detect_if_not_defined, validate_else): Remove. (lex_macro_node): New function to replace parse_ifdef and get_define_node. (_cpp_handle_directive): New function, combines _cpp_check_directive and _cpp_check_linemarker. (do_define, do_undef, parse_include, do_include, do_import, do_include_next, read_line_number, do_line, do_ident, do_pragma, do_pragma_once, do_pragma_poison, do_pragma_dependency): Update for new token getting interface. (do_ifdef, do_ifndef, do_if, do_else, do_endif, push_conditional) : Update for new multiple-include optimisation technique. (do_elif): Don't forget to invalidate controlling macros. (unwind_if_stack, cpp_defined, cpp_push_buffer, cpp_pop_buffer): Update. (parse_assertion, parse_answer, find_answer, _cpp_test_assertion): Functions to handle assertions with the new token interface. (do_assert, do_unassert): Use them. (cpp_define, _cpp_define_builtin, cpp_undef, cpp_assert, cpp_unassert): Use run_directive. (_cpp_init_stacks): Register directive names. Don't register special nodes. * cpperror.c (print_containing_files, _cpp_begin_message): Update to new position recording regime. (cpp_ice, cpp_fatal, cpp_error, cpp_error_with_line, cpp_warning, cpp_warning_with_line, cpp_pedwarn, cpp_pedwarn_with_line, cpp_pedwarn_with_file_and_line): Update for _cpp_begin_message changes. (cpp_type2name): Move to cpplex.c. * cppexp.c (parse_charconst): spec_nodes is no longer a pointer. (parse_defined): Update to handle new multiple include optimisation method. Remove poisoned identifier warning. (parse_assertion, TYPE_NAME): Delete. (lex): Update for multiple include optimisation, removal of CPP_DEFINED, to use _cpp_test_assertion for assertions and cpp_token_as_text. (_cpp_parse_expr): Update for MI optimisation, and to use op_as_text. (op_as_text): New function, to wrap cpp_token_as_text. * cppfiles.c (stack_include_file, _cpp_pop_file_buffer): Update for MI optimisation. (_cpp_execute_include): Take a token rather than 3 arguments. Fix segfault on diagnostic. (_cpp_compare_file_date): Take a token rather than 3 args. (cpp_read_file): Work correctly for zero-length files. * cpphash.c (_cpp_init_macros, _cpp_cleanup_macros): Rename _cpp_init_hashtable and _cpp_cleanup_hashtable. (cpp_lookup): Place identifiers at front of identifier pool for _cpp_lookup_with_hash. (_cpp_lookup_with_hash): Require identifiers to be at the front of the identifier pool. Commit the memory if not already in the hash table. * cppinit.c (cpp_reader_init): Move cpp_init_completed test to top. Initialise various members of cpp_reader, memory pools, and the special nodes. (cpp_printer_init): Delete. (cpp_cleanup): Update. (struct builtin, builtin_array, initialize_builtins): Update for new hashnode definition and builtin handling. (cpp_start_read, cpp_finish): Don't take or initialise a printer. Update. * cpplib.h (cpp_printer, cpp_toklist, CPP_DEFINED, BOL, PASTED, VAR_ARGS, BEG_OF_FILE, IN_DIRECTIVE, KNOWN_DIRECTIVE, T_VOID, T_SPECLINE, T_DATE, T_FILE, T_BASE_FILE, T_INCLUDE_LEVEL, T_TIME, T_STDC, T_OPERATOR, T_POISON, T_MACRO, T_ASSERTION): Delete. (struct cpp_pool, struct cpp_macro, struct cpp_lexer_pos, struct cpp_lookahead, CPP_DHASH, enum mi_state, enum mi_ind, NO_EXPAND, VARARGS_FIRST, struct cpp_token_with_pos, struct toklist, struct cpp_context, struct specnodes, TOKEN_LOOKAHEAD, TOKEN_BUFFSIZE, NODE_OPERATOR, NODE_POISONED, NODE_BUILTIN, NODE_DIAGNOSTIC, NT_VOID, NT_MACRO, NT_ASSERTION, enum builtin_type, cpp_can_paste): New. (struct cpp_token): Delete line and col members. (struct cpp_buffer): New member output_lineno. (struct lexer_state): Delete indented, in_lex_line, seen_dot. Add va_args_ok, poisoned_ok, prevent_expansion, parsing_args. (struct cpp_reader): New members lexer_pos, macro_pos, directive_pos, ident_pool, temp_string_pool, macro_pool, argument_pool, string_pool, base_context, context, directive, mi_state, mi_if_not_defined, mi_lexed, mi_cmacro, mi_ind_cmacro, la_read, la_write, la_unused, mlstring_pos, macro_buffer, macro_buffer_len. Delete members mls_line, mls_column, token_list, potential_control_macro, temp_tokens, temp_cap, temp_alloced, temp_used, first_directive_token, context_cap, cur_context, no_expand_level, paste_level, contexts, args, save_parameter_spellings, need_newline, . Change type of date, time and spec_nodes members. Change prototypes for include and ident callbacks. (struct cpp_hashnode): Change type of name. Remove union members expansion and code. Add members macro, operator and builtin. (cpp_token_len, cpp_token_as_text, cpp_spell_token, cpp_start_read, cpp_finish, cpp_avoid_paste, cpp_get_token, cpp_get_line, cpp_get_output_line, cpp_macro_definition, cpp_start_lookahead, cpp_stop_lookahead): New prototypes. (cpp_printer_init, cpp_dump_definition): Delete prototypes. (U_CHAR, U, ustrcmp, ustrncmp, ustrlen, uxstrdup, ustrchr, ufputs): Move from cpphash.h. * cpphash.h (U_CHAR, U, ustrcmp, ustrncmp, ustrlen, uxstrdup, ustrchr, ufputs): Move to cpplib.h. (enum spell_type, struct token_spelling, _cpp_token_spellings, TOKEN_SPELL, TOKEN_NAME, struct answer, FREE_ANSWER, KANDR, STDC89, EXTENSION, COND, EXPAND, INCL, COMMENTS, IN_I, struct directive, directive_handler, struct spec_nodes, _cpp_digraph_spellings, _cpp_free_temp_tokens, _cpp_init_input_buffer, _cpp_grow_token_buffer, _cpp_init_toklist, _cpp_clear_toklist, _cpp_expand_token_space, _cpp_expand_name_space, _cpp_equiv_tokens, _cpp_equiv_toklists, _cpp_process_directive, _cpp_run_directive, _cpp_get_line, _cpp_get_raw_token, _cpp_glue_header_name, _cpp_can_paste, _cpp_check_directive, _cpp_check_linemarker, _cpp_parse_assertion, _cpp_find_answer): Delete. (VALID_SIGN, ALIGN, POOL_FRONT, POOL_LIMIT, POOL_BASE, POOL_SIZE, POOL_USED, POOL_COMMIT, struct cpp_chunk, _cpp_lex_token, _cpp_init_pool, _cpp_free_pool, _cpp_pool_reserve, _cpp_pool_alloc, _cpp_next_chunk, _cpp_lock_pool, _cpp_unlock_pool, _cpp_test_assertion, _cpp_handle_directive, DSC): New. (struct include_file): New member defined. (DO_NOT_REREAD, _cpp_begin_message, _cpp_execute_include, _cpp_compare_file_date): Update. (_cpp_pop_context, _cpp_get_token, _cpp_free_lookaheads, _cpp_push_token): New. (_cpp_init_macros, _cpp_cleanup_macros): Rename to _cpp_init_hashtable, _cpp_cleanup_hashtable. * Makefile.in: Remove cppoutput.c. * cppoutput.c: Delete * fixheader.c (read_scan_file): Update for new cpp_get_token prototype. (recognized_function): New argument LINE. * scan-decls.c (skip_to_closing_brace, scan_decls): Update for new cpp_get_token prototype. * scan.h (recognized_function): Update prototype. * po/POTFILES.in: Remove cppoutput.c. From-SVN: r37098
2000-10-28 19:59:06 +02:00
/* End any previous line of text. */
if (print.printed)
putc ('\n', stream);
print.printed = false;
New macro expander. 2000-10-28 Neil Booth <neilb@earthling.net> New macro expander. * cpplib.c (struct answer): New. (struct if_stack): Use cpp_lexer_pos rather than line and col. Rename cmacro mi_cmacro. (struct directive, KANDR, STDC89, EXTENSION, COND, IF_COND, INCL, IN_I): New directive and flags. (skip_rest_of_line, check_eol, run_directive, glue_header_name, parse_answer, parse_assertion, find_answer): New functions. (parse_ifdef, detect_if_not_defined, validate_else): Remove. (lex_macro_node): New function to replace parse_ifdef and get_define_node. (_cpp_handle_directive): New function, combines _cpp_check_directive and _cpp_check_linemarker. (do_define, do_undef, parse_include, do_include, do_import, do_include_next, read_line_number, do_line, do_ident, do_pragma, do_pragma_once, do_pragma_poison, do_pragma_dependency): Update for new token getting interface. (do_ifdef, do_ifndef, do_if, do_else, do_endif, push_conditional) : Update for new multiple-include optimisation technique. (do_elif): Don't forget to invalidate controlling macros. (unwind_if_stack, cpp_defined, cpp_push_buffer, cpp_pop_buffer): Update. (parse_assertion, parse_answer, find_answer, _cpp_test_assertion): Functions to handle assertions with the new token interface. (do_assert, do_unassert): Use them. (cpp_define, _cpp_define_builtin, cpp_undef, cpp_assert, cpp_unassert): Use run_directive. (_cpp_init_stacks): Register directive names. Don't register special nodes. * cpperror.c (print_containing_files, _cpp_begin_message): Update to new position recording regime. (cpp_ice, cpp_fatal, cpp_error, cpp_error_with_line, cpp_warning, cpp_warning_with_line, cpp_pedwarn, cpp_pedwarn_with_line, cpp_pedwarn_with_file_and_line): Update for _cpp_begin_message changes. (cpp_type2name): Move to cpplex.c. * cppexp.c (parse_charconst): spec_nodes is no longer a pointer. (parse_defined): Update to handle new multiple include optimisation method. Remove poisoned identifier warning. (parse_assertion, TYPE_NAME): Delete. (lex): Update for multiple include optimisation, removal of CPP_DEFINED, to use _cpp_test_assertion for assertions and cpp_token_as_text. (_cpp_parse_expr): Update for MI optimisation, and to use op_as_text. (op_as_text): New function, to wrap cpp_token_as_text. * cppfiles.c (stack_include_file, _cpp_pop_file_buffer): Update for MI optimisation. (_cpp_execute_include): Take a token rather than 3 arguments. Fix segfault on diagnostic. (_cpp_compare_file_date): Take a token rather than 3 args. (cpp_read_file): Work correctly for zero-length files. * cpphash.c (_cpp_init_macros, _cpp_cleanup_macros): Rename _cpp_init_hashtable and _cpp_cleanup_hashtable. (cpp_lookup): Place identifiers at front of identifier pool for _cpp_lookup_with_hash. (_cpp_lookup_with_hash): Require identifiers to be at the front of the identifier pool. Commit the memory if not already in the hash table. * cppinit.c (cpp_reader_init): Move cpp_init_completed test to top. Initialise various members of cpp_reader, memory pools, and the special nodes. (cpp_printer_init): Delete. (cpp_cleanup): Update. (struct builtin, builtin_array, initialize_builtins): Update for new hashnode definition and builtin handling. (cpp_start_read, cpp_finish): Don't take or initialise a printer. Update. * cpplib.h (cpp_printer, cpp_toklist, CPP_DEFINED, BOL, PASTED, VAR_ARGS, BEG_OF_FILE, IN_DIRECTIVE, KNOWN_DIRECTIVE, T_VOID, T_SPECLINE, T_DATE, T_FILE, T_BASE_FILE, T_INCLUDE_LEVEL, T_TIME, T_STDC, T_OPERATOR, T_POISON, T_MACRO, T_ASSERTION): Delete. (struct cpp_pool, struct cpp_macro, struct cpp_lexer_pos, struct cpp_lookahead, CPP_DHASH, enum mi_state, enum mi_ind, NO_EXPAND, VARARGS_FIRST, struct cpp_token_with_pos, struct toklist, struct cpp_context, struct specnodes, TOKEN_LOOKAHEAD, TOKEN_BUFFSIZE, NODE_OPERATOR, NODE_POISONED, NODE_BUILTIN, NODE_DIAGNOSTIC, NT_VOID, NT_MACRO, NT_ASSERTION, enum builtin_type, cpp_can_paste): New. (struct cpp_token): Delete line and col members. (struct cpp_buffer): New member output_lineno. (struct lexer_state): Delete indented, in_lex_line, seen_dot. Add va_args_ok, poisoned_ok, prevent_expansion, parsing_args. (struct cpp_reader): New members lexer_pos, macro_pos, directive_pos, ident_pool, temp_string_pool, macro_pool, argument_pool, string_pool, base_context, context, directive, mi_state, mi_if_not_defined, mi_lexed, mi_cmacro, mi_ind_cmacro, la_read, la_write, la_unused, mlstring_pos, macro_buffer, macro_buffer_len. Delete members mls_line, mls_column, token_list, potential_control_macro, temp_tokens, temp_cap, temp_alloced, temp_used, first_directive_token, context_cap, cur_context, no_expand_level, paste_level, contexts, args, save_parameter_spellings, need_newline, . Change type of date, time and spec_nodes members. Change prototypes for include and ident callbacks. (struct cpp_hashnode): Change type of name. Remove union members expansion and code. Add members macro, operator and builtin. (cpp_token_len, cpp_token_as_text, cpp_spell_token, cpp_start_read, cpp_finish, cpp_avoid_paste, cpp_get_token, cpp_get_line, cpp_get_output_line, cpp_macro_definition, cpp_start_lookahead, cpp_stop_lookahead): New prototypes. (cpp_printer_init, cpp_dump_definition): Delete prototypes. (U_CHAR, U, ustrcmp, ustrncmp, ustrlen, uxstrdup, ustrchr, ufputs): Move from cpphash.h. * cpphash.h (U_CHAR, U, ustrcmp, ustrncmp, ustrlen, uxstrdup, ustrchr, ufputs): Move to cpplib.h. (enum spell_type, struct token_spelling, _cpp_token_spellings, TOKEN_SPELL, TOKEN_NAME, struct answer, FREE_ANSWER, KANDR, STDC89, EXTENSION, COND, EXPAND, INCL, COMMENTS, IN_I, struct directive, directive_handler, struct spec_nodes, _cpp_digraph_spellings, _cpp_free_temp_tokens, _cpp_init_input_buffer, _cpp_grow_token_buffer, _cpp_init_toklist, _cpp_clear_toklist, _cpp_expand_token_space, _cpp_expand_name_space, _cpp_equiv_tokens, _cpp_equiv_toklists, _cpp_process_directive, _cpp_run_directive, _cpp_get_line, _cpp_get_raw_token, _cpp_glue_header_name, _cpp_can_paste, _cpp_check_directive, _cpp_check_linemarker, _cpp_parse_assertion, _cpp_find_answer): Delete. (VALID_SIGN, ALIGN, POOL_FRONT, POOL_LIMIT, POOL_BASE, POOL_SIZE, POOL_USED, POOL_COMMIT, struct cpp_chunk, _cpp_lex_token, _cpp_init_pool, _cpp_free_pool, _cpp_pool_reserve, _cpp_pool_alloc, _cpp_next_chunk, _cpp_lock_pool, _cpp_unlock_pool, _cpp_test_assertion, _cpp_handle_directive, DSC): New. (struct include_file): New member defined. (DO_NOT_REREAD, _cpp_begin_message, _cpp_execute_include, _cpp_compare_file_date): Update. (_cpp_pop_context, _cpp_get_token, _cpp_free_lookaheads, _cpp_push_token): New. (_cpp_init_macros, _cpp_cleanup_macros): Rename to _cpp_init_hashtable, _cpp_cleanup_hashtable. * Makefile.in: Remove cppoutput.c. * cppoutput.c: Delete * fixheader.c (read_scan_file): Update for new cpp_get_token prototype. (recognized_function): New argument LINE. * scan-decls.c (skip_to_closing_brace, scan_decls): Update for new cpp_get_token prototype. * scan.h (recognized_function): Update prototype. * po/POTFILES.in: Remove cppoutput.c. From-SVN: r37098
2000-10-28 19:59:06 +02:00
if (!flag_no_line_commands)
c-lex.c (map): Make const. * c-lex.c (map): Make const. (cb_file_change): Update for callback passing a line map. Don't assume we have a previous map. Remove sanity check about popping too many files. * cpperror.c (print_location): Make map const. * cppfiles.c (stack_include_file): Update; line maps now hold sysp. (cpp_make_system_header): Similarly. (search_from): Similarly. (_cpp_execute_include): Don't remember where we came from. * cpphash.h (struct cpp_buffer): Remove return_to_line, sysp. (struct cpp_reader): Make map const. (CPP_IN_SYSTEM_HEADER, _cpp_do_file_change): Update. * cpplib.c (do_line): Update; line maps now hold sysp. (cpp_push_buffer): Similarly. (_cpp_do_file_change): Similarly; callback with map instead. (cpp_get_line_maps): Constify return value. (_cpp_pop_buffer): Update. * cpplib.h (struct cpp_file_change): Remove. (struct cpp_callbacks): Update. (cpp_get_line_maps): Constify return value. * cppmacro.c (_cpp_create_definition): Update. * cppmain.c (struct printer): Constify map. (maybe_print_line): Similarly. (print_line): Similarly. Deduce flags 1 and 2 here. (cb_file_change): Update. * line-map.c (free_line_maps): Warn regardless. (add_line_map): Return pointer to const. When passed NULL to_file with LC_LEAVE, use the obvious values for the return point so the caller doesn't have to figure them out. (lookup_line): Return pointer to const. (print_containing_files): Take pointer to const. * line-map.h (struct line_map): New members reason, sysp. (add_line_map): Return pointer to const. (lookup_line): Similarly. (print_containing_files): Take pointer to const. From-SVN: r44789
2001-08-11 09:33:39 +02:00
{
Linemap infrastructure for virtual locations This is the first instalment of a set which goal is to track locations of tokens across macro expansions. Tom Tromey did the original work and attached the patch to PR preprocessor/7263. This opus is a derivative of that original work. This patch modifies the linemap module of libcpp to add virtual locations support. A virtual location is a mapped location that can resolve to several different physical locations. It can always resolve to the spelling location of a token. For tokens resulting from macro expansion it can resolve to: - either the location of the expansion point of the macro. - or the location of the token in the definition of the macro - or, if the token is an argument of a function-like macro, the location of the use of the matching macro parameter in the definition of the macro The patch creates a new type of line map called a macro map. For every single macro expansion, there is a macro map that generates a virtual location for every single resulting token of the expansion. The good old type of line map we all know is now called an ordinary map. That one still encodes spelling locations as it has always had. As a result linemap_lookup as been extended to return a macro map when given a virtual location resulting from a macro expansion. The layout of structs line_map has changed to support this new type of map. So did the layout of struct line_maps. Accessor macros have been introduced to avoid messing with the implementation details of these datastructures directly. This helped already as we have been testing different ways of arranging these datastructure. Having to constantly adjust client code that is too tied with the internals of line_map and line_maps would have been even more painful. Of course, many new public functions have been added to the linemap module to handle the resolution of virtual locations. This patch introduces the infrastructure but no part of the compiler uses virtual locations yet. However the client code of the linemap data structures has been adjusted as per the changes. E.g, it's not anymore reliable for a client code to manipulate struct line_map directly if it just wants to deal with spelling locations, because struct line_map can now represent a macro map as well. In that case, it's better to use the convenient API to resolve the initial (possibly virtual) location to a spelling location (or to an ordinary map) and use that. This is the reason why the patch adjusts the Java, Ada and Fortran front ends. Also, note that virtual locations are not supposed to be ordered for relations '<' and '>' anymore. To test if a virtual location appears "before" another one, one has to use a new operator exposed by the line map interface. The patch updates the only spot (in the diagnostics module) I have found that was making the assumption that locations were ordered for these relations. This is the only change that introduces a use of the new line map API in this patch, so I am adding a regression test for it only. From-SVN: r180081
2011-10-17 11:58:56 +02:00
const char *file_path = LOCATION_FILE (src_loc);
int sysp;
size_t to_file_len = strlen (file_path);
tree-inline.c (copy_body_r): Use explicit cast when converting from void *. * tree-inline.c (copy_body_r): Use explicit cast when converting from void *. (copy_bb): Likewise. (copy_edges_for_bb): Likewise. (remap_decl_1): Likewise. (estimate_num_insns_1): Likewise. * cgraph.c (hash_node): Use explicit cast when converting from void *. (eq_node): Likewise. (cgraph_create_node): Use GGC_CNEW. (cgraph_create_edge): Use GGC_NEW. (cgraph_remove_node): Use explicit cast when converting from void *. (hash_varpool_node): Likewise. (eq_varpool_node): Likewise. (cgraph_varpool_node): Use GGC_CNEW. * lambda.h (lambda_vector_new): Use GGC_CNEWVEC. * tree-scalar-evolution.c (new_scev_info_str): Use XNEW. (eq_scev_info): Use explicit cast when converting from void *. (find_var_scev_info): Likewise. (set_instantiated_value): Likewise. (gather_stats_on_scev_database_1): Likewise. * cfgloop.h (simple_loop_desc): Use explicit cast when converting from void *. * c-pch.c (c_common_write_pch): Use XNEWVEC. (c_common_read_pch): Likewise. * prefix.c (save_string): Use XNEWVEC. (translate_name): Use explicit cast when converting from void *. * c-ppoutput.c (print_line): Use explicit cast when converting from void *. (pp_dir_change): Likewise. * c-cppbuiltin.c (builtin_define_std): Likewise. (builtin_define_with_value): Likewise. (builtin_define_with_value_n): Likewise. (builtin_define_with_int_value): Likewise. (builtin_define_type_max): Likewise. * c-incpath.c (add_env_var_paths): Use XNEWVEC. (add_path): Use XNEW. * c-format.c (check_format_info_main): Use GGC_NEW. (format_type_warning): Use explicit cast when converting from void *. * c-typeck.c (alloc_tagged_tu_seen_cache): Use XNEW instead of xmalloc. (start_init): Likewise. * tree-flow-inline.h (first_referenced_var): Use explicit cast when converting from void *. (next_referenced_var): Likewise. * c-pragma.c (push_alignment): Use GGC_NEW instead of ggc_alloc. * gensupport.c (lookup_predicate): Use explicit cast to convert from void *. (init_predicate_table): Use XCNEW instead of xcalloc. * genpreds.c (process_define_predicate): Likewise. From-SVN: r108723
2005-12-17 21:45:46 +01:00
unsigned char *to_file_quoted =
(unsigned char *) alloca (to_file_len * 4 + 1);
unsigned char *p;
Linemap infrastructure for virtual locations This is the first instalment of a set which goal is to track locations of tokens across macro expansions. Tom Tromey did the original work and attached the patch to PR preprocessor/7263. This opus is a derivative of that original work. This patch modifies the linemap module of libcpp to add virtual locations support. A virtual location is a mapped location that can resolve to several different physical locations. It can always resolve to the spelling location of a token. For tokens resulting from macro expansion it can resolve to: - either the location of the expansion point of the macro. - or the location of the token in the definition of the macro - or, if the token is an argument of a function-like macro, the location of the use of the matching macro parameter in the definition of the macro The patch creates a new type of line map called a macro map. For every single macro expansion, there is a macro map that generates a virtual location for every single resulting token of the expansion. The good old type of line map we all know is now called an ordinary map. That one still encodes spelling locations as it has always had. As a result linemap_lookup as been extended to return a macro map when given a virtual location resulting from a macro expansion. The layout of structs line_map has changed to support this new type of map. So did the layout of struct line_maps. Accessor macros have been introduced to avoid messing with the implementation details of these datastructures directly. This helped already as we have been testing different ways of arranging these datastructure. Having to constantly adjust client code that is too tied with the internals of line_map and line_maps would have been even more painful. Of course, many new public functions have been added to the linemap module to handle the resolution of virtual locations. This patch introduces the infrastructure but no part of the compiler uses virtual locations yet. However the client code of the linemap data structures has been adjusted as per the changes. E.g, it's not anymore reliable for a client code to manipulate struct line_map directly if it just wants to deal with spelling locations, because struct line_map can now represent a macro map as well. In that case, it's better to use the convenient API to resolve the initial (possibly virtual) location to a spelling location (or to an ordinary map) and use that. This is the reason why the patch adjusts the Java, Ada and Fortran front ends. Also, note that virtual locations are not supposed to be ordered for relations '<' and '>' anymore. To test if a virtual location appears "before" another one, one has to use a new operator exposed by the line map interface. The patch updates the only spot (in the diagnostics module) I have found that was making the assumption that locations were ordered for these relations. This is the only change that introduces a use of the new line map API in this patch, so I am adding a regression test for it only. From-SVN: r180081
2011-10-17 11:58:56 +02:00
print.src_line = LOCATION_LINE (src_loc);
print.src_file = file_path;
Represent column numbers using line-map's source_location. The "next available source_location" is now managed internally by line-maps.c rather than by clients. * line-map.h (struct line_map): New field column_bits. <from_line>: Rename field to start_location. (struct line_maps): New fields highest_location and max_column_hint. (linemap_check_files_exited): New declaration. (linemap_line_start): New declaration. (linemap_add): Remove from_line parameter; use highest_location field. (SOURCE_LINE, LAST_SOURCE_LINE): Modify to use column_bits. (SOURCE_COLUMN, LAST_SOURCE_LINE_LOCATION): New macros. (CURRENT_LINE_MAP): Remove macro. (linemap_position_for_column): New inline function. * line-map.c (linemap_init): Clear new fields. (linemap_check_files_exited): New function, extracted from ... (linemap_free): Use linemap_check_files_exited. (linemap_add): Remove from_line parameter. Various updates. (linemap_line_start): New function. (linemap_lookeup): Update for new field names. * cpphash.h (struct cpp_reader) <map>: Field removed. Because linemap_position_for_column may unpredictably change the current map, it is cleaner and simpler for us to not cache it in cpp_reader. (struct cpp_buffer): New sysp field. Changed warned_cplusplus_comments and from_stage3 to bitfields. * cppinit.c (cpp_read_min_file): pfile->map no longer exists. * cpplib.c (do_line, do_linemarker, _cpp_do_file_change): Get current map using linemap_lookup. (do_linemarker): Also set buffer's sysp field. (destringize_and_run): No longer need to decrement current line. * cppfiles.c (_cpp_stack_file): Set sysp from and in buffer. (search_path_head, open_file_failed): Use buffer's sysp. (cpp_make_system_header): Get current map using linemap_lookup. Also set buffer's sysp flag. * cppmacro.c (_cpp_builtin_macro_text): Likewise use linemap_lookup. * cpphash.h (CPP_INCREMENT_LINE): New macro. (struct cpp_buffer): Moved fields saved_cur, saved_rlimit to ... (struct cpp_reader): ... and adding saved_line_base field. * cpptrad.c (_cpp_overlay_buffer, _cpp_remove_overlay): Update accordingly. Don't adjust line. (_cpp_scan_out_logical_line): Use CPP_INCREMENT_LINE. * cpphash.c (CPP_IN_SYSTEM_HEADER): Replaced macro by ... (cpp_in_system_header): ... new inline function, using buffer's sysp. * cpperror.c (_cpp_begin_message): Update to use cpp_in_system_header. * cpplex.c (_cpp_lex_direct): Likewise. * cppmacro.c (_cpp_builtin_macro_text): Likewise. * cppmacro.c (_cpp_create_definition): Use buffer's sysp field. * cpplib.h (struct cpp_token): Rename line field to src_loc. Remove col field as it is now subsumed by src_loc. * cpperror.c: Update various field, parameter, and macro names. (print_location): If col==0, try SOURCE_COLUMN of line. (cpp_error): Use cur_token's src_loc field, rather than line+col. * cpplib.c (do_diagnostic): Token's src_loc fields replaces line+col. * cpplex.c (_cpp_process_line_notes, _cpp_lex_direct, _cpp_skip_block_comment): Use CPP_INCREMENT_LINE. (_cpp_temp_token): Replace cpp_token's line+col fields by src_loc. (_cpp_get_fresh_line): Don't need to adjust line for missing newline. (_cpp_lex_direct): Use linemap_position_for_column. * c-ppoutput.c (maybe_print_line, print_line): Don't take map parameter. Instead get it from the line_table global. Adjust callers. (print): Remove map field. Replace line field to src_line. (init_pp_output, account_for_newlines, maybe_print_line): Adjust. (cb_line_change): Use SOURCE_COLUMN. Minor optimizations. (pp_file_change): Use MAIN_FILE_P since we cannot checked print.map. Use LAST_SOURCE_LINE_LOCATION to "catch up" after #include. * cpptrad.c (copy_comment): Rename variable. * c-lex.c (map): Remove static variable, for same reason we removed cpp_reader's map field. (cb_line_change, cb_def_pragma, cb_define, cb_undef): Hence we need to call linemap_lookup. (cb_line_change): Token's line field replaced by src_loc. (fe_file_change): Use MAINFILE_P and LAST_SOURCE_LINE macros. Don't save new_map. * cpphash.h, cpperror.c, cpplib.h: Some renames of fileline to source_location. From-SVN: r77663
2004-02-11 16:29:30 +01:00
/* cpp_quote_string does not nul-terminate, so we have to do it
ourselves. */
p = cpp_quote_string (to_file_quoted,
Linemap infrastructure for virtual locations This is the first instalment of a set which goal is to track locations of tokens across macro expansions. Tom Tromey did the original work and attached the patch to PR preprocessor/7263. This opus is a derivative of that original work. This patch modifies the linemap module of libcpp to add virtual locations support. A virtual location is a mapped location that can resolve to several different physical locations. It can always resolve to the spelling location of a token. For tokens resulting from macro expansion it can resolve to: - either the location of the expansion point of the macro. - or the location of the token in the definition of the macro - or, if the token is an argument of a function-like macro, the location of the use of the matching macro parameter in the definition of the macro The patch creates a new type of line map called a macro map. For every single macro expansion, there is a macro map that generates a virtual location for every single resulting token of the expansion. The good old type of line map we all know is now called an ordinary map. That one still encodes spelling locations as it has always had. As a result linemap_lookup as been extended to return a macro map when given a virtual location resulting from a macro expansion. The layout of structs line_map has changed to support this new type of map. So did the layout of struct line_maps. Accessor macros have been introduced to avoid messing with the implementation details of these datastructures directly. This helped already as we have been testing different ways of arranging these datastructure. Having to constantly adjust client code that is too tied with the internals of line_map and line_maps would have been even more painful. Of course, many new public functions have been added to the linemap module to handle the resolution of virtual locations. This patch introduces the infrastructure but no part of the compiler uses virtual locations yet. However the client code of the linemap data structures has been adjusted as per the changes. E.g, it's not anymore reliable for a client code to manipulate struct line_map directly if it just wants to deal with spelling locations, because struct line_map can now represent a macro map as well. In that case, it's better to use the convenient API to resolve the initial (possibly virtual) location to a spelling location (or to an ordinary map) and use that. This is the reason why the patch adjusts the Java, Ada and Fortran front ends. Also, note that virtual locations are not supposed to be ordered for relations '<' and '>' anymore. To test if a virtual location appears "before" another one, one has to use a new operator exposed by the line map interface. The patch updates the only spot (in the diagnostics module) I have found that was making the assumption that locations were ordered for these relations. This is the only change that introduces a use of the new line map API in this patch, so I am adding a regression test for it only. From-SVN: r180081
2011-10-17 11:58:56 +02:00
(const unsigned char *) file_path,
to_file_len);
*p = '\0';
fprintf (stream, "# %u \"%s\"%s",
print.src_line == 0 ? 1 : print.src_line,
to_file_quoted, special_flags);
c-lex.c (map): Make const. * c-lex.c (map): Make const. (cb_file_change): Update for callback passing a line map. Don't assume we have a previous map. Remove sanity check about popping too many files. * cpperror.c (print_location): Make map const. * cppfiles.c (stack_include_file): Update; line maps now hold sysp. (cpp_make_system_header): Similarly. (search_from): Similarly. (_cpp_execute_include): Don't remember where we came from. * cpphash.h (struct cpp_buffer): Remove return_to_line, sysp. (struct cpp_reader): Make map const. (CPP_IN_SYSTEM_HEADER, _cpp_do_file_change): Update. * cpplib.c (do_line): Update; line maps now hold sysp. (cpp_push_buffer): Similarly. (_cpp_do_file_change): Similarly; callback with map instead. (cpp_get_line_maps): Constify return value. (_cpp_pop_buffer): Update. * cpplib.h (struct cpp_file_change): Remove. (struct cpp_callbacks): Update. (cpp_get_line_maps): Constify return value. * cppmacro.c (_cpp_create_definition): Update. * cppmain.c (struct printer): Constify map. (maybe_print_line): Similarly. (print_line): Similarly. Deduce flags 1 and 2 here. (cb_file_change): Update. * line-map.c (free_line_maps): Warn regardless. (add_line_map): Return pointer to const. When passed NULL to_file with LC_LEAVE, use the obvious values for the return point so the caller doesn't have to figure them out. (lookup_line): Return pointer to const. (print_containing_files): Take pointer to const. * line-map.h (struct line_map): New members reason, sysp. (add_line_map): Return pointer to const. (lookup_line): Similarly. (print_containing_files): Take pointer to const. From-SVN: r44789
2001-08-11 09:33:39 +02:00
Linemap infrastructure for virtual locations This is the first instalment of a set which goal is to track locations of tokens across macro expansions. Tom Tromey did the original work and attached the patch to PR preprocessor/7263. This opus is a derivative of that original work. This patch modifies the linemap module of libcpp to add virtual locations support. A virtual location is a mapped location that can resolve to several different physical locations. It can always resolve to the spelling location of a token. For tokens resulting from macro expansion it can resolve to: - either the location of the expansion point of the macro. - or the location of the token in the definition of the macro - or, if the token is an argument of a function-like macro, the location of the use of the matching macro parameter in the definition of the macro The patch creates a new type of line map called a macro map. For every single macro expansion, there is a macro map that generates a virtual location for every single resulting token of the expansion. The good old type of line map we all know is now called an ordinary map. That one still encodes spelling locations as it has always had. As a result linemap_lookup as been extended to return a macro map when given a virtual location resulting from a macro expansion. The layout of structs line_map has changed to support this new type of map. So did the layout of struct line_maps. Accessor macros have been introduced to avoid messing with the implementation details of these datastructures directly. This helped already as we have been testing different ways of arranging these datastructure. Having to constantly adjust client code that is too tied with the internals of line_map and line_maps would have been even more painful. Of course, many new public functions have been added to the linemap module to handle the resolution of virtual locations. This patch introduces the infrastructure but no part of the compiler uses virtual locations yet. However the client code of the linemap data structures has been adjusted as per the changes. E.g, it's not anymore reliable for a client code to manipulate struct line_map directly if it just wants to deal with spelling locations, because struct line_map can now represent a macro map as well. In that case, it's better to use the convenient API to resolve the initial (possibly virtual) location to a spelling location (or to an ordinary map) and use that. This is the reason why the patch adjusts the Java, Ada and Fortran front ends. Also, note that virtual locations are not supposed to be ordered for relations '<' and '>' anymore. To test if a virtual location appears "before" another one, one has to use a new operator exposed by the line map interface. The patch updates the only spot (in the diagnostics module) I have found that was making the assumption that locations were ordered for these relations. This is the only change that introduces a use of the new line map API in this patch, so I am adding a regression test for it only. From-SVN: r180081
2011-10-17 11:58:56 +02:00
sysp = in_system_header_at (src_loc);
if (sysp == 2)
fputs (" 3 4", stream);
Linemap infrastructure for virtual locations This is the first instalment of a set which goal is to track locations of tokens across macro expansions. Tom Tromey did the original work and attached the patch to PR preprocessor/7263. This opus is a derivative of that original work. This patch modifies the linemap module of libcpp to add virtual locations support. A virtual location is a mapped location that can resolve to several different physical locations. It can always resolve to the spelling location of a token. For tokens resulting from macro expansion it can resolve to: - either the location of the expansion point of the macro. - or the location of the token in the definition of the macro - or, if the token is an argument of a function-like macro, the location of the use of the matching macro parameter in the definition of the macro The patch creates a new type of line map called a macro map. For every single macro expansion, there is a macro map that generates a virtual location for every single resulting token of the expansion. The good old type of line map we all know is now called an ordinary map. That one still encodes spelling locations as it has always had. As a result linemap_lookup as been extended to return a macro map when given a virtual location resulting from a macro expansion. The layout of structs line_map has changed to support this new type of map. So did the layout of struct line_maps. Accessor macros have been introduced to avoid messing with the implementation details of these datastructures directly. This helped already as we have been testing different ways of arranging these datastructure. Having to constantly adjust client code that is too tied with the internals of line_map and line_maps would have been even more painful. Of course, many new public functions have been added to the linemap module to handle the resolution of virtual locations. This patch introduces the infrastructure but no part of the compiler uses virtual locations yet. However the client code of the linemap data structures has been adjusted as per the changes. E.g, it's not anymore reliable for a client code to manipulate struct line_map directly if it just wants to deal with spelling locations, because struct line_map can now represent a macro map as well. In that case, it's better to use the convenient API to resolve the initial (possibly virtual) location to a spelling location (or to an ordinary map) and use that. This is the reason why the patch adjusts the Java, Ada and Fortran front ends. Also, note that virtual locations are not supposed to be ordered for relations '<' and '>' anymore. To test if a virtual location appears "before" another one, one has to use a new operator exposed by the line map interface. The patch updates the only spot (in the diagnostics module) I have found that was making the assumption that locations were ordered for these relations. This is the only change that introduces a use of the new line map API in this patch, so I am adding a regression test for it only. From-SVN: r180081
2011-10-17 11:58:56 +02:00
else if (sysp == 1)
fputs (" 3", stream);
c-lex.c (map): Make const. * c-lex.c (map): Make const. (cb_file_change): Update for callback passing a line map. Don't assume we have a previous map. Remove sanity check about popping too many files. * cpperror.c (print_location): Make map const. * cppfiles.c (stack_include_file): Update; line maps now hold sysp. (cpp_make_system_header): Similarly. (search_from): Similarly. (_cpp_execute_include): Don't remember where we came from. * cpphash.h (struct cpp_buffer): Remove return_to_line, sysp. (struct cpp_reader): Make map const. (CPP_IN_SYSTEM_HEADER, _cpp_do_file_change): Update. * cpplib.c (do_line): Update; line maps now hold sysp. (cpp_push_buffer): Similarly. (_cpp_do_file_change): Similarly; callback with map instead. (cpp_get_line_maps): Constify return value. (_cpp_pop_buffer): Update. * cpplib.h (struct cpp_file_change): Remove. (struct cpp_callbacks): Update. (cpp_get_line_maps): Constify return value. * cppmacro.c (_cpp_create_definition): Update. * cppmain.c (struct printer): Constify map. (maybe_print_line): Similarly. (print_line): Similarly. Deduce flags 1 and 2 here. (cb_file_change): Update. * line-map.c (free_line_maps): Warn regardless. (add_line_map): Return pointer to const. When passed NULL to_file with LC_LEAVE, use the obvious values for the return point so the caller doesn't have to figure them out. (lookup_line): Return pointer to const. (print_containing_files): Take pointer to const. * line-map.h (struct line_map): New members reason, sysp. (add_line_map): Return pointer to const. (lookup_line): Similarly. (print_containing_files): Take pointer to const. From-SVN: r44789
2001-08-11 09:33:39 +02:00
putc ('\n', stream);
PR preprocessor/60723 - missing system-ness marks for macro tokens When a system macro is expanded in a non-system file during out-of-line preprocessing, it can happen that the preprocessor forgets to emit line markers to express the system-ness status of tokens that come after the expansion of the macro. That can lead to situations where the entire non-system file can be considered as being a system file and thus have its warnings be discarded during the compilation of the resulting preprocessed file. My understanding is that this is due to the preprocessor not systematically detecting (and reporting) the change in system-ness of tokens. And this is what this patch does. Each time the system-ness of a given token is different from the previous token that was emitted by the preprocessor, it emits a line marker for the sole purpose of marking the new system-ness of the subsequent tokens to come. Bootstrapped and tested on x86_64-unknown-linux-gnu against trunk. gcc/c-family/ChangeLog: * c-ppoutput.c (struct print::prev_was_system_token): New data member. (init_pp_output): Initialize it. (maybe_print_line_1, maybe_print_line, print_line_1, print_line) (do_line_change): Return a flag saying if a line marker was emitted or not. (scan_translation_unit): Detect if the system-ness of the token we are about to emit is different from the one of the previously emitted token. If so, emit a line marker. Avoid emitting useless adjacent line markers. Avoid emitting line markers for tokens originating from the expansion of built-in macros. (scan_translation_unit_directives_only): Adjust. gcc/testsuite/ChangeLog: * gcc.dg/cpp/syshdr{4,5}.{c,h}: New test files. Signed-off-by: Dodji Seketeli <dodji@redhat.com> Signed-off-by: Dodji Seketeli <dodji@redhat.com> From-SVN: r212638
2014-07-16 12:33:36 +02:00
emitted_line_marker = true;
c-lex.c (map): Make const. * c-lex.c (map): Make const. (cb_file_change): Update for callback passing a line map. Don't assume we have a previous map. Remove sanity check about popping too many files. * cpperror.c (print_location): Make map const. * cppfiles.c (stack_include_file): Update; line maps now hold sysp. (cpp_make_system_header): Similarly. (search_from): Similarly. (_cpp_execute_include): Don't remember where we came from. * cpphash.h (struct cpp_buffer): Remove return_to_line, sysp. (struct cpp_reader): Make map const. (CPP_IN_SYSTEM_HEADER, _cpp_do_file_change): Update. * cpplib.c (do_line): Update; line maps now hold sysp. (cpp_push_buffer): Similarly. (_cpp_do_file_change): Similarly; callback with map instead. (cpp_get_line_maps): Constify return value. (_cpp_pop_buffer): Update. * cpplib.h (struct cpp_file_change): Remove. (struct cpp_callbacks): Update. (cpp_get_line_maps): Constify return value. * cppmacro.c (_cpp_create_definition): Update. * cppmain.c (struct printer): Constify map. (maybe_print_line): Similarly. (print_line): Similarly. Deduce flags 1 and 2 here. (cb_file_change): Update. * line-map.c (free_line_maps): Warn regardless. (add_line_map): Return pointer to const. When passed NULL to_file with LC_LEAVE, use the obvious values for the return point so the caller doesn't have to figure them out. (lookup_line): Return pointer to const. (print_containing_files): Take pointer to const. * line-map.h (struct line_map): New members reason, sysp. (add_line_map): Return pointer to const. (lookup_line): Similarly. (print_containing_files): Take pointer to const. From-SVN: r44789
2001-08-11 09:33:39 +02:00
}
PR preprocessor/60723 - missing system-ness marks for macro tokens When a system macro is expanded in a non-system file during out-of-line preprocessing, it can happen that the preprocessor forgets to emit line markers to express the system-ness status of tokens that come after the expansion of the macro. That can lead to situations where the entire non-system file can be considered as being a system file and thus have its warnings be discarded during the compilation of the resulting preprocessed file. My understanding is that this is due to the preprocessor not systematically detecting (and reporting) the change in system-ness of tokens. And this is what this patch does. Each time the system-ness of a given token is different from the previous token that was emitted by the preprocessor, it emits a line marker for the sole purpose of marking the new system-ness of the subsequent tokens to come. Bootstrapped and tested on x86_64-unknown-linux-gnu against trunk. gcc/c-family/ChangeLog: * c-ppoutput.c (struct print::prev_was_system_token): New data member. (init_pp_output): Initialize it. (maybe_print_line_1, maybe_print_line, print_line_1, print_line) (do_line_change): Return a flag saying if a line marker was emitted or not. (scan_translation_unit): Detect if the system-ness of the token we are about to emit is different from the one of the previously emitted token. If so, emit a line marker. Avoid emitting useless adjacent line markers. Avoid emitting line markers for tokens originating from the expansion of built-in macros. (scan_translation_unit_directives_only): Adjust. gcc/testsuite/ChangeLog: * gcc.dg/cpp/syshdr{4,5}.{c,h}: New test files. Signed-off-by: Dodji Seketeli <dodji@redhat.com> Signed-off-by: Dodji Seketeli <dodji@redhat.com> From-SVN: r212638
2014-07-16 12:33:36 +02:00
return emitted_line_marker;
New macro expander. 2000-10-28 Neil Booth <neilb@earthling.net> New macro expander. * cpplib.c (struct answer): New. (struct if_stack): Use cpp_lexer_pos rather than line and col. Rename cmacro mi_cmacro. (struct directive, KANDR, STDC89, EXTENSION, COND, IF_COND, INCL, IN_I): New directive and flags. (skip_rest_of_line, check_eol, run_directive, glue_header_name, parse_answer, parse_assertion, find_answer): New functions. (parse_ifdef, detect_if_not_defined, validate_else): Remove. (lex_macro_node): New function to replace parse_ifdef and get_define_node. (_cpp_handle_directive): New function, combines _cpp_check_directive and _cpp_check_linemarker. (do_define, do_undef, parse_include, do_include, do_import, do_include_next, read_line_number, do_line, do_ident, do_pragma, do_pragma_once, do_pragma_poison, do_pragma_dependency): Update for new token getting interface. (do_ifdef, do_ifndef, do_if, do_else, do_endif, push_conditional) : Update for new multiple-include optimisation technique. (do_elif): Don't forget to invalidate controlling macros. (unwind_if_stack, cpp_defined, cpp_push_buffer, cpp_pop_buffer): Update. (parse_assertion, parse_answer, find_answer, _cpp_test_assertion): Functions to handle assertions with the new token interface. (do_assert, do_unassert): Use them. (cpp_define, _cpp_define_builtin, cpp_undef, cpp_assert, cpp_unassert): Use run_directive. (_cpp_init_stacks): Register directive names. Don't register special nodes. * cpperror.c (print_containing_files, _cpp_begin_message): Update to new position recording regime. (cpp_ice, cpp_fatal, cpp_error, cpp_error_with_line, cpp_warning, cpp_warning_with_line, cpp_pedwarn, cpp_pedwarn_with_line, cpp_pedwarn_with_file_and_line): Update for _cpp_begin_message changes. (cpp_type2name): Move to cpplex.c. * cppexp.c (parse_charconst): spec_nodes is no longer a pointer. (parse_defined): Update to handle new multiple include optimisation method. Remove poisoned identifier warning. (parse_assertion, TYPE_NAME): Delete. (lex): Update for multiple include optimisation, removal of CPP_DEFINED, to use _cpp_test_assertion for assertions and cpp_token_as_text. (_cpp_parse_expr): Update for MI optimisation, and to use op_as_text. (op_as_text): New function, to wrap cpp_token_as_text. * cppfiles.c (stack_include_file, _cpp_pop_file_buffer): Update for MI optimisation. (_cpp_execute_include): Take a token rather than 3 arguments. Fix segfault on diagnostic. (_cpp_compare_file_date): Take a token rather than 3 args. (cpp_read_file): Work correctly for zero-length files. * cpphash.c (_cpp_init_macros, _cpp_cleanup_macros): Rename _cpp_init_hashtable and _cpp_cleanup_hashtable. (cpp_lookup): Place identifiers at front of identifier pool for _cpp_lookup_with_hash. (_cpp_lookup_with_hash): Require identifiers to be at the front of the identifier pool. Commit the memory if not already in the hash table. * cppinit.c (cpp_reader_init): Move cpp_init_completed test to top. Initialise various members of cpp_reader, memory pools, and the special nodes. (cpp_printer_init): Delete. (cpp_cleanup): Update. (struct builtin, builtin_array, initialize_builtins): Update for new hashnode definition and builtin handling. (cpp_start_read, cpp_finish): Don't take or initialise a printer. Update. * cpplib.h (cpp_printer, cpp_toklist, CPP_DEFINED, BOL, PASTED, VAR_ARGS, BEG_OF_FILE, IN_DIRECTIVE, KNOWN_DIRECTIVE, T_VOID, T_SPECLINE, T_DATE, T_FILE, T_BASE_FILE, T_INCLUDE_LEVEL, T_TIME, T_STDC, T_OPERATOR, T_POISON, T_MACRO, T_ASSERTION): Delete. (struct cpp_pool, struct cpp_macro, struct cpp_lexer_pos, struct cpp_lookahead, CPP_DHASH, enum mi_state, enum mi_ind, NO_EXPAND, VARARGS_FIRST, struct cpp_token_with_pos, struct toklist, struct cpp_context, struct specnodes, TOKEN_LOOKAHEAD, TOKEN_BUFFSIZE, NODE_OPERATOR, NODE_POISONED, NODE_BUILTIN, NODE_DIAGNOSTIC, NT_VOID, NT_MACRO, NT_ASSERTION, enum builtin_type, cpp_can_paste): New. (struct cpp_token): Delete line and col members. (struct cpp_buffer): New member output_lineno. (struct lexer_state): Delete indented, in_lex_line, seen_dot. Add va_args_ok, poisoned_ok, prevent_expansion, parsing_args. (struct cpp_reader): New members lexer_pos, macro_pos, directive_pos, ident_pool, temp_string_pool, macro_pool, argument_pool, string_pool, base_context, context, directive, mi_state, mi_if_not_defined, mi_lexed, mi_cmacro, mi_ind_cmacro, la_read, la_write, la_unused, mlstring_pos, macro_buffer, macro_buffer_len. Delete members mls_line, mls_column, token_list, potential_control_macro, temp_tokens, temp_cap, temp_alloced, temp_used, first_directive_token, context_cap, cur_context, no_expand_level, paste_level, contexts, args, save_parameter_spellings, need_newline, . Change type of date, time and spec_nodes members. Change prototypes for include and ident callbacks. (struct cpp_hashnode): Change type of name. Remove union members expansion and code. Add members macro, operator and builtin. (cpp_token_len, cpp_token_as_text, cpp_spell_token, cpp_start_read, cpp_finish, cpp_avoid_paste, cpp_get_token, cpp_get_line, cpp_get_output_line, cpp_macro_definition, cpp_start_lookahead, cpp_stop_lookahead): New prototypes. (cpp_printer_init, cpp_dump_definition): Delete prototypes. (U_CHAR, U, ustrcmp, ustrncmp, ustrlen, uxstrdup, ustrchr, ufputs): Move from cpphash.h. * cpphash.h (U_CHAR, U, ustrcmp, ustrncmp, ustrlen, uxstrdup, ustrchr, ufputs): Move to cpplib.h. (enum spell_type, struct token_spelling, _cpp_token_spellings, TOKEN_SPELL, TOKEN_NAME, struct answer, FREE_ANSWER, KANDR, STDC89, EXTENSION, COND, EXPAND, INCL, COMMENTS, IN_I, struct directive, directive_handler, struct spec_nodes, _cpp_digraph_spellings, _cpp_free_temp_tokens, _cpp_init_input_buffer, _cpp_grow_token_buffer, _cpp_init_toklist, _cpp_clear_toklist, _cpp_expand_token_space, _cpp_expand_name_space, _cpp_equiv_tokens, _cpp_equiv_toklists, _cpp_process_directive, _cpp_run_directive, _cpp_get_line, _cpp_get_raw_token, _cpp_glue_header_name, _cpp_can_paste, _cpp_check_directive, _cpp_check_linemarker, _cpp_parse_assertion, _cpp_find_answer): Delete. (VALID_SIGN, ALIGN, POOL_FRONT, POOL_LIMIT, POOL_BASE, POOL_SIZE, POOL_USED, POOL_COMMIT, struct cpp_chunk, _cpp_lex_token, _cpp_init_pool, _cpp_free_pool, _cpp_pool_reserve, _cpp_pool_alloc, _cpp_next_chunk, _cpp_lock_pool, _cpp_unlock_pool, _cpp_test_assertion, _cpp_handle_directive, DSC): New. (struct include_file): New member defined. (DO_NOT_REREAD, _cpp_begin_message, _cpp_execute_include, _cpp_compare_file_date): Update. (_cpp_pop_context, _cpp_get_token, _cpp_free_lookaheads, _cpp_push_token): New. (_cpp_init_macros, _cpp_cleanup_macros): Rename to _cpp_init_hashtable, _cpp_cleanup_hashtable. * Makefile.in: Remove cppoutput.c. * cppoutput.c: Delete * fixheader.c (read_scan_file): Update for new cpp_get_token prototype. (recognized_function): New argument LINE. * scan-decls.c (skip_to_closing_brace, scan_decls): Update for new cpp_get_token prototype. * scan.h (recognized_function): Update prototype. * po/POTFILES.in: Remove cppoutput.c. From-SVN: r37098
2000-10-28 19:59:06 +02:00
}
/* Output a line marker for logical line LINE. Special flags are "1"
PR preprocessor/60723 - missing system-ness marks for macro tokens When a system macro is expanded in a non-system file during out-of-line preprocessing, it can happen that the preprocessor forgets to emit line markers to express the system-ness status of tokens that come after the expansion of the macro. That can lead to situations where the entire non-system file can be considered as being a system file and thus have its warnings be discarded during the compilation of the resulting preprocessed file. My understanding is that this is due to the preprocessor not systematically detecting (and reporting) the change in system-ness of tokens. And this is what this patch does. Each time the system-ness of a given token is different from the previous token that was emitted by the preprocessor, it emits a line marker for the sole purpose of marking the new system-ness of the subsequent tokens to come. Bootstrapped and tested on x86_64-unknown-linux-gnu against trunk. gcc/c-family/ChangeLog: * c-ppoutput.c (struct print::prev_was_system_token): New data member. (init_pp_output): Initialize it. (maybe_print_line_1, maybe_print_line, print_line_1, print_line) (do_line_change): Return a flag saying if a line marker was emitted or not. (scan_translation_unit): Detect if the system-ness of the token we are about to emit is different from the one of the previously emitted token. If so, emit a line marker. Avoid emitting useless adjacent line markers. Avoid emitting line markers for tokens originating from the expansion of built-in macros. (scan_translation_unit_directives_only): Adjust. gcc/testsuite/ChangeLog: * gcc.dg/cpp/syshdr{4,5}.{c,h}: New test files. Signed-off-by: Dodji Seketeli <dodji@redhat.com> Signed-off-by: Dodji Seketeli <dodji@redhat.com> From-SVN: r212638
2014-07-16 12:33:36 +02:00
or "2" indicating entering or leaving a file. Return TRUE if a
line marker was effectively emitted, FALSE otherwise. */
PR preprocessor/60723 - missing system-ness marks for macro tokens When a system macro is expanded in a non-system file during out-of-line preprocessing, it can happen that the preprocessor forgets to emit line markers to express the system-ness status of tokens that come after the expansion of the macro. That can lead to situations where the entire non-system file can be considered as being a system file and thus have its warnings be discarded during the compilation of the resulting preprocessed file. My understanding is that this is due to the preprocessor not systematically detecting (and reporting) the change in system-ness of tokens. And this is what this patch does. Each time the system-ness of a given token is different from the previous token that was emitted by the preprocessor, it emits a line marker for the sole purpose of marking the new system-ness of the subsequent tokens to come. Bootstrapped and tested on x86_64-unknown-linux-gnu against trunk. gcc/c-family/ChangeLog: * c-ppoutput.c (struct print::prev_was_system_token): New data member. (init_pp_output): Initialize it. (maybe_print_line_1, maybe_print_line, print_line_1, print_line) (do_line_change): Return a flag saying if a line marker was emitted or not. (scan_translation_unit): Detect if the system-ness of the token we are about to emit is different from the one of the previously emitted token. If so, emit a line marker. Avoid emitting useless adjacent line markers. Avoid emitting line markers for tokens originating from the expansion of built-in macros. (scan_translation_unit_directives_only): Adjust. gcc/testsuite/ChangeLog: * gcc.dg/cpp/syshdr{4,5}.{c,h}: New test files. Signed-off-by: Dodji Seketeli <dodji@redhat.com> Signed-off-by: Dodji Seketeli <dodji@redhat.com> From-SVN: r212638
2014-07-16 12:33:36 +02:00
static bool
print_line (source_location src_loc, const char *special_flags)
{
if (cpp_get_options (parse_in)->debug)
linemap_dump_location (line_table, src_loc,
print.outf);
PR preprocessor/60723 - missing system-ness marks for macro tokens When a system macro is expanded in a non-system file during out-of-line preprocessing, it can happen that the preprocessor forgets to emit line markers to express the system-ness status of tokens that come after the expansion of the macro. That can lead to situations where the entire non-system file can be considered as being a system file and thus have its warnings be discarded during the compilation of the resulting preprocessed file. My understanding is that this is due to the preprocessor not systematically detecting (and reporting) the change in system-ness of tokens. And this is what this patch does. Each time the system-ness of a given token is different from the previous token that was emitted by the preprocessor, it emits a line marker for the sole purpose of marking the new system-ness of the subsequent tokens to come. Bootstrapped and tested on x86_64-unknown-linux-gnu against trunk. gcc/c-family/ChangeLog: * c-ppoutput.c (struct print::prev_was_system_token): New data member. (init_pp_output): Initialize it. (maybe_print_line_1, maybe_print_line, print_line_1, print_line) (do_line_change): Return a flag saying if a line marker was emitted or not. (scan_translation_unit): Detect if the system-ness of the token we are about to emit is different from the one of the previously emitted token. If so, emit a line marker. Avoid emitting useless adjacent line markers. Avoid emitting line markers for tokens originating from the expansion of built-in macros. (scan_translation_unit_directives_only): Adjust. gcc/testsuite/ChangeLog: * gcc.dg/cpp/syshdr{4,5}.{c,h}: New test files. Signed-off-by: Dodji Seketeli <dodji@redhat.com> Signed-off-by: Dodji Seketeli <dodji@redhat.com> From-SVN: r212638
2014-07-16 12:33:36 +02:00
return print_line_1 (src_loc, special_flags, print.outf);
}
PR preprocessor/60723 - missing system-ness marks for macro tokens When a system macro is expanded in a non-system file during out-of-line preprocessing, it can happen that the preprocessor forgets to emit line markers to express the system-ness status of tokens that come after the expansion of the macro. That can lead to situations where the entire non-system file can be considered as being a system file and thus have its warnings be discarded during the compilation of the resulting preprocessed file. My understanding is that this is due to the preprocessor not systematically detecting (and reporting) the change in system-ness of tokens. And this is what this patch does. Each time the system-ness of a given token is different from the previous token that was emitted by the preprocessor, it emits a line marker for the sole purpose of marking the new system-ness of the subsequent tokens to come. Bootstrapped and tested on x86_64-unknown-linux-gnu against trunk. gcc/c-family/ChangeLog: * c-ppoutput.c (struct print::prev_was_system_token): New data member. (init_pp_output): Initialize it. (maybe_print_line_1, maybe_print_line, print_line_1, print_line) (do_line_change): Return a flag saying if a line marker was emitted or not. (scan_translation_unit): Detect if the system-ness of the token we are about to emit is different from the one of the previously emitted token. If so, emit a line marker. Avoid emitting useless adjacent line markers. Avoid emitting line markers for tokens originating from the expansion of built-in macros. (scan_translation_unit_directives_only): Adjust. gcc/testsuite/ChangeLog: * gcc.dg/cpp/syshdr{4,5}.{c,h}: New test files. Signed-off-by: Dodji Seketeli <dodji@redhat.com> Signed-off-by: Dodji Seketeli <dodji@redhat.com> From-SVN: r212638
2014-07-16 12:33:36 +02:00
/* Helper function for cb_line_change and scan_translation_unit.
Return TRUE if a line marker is emitted, FALSE otherwise. */
static bool
do_line_change (cpp_reader *pfile, const cpp_token *token,
source_location src_loc, int parsing_args)
{
PR preprocessor/60723 - missing system-ness marks for macro tokens When a system macro is expanded in a non-system file during out-of-line preprocessing, it can happen that the preprocessor forgets to emit line markers to express the system-ness status of tokens that come after the expansion of the macro. That can lead to situations where the entire non-system file can be considered as being a system file and thus have its warnings be discarded during the compilation of the resulting preprocessed file. My understanding is that this is due to the preprocessor not systematically detecting (and reporting) the change in system-ness of tokens. And this is what this patch does. Each time the system-ness of a given token is different from the previous token that was emitted by the preprocessor, it emits a line marker for the sole purpose of marking the new system-ness of the subsequent tokens to come. Bootstrapped and tested on x86_64-unknown-linux-gnu against trunk. gcc/c-family/ChangeLog: * c-ppoutput.c (struct print::prev_was_system_token): New data member. (init_pp_output): Initialize it. (maybe_print_line_1, maybe_print_line, print_line_1, print_line) (do_line_change): Return a flag saying if a line marker was emitted or not. (scan_translation_unit): Detect if the system-ness of the token we are about to emit is different from the one of the previously emitted token. If so, emit a line marker. Avoid emitting useless adjacent line markers. Avoid emitting line markers for tokens originating from the expansion of built-in macros. (scan_translation_unit_directives_only): Adjust. gcc/testsuite/ChangeLog: * gcc.dg/cpp/syshdr{4,5}.{c,h}: New test files. Signed-off-by: Dodji Seketeli <dodji@redhat.com> Signed-off-by: Dodji Seketeli <dodji@redhat.com> From-SVN: r212638
2014-07-16 12:33:36 +02:00
bool emitted_line_marker = false;
if (define_queue || undef_queue)
dump_queued_macros (pfile);
if (token->type == CPP_EOF || parsing_args)
PR preprocessor/60723 - missing system-ness marks for macro tokens When a system macro is expanded in a non-system file during out-of-line preprocessing, it can happen that the preprocessor forgets to emit line markers to express the system-ness status of tokens that come after the expansion of the macro. That can lead to situations where the entire non-system file can be considered as being a system file and thus have its warnings be discarded during the compilation of the resulting preprocessed file. My understanding is that this is due to the preprocessor not systematically detecting (and reporting) the change in system-ness of tokens. And this is what this patch does. Each time the system-ness of a given token is different from the previous token that was emitted by the preprocessor, it emits a line marker for the sole purpose of marking the new system-ness of the subsequent tokens to come. Bootstrapped and tested on x86_64-unknown-linux-gnu against trunk. gcc/c-family/ChangeLog: * c-ppoutput.c (struct print::prev_was_system_token): New data member. (init_pp_output): Initialize it. (maybe_print_line_1, maybe_print_line, print_line_1, print_line) (do_line_change): Return a flag saying if a line marker was emitted or not. (scan_translation_unit): Detect if the system-ness of the token we are about to emit is different from the one of the previously emitted token. If so, emit a line marker. Avoid emitting useless adjacent line markers. Avoid emitting line markers for tokens originating from the expansion of built-in macros. (scan_translation_unit_directives_only): Adjust. gcc/testsuite/ChangeLog: * gcc.dg/cpp/syshdr{4,5}.{c,h}: New test files. Signed-off-by: Dodji Seketeli <dodji@redhat.com> Signed-off-by: Dodji Seketeli <dodji@redhat.com> From-SVN: r212638
2014-07-16 12:33:36 +02:00
return false;
PR preprocessor/60723 - missing system-ness marks for macro tokens When a system macro is expanded in a non-system file during out-of-line preprocessing, it can happen that the preprocessor forgets to emit line markers to express the system-ness status of tokens that come after the expansion of the macro. That can lead to situations where the entire non-system file can be considered as being a system file and thus have its warnings be discarded during the compilation of the resulting preprocessed file. My understanding is that this is due to the preprocessor not systematically detecting (and reporting) the change in system-ness of tokens. And this is what this patch does. Each time the system-ness of a given token is different from the previous token that was emitted by the preprocessor, it emits a line marker for the sole purpose of marking the new system-ness of the subsequent tokens to come. Bootstrapped and tested on x86_64-unknown-linux-gnu against trunk. gcc/c-family/ChangeLog: * c-ppoutput.c (struct print::prev_was_system_token): New data member. (init_pp_output): Initialize it. (maybe_print_line_1, maybe_print_line, print_line_1, print_line) (do_line_change): Return a flag saying if a line marker was emitted or not. (scan_translation_unit): Detect if the system-ness of the token we are about to emit is different from the one of the previously emitted token. If so, emit a line marker. Avoid emitting useless adjacent line markers. Avoid emitting line markers for tokens originating from the expansion of built-in macros. (scan_translation_unit_directives_only): Adjust. gcc/testsuite/ChangeLog: * gcc.dg/cpp/syshdr{4,5}.{c,h}: New test files. Signed-off-by: Dodji Seketeli <dodji@redhat.com> Signed-off-by: Dodji Seketeli <dodji@redhat.com> From-SVN: r212638
2014-07-16 12:33:36 +02:00
emitted_line_marker = maybe_print_line (src_loc);
print.prev = 0;
print.source = 0;
/* Supply enough spaces to put this token in its original column,
one space per column greater than 2, since scan_translation_unit
will provide a space if PREV_WHITE. Don't bother trying to
reconstruct tabs; we can't get it right in general, and nothing
ought to care. Some things do care; the fault lies with them. */
if (!CPP_OPTION (pfile, traditional))
{
Linemap infrastructure for virtual locations This is the first instalment of a set which goal is to track locations of tokens across macro expansions. Tom Tromey did the original work and attached the patch to PR preprocessor/7263. This opus is a derivative of that original work. This patch modifies the linemap module of libcpp to add virtual locations support. A virtual location is a mapped location that can resolve to several different physical locations. It can always resolve to the spelling location of a token. For tokens resulting from macro expansion it can resolve to: - either the location of the expansion point of the macro. - or the location of the token in the definition of the macro - or, if the token is an argument of a function-like macro, the location of the use of the matching macro parameter in the definition of the macro The patch creates a new type of line map called a macro map. For every single macro expansion, there is a macro map that generates a virtual location for every single resulting token of the expansion. The good old type of line map we all know is now called an ordinary map. That one still encodes spelling locations as it has always had. As a result linemap_lookup as been extended to return a macro map when given a virtual location resulting from a macro expansion. The layout of structs line_map has changed to support this new type of map. So did the layout of struct line_maps. Accessor macros have been introduced to avoid messing with the implementation details of these datastructures directly. This helped already as we have been testing different ways of arranging these datastructure. Having to constantly adjust client code that is too tied with the internals of line_map and line_maps would have been even more painful. Of course, many new public functions have been added to the linemap module to handle the resolution of virtual locations. This patch introduces the infrastructure but no part of the compiler uses virtual locations yet. However the client code of the linemap data structures has been adjusted as per the changes. E.g, it's not anymore reliable for a client code to manipulate struct line_map directly if it just wants to deal with spelling locations, because struct line_map can now represent a macro map as well. In that case, it's better to use the convenient API to resolve the initial (possibly virtual) location to a spelling location (or to an ordinary map) and use that. This is the reason why the patch adjusts the Java, Ada and Fortran front ends. Also, note that virtual locations are not supposed to be ordered for relations '<' and '>' anymore. To test if a virtual location appears "before" another one, one has to use a new operator exposed by the line map interface. The patch updates the only spot (in the diagnostics module) I have found that was making the assumption that locations were ordered for these relations. This is the only change that introduces a use of the new line map API in this patch, so I am adding a regression test for it only. From-SVN: r180081
2011-10-17 11:58:56 +02:00
int spaces = LOCATION_COLUMN (src_loc) - 2;
print.printed = true;
Represent column numbers using line-map's source_location. The "next available source_location" is now managed internally by line-maps.c rather than by clients. * line-map.h (struct line_map): New field column_bits. <from_line>: Rename field to start_location. (struct line_maps): New fields highest_location and max_column_hint. (linemap_check_files_exited): New declaration. (linemap_line_start): New declaration. (linemap_add): Remove from_line parameter; use highest_location field. (SOURCE_LINE, LAST_SOURCE_LINE): Modify to use column_bits. (SOURCE_COLUMN, LAST_SOURCE_LINE_LOCATION): New macros. (CURRENT_LINE_MAP): Remove macro. (linemap_position_for_column): New inline function. * line-map.c (linemap_init): Clear new fields. (linemap_check_files_exited): New function, extracted from ... (linemap_free): Use linemap_check_files_exited. (linemap_add): Remove from_line parameter. Various updates. (linemap_line_start): New function. (linemap_lookeup): Update for new field names. * cpphash.h (struct cpp_reader) <map>: Field removed. Because linemap_position_for_column may unpredictably change the current map, it is cleaner and simpler for us to not cache it in cpp_reader. (struct cpp_buffer): New sysp field. Changed warned_cplusplus_comments and from_stage3 to bitfields. * cppinit.c (cpp_read_min_file): pfile->map no longer exists. * cpplib.c (do_line, do_linemarker, _cpp_do_file_change): Get current map using linemap_lookup. (do_linemarker): Also set buffer's sysp field. (destringize_and_run): No longer need to decrement current line. * cppfiles.c (_cpp_stack_file): Set sysp from and in buffer. (search_path_head, open_file_failed): Use buffer's sysp. (cpp_make_system_header): Get current map using linemap_lookup. Also set buffer's sysp flag. * cppmacro.c (_cpp_builtin_macro_text): Likewise use linemap_lookup. * cpphash.h (CPP_INCREMENT_LINE): New macro. (struct cpp_buffer): Moved fields saved_cur, saved_rlimit to ... (struct cpp_reader): ... and adding saved_line_base field. * cpptrad.c (_cpp_overlay_buffer, _cpp_remove_overlay): Update accordingly. Don't adjust line. (_cpp_scan_out_logical_line): Use CPP_INCREMENT_LINE. * cpphash.c (CPP_IN_SYSTEM_HEADER): Replaced macro by ... (cpp_in_system_header): ... new inline function, using buffer's sysp. * cpperror.c (_cpp_begin_message): Update to use cpp_in_system_header. * cpplex.c (_cpp_lex_direct): Likewise. * cppmacro.c (_cpp_builtin_macro_text): Likewise. * cppmacro.c (_cpp_create_definition): Use buffer's sysp field. * cpplib.h (struct cpp_token): Rename line field to src_loc. Remove col field as it is now subsumed by src_loc. * cpperror.c: Update various field, parameter, and macro names. (print_location): If col==0, try SOURCE_COLUMN of line. (cpp_error): Use cur_token's src_loc field, rather than line+col. * cpplib.c (do_diagnostic): Token's src_loc fields replaces line+col. * cpplex.c (_cpp_process_line_notes, _cpp_lex_direct, _cpp_skip_block_comment): Use CPP_INCREMENT_LINE. (_cpp_temp_token): Replace cpp_token's line+col fields by src_loc. (_cpp_get_fresh_line): Don't need to adjust line for missing newline. (_cpp_lex_direct): Use linemap_position_for_column. * c-ppoutput.c (maybe_print_line, print_line): Don't take map parameter. Instead get it from the line_table global. Adjust callers. (print): Remove map field. Replace line field to src_line. (init_pp_output, account_for_newlines, maybe_print_line): Adjust. (cb_line_change): Use SOURCE_COLUMN. Minor optimizations. (pp_file_change): Use MAIN_FILE_P since we cannot checked print.map. Use LAST_SOURCE_LINE_LOCATION to "catch up" after #include. * cpptrad.c (copy_comment): Rename variable. * c-lex.c (map): Remove static variable, for same reason we removed cpp_reader's map field. (cb_line_change, cb_def_pragma, cb_define, cb_undef): Hence we need to call linemap_lookup. (cb_line_change): Token's line field replaced by src_loc. (fe_file_change): Use MAINFILE_P and LAST_SOURCE_LINE macros. Don't save new_map. * cpphash.h, cpperror.c, cpplib.h: Some renames of fileline to source_location. From-SVN: r77663
2004-02-11 16:29:30 +01:00
while (-- spaces >= 0)
putc (' ', print.outf);
}
PR preprocessor/60723 - missing system-ness marks for macro tokens When a system macro is expanded in a non-system file during out-of-line preprocessing, it can happen that the preprocessor forgets to emit line markers to express the system-ness status of tokens that come after the expansion of the macro. That can lead to situations where the entire non-system file can be considered as being a system file and thus have its warnings be discarded during the compilation of the resulting preprocessed file. My understanding is that this is due to the preprocessor not systematically detecting (and reporting) the change in system-ness of tokens. And this is what this patch does. Each time the system-ness of a given token is different from the previous token that was emitted by the preprocessor, it emits a line marker for the sole purpose of marking the new system-ness of the subsequent tokens to come. Bootstrapped and tested on x86_64-unknown-linux-gnu against trunk. gcc/c-family/ChangeLog: * c-ppoutput.c (struct print::prev_was_system_token): New data member. (init_pp_output): Initialize it. (maybe_print_line_1, maybe_print_line, print_line_1, print_line) (do_line_change): Return a flag saying if a line marker was emitted or not. (scan_translation_unit): Detect if the system-ness of the token we are about to emit is different from the one of the previously emitted token. If so, emit a line marker. Avoid emitting useless adjacent line markers. Avoid emitting line markers for tokens originating from the expansion of built-in macros. (scan_translation_unit_directives_only): Adjust. gcc/testsuite/ChangeLog: * gcc.dg/cpp/syshdr{4,5}.{c,h}: New test files. Signed-off-by: Dodji Seketeli <dodji@redhat.com> Signed-off-by: Dodji Seketeli <dodji@redhat.com> From-SVN: r212638
2014-07-16 12:33:36 +02:00
return emitted_line_marker;
}
New macro expander. 2000-10-28 Neil Booth <neilb@earthling.net> New macro expander. * cpplib.c (struct answer): New. (struct if_stack): Use cpp_lexer_pos rather than line and col. Rename cmacro mi_cmacro. (struct directive, KANDR, STDC89, EXTENSION, COND, IF_COND, INCL, IN_I): New directive and flags. (skip_rest_of_line, check_eol, run_directive, glue_header_name, parse_answer, parse_assertion, find_answer): New functions. (parse_ifdef, detect_if_not_defined, validate_else): Remove. (lex_macro_node): New function to replace parse_ifdef and get_define_node. (_cpp_handle_directive): New function, combines _cpp_check_directive and _cpp_check_linemarker. (do_define, do_undef, parse_include, do_include, do_import, do_include_next, read_line_number, do_line, do_ident, do_pragma, do_pragma_once, do_pragma_poison, do_pragma_dependency): Update for new token getting interface. (do_ifdef, do_ifndef, do_if, do_else, do_endif, push_conditional) : Update for new multiple-include optimisation technique. (do_elif): Don't forget to invalidate controlling macros. (unwind_if_stack, cpp_defined, cpp_push_buffer, cpp_pop_buffer): Update. (parse_assertion, parse_answer, find_answer, _cpp_test_assertion): Functions to handle assertions with the new token interface. (do_assert, do_unassert): Use them. (cpp_define, _cpp_define_builtin, cpp_undef, cpp_assert, cpp_unassert): Use run_directive. (_cpp_init_stacks): Register directive names. Don't register special nodes. * cpperror.c (print_containing_files, _cpp_begin_message): Update to new position recording regime. (cpp_ice, cpp_fatal, cpp_error, cpp_error_with_line, cpp_warning, cpp_warning_with_line, cpp_pedwarn, cpp_pedwarn_with_line, cpp_pedwarn_with_file_and_line): Update for _cpp_begin_message changes. (cpp_type2name): Move to cpplex.c. * cppexp.c (parse_charconst): spec_nodes is no longer a pointer. (parse_defined): Update to handle new multiple include optimisation method. Remove poisoned identifier warning. (parse_assertion, TYPE_NAME): Delete. (lex): Update for multiple include optimisation, removal of CPP_DEFINED, to use _cpp_test_assertion for assertions and cpp_token_as_text. (_cpp_parse_expr): Update for MI optimisation, and to use op_as_text. (op_as_text): New function, to wrap cpp_token_as_text. * cppfiles.c (stack_include_file, _cpp_pop_file_buffer): Update for MI optimisation. (_cpp_execute_include): Take a token rather than 3 arguments. Fix segfault on diagnostic. (_cpp_compare_file_date): Take a token rather than 3 args. (cpp_read_file): Work correctly for zero-length files. * cpphash.c (_cpp_init_macros, _cpp_cleanup_macros): Rename _cpp_init_hashtable and _cpp_cleanup_hashtable. (cpp_lookup): Place identifiers at front of identifier pool for _cpp_lookup_with_hash. (_cpp_lookup_with_hash): Require identifiers to be at the front of the identifier pool. Commit the memory if not already in the hash table. * cppinit.c (cpp_reader_init): Move cpp_init_completed test to top. Initialise various members of cpp_reader, memory pools, and the special nodes. (cpp_printer_init): Delete. (cpp_cleanup): Update. (struct builtin, builtin_array, initialize_builtins): Update for new hashnode definition and builtin handling. (cpp_start_read, cpp_finish): Don't take or initialise a printer. Update. * cpplib.h (cpp_printer, cpp_toklist, CPP_DEFINED, BOL, PASTED, VAR_ARGS, BEG_OF_FILE, IN_DIRECTIVE, KNOWN_DIRECTIVE, T_VOID, T_SPECLINE, T_DATE, T_FILE, T_BASE_FILE, T_INCLUDE_LEVEL, T_TIME, T_STDC, T_OPERATOR, T_POISON, T_MACRO, T_ASSERTION): Delete. (struct cpp_pool, struct cpp_macro, struct cpp_lexer_pos, struct cpp_lookahead, CPP_DHASH, enum mi_state, enum mi_ind, NO_EXPAND, VARARGS_FIRST, struct cpp_token_with_pos, struct toklist, struct cpp_context, struct specnodes, TOKEN_LOOKAHEAD, TOKEN_BUFFSIZE, NODE_OPERATOR, NODE_POISONED, NODE_BUILTIN, NODE_DIAGNOSTIC, NT_VOID, NT_MACRO, NT_ASSERTION, enum builtin_type, cpp_can_paste): New. (struct cpp_token): Delete line and col members. (struct cpp_buffer): New member output_lineno. (struct lexer_state): Delete indented, in_lex_line, seen_dot. Add va_args_ok, poisoned_ok, prevent_expansion, parsing_args. (struct cpp_reader): New members lexer_pos, macro_pos, directive_pos, ident_pool, temp_string_pool, macro_pool, argument_pool, string_pool, base_context, context, directive, mi_state, mi_if_not_defined, mi_lexed, mi_cmacro, mi_ind_cmacro, la_read, la_write, la_unused, mlstring_pos, macro_buffer, macro_buffer_len. Delete members mls_line, mls_column, token_list, potential_control_macro, temp_tokens, temp_cap, temp_alloced, temp_used, first_directive_token, context_cap, cur_context, no_expand_level, paste_level, contexts, args, save_parameter_spellings, need_newline, . Change type of date, time and spec_nodes members. Change prototypes for include and ident callbacks. (struct cpp_hashnode): Change type of name. Remove union members expansion and code. Add members macro, operator and builtin. (cpp_token_len, cpp_token_as_text, cpp_spell_token, cpp_start_read, cpp_finish, cpp_avoid_paste, cpp_get_token, cpp_get_line, cpp_get_output_line, cpp_macro_definition, cpp_start_lookahead, cpp_stop_lookahead): New prototypes. (cpp_printer_init, cpp_dump_definition): Delete prototypes. (U_CHAR, U, ustrcmp, ustrncmp, ustrlen, uxstrdup, ustrchr, ufputs): Move from cpphash.h. * cpphash.h (U_CHAR, U, ustrcmp, ustrncmp, ustrlen, uxstrdup, ustrchr, ufputs): Move to cpplib.h. (enum spell_type, struct token_spelling, _cpp_token_spellings, TOKEN_SPELL, TOKEN_NAME, struct answer, FREE_ANSWER, KANDR, STDC89, EXTENSION, COND, EXPAND, INCL, COMMENTS, IN_I, struct directive, directive_handler, struct spec_nodes, _cpp_digraph_spellings, _cpp_free_temp_tokens, _cpp_init_input_buffer, _cpp_grow_token_buffer, _cpp_init_toklist, _cpp_clear_toklist, _cpp_expand_token_space, _cpp_expand_name_space, _cpp_equiv_tokens, _cpp_equiv_toklists, _cpp_process_directive, _cpp_run_directive, _cpp_get_line, _cpp_get_raw_token, _cpp_glue_header_name, _cpp_can_paste, _cpp_check_directive, _cpp_check_linemarker, _cpp_parse_assertion, _cpp_find_answer): Delete. (VALID_SIGN, ALIGN, POOL_FRONT, POOL_LIMIT, POOL_BASE, POOL_SIZE, POOL_USED, POOL_COMMIT, struct cpp_chunk, _cpp_lex_token, _cpp_init_pool, _cpp_free_pool, _cpp_pool_reserve, _cpp_pool_alloc, _cpp_next_chunk, _cpp_lock_pool, _cpp_unlock_pool, _cpp_test_assertion, _cpp_handle_directive, DSC): New. (struct include_file): New member defined. (DO_NOT_REREAD, _cpp_begin_message, _cpp_execute_include, _cpp_compare_file_date): Update. (_cpp_pop_context, _cpp_get_token, _cpp_free_lookaheads, _cpp_push_token): New. (_cpp_init_macros, _cpp_cleanup_macros): Rename to _cpp_init_hashtable, _cpp_cleanup_hashtable. * Makefile.in: Remove cppoutput.c. * cppoutput.c: Delete * fixheader.c (read_scan_file): Update for new cpp_get_token prototype. (recognized_function): New argument LINE. * scan-decls.c (skip_to_closing_brace, scan_decls): Update for new cpp_get_token prototype. * scan.h (recognized_function): Update prototype. * po/POTFILES.in: Remove cppoutput.c. From-SVN: r37098
2000-10-28 19:59:06 +02:00
/* Called when a line of output is started. TOKEN is the first token
of the line, and at end of file will be CPP_EOF. */
static void
cb_line_change (cpp_reader *pfile, const cpp_token *token,
int parsing_args)
{
do_line_change (pfile, token, token->src_loc, parsing_args);
}
New macro expander. 2000-10-28 Neil Booth <neilb@earthling.net> New macro expander. * cpplib.c (struct answer): New. (struct if_stack): Use cpp_lexer_pos rather than line and col. Rename cmacro mi_cmacro. (struct directive, KANDR, STDC89, EXTENSION, COND, IF_COND, INCL, IN_I): New directive and flags. (skip_rest_of_line, check_eol, run_directive, glue_header_name, parse_answer, parse_assertion, find_answer): New functions. (parse_ifdef, detect_if_not_defined, validate_else): Remove. (lex_macro_node): New function to replace parse_ifdef and get_define_node. (_cpp_handle_directive): New function, combines _cpp_check_directive and _cpp_check_linemarker. (do_define, do_undef, parse_include, do_include, do_import, do_include_next, read_line_number, do_line, do_ident, do_pragma, do_pragma_once, do_pragma_poison, do_pragma_dependency): Update for new token getting interface. (do_ifdef, do_ifndef, do_if, do_else, do_endif, push_conditional) : Update for new multiple-include optimisation technique. (do_elif): Don't forget to invalidate controlling macros. (unwind_if_stack, cpp_defined, cpp_push_buffer, cpp_pop_buffer): Update. (parse_assertion, parse_answer, find_answer, _cpp_test_assertion): Functions to handle assertions with the new token interface. (do_assert, do_unassert): Use them. (cpp_define, _cpp_define_builtin, cpp_undef, cpp_assert, cpp_unassert): Use run_directive. (_cpp_init_stacks): Register directive names. Don't register special nodes. * cpperror.c (print_containing_files, _cpp_begin_message): Update to new position recording regime. (cpp_ice, cpp_fatal, cpp_error, cpp_error_with_line, cpp_warning, cpp_warning_with_line, cpp_pedwarn, cpp_pedwarn_with_line, cpp_pedwarn_with_file_and_line): Update for _cpp_begin_message changes. (cpp_type2name): Move to cpplex.c. * cppexp.c (parse_charconst): spec_nodes is no longer a pointer. (parse_defined): Update to handle new multiple include optimisation method. Remove poisoned identifier warning. (parse_assertion, TYPE_NAME): Delete. (lex): Update for multiple include optimisation, removal of CPP_DEFINED, to use _cpp_test_assertion for assertions and cpp_token_as_text. (_cpp_parse_expr): Update for MI optimisation, and to use op_as_text. (op_as_text): New function, to wrap cpp_token_as_text. * cppfiles.c (stack_include_file, _cpp_pop_file_buffer): Update for MI optimisation. (_cpp_execute_include): Take a token rather than 3 arguments. Fix segfault on diagnostic. (_cpp_compare_file_date): Take a token rather than 3 args. (cpp_read_file): Work correctly for zero-length files. * cpphash.c (_cpp_init_macros, _cpp_cleanup_macros): Rename _cpp_init_hashtable and _cpp_cleanup_hashtable. (cpp_lookup): Place identifiers at front of identifier pool for _cpp_lookup_with_hash. (_cpp_lookup_with_hash): Require identifiers to be at the front of the identifier pool. Commit the memory if not already in the hash table. * cppinit.c (cpp_reader_init): Move cpp_init_completed test to top. Initialise various members of cpp_reader, memory pools, and the special nodes. (cpp_printer_init): Delete. (cpp_cleanup): Update. (struct builtin, builtin_array, initialize_builtins): Update for new hashnode definition and builtin handling. (cpp_start_read, cpp_finish): Don't take or initialise a printer. Update. * cpplib.h (cpp_printer, cpp_toklist, CPP_DEFINED, BOL, PASTED, VAR_ARGS, BEG_OF_FILE, IN_DIRECTIVE, KNOWN_DIRECTIVE, T_VOID, T_SPECLINE, T_DATE, T_FILE, T_BASE_FILE, T_INCLUDE_LEVEL, T_TIME, T_STDC, T_OPERATOR, T_POISON, T_MACRO, T_ASSERTION): Delete. (struct cpp_pool, struct cpp_macro, struct cpp_lexer_pos, struct cpp_lookahead, CPP_DHASH, enum mi_state, enum mi_ind, NO_EXPAND, VARARGS_FIRST, struct cpp_token_with_pos, struct toklist, struct cpp_context, struct specnodes, TOKEN_LOOKAHEAD, TOKEN_BUFFSIZE, NODE_OPERATOR, NODE_POISONED, NODE_BUILTIN, NODE_DIAGNOSTIC, NT_VOID, NT_MACRO, NT_ASSERTION, enum builtin_type, cpp_can_paste): New. (struct cpp_token): Delete line and col members. (struct cpp_buffer): New member output_lineno. (struct lexer_state): Delete indented, in_lex_line, seen_dot. Add va_args_ok, poisoned_ok, prevent_expansion, parsing_args. (struct cpp_reader): New members lexer_pos, macro_pos, directive_pos, ident_pool, temp_string_pool, macro_pool, argument_pool, string_pool, base_context, context, directive, mi_state, mi_if_not_defined, mi_lexed, mi_cmacro, mi_ind_cmacro, la_read, la_write, la_unused, mlstring_pos, macro_buffer, macro_buffer_len. Delete members mls_line, mls_column, token_list, potential_control_macro, temp_tokens, temp_cap, temp_alloced, temp_used, first_directive_token, context_cap, cur_context, no_expand_level, paste_level, contexts, args, save_parameter_spellings, need_newline, . Change type of date, time and spec_nodes members. Change prototypes for include and ident callbacks. (struct cpp_hashnode): Change type of name. Remove union members expansion and code. Add members macro, operator and builtin. (cpp_token_len, cpp_token_as_text, cpp_spell_token, cpp_start_read, cpp_finish, cpp_avoid_paste, cpp_get_token, cpp_get_line, cpp_get_output_line, cpp_macro_definition, cpp_start_lookahead, cpp_stop_lookahead): New prototypes. (cpp_printer_init, cpp_dump_definition): Delete prototypes. (U_CHAR, U, ustrcmp, ustrncmp, ustrlen, uxstrdup, ustrchr, ufputs): Move from cpphash.h. * cpphash.h (U_CHAR, U, ustrcmp, ustrncmp, ustrlen, uxstrdup, ustrchr, ufputs): Move to cpplib.h. (enum spell_type, struct token_spelling, _cpp_token_spellings, TOKEN_SPELL, TOKEN_NAME, struct answer, FREE_ANSWER, KANDR, STDC89, EXTENSION, COND, EXPAND, INCL, COMMENTS, IN_I, struct directive, directive_handler, struct spec_nodes, _cpp_digraph_spellings, _cpp_free_temp_tokens, _cpp_init_input_buffer, _cpp_grow_token_buffer, _cpp_init_toklist, _cpp_clear_toklist, _cpp_expand_token_space, _cpp_expand_name_space, _cpp_equiv_tokens, _cpp_equiv_toklists, _cpp_process_directive, _cpp_run_directive, _cpp_get_line, _cpp_get_raw_token, _cpp_glue_header_name, _cpp_can_paste, _cpp_check_directive, _cpp_check_linemarker, _cpp_parse_assertion, _cpp_find_answer): Delete. (VALID_SIGN, ALIGN, POOL_FRONT, POOL_LIMIT, POOL_BASE, POOL_SIZE, POOL_USED, POOL_COMMIT, struct cpp_chunk, _cpp_lex_token, _cpp_init_pool, _cpp_free_pool, _cpp_pool_reserve, _cpp_pool_alloc, _cpp_next_chunk, _cpp_lock_pool, _cpp_unlock_pool, _cpp_test_assertion, _cpp_handle_directive, DSC): New. (struct include_file): New member defined. (DO_NOT_REREAD, _cpp_begin_message, _cpp_execute_include, _cpp_compare_file_date): Update. (_cpp_pop_context, _cpp_get_token, _cpp_free_lookaheads, _cpp_push_token): New. (_cpp_init_macros, _cpp_cleanup_macros): Rename to _cpp_init_hashtable, _cpp_cleanup_hashtable. * Makefile.in: Remove cppoutput.c. * cppoutput.c: Delete * fixheader.c (read_scan_file): Update for new cpp_get_token prototype. (recognized_function): New argument LINE. * scan-decls.c (skip_to_closing_brace, scan_decls): Update for new cpp_get_token prototype. * scan.h (recognized_function): Update prototype. * po/POTFILES.in: Remove cppoutput.c. From-SVN: r37098
2000-10-28 19:59:06 +02:00
static void
cb_ident (cpp_reader *pfile ATTRIBUTE_UNUSED, source_location line,
const cpp_string *str)
cpperror.c (v_message): Split into _cpp_begin_message and v_message macro. * cpperror.c (v_message): Split into _cpp_begin_message and v_message macro. All callers updated. (_cpp_begin_message): Do inhibit_errors/inhibit_warnings checks here. * cppfiles.c (cpp_syshdr_flags): New function. (read_include_file): Don't call cpp_output_tokens. Call enter_file hook. * cppinit.c (dump_macros_helper): Moved to cppmain.c. (cpp_reader_init): Don't initialize token_buffer. Call _cpp_init_internal_pragmas. (cpp_cleanup): Don't clear token_buffer. (cpp_start_read): Don't worry about output from -D processing. Don't call cpp_output_tokens. (cpp_finish): Don't dump macros here. Don't call cpp_output_tokens. * cppmacro.c (_cpp_dump_definition): Rename cpp_dump_definition. Write directly to a FILE *. (dump_funlike_macro): Delete. (dump_macro_args): New. * cpplex.c (TOKEN_LEN): Convert to inline function. (_cpp_grow_token_buffer, safe_fwrite, cpp_output_tokens, cpp_scan_line, _cpp_dump_list): Delete. (cpp_printf, cpp_output_list): New. (output_line_command): Don't worry about entering or leaving files. (cpp_scan_buffer): Just output each token as we hit it. (process_directive): Don't call cpp_output_tokens. (_cpp_glue_header_name): Don't use token_buffer. (output_token, dump_param_spelling): Write directly to a FILE *. * cpplib.c (pass_thru_directive, dump_macro_name, pragma_dispatch, do_pragma_gcc): Delete. (do_define, do_undef, parse_include, do_line, do_ident, do_pragma, do_pragma_poison, cpp_pop_buffer): Call the appropriate hook functions. (do_error, do_warning, pragma_dependency): Call _cpp_begin_message, then cpp_output_list. (cpp_register_pragma, cpp_register_pragma_space, _cpp_init_internal_pragmas): New. (do_pragma): Walk the pragmas table here. (do_pragma_once, do_pragma_poison, do_pragma_system_header, do_pragma_dependency): Return void. (do_pragma_implementation): Moved to cppmain.c. * cpplib.h: Update prototypes. (struct cpp_reader): Remove printer, token_buffer, token_buffer_size, and limit. Add struct cb, and pragmas. (struct cpp_printer): Remove last_id and written. (CPP_WRITTEN, CPP_PWRITTEN, CPP_SET_WRITTEN, CPP_ADJUST_WRITTEN): Delete. * cpphash.h: Update prototypes. (ufputs): New wrapper. * cppmain.c (cb_define, cb_undef, cb_include, cb_ident, cb_enter_file, cb_leave_file, cb_def_pragma): New functions. (main): Set up callbacks. Register #pragma implementation. Dump macros from here. From-SVN: r35415
2000-08-02 03:13:45 +02:00
{
Represent column numbers using line-map's source_location. The "next available source_location" is now managed internally by line-maps.c rather than by clients. * line-map.h (struct line_map): New field column_bits. <from_line>: Rename field to start_location. (struct line_maps): New fields highest_location and max_column_hint. (linemap_check_files_exited): New declaration. (linemap_line_start): New declaration. (linemap_add): Remove from_line parameter; use highest_location field. (SOURCE_LINE, LAST_SOURCE_LINE): Modify to use column_bits. (SOURCE_COLUMN, LAST_SOURCE_LINE_LOCATION): New macros. (CURRENT_LINE_MAP): Remove macro. (linemap_position_for_column): New inline function. * line-map.c (linemap_init): Clear new fields. (linemap_check_files_exited): New function, extracted from ... (linemap_free): Use linemap_check_files_exited. (linemap_add): Remove from_line parameter. Various updates. (linemap_line_start): New function. (linemap_lookeup): Update for new field names. * cpphash.h (struct cpp_reader) <map>: Field removed. Because linemap_position_for_column may unpredictably change the current map, it is cleaner and simpler for us to not cache it in cpp_reader. (struct cpp_buffer): New sysp field. Changed warned_cplusplus_comments and from_stage3 to bitfields. * cppinit.c (cpp_read_min_file): pfile->map no longer exists. * cpplib.c (do_line, do_linemarker, _cpp_do_file_change): Get current map using linemap_lookup. (do_linemarker): Also set buffer's sysp field. (destringize_and_run): No longer need to decrement current line. * cppfiles.c (_cpp_stack_file): Set sysp from and in buffer. (search_path_head, open_file_failed): Use buffer's sysp. (cpp_make_system_header): Get current map using linemap_lookup. Also set buffer's sysp flag. * cppmacro.c (_cpp_builtin_macro_text): Likewise use linemap_lookup. * cpphash.h (CPP_INCREMENT_LINE): New macro. (struct cpp_buffer): Moved fields saved_cur, saved_rlimit to ... (struct cpp_reader): ... and adding saved_line_base field. * cpptrad.c (_cpp_overlay_buffer, _cpp_remove_overlay): Update accordingly. Don't adjust line. (_cpp_scan_out_logical_line): Use CPP_INCREMENT_LINE. * cpphash.c (CPP_IN_SYSTEM_HEADER): Replaced macro by ... (cpp_in_system_header): ... new inline function, using buffer's sysp. * cpperror.c (_cpp_begin_message): Update to use cpp_in_system_header. * cpplex.c (_cpp_lex_direct): Likewise. * cppmacro.c (_cpp_builtin_macro_text): Likewise. * cppmacro.c (_cpp_create_definition): Use buffer's sysp field. * cpplib.h (struct cpp_token): Rename line field to src_loc. Remove col field as it is now subsumed by src_loc. * cpperror.c: Update various field, parameter, and macro names. (print_location): If col==0, try SOURCE_COLUMN of line. (cpp_error): Use cur_token's src_loc field, rather than line+col. * cpplib.c (do_diagnostic): Token's src_loc fields replaces line+col. * cpplex.c (_cpp_process_line_notes, _cpp_lex_direct, _cpp_skip_block_comment): Use CPP_INCREMENT_LINE. (_cpp_temp_token): Replace cpp_token's line+col fields by src_loc. (_cpp_get_fresh_line): Don't need to adjust line for missing newline. (_cpp_lex_direct): Use linemap_position_for_column. * c-ppoutput.c (maybe_print_line, print_line): Don't take map parameter. Instead get it from the line_table global. Adjust callers. (print): Remove map field. Replace line field to src_line. (init_pp_output, account_for_newlines, maybe_print_line): Adjust. (cb_line_change): Use SOURCE_COLUMN. Minor optimizations. (pp_file_change): Use MAIN_FILE_P since we cannot checked print.map. Use LAST_SOURCE_LINE_LOCATION to "catch up" after #include. * cpptrad.c (copy_comment): Rename variable. * c-lex.c (map): Remove static variable, for same reason we removed cpp_reader's map field. (cb_line_change, cb_def_pragma, cb_define, cb_undef): Hence we need to call linemap_lookup. (cb_line_change): Token's line field replaced by src_loc. (fe_file_change): Use MAINFILE_P and LAST_SOURCE_LINE macros. Don't save new_map. * cpphash.h, cpperror.c, cpplib.h: Some renames of fileline to source_location. From-SVN: r77663
2004-02-11 16:29:30 +01:00
maybe_print_line (line);
fprintf (print.outf, "#ident %s\n", str->text);
Represent column numbers using line-map's source_location. The "next available source_location" is now managed internally by line-maps.c rather than by clients. * line-map.h (struct line_map): New field column_bits. <from_line>: Rename field to start_location. (struct line_maps): New fields highest_location and max_column_hint. (linemap_check_files_exited): New declaration. (linemap_line_start): New declaration. (linemap_add): Remove from_line parameter; use highest_location field. (SOURCE_LINE, LAST_SOURCE_LINE): Modify to use column_bits. (SOURCE_COLUMN, LAST_SOURCE_LINE_LOCATION): New macros. (CURRENT_LINE_MAP): Remove macro. (linemap_position_for_column): New inline function. * line-map.c (linemap_init): Clear new fields. (linemap_check_files_exited): New function, extracted from ... (linemap_free): Use linemap_check_files_exited. (linemap_add): Remove from_line parameter. Various updates. (linemap_line_start): New function. (linemap_lookeup): Update for new field names. * cpphash.h (struct cpp_reader) <map>: Field removed. Because linemap_position_for_column may unpredictably change the current map, it is cleaner and simpler for us to not cache it in cpp_reader. (struct cpp_buffer): New sysp field. Changed warned_cplusplus_comments and from_stage3 to bitfields. * cppinit.c (cpp_read_min_file): pfile->map no longer exists. * cpplib.c (do_line, do_linemarker, _cpp_do_file_change): Get current map using linemap_lookup. (do_linemarker): Also set buffer's sysp field. (destringize_and_run): No longer need to decrement current line. * cppfiles.c (_cpp_stack_file): Set sysp from and in buffer. (search_path_head, open_file_failed): Use buffer's sysp. (cpp_make_system_header): Get current map using linemap_lookup. Also set buffer's sysp flag. * cppmacro.c (_cpp_builtin_macro_text): Likewise use linemap_lookup. * cpphash.h (CPP_INCREMENT_LINE): New macro. (struct cpp_buffer): Moved fields saved_cur, saved_rlimit to ... (struct cpp_reader): ... and adding saved_line_base field. * cpptrad.c (_cpp_overlay_buffer, _cpp_remove_overlay): Update accordingly. Don't adjust line. (_cpp_scan_out_logical_line): Use CPP_INCREMENT_LINE. * cpphash.c (CPP_IN_SYSTEM_HEADER): Replaced macro by ... (cpp_in_system_header): ... new inline function, using buffer's sysp. * cpperror.c (_cpp_begin_message): Update to use cpp_in_system_header. * cpplex.c (_cpp_lex_direct): Likewise. * cppmacro.c (_cpp_builtin_macro_text): Likewise. * cppmacro.c (_cpp_create_definition): Use buffer's sysp field. * cpplib.h (struct cpp_token): Rename line field to src_loc. Remove col field as it is now subsumed by src_loc. * cpperror.c: Update various field, parameter, and macro names. (print_location): If col==0, try SOURCE_COLUMN of line. (cpp_error): Use cur_token's src_loc field, rather than line+col. * cpplib.c (do_diagnostic): Token's src_loc fields replaces line+col. * cpplex.c (_cpp_process_line_notes, _cpp_lex_direct, _cpp_skip_block_comment): Use CPP_INCREMENT_LINE. (_cpp_temp_token): Replace cpp_token's line+col fields by src_loc. (_cpp_get_fresh_line): Don't need to adjust line for missing newline. (_cpp_lex_direct): Use linemap_position_for_column. * c-ppoutput.c (maybe_print_line, print_line): Don't take map parameter. Instead get it from the line_table global. Adjust callers. (print): Remove map field. Replace line field to src_line. (init_pp_output, account_for_newlines, maybe_print_line): Adjust. (cb_line_change): Use SOURCE_COLUMN. Minor optimizations. (pp_file_change): Use MAIN_FILE_P since we cannot checked print.map. Use LAST_SOURCE_LINE_LOCATION to "catch up" after #include. * cpptrad.c (copy_comment): Rename variable. * c-lex.c (map): Remove static variable, for same reason we removed cpp_reader's map field. (cb_line_change, cb_def_pragma, cb_define, cb_undef): Hence we need to call linemap_lookup. (cb_line_change): Token's line field replaced by src_loc. (fe_file_change): Use MAINFILE_P and LAST_SOURCE_LINE macros. Don't save new_map. * cpphash.h, cpperror.c, cpplib.h: Some renames of fileline to source_location. From-SVN: r77663
2004-02-11 16:29:30 +01:00
print.src_line++;
cpperror.c (v_message): Split into _cpp_begin_message and v_message macro. * cpperror.c (v_message): Split into _cpp_begin_message and v_message macro. All callers updated. (_cpp_begin_message): Do inhibit_errors/inhibit_warnings checks here. * cppfiles.c (cpp_syshdr_flags): New function. (read_include_file): Don't call cpp_output_tokens. Call enter_file hook. * cppinit.c (dump_macros_helper): Moved to cppmain.c. (cpp_reader_init): Don't initialize token_buffer. Call _cpp_init_internal_pragmas. (cpp_cleanup): Don't clear token_buffer. (cpp_start_read): Don't worry about output from -D processing. Don't call cpp_output_tokens. (cpp_finish): Don't dump macros here. Don't call cpp_output_tokens. * cppmacro.c (_cpp_dump_definition): Rename cpp_dump_definition. Write directly to a FILE *. (dump_funlike_macro): Delete. (dump_macro_args): New. * cpplex.c (TOKEN_LEN): Convert to inline function. (_cpp_grow_token_buffer, safe_fwrite, cpp_output_tokens, cpp_scan_line, _cpp_dump_list): Delete. (cpp_printf, cpp_output_list): New. (output_line_command): Don't worry about entering or leaving files. (cpp_scan_buffer): Just output each token as we hit it. (process_directive): Don't call cpp_output_tokens. (_cpp_glue_header_name): Don't use token_buffer. (output_token, dump_param_spelling): Write directly to a FILE *. * cpplib.c (pass_thru_directive, dump_macro_name, pragma_dispatch, do_pragma_gcc): Delete. (do_define, do_undef, parse_include, do_line, do_ident, do_pragma, do_pragma_poison, cpp_pop_buffer): Call the appropriate hook functions. (do_error, do_warning, pragma_dependency): Call _cpp_begin_message, then cpp_output_list. (cpp_register_pragma, cpp_register_pragma_space, _cpp_init_internal_pragmas): New. (do_pragma): Walk the pragmas table here. (do_pragma_once, do_pragma_poison, do_pragma_system_header, do_pragma_dependency): Return void. (do_pragma_implementation): Moved to cppmain.c. * cpplib.h: Update prototypes. (struct cpp_reader): Remove printer, token_buffer, token_buffer_size, and limit. Add struct cb, and pragmas. (struct cpp_printer): Remove last_id and written. (CPP_WRITTEN, CPP_PWRITTEN, CPP_SET_WRITTEN, CPP_ADJUST_WRITTEN): Delete. * cpphash.h: Update prototypes. (ufputs): New wrapper. * cppmain.c (cb_define, cb_undef, cb_include, cb_ident, cb_enter_file, cb_leave_file, cb_def_pragma): New functions. (main): Set up callbacks. Register #pragma implementation. Dump macros from here. From-SVN: r35415
2000-08-02 03:13:45 +02:00
}
static void
cb_define (cpp_reader *pfile, source_location line, cpp_hashnode *node)
cpperror.c (v_message): Split into _cpp_begin_message and v_message macro. * cpperror.c (v_message): Split into _cpp_begin_message and v_message macro. All callers updated. (_cpp_begin_message): Do inhibit_errors/inhibit_warnings checks here. * cppfiles.c (cpp_syshdr_flags): New function. (read_include_file): Don't call cpp_output_tokens. Call enter_file hook. * cppinit.c (dump_macros_helper): Moved to cppmain.c. (cpp_reader_init): Don't initialize token_buffer. Call _cpp_init_internal_pragmas. (cpp_cleanup): Don't clear token_buffer. (cpp_start_read): Don't worry about output from -D processing. Don't call cpp_output_tokens. (cpp_finish): Don't dump macros here. Don't call cpp_output_tokens. * cppmacro.c (_cpp_dump_definition): Rename cpp_dump_definition. Write directly to a FILE *. (dump_funlike_macro): Delete. (dump_macro_args): New. * cpplex.c (TOKEN_LEN): Convert to inline function. (_cpp_grow_token_buffer, safe_fwrite, cpp_output_tokens, cpp_scan_line, _cpp_dump_list): Delete. (cpp_printf, cpp_output_list): New. (output_line_command): Don't worry about entering or leaving files. (cpp_scan_buffer): Just output each token as we hit it. (process_directive): Don't call cpp_output_tokens. (_cpp_glue_header_name): Don't use token_buffer. (output_token, dump_param_spelling): Write directly to a FILE *. * cpplib.c (pass_thru_directive, dump_macro_name, pragma_dispatch, do_pragma_gcc): Delete. (do_define, do_undef, parse_include, do_line, do_ident, do_pragma, do_pragma_poison, cpp_pop_buffer): Call the appropriate hook functions. (do_error, do_warning, pragma_dependency): Call _cpp_begin_message, then cpp_output_list. (cpp_register_pragma, cpp_register_pragma_space, _cpp_init_internal_pragmas): New. (do_pragma): Walk the pragmas table here. (do_pragma_once, do_pragma_poison, do_pragma_system_header, do_pragma_dependency): Return void. (do_pragma_implementation): Moved to cppmain.c. * cpplib.h: Update prototypes. (struct cpp_reader): Remove printer, token_buffer, token_buffer_size, and limit. Add struct cb, and pragmas. (struct cpp_printer): Remove last_id and written. (CPP_WRITTEN, CPP_PWRITTEN, CPP_SET_WRITTEN, CPP_ADJUST_WRITTEN): Delete. * cpphash.h: Update prototypes. (ufputs): New wrapper. * cppmain.c (cb_define, cb_undef, cb_include, cb_ident, cb_enter_file, cb_leave_file, cb_def_pragma): New functions. (main): Set up callbacks. Register #pragma implementation. Dump macros from here. From-SVN: r35415
2000-08-02 03:13:45 +02:00
{
Replace line_map union with C++ class hierarchy gcc/ChangeLog: * diagnostic.c (diagnostic_report_current_module): Strengthen local "new_map" from const line_map * to const line_map_ordinary *. * genmatch.c (error_cb): Likewise for local "map". (output_line_directive): Likewise for local "map". * input.c (expand_location_1): Likewise for local "map". Pass NULL rather than &map to linemap_unwind_to_first_non_reserved_loc, since the value is never read from there, and the value written back not read from here. (is_location_from_builtin_token): Strengthen local "map" from const line_map * to const line_map_ordinary *. (dump_location_info): Strengthen locals "map" from line_map *, one to const line_map_ordinary *, the other to const line_map_macro *. * tree-diagnostic.c (loc_map_pair): Strengthen field "map" from const line_map * to const line_map_macro *. (maybe_unwind_expanded_macro_loc): Add a call to linemap_check_macro when writing to the "map" field of the loc_map_pair. Introduce local const line_map_ordinary * "ord_map", using it in place of "map" in the part of the function where we know we have an ordinary map. Strengthen local "m" from const line_map * to const line_map_ordinary *. gcc/ada/ChangeLog: * gcc-interface/trans.c (Sloc_to_locus1): Strenghthen local "map" from line_map * to line_map_ordinary *. gcc/c-family/ChangeLog: * c-common.h (fe_file_change): Strengthen param from const line_map * to const line_map_ordinary *. (pp_file_change): Likewise. * c-lex.c (fe_file_change): Likewise. (cb_define): Use linemap_check_ordinary when invoking SOURCE_LINE. (cb_undef): Likewise. * c-opts.c (c_finish_options): Use linemap_check_ordinary when invoking cb_file_change. (c_finish_options): Likewise. (push_command_line_include): Likewise. (cb_file_change): Strengthen param "new_map" from const line_map * to const line_map_ordinary *. * c-ppoutput.c (cb_define): Likewise for local "map". (pp_file_change): Likewise for param "map" and local "from". gcc/fortran/ChangeLog: * cpp.c (maybe_print_line): Strengthen local "map" from const line_map * to const line_map_ordinary *. (cb_file_change): Likewise for param "map" and local "from". (cb_line_change): Likewise for local "map". libcpp/ChangeLog: * directives.c (do_line): Strengthen local "map" from const line_map * to const line_map_ordinary *. (do_linemarker): Likewise. (_cpp_do_file_change): Assert that we're not dealing with a macro map. Introduce local "ord_map" via a call to linemap_check_ordinary, guarded within the check for non-NULL. Use it for typesafety. * files.c (cpp_make_system_header): Strengthen local "map" from const line_map * to const line_map_ordinary *. * include/cpplib.h (struct cpp_callbacks): Likewise for second parameter of "file_change" callback. * include/line-map.h (struct line_map): Convert from a struct containing a union to a base class. (struct line_map_ordinary): Convert to a subclass of line_map. (struct line_map_macro): Likewise. (linemap_check_ordinary): Strengthen return type from line_map * to line_map_ordinary *, and add a const-variant. (linemap_check_macro): New pair of functions. (ORDINARY_MAP_STARTING_LINE_NUMBER): Strengthen param from const line_map * to const line_map_ordinary *, eliminating call to linemap_check_ordinary. Likewise for the non-const variant. (ORDINARY_MAP_INCLUDER_FILE_INDEX): Likewise. (ORDINARY_MAP_IN_SYSTEM_HEADER_P): Likewise. (ORDINARY_MAP_NUMBER_OF_COLUMN_BITS): Likewise. (ORDINARY_MAP_FILE_NAME): Likewise. (MACRO_MAP_MACRO): Strengthen param from const line_map * to const line_map_macro *. Likewise for the non-const variant. (MACRO_MAP_NUM_MACRO_TOKENS): Likewise. (MACRO_MAP_LOCATIONS): Likewise. (MACRO_MAP_EXPANSION_POINT_LOCATION): Likewise. (struct maps_info): Replace with... (struct maps_info_ordinary):...this and... (struct maps_info_macro): ...this. (struct line_maps): Convert fields "info_ordinary" and "info_macro" to the above new structs. (LINEMAPS_MAP_INFO): Delete both functions. (LINEMAPS_MAPS): Likewise. (LINEMAPS_ALLOCATED): Rewrite both variants to avoid using LINEMAPS_MAP_INFO. (LINEMAPS_USED): Likewise. (LINEMAPS_CACHE): Likewise. (LINEMAPS_MAP_AT): Likewise. (LINEMAPS_ORDINARY_MAPS): Strengthen return type from line_map * to line_map_ordinary *. (LINEMAPS_ORDINARY_MAP_AT): Likewise. (LINEMAPS_LAST_ORDINARY_MAP): Likewise. (LINEMAPS_LAST_ALLOCATED_ORDINARY_MAP): Likewise. (LINEMAPS_MACRO_MAPS): Strengthen return type from line_map * to line_map_macro *. (LINEMAPS_MACRO_MAP_AT): Likewise. (LINEMAPS_LAST_MACRO_MAP): Likewise. (LINEMAPS_LAST_ALLOCATED_MACRO_MAP): Likewise. (linemap_map_get_macro_name): Strengthen param from const line_map * to const line_map_macro *. (SOURCE_LINE): Strengthen first param from const line_map * to const line_map_ordinary *, removing call to linemap_check_ordinary. (SOURCE_COLUMN): Likewise. (LAST_SOURCE_LINE_LOCATION): Likewise. (LAST_SOURCE_LINE): Strengthen first param from const line_map * to const line_map_ordinary *. (LAST_SOURCE_COLUMN): Likewise. (INCLUDED_FROM): Strengthen return type from line_map * to line_map_ordinary *., and second param from const line_map * to const line_map_ordinary *, removing call to linemap_check_ordinary. (MAIN_FILE_P): Strengthen param from const line_map * to const line_map_ordinary *, removing call to linemap_check_ordinary. (linemap_position_for_line_and_column): Strengthen param from const line_map * to const line_map_ordinary *. (LINEMAP_FILE): Strengthen param from const line_map * to const line_map_ordinary *, removing call to linemap_check_ordinary. (LINEMAP_LINE): Likewise. (LINEMAP_SYSP): Likewise. (linemap_resolve_location): Strengthen final param from const line_map ** to const line_map_ordinary **. * internal.h (CPP_INCREMENT_LINE): Likewise for local "map". (linemap_enter_macro): Strengthen return type from const line_map * to const line_map_macro *. (linemap_add_macro_token): Likewise for first param. * line-map.c (linemap_check_files_exited): Strengthen local "map" from const line_map * to const line_map_ordinary *. (new_linemap): Introduce local "map_size" and use it when calculating how large the buffer should be. Rewrite based on change of info_macro and info_ordinary into distinct types. (linemap_add): Strengthen locals "map" and "from" from line_map * to line_map_ordinary *. (linemap_enter_macro): Strengthen return type from const line_map * to const line_map_macro *, and local "map" from line_map * to line_map_macro *. (linemap_add_macro_token): Strengthen param "map" from const line_map * to const line_map_macro *. (linemap_line_start): Strengthen local "map" from line_map * to line_map_ordinary *. (linemap_position_for_column): Likewise. (linemap_position_for_line_and_column): Strengthen first param from const line_map * to const line_map_ordinary *. (linemap_position_for_loc_and_offset): Strengthen local "map" from const line_map * to const line_map_ordinary *. (linemap_ordinary_map_lookup): Likewise for return type and locals "cached" and "result". (linemap_macro_map_lookup): Strengthen return type and locals "cached" and "result" from const line_map * to const line_map_macro *. (linemap_macro_map_loc_to_exp_point): Likewise for param "map". (linemap_macro_map_loc_to_def_point): Likewise. (linemap_macro_map_loc_unwind_toward_spelling): Likewise. (linemap_get_expansion_line): Strengthen local "map" from const line_map * to const line_map_ordinary *. (linemap_get_expansion_filename): Likewise. (linemap_map_get_macro_name): Strengthen param from const line_map * to const line_map_macro *. (linemap_location_in_system_header_p): Add call to linemap_check_ordinary in region guarded by !linemap_macro_expansion_map_p. Introduce local "macro_map" via linemap_check_macro in other region, using it in place of "map" for typesafety. (first_map_in_common_1): Add calls to linemap_check_macro. (trace_include): Strengthen param "map" from const line_map * to const line_map_ordinary *. (linemap_macro_loc_to_spelling_point): Strengthen final param from const line_map ** to const line_map_ordinary **. Replace a C-style cast with a const_cast, and add calls to linemap_check_macro and linemap_check_ordinary. (linemap_macro_loc_to_def_point): Likewise. (linemap_macro_loc_to_exp_point): Likewise. (linemap_resolve_location): Strengthen final param from const line_map ** to const line_map_ordinary **. (linemap_unwind_toward_expansion): Introduce local "macro_map" via a checked cast and use it in place of *map. (linemap_unwind_to_first_non_reserved_loc): Strengthen local "map1" from const line_map * to const line_map_ordinary *. (linemap_expand_location): Introduce local "ord_map" via a checked cast and use it in place of map. (linemap_dump): Make local "map" const. Strengthen local "includer_map" from line_map * to const line_map_ordinary *. Introduce locals "ord_map" and "macro_map" via checked casts and use them in place of "map" for typesafety. (linemap_dump_location): Strengthen local "map" from const line_map * to const line_map_ordinary *. (linemap_get_file_highest_location): Update for elimination of union. (linemap_get_statistics): Strengthen local "cur_map" from line_map * to const line_map_macro *. Update uses of sizeof to use the appropriate line_map subclasses. * macro.c (_cpp_warn_if_unused_macro): Add call to linemap_check_ordinary. (builtin_macro): Strengthen local "map" from const line_map * to const line_map_macro *. (enter_macro_context): Likewise. (replace_args): Likewise. (tokens_buff_put_token_to): Likewise for param "map". (tokens_buff_add_token): Likewise. From-SVN: r223365
2015-05-19 15:18:01 +02:00
const line_map_ordinary *map;
Linemap infrastructure for virtual locations This is the first instalment of a set which goal is to track locations of tokens across macro expansions. Tom Tromey did the original work and attached the patch to PR preprocessor/7263. This opus is a derivative of that original work. This patch modifies the linemap module of libcpp to add virtual locations support. A virtual location is a mapped location that can resolve to several different physical locations. It can always resolve to the spelling location of a token. For tokens resulting from macro expansion it can resolve to: - either the location of the expansion point of the macro. - or the location of the token in the definition of the macro - or, if the token is an argument of a function-like macro, the location of the use of the matching macro parameter in the definition of the macro The patch creates a new type of line map called a macro map. For every single macro expansion, there is a macro map that generates a virtual location for every single resulting token of the expansion. The good old type of line map we all know is now called an ordinary map. That one still encodes spelling locations as it has always had. As a result linemap_lookup as been extended to return a macro map when given a virtual location resulting from a macro expansion. The layout of structs line_map has changed to support this new type of map. So did the layout of struct line_maps. Accessor macros have been introduced to avoid messing with the implementation details of these datastructures directly. This helped already as we have been testing different ways of arranging these datastructure. Having to constantly adjust client code that is too tied with the internals of line_map and line_maps would have been even more painful. Of course, many new public functions have been added to the linemap module to handle the resolution of virtual locations. This patch introduces the infrastructure but no part of the compiler uses virtual locations yet. However the client code of the linemap data structures has been adjusted as per the changes. E.g, it's not anymore reliable for a client code to manipulate struct line_map directly if it just wants to deal with spelling locations, because struct line_map can now represent a macro map as well. In that case, it's better to use the convenient API to resolve the initial (possibly virtual) location to a spelling location (or to an ordinary map) and use that. This is the reason why the patch adjusts the Java, Ada and Fortran front ends. Also, note that virtual locations are not supposed to be ordered for relations '<' and '>' anymore. To test if a virtual location appears "before" another one, one has to use a new operator exposed by the line map interface. The patch updates the only spot (in the diagnostics module) I have found that was making the assumption that locations were ordered for these relations. This is the only change that introduces a use of the new line map API in this patch, so I am adding a regression test for it only. From-SVN: r180081
2011-10-17 11:58:56 +02:00
Represent column numbers using line-map's source_location. The "next available source_location" is now managed internally by line-maps.c rather than by clients. * line-map.h (struct line_map): New field column_bits. <from_line>: Rename field to start_location. (struct line_maps): New fields highest_location and max_column_hint. (linemap_check_files_exited): New declaration. (linemap_line_start): New declaration. (linemap_add): Remove from_line parameter; use highest_location field. (SOURCE_LINE, LAST_SOURCE_LINE): Modify to use column_bits. (SOURCE_COLUMN, LAST_SOURCE_LINE_LOCATION): New macros. (CURRENT_LINE_MAP): Remove macro. (linemap_position_for_column): New inline function. * line-map.c (linemap_init): Clear new fields. (linemap_check_files_exited): New function, extracted from ... (linemap_free): Use linemap_check_files_exited. (linemap_add): Remove from_line parameter. Various updates. (linemap_line_start): New function. (linemap_lookeup): Update for new field names. * cpphash.h (struct cpp_reader) <map>: Field removed. Because linemap_position_for_column may unpredictably change the current map, it is cleaner and simpler for us to not cache it in cpp_reader. (struct cpp_buffer): New sysp field. Changed warned_cplusplus_comments and from_stage3 to bitfields. * cppinit.c (cpp_read_min_file): pfile->map no longer exists. * cpplib.c (do_line, do_linemarker, _cpp_do_file_change): Get current map using linemap_lookup. (do_linemarker): Also set buffer's sysp field. (destringize_and_run): No longer need to decrement current line. * cppfiles.c (_cpp_stack_file): Set sysp from and in buffer. (search_path_head, open_file_failed): Use buffer's sysp. (cpp_make_system_header): Get current map using linemap_lookup. Also set buffer's sysp flag. * cppmacro.c (_cpp_builtin_macro_text): Likewise use linemap_lookup. * cpphash.h (CPP_INCREMENT_LINE): New macro. (struct cpp_buffer): Moved fields saved_cur, saved_rlimit to ... (struct cpp_reader): ... and adding saved_line_base field. * cpptrad.c (_cpp_overlay_buffer, _cpp_remove_overlay): Update accordingly. Don't adjust line. (_cpp_scan_out_logical_line): Use CPP_INCREMENT_LINE. * cpphash.c (CPP_IN_SYSTEM_HEADER): Replaced macro by ... (cpp_in_system_header): ... new inline function, using buffer's sysp. * cpperror.c (_cpp_begin_message): Update to use cpp_in_system_header. * cpplex.c (_cpp_lex_direct): Likewise. * cppmacro.c (_cpp_builtin_macro_text): Likewise. * cppmacro.c (_cpp_create_definition): Use buffer's sysp field. * cpplib.h (struct cpp_token): Rename line field to src_loc. Remove col field as it is now subsumed by src_loc. * cpperror.c: Update various field, parameter, and macro names. (print_location): If col==0, try SOURCE_COLUMN of line. (cpp_error): Use cur_token's src_loc field, rather than line+col. * cpplib.c (do_diagnostic): Token's src_loc fields replaces line+col. * cpplex.c (_cpp_process_line_notes, _cpp_lex_direct, _cpp_skip_block_comment): Use CPP_INCREMENT_LINE. (_cpp_temp_token): Replace cpp_token's line+col fields by src_loc. (_cpp_get_fresh_line): Don't need to adjust line for missing newline. (_cpp_lex_direct): Use linemap_position_for_column. * c-ppoutput.c (maybe_print_line, print_line): Don't take map parameter. Instead get it from the line_table global. Adjust callers. (print): Remove map field. Replace line field to src_line. (init_pp_output, account_for_newlines, maybe_print_line): Adjust. (cb_line_change): Use SOURCE_COLUMN. Minor optimizations. (pp_file_change): Use MAIN_FILE_P since we cannot checked print.map. Use LAST_SOURCE_LINE_LOCATION to "catch up" after #include. * cpptrad.c (copy_comment): Rename variable. * c-lex.c (map): Remove static variable, for same reason we removed cpp_reader's map field. (cb_line_change, cb_def_pragma, cb_define, cb_undef): Hence we need to call linemap_lookup. (cb_line_change): Token's line field replaced by src_loc. (fe_file_change): Use MAINFILE_P and LAST_SOURCE_LINE macros. Don't save new_map. * cpphash.h, cpperror.c, cpplib.h: Some renames of fileline to source_location. From-SVN: r77663
2004-02-11 16:29:30 +01:00
maybe_print_line (line);
fputs ("#define ", print.outf);
New macro expander. 2000-10-28 Neil Booth <neilb@earthling.net> New macro expander. * cpplib.c (struct answer): New. (struct if_stack): Use cpp_lexer_pos rather than line and col. Rename cmacro mi_cmacro. (struct directive, KANDR, STDC89, EXTENSION, COND, IF_COND, INCL, IN_I): New directive and flags. (skip_rest_of_line, check_eol, run_directive, glue_header_name, parse_answer, parse_assertion, find_answer): New functions. (parse_ifdef, detect_if_not_defined, validate_else): Remove. (lex_macro_node): New function to replace parse_ifdef and get_define_node. (_cpp_handle_directive): New function, combines _cpp_check_directive and _cpp_check_linemarker. (do_define, do_undef, parse_include, do_include, do_import, do_include_next, read_line_number, do_line, do_ident, do_pragma, do_pragma_once, do_pragma_poison, do_pragma_dependency): Update for new token getting interface. (do_ifdef, do_ifndef, do_if, do_else, do_endif, push_conditional) : Update for new multiple-include optimisation technique. (do_elif): Don't forget to invalidate controlling macros. (unwind_if_stack, cpp_defined, cpp_push_buffer, cpp_pop_buffer): Update. (parse_assertion, parse_answer, find_answer, _cpp_test_assertion): Functions to handle assertions with the new token interface. (do_assert, do_unassert): Use them. (cpp_define, _cpp_define_builtin, cpp_undef, cpp_assert, cpp_unassert): Use run_directive. (_cpp_init_stacks): Register directive names. Don't register special nodes. * cpperror.c (print_containing_files, _cpp_begin_message): Update to new position recording regime. (cpp_ice, cpp_fatal, cpp_error, cpp_error_with_line, cpp_warning, cpp_warning_with_line, cpp_pedwarn, cpp_pedwarn_with_line, cpp_pedwarn_with_file_and_line): Update for _cpp_begin_message changes. (cpp_type2name): Move to cpplex.c. * cppexp.c (parse_charconst): spec_nodes is no longer a pointer. (parse_defined): Update to handle new multiple include optimisation method. Remove poisoned identifier warning. (parse_assertion, TYPE_NAME): Delete. (lex): Update for multiple include optimisation, removal of CPP_DEFINED, to use _cpp_test_assertion for assertions and cpp_token_as_text. (_cpp_parse_expr): Update for MI optimisation, and to use op_as_text. (op_as_text): New function, to wrap cpp_token_as_text. * cppfiles.c (stack_include_file, _cpp_pop_file_buffer): Update for MI optimisation. (_cpp_execute_include): Take a token rather than 3 arguments. Fix segfault on diagnostic. (_cpp_compare_file_date): Take a token rather than 3 args. (cpp_read_file): Work correctly for zero-length files. * cpphash.c (_cpp_init_macros, _cpp_cleanup_macros): Rename _cpp_init_hashtable and _cpp_cleanup_hashtable. (cpp_lookup): Place identifiers at front of identifier pool for _cpp_lookup_with_hash. (_cpp_lookup_with_hash): Require identifiers to be at the front of the identifier pool. Commit the memory if not already in the hash table. * cppinit.c (cpp_reader_init): Move cpp_init_completed test to top. Initialise various members of cpp_reader, memory pools, and the special nodes. (cpp_printer_init): Delete. (cpp_cleanup): Update. (struct builtin, builtin_array, initialize_builtins): Update for new hashnode definition and builtin handling. (cpp_start_read, cpp_finish): Don't take or initialise a printer. Update. * cpplib.h (cpp_printer, cpp_toklist, CPP_DEFINED, BOL, PASTED, VAR_ARGS, BEG_OF_FILE, IN_DIRECTIVE, KNOWN_DIRECTIVE, T_VOID, T_SPECLINE, T_DATE, T_FILE, T_BASE_FILE, T_INCLUDE_LEVEL, T_TIME, T_STDC, T_OPERATOR, T_POISON, T_MACRO, T_ASSERTION): Delete. (struct cpp_pool, struct cpp_macro, struct cpp_lexer_pos, struct cpp_lookahead, CPP_DHASH, enum mi_state, enum mi_ind, NO_EXPAND, VARARGS_FIRST, struct cpp_token_with_pos, struct toklist, struct cpp_context, struct specnodes, TOKEN_LOOKAHEAD, TOKEN_BUFFSIZE, NODE_OPERATOR, NODE_POISONED, NODE_BUILTIN, NODE_DIAGNOSTIC, NT_VOID, NT_MACRO, NT_ASSERTION, enum builtin_type, cpp_can_paste): New. (struct cpp_token): Delete line and col members. (struct cpp_buffer): New member output_lineno. (struct lexer_state): Delete indented, in_lex_line, seen_dot. Add va_args_ok, poisoned_ok, prevent_expansion, parsing_args. (struct cpp_reader): New members lexer_pos, macro_pos, directive_pos, ident_pool, temp_string_pool, macro_pool, argument_pool, string_pool, base_context, context, directive, mi_state, mi_if_not_defined, mi_lexed, mi_cmacro, mi_ind_cmacro, la_read, la_write, la_unused, mlstring_pos, macro_buffer, macro_buffer_len. Delete members mls_line, mls_column, token_list, potential_control_macro, temp_tokens, temp_cap, temp_alloced, temp_used, first_directive_token, context_cap, cur_context, no_expand_level, paste_level, contexts, args, save_parameter_spellings, need_newline, . Change type of date, time and spec_nodes members. Change prototypes for include and ident callbacks. (struct cpp_hashnode): Change type of name. Remove union members expansion and code. Add members macro, operator and builtin. (cpp_token_len, cpp_token_as_text, cpp_spell_token, cpp_start_read, cpp_finish, cpp_avoid_paste, cpp_get_token, cpp_get_line, cpp_get_output_line, cpp_macro_definition, cpp_start_lookahead, cpp_stop_lookahead): New prototypes. (cpp_printer_init, cpp_dump_definition): Delete prototypes. (U_CHAR, U, ustrcmp, ustrncmp, ustrlen, uxstrdup, ustrchr, ufputs): Move from cpphash.h. * cpphash.h (U_CHAR, U, ustrcmp, ustrncmp, ustrlen, uxstrdup, ustrchr, ufputs): Move to cpplib.h. (enum spell_type, struct token_spelling, _cpp_token_spellings, TOKEN_SPELL, TOKEN_NAME, struct answer, FREE_ANSWER, KANDR, STDC89, EXTENSION, COND, EXPAND, INCL, COMMENTS, IN_I, struct directive, directive_handler, struct spec_nodes, _cpp_digraph_spellings, _cpp_free_temp_tokens, _cpp_init_input_buffer, _cpp_grow_token_buffer, _cpp_init_toklist, _cpp_clear_toklist, _cpp_expand_token_space, _cpp_expand_name_space, _cpp_equiv_tokens, _cpp_equiv_toklists, _cpp_process_directive, _cpp_run_directive, _cpp_get_line, _cpp_get_raw_token, _cpp_glue_header_name, _cpp_can_paste, _cpp_check_directive, _cpp_check_linemarker, _cpp_parse_assertion, _cpp_find_answer): Delete. (VALID_SIGN, ALIGN, POOL_FRONT, POOL_LIMIT, POOL_BASE, POOL_SIZE, POOL_USED, POOL_COMMIT, struct cpp_chunk, _cpp_lex_token, _cpp_init_pool, _cpp_free_pool, _cpp_pool_reserve, _cpp_pool_alloc, _cpp_next_chunk, _cpp_lock_pool, _cpp_unlock_pool, _cpp_test_assertion, _cpp_handle_directive, DSC): New. (struct include_file): New member defined. (DO_NOT_REREAD, _cpp_begin_message, _cpp_execute_include, _cpp_compare_file_date): Update. (_cpp_pop_context, _cpp_get_token, _cpp_free_lookaheads, _cpp_push_token): New. (_cpp_init_macros, _cpp_cleanup_macros): Rename to _cpp_init_hashtable, _cpp_cleanup_hashtable. * Makefile.in: Remove cppoutput.c. * cppoutput.c: Delete * fixheader.c (read_scan_file): Update for new cpp_get_token prototype. (recognized_function): New argument LINE. * scan-decls.c (skip_to_closing_brace, scan_decls): Update for new cpp_get_token prototype. * scan.h (recognized_function): Update prototype. * po/POTFILES.in: Remove cppoutput.c. From-SVN: r37098
2000-10-28 19:59:06 +02:00
/* 'D' is whole definition; 'N' is name only. */
if (flag_dump_macros == 'D')
fputs ((const char *) cpp_macro_definition (pfile, node),
print.outf);
else
fputs ((const char *) NODE_NAME (node), print.outf);
New macro expander. 2000-10-28 Neil Booth <neilb@earthling.net> New macro expander. * cpplib.c (struct answer): New. (struct if_stack): Use cpp_lexer_pos rather than line and col. Rename cmacro mi_cmacro. (struct directive, KANDR, STDC89, EXTENSION, COND, IF_COND, INCL, IN_I): New directive and flags. (skip_rest_of_line, check_eol, run_directive, glue_header_name, parse_answer, parse_assertion, find_answer): New functions. (parse_ifdef, detect_if_not_defined, validate_else): Remove. (lex_macro_node): New function to replace parse_ifdef and get_define_node. (_cpp_handle_directive): New function, combines _cpp_check_directive and _cpp_check_linemarker. (do_define, do_undef, parse_include, do_include, do_import, do_include_next, read_line_number, do_line, do_ident, do_pragma, do_pragma_once, do_pragma_poison, do_pragma_dependency): Update for new token getting interface. (do_ifdef, do_ifndef, do_if, do_else, do_endif, push_conditional) : Update for new multiple-include optimisation technique. (do_elif): Don't forget to invalidate controlling macros. (unwind_if_stack, cpp_defined, cpp_push_buffer, cpp_pop_buffer): Update. (parse_assertion, parse_answer, find_answer, _cpp_test_assertion): Functions to handle assertions with the new token interface. (do_assert, do_unassert): Use them. (cpp_define, _cpp_define_builtin, cpp_undef, cpp_assert, cpp_unassert): Use run_directive. (_cpp_init_stacks): Register directive names. Don't register special nodes. * cpperror.c (print_containing_files, _cpp_begin_message): Update to new position recording regime. (cpp_ice, cpp_fatal, cpp_error, cpp_error_with_line, cpp_warning, cpp_warning_with_line, cpp_pedwarn, cpp_pedwarn_with_line, cpp_pedwarn_with_file_and_line): Update for _cpp_begin_message changes. (cpp_type2name): Move to cpplex.c. * cppexp.c (parse_charconst): spec_nodes is no longer a pointer. (parse_defined): Update to handle new multiple include optimisation method. Remove poisoned identifier warning. (parse_assertion, TYPE_NAME): Delete. (lex): Update for multiple include optimisation, removal of CPP_DEFINED, to use _cpp_test_assertion for assertions and cpp_token_as_text. (_cpp_parse_expr): Update for MI optimisation, and to use op_as_text. (op_as_text): New function, to wrap cpp_token_as_text. * cppfiles.c (stack_include_file, _cpp_pop_file_buffer): Update for MI optimisation. (_cpp_execute_include): Take a token rather than 3 arguments. Fix segfault on diagnostic. (_cpp_compare_file_date): Take a token rather than 3 args. (cpp_read_file): Work correctly for zero-length files. * cpphash.c (_cpp_init_macros, _cpp_cleanup_macros): Rename _cpp_init_hashtable and _cpp_cleanup_hashtable. (cpp_lookup): Place identifiers at front of identifier pool for _cpp_lookup_with_hash. (_cpp_lookup_with_hash): Require identifiers to be at the front of the identifier pool. Commit the memory if not already in the hash table. * cppinit.c (cpp_reader_init): Move cpp_init_completed test to top. Initialise various members of cpp_reader, memory pools, and the special nodes. (cpp_printer_init): Delete. (cpp_cleanup): Update. (struct builtin, builtin_array, initialize_builtins): Update for new hashnode definition and builtin handling. (cpp_start_read, cpp_finish): Don't take or initialise a printer. Update. * cpplib.h (cpp_printer, cpp_toklist, CPP_DEFINED, BOL, PASTED, VAR_ARGS, BEG_OF_FILE, IN_DIRECTIVE, KNOWN_DIRECTIVE, T_VOID, T_SPECLINE, T_DATE, T_FILE, T_BASE_FILE, T_INCLUDE_LEVEL, T_TIME, T_STDC, T_OPERATOR, T_POISON, T_MACRO, T_ASSERTION): Delete. (struct cpp_pool, struct cpp_macro, struct cpp_lexer_pos, struct cpp_lookahead, CPP_DHASH, enum mi_state, enum mi_ind, NO_EXPAND, VARARGS_FIRST, struct cpp_token_with_pos, struct toklist, struct cpp_context, struct specnodes, TOKEN_LOOKAHEAD, TOKEN_BUFFSIZE, NODE_OPERATOR, NODE_POISONED, NODE_BUILTIN, NODE_DIAGNOSTIC, NT_VOID, NT_MACRO, NT_ASSERTION, enum builtin_type, cpp_can_paste): New. (struct cpp_token): Delete line and col members. (struct cpp_buffer): New member output_lineno. (struct lexer_state): Delete indented, in_lex_line, seen_dot. Add va_args_ok, poisoned_ok, prevent_expansion, parsing_args. (struct cpp_reader): New members lexer_pos, macro_pos, directive_pos, ident_pool, temp_string_pool, macro_pool, argument_pool, string_pool, base_context, context, directive, mi_state, mi_if_not_defined, mi_lexed, mi_cmacro, mi_ind_cmacro, la_read, la_write, la_unused, mlstring_pos, macro_buffer, macro_buffer_len. Delete members mls_line, mls_column, token_list, potential_control_macro, temp_tokens, temp_cap, temp_alloced, temp_used, first_directive_token, context_cap, cur_context, no_expand_level, paste_level, contexts, args, save_parameter_spellings, need_newline, . Change type of date, time and spec_nodes members. Change prototypes for include and ident callbacks. (struct cpp_hashnode): Change type of name. Remove union members expansion and code. Add members macro, operator and builtin. (cpp_token_len, cpp_token_as_text, cpp_spell_token, cpp_start_read, cpp_finish, cpp_avoid_paste, cpp_get_token, cpp_get_line, cpp_get_output_line, cpp_macro_definition, cpp_start_lookahead, cpp_stop_lookahead): New prototypes. (cpp_printer_init, cpp_dump_definition): Delete prototypes. (U_CHAR, U, ustrcmp, ustrncmp, ustrlen, uxstrdup, ustrchr, ufputs): Move from cpphash.h. * cpphash.h (U_CHAR, U, ustrcmp, ustrncmp, ustrlen, uxstrdup, ustrchr, ufputs): Move to cpplib.h. (enum spell_type, struct token_spelling, _cpp_token_spellings, TOKEN_SPELL, TOKEN_NAME, struct answer, FREE_ANSWER, KANDR, STDC89, EXTENSION, COND, EXPAND, INCL, COMMENTS, IN_I, struct directive, directive_handler, struct spec_nodes, _cpp_digraph_spellings, _cpp_free_temp_tokens, _cpp_init_input_buffer, _cpp_grow_token_buffer, _cpp_init_toklist, _cpp_clear_toklist, _cpp_expand_token_space, _cpp_expand_name_space, _cpp_equiv_tokens, _cpp_equiv_toklists, _cpp_process_directive, _cpp_run_directive, _cpp_get_line, _cpp_get_raw_token, _cpp_glue_header_name, _cpp_can_paste, _cpp_check_directive, _cpp_check_linemarker, _cpp_parse_assertion, _cpp_find_answer): Delete. (VALID_SIGN, ALIGN, POOL_FRONT, POOL_LIMIT, POOL_BASE, POOL_SIZE, POOL_USED, POOL_COMMIT, struct cpp_chunk, _cpp_lex_token, _cpp_init_pool, _cpp_free_pool, _cpp_pool_reserve, _cpp_pool_alloc, _cpp_next_chunk, _cpp_lock_pool, _cpp_unlock_pool, _cpp_test_assertion, _cpp_handle_directive, DSC): New. (struct include_file): New member defined. (DO_NOT_REREAD, _cpp_begin_message, _cpp_execute_include, _cpp_compare_file_date): Update. (_cpp_pop_context, _cpp_get_token, _cpp_free_lookaheads, _cpp_push_token): New. (_cpp_init_macros, _cpp_cleanup_macros): Rename to _cpp_init_hashtable, _cpp_cleanup_hashtable. * Makefile.in: Remove cppoutput.c. * cppoutput.c: Delete * fixheader.c (read_scan_file): Update for new cpp_get_token prototype. (recognized_function): New argument LINE. * scan-decls.c (skip_to_closing_brace, scan_decls): Update for new cpp_get_token prototype. * scan.h (recognized_function): Update prototype. * po/POTFILES.in: Remove cppoutput.c. From-SVN: r37098
2000-10-28 19:59:06 +02:00
putc ('\n', print.outf);
print.printed = false;
Linemap infrastructure for virtual locations This is the first instalment of a set which goal is to track locations of tokens across macro expansions. Tom Tromey did the original work and attached the patch to PR preprocessor/7263. This opus is a derivative of that original work. This patch modifies the linemap module of libcpp to add virtual locations support. A virtual location is a mapped location that can resolve to several different physical locations. It can always resolve to the spelling location of a token. For tokens resulting from macro expansion it can resolve to: - either the location of the expansion point of the macro. - or the location of the token in the definition of the macro - or, if the token is an argument of a function-like macro, the location of the use of the matching macro parameter in the definition of the macro The patch creates a new type of line map called a macro map. For every single macro expansion, there is a macro map that generates a virtual location for every single resulting token of the expansion. The good old type of line map we all know is now called an ordinary map. That one still encodes spelling locations as it has always had. As a result linemap_lookup as been extended to return a macro map when given a virtual location resulting from a macro expansion. The layout of structs line_map has changed to support this new type of map. So did the layout of struct line_maps. Accessor macros have been introduced to avoid messing with the implementation details of these datastructures directly. This helped already as we have been testing different ways of arranging these datastructure. Having to constantly adjust client code that is too tied with the internals of line_map and line_maps would have been even more painful. Of course, many new public functions have been added to the linemap module to handle the resolution of virtual locations. This patch introduces the infrastructure but no part of the compiler uses virtual locations yet. However the client code of the linemap data structures has been adjusted as per the changes. E.g, it's not anymore reliable for a client code to manipulate struct line_map directly if it just wants to deal with spelling locations, because struct line_map can now represent a macro map as well. In that case, it's better to use the convenient API to resolve the initial (possibly virtual) location to a spelling location (or to an ordinary map) and use that. This is the reason why the patch adjusts the Java, Ada and Fortran front ends. Also, note that virtual locations are not supposed to be ordered for relations '<' and '>' anymore. To test if a virtual location appears "before" another one, one has to use a new operator exposed by the line map interface. The patch updates the only spot (in the diagnostics module) I have found that was making the assumption that locations were ordered for these relations. This is the only change that introduces a use of the new line map API in this patch, so I am adding a regression test for it only. From-SVN: r180081
2011-10-17 11:58:56 +02:00
linemap_resolve_location (line_table, line,
LRK_MACRO_DEFINITION_LOCATION,
&map);
if (LINEMAP_LINE (map) != 0)
print.src_line++;
cpperror.c (v_message): Split into _cpp_begin_message and v_message macro. * cpperror.c (v_message): Split into _cpp_begin_message and v_message macro. All callers updated. (_cpp_begin_message): Do inhibit_errors/inhibit_warnings checks here. * cppfiles.c (cpp_syshdr_flags): New function. (read_include_file): Don't call cpp_output_tokens. Call enter_file hook. * cppinit.c (dump_macros_helper): Moved to cppmain.c. (cpp_reader_init): Don't initialize token_buffer. Call _cpp_init_internal_pragmas. (cpp_cleanup): Don't clear token_buffer. (cpp_start_read): Don't worry about output from -D processing. Don't call cpp_output_tokens. (cpp_finish): Don't dump macros here. Don't call cpp_output_tokens. * cppmacro.c (_cpp_dump_definition): Rename cpp_dump_definition. Write directly to a FILE *. (dump_funlike_macro): Delete. (dump_macro_args): New. * cpplex.c (TOKEN_LEN): Convert to inline function. (_cpp_grow_token_buffer, safe_fwrite, cpp_output_tokens, cpp_scan_line, _cpp_dump_list): Delete. (cpp_printf, cpp_output_list): New. (output_line_command): Don't worry about entering or leaving files. (cpp_scan_buffer): Just output each token as we hit it. (process_directive): Don't call cpp_output_tokens. (_cpp_glue_header_name): Don't use token_buffer. (output_token, dump_param_spelling): Write directly to a FILE *. * cpplib.c (pass_thru_directive, dump_macro_name, pragma_dispatch, do_pragma_gcc): Delete. (do_define, do_undef, parse_include, do_line, do_ident, do_pragma, do_pragma_poison, cpp_pop_buffer): Call the appropriate hook functions. (do_error, do_warning, pragma_dependency): Call _cpp_begin_message, then cpp_output_list. (cpp_register_pragma, cpp_register_pragma_space, _cpp_init_internal_pragmas): New. (do_pragma): Walk the pragmas table here. (do_pragma_once, do_pragma_poison, do_pragma_system_header, do_pragma_dependency): Return void. (do_pragma_implementation): Moved to cppmain.c. * cpplib.h: Update prototypes. (struct cpp_reader): Remove printer, token_buffer, token_buffer_size, and limit. Add struct cb, and pragmas. (struct cpp_printer): Remove last_id and written. (CPP_WRITTEN, CPP_PWRITTEN, CPP_SET_WRITTEN, CPP_ADJUST_WRITTEN): Delete. * cpphash.h: Update prototypes. (ufputs): New wrapper. * cppmain.c (cb_define, cb_undef, cb_include, cb_ident, cb_enter_file, cb_leave_file, cb_def_pragma): New functions. (main): Set up callbacks. Register #pragma implementation. Dump macros from here. From-SVN: r35415
2000-08-02 03:13:45 +02:00
}
static void
Represent column numbers using line-map's source_location. The "next available source_location" is now managed internally by line-maps.c rather than by clients. * line-map.h (struct line_map): New field column_bits. <from_line>: Rename field to start_location. (struct line_maps): New fields highest_location and max_column_hint. (linemap_check_files_exited): New declaration. (linemap_line_start): New declaration. (linemap_add): Remove from_line parameter; use highest_location field. (SOURCE_LINE, LAST_SOURCE_LINE): Modify to use column_bits. (SOURCE_COLUMN, LAST_SOURCE_LINE_LOCATION): New macros. (CURRENT_LINE_MAP): Remove macro. (linemap_position_for_column): New inline function. * line-map.c (linemap_init): Clear new fields. (linemap_check_files_exited): New function, extracted from ... (linemap_free): Use linemap_check_files_exited. (linemap_add): Remove from_line parameter. Various updates. (linemap_line_start): New function. (linemap_lookeup): Update for new field names. * cpphash.h (struct cpp_reader) <map>: Field removed. Because linemap_position_for_column may unpredictably change the current map, it is cleaner and simpler for us to not cache it in cpp_reader. (struct cpp_buffer): New sysp field. Changed warned_cplusplus_comments and from_stage3 to bitfields. * cppinit.c (cpp_read_min_file): pfile->map no longer exists. * cpplib.c (do_line, do_linemarker, _cpp_do_file_change): Get current map using linemap_lookup. (do_linemarker): Also set buffer's sysp field. (destringize_and_run): No longer need to decrement current line. * cppfiles.c (_cpp_stack_file): Set sysp from and in buffer. (search_path_head, open_file_failed): Use buffer's sysp. (cpp_make_system_header): Get current map using linemap_lookup. Also set buffer's sysp flag. * cppmacro.c (_cpp_builtin_macro_text): Likewise use linemap_lookup. * cpphash.h (CPP_INCREMENT_LINE): New macro. (struct cpp_buffer): Moved fields saved_cur, saved_rlimit to ... (struct cpp_reader): ... and adding saved_line_base field. * cpptrad.c (_cpp_overlay_buffer, _cpp_remove_overlay): Update accordingly. Don't adjust line. (_cpp_scan_out_logical_line): Use CPP_INCREMENT_LINE. * cpphash.c (CPP_IN_SYSTEM_HEADER): Replaced macro by ... (cpp_in_system_header): ... new inline function, using buffer's sysp. * cpperror.c (_cpp_begin_message): Update to use cpp_in_system_header. * cpplex.c (_cpp_lex_direct): Likewise. * cppmacro.c (_cpp_builtin_macro_text): Likewise. * cppmacro.c (_cpp_create_definition): Use buffer's sysp field. * cpplib.h (struct cpp_token): Rename line field to src_loc. Remove col field as it is now subsumed by src_loc. * cpperror.c: Update various field, parameter, and macro names. (print_location): If col==0, try SOURCE_COLUMN of line. (cpp_error): Use cur_token's src_loc field, rather than line+col. * cpplib.c (do_diagnostic): Token's src_loc fields replaces line+col. * cpplex.c (_cpp_process_line_notes, _cpp_lex_direct, _cpp_skip_block_comment): Use CPP_INCREMENT_LINE. (_cpp_temp_token): Replace cpp_token's line+col fields by src_loc. (_cpp_get_fresh_line): Don't need to adjust line for missing newline. (_cpp_lex_direct): Use linemap_position_for_column. * c-ppoutput.c (maybe_print_line, print_line): Don't take map parameter. Instead get it from the line_table global. Adjust callers. (print): Remove map field. Replace line field to src_line. (init_pp_output, account_for_newlines, maybe_print_line): Adjust. (cb_line_change): Use SOURCE_COLUMN. Minor optimizations. (pp_file_change): Use MAIN_FILE_P since we cannot checked print.map. Use LAST_SOURCE_LINE_LOCATION to "catch up" after #include. * cpptrad.c (copy_comment): Rename variable. * c-lex.c (map): Remove static variable, for same reason we removed cpp_reader's map field. (cb_line_change, cb_def_pragma, cb_define, cb_undef): Hence we need to call linemap_lookup. (cb_line_change): Token's line field replaced by src_loc. (fe_file_change): Use MAINFILE_P and LAST_SOURCE_LINE macros. Don't save new_map. * cpphash.h, cpperror.c, cpplib.h: Some renames of fileline to source_location. From-SVN: r77663
2004-02-11 16:29:30 +01:00
cb_undef (cpp_reader *pfile ATTRIBUTE_UNUSED, source_location line,
cpp_hashnode *node)
cpperror.c (v_message): Split into _cpp_begin_message and v_message macro. * cpperror.c (v_message): Split into _cpp_begin_message and v_message macro. All callers updated. (_cpp_begin_message): Do inhibit_errors/inhibit_warnings checks here. * cppfiles.c (cpp_syshdr_flags): New function. (read_include_file): Don't call cpp_output_tokens. Call enter_file hook. * cppinit.c (dump_macros_helper): Moved to cppmain.c. (cpp_reader_init): Don't initialize token_buffer. Call _cpp_init_internal_pragmas. (cpp_cleanup): Don't clear token_buffer. (cpp_start_read): Don't worry about output from -D processing. Don't call cpp_output_tokens. (cpp_finish): Don't dump macros here. Don't call cpp_output_tokens. * cppmacro.c (_cpp_dump_definition): Rename cpp_dump_definition. Write directly to a FILE *. (dump_funlike_macro): Delete. (dump_macro_args): New. * cpplex.c (TOKEN_LEN): Convert to inline function. (_cpp_grow_token_buffer, safe_fwrite, cpp_output_tokens, cpp_scan_line, _cpp_dump_list): Delete. (cpp_printf, cpp_output_list): New. (output_line_command): Don't worry about entering or leaving files. (cpp_scan_buffer): Just output each token as we hit it. (process_directive): Don't call cpp_output_tokens. (_cpp_glue_header_name): Don't use token_buffer. (output_token, dump_param_spelling): Write directly to a FILE *. * cpplib.c (pass_thru_directive, dump_macro_name, pragma_dispatch, do_pragma_gcc): Delete. (do_define, do_undef, parse_include, do_line, do_ident, do_pragma, do_pragma_poison, cpp_pop_buffer): Call the appropriate hook functions. (do_error, do_warning, pragma_dependency): Call _cpp_begin_message, then cpp_output_list. (cpp_register_pragma, cpp_register_pragma_space, _cpp_init_internal_pragmas): New. (do_pragma): Walk the pragmas table here. (do_pragma_once, do_pragma_poison, do_pragma_system_header, do_pragma_dependency): Return void. (do_pragma_implementation): Moved to cppmain.c. * cpplib.h: Update prototypes. (struct cpp_reader): Remove printer, token_buffer, token_buffer_size, and limit. Add struct cb, and pragmas. (struct cpp_printer): Remove last_id and written. (CPP_WRITTEN, CPP_PWRITTEN, CPP_SET_WRITTEN, CPP_ADJUST_WRITTEN): Delete. * cpphash.h: Update prototypes. (ufputs): New wrapper. * cppmain.c (cb_define, cb_undef, cb_include, cb_ident, cb_enter_file, cb_leave_file, cb_def_pragma): New functions. (main): Set up callbacks. Register #pragma implementation. Dump macros from here. From-SVN: r35415
2000-08-02 03:13:45 +02:00
{
Represent column numbers using line-map's source_location. The "next available source_location" is now managed internally by line-maps.c rather than by clients. * line-map.h (struct line_map): New field column_bits. <from_line>: Rename field to start_location. (struct line_maps): New fields highest_location and max_column_hint. (linemap_check_files_exited): New declaration. (linemap_line_start): New declaration. (linemap_add): Remove from_line parameter; use highest_location field. (SOURCE_LINE, LAST_SOURCE_LINE): Modify to use column_bits. (SOURCE_COLUMN, LAST_SOURCE_LINE_LOCATION): New macros. (CURRENT_LINE_MAP): Remove macro. (linemap_position_for_column): New inline function. * line-map.c (linemap_init): Clear new fields. (linemap_check_files_exited): New function, extracted from ... (linemap_free): Use linemap_check_files_exited. (linemap_add): Remove from_line parameter. Various updates. (linemap_line_start): New function. (linemap_lookeup): Update for new field names. * cpphash.h (struct cpp_reader) <map>: Field removed. Because linemap_position_for_column may unpredictably change the current map, it is cleaner and simpler for us to not cache it in cpp_reader. (struct cpp_buffer): New sysp field. Changed warned_cplusplus_comments and from_stage3 to bitfields. * cppinit.c (cpp_read_min_file): pfile->map no longer exists. * cpplib.c (do_line, do_linemarker, _cpp_do_file_change): Get current map using linemap_lookup. (do_linemarker): Also set buffer's sysp field. (destringize_and_run): No longer need to decrement current line. * cppfiles.c (_cpp_stack_file): Set sysp from and in buffer. (search_path_head, open_file_failed): Use buffer's sysp. (cpp_make_system_header): Get current map using linemap_lookup. Also set buffer's sysp flag. * cppmacro.c (_cpp_builtin_macro_text): Likewise use linemap_lookup. * cpphash.h (CPP_INCREMENT_LINE): New macro. (struct cpp_buffer): Moved fields saved_cur, saved_rlimit to ... (struct cpp_reader): ... and adding saved_line_base field. * cpptrad.c (_cpp_overlay_buffer, _cpp_remove_overlay): Update accordingly. Don't adjust line. (_cpp_scan_out_logical_line): Use CPP_INCREMENT_LINE. * cpphash.c (CPP_IN_SYSTEM_HEADER): Replaced macro by ... (cpp_in_system_header): ... new inline function, using buffer's sysp. * cpperror.c (_cpp_begin_message): Update to use cpp_in_system_header. * cpplex.c (_cpp_lex_direct): Likewise. * cppmacro.c (_cpp_builtin_macro_text): Likewise. * cppmacro.c (_cpp_create_definition): Use buffer's sysp field. * cpplib.h (struct cpp_token): Rename line field to src_loc. Remove col field as it is now subsumed by src_loc. * cpperror.c: Update various field, parameter, and macro names. (print_location): If col==0, try SOURCE_COLUMN of line. (cpp_error): Use cur_token's src_loc field, rather than line+col. * cpplib.c (do_diagnostic): Token's src_loc fields replaces line+col. * cpplex.c (_cpp_process_line_notes, _cpp_lex_direct, _cpp_skip_block_comment): Use CPP_INCREMENT_LINE. (_cpp_temp_token): Replace cpp_token's line+col fields by src_loc. (_cpp_get_fresh_line): Don't need to adjust line for missing newline. (_cpp_lex_direct): Use linemap_position_for_column. * c-ppoutput.c (maybe_print_line, print_line): Don't take map parameter. Instead get it from the line_table global. Adjust callers. (print): Remove map field. Replace line field to src_line. (init_pp_output, account_for_newlines, maybe_print_line): Adjust. (cb_line_change): Use SOURCE_COLUMN. Minor optimizations. (pp_file_change): Use MAIN_FILE_P since we cannot checked print.map. Use LAST_SOURCE_LINE_LOCATION to "catch up" after #include. * cpptrad.c (copy_comment): Rename variable. * c-lex.c (map): Remove static variable, for same reason we removed cpp_reader's map field. (cb_line_change, cb_def_pragma, cb_define, cb_undef): Hence we need to call linemap_lookup. (cb_line_change): Token's line field replaced by src_loc. (fe_file_change): Use MAINFILE_P and LAST_SOURCE_LINE macros. Don't save new_map. * cpphash.h, cpperror.c, cpplib.h: Some renames of fileline to source_location. From-SVN: r77663
2004-02-11 16:29:30 +01:00
maybe_print_line (line);
fprintf (print.outf, "#undef %s\n", NODE_NAME (node));
Represent column numbers using line-map's source_location. The "next available source_location" is now managed internally by line-maps.c rather than by clients. * line-map.h (struct line_map): New field column_bits. <from_line>: Rename field to start_location. (struct line_maps): New fields highest_location and max_column_hint. (linemap_check_files_exited): New declaration. (linemap_line_start): New declaration. (linemap_add): Remove from_line parameter; use highest_location field. (SOURCE_LINE, LAST_SOURCE_LINE): Modify to use column_bits. (SOURCE_COLUMN, LAST_SOURCE_LINE_LOCATION): New macros. (CURRENT_LINE_MAP): Remove macro. (linemap_position_for_column): New inline function. * line-map.c (linemap_init): Clear new fields. (linemap_check_files_exited): New function, extracted from ... (linemap_free): Use linemap_check_files_exited. (linemap_add): Remove from_line parameter. Various updates. (linemap_line_start): New function. (linemap_lookeup): Update for new field names. * cpphash.h (struct cpp_reader) <map>: Field removed. Because linemap_position_for_column may unpredictably change the current map, it is cleaner and simpler for us to not cache it in cpp_reader. (struct cpp_buffer): New sysp field. Changed warned_cplusplus_comments and from_stage3 to bitfields. * cppinit.c (cpp_read_min_file): pfile->map no longer exists. * cpplib.c (do_line, do_linemarker, _cpp_do_file_change): Get current map using linemap_lookup. (do_linemarker): Also set buffer's sysp field. (destringize_and_run): No longer need to decrement current line. * cppfiles.c (_cpp_stack_file): Set sysp from and in buffer. (search_path_head, open_file_failed): Use buffer's sysp. (cpp_make_system_header): Get current map using linemap_lookup. Also set buffer's sysp flag. * cppmacro.c (_cpp_builtin_macro_text): Likewise use linemap_lookup. * cpphash.h (CPP_INCREMENT_LINE): New macro. (struct cpp_buffer): Moved fields saved_cur, saved_rlimit to ... (struct cpp_reader): ... and adding saved_line_base field. * cpptrad.c (_cpp_overlay_buffer, _cpp_remove_overlay): Update accordingly. Don't adjust line. (_cpp_scan_out_logical_line): Use CPP_INCREMENT_LINE. * cpphash.c (CPP_IN_SYSTEM_HEADER): Replaced macro by ... (cpp_in_system_header): ... new inline function, using buffer's sysp. * cpperror.c (_cpp_begin_message): Update to use cpp_in_system_header. * cpplex.c (_cpp_lex_direct): Likewise. * cppmacro.c (_cpp_builtin_macro_text): Likewise. * cppmacro.c (_cpp_create_definition): Use buffer's sysp field. * cpplib.h (struct cpp_token): Rename line field to src_loc. Remove col field as it is now subsumed by src_loc. * cpperror.c: Update various field, parameter, and macro names. (print_location): If col==0, try SOURCE_COLUMN of line. (cpp_error): Use cur_token's src_loc field, rather than line+col. * cpplib.c (do_diagnostic): Token's src_loc fields replaces line+col. * cpplex.c (_cpp_process_line_notes, _cpp_lex_direct, _cpp_skip_block_comment): Use CPP_INCREMENT_LINE. (_cpp_temp_token): Replace cpp_token's line+col fields by src_loc. (_cpp_get_fresh_line): Don't need to adjust line for missing newline. (_cpp_lex_direct): Use linemap_position_for_column. * c-ppoutput.c (maybe_print_line, print_line): Don't take map parameter. Instead get it from the line_table global. Adjust callers. (print): Remove map field. Replace line field to src_line. (init_pp_output, account_for_newlines, maybe_print_line): Adjust. (cb_line_change): Use SOURCE_COLUMN. Minor optimizations. (pp_file_change): Use MAIN_FILE_P since we cannot checked print.map. Use LAST_SOURCE_LINE_LOCATION to "catch up" after #include. * cpptrad.c (copy_comment): Rename variable. * c-lex.c (map): Remove static variable, for same reason we removed cpp_reader's map field. (cb_line_change, cb_def_pragma, cb_define, cb_undef): Hence we need to call linemap_lookup. (cb_line_change): Token's line field replaced by src_loc. (fe_file_change): Use MAINFILE_P and LAST_SOURCE_LINE macros. Don't save new_map. * cpphash.h, cpperror.c, cpplib.h: Some renames of fileline to source_location. From-SVN: r77663
2004-02-11 16:29:30 +01:00
print.src_line++;
cpperror.c (v_message): Split into _cpp_begin_message and v_message macro. * cpperror.c (v_message): Split into _cpp_begin_message and v_message macro. All callers updated. (_cpp_begin_message): Do inhibit_errors/inhibit_warnings checks here. * cppfiles.c (cpp_syshdr_flags): New function. (read_include_file): Don't call cpp_output_tokens. Call enter_file hook. * cppinit.c (dump_macros_helper): Moved to cppmain.c. (cpp_reader_init): Don't initialize token_buffer. Call _cpp_init_internal_pragmas. (cpp_cleanup): Don't clear token_buffer. (cpp_start_read): Don't worry about output from -D processing. Don't call cpp_output_tokens. (cpp_finish): Don't dump macros here. Don't call cpp_output_tokens. * cppmacro.c (_cpp_dump_definition): Rename cpp_dump_definition. Write directly to a FILE *. (dump_funlike_macro): Delete. (dump_macro_args): New. * cpplex.c (TOKEN_LEN): Convert to inline function. (_cpp_grow_token_buffer, safe_fwrite, cpp_output_tokens, cpp_scan_line, _cpp_dump_list): Delete. (cpp_printf, cpp_output_list): New. (output_line_command): Don't worry about entering or leaving files. (cpp_scan_buffer): Just output each token as we hit it. (process_directive): Don't call cpp_output_tokens. (_cpp_glue_header_name): Don't use token_buffer. (output_token, dump_param_spelling): Write directly to a FILE *. * cpplib.c (pass_thru_directive, dump_macro_name, pragma_dispatch, do_pragma_gcc): Delete. (do_define, do_undef, parse_include, do_line, do_ident, do_pragma, do_pragma_poison, cpp_pop_buffer): Call the appropriate hook functions. (do_error, do_warning, pragma_dependency): Call _cpp_begin_message, then cpp_output_list. (cpp_register_pragma, cpp_register_pragma_space, _cpp_init_internal_pragmas): New. (do_pragma): Walk the pragmas table here. (do_pragma_once, do_pragma_poison, do_pragma_system_header, do_pragma_dependency): Return void. (do_pragma_implementation): Moved to cppmain.c. * cpplib.h: Update prototypes. (struct cpp_reader): Remove printer, token_buffer, token_buffer_size, and limit. Add struct cb, and pragmas. (struct cpp_printer): Remove last_id and written. (CPP_WRITTEN, CPP_PWRITTEN, CPP_SET_WRITTEN, CPP_ADJUST_WRITTEN): Delete. * cpphash.h: Update prototypes. (ufputs): New wrapper. * cppmain.c (cb_define, cb_undef, cb_include, cb_ident, cb_enter_file, cb_leave_file, cb_def_pragma): New functions. (main): Set up callbacks. Register #pragma implementation. Dump macros from here. From-SVN: r35415
2000-08-02 03:13:45 +02:00
}
static void
cb_used_define (cpp_reader *pfile, source_location line ATTRIBUTE_UNUSED,
cpp_hashnode *node)
{
macro_queue *q;
if (node->flags & NODE_BUILTIN)
return;
q = XNEW (macro_queue);
q->macro = xstrdup ((const char *) cpp_macro_definition (pfile, node));
q->next = define_queue;
define_queue = q;
}
static void
cb_used_undef (cpp_reader *pfile ATTRIBUTE_UNUSED,
source_location line ATTRIBUTE_UNUSED,
cpp_hashnode *node)
{
macro_queue *q;
q = XNEW (macro_queue);
q->macro = xstrdup ((const char *) NODE_NAME (node));
q->next = undef_queue;
undef_queue = q;
}
static void
dump_queued_macros (cpp_reader *pfile ATTRIBUTE_UNUSED)
{
macro_queue *q;
/* End the previous line of text. */
if (print.printed)
{
putc ('\n', print.outf);
print.src_line++;
print.printed = false;
}
for (q = define_queue; q;)
{
macro_queue *oq;
fputs ("#define ", print.outf);
fputs (q->macro, print.outf);
putc ('\n', print.outf);
print.printed = false;
print.src_line++;
oq = q;
q = q->next;
free (oq->macro);
free (oq);
}
define_queue = NULL;
for (q = undef_queue; q;)
{
macro_queue *oq;
fprintf (print.outf, "#undef %s\n", q->macro);
print.src_line++;
oq = q;
q = q->next;
free (oq->macro);
free (oq);
}
undef_queue = NULL;
}
cpperror.c (v_message): Split into _cpp_begin_message and v_message macro. * cpperror.c (v_message): Split into _cpp_begin_message and v_message macro. All callers updated. (_cpp_begin_message): Do inhibit_errors/inhibit_warnings checks here. * cppfiles.c (cpp_syshdr_flags): New function. (read_include_file): Don't call cpp_output_tokens. Call enter_file hook. * cppinit.c (dump_macros_helper): Moved to cppmain.c. (cpp_reader_init): Don't initialize token_buffer. Call _cpp_init_internal_pragmas. (cpp_cleanup): Don't clear token_buffer. (cpp_start_read): Don't worry about output from -D processing. Don't call cpp_output_tokens. (cpp_finish): Don't dump macros here. Don't call cpp_output_tokens. * cppmacro.c (_cpp_dump_definition): Rename cpp_dump_definition. Write directly to a FILE *. (dump_funlike_macro): Delete. (dump_macro_args): New. * cpplex.c (TOKEN_LEN): Convert to inline function. (_cpp_grow_token_buffer, safe_fwrite, cpp_output_tokens, cpp_scan_line, _cpp_dump_list): Delete. (cpp_printf, cpp_output_list): New. (output_line_command): Don't worry about entering or leaving files. (cpp_scan_buffer): Just output each token as we hit it. (process_directive): Don't call cpp_output_tokens. (_cpp_glue_header_name): Don't use token_buffer. (output_token, dump_param_spelling): Write directly to a FILE *. * cpplib.c (pass_thru_directive, dump_macro_name, pragma_dispatch, do_pragma_gcc): Delete. (do_define, do_undef, parse_include, do_line, do_ident, do_pragma, do_pragma_poison, cpp_pop_buffer): Call the appropriate hook functions. (do_error, do_warning, pragma_dependency): Call _cpp_begin_message, then cpp_output_list. (cpp_register_pragma, cpp_register_pragma_space, _cpp_init_internal_pragmas): New. (do_pragma): Walk the pragmas table here. (do_pragma_once, do_pragma_poison, do_pragma_system_header, do_pragma_dependency): Return void. (do_pragma_implementation): Moved to cppmain.c. * cpplib.h: Update prototypes. (struct cpp_reader): Remove printer, token_buffer, token_buffer_size, and limit. Add struct cb, and pragmas. (struct cpp_printer): Remove last_id and written. (CPP_WRITTEN, CPP_PWRITTEN, CPP_SET_WRITTEN, CPP_ADJUST_WRITTEN): Delete. * cpphash.h: Update prototypes. (ufputs): New wrapper. * cppmain.c (cb_define, cb_undef, cb_include, cb_ident, cb_enter_file, cb_leave_file, cb_def_pragma): New functions. (main): Set up callbacks. Register #pragma implementation. Dump macros from here. From-SVN: r35415
2000-08-02 03:13:45 +02:00
static void
Represent column numbers using line-map's source_location. The "next available source_location" is now managed internally by line-maps.c rather than by clients. * line-map.h (struct line_map): New field column_bits. <from_line>: Rename field to start_location. (struct line_maps): New fields highest_location and max_column_hint. (linemap_check_files_exited): New declaration. (linemap_line_start): New declaration. (linemap_add): Remove from_line parameter; use highest_location field. (SOURCE_LINE, LAST_SOURCE_LINE): Modify to use column_bits. (SOURCE_COLUMN, LAST_SOURCE_LINE_LOCATION): New macros. (CURRENT_LINE_MAP): Remove macro. (linemap_position_for_column): New inline function. * line-map.c (linemap_init): Clear new fields. (linemap_check_files_exited): New function, extracted from ... (linemap_free): Use linemap_check_files_exited. (linemap_add): Remove from_line parameter. Various updates. (linemap_line_start): New function. (linemap_lookeup): Update for new field names. * cpphash.h (struct cpp_reader) <map>: Field removed. Because linemap_position_for_column may unpredictably change the current map, it is cleaner and simpler for us to not cache it in cpp_reader. (struct cpp_buffer): New sysp field. Changed warned_cplusplus_comments and from_stage3 to bitfields. * cppinit.c (cpp_read_min_file): pfile->map no longer exists. * cpplib.c (do_line, do_linemarker, _cpp_do_file_change): Get current map using linemap_lookup. (do_linemarker): Also set buffer's sysp field. (destringize_and_run): No longer need to decrement current line. * cppfiles.c (_cpp_stack_file): Set sysp from and in buffer. (search_path_head, open_file_failed): Use buffer's sysp. (cpp_make_system_header): Get current map using linemap_lookup. Also set buffer's sysp flag. * cppmacro.c (_cpp_builtin_macro_text): Likewise use linemap_lookup. * cpphash.h (CPP_INCREMENT_LINE): New macro. (struct cpp_buffer): Moved fields saved_cur, saved_rlimit to ... (struct cpp_reader): ... and adding saved_line_base field. * cpptrad.c (_cpp_overlay_buffer, _cpp_remove_overlay): Update accordingly. Don't adjust line. (_cpp_scan_out_logical_line): Use CPP_INCREMENT_LINE. * cpphash.c (CPP_IN_SYSTEM_HEADER): Replaced macro by ... (cpp_in_system_header): ... new inline function, using buffer's sysp. * cpperror.c (_cpp_begin_message): Update to use cpp_in_system_header. * cpplex.c (_cpp_lex_direct): Likewise. * cppmacro.c (_cpp_builtin_macro_text): Likewise. * cppmacro.c (_cpp_create_definition): Use buffer's sysp field. * cpplib.h (struct cpp_token): Rename line field to src_loc. Remove col field as it is now subsumed by src_loc. * cpperror.c: Update various field, parameter, and macro names. (print_location): If col==0, try SOURCE_COLUMN of line. (cpp_error): Use cur_token's src_loc field, rather than line+col. * cpplib.c (do_diagnostic): Token's src_loc fields replaces line+col. * cpplex.c (_cpp_process_line_notes, _cpp_lex_direct, _cpp_skip_block_comment): Use CPP_INCREMENT_LINE. (_cpp_temp_token): Replace cpp_token's line+col fields by src_loc. (_cpp_get_fresh_line): Don't need to adjust line for missing newline. (_cpp_lex_direct): Use linemap_position_for_column. * c-ppoutput.c (maybe_print_line, print_line): Don't take map parameter. Instead get it from the line_table global. Adjust callers. (print): Remove map field. Replace line field to src_line. (init_pp_output, account_for_newlines, maybe_print_line): Adjust. (cb_line_change): Use SOURCE_COLUMN. Minor optimizations. (pp_file_change): Use MAIN_FILE_P since we cannot checked print.map. Use LAST_SOURCE_LINE_LOCATION to "catch up" after #include. * cpptrad.c (copy_comment): Rename variable. * c-lex.c (map): Remove static variable, for same reason we removed cpp_reader's map field. (cb_line_change, cb_def_pragma, cb_define, cb_undef): Hence we need to call linemap_lookup. (cb_line_change): Token's line field replaced by src_loc. (fe_file_change): Use MAINFILE_P and LAST_SOURCE_LINE macros. Don't save new_map. * cpphash.h, cpperror.c, cpplib.h: Some renames of fileline to source_location. From-SVN: r77663
2004-02-11 16:29:30 +01:00
cb_include (cpp_reader *pfile ATTRIBUTE_UNUSED, source_location line,
const unsigned char *dir, const char *header, int angle_brackets,
const cpp_token **comments)
cpperror.c (v_message): Split into _cpp_begin_message and v_message macro. * cpperror.c (v_message): Split into _cpp_begin_message and v_message macro. All callers updated. (_cpp_begin_message): Do inhibit_errors/inhibit_warnings checks here. * cppfiles.c (cpp_syshdr_flags): New function. (read_include_file): Don't call cpp_output_tokens. Call enter_file hook. * cppinit.c (dump_macros_helper): Moved to cppmain.c. (cpp_reader_init): Don't initialize token_buffer. Call _cpp_init_internal_pragmas. (cpp_cleanup): Don't clear token_buffer. (cpp_start_read): Don't worry about output from -D processing. Don't call cpp_output_tokens. (cpp_finish): Don't dump macros here. Don't call cpp_output_tokens. * cppmacro.c (_cpp_dump_definition): Rename cpp_dump_definition. Write directly to a FILE *. (dump_funlike_macro): Delete. (dump_macro_args): New. * cpplex.c (TOKEN_LEN): Convert to inline function. (_cpp_grow_token_buffer, safe_fwrite, cpp_output_tokens, cpp_scan_line, _cpp_dump_list): Delete. (cpp_printf, cpp_output_list): New. (output_line_command): Don't worry about entering or leaving files. (cpp_scan_buffer): Just output each token as we hit it. (process_directive): Don't call cpp_output_tokens. (_cpp_glue_header_name): Don't use token_buffer. (output_token, dump_param_spelling): Write directly to a FILE *. * cpplib.c (pass_thru_directive, dump_macro_name, pragma_dispatch, do_pragma_gcc): Delete. (do_define, do_undef, parse_include, do_line, do_ident, do_pragma, do_pragma_poison, cpp_pop_buffer): Call the appropriate hook functions. (do_error, do_warning, pragma_dependency): Call _cpp_begin_message, then cpp_output_list. (cpp_register_pragma, cpp_register_pragma_space, _cpp_init_internal_pragmas): New. (do_pragma): Walk the pragmas table here. (do_pragma_once, do_pragma_poison, do_pragma_system_header, do_pragma_dependency): Return void. (do_pragma_implementation): Moved to cppmain.c. * cpplib.h: Update prototypes. (struct cpp_reader): Remove printer, token_buffer, token_buffer_size, and limit. Add struct cb, and pragmas. (struct cpp_printer): Remove last_id and written. (CPP_WRITTEN, CPP_PWRITTEN, CPP_SET_WRITTEN, CPP_ADJUST_WRITTEN): Delete. * cpphash.h: Update prototypes. (ufputs): New wrapper. * cppmain.c (cb_define, cb_undef, cb_include, cb_ident, cb_enter_file, cb_leave_file, cb_def_pragma): New functions. (main): Set up callbacks. Register #pragma implementation. Dump macros from here. From-SVN: r35415
2000-08-02 03:13:45 +02:00
{
Represent column numbers using line-map's source_location. The "next available source_location" is now managed internally by line-maps.c rather than by clients. * line-map.h (struct line_map): New field column_bits. <from_line>: Rename field to start_location. (struct line_maps): New fields highest_location and max_column_hint. (linemap_check_files_exited): New declaration. (linemap_line_start): New declaration. (linemap_add): Remove from_line parameter; use highest_location field. (SOURCE_LINE, LAST_SOURCE_LINE): Modify to use column_bits. (SOURCE_COLUMN, LAST_SOURCE_LINE_LOCATION): New macros. (CURRENT_LINE_MAP): Remove macro. (linemap_position_for_column): New inline function. * line-map.c (linemap_init): Clear new fields. (linemap_check_files_exited): New function, extracted from ... (linemap_free): Use linemap_check_files_exited. (linemap_add): Remove from_line parameter. Various updates. (linemap_line_start): New function. (linemap_lookeup): Update for new field names. * cpphash.h (struct cpp_reader) <map>: Field removed. Because linemap_position_for_column may unpredictably change the current map, it is cleaner and simpler for us to not cache it in cpp_reader. (struct cpp_buffer): New sysp field. Changed warned_cplusplus_comments and from_stage3 to bitfields. * cppinit.c (cpp_read_min_file): pfile->map no longer exists. * cpplib.c (do_line, do_linemarker, _cpp_do_file_change): Get current map using linemap_lookup. (do_linemarker): Also set buffer's sysp field. (destringize_and_run): No longer need to decrement current line. * cppfiles.c (_cpp_stack_file): Set sysp from and in buffer. (search_path_head, open_file_failed): Use buffer's sysp. (cpp_make_system_header): Get current map using linemap_lookup. Also set buffer's sysp flag. * cppmacro.c (_cpp_builtin_macro_text): Likewise use linemap_lookup. * cpphash.h (CPP_INCREMENT_LINE): New macro. (struct cpp_buffer): Moved fields saved_cur, saved_rlimit to ... (struct cpp_reader): ... and adding saved_line_base field. * cpptrad.c (_cpp_overlay_buffer, _cpp_remove_overlay): Update accordingly. Don't adjust line. (_cpp_scan_out_logical_line): Use CPP_INCREMENT_LINE. * cpphash.c (CPP_IN_SYSTEM_HEADER): Replaced macro by ... (cpp_in_system_header): ... new inline function, using buffer's sysp. * cpperror.c (_cpp_begin_message): Update to use cpp_in_system_header. * cpplex.c (_cpp_lex_direct): Likewise. * cppmacro.c (_cpp_builtin_macro_text): Likewise. * cppmacro.c (_cpp_create_definition): Use buffer's sysp field. * cpplib.h (struct cpp_token): Rename line field to src_loc. Remove col field as it is now subsumed by src_loc. * cpperror.c: Update various field, parameter, and macro names. (print_location): If col==0, try SOURCE_COLUMN of line. (cpp_error): Use cur_token's src_loc field, rather than line+col. * cpplib.c (do_diagnostic): Token's src_loc fields replaces line+col. * cpplex.c (_cpp_process_line_notes, _cpp_lex_direct, _cpp_skip_block_comment): Use CPP_INCREMENT_LINE. (_cpp_temp_token): Replace cpp_token's line+col fields by src_loc. (_cpp_get_fresh_line): Don't need to adjust line for missing newline. (_cpp_lex_direct): Use linemap_position_for_column. * c-ppoutput.c (maybe_print_line, print_line): Don't take map parameter. Instead get it from the line_table global. Adjust callers. (print): Remove map field. Replace line field to src_line. (init_pp_output, account_for_newlines, maybe_print_line): Adjust. (cb_line_change): Use SOURCE_COLUMN. Minor optimizations. (pp_file_change): Use MAIN_FILE_P since we cannot checked print.map. Use LAST_SOURCE_LINE_LOCATION to "catch up" after #include. * cpptrad.c (copy_comment): Rename variable. * c-lex.c (map): Remove static variable, for same reason we removed cpp_reader's map field. (cb_line_change, cb_def_pragma, cb_define, cb_undef): Hence we need to call linemap_lookup. (cb_line_change): Token's line field replaced by src_loc. (fe_file_change): Use MAINFILE_P and LAST_SOURCE_LINE macros. Don't save new_map. * cpphash.h, cpperror.c, cpplib.h: Some renames of fileline to source_location. From-SVN: r77663
2004-02-11 16:29:30 +01:00
maybe_print_line (line);
if (angle_brackets)
fprintf (print.outf, "#%s <%s>", dir, header);
else
fprintf (print.outf, "#%s \"%s\"", dir, header);
if (comments != NULL)
{
while (*comments != NULL)
{
if ((*comments)->flags & PREV_WHITE)
putc (' ', print.outf);
cpp_output_token (*comments, print.outf);
++comments;
}
}
putc ('\n', print.outf);
print.printed = false;
Represent column numbers using line-map's source_location. The "next available source_location" is now managed internally by line-maps.c rather than by clients. * line-map.h (struct line_map): New field column_bits. <from_line>: Rename field to start_location. (struct line_maps): New fields highest_location and max_column_hint. (linemap_check_files_exited): New declaration. (linemap_line_start): New declaration. (linemap_add): Remove from_line parameter; use highest_location field. (SOURCE_LINE, LAST_SOURCE_LINE): Modify to use column_bits. (SOURCE_COLUMN, LAST_SOURCE_LINE_LOCATION): New macros. (CURRENT_LINE_MAP): Remove macro. (linemap_position_for_column): New inline function. * line-map.c (linemap_init): Clear new fields. (linemap_check_files_exited): New function, extracted from ... (linemap_free): Use linemap_check_files_exited. (linemap_add): Remove from_line parameter. Various updates. (linemap_line_start): New function. (linemap_lookeup): Update for new field names. * cpphash.h (struct cpp_reader) <map>: Field removed. Because linemap_position_for_column may unpredictably change the current map, it is cleaner and simpler for us to not cache it in cpp_reader. (struct cpp_buffer): New sysp field. Changed warned_cplusplus_comments and from_stage3 to bitfields. * cppinit.c (cpp_read_min_file): pfile->map no longer exists. * cpplib.c (do_line, do_linemarker, _cpp_do_file_change): Get current map using linemap_lookup. (do_linemarker): Also set buffer's sysp field. (destringize_and_run): No longer need to decrement current line. * cppfiles.c (_cpp_stack_file): Set sysp from and in buffer. (search_path_head, open_file_failed): Use buffer's sysp. (cpp_make_system_header): Get current map using linemap_lookup. Also set buffer's sysp flag. * cppmacro.c (_cpp_builtin_macro_text): Likewise use linemap_lookup. * cpphash.h (CPP_INCREMENT_LINE): New macro. (struct cpp_buffer): Moved fields saved_cur, saved_rlimit to ... (struct cpp_reader): ... and adding saved_line_base field. * cpptrad.c (_cpp_overlay_buffer, _cpp_remove_overlay): Update accordingly. Don't adjust line. (_cpp_scan_out_logical_line): Use CPP_INCREMENT_LINE. * cpphash.c (CPP_IN_SYSTEM_HEADER): Replaced macro by ... (cpp_in_system_header): ... new inline function, using buffer's sysp. * cpperror.c (_cpp_begin_message): Update to use cpp_in_system_header. * cpplex.c (_cpp_lex_direct): Likewise. * cppmacro.c (_cpp_builtin_macro_text): Likewise. * cppmacro.c (_cpp_create_definition): Use buffer's sysp field. * cpplib.h (struct cpp_token): Rename line field to src_loc. Remove col field as it is now subsumed by src_loc. * cpperror.c: Update various field, parameter, and macro names. (print_location): If col==0, try SOURCE_COLUMN of line. (cpp_error): Use cur_token's src_loc field, rather than line+col. * cpplib.c (do_diagnostic): Token's src_loc fields replaces line+col. * cpplex.c (_cpp_process_line_notes, _cpp_lex_direct, _cpp_skip_block_comment): Use CPP_INCREMENT_LINE. (_cpp_temp_token): Replace cpp_token's line+col fields by src_loc. (_cpp_get_fresh_line): Don't need to adjust line for missing newline. (_cpp_lex_direct): Use linemap_position_for_column. * c-ppoutput.c (maybe_print_line, print_line): Don't take map parameter. Instead get it from the line_table global. Adjust callers. (print): Remove map field. Replace line field to src_line. (init_pp_output, account_for_newlines, maybe_print_line): Adjust. (cb_line_change): Use SOURCE_COLUMN. Minor optimizations. (pp_file_change): Use MAIN_FILE_P since we cannot checked print.map. Use LAST_SOURCE_LINE_LOCATION to "catch up" after #include. * cpptrad.c (copy_comment): Rename variable. * c-lex.c (map): Remove static variable, for same reason we removed cpp_reader's map field. (cb_line_change, cb_def_pragma, cb_define, cb_undef): Hence we need to call linemap_lookup. (cb_line_change): Token's line field replaced by src_loc. (fe_file_change): Use MAINFILE_P and LAST_SOURCE_LINE macros. Don't save new_map. * cpphash.h, cpperror.c, cpplib.h: Some renames of fileline to source_location. From-SVN: r77663
2004-02-11 16:29:30 +01:00
print.src_line++;
cpperror.c (v_message): Split into _cpp_begin_message and v_message macro. * cpperror.c (v_message): Split into _cpp_begin_message and v_message macro. All callers updated. (_cpp_begin_message): Do inhibit_errors/inhibit_warnings checks here. * cppfiles.c (cpp_syshdr_flags): New function. (read_include_file): Don't call cpp_output_tokens. Call enter_file hook. * cppinit.c (dump_macros_helper): Moved to cppmain.c. (cpp_reader_init): Don't initialize token_buffer. Call _cpp_init_internal_pragmas. (cpp_cleanup): Don't clear token_buffer. (cpp_start_read): Don't worry about output from -D processing. Don't call cpp_output_tokens. (cpp_finish): Don't dump macros here. Don't call cpp_output_tokens. * cppmacro.c (_cpp_dump_definition): Rename cpp_dump_definition. Write directly to a FILE *. (dump_funlike_macro): Delete. (dump_macro_args): New. * cpplex.c (TOKEN_LEN): Convert to inline function. (_cpp_grow_token_buffer, safe_fwrite, cpp_output_tokens, cpp_scan_line, _cpp_dump_list): Delete. (cpp_printf, cpp_output_list): New. (output_line_command): Don't worry about entering or leaving files. (cpp_scan_buffer): Just output each token as we hit it. (process_directive): Don't call cpp_output_tokens. (_cpp_glue_header_name): Don't use token_buffer. (output_token, dump_param_spelling): Write directly to a FILE *. * cpplib.c (pass_thru_directive, dump_macro_name, pragma_dispatch, do_pragma_gcc): Delete. (do_define, do_undef, parse_include, do_line, do_ident, do_pragma, do_pragma_poison, cpp_pop_buffer): Call the appropriate hook functions. (do_error, do_warning, pragma_dependency): Call _cpp_begin_message, then cpp_output_list. (cpp_register_pragma, cpp_register_pragma_space, _cpp_init_internal_pragmas): New. (do_pragma): Walk the pragmas table here. (do_pragma_once, do_pragma_poison, do_pragma_system_header, do_pragma_dependency): Return void. (do_pragma_implementation): Moved to cppmain.c. * cpplib.h: Update prototypes. (struct cpp_reader): Remove printer, token_buffer, token_buffer_size, and limit. Add struct cb, and pragmas. (struct cpp_printer): Remove last_id and written. (CPP_WRITTEN, CPP_PWRITTEN, CPP_SET_WRITTEN, CPP_ADJUST_WRITTEN): Delete. * cpphash.h: Update prototypes. (ufputs): New wrapper. * cppmain.c (cb_define, cb_undef, cb_include, cb_ident, cb_enter_file, cb_leave_file, cb_def_pragma): New functions. (main): Set up callbacks. Register #pragma implementation. Dump macros from here. From-SVN: r35415
2000-08-02 03:13:45 +02:00
}
Partially revert/redo 2003-10-01 change; fix -fworking-directory. * c-ppoutput.c (pp_dir_change): New function. * c-common.h (pp_dir_change): New declaration. * cpplib.h (struct cpp_options): Remove working_directory field. * cppinit.c (cpp_find_main_file, cpp_push_main_file): Merge back to (cpp_read_main_file): as before 10-01. Call _cpp_stack_file. Don't handle -fworking_directory here, but in c_common_post_options. (read_original_directory): Don't back up when done. Don't clear no-longer used working_directory flag. * cpplib.h: Update declarations to match. * c-lex.c (cb_dir_change): Move to c-opts.c. (init_c_lex): Don't set dir_change callback here, since we want to set it even if flag_preprocess_only. * c-opts.c (cb_dir_change): Function moved from c-lex.c. (c_common_post_options): Set dir_change callback. Call pp_dir_change if approporiate. (finish_options): Don't call cpp_find_main_file here. Hence remove unneeded parameter and result. Do LC_RENAME for <built-in>. (c_common_post_options): Call cpp_read_main_file here instead. (c_common_init): Update accordingly. (push_command_line_include): Don't cpp_push_main_file. Do LC_RENAME rather than LC_LEASE to get back to main file. Compared to pre-10-01 version, inline cpp_rename_to_main_file. (c_common_parse_file): Call cpp_read_main_file for subsequent main files, but call finish_options for all files. * c-opts.c (sanitize_cpp_opts): Don't set cpp_opts->working_directory. * fix-header.c (read_scan_file): Call cpp_read_main_file instead of cpp_find_main_file + cpp_push_main_file. * c-lex.c (fe_file_change): Don't set main_input_filename here. * opts.c (handle_options): Only set main_input_filename first time. From-SVN: r77303
2004-02-05 07:52:26 +01:00
/* Callback called when -fworking-director and -E to emit working
directory in cpp output file. */
Partially revert/redo 2003-10-01 change; fix -fworking-directory. * c-ppoutput.c (pp_dir_change): New function. * c-common.h (pp_dir_change): New declaration. * cpplib.h (struct cpp_options): Remove working_directory field. * cppinit.c (cpp_find_main_file, cpp_push_main_file): Merge back to (cpp_read_main_file): as before 10-01. Call _cpp_stack_file. Don't handle -fworking_directory here, but in c_common_post_options. (read_original_directory): Don't back up when done. Don't clear no-longer used working_directory flag. * cpplib.h: Update declarations to match. * c-lex.c (cb_dir_change): Move to c-opts.c. (init_c_lex): Don't set dir_change callback here, since we want to set it even if flag_preprocess_only. * c-opts.c (cb_dir_change): Function moved from c-lex.c. (c_common_post_options): Set dir_change callback. Call pp_dir_change if approporiate. (finish_options): Don't call cpp_find_main_file here. Hence remove unneeded parameter and result. Do LC_RENAME for <built-in>. (c_common_post_options): Call cpp_read_main_file here instead. (c_common_init): Update accordingly. (push_command_line_include): Don't cpp_push_main_file. Do LC_RENAME rather than LC_LEASE to get back to main file. Compared to pre-10-01 version, inline cpp_rename_to_main_file. (c_common_parse_file): Call cpp_read_main_file for subsequent main files, but call finish_options for all files. * c-opts.c (sanitize_cpp_opts): Don't set cpp_opts->working_directory. * fix-header.c (read_scan_file): Call cpp_read_main_file instead of cpp_find_main_file + cpp_push_main_file. * c-lex.c (fe_file_change): Don't set main_input_filename here. * opts.c (handle_options): Only set main_input_filename first time. From-SVN: r77303
2004-02-05 07:52:26 +01:00
void
pp_dir_change (cpp_reader *pfile ATTRIBUTE_UNUSED, const char *dir)
{
size_t to_file_len = strlen (dir);
tree-inline.c (copy_body_r): Use explicit cast when converting from void *. * tree-inline.c (copy_body_r): Use explicit cast when converting from void *. (copy_bb): Likewise. (copy_edges_for_bb): Likewise. (remap_decl_1): Likewise. (estimate_num_insns_1): Likewise. * cgraph.c (hash_node): Use explicit cast when converting from void *. (eq_node): Likewise. (cgraph_create_node): Use GGC_CNEW. (cgraph_create_edge): Use GGC_NEW. (cgraph_remove_node): Use explicit cast when converting from void *. (hash_varpool_node): Likewise. (eq_varpool_node): Likewise. (cgraph_varpool_node): Use GGC_CNEW. * lambda.h (lambda_vector_new): Use GGC_CNEWVEC. * tree-scalar-evolution.c (new_scev_info_str): Use XNEW. (eq_scev_info): Use explicit cast when converting from void *. (find_var_scev_info): Likewise. (set_instantiated_value): Likewise. (gather_stats_on_scev_database_1): Likewise. * cfgloop.h (simple_loop_desc): Use explicit cast when converting from void *. * c-pch.c (c_common_write_pch): Use XNEWVEC. (c_common_read_pch): Likewise. * prefix.c (save_string): Use XNEWVEC. (translate_name): Use explicit cast when converting from void *. * c-ppoutput.c (print_line): Use explicit cast when converting from void *. (pp_dir_change): Likewise. * c-cppbuiltin.c (builtin_define_std): Likewise. (builtin_define_with_value): Likewise. (builtin_define_with_value_n): Likewise. (builtin_define_with_int_value): Likewise. (builtin_define_type_max): Likewise. * c-incpath.c (add_env_var_paths): Use XNEWVEC. (add_path): Use XNEW. * c-format.c (check_format_info_main): Use GGC_NEW. (format_type_warning): Use explicit cast when converting from void *. * c-typeck.c (alloc_tagged_tu_seen_cache): Use XNEW instead of xmalloc. (start_init): Likewise. * tree-flow-inline.h (first_referenced_var): Use explicit cast when converting from void *. (next_referenced_var): Likewise. * c-pragma.c (push_alignment): Use GGC_NEW instead of ggc_alloc. * gensupport.c (lookup_predicate): Use explicit cast to convert from void *. (init_predicate_table): Use XCNEW instead of xcalloc. * genpreds.c (process_define_predicate): Likewise. From-SVN: r108723
2005-12-17 21:45:46 +01:00
unsigned char *to_file_quoted =
(unsigned char *) alloca (to_file_len * 4 + 1);
Partially revert/redo 2003-10-01 change; fix -fworking-directory. * c-ppoutput.c (pp_dir_change): New function. * c-common.h (pp_dir_change): New declaration. * cpplib.h (struct cpp_options): Remove working_directory field. * cppinit.c (cpp_find_main_file, cpp_push_main_file): Merge back to (cpp_read_main_file): as before 10-01. Call _cpp_stack_file. Don't handle -fworking_directory here, but in c_common_post_options. (read_original_directory): Don't back up when done. Don't clear no-longer used working_directory flag. * cpplib.h: Update declarations to match. * c-lex.c (cb_dir_change): Move to c-opts.c. (init_c_lex): Don't set dir_change callback here, since we want to set it even if flag_preprocess_only. * c-opts.c (cb_dir_change): Function moved from c-lex.c. (c_common_post_options): Set dir_change callback. Call pp_dir_change if approporiate. (finish_options): Don't call cpp_find_main_file here. Hence remove unneeded parameter and result. Do LC_RENAME for <built-in>. (c_common_post_options): Call cpp_read_main_file here instead. (c_common_init): Update accordingly. (push_command_line_include): Don't cpp_push_main_file. Do LC_RENAME rather than LC_LEASE to get back to main file. Compared to pre-10-01 version, inline cpp_rename_to_main_file. (c_common_parse_file): Call cpp_read_main_file for subsequent main files, but call finish_options for all files. * c-opts.c (sanitize_cpp_opts): Don't set cpp_opts->working_directory. * fix-header.c (read_scan_file): Call cpp_read_main_file instead of cpp_find_main_file + cpp_push_main_file. * c-lex.c (fe_file_change): Don't set main_input_filename here. * opts.c (handle_options): Only set main_input_filename first time. From-SVN: r77303
2004-02-05 07:52:26 +01:00
unsigned char *p;
/* cpp_quote_string does not nul-terminate, so we have to do it ourselves. */
p = cpp_quote_string (to_file_quoted, (const unsigned char *) dir, to_file_len);
Partially revert/redo 2003-10-01 change; fix -fworking-directory. * c-ppoutput.c (pp_dir_change): New function. * c-common.h (pp_dir_change): New declaration. * cpplib.h (struct cpp_options): Remove working_directory field. * cppinit.c (cpp_find_main_file, cpp_push_main_file): Merge back to (cpp_read_main_file): as before 10-01. Call _cpp_stack_file. Don't handle -fworking_directory here, but in c_common_post_options. (read_original_directory): Don't back up when done. Don't clear no-longer used working_directory flag. * cpplib.h: Update declarations to match. * c-lex.c (cb_dir_change): Move to c-opts.c. (init_c_lex): Don't set dir_change callback here, since we want to set it even if flag_preprocess_only. * c-opts.c (cb_dir_change): Function moved from c-lex.c. (c_common_post_options): Set dir_change callback. Call pp_dir_change if approporiate. (finish_options): Don't call cpp_find_main_file here. Hence remove unneeded parameter and result. Do LC_RENAME for <built-in>. (c_common_post_options): Call cpp_read_main_file here instead. (c_common_init): Update accordingly. (push_command_line_include): Don't cpp_push_main_file. Do LC_RENAME rather than LC_LEASE to get back to main file. Compared to pre-10-01 version, inline cpp_rename_to_main_file. (c_common_parse_file): Call cpp_read_main_file for subsequent main files, but call finish_options for all files. * c-opts.c (sanitize_cpp_opts): Don't set cpp_opts->working_directory. * fix-header.c (read_scan_file): Call cpp_read_main_file instead of cpp_find_main_file + cpp_push_main_file. * c-lex.c (fe_file_change): Don't set main_input_filename here. * opts.c (handle_options): Only set main_input_filename first time. From-SVN: r77303
2004-02-05 07:52:26 +01:00
*p = '\0';
fprintf (print.outf, "# 1 \"%s//\"\n", to_file_quoted);
}
/* The file name, line number or system header flags have changed, as
Represent column numbers using line-map's source_location. The "next available source_location" is now managed internally by line-maps.c rather than by clients. * line-map.h (struct line_map): New field column_bits. <from_line>: Rename field to start_location. (struct line_maps): New fields highest_location and max_column_hint. (linemap_check_files_exited): New declaration. (linemap_line_start): New declaration. (linemap_add): Remove from_line parameter; use highest_location field. (SOURCE_LINE, LAST_SOURCE_LINE): Modify to use column_bits. (SOURCE_COLUMN, LAST_SOURCE_LINE_LOCATION): New macros. (CURRENT_LINE_MAP): Remove macro. (linemap_position_for_column): New inline function. * line-map.c (linemap_init): Clear new fields. (linemap_check_files_exited): New function, extracted from ... (linemap_free): Use linemap_check_files_exited. (linemap_add): Remove from_line parameter. Various updates. (linemap_line_start): New function. (linemap_lookeup): Update for new field names. * cpphash.h (struct cpp_reader) <map>: Field removed. Because linemap_position_for_column may unpredictably change the current map, it is cleaner and simpler for us to not cache it in cpp_reader. (struct cpp_buffer): New sysp field. Changed warned_cplusplus_comments and from_stage3 to bitfields. * cppinit.c (cpp_read_min_file): pfile->map no longer exists. * cpplib.c (do_line, do_linemarker, _cpp_do_file_change): Get current map using linemap_lookup. (do_linemarker): Also set buffer's sysp field. (destringize_and_run): No longer need to decrement current line. * cppfiles.c (_cpp_stack_file): Set sysp from and in buffer. (search_path_head, open_file_failed): Use buffer's sysp. (cpp_make_system_header): Get current map using linemap_lookup. Also set buffer's sysp flag. * cppmacro.c (_cpp_builtin_macro_text): Likewise use linemap_lookup. * cpphash.h (CPP_INCREMENT_LINE): New macro. (struct cpp_buffer): Moved fields saved_cur, saved_rlimit to ... (struct cpp_reader): ... and adding saved_line_base field. * cpptrad.c (_cpp_overlay_buffer, _cpp_remove_overlay): Update accordingly. Don't adjust line. (_cpp_scan_out_logical_line): Use CPP_INCREMENT_LINE. * cpphash.c (CPP_IN_SYSTEM_HEADER): Replaced macro by ... (cpp_in_system_header): ... new inline function, using buffer's sysp. * cpperror.c (_cpp_begin_message): Update to use cpp_in_system_header. * cpplex.c (_cpp_lex_direct): Likewise. * cppmacro.c (_cpp_builtin_macro_text): Likewise. * cppmacro.c (_cpp_create_definition): Use buffer's sysp field. * cpplib.h (struct cpp_token): Rename line field to src_loc. Remove col field as it is now subsumed by src_loc. * cpperror.c: Update various field, parameter, and macro names. (print_location): If col==0, try SOURCE_COLUMN of line. (cpp_error): Use cur_token's src_loc field, rather than line+col. * cpplib.c (do_diagnostic): Token's src_loc fields replaces line+col. * cpplex.c (_cpp_process_line_notes, _cpp_lex_direct, _cpp_skip_block_comment): Use CPP_INCREMENT_LINE. (_cpp_temp_token): Replace cpp_token's line+col fields by src_loc. (_cpp_get_fresh_line): Don't need to adjust line for missing newline. (_cpp_lex_direct): Use linemap_position_for_column. * c-ppoutput.c (maybe_print_line, print_line): Don't take map parameter. Instead get it from the line_table global. Adjust callers. (print): Remove map field. Replace line field to src_line. (init_pp_output, account_for_newlines, maybe_print_line): Adjust. (cb_line_change): Use SOURCE_COLUMN. Minor optimizations. (pp_file_change): Use MAIN_FILE_P since we cannot checked print.map. Use LAST_SOURCE_LINE_LOCATION to "catch up" after #include. * cpptrad.c (copy_comment): Rename variable. * c-lex.c (map): Remove static variable, for same reason we removed cpp_reader's map field. (cb_line_change, cb_def_pragma, cb_define, cb_undef): Hence we need to call linemap_lookup. (cb_line_change): Token's line field replaced by src_loc. (fe_file_change): Use MAINFILE_P and LAST_SOURCE_LINE macros. Don't save new_map. * cpphash.h, cpperror.c, cpplib.h: Some renames of fileline to source_location. From-SVN: r77663
2004-02-11 16:29:30 +01:00
described in MAP. */
void
Replace line_map union with C++ class hierarchy gcc/ChangeLog: * diagnostic.c (diagnostic_report_current_module): Strengthen local "new_map" from const line_map * to const line_map_ordinary *. * genmatch.c (error_cb): Likewise for local "map". (output_line_directive): Likewise for local "map". * input.c (expand_location_1): Likewise for local "map". Pass NULL rather than &map to linemap_unwind_to_first_non_reserved_loc, since the value is never read from there, and the value written back not read from here. (is_location_from_builtin_token): Strengthen local "map" from const line_map * to const line_map_ordinary *. (dump_location_info): Strengthen locals "map" from line_map *, one to const line_map_ordinary *, the other to const line_map_macro *. * tree-diagnostic.c (loc_map_pair): Strengthen field "map" from const line_map * to const line_map_macro *. (maybe_unwind_expanded_macro_loc): Add a call to linemap_check_macro when writing to the "map" field of the loc_map_pair. Introduce local const line_map_ordinary * "ord_map", using it in place of "map" in the part of the function where we know we have an ordinary map. Strengthen local "m" from const line_map * to const line_map_ordinary *. gcc/ada/ChangeLog: * gcc-interface/trans.c (Sloc_to_locus1): Strenghthen local "map" from line_map * to line_map_ordinary *. gcc/c-family/ChangeLog: * c-common.h (fe_file_change): Strengthen param from const line_map * to const line_map_ordinary *. (pp_file_change): Likewise. * c-lex.c (fe_file_change): Likewise. (cb_define): Use linemap_check_ordinary when invoking SOURCE_LINE. (cb_undef): Likewise. * c-opts.c (c_finish_options): Use linemap_check_ordinary when invoking cb_file_change. (c_finish_options): Likewise. (push_command_line_include): Likewise. (cb_file_change): Strengthen param "new_map" from const line_map * to const line_map_ordinary *. * c-ppoutput.c (cb_define): Likewise for local "map". (pp_file_change): Likewise for param "map" and local "from". gcc/fortran/ChangeLog: * cpp.c (maybe_print_line): Strengthen local "map" from const line_map * to const line_map_ordinary *. (cb_file_change): Likewise for param "map" and local "from". (cb_line_change): Likewise for local "map". libcpp/ChangeLog: * directives.c (do_line): Strengthen local "map" from const line_map * to const line_map_ordinary *. (do_linemarker): Likewise. (_cpp_do_file_change): Assert that we're not dealing with a macro map. Introduce local "ord_map" via a call to linemap_check_ordinary, guarded within the check for non-NULL. Use it for typesafety. * files.c (cpp_make_system_header): Strengthen local "map" from const line_map * to const line_map_ordinary *. * include/cpplib.h (struct cpp_callbacks): Likewise for second parameter of "file_change" callback. * include/line-map.h (struct line_map): Convert from a struct containing a union to a base class. (struct line_map_ordinary): Convert to a subclass of line_map. (struct line_map_macro): Likewise. (linemap_check_ordinary): Strengthen return type from line_map * to line_map_ordinary *, and add a const-variant. (linemap_check_macro): New pair of functions. (ORDINARY_MAP_STARTING_LINE_NUMBER): Strengthen param from const line_map * to const line_map_ordinary *, eliminating call to linemap_check_ordinary. Likewise for the non-const variant. (ORDINARY_MAP_INCLUDER_FILE_INDEX): Likewise. (ORDINARY_MAP_IN_SYSTEM_HEADER_P): Likewise. (ORDINARY_MAP_NUMBER_OF_COLUMN_BITS): Likewise. (ORDINARY_MAP_FILE_NAME): Likewise. (MACRO_MAP_MACRO): Strengthen param from const line_map * to const line_map_macro *. Likewise for the non-const variant. (MACRO_MAP_NUM_MACRO_TOKENS): Likewise. (MACRO_MAP_LOCATIONS): Likewise. (MACRO_MAP_EXPANSION_POINT_LOCATION): Likewise. (struct maps_info): Replace with... (struct maps_info_ordinary):...this and... (struct maps_info_macro): ...this. (struct line_maps): Convert fields "info_ordinary" and "info_macro" to the above new structs. (LINEMAPS_MAP_INFO): Delete both functions. (LINEMAPS_MAPS): Likewise. (LINEMAPS_ALLOCATED): Rewrite both variants to avoid using LINEMAPS_MAP_INFO. (LINEMAPS_USED): Likewise. (LINEMAPS_CACHE): Likewise. (LINEMAPS_MAP_AT): Likewise. (LINEMAPS_ORDINARY_MAPS): Strengthen return type from line_map * to line_map_ordinary *. (LINEMAPS_ORDINARY_MAP_AT): Likewise. (LINEMAPS_LAST_ORDINARY_MAP): Likewise. (LINEMAPS_LAST_ALLOCATED_ORDINARY_MAP): Likewise. (LINEMAPS_MACRO_MAPS): Strengthen return type from line_map * to line_map_macro *. (LINEMAPS_MACRO_MAP_AT): Likewise. (LINEMAPS_LAST_MACRO_MAP): Likewise. (LINEMAPS_LAST_ALLOCATED_MACRO_MAP): Likewise. (linemap_map_get_macro_name): Strengthen param from const line_map * to const line_map_macro *. (SOURCE_LINE): Strengthen first param from const line_map * to const line_map_ordinary *, removing call to linemap_check_ordinary. (SOURCE_COLUMN): Likewise. (LAST_SOURCE_LINE_LOCATION): Likewise. (LAST_SOURCE_LINE): Strengthen first param from const line_map * to const line_map_ordinary *. (LAST_SOURCE_COLUMN): Likewise. (INCLUDED_FROM): Strengthen return type from line_map * to line_map_ordinary *., and second param from const line_map * to const line_map_ordinary *, removing call to linemap_check_ordinary. (MAIN_FILE_P): Strengthen param from const line_map * to const line_map_ordinary *, removing call to linemap_check_ordinary. (linemap_position_for_line_and_column): Strengthen param from const line_map * to const line_map_ordinary *. (LINEMAP_FILE): Strengthen param from const line_map * to const line_map_ordinary *, removing call to linemap_check_ordinary. (LINEMAP_LINE): Likewise. (LINEMAP_SYSP): Likewise. (linemap_resolve_location): Strengthen final param from const line_map ** to const line_map_ordinary **. * internal.h (CPP_INCREMENT_LINE): Likewise for local "map". (linemap_enter_macro): Strengthen return type from const line_map * to const line_map_macro *. (linemap_add_macro_token): Likewise for first param. * line-map.c (linemap_check_files_exited): Strengthen local "map" from const line_map * to const line_map_ordinary *. (new_linemap): Introduce local "map_size" and use it when calculating how large the buffer should be. Rewrite based on change of info_macro and info_ordinary into distinct types. (linemap_add): Strengthen locals "map" and "from" from line_map * to line_map_ordinary *. (linemap_enter_macro): Strengthen return type from const line_map * to const line_map_macro *, and local "map" from line_map * to line_map_macro *. (linemap_add_macro_token): Strengthen param "map" from const line_map * to const line_map_macro *. (linemap_line_start): Strengthen local "map" from line_map * to line_map_ordinary *. (linemap_position_for_column): Likewise. (linemap_position_for_line_and_column): Strengthen first param from const line_map * to const line_map_ordinary *. (linemap_position_for_loc_and_offset): Strengthen local "map" from const line_map * to const line_map_ordinary *. (linemap_ordinary_map_lookup): Likewise for return type and locals "cached" and "result". (linemap_macro_map_lookup): Strengthen return type and locals "cached" and "result" from const line_map * to const line_map_macro *. (linemap_macro_map_loc_to_exp_point): Likewise for param "map". (linemap_macro_map_loc_to_def_point): Likewise. (linemap_macro_map_loc_unwind_toward_spelling): Likewise. (linemap_get_expansion_line): Strengthen local "map" from const line_map * to const line_map_ordinary *. (linemap_get_expansion_filename): Likewise. (linemap_map_get_macro_name): Strengthen param from const line_map * to const line_map_macro *. (linemap_location_in_system_header_p): Add call to linemap_check_ordinary in region guarded by !linemap_macro_expansion_map_p. Introduce local "macro_map" via linemap_check_macro in other region, using it in place of "map" for typesafety. (first_map_in_common_1): Add calls to linemap_check_macro. (trace_include): Strengthen param "map" from const line_map * to const line_map_ordinary *. (linemap_macro_loc_to_spelling_point): Strengthen final param from const line_map ** to const line_map_ordinary **. Replace a C-style cast with a const_cast, and add calls to linemap_check_macro and linemap_check_ordinary. (linemap_macro_loc_to_def_point): Likewise. (linemap_macro_loc_to_exp_point): Likewise. (linemap_resolve_location): Strengthen final param from const line_map ** to const line_map_ordinary **. (linemap_unwind_toward_expansion): Introduce local "macro_map" via a checked cast and use it in place of *map. (linemap_unwind_to_first_non_reserved_loc): Strengthen local "map1" from const line_map * to const line_map_ordinary *. (linemap_expand_location): Introduce local "ord_map" via a checked cast and use it in place of map. (linemap_dump): Make local "map" const. Strengthen local "includer_map" from line_map * to const line_map_ordinary *. Introduce locals "ord_map" and "macro_map" via checked casts and use them in place of "map" for typesafety. (linemap_dump_location): Strengthen local "map" from const line_map * to const line_map_ordinary *. (linemap_get_file_highest_location): Update for elimination of union. (linemap_get_statistics): Strengthen local "cur_map" from line_map * to const line_map_macro *. Update uses of sizeof to use the appropriate line_map subclasses. * macro.c (_cpp_warn_if_unused_macro): Add call to linemap_check_ordinary. (builtin_macro): Strengthen local "map" from const line_map * to const line_map_macro *. (enter_macro_context): Likewise. (replace_args): Likewise. (tokens_buff_put_token_to): Likewise for param "map". (tokens_buff_add_token): Likewise. From-SVN: r223365
2015-05-19 15:18:01 +02:00
pp_file_change (const line_map_ordinary *map)
cpperror.c (v_message): Split into _cpp_begin_message and v_message macro. * cpperror.c (v_message): Split into _cpp_begin_message and v_message macro. All callers updated. (_cpp_begin_message): Do inhibit_errors/inhibit_warnings checks here. * cppfiles.c (cpp_syshdr_flags): New function. (read_include_file): Don't call cpp_output_tokens. Call enter_file hook. * cppinit.c (dump_macros_helper): Moved to cppmain.c. (cpp_reader_init): Don't initialize token_buffer. Call _cpp_init_internal_pragmas. (cpp_cleanup): Don't clear token_buffer. (cpp_start_read): Don't worry about output from -D processing. Don't call cpp_output_tokens. (cpp_finish): Don't dump macros here. Don't call cpp_output_tokens. * cppmacro.c (_cpp_dump_definition): Rename cpp_dump_definition. Write directly to a FILE *. (dump_funlike_macro): Delete. (dump_macro_args): New. * cpplex.c (TOKEN_LEN): Convert to inline function. (_cpp_grow_token_buffer, safe_fwrite, cpp_output_tokens, cpp_scan_line, _cpp_dump_list): Delete. (cpp_printf, cpp_output_list): New. (output_line_command): Don't worry about entering or leaving files. (cpp_scan_buffer): Just output each token as we hit it. (process_directive): Don't call cpp_output_tokens. (_cpp_glue_header_name): Don't use token_buffer. (output_token, dump_param_spelling): Write directly to a FILE *. * cpplib.c (pass_thru_directive, dump_macro_name, pragma_dispatch, do_pragma_gcc): Delete. (do_define, do_undef, parse_include, do_line, do_ident, do_pragma, do_pragma_poison, cpp_pop_buffer): Call the appropriate hook functions. (do_error, do_warning, pragma_dependency): Call _cpp_begin_message, then cpp_output_list. (cpp_register_pragma, cpp_register_pragma_space, _cpp_init_internal_pragmas): New. (do_pragma): Walk the pragmas table here. (do_pragma_once, do_pragma_poison, do_pragma_system_header, do_pragma_dependency): Return void. (do_pragma_implementation): Moved to cppmain.c. * cpplib.h: Update prototypes. (struct cpp_reader): Remove printer, token_buffer, token_buffer_size, and limit. Add struct cb, and pragmas. (struct cpp_printer): Remove last_id and written. (CPP_WRITTEN, CPP_PWRITTEN, CPP_SET_WRITTEN, CPP_ADJUST_WRITTEN): Delete. * cpphash.h: Update prototypes. (ufputs): New wrapper. * cppmain.c (cb_define, cb_undef, cb_include, cb_ident, cb_enter_file, cb_leave_file, cb_def_pragma): New functions. (main): Set up callbacks. Register #pragma implementation. Dump macros from here. From-SVN: r35415
2000-08-02 03:13:45 +02:00
{
const char *flags = "";
cpperror.c (v_message): Split into _cpp_begin_message and v_message macro. * cpperror.c (v_message): Split into _cpp_begin_message and v_message macro. All callers updated. (_cpp_begin_message): Do inhibit_errors/inhibit_warnings checks here. * cppfiles.c (cpp_syshdr_flags): New function. (read_include_file): Don't call cpp_output_tokens. Call enter_file hook. * cppinit.c (dump_macros_helper): Moved to cppmain.c. (cpp_reader_init): Don't initialize token_buffer. Call _cpp_init_internal_pragmas. (cpp_cleanup): Don't clear token_buffer. (cpp_start_read): Don't worry about output from -D processing. Don't call cpp_output_tokens. (cpp_finish): Don't dump macros here. Don't call cpp_output_tokens. * cppmacro.c (_cpp_dump_definition): Rename cpp_dump_definition. Write directly to a FILE *. (dump_funlike_macro): Delete. (dump_macro_args): New. * cpplex.c (TOKEN_LEN): Convert to inline function. (_cpp_grow_token_buffer, safe_fwrite, cpp_output_tokens, cpp_scan_line, _cpp_dump_list): Delete. (cpp_printf, cpp_output_list): New. (output_line_command): Don't worry about entering or leaving files. (cpp_scan_buffer): Just output each token as we hit it. (process_directive): Don't call cpp_output_tokens. (_cpp_glue_header_name): Don't use token_buffer. (output_token, dump_param_spelling): Write directly to a FILE *. * cpplib.c (pass_thru_directive, dump_macro_name, pragma_dispatch, do_pragma_gcc): Delete. (do_define, do_undef, parse_include, do_line, do_ident, do_pragma, do_pragma_poison, cpp_pop_buffer): Call the appropriate hook functions. (do_error, do_warning, pragma_dependency): Call _cpp_begin_message, then cpp_output_list. (cpp_register_pragma, cpp_register_pragma_space, _cpp_init_internal_pragmas): New. (do_pragma): Walk the pragmas table here. (do_pragma_once, do_pragma_poison, do_pragma_system_header, do_pragma_dependency): Return void. (do_pragma_implementation): Moved to cppmain.c. * cpplib.h: Update prototypes. (struct cpp_reader): Remove printer, token_buffer, token_buffer_size, and limit. Add struct cb, and pragmas. (struct cpp_printer): Remove last_id and written. (CPP_WRITTEN, CPP_PWRITTEN, CPP_SET_WRITTEN, CPP_ADJUST_WRITTEN): Delete. * cpphash.h: Update prototypes. (ufputs): New wrapper. * cppmain.c (cb_define, cb_undef, cb_include, cb_ident, cb_enter_file, cb_leave_file, cb_def_pragma): New functions. (main): Set up callbacks. Register #pragma implementation. Dump macros from here. From-SVN: r35415
2000-08-02 03:13:45 +02:00
if (flag_no_line_commands)
return;
if (map != NULL)
{
re PR preprocessor/34695 (Preprocessor warning->error conversion from -Werror is silent) PR preprocessor/34695 gcc: * Makefile.in (c-opts.o): Depend on c-tree.h. * c-common.c: Move down include of diagnostic.h. (done_lexing, c_cpp_error): New. * c-common.h (done_lexing): Declare. * c-decl.c (c_write_global_declarations): Don't check cpp_errors (parse_in). * c-opts.c: Include c-tree.h. (c_common_init_options): Set preprocessor error callback. (c_common_handle_option): Do not set preprocessor inhibit_warnings, warnings_are_errors, warn_system_headers, pedantic_errors or inhibit_warnings flags. (c_common_post_options): Do not check cpp_errors (parse_in). (c_common_finish): Do not output dependencies if there were errors. Do not check return value of cpp_finish. * c-ppoutput.c (pp_file_change): Set input_location. * c-tree.h (c_cpp_error): Declare. * diagnostic.c (diagnostic_set_info_translated): Also initialize override_column. (diagnostic_build_prefix): Check override_column. * diagnostic.h (diagnostic_info): Add override_column field. (diagnostic_override_column): Define. gcc/cp: * cp-tree.h (cp_cpp_error): Remove. * error.c (cp_cpp_error): Remove. * parser.c (cp_lexer_new_main): Set done_lexing instead of client_diagnostic and error callback. gcc/fortran: * cpp.c (cb_cpp_error): New. (gfc_cpp_post_options): Don't set cpp_option->inhibit_warnings. Don't check cpp_errors (cpp_in). (gfc_cpp_init_0): Set cb->error. gcc/testsuite: * gcc.dg/builtin-redefine.c, gcc.dg/cpp/redef2.c, gcc.dg/cpp/redef3.c, gcc.dg/cpp/trad/redef2.c: Use dg-message instead of dg-warning for "previous definition" messages. * gcc.dg/cpp/Wvariadic-1.c, gcc.dg/cpp/Wvariadic-3.c: Expect "warnings being treated as errors" message. * gcc.dg/fltconst-1.c: Use -fshow-column. libcpp: * makedepend.c: Remove. * Makefile.in (makedepend_OBJS, makedepend$(EXEEXT)): Remove. (all, clean, TAGS_SOURCES, include): Remove makedepend handling. * directives.c (cpp_errors): Remove. * errors.c (print_location, _cpp_begin_message, v_message): Remove. (cpp_error, cpp_error_with_line): Always use error callback. (cpp_error, cpp_error_with_line, cpp_errno): Return bool. * include/cpplib.h (cpp_options): Remove pedantic_errors, inhibit_warnings, warn_system_headers, inhibit_errors, warnings_are_errors, client_diagnostic. (cpp_callbacks): Add extra arguments to error callback; make it return bool. (cpp_finish): Return void. (cpp_destroy): Remove inaccurate comment about return value. (cpp_errors, CPP_DL_EXTRACT, CPP_DL_WARNING_P): Remove. (CPP_DL_NOTE): Define. * include/line-map.h (linemap_print_containing_files): Remove. * init.c (cpp_finish): Do not check for or return number of errors. * internal.h (cpp_reader): Remove errors field. * line-map.c (linemap_print_containing_files): Remove. * macro.c (_cpp_create_definition): Use CPP_DL_NOTE for message about previous definition. Only emit it if previous diagnostic was emitted. From-SVN: r145263
2009-03-30 00:56:07 +02:00
input_location = map->start_location;
if (print.first_time)
{
/* Avoid printing foo.i when the main file is foo.c. */
if (!cpp_get_options (parse_in)->preprocessed)
Represent column numbers using line-map's source_location. The "next available source_location" is now managed internally by line-maps.c rather than by clients. * line-map.h (struct line_map): New field column_bits. <from_line>: Rename field to start_location. (struct line_maps): New fields highest_location and max_column_hint. (linemap_check_files_exited): New declaration. (linemap_line_start): New declaration. (linemap_add): Remove from_line parameter; use highest_location field. (SOURCE_LINE, LAST_SOURCE_LINE): Modify to use column_bits. (SOURCE_COLUMN, LAST_SOURCE_LINE_LOCATION): New macros. (CURRENT_LINE_MAP): Remove macro. (linemap_position_for_column): New inline function. * line-map.c (linemap_init): Clear new fields. (linemap_check_files_exited): New function, extracted from ... (linemap_free): Use linemap_check_files_exited. (linemap_add): Remove from_line parameter. Various updates. (linemap_line_start): New function. (linemap_lookeup): Update for new field names. * cpphash.h (struct cpp_reader) <map>: Field removed. Because linemap_position_for_column may unpredictably change the current map, it is cleaner and simpler for us to not cache it in cpp_reader. (struct cpp_buffer): New sysp field. Changed warned_cplusplus_comments and from_stage3 to bitfields. * cppinit.c (cpp_read_min_file): pfile->map no longer exists. * cpplib.c (do_line, do_linemarker, _cpp_do_file_change): Get current map using linemap_lookup. (do_linemarker): Also set buffer's sysp field. (destringize_and_run): No longer need to decrement current line. * cppfiles.c (_cpp_stack_file): Set sysp from and in buffer. (search_path_head, open_file_failed): Use buffer's sysp. (cpp_make_system_header): Get current map using linemap_lookup. Also set buffer's sysp flag. * cppmacro.c (_cpp_builtin_macro_text): Likewise use linemap_lookup. * cpphash.h (CPP_INCREMENT_LINE): New macro. (struct cpp_buffer): Moved fields saved_cur, saved_rlimit to ... (struct cpp_reader): ... and adding saved_line_base field. * cpptrad.c (_cpp_overlay_buffer, _cpp_remove_overlay): Update accordingly. Don't adjust line. (_cpp_scan_out_logical_line): Use CPP_INCREMENT_LINE. * cpphash.c (CPP_IN_SYSTEM_HEADER): Replaced macro by ... (cpp_in_system_header): ... new inline function, using buffer's sysp. * cpperror.c (_cpp_begin_message): Update to use cpp_in_system_header. * cpplex.c (_cpp_lex_direct): Likewise. * cppmacro.c (_cpp_builtin_macro_text): Likewise. * cppmacro.c (_cpp_create_definition): Use buffer's sysp field. * cpplib.h (struct cpp_token): Rename line field to src_loc. Remove col field as it is now subsumed by src_loc. * cpperror.c: Update various field, parameter, and macro names. (print_location): If col==0, try SOURCE_COLUMN of line. (cpp_error): Use cur_token's src_loc field, rather than line+col. * cpplib.c (do_diagnostic): Token's src_loc fields replaces line+col. * cpplex.c (_cpp_process_line_notes, _cpp_lex_direct, _cpp_skip_block_comment): Use CPP_INCREMENT_LINE. (_cpp_temp_token): Replace cpp_token's line+col fields by src_loc. (_cpp_get_fresh_line): Don't need to adjust line for missing newline. (_cpp_lex_direct): Use linemap_position_for_column. * c-ppoutput.c (maybe_print_line, print_line): Don't take map parameter. Instead get it from the line_table global. Adjust callers. (print): Remove map field. Replace line field to src_line. (init_pp_output, account_for_newlines, maybe_print_line): Adjust. (cb_line_change): Use SOURCE_COLUMN. Minor optimizations. (pp_file_change): Use MAIN_FILE_P since we cannot checked print.map. Use LAST_SOURCE_LINE_LOCATION to "catch up" after #include. * cpptrad.c (copy_comment): Rename variable. * c-lex.c (map): Remove static variable, for same reason we removed cpp_reader's map field. (cb_line_change, cb_def_pragma, cb_define, cb_undef): Hence we need to call linemap_lookup. (cb_line_change): Token's line field replaced by src_loc. (fe_file_change): Use MAINFILE_P and LAST_SOURCE_LINE macros. Don't save new_map. * cpphash.h, cpperror.c, cpplib.h: Some renames of fileline to source_location. From-SVN: r77663
2004-02-11 16:29:30 +01:00
print_line (map->start_location, flags);
print.first_time = 0;
}
else
{
/* Bring current file to correct line when entering a new file. */
if (map->reason == LC_ENTER)
Represent column numbers using line-map's source_location. The "next available source_location" is now managed internally by line-maps.c rather than by clients. * line-map.h (struct line_map): New field column_bits. <from_line>: Rename field to start_location. (struct line_maps): New fields highest_location and max_column_hint. (linemap_check_files_exited): New declaration. (linemap_line_start): New declaration. (linemap_add): Remove from_line parameter; use highest_location field. (SOURCE_LINE, LAST_SOURCE_LINE): Modify to use column_bits. (SOURCE_COLUMN, LAST_SOURCE_LINE_LOCATION): New macros. (CURRENT_LINE_MAP): Remove macro. (linemap_position_for_column): New inline function. * line-map.c (linemap_init): Clear new fields. (linemap_check_files_exited): New function, extracted from ... (linemap_free): Use linemap_check_files_exited. (linemap_add): Remove from_line parameter. Various updates. (linemap_line_start): New function. (linemap_lookeup): Update for new field names. * cpphash.h (struct cpp_reader) <map>: Field removed. Because linemap_position_for_column may unpredictably change the current map, it is cleaner and simpler for us to not cache it in cpp_reader. (struct cpp_buffer): New sysp field. Changed warned_cplusplus_comments and from_stage3 to bitfields. * cppinit.c (cpp_read_min_file): pfile->map no longer exists. * cpplib.c (do_line, do_linemarker, _cpp_do_file_change): Get current map using linemap_lookup. (do_linemarker): Also set buffer's sysp field. (destringize_and_run): No longer need to decrement current line. * cppfiles.c (_cpp_stack_file): Set sysp from and in buffer. (search_path_head, open_file_failed): Use buffer's sysp. (cpp_make_system_header): Get current map using linemap_lookup. Also set buffer's sysp flag. * cppmacro.c (_cpp_builtin_macro_text): Likewise use linemap_lookup. * cpphash.h (CPP_INCREMENT_LINE): New macro. (struct cpp_buffer): Moved fields saved_cur, saved_rlimit to ... (struct cpp_reader): ... and adding saved_line_base field. * cpptrad.c (_cpp_overlay_buffer, _cpp_remove_overlay): Update accordingly. Don't adjust line. (_cpp_scan_out_logical_line): Use CPP_INCREMENT_LINE. * cpphash.c (CPP_IN_SYSTEM_HEADER): Replaced macro by ... (cpp_in_system_header): ... new inline function, using buffer's sysp. * cpperror.c (_cpp_begin_message): Update to use cpp_in_system_header. * cpplex.c (_cpp_lex_direct): Likewise. * cppmacro.c (_cpp_builtin_macro_text): Likewise. * cppmacro.c (_cpp_create_definition): Use buffer's sysp field. * cpplib.h (struct cpp_token): Rename line field to src_loc. Remove col field as it is now subsumed by src_loc. * cpperror.c: Update various field, parameter, and macro names. (print_location): If col==0, try SOURCE_COLUMN of line. (cpp_error): Use cur_token's src_loc field, rather than line+col. * cpplib.c (do_diagnostic): Token's src_loc fields replaces line+col. * cpplex.c (_cpp_process_line_notes, _cpp_lex_direct, _cpp_skip_block_comment): Use CPP_INCREMENT_LINE. (_cpp_temp_token): Replace cpp_token's line+col fields by src_loc. (_cpp_get_fresh_line): Don't need to adjust line for missing newline. (_cpp_lex_direct): Use linemap_position_for_column. * c-ppoutput.c (maybe_print_line, print_line): Don't take map parameter. Instead get it from the line_table global. Adjust callers. (print): Remove map field. Replace line field to src_line. (init_pp_output, account_for_newlines, maybe_print_line): Adjust. (cb_line_change): Use SOURCE_COLUMN. Minor optimizations. (pp_file_change): Use MAIN_FILE_P since we cannot checked print.map. Use LAST_SOURCE_LINE_LOCATION to "catch up" after #include. * cpptrad.c (copy_comment): Rename variable. * c-lex.c (map): Remove static variable, for same reason we removed cpp_reader's map field. (cb_line_change, cb_def_pragma, cb_define, cb_undef): Hence we need to call linemap_lookup. (cb_line_change): Token's line field replaced by src_loc. (fe_file_change): Use MAINFILE_P and LAST_SOURCE_LINE macros. Don't save new_map. * cpphash.h, cpperror.c, cpplib.h: Some renames of fileline to source_location. From-SVN: r77663
2004-02-11 16:29:30 +01:00
{
Replace line_map union with C++ class hierarchy gcc/ChangeLog: * diagnostic.c (diagnostic_report_current_module): Strengthen local "new_map" from const line_map * to const line_map_ordinary *. * genmatch.c (error_cb): Likewise for local "map". (output_line_directive): Likewise for local "map". * input.c (expand_location_1): Likewise for local "map". Pass NULL rather than &map to linemap_unwind_to_first_non_reserved_loc, since the value is never read from there, and the value written back not read from here. (is_location_from_builtin_token): Strengthen local "map" from const line_map * to const line_map_ordinary *. (dump_location_info): Strengthen locals "map" from line_map *, one to const line_map_ordinary *, the other to const line_map_macro *. * tree-diagnostic.c (loc_map_pair): Strengthen field "map" from const line_map * to const line_map_macro *. (maybe_unwind_expanded_macro_loc): Add a call to linemap_check_macro when writing to the "map" field of the loc_map_pair. Introduce local const line_map_ordinary * "ord_map", using it in place of "map" in the part of the function where we know we have an ordinary map. Strengthen local "m" from const line_map * to const line_map_ordinary *. gcc/ada/ChangeLog: * gcc-interface/trans.c (Sloc_to_locus1): Strenghthen local "map" from line_map * to line_map_ordinary *. gcc/c-family/ChangeLog: * c-common.h (fe_file_change): Strengthen param from const line_map * to const line_map_ordinary *. (pp_file_change): Likewise. * c-lex.c (fe_file_change): Likewise. (cb_define): Use linemap_check_ordinary when invoking SOURCE_LINE. (cb_undef): Likewise. * c-opts.c (c_finish_options): Use linemap_check_ordinary when invoking cb_file_change. (c_finish_options): Likewise. (push_command_line_include): Likewise. (cb_file_change): Strengthen param "new_map" from const line_map * to const line_map_ordinary *. * c-ppoutput.c (cb_define): Likewise for local "map". (pp_file_change): Likewise for param "map" and local "from". gcc/fortran/ChangeLog: * cpp.c (maybe_print_line): Strengthen local "map" from const line_map * to const line_map_ordinary *. (cb_file_change): Likewise for param "map" and local "from". (cb_line_change): Likewise for local "map". libcpp/ChangeLog: * directives.c (do_line): Strengthen local "map" from const line_map * to const line_map_ordinary *. (do_linemarker): Likewise. (_cpp_do_file_change): Assert that we're not dealing with a macro map. Introduce local "ord_map" via a call to linemap_check_ordinary, guarded within the check for non-NULL. Use it for typesafety. * files.c (cpp_make_system_header): Strengthen local "map" from const line_map * to const line_map_ordinary *. * include/cpplib.h (struct cpp_callbacks): Likewise for second parameter of "file_change" callback. * include/line-map.h (struct line_map): Convert from a struct containing a union to a base class. (struct line_map_ordinary): Convert to a subclass of line_map. (struct line_map_macro): Likewise. (linemap_check_ordinary): Strengthen return type from line_map * to line_map_ordinary *, and add a const-variant. (linemap_check_macro): New pair of functions. (ORDINARY_MAP_STARTING_LINE_NUMBER): Strengthen param from const line_map * to const line_map_ordinary *, eliminating call to linemap_check_ordinary. Likewise for the non-const variant. (ORDINARY_MAP_INCLUDER_FILE_INDEX): Likewise. (ORDINARY_MAP_IN_SYSTEM_HEADER_P): Likewise. (ORDINARY_MAP_NUMBER_OF_COLUMN_BITS): Likewise. (ORDINARY_MAP_FILE_NAME): Likewise. (MACRO_MAP_MACRO): Strengthen param from const line_map * to const line_map_macro *. Likewise for the non-const variant. (MACRO_MAP_NUM_MACRO_TOKENS): Likewise. (MACRO_MAP_LOCATIONS): Likewise. (MACRO_MAP_EXPANSION_POINT_LOCATION): Likewise. (struct maps_info): Replace with... (struct maps_info_ordinary):...this and... (struct maps_info_macro): ...this. (struct line_maps): Convert fields "info_ordinary" and "info_macro" to the above new structs. (LINEMAPS_MAP_INFO): Delete both functions. (LINEMAPS_MAPS): Likewise. (LINEMAPS_ALLOCATED): Rewrite both variants to avoid using LINEMAPS_MAP_INFO. (LINEMAPS_USED): Likewise. (LINEMAPS_CACHE): Likewise. (LINEMAPS_MAP_AT): Likewise. (LINEMAPS_ORDINARY_MAPS): Strengthen return type from line_map * to line_map_ordinary *. (LINEMAPS_ORDINARY_MAP_AT): Likewise. (LINEMAPS_LAST_ORDINARY_MAP): Likewise. (LINEMAPS_LAST_ALLOCATED_ORDINARY_MAP): Likewise. (LINEMAPS_MACRO_MAPS): Strengthen return type from line_map * to line_map_macro *. (LINEMAPS_MACRO_MAP_AT): Likewise. (LINEMAPS_LAST_MACRO_MAP): Likewise. (LINEMAPS_LAST_ALLOCATED_MACRO_MAP): Likewise. (linemap_map_get_macro_name): Strengthen param from const line_map * to const line_map_macro *. (SOURCE_LINE): Strengthen first param from const line_map * to const line_map_ordinary *, removing call to linemap_check_ordinary. (SOURCE_COLUMN): Likewise. (LAST_SOURCE_LINE_LOCATION): Likewise. (LAST_SOURCE_LINE): Strengthen first param from const line_map * to const line_map_ordinary *. (LAST_SOURCE_COLUMN): Likewise. (INCLUDED_FROM): Strengthen return type from line_map * to line_map_ordinary *., and second param from const line_map * to const line_map_ordinary *, removing call to linemap_check_ordinary. (MAIN_FILE_P): Strengthen param from const line_map * to const line_map_ordinary *, removing call to linemap_check_ordinary. (linemap_position_for_line_and_column): Strengthen param from const line_map * to const line_map_ordinary *. (LINEMAP_FILE): Strengthen param from const line_map * to const line_map_ordinary *, removing call to linemap_check_ordinary. (LINEMAP_LINE): Likewise. (LINEMAP_SYSP): Likewise. (linemap_resolve_location): Strengthen final param from const line_map ** to const line_map_ordinary **. * internal.h (CPP_INCREMENT_LINE): Likewise for local "map". (linemap_enter_macro): Strengthen return type from const line_map * to const line_map_macro *. (linemap_add_macro_token): Likewise for first param. * line-map.c (linemap_check_files_exited): Strengthen local "map" from const line_map * to const line_map_ordinary *. (new_linemap): Introduce local "map_size" and use it when calculating how large the buffer should be. Rewrite based on change of info_macro and info_ordinary into distinct types. (linemap_add): Strengthen locals "map" and "from" from line_map * to line_map_ordinary *. (linemap_enter_macro): Strengthen return type from const line_map * to const line_map_macro *, and local "map" from line_map * to line_map_macro *. (linemap_add_macro_token): Strengthen param "map" from const line_map * to const line_map_macro *. (linemap_line_start): Strengthen local "map" from line_map * to line_map_ordinary *. (linemap_position_for_column): Likewise. (linemap_position_for_line_and_column): Strengthen first param from const line_map * to const line_map_ordinary *. (linemap_position_for_loc_and_offset): Strengthen local "map" from const line_map * to const line_map_ordinary *. (linemap_ordinary_map_lookup): Likewise for return type and locals "cached" and "result". (linemap_macro_map_lookup): Strengthen return type and locals "cached" and "result" from const line_map * to const line_map_macro *. (linemap_macro_map_loc_to_exp_point): Likewise for param "map". (linemap_macro_map_loc_to_def_point): Likewise. (linemap_macro_map_loc_unwind_toward_spelling): Likewise. (linemap_get_expansion_line): Strengthen local "map" from const line_map * to const line_map_ordinary *. (linemap_get_expansion_filename): Likewise. (linemap_map_get_macro_name): Strengthen param from const line_map * to const line_map_macro *. (linemap_location_in_system_header_p): Add call to linemap_check_ordinary in region guarded by !linemap_macro_expansion_map_p. Introduce local "macro_map" via linemap_check_macro in other region, using it in place of "map" for typesafety. (first_map_in_common_1): Add calls to linemap_check_macro. (trace_include): Strengthen param "map" from const line_map * to const line_map_ordinary *. (linemap_macro_loc_to_spelling_point): Strengthen final param from const line_map ** to const line_map_ordinary **. Replace a C-style cast with a const_cast, and add calls to linemap_check_macro and linemap_check_ordinary. (linemap_macro_loc_to_def_point): Likewise. (linemap_macro_loc_to_exp_point): Likewise. (linemap_resolve_location): Strengthen final param from const line_map ** to const line_map_ordinary **. (linemap_unwind_toward_expansion): Introduce local "macro_map" via a checked cast and use it in place of *map. (linemap_unwind_to_first_non_reserved_loc): Strengthen local "map1" from const line_map * to const line_map_ordinary *. (linemap_expand_location): Introduce local "ord_map" via a checked cast and use it in place of map. (linemap_dump): Make local "map" const. Strengthen local "includer_map" from line_map * to const line_map_ordinary *. Introduce locals "ord_map" and "macro_map" via checked casts and use them in place of "map" for typesafety. (linemap_dump_location): Strengthen local "map" from const line_map * to const line_map_ordinary *. (linemap_get_file_highest_location): Update for elimination of union. (linemap_get_statistics): Strengthen local "cur_map" from line_map * to const line_map_macro *. Update uses of sizeof to use the appropriate line_map subclasses. * macro.c (_cpp_warn_if_unused_macro): Add call to linemap_check_ordinary. (builtin_macro): Strengthen local "map" from const line_map * to const line_map_macro *. (enter_macro_context): Likewise. (replace_args): Likewise. (tokens_buff_put_token_to): Likewise for param "map". (tokens_buff_add_token): Likewise. From-SVN: r223365
2015-05-19 15:18:01 +02:00
const line_map_ordinary *from = INCLUDED_FROM (line_table, map);
Represent column numbers using line-map's source_location. The "next available source_location" is now managed internally by line-maps.c rather than by clients. * line-map.h (struct line_map): New field column_bits. <from_line>: Rename field to start_location. (struct line_maps): New fields highest_location and max_column_hint. (linemap_check_files_exited): New declaration. (linemap_line_start): New declaration. (linemap_add): Remove from_line parameter; use highest_location field. (SOURCE_LINE, LAST_SOURCE_LINE): Modify to use column_bits. (SOURCE_COLUMN, LAST_SOURCE_LINE_LOCATION): New macros. (CURRENT_LINE_MAP): Remove macro. (linemap_position_for_column): New inline function. * line-map.c (linemap_init): Clear new fields. (linemap_check_files_exited): New function, extracted from ... (linemap_free): Use linemap_check_files_exited. (linemap_add): Remove from_line parameter. Various updates. (linemap_line_start): New function. (linemap_lookeup): Update for new field names. * cpphash.h (struct cpp_reader) <map>: Field removed. Because linemap_position_for_column may unpredictably change the current map, it is cleaner and simpler for us to not cache it in cpp_reader. (struct cpp_buffer): New sysp field. Changed warned_cplusplus_comments and from_stage3 to bitfields. * cppinit.c (cpp_read_min_file): pfile->map no longer exists. * cpplib.c (do_line, do_linemarker, _cpp_do_file_change): Get current map using linemap_lookup. (do_linemarker): Also set buffer's sysp field. (destringize_and_run): No longer need to decrement current line. * cppfiles.c (_cpp_stack_file): Set sysp from and in buffer. (search_path_head, open_file_failed): Use buffer's sysp. (cpp_make_system_header): Get current map using linemap_lookup. Also set buffer's sysp flag. * cppmacro.c (_cpp_builtin_macro_text): Likewise use linemap_lookup. * cpphash.h (CPP_INCREMENT_LINE): New macro. (struct cpp_buffer): Moved fields saved_cur, saved_rlimit to ... (struct cpp_reader): ... and adding saved_line_base field. * cpptrad.c (_cpp_overlay_buffer, _cpp_remove_overlay): Update accordingly. Don't adjust line. (_cpp_scan_out_logical_line): Use CPP_INCREMENT_LINE. * cpphash.c (CPP_IN_SYSTEM_HEADER): Replaced macro by ... (cpp_in_system_header): ... new inline function, using buffer's sysp. * cpperror.c (_cpp_begin_message): Update to use cpp_in_system_header. * cpplex.c (_cpp_lex_direct): Likewise. * cppmacro.c (_cpp_builtin_macro_text): Likewise. * cppmacro.c (_cpp_create_definition): Use buffer's sysp field. * cpplib.h (struct cpp_token): Rename line field to src_loc. Remove col field as it is now subsumed by src_loc. * cpperror.c: Update various field, parameter, and macro names. (print_location): If col==0, try SOURCE_COLUMN of line. (cpp_error): Use cur_token's src_loc field, rather than line+col. * cpplib.c (do_diagnostic): Token's src_loc fields replaces line+col. * cpplex.c (_cpp_process_line_notes, _cpp_lex_direct, _cpp_skip_block_comment): Use CPP_INCREMENT_LINE. (_cpp_temp_token): Replace cpp_token's line+col fields by src_loc. (_cpp_get_fresh_line): Don't need to adjust line for missing newline. (_cpp_lex_direct): Use linemap_position_for_column. * c-ppoutput.c (maybe_print_line, print_line): Don't take map parameter. Instead get it from the line_table global. Adjust callers. (print): Remove map field. Replace line field to src_line. (init_pp_output, account_for_newlines, maybe_print_line): Adjust. (cb_line_change): Use SOURCE_COLUMN. Minor optimizations. (pp_file_change): Use MAIN_FILE_P since we cannot checked print.map. Use LAST_SOURCE_LINE_LOCATION to "catch up" after #include. * cpptrad.c (copy_comment): Rename variable. * c-lex.c (map): Remove static variable, for same reason we removed cpp_reader's map field. (cb_line_change, cb_def_pragma, cb_define, cb_undef): Hence we need to call linemap_lookup. (cb_line_change): Token's line field replaced by src_loc. (fe_file_change): Use MAINFILE_P and LAST_SOURCE_LINE macros. Don't save new_map. * cpphash.h, cpperror.c, cpplib.h: Some renames of fileline to source_location. From-SVN: r77663
2004-02-11 16:29:30 +01:00
maybe_print_line (LAST_SOURCE_LINE_LOCATION (from));
}
if (map->reason == LC_ENTER)
flags = " 1";
else if (map->reason == LC_LEAVE)
flags = " 2";
Represent column numbers using line-map's source_location. The "next available source_location" is now managed internally by line-maps.c rather than by clients. * line-map.h (struct line_map): New field column_bits. <from_line>: Rename field to start_location. (struct line_maps): New fields highest_location and max_column_hint. (linemap_check_files_exited): New declaration. (linemap_line_start): New declaration. (linemap_add): Remove from_line parameter; use highest_location field. (SOURCE_LINE, LAST_SOURCE_LINE): Modify to use column_bits. (SOURCE_COLUMN, LAST_SOURCE_LINE_LOCATION): New macros. (CURRENT_LINE_MAP): Remove macro. (linemap_position_for_column): New inline function. * line-map.c (linemap_init): Clear new fields. (linemap_check_files_exited): New function, extracted from ... (linemap_free): Use linemap_check_files_exited. (linemap_add): Remove from_line parameter. Various updates. (linemap_line_start): New function. (linemap_lookeup): Update for new field names. * cpphash.h (struct cpp_reader) <map>: Field removed. Because linemap_position_for_column may unpredictably change the current map, it is cleaner and simpler for us to not cache it in cpp_reader. (struct cpp_buffer): New sysp field. Changed warned_cplusplus_comments and from_stage3 to bitfields. * cppinit.c (cpp_read_min_file): pfile->map no longer exists. * cpplib.c (do_line, do_linemarker, _cpp_do_file_change): Get current map using linemap_lookup. (do_linemarker): Also set buffer's sysp field. (destringize_and_run): No longer need to decrement current line. * cppfiles.c (_cpp_stack_file): Set sysp from and in buffer. (search_path_head, open_file_failed): Use buffer's sysp. (cpp_make_system_header): Get current map using linemap_lookup. Also set buffer's sysp flag. * cppmacro.c (_cpp_builtin_macro_text): Likewise use linemap_lookup. * cpphash.h (CPP_INCREMENT_LINE): New macro. (struct cpp_buffer): Moved fields saved_cur, saved_rlimit to ... (struct cpp_reader): ... and adding saved_line_base field. * cpptrad.c (_cpp_overlay_buffer, _cpp_remove_overlay): Update accordingly. Don't adjust line. (_cpp_scan_out_logical_line): Use CPP_INCREMENT_LINE. * cpphash.c (CPP_IN_SYSTEM_HEADER): Replaced macro by ... (cpp_in_system_header): ... new inline function, using buffer's sysp. * cpperror.c (_cpp_begin_message): Update to use cpp_in_system_header. * cpplex.c (_cpp_lex_direct): Likewise. * cppmacro.c (_cpp_builtin_macro_text): Likewise. * cppmacro.c (_cpp_create_definition): Use buffer's sysp field. * cpplib.h (struct cpp_token): Rename line field to src_loc. Remove col field as it is now subsumed by src_loc. * cpperror.c: Update various field, parameter, and macro names. (print_location): If col==0, try SOURCE_COLUMN of line. (cpp_error): Use cur_token's src_loc field, rather than line+col. * cpplib.c (do_diagnostic): Token's src_loc fields replaces line+col. * cpplex.c (_cpp_process_line_notes, _cpp_lex_direct, _cpp_skip_block_comment): Use CPP_INCREMENT_LINE. (_cpp_temp_token): Replace cpp_token's line+col fields by src_loc. (_cpp_get_fresh_line): Don't need to adjust line for missing newline. (_cpp_lex_direct): Use linemap_position_for_column. * c-ppoutput.c (maybe_print_line, print_line): Don't take map parameter. Instead get it from the line_table global. Adjust callers. (print): Remove map field. Replace line field to src_line. (init_pp_output, account_for_newlines, maybe_print_line): Adjust. (cb_line_change): Use SOURCE_COLUMN. Minor optimizations. (pp_file_change): Use MAIN_FILE_P since we cannot checked print.map. Use LAST_SOURCE_LINE_LOCATION to "catch up" after #include. * cpptrad.c (copy_comment): Rename variable. * c-lex.c (map): Remove static variable, for same reason we removed cpp_reader's map field. (cb_line_change, cb_def_pragma, cb_define, cb_undef): Hence we need to call linemap_lookup. (cb_line_change): Token's line field replaced by src_loc. (fe_file_change): Use MAINFILE_P and LAST_SOURCE_LINE macros. Don't save new_map. * cpphash.h, cpperror.c, cpplib.h: Some renames of fileline to source_location. From-SVN: r77663
2004-02-11 16:29:30 +01:00
print_line (map->start_location, flags);
}
}
}
/* Copy a #pragma directive to the preprocessed output. */
cpperror.c (v_message): Split into _cpp_begin_message and v_message macro. * cpperror.c (v_message): Split into _cpp_begin_message and v_message macro. All callers updated. (_cpp_begin_message): Do inhibit_errors/inhibit_warnings checks here. * cppfiles.c (cpp_syshdr_flags): New function. (read_include_file): Don't call cpp_output_tokens. Call enter_file hook. * cppinit.c (dump_macros_helper): Moved to cppmain.c. (cpp_reader_init): Don't initialize token_buffer. Call _cpp_init_internal_pragmas. (cpp_cleanup): Don't clear token_buffer. (cpp_start_read): Don't worry about output from -D processing. Don't call cpp_output_tokens. (cpp_finish): Don't dump macros here. Don't call cpp_output_tokens. * cppmacro.c (_cpp_dump_definition): Rename cpp_dump_definition. Write directly to a FILE *. (dump_funlike_macro): Delete. (dump_macro_args): New. * cpplex.c (TOKEN_LEN): Convert to inline function. (_cpp_grow_token_buffer, safe_fwrite, cpp_output_tokens, cpp_scan_line, _cpp_dump_list): Delete. (cpp_printf, cpp_output_list): New. (output_line_command): Don't worry about entering or leaving files. (cpp_scan_buffer): Just output each token as we hit it. (process_directive): Don't call cpp_output_tokens. (_cpp_glue_header_name): Don't use token_buffer. (output_token, dump_param_spelling): Write directly to a FILE *. * cpplib.c (pass_thru_directive, dump_macro_name, pragma_dispatch, do_pragma_gcc): Delete. (do_define, do_undef, parse_include, do_line, do_ident, do_pragma, do_pragma_poison, cpp_pop_buffer): Call the appropriate hook functions. (do_error, do_warning, pragma_dependency): Call _cpp_begin_message, then cpp_output_list. (cpp_register_pragma, cpp_register_pragma_space, _cpp_init_internal_pragmas): New. (do_pragma): Walk the pragmas table here. (do_pragma_once, do_pragma_poison, do_pragma_system_header, do_pragma_dependency): Return void. (do_pragma_implementation): Moved to cppmain.c. * cpplib.h: Update prototypes. (struct cpp_reader): Remove printer, token_buffer, token_buffer_size, and limit. Add struct cb, and pragmas. (struct cpp_printer): Remove last_id and written. (CPP_WRITTEN, CPP_PWRITTEN, CPP_SET_WRITTEN, CPP_ADJUST_WRITTEN): Delete. * cpphash.h: Update prototypes. (ufputs): New wrapper. * cppmain.c (cb_define, cb_undef, cb_include, cb_ident, cb_enter_file, cb_leave_file, cb_def_pragma): New functions. (main): Set up callbacks. Register #pragma implementation. Dump macros from here. From-SVN: r35415
2000-08-02 03:13:45 +02:00
static void
cb_def_pragma (cpp_reader *pfile, source_location line)
cpperror.c (v_message): Split into _cpp_begin_message and v_message macro. * cpperror.c (v_message): Split into _cpp_begin_message and v_message macro. All callers updated. (_cpp_begin_message): Do inhibit_errors/inhibit_warnings checks here. * cppfiles.c (cpp_syshdr_flags): New function. (read_include_file): Don't call cpp_output_tokens. Call enter_file hook. * cppinit.c (dump_macros_helper): Moved to cppmain.c. (cpp_reader_init): Don't initialize token_buffer. Call _cpp_init_internal_pragmas. (cpp_cleanup): Don't clear token_buffer. (cpp_start_read): Don't worry about output from -D processing. Don't call cpp_output_tokens. (cpp_finish): Don't dump macros here. Don't call cpp_output_tokens. * cppmacro.c (_cpp_dump_definition): Rename cpp_dump_definition. Write directly to a FILE *. (dump_funlike_macro): Delete. (dump_macro_args): New. * cpplex.c (TOKEN_LEN): Convert to inline function. (_cpp_grow_token_buffer, safe_fwrite, cpp_output_tokens, cpp_scan_line, _cpp_dump_list): Delete. (cpp_printf, cpp_output_list): New. (output_line_command): Don't worry about entering or leaving files. (cpp_scan_buffer): Just output each token as we hit it. (process_directive): Don't call cpp_output_tokens. (_cpp_glue_header_name): Don't use token_buffer. (output_token, dump_param_spelling): Write directly to a FILE *. * cpplib.c (pass_thru_directive, dump_macro_name, pragma_dispatch, do_pragma_gcc): Delete. (do_define, do_undef, parse_include, do_line, do_ident, do_pragma, do_pragma_poison, cpp_pop_buffer): Call the appropriate hook functions. (do_error, do_warning, pragma_dependency): Call _cpp_begin_message, then cpp_output_list. (cpp_register_pragma, cpp_register_pragma_space, _cpp_init_internal_pragmas): New. (do_pragma): Walk the pragmas table here. (do_pragma_once, do_pragma_poison, do_pragma_system_header, do_pragma_dependency): Return void. (do_pragma_implementation): Moved to cppmain.c. * cpplib.h: Update prototypes. (struct cpp_reader): Remove printer, token_buffer, token_buffer_size, and limit. Add struct cb, and pragmas. (struct cpp_printer): Remove last_id and written. (CPP_WRITTEN, CPP_PWRITTEN, CPP_SET_WRITTEN, CPP_ADJUST_WRITTEN): Delete. * cpphash.h: Update prototypes. (ufputs): New wrapper. * cppmain.c (cb_define, cb_undef, cb_include, cb_ident, cb_enter_file, cb_leave_file, cb_def_pragma): New functions. (main): Set up callbacks. Register #pragma implementation. Dump macros from here. From-SVN: r35415
2000-08-02 03:13:45 +02:00
{
Represent column numbers using line-map's source_location. The "next available source_location" is now managed internally by line-maps.c rather than by clients. * line-map.h (struct line_map): New field column_bits. <from_line>: Rename field to start_location. (struct line_maps): New fields highest_location and max_column_hint. (linemap_check_files_exited): New declaration. (linemap_line_start): New declaration. (linemap_add): Remove from_line parameter; use highest_location field. (SOURCE_LINE, LAST_SOURCE_LINE): Modify to use column_bits. (SOURCE_COLUMN, LAST_SOURCE_LINE_LOCATION): New macros. (CURRENT_LINE_MAP): Remove macro. (linemap_position_for_column): New inline function. * line-map.c (linemap_init): Clear new fields. (linemap_check_files_exited): New function, extracted from ... (linemap_free): Use linemap_check_files_exited. (linemap_add): Remove from_line parameter. Various updates. (linemap_line_start): New function. (linemap_lookeup): Update for new field names. * cpphash.h (struct cpp_reader) <map>: Field removed. Because linemap_position_for_column may unpredictably change the current map, it is cleaner and simpler for us to not cache it in cpp_reader. (struct cpp_buffer): New sysp field. Changed warned_cplusplus_comments and from_stage3 to bitfields. * cppinit.c (cpp_read_min_file): pfile->map no longer exists. * cpplib.c (do_line, do_linemarker, _cpp_do_file_change): Get current map using linemap_lookup. (do_linemarker): Also set buffer's sysp field. (destringize_and_run): No longer need to decrement current line. * cppfiles.c (_cpp_stack_file): Set sysp from and in buffer. (search_path_head, open_file_failed): Use buffer's sysp. (cpp_make_system_header): Get current map using linemap_lookup. Also set buffer's sysp flag. * cppmacro.c (_cpp_builtin_macro_text): Likewise use linemap_lookup. * cpphash.h (CPP_INCREMENT_LINE): New macro. (struct cpp_buffer): Moved fields saved_cur, saved_rlimit to ... (struct cpp_reader): ... and adding saved_line_base field. * cpptrad.c (_cpp_overlay_buffer, _cpp_remove_overlay): Update accordingly. Don't adjust line. (_cpp_scan_out_logical_line): Use CPP_INCREMENT_LINE. * cpphash.c (CPP_IN_SYSTEM_HEADER): Replaced macro by ... (cpp_in_system_header): ... new inline function, using buffer's sysp. * cpperror.c (_cpp_begin_message): Update to use cpp_in_system_header. * cpplex.c (_cpp_lex_direct): Likewise. * cppmacro.c (_cpp_builtin_macro_text): Likewise. * cppmacro.c (_cpp_create_definition): Use buffer's sysp field. * cpplib.h (struct cpp_token): Rename line field to src_loc. Remove col field as it is now subsumed by src_loc. * cpperror.c: Update various field, parameter, and macro names. (print_location): If col==0, try SOURCE_COLUMN of line. (cpp_error): Use cur_token's src_loc field, rather than line+col. * cpplib.c (do_diagnostic): Token's src_loc fields replaces line+col. * cpplex.c (_cpp_process_line_notes, _cpp_lex_direct, _cpp_skip_block_comment): Use CPP_INCREMENT_LINE. (_cpp_temp_token): Replace cpp_token's line+col fields by src_loc. (_cpp_get_fresh_line): Don't need to adjust line for missing newline. (_cpp_lex_direct): Use linemap_position_for_column. * c-ppoutput.c (maybe_print_line, print_line): Don't take map parameter. Instead get it from the line_table global. Adjust callers. (print): Remove map field. Replace line field to src_line. (init_pp_output, account_for_newlines, maybe_print_line): Adjust. (cb_line_change): Use SOURCE_COLUMN. Minor optimizations. (pp_file_change): Use MAIN_FILE_P since we cannot checked print.map. Use LAST_SOURCE_LINE_LOCATION to "catch up" after #include. * cpptrad.c (copy_comment): Rename variable. * c-lex.c (map): Remove static variable, for same reason we removed cpp_reader's map field. (cb_line_change, cb_def_pragma, cb_define, cb_undef): Hence we need to call linemap_lookup. (cb_line_change): Token's line field replaced by src_loc. (fe_file_change): Use MAINFILE_P and LAST_SOURCE_LINE macros. Don't save new_map. * cpphash.h, cpperror.c, cpplib.h: Some renames of fileline to source_location. From-SVN: r77663
2004-02-11 16:29:30 +01:00
maybe_print_line (line);
fputs ("#pragma ", print.outf);
cpp_output_line (pfile, print.outf);
print.printed = false;
Represent column numbers using line-map's source_location. The "next available source_location" is now managed internally by line-maps.c rather than by clients. * line-map.h (struct line_map): New field column_bits. <from_line>: Rename field to start_location. (struct line_maps): New fields highest_location and max_column_hint. (linemap_check_files_exited): New declaration. (linemap_line_start): New declaration. (linemap_add): Remove from_line parameter; use highest_location field. (SOURCE_LINE, LAST_SOURCE_LINE): Modify to use column_bits. (SOURCE_COLUMN, LAST_SOURCE_LINE_LOCATION): New macros. (CURRENT_LINE_MAP): Remove macro. (linemap_position_for_column): New inline function. * line-map.c (linemap_init): Clear new fields. (linemap_check_files_exited): New function, extracted from ... (linemap_free): Use linemap_check_files_exited. (linemap_add): Remove from_line parameter. Various updates. (linemap_line_start): New function. (linemap_lookeup): Update for new field names. * cpphash.h (struct cpp_reader) <map>: Field removed. Because linemap_position_for_column may unpredictably change the current map, it is cleaner and simpler for us to not cache it in cpp_reader. (struct cpp_buffer): New sysp field. Changed warned_cplusplus_comments and from_stage3 to bitfields. * cppinit.c (cpp_read_min_file): pfile->map no longer exists. * cpplib.c (do_line, do_linemarker, _cpp_do_file_change): Get current map using linemap_lookup. (do_linemarker): Also set buffer's sysp field. (destringize_and_run): No longer need to decrement current line. * cppfiles.c (_cpp_stack_file): Set sysp from and in buffer. (search_path_head, open_file_failed): Use buffer's sysp. (cpp_make_system_header): Get current map using linemap_lookup. Also set buffer's sysp flag. * cppmacro.c (_cpp_builtin_macro_text): Likewise use linemap_lookup. * cpphash.h (CPP_INCREMENT_LINE): New macro. (struct cpp_buffer): Moved fields saved_cur, saved_rlimit to ... (struct cpp_reader): ... and adding saved_line_base field. * cpptrad.c (_cpp_overlay_buffer, _cpp_remove_overlay): Update accordingly. Don't adjust line. (_cpp_scan_out_logical_line): Use CPP_INCREMENT_LINE. * cpphash.c (CPP_IN_SYSTEM_HEADER): Replaced macro by ... (cpp_in_system_header): ... new inline function, using buffer's sysp. * cpperror.c (_cpp_begin_message): Update to use cpp_in_system_header. * cpplex.c (_cpp_lex_direct): Likewise. * cppmacro.c (_cpp_builtin_macro_text): Likewise. * cppmacro.c (_cpp_create_definition): Use buffer's sysp field. * cpplib.h (struct cpp_token): Rename line field to src_loc. Remove col field as it is now subsumed by src_loc. * cpperror.c: Update various field, parameter, and macro names. (print_location): If col==0, try SOURCE_COLUMN of line. (cpp_error): Use cur_token's src_loc field, rather than line+col. * cpplib.c (do_diagnostic): Token's src_loc fields replaces line+col. * cpplex.c (_cpp_process_line_notes, _cpp_lex_direct, _cpp_skip_block_comment): Use CPP_INCREMENT_LINE. (_cpp_temp_token): Replace cpp_token's line+col fields by src_loc. (_cpp_get_fresh_line): Don't need to adjust line for missing newline. (_cpp_lex_direct): Use linemap_position_for_column. * c-ppoutput.c (maybe_print_line, print_line): Don't take map parameter. Instead get it from the line_table global. Adjust callers. (print): Remove map field. Replace line field to src_line. (init_pp_output, account_for_newlines, maybe_print_line): Adjust. (cb_line_change): Use SOURCE_COLUMN. Minor optimizations. (pp_file_change): Use MAIN_FILE_P since we cannot checked print.map. Use LAST_SOURCE_LINE_LOCATION to "catch up" after #include. * cpptrad.c (copy_comment): Rename variable. * c-lex.c (map): Remove static variable, for same reason we removed cpp_reader's map field. (cb_line_change, cb_def_pragma, cb_define, cb_undef): Hence we need to call linemap_lookup. (cb_line_change): Token's line field replaced by src_loc. (fe_file_change): Use MAINFILE_P and LAST_SOURCE_LINE macros. Don't save new_map. * cpphash.h, cpperror.c, cpplib.h: Some renames of fileline to source_location. From-SVN: r77663
2004-02-11 16:29:30 +01:00
print.src_line++;
cpperror.c (v_message): Split into _cpp_begin_message and v_message macro. * cpperror.c (v_message): Split into _cpp_begin_message and v_message macro. All callers updated. (_cpp_begin_message): Do inhibit_errors/inhibit_warnings checks here. * cppfiles.c (cpp_syshdr_flags): New function. (read_include_file): Don't call cpp_output_tokens. Call enter_file hook. * cppinit.c (dump_macros_helper): Moved to cppmain.c. (cpp_reader_init): Don't initialize token_buffer. Call _cpp_init_internal_pragmas. (cpp_cleanup): Don't clear token_buffer. (cpp_start_read): Don't worry about output from -D processing. Don't call cpp_output_tokens. (cpp_finish): Don't dump macros here. Don't call cpp_output_tokens. * cppmacro.c (_cpp_dump_definition): Rename cpp_dump_definition. Write directly to a FILE *. (dump_funlike_macro): Delete. (dump_macro_args): New. * cpplex.c (TOKEN_LEN): Convert to inline function. (_cpp_grow_token_buffer, safe_fwrite, cpp_output_tokens, cpp_scan_line, _cpp_dump_list): Delete. (cpp_printf, cpp_output_list): New. (output_line_command): Don't worry about entering or leaving files. (cpp_scan_buffer): Just output each token as we hit it. (process_directive): Don't call cpp_output_tokens. (_cpp_glue_header_name): Don't use token_buffer. (output_token, dump_param_spelling): Write directly to a FILE *. * cpplib.c (pass_thru_directive, dump_macro_name, pragma_dispatch, do_pragma_gcc): Delete. (do_define, do_undef, parse_include, do_line, do_ident, do_pragma, do_pragma_poison, cpp_pop_buffer): Call the appropriate hook functions. (do_error, do_warning, pragma_dependency): Call _cpp_begin_message, then cpp_output_list. (cpp_register_pragma, cpp_register_pragma_space, _cpp_init_internal_pragmas): New. (do_pragma): Walk the pragmas table here. (do_pragma_once, do_pragma_poison, do_pragma_system_header, do_pragma_dependency): Return void. (do_pragma_implementation): Moved to cppmain.c. * cpplib.h: Update prototypes. (struct cpp_reader): Remove printer, token_buffer, token_buffer_size, and limit. Add struct cb, and pragmas. (struct cpp_printer): Remove last_id and written. (CPP_WRITTEN, CPP_PWRITTEN, CPP_SET_WRITTEN, CPP_ADJUST_WRITTEN): Delete. * cpphash.h: Update prototypes. (ufputs): New wrapper. * cppmain.c (cb_define, cb_undef, cb_include, cb_ident, cb_enter_file, cb_leave_file, cb_def_pragma): New functions. (main): Set up callbacks. Register #pragma implementation. Dump macros from here. From-SVN: r35415
2000-08-02 03:13:45 +02:00
}
/* Dump out the hash table. */
static int
dump_macro (cpp_reader *pfile, cpp_hashnode *node, void *v ATTRIBUTE_UNUSED)
cpperror.c (v_message): Split into _cpp_begin_message and v_message macro. * cpperror.c (v_message): Split into _cpp_begin_message and v_message macro. All callers updated. (_cpp_begin_message): Do inhibit_errors/inhibit_warnings checks here. * cppfiles.c (cpp_syshdr_flags): New function. (read_include_file): Don't call cpp_output_tokens. Call enter_file hook. * cppinit.c (dump_macros_helper): Moved to cppmain.c. (cpp_reader_init): Don't initialize token_buffer. Call _cpp_init_internal_pragmas. (cpp_cleanup): Don't clear token_buffer. (cpp_start_read): Don't worry about output from -D processing. Don't call cpp_output_tokens. (cpp_finish): Don't dump macros here. Don't call cpp_output_tokens. * cppmacro.c (_cpp_dump_definition): Rename cpp_dump_definition. Write directly to a FILE *. (dump_funlike_macro): Delete. (dump_macro_args): New. * cpplex.c (TOKEN_LEN): Convert to inline function. (_cpp_grow_token_buffer, safe_fwrite, cpp_output_tokens, cpp_scan_line, _cpp_dump_list): Delete. (cpp_printf, cpp_output_list): New. (output_line_command): Don't worry about entering or leaving files. (cpp_scan_buffer): Just output each token as we hit it. (process_directive): Don't call cpp_output_tokens. (_cpp_glue_header_name): Don't use token_buffer. (output_token, dump_param_spelling): Write directly to a FILE *. * cpplib.c (pass_thru_directive, dump_macro_name, pragma_dispatch, do_pragma_gcc): Delete. (do_define, do_undef, parse_include, do_line, do_ident, do_pragma, do_pragma_poison, cpp_pop_buffer): Call the appropriate hook functions. (do_error, do_warning, pragma_dependency): Call _cpp_begin_message, then cpp_output_list. (cpp_register_pragma, cpp_register_pragma_space, _cpp_init_internal_pragmas): New. (do_pragma): Walk the pragmas table here. (do_pragma_once, do_pragma_poison, do_pragma_system_header, do_pragma_dependency): Return void. (do_pragma_implementation): Moved to cppmain.c. * cpplib.h: Update prototypes. (struct cpp_reader): Remove printer, token_buffer, token_buffer_size, and limit. Add struct cb, and pragmas. (struct cpp_printer): Remove last_id and written. (CPP_WRITTEN, CPP_PWRITTEN, CPP_SET_WRITTEN, CPP_ADJUST_WRITTEN): Delete. * cpphash.h: Update prototypes. (ufputs): New wrapper. * cppmain.c (cb_define, cb_undef, cb_include, cb_ident, cb_enter_file, cb_leave_file, cb_def_pragma): New functions. (main): Set up callbacks. Register #pragma implementation. Dump macros from here. From-SVN: r35415
2000-08-02 03:13:45 +02:00
{
New macro expander. 2000-10-28 Neil Booth <neilb@earthling.net> New macro expander. * cpplib.c (struct answer): New. (struct if_stack): Use cpp_lexer_pos rather than line and col. Rename cmacro mi_cmacro. (struct directive, KANDR, STDC89, EXTENSION, COND, IF_COND, INCL, IN_I): New directive and flags. (skip_rest_of_line, check_eol, run_directive, glue_header_name, parse_answer, parse_assertion, find_answer): New functions. (parse_ifdef, detect_if_not_defined, validate_else): Remove. (lex_macro_node): New function to replace parse_ifdef and get_define_node. (_cpp_handle_directive): New function, combines _cpp_check_directive and _cpp_check_linemarker. (do_define, do_undef, parse_include, do_include, do_import, do_include_next, read_line_number, do_line, do_ident, do_pragma, do_pragma_once, do_pragma_poison, do_pragma_dependency): Update for new token getting interface. (do_ifdef, do_ifndef, do_if, do_else, do_endif, push_conditional) : Update for new multiple-include optimisation technique. (do_elif): Don't forget to invalidate controlling macros. (unwind_if_stack, cpp_defined, cpp_push_buffer, cpp_pop_buffer): Update. (parse_assertion, parse_answer, find_answer, _cpp_test_assertion): Functions to handle assertions with the new token interface. (do_assert, do_unassert): Use them. (cpp_define, _cpp_define_builtin, cpp_undef, cpp_assert, cpp_unassert): Use run_directive. (_cpp_init_stacks): Register directive names. Don't register special nodes. * cpperror.c (print_containing_files, _cpp_begin_message): Update to new position recording regime. (cpp_ice, cpp_fatal, cpp_error, cpp_error_with_line, cpp_warning, cpp_warning_with_line, cpp_pedwarn, cpp_pedwarn_with_line, cpp_pedwarn_with_file_and_line): Update for _cpp_begin_message changes. (cpp_type2name): Move to cpplex.c. * cppexp.c (parse_charconst): spec_nodes is no longer a pointer. (parse_defined): Update to handle new multiple include optimisation method. Remove poisoned identifier warning. (parse_assertion, TYPE_NAME): Delete. (lex): Update for multiple include optimisation, removal of CPP_DEFINED, to use _cpp_test_assertion for assertions and cpp_token_as_text. (_cpp_parse_expr): Update for MI optimisation, and to use op_as_text. (op_as_text): New function, to wrap cpp_token_as_text. * cppfiles.c (stack_include_file, _cpp_pop_file_buffer): Update for MI optimisation. (_cpp_execute_include): Take a token rather than 3 arguments. Fix segfault on diagnostic. (_cpp_compare_file_date): Take a token rather than 3 args. (cpp_read_file): Work correctly for zero-length files. * cpphash.c (_cpp_init_macros, _cpp_cleanup_macros): Rename _cpp_init_hashtable and _cpp_cleanup_hashtable. (cpp_lookup): Place identifiers at front of identifier pool for _cpp_lookup_with_hash. (_cpp_lookup_with_hash): Require identifiers to be at the front of the identifier pool. Commit the memory if not already in the hash table. * cppinit.c (cpp_reader_init): Move cpp_init_completed test to top. Initialise various members of cpp_reader, memory pools, and the special nodes. (cpp_printer_init): Delete. (cpp_cleanup): Update. (struct builtin, builtin_array, initialize_builtins): Update for new hashnode definition and builtin handling. (cpp_start_read, cpp_finish): Don't take or initialise a printer. Update. * cpplib.h (cpp_printer, cpp_toklist, CPP_DEFINED, BOL, PASTED, VAR_ARGS, BEG_OF_FILE, IN_DIRECTIVE, KNOWN_DIRECTIVE, T_VOID, T_SPECLINE, T_DATE, T_FILE, T_BASE_FILE, T_INCLUDE_LEVEL, T_TIME, T_STDC, T_OPERATOR, T_POISON, T_MACRO, T_ASSERTION): Delete. (struct cpp_pool, struct cpp_macro, struct cpp_lexer_pos, struct cpp_lookahead, CPP_DHASH, enum mi_state, enum mi_ind, NO_EXPAND, VARARGS_FIRST, struct cpp_token_with_pos, struct toklist, struct cpp_context, struct specnodes, TOKEN_LOOKAHEAD, TOKEN_BUFFSIZE, NODE_OPERATOR, NODE_POISONED, NODE_BUILTIN, NODE_DIAGNOSTIC, NT_VOID, NT_MACRO, NT_ASSERTION, enum builtin_type, cpp_can_paste): New. (struct cpp_token): Delete line and col members. (struct cpp_buffer): New member output_lineno. (struct lexer_state): Delete indented, in_lex_line, seen_dot. Add va_args_ok, poisoned_ok, prevent_expansion, parsing_args. (struct cpp_reader): New members lexer_pos, macro_pos, directive_pos, ident_pool, temp_string_pool, macro_pool, argument_pool, string_pool, base_context, context, directive, mi_state, mi_if_not_defined, mi_lexed, mi_cmacro, mi_ind_cmacro, la_read, la_write, la_unused, mlstring_pos, macro_buffer, macro_buffer_len. Delete members mls_line, mls_column, token_list, potential_control_macro, temp_tokens, temp_cap, temp_alloced, temp_used, first_directive_token, context_cap, cur_context, no_expand_level, paste_level, contexts, args, save_parameter_spellings, need_newline, . Change type of date, time and spec_nodes members. Change prototypes for include and ident callbacks. (struct cpp_hashnode): Change type of name. Remove union members expansion and code. Add members macro, operator and builtin. (cpp_token_len, cpp_token_as_text, cpp_spell_token, cpp_start_read, cpp_finish, cpp_avoid_paste, cpp_get_token, cpp_get_line, cpp_get_output_line, cpp_macro_definition, cpp_start_lookahead, cpp_stop_lookahead): New prototypes. (cpp_printer_init, cpp_dump_definition): Delete prototypes. (U_CHAR, U, ustrcmp, ustrncmp, ustrlen, uxstrdup, ustrchr, ufputs): Move from cpphash.h. * cpphash.h (U_CHAR, U, ustrcmp, ustrncmp, ustrlen, uxstrdup, ustrchr, ufputs): Move to cpplib.h. (enum spell_type, struct token_spelling, _cpp_token_spellings, TOKEN_SPELL, TOKEN_NAME, struct answer, FREE_ANSWER, KANDR, STDC89, EXTENSION, COND, EXPAND, INCL, COMMENTS, IN_I, struct directive, directive_handler, struct spec_nodes, _cpp_digraph_spellings, _cpp_free_temp_tokens, _cpp_init_input_buffer, _cpp_grow_token_buffer, _cpp_init_toklist, _cpp_clear_toklist, _cpp_expand_token_space, _cpp_expand_name_space, _cpp_equiv_tokens, _cpp_equiv_toklists, _cpp_process_directive, _cpp_run_directive, _cpp_get_line, _cpp_get_raw_token, _cpp_glue_header_name, _cpp_can_paste, _cpp_check_directive, _cpp_check_linemarker, _cpp_parse_assertion, _cpp_find_answer): Delete. (VALID_SIGN, ALIGN, POOL_FRONT, POOL_LIMIT, POOL_BASE, POOL_SIZE, POOL_USED, POOL_COMMIT, struct cpp_chunk, _cpp_lex_token, _cpp_init_pool, _cpp_free_pool, _cpp_pool_reserve, _cpp_pool_alloc, _cpp_next_chunk, _cpp_lock_pool, _cpp_unlock_pool, _cpp_test_assertion, _cpp_handle_directive, DSC): New. (struct include_file): New member defined. (DO_NOT_REREAD, _cpp_begin_message, _cpp_execute_include, _cpp_compare_file_date): Update. (_cpp_pop_context, _cpp_get_token, _cpp_free_lookaheads, _cpp_push_token): New. (_cpp_init_macros, _cpp_cleanup_macros): Rename to _cpp_init_hashtable, _cpp_cleanup_hashtable. * Makefile.in: Remove cppoutput.c. * cppoutput.c: Delete * fixheader.c (read_scan_file): Update for new cpp_get_token prototype. (recognized_function): New argument LINE. * scan-decls.c (skip_to_closing_brace, scan_decls): Update for new cpp_get_token prototype. * scan.h (recognized_function): Update prototype. * po/POTFILES.in: Remove cppoutput.c. From-SVN: r37098
2000-10-28 19:59:06 +02:00
if (node->type == NT_MACRO && !(node->flags & NODE_BUILTIN))
cpperror.c (v_message): Split into _cpp_begin_message and v_message macro. * cpperror.c (v_message): Split into _cpp_begin_message and v_message macro. All callers updated. (_cpp_begin_message): Do inhibit_errors/inhibit_warnings checks here. * cppfiles.c (cpp_syshdr_flags): New function. (read_include_file): Don't call cpp_output_tokens. Call enter_file hook. * cppinit.c (dump_macros_helper): Moved to cppmain.c. (cpp_reader_init): Don't initialize token_buffer. Call _cpp_init_internal_pragmas. (cpp_cleanup): Don't clear token_buffer. (cpp_start_read): Don't worry about output from -D processing. Don't call cpp_output_tokens. (cpp_finish): Don't dump macros here. Don't call cpp_output_tokens. * cppmacro.c (_cpp_dump_definition): Rename cpp_dump_definition. Write directly to a FILE *. (dump_funlike_macro): Delete. (dump_macro_args): New. * cpplex.c (TOKEN_LEN): Convert to inline function. (_cpp_grow_token_buffer, safe_fwrite, cpp_output_tokens, cpp_scan_line, _cpp_dump_list): Delete. (cpp_printf, cpp_output_list): New. (output_line_command): Don't worry about entering or leaving files. (cpp_scan_buffer): Just output each token as we hit it. (process_directive): Don't call cpp_output_tokens. (_cpp_glue_header_name): Don't use token_buffer. (output_token, dump_param_spelling): Write directly to a FILE *. * cpplib.c (pass_thru_directive, dump_macro_name, pragma_dispatch, do_pragma_gcc): Delete. (do_define, do_undef, parse_include, do_line, do_ident, do_pragma, do_pragma_poison, cpp_pop_buffer): Call the appropriate hook functions. (do_error, do_warning, pragma_dependency): Call _cpp_begin_message, then cpp_output_list. (cpp_register_pragma, cpp_register_pragma_space, _cpp_init_internal_pragmas): New. (do_pragma): Walk the pragmas table here. (do_pragma_once, do_pragma_poison, do_pragma_system_header, do_pragma_dependency): Return void. (do_pragma_implementation): Moved to cppmain.c. * cpplib.h: Update prototypes. (struct cpp_reader): Remove printer, token_buffer, token_buffer_size, and limit. Add struct cb, and pragmas. (struct cpp_printer): Remove last_id and written. (CPP_WRITTEN, CPP_PWRITTEN, CPP_SET_WRITTEN, CPP_ADJUST_WRITTEN): Delete. * cpphash.h: Update prototypes. (ufputs): New wrapper. * cppmain.c (cb_define, cb_undef, cb_include, cb_ident, cb_enter_file, cb_leave_file, cb_def_pragma): New functions. (main): Set up callbacks. Register #pragma implementation. Dump macros from here. From-SVN: r35415
2000-08-02 03:13:45 +02:00
{
fputs ("#define ", print.outf);
fputs ((const char *) cpp_macro_definition (pfile, node),
print.outf);
putc ('\n', print.outf);
print.printed = false;
Represent column numbers using line-map's source_location. The "next available source_location" is now managed internally by line-maps.c rather than by clients. * line-map.h (struct line_map): New field column_bits. <from_line>: Rename field to start_location. (struct line_maps): New fields highest_location and max_column_hint. (linemap_check_files_exited): New declaration. (linemap_line_start): New declaration. (linemap_add): Remove from_line parameter; use highest_location field. (SOURCE_LINE, LAST_SOURCE_LINE): Modify to use column_bits. (SOURCE_COLUMN, LAST_SOURCE_LINE_LOCATION): New macros. (CURRENT_LINE_MAP): Remove macro. (linemap_position_for_column): New inline function. * line-map.c (linemap_init): Clear new fields. (linemap_check_files_exited): New function, extracted from ... (linemap_free): Use linemap_check_files_exited. (linemap_add): Remove from_line parameter. Various updates. (linemap_line_start): New function. (linemap_lookeup): Update for new field names. * cpphash.h (struct cpp_reader) <map>: Field removed. Because linemap_position_for_column may unpredictably change the current map, it is cleaner and simpler for us to not cache it in cpp_reader. (struct cpp_buffer): New sysp field. Changed warned_cplusplus_comments and from_stage3 to bitfields. * cppinit.c (cpp_read_min_file): pfile->map no longer exists. * cpplib.c (do_line, do_linemarker, _cpp_do_file_change): Get current map using linemap_lookup. (do_linemarker): Also set buffer's sysp field. (destringize_and_run): No longer need to decrement current line. * cppfiles.c (_cpp_stack_file): Set sysp from and in buffer. (search_path_head, open_file_failed): Use buffer's sysp. (cpp_make_system_header): Get current map using linemap_lookup. Also set buffer's sysp flag. * cppmacro.c (_cpp_builtin_macro_text): Likewise use linemap_lookup. * cpphash.h (CPP_INCREMENT_LINE): New macro. (struct cpp_buffer): Moved fields saved_cur, saved_rlimit to ... (struct cpp_reader): ... and adding saved_line_base field. * cpptrad.c (_cpp_overlay_buffer, _cpp_remove_overlay): Update accordingly. Don't adjust line. (_cpp_scan_out_logical_line): Use CPP_INCREMENT_LINE. * cpphash.c (CPP_IN_SYSTEM_HEADER): Replaced macro by ... (cpp_in_system_header): ... new inline function, using buffer's sysp. * cpperror.c (_cpp_begin_message): Update to use cpp_in_system_header. * cpplex.c (_cpp_lex_direct): Likewise. * cppmacro.c (_cpp_builtin_macro_text): Likewise. * cppmacro.c (_cpp_create_definition): Use buffer's sysp field. * cpplib.h (struct cpp_token): Rename line field to src_loc. Remove col field as it is now subsumed by src_loc. * cpperror.c: Update various field, parameter, and macro names. (print_location): If col==0, try SOURCE_COLUMN of line. (cpp_error): Use cur_token's src_loc field, rather than line+col. * cpplib.c (do_diagnostic): Token's src_loc fields replaces line+col. * cpplex.c (_cpp_process_line_notes, _cpp_lex_direct, _cpp_skip_block_comment): Use CPP_INCREMENT_LINE. (_cpp_temp_token): Replace cpp_token's line+col fields by src_loc. (_cpp_get_fresh_line): Don't need to adjust line for missing newline. (_cpp_lex_direct): Use linemap_position_for_column. * c-ppoutput.c (maybe_print_line, print_line): Don't take map parameter. Instead get it from the line_table global. Adjust callers. (print): Remove map field. Replace line field to src_line. (init_pp_output, account_for_newlines, maybe_print_line): Adjust. (cb_line_change): Use SOURCE_COLUMN. Minor optimizations. (pp_file_change): Use MAIN_FILE_P since we cannot checked print.map. Use LAST_SOURCE_LINE_LOCATION to "catch up" after #include. * cpptrad.c (copy_comment): Rename variable. * c-lex.c (map): Remove static variable, for same reason we removed cpp_reader's map field. (cb_line_change, cb_def_pragma, cb_define, cb_undef): Hence we need to call linemap_lookup. (cb_line_change): Token's line field replaced by src_loc. (fe_file_change): Use MAINFILE_P and LAST_SOURCE_LINE macros. Don't save new_map. * cpphash.h, cpperror.c, cpplib.h: Some renames of fileline to source_location. From-SVN: r77663
2004-02-11 16:29:30 +01:00
print.src_line++;
cpperror.c (v_message): Split into _cpp_begin_message and v_message macro. * cpperror.c (v_message): Split into _cpp_begin_message and v_message macro. All callers updated. (_cpp_begin_message): Do inhibit_errors/inhibit_warnings checks here. * cppfiles.c (cpp_syshdr_flags): New function. (read_include_file): Don't call cpp_output_tokens. Call enter_file hook. * cppinit.c (dump_macros_helper): Moved to cppmain.c. (cpp_reader_init): Don't initialize token_buffer. Call _cpp_init_internal_pragmas. (cpp_cleanup): Don't clear token_buffer. (cpp_start_read): Don't worry about output from -D processing. Don't call cpp_output_tokens. (cpp_finish): Don't dump macros here. Don't call cpp_output_tokens. * cppmacro.c (_cpp_dump_definition): Rename cpp_dump_definition. Write directly to a FILE *. (dump_funlike_macro): Delete. (dump_macro_args): New. * cpplex.c (TOKEN_LEN): Convert to inline function. (_cpp_grow_token_buffer, safe_fwrite, cpp_output_tokens, cpp_scan_line, _cpp_dump_list): Delete. (cpp_printf, cpp_output_list): New. (output_line_command): Don't worry about entering or leaving files. (cpp_scan_buffer): Just output each token as we hit it. (process_directive): Don't call cpp_output_tokens. (_cpp_glue_header_name): Don't use token_buffer. (output_token, dump_param_spelling): Write directly to a FILE *. * cpplib.c (pass_thru_directive, dump_macro_name, pragma_dispatch, do_pragma_gcc): Delete. (do_define, do_undef, parse_include, do_line, do_ident, do_pragma, do_pragma_poison, cpp_pop_buffer): Call the appropriate hook functions. (do_error, do_warning, pragma_dependency): Call _cpp_begin_message, then cpp_output_list. (cpp_register_pragma, cpp_register_pragma_space, _cpp_init_internal_pragmas): New. (do_pragma): Walk the pragmas table here. (do_pragma_once, do_pragma_poison, do_pragma_system_header, do_pragma_dependency): Return void. (do_pragma_implementation): Moved to cppmain.c. * cpplib.h: Update prototypes. (struct cpp_reader): Remove printer, token_buffer, token_buffer_size, and limit. Add struct cb, and pragmas. (struct cpp_printer): Remove last_id and written. (CPP_WRITTEN, CPP_PWRITTEN, CPP_SET_WRITTEN, CPP_ADJUST_WRITTEN): Delete. * cpphash.h: Update prototypes. (ufputs): New wrapper. * cppmain.c (cb_define, cb_undef, cb_include, cb_ident, cb_enter_file, cb_leave_file, cb_def_pragma): New functions. (main): Set up callbacks. Register #pragma implementation. Dump macros from here. From-SVN: r35415
2000-08-02 03:13:45 +02:00
}
return 1;
}
/* Load in the PCH file NAME, open on FD. It was originally searched for
by ORIG_NAME. Also, print out a #include command so that the PCH
file can be loaded when the preprocessed output is compiled. */
static void
cb_read_pch (cpp_reader *pfile, const char *name,
int fd, const char *orig_name ATTRIBUTE_UNUSED)
{
c_common_read_pch (pfile, name, fd, orig_name);
2006-05-19 00:16:23 +02:00
fprintf (print.outf, "#pragma GCC pch_preprocess \"%s\"\n", name);
print.src_line++;
}