| 402 | |
| 403 | |
| 404 | def generate_class_header(dir: Path, bytecode_class: BytecodeClass) -> None: |
| 405 | file_stem = bytecode_class.file_stem |
| 406 | class_name = bytecode_class.class_name |
| 407 | func_names = bytecode_class.func_names |
| 408 | tk_names = bytecode_class.tk_names |
| 409 | bytecode_version = bytecode_class.bytecode_version |
| 410 | bytecode_rev = bytecode_class.bytecode_rev |
| 411 | bytecode_rev_num = bytecode_class.bytecode_rev_num |
| 412 | engine_ver_major = bytecode_class.engine_ver_major |
| 413 | variant_ver_major = bytecode_class.variant_ver_major |
| 414 | new_dir = dir |
| 415 | # ensure the directory exists |
| 416 | if not new_dir.exists(): |
| 417 | new_dir.mkdir() |
| 418 | new_file_h = new_dir / (file_stem + ".h") |
| 419 | |
| 420 | # Read the template file |
| 421 | template_path = Path(__file__).parent / "misc" / "bytecode_template.h.inc" |
| 422 | with open(template_path, "r") as template_file: |
| 423 | template_content = template_file.read() |
| 424 | |
| 425 | ADDED_TOKEN_PREFIX = "\tvirtual Vector<GlobalToken> get_added_tokens() const override { return {" |
| 426 | REMOVED_TOKEN_PREFIX = "\tvirtual Vector<GlobalToken> get_removed_tokens() const override { return {" |
| 427 | ADDED_FUNCTION_PREFIX = "\tvirtual Vector<String> get_added_functions() const override { return {" |
| 428 | REMOVED_FUNCTION_PREFIX = "\tvirtual Vector<String> get_removed_functions() const override { return {" |
| 429 | ARG_COUNT_CHANGED_PREFIX = "\tvirtual Vector<String> get_function_arg_count_changed() const override { return {" |
| 430 | TOKENS_RENAMED_PREFIX = "\tvirtual Dictionary get_tokens_renamed() const override { return {" |
| 431 | FUNCTIONS_RENAMED_PREFIX = "\tvirtual Dictionary get_renamed_functions() const override { return {" |
| 432 | |
| 433 | # Prepare replacement values |
| 434 | new_added_tokens = ["GlobalToken::G_" + tk_name for tk_name in bytecode_class.added_tokens] |
| 435 | new_removed_tokens = ["GlobalToken::G_" + tk_name for tk_name in bytecode_class.removed_tokens] |
| 436 | |
| 437 | added_functions = ['"' + func_name + '"' for func_name in bytecode_class.added_functions] |
| 438 | removed_functions = ['"' + func_name + '"' for func_name in bytecode_class.removed_functions] |
| 439 | arg_count_changed = ['"' + func_name + '"' for func_name in bytecode_class.arg_count_changed] |
| 440 | |
| 441 | # Handle parent commit |
| 442 | parent_value = "0x" + str(bytecode_class.parent) if bytecode_class.parent is not None else "0" |
| 443 | added_tokens_str = "" |
| 444 | removed_tokens_str = "" |
| 445 | added_functions_str = "" |
| 446 | removed_functions_str = "" |
| 447 | arg_count_changed_str = "" |
| 448 | tokens_renamed_str = "" |
| 449 | renamed_functions_str = "" |
| 450 | |
| 451 | # ARR_PREFIX = "\n\t\t" |
| 452 | # ARR_SUFFIX = "\n\t}; }\n" |
| 453 | # ARR_JOIN_STR = ",\n\t\t" |
| 454 | |
| 455 | ARR_PREFIX = "" |
| 456 | ARR_SUFFIX = "}; }\n" |
| 457 | ARR_JOIN_STR = ", " |
| 458 | ARR_STR_JOIN_STR = '", "' |
| 459 | ARR_STRING_FORMAT = "" |
| 460 | # Prepare token and function lists |
| 461 | if len(new_added_tokens) > 0: |