gdb/fortran: add parser support for lbound and ubound
authorAndrew Burgess <andrew.burgess@embecosm.com>
Tue, 9 Feb 2021 15:46:13 +0000 (15:46 +0000)
committerAndrew Burgess <andrew.burgess@embecosm.com>
Wed, 10 Feb 2021 16:03:49 +0000 (16:03 +0000)
commite92c8eb86dcef673652644694c832c504cf9a9a9
treeb4fb64a5caf89a02b76743fc7f99558e39df8231
parent758f590744b1cf8d1049fca3223d1817242cacb8
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.
gdb/ChangeLog
gdb/f-exp.y
gdb/f-lang.c
gdb/std-operator.def
gdb/testsuite/ChangeLog
gdb/testsuite/gdb.fortran/lbound-ubound.F90 [new file with mode: 0644]
gdb/testsuite/gdb.fortran/lbound-ubound.exp [new file with mode: 0644]