Update struct to split declaration and definition
This commit is contained in:
parent
cb093cc030
commit
a9791962b0
@ -92,16 +92,23 @@ class CEnum:
|
|||||||
class CStruct:
|
class CStruct:
|
||||||
name: str
|
name: str
|
||||||
cargs: list["CArg"]
|
cargs: list["CArg"]
|
||||||
|
typedef_name: str | None = None
|
||||||
|
|
||||||
def __str__(self) -> str:
|
def __str__(self) -> str:
|
||||||
typedef = f"typedef struct {self.name} {self.name};\n"
|
return self.declare() + self.define()
|
||||||
header = f"struct {self.name} {{\n"
|
|
||||||
|
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 = ""
|
args = ""
|
||||||
for arg in self.cargs:
|
for arg in self.cargs:
|
||||||
args += f" {str(arg)};\n"
|
args += f" {str(arg)};\n"
|
||||||
footer = "};\n"
|
footer = "};\n"
|
||||||
|
|
||||||
return typedef + header + args + footer;
|
return definition + args + footer;
|
||||||
|
|
||||||
|
|
||||||
CUserType = Union[CStruct, CEnum]
|
CUserType = Union[CStruct, CEnum]
|
||||||
|
Loading…
Reference in New Issue
Block a user