Update struct to split declaration and definition
This commit is contained in:
		| @@ -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] | ||||
|   | ||||
		Reference in New Issue
	
	Block a user