| 1439 | } |
| 1440 | |
| 1441 | GDScriptCodeGenerator::Address GDScriptCompiler::_parse_match_pattern(CodeGen &codegen, Error &r_error, const GDScriptParser::PatternNode *p_pattern, const GDScriptCodeGenerator::Address &p_value_addr, const GDScriptCodeGenerator::Address &p_type_addr, const GDScriptCodeGenerator::Address &p_previous_test, bool p_is_first, bool p_is_nested) { |
| 1442 | switch (p_pattern->pattern_type) { |
| 1443 | case GDScriptParser::PatternNode::PT_LITERAL: { |
| 1444 | if (p_is_nested) { |
| 1445 | codegen.generator->write_and_left_operand(p_previous_test); |
| 1446 | } else if (!p_is_first) { |
| 1447 | codegen.generator->write_or_left_operand(p_previous_test); |
| 1448 | } |
| 1449 | |
| 1450 | // Get literal type into constant map. |
| 1451 | Variant::Type literal_type = p_pattern->literal->value.get_type(); |
| 1452 | GDScriptCodeGenerator::Address literal_type_addr = codegen.add_constant(literal_type); |
| 1453 | |
| 1454 | // Equality is always a boolean. |
| 1455 | GDScriptDataType equality_type; |
| 1456 | equality_type.has_type = true; |
| 1457 | equality_type.kind = GDScriptDataType::BUILTIN; |
| 1458 | equality_type.builtin_type = Variant::BOOL; |
| 1459 | |
| 1460 | // Check type equality. |
| 1461 | GDScriptCodeGenerator::Address type_equality_addr = codegen.add_temporary(equality_type); |
| 1462 | codegen.generator->write_binary_operator(type_equality_addr, Variant::OP_EQUAL, p_type_addr, literal_type_addr); |
| 1463 | |
| 1464 | if (literal_type == Variant::STRING) { |
| 1465 | GDScriptCodeGenerator::Address type_stringname_addr = codegen.add_constant(Variant::STRING_NAME); |
| 1466 | |
| 1467 | // Check StringName <-> String type equality. |
| 1468 | GDScriptCodeGenerator::Address tmp_comp_addr = codegen.add_temporary(equality_type); |
| 1469 | |
| 1470 | codegen.generator->write_binary_operator(tmp_comp_addr, Variant::OP_EQUAL, p_type_addr, type_stringname_addr); |
| 1471 | codegen.generator->write_binary_operator(type_equality_addr, Variant::OP_OR, type_equality_addr, tmp_comp_addr); |
| 1472 | |
| 1473 | codegen.generator->pop_temporary(); // Remove tmp_comp_addr from stack. |
| 1474 | } else if (literal_type == Variant::STRING_NAME) { |
| 1475 | GDScriptCodeGenerator::Address type_string_addr = codegen.add_constant(Variant::STRING); |
| 1476 | |
| 1477 | // Check String <-> StringName type equality. |
| 1478 | GDScriptCodeGenerator::Address tmp_comp_addr = codegen.add_temporary(equality_type); |
| 1479 | |
| 1480 | codegen.generator->write_binary_operator(tmp_comp_addr, Variant::OP_EQUAL, p_type_addr, type_string_addr); |
| 1481 | codegen.generator->write_binary_operator(type_equality_addr, Variant::OP_OR, type_equality_addr, tmp_comp_addr); |
| 1482 | |
| 1483 | codegen.generator->pop_temporary(); // Remove tmp_comp_addr from stack. |
| 1484 | } |
| 1485 | |
| 1486 | codegen.generator->write_and_left_operand(type_equality_addr); |
| 1487 | |
| 1488 | // Get literal. |
| 1489 | GDScriptCodeGenerator::Address literal_addr = _parse_expression(codegen, r_error, p_pattern->literal); |
| 1490 | if (r_error) { |
| 1491 | return GDScriptCodeGenerator::Address(); |
| 1492 | } |
| 1493 | |
| 1494 | // Check value equality. |
| 1495 | GDScriptCodeGenerator::Address equality_addr = codegen.add_temporary(equality_type); |
| 1496 | codegen.generator->write_binary_operator(equality_addr, Variant::OP_EQUAL, p_value_addr, literal_addr); |
| 1497 | codegen.generator->write_and_right_operand(equality_addr); |
| 1498 |
nothing calls this directly
no test coverage detected