gdb: add tab completion of type field names for Fortran
authorAndrew Burgess <andrew.burgess@embecosm.com>
Fri, 13 Nov 2020 18:27:42 +0000 (18:27 +0000)
committerAndrew Burgess <andrew.burgess@embecosm.com>
Sat, 14 Nov 2020 21:19:27 +0000 (21:19 +0000)
commit9dd02fc063284f59994c095ce525e1b8934b0dc1
tree54b999286c860db72841595efeeb35f80dd85724
parent758cb81029440efad398f1aba4789a18e59daee2
gdb: add tab completion of type field names for Fortran

Add support for tab-completion on Fortran field names.  Consider this
test case:

 program test
   type my_type
      integer :: field_a
      integer :: other_field
      integer :: last_field
   end type my_type

   type(my_type) :: var

   print *, var
 end program test

And the GDB session before this patch:

 (gdb) start
 ...
 (gdb) p var%                   <- Trigger TAB completion here.
 Display all 200 possibilities? (y or n) n
 (gdb) p var%

And the GDB session with this patch:

 (gdb) start
 ...
 (gdb) p var%                   <- Trigger TAB completion here.
 field_a      last_field   other_field
 (gdb) p var%

The implementation for this is basically copied from c-exp.y, I
tweaked the parser patterns to be appropriate for Fortran, and it
"just worked".

gdb/ChangeLog:

PR cli/26879
* f-exp.y (COMPLETE): New token.
(exp): Two new rules for tab-completion.
(saw_name_at_eof): New static global.
(last_was_structop): Likewise.
(yylex): Set new variables, and return COMPLETE token at the end
of the input stream in some cases.

gdb/testsuite/ChangeLog:

PR cli/26879
* gdb.fortran/completion.exp: New file.
* gdb.fortran/completion.f90: New file.
gdb/ChangeLog
gdb/f-exp.y
gdb/testsuite/ChangeLog
gdb/testsuite/gdb.fortran/completion.exp [new file with mode: 0644]
gdb/testsuite/gdb.fortran/completion.f90 [new file with mode: 0644]