Skip to content

Commit

Permalink
headers: Ultimate vertical spacing fix
Browse files Browse the repository at this point in the history
  • Loading branch information
bwrsandman committed Sep 29, 2024
1 parent a2afcf1 commit cda3885
Show file tree
Hide file tree
Showing 3 changed files with 22 additions and 16 deletions.
22 changes: 11 additions & 11 deletions scripts/headers/bw1_decomp_gen/header.py
Original file line number Diff line number Diff line change
Expand Up @@ -219,21 +219,21 @@ def to_code(self, cw: csnake.CodeWriter):

if fwd:
cw.add_line("// Forward Declares")
cw.add_line()
for f in sorted(fwd):
cw.add_line(f"{f};")
cw.add_line()

for s in self.structs:
s.to_code(cw)
if self.linked_lists_pointered or self.linked_lists or self.lists_heads:
cw.add_line()
if s.decorated_name in self.linked_lists:
cw.add_line(f"DECLARE_LH_LINKED_LIST({s.name});")
if s.decorated_name in self.linked_lists_pointered:
cw.add_line(f"DECLARE_P_LH_LINKED_LIST({s.name});")
if s.decorated_name in self.lists_heads:
cw.add_line(f"DECLARE_LH_LIST_HEAD({s.name});")
if s.decorated_name in self.linked_lists or s.decorated_name in self.linked_lists_pointered or s.decorated_name in self.lists_heads:
if self.structs:
for s in self.structs:
s.to_code(cw)
if s.decorated_name in self.linked_lists_pointered | self.linked_lists | self.lists_heads:
if s.decorated_name in self.linked_lists:
cw.add_line(f"DECLARE_LH_LINKED_LIST({s.name});")
if s.decorated_name in self.linked_lists_pointered:
cw.add_line(f"DECLARE_P_LH_LINKED_LIST({s.name});")
if s.decorated_name in self.lists_heads:
cw.add_line(f"DECLARE_LH_LIST_HEAD({s.name});")
cw.add_line()

cw.end_if_def()
Expand Down
13 changes: 8 additions & 5 deletions scripts/headers/bw1_decomp_gen/structs.py
Original file line number Diff line number Diff line change
Expand Up @@ -84,6 +84,7 @@ def to_csnake(self) -> csnake.Struct:
def to_code(self, cw: csnake.CodeWriter):
cw.add_struct(self.to_csnake())
cw.add_line(f'static_assert(sizeof({self.decorated_name}) == 0x{self.size:x}, "Data type is of wrong size");')
cw.add_line()


# TODO: Replace with csnake.Union when https://gitlab.com/andrejr/csnake/-/merge_requests/5 lands
Expand Down Expand Up @@ -136,6 +137,7 @@ def to_code(self, cw: csnake.CodeWriter):
# TODO: Must be add_union
cw.add_struct(self.to_csnake())
cw.add_line(f'static_assert(sizeof({self.decorated_name}) == 0x{self.size:x}, "Data type is of wrong size");')
cw.add_line()


@dataclass
Expand Down Expand Up @@ -168,6 +170,7 @@ def to_csnake(self) -> csnake.Enum:
def to_code(self, cw: csnake.CodeWriter):
cw.add_enum(self.to_csnake())
cw.add_line(f'static_assert(sizeof({self.decorated_name}) == 0x{self.size:x}, "Data type is of wrong size");')
cw.add_line()


@dataclass
Expand Down Expand Up @@ -219,41 +222,41 @@ def get_types(self) -> set[str]:
def to_code(self, cw: csnake.CodeWriter):
super().to_code(cw)
if self.vftable_address:
cw.add_line()
vftable_ptr_type = f"{self.decorated_name}Vftable*"
# TODO: Custom fix needed https://gitlab.com/andrejr/csnake/-/merge_requests/10
address = csnake.FormattedLiteral(
value=self.vftable_address, int_formatter=lambda x: f"({vftable_ptr_type})0x{x:08x}")
cw.add_variable_initialization(csnake.Variable(f"__vt__{len(self.name)}{self.name}", vftable_ptr_type, ["static"], value=address))
cw.add_line()

if self.constructors:
cw.add_line()
cw.add_line('// Constructors')
cw.add_line()

for f in self.constructors:
f.to_code(cw)
cw.add_line()

if self.method_overrides:
cw.add_line()
cw.add_line('// Override methods')
cw.add_line()

for f in self.method_overrides:
f.to_code(cw)
cw.add_line()

if self.methods:
cw.add_line()
cw.add_line('// Non-virtual methods')
cw.add_line()

for f in self.methods:
f.to_code(cw)
cw.add_line()

if self.static_methods:
cw.add_line()
cw.add_line('// Static methods')
cw.add_line()

for f in self.static_methods:
f.to_code(cw)
cw.add_line()
3 changes: 3 additions & 0 deletions scripts/headers/tests/header_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -253,6 +253,7 @@ def test_struct_struct_ptr(self):
#include <assert.h> /* For static_assert */
// Forward Declares
struct TestStruct2;
struct TestStruct1
Expand Down Expand Up @@ -489,6 +490,7 @@ def test_structs_with_forward_declare(self):
#include <assert.h> /* For static_assert */
// Forward Declares
enum TestEnum;
struct TestStruct1;
struct TestStruct3;
Expand Down Expand Up @@ -567,6 +569,7 @@ def test_structs_with_functions(self):
#include <assert.h> /* For static_assert */
// Forward Declares
struct TestChildStruct;
struct TestStruct;
Expand Down

0 comments on commit cda3885

Please sign in to comment.