diff options
author | Tobias Burnus <burnus@net-b.de> | 2011-01-07 17:19:29 +0100 |
---|---|---|
committer | Tobias Burnus <burnus@gcc.gnu.org> | 2011-01-07 17:19:29 +0100 |
commit | eaf31d823ff3421a12139fec6d7c9788cf456667 (patch) | |
tree | 85c2c6458a7dacec5f59009fd496c87e16d7732e /gcc/fortran | |
parent | 138d831e9bec104b57e9d063f39ae000021c4360 (diff) | |
download | gcc-eaf31d823ff3421a12139fec6d7c9788cf456667.tar.gz |
re PR fortran/41580 ([OOP] SAME_TYPE_AS and EXTENDS_TYPE_OF - add compile-time simplifcation)
2011-01-07 Tobias Burnus <burnus@net-b.de>
PR fortran/41580
* class.c (gfc_build_class_symbol): Mark __vtab as attr.vtab.
* intrinsic.c (add_functions): Use simplify functions for
EXTENDS_TYPE_OF and SAME_TYPE_AS.
* intrinsic.h (gfc_simplify_extends_type_of,
gfc_simplify_same_type_as): New prototypes.
* simplify.c (is_last_ref_vtab, gfc_simplify_extends_type_of,
gfc_simplify_same_type_as): New functions.
2011-01-07 Tobias Burnus <burnus@net-b.de>
PR fortran/41580
* gfortran.dg/extends_type_of_3.f90: New.
From-SVN: r168579
Diffstat (limited to 'gcc/fortran')
-rw-r--r-- | gcc/fortran/ChangeLog | 11 | ||||
-rw-r--r-- | gcc/fortran/intrinsic.c | 7 | ||||
-rw-r--r-- | gcc/fortran/intrinsic.h | 4 | ||||
-rw-r--r-- | gcc/fortran/simplify.c | 89 |
4 files changed, 106 insertions, 5 deletions
diff --git a/gcc/fortran/ChangeLog b/gcc/fortran/ChangeLog index aadd14326d9..57b07100709 100644 --- a/gcc/fortran/ChangeLog +++ b/gcc/fortran/ChangeLog @@ -1,3 +1,14 @@ +2011-01-07 Tobias Burnus <burnus@net-b.de> + + PR fortran/41580 + * class.c (gfc_build_class_symbol): Mark __vtab as attr.vtab. + * intrinsic.c (add_functions): Use simplify functions for + EXTENDS_TYPE_OF and SAME_TYPE_AS. + * intrinsic.h (gfc_simplify_extends_type_of, + gfc_simplify_same_type_as): New prototypes. + * simplify.c (is_last_ref_vtab, gfc_simplify_extends_type_of, + gfc_simplify_same_type_as): New functions. + 2011-01-07 Janus Weil <janus@gcc.gnu.org> PR fortran/47189 diff --git a/gcc/fortran/intrinsic.c b/gcc/fortran/intrinsic.c index d17544c74b0..9458ca948f1 100644 --- a/gcc/fortran/intrinsic.c +++ b/gcc/fortran/intrinsic.c @@ -1,7 +1,7 @@ /* Build up a list of intrinsic subroutines and functions for the name-resolution stage. Copyright (C) 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, - 2009, 2010 + 2009, 2010, 2011 Free Software Foundation, Inc. Contributed by Andy Vaught & Katherine Holcomb @@ -1663,7 +1663,8 @@ add_functions (void) add_sym_2 ("extends_type_of", GFC_ISYM_EXTENDS_TYPE_OF, CLASS_INQUIRY, ACTUAL_NO, BT_LOGICAL, dl, GFC_STD_F2003, - gfc_check_same_type_as, NULL, gfc_resolve_extends_type_of, + gfc_check_same_type_as, gfc_simplify_extends_type_of, + gfc_resolve_extends_type_of, a, BT_UNKNOWN, 0, REQUIRED, mo, BT_UNKNOWN, 0, REQUIRED); @@ -2481,7 +2482,7 @@ add_functions (void) add_sym_2 ("same_type_as", GFC_ISYM_SAME_TYPE_AS, CLASS_INQUIRY, ACTUAL_NO, BT_LOGICAL, dl, GFC_STD_F2003, - gfc_check_same_type_as, NULL, NULL, + gfc_check_same_type_as, gfc_simplify_same_type_as, NULL, a, BT_UNKNOWN, 0, REQUIRED, b, BT_UNKNOWN, 0, REQUIRED); diff --git a/gcc/fortran/intrinsic.h b/gcc/fortran/intrinsic.h index e9574e8a0e5..540cc8ebbf7 100644 --- a/gcc/fortran/intrinsic.h +++ b/gcc/fortran/intrinsic.h @@ -1,7 +1,7 @@ /* Header file for intrinsics check, resolve and simplify function prototypes. Copyright (C) 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, - 2010 Free Software Foundation, Inc. + 2010, 2011 Free Software Foundation, Inc. Contributed by Andy Vaught & Katherine Holcomb This file is part of GCC. @@ -267,6 +267,7 @@ gfc_expr *gfc_simplify_erfc (gfc_expr *); gfc_expr *gfc_simplify_erfc_scaled (gfc_expr *); gfc_expr *gfc_simplify_exp (gfc_expr *); gfc_expr *gfc_simplify_exponent (gfc_expr *); +gfc_expr *gfc_simplify_extends_type_of (gfc_expr *, gfc_expr *); gfc_expr *gfc_simplify_float (gfc_expr *); gfc_expr *gfc_simplify_floor (gfc_expr *, gfc_expr *); gfc_expr *gfc_simplify_fraction (gfc_expr *); @@ -351,6 +352,7 @@ gfc_expr *gfc_simplify_reshape (gfc_expr *, gfc_expr *, gfc_expr *, gfc_expr *); gfc_expr *gfc_simplify_rrspacing (gfc_expr *); gfc_expr *gfc_simplify_rshift (gfc_expr *, gfc_expr *); +gfc_expr *gfc_simplify_same_type_as (gfc_expr *, gfc_expr *); gfc_expr *gfc_simplify_scale (gfc_expr *, gfc_expr *); gfc_expr *gfc_simplify_scan (gfc_expr *, gfc_expr *, gfc_expr *, gfc_expr *); gfc_expr *gfc_simplify_selected_char_kind (gfc_expr *); diff --git a/gcc/fortran/simplify.c b/gcc/fortran/simplify.c index e45ed401085..3beac15177c 100644 --- a/gcc/fortran/simplify.c +++ b/gcc/fortran/simplify.c @@ -1,6 +1,6 @@ /* Simplify intrinsic functions at compile-time. Copyright (C) 2000, 2001, 2002, 2003, 2004, 2005, 2006, 2007, 2008, 2009, - 2010 Free Software Foundation, Inc. + 2010, 2011 Free Software Foundation, Inc. Contributed by Andy Vaught & Katherine Holcomb This file is part of GCC. @@ -2202,6 +2202,93 @@ gfc_simplify_float (gfc_expr *a) } +static bool +is_last_ref_vtab (gfc_expr *e) +{ + gfc_ref *ref; + gfc_component *comp = NULL; + + if (e->expr_type != EXPR_VARIABLE) + return false; + + for (ref = e->ref; ref; ref = ref->next) + if (ref->type == REF_COMPONENT) + comp = ref->u.c.component; + + if (!e->ref || !comp) + return e->symtree->n.sym->attr.vtab; + + if (comp->name[0] == '_' && strcmp (comp->name, "_vptr") == 0) + return true; + + return false; +} + + +gfc_expr * +gfc_simplify_extends_type_of (gfc_expr *a, gfc_expr *mold) +{ + /* Avoid simplification of resolved symbols. */ + if (is_last_ref_vtab (a) || is_last_ref_vtab (mold)) + return NULL; + + if (a->ts.type == BT_DERIVED && mold->ts.type == BT_DERIVED) + return gfc_get_logical_expr (gfc_default_logical_kind, &a->where, + gfc_type_is_extension_of (mold->ts.u.derived, + a->ts.u.derived)); + /* Return .false. if the dynamic type can never be the same. */ + if ((a->ts.type == BT_CLASS && mold->ts.type == BT_CLASS + && !gfc_type_is_extension_of + (mold->ts.u.derived->components->ts.u.derived, + a->ts.u.derived->components->ts.u.derived) + && !gfc_type_is_extension_of + (a->ts.u.derived->components->ts.u.derived, + mold->ts.u.derived->components->ts.u.derived)) + || (a->ts.type == BT_DERIVED && mold->ts.type == BT_CLASS + && !gfc_type_is_extension_of + (a->ts.u.derived, + mold->ts.u.derived->components->ts.u.derived) + && !gfc_type_is_extension_of + (mold->ts.u.derived->components->ts.u.derived, + a->ts.u.derived)) + || (a->ts.type == BT_CLASS && mold->ts.type == BT_DERIVED + && !gfc_type_is_extension_of + (mold->ts.u.derived, + a->ts.u.derived->components->ts.u.derived))) + return gfc_get_logical_expr (gfc_default_logical_kind, &a->where, false); + + if (mold->ts.type == BT_DERIVED + && gfc_type_is_extension_of (mold->ts.u.derived, + a->ts.u.derived->components->ts.u.derived)) + return gfc_get_logical_expr (gfc_default_logical_kind, &a->where, true); + + return NULL; +} + + +gfc_expr * +gfc_simplify_same_type_as (gfc_expr *a, gfc_expr *b) +{ + /* Avoid simplification of resolved symbols. */ + if (is_last_ref_vtab (a) || is_last_ref_vtab (b)) + return NULL; + + /* Return .false. if the dynamic type can never be the + same. */ + if ((a->ts.type == BT_CLASS || b->ts.type == BT_CLASS) + && !gfc_type_compatible (&a->ts, &b->ts) + && !gfc_type_compatible (&b->ts, &a->ts)) + return gfc_get_logical_expr (gfc_default_logical_kind, &a->where, false); + + if (a->ts.type != BT_DERIVED || b->ts.type != BT_DERIVED) + return NULL; + + return gfc_get_logical_expr (gfc_default_logical_kind, &a->where, + gfc_compare_derived_types (a->ts.u.derived, + b->ts.u.derived)); +} + + gfc_expr * gfc_simplify_floor (gfc_expr *e, gfc_expr *k) { |