| 1245 | } |
| 1246 | |
| 1247 | bool Expression::_execute(const Array &p_inputs, Object *p_instance, Expression::ENode *p_node, Variant &r_ret, bool p_const_calls_only, String &r_error_str) { |
| 1248 | switch (p_node->type) { |
| 1249 | case Expression::ENode::TYPE_INPUT: { |
| 1250 | const Expression::InputNode *in = static_cast<const Expression::InputNode *>(p_node); |
| 1251 | if (in->index < 0 || in->index >= p_inputs.size()) { |
| 1252 | r_error_str = vformat(RTR("Invalid input %d (not passed) in expression"), in->index); |
| 1253 | return true; |
| 1254 | } |
| 1255 | r_ret = p_inputs[in->index]; |
| 1256 | } break; |
| 1257 | case Expression::ENode::TYPE_CONSTANT: { |
| 1258 | const Expression::ConstantNode *c = static_cast<const Expression::ConstantNode *>(p_node); |
| 1259 | r_ret = c->value; |
| 1260 | |
| 1261 | } break; |
| 1262 | case Expression::ENode::TYPE_SELF: { |
| 1263 | if (!p_instance) { |
| 1264 | r_error_str = RTR("self can't be used because instance is null (not passed)"); |
| 1265 | return true; |
| 1266 | } |
| 1267 | r_ret = p_instance; |
| 1268 | } break; |
| 1269 | case Expression::ENode::TYPE_OPERATOR: { |
| 1270 | const Expression::OperatorNode *op = static_cast<const Expression::OperatorNode *>(p_node); |
| 1271 | |
| 1272 | Variant a; |
| 1273 | bool ret = _execute(p_inputs, p_instance, op->nodes[0], a, p_const_calls_only, r_error_str); |
| 1274 | if (ret) { |
| 1275 | return true; |
| 1276 | } |
| 1277 | |
| 1278 | Variant b; |
| 1279 | |
| 1280 | if (op->nodes[1]) { |
| 1281 | ret = _execute(p_inputs, p_instance, op->nodes[1], b, p_const_calls_only, r_error_str); |
| 1282 | if (ret) { |
| 1283 | return true; |
| 1284 | } |
| 1285 | } |
| 1286 | |
| 1287 | bool valid = true; |
| 1288 | Variant::evaluate(op->op, a, b, r_ret, valid); |
| 1289 | if (!valid) { |
| 1290 | r_error_str = vformat(RTR("Invalid operands to operator %s, %s and %s."), Variant::get_operator_name(op->op), Variant::get_type_name(a.get_type()), Variant::get_type_name(b.get_type())); |
| 1291 | return true; |
| 1292 | } |
| 1293 | |
| 1294 | } break; |
| 1295 | case Expression::ENode::TYPE_INDEX: { |
| 1296 | const Expression::IndexNode *index = static_cast<const Expression::IndexNode *>(p_node); |
| 1297 | |
| 1298 | Variant base; |
| 1299 | bool ret = _execute(p_inputs, p_instance, index->base, base, p_const_calls_only, r_error_str); |
| 1300 | if (ret) { |
| 1301 | return true; |
| 1302 | } |
| 1303 | |
| 1304 | Variant idx; |
nothing calls this directly
no test coverage detected