This is the mail archive of the gcc-patches@gcc.gnu.org mailing list for the GCC project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

[gfortran] Don't always inherit implicit types from surrounding namespace


This patch adds a second argument to gfc_get_namespace() which controls if
implicit types are inherited from the surrounding namespace.  Without this
patch the attached testcase (which I will add to the testsuite alongside this
patch) will give the following bogus errors:
--------
 In file impl_cont.f90:10

     dimension l(k)
                1
Error: Expression at (1) must be of INTEGER type
 In file impl_cont.f90:10

     dimension l(k)
                1
Error: Expression at (1) must be of INTEGER type
--------
With the patch, the test correctly compiles.  I also verified that the correct
types are set by looking at -fdump-parse-tree output.

Bubblestrapped and regtested.  Seen in g95.  Ok?

- Tobi

2005-02-12  Tobias Schl"uter  <tobias.schlueter@physik.uni-muenchen.de>

	* gfortran.h (gfc_get_namespace): Add second argument to prototype.
	* intrinsic.c (gfc_intrinsic_init_1): Pass second argument to
	gfc_get_namespace.
	* module.c (mio_namespace_ref, load_needed): Likewise.
	* parse.c (parse_interface, parse_contained): Likewise.  Here the
	correct second argument matters.
	* symbol.c (gfc_get_namespace): Add parent_types argument, only copy
	parent's implicit types if this is set.
	(gfc_symbol_init_2): Pass second argument to gfc_get_namespace.
	* trans-common.c (build_common_decl): Likewise.

Index: gfortran.h
===================================================================
RCS file: /cvs/gcc/gcc/gcc/fortran/gfortran.h,v
retrieving revision 1.52
diff -u -p -r1.52 gfortran.h
--- gfortran.h  7 Feb 2005 22:16:13 -0000       1.52
+++ gfortran.h  12 Feb 2005 18:09:41 -0000
@@ -1619,7 +1619,7 @@ void gfc_free_st_label (gfc_st_label *);
 void gfc_define_st_label (gfc_st_label *, gfc_sl_type, locus *);
 try gfc_reference_st_label (gfc_st_label *, gfc_sl_type);

-gfc_namespace *gfc_get_namespace (gfc_namespace *);
+gfc_namespace *gfc_get_namespace (gfc_namespace *, int);
 gfc_symtree *gfc_new_symtree (gfc_symtree **, const char *);
 gfc_symtree *gfc_find_symtree (gfc_symtree *, const char *);
 gfc_user_op *gfc_get_uop (const char *);
Index: intrinsic.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/fortran/intrinsic.c,v
retrieving revision 1.38
diff -u -p -r1.38 intrinsic.c
--- intrinsic.c 29 Jan 2005 17:46:31 -0000      1.38
+++ intrinsic.c 12 Feb 2005 18:09:42 -0000
@@ -2241,7 +2241,7 @@ gfc_intrinsic_init_1 (void)
   nargs = nfunc = nsub = nconv = 0;

   /* Create a namespace to hold the resolved intrinsic symbols.  */
-  gfc_intrinsic_namespace = gfc_get_namespace (NULL);
+  gfc_intrinsic_namespace = gfc_get_namespace (NULL, 0);

   sizing = SZ_FUNCS;
   add_functions ();
Index: module.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/fortran/module.c,v
retrieving revision 1.26
diff -u -p -r1.26 module.c
--- module.c    8 Feb 2005 13:40:59 -0000       1.26
+++ module.c    12 Feb 2005 18:09:42 -0000
@@ -2627,7 +2627,7 @@ mio_namespace_ref (gfc_namespace ** nsp)
       ns = (gfc_namespace *)p->u.pointer;
       if (ns == NULL)
        {
-         ns = gfc_get_namespace (NULL);
+         ns = gfc_get_namespace (NULL, 0);
          associate_integer_pointer (p, ns);
        }
       else
@@ -2878,7 +2878,7 @@ load_needed (pointer_info * p)
             the namespaces that hold the formal parameters of module
             procedures.  */

-         ns = gfc_get_namespace (NULL);
+         ns = gfc_get_namespace (NULL, 0);
          associate_integer_pointer (q, ns);
        }

Index: parse.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/fortran/parse.c,v
retrieving revision 1.24
diff -u -p -r1.24 parse.c
--- parse.c     7 Feb 2005 22:16:13 -0000       1.24
+++ parse.c     12 Feb 2005 18:09:43 -0000
@@ -1405,7 +1405,7 @@ parse_interface (void)
   current_state = COMP_NONE;

 loop:
-  gfc_current_ns = gfc_get_namespace (current_interface.ns);
+  gfc_current_ns = gfc_get_namespace (current_interface.ns, 0);

   st = next_statement ();
   switch (st)
@@ -2170,7 +2170,7 @@ parse_contained (int module)

   do
     {
-      gfc_current_ns = gfc_get_namespace (parent_ns);
+      gfc_current_ns = gfc_get_namespace (parent_ns, 1);

       gfc_current_ns->sibling = parent_ns->contained;
       parent_ns->contained = gfc_current_ns;
Index: symbol.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/fortran/symbol.c,v
retrieving revision 1.20
diff -u -p -r1.20 symbol.c
--- symbol.c    12 Feb 2005 15:44:01 -0000      1.20
+++ symbol.c    12 Feb 2005 18:09:43 -0000
@@ -1532,10 +1532,11 @@ done:
    this case, that symbol has been used as a host associated variable
    at some previous time.  */

-/* Allocate a new namespace structure.  */
+/* Allocate a new namespace structure.  Copies the implicit types from
+   PARENT if PARENT_TYPES is set.  */

 gfc_namespace *
-gfc_get_namespace (gfc_namespace * parent)
+gfc_get_namespace (gfc_namespace * parent, int parent_types)
 {
   gfc_namespace *ns;
   gfc_typespec *ts;
@@ -1557,7 +1558,7 @@ gfc_get_namespace (gfc_namespace * paren
       ns->set_flag[i - 'a'] = 0;
       ts = &ns->default_type[i - 'a'];

-      if (ns->parent != NULL)
+      if (parent_types && ns->parent != NULL)
        {
          /* Copy parent settings */
          *ts = ns->parent->default_type[i - 'a'];
@@ -2244,7 +2245,7 @@ void
 gfc_symbol_init_2 (void)
 {

-  gfc_current_ns = gfc_get_namespace (NULL);
+  gfc_current_ns = gfc_get_namespace (NULL, 0);
 }


Index: trans-common.c
===================================================================
RCS file: /cvs/gcc/gcc/gcc/fortran/trans-common.c,v
retrieving revision 1.22
diff -u -p -r1.22 trans-common.c
--- trans-common.c      16 Jan 2005 17:53:26 -0000      1.22
+++ trans-common.c      12 Feb 2005 18:09:43 -0000
@@ -288,7 +288,7 @@ build_common_decl (gfc_common_head *com,

   /* Create a namespace to store symbols for common blocks.  */
   if (gfc_common_ns == NULL)
-    gfc_common_ns = gfc_get_namespace (NULL);
+    gfc_common_ns = gfc_get_namespace (NULL, 0);

   gfc_get_symbol (com->name, gfc_common_ns, &common_sym);
   decl = common_sym->backend_decl;
! { dg-do compile }
! INTERFACEs used to wrongly inherit the implicit types of the
! surrounding namespace.
implicit complex (i-k)

interface
   function f(k,l)
     ! the implicit statement in the main program shouldn't affect k
     ! in the function
     dimension l(k)
   end function f
end interface
end

Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]