| 350 | } |
| 351 | |
| 352 | Error FakeGDScript::parse_script() { |
| 353 | using GT = GlobalToken; |
| 354 | |
| 355 | FAKEGDSCRIPT_FAIL_COND_V_MSG(script_state.bytecode_version == -1, ERR_INVALID_DATA, "Bytecode version is invalid"); |
| 356 | Vector<StringName> &identifiers = script_state.identifiers; |
| 357 | Vector<Variant> &constants = script_state.constants; |
| 358 | Vector<uint32_t> &tokens = script_state.tokens; |
| 359 | int variant_ver_major = decomp->get_variant_ver_major(); |
| 360 | |
| 361 | // reserved words can be used as class members in GDScript. Hooray. |
| 362 | auto is_not_actually_reserved_word = [&](int i) { |
| 363 | return (decomp->check_prev_token(i, tokens, GT::G_TK_PERIOD) || |
| 364 | (script_state.bytecode_version < GDScriptDecomp::GDSCRIPT_2_0_VERSION && |
| 365 | (decomp->check_prev_token(i, tokens, GT::G_TK_PR_FUNCTION) || |
| 366 | decomp->is_token_func_call(i, tokens)))); |
| 367 | }; |
| 368 | bool func_used = false; |
| 369 | bool class_used = false; |
| 370 | bool var_used = false; |
| 371 | bool const_used = false; |
| 372 | bool extends_used = false; |
| 373 | bool class_name_used = false; |
| 374 | export_vars.clear(); |
| 375 | int indent = 0; |
| 376 | uint32_t prev_line = 1; |
| 377 | uint32_t prev_line_start_column = 1; |
| 378 | GT prev_token = GT::G_TK_NEWLINE; |
| 379 | int tab_size = 1; |
| 380 | |
| 381 | // We should only fail when there's something that the decompiler should have already caught; otherwise we'll just warn. |
| 382 | #define FAKEGDSCRIPT_PARSE_FAIL_COND_V_MSG(cond, msg) \ |
| 383 | if (unlikely(cond)) { \ |
| 384 | error_message = "Failed to parse script: Line " + itos(prev_line) + ": " + msg; \ |
| 385 | return ERR_PARSE_ERROR; \ |
| 386 | } |
| 387 | |
| 388 | auto handle_newline = [&](int i, GlobalToken curr_token) { |
| 389 | auto curr_line = script_state.get_token_line(i); |
| 390 | auto curr_column = script_state.get_token_column(i); |
| 391 | if (curr_line <= prev_line) { |
| 392 | curr_line = prev_line + 1; // force new line |
| 393 | } |
| 394 | while (curr_line > prev_line) { |
| 395 | prev_line++; |
| 396 | } |
| 397 | if (curr_token == GT::G_TK_NEWLINE) { |
| 398 | indent = tokens[i] >> GDScriptDecomp::TOKEN_BITS; |
| 399 | } else if (script_state.bytecode_version >= GDScriptDecomp::GDSCRIPT_2_0_VERSION) { |
| 400 | prev_token = GT::G_TK_NEWLINE; |
| 401 | int col_diff = (int)curr_column - (int)prev_line_start_column; |
| 402 | if (col_diff != 0) { |
| 403 | int tabs = col_diff / tab_size; |
| 404 | if (tabs == 0) { |
| 405 | indent += (col_diff > 0 ? 1 : -1); |
| 406 | } else { |
| 407 | indent += tabs; |
| 408 | } |
| 409 | } |
nothing calls this directly
no test coverage detected