aboutsummaryrefslogtreecommitdiff
path: root/gcc/fortran/symbol.c
diff options
context:
space:
mode:
authorMikael Morin <mikael@gcc.gnu.org>2010-07-30 16:41:55 +0000
committerMikael Morin <mikael@gcc.gnu.org>2010-07-30 16:41:55 +0000
commit3cb595ac0ba4140c959dfcf18c4f7b80ccc861d7 (patch)
tree456986113aabb474edce8322001f1bfe8270a975 /gcc/fortran/symbol.c
parent2d5bfc67abf07302897ced5f0e620dc0e31820c2 (diff)
downloadgcc-3cb595ac0ba4140c959dfcf18c4f7b80ccc861d7.zip
gcc-3cb595ac0ba4140c959dfcf18c4f7b80ccc861d7.tar.gz
gcc-3cb595ac0ba4140c959dfcf18c4f7b80ccc861d7.tar.bz2
gfortran.h (gfc_release_symbol): New prototype.
2010-07-30 Mikael Morin <mikael@gcc.gnu.org> * gfortran.h (gfc_release_symbol): New prototype. * symbol.c (gfc_release_symbol): New. Code taken from free_sym_tree. (gfc_undo_symbols, free_sym_tree, gfc_free_finalizer): Use gfc_release_symbol. * parse.c (gfc_fixup_sibling_symbols): Ditto. * resolve.c (resolve_symbol): Ditto. From-SVN: r162719
Diffstat (limited to 'gcc/fortran/symbol.c')
-rw-r--r--gcc/fortran/symbol.c63
1 files changed, 28 insertions, 35 deletions
diff --git a/gcc/fortran/symbol.c b/gcc/fortran/symbol.c
index 18f7b25..e713cd8 100644
--- a/gcc/fortran/symbol.c
+++ b/gcc/fortran/symbol.c
@@ -2502,6 +2502,31 @@ gfc_free_symbol (gfc_symbol *sym)
}
+/* Decrease the reference counter and free memory when we reach zero. */
+void
+gfc_release_symbol (gfc_symbol *sym)
+{
+ if (sym == NULL)
+ return;
+
+ if (sym->formal_ns != NULL && sym->refs == 2)
+ {
+ /* As formal_ns contains a reference to sym, delete formal_ns just
+ before the deletion of sym. */
+ gfc_namespace *ns = sym->formal_ns;
+ sym->formal_ns = NULL;
+ gfc_free_namespace (ns);
+ }
+
+ sym->refs--;
+ if (sym->refs > 0)
+ return;
+
+ gcc_assert (sym->refs == 0);
+ gfc_free_symbol (sym);
+}
+
+
/* Allocate and initialize a new symbol node. */
gfc_symbol *
@@ -2893,11 +2918,7 @@ gfc_undo_symbols (void)
gfc_delete_symtree (&p->ns->sym_root, p->name);
- p->refs--;
- if (p->refs < 0)
- gfc_internal_error ("gfc_undo_symbols(): Negative refs");
- if (p->refs == 0)
- gfc_free_symbol (p);
+ gfc_release_symbol (p);
continue;
}
@@ -3107,35 +3128,13 @@ free_uop_tree (gfc_symtree *uop_tree)
static void
free_sym_tree (gfc_symtree *sym_tree)
{
- gfc_namespace *ns;
- gfc_symbol *sym;
-
if (sym_tree == NULL)
return;
free_sym_tree (sym_tree->left);
free_sym_tree (sym_tree->right);
- sym = sym_tree->n.sym;
-
- sym->refs--;
- if (sym->refs < 0)
- gfc_internal_error ("free_sym_tree(): Negative refs");
-
- if (sym->formal_ns != NULL && sym->refs == 1)
- {
- /* As formal_ns contains a reference to sym, delete formal_ns just
- before the deletion of sym. */
- ns = sym->formal_ns;
- sym->formal_ns = NULL;
- gfc_free_namespace (ns);
- }
- else if (sym->refs == 0)
- {
- /* Go ahead and delete the symbol. */
- gfc_free_symbol (sym);
- }
-
+ gfc_release_symbol (sym_tree->n.sym);
gfc_free (sym_tree);
}
@@ -3189,13 +3188,7 @@ gfc_free_finalizer (gfc_finalizer* el)
{
if (el)
{
- if (el->proc_sym)
- {
- --el->proc_sym->refs;
- if (!el->proc_sym->refs)
- gfc_free_symbol (el->proc_sym);
- }
-
+ gfc_release_symbol (el->proc_sym);
gfc_free (el);
}
}