gfortran.h (gfc_use_list): Add where field.
authorJakub Jelinek <jakub@redhat.com>
Fri, 29 Aug 2008 18:50:30 +0000 (20:50 +0200)
committerJakub Jelinek <jakub@gcc.gnu.org>
Fri, 29 Aug 2008 18:50:30 +0000 (20:50 +0200)
* gfortran.h (gfc_use_list): Add where field.
* module.c (use_locus): New static variable.
(gfc_match_use): Set it.
(gfc_use_module): Copy it to gfc_use_list's where field.
* trans-decl.c (gfc_generate_module_vars): Call gfc_trans_use_stmts.
(gfc_trans_use_stmts): Set backend locus before calling the debug
hook.  Allow non-VAR_DECLs to be created even for non-external
module.  Don't emit anything so far for renames from different
modules.

From-SVN: r139780

gcc/fortran/ChangeLog
gcc/fortran/gfortran.h
gcc/fortran/module.c
gcc/fortran/trans-decl.c

index 671ef074d655022cd3c0182b428a8a92d05cb636..aee333944afc07591cefe403257e304761bab54a 100644 (file)
@@ -1,5 +1,15 @@
 2008-08-29  Jakub Jelinek  <jakub@redhat.com>
 
+       * gfortran.h (gfc_use_list): Add where field.
+       * module.c (use_locus): New static variable.
+       (gfc_match_use): Set it.
+       (gfc_use_module): Copy it to gfc_use_list's where field.
+       * trans-decl.c (gfc_generate_module_vars): Call gfc_trans_use_stmts.
+       (gfc_trans_use_stmts): Set backend locus before calling the debug
+       hook.  Allow non-VAR_DECLs to be created even for non-external
+       module.  Don't emit anything so far for renames from different
+       modules.
+
        PR fortran/24790
        * trans-decl.c (create_function_arglist): Set DECL_BY_REFERENCE on
        PARM_DECLs with pointer or reference type.
index 81e48b7a21d5e304b4116b3b70f046fcb0f7fb42..d64435155675eb9f4ee134f3a5f5c84f355a7275 100644 (file)
@@ -1153,6 +1153,7 @@ typedef struct gfc_use_list
   const char *module_name;
   int only_flag;
   struct gfc_use_rename *rename;
+  locus where;
   /* Next USE statement.  */
   struct gfc_use_list *next;
 }
index b67b87839d5c1666abdc23990f26e4512a95e1bd..0f504efededfc6d0ab68b67e0693899cf4cd558b 100644 (file)
@@ -188,6 +188,8 @@ static int symbol_number;   /* Counter for assigning symbol numbers */
 /* Tells mio_expr_ref to make symbols for unused equivalence members.  */
 static bool in_load_equiv;
 
+static locus use_locus;
+
 
 
 /*****************************************************************/
@@ -546,6 +548,8 @@ gfc_match_use (void)
        }
     }
 
+  use_locus = gfc_current_locus;
+
   m = gfc_match_name (module_name);
   if (m != MATCH_YES)
     return m;
@@ -5142,6 +5146,7 @@ gfc_use_module (void)
   use_stmt->module_name = gfc_get_string (module_name);
   use_stmt->only_flag = only_flag;
   use_stmt->rename = gfc_rename_list;
+  use_stmt->where = use_locus;
   gfc_rename_list = NULL;
   use_stmt->next = gfc_current_ns->use_stmts;
   gfc_current_ns->use_stmts = use_stmt;
index bf038f7cf94d4469bbab295c190a07f2da9484e4..042821df121f78a973e5a56aac4e99b6fcf28758 100644 (file)
@@ -3151,26 +3151,7 @@ gfc_create_module_variable (gfc_symbol * sym)
     }
 }
 
-
-/* Generate all the required code for module variables.  */
-
-void
-gfc_generate_module_vars (gfc_namespace * ns)
-{
-  module_namespace = ns;
-  cur_module = gfc_find_module (ns->proc_name->name);
-
-  /* Check if the frontend left the namespace in a reasonable state.  */
-  gcc_assert (ns->proc_name && !ns->proc_name->tlink);
-
-  /* Generate COMMON blocks.  */
-  gfc_trans_common (ns);
-
-  /* Create decls for all the module variables.  */
-  gfc_traverse_ns (ns, gfc_create_module_variable);
-
-  cur_module = NULL;
-}
+/* Emit debug information for USE statements.  */
 
 static void
 gfc_trans_use_stmts (gfc_namespace * ns)
@@ -3190,6 +3171,7 @@ gfc_trans_use_stmts (gfc_namespace * ns)
                          void_type_node);
          DECL_EXTERNAL (entry->namespace_decl) = 1;
        }
+      gfc_set_backend_locus (&use_stmt->where);
       if (!use_stmt->only_flag)
        (*debug_hooks->imported_module_or_decl) (entry->namespace_decl,
                                                 NULL_TREE,
@@ -3214,9 +3196,14 @@ gfc_trans_use_stmts (gfc_namespace * ns)
                                     rent->local_name[0]
                                     ? rent->local_name : rent->use_name);
              gcc_assert (st && st->n.sym->attr.use_assoc);
-             if (st->n.sym->backend_decl && DECL_P (st->n.sym->backend_decl))
+             if (st->n.sym->backend_decl
+                 && DECL_P (st->n.sym->backend_decl)
+                 && st->n.sym->module
+                 && strcmp (st->n.sym->module, use_stmt->module_name) == 0)
                {
-                 gcc_assert (DECL_EXTERNAL (entry->namespace_decl));
+                 gcc_assert (DECL_EXTERNAL (entry->namespace_decl)
+                             || (TREE_CODE (st->n.sym->backend_decl)
+                                 != VAR_DECL));
                  decl = copy_node (st->n.sym->backend_decl);
                  DECL_CONTEXT (decl) = entry->namespace_decl;
                  DECL_EXTERNAL (decl) = 1;
@@ -3236,6 +3223,7 @@ gfc_trans_use_stmts (gfc_namespace * ns)
            local_name = get_identifier (rent->local_name);
          else
            local_name = NULL_TREE;
+         gfc_set_backend_locus (&rent->where);
          (*debug_hooks->imported_module_or_decl) (decl, local_name,
                                                   ns->proc_name->backend_decl,
                                                   !use_stmt->only_flag);
@@ -3243,6 +3231,30 @@ gfc_trans_use_stmts (gfc_namespace * ns)
     }
 }
 
+
+/* Generate all the required code for module variables.  */
+
+void
+gfc_generate_module_vars (gfc_namespace * ns)
+{
+  module_namespace = ns;
+  cur_module = gfc_find_module (ns->proc_name->name);
+
+  /* Check if the frontend left the namespace in a reasonable state.  */
+  gcc_assert (ns->proc_name && !ns->proc_name->tlink);
+
+  /* Generate COMMON blocks.  */
+  gfc_trans_common (ns);
+
+  /* Create decls for all the module variables.  */
+  gfc_traverse_ns (ns, gfc_create_module_variable);
+
+  cur_module = NULL;
+
+  gfc_trans_use_stmts (ns);
+}
+
+
 static void
 gfc_generate_contained_functions (gfc_namespace * parent)
 {