Patchwork [fortran] Make front end walker more complete

login
register
mail settings
Submitter Thomas Koenig
Date Sept. 17, 2010, 7:34 p.m.
Message ID <1284752085.9243.100.camel@linux-fd1f.site>
Download mbox | patch
Permalink /patch/65102/
State New
Headers show

Comments

Thomas Koenig - Sept. 17, 2010, 7:34 p.m.
Hello world,

here's a patch to handle more cases in the front end, pretty
self-explanatory.

Regression-tested.

OK for trunk?

2010-09-17  Thomas Koenig  <tkoenig@gcc.gnu.org>

	* frontend-passes.c (gfc_expr_walker):  Handle
	constructors and references.
Mikael Morin - Sept. 18, 2010, 10:18 p.m.
On Friday 17 September 2010 21:34:45 Thomas Koenig wrote:
> Hello world,
> 
> here's a patch to handle more cases in the front end, pretty
> self-explanatory.
> 
> Regression-tested.
> 
> OK for trunk?
> 
> 2010-09-17  Thomas Koenig  <tkoenig@gcc.gnu.org>
> 
> 	* frontend-passes.c (gfc_expr_walker):  Handle
> 	constructors and references.
There is still EXPR_SUBSTRING that can have a subreference, but it can be a 
follow-up (obvious probably) patch. 
Thus, OK. 

Mikael

Patch

Index: frontend-passes.c
===================================================================
--- frontend-passes.c	(Revision 164345)
+++ frontend-passes.c	(Arbeitskopie)
@@ -24,6 +24,7 @@  along with GCC; see the file COPYING3.  If not see
 #include "arith.h"
 #include "flags.h"
 #include "dependency.h"
+#include "constructor.h"
 
 /* Forward declarations.  */
 
@@ -319,6 +320,9 @@  gfc_expr_walker (gfc_expr **e, walk_expr_fn_t expr
     {
       int walk_subtrees = 1;
       gfc_actual_arglist *a;
+      gfc_ref *r;
+      gfc_constructor *c;
+
       int result = exprfn (e, &walk_subtrees, data);
       if (result)
 	return result;
@@ -339,6 +343,60 @@  gfc_expr_walker (gfc_expr **e, walk_expr_fn_t expr
 	    for (a = (*e)->value.compcall.actual; a; a = a->next)
 	      WALK_SUBEXPR (a->expr);
 	    break;
+
+	  case EXPR_STRUCTURE:
+	  case EXPR_ARRAY:
+	    for (c = gfc_constructor_first ((*e)->value.constructor); c;
+		 c = gfc_constructor_next (c))
+	      {
+		WALK_SUBEXPR (c->expr);
+		if (c->iterator != NULL)
+		  {
+		    WALK_SUBEXPR (c->iterator->var);
+		    WALK_SUBEXPR (c->iterator->start);
+		    WALK_SUBEXPR (c->iterator->end);
+		    WALK_SUBEXPR (c->iterator->step);
+		  }
+	      }
+
+	    if ((*e)->expr_type != EXPR_ARRAY)
+	      break;
+
+	    /* Fall through to the variable case in order to walk the
+	       the reference.  */
+
+	  case EXPR_VARIABLE:
+	    for (r = (*e)->ref; r; r = r->next)
+	      {
+		gfc_array_ref *ar;
+		int i;
+
+		switch (r->type)
+		  {
+		  case REF_ARRAY:
+		    ar = &r->u.ar;
+		    if (ar->type == AR_SECTION || ar->type == AR_ELEMENT)
+		      {
+			for (i=0; i< ar->dimen; i++)
+			  {
+			    WALK_SUBEXPR (ar->start[i]);
+			    WALK_SUBEXPR (ar->end[i]);
+			    WALK_SUBEXPR (ar->stride[i]);
+			  }
+		      }
+
+		    break;
+
+		  case REF_SUBSTRING:
+		    WALK_SUBEXPR (r->u.ss.start);
+		    WALK_SUBEXPR (r->u.ss.end);
+		    break;
+
+		  case REF_COMPONENT:
+		    break;
+		  }
+	      }
+
 	  default:
 	    break;
 	  }