We're at the identifier token
| 1448 | |
| 1449 | // We're at the identifier token |
| 1450 | int GDScriptDecomp::get_func_arg_count_and_params(int curr_pos, const Vector<uint32_t> &tokens, Vector<Vector<uint32_t>> &r_arguments) { |
| 1451 | if (curr_pos + 2 >= tokens.size()) { |
| 1452 | return -1; |
| 1453 | } |
| 1454 | GlobalToken t = get_global_token(tokens[curr_pos + 1]); |
| 1455 | if (t != G_TK_PARENTHESIS_OPEN) { |
| 1456 | return -1; |
| 1457 | } |
| 1458 | int bracket_open = 0; |
| 1459 | // we should be just past the open parenthesis |
| 1460 | int pos = curr_pos + 2; |
| 1461 | |
| 1462 | Vector<uint32_t> curr_arg; |
| 1463 | // count the commas |
| 1464 | // at least in 3.x and below, the only time commas are allowed in function args are other expressions |
| 1465 | // This test is not applicable to GDScript 2.0 versions, as there are no bytecode-specific built-in functions. |
| 1466 | for (; pos < tokens.size(); pos++) { |
| 1467 | t = get_global_token(tokens[pos]); |
| 1468 | switch (t) { |
| 1469 | case G_TK_BRACKET_OPEN: |
| 1470 | case G_TK_CURLY_BRACKET_OPEN: |
| 1471 | case G_TK_PARENTHESIS_OPEN: |
| 1472 | bracket_open++; |
| 1473 | break; |
| 1474 | case G_TK_BRACKET_CLOSE: |
| 1475 | case G_TK_CURLY_BRACKET_CLOSE: |
| 1476 | case G_TK_PARENTHESIS_CLOSE: |
| 1477 | bracket_open--; |
| 1478 | break; |
| 1479 | case G_TK_COMMA: |
| 1480 | if (bracket_open == 0) { |
| 1481 | r_arguments.push_back(curr_arg); |
| 1482 | } |
| 1483 | break; |
| 1484 | default: |
| 1485 | break; |
| 1486 | } |
| 1487 | if (bracket_open == -1) { |
| 1488 | if (curr_arg.size() > 0) { |
| 1489 | r_arguments.push_back(curr_arg); |
| 1490 | } |
| 1491 | break; |
| 1492 | } |
| 1493 | if (!is_whitespace_or_ignorable(t)) { |
| 1494 | curr_arg.push_back(tokens[pos]); |
| 1495 | } |
| 1496 | } |
| 1497 | // trailing commas are not allowed after the last argument |
| 1498 | if (pos == tokens.size() || t != G_TK_PARENTHESIS_CLOSE) { |
| 1499 | r_arguments.clear(); |
| 1500 | error_message = "Did not find close parenthesis before EOF"; |
| 1501 | return -1; |
| 1502 | } |
| 1503 | return r_arguments.size(); |
| 1504 | } |
| 1505 | Ref<GodotVer> GDScriptDecomp::get_godot_ver() const { |
| 1506 | return GodotVer::parse(get_engine_version()); |
| 1507 | } |
no test coverage detected