From patchwork Fri Jul 14 16:55:23 2017 Content-Type: text/plain; charset="utf-8" MIME-Version: 1.0 Content-Transfer-Encoding: 7bit X-Patchwork-Submitter: Nathan Sidwell X-Patchwork-Id: 788636 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 3x8Jj50SJTz9s76 for ; Sat, 15 Jul 2017 02:55:36 +1000 (AEST) Authentication-Results: ozlabs.org; dkim=pass (1024-bit key; unprotected) header.d=gcc.gnu.org header.i=@gcc.gnu.org header.b="OPnsMr4b"; 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 :subject:to:references:cc:from:message-id:date:mime-version :in-reply-to:content-type; q=dns; s=default; b=lOLklsHjz4bIR84pJ JIHz113muLKRXbREyAKnIyu46eKX8GoFTNkspEFRdr+Zpicluzq2MNc90Uu50pNQ B+0ibAs27YTVeM1ait2ChR9DRDx4xsMOFfcicprA58JuVybWftlp9//KSN4u6BDs Lf66QXAWq318HATAqO5EGKs420= 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 :subject:to:references:cc:from:message-id:date:mime-version :in-reply-to:content-type; s=default; bh=HXu94ksGlVVaFvcX6HaOXS1 I+mQ=; b=OPnsMr4b5Pk31UDRz00rsYTZcGnmEod9/GA/KZk+YIrYsyMsmdLDZxe 1GCdP8KrdaSbRNaXnvzWQMqHALFN6XxvYvjXa9HVBXcYZFHdSywHSwoaG/ep7gGw NEOGa7FN39HliH0hTVLk22cdxPYF6XdySh+96rcOvpBWx9y08l3s= Received: (qmail 84483 invoked by alias); 14 Jul 2017 16:55:28 -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 84456 invoked by uid 89); 14 Jul 2017 16:55:28 -0000 Authentication-Results: sourceware.org; auth=none X-Virus-Found: No X-Spam-SWARE-Status: No, score=-11.9 required=5.0 tests=AWL, BAYES_00, FREEMAIL_FROM, GIT_PATCH_2, GIT_PATCH_3, RCVD_IN_DNSWL_LOW, RCVD_IN_SORBS_SPAM, SPF_PASS autolearn=ham version=3.3.2 spammy=Hx-languages-length:5012 X-HELO: mail-it0-f50.google.com Received: from mail-it0-f50.google.com (HELO mail-it0-f50.google.com) (209.85.214.50) by sourceware.org (qpsmtpd/0.93/v0.84-503-g423c35a) with ESMTP; Fri, 14 Jul 2017 16:55:26 +0000 Received: by mail-it0-f50.google.com with SMTP id 188so9060257itx.0 for ; Fri, 14 Jul 2017 09:55:26 -0700 (PDT) X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:sender:subject:to:references:cc:from:message-id :date:user-agent:mime-version:in-reply-to; bh=8vkzVeS0ABPveRgDREl7EViOS8783xg+G+RmwRmjI3c=; b=E9V+WTAMh06ytmgvq7dMjsYFA+jn/J7mvTghYpSCPLt5c/mykEhcjrcBDV+JK9IANY hIhW78AiLZPRxPYC+Sk3OGTenpeDdYayFvT7N06zndRmhAkzGyGQQt4Zd347Vqsxx0Vu kF45V+e4bUc/5JvZnPHU4RtyfsGYa4V+VMi9cBpRNiTYaGkziG34oOsPM+nKu2t3jCIC 6xTiMFwxDQbt10mnPuqT0qkujkTJi4A8fx1jxbNyYBURRDEFBIHbNsDr/CA15bA1vbpd kZiwO9PFuyFY9LLsLQmIoEaSA7BlR3hZzNmZjBIfjBP71KcJspGH9vijgRycC9il/IxT dFEQ== X-Gm-Message-State: AIVw111RSEvV/hEBYFOqBBER0/Rh8TbVro9xCV9U6gfndTpzqru04FN8 LnRONchStqkykw== X-Received: by 10.36.19.5 with SMTP id 5mr4732648itz.65.1500051325104; Fri, 14 Jul 2017 09:55:25 -0700 (PDT) Received: from [100.64.209.104] (public-120-7.nat.utoronto.ca. [138.51.120.7]) by smtp.googlemail.com with ESMTPSA id v96sm4839534ioi.50.2017.07.14.09.55.24 (version=TLS1_2 cipher=ECDHE-RSA-AES128-GCM-SHA256 bits=128/128); Fri, 14 Jul 2017 09:55:24 -0700 (PDT) Subject: Re: [PATCH] Kill TYPE_METHODS ada-spec 4/9 To: GCC Patches References: <8377f2cd-577c-60b2-63ac-f2619ebe63aa@acm.org> Cc: Jason Merrill , Richard Guenther , Jim Wilson , Jan Hubicka From: Nathan Sidwell Message-ID: Date: Fri, 14 Jul 2017 12:55:23 -0400 User-Agent: Mozilla/5.0 (X11; Linux x86_64; rv:45.0) Gecko/20100101 Thunderbird/45.8.0 MIME-Version: 1.0 In-Reply-To: <8377f2cd-577c-60b2-63ac-f2619ebe63aa@acm.org> This change to the ada-spec generation teaches it about looking at TYPE_FIELDS. quite straight forwards. nathan Index: gcc/c-family/c-ada-spec.c =================================================================== --- gcc/c-family/c-ada-spec.c (revision 250160) +++ gcc/c-family/c-ada-spec.c (working copy) @@ -1070,16 +1070,11 @@ has_static_fields (const_tree type) static bool is_tagged_type (const_tree type) { - tree tmp; - if (!type || !RECORD_OR_UNION_TYPE_P (type)) return false; - /* TYPE_METHODS is only set on the main variant. */ - type = TYPE_MAIN_VARIANT (type); - - for (tmp = TYPE_METHODS (type); tmp; tmp = TREE_CHAIN (tmp)) - if (TREE_CODE (tmp) == FUNCTION_DECL && DECL_VINDEX (tmp)) + for (tree fld = TYPE_FIELDS (type); fld; fld = TREE_CHAIN (fld)) + if (TREE_CODE (fld) == FUNCTION_DECL && DECL_VINDEX (fld)) return true; return false; @@ -1093,8 +1088,6 @@ is_tagged_type (const_tree type) static bool has_nontrivial_methods (tree type) { - tree tmp; - if (!type || !RECORD_OR_UNION_TYPE_P (type)) return false; @@ -1106,12 +1099,9 @@ has_nontrivial_methods (tree type) if (!cpp_check (type, IS_TRIVIAL)) return true; - /* TYPE_METHODS is only set on the main variant. */ - type = TYPE_MAIN_VARIANT (type); - /* If there are user-defined methods, they are deemed non-trivial. */ - for (tmp = TYPE_METHODS (type); tmp; tmp = TREE_CHAIN (tmp)) - if (!DECL_ARTIFICIAL (tmp)) + for (tree fld = TYPE_FIELDS (type); fld; fld = DECL_CHAIN (fld)) + if (TREE_CODE (TREE_TYPE (fld)) == METHOD_TYPE && !DECL_ARTIFICIAL (fld)) return true; return false; @@ -1896,7 +1886,7 @@ dump_ada_template (pretty_printer *buffe if (TREE_VEC_LENGTH (types) == 0) break; - if (!RECORD_OR_UNION_TYPE_P (instance) || !TYPE_METHODS (instance)) + if (!RECORD_OR_UNION_TYPE_P (instance)) break; /* We are interested in concrete template instantiations only: skip @@ -2442,25 +2432,23 @@ dump_generic_ada_node (pretty_printer *b static int print_ada_methods (pretty_printer *buffer, tree node, int spc) { - tree t; - int res; - if (!has_nontrivial_methods (node)) return 0; pp_semicolon (buffer); - res = 1; - for (t = TYPE_METHODS (node); t; t = TREE_CHAIN (t)) - { - if (res) - { - pp_newline (buffer); - pp_newline (buffer); - } - - res = print_ada_declaration (buffer, t, node, spc); - } + int res = 1; + for (tree fld = TYPE_FIELDS (node); fld; fld = DECL_CHAIN (fld)) + if (TREE_CODE (TREE_TYPE (fld)) == METHOD_TYPE) + { + if (res) + { + pp_newline (buffer); + pp_newline (buffer); + } + + res = print_ada_declaration (buffer, fld, node, spc); + } return 1; } @@ -2961,19 +2949,13 @@ print_ada_declaration (pretty_printer *b dump_generic_ada_node (buffer, ret_type, type, spc, false, true); } - if (is_constructor - && RECORD_OR_UNION_TYPE_P (type) - && TYPE_METHODS (type)) - { - tree tmp; - - for (tmp = TYPE_METHODS (type); tmp; tmp = TREE_CHAIN (tmp)) - if (cpp_check (tmp, IS_ABSTRACT)) - { - is_abstract_class = true; - break; - } - } + if (is_constructor && RECORD_OR_UNION_TYPE_P (type)) + for (tree fld = TYPE_FIELDS (type); fld; fld = DECL_CHAIN (fld)) + if (cpp_check (fld, IS_ABSTRACT)) + { + is_abstract_class = true; + break; + } if (is_abstract || is_abstract_class) pp_string (buffer, " is abstract"); @@ -3028,35 +3010,33 @@ print_ada_declaration (pretty_printer *b pp_string (buffer, " is "); - /* Check whether we have an Ada interface compatible class. */ + /* Check whether we have an Ada interface compatible class. + That is only have a vtable non-static data member and no + non-abstract methods. */ if (cpp_check - && RECORD_OR_UNION_TYPE_P (TREE_TYPE (t)) - && TYPE_METHODS (TREE_TYPE (t))) + && RECORD_OR_UNION_TYPE_P (TREE_TYPE (t))) { - int num_fields = 0; - tree tmp; + is_interface = -1; /* Check that there are no fields other than the virtual table. */ - for (tmp = TYPE_FIELDS (TREE_TYPE (t)); tmp; tmp = TREE_CHAIN (tmp)) + for (tree fld = TYPE_FIELDS (TREE_TYPE (t)); + fld; fld = TREE_CHAIN (fld)) { - if (TREE_CODE (tmp) == TYPE_DECL) - continue; - num_fields++; - } - - if (num_fields == 1) - is_interface = 1; - - /* Also check that there are only pure virtual methods. Since the - class is empty, we can skip implicit constructors/destructors. */ - for (tmp = TYPE_METHODS (TREE_TYPE (t)); tmp; tmp = TREE_CHAIN (tmp)) - { - if (DECL_ARTIFICIAL (tmp)) - continue; - if (cpp_check (tmp, IS_ABSTRACT)) - is_abstract_record = 1; - else - is_interface = 0; + if (TREE_CODE (fld) == FIELD_DECL) + { + if (is_interface < 0 && DECL_VIRTUAL_P (fld)) + is_interface = 1; + else + is_interface = 0; + } + else if (TREE_CODE (TREE_TYPE (fld)) == METHOD_TYPE + && !DECL_ARTIFICIAL (fld)) + { + if (cpp_check (fld, IS_ABSTRACT)) + is_abstract_record = 1; + else + is_interface = 0; + } } }