Home | History | Annotate | Line # | Download | only in gdb
ada-exp.h revision 1.1.1.2
      1 /* Definitions for Ada expressions
      2 
      3    Copyright (C) 2020-2024 Free Software Foundation, Inc.
      4 
      5    This file is part of GDB.
      6 
      7    This program is free software; you can redistribute it and/or modify
      8    it under the terms of the GNU General Public License as published by
      9    the Free Software Foundation; either version 3 of the License, or
     10    (at your option) any later version.
     11 
     12    This program is distributed in the hope that it will be useful,
     13    but WITHOUT ANY WARRANTY; without even the implied warranty of
     14    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
     15    GNU General Public License for more details.
     16 
     17    You should have received a copy of the GNU General Public License
     18    along with this program.  If not, see <http://www.gnu.org/licenses/>.  */
     19 
     20 #ifndef ADA_EXP_H
     21 #define ADA_EXP_H
     22 
     23 #include "expop.h"
     24 
     25 extern struct value *ada_unop_neg (struct type *expect_type,
     26 				   struct expression *exp,
     27 				   enum noside noside, enum exp_opcode op,
     28 				   struct value *arg1);
     29 extern struct value *ada_atr_tag (struct type *expect_type,
     30 				  struct expression *exp,
     31 				  enum noside noside, enum exp_opcode op,
     32 				  struct value *arg1);
     33 extern struct value *ada_atr_size (struct type *expect_type,
     34 				   struct expression *exp,
     35 				   enum noside noside, enum exp_opcode op,
     36 				   struct value *arg1);
     37 extern struct value *ada_abs (struct type *expect_type,
     38 			      struct expression *exp,
     39 			      enum noside noside, enum exp_opcode op,
     40 			      struct value *arg1);
     41 extern struct value *ada_unop_in_range (struct type *expect_type,
     42 					struct expression *exp,
     43 					enum noside noside, enum exp_opcode op,
     44 					struct value *arg1, struct type *type);
     45 extern struct value *ada_mult_binop (struct type *expect_type,
     46 				     struct expression *exp,
     47 				     enum noside noside, enum exp_opcode op,
     48 				     struct value *arg1, struct value *arg2);
     49 extern struct value *ada_equal_binop (struct type *expect_type,
     50 				      struct expression *exp,
     51 				      enum noside noside, enum exp_opcode op,
     52 				      struct value *arg1, struct value *arg2);
     53 extern struct value *ada_ternop_slice (struct expression *exp,
     54 				       enum noside noside,
     55 				       struct value *array,
     56 				       struct value *low_bound_val,
     57 				       struct value *high_bound_val);
     58 extern struct value *ada_binop_in_bounds (struct expression *exp,
     59 					  enum noside noside,
     60 					  struct value *arg1,
     61 					  struct value *arg2,
     62 					  int n);
     63 extern struct value *ada_binop_minmax (struct type *expect_type,
     64 				       struct expression *exp,
     65 				       enum noside noside, enum exp_opcode op,
     66 				       struct value *arg1,
     67 				       struct value *arg2);
     68 extern struct value *ada_pos_atr (struct type *expect_type,
     69 				  struct expression *exp,
     70 				  enum noside noside, enum exp_opcode op,
     71 				  struct value *arg);
     72 extern struct value *ada_atr_enum_rep (struct expression *exp,
     73 				       enum noside noside, struct type *type,
     74 				       struct value *arg);
     75 extern struct value *ada_atr_enum_val (struct expression *exp,
     76 				       enum noside noside, struct type *type,
     77 				       struct value *arg);
     78 extern struct value *ada_val_atr (struct expression *exp,
     79 				  enum noside noside, struct type *type,
     80 				  struct value *arg);
     81 extern struct value *ada_binop_exp (struct type *expect_type,
     82 				    struct expression *exp,
     83 				    enum noside noside, enum exp_opcode op,
     84 				    struct value *arg1, struct value *arg2);
     85 
     86 namespace expr
     87 {
     88 
     89 /* The base class for Ada type resolution.  Ada operations that want
     90    to participate in resolution implement this interface.  */
     91 struct ada_resolvable
     92 {
     93   /* Resolve this object.  EXP is the expression being resolved.
     94      DEPROCEDURE_P is true if a symbol that refers to a zero-argument
     95      function may be turned into a function call.  PARSE_COMPLETION
     96      and TRACKER are passed in from the parser context.  CONTEXT_TYPE
     97      is the expected type of the expression, or nullptr if none is
     98      known.  This method should return true if the operation should be
     99      replaced by a function call with this object as the callee.  */
    100   virtual bool resolve (struct expression *exp,
    101 			bool deprocedure_p,
    102 			bool parse_completion,
    103 			innermost_block_tracker *tracker,
    104 			struct type *context_type) = 0;
    105 
    106   /* Possibly replace this object with some other expression object.
    107      This is like 'resolve', but can return a replacement.
    108 
    109      The default implementation calls 'resolve' and wraps this object
    110      in a function call if that call returns true.  OWNER is a
    111      reference to the unique pointer that owns the 'this'; it can be
    112      'move'd from to construct the replacement.
    113 
    114      This should either return a new object, or OWNER -- never
    115      nullptr.  */
    116 
    117   virtual operation_up replace (operation_up &&owner,
    118 				struct expression *exp,
    119 				bool deprocedure_p,
    120 				bool parse_completion,
    121 				innermost_block_tracker *tracker,
    122 				struct type *context_type);
    123 };
    124 
    125 /* In Ada, some generic operations must be wrapped with a handler that
    126    handles some Ada-specific type conversions.  */
    127 class ada_wrapped_operation
    128   : public tuple_holding_operation<operation_up>
    129 {
    130 public:
    131 
    132   using tuple_holding_operation::tuple_holding_operation;
    133 
    134   value *evaluate (struct type *expect_type,
    135 		   struct expression *exp,
    136 		   enum noside noside) override;
    137 
    138   enum exp_opcode opcode () const override
    139   { return std::get<0> (m_storage)->opcode (); }
    140 
    141 protected:
    142 
    143   void do_generate_ax (struct expression *exp,
    144 		       struct agent_expr *ax,
    145 		       struct axs_value *value,
    146 		       struct type *cast_type)
    147     override;
    148 };
    149 
    150 /* An Ada string constant.  */
    151 class ada_string_operation
    152   : public string_operation
    153 {
    154 public:
    155 
    156   using string_operation::string_operation;
    157 
    158   /* Return the underlying string.  */
    159   const char *get_name () const
    160   {
    161     return std::get<0> (m_storage).c_str ();
    162   }
    163 
    164   value *evaluate (struct type *expect_type,
    165 		   struct expression *exp,
    166 		   enum noside noside) override;
    167 };
    168 
    169 /* The Ada TYPE'(EXP) construct.  */
    170 class ada_qual_operation
    171   : public tuple_holding_operation<operation_up, struct type *>
    172 {
    173 public:
    174 
    175   using tuple_holding_operation::tuple_holding_operation;
    176 
    177   value *evaluate (struct type *expect_type,
    178 		   struct expression *exp,
    179 		   enum noside noside) override;
    180 
    181   enum exp_opcode opcode () const override
    182   { return UNOP_QUAL; }
    183 };
    184 
    185 /* Ternary in-range operator.  */
    186 class ada_ternop_range_operation
    187   : public tuple_holding_operation<operation_up, operation_up, operation_up>
    188 {
    189 public:
    190 
    191   using tuple_holding_operation::tuple_holding_operation;
    192 
    193   value *evaluate (struct type *expect_type,
    194 		   struct expression *exp,
    195 		   enum noside noside) override;
    196 
    197   enum exp_opcode opcode () const override
    198   { return TERNOP_IN_RANGE; }
    199 };
    200 
    201 using ada_neg_operation = unop_operation<UNOP_NEG, ada_unop_neg>;
    202 using ada_atr_tag_operation = unop_operation<OP_ATR_TAG, ada_atr_tag>;
    203 using ada_atr_size_operation = unop_operation<OP_ATR_SIZE, ada_atr_size>;
    204 using ada_abs_operation = unop_operation<UNOP_ABS, ada_abs>;
    205 using ada_pos_operation = unop_operation<OP_ATR_POS, ada_pos_atr>;
    206 
    207 /* The in-range operation, given a type.  */
    208 class ada_unop_range_operation
    209   : public tuple_holding_operation<operation_up, struct type *>
    210 {
    211 public:
    212 
    213   using tuple_holding_operation::tuple_holding_operation;
    214 
    215   value *evaluate (struct type *expect_type,
    216 		   struct expression *exp,
    217 		   enum noside noside) override
    218   {
    219     value *val = std::get<0> (m_storage)->evaluate (nullptr, exp, noside);
    220     return ada_unop_in_range (expect_type, exp, noside, UNOP_IN_RANGE,
    221 			      val, std::get<1> (m_storage));
    222   }
    223 
    224   enum exp_opcode opcode () const override
    225   { return UNOP_IN_RANGE; }
    226 };
    227 
    228 /* The Ada + and - operators.  */
    229 class ada_binop_addsub_operation
    230   : public tuple_holding_operation<enum exp_opcode, operation_up, operation_up>
    231 {
    232 public:
    233 
    234   using tuple_holding_operation::tuple_holding_operation;
    235 
    236   value *evaluate (struct type *expect_type,
    237 		   struct expression *exp,
    238 		   enum noside noside) override;
    239 
    240   enum exp_opcode opcode () const override
    241   { return std::get<0> (m_storage); }
    242 };
    243 
    244 using ada_binop_mul_operation = binop_operation<BINOP_MUL, ada_mult_binop>;
    245 using ada_binop_div_operation = binop_operation<BINOP_DIV, ada_mult_binop>;
    246 using ada_binop_rem_operation = binop_operation<BINOP_REM, ada_mult_binop>;
    247 using ada_binop_mod_operation = binop_operation<BINOP_MOD, ada_mult_binop>;
    248 
    249 using ada_binop_min_operation = binop_operation<BINOP_MIN, ada_binop_minmax>;
    250 using ada_binop_max_operation = binop_operation<BINOP_MAX, ada_binop_minmax>;
    251 
    252 using ada_binop_exp_operation = binop_operation<BINOP_EXP, ada_binop_exp>;
    253 
    254 /* Implement the equal and not-equal operations for Ada.  */
    255 class ada_binop_equal_operation
    256   : public tuple_holding_operation<enum exp_opcode, operation_up, operation_up>
    257 {
    258 public:
    259 
    260   using tuple_holding_operation::tuple_holding_operation;
    261 
    262   value *evaluate (struct type *expect_type,
    263 		   struct expression *exp,
    264 		   enum noside noside) override
    265   {
    266     value *arg1 = std::get<1> (m_storage)->evaluate (nullptr, exp, noside);
    267     value *arg2 = std::get<2> (m_storage)->evaluate (arg1->type (),
    268 						     exp, noside);
    269     return ada_equal_binop (expect_type, exp, noside, std::get<0> (m_storage),
    270 			    arg1, arg2);
    271   }
    272 
    273   void do_generate_ax (struct expression *exp,
    274 		       struct agent_expr *ax,
    275 		       struct axs_value *value,
    276 		       struct type *cast_type)
    277     override
    278   {
    279     gen_expr_binop (exp, opcode (),
    280 		    std::get<1> (this->m_storage).get (),
    281 		    std::get<2> (this->m_storage).get (),
    282 		    ax, value);
    283   }
    284 
    285   enum exp_opcode opcode () const override
    286   { return std::get<0> (m_storage); }
    287 };
    288 
    289 /* Ada array- or string-slice operation.  */
    290 class ada_ternop_slice_operation
    291   : public maybe_constant_operation<operation_up, operation_up, operation_up>,
    292     public ada_resolvable
    293 {
    294 public:
    295 
    296   using maybe_constant_operation::maybe_constant_operation;
    297 
    298   value *evaluate (struct type *expect_type,
    299 		   struct expression *exp,
    300 		   enum noside noside) override
    301   {
    302     value *array = std::get<0> (m_storage)->evaluate (nullptr, exp, noside);
    303     value *low = std::get<1> (m_storage)->evaluate (nullptr, exp, noside);
    304     value *high = std::get<2> (m_storage)->evaluate (nullptr, exp, noside);
    305     return ada_ternop_slice (exp, noside, array, low, high);
    306   }
    307 
    308   enum exp_opcode opcode () const override
    309   { return TERNOP_SLICE; }
    310 
    311   bool resolve (struct expression *exp,
    312 		bool deprocedure_p,
    313 		bool parse_completion,
    314 		innermost_block_tracker *tracker,
    315 		struct type *context_type) override;
    316 };
    317 
    318 /* Implement BINOP_IN_BOUNDS for Ada.  */
    319 class ada_binop_in_bounds_operation
    320   : public maybe_constant_operation<operation_up, operation_up, int>
    321 {
    322 public:
    323 
    324   using maybe_constant_operation::maybe_constant_operation;
    325 
    326   value *evaluate (struct type *expect_type,
    327 		   struct expression *exp,
    328 		   enum noside noside) override
    329   {
    330     value *arg1 = std::get<0> (m_storage)->evaluate (nullptr, exp, noside);
    331     value *arg2 = std::get<1> (m_storage)->evaluate (nullptr, exp, noside);
    332     return ada_binop_in_bounds (exp, noside, arg1, arg2,
    333 				std::get<2> (m_storage));
    334   }
    335 
    336   enum exp_opcode opcode () const override
    337   { return BINOP_IN_BOUNDS; }
    338 };
    339 
    340 /* Implement several unary Ada OP_ATR_* operations.  */
    341 class ada_unop_atr_operation
    342   : public maybe_constant_operation<operation_up, enum exp_opcode, int>
    343 {
    344 public:
    345 
    346   using maybe_constant_operation::maybe_constant_operation;
    347 
    348   value *evaluate (struct type *expect_type,
    349 		   struct expression *exp,
    350 		   enum noside noside) override;
    351 
    352   enum exp_opcode opcode () const override
    353   { return std::get<1> (m_storage); }
    354 };
    355 
    356 /* Variant of var_value_operation for Ada.  */
    357 class ada_var_value_operation
    358   : public var_value_operation, public ada_resolvable
    359 {
    360 public:
    361 
    362   using var_value_operation::var_value_operation;
    363 
    364   value *evaluate (struct type *expect_type,
    365 		   struct expression *exp,
    366 		   enum noside noside) override;
    367 
    368   value *evaluate_for_cast (struct type *expect_type,
    369 			    struct expression *exp,
    370 			    enum noside noside) override;
    371 
    372   const block *get_block () const
    373   { return std::get<0> (m_storage).block; }
    374 
    375   bool resolve (struct expression *exp,
    376 		bool deprocedure_p,
    377 		bool parse_completion,
    378 		innermost_block_tracker *tracker,
    379 		struct type *context_type) override;
    380 
    381 protected:
    382 
    383   void do_generate_ax (struct expression *exp,
    384 		       struct agent_expr *ax,
    385 		       struct axs_value *value,
    386 		       struct type *cast_type)
    387     override;
    388 };
    389 
    390 /* Variant of var_msym_value_operation for Ada.  */
    391 class ada_var_msym_value_operation
    392   : public var_msym_value_operation
    393 {
    394 public:
    395 
    396   using var_msym_value_operation::var_msym_value_operation;
    397 
    398   value *evaluate_for_cast (struct type *expect_type,
    399 			    struct expression *exp,
    400 			    enum noside noside) override;
    401 
    402 protected:
    403 
    404   using operation::do_generate_ax;
    405 };
    406 
    407 typedef struct value *ada_atr_ftype (struct expression *exp,
    408 				     enum noside noside,
    409 				     struct type *type,
    410 				     struct value *arg);
    411 
    412 /* Implement several Ada attributes.  */
    413 template<ada_atr_ftype FUNC>
    414 class ada_atr_operation
    415   : public tuple_holding_operation<struct type *, operation_up>
    416 {
    417 public:
    418 
    419   using tuple_holding_operation::tuple_holding_operation;
    420 
    421   value *evaluate (struct type *expect_type,
    422 		   struct expression *exp,
    423 		   enum noside noside) override
    424   {
    425     value *arg = std::get<1> (m_storage)->evaluate (nullptr, exp, noside);
    426     return FUNC (exp, noside, std::get<0> (m_storage), arg);
    427   }
    428 
    429   enum exp_opcode opcode () const override
    430   {
    431     /* The value here generally doesn't matter.  */
    432     return OP_ATR_VAL;
    433   }
    434 };
    435 
    436 using ada_atr_val_operation = ada_atr_operation<ada_val_atr>;
    437 using ada_atr_enum_rep_operation = ada_atr_operation<ada_atr_enum_rep>;
    438 using ada_atr_enum_val_operation = ada_atr_operation<ada_atr_enum_val>;
    439 
    440 /* The indirection operator for Ada.  */
    441 class ada_unop_ind_operation
    442   : public unop_ind_base_operation
    443 {
    444 public:
    445 
    446   using unop_ind_base_operation::unop_ind_base_operation;
    447 
    448   value *evaluate (struct type *expect_type,
    449 		   struct expression *exp,
    450 		   enum noside noside) override;
    451 };
    452 
    453 /* Implement STRUCTOP_STRUCT for Ada.  */
    454 class ada_structop_operation
    455   : public structop_base_operation
    456 {
    457 public:
    458 
    459   using structop_base_operation::structop_base_operation;
    460 
    461   value *evaluate (struct type *expect_type,
    462 		   struct expression *exp,
    463 		   enum noside noside) override;
    464 
    465   enum exp_opcode opcode () const override
    466   { return STRUCTOP_STRUCT; }
    467 
    468   /* Set the completion prefix.  */
    469   void set_prefix (std::string &&prefix)
    470   {
    471     m_prefix = std::move (prefix);
    472   }
    473 
    474   bool complete (struct expression *exp, completion_tracker &tracker) override
    475   {
    476     return structop_base_operation::complete (exp, tracker, m_prefix.c_str ());
    477   }
    478 
    479   void dump (struct ui_file *stream, int depth) const override
    480   {
    481     structop_base_operation::dump (stream, depth);
    482     dump_for_expression (stream, depth + 1, m_prefix);
    483   }
    484 
    485 private:
    486 
    487   /* We may need to provide a prefix to field name completion.  See
    488      ada-exp.y:find_completion_bounds for details.  */
    489   std::string m_prefix;
    490 };
    491 
    492 /* Function calls for Ada.  */
    493 class ada_funcall_operation
    494   : public tuple_holding_operation<operation_up, std::vector<operation_up>>,
    495     public ada_resolvable
    496 {
    497 public:
    498 
    499   using tuple_holding_operation::tuple_holding_operation;
    500 
    501   value *evaluate (struct type *expect_type,
    502 		   struct expression *exp,
    503 		   enum noside noside) override;
    504 
    505   bool resolve (struct expression *exp,
    506 		bool deprocedure_p,
    507 		bool parse_completion,
    508 		innermost_block_tracker *tracker,
    509 		struct type *context_type) override;
    510 
    511   enum exp_opcode opcode () const override
    512   { return OP_FUNCALL; }
    513 };
    514 
    515 /* An Ada assignment operation.  */
    516 class ada_assign_operation
    517   : public assign_operation
    518 {
    519 public:
    520 
    521   using assign_operation::assign_operation;
    522 
    523   value *evaluate (struct type *expect_type,
    524 		   struct expression *exp,
    525 		   enum noside noside) override;
    526 
    527   enum exp_opcode opcode () const override
    528   { return BINOP_ASSIGN; }
    529 
    530   value *current ()
    531   { return m_current; }
    532 
    533   /* A helper function for the parser to evaluate just the LHS of the
    534      assignment.  */
    535   value *eval_for_resolution (struct expression *exp)
    536   {
    537     return std::get<0> (m_storage)->evaluate (nullptr, exp,
    538 					      EVAL_AVOID_SIDE_EFFECTS);
    539   }
    540 
    541   /* The parser must construct the assignment node before parsing the
    542      RHS, so that '@' can access the assignment, so this helper
    543      function is needed to set the RHS after construction.  */
    544   void set_rhs (operation_up rhs)
    545   {
    546     std::get<1> (m_storage) = std::move (rhs);
    547   }
    548 
    549 private:
    550 
    551   /* Temporary storage for the value of the left-hand-side.  */
    552   value *m_current = nullptr;
    553 };
    554 
    555 /* Implement the Ada target name symbol ('@').  This is used to refer
    556    to the LHS of an assignment from the RHS.  */
    557 class ada_target_operation : public operation
    558 {
    559 public:
    560 
    561   explicit ada_target_operation (ada_assign_operation *lhs)
    562     : m_lhs (lhs)
    563   { }
    564 
    565   value *evaluate (struct type *expect_type,
    566 		   struct expression *exp,
    567 		   enum noside noside) override
    568   {
    569     if (noside == EVAL_AVOID_SIDE_EFFECTS)
    570       return m_lhs->eval_for_resolution (exp);
    571     return m_lhs->current ();
    572   }
    573 
    574   enum exp_opcode opcode () const override
    575   {
    576     /* It doesn't really matter.  */
    577     return OP_VAR_VALUE;
    578   }
    579 
    580   void dump (struct ui_file *stream, int depth) const override
    581   {
    582     gdb_printf (stream, _("%*sAda target symbol '@'\n"), depth, "");
    583   }
    584 
    585 private:
    586 
    587   /* The left hand side of the assignment.  */
    588   ada_assign_operation *m_lhs;
    589 };
    590 
    591 /* When constructing an aggregate, an object of this type is created
    592    to track the needed state.  */
    593 
    594 struct aggregate_assigner
    595 {
    596   /* An lvalue containing LHS (possibly LHS itself).  */
    597   value *container;
    598 
    599   /* An lvalue of record or array type; this is the object being
    600      assigned to.  */
    601   value *lhs;
    602 
    603   /* The expression being evaluated.  */
    604   expression *exp;
    605 
    606   /* The bounds of LHS.  This is used by the 'others' component.  */
    607   LONGEST low;
    608   LONGEST high;
    609 
    610   /* This indicates which sub-components have already been assigned
    611      to.  */
    612   std::vector<LONGEST> indices;
    613 
    614 private:
    615 
    616   /* The current index value.  This is only valid during the 'assign'
    617      operation and is part of the implementation of iterated component
    618      association.  */
    619   LONGEST m_current_index = 0;
    620 
    621 public:
    622 
    623   /* Assign the result of evaluating ARG to the INDEXth component of
    624      LHS (a simple array or a record).  Does not modify the inferior's
    625      memory, nor does it modify LHS (unless LHS == CONTAINER).  */
    626   void assign (LONGEST index, operation_up &arg);
    627 
    628   /* Add the interval [FROM .. TO] to the sorted set of intervals
    629      [ INDICES[0] .. INDICES[1] ],...  The resulting intervals do not
    630      overlap.  */
    631   void add_interval (LONGEST low, LONGEST high);
    632 
    633   /* Return the current index as a value, using the index type of
    634      LHS.  */
    635   value *current_value () const;
    636 };
    637 
    638 /* This abstract class represents a single component in an Ada
    639    aggregate assignment.  */
    640 class ada_component
    641 {
    642 public:
    643 
    644   /* Assign to ASSIGNER.  */
    645   virtual void assign (aggregate_assigner &assigner) = 0;
    646 
    647   /* Same as operation::uses_objfile.  */
    648   virtual bool uses_objfile (struct objfile *objfile) = 0;
    649 
    650   /* Same as operation::dump.  */
    651   virtual void dump (ui_file *stream, int depth) = 0;
    652 
    653   virtual ~ada_component () = default;
    654 
    655 protected:
    656 
    657   ada_component () = default;
    658   DISABLE_COPY_AND_ASSIGN (ada_component);
    659 };
    660 
    661 /* Unique pointer specialization for Ada assignment components.  */
    662 typedef std::unique_ptr<ada_component> ada_component_up;
    663 
    664 /* An operation that holds a single component.  */
    665 class ada_aggregate_operation
    666   : public tuple_holding_operation<ada_component_up>
    667 {
    668 public:
    669 
    670   using tuple_holding_operation::tuple_holding_operation;
    671 
    672   /* Assuming that LHS represents an lvalue having a record or array
    673      type, evaluate an assignment of this aggregate's value to LHS.
    674      CONTAINER is an lvalue containing LHS (possibly LHS itself).
    675      Does not modify the inferior's memory, nor does it modify the
    676      contents of LHS (unless == CONTAINER).  Returns the modified
    677      CONTAINER.  */
    678 
    679   value *assign_aggregate (struct value *container,
    680 			   struct value *lhs,
    681 			   struct expression *exp);
    682 
    683   value *evaluate (struct type *expect_type,
    684 		   struct expression *exp,
    685 		   enum noside noside) override
    686   {
    687     error (_("Aggregates only allowed on the right of an assignment"));
    688   }
    689 
    690   enum exp_opcode opcode () const override
    691   { return OP_AGGREGATE; }
    692 };
    693 
    694 /* A component holding a vector of other components to assign.  */
    695 class ada_aggregate_component : public ada_component
    696 {
    697 public:
    698 
    699   explicit ada_aggregate_component (std::vector<ada_component_up> &&components)
    700     : m_components (std::move (components))
    701   {
    702   }
    703 
    704   /* This is the "with delta" form -- BASE is the base expression.  */
    705   ada_aggregate_component (operation_up &&base,
    706 			   std::vector<ada_component_up> &&components);
    707 
    708   void assign (aggregate_assigner &assigner) override;
    709 
    710   bool uses_objfile (struct objfile *objfile) override;
    711 
    712   void dump (ui_file *stream, int depth) override;
    713 
    714 private:
    715 
    716   /* If the assignment has a "with delta" clause, this is the
    717      base expression.  */
    718   operation_up m_base;
    719   /* The individual components to assign.  */
    720   std::vector<ada_component_up> m_components;
    721 };
    722 
    723 /* A component that assigns according to a provided index (which is
    724    relative to the "low" value).  */
    725 class ada_positional_component : public ada_component
    726 {
    727 public:
    728 
    729   ada_positional_component (int index, operation_up &&op)
    730     : m_index (index),
    731       m_op (std::move (op))
    732   {
    733   }
    734 
    735   void assign (aggregate_assigner &assigner) override;
    736 
    737   bool uses_objfile (struct objfile *objfile) override;
    738 
    739   void dump (ui_file *stream, int depth) override;
    740 
    741 private:
    742 
    743   int m_index;
    744   operation_up m_op;
    745 };
    746 
    747 /* A component which handles an "others" clause.  */
    748 class ada_others_component : public ada_component
    749 {
    750 public:
    751 
    752   explicit ada_others_component (operation_up &&op)
    753     : m_op (std::move (op))
    754   {
    755   }
    756 
    757   void assign (aggregate_assigner &assigner) override;
    758 
    759   bool uses_objfile (struct objfile *objfile) override;
    760 
    761   void dump (ui_file *stream, int depth) override;
    762 
    763 private:
    764 
    765   operation_up m_op;
    766 };
    767 
    768 /* An interface that represents an association that is used in
    769    aggregate assignment.  */
    770 class ada_association
    771 {
    772 public:
    773 
    774   /* Like ada_component::assign, but takes an operation as a
    775      parameter.  The operation is evaluated and then assigned into
    776      ASSIGNER according to the rules of the concrete
    777      implementation.  */
    778   virtual void assign (aggregate_assigner &assigner, operation_up &op) = 0;
    779 
    780   /* Same as operation::uses_objfile.  */
    781   virtual bool uses_objfile (struct objfile *objfile) = 0;
    782 
    783   /* Same as operation::dump.  */
    784   virtual void dump (ui_file *stream, int depth) = 0;
    785 
    786   virtual ~ada_association () = default;
    787 
    788 protected:
    789 
    790   ada_association () = default;
    791   DISABLE_COPY_AND_ASSIGN (ada_association);
    792 };
    793 
    794 /* Unique pointer specialization for Ada assignment associations.  */
    795 typedef std::unique_ptr<ada_association> ada_association_up;
    796 
    797 /* A component that holds a vector of associations and an operation.
    798    The operation is re-evaluated for each choice.  */
    799 class ada_choices_component : public ada_component
    800 {
    801 public:
    802 
    803   explicit ada_choices_component (operation_up &&op)
    804     : m_op (std::move (op))
    805   {
    806   }
    807 
    808   /* Set the vector of associations.  This is done separately from the
    809      constructor because it was simpler for the implementation of the
    810      parser.  */
    811   void set_associations (std::vector<ada_association_up> &&assoc)
    812   {
    813     m_assocs = std::move (assoc);
    814   }
    815 
    816   /* Set the underlying operation  */
    817   void set_operation (operation_up op)
    818   { m_op = std::move (op); }
    819 
    820   /* Set the index variable name for an iterated association.  */
    821   void set_name (std::string &&name)
    822   { m_name = std::move (name); }
    823 
    824   /* The name of this choice component.  This is empty unless this is
    825      an iterated association.  */
    826   const std::string &name () const
    827   { return m_name; }
    828 
    829   void assign (aggregate_assigner &assigner) override;
    830 
    831   bool uses_objfile (struct objfile *objfile) override;
    832 
    833   void dump (ui_file *stream, int depth) override;
    834 
    835   /* Return the current value of the index variable.  This may only be
    836      called underneath a call to 'assign'.  */
    837   value *current_value () const
    838   { return m_assigner->current_value (); }
    839 
    840 private:
    841 
    842   std::vector<ada_association_up> m_assocs;
    843   operation_up m_op;
    844 
    845   /* Name of the variable used for iteration.  This isn't needed for
    846      evaluation, only for debug dumping.  This is the empty string for
    847      ordinary (non-iterated) choices.  */
    848   std::string m_name;
    849 
    850   /* A pointer to the current assignment operation; only valid when in
    851      a call to the 'assign' method.  This is used to find the index
    852      variable value during the evaluation of the RHS of the =>, via
    853      ada_index_var_operation.  */
    854   const aggregate_assigner *m_assigner = nullptr;
    855 };
    856 
    857 /* Implement the index variable for iterated component
    858    association.  */
    859 class ada_index_var_operation : public operation
    860 {
    861 public:
    862 
    863   ada_index_var_operation ()
    864   { }
    865 
    866   /* Link this variable to the choices object.  May only be called
    867      once.  */
    868   void set_choices (ada_choices_component *var)
    869   {
    870     gdb_assert (m_var == nullptr && var != nullptr);
    871     m_var = var;
    872   }
    873 
    874   value *evaluate (struct type *expect_type,
    875 		   struct expression *exp,
    876 		   enum noside noside) override;
    877 
    878   enum exp_opcode opcode () const override
    879   {
    880     /* It doesn't really matter.  */
    881     return OP_VAR_VALUE;
    882   }
    883 
    884   void dump (struct ui_file *stream, int depth) const override;
    885 
    886 private:
    887 
    888   /* The choices component that introduced the index variable.  */
    889   ada_choices_component *m_var = nullptr;
    890 };
    891 
    892 /* An association that uses a discrete range.  */
    893 class ada_discrete_range_association : public ada_association
    894 {
    895 public:
    896 
    897   ada_discrete_range_association (operation_up &&low, operation_up &&high)
    898     : m_low (std::move (low)),
    899       m_high (std::move (high))
    900   {
    901   }
    902 
    903   void assign (aggregate_assigner &assigner, operation_up &op) override;
    904 
    905   bool uses_objfile (struct objfile *objfile) override;
    906 
    907   void dump (ui_file *stream, int depth) override;
    908 
    909 private:
    910 
    911   operation_up m_low;
    912   operation_up m_high;
    913 };
    914 
    915 /* An association that uses a name.  The name may be an expression
    916    that evaluates to an integer (for arrays), or an Ada string or
    917    variable value operation.  */
    918 class ada_name_association : public ada_association
    919 {
    920 public:
    921 
    922   explicit ada_name_association (operation_up val)
    923     : m_val (std::move (val))
    924   {
    925   }
    926 
    927   void assign (aggregate_assigner &assigner, operation_up &op) override;
    928 
    929   bool uses_objfile (struct objfile *objfile) override;
    930 
    931   void dump (ui_file *stream, int depth) override;
    932 
    933 private:
    934 
    935   operation_up m_val;
    936 };
    937 
    938 /* A character constant expression.  This is a separate operation so
    939    that it can participate in resolution, so that TYPE'(CST) can
    940    work correctly for enums with character enumerators.  */
    941 class ada_char_operation : public long_const_operation,
    942 			   public ada_resolvable
    943 {
    944 public:
    945 
    946   using long_const_operation::long_const_operation;
    947 
    948   bool resolve (struct expression *exp,
    949 		bool deprocedure_p,
    950 		bool parse_completion,
    951 		innermost_block_tracker *tracker,
    952 		struct type *context_type) override
    953   {
    954     /* This should never be called, because this class also implements
    955        'replace'.  */
    956     gdb_assert_not_reached ("unexpected call");
    957   }
    958 
    959   operation_up replace (operation_up &&owner,
    960 			struct expression *exp,
    961 			bool deprocedure_p,
    962 			bool parse_completion,
    963 			innermost_block_tracker *tracker,
    964 			struct type *context_type) override;
    965 
    966   value *evaluate (struct type *expect_type,
    967 		   struct expression *exp,
    968 		   enum noside noside) override;
    969 };
    970 
    971 class ada_concat_operation : public concat_operation
    972 {
    973 public:
    974 
    975   using concat_operation::concat_operation;
    976 
    977   value *evaluate (struct type *expect_type,
    978 		   struct expression *exp,
    979 		   enum noside noside) override;
    980 };
    981 
    982 } /* namespace expr */
    983 
    984 #endif /* ADA_EXP_H */
    985