From patchwork Thu Oct 7 18:30:23 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nicola Pero X-Patchwork-Id: 67089 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 0C286B6EEC for ; Fri, 8 Oct 2010 05:30:39 +1100 (EST) Received: (qmail 13478 invoked by alias); 7 Oct 2010 18:30:37 -0000 Received: (qmail 13452 invoked by uid 22791); 7 Oct 2010 18:30:33 -0000 X-SWARE-Spam-Status: No, hits=-1.2 required=5.0 tests=AWL, BAYES_00, TW_CX, T_RP_MATCHES_RCVD X-Spam-Check-By: sourceware.org Received: from fencepost.gnu.org (HELO fencepost.gnu.org) (140.186.70.10) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Thu, 07 Oct 2010 18:30:27 +0000 Received: from eggs.gnu.org ([140.186.70.92]:45041) by fencepost.gnu.org with esmtps (TLS-1.0:RSA_AES_256_CBC_SHA1:32) (Exim 4.69) (envelope-from ) id 1P3vEX-0003N9-Eu for gcc-patches@gnu.org; Thu, 07 Oct 2010 14:30:25 -0400 Received: from Debian-exim by eggs.gnu.org with spam-scanned (Exim 4.71) (envelope-from ) id 1P3vEV-0006WK-SF for gcc-patches@gnu.org; Thu, 07 Oct 2010 14:30:25 -0400 Received: from smtp151.iad.emailsrvr.com ([207.97.245.151]:41804) by eggs.gnu.org with esmtp (Exim 4.71) (envelope-from ) id 1P3vEV-0006WF-Mo for gcc-patches@gnu.org; Thu, 07 Oct 2010 14:30:23 -0400 Received: from relay25.relay.iad.mlsrvr.com (localhost [127.0.0.1]) by relay25.relay.iad.mlsrvr.com (SMTP Server) with ESMTP id 2486C1B4F17 for ; Thu, 7 Oct 2010 14:30:23 -0400 (EDT) Received: from dynamic12.wm-web.iad.mlsrvr.com (dynamic12.wm-web.iad.mlsrvr.com [192.168.2.219]) by relay25.relay.iad.mlsrvr.com (SMTP Server) with ESMTP id 1FD231B4F0C for ; Thu, 7 Oct 2010 14:30:23 -0400 (EDT) Received: from meta-innovation.com (localhost [127.0.0.1]) by dynamic12.wm-web.iad.mlsrvr.com (Postfix) with ESMTP id 0E8A12168085 for ; Thu, 7 Oct 2010 14:30:23 -0400 (EDT) Received: by www2.webmail.us (Authenticated sender: nicola.pero@meta-innovation.com, from: nicola.pero@meta-innovation.com) with HTTP; Thu, 7 Oct 2010 20:30:23 +0200 (CEST) Date: Thu, 7 Oct 2010 20:30:23 +0200 (CEST) Subject: More ObjC++ work on @encode in C++ templates From: "Nicola Pero" To: "gcc-patches@gnu.org" MIME-Version: 1.0 X-Type: plain Message-ID: <1286476223.05799754@192.168.2.228> X-detected-operating-system: by eggs.gnu.org: GNU/Linux 2.4-2.6 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 completes the work to get @encode working in C++ templates. I had to finish it myself as there was nothing more to merge from the apple/trunk branch on the matter. :-) Ok to apply ? Thanks Index: gcc/testsuite/ChangeLog =================================================================== --- gcc/testsuite/ChangeLog (revision 165128) +++ gcc/testsuite/ChangeLog (working copy) @@ -1,3 +1,7 @@ +2010-10-07 Nicola Pero + + * obj-c++.dg/encode-10.mm: New testcase. + 2010-10-07 Janus Weil PR fortran/45933 Index: gcc/testsuite/obj-c++.dg/encode-10.mm =================================================================== --- gcc/testsuite/obj-c++.dg/encode-10.mm (revision 0) +++ gcc/testsuite/obj-c++.dg/encode-10.mm (revision 0) @@ -0,0 +1,46 @@ +/* Test for @encode in templates. */ +/* { dg-options "-lobjc" } */ +/* { dg-do run } */ +#include +#include + +template +const char *my_encode(int variant) +{ + const char *result; + + switch (variant) + { + case 0: + result = @encode(T); + break; + case 1: + result = @encode(T*); + break; + case 2: + result = @encode(const T*); + break; + default: + result = @encode(int); + break; + } + + return result; +} + +int main() +{ + if (strcmp (@encode(char), my_encode(0))) + abort (); + + if (strcmp (@encode(char *), my_encode(1))) + abort (); + + if (strcmp (@encode(const char *), my_encode(2))) + abort (); + + if (strcmp (@encode(int), my_encode(3))) + abort (); + + return 0; +} Index: gcc/cp/error.c =================================================================== --- gcc/cp/error.c (revision 165128) +++ gcc/cp/error.c (working copy) @@ -2141,6 +2141,14 @@ dump_expr (tree t, int flags) pp_cxx_right_paren (cxx_pp); break; + case AT_ENCODE_EXPR: + pp_cxx_ws_string (cxx_pp, "@encode"); + pp_cxx_whitespace (cxx_pp); + pp_cxx_left_paren (cxx_pp); + dump_type (TREE_OPERAND (t, 0), flags); + pp_cxx_right_paren (cxx_pp); + break; + case NOEXCEPT_EXPR: pp_cxx_ws_string (cxx_pp, "noexcept"); pp_cxx_whitespace (cxx_pp); Index: gcc/cp/ChangeLog =================================================================== --- gcc/cp/ChangeLog (revision 165128) +++ gcc/cp/ChangeLog (working copy) @@ -1,3 +1,15 @@ +2010-10-07 Nicola Pero + + * cp-tree.def: Changed type of AT_ENCODE_EXPR from tcc_unary to + tcc_expression. + * cxx-pretty-print.c (pp_cxx_unary_expression): Added case for + AT_ENCODE_EXPR. + * error.c (dump_expr): Added case for AT_ENCODE_EXPR. + * pt.c (tsubst_copy): Added case for AT_ENCODE_EXPR. + (value_dependent_expression_p): Added case for AT_ENCODE_EXPR. + (type_dependent_expression_p): Added case for AT_ENCODE_EXPR. + * parser.c (cp_parser_objc_encode_expression): Updated comment. + 2010-10-07 Nicola Pero Merge from apple/trunk branch on FSF servers. Index: gcc/cp/cxx-pretty-print.c =================================================================== --- gcc/cp/cxx-pretty-print.c (revision 165128) +++ gcc/cp/cxx-pretty-print.c (working copy) @@ -791,6 +791,14 @@ pp_cxx_unary_expression (cxx_pretty_printer *pp, t pp_unary_expression (pp, TREE_OPERAND (t, 0)); break; + case AT_ENCODE_EXPR: + pp_cxx_ws_string (pp, "@encode"); + pp_cxx_whitespace (pp); + pp_cxx_left_paren (pp); + pp_cxx_type_id (pp, TREE_OPERAND (t, 0)); + pp_cxx_right_paren (pp); + break; + case NOEXCEPT_EXPR: pp_cxx_ws_string (pp, "noexcept"); pp_cxx_whitespace (pp); Index: gcc/cp/pt.c =================================================================== --- gcc/cp/pt.c (revision 165128) +++ gcc/cp/pt.c (working copy) @@ -11131,6 +11131,7 @@ tsubst_copy (tree t, tree args, tsubst_flags_t com case ADDR_EXPR: case UNARY_PLUS_EXPR: /* Unary + */ case ALIGNOF_EXPR: + case AT_ENCODE_EXPR: case ARROW_EXPR: case THROW_EXPR: case TYPEID_EXPR: @@ -17689,6 +17690,12 @@ value_dependent_expression_p (tree expression) return dependent_type_p (expression); return type_dependent_expression_p (expression); + case AT_ENCODE_EXPR: + /* An 'encode' expression is value-dependent if the operand is + type-dependent. */ + expression = TREE_OPERAND (expression, 0); + return dependent_type_p (expression); + case NOEXCEPT_EXPR: expression = TREE_OPERAND (expression, 0); /* FIXME why check value-dependency? */ @@ -17806,6 +17813,7 @@ type_dependent_expression_p (tree expression) if (TREE_CODE (expression) == PSEUDO_DTOR_EXPR || TREE_CODE (expression) == SIZEOF_EXPR || TREE_CODE (expression) == ALIGNOF_EXPR + || TREE_CODE (expression) == AT_ENCODE_EXPR || TREE_CODE (expression) == NOEXCEPT_EXPR || TREE_CODE (expression) == TRAIT_EXPR || TREE_CODE (expression) == TYPEID_EXPR Index: gcc/cp/parser.c =================================================================== --- gcc/cp/parser.c (revision 165128) +++ gcc/cp/parser.c (working copy) @@ -21128,6 +21128,12 @@ cp_parser_objc_encode_expression (cp_parser* parse return error_mark_node; } + /* This happens if we find @encode(T) (where T is a template + typename or something dependent on a template typename) when + parsing a template. In that case, we can't compile it + immediately, but we rather create an AT_ENCODE_EXPR which will + need to be instantiated when the template is used. + */ if (dependent_type_p (type)) { tree value = build_min (AT_ENCODE_EXPR, size_type_node, type); Index: gcc/cp/cp-tree.def =================================================================== --- gcc/cp/cp-tree.def (revision 165128) +++ gcc/cp/cp-tree.def (working copy) @@ -337,7 +337,7 @@ DEFTREECODE (ALIGNOF_EXPR, "alignof_expr", tcc_exp /* Represents an Objective-C++ '@encode' expression during template expansion. */ -DEFTREECODE (AT_ENCODE_EXPR, "at_encode_expr", tcc_unary, 1) +DEFTREECODE (AT_ENCODE_EXPR, "at_encode_expr", tcc_expression, 1) /* A STMT_EXPR represents a statement-expression during template expansion. This is the GCC extension { ( ... ) }. The