+2010-10-04 Richard Guenther <rguenther@suse.de>
+
+ * f95-lang.c (current_translation_unit): New global variable.
+ (gfc_create_decls): Build a translation-unit decl.
+ (pushdecl): In the global binding-level use the
+ translation-unit decl as DECL_CONTEXT.
+ * trans-decl.c (gfc_get_symbol_decl): Use DECL_FILE_SCOPE_P.
+ (build_function_decl): Likewise. Delay setting the assembler
+ name, leave setting of DECL_CONTEXT to pushdecl.
+ (trans_function_start): Use DECL_FILE_SCOPE_P.
+ (gfc_create_module_variable): Likewise. Remove questionable
+ asserts.
+ * trans.c (gfc_generate_module_code): Likewise.
+
2010-10-03 Francois-Xavier Coudert <fxcoudert@gcc.gnu.org>
* cpp.c (cpp_define_builtins): Call functions from cppbuiltin.c
/* True means we've initialized exception handling. */
bool gfc_eh_initialized_p;
+/* The current translation unit. */
+static GTY(()) tree current_translation_unit;
+
/* Prepare expr to be an argument of a TRUTH_NOT_EXPR,
or validate its data type for an `if' or `while' statement or ?..: exp.
gfc_build_builtin_function_decls ();
gfc_init_constants ();
+
+ /* Build our translation-unit decl. */
+ current_translation_unit = build_translation_unit_decl (NULL_TREE);
}
pushdecl (tree decl)
{
/* External objects aren't nested, other objects may be. */
- if ((DECL_EXTERNAL (decl)) || (decl == current_function_decl))
- DECL_CONTEXT (decl) = 0;
+ if (DECL_EXTERNAL (decl))
+ DECL_CONTEXT (decl) = NULL_TREE;
+ else if (global_bindings_p ())
+ DECL_CONTEXT (decl) = current_translation_unit;
else
DECL_CONTEXT (decl) = current_function_decl;
else
length = sym->ts.u.cl->backend_decl;
if (TREE_CODE (length) == VAR_DECL
- && DECL_CONTEXT (length) == NULL_TREE)
+ && DECL_FILE_SCOPE_P (length))
{
/* Add the string length to the same context as the symbol. */
if (DECL_CONTEXT (sym->backend_decl) == current_function_decl)
/* Allow only one nesting level. Allow public declarations. */
gcc_assert (current_function_decl == NULL_TREE
- || DECL_CONTEXT (current_function_decl) == NULL_TREE
- || TREE_CODE (DECL_CONTEXT (current_function_decl))
- == NAMESPACE_DECL);
+ || DECL_FILE_SCOPE_P (current_function_decl)
+ || (TREE_CODE (DECL_CONTEXT (current_function_decl))
+ == NAMESPACE_DECL));
type = gfc_get_function_type (sym);
fndecl = build_decl (input_location,
attributes = add_attributes_to_decl (attr, NULL_TREE);
decl_attributes (&fndecl, attributes, 0);
- /* Perform name mangling if this is a top level or module procedure. */
- if (current_function_decl == NULL_TREE)
- gfc_set_decl_assembler_name (fndecl, gfc_sym_mangled_function_id (sym));
-
/* Figure out the return type of the declared function, and build a
RESULT_DECL for it. If this is a subroutine with alternate
returns, build a RESULT_DECL for it. */
layout_decl (result_decl, 0); */
/* Set up all attributes for the function. */
- DECL_CONTEXT (fndecl) = current_function_decl;
DECL_EXTERNAL (fndecl) = 0;
/* This specifies if a function is globally visible, i.e. it is
the opposite of declaring static in C. */
- if (DECL_CONTEXT (fndecl) == NULL_TREE
+ if (!current_function_decl
&& !sym->attr.entry_master && !sym->attr.is_main_program)
TREE_PUBLIC (fndecl) = 1;
else
pushdecl (fndecl);
+ /* Perform name mangling if this is a top level or module procedure. */
+ if (current_function_decl == NULL_TREE)
+ gfc_set_decl_assembler_name (fndecl, gfc_sym_mangled_function_id (sym));
+
sym->backend_decl = fndecl;
}
/* Let the world know what we're about to do. */
announce_function (fndecl);
- if (DECL_CONTEXT (fndecl) == NULL_TREE)
+ if (DECL_FILE_SCOPE_P (fndecl))
{
/* Create RTL for function declaration. */
rest_of_decl_compilation (fndecl, 1, 0);
if ((sym->attr.in_common || sym->attr.in_equivalence) && sym->backend_decl)
{
decl = sym->backend_decl;
- gcc_assert (DECL_CONTEXT (decl) == NULL_TREE);
+ gcc_assert (DECL_FILE_SCOPE_P (decl));
gcc_assert (sym->ns->proc_name->attr.flavor == FL_MODULE);
DECL_CONTEXT (decl) = sym->ns->proc_name->backend_decl;
gfc_module_add_decl (cur_module, decl);
/* Create the variable. */
pushdecl (decl);
- gcc_assert (DECL_CONTEXT (decl) == NULL_TREE);
gcc_assert (sym->ns->proc_name->attr.flavor == FL_MODULE);
DECL_CONTEXT (decl) = sym->ns->proc_name->backend_decl;
rest_of_decl_compilation (decl, 1, 0);