diff options
author | Tom Tromey <tromey@adacore.com> | 2023-06-23 06:38:55 -0600 |
---|---|---|
committer | Tom Tromey <tromey@adacore.com> | 2023-07-21 09:36:39 -0600 |
commit | b3a27d2f97aa3e21237036e50b54bbe94d19d048 (patch) | |
tree | 1e184ee007848bee5df2020548662f0584b277e4 /gdb/ada-exp.h | |
parent | 812e7caf60b11c1b9ed09f7d5eda47c2178005dc (diff) | |
download | gdb-b3a27d2f97aa3e21237036e50b54bbe94d19d048.zip gdb-b3a27d2f97aa3e21237036e50b54bbe94d19d048.tar.gz gdb-b3a27d2f97aa3e21237036e50b54bbe94d19d048.tar.bz2 |
Implement Ada target name symbol
Ada 2022 adds the "target name symbol", which can be used on the right
hand side of an assignment to refer to the left hand side. This
allows for convenient updates. This patch implements this for gdb's
Ada expression parser.
Reviewed-By: Eli Zaretskii <eliz@gnu.org>
Diffstat (limited to 'gdb/ada-exp.h')
-rw-r--r-- | gdb/ada-exp.h | 60 |
1 files changed, 60 insertions, 0 deletions
diff --git a/gdb/ada-exp.h b/gdb/ada-exp.h index dc34a43..c66c9a1 100644 --- a/gdb/ada-exp.h +++ b/gdb/ada-exp.h @@ -553,6 +553,66 @@ public: enum exp_opcode opcode () const override { return BINOP_ASSIGN; } + + value *current () + { return m_current; } + + /* A helper function for the parser to evaluate just the LHS of the + assignment. */ + value *eval_for_resolution (struct expression *exp) + { + return std::get<0> (m_storage)->evaluate (nullptr, exp, + EVAL_AVOID_SIDE_EFFECTS); + } + + /* The parser must construct the assignment node before parsing the + RHS, so that '@' can access the assignment, so this helper + function is needed to set the RHS after construction. */ + void set_rhs (operation_up rhs) + { + std::get<1> (m_storage) = std::move (rhs); + } + +private: + + /* Temporary storage for the value of the left-hand-side. */ + value *m_current = nullptr; +}; + +/* Implement the Ada target name symbol ('@'). This is used to refer + to the LHS of an assignment from the RHS. */ +class ada_target_operation : public operation +{ +public: + + explicit ada_target_operation (ada_assign_operation *lhs) + : m_lhs (lhs) + { } + + value *evaluate (struct type *expect_type, + struct expression *exp, + enum noside noside) override + { + if (noside == EVAL_AVOID_SIDE_EFFECTS) + return m_lhs->eval_for_resolution (exp); + return m_lhs->current (); + } + + enum exp_opcode opcode () const override + { + /* It doesn't really matter. */ + return OP_VAR_VALUE; + } + + void dump (struct ui_file *stream, int depth) const override + { + gdb_printf (stream, _("%*sAda target symbol '@'\n"), depth, ""); + } + +private: + + /* The left hand side of the assignment. */ + ada_assign_operation *m_lhs; }; /* This abstract class represents a single component in an Ada |