aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTobias Burnus <burnus@net-b.de>2007-03-08 14:11:54 +0100
committerTobias Burnus <burnus@gcc.gnu.org>2007-03-08 14:11:54 +0100
commit56bedf420fd15955cfa194ead87f2beaedac9509 (patch)
treee00b232da514f8ce7cd1afe09475bd9cd69a6751
parentac497e6a6e1ea5232c801338a34a41ae30555650 (diff)
downloadgcc-56bedf420fd15955cfa194ead87f2beaedac9509.zip
gcc-56bedf420fd15955cfa194ead87f2beaedac9509.tar.gz
gcc-56bedf420fd15955cfa194ead87f2beaedac9509.tar.bz2
[multiple changes]
2007-07-08 Tobias Burnus <burnus@net-b.de> * module.c (gfc_match_use): Support renaming of operators in USE statements. * gfortran.texi (Fortran 2003 Status): Document support of renaming of operators. 2007-03-08 Tobias Burnus <burnus@net-b.de> * gfortran.dg/use_5.f90: New test. * gfortran.dg/use_6.f90: Ditto. * gfortran.dg/use_7.f90: Ditto. From-SVN: r122699
-rw-r--r--gcc/fortran/ChangeLog7
-rw-r--r--gcc/fortran/gfortran.texi3
-rw-r--r--gcc/fortran/module.c25
-rw-r--r--gcc/testsuite/ChangeLog6
-rw-r--r--gcc/testsuite/gfortran.dg/use_5.f9049
-rw-r--r--gcc/testsuite/gfortran.dg/use_6.f9045
-rw-r--r--gcc/testsuite/gfortran.dg/use_7.f9049
7 files changed, 176 insertions, 8 deletions
diff --git a/gcc/fortran/ChangeLog b/gcc/fortran/ChangeLog
index 3580963..b7e4c4a 100644
--- a/gcc/fortran/ChangeLog
+++ b/gcc/fortran/ChangeLog
@@ -1,5 +1,12 @@
2007-07-08 Tobias Burnus <burnus@net-b.de>
+ * module.c (gfc_match_use): Support renaming of operators
+ in USE statements.
+ * gfortran.texi (Fortran 2003 Status): Document support of
+ renaming of operators.
+
+2007-07-08 Tobias Burnus <burnus@net-b.de>
+
PR fortran/30973
* module.c (read_module): Always import module name as symbol.
(gfc_match_use): Disallow module name in the only clause of
diff --git a/gcc/fortran/gfortran.texi b/gcc/fortran/gfortran.texi
index 3f4a149..52b4c2c 100644
--- a/gcc/fortran/gfortran.texi
+++ b/gcc/fortran/gfortran.texi
@@ -764,6 +764,9 @@ host-associated derived types.
attribute; supported intrinsic modules: @code{ISO_FORTRAN_ENV},
@code{OMP_LIB} and @code{OMP_LIB_KINDS}.
+@item
+Renaming of operators in the @code{USE} statement.
+
@end itemize
diff --git a/gcc/fortran/module.c b/gcc/fortran/module.c
index fcae6bd..5b8bd55 100644
--- a/gcc/fortran/module.c
+++ b/gcc/fortran/module.c
@@ -488,7 +488,7 @@ gfc_match_use (void)
{
char name[GFC_MAX_SYMBOL_LEN + 1], module_nature[GFC_MAX_SYMBOL_LEN + 1];
gfc_use_rename *tail = NULL, *new;
- interface_type type;
+ interface_type type, type2;
gfc_intrinsic_op operator;
match m;
@@ -588,9 +588,16 @@ gfc_match_use (void)
gfc_error ("Missing generic specification in USE statement at %C");
goto cleanup;
+ case INTERFACE_USER_OP:
case INTERFACE_GENERIC:
m = gfc_match (" =>");
+ if (type == INTERFACE_USER_OP && m == MATCH_YES
+ && (gfc_notify_std (GFC_STD_F2003, "Fortran 2003: Renaming "
+ "operators in USE statements at %C")
+ == FAILURE))
+ goto cleanup;
+
if (only_flag)
{
if (m != MATCH_YES)
@@ -598,8 +605,9 @@ gfc_match_use (void)
else
{
strcpy (new->local_name, name);
-
- m = gfc_match_name (new->use_name);
+ m = gfc_match_generic_spec (&type2, new->use_name, &operator);
+ if (type != type2)
+ goto syntax;
if (m == MATCH_NO)
goto syntax;
if (m == MATCH_ERROR)
@@ -612,7 +620,9 @@ gfc_match_use (void)
goto syntax;
strcpy (new->local_name, name);
- m = gfc_match_name (new->use_name);
+ m = gfc_match_generic_spec (&type2, new->use_name, &operator);
+ if (type != type2)
+ goto syntax;
if (m == MATCH_NO)
goto syntax;
if (m == MATCH_ERROR)
@@ -627,11 +637,10 @@ gfc_match_use (void)
goto cleanup;
}
- break;
+ if (type == INTERFACE_USER_OP)
+ new->operator = operator;
- case INTERFACE_USER_OP:
- strcpy (new->use_name, name);
- /* Fall through */
+ break;
case INTERFACE_INTRINSIC_OP:
new->operator = operator;
diff --git a/gcc/testsuite/ChangeLog b/gcc/testsuite/ChangeLog
index dbc2c1f..cef80b0 100644
--- a/gcc/testsuite/ChangeLog
+++ b/gcc/testsuite/ChangeLog
@@ -1,5 +1,11 @@
2007-03-08 Tobias Burnus <burnus@net-b.de>
+ * gfortran.dg/use_5.f90: New test.
+ * gfortran.dg/use_6.f90: Ditto.
+ * gfortran.dg/use_7.f90: Ditto.
+
+2007-03-08 Tobias Burnus <burnus@net-b.de>
+
PR fortran/30973
* gfortran.dg/use_4.f90: New test.
* gfortran.dg/used_dummy_types_7.f90: Correct ambiguous symbol.
diff --git a/gcc/testsuite/gfortran.dg/use_5.f90 b/gcc/testsuite/gfortran.dg/use_5.f90
new file mode 100644
index 0000000..6d2de04
--- /dev/null
+++ b/gcc/testsuite/gfortran.dg/use_5.f90
@@ -0,0 +1,49 @@
+! { dg-do "run" }
+! Renaming of operators
+module z
+ interface operator(.addfive.)
+ module procedure sub2
+ end interface
+contains
+function sub2(x)
+ integer :: sub
+ integer,intent(in) :: x
+ sub2 = x + 5
+end function sub2
+end module z
+
+module y
+ interface operator(.addfive.)
+ module procedure sub
+ end interface
+contains
+function sub(x)
+ integer :: sub
+ integer,intent(in) :: x
+ sub = x + 15
+end function sub
+end module y
+
+module x
+ interface operator(.addfive.)
+ module procedure sub
+ end interface
+contains
+function sub(x)
+ integer :: sub
+ integer,intent(in) :: x
+ sub = x + 25
+end function sub
+end module x
+
+use x, only : operator(.bar.) => operator(.addfive.)
+use y, operator(.my.) => operator(.addfive.)
+use z
+ integer :: i
+ i = 2
+ if ((.bar. i) /= 2+25) call abort ()
+ if ((.my. i) /= 2+15) call abort ()
+ if ((.addfive. i) /= 2+5) call abort ()
+end
+
+! { dg-final { cleanup-tree-dump "x y z" } }
diff --git a/gcc/testsuite/gfortran.dg/use_6.f90 b/gcc/testsuite/gfortran.dg/use_6.f90
new file mode 100644
index 0000000..f0b133e
--- /dev/null
+++ b/gcc/testsuite/gfortran.dg/use_6.f90
@@ -0,0 +1,45 @@
+! { dg-do "compile" }
+! { dg-options "-std=f95" }
+! Renaming of operators
+module z
+ interface operator(.addfive.)
+ module procedure sub2
+ end interface
+contains
+function sub2(x)
+ integer :: sub
+ integer,intent(in) :: x
+ sub2 = x + 5
+end function sub2
+end module z
+
+module y
+ interface operator(.addfive.)
+ module procedure sub
+ end interface
+contains
+function sub(x)
+ integer :: sub
+ integer,intent(in) :: x
+ sub = x + 15
+end function sub
+end module y
+
+module x
+ interface operator(.addfive.)
+ module procedure sub
+ end interface
+contains
+function sub(x)
+ integer :: sub
+ integer,intent(in) :: x
+ sub = x + 25
+end function sub
+end module x
+
+use x, only : operator(.bar.) => operator(.addfive.) ! { dg-error "Fortran 2003: Renaming operators in USE statements" }
+use y, operator(.my.) => operator(.addfive.) ! { dg-error "Fortran 2003: Renaming operators in USE statements" }
+use z
+end
+
+! { dg-final { cleanup-tree-dump "x y z" } }
diff --git a/gcc/testsuite/gfortran.dg/use_7.f90 b/gcc/testsuite/gfortran.dg/use_7.f90
new file mode 100644
index 0000000..3973176
--- /dev/null
+++ b/gcc/testsuite/gfortran.dg/use_7.f90
@@ -0,0 +1,49 @@
+! { dg-do "compile" }
+! Renaming of operators
+module z
+ type myT
+ integer :: t
+ end type myT
+ interface operator(+)
+ module procedure sub2
+ end interface
+contains
+function sub2(x)
+ type(myT) :: sub2
+ type(myT),intent(in) :: x
+ sub2%t = x%t + 5
+end function sub2
+end module z
+
+module y
+ interface operator(.addfive.)
+ module procedure sub
+ end interface
+contains
+function sub(x)
+ integer :: sub
+ integer,intent(in) :: x
+ sub = x + 15
+end function sub
+end module y
+
+module x
+ interface operator(.addfive.)
+ module procedure sub
+ end interface
+contains
+function sub(x)
+ integer :: sub
+ integer,intent(in) :: x
+ sub = x + 25
+end function sub
+end module x
+
+use z, operator(-) => operator(+) ! { dg-error "Syntax error in USE statement" }
+use z, operator(.op.) => operator(+) ! { dg-error "Syntax error in USE statement" }
+use x, only : bar => operator(.addfive.) ! { dg-error "Syntax error in USE statement" }
+use y, operator(.my.) => sub ! { dg-error "Syntax error in USE statement" }
+use y, operator(+) => operator(.addfive.) ! { dg-error "Syntax error in USE statement" }
+end
+
+! { dg-final { cleanup-tree-dump "x y z" } }