public inbox for gcc-patches@gcc.gnu.org
 help / color / mirror / Atom feed
* [committed 01/12] d: Factor d_nested_class and d_nested_struct into single function.
@ 2021-07-30 11:01 Iain Buclaw
  2021-07-30 11:01 ` [committed 02/12] d: Drop any field or parameter types that got cached before conversion failed Iain Buclaw
                   ` (10 more replies)
  0 siblings, 11 replies; 15+ messages in thread
From: Iain Buclaw @ 2021-07-30 11:01 UTC (permalink / raw)
  To: gcc-patches

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


^ permalink raw reply	[flat|nested] 15+ messages in thread

end of thread, other threads:[~2021-11-29  0:31 UTC | newest]

Thread overview: 15+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2021-07-30 11:01 [committed 01/12] d: Factor d_nested_class and d_nested_struct into single function Iain Buclaw
2021-07-30 11:01 ` [committed 02/12] d: Drop any field or parameter types that got cached before conversion failed Iain Buclaw
2021-07-30 11:01 ` [committed 03/12] d: Insert null terminator in obstack buffers Iain Buclaw
2021-11-25 14:09   ` Martin Liška
2021-11-26 12:35     ` Iain Buclaw
2021-11-29  0:31       ` Iain Buclaw
2021-07-30 11:01 ` [committed 04/12] d: Use hasMonitor to determine whether to emit a __monitor field in D classes Iain Buclaw
2021-07-30 11:01 ` [committed 05/12] d: Use Identifier::idPool to generate anonymous field name Iain Buclaw
2021-07-30 11:01 ` [committed 06/12] d: Factor aggregate_initializer_decl to set the sinit for aggregate declarations Iain Buclaw
2021-07-30 11:01 ` [committed 07/12] d: Set COMDAT and visibility of thunks only if they are public Iain Buclaw
2021-07-30 11:01 ` [committed 08/12] d: Only handle named enums in enum_initializer_decl Iain Buclaw
2021-07-30 11:01 ` [committed 09/12] d: Clarify comment for generating static array assignment with literal Iain Buclaw
2021-07-30 11:01 ` [committed 10/12] d: Don't generate a PREDICT_EXPR when assert contracts are turned off Iain Buclaw
2021-07-30 11:01 ` [committed 11/12] d: Always layout initializer for the m_RTInfo field in TypeInfo_Class Iain Buclaw
2021-07-30 11:01 ` [committed 12/12] d: Remove dead code from binary_op Iain Buclaw

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for read-only IMAP folder(s) and NNTP newsgroup(s).