m2-exp.h 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384
  1. /* Definitions for Modula-2 expressions
  2. Copyright (C) 2020-2022 Free Software Foundation, Inc.
  3. This file is part of GDB.
  4. This program is free software; you can redistribute it and/or modify
  5. it under the terms of the GNU General Public License as published by
  6. the Free Software Foundation; either version 3 of the License, or
  7. (at your option) any later version.
  8. This program is distributed in the hope that it will be useful,
  9. but WITHOUT ANY WARRANTY; without even the implied warranty of
  10. MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
  11. GNU General Public License for more details.
  12. You should have received a copy of the GNU General Public License
  13. along with this program. If not, see <http://www.gnu.org/licenses/>. */
  14. #ifndef M2_EXP_H
  15. #define M2_EXP_H
  16. #include "expop.h"
  17. extern struct value *eval_op_m2_high (struct type *expect_type,
  18. struct expression *exp,
  19. enum noside noside,
  20. struct value *arg1);
  21. extern struct value *eval_op_m2_subscript (struct type *expect_type,
  22. struct expression *exp,
  23. enum noside noside,
  24. struct value *arg1,
  25. struct value *arg2);
  26. namespace expr
  27. {
  28. /* The Modula-2 "HIGH" operation. */
  29. class m2_unop_high_operation
  30. : public tuple_holding_operation<operation_up>
  31. {
  32. public:
  33. using tuple_holding_operation::tuple_holding_operation;
  34. value *evaluate (struct type *expect_type,
  35. struct expression *exp,
  36. enum noside noside) override
  37. {
  38. value *arg1 = std::get<0> (m_storage)->evaluate_with_coercion (exp,
  39. noside);
  40. return eval_op_m2_high (expect_type, exp, noside, arg1);
  41. }
  42. enum exp_opcode opcode () const override
  43. { return UNOP_HIGH; }
  44. };
  45. /* Subscripting for Modula-2. */
  46. class m2_binop_subscript_operation
  47. : public tuple_holding_operation<operation_up, operation_up>
  48. {
  49. public:
  50. using tuple_holding_operation::tuple_holding_operation;
  51. value *evaluate (struct type *expect_type,
  52. struct expression *exp,
  53. enum noside noside) override
  54. {
  55. value *arg1 = std::get<0> (m_storage)->evaluate_with_coercion (exp,
  56. noside);
  57. value *arg2 = std::get<1> (m_storage)->evaluate_with_coercion (exp,
  58. noside);
  59. return eval_op_m2_subscript (expect_type, exp, noside, arg1, arg2);
  60. }
  61. enum exp_opcode opcode () const override
  62. { return BINOP_SUBSCRIPT; }
  63. };
  64. } /* namespace expr */
  65. #endif /* M2_EXP_H */