diff --git a/codegen/datatypes.py b/codegen/datatypes.py index 3569180..8aef6b8 100644 --- a/codegen/datatypes.py +++ b/codegen/datatypes.py @@ -92,16 +92,23 @@ class CEnum: class CStruct: name: str cargs: list["CArg"] + typedef_name: str | None = None def __str__(self) -> str: - typedef = f"typedef struct {self.name} {self.name};\n" - header = f"struct {self.name} {{\n" + return self.declare() + self.define() + + def declare(self) -> str: + declaration = f"typedef struct {self.name} {self.typedef_name if self.typedef_name is not None else self.name};\n" + return declaration + + def define(self): + definition = f"struct {self.name} {{\n" args = "" for arg in self.cargs: args += f" {str(arg)};\n" footer = "};\n" - return typedef + header + args + footer; + return definition + args + footer; CUserType = Union[CStruct, CEnum]