diff --git a/docs/Changelog.txt b/docs/Changelog.txt index 3ce864c..dd980cd 100644 --- a/docs/Changelog.txt +++ b/docs/Changelog.txt @@ -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 diff --git a/src/code_dom/classstructunion.py b/src/code_dom/classstructunion.py index ee4759d..2a2904f 100644 --- a/src/code_dom/classstructunion.py +++ b/src/code_dom/classstructunion.py @@ -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? @@ -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": @@ -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 + ";")) diff --git a/src/modifiers/mod_forward_declare_structs.py b/src/modifiers/mod_forward_declare_structs.py index 49ca151..b978de0 100644 --- a/src/modifiers/mod_forward_declare_structs.py +++ b/src/modifiers/mod_forward_declare_structs.py @@ -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