From patchwork Sun Jul 4 15:40:49 2010 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Paolo Carlini X-Patchwork-Id: 57848 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 CD707B6EF3 for ; Mon, 5 Jul 2010 01:40:59 +1000 (EST) Received: (qmail 20156 invoked by alias); 4 Jul 2010 15:40:58 -0000 Received: (qmail 20145 invoked by uid 22791); 4 Jul 2010 15:40:57 -0000 X-SWARE-Spam-Status: No, hits=-0.7 required=5.0 tests=AWL, BAYES_40, RCVD_IN_DNSWL_NONE, TW_CX, TW_RG X-Spam-Check-By: sourceware.org Received: from vsmtp21.tin.it (HELO vsmtp21.tin.it) (212.216.176.109) by sourceware.org (qpsmtpd/0.43rc1) with ESMTP; Sun, 04 Jul 2010 15:40:52 +0000 Received: from [192.168.0.4] (79.43.214.71) by vsmtp21.tin.it (8.5.113) id 4BC86A4906848BFD; Sun, 4 Jul 2010 17:40:49 +0200 Message-ID: <4C30AB81.3080308@oracle.com> Date: Sun, 04 Jul 2010 17:40:49 +0200 From: Paolo Carlini User-Agent: Mozilla/5.0 (X11; U; Linux x86_64; en-US; rv:1.9.1.9) Gecko/20100317 SUSE/3.0.4-1.1.1 Thunderbird/3.0.4 MIME-Version: 1.0 To: "gcc-patches@gcc.gnu.org" CC: Jason Merrill Subject: [C++ Patch] Small clean up to tsubst 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 Hi, today while looking into something else I noticed that the code variable could be declared earlier, similarly to tsubst_copy. Patch tested x86_64-linux. Is it ok for mainline? Paolo. ////////////////////// 2010-07-04 Paolo Carlini * pt.c (tsubst): Early declare code = TREE_CODE (t) and use it throughout. Index: pt.c =================================================================== --- pt.c (revision 161801) +++ pt.c (working copy) @@ -9958,6 +9958,7 @@ tsubst_exception_specification (tree fntype, tree tsubst (tree t, tree args, tsubst_flags_t complain, tree in_decl) { + enum tree_code code; tree type, r; if (t == NULL_TREE || t == error_mark_node @@ -9974,7 +9975,9 @@ tsubst (tree t, tree args, tsubst_flags_t complain if (args == NULL_TREE) return t; - if (TREE_CODE (t) == IDENTIFIER_NODE) + code = TREE_CODE (t); + + if (code == IDENTIFIER_NODE) type = IDENTIFIER_TYPE_VALUE (t); else type = TREE_TYPE (t); @@ -10017,16 +10020,16 @@ tsubst (tree t, tree args, tsubst_flags_t complain } if (type - && TREE_CODE (t) != TYPENAME_TYPE - && TREE_CODE (t) != TEMPLATE_TYPE_PARM - && TREE_CODE (t) != IDENTIFIER_NODE - && TREE_CODE (t) != FUNCTION_TYPE - && TREE_CODE (t) != METHOD_TYPE) + && code != TYPENAME_TYPE + && code != TEMPLATE_TYPE_PARM + && code != IDENTIFIER_NODE + && code != FUNCTION_TYPE + && code != METHOD_TYPE) type = tsubst (type, args, complain, in_decl); if (type == error_mark_node) return error_mark_node; - switch (TREE_CODE (t)) + switch (code) { case RECORD_TYPE: case UNION_TYPE: @@ -10156,7 +10159,7 @@ tsubst (tree t, tree args, tsubst_flags_t complain }; */ return t; - if (TREE_CODE (t) == TEMPLATE_TYPE_PARM) + if (code == TEMPLATE_TYPE_PARM) { int quals; gcc_assert (TYPE_P (arg)); @@ -10166,7 +10169,7 @@ tsubst (tree t, tree args, tsubst_flags_t complain return cp_build_qualified_type_real (arg, quals, complain | tf_ignore_bad_quals); } - else if (TREE_CODE (t) == BOUND_TEMPLATE_TEMPLATE_PARM) + else if (code == BOUND_TEMPLATE_TEMPLATE_PARM) { /* We are processing a type constructed from a template template parameter. */ @@ -10205,7 +10208,7 @@ tsubst (tree t, tree args, tsubst_flags_t complain /* If we get here, we must have been looking at a parm for a more deeply nested template. Make a new version of this template parameter, but with a lower level. */ - switch (TREE_CODE (t)) + switch (code) { case TEMPLATE_TYPE_PARM: case TEMPLATE_TEMPLATE_PARM: @@ -10215,7 +10218,7 @@ tsubst (tree t, tree args, tsubst_flags_t complain r = tsubst (TYPE_MAIN_VARIANT (t), args, complain, in_decl); r = cp_build_qualified_type_real (r, cp_type_quals (t), - complain | (TREE_CODE (t) == TEMPLATE_TYPE_PARM + complain | (code == TEMPLATE_TYPE_PARM ? tf_ignore_bad_quals : 0)); } else @@ -10243,7 +10246,7 @@ tsubst (tree t, tree args, tsubst_flags_t complain else TYPE_CANONICAL (r) = canonical_type_parameter (r); - if (TREE_CODE (t) == BOUND_TEMPLATE_TEMPLATE_PARM) + if (code == BOUND_TEMPLATE_TEMPLATE_PARM) { tree argvec = tsubst (TYPE_TI_ARGS (t), args, complain, in_decl); @@ -10314,14 +10317,9 @@ tsubst (tree t, tree args, tsubst_flags_t complain case POINTER_TYPE: case REFERENCE_TYPE: { - enum tree_code code; - if (type == TREE_TYPE (t) && TREE_CODE (type) != METHOD_TYPE) return t; - code = TREE_CODE (t); - - /* [temp.deduct] Type deduction may fail for any of the following @@ -10506,7 +10504,7 @@ tsubst (tree t, tree args, tsubst_flags_t complain return error_mark_node; return fold_build2_loc (input_location, - TREE_CODE (t), TREE_TYPE (t), e1, e2); + code, TREE_TYPE (t), e1, e2); } case NEGATE_EXPR: @@ -10516,7 +10514,7 @@ tsubst (tree t, tree args, tsubst_flags_t complain if (e == error_mark_node) return error_mark_node; - return fold_build1_loc (input_location, TREE_CODE (t), TREE_TYPE (t), e); + return fold_build1_loc (input_location, code, TREE_TYPE (t), e); } case TYPENAME_TYPE: @@ -10672,9 +10670,7 @@ tsubst (tree t, tree args, tsubst_flags_t complain case TYPE_ARGUMENT_PACK: case NONTYPE_ARGUMENT_PACK: { - tree r = TYPE_P (t) - ? cxx_make_type (TREE_CODE (t)) - : make_node (TREE_CODE (t)); + tree r = TYPE_P (t) ? cxx_make_type (code) : make_node (code); tree packed_out = tsubst_template_args (ARGUMENT_PACK_ARGS (t), args, @@ -10684,7 +10680,7 @@ tsubst (tree t, tree args, tsubst_flags_t complain /* For template nontype argument packs, also substitute into the type. */ - if (TREE_CODE (t) == NONTYPE_ARGUMENT_PACK) + if (code == NONTYPE_ARGUMENT_PACK) TREE_TYPE (r) = tsubst (TREE_TYPE (t), args, complain, in_decl); return r; @@ -10692,8 +10688,7 @@ tsubst (tree t, tree args, tsubst_flags_t complain break; default: - sorry ("use of %qs in template", - tree_code_name [(int) TREE_CODE (t)]); + sorry ("use of %qs in template", tree_code_name [(int) code]); return error_mark_node; } }