From 7ba155b37073a3512c85f1d7f12dbaed9a6db3e2 Mon Sep 17 00:00:00 2001 From: Andrew Burgess Date: Thu, 25 Feb 2021 16:15:52 +0000 Subject: gdb/fortran: add support for 'SIZE' keyword Add support for the 'SIZE' keyword to the Fortran expression parser. This returns the number of elements either in an entire array (passing a single argument to SIZE), or in a particular dimension of an array (passing two arguments to SIZE). At this point I have not added support for the optional third argument to SIZE, which controls the exact integer type of the result. gdb/ChangeLog: * f-exp.y (eval_op_f_array_size): Declare 1 and 2 argument forms of this function. (expr::fortran_array_size_1arg): New type. (expr::fortran_array_size_2arg): Likewise. * f-exp.y (exp): Handle FORTRAN_ARRAY_SIZE after parsing UNOP_OR_BINOP_INTRINSIC. (f77_keywords): Add "size" keyword. * f-lang.c (fortran_array_size): New function. (eval_op_f_array_size): New function, has a 1 arg and 2 arg form. * std-operator.def (FORTRAN_ARRAY_SIZE): New operator. gdb/testsuite/ChangeLog: * gdb.fortran/size.exp: New file. * gdb.fortran/size.f90: New file. --- gdb/f-exp.y | 8 ++++++++ 1 file changed, 8 insertions(+) (limited to 'gdb/f-exp.y') diff --git a/gdb/f-exp.y b/gdb/f-exp.y index 02e35c8..e652bd9 100644 --- a/gdb/f-exp.y +++ b/gdb/f-exp.y @@ -260,6 +260,13 @@ exp : UNOP_OR_BINOP_INTRINSIC '(' else pstate->wrap2 (); } + else if ($1 == FORTRAN_ARRAY_SIZE) + { + if (n == 1) + pstate->wrap (); + else + pstate->wrap2 (); + } else { std::vector args @@ -1143,6 +1150,7 @@ static const struct token f77_keywords[] = { "allocated", UNOP_INTRINSIC, UNOP_FORTRAN_ALLOCATED, false }, { "associated", UNOP_OR_BINOP_INTRINSIC, FORTRAN_ASSOCIATED, false }, { "rank", UNOP_INTRINSIC, UNOP_FORTRAN_RANK, false }, + { "size", UNOP_OR_BINOP_INTRINSIC, FORTRAN_ARRAY_SIZE, false }, }; /* Implementation of a dynamically expandable buffer for processing input -- cgit v1.1