2021-03-08 22:27:57 +08:00
|
|
|
/* Definitions for Fortran expressions
|
|
|
|
|
2022-01-01 22:56:03 +08:00
|
|
|
Copyright (C) 2020-2022 Free Software Foundation, Inc.
|
2021-03-08 22:27:57 +08:00
|
|
|
|
|
|
|
This file is part of GDB.
|
|
|
|
|
|
|
|
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/>. */
|
|
|
|
|
|
|
|
#ifndef FORTRAN_EXP_H
|
|
|
|
#define FORTRAN_EXP_H
|
|
|
|
|
|
|
|
#include "expop.h"
|
|
|
|
|
|
|
|
extern struct value *eval_op_f_abs (struct type *expect_type,
|
|
|
|
struct expression *exp,
|
|
|
|
enum noside noside,
|
|
|
|
enum exp_opcode opcode,
|
|
|
|
struct value *arg1);
|
|
|
|
extern struct value *eval_op_f_mod (struct type *expect_type,
|
|
|
|
struct expression *exp,
|
|
|
|
enum noside noside,
|
|
|
|
enum exp_opcode opcode,
|
|
|
|
struct value *arg1, struct value *arg2);
|
gdb/fortran: rewrite intrinsic handling and add some missing overloads
The operators FLOOR, CEILING, CMPLX, LBOUND, UBOUND, and SIZE accept
(some only with Fortran 2003) the optional parameter KIND. This
parameter determines the kind of the associated return value. So far,
implementation of this kind parameter has been missing in GDB.
Additionally, the one argument overload for the CMPLX intrinsic function
was not yet available.
This patch adds overloads for all above mentioned functions to the
Fortran intrinsics handling in GDB.
It re-writes the intrinsic function handling section to use the helper
methods wrap_unop_intrinsic/wrap_binop_intrinsic/wrap_triop_intrinsic.
These methods define the action taken when a Fortran intrinsic function
is called with a certain amount of arguments (1/2/3). The helper methods
fortran_wrap2_kind and fortran_wrap3_kind have been added as equivalents
to the existing wrap and wrap2 methods.
After adding more overloads to the intrinsics handling, some of the
operation names were no longer accurate. E.g. UNOP_FORTRAN_CEILING
has been renamed to FORTRAN_CEILING as it is no longer a purely unary
intrinsic function. This patch also introduces intrinsic functions with
one, two, or three arguments to the Fortran parser and the
UNOP_OR_BINOP_OR_TERNOP_INTRINSIC token has been added.
2022-04-11 20:06:56 +08:00
|
|
|
|
|
|
|
/* Implement expression evaluation for Fortran's CEILING intrinsic function
|
|
|
|
called with one argument. For EXPECT_TYPE, EXP, and NOSIDE see
|
|
|
|
expression::evaluate (in expression.h). OPCODE will always be
|
|
|
|
FORTRAN_CEILING and ARG1 is the argument passed to CEILING. */
|
|
|
|
|
2021-03-08 22:27:57 +08:00
|
|
|
extern struct value *eval_op_f_ceil (struct type *expect_type,
|
|
|
|
struct expression *exp,
|
|
|
|
enum noside noside,
|
|
|
|
enum exp_opcode opcode,
|
|
|
|
struct value *arg1);
|
gdb/fortran: rewrite intrinsic handling and add some missing overloads
The operators FLOOR, CEILING, CMPLX, LBOUND, UBOUND, and SIZE accept
(some only with Fortran 2003) the optional parameter KIND. This
parameter determines the kind of the associated return value. So far,
implementation of this kind parameter has been missing in GDB.
Additionally, the one argument overload for the CMPLX intrinsic function
was not yet available.
This patch adds overloads for all above mentioned functions to the
Fortran intrinsics handling in GDB.
It re-writes the intrinsic function handling section to use the helper
methods wrap_unop_intrinsic/wrap_binop_intrinsic/wrap_triop_intrinsic.
These methods define the action taken when a Fortran intrinsic function
is called with a certain amount of arguments (1/2/3). The helper methods
fortran_wrap2_kind and fortran_wrap3_kind have been added as equivalents
to the existing wrap and wrap2 methods.
After adding more overloads to the intrinsics handling, some of the
operation names were no longer accurate. E.g. UNOP_FORTRAN_CEILING
has been renamed to FORTRAN_CEILING as it is no longer a purely unary
intrinsic function. This patch also introduces intrinsic functions with
one, two, or three arguments to the Fortran parser and the
UNOP_OR_BINOP_OR_TERNOP_INTRINSIC token has been added.
2022-04-11 20:06:56 +08:00
|
|
|
|
|
|
|
/* Implement expression evaluation for Fortran's CEILING intrinsic function
|
|
|
|
called with two arguments. For EXPECT_TYPE, EXP, and NOSIDE see
|
|
|
|
expression::evaluate (in expression.h). OPCODE will always be
|
|
|
|
FORTRAN_CEILING, ARG1 is the first argument passed to CEILING, and KIND_ARG
|
|
|
|
is the type corresponding to the KIND parameter passed to CEILING. */
|
|
|
|
|
|
|
|
extern value *eval_op_f_ceil (type *expect_type, expression *exp,
|
|
|
|
noside noside, exp_opcode opcode, value *arg1,
|
|
|
|
type *kind_arg);
|
|
|
|
|
|
|
|
/* Implement expression evaluation for Fortran's FLOOR intrinsic function
|
|
|
|
called with one argument. For EXPECT_TYPE, EXP, and NOSIDE see
|
|
|
|
expression::evaluate (in expression.h). OPCODE will always be FORTRAN_FLOOR
|
|
|
|
and ARG1 is the argument passed to FLOOR. */
|
|
|
|
|
2021-03-08 22:27:57 +08:00
|
|
|
extern struct value *eval_op_f_floor (struct type *expect_type,
|
|
|
|
struct expression *exp,
|
|
|
|
enum noside noside,
|
|
|
|
enum exp_opcode opcode,
|
|
|
|
struct value *arg1);
|
gdb/fortran: rewrite intrinsic handling and add some missing overloads
The operators FLOOR, CEILING, CMPLX, LBOUND, UBOUND, and SIZE accept
(some only with Fortran 2003) the optional parameter KIND. This
parameter determines the kind of the associated return value. So far,
implementation of this kind parameter has been missing in GDB.
Additionally, the one argument overload for the CMPLX intrinsic function
was not yet available.
This patch adds overloads for all above mentioned functions to the
Fortran intrinsics handling in GDB.
It re-writes the intrinsic function handling section to use the helper
methods wrap_unop_intrinsic/wrap_binop_intrinsic/wrap_triop_intrinsic.
These methods define the action taken when a Fortran intrinsic function
is called with a certain amount of arguments (1/2/3). The helper methods
fortran_wrap2_kind and fortran_wrap3_kind have been added as equivalents
to the existing wrap and wrap2 methods.
After adding more overloads to the intrinsics handling, some of the
operation names were no longer accurate. E.g. UNOP_FORTRAN_CEILING
has been renamed to FORTRAN_CEILING as it is no longer a purely unary
intrinsic function. This patch also introduces intrinsic functions with
one, two, or three arguments to the Fortran parser and the
UNOP_OR_BINOP_OR_TERNOP_INTRINSIC token has been added.
2022-04-11 20:06:56 +08:00
|
|
|
|
|
|
|
/* Implement expression evaluation for Fortran's FLOOR intrinsic function
|
|
|
|
called with two arguments. For EXPECT_TYPE, EXP, and NOSIDE see
|
|
|
|
expression::evaluate (in expression.h). OPCODE will always be
|
|
|
|
FORTRAN_FLOOR, ARG1 is the first argument passed to FLOOR, and KIND_ARG is
|
|
|
|
the type corresponding to the KIND parameter passed to FLOOR. */
|
|
|
|
|
|
|
|
extern value *eval_op_f_floor (type *expect_type, expression *exp,
|
|
|
|
noside noside, exp_opcode opcode, value *arg1,
|
|
|
|
type *kind_arg);
|
|
|
|
|
2021-03-08 22:27:57 +08:00
|
|
|
extern struct value *eval_op_f_modulo (struct type *expect_type,
|
|
|
|
struct expression *exp,
|
|
|
|
enum noside noside,
|
|
|
|
enum exp_opcode opcode,
|
|
|
|
struct value *arg1, struct value *arg2);
|
gdb/fortran: rewrite intrinsic handling and add some missing overloads
The operators FLOOR, CEILING, CMPLX, LBOUND, UBOUND, and SIZE accept
(some only with Fortran 2003) the optional parameter KIND. This
parameter determines the kind of the associated return value. So far,
implementation of this kind parameter has been missing in GDB.
Additionally, the one argument overload for the CMPLX intrinsic function
was not yet available.
This patch adds overloads for all above mentioned functions to the
Fortran intrinsics handling in GDB.
It re-writes the intrinsic function handling section to use the helper
methods wrap_unop_intrinsic/wrap_binop_intrinsic/wrap_triop_intrinsic.
These methods define the action taken when a Fortran intrinsic function
is called with a certain amount of arguments (1/2/3). The helper methods
fortran_wrap2_kind and fortran_wrap3_kind have been added as equivalents
to the existing wrap and wrap2 methods.
After adding more overloads to the intrinsics handling, some of the
operation names were no longer accurate. E.g. UNOP_FORTRAN_CEILING
has been renamed to FORTRAN_CEILING as it is no longer a purely unary
intrinsic function. This patch also introduces intrinsic functions with
one, two, or three arguments to the Fortran parser and the
UNOP_OR_BINOP_OR_TERNOP_INTRINSIC token has been added.
2022-04-11 20:06:56 +08:00
|
|
|
|
|
|
|
/* Implement expression evaluation for Fortran's CMPLX intrinsic function
|
|
|
|
called with one argument. For EXPECT_TYPE, EXP, and NOSIDE see
|
|
|
|
expression::evaluate (in expression.h). OPCODE will always be
|
|
|
|
FORTRAN_CMPLX and ARG1 is the argument passed to CMPLX if. */
|
|
|
|
|
|
|
|
extern value *eval_op_f_cmplx (type *expect_type, expression *exp,
|
|
|
|
noside noside, exp_opcode opcode, value *arg1);
|
|
|
|
|
|
|
|
/* Implement expression evaluation for Fortran's CMPLX intrinsic function
|
|
|
|
called with two arguments. For EXPECT_TYPE, EXP, and NOSIDE see
|
|
|
|
expression::evaluate (in expression.h). OPCODE will always be
|
|
|
|
FORTRAN_CMPLX, ARG1 and ARG2 are the arguments passed to CMPLX. */
|
|
|
|
|
2021-03-08 22:27:57 +08:00
|
|
|
extern struct value *eval_op_f_cmplx (struct type *expect_type,
|
|
|
|
struct expression *exp,
|
|
|
|
enum noside noside,
|
|
|
|
enum exp_opcode opcode,
|
|
|
|
struct value *arg1, struct value *arg2);
|
gdb/fortran: rewrite intrinsic handling and add some missing overloads
The operators FLOOR, CEILING, CMPLX, LBOUND, UBOUND, and SIZE accept
(some only with Fortran 2003) the optional parameter KIND. This
parameter determines the kind of the associated return value. So far,
implementation of this kind parameter has been missing in GDB.
Additionally, the one argument overload for the CMPLX intrinsic function
was not yet available.
This patch adds overloads for all above mentioned functions to the
Fortran intrinsics handling in GDB.
It re-writes the intrinsic function handling section to use the helper
methods wrap_unop_intrinsic/wrap_binop_intrinsic/wrap_triop_intrinsic.
These methods define the action taken when a Fortran intrinsic function
is called with a certain amount of arguments (1/2/3). The helper methods
fortran_wrap2_kind and fortran_wrap3_kind have been added as equivalents
to the existing wrap and wrap2 methods.
After adding more overloads to the intrinsics handling, some of the
operation names were no longer accurate. E.g. UNOP_FORTRAN_CEILING
has been renamed to FORTRAN_CEILING as it is no longer a purely unary
intrinsic function. This patch also introduces intrinsic functions with
one, two, or three arguments to the Fortran parser and the
UNOP_OR_BINOP_OR_TERNOP_INTRINSIC token has been added.
2022-04-11 20:06:56 +08:00
|
|
|
|
|
|
|
/* Implement expression evaluation for Fortran's CMPLX intrinsic function
|
|
|
|
called with three arguments. For EXPECT_TYPE, EXP, and NOSIDE see
|
|
|
|
expression::evaluate (in expression.h). OPCODE will always be
|
|
|
|
FORTRAN_CMPLX, ARG1 and ARG2 are real and imaginary part passed to CMPLX,
|
|
|
|
and KIND_ARG is the type corresponding to the KIND parameter passed to
|
|
|
|
CMPLX. */
|
|
|
|
|
|
|
|
extern value *eval_op_f_cmplx (type *expect_type, expression *exp,
|
|
|
|
noside noside, exp_opcode opcode, value *arg1,
|
|
|
|
value *arg2, type *kind_arg);
|
|
|
|
|
2021-03-08 22:27:57 +08:00
|
|
|
extern struct value *eval_op_f_kind (struct type *expect_type,
|
|
|
|
struct expression *exp,
|
|
|
|
enum noside noside,
|
|
|
|
enum exp_opcode opcode,
|
|
|
|
struct value *arg1);
|
2021-03-08 22:27:57 +08:00
|
|
|
extern struct value *eval_op_f_associated (struct type *expect_type,
|
|
|
|
struct expression *exp,
|
|
|
|
enum noside noside,
|
|
|
|
enum exp_opcode opcode,
|
|
|
|
struct value *arg1);
|
|
|
|
extern struct value *eval_op_f_associated (struct type *expect_type,
|
|
|
|
struct expression *exp,
|
|
|
|
enum noside noside,
|
|
|
|
enum exp_opcode opcode,
|
|
|
|
struct value *arg1,
|
|
|
|
struct value *arg2);
|
2021-03-08 22:27:57 +08:00
|
|
|
extern struct value * eval_op_f_allocated (struct type *expect_type,
|
|
|
|
struct expression *exp,
|
|
|
|
enum noside noside,
|
|
|
|
enum exp_opcode op,
|
|
|
|
struct value *arg1);
|
2021-03-09 18:34:55 +08:00
|
|
|
extern struct value * eval_op_f_loc (struct type *expect_type,
|
|
|
|
struct expression *exp,
|
|
|
|
enum noside noside,
|
|
|
|
enum exp_opcode op,
|
|
|
|
struct value *arg1);
|
2021-03-08 22:27:57 +08:00
|
|
|
|
2021-02-25 19:41:57 +08:00
|
|
|
/* Implement the evaluation of UNOP_FORTRAN_RANK. EXPECTED_TYPE, EXP, and
|
|
|
|
NOSIDE are as for expression::evaluate (see expression.h). OP will
|
|
|
|
always be UNOP_FORTRAN_RANK, and ARG1 is the argument being passed to
|
|
|
|
the expression. */
|
|
|
|
|
|
|
|
extern struct value *eval_op_f_rank (struct type *expect_type,
|
|
|
|
struct expression *exp,
|
|
|
|
enum noside noside,
|
|
|
|
enum exp_opcode op,
|
|
|
|
struct value *arg1);
|
|
|
|
|
2021-02-26 00:15:52 +08:00
|
|
|
/* Implement expression evaluation for Fortran's SIZE keyword. For
|
|
|
|
EXPECT_TYPE, EXP, and NOSIDE see expression::evaluate (in
|
gdb/fortran: rewrite intrinsic handling and add some missing overloads
The operators FLOOR, CEILING, CMPLX, LBOUND, UBOUND, and SIZE accept
(some only with Fortran 2003) the optional parameter KIND. This
parameter determines the kind of the associated return value. So far,
implementation of this kind parameter has been missing in GDB.
Additionally, the one argument overload for the CMPLX intrinsic function
was not yet available.
This patch adds overloads for all above mentioned functions to the
Fortran intrinsics handling in GDB.
It re-writes the intrinsic function handling section to use the helper
methods wrap_unop_intrinsic/wrap_binop_intrinsic/wrap_triop_intrinsic.
These methods define the action taken when a Fortran intrinsic function
is called with a certain amount of arguments (1/2/3). The helper methods
fortran_wrap2_kind and fortran_wrap3_kind have been added as equivalents
to the existing wrap and wrap2 methods.
After adding more overloads to the intrinsics handling, some of the
operation names were no longer accurate. E.g. UNOP_FORTRAN_CEILING
has been renamed to FORTRAN_CEILING as it is no longer a purely unary
intrinsic function. This patch also introduces intrinsic functions with
one, two, or three arguments to the Fortran parser and the
UNOP_OR_BINOP_OR_TERNOP_INTRINSIC token has been added.
2022-04-11 20:06:56 +08:00
|
|
|
expression.h). OPCODE will always for FORTRAN_ARRAY_SIZE. ARG1 is the
|
2021-02-26 00:15:52 +08:00
|
|
|
value passed to SIZE if it is only passed a single argument. For the
|
|
|
|
two argument form see the overload of this function below. */
|
|
|
|
|
|
|
|
extern struct value *eval_op_f_array_size (struct type *expect_type,
|
|
|
|
struct expression *exp,
|
|
|
|
enum noside noside,
|
|
|
|
enum exp_opcode opcode,
|
|
|
|
struct value *arg1);
|
|
|
|
|
|
|
|
/* An overload of EVAL_OP_F_ARRAY_SIZE above, this version takes two
|
|
|
|
arguments, representing the two values passed to Fortran's SIZE
|
|
|
|
keyword. */
|
|
|
|
|
|
|
|
extern struct value *eval_op_f_array_size (struct type *expect_type,
|
|
|
|
struct expression *exp,
|
|
|
|
enum noside noside,
|
|
|
|
enum exp_opcode opcode,
|
|
|
|
struct value *arg1,
|
|
|
|
struct value *arg2);
|
|
|
|
|
gdb/fortran: rewrite intrinsic handling and add some missing overloads
The operators FLOOR, CEILING, CMPLX, LBOUND, UBOUND, and SIZE accept
(some only with Fortran 2003) the optional parameter KIND. This
parameter determines the kind of the associated return value. So far,
implementation of this kind parameter has been missing in GDB.
Additionally, the one argument overload for the CMPLX intrinsic function
was not yet available.
This patch adds overloads for all above mentioned functions to the
Fortran intrinsics handling in GDB.
It re-writes the intrinsic function handling section to use the helper
methods wrap_unop_intrinsic/wrap_binop_intrinsic/wrap_triop_intrinsic.
These methods define the action taken when a Fortran intrinsic function
is called with a certain amount of arguments (1/2/3). The helper methods
fortran_wrap2_kind and fortran_wrap3_kind have been added as equivalents
to the existing wrap and wrap2 methods.
After adding more overloads to the intrinsics handling, some of the
operation names were no longer accurate. E.g. UNOP_FORTRAN_CEILING
has been renamed to FORTRAN_CEILING as it is no longer a purely unary
intrinsic function. This patch also introduces intrinsic functions with
one, two, or three arguments to the Fortran parser and the
UNOP_OR_BINOP_OR_TERNOP_INTRINSIC token has been added.
2022-04-11 20:06:56 +08:00
|
|
|
/* Implement expression evaluation for Fortran's SIZE intrinsic function called
|
|
|
|
with three arguments. For EXPECT_TYPE, EXP, and NOSIDE see
|
|
|
|
expression::evaluate (in expression.h). OPCODE will always be
|
|
|
|
FORTRAN_ARRAY_SIZE, ARG1 and ARG2 the first two values passed to SIZE, and
|
|
|
|
KIND_ARG is the type corresponding to the KIND parameter passed to SIZE. */
|
|
|
|
|
|
|
|
extern value *eval_op_f_array_size (type *expect_type, expression *exp,
|
|
|
|
noside noside, exp_opcode opcode,
|
|
|
|
value *arg1, value *arg2, type *kind_arg);
|
|
|
|
|
2021-02-26 19:14:24 +08:00
|
|
|
/* Implement the evaluation of Fortran's SHAPE keyword. EXPECTED_TYPE,
|
|
|
|
EXP, and NOSIDE are as for expression::evaluate (see expression.h). OP
|
|
|
|
will always be UNOP_FORTRAN_SHAPE, and ARG1 is the argument being passed
|
|
|
|
to the expression. */
|
|
|
|
|
|
|
|
extern struct value *eval_op_f_array_shape (struct type *expect_type,
|
|
|
|
struct expression *exp,
|
|
|
|
enum noside noside,
|
|
|
|
enum exp_opcode op,
|
|
|
|
struct value *arg1);
|
2021-02-26 00:15:52 +08:00
|
|
|
|
2021-03-08 22:27:57 +08:00
|
|
|
namespace expr
|
|
|
|
{
|
|
|
|
|
gdb/fortran: rewrite intrinsic handling and add some missing overloads
The operators FLOOR, CEILING, CMPLX, LBOUND, UBOUND, and SIZE accept
(some only with Fortran 2003) the optional parameter KIND. This
parameter determines the kind of the associated return value. So far,
implementation of this kind parameter has been missing in GDB.
Additionally, the one argument overload for the CMPLX intrinsic function
was not yet available.
This patch adds overloads for all above mentioned functions to the
Fortran intrinsics handling in GDB.
It re-writes the intrinsic function handling section to use the helper
methods wrap_unop_intrinsic/wrap_binop_intrinsic/wrap_triop_intrinsic.
These methods define the action taken when a Fortran intrinsic function
is called with a certain amount of arguments (1/2/3). The helper methods
fortran_wrap2_kind and fortran_wrap3_kind have been added as equivalents
to the existing wrap and wrap2 methods.
After adding more overloads to the intrinsics handling, some of the
operation names were no longer accurate. E.g. UNOP_FORTRAN_CEILING
has been renamed to FORTRAN_CEILING as it is no longer a purely unary
intrinsic function. This patch also introduces intrinsic functions with
one, two, or three arguments to the Fortran parser and the
UNOP_OR_BINOP_OR_TERNOP_INTRINSIC token has been added.
2022-04-11 20:06:56 +08:00
|
|
|
/* Function prototype for Fortran intrinsic functions taking one argument and
|
|
|
|
one kind argument. */
|
|
|
|
typedef value *binary_kind_ftype (type *expect_type, expression *exp,
|
|
|
|
noside noside, exp_opcode op, value *arg1,
|
|
|
|
type *kind_arg);
|
|
|
|
|
|
|
|
/* Two-argument operation with the second argument being a kind argument. */
|
|
|
|
template<exp_opcode OP, binary_kind_ftype FUNC>
|
|
|
|
class fortran_kind_2arg
|
|
|
|
: public tuple_holding_operation<operation_up, type*>
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
|
|
|
|
using tuple_holding_operation::tuple_holding_operation;
|
|
|
|
|
|
|
|
value *evaluate (type *expect_type, expression *exp, noside noside) override
|
|
|
|
{
|
|
|
|
value *arg1 = std::get<0> (m_storage)->evaluate (nullptr, exp, noside);
|
|
|
|
type *kind_arg = std::get<1> (m_storage);
|
|
|
|
return FUNC (expect_type, exp, noside, OP, arg1, kind_arg);
|
|
|
|
}
|
|
|
|
|
|
|
|
exp_opcode opcode () const override
|
|
|
|
{ return OP; }
|
|
|
|
};
|
|
|
|
|
|
|
|
/* Function prototype for Fortran intrinsic functions taking two arguments and
|
|
|
|
one kind argument. */
|
|
|
|
typedef value *ternary_kind_ftype (type *expect_type, expression *exp,
|
|
|
|
noside noside, exp_opcode op, value *arg1,
|
|
|
|
value *arg2, type *kind_arg);
|
|
|
|
|
|
|
|
/* Three-argument operation with the third argument being a kind argument. */
|
|
|
|
template<exp_opcode OP, ternary_kind_ftype FUNC>
|
|
|
|
class fortran_kind_3arg
|
|
|
|
: public tuple_holding_operation<operation_up, operation_up, type *>
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
|
|
|
|
using tuple_holding_operation::tuple_holding_operation;
|
|
|
|
|
|
|
|
value *evaluate (type *expect_type, expression *exp, noside noside) override
|
|
|
|
{
|
|
|
|
value *arg1 = std::get<0> (m_storage)->evaluate (nullptr, exp, noside);
|
|
|
|
value *arg2 = std::get<1> (m_storage)->evaluate (nullptr, exp, noside);
|
|
|
|
type *kind_arg = std::get<2> (m_storage);
|
|
|
|
return FUNC (expect_type, exp, noside, OP, arg1, arg2, kind_arg);
|
|
|
|
}
|
|
|
|
|
|
|
|
exp_opcode opcode () const override
|
|
|
|
{ return OP; }
|
|
|
|
};
|
|
|
|
|
2021-03-08 22:27:57 +08:00
|
|
|
using fortran_abs_operation = unop_operation<UNOP_ABS, eval_op_f_abs>;
|
gdb/fortran: rewrite intrinsic handling and add some missing overloads
The operators FLOOR, CEILING, CMPLX, LBOUND, UBOUND, and SIZE accept
(some only with Fortran 2003) the optional parameter KIND. This
parameter determines the kind of the associated return value. So far,
implementation of this kind parameter has been missing in GDB.
Additionally, the one argument overload for the CMPLX intrinsic function
was not yet available.
This patch adds overloads for all above mentioned functions to the
Fortran intrinsics handling in GDB.
It re-writes the intrinsic function handling section to use the helper
methods wrap_unop_intrinsic/wrap_binop_intrinsic/wrap_triop_intrinsic.
These methods define the action taken when a Fortran intrinsic function
is called with a certain amount of arguments (1/2/3). The helper methods
fortran_wrap2_kind and fortran_wrap3_kind have been added as equivalents
to the existing wrap and wrap2 methods.
After adding more overloads to the intrinsics handling, some of the
operation names were no longer accurate. E.g. UNOP_FORTRAN_CEILING
has been renamed to FORTRAN_CEILING as it is no longer a purely unary
intrinsic function. This patch also introduces intrinsic functions with
one, two, or three arguments to the Fortran parser and the
UNOP_OR_BINOP_OR_TERNOP_INTRINSIC token has been added.
2022-04-11 20:06:56 +08:00
|
|
|
using fortran_ceil_operation_1arg = unop_operation<FORTRAN_CEILING,
|
|
|
|
eval_op_f_ceil>;
|
|
|
|
using fortran_ceil_operation_2arg = fortran_kind_2arg<FORTRAN_CEILING,
|
|
|
|
eval_op_f_ceil>;
|
|
|
|
using fortran_floor_operation_1arg = unop_operation<FORTRAN_FLOOR,
|
|
|
|
eval_op_f_floor>;
|
|
|
|
using fortran_floor_operation_2arg = fortran_kind_2arg<FORTRAN_FLOOR,
|
|
|
|
eval_op_f_floor>;
|
2021-03-08 22:27:57 +08:00
|
|
|
using fortran_kind_operation = unop_operation<UNOP_FORTRAN_KIND,
|
|
|
|
eval_op_f_kind>;
|
2021-03-08 22:27:57 +08:00
|
|
|
using fortran_allocated_operation = unop_operation<UNOP_FORTRAN_ALLOCATED,
|
|
|
|
eval_op_f_allocated>;
|
2021-03-09 18:34:55 +08:00
|
|
|
using fortran_loc_operation = unop_operation<UNOP_FORTRAN_LOC,
|
|
|
|
eval_op_f_loc>;
|
2021-03-08 22:27:57 +08:00
|
|
|
|
|
|
|
using fortran_mod_operation = binop_operation<BINOP_MOD, eval_op_f_mod>;
|
|
|
|
using fortran_modulo_operation = binop_operation<BINOP_FORTRAN_MODULO,
|
|
|
|
eval_op_f_modulo>;
|
2021-03-08 22:27:57 +08:00
|
|
|
using fortran_associated_1arg = unop_operation<FORTRAN_ASSOCIATED,
|
|
|
|
eval_op_f_associated>;
|
|
|
|
using fortran_associated_2arg = binop_operation<FORTRAN_ASSOCIATED,
|
|
|
|
eval_op_f_associated>;
|
2021-02-25 19:41:57 +08:00
|
|
|
using fortran_rank_operation = unop_operation<UNOP_FORTRAN_RANK,
|
|
|
|
eval_op_f_rank>;
|
2021-02-26 00:15:52 +08:00
|
|
|
using fortran_array_size_1arg = unop_operation<FORTRAN_ARRAY_SIZE,
|
|
|
|
eval_op_f_array_size>;
|
|
|
|
using fortran_array_size_2arg = binop_operation<FORTRAN_ARRAY_SIZE,
|
|
|
|
eval_op_f_array_size>;
|
gdb/fortran: rewrite intrinsic handling and add some missing overloads
The operators FLOOR, CEILING, CMPLX, LBOUND, UBOUND, and SIZE accept
(some only with Fortran 2003) the optional parameter KIND. This
parameter determines the kind of the associated return value. So far,
implementation of this kind parameter has been missing in GDB.
Additionally, the one argument overload for the CMPLX intrinsic function
was not yet available.
This patch adds overloads for all above mentioned functions to the
Fortran intrinsics handling in GDB.
It re-writes the intrinsic function handling section to use the helper
methods wrap_unop_intrinsic/wrap_binop_intrinsic/wrap_triop_intrinsic.
These methods define the action taken when a Fortran intrinsic function
is called with a certain amount of arguments (1/2/3). The helper methods
fortran_wrap2_kind and fortran_wrap3_kind have been added as equivalents
to the existing wrap and wrap2 methods.
After adding more overloads to the intrinsics handling, some of the
operation names were no longer accurate. E.g. UNOP_FORTRAN_CEILING
has been renamed to FORTRAN_CEILING as it is no longer a purely unary
intrinsic function. This patch also introduces intrinsic functions with
one, two, or three arguments to the Fortran parser and the
UNOP_OR_BINOP_OR_TERNOP_INTRINSIC token has been added.
2022-04-11 20:06:56 +08:00
|
|
|
using fortran_array_size_3arg = fortran_kind_3arg<FORTRAN_ARRAY_SIZE,
|
|
|
|
eval_op_f_array_size>;
|
2021-02-26 19:14:24 +08:00
|
|
|
using fortran_array_shape_operation = unop_operation<UNOP_FORTRAN_SHAPE,
|
|
|
|
eval_op_f_array_shape>;
|
gdb/fortran: rewrite intrinsic handling and add some missing overloads
The operators FLOOR, CEILING, CMPLX, LBOUND, UBOUND, and SIZE accept
(some only with Fortran 2003) the optional parameter KIND. This
parameter determines the kind of the associated return value. So far,
implementation of this kind parameter has been missing in GDB.
Additionally, the one argument overload for the CMPLX intrinsic function
was not yet available.
This patch adds overloads for all above mentioned functions to the
Fortran intrinsics handling in GDB.
It re-writes the intrinsic function handling section to use the helper
methods wrap_unop_intrinsic/wrap_binop_intrinsic/wrap_triop_intrinsic.
These methods define the action taken when a Fortran intrinsic function
is called with a certain amount of arguments (1/2/3). The helper methods
fortran_wrap2_kind and fortran_wrap3_kind have been added as equivalents
to the existing wrap and wrap2 methods.
After adding more overloads to the intrinsics handling, some of the
operation names were no longer accurate. E.g. UNOP_FORTRAN_CEILING
has been renamed to FORTRAN_CEILING as it is no longer a purely unary
intrinsic function. This patch also introduces intrinsic functions with
one, two, or three arguments to the Fortran parser and the
UNOP_OR_BINOP_OR_TERNOP_INTRINSIC token has been added.
2022-04-11 20:06:56 +08:00
|
|
|
using fortran_cmplx_operation_1arg = unop_operation<FORTRAN_CMPLX,
|
|
|
|
eval_op_f_cmplx>;
|
|
|
|
using fortran_cmplx_operation_2arg = binop_operation<FORTRAN_CMPLX,
|
|
|
|
eval_op_f_cmplx>;
|
|
|
|
using fortran_cmplx_operation_3arg = fortran_kind_3arg<FORTRAN_CMPLX,
|
|
|
|
eval_op_f_cmplx>;
|
2021-03-08 22:27:57 +08:00
|
|
|
|
2021-03-08 22:27:57 +08:00
|
|
|
/* OP_RANGE for Fortran. */
|
|
|
|
class fortran_range_operation
|
|
|
|
: public tuple_holding_operation<enum range_flag, operation_up, operation_up,
|
|
|
|
operation_up>
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
|
|
|
|
using tuple_holding_operation::tuple_holding_operation;
|
|
|
|
|
|
|
|
value *evaluate (struct type *expect_type,
|
|
|
|
struct expression *exp,
|
|
|
|
enum noside noside) override
|
|
|
|
{
|
|
|
|
error (_("ranges not allowed in this context"));
|
|
|
|
}
|
|
|
|
|
|
|
|
range_flag get_flags () const
|
|
|
|
{
|
|
|
|
return std::get<0> (m_storage);
|
|
|
|
}
|
|
|
|
|
|
|
|
value *evaluate0 (struct expression *exp, enum noside noside) const
|
|
|
|
{
|
|
|
|
return std::get<1> (m_storage)->evaluate (nullptr, exp, noside);
|
|
|
|
}
|
|
|
|
|
|
|
|
value *evaluate1 (struct expression *exp, enum noside noside) const
|
|
|
|
{
|
|
|
|
return std::get<2> (m_storage)->evaluate (nullptr, exp, noside);
|
|
|
|
}
|
|
|
|
|
|
|
|
value *evaluate2 (struct expression *exp, enum noside noside) const
|
|
|
|
{
|
|
|
|
return std::get<3> (m_storage)->evaluate (nullptr, exp, noside);
|
|
|
|
}
|
|
|
|
|
|
|
|
enum exp_opcode opcode () const override
|
|
|
|
{ return OP_RANGE; }
|
|
|
|
};
|
|
|
|
|
|
|
|
/* In F77, functions, substring ops and array subscript operations
|
|
|
|
cannot be disambiguated at parse time. This operation handles
|
|
|
|
both, deciding which do to at evaluation time. */
|
|
|
|
class fortran_undetermined
|
|
|
|
: public tuple_holding_operation<operation_up, std::vector<operation_up>>
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
|
|
|
|
using tuple_holding_operation::tuple_holding_operation;
|
|
|
|
|
|
|
|
value *evaluate (struct type *expect_type,
|
|
|
|
struct expression *exp,
|
|
|
|
enum noside noside) override;
|
|
|
|
|
|
|
|
enum exp_opcode opcode () const override
|
|
|
|
{ return OP_F77_UNDETERMINED_ARGLIST; }
|
|
|
|
|
|
|
|
private:
|
|
|
|
|
|
|
|
value *value_subarray (value *array, struct expression *exp,
|
|
|
|
enum noside noside);
|
|
|
|
};
|
|
|
|
|
2021-03-08 22:27:57 +08:00
|
|
|
/* Single-argument form of Fortran ubound/lbound intrinsics. */
|
|
|
|
class fortran_bound_1arg
|
|
|
|
: public tuple_holding_operation<exp_opcode, operation_up>
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
|
|
|
|
using tuple_holding_operation::tuple_holding_operation;
|
|
|
|
|
|
|
|
value *evaluate (struct type *expect_type,
|
|
|
|
struct expression *exp,
|
|
|
|
enum noside noside) override;
|
|
|
|
|
|
|
|
enum exp_opcode opcode () const override
|
|
|
|
{ return std::get<0> (m_storage); }
|
|
|
|
};
|
|
|
|
|
|
|
|
/* Two-argument form of Fortran ubound/lbound intrinsics. */
|
|
|
|
class fortran_bound_2arg
|
|
|
|
: public tuple_holding_operation<exp_opcode, operation_up, operation_up>
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
|
|
|
|
using tuple_holding_operation::tuple_holding_operation;
|
|
|
|
|
|
|
|
value *evaluate (struct type *expect_type,
|
|
|
|
struct expression *exp,
|
|
|
|
enum noside noside) override;
|
|
|
|
|
|
|
|
enum exp_opcode opcode () const override
|
|
|
|
{ return std::get<0> (m_storage); }
|
|
|
|
};
|
|
|
|
|
gdb/fortran: rewrite intrinsic handling and add some missing overloads
The operators FLOOR, CEILING, CMPLX, LBOUND, UBOUND, and SIZE accept
(some only with Fortran 2003) the optional parameter KIND. This
parameter determines the kind of the associated return value. So far,
implementation of this kind parameter has been missing in GDB.
Additionally, the one argument overload for the CMPLX intrinsic function
was not yet available.
This patch adds overloads for all above mentioned functions to the
Fortran intrinsics handling in GDB.
It re-writes the intrinsic function handling section to use the helper
methods wrap_unop_intrinsic/wrap_binop_intrinsic/wrap_triop_intrinsic.
These methods define the action taken when a Fortran intrinsic function
is called with a certain amount of arguments (1/2/3). The helper methods
fortran_wrap2_kind and fortran_wrap3_kind have been added as equivalents
to the existing wrap and wrap2 methods.
After adding more overloads to the intrinsics handling, some of the
operation names were no longer accurate. E.g. UNOP_FORTRAN_CEILING
has been renamed to FORTRAN_CEILING as it is no longer a purely unary
intrinsic function. This patch also introduces intrinsic functions with
one, two, or three arguments to the Fortran parser and the
UNOP_OR_BINOP_OR_TERNOP_INTRINSIC token has been added.
2022-04-11 20:06:56 +08:00
|
|
|
/* Three-argument form of Fortran ubound/lbound intrinsics. */
|
|
|
|
class fortran_bound_3arg
|
|
|
|
: public tuple_holding_operation<exp_opcode, operation_up, operation_up,
|
|
|
|
type *>
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
|
|
|
|
using tuple_holding_operation::tuple_holding_operation;
|
|
|
|
|
|
|
|
value *evaluate (type *expect_type, expression *exp, noside noside) override;
|
|
|
|
|
|
|
|
exp_opcode opcode () const override
|
|
|
|
{ return std::get<0> (m_storage); }
|
|
|
|
};
|
|
|
|
|
gdb/fortran: handle dynamic types within arrays and structures
This commit replaces this patch:
https://sourceware.org/pipermail/gdb-patches/2021-January/174933.html
which was itself a replacement for this patch:
https://sourceware.org/pipermail/gdb-patches/2020-July/170335.html
The motivation behind the original patch can be seen in the new test,
which currently gives a GDB session like this:
(gdb) ptype var8
type = Type type6
PTR TO -> ( Type type2 :: ptr_1 )
PTR TO -> ( Type type2 :: ptr_2 )
End Type type6
(gdb) ptype var8%ptr_2
type = PTR TO -> ( Type type2
integer(kind=4) :: spacer
Type type1, allocatable :: t2_array(:) <------ Issue #1
End Type type2 )
(gdb) ptype var8%ptr_2%t2_array
Cannot access memory at address 0x38 <------ Issue #2
(gdb)
Issue #1: Here we see the abstract dynamic type, rather than the
resolved concrete type. Though in some cases the user might be
interested in the abstract dynamic type, I think that in most cases
showing the resolved concrete type will be of more use. Plus, the
user can always figure out the dynamic type (by source code inspection
if nothing else) given the concrete type, but it is much harder to
figure out the concrete type given only the dynamic type.
Issue #2: In this example, GDB evaluates the expression in
EVAL_AVOID_SIDE_EFFECTS mode (due to ptype). The value returned for
var8%ptr_2 will be a non-lazy, zero value of the correct dynamic
type. However, when GDB asks about the type of t2_array this requires
GDB to access the value of var8%ptr_2 in order to read the dynamic
properties. As this value was forced to zero (thanks to the use of
EVAL_AVOID_SIDE_EFFECTS) then GDB ends up accessing memory at a base
of zero plus some offset.
Both this patch, and my previous two attempts, have all tried to
resolve this problem by stopping EVAL_AVOID_SIDE_EFFECTS replacing the
result value with a zero value in some cases.
This new patch is influenced by how Ada handles its tagged typed.
There are plenty of examples in ada-lang.c, but one specific case is
ada_structop_operation::evaluate. When GDB spots that we are dealing
with a tagged (dynamic) type, and we're in EVAL_AVOID_SIDE_EFFECTS
mode, then GDB re-evaluates the child operation in EVAL_NORMAL mode.
This commit handles two cases like this specifically for Fortran, a
new fortran_structop_operation, and the already existing
fortran_undetermined, which is where we handle array accesses.
In these two locations we spot when we are dealing with a dynamic type
and re-evaluate the child operation in EVAL_NORMAL mode so that we
are able to access the dynamic properties of the type.
The rest of this commit message is my attempt to record why my
previous patches failed.
To understand my second patch, and why it failed lets consider two
expressions, this Fortran expression:
(gdb) ptype var8%ptr_2%t2_array --<A>
Operation: STRUCTOP_STRUCT --(1)
Operation: STRUCTOP_STRUCT --(2)
Operation: OP_VAR_VALUE --(3)
Symbol: var8
Block: 0x3980ac0
String: ptr_2
String: t2_array
And this C expression:
(gdb) ptype ptr && ptr->a == 3 --<B>
Operation: BINOP_LOGICAL_AND --(4)
Operation: OP_VAR_VALUE --(5)
Symbol: ptr
Block: 0x45a2a00
Operation: BINOP_EQUAL --(6)
Operation: STRUCTOP_PTR --(7)
Operation: OP_VAR_VALUE --(8)
Symbol: ptr
Block: 0x45a2a00
String: a
Operation: OP_LONG --(9)
Type: int
Constant: 0x0000000000000003
In expression <A> we should assume that t2_array is of dynamic type.
Nothing has dynamic type in expression <B>.
This is how GDB currently handles expression <A>, in all cases,
EVAL_AVOID_SIDE_EFFECTS or EVAL_NORMAL, an OP_VAR_VALUE operation
always returns the real value of the symbol, this is not forced to a
zero value even in EVAL_AVOID_SIDE_EFFECTS mode. This means that (3),
(5), and (8) will always return a real lazy value for the symbol.
However a STRUCTOP_STRUCT will always replace its result with a
non-lazy, zero value with the same type as its result. So (2) will
lookup the field ptr_2 and create a zero value with that type. In
this case the type is a pointer to a dynamic type.
Then, when we evaluate (1) to figure out the resolved type of
t2_array, we need to read the types dynamic properties. These
properties are stored in memory relative to the objects base address,
and the base address is in var8%ptr_2, which we already figured out
has the value zero. GDB then evaluates the DWARF expressions that
take the base address, add an offset and dereference. GDB then ends
up trying to access addresses like 0x16, 0x8, etc.
To fix this, I proposed changing STRUCTOP_STRUCT so that instead of
returning a zero value we instead returned the actual value
representing the structure's field in the target. My thinking was
that GDB would not try to access the value's contents unless it needed
it to resolve a dynamic type. This belief was incorrect.
Consider expression <B>. We already know that (5) and (8) will return
real values for the symbols being referenced. The BINOP_LOGICAL_AND,
operation (4) will evaluate both of its children in
EVAL_AVOID_SIDE_EFFECTS in order to get the types, this is required
for C++ operator lookup. This means that even if the value of (5)
would result in the BINOP_LOGICAL_AND returning false (say, ptr is
NULL), we still evaluate (6) in EVAL_AVOID_SIDE_EFFECTS mode.
Operation (6) will evaluate both children in EVAL_AVOID_SIDE_EFFECTS
mode, operation (9) is easy, it just returns a value with the constant
packed into it, but (7) is where the problem lies. Currently in GDB
this STRUCTOP_STRUCT will always return a non-lazy zero value of the
correct type.
When the results of (7) and (9) are back in the BINOP_LOGICAL_AND
operation (6), the two values are passed to value_equal which performs
the comparison and returns a result. Note, the two things compared
here are the immediate value (9), and a non-lazy zero value from (7).
However, with my proposed patch operation (7) no longer returns a zero
value, instead it returns a lazy value representing the actual value
in target memory. When we call value_equal in (6) this code causes
GDB to try and fetch the actual value from target memory. If `ptr` is
NULL then this will cause GDB to access some invalid address at an
offset from zero, this will most likely fail, and cause GDB to throw
an error instead of returning the expected type.
And so, we can now describe the problem that we're facing. The way
GDB's expression evaluator is currently written we assume, when in
EVAL_AVOID_SIDE_EFFECTS mode, that any value returned from a child
operation can safely have its content read without throwing an
error. If child operations start returning real values (instead of
the fake zero values), then this is simply not true.
If we wanted to work around this then we would need to rewrite almost
all operations (I would guess) so that EVAL_AVOID_SIDE_EFFECTS mode
does not cause evaluation of an operation to try and read the value of
a child operation. As an example, consider this current GDB code from
eval.c:
struct value *
eval_op_equal (struct type *expect_type, struct expression *exp,
enum noside noside, enum exp_opcode op,
struct value *arg1, struct value *arg2)
{
if (binop_user_defined_p (op, arg1, arg2))
{
return value_x_binop (arg1, arg2, op, OP_NULL, noside);
}
else
{
binop_promote (exp->language_defn, exp->gdbarch, &arg1, &arg2);
int tem = value_equal (arg1, arg2);
struct type *type = language_bool_type (exp->language_defn,
exp->gdbarch);
return value_from_longest (type, (LONGEST) tem);
}
}
We could change this function to be this:
struct value *
eval_op_equal (struct type *expect_type, struct expression *exp,
enum noside noside, enum exp_opcode op,
struct value *arg1, struct value *arg2)
{
if (binop_user_defined_p (op, arg1, arg2))
{
return value_x_binop (arg1, arg2, op, OP_NULL, noside);
}
else
{
struct type *type = language_bool_type (exp->language_defn,
exp->gdbarch);
if (noside == EVAL_AVOID_SIDE_EFFECTS)
return value_zero (type, VALUE_LVAL (arg1));
else
{
binop_promote (exp->language_defn, exp->gdbarch, &arg1, &arg2);
int tem = value_equal (arg1, arg2);
return value_from_longest (type, (LONGEST) tem);
}
}
}
Now we don't call value_equal unless we really need to. However, we
would need to make the same, or similar change to almost all
operations, which would be a big task, and might not be a direction we
wanted to take GDB in.
So, for now, I'm proposing we go with the more targeted, Fortran
specific solution, that does the minimal required in order to
correctly resolve the dynamic types.
gdb/ChangeLog:
* f-exp.h (class fortran_structop_operation): New class.
* f-exp.y (exp): Create fortran_structop_operation instead of the
generic structop_operation.
* f-lang.c (fortran_undetermined::evaluate): Re-evaluate
expression as EVAL_NORMAL if the result type was dynamic so we can
extract the actual array bounds.
(fortran_structop_operation::evaluate): New function.
gdb/testsuite/ChangeLog:
* gdb.fortran/dynamic-ptype-whatis.exp: New file.
* gdb.fortran/dynamic-ptype-whatis.f90: New file.
2021-01-08 21:07:32 +08:00
|
|
|
/* Implement STRUCTOP_STRUCT for Fortran. */
|
|
|
|
class fortran_structop_operation
|
|
|
|
: public structop_base_operation
|
|
|
|
{
|
|
|
|
public:
|
|
|
|
|
|
|
|
using structop_base_operation::structop_base_operation;
|
|
|
|
|
|
|
|
value *evaluate (struct type *expect_type,
|
|
|
|
struct expression *exp,
|
|
|
|
enum noside noside) override;
|
|
|
|
|
|
|
|
enum exp_opcode opcode () const override
|
|
|
|
{ return STRUCTOP_STRUCT; }
|
|
|
|
};
|
|
|
|
|
2021-03-08 22:27:57 +08:00
|
|
|
} /* namespace expr */
|
|
|
|
|
|
|
|
#endif /* FORTRAN_EXP_H */
|