diff options
author | Andrew Burgess <andrew.burgess@embecosm.com> | 2019-01-16 16:42:10 +0000 |
---|---|---|
committer | Andrew Burgess <andrew.burgess@embecosm.com> | 2019-03-06 18:11:31 +0000 |
commit | 4d00f5d8f6c4a1c9f334b1abb45b9ce05fb45b0a (patch) | |
tree | 24f8cddb29a1036f7f0f23d6a2178f593a2daeef /gdb/testsuite | |
parent | e454224fa82aa52a1288a3d6a2e26e8d224d732a (diff) | |
download | gdb-4d00f5d8f6c4a1c9f334b1abb45b9ce05fb45b0a.zip gdb-4d00f5d8f6c4a1c9f334b1abb45b9ce05fb45b0a.tar.gz gdb-4d00f5d8f6c4a1c9f334b1abb45b9ce05fb45b0a.tar.bz2 |
gdb/fortran: Add Fortran 'kind' intrinsic and keyword
The 'kind' keyword has two uses in Fortran, it is the name of a
builtin intrinsic function, and it is also a keyword used to create a
type of a specific kind.
This commit adds support for using kind as an intrinsic function, and
also adds some initial support for using kind to create types of a
specific kind.
This commit only allows the creation of the type 'character(kind=1)',
however, it will be easy enough to extend this in future to support
more type kinds.
The kind of any expression can be queried using the kind intrinsic
function. At the moment the kind returned corresponds to the size of
the type, this matches how gfortran handles kinds. However, the
correspondence between kind and type size depends on the compiler
and/or the specific target, so this might not be correct for
everyone. If we want to support different compilers/targets in future
the code to compute the kind from a type will need to be updated.
gdb/ChangeLog:
* expprint.c (dump_subexp_body_standard): Support UNOP_KIND.
* f-exp.y: Define 'KIND' token.
(exp): New pattern for KIND expressions.
(ptype): Handle types with a kind extension.
(direct_abs_decl): Extend to spot kind extensions.
(f77_keywords): Add 'kind' to the list.
(push_kind_type): New function.
(convert_to_kind_type): New function.
* f-lang.c (evaluate_subexp_f): Support UNOP_KIND.
* parse.c (operator_length_standard): Likewise.
* parser-defs.h (enum type_pieces): Add tp_kind.
* std-operator.def: Add UNOP_KIND.
gdb/testsuite/ChangeLog:
* gdb.fortran/intrinsics.exp: New file.
* gdb.fortran/intrinsics.f90: New file.
* gdb.fortran/type-kinds.exp: New file.
Diffstat (limited to 'gdb/testsuite')
-rw-r--r-- | gdb/testsuite/ChangeLog | 6 | ||||
-rw-r--r-- | gdb/testsuite/gdb.fortran/intrinsics.exp | 42 | ||||
-rw-r--r-- | gdb/testsuite/gdb.fortran/intrinsics.f90 | 39 | ||||
-rw-r--r-- | gdb/testsuite/gdb.fortran/type-kinds.exp | 35 |
4 files changed, 122 insertions, 0 deletions
diff --git a/gdb/testsuite/ChangeLog b/gdb/testsuite/ChangeLog index 296f03d..221e300 100644 --- a/gdb/testsuite/ChangeLog +++ b/gdb/testsuite/ChangeLog @@ -1,5 +1,11 @@ 2019-03-06 Andrew Burgess <andrew.burgess@embecosm.com> + * gdb.fortran/intrinsics.exp: New file. + * gdb.fortran/intrinsics.f90: New file. + * gdb.fortran/type-kinds.exp: New file. + +2019-03-06 Andrew Burgess <andrew.burgess@embecosm.com> + * gdb.fortran/dot-ops.exp: New file. 2019-03-06 Andrew Burgess <andrew.burgess@embecosm.com> diff --git a/gdb/testsuite/gdb.fortran/intrinsics.exp b/gdb/testsuite/gdb.fortran/intrinsics.exp new file mode 100644 index 0000000..674f299 --- /dev/null +++ b/gdb/testsuite/gdb.fortran/intrinsics.exp @@ -0,0 +1,42 @@ +# Copyright 2019 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 3 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, see <http://www.gnu.org/licenses/>. + +# This file tests GDB's handling of Fortran builtin intrinsic functions. + +load_lib "fortran.exp" + +if { [skip_fortran_tests] } { continue } + +standard_testfile .f90 + +if { [prepare_for_testing "failed to prepare" $testfile $srcfile {debug f90}] } { + return -1 +} + +if { ![runto MAIN__] } { + perror "Could not run to breakpoint `MAIN__'." + continue +} + +gdb_breakpoint [gdb_get_line_number "stop-here"] +gdb_continue_to_breakpoint "stop-here" ".*stop-here.*" + +# Test KIND + +gdb_test "p kind (l1)" " = 1" +gdb_test "p kind (l2)" " = 2" +gdb_test "p kind (l4)" " = 4" +gdb_test "p kind (l8)" " = 8" +gdb_test "p kind (s1)" "argument to kind must be an intrinsic type" diff --git a/gdb/testsuite/gdb.fortran/intrinsics.f90 b/gdb/testsuite/gdb.fortran/intrinsics.f90 new file mode 100644 index 0000000..1be22ba --- /dev/null +++ b/gdb/testsuite/gdb.fortran/intrinsics.f90 @@ -0,0 +1,39 @@ +! Copyright 2019 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 3 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, see <http://www.gnu.org/licenses/>. + +program test + logical :: l + logical (kind=1) :: l1 + logical (kind=2) :: l2 + logical (kind=4) :: l4 + logical (kind=8) :: l8 + + type :: a_struct + logical :: a1 + logical :: a2 + end type a_struct + + type (a_struct) :: s1 + + s1%a1 = .TRUE. + s1%a2 = .FALSE. + + l1 = .TRUE. + l2 = .TRUE. + l4 = .TRUE. + l8 = .TRUE. + + l = .FALSE. ! stop-here +end diff --git a/gdb/testsuite/gdb.fortran/type-kinds.exp b/gdb/testsuite/gdb.fortran/type-kinds.exp new file mode 100644 index 0000000..b60b804 --- /dev/null +++ b/gdb/testsuite/gdb.fortran/type-kinds.exp @@ -0,0 +1,35 @@ +# Copyright 2019 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 3 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, see <http://www.gnu.org/licenses/>. + +# This is a set of tests related to GDB's ability to parse and +# correctly handle the (kind=N) type adjustment mechanism within +# Fortran. + +load_lib "fortran.exp" + +if { [skip_fortran_tests] } { continue } + +# Test parsing of `(kind=N)` type modifiers. +proc test_basic_parsing_of_type_kinds {} { + gdb_test "p ((character (kind=1)) 1)" " = 1" +} + +clean_restart + +if [set_lang_fortran] then { + test_basic_parsing_of_type_kinds +} else { + warning "$test_name tests suppressed." 0 +} |