1*6881a400Schristos /* Definitions for C expressions 2*6881a400Schristos 3*6881a400Schristos Copyright (C) 2020-2023 Free Software Foundation, Inc. 4*6881a400Schristos 5*6881a400Schristos This file is part of GDB. 6*6881a400Schristos 7*6881a400Schristos This program is free software; you can redistribute it and/or modify 8*6881a400Schristos it under the terms of the GNU General Public License as published by 9*6881a400Schristos the Free Software Foundation; either version 3 of the License, or 10*6881a400Schristos (at your option) any later version. 11*6881a400Schristos 12*6881a400Schristos This program is distributed in the hope that it will be useful, 13*6881a400Schristos but WITHOUT ANY WARRANTY; without even the implied warranty of 14*6881a400Schristos MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 15*6881a400Schristos GNU General Public License for more details. 16*6881a400Schristos 17*6881a400Schristos You should have received a copy of the GNU General Public License 18*6881a400Schristos along with this program. If not, see <http://www.gnu.org/licenses/>. */ 19*6881a400Schristos 20*6881a400Schristos #ifndef C_EXP_H 21*6881a400Schristos #define C_EXP_H 22*6881a400Schristos 23*6881a400Schristos #include "expop.h" 24*6881a400Schristos #include "objc-lang.h" 25*6881a400Schristos 26*6881a400Schristos extern struct value *eval_op_objc_selector (struct type *expect_type, 27*6881a400Schristos struct expression *exp, 28*6881a400Schristos enum noside noside, 29*6881a400Schristos const char *sel); 30*6881a400Schristos extern struct value *opencl_value_cast (struct type *type, struct value *arg); 31*6881a400Schristos extern struct value *eval_opencl_assign (struct type *expect_type, 32*6881a400Schristos struct expression *exp, 33*6881a400Schristos enum noside noside, 34*6881a400Schristos enum exp_opcode op, 35*6881a400Schristos struct value *arg1, 36*6881a400Schristos struct value *arg2); 37*6881a400Schristos extern struct value *opencl_relop (struct type *expect_type, 38*6881a400Schristos struct expression *exp, 39*6881a400Schristos enum noside noside, enum exp_opcode op, 40*6881a400Schristos struct value *arg1, struct value *arg2); 41*6881a400Schristos extern struct value *opencl_logical_not (struct type *expect_type, 42*6881a400Schristos struct expression *exp, 43*6881a400Schristos enum noside noside, 44*6881a400Schristos enum exp_opcode op, 45*6881a400Schristos struct value *arg); 46*6881a400Schristos 47*6881a400Schristos namespace expr 48*6881a400Schristos { 49*6881a400Schristos 50*6881a400Schristos class c_string_operation 51*6881a400Schristos : public tuple_holding_operation<enum c_string_type_values, 52*6881a400Schristos std::vector<std::string>> 53*6881a400Schristos { 54*6881a400Schristos public: 55*6881a400Schristos 56*6881a400Schristos using tuple_holding_operation::tuple_holding_operation; 57*6881a400Schristos 58*6881a400Schristos value *evaluate (struct type *expect_type, 59*6881a400Schristos struct expression *exp, 60*6881a400Schristos enum noside noside) override; 61*6881a400Schristos 62*6881a400Schristos enum exp_opcode opcode () const override 63*6881a400Schristos { return OP_STRING; } 64*6881a400Schristos }; 65*6881a400Schristos 66*6881a400Schristos class objc_nsstring_operation 67*6881a400Schristos : public tuple_holding_operation<std::string> 68*6881a400Schristos { 69*6881a400Schristos public: 70*6881a400Schristos 71*6881a400Schristos using tuple_holding_operation::tuple_holding_operation; 72*6881a400Schristos 73*6881a400Schristos value *evaluate (struct type *expect_type, 74*6881a400Schristos struct expression *exp, 75*6881a400Schristos enum noside noside) override 76*6881a400Schristos { 77*6881a400Schristos const std::string &str = std::get<0> (m_storage); 78*6881a400Schristos return value_nsstring (exp->gdbarch, str.c_str (), str.size () + 1); 79*6881a400Schristos } 80*6881a400Schristos 81*6881a400Schristos enum exp_opcode opcode () const override 82*6881a400Schristos { return OP_OBJC_NSSTRING; } 83*6881a400Schristos }; 84*6881a400Schristos 85*6881a400Schristos class objc_selector_operation 86*6881a400Schristos : public tuple_holding_operation<std::string> 87*6881a400Schristos { 88*6881a400Schristos public: 89*6881a400Schristos 90*6881a400Schristos using tuple_holding_operation::tuple_holding_operation; 91*6881a400Schristos 92*6881a400Schristos value *evaluate (struct type *expect_type, 93*6881a400Schristos struct expression *exp, 94*6881a400Schristos enum noside noside) override 95*6881a400Schristos { 96*6881a400Schristos return eval_op_objc_selector (expect_type, exp, noside, 97*6881a400Schristos std::get<0> (m_storage).c_str ()); 98*6881a400Schristos } 99*6881a400Schristos 100*6881a400Schristos enum exp_opcode opcode () const override 101*6881a400Schristos { return OP_OBJC_SELECTOR; } 102*6881a400Schristos }; 103*6881a400Schristos 104*6881a400Schristos /* An Objective C message call. */ 105*6881a400Schristos class objc_msgcall_operation 106*6881a400Schristos : public tuple_holding_operation<CORE_ADDR, operation_up, 107*6881a400Schristos std::vector<operation_up>> 108*6881a400Schristos { 109*6881a400Schristos public: 110*6881a400Schristos 111*6881a400Schristos using tuple_holding_operation::tuple_holding_operation; 112*6881a400Schristos 113*6881a400Schristos value *evaluate (struct type *expect_type, 114*6881a400Schristos struct expression *exp, 115*6881a400Schristos enum noside noside) override; 116*6881a400Schristos 117*6881a400Schristos enum exp_opcode opcode () const override 118*6881a400Schristos { return OP_OBJC_MSGCALL; } 119*6881a400Schristos }; 120*6881a400Schristos 121*6881a400Schristos using opencl_cast_type_operation = cxx_cast_operation<UNOP_CAST_TYPE, 122*6881a400Schristos opencl_value_cast>; 123*6881a400Schristos 124*6881a400Schristos /* Binary operations, as needed for OpenCL. */ 125*6881a400Schristos template<enum exp_opcode OP, binary_ftype FUNC, 126*6881a400Schristos typename BASE = maybe_constant_operation<operation_up, operation_up>> 127*6881a400Schristos class opencl_binop_operation 128*6881a400Schristos : public BASE 129*6881a400Schristos { 130*6881a400Schristos public: 131*6881a400Schristos 132*6881a400Schristos using BASE::BASE; 133*6881a400Schristos 134*6881a400Schristos value *evaluate (struct type *expect_type, 135*6881a400Schristos struct expression *exp, 136*6881a400Schristos enum noside noside) override 137*6881a400Schristos { 138*6881a400Schristos value *lhs 139*6881a400Schristos = std::get<0> (this->m_storage)->evaluate (nullptr, exp, noside); 140*6881a400Schristos value *rhs 141*6881a400Schristos = std::get<1> (this->m_storage)->evaluate (value_type (lhs), exp, 142*6881a400Schristos noside); 143*6881a400Schristos return FUNC (expect_type, exp, noside, OP, lhs, rhs); 144*6881a400Schristos } 145*6881a400Schristos 146*6881a400Schristos enum exp_opcode opcode () const override 147*6881a400Schristos { return OP; } 148*6881a400Schristos }; 149*6881a400Schristos 150*6881a400Schristos using opencl_assign_operation = opencl_binop_operation<BINOP_ASSIGN, 151*6881a400Schristos eval_opencl_assign, 152*6881a400Schristos assign_operation>; 153*6881a400Schristos using opencl_equal_operation = opencl_binop_operation<BINOP_EQUAL, 154*6881a400Schristos opencl_relop>; 155*6881a400Schristos using opencl_notequal_operation = opencl_binop_operation<BINOP_NOTEQUAL, 156*6881a400Schristos opencl_relop>; 157*6881a400Schristos using opencl_less_operation = opencl_binop_operation<BINOP_LESS, 158*6881a400Schristos opencl_relop>; 159*6881a400Schristos using opencl_gtr_operation = opencl_binop_operation<BINOP_GTR, 160*6881a400Schristos opencl_relop>; 161*6881a400Schristos using opencl_geq_operation = opencl_binop_operation<BINOP_GEQ, 162*6881a400Schristos opencl_relop>; 163*6881a400Schristos using opencl_leq_operation = opencl_binop_operation<BINOP_LEQ, 164*6881a400Schristos opencl_relop>; 165*6881a400Schristos 166*6881a400Schristos using opencl_not_operation = unop_operation<UNOP_LOGICAL_NOT, 167*6881a400Schristos opencl_logical_not>; 168*6881a400Schristos 169*6881a400Schristos /* STRUCTOP_STRUCT implementation for OpenCL. */ 170*6881a400Schristos class opencl_structop_operation 171*6881a400Schristos : public structop_base_operation 172*6881a400Schristos { 173*6881a400Schristos public: 174*6881a400Schristos 175*6881a400Schristos using structop_base_operation::structop_base_operation; 176*6881a400Schristos 177*6881a400Schristos value *evaluate (struct type *expect_type, 178*6881a400Schristos struct expression *exp, 179*6881a400Schristos enum noside noside) override; 180*6881a400Schristos 181*6881a400Schristos enum exp_opcode opcode () const override 182*6881a400Schristos { return STRUCTOP_STRUCT; } 183*6881a400Schristos }; 184*6881a400Schristos 185*6881a400Schristos /* This handles the "&&" and "||" operations for OpenCL. */ 186*6881a400Schristos class opencl_logical_binop_operation 187*6881a400Schristos : public tuple_holding_operation<enum exp_opcode, 188*6881a400Schristos operation_up, operation_up> 189*6881a400Schristos { 190*6881a400Schristos public: 191*6881a400Schristos 192*6881a400Schristos using tuple_holding_operation::tuple_holding_operation; 193*6881a400Schristos 194*6881a400Schristos value *evaluate (struct type *expect_type, 195*6881a400Schristos struct expression *exp, 196*6881a400Schristos enum noside noside) override; 197*6881a400Schristos 198*6881a400Schristos enum exp_opcode opcode () const override 199*6881a400Schristos { return std::get<0> (m_storage); } 200*6881a400Schristos }; 201*6881a400Schristos 202*6881a400Schristos /* The ?: ternary operator for OpenCL. */ 203*6881a400Schristos class opencl_ternop_cond_operation 204*6881a400Schristos : public tuple_holding_operation<operation_up, operation_up, operation_up> 205*6881a400Schristos { 206*6881a400Schristos public: 207*6881a400Schristos 208*6881a400Schristos using tuple_holding_operation::tuple_holding_operation; 209*6881a400Schristos 210*6881a400Schristos value *evaluate (struct type *expect_type, 211*6881a400Schristos struct expression *exp, 212*6881a400Schristos enum noside noside) override; 213*6881a400Schristos 214*6881a400Schristos enum exp_opcode opcode () const override 215*6881a400Schristos { return TERNOP_COND; } 216*6881a400Schristos }; 217*6881a400Schristos 218*6881a400Schristos }/* namespace expr */ 219*6881a400Schristos 220*6881a400Schristos #endif /* C_EXP_H */ 221