* [RFA] New testcase to evaluate Fortran substring expression
@ 2005-06-22 4:02 Wu Zhou
2005-07-03 18:57 ` Daniel Jacobowitz
0 siblings, 1 reply; 11+ messages in thread
From: Wu Zhou @ 2005-06-22 4:02 UTC (permalink / raw)
To: gdb-patches
Sorry, I miss-typed the mail address. Original text is as follows:
---------- Forwarded message ----------
Date: Wed, 22 Jun 2005 10:39:48 +0800 (CST)
From: Wu Zhou <woodzltc@cn.ibm.com>
To: gdb-patches@cn.ibm.com
Cc: eliz@gnu.org, drow@false.org
Subject: [RFA] New testcase to evaluate Fortran substring expression
Eli/Daniel and all,
Here is my new testcase to evaluate Fortran substring expression. The
intention is to test whehter current GDB could correctly handle substring
expression evaluation of Fortran. I tested it against g77-3.2.3 and
gfortran-4.0.0. The last four tests failed for both configuration.
I am also thinking of fixing these errors. It is easy to fix str(exp:exp)
and str(:), but I am not sure how to fix str(:exp) and str(exp:) yet. Any
hints/tips on this? TIA.
2005-06-22 Wu Zhou <woodzltc@cn.ibm.com>
* gdb.fortran/substring.f: New file.
* gdb.fortran/substring.exp: New testcase.
*** /dev/null 2005-06-19 07:34:09.109204120 +0800
--- gdb.fortran/substring.f 2005-06-21 02:28:32.000000000 +0800
***************
*** 0 ****
--- 1,31 ----
+ c Copyright 2005 Free Software Foundation, Inc.
+
+ c This program is free software; you can redistribute it and/or modify
+ c it under the terms of the GNU General Public License as published by
+ c the Free Software Foundation; either version 2 of the License, or
+ c (at your option) any later version.
+ c
+ c This program is distributed in the hope that it will be useful,
+ c but WITHOUT ANY WARRANTY; without even the implied warranty of
+ c MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ c GNU General Public License for more details.
+ c
+ c You should have received a copy of the GNU General Public License
+ c along with this program; if not, write to the Free Software
+ c Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+
+ c Ihis file is the Fortran source file for substring.exp. It was written
+ c by Wu Zhou. (woodzltc@cn.ibm.com)
+
+ PROGRAM substring
+
+ character *26 str
+
+ str = 'abcdefghijklmnopqrstuvwxyz'
+
+ write (*, *) str(1:7)
+ write (*, *) str(:7)
+ write (*, *) str(20:)
+ write (*, *) str(:)
+
+ END PROGRAM
*** /dev/null 2005-06-19 07:34:09.109204120 +0800
--- gdb.fortran/substring.exp 2005-06-22 10:32:41.000000000 +0800
***************
*** 0 ****
--- 1,60 ----
+ # Copyright 2005 Free Software Foundation, Inc.
+
+ # This program is free software; you can redistribute it and/or modify
+ # it under the terms of the GNU General Public License as published by
+ # the Free Software Foundation; either version 2 of the License, or
+ # (at your option) any later version.
+ #
+ # This program is distributed in the hope that it will be useful,
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ # GNU General Public License for more details.
+ #
+ # You should have received a copy of the GNU General Public License
+ # along with this program; if not, write to the Free Software
+ # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+
+ # This file was written by Wu Zhou. (woodzltc@cn.ibm.com)
+
+ # This file is part of the gdb testsuite. It contains tests for evaluating
+ # Fortran substring expression
+
+ if $tracelevel then {
+ strace $tracelevel
+ }
+
+ set testfile "substring"
+ set srcfile ${testfile}.f
+ set binfile ${objdir}/${subdir}/${testfile}
+
+ if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable {debug f77 quiet}] != "" } {
+ untested "Couldn't compile ${srcfile}"
+ return -1
+ }
+
+ gdb_exit
+ gdb_start
+ gdb_reinitialize_dir $srcdir/$subdir
+ gdb_load ${binfile}
+
+ if ![runto MAIN__] then {
+ perror "couldn't run to breakpoint sub_"
+ continue
+ }
+
+ # Try to set breakpoint at the last write statement.
+
+ set bp_location [gdb_get_line_number "str(:)"]
+ gdb_test "break $bp_location" \
+ "Breakpoint.*at.* file .*$srcfile, line $bp_location\\." \
+ "breakpoint at the last write statement"
+ gdb_test "continue" \
+ "Continuing\\..*Breakpoint.*" \
+ "continue to breakpoint"
+
+ # Test four different kinds of substring expression evaluation.
+
+ gdb_test "print str(1:7)" ".*1 = .*" "print str(1:7)"
+ gdb_test "print str(:7)" ".*2 = .*" "print str(:7)"
+ gdb_test "print str(20:)" ".*3 = .*" "print str(20:)"
+ gdb_test "print str(:)" ".*4 = .*" "print str(:)"
Cheers
- Wu Zhou
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: [RFA] New testcase to evaluate Fortran substring expression
2005-06-22 4:02 [RFA] New testcase to evaluate Fortran substring expression Wu Zhou
@ 2005-07-03 18:57 ` Daniel Jacobowitz
2005-07-09 3:12 ` Wu Zhou
0 siblings, 1 reply; 11+ messages in thread
From: Daniel Jacobowitz @ 2005-07-03 18:57 UTC (permalink / raw)
To: Wu Zhou; +Cc: gdb-patches
On Wed, Jun 22, 2005 at 10:53:35AM +0800, Wu Zhou wrote:
> Eli/Daniel and all,
>
> Here is my new testcase to evaluate Fortran substring expression. The
> intention is to test whehter current GDB could correctly handle substring
> expression evaluation of Fortran. I tested it against g77-3.2.3 and
> gfortran-4.0.0. The last four tests failed for both configuration.
>
> I am also thinking of fixing these errors. It is easy to fix str(exp:exp)
> and str(:), but I am not sure how to fix str(:exp) and str(exp:) yet. Any
> hints/tips on this? TIA.
Let's hold this thought, OK? I would rather add the tests when you
have a patch to fix them. Alternatively PRs could be filed and the new
tests KFAILd, but I don't think that adds much value.
What's the problem with parsing (:exp)? An exp can't be empty, and a
colon can't appear at the start of an exp. I don't think (exp:) will
be any harder but my yacc is rusty.
--
Daniel Jacobowitz
CodeSourcery, LLC
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: [RFA] New testcase to evaluate Fortran substring expression
2005-07-03 18:57 ` Daniel Jacobowitz
@ 2005-07-09 3:12 ` Wu Zhou
2005-07-14 23:46 ` Daniel Jacobowitz
0 siblings, 1 reply; 11+ messages in thread
From: Wu Zhou @ 2005-07-09 3:12 UTC (permalink / raw)
To: Daniel Jacobowitz; +Cc: gdb-patches
On Sun, 3 Jul 2005, Daniel Jacobowitz wrote:
> On Wed, Jun 22, 2005 at 10:53:35AM +0800, Wu Zhou wrote:
> > Eli/Daniel and all,
> >
> > Here is my new testcase to evaluate Fortran substring expression. The
> > intention is to test whehter current GDB could correctly handle substring
> > expression evaluation of Fortran. I tested it against g77-3.2.3 and
> > gfortran-4.0.0. The last four tests failed for both configuration.
> >
> > I am also thinking of fixing these errors. It is easy to fix str(exp:exp)
> > and str(:), but I am not sure how to fix str(:exp) and str(exp:) yet. Any
> > hints/tips on this? TIA.
>
> Let's hold this thought, OK? I would rather add the tests when you
> have a patch to fix them. Alternatively PRs could be filed and the new
> tests KFAILd, but I don't think that adds much value.
>
> What's the problem with parsing (:exp)? An exp can't be empty, and a
> colon can't appear at the start of an exp. I don't think (exp:) will
> be any harder but my yacc is rusty.
The original thought of mine is to not add any new operators. The problem
of this idea is how to transfer the lowerbound (or upperbound or both) of
the prefixed array expression? Any ideas on this?
Now I coded a patch (attached below) to add four new operators for F90
subrange: OP_F90_RANGE_NORMAL, OP_F90_RANGE_DFT_END, OP_F90_RANGE_DFT_START
and OP_F90_RANGE_DFT_ALL. The code of evaluating sub-array is also added
and the code of substring evaluation is updated to use the former
(sub-array evaluation). Would you please comment on this patch?
It is not complete, I am also thinking of enabling GDB to evaluate
multi-dimension sub-array. But not sure which is the easiest way. And
if possible I'd also like to replace the usage of some gotos with some
function. So this patch is just the first step. Thanks in advance
for reviewing it.
OK. Here goes the patch:
2005-07-09 Wu Zhou <woodzltc@cn.ibm.com>
* f-exp.y (yyparse): Add support for parsing F90 subrange and
change substring parsing to subrange parsing.
* parse.c (operator_length_standard): Set the operator length
and args number for new F90 subrange operators.
* expression.h (enum exp_opcode): Add four operators for F90
subrange.
* eval.c (evaluate_subexp_standard): Add code to evaluate F90
sub-array.
Index: f-exp.y
===================================================================
RCS file: /cvs/src/src/gdb/f-exp.y,v
retrieving revision 1.17
diff -c -p -r1.17 f-exp.y
*** f-exp.y 6 Jul 2005 06:52:25 -0000 1.17
--- f-exp.y 9 Jul 2005 02:25:18 -0000
*************** arglist : exp
*** 283,300 ****
{ arglist_len = 1; }
;
! arglist : substring
! { arglist_len = 2;}
;
! arglist : arglist ',' exp %prec ABOVE_COMMA
{ arglist_len++; }
;
! substring: exp ':' exp %prec ABOVE_COMMA
! { }
;
complexnum: exp ',' exp
{ }
--- 283,318 ----
{ arglist_len = 1; }
;
! arglist : subrange
! { }
;
! arglist : arglist ',' arglist %prec ABOVE_COMMA
{ arglist_len++; }
;
! subrange: exp ':' exp %prec ABOVE_COMMA
! { arglist_len = 1;
! write_exp_elt_opcode (OP_F90_RANGE_NORMAL); }
;
+ subrange: exp ':' %prec ABOVE_COMMA
+ { arglist_len = 1;
+ write_exp_elt_opcode (OP_F90_RANGE_DFT_END); }
+ ;
+
+ subrange: ':' exp %prec ABOVE_COMMA
+ { arglist_len = 1;
+ write_exp_elt_opcode (OP_F90_RANGE_DFT_START); }
+ ;
+
+ subrange: ':' %prec ABOVE_COMMA
+ { arglist_len = 1;
+ write_exp_elt_opcode (OP_F90_RANGE_DFT_ALL); }
+ /*
+ write_exp_elt_longcst (1);
+ write_exp_elt_opcode (OP_F90_RANGE_DFT_ALL); }
+ */ ;
complexnum: exp ',' exp
{ }
Index: parse.c
===================================================================
RCS file: /cvs/src/src/gdb/parse.c,v
retrieving revision 1.49
diff -c -p -r1.49 parse.c
*** parse.c 29 Apr 2005 00:04:06 -0000 1.49
--- parse.c 9 Jul 2005 02:25:18 -0000
*************** operator_length_standard (struct express
*** 957,962 ****
--- 957,971 ----
oplen = 2;
break;
+ case OP_F90_RANGE_NORMAL:
+ oplen = 1;
+ args = 2;
+ break;
+
+ case OP_F90_RANGE_DFT_ALL:
+ oplen = 1;
+ break;
+
default:
args = 1 + (i < (int) BINOP_END);
}
Index: expression.h
===================================================================
RCS file: /cvs/src/src/gdb/expression.h,v
retrieving revision 1.15
diff -c -p -r1.15 expression.h
*** expression.h 8 Jun 2005 06:28:28 -0000 1.15
--- expression.h 9 Jul 2005 02:25:18 -0000
*************** enum exp_opcode
*** 324,329 ****
--- 324,335 ----
/* An Objective C Foundation Class NSString constant */
OP_OBJC_NSSTRING,
+ /* Four different kinds of subrange expression for F90 and above. */
+ OP_F90_RANGE_NORMAL,
+ OP_F90_RANGE_DFT_END,
+ OP_F90_RANGE_DFT_START,
+ OP_F90_RANGE_DFT_ALL,
+
/* First extension operator. Individual language modules define
extra operators they need as constants with values
OP_LANGUAGE_SPECIFIC0 + k, for k >= 0, using a separate
Index: eval.c
===================================================================
RCS file: /cvs/src/src/gdb/eval.c,v
retrieving revision 1.58
diff -c -p -r1.58 eval.c
*** eval.c 6 Jul 2005 06:52:25 -0000 1.58
--- eval.c 9 Jul 2005 02:25:19 -0000
*************** init_array_element (struct value *array,
*** 377,382 ****
--- 377,435 ----
return index;
}
+ static int
+ is_f90_subarray (struct expression *exp, int position)
+ {
+ int nelts = exp->nelts;
+ enum exp_opcode op = exp->elts[position].opcode;
+
+ if (op == OP_F90_RANGE_NORMAL || op == OP_F90_RANGE_DFT_END
+ || op == OP_F90_RANGE_DFT_START
+ || op == OP_F90_RANGE_DFT_ALL )
+ return 1;
+
+ return 0;
+
+ }
+
+ struct value *
+ value_f90_subarray (struct value *array, struct expression *exp, int *pos, enum noside noside)
+ {
+ int pc = (*pos)++;
+ enum exp_opcode op = exp->elts[pc].opcode;
+ LONGEST lower_bound, upper_bound;
+ struct type *range_type;
+
+ switch (op)
+ {
+ case OP_F90_RANGE_NORMAL:
+ lower_bound = value_as_long (evaluate_subexp (NULL_TYPE, exp, pos, noside));
+ upper_bound = value_as_long (evaluate_subexp (NULL_TYPE, exp, pos, noside));
+ return value_slice (array, lower_bound, upper_bound - lower_bound + 1);
+
+ case OP_F90_RANGE_DFT_END:
+ range_type = check_typedef (TYPE_INDEX_TYPE (value_type (array)));
+ lower_bound = value_as_long (evaluate_subexp (NULL_TYPE, exp, pos, noside));
+ upper_bound = TYPE_HIGH_BOUND (range_type);
+ return value_slice (array, lower_bound, upper_bound - lower_bound + 1);
+
+ case OP_F90_RANGE_DFT_START:
+ range_type = check_typedef (TYPE_INDEX_TYPE (value_type (array)));
+ lower_bound = TYPE_LOW_BOUND (range_type);
+ upper_bound = value_as_long (evaluate_subexp (NULL_TYPE, exp, pos, noside));
+ return value_slice (array, lower_bound, upper_bound - lower_bound + 1);
+
+ case OP_F90_RANGE_DFT_ALL:
+ range_type = check_typedef (TYPE_INDEX_TYPE (value_type (array)));
+ lower_bound = TYPE_LOW_BOUND (range_type);
+ upper_bound = TYPE_HIGH_BOUND (range_type);
+ return value_slice (array, lower_bound, upper_bound - lower_bound + 1);
+
+ default:
+ error (_("This is not a f90 subarray"));
+ }
+ }
+
struct value *
evaluate_subexp_standard (struct type *expect_type,
struct expression *exp, int *pos,
*************** evaluate_subexp_standard (struct type *e
*** 1267,1276 ****
switch (code)
{
case TYPE_CODE_ARRAY:
! goto multi_f77_subscript;
case TYPE_CODE_STRING:
! goto op_f77_substr;
case TYPE_CODE_PTR:
case TYPE_CODE_FUNC:
--- 1320,1338 ----
switch (code)
{
case TYPE_CODE_ARRAY:
! if (is_f90_subarray (exp, *pos))
! return value_f90_subarray (arg1, exp, pos, noside);
! else
! goto multi_f77_subscript;
case TYPE_CODE_STRING:
! if (is_f90_subarray (exp, *pos))
! return value_f90_subarray (arg1, exp, pos, noside);
! else
! {
! arg2 = evaluate_subexp_with_coercion (exp, pos, noside);
! return value_subscript (arg1, arg2);
! }
case TYPE_CODE_PTR:
case TYPE_CODE_FUNC:
Regards
- Wu Zhou
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: [RFA] New testcase to evaluate Fortran substring expression
2005-07-09 3:12 ` Wu Zhou
@ 2005-07-14 23:46 ` Daniel Jacobowitz
2005-07-15 5:25 ` Wu Zhou
0 siblings, 1 reply; 11+ messages in thread
From: Daniel Jacobowitz @ 2005-07-14 23:46 UTC (permalink / raw)
To: Wu Zhou; +Cc: gdb-patches
On Fri, Jul 08, 2005 at 12:54:21AM +0800, Wu Zhou wrote:
> The original thought of mine is to not add any new operators. The problem
> of this idea is how to transfer the lowerbound (or upperbound or both) of
> the prefixed array expression? Any ideas on this?
>
> Now I coded a patch (attached below) to add four new operators for F90
> subrange: OP_F90_RANGE_NORMAL, OP_F90_RANGE_DFT_END, OP_F90_RANGE_DFT_START
> and OP_F90_RANGE_DFT_ALL. The code of evaluating sub-array is also added
> and the code of substring evaluation is updated to use the former
> (sub-array evaluation). Would you please comment on this patch?
First of all, why do you need four operators? I'd just use one, and
push some sentinel value for the empty boundary case. I'm not sure if
you can use NULL in this context, but if you can, that'd work nicely.
> ! arglist : subrange
> ! { }
> ;
>
IIRC empty actions can just be skipped.
> ! arglist : arglist ',' arglist %prec ABOVE_COMMA
> { arglist_len++; }
> ;
>
The old grammar was:
arglist: /* empty */
| exp
| substring
| arglist ',' exp
substring: exp ':' exp
So "1, 1" "1:1", "1:1,1", "1:1,1,1" were all valid arglists. I don't
know Fortran, but I'm guessing this is intended, for multidimensional
arrays?
The new grammar is:
arglist : /* empty */
| exp
| subrange
| arglist ',' arglist
subrange : exp ':' exp
| exp ':'
| ':' exp
| ':'
One big problem here: I would have assumed bison would have bumped up
the number of conflicts reported here. Maybe it doesn't because of the
%prec. But you probaby don't want arglist ',' arglist. It has all
sorts of quirks; for instance, it allows "," as an arglist with two
elements. If what you are trying to do is allow "1:1, 1:1" then you
want:
arglist : /* empty */
| exp
| subrange
| arglist ',' exp
| arglist ',' subrange
--
Daniel Jacobowitz
CodeSourcery, LLC
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: [RFA] New testcase to evaluate Fortran substring expression
2005-07-14 23:46 ` Daniel Jacobowitz
@ 2005-07-15 5:25 ` Wu Zhou
2005-07-15 11:49 ` Wu Zhou
0 siblings, 1 reply; 11+ messages in thread
From: Wu Zhou @ 2005-07-15 5:25 UTC (permalink / raw)
To: Daniel Jacobowitz; +Cc: gdb-patches
On Thu, 14 Jul 2005, Daniel Jacobowitz wrote:
> First of all, why do you need four operators? I'd just use one, and
> push some sentinel value for the empty boundary case. I'm not sure if
> you can use NULL in this context, but if you can, that'd work nicely.
I ever tried to use NULL, but it can't distinguish between ":exp" and
"exp:". But I am thinking of adding one longcst into operator
OP_F90_RANGE to indicate the range type, 0 refer to ":", 1 refer to
"exp:", "-1" means ":exp" and 2 means "exp:exp". Or add two boolean
to indicate whether that bound is empty or not. What is your point on
this. I will try to do some tests soon.
> > ! arglist : subrange
> > ! { }
> > ;
> >
>
> IIRC empty actions can just be skipped.
Do you means that I need to delete this empty action? I see others keep
this. So I did this too.
> > ! arglist : arglist ',' arglist %prec ABOVE_COMMA
> > { arglist_len++; }
> > ;
> >
>
> The old grammar was:
> arglist: /* empty */
> | exp
> | substring
> | arglist ',' exp
> substring: exp ':' exp
>
> So "1, 1" "1:1", "1:1,1", "1:1,1,1" were all valid arglists. I don't
> know Fortran, but I'm guessing this is intended, for multidimensional
> arrays?
They are not valid expression for multi-dimensional array. I guess it is
might be the fault of the original author. This grammar was adapted from
the C parser. (You have a look at the header of f-exp.y for proof). In C
parser, it is just used to expression Function argments list. But in
fortran, things are somewhat complicated: parentheses are also express
array subscript, substring and also array section (the latter is the F90
extension). I guess the case is that the original author just add
substring as a valid arglist and didn't notice that it might interpret
"1:1,1", "1:1,1,1" and such as valid too.
>
> The new grammar is:
> arglist : /* empty */
> | exp
> | subrange
> | arglist ',' arglist
My intention is to use this to allow such things like "1:3, 2", "1:3, 2,
2:5" and so on. It is somewhat awesome to have to use "1:3, 2:2" or
"1:3, 2:2, 2:5".
>
> subrange : exp ':' exp
> | exp ':'
> | ':' exp
> | ':'
>
> One big problem here: I would have assumed bison would have bumped up
> the number of conflicts reported here. Maybe it doesn't because of the
> %prec. But you probaby don't want arglist ',' arglist. It has all
> sorts of quirks; for instance, it allows "," as an arglist with two
> elements. If what you are trying to do is allow "1:1, 1:1" then you
> want:
Yes, I ever had some thought about that. If you really care, I can
drop my grammar, and accept yours.
>
> arglist : /* empty */
> | exp
> | subrange
> | arglist ',' exp
> | arglist ',' subrange
>
Thanks very much for your kind comments.
Regards
- Wu Zhou
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: [RFA] New testcase to evaluate Fortran substring expression
2005-07-15 5:25 ` Wu Zhou
@ 2005-07-15 11:49 ` Wu Zhou
2005-08-01 2:12 ` Daniel Jacobowitz
0 siblings, 1 reply; 11+ messages in thread
From: Wu Zhou @ 2005-07-15 11:49 UTC (permalink / raw)
To: Daniel Jacobowitz; +Cc: gdb-patches
Daniel,
I made some modification to the original patch. The changes include:
- Don't include "arglist : arglist, subrange". Because I don't figure
out how to evaluate multi-dimension array section yet.
- Only add a new operator: OP_F90_RANGE and get the range type wrapped by
this operator.
- Change the name of new testcase from substring to subarray. Because
g77 will handle string variable as character array instead. (gfortran did
this too) Added four tests for substring evaluation in gdb.fortran/exprs.exp,
the reason is that g77 and gfortran still treat string constant as string.
Please help review this too. Thanks a lot!
P.S: I had tested this on FC4. All passed. And no regression on fortran
related test. (Didn't test other part of the testsuite.)
2005-07-15 Wu Zhou <woodzltc@cn.ibm.com>
* expression.h (enum exp_opcode): Add a new operator for F90
subrange.
* f-exp.y (yyparse): Add support for parsing F90 subrange and
change substring parsing to subrange parsing.
* parse.c (operator_length_standard): Set the operator length
and args number for OP_F90_RANGE.
* eval.c (evaluate_subexp_standard): Add code to evaluate F90
sub-array.
(value_f90_subarray): New function to evaluate f90 subarray.
Index: expression.h
===================================================================
RCS file: /cvs/src/src/gdb/expression.h,v
retrieving revision 1.15
diff -c -p -r1.15 expression.h
*** expression.h 8 Jun 2005 06:28:28 -0000 1.15
--- expression.h 15 Jul 2005 10:01:38 -0000
*************** enum exp_opcode
*** 324,329 ****
--- 324,332 ----
/* An Objective C Foundation Class NSString constant */
OP_OBJC_NSSTRING,
+ /* A F90 array range operator. (for "exp:exp", "exp:", ":exp" and ":") */
+ OP_F90_RANGE,
+
/* First extension operator. Individual language modules define
extra operators they need as constants with values
OP_LANGUAGE_SPECIFIC0 + k, for k >= 0, using a separate
Index: f-exp.y
===================================================================
RCS file: /cvs/src/src/gdb/f-exp.y,v
retrieving revision 1.17
diff -c -p -r1.17 f-exp.y
*** f-exp.y 6 Jul 2005 06:52:25 -0000 1.17
--- f-exp.y 15 Jul 2005 10:01:39 -0000
*************** arglist : exp
*** 283,300 ****
{ arglist_len = 1; }
;
! arglist : substring
! { arglist_len = 2;}
;
arglist : arglist ',' exp %prec ABOVE_COMMA
{ arglist_len++; }
;
! substring: exp ':' exp %prec ABOVE_COMMA
! { }
;
complexnum: exp ',' exp
{ }
--- 283,319 ----
{ arglist_len = 1; }
;
! arglist : subrange
! { arglist_len = 1; }
;
arglist : arglist ',' exp %prec ABOVE_COMMA
{ arglist_len++; }
;
! subrange: exp ':' exp %prec ABOVE_COMMA
! { write_exp_elt_opcode (OP_F90_RANGE);
! write_exp_elt_longcst (2);
! write_exp_elt_opcode (OP_F90_RANGE); }
;
+ subrange: exp ':' %prec ABOVE_COMMA
+ { write_exp_elt_opcode (OP_F90_RANGE);
+ write_exp_elt_longcst (1);
+ write_exp_elt_opcode (OP_F90_RANGE); }
+ ;
+
+ subrange: ':' exp %prec ABOVE_COMMA
+ { write_exp_elt_opcode (OP_F90_RANGE);
+ write_exp_elt_longcst (-1);
+ write_exp_elt_opcode (OP_F90_RANGE); }
+ ;
+
+ subrange: ':' %prec ABOVE_COMMA
+ { write_exp_elt_opcode (OP_F90_RANGE);
+ write_exp_elt_longcst (0);
+ write_exp_elt_opcode (OP_F90_RANGE); }
+ ;
complexnum: exp ',' exp
{ }
Index: parse.c
===================================================================
RCS file: /cvs/src/src/gdb/parse.c,v
retrieving revision 1.49
diff -c -p -r1.49 parse.c
*** parse.c 29 Apr 2005 00:04:06 -0000 1.49
--- parse.c 15 Jul 2005 10:01:40 -0000
*************** operator_length_standard (struct express
*** 957,962 ****
--- 957,967 ----
oplen = 2;
break;
+ case OP_F90_RANGE:
+ oplen = 3;
+ args = abs (longest_to_int (expr->elts[endpos - 2].longconst));
+ break;
+
default:
args = 1 + (i < (int) BINOP_END);
}
Index: eval.c
===================================================================
RCS file: /cvs/src/src/gdb/eval.c,v
retrieving revision 1.58
diff -c -p -r1.58 eval.c
*** eval.c 6 Jul 2005 06:52:25 -0000 1.58
--- eval.c 15 Jul 2005 10:01:42 -0000
*************** init_array_element (struct value *array,
*** 378,383 ****
--- 378,405 ----
}
struct value *
+ value_f90_subarray (struct value *array, struct expression *exp, int *pos, enum noside noside)
+ {
+ int pc = (*pos) + 1;
+ int nargs = longest_to_int (exp->elts[pc].longconst);
+ LONGEST lower_bound, upper_bound;
+ struct type *range_type = check_typedef (TYPE_INDEX_TYPE (value_type (array)));
+
+ *pos += 3;
+ if (nargs == 0 || nargs == -1)
+ lower_bound = TYPE_LOW_BOUND (range_type);
+ else
+ lower_bound = value_as_long (evaluate_subexp (NULL_TYPE, exp, pos, noside));
+
+ if (nargs == 0 || nargs == 1)
+ upper_bound = TYPE_HIGH_BOUND (range_type);
+ else
+ upper_bound = value_as_long (evaluate_subexp (NULL_TYPE, exp, pos, noside));
+
+ return value_slice (array, lower_bound, upper_bound - lower_bound + 1);
+ }
+
+ struct value *
evaluate_subexp_standard (struct type *expect_type,
struct expression *exp, int *pos,
enum noside noside)
*************** evaluate_subexp_standard (struct type *e
*** 1267,1276 ****
switch (code)
{
case TYPE_CODE_ARRAY:
! goto multi_f77_subscript;
case TYPE_CODE_STRING:
! goto op_f77_substr;
case TYPE_CODE_PTR:
case TYPE_CODE_FUNC:
--- 1289,1307 ----
switch (code)
{
case TYPE_CODE_ARRAY:
! if (exp->elts[*pos].opcode == OP_F90_RANGE)
! return value_f90_subarray (arg1, exp, pos, noside);
! else
! goto multi_f77_subscript;
case TYPE_CODE_STRING:
! if (exp->elts[*pos].opcode == OP_F90_RANGE)
! return value_f90_subarray (arg1, exp, pos, noside);
! else
! {
! arg2 = evaluate_subexp_with_coercion (exp, pos, noside);
! return value_subscript (arg1, arg2);
! }
case TYPE_CODE_PTR:
case TYPE_CODE_FUNC:
Here is the patch for exprs.exp:
==================================
Index: gdb.fortran/exprs.exp
===================================================================
RCS file: /cvs/src/src/gdb/testsuite/gdb.fortran/exprs.exp,v
retrieving revision 1.4
diff -c -p -r1.4 exprs.exp
*** gdb.fortran/exprs.exp 6 Jul 2005 06:11:54 -0000 1.4
--- gdb.fortran/exprs.exp 15 Jul 2005 10:05:15 -0000
*************** proc test_character_literals_accepted {}
*** 59,64 ****
--- 59,71 ----
# Test various character values.
gdb_test "p 'a'" " = 'a'"
+
+ # Test various substring expression.
+ gdb_test "p 'abcdefg'(2:4)" " = 'bcd'"
+ gdb_test "p 'abcdefg'(:3)" " = 'abc'"
+ gdb_test "p 'abcdefg'(5:)" " = 'efg'"
+ gdb_test "p 'abcdefg'(:)" " = 'abcdefg'"
+
}
proc test_integer_literals_rejected {} {
*************** proc test_arithmetic_expressions {} {
*** 248,255 ****
gdb_test "p 6.0 / 3" " = 2" "real divided by int"
gdb_test "p 6.0 / 3.0" " = 2" "real divided by real"
- # Test modulo with various operands
-
# Test exponentiation with various operands
gdb_test "p 2 ** 3" " = 8" "int powered by int"
--- 255,260 ----
Here is the renamed subarray testcase:
========================================
*** /dev/null 2005-06-19 07:34:09.109204120 +0800
--- gdb.fortran/subarray.f 2005-07-14 13:40:35.000000000 +0800
***************
*** 0 ****
--- 1,36 ----
+ c Copyright 2005 Free Software Foundation, Inc.
+
+ c This program is free software; you can redistribute it and/or modify
+ c it under the terms of the GNU General Public License as published by
+ c the Free Software Foundation; either version 2 of the License, or
+ c (at your option) any later version.
+ c
+ c This program is distributed in the hope that it will be useful,
+ c but WITHOUT ANY WARRANTY; without even the implied warranty of
+ c MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ c GNU General Public License for more details.
+ c
+ c You should have received a copy of the GNU General Public License
+ c along with this program; if not, write to the Free Software
+ c Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+
+ c Ihis file is the Fortran source file for subarray.exp. It was written
+ c by Wu Zhou. (woodzltc@cn.ibm.com)
+
+ PROGRAM subarray
+
+ character *7 str
+ integer array(7)
+
+ c Initialize character array "str" and integer array "array".
+ str = 'abcdefg'
+ do i = 1, 7
+ array(i) = i
+ end do
+
+ write (*, *) str(2:4)
+ write (*, *) str(:3)
+ write (*, *) str(5:)
+ write (*, *) str(:)
+
+ END PROGRAM
*** /dev/null 2005-06-19 07:34:09.109204120 +0800
--- gdb.fortran/subarray.exp 2005-07-14 13:43:58.000000000 +0800
***************
*** 0 ****
--- 1,66 ----
+ # Copyright 2005 Free Software Foundation, Inc.
+
+ # This program is free software; you can redistribute it and/or modify
+ # it under the terms of the GNU General Public License as published by
+ # the Free Software Foundation; either version 2 of the License, or
+ # (at your option) any later version.
+ #
+ # This program is distributed in the hope that it will be useful,
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ # GNU General Public License for more details.
+ #
+ # You should have received a copy of the GNU General Public License
+ # along with this program; if not, write to the Free Software
+ # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+
+ # This file was written by Wu Zhou. (woodzltc@cn.ibm.com)
+
+ # This file is part of the gdb testsuite. It contains tests for evaluating
+ # Fortran subarray expression
+
+ if $tracelevel then {
+ strace $tracelevel
+ }
+
+ set testfile "subarray"
+ set srcfile ${testfile}.f
+ set binfile ${objdir}/${subdir}/${testfile}
+
+ if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable {debug f77 quiet}] != "" } {
+ untested "Couldn't compile ${srcfile}"
+ return -1
+ }
+
+ gdb_exit
+ gdb_start
+ gdb_reinitialize_dir $srcdir/$subdir
+ gdb_load ${binfile}
+
+ if ![runto MAIN__] then {
+ perror "couldn't run to breakpoint sub_"
+ continue
+ }
+
+ # Try to set breakpoint at the last write statement.
+
+ set bp_location [gdb_get_line_number "str(:)"]
+ gdb_test "break $bp_location" \
+ "Breakpoint.*at.* file .*$srcfile, line $bp_location\\." \
+ "breakpoint at the last write statement"
+ gdb_test "continue" \
+ "Continuing\\..*Breakpoint.*" \
+ "continue to breakpoint"
+
+ # Test four different kinds of subarray expression evaluation.
+
+ gdb_test "print str(2:4)" ".*1 = \\(98 'b', 99 'c', 100 'd'\\).*" "print str(2:4)"
+ gdb_test "print str(:3)" ".*2 = \\(97 'a', 98 'b', 99 'c'\\).*" "print str(:3)"
+ gdb_test "print str(5:)" ".*3 = \\(101 'e', 102 'f', 103 'g'\\).*" "print str(5:)"
+ gdb_test "print str(:)" ".*4 = \\(97 'a', 98 'b', 99 'c', 100 'd', 101 'e', 102 'f', 103 'g'\\).*" "print str(:)"
+
+ gdb_test "print array(2:4)" ".*5 = \\(2, 3, 4\\).*" "print array(2:4)"
+ gdb_test "print array(:3)" ".*6 = \\(1, 2, 3\\).*" "print array(:3)"
+ gdb_test "print array(5:)" ".*7 = \\(5, 6, 7\\).*" "print array(5:)"
+ gdb_test "print array(:)" ".*8 = \\(1, 2, 3, 4, 5, 6, 7\\).*" "print array(:)"
+
Regards
- Wu Zhou
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: [RFA] New testcase to evaluate Fortran substring expression
2005-07-15 11:49 ` Wu Zhou
@ 2005-08-01 2:12 ` Daniel Jacobowitz
2005-08-01 4:44 ` Wu Zhou
0 siblings, 1 reply; 11+ messages in thread
From: Daniel Jacobowitz @ 2005-08-01 2:12 UTC (permalink / raw)
To: Wu Zhou; +Cc: gdb-patches
On Fri, Jul 15, 2005 at 06:25:02PM +0800, Wu Zhou wrote:
> Daniel,
>
> I made some modification to the original patch. The changes include:
>
> - Don't include "arglist : arglist, subrange". Because I don't figure
> out how to evaluate multi-dimension array section yet.
>
> - Only add a new operator: OP_F90_RANGE and get the range type wrapped by
> this operator.
>
> - Change the name of new testcase from substring to subarray. Because
> g77 will handle string variable as character array instead. (gfortran did
> this too) Added four tests for substring evaluation in gdb.fortran/exprs.exp,
> the reason is that g77 and gfortran still treat string constant as string.
>
> Please help review this too. Thanks a lot!
This is looks very good! Two comments for you:
- The magic (and undocumented) constants are not a good idea. Rather
than being clever with abs(), how about using an enum saying what
sort of range it is?
- You have a bunch of lines which are too long in eval.c; could you
fix that, please?
--
Daniel Jacobowitz
CodeSourcery, LLC
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: [RFA] New testcase to evaluate Fortran substring expression
2005-08-01 2:12 ` Daniel Jacobowitz
@ 2005-08-01 4:44 ` Wu Zhou
2005-08-01 6:23 ` Mark Kettenis
2005-08-02 3:10 ` Daniel Jacobowitz
0 siblings, 2 replies; 11+ messages in thread
From: Wu Zhou @ 2005-08-01 4:44 UTC (permalink / raw)
To: Daniel Jacobowitz; +Cc: gdb-patches
On Sun, 31 Jul 2005, Daniel Jacobowitz wrote:
> This is looks very good! Two comments for you:
>
> - The magic (and undocumented) constants are not a good idea. Rather
> than being clever with abs(), how about using an enum saying what
> sort of range it is?
What about adding the following enumeration definition to f-lang.h and
keeping the use of abs to get the number of arguments following the F90
subrange expression:
/* This enumeration type is to identify the sort of F90 subrange expression.
If only the low bound is by default, set it to -1; if both bounds are by
default, set it to 0; if only the high bound is by default, set it to 1;
if no bound is by default, set it to 2. The absolute value of the value
is also the number of arguments following this expression */
enum f90_range_type
{
LOW_BOUND_DEFAULT=-1,
BOTH_BOUND_DEFAULT,
HIGH_BOUND_DEFAULT,
NONE_BOUND_DEFAULT
};
If use other values, it might looks ugly to me to set the nargs based on
the type value respectively. What is your point on this?
>
> - You have a bunch of lines which are too long in eval.c; could you
> fix that, please?
Sorry, I am not very sure what is the maximum limit of a line in the sources
and comments. Maybe it is 72? or 80, or any other number? Maybe I can
choose to use the smaller one?
Regards
- Wu Zhou
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: [RFA] New testcase to evaluate Fortran substring expression
2005-08-01 4:44 ` Wu Zhou
@ 2005-08-01 6:23 ` Mark Kettenis
2005-08-02 3:10 ` Daniel Jacobowitz
1 sibling, 0 replies; 11+ messages in thread
From: Mark Kettenis @ 2005-08-01 6:23 UTC (permalink / raw)
To: woodzltc; +Cc: drow, gdb-patches
Date: Fri, 29 Jul 2005 16:21:37 +0800 (CST)
From: Wu Zhou <woodzltc@cn.ibm.com>
Sorry, I am not very sure what is the maximum limit of a line in the sources
and comments. Maybe it is 72? or 80, or any other number? Maybe I can
choose to use the smaller one?
We're not too strict about it. The default value for "fill-column" in
emacs is 70, so I'd say it's more 72 than 80, especially for comments.
But for code it's ok to have slightly longer lines, if it improves the
readability of your code, as long as things stay under 80. Please
don't put anything in column 80 (or 79 if you live in a non-Fortran
world ;-), because some terminals wrap as soon as you put something in
the last column.
By the way, there is a good reason for following this practice, even
if many people are using environments that can display more than 80
characters on a line. There has been quite a bit of research on
optimal line length by psychologists. Making lines to long makes
things difficult to read; people start skipping lines. Look at some
well typeset books and count the number of characters on it. You'll
end up with somthing 70-ish for most of them
Mark
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: [RFA] New testcase to evaluate Fortran substring expression
2005-08-01 4:44 ` Wu Zhou
2005-08-01 6:23 ` Mark Kettenis
@ 2005-08-02 3:10 ` Daniel Jacobowitz
2005-08-02 10:16 ` Wu Zhou
1 sibling, 1 reply; 11+ messages in thread
From: Daniel Jacobowitz @ 2005-08-02 3:10 UTC (permalink / raw)
To: Wu Zhou; +Cc: gdb-patches
Could you try again to fix your clock, please? These dates can't be
right... by the time I sent this you ought to be well on to Monday.
On Fri, Jul 29, 2005 at 04:21:37PM +0800, Wu Zhou wrote:
> On Sun, 31 Jul 2005, Daniel Jacobowitz wrote:
>
> > This is looks very good! Two comments for you:
> >
> > - The magic (and undocumented) constants are not a good idea. Rather
> > than being clever with abs(), how about using an enum saying what
> > sort of range it is?
>
> What about adding the following enumeration definition to f-lang.h and
> keeping the use of abs to get the number of arguments following the F90
> subrange expression:
>
> /* This enumeration type is to identify the sort of F90 subrange expression.
> If only the low bound is by default, set it to -1; if both bounds are by
> default, set it to 0; if only the high bound is by default, set it to 1;
> if no bound is by default, set it to 2. The absolute value of the value
> is also the number of arguments following this expression */
>
> enum f90_range_type
> {
> LOW_BOUND_DEFAULT=-1,
> BOTH_BOUND_DEFAULT,
> HIGH_BOUND_DEFAULT,
> NONE_BOUND_DEFAULT
> };
>
> If use other values, it might looks ugly to me to set the nargs based on
> the type value respectively. What is your point on this?
What's so unpleasant about:
switch (range_type)
{
case LOW_BOUND_DEFAULT:
case HIGH_BOUND_DEFAULT:
num_args = 1;
break;
case BOTH_BOUND_DEFAULT:
num_args = 0;
break;
case NONE_BOUND_DEFAULT:
num_args = 2;
break;
}
The fundamental difference is that this is self-documenting at the
point of use. You don't need to look anything up to understand what it
means.
> > - You have a bunch of lines which are too long in eval.c; could you
> > fix that, please?
>
> Sorry, I am not very sure what is the maximum limit of a line in the sources
> and comments. Maybe it is 72? or 80, or any other number? Maybe I can
> choose to use the smaller one?
As Mark said: I generally try to use 79 columns. I find 72 a little
restrictive.
--
Daniel Jacobowitz
CodeSourcery, LLC
^ permalink raw reply [flat|nested] 11+ messages in thread
* Re: [RFA] New testcase to evaluate Fortran substring expression
2005-08-02 3:10 ` Daniel Jacobowitz
@ 2005-08-02 10:16 ` Wu Zhou
0 siblings, 0 replies; 11+ messages in thread
From: Wu Zhou @ 2005-08-02 10:16 UTC (permalink / raw)
To: Daniel Jacobowitz; +Cc: gdb-patches
On Mon, 1 Aug 2005, Daniel Jacobowitz wrote:
> Could you try again to fix your clock, please? These dates can't be
> right... by the time I sent this you ought to be well on to Monday.
Yes. You are right. Really sorry for the trouble. Hope it is okay this
time.
[snip]
> What's so unpleasant about:
>
> switch (range_type)
> {
> case LOW_BOUND_DEFAULT:
> case HIGH_BOUND_DEFAULT:
> num_args = 1;
> break;
> case BOTH_BOUND_DEFAULT:
> num_args = 0;
> break;
> case NONE_BOUND_DEFAULT:
> num_args = 2;
> break;
> }
>
> The fundamental difference is that this is self-documenting at the
> point of use. You don't need to look anything up to understand what it
> means.
OK. I buy your deal. Good readablity rules here. Appended is a new
patch for this. Please review it. Thanks a lot!
The changes include:
- Add a new enumeration type named f90_range_type.
- Set the number of arguments of f90 subrange dependent on the range_type.
- Fix the long lines in eval.c.
- Remove the label "op_f77_substring" in eval.c, it is obsoleted by my patch.
- Fix a typo in subarray.exp.
Had tested it on FC4. Same result as the original patch: fix the relevant
problem and no regression.
Index: expression.h
===================================================================
RCS file: /cvs/src/src/gdb/expression.h,v
retrieving revision 1.15
diff -c -p -r1.15 expression.h
*** expression.h 8 Jun 2005 06:28:28 -0000 1.15
--- expression.h 2 Aug 2005 09:52:00 -0000
*************** enum exp_opcode
*** 324,329 ****
--- 324,332 ----
/* An Objective C Foundation Class NSString constant */
OP_OBJC_NSSTRING,
+ /* A F90 array range operator. (for "exp:exp", "exp:", ":exp" and ":") */
+ OP_F90_RANGE,
+
/* First extension operator. Individual language modules define
extra operators they need as constants with values
OP_LANGUAGE_SPECIFIC0 + k, for k >= 0, using a separate
Index: f-lang.h
===================================================================
RCS file: /cvs/src/src/gdb/f-lang.h,v
retrieving revision 1.5
diff -c -p -r1.5 f-lang.h
*** f-lang.h 9 May 2005 21:20:30 -0000 1.5
--- f-lang.h 2 Aug 2005 09:52:01 -0000
*************** extern int f_val_print (struct type *, c
*** 36,41 ****
--- 36,54 ----
/* Language-specific data structures */
+ /* In F90 subrange expression, either bound could be empty, indicating that
+ its value is by default that of the corresponding bound of the array or
+ string. So we have four sorts of subrange in F90. This enumeration type
+ is to identify this. */
+
+ enum f90_range_type
+ {
+ BOTH_BOUND_DEFAULT, /* "(:)" */
+ LOW_BOUND_DEFAULT, /* "(:high)" */
+ HIGH_BOUND_DEFAULT, /* "(low:)" */
+ NONE_BOUND_DEFAULT /* "(low:high)" */
+ };
+
struct common_entry
{
struct symbol *symbol; /* The symbol node corresponding
Index: f-exp.y
===================================================================
RCS file: /cvs/src/src/gdb/f-exp.y,v
retrieving revision 1.17
diff -c -p -r1.17 f-exp.y
*** f-exp.y 6 Jul 2005 06:52:25 -0000 1.17
--- f-exp.y 2 Aug 2005 09:52:03 -0000
*************** arglist : exp
*** 283,300 ****
{ arglist_len = 1; }
;
! arglist : substring
! { arglist_len = 2;}
;
arglist : arglist ',' exp %prec ABOVE_COMMA
{ arglist_len++; }
;
! substring: exp ':' exp %prec ABOVE_COMMA
! { }
;
complexnum: exp ',' exp
{ }
--- 283,321 ----
{ arglist_len = 1; }
;
! arglist : subrange
! { arglist_len = 1; }
;
arglist : arglist ',' exp %prec ABOVE_COMMA
{ arglist_len++; }
;
! /* There are four sorts of subrange types in F90. */
!
! subrange: exp ':' exp %prec ABOVE_COMMA
! { write_exp_elt_opcode (OP_F90_RANGE);
! write_exp_elt_longcst (NONE_BOUND_DEFAULT);
! write_exp_elt_opcode (OP_F90_RANGE); }
! ;
!
! subrange: exp ':' %prec ABOVE_COMMA
! { write_exp_elt_opcode (OP_F90_RANGE);
! write_exp_elt_longcst (HIGH_BOUND_DEFAULT);
! write_exp_elt_opcode (OP_F90_RANGE); }
;
+ subrange: ':' exp %prec ABOVE_COMMA
+ { write_exp_elt_opcode (OP_F90_RANGE);
+ write_exp_elt_longcst (LOW_BOUND_DEFAULT);
+ write_exp_elt_opcode (OP_F90_RANGE); }
+ ;
+
+ subrange: ':' %prec ABOVE_COMMA
+ { write_exp_elt_opcode (OP_F90_RANGE);
+ write_exp_elt_longcst (BOTH_BOUND_DEFAULT);
+ write_exp_elt_opcode (OP_F90_RANGE); }
+ ;
complexnum: exp ',' exp
{ }
Index: parse.c
===================================================================
RCS file: /cvs/src/src/gdb/parse.c,v
retrieving revision 1.49
diff -c -p -r1.49 parse.c
*** parse.c 29 Apr 2005 00:04:06 -0000 1.49
--- parse.c 2 Aug 2005 09:52:04 -0000
***************
*** 43,48 ****
--- 43,49 ----
#include "value.h"
#include "command.h"
#include "language.h"
+ #include "f-lang.h"
#include "parser-defs.h"
#include "gdbcmd.h"
#include "symfile.h" /* for overlay functions */
*************** operator_length_standard (struct express
*** 837,842 ****
--- 838,844 ----
{
int oplen = 1;
int args = 0;
+ enum f90_range_type range_type;
int i;
if (endpos < 1)
*************** operator_length_standard (struct express
*** 957,962 ****
--- 959,984 ----
oplen = 2;
break;
+ case OP_F90_RANGE:
+ oplen = 3;
+
+ range_type = longest_to_int (expr->elts[endpos - 2].longconst);
+ switch (range_type)
+ {
+ case LOW_BOUND_DEFAULT:
+ case HIGH_BOUND_DEFAULT:
+ args = 1;
+ break;
+ case BOTH_BOUND_DEFAULT:
+ args = 0;
+ break;
+ case NONE_BOUND_DEFAULT:
+ args = 2;
+ break;
+ }
+
+ break;
+
default:
args = 1 + (i < (int) BINOP_END);
}
Index: eval.c
===================================================================
RCS file: /cvs/src/src/gdb/eval.c,v
retrieving revision 1.58
diff -c -p -r1.58 eval.c
*** eval.c 6 Jul 2005 06:52:25 -0000 1.58
--- eval.c 2 Aug 2005 09:52:07 -0000
*************** init_array_element (struct value *array,
*** 378,383 ****
--- 378,407 ----
}
struct value *
+ value_f90_subarray (struct value *array,
+ struct expression *exp, int *pos, enum noside noside)
+ {
+ int pc = (*pos) + 1;
+ LONGEST low_bound, high_bound;
+ struct type *range = check_typedef (TYPE_INDEX_TYPE (value_type (array)));
+ enum f90_range_type range_type = longest_to_int (exp->elts[pc].longconst);
+
+ *pos += 3;
+
+ if (range_type == LOW_BOUND_DEFAULT || range_type == BOTH_BOUND_DEFAULT)
+ low_bound = TYPE_LOW_BOUND (range);
+ else
+ low_bound = value_as_long (evaluate_subexp (NULL_TYPE, exp, pos, noside));
+
+ if (range_type == HIGH_BOUND_DEFAULT || range_type == BOTH_BOUND_DEFAULT)
+ high_bound = TYPE_HIGH_BOUND (range);
+ else
+ high_bound = value_as_long (evaluate_subexp (NULL_TYPE, exp, pos, noside));
+
+ return value_slice (array, low_bound, high_bound - low_bound + 1);
+ }
+
+ struct value *
evaluate_subexp_standard (struct type *expect_type,
struct expression *exp, int *pos,
enum noside noside)
*************** evaluate_subexp_standard (struct type *e
*** 1267,1276 ****
switch (code)
{
case TYPE_CODE_ARRAY:
! goto multi_f77_subscript;
case TYPE_CODE_STRING:
! goto op_f77_substr;
case TYPE_CODE_PTR:
case TYPE_CODE_FUNC:
--- 1291,1309 ----
switch (code)
{
case TYPE_CODE_ARRAY:
! if (exp->elts[*pos].opcode == OP_F90_RANGE)
! return value_f90_subarray (arg1, exp, pos, noside);
! else
! goto multi_f77_subscript;
case TYPE_CODE_STRING:
! if (exp->elts[*pos].opcode == OP_F90_RANGE)
! return value_f90_subarray (arg1, exp, pos, noside);
! else
! {
! arg2 = evaluate_subexp_with_coercion (exp, pos, noside);
! return value_subscript (arg1, arg2);
! }
case TYPE_CODE_PTR:
case TYPE_CODE_FUNC:
*************** evaluate_subexp_standard (struct type *e
*** 1289,1315 ****
error (_("Cannot perform substring on this type"));
}
- op_f77_substr:
- /* We have a substring operation on our hands here,
- let us get the string we will be dealing with */
-
- /* Now evaluate the 'from' and 'to' */
-
- arg2 = evaluate_subexp_with_coercion (exp, pos, noside);
-
- if (nargs < 2)
- return value_subscript (arg1, arg2);
-
- arg3 = evaluate_subexp_with_coercion (exp, pos, noside);
-
- if (noside == EVAL_SKIP)
- goto nosideret;
-
- tem2 = value_as_long (arg2);
- tem3 = value_as_long (arg3);
-
- return value_slice (arg1, tem2, tem3 - tem2 + 1);
-
case OP_COMPLEX:
/* We have a complex number, There should be 2 floating
point numbers that compose it */
--- 1322,1327 ----
*** /dev/null Thu Jul 28 02:28:02 2005
--- gdb.fortran/subarray.f Thu Jul 14 13:40:35 2005
***************
*** 0 ****
--- 1,36 ----
+ c Copyright 2005 Free Software Foundation, Inc.
+
+ c This program is free software; you can redistribute it and/or modify
+ c it under the terms of the GNU General Public License as published by
+ c the Free Software Foundation; either version 2 of the License, or
+ c (at your option) any later version.
+ c
+ c This program is distributed in the hope that it will be useful,
+ c but WITHOUT ANY WARRANTY; without even the implied warranty of
+ c MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ c GNU General Public License for more details.
+ c
+ c You should have received a copy of the GNU General Public License
+ c along with this program; if not, write to the Free Software
+ c Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+
+ c Ihis file is the Fortran source file for subarray.exp. It was written
+ c by Wu Zhou. (woodzltc@cn.ibm.com)
+
+ PROGRAM subarray
+
+ character *7 str
+ integer array(7)
+
+ c Initialize character array "str" and integer array "array".
+ str = 'abcdefg'
+ do i = 1, 7
+ array(i) = i
+ end do
+
+ write (*, *) str(2:4)
+ write (*, *) str(:3)
+ write (*, *) str(5:)
+ write (*, *) str(:)
+
+ END PROGRAM
*** /dev/null Thu Jul 28 02:28:02 2005
--- gdb.fortran/subarray.exp Sat Jul 30 06:04:47 2005
***************
*** 0 ****
--- 1,66 ----
+ # Copyright 2005 Free Software Foundation, Inc.
+
+ # This program is free software; you can redistribute it and/or modify
+ # it under the terms of the GNU General Public License as published by
+ # the Free Software Foundation; either version 2 of the License, or
+ # (at your option) any later version.
+ #
+ # This program is distributed in the hope that it will be useful,
+ # but WITHOUT ANY WARRANTY; without even the implied warranty of
+ # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ # GNU General Public License for more details.
+ #
+ # You should have received a copy of the GNU General Public License
+ # along with this program; if not, write to the Free Software
+ # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+
+ # This file was written by Wu Zhou. (woodzltc@cn.ibm.com)
+
+ # This file is part of the gdb testsuite. It contains tests for evaluating
+ # Fortran subarray expression.
+
+ if $tracelevel then {
+ strace $tracelevel
+ }
+
+ set testfile "subarray"
+ set srcfile ${testfile}.f
+ set binfile ${objdir}/${subdir}/${testfile}
+
+ if { [gdb_compile "${srcdir}/${subdir}/${srcfile}" "${binfile}" executable {debug f77 quiet}] != "" } {
+ untested "Couldn't compile ${srcfile}"
+ return -1
+ }
+
+ gdb_exit
+ gdb_start
+ gdb_reinitialize_dir $srcdir/$subdir
+ gdb_load ${binfile}
+
+ if ![runto MAIN__] then {
+ perror "couldn't run to breakpoint MAIN__"
+ continue
+ }
+
+ # Try to set breakpoint at the last write statement.
+
+ set bp_location [gdb_get_line_number "str(:)"]
+ gdb_test "break $bp_location" \
+ "Breakpoint.*at.* file .*$srcfile, line $bp_location\\." \
+ "breakpoint at the last write statement"
+ gdb_test "continue" \
+ "Continuing\\..*Breakpoint.*" \
+ "continue to breakpoint"
+
+ # Test four different kinds of subarray expression evaluation.
+
+ gdb_test "print str(2:4)" ".*1 = \\(98 'b', 99 'c', 100 'd'\\).*" "print str(2:4)"
+ gdb_test "print str(:3)" ".*2 = \\(97 'a', 98 'b', 99 'c'\\).*" "print str(:3)"
+ gdb_test "print str(5:)" ".*3 = \\(101 'e', 102 'f', 103 'g'\\).*" "print str(5:)"
+ gdb_test "print str(:)" ".*4 = \\(97 'a', 98 'b', 99 'c', 100 'd', 101 'e', 102 'f', 103 'g'\\).*" "print str(:)"
+
+ gdb_test "print array(2:4)" ".*5 = \\(2, 3, 4\\).*" "print array(2:4)"
+ gdb_test "print array(:3)" ".*6 = \\(1, 2, 3\\).*" "print array(:3)"
+ gdb_test "print array(5:)" ".*7 = \\(5, 6, 7\\).*" "print array(5:)"
+ gdb_test "print array(:)" ".*8 = \\(1, 2, 3, 4, 5, 6, 7\\).*" "print array(:)"
+
Index: gdb.fortran/exprs.exp
===================================================================
RCS file: /cvs/src/src/gdb/testsuite/gdb.fortran/exprs.exp,v
retrieving revision 1.4
diff -c -p -r1.4 exprs.exp
*** gdb.fortran/exprs.exp 6 Jul 2005 06:11:54 -0000 1.4
--- gdb.fortran/exprs.exp 2 Aug 2005 09:54:35 -0000
*************** proc test_character_literals_accepted {}
*** 59,64 ****
--- 59,71 ----
# Test various character values.
gdb_test "p 'a'" " = 'a'"
+
+ # Test various substring expression.
+ gdb_test "p 'abcdefg'(2:4)" " = 'bcd'"
+ gdb_test "p 'abcdefg'(:3)" " = 'abc'"
+ gdb_test "p 'abcdefg'(5:)" " = 'efg'"
+ gdb_test "p 'abcdefg'(:)" " = 'abcdefg'"
+
}
proc test_integer_literals_rejected {} {
*************** proc test_arithmetic_expressions {} {
*** 248,255 ****
gdb_test "p 6.0 / 3" " = 2" "real divided by int"
gdb_test "p 6.0 / 3.0" " = 2" "real divided by real"
- # Test modulo with various operands
-
# Test exponentiation with various operands
gdb_test "p 2 ** 3" " = 8" "int powered by int"
--- 255,260 ----
Regards
- Wu Zhou
^ permalink raw reply [flat|nested] 11+ messages in thread
end of thread, other threads:[~2005-08-02 10:16 UTC | newest]
Thread overview: 11+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2005-06-22 4:02 [RFA] New testcase to evaluate Fortran substring expression Wu Zhou
2005-07-03 18:57 ` Daniel Jacobowitz
2005-07-09 3:12 ` Wu Zhou
2005-07-14 23:46 ` Daniel Jacobowitz
2005-07-15 5:25 ` Wu Zhou
2005-07-15 11:49 ` Wu Zhou
2005-08-01 2:12 ` Daniel Jacobowitz
2005-08-01 4:44 ` Wu Zhou
2005-08-01 6:23 ` Mark Kettenis
2005-08-02 3:10 ` Daniel Jacobowitz
2005-08-02 10:16 ` Wu Zhou
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox