From patchwork Mon Mar 16 14:20:38 2015 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Andre Vehreschild X-Patchwork-Id: 450590 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]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by ozlabs.org (Postfix) with ESMTPS id ADD1F14007F for ; Tue, 17 Mar 2015 01:20:53 +1100 (AEDT) Authentication-Results: ozlabs.org; dkim=pass reason="1024-bit key; unprotected key" header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b=cZiP6JLQ; dkim-adsp=none (unprotected policy); dkim-atps=neutral DomainKey-Signature: a=rsa-sha1; c=nofws; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:date :from:to:subject:message-id:mime-version:content-type; q=dns; s= default; b=SPBUGU56FRaG6tr0rTh01rSIP0ZvtQs+HlBaO/m0nTgcylUABHZMF s9tpWR1GTu7B5pbkeXBdmWj4kqciBePNqGjOj0JTpZ7GPfrASfkN/T8wTT8tfnyC PRjntJOcAfx/Qa4vHvWW/rmJZflgHiCo4jTbHCd+vS0XxCmDAjoJjE= DKIM-Signature: v=1; a=rsa-sha1; c=relaxed; d=gcc.gnu.org; h=list-id :list-unsubscribe:list-archive:list-post:list-help:sender:date :from:to:subject:message-id:mime-version:content-type; s= default; bh=Q64BG4MezEau6NVJyaTeimoSDgY=; b=cZiP6JLQm1fQ+6p/hIj3 aMY5EvlxuE1BARXYEu/DYsDiRtZTRK/pfePKVCZeQYz5w6z9WFslXCsyX093NGlI YNtCNX50H7RtmeCBNseSb1D1Qr67C4DMazxFt0tzQLmJFaDhRplop32TDjnVcCBq kTtmHKRgsPv5gIc5LelNFAs= Received: (qmail 71681 invoked by alias); 16 Mar 2015 14:20:45 -0000 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 Received: (qmail 71661 invoked by uid 89); 16 Mar 2015 14:20:44 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-1.7 required=5.0 tests=AWL, BAYES_00, FREEMAIL_FROM, RCVD_IN_DNSWL_NONE, SPF_PASS autolearn=ham version=3.3.2 X-Spam-User: qpsmtpd, 2 recipients X-HELO: mout.gmx.net Received: from mout.gmx.net (HELO mout.gmx.net) (212.227.17.22) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with (AES256-GCM-SHA384 encrypted) ESMTPS; Mon, 16 Mar 2015 14:20:43 +0000 Received: from vepi2 ([88.75.104.20]) by mail.gmx.com (mrgmx102) with ESMTPSA (Nemesis) id 0LkSOt-1Z8VOW2iGB-00cQCD; Mon, 16 Mar 2015 15:20:39 +0100 Date: Mon, 16 Mar 2015 15:20:38 +0100 From: Andre Vehreschild To: GCC-Patches-ML , GCC-Fortran-ML Subject: [Patch, Fortran, 1/2] Proposal on renaming gfc_vtable_*_get() to gfc_class_vtab_*_get() Message-ID: <20150316152038.69867f6c@vepi2> MIME-Version: 1.0 X-UI-Out-Filterresults: notjunk:1; Hi all, I like to propose a rename and split of the function trans-expr.c::gfc_vtable_*_get(). Background: During fixing an issue, I encountered the case, that I had a handle to get the vptr already and now wanted to retrieve the size component using that vtpr handle. There was no function to easily do this. One is only able to get the size member of a class' vtab using the function gfc_vtable_size_get(). I therefore resided to extract from the gfc_vtable_field_get() function, which is called by all gfc_vtable_*_get() functions, the part that is taking care about the vptr's component ref and put it into a new function vptr_field_get(). The old gfc_vtable_field_get () then calls this new vptr_field_get() function. During the split it occurred to me, that the name for gfc_vtable_*_get() is not clearly saying what it is supposed to do. When reading the function name the first time, one may think, that the function gets the named field from a vtable, but looking into the function one learns that not a handle to a vptr is expected, but a handle to a class object. Therefore I propose to rename the gfc_vtable_*_get () function to gfc_class_vtab_*_get (). Side note: Unfortunately we are not allowed to use ' in function names, or the name would have been even better gfc_class'_vtab's_*_get (), e.g., for size gfc_class'_vtab's_size_get (). This is a two parts patch. This first patch does the split and introduces defines to stick with the old gfc_vtable_*_get (). The second part substitutes the new name gfc_class_vtab_*_get () where needed. Bootstraps and regtests fine on x86_64-linux-gnu/F20. Ok for trunk? Regards, Andre diff --git a/gcc/fortran/trans-expr.c b/gcc/fortran/trans-expr.c index f61c79f..062c927 100644 --- a/gcc/fortran/trans-expr.c +++ b/gcc/fortran/trans-expr.c @@ -176,72 +176,85 @@ gfc_class_len_get (tree decl) if (POINTER_TYPE_P (TREE_TYPE (decl))) decl = build_fold_indirect_ref_loc (input_location, decl); len = gfc_advance_chain (TYPE_FIELDS (TREE_TYPE (decl)), - CLASS_LEN_FIELD); + CLASS_LEN_FIELD); return fold_build3_loc (input_location, COMPONENT_REF, TREE_TYPE (len), decl, len, NULL_TREE); } +/* Get the specified FIELD from the VPTR. */ + static tree -gfc_vtable_field_get (tree decl, int field) +vptr_field_get (tree vptr, int fieldno) { - tree size; - tree vptr; - vptr = gfc_class_vptr_get (decl); + tree field; vptr = build_fold_indirect_ref_loc (input_location, vptr); - size = gfc_advance_chain (TYPE_FIELDS (TREE_TYPE (vptr)), - field); - size = fold_build3_loc (input_location, COMPONENT_REF, - TREE_TYPE (size), vptr, size, - NULL_TREE); - /* Always return size as an array index type. */ - if (field == VTABLE_SIZE_FIELD) - size = fold_convert (gfc_array_index_type, size); - gcc_assert (size); - return size; + field = gfc_advance_chain (TYPE_FIELDS (TREE_TYPE (vptr)), + fieldno); + field = fold_build3_loc (input_location, COMPONENT_REF, + TREE_TYPE (field), vptr, field, + NULL_TREE); + gcc_assert (field); + return field; } -tree -gfc_vtable_hash_get (tree decl) -{ - return gfc_vtable_field_get (decl, VTABLE_HASH_FIELD); -} - +/* Get the field from the class' vptr. */ -tree -gfc_vtable_size_get (tree decl) +static tree +class_vtab_field_get (tree decl, int fieldno) { - return gfc_vtable_field_get (decl, VTABLE_SIZE_FIELD); + tree vptr; + vptr = gfc_class_vptr_get (decl); + return vptr_field_get (vptr, fieldno); } -tree -gfc_vtable_extends_get (tree decl) -{ - return gfc_vtable_field_get (decl, VTABLE_EXTENDS_FIELD); +/* Define a macro for creating the class_vtab_* and vptr_* accessors in + unison. */ +#define VTAB_GET_FIELD_GEN(name, field) tree \ +gfc_class_vtab_## name ##_get (tree cl) \ +{ \ + return class_vtab_field_get (cl, field); \ +} \ + \ +tree \ +gfc_vptr_## name ##_get (tree vptr) \ +{ \ + return vptr_field_get (vptr, field); \ } +VTAB_GET_FIELD_GEN (hash, VTABLE_HASH_FIELD) +VTAB_GET_FIELD_GEN (extends, VTABLE_EXTENDS_FIELD) +VTAB_GET_FIELD_GEN (def_init, VTABLE_DEF_INIT_FIELD) +VTAB_GET_FIELD_GEN (copy, VTABLE_COPY_FIELD) +VTAB_GET_FIELD_GEN (final, VTABLE_FINAL_FIELD) -tree -gfc_vtable_def_init_get (tree decl) -{ - return gfc_vtable_field_get (decl, VTABLE_DEF_INIT_FIELD); -} +/* The size field is returned as an array index. Therefore treat it and only + it specially. */ tree -gfc_vtable_copy_get (tree decl) +gfc_class_vtab_size_get (tree cl) { - return gfc_vtable_field_get (decl, VTABLE_COPY_FIELD); + tree size; + size = class_vtab_field_get (cl, VTABLE_SIZE_FIELD); + /* Always return size as an array index type. */ + size = fold_convert (gfc_array_index_type, size); + gcc_assert (size); + return size; } - tree -gfc_vtable_final_get (tree decl) +gfc_vptr_size_get (tree vptr) { - return gfc_vtable_field_get (decl, VTABLE_FINAL_FIELD); + tree size; + size = vptr_field_get (vptr, VTABLE_SIZE_FIELD); + /* Always return size as an array index type. */ + size = fold_convert (gfc_array_index_type, size); + gcc_assert (size); + return size; } diff --git a/gcc/fortran/trans.h b/gcc/fortran/trans.h index 3ba2f88..4b9e8ac 100644 --- a/gcc/fortran/trans.h +++ b/gcc/fortran/trans.h @@ -346,17 +346,32 @@ typedef struct gfc_wrapped_block; /* Class API functions. */ +tree gfc_class_set_static_fields (tree, tree, tree); tree gfc_class_data_get (tree); tree gfc_class_vptr_get (tree); tree gfc_class_len_get (tree); +#define gfc_vtable_hash_get gfc_class_vtab_hash_get +#define gfc_vtable_size_get gfc_class_vtab_size_get +#define gfc_vtable_extends_get gfc_class_vtab_extends_get +#define gfc_vtable_def_init_get gfc_class_vtab_def_init_get +#define gfc_vtable_copy_get gfc_class_vtab_copy_get +#define gfc_vtable_final_get gfc_class_vtab_final_get +/* Get an accessor to the class' vtab's * field, when a class handle is + available. */ +tree gfc_class_vtab_hash_get (tree); +tree gfc_class_vtab_size_get (tree); +tree gfc_class_vtab_extends_get (tree); +tree gfc_class_vtab_def_init_get (tree); +tree gfc_class_vtab_copy_get (tree); +tree gfc_class_vtab_final_get (tree); +/* Get an accessor to the vtab's * field, when a vptr handle is present. */ +tree gfc_vtpr_hash_get (tree); +tree gfc_vptr_size_get (tree); +tree gfc_vptr_extends_get (tree); +tree gfc_vptr_def_init_get (tree); +tree gfc_vptr_copy_get (tree); +tree gfc_vptr_final_get (tree); void gfc_reset_vptr (stmtblock_t *, gfc_expr *); -tree gfc_class_set_static_fields (tree, tree, tree); -tree gfc_vtable_hash_get (tree); -tree gfc_vtable_size_get (tree); -tree gfc_vtable_extends_get (tree); -tree gfc_vtable_def_init_get (tree); -tree gfc_vtable_copy_get (tree); -tree gfc_vtable_final_get (tree); tree gfc_get_vptr_from_expr (tree); tree gfc_get_class_array_ref (tree, tree); tree gfc_copy_class_to_class (tree, tree, tree);