diff options
author | Tom Tromey <tom@tromey.com> | 2021-03-08 07:27:57 -0700 |
---|---|---|
committer | Tom Tromey <tom@tromey.com> | 2021-03-08 07:28:35 -0700 |
commit | ebc06ad8f4365b8881ac40760fbb8cc71b490edd (patch) | |
tree | 91145aac4d52025b624e6bbca2f3d53da95762f9 | |
parent | e8c33fa16a85801af1812bc9e6120cdf0538b401 (diff) | |
download | gdb-ebc06ad8f4365b8881ac40760fbb8cc71b490edd.zip gdb-ebc06ad8f4365b8881ac40760fbb8cc71b490edd.tar.gz gdb-ebc06ad8f4365b8881ac40760fbb8cc71b490edd.tar.bz2 |
Introduce ada_structop_operation
This adds class ada_structop_operation, which implements
STRUCTOP_STRUCT for Ada.
gdb/ChangeLog
2021-03-08 Tom Tromey <tom@tromey.com>
* ada-lang.c (ada_structop_operation::evaluate): New method.
* ada-exp.h (class ada_structop_operation): New.
-rw-r--r-- | gdb/ChangeLog | 5 | ||||
-rw-r--r-- | gdb/ada-exp.h | 16 | ||||
-rw-r--r-- | gdb/ada-lang.c | 42 |
3 files changed, 63 insertions, 0 deletions
diff --git a/gdb/ChangeLog b/gdb/ChangeLog index 5f6dcfb..781fa8b 100644 --- a/gdb/ChangeLog +++ b/gdb/ChangeLog @@ -1,5 +1,10 @@ 2021-03-08 Tom Tromey <tom@tromey.com> + * ada-lang.c (ada_structop_operation::evaluate): New method. + * ada-exp.h (class ada_structop_operation): New. + +2021-03-08 Tom Tromey <tom@tromey.com> + * ada-lang.c (ada_unop_ind_operation::evaluate): New method. * ada-exp.h (class ada_unop_ind_operation): New. diff --git a/gdb/ada-exp.h b/gdb/ada-exp.h index c87036e..34b9c1d 100644 --- a/gdb/ada-exp.h +++ b/gdb/ada-exp.h @@ -371,6 +371,22 @@ public: enum noside noside) override; }; +/* Implement STRUCTOP_STRUCT for Ada. */ +class ada_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; } +}; + } /* namespace expr */ #endif /* ADA_EXP_H */ diff --git a/gdb/ada-lang.c b/gdb/ada-lang.c index 5998ae7..915fbe3 100644 --- a/gdb/ada-lang.c +++ b/gdb/ada-lang.c @@ -10788,6 +10788,48 @@ ada_unop_ind_operation::evaluate (struct type *expect_type, return ada_value_ind (arg1); } +value * +ada_structop_operation::evaluate (struct type *expect_type, + struct expression *exp, + enum noside noside) +{ + value *arg1 = std::get<0> (m_storage)->evaluate (nullptr, exp, noside); + const char *str = std::get<1> (m_storage).c_str (); + if (noside == EVAL_AVOID_SIDE_EFFECTS) + { + struct type *type; + struct type *type1 = value_type (arg1); + + if (ada_is_tagged_type (type1, 1)) + { + type = ada_lookup_struct_elt_type (type1, str, 1, 1); + + /* If the field is not found, check if it exists in the + extension of this object's type. This means that we + need to evaluate completely the expression. */ + + if (type == NULL) + { + arg1 = std::get<0> (m_storage)->evaluate (nullptr, exp, + EVAL_NORMAL); + arg1 = ada_value_struct_elt (arg1, str, 0); + arg1 = unwrap_value (arg1); + type = value_type (ada_to_fixed_value (arg1)); + } + } + else + type = ada_lookup_struct_elt_type (type1, str, 1, 0); + + return value_zero (ada_aligned_type (type), lval_memory); + } + else + { + arg1 = ada_value_struct_elt (arg1, str, 0); + arg1 = unwrap_value (arg1); + return ada_to_fixed_value (arg1); + } +} + } /* Implement the evaluate_exp routine in the exp_descriptor structure |