Add support for forward declarations
This commit is contained in:
parent
a9791962b0
commit
b8e2f8a4d7
@ -190,6 +190,7 @@ class CInclude:
|
||||
class CFile:
|
||||
name: str
|
||||
extension: str
|
||||
decl_types: list[CStruct] = field(default_factory=list)
|
||||
|
||||
def save(self, output_dir: Path):
|
||||
output_file = output_dir / f"{self.name}.{self.extension}"
|
||||
@ -212,6 +213,12 @@ class CHeader(CFile):
|
||||
|
||||
includes = _get_includes_string(self.includes)
|
||||
|
||||
forward_declarations = ""
|
||||
for _type in self.decl_types:
|
||||
forward_declarations += _type.declare()
|
||||
if len(forward_declarations) > 0:
|
||||
forward_declarations += "\n"
|
||||
|
||||
types = ""
|
||||
for _type in self.types:
|
||||
types += str(_type) + "\n"
|
||||
@ -220,7 +227,7 @@ class CHeader(CFile):
|
||||
for func in self.funcs:
|
||||
funcs += func.declare()
|
||||
|
||||
return pragma + includes + types + funcs
|
||||
return pragma + includes + forward_declarations + types + funcs
|
||||
|
||||
|
||||
@dataclass
|
||||
@ -234,6 +241,12 @@ class CSource(CFile):
|
||||
def __str__(self) -> str:
|
||||
includes = _get_includes_string(self.includes)
|
||||
|
||||
forward_declarations = ""
|
||||
for _type in self.decl_types:
|
||||
forward_declarations += _type.declare()
|
||||
if len(forward_declarations) > 0:
|
||||
forward_declarations += "\n"
|
||||
|
||||
types = ""
|
||||
for _type in self.types:
|
||||
types += str(_type) + "\n"
|
||||
@ -251,7 +264,7 @@ class CSource(CFile):
|
||||
for func in self.funcs:
|
||||
funcs += func.define()
|
||||
|
||||
return includes + types + internal_funcs_decl + funcs + internal_funcs_def
|
||||
return includes + forward_declarations + types + internal_funcs_decl + funcs + internal_funcs_def
|
||||
|
||||
|
||||
def get_datatype_string(_type: CDataType) -> str:
|
||||
|
Loading…
Reference in New Issue
Block a user