From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: Received: from mout-p-201.mailbox.org (mout-p-201.mailbox.org [80.241.56.171]) by sourceware.org (Postfix) with ESMTPS id 928CE3861812 for ; Fri, 30 Jul 2021 11:01:18 +0000 (GMT) DMARC-Filter: OpenDMARC Filter v1.4.1 sourceware.org 928CE3861812 Received: from smtp2.mailbox.org (smtp2.mailbox.org [80.241.60.241]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (P-384) server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by mout-p-201.mailbox.org (Postfix) with ESMTPS id 4GbkwY4Rs2zQjhX; Fri, 30 Jul 2021 13:01:17 +0200 (CEST) X-Virus-Scanned: amavisd-new at heinlein-support.de Received: from smtp2.mailbox.org ([80.241.60.241]) by hefe.heinlein-support.de (hefe.heinlein-support.de [91.198.250.172]) (amavisd-new, port 10030) with ESMTP id mZMpEfhFQOxj; Fri, 30 Jul 2021 13:01:14 +0200 (CEST) From: Iain Buclaw To: gcc-patches@gcc.gnu.org Subject: [committed 01/12] d: Factor d_nested_class and d_nested_struct into single function. Date: Fri, 30 Jul 2021 13:01:00 +0200 Message-Id: <20210730110111.569140-1-ibuclaw@gdcproject.org> MIME-Version: 1.0 Content-Transfer-Encoding: 8bit X-Rspamd-Queue-Id: CBE861842 X-Rspamd-UID: 856887 X-Spam-Status: No, score=-15.7 required=5.0 tests=BAYES_00, DKIM_SIGNED, DKIM_VALID, DKIM_VALID_AU, DKIM_VALID_EF, GIT_PATCH_0, RCVD_IN_DNSWL_LOW, SPF_HELO_NONE, SPF_PASS, TXREP autolearn=ham autolearn_force=no version=3.4.4 X-Spam-Checker-Version: SpamAssassin 3.4.4 (2020-01-24) on server2.sourceware.org X-BeenThere: gcc-patches@gcc.gnu.org X-Mailman-Version: 2.1.29 Precedence: list List-Id: Gcc-patches mailing list List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Fri, 30 Jul 2021 11:01:21 -0000 Both do the exact same operation, just on different AST nodes. gcc/d/ChangeLog: * d-codegen.cc (d_nested_class): Rename to ... (get_outer_function): ... this. Handle all aggregate declarations. (d_nested_struct): Remove. (find_this_tree): Use get_outer_function. (get_framedecl): Likewise. --- gcc/d/d-codegen.cc | 54 ++++++++++++---------------------------------- 1 file changed, 14 insertions(+), 40 deletions(-) diff --git a/gcc/d/d-codegen.cc b/gcc/d/d-codegen.cc index f35de90b54c..fe2ad98e60a 100644 --- a/gcc/d/d-codegen.cc +++ b/gcc/d/d-codegen.cc @@ -2354,41 +2354,24 @@ get_frame_for_symbol (Dsymbol *sym) return null_pointer_node; } -/* Return the parent function of a nested class CD. */ +/* Return the parent function of a nested class or struct AD. */ static FuncDeclaration * -d_nested_class (ClassDeclaration *cd) +get_outer_function (AggregateDeclaration *ad) { FuncDeclaration *fd = NULL; - while (cd && cd->isNested ()) + while (ad && ad->isNested ()) { - Dsymbol *dsym = cd->toParent2 (); + Dsymbol *dsym = ad->toParent2 (); if ((fd = dsym->isFuncDeclaration ())) return fd; else - cd = dsym->isClassDeclaration (); + ad = dsym->isAggregateDeclaration (); } - return NULL; -} - -/* Return the parent function of a nested struct SD. */ -static FuncDeclaration * -d_nested_struct (StructDeclaration *sd) -{ - FuncDeclaration *fd = NULL; - while (sd && sd->isNested ()) - { - Dsymbol *dsym = sd->toParent2 (); - if ((fd = dsym->isFuncDeclaration ())) - return fd; - else - sd = dsym->isStructDeclaration (); - } return NULL; } - /* Starting from the current function FD, try to find a suitable value of `this' in nested function instances. A suitable `this' value is an instance of OCD or a class that has OCD as a base. */ @@ -2411,18 +2394,17 @@ find_this_tree (ClassDeclaration *ocd) return convert_expr (get_decl_tree (fd->vthis), cd->type, ocd->type); - fd = d_nested_class (cd); + fd = get_outer_function (cd); + continue; } - else - { - if (fd->isNested ()) - { - fd = fd->toParent2 ()->isFuncDeclaration (); - continue; - } - fd = NULL; + if (fd->isNested ()) + { + fd = fd->toParent2 ()->isFuncDeclaration (); + continue; } + + fd = NULL; } return NULL_TREE; @@ -2760,10 +2742,6 @@ get_framedecl (FuncDeclaration *inner, FuncDeclaration *outer) while (fd && fd != outer) { - AggregateDeclaration *ad; - ClassDeclaration *cd; - StructDeclaration *sd; - /* Parent frame link is the first field. */ if (FRAMEINFO_CREATES_FRAME (get_frameinfo (fd))) result = indirect_ref (ptr_type_node, result); @@ -2773,12 +2751,8 @@ get_framedecl (FuncDeclaration *inner, FuncDeclaration *outer) /* The frame/closure record always points to the outer function's frame, even if there are intervening nested classes or structs. So, we can just skip over these. */ - else if ((ad = fd->isThis ()) && (cd = ad->isClassDeclaration ())) - fd = d_nested_class (cd); - else if ((ad = fd->isThis ()) && (sd = ad->isStructDeclaration ())) - fd = d_nested_struct (sd); else - break; + fd = get_outer_function (fd->isThis ()); } if (fd != outer) -- 2.30.2