aboutsummaryrefslogtreecommitdiff
path: root/gdb/f-exp.y
diff options
context:
space:
mode:
authorAndrew Burgess <andrew.burgess@embecosm.com>2021-02-09 15:46:13 +0000
committerAndrew Burgess <andrew.burgess@embecosm.com>2021-02-10 16:03:49 +0000
commite92c8eb86dcef673652644694c832c504cf9a9a9 (patch)
treeb4fb64a5caf89a02b76743fc7f99558e39df8231 /gdb/f-exp.y
parent758f590744b1cf8d1049fca3223d1817242cacb8 (diff)
downloadgdb-e92c8eb86dcef673652644694c832c504cf9a9a9.zip
gdb-e92c8eb86dcef673652644694c832c504cf9a9a9.tar.gz
gdb-e92c8eb86dcef673652644694c832c504cf9a9a9.tar.bz2
gdb/fortran: add parser support for lbound and ubound
Add support for the LBOUND and UBOUND built in functions to the Fortran expression parser. Both support taking one or two arguments. A single argument, which must be an array, returns an array containing all of the lower or upper bound data. When passed two arguments, the second argument is the dimension being asked about. In this case the result is a scalar containing the lower or upper bound just for that dimension. Some examples of usage taken from the new test: # Given: # integer, dimension (-8:-1,-10:-2) :: neg_array # (gdb) p lbound (neg_array) $1 = (-8, -10) (gdb) p lbound (neg_array, 1) $3 = -8 (gdb) p lbound (neg_array, 2) $5 = -10 gdb/ChangeLog: * f-exp.y (UNOP_OR_BINOP_INTRINSIC): New token. (exp): New pattern using UNOP_OR_BINOP_INTRINSIC. (one_or_two_args): New pattern. (f77_keywords): Add lbound and ubound. * f-lang.c (fortran_bounds_all_dims): New function. (fortran_bounds_for_dimension): New function. (evaluate_subexp_f): Handle FORTRAN_LBOUND and FORTRAN_UBOUND. (operator_length_f): Likewise. (print_subexp_f): Likewise. (dump_subexp_body_f): Likewise. (operator_check_f): Likewise. * std-operator.def (FORTRAN_LBOUND): Define. (FORTRAN_UBOUND): Define. gdb/testsuite/ChangeLog: * gdb.fortran/lbound-ubound.F90: New file. * gdb.fortran/lbound-ubound.exp: New file.
Diffstat (limited to 'gdb/f-exp.y')
-rw-r--r--gdb/f-exp.y18
1 files changed, 18 insertions, 0 deletions
diff --git a/gdb/f-exp.y b/gdb/f-exp.y
index 92a70b4..00f0df3 100644
--- a/gdb/f-exp.y
+++ b/gdb/f-exp.y
@@ -178,6 +178,7 @@ static int parse_number (struct parser_state *, const char *, int,
%token <opcode> ASSIGN_MODIFY
%token <opcode> UNOP_INTRINSIC BINOP_INTRINSIC
+%token <opcode> UNOP_OR_BINOP_INTRINSIC
%left ','
%left ABOVE_COMMA
@@ -246,6 +247,21 @@ exp : KIND '(' exp ')' %prec UNARY
{ write_exp_elt_opcode (pstate, UNOP_FORTRAN_KIND); }
;
+exp : UNOP_OR_BINOP_INTRINSIC '('
+ { pstate->start_arglist (); }
+ one_or_two_args ')'
+ { write_exp_elt_opcode (pstate, $1);
+ write_exp_elt_longcst (pstate, pstate->end_arglist ());
+ write_exp_elt_opcode (pstate, $1); }
+ ;
+
+one_or_two_args
+ : exp
+ { pstate->arglist_len = 1; }
+ | exp ',' exp
+ { pstate->arglist_len = 2; }
+ ;
+
/* No more explicit array operators, we treat everything in F77 as
a function call. The disambiguation as to whether we are
doing a subscript operation or a function call is done
@@ -1028,6 +1044,8 @@ static const struct token f77_keywords[] =
{ "ceiling", UNOP_INTRINSIC, UNOP_FORTRAN_CEILING, false },
{ "modulo", BINOP_INTRINSIC, BINOP_FORTRAN_MODULO, false },
{ "cmplx", BINOP_INTRINSIC, BINOP_FORTRAN_CMPLX, false },
+ { "lbound", UNOP_OR_BINOP_INTRINSIC, FORTRAN_LBOUND, false },
+ { "ubound", UNOP_OR_BINOP_INTRINSIC, FORTRAN_UBOUND, false },
};
/* Implementation of a dynamically expandable buffer for processing input