From patchwork Tue Apr 12 20:28:45 2011 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Diego Novillo X-Patchwork-Id: 90864 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 6F3BBB6F1B for ; Wed, 13 Apr 2011 06:28:58 +1000 (EST) Received: (qmail 14060 invoked by alias); 12 Apr 2011 20:28:56 -0000 Received: (qmail 14051 invoked by uid 22791); 12 Apr 2011 20:28:55 -0000 X-SWARE-Spam-Status: No, hits=-2.1 required=5.0 tests=AWL, BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, SPF_HELO_PASS, T_RP_MATCHES_RCVD X-Spam-Check-By: sourceware.org Received: from smtp-out.google.com (HELO smtp-out.google.com) (216.239.44.51) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Tue, 12 Apr 2011 20:28:47 +0000 Received: from wpaz21.hot.corp.google.com (wpaz21.hot.corp.google.com [172.24.198.85]) by smtp-out.google.com with ESMTP id p3CKSkLM023460; Tue, 12 Apr 2011 13:28:46 -0700 Received: from topo.tor.corp.google.com (topo.tor.corp.google.com [172.29.41.2]) by wpaz21.hot.corp.google.com with ESMTP id p3CKSjIk004594; Tue, 12 Apr 2011 13:28:45 -0700 Received: by topo.tor.corp.google.com (Postfix, from userid 54752) id 164371DA1BE; Tue, 12 Apr 2011 16:28:45 -0400 (EDT) To: reply@codereview.appspotmail.com, crowl@google.com, tromey@redhat.com, gcc-patches@gcc.gnu.org Subject: [pph/libcpp] Allow include callback to not read the file (issue4388057) Message-Id: <20110412202845.164371DA1BE@topo.tor.corp.google.com> Date: Tue, 12 Apr 2011 16:28:45 -0400 (EDT) From: dnovillo@google.com (Diego Novillo) 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 During pph processing, when we find an included file that we are going to instantiate from an image, we don't want libcpp to stack and read it. I've implemented this by allowing the 'include' callback to return a boolean value. If it returns true, then we call _cpp_stack_include. Otherwise, the file is ignored. Tom, I believe this is the right approach, but I'm not sure. It does what I want, though. Thanks. Diego. libcpp/ChangeLog.pph 2011-04-12 Diego Novillo * directives.c (do_include_common): If the callback pfile->cb.include returns falose do not call _cpp_stack_include. * include/cpplib.h (struct cpp_callbacks): Change return type of field 'include' to bool. gcc/cp/ChangeLog.pph 2011-04-12 Diego Novillo * pph.c (pth_include_handler): Return true. (pph_include_handler): If the header file exists as a PPH image, return false. --- This patch is available for review at http://codereview.appspot.com/4388057 diff --git a/gcc/cp/pph.c b/gcc/cp/pph.c index 74d1d50..6584e72 100644 --- a/gcc/cp/pph.c +++ b/gcc/cp/pph.c @@ -1984,9 +2008,10 @@ pph_read_file (const char *filename) error ("Cannot open PPH file for reading: %s: %m", filename); } + /* Record a #include or #include_next for PTH. */ -static void +static bool pth_include_handler (cpp_reader *reader ATTRIBUTE_UNUSED, location_t loc ATTRIBUTE_UNUSED, const unsigned char *dname, @@ -2012,11 +2037,14 @@ pth_include_handler (cpp_reader *reader ATTRIBUTE_UNUSED, state->new_angle_brackets = angle_brackets; state->new_iname = name; + + return true; } + /* Record a #include or #include_next for PPH. */ -static void +static bool pph_include_handler (cpp_reader *reader, location_t loc ATTRIBUTE_UNUSED, const unsigned char *dname, @@ -2025,6 +2053,7 @@ pph_include_handler (cpp_reader *reader, const cpp_token **tok_p ATTRIBUTE_UNUSED) { const char *pph_file; + bool read_text_file_p; if (flag_pph_debug >= 1) { @@ -2034,9 +2063,15 @@ pph_include_handler (cpp_reader *reader, fprintf (pph_logfile, "%c\n", angle_brackets ? '>' : '"'); } + read_text_file_p = true; pph_file = query_pph_include_map (name); if (pph_file != NULL && !cpp_included_before (reader, name, input_location)) - pph_read_file (pph_file); + { + pph_read_file (pph_file); + read_text_file_p = false; + } + + return read_text_file_p; } diff --git a/libcpp/directives.c b/libcpp/directives.c index 7812b57..09c7686 100644 --- a/libcpp/directives.c +++ b/libcpp/directives.c @@ -788,15 +788,19 @@ do_include_common (cpp_reader *pfile, enum include_type type) cpp_error (pfile, CPP_DL_ERROR, "#include nested too deeply"); else { + bool do_stack_include; + /* Get out of macro context, if we are. */ skip_rest_of_line (pfile); + do_stack_include = true; if (pfile->cb.include) - pfile->cb.include (pfile, pfile->directive_line, - pfile->directive->name, fname, angle_brackets, - buf); + do_stack_include = pfile->cb.include (pfile, pfile->directive_line, + pfile->directive->name, + fname, angle_brackets, buf); - _cpp_stack_include (pfile, NULL, fname, angle_brackets, type); + if (do_stack_include) + _cpp_stack_include (pfile, NULL, fname, angle_brackets, type); } XDELETEVEC (fname); diff --git a/libcpp/include/cpplib.h b/libcpp/include/cpplib.h index 3dc4139..c9f3dfb 100644 --- a/libcpp/include/cpplib.h +++ b/libcpp/include/cpplib.h @@ -480,7 +480,9 @@ struct cpp_callbacks void (*file_change) (cpp_reader *, const struct line_map *); void (*dir_change) (cpp_reader *, const char *); - void (*include) (cpp_reader *, unsigned int, const unsigned char *, + /* Called when processing a #include directive. If the handler + returns false, the file will not be read. */ + bool (*include) (cpp_reader *, unsigned int, const unsigned char *, const char *, int, const cpp_token **); void (*define) (cpp_reader *, unsigned int, cpp_hashnode *); void (*undef) (cpp_reader *, unsigned int, cpp_hashnode *);