File utilities and datatype implementation for a C-based code generator (#5)
Co-authored-by: Abdelrahman Said <said.abdelrahman@flawlessai.com> Reviewed-on: #5 Co-authored-by: Abdelrahman <said.abdelrahman89@gmail.com> Co-committed-by: Abdelrahman <said.abdelrahman89@gmail.com>
This commit is contained in:
@@ -56,16 +56,11 @@ def make_dbl_list(user_datatypes: Dict[CDataType, DblListData] = {}):
|
||||
out_dir = WAPP_SRC_ROOT / "primitives" / "dbl_list"
|
||||
out_dir.mkdir(parents=True, exist_ok=True)
|
||||
|
||||
common_includes: List[CInclude] = [
|
||||
CInclude(
|
||||
header=str(convert_to_relative(WAPP_SRC_ROOT / "common" / "aliases" / "aliases.h", out_dir)).replace("\\", "/"),
|
||||
local=True,
|
||||
)
|
||||
]
|
||||
|
||||
common_decl_types: List[CStruct] = []
|
||||
|
||||
datatypes: dict[CDataType, DblListData] = {
|
||||
CType.VOID: DblListData(node_typename="GenericNode", list_typename="GenericList"),
|
||||
"void *": DblListData(node_typename="VoidPNode", list_typename="VoidPList"),
|
||||
"Str8": DblListData(
|
||||
node_typename="Str8Node",
|
||||
list_typename="Str8List",
|
||||
@@ -77,14 +72,10 @@ def make_dbl_list(user_datatypes: Dict[CDataType, DblListData] = {}):
|
||||
|
||||
for _type in CType:
|
||||
if _type == CType.VOID:
|
||||
datatypes["void *"] = DblListData(
|
||||
node_typename="VoidPNode",
|
||||
list_typename="VoidPList",
|
||||
)
|
||||
continue
|
||||
|
||||
type_title = _type.value.title()
|
||||
datatypes[_type.value] = DblListData(
|
||||
datatypes[_type] = DblListData(
|
||||
node_typename=f"{type_title}Node",
|
||||
list_typename=f"{type_title}List",
|
||||
)
|
||||
@@ -111,16 +102,11 @@ def make_dbl_list(user_datatypes: Dict[CDataType, DblListData] = {}):
|
||||
local=True
|
||||
),
|
||||
CInclude(header="stddef.h"),
|
||||
CInclude(header="assert.h"),
|
||||
],
|
||||
internal_funcs=[],
|
||||
funcs=header.funcs
|
||||
)
|
||||
|
||||
if len(common_includes) > 0:
|
||||
header.includes.extend(common_includes)
|
||||
source.includes.extend(common_includes)
|
||||
|
||||
for _type, dbl_list_data in datatypes.items():
|
||||
type_string = get_datatype_string(_type)
|
||||
clean_type_string = type_string.replace(" ", "").replace("*", "_ptr")
|
||||
@@ -147,6 +133,13 @@ def make_dbl_list(user_datatypes: Dict[CDataType, DblListData] = {}):
|
||||
],
|
||||
)
|
||||
|
||||
header.types.extend([node, dl_list])
|
||||
header.decl_types.extend(dbl_list_data.hdr_decl_types)
|
||||
source.decl_types.extend(dbl_list_data.src_decl_types)
|
||||
if isinstance(_type, CType) and _type == CType.VOID:
|
||||
# Don't define any functions for the generic node and list
|
||||
continue
|
||||
|
||||
node_cmacro = CMacro(
|
||||
name=f"wapp_{type_string_lower}_list_node(ITEM_PTR)",
|
||||
value=__format_func_body(
|
||||
@@ -326,10 +319,8 @@ def make_dbl_list(user_datatypes: Dict[CDataType, DblListData] = {}):
|
||||
qualifiers=[CQualifier.INTERNAL],
|
||||
)
|
||||
|
||||
header.decl_types.extend(dbl_list_data.hdr_decl_types)
|
||||
header.c_macros.append(node_cmacro)
|
||||
header.cpp_macros.append(node_cppmacro)
|
||||
header.types.extend([node, dl_list])
|
||||
header.funcs.extend([
|
||||
get_func,
|
||||
push_front_func,
|
||||
@@ -341,7 +332,6 @@ def make_dbl_list(user_datatypes: Dict[CDataType, DblListData] = {}):
|
||||
empty_func,
|
||||
])
|
||||
|
||||
source.decl_types.extend(dbl_list_data.src_decl_types)
|
||||
source.internal_funcs.append(node_to_list_func)
|
||||
source.funcs = header.funcs
|
||||
|
||||
|
Reference in New Issue
Block a user