[gfortran] Support for [...] style array constructors
Erik Edelmann
eedelman@acclab.helsinki.fi
Wed May 11 21:17:00 GMT 2005
I've been told that my copyright assignment has been processed, so
here comes the updated patch I promised.
Den 23.04 kl 22:36:19 skrev eedelman@acclab.helsinki.fi:
> Den 23.04 kl 11:17:26 skrev tobias.schlueter@physik.uni-muenchen.de:
> > Erik Edelmann wrote:
> > > After looking at a bunch of other test cases, and some trial and
> > > error, I've come up with the test cases below.
> > > br_array_constr_1.f90 adds 32 new "# of expected passes", and
> > > br_array_constr_2.f90 adds 3. If someone with better knowledge
> > > than me on how this testsuite system is expected to work would
> > > take the time and look at my test cases and either confirm that
> > > they are OK, or tell me what's wrong with them, I would be most
> > > grateful.
> >
> > Yes they look right. The { dg-warning } line should probably match "array
> > constructor" instead of "New in Fortran 2003:",
>
> Ok.
Fixed.
> > because I don't like that
> > wording too much ("... are an extension to Fortran 95"? Hm, not too good
> > either),
>
> No, I wasn't completely satisfied with the wording either. I'll
> think about it some more. Suggestions wellcome.
Well, I haven't found anything better (but I'll have to admit
that I have not thought about this issue _very_ much). But the
current error message still conveys what I feel is important: the
feature is not F95 (or earlier) standard, but it _is_ F2003
standard (and thus different from other extensions).
Reg. tested on mainline.
Please commit if OK.
Erik
(test cases as attachments)
2005-05-12 Erik Edelmann <erik.edelmann@iki.fi>
* gfortran.dg/br_array_constr_1.f90: New test.
* gfortran.dg/br_array_constr_2.f90: New test.
2005-05-12 Erik Edelmann <erik.edelmann@iki.fi>
* array.c (gfc_match_array_constructor): Support [ ... ]
style array constructors.
Index: gcc/fortran/array.c
===================================================================
RCS file: /cvsroot/gcc/gcc/gcc/fortran/array.c,v
retrieving revision 1.14
diff -u -p -r1.14 array.c
--- gcc/fortran/array.c 5 Apr 2005 08:54:30 -0000 1.14
+++ gcc/fortran/array.c 11 May 2005 19:50:37 -0000
@@ -866,14 +866,27 @@ gfc_match_array_constructor (gfc_expr **
gfc_expr *expr;
locus where;
match m;
+ const char *end_delim;
if (gfc_match (" (/") == MATCH_NO)
- return MATCH_NO;
+ {
+ if (gfc_match (" [") == MATCH_NO)
+ return MATCH_NO;
+ else
+ {
+ if (gfc_notify_std (GFC_STD_F2003, "New in Fortran 2003: [...] "
+ "style array constructors at %C") == FAILURE)
+ return MATCH_ERROR;
+ end_delim = " ]";
+ }
+ }
+ else
+ end_delim = " /)";
where = gfc_current_locus;
head = tail = NULL;
- if (gfc_match (" /)") == MATCH_YES)
+ if (gfc_match (end_delim) == MATCH_YES)
goto empty; /* Special case */
for (;;)
@@ -895,7 +908,7 @@ gfc_match_array_constructor (gfc_expr **
break;
}
- if (gfc_match (" /)") == MATCH_NO)
+ if (gfc_match (end_delim) == MATCH_NO)
goto syntax;
empty:
-------------- next part --------------
! { dg-do run }
! Check that [...] style array constructors work
program bracket_array_constructor
implicit none
integer :: a(4), i
a = [ 1, 2, 3, 4 ] ! { dg-warning "array constructor" }
do i = 1, size(a)
if (a(i) /= i) call abort()
end do
a = [ (/ 1, 2, 3, 4 /) ] ! { dg-warning "array constructor" }
do i = 1, size(a)
if (a(i) /= i) call abort()
end do
end program bracket_array_constructor
-------------- next part --------------
! { dg-do compile }
! Check that array constructor delimiters match
program bracket_array_constr_2
implicit none
integer :: a(4)
a = (/ 1, 2, 3, 4 ] ! { dg-error "array constructor" }
a = (/ [ 1, 2, 3, 4 /) ] ! { dg-error "array constructor" }
end program bracket_array_constr_2
More information about the Fortran
mailing list