From patchwork Tue Aug 16 20:27:53 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Gab Charette X-Patchwork-Id: 110222 Return-Path: X-Original-To: incoming@patchwork.ozlabs.org Delivered-To: patchwork-incoming@bilbo.ozlabs.org Received: from sourceware.org (server1.sourceware.org [209.132.180.131]) by ozlabs.org (Postfix) with SMTP id 253C6B6F80 for ; Wed, 17 Aug 2011 06:28:20 +1000 (EST) Received: (qmail 21557 invoked by alias); 16 Aug 2011 20:28:18 -0000 Received: (qmail 21539 invoked by uid 22791); 16 Aug 2011 20:28:16 -0000 X-SWARE-Spam-Status: No, hits=-2.4 required=5.0 tests=AWL, BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, RP_MATCHES_RCVD, SPF_HELO_PASS X-Spam-Check-By: sourceware.org Received: from smtp-out.google.com (HELO smtp-out.google.com) (74.125.121.67) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Tue, 16 Aug 2011 20:27:58 +0000 Received: from hpaq3.eem.corp.google.com (hpaq3.eem.corp.google.com [172.25.149.3]) by smtp-out.google.com with ESMTP id p7GKRuXY008462; Tue, 16 Aug 2011 13:27:56 -0700 Received: from gchare.mtv.corp.google.com (gchare.mtv.corp.google.com [172.18.111.122]) by hpaq3.eem.corp.google.com with ESMTP id p7GKRsgr014358; Tue, 16 Aug 2011 13:27:54 -0700 Received: by gchare.mtv.corp.google.com (Postfix, from userid 138564) id 033771C0F8B; Tue, 16 Aug 2011 13:27:53 -0700 (PDT) To: locations@google.com, patch@google.com, from@google.com, "trunk."@google.com (issue4907044), reply@codereview.appspotmail.com, crowl@google.com, dnovillo@google.com, gcc-patches@gcc.gnu.org, token@google.com Subject: [pph] Forwarding force Message-Id: <20110816202754.033771C0F8B@gchare.mtv.corp.google.com> Date: Tue, 16 Aug 2011 13:27:53 -0700 (PDT) From: gchare@google.com (Gabriel Charette) X-System-Of-Record: true X-IsSubscribed: yes Mailing-List: contact gcc-patches-help@gcc.gnu.org; run by ezmlm Precedence: bulk List-Id: List-Unsubscribe: List-Archive: List-Post: List-Help: Sender: gcc-patches-owner@gcc.gnu.org Delivered-To: mailing list gcc-patches@gcc.gnu.org This patch has yet to be committed to trunk, but I need it in pph. This doesn't change anything (except that we now removed the built-in entry in the line_table, so there are now only 2 ignored line table entries). Tested with bootstrap and pph regression testing (full testing done with trunk patch pending review). Gab 2011-08-16 Gabriel Charette gcc/c-family/ChangeLog.pph * c-opts.c (c_finish_options): Force BUILTINS_LOCATION for tokens defined in cpp_init_builtins and c_cpp_builtins. libcpp/ChangeLog.pph * init.c (cpp_create_reader): Inititalize forced_token_location_p. * internal.h (struct cpp_reader): Add field forced_token_location_p. * lex.c (_cpp_lex_direct): Use forced_token_location_p. (cpp_force_token_locations): New. (cpp_stop_forcing_token_locations): New. gcc/cp/ChangeLog.pph * pph-streamer-out.c (pph_write_location): Better asserts. * pph-streamer.h (PPH_NUM_IGNORED_LINE_TABLE_ENTRIES): Set to 2. --- This patch is available for review at http://codereview.appspot.com/4907044 diff --git a/gcc/c-family/c-opts.c b/gcc/c-family/c-opts.c index 8c8627e..3ee5860 100644 --- a/gcc/c-family/c-opts.c +++ b/gcc/c-family/c-opts.c @@ -1419,12 +1419,17 @@ c_finish_options (void) { size_t i; - cb_file_change (parse_in, - linemap_add (line_table, LC_RENAME, 0, - _(""), 0)); + { + /* Make sure all of the builtins about to be declared have + BUILTINS_LOCATION has their source_location. */ + source_location builtins_loc = BUILTINS_LOCATION; + cpp_force_token_locations (parse_in, &builtins_loc); - cpp_init_builtins (parse_in, flag_hosted); - c_cpp_builtins (parse_in); + cpp_init_builtins (parse_in, flag_hosted); + c_cpp_builtins (parse_in); + + cpp_stop_forcing_token_locations (parse_in); + } /* We're about to send user input to cpplib, so make it warn for things that we previously (when we sent it internal definitions) diff --git a/gcc/cp/pph-streamer-out.c b/gcc/cp/pph-streamer-out.c index b7a965c..1c5c5d4 100644 --- a/gcc/cp/pph-streamer-out.c +++ b/gcc/cp/pph-streamer-out.c @@ -94,11 +94,19 @@ pph_write_location (struct output_block *ob, location_t loc) streaming some builtins, we probably want to figure out what those are and simply add them to the cache in the preload. */ struct bitpack_d bp; - location_t highest_builtin_loc = line_table->maps[2].start_location - 1; + location_t first_non_builtin_loc = + line_table->maps[PPH_NUM_IGNORED_LINE_TABLE_ENTRIES].start_location; bp = bitpack_create (ob->main_stream); - if (loc < highest_builtin_loc) - bp_pack_value (&bp, true, 1); + if (loc < first_non_builtin_loc) + { + /* We should never stream out trees with locations between builtins + and user locations (e.g. ). */ + if (loc > BUILTINS_LOCATION) + gcc_unreachable (); + + bp_pack_value (&bp, true, 1); + } else { gcc_assert (loc >= diff --git a/gcc/cp/pph-streamer.h b/gcc/cp/pph-streamer.h index 19578fd..415995b 100644 --- a/gcc/cp/pph-streamer.h +++ b/gcc/cp/pph-streamer.h @@ -72,13 +72,13 @@ enum pph_symtab_marker { exactly 8 bytes in the file. */ static const char pph_id_str[] = "PPH0x42"; -/* When streaming out the line_table we will ignore the first 3 entries. - The first one is the entrance in the header, the second one is for - builtins, the third one is the command line, the fourth one is finally - the LC_RENAME back to the header file, we want to stream out starting at - that one, changing it's reason to LC_ENTER (as we ignored the original - entrance), and then streaming every other entry as is from that point on. */ -#define PPH_NUM_IGNORED_LINE_TABLE_ENTRIES 3 +/* When streaming out the line_table we will ignore the first 2 entries. + The first one is the entrance in the header, the second one is the command + line, the third one is the LC_RENAME back to the header file: we want to + stream out starting at that one, changing it's reason to LC_ENTER (as we + ignored the original entrance), and then streaming every other entry as is + from that point on. */ +#define PPH_NUM_IGNORED_LINE_TABLE_ENTRIES 2 /* Structure of the header of a PPH file. */ typedef struct pph_file_header { diff --git a/libcpp/include/cpplib.h b/libcpp/include/cpplib.h index 97df9bb..06623fe 100644 --- a/libcpp/include/cpplib.h +++ b/libcpp/include/cpplib.h @@ -1043,4 +1043,8 @@ extern void cpp_prepare_state (cpp_reader *, struct save_macro_data **); extern int cpp_read_state (cpp_reader *, const char *, FILE *, struct save_macro_data *); +/* In lex.c */ +extern void cpp_force_token_locations (cpp_reader *, source_location *); +extern void cpp_stop_forcing_token_locations (cpp_reader *); + #endif /* ! LIBCPP_CPPLIB_H */ diff --git a/libcpp/init.c b/libcpp/init.c index f3953d5..987482b 100644 --- a/libcpp/init.c +++ b/libcpp/init.c @@ -221,6 +221,9 @@ cpp_create_reader (enum c_lang lang, hash_table *table, /* Initialize table for push_macro/pop_macro. */ pfile->pushed_macros = 0; + /* Do not force token locations by default. */ + pfile->forced_token_location_p = NULL; + /* The expression parser stack. */ _cpp_expand_op_stack (pfile); diff --git a/libcpp/internal.h b/libcpp/internal.h index 31bb477..a8458aa 100644 --- a/libcpp/internal.h +++ b/libcpp/internal.h @@ -554,6 +554,10 @@ struct cpp_reader /* List of saved macros by push_macro. */ struct def_pragma_macro *pushed_macros; + + /* If non-null, the lexer will use this location for the next token + instead of getting a location from the linemap. */ + source_location *forced_token_location_p; }; /* Character classes. Based on the more primitive macros in safe-ctype.h. diff --git a/libcpp/lex.c b/libcpp/lex.c index 2a06b4f..0e3c27c 100644 --- a/libcpp/lex.c +++ b/libcpp/lex.c @@ -1974,8 +1974,11 @@ _cpp_lex_direct (cpp_reader *pfile) } c = *buffer->cur++; - result->src_loc = linemap_position_for_column (pfile->line_table, - CPP_BUF_COLUMN (buffer, buffer->cur)); + if (pfile->forced_token_location_p) + result->src_loc = *pfile->forced_token_location_p; + else + result->src_loc = linemap_position_for_column (pfile->line_table, + CPP_BUF_COLUMN (buffer, buffer->cur)); switch (c) { @@ -2836,3 +2839,19 @@ cpp_token_val_index (cpp_token *tok) return CPP_TOKEN_FLD_NONE; } } + +/* All tokens lexed in R after calling this function will be forced to have + their source_location the same as the location referenced by P, until + cpp_stop_forcing_token_locations is called for R. */ + +void cpp_force_token_locations (cpp_reader *r, source_location *p) +{ + r->forced_token_location_p = p; +} + +/* Go back to assigning locations naturally for lexed tokens. */ + +void cpp_stop_forcing_token_locations (cpp_reader *r) +{ + r->forced_token_location_p = NULL; +}