Skip to content

Commit

Permalink
Removed unnecessary typedefs from structs with forward declarations t…
Browse files Browse the repository at this point in the history
…o avoid warnings on C99 compilers
  • Loading branch information
ShironekoBen committed Dec 9, 2024
1 parent 0a5b58e commit 139b5b8
Show file tree
Hide file tree
Showing 3 changed files with 15 additions and 4 deletions.
1 change: 1 addition & 0 deletions docs/Changelog.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,6 +5,7 @@
* Added --custom-namespace-prefix and --replace-prefix to support custom naming schemes (#80)
* Make the imconfig.h path use the parent directory by default if --backend is specified (#81)
* **BREAKING CHANGE** Modified default output filename to be dcimgui.h instead of cimgui.h to avoid ambiguity (#80)
* Removed unnecessary typedefs from structs with forward declarations to avoid warnings on C99 compilers (#82)

--- v0.10

Expand Down
11 changes: 7 additions & 4 deletions src/code_dom/classstructunion.py
Original file line number Diff line number Diff line change
Expand Up @@ -8,7 +8,8 @@ def __init__(self):
super().__init__()
self.name = None # Can be none for anonymous things if they haven't been given a temporary name
self.is_anonymous = True
self.is_forward_declaration = True
self.is_forward_declaration = True # Is this a forward-declaration
self.has_forward_declaration = False
self.is_by_value = False # Is this to be passed by value? (set during modification)
self.structure_type = None # Will be "STRUCT", "CLASS" or "UNION"
self.is_imgui_api = False # Does this use IMGUI_API?
Expand Down Expand Up @@ -107,7 +108,9 @@ def write_to_c(self, file, indent=0, context=WriteContext()):

declaration = ""

if context.for_c and not self.is_anonymous:
need_typedef = context.for_c and not self.is_anonymous and not self.has_forward_declaration

if need_typedef:
declaration += "typedef "

if self.structure_type == "STRUCT":
Expand Down Expand Up @@ -149,12 +152,12 @@ def write_to_c(self, file, indent=0, context=WriteContext()):
write_c_line(file, indent, context, "{")
for child in self.children:
child.write_to_c(file, indent + 1, context)
if context.for_c and not self.is_anonymous:
if need_typedef:
write_c_line(file, indent, context, "} " + self.name + ";")
else:
write_c_line(file, indent, context, "};")
else:
if context.for_c and not self.is_anonymous:
if need_typedef:
write_c_line(file, indent, context, self.add_attached_comment_to_line(context, declaration + " " + self.name + ";"))
else:
write_c_line(file, indent, context, self.add_attached_comment_to_line(context, declaration + ";"))
Expand Down
7 changes: 7 additions & 0 deletions src/modifiers/mod_forward_declare_structs.py
Original file line number Diff line number Diff line change
Expand Up @@ -76,3 +76,10 @@ def apply(dom_root):
next_line = insert_point.parent.get_next_child(insert_point)

insert_point.parent.insert_after_child(insert_point, dom_headers_declarations)

# Mark anything we found a forward declaration for as having one

for struct in dom_root.list_all_children_of_type(code_dom.DOMClassStructUnion):
if (struct.structure_type != "UNION") and struct.name in forward_declarations:
if not struct.is_forward_declaration:
struct.has_forward_declaration = True

0 comments on commit 139b5b8

Please sign in to comment.