Update code generation to create one file for dbl_list
This commit is contained in:
parent
3c32b247c0
commit
63ed2633ea
@ -8,7 +8,6 @@ def main():
|
|||||||
|
|
||||||
def gen_dbl_list():
|
def gen_dbl_list():
|
||||||
datatypes: dict[CDataType, DblListData] = {}
|
datatypes: dict[CDataType, DblListData] = {}
|
||||||
|
|
||||||
make_dbl_list(datatypes)
|
make_dbl_list(datatypes)
|
||||||
|
|
||||||
|
|
||||||
|
@ -88,6 +88,15 @@ class CEnum:
|
|||||||
return header + values + footer
|
return header + values + footer
|
||||||
|
|
||||||
|
|
||||||
|
@dataclass
|
||||||
|
class CMacro:
|
||||||
|
name: str
|
||||||
|
value: str
|
||||||
|
|
||||||
|
def __str__(self) -> str:
|
||||||
|
return f"#define {self.name} {self.value}\n"
|
||||||
|
|
||||||
|
|
||||||
@dataclass
|
@dataclass
|
||||||
class CStruct:
|
class CStruct:
|
||||||
name: str
|
name: str
|
||||||
@ -195,6 +204,7 @@ class CFile:
|
|||||||
name: str
|
name: str
|
||||||
extension: str
|
extension: str
|
||||||
decl_types: list[CStruct] = field(default_factory=list)
|
decl_types: list[CStruct] = field(default_factory=list)
|
||||||
|
macros: list[CMacro] = field(default_factory=list)
|
||||||
|
|
||||||
def save(self, output_dir: Path):
|
def save(self, output_dir: Path):
|
||||||
output_file = output_dir / f"{self.name}.{self.extension}"
|
output_file = output_dir / f"{self.name}.{self.extension}"
|
||||||
@ -228,6 +238,12 @@ class CHeader(CFile):
|
|||||||
|
|
||||||
includes = _get_includes_string(self.includes)
|
includes = _get_includes_string(self.includes)
|
||||||
|
|
||||||
|
macros = ""
|
||||||
|
for macro in self.macros:
|
||||||
|
macros += str(macro)
|
||||||
|
if len(macros) > 0:
|
||||||
|
macros += "\n"
|
||||||
|
|
||||||
forward_declarations = ""
|
forward_declarations = ""
|
||||||
for _type in self.decl_types:
|
for _type in self.decl_types:
|
||||||
forward_declarations += _type.declare()
|
forward_declarations += _type.declare()
|
||||||
@ -247,6 +263,7 @@ class CHeader(CFile):
|
|||||||
header_guard_open +
|
header_guard_open +
|
||||||
includes +
|
includes +
|
||||||
c_linkage_open +
|
c_linkage_open +
|
||||||
|
macros +
|
||||||
forward_declarations +
|
forward_declarations +
|
||||||
types +
|
types +
|
||||||
funcs +
|
funcs +
|
||||||
@ -266,6 +283,12 @@ class CSource(CFile):
|
|||||||
def __str__(self) -> str:
|
def __str__(self) -> str:
|
||||||
includes = _get_includes_string(self.includes)
|
includes = _get_includes_string(self.includes)
|
||||||
|
|
||||||
|
macros = ""
|
||||||
|
for macro in self.macros:
|
||||||
|
macros += str(macro)
|
||||||
|
if len(macros) > 0:
|
||||||
|
macros += "\n"
|
||||||
|
|
||||||
forward_declarations = ""
|
forward_declarations = ""
|
||||||
for _type in self.decl_types:
|
for _type in self.decl_types:
|
||||||
forward_declarations += _type.declare()
|
forward_declarations += _type.declare()
|
||||||
@ -292,6 +315,7 @@ class CSource(CFile):
|
|||||||
return (
|
return (
|
||||||
super().__str__() +
|
super().__str__() +
|
||||||
includes +
|
includes +
|
||||||
|
macros +
|
||||||
forward_declarations +
|
forward_declarations +
|
||||||
types +
|
types +
|
||||||
internal_funcs_decl +
|
internal_funcs_decl +
|
||||||
|
@ -4,6 +4,7 @@ from codegen.constants import WAPP_SRC_ROOT
|
|||||||
from codegen.utils import load_func_body_from_file
|
from codegen.utils import load_func_body_from_file
|
||||||
from codegen.datatypes import (
|
from codegen.datatypes import (
|
||||||
CDataType,
|
CDataType,
|
||||||
|
CMacro,
|
||||||
CStruct,
|
CStruct,
|
||||||
CFunc,
|
CFunc,
|
||||||
CHeader,
|
CHeader,
|
||||||
@ -20,9 +21,6 @@ from codegen.datatypes import (
|
|||||||
|
|
||||||
@dataclass
|
@dataclass
|
||||||
class DblListData:
|
class DblListData:
|
||||||
out_dir: Path
|
|
||||||
hdr_includes: list[CInclude] = field(default_factory=list)
|
|
||||||
src_includes: list[CInclude] = field(default_factory=list)
|
|
||||||
hdr_decl_types: list[CStruct] = field(default_factory=list)
|
hdr_decl_types: list[CStruct] = field(default_factory=list)
|
||||||
src_decl_types: list[CStruct] = field(default_factory=list)
|
src_decl_types: list[CStruct] = field(default_factory=list)
|
||||||
|
|
||||||
@ -36,10 +34,20 @@ def make_dbl_list(user_datatypes: dict[CDataType, DblListData] = {}):
|
|||||||
Tlower=type_string.lower(),
|
Tlower=type_string.lower(),
|
||||||
)
|
)
|
||||||
|
|
||||||
|
out_dir = WAPP_SRC_ROOT / "containers" / "dbl_list"
|
||||||
|
out_dir.mkdir(parents=True, exist_ok=True)
|
||||||
|
|
||||||
common_local_include_files = [
|
common_local_include_files = [
|
||||||
(WAPP_SRC_ROOT / "common" / "aliases" / "aliases.h")
|
(WAPP_SRC_ROOT / "common" / "aliases" / "aliases.h")
|
||||||
]
|
]
|
||||||
common_includes: list[CInclude] = []
|
common_includes: list[CInclude] = []
|
||||||
|
for local_file in common_local_include_files:
|
||||||
|
common_includes.append(
|
||||||
|
CInclude(
|
||||||
|
header=str(local_file.relative_to(out_dir, walk_up=True)),
|
||||||
|
local=True,
|
||||||
|
)
|
||||||
|
)
|
||||||
|
|
||||||
common_decl_types: list[CStruct] = []
|
common_decl_types: list[CStruct] = []
|
||||||
|
|
||||||
@ -48,13 +56,32 @@ def make_dbl_list(user_datatypes: dict[CDataType, DblListData] = {}):
|
|||||||
hdr_decl_types=[
|
hdr_decl_types=[
|
||||||
CStruct(name="str8", cargs=[], typedef_name="Str8"),
|
CStruct(name="str8", cargs=[], typedef_name="Str8"),
|
||||||
],
|
],
|
||||||
out_dir=WAPP_SRC_ROOT / "core" / "strings" / "str8",
|
|
||||||
),
|
),
|
||||||
}
|
}
|
||||||
datatypes.update(user_datatypes)
|
datatypes.update(user_datatypes)
|
||||||
|
|
||||||
snippets_dir = Path(__file__).parent / "snippets"
|
snippets_dir = Path(__file__).parent / "snippets"
|
||||||
|
|
||||||
|
header = CHeader(
|
||||||
|
name="dbl_list",
|
||||||
|
decl_types=common_decl_types,
|
||||||
|
includes=[],
|
||||||
|
types=[],
|
||||||
|
funcs=[]
|
||||||
|
)
|
||||||
|
|
||||||
|
source = CSource(
|
||||||
|
name=header.name,
|
||||||
|
decl_types=common_decl_types,
|
||||||
|
includes=[CInclude(header, local=True, same_dir=True), CInclude(header="stddef.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():
|
for _type, dbl_list_data in datatypes.items():
|
||||||
type_string = get_datatype_string(_type)
|
type_string = get_datatype_string(_type)
|
||||||
|
|
||||||
@ -78,13 +105,9 @@ def make_dbl_list(user_datatypes: dict[CDataType, DblListData] = {}):
|
|||||||
],
|
],
|
||||||
)
|
)
|
||||||
|
|
||||||
node_func = CFunc(
|
node_macro = CMacro(
|
||||||
name=f"wapp_{type_string.lower()}_list_node",
|
name=f"wapp_{type_string.lower()}_list_node(ITEM_PTR)",
|
||||||
ret_type=node,
|
value=__format_func_body(snippets_dir / "list_node", type_string),
|
||||||
args=[
|
|
||||||
CArg(name="item", _type=type_string, pointer=CPointer(CPointerType.SINGLE)),
|
|
||||||
],
|
|
||||||
body=__format_func_body(snippets_dir / "list_node", type_string),
|
|
||||||
)
|
)
|
||||||
|
|
||||||
get_func = CFunc(
|
get_func = CFunc(
|
||||||
@ -179,13 +202,10 @@ def make_dbl_list(user_datatypes: dict[CDataType, DblListData] = {}):
|
|||||||
qualifiers=[CQualifier.INTERNAL],
|
qualifiers=[CQualifier.INTERNAL],
|
||||||
)
|
)
|
||||||
|
|
||||||
header = CHeader(
|
header.decl_types.extend(dbl_list_data.hdr_decl_types)
|
||||||
name=f"{type_string.lower()}_list",
|
header.macros.append(node_macro)
|
||||||
decl_types=common_decl_types + dbl_list_data.hdr_decl_types,
|
header.types.extend([node, dl_list])
|
||||||
includes=[],
|
header.funcs.extend([
|
||||||
types=[node, dl_list],
|
|
||||||
funcs=[
|
|
||||||
node_func,
|
|
||||||
get_func,
|
get_func,
|
||||||
push_front_func,
|
push_front_func,
|
||||||
push_back_func,
|
push_back_func,
|
||||||
@ -194,31 +214,11 @@ def make_dbl_list(user_datatypes: dict[CDataType, DblListData] = {}):
|
|||||||
pop_back_func,
|
pop_back_func,
|
||||||
remove_func,
|
remove_func,
|
||||||
empty_func,
|
empty_func,
|
||||||
]
|
])
|
||||||
)
|
|
||||||
|
|
||||||
source = CSource(
|
source.decl_types.extend(dbl_list_data.src_decl_types)
|
||||||
name=header.name,
|
source.internal_funcs.append(node_to_list_func)
|
||||||
decl_types=common_decl_types + dbl_list_data.src_decl_types,
|
source.funcs = header.funcs
|
||||||
includes=[CInclude(header, local=True, same_dir=True), CInclude(header="stddef.h")],
|
|
||||||
internal_funcs=[node_to_list_func],
|
|
||||||
funcs=header.funcs
|
|
||||||
)
|
|
||||||
|
|
||||||
if len(common_includes) > 0:
|
header.save(out_dir)
|
||||||
header.includes.extend(common_includes)
|
source.save(out_dir)
|
||||||
source.includes.extend(common_includes)
|
|
||||||
|
|
||||||
for include_file in common_local_include_files:
|
|
||||||
include = CInclude(header=str(include_file.relative_to(dbl_list_data.out_dir, walk_up=True)), local=True)
|
|
||||||
header.includes.append(include)
|
|
||||||
source.includes.append(include)
|
|
||||||
|
|
||||||
if len(dbl_list_data.hdr_includes) > 0:
|
|
||||||
header.includes.extend(dbl_list_data.hdr_includes)
|
|
||||||
|
|
||||||
if len(dbl_list_data.src_includes) > 0:
|
|
||||||
source.includes.extend(dbl_list_data.src_includes)
|
|
||||||
|
|
||||||
header.save(dbl_list_data.out_dir)
|
|
||||||
source.save(dbl_list_data.out_dir)
|
|
||||||
|
@ -1 +1 @@
|
|||||||
return ({Ttitle}Node){{.item = item}};
|
(({Ttitle}Node){{.item = ITEM_PTR}})
|
||||||
|
@ -2,15 +2,13 @@
|
|||||||
* THIS FILE IS AUTOMATICALLY GENERATED. ANY MODIFICATIONS TO IT WILL BE OVERWRITTEN
|
* THIS FILE IS AUTOMATICALLY GENERATED. ANY MODIFICATIONS TO IT WILL BE OVERWRITTEN
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include "./str8_list.h"
|
#include "./dbl_list.h"
|
||||||
#include "../../../common/aliases/aliases.h"
|
#include "../../common/aliases/aliases.h"
|
||||||
#include <stddef.h>
|
#include <stddef.h>
|
||||||
|
|
||||||
internal Str8List str8_node_to_list(Str8Node *node);
|
typedef struct str8 Str8;
|
||||||
|
|
||||||
Str8Node wapp_str8_list_node(Str8 *item) {
|
internal Str8List str8_node_to_list(Str8Node *node);
|
||||||
return (Str8Node){.item = item};
|
|
||||||
}
|
|
||||||
|
|
||||||
Str8Node *wapp_str8_list_get(const Str8List *list, u64 index) {
|
Str8Node *wapp_str8_list_get(const Str8List *list, u64 index) {
|
||||||
if (index >= list->node_count) {
|
if (index >= list->node_count) {
|
@ -2,15 +2,17 @@
|
|||||||
* THIS FILE IS AUTOMATICALLY GENERATED. ANY MODIFICATIONS TO IT WILL BE OVERWRITTEN
|
* THIS FILE IS AUTOMATICALLY GENERATED. ANY MODIFICATIONS TO IT WILL BE OVERWRITTEN
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#ifndef STR8_LIST_H
|
#ifndef DBL_LIST_H
|
||||||
#define STR8_LIST_H
|
#define DBL_LIST_H
|
||||||
|
|
||||||
#include "../../../common/aliases/aliases.h"
|
#include "../../common/aliases/aliases.h"
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
BEGIN_C_LINKAGE
|
BEGIN_C_LINKAGE
|
||||||
#endif // !__cplusplus
|
#endif // !__cplusplus
|
||||||
|
|
||||||
|
#define wapp_str8_list_node(ITEM_PTR) ((Str8Node){.item = ITEM_PTR})
|
||||||
|
|
||||||
typedef struct str8 Str8;
|
typedef struct str8 Str8;
|
||||||
|
|
||||||
typedef struct Str8Node Str8Node;
|
typedef struct Str8Node Str8Node;
|
||||||
@ -27,7 +29,6 @@ struct Str8List {
|
|||||||
u64 node_count;
|
u64 node_count;
|
||||||
};
|
};
|
||||||
|
|
||||||
Str8Node wapp_str8_list_node(Str8 *item);
|
|
||||||
Str8Node *wapp_str8_list_get(const Str8List *list, u64 index);
|
Str8Node *wapp_str8_list_get(const Str8List *list, u64 index);
|
||||||
void wapp_str8_list_push_front(Str8List *list, Str8Node *node);
|
void wapp_str8_list_push_front(Str8List *list, Str8Node *node);
|
||||||
void wapp_str8_list_push_back(Str8List *list, Str8Node *node);
|
void wapp_str8_list_push_back(Str8List *list, Str8Node *node);
|
||||||
@ -41,4 +42,4 @@ void wapp_str8_list_empty(Str8List *list);
|
|||||||
END_C_LINKAGE
|
END_C_LINKAGE
|
||||||
#endif // !__cplusplus
|
#endif // !__cplusplus
|
||||||
|
|
||||||
#endif // !STR8_LIST_H
|
#endif // !DBL_LIST_H
|
6
src/containers/wapp_containers.c
Normal file
6
src/containers/wapp_containers.c
Normal file
@ -0,0 +1,6 @@
|
|||||||
|
#ifndef WAPP_CONTAINERS_C
|
||||||
|
#define WAPP_CONTAINERS_C
|
||||||
|
|
||||||
|
#include "dbl_list/dbl_list.c"
|
||||||
|
|
||||||
|
#endif // !WAPP_CONTAINERS_C
|
7
src/containers/wapp_containers.h
Normal file
7
src/containers/wapp_containers.h
Normal file
@ -0,0 +1,7 @@
|
|||||||
|
#ifndef WAPP_CONTAINERS_H
|
||||||
|
#define WAPP_CONTAINERS_H
|
||||||
|
|
||||||
|
#include "dbl_list/dbl_list.h"
|
||||||
|
#include "../common/wapp_common.h"
|
||||||
|
|
||||||
|
#endif // !WAPP_CONTAINERS_H
|
@ -1,8 +1,8 @@
|
|||||||
#ifndef STR8_H
|
#ifndef STR8_H
|
||||||
#define STR8_H
|
#define STR8_H
|
||||||
|
|
||||||
#include "./str8_list.h"
|
|
||||||
#include "../../../common/aliases/aliases.h"
|
#include "../../../common/aliases/aliases.h"
|
||||||
|
#include "../../../containers/dbl_list/dbl_list.h"
|
||||||
#include "../../mem/allocator/mem_allocator.h"
|
#include "../../mem/allocator/mem_allocator.h"
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <stdbool.h>
|
#include <stdbool.h>
|
||||||
@ -91,8 +91,8 @@ Str8 *wapp_str8_join(const Allocator *allocator, const Str8List *list, Str8R
|
|||||||
/**
|
/**
|
||||||
* Str8 list utilities
|
* Str8 list utilities
|
||||||
*/
|
*/
|
||||||
#define wapp_str8_node_from_cstr(STRING) ((Str8Node){.item = &wapp_str8_lit(STRING)})
|
#define wapp_str8_node_from_cstr(STRING) wapp_str8_list_node(&wapp_str8_lit(STRING))
|
||||||
#define wapp_str8_node_from_str8(STRING) ((Str8Node){.item = &(STRING)})
|
#define wapp_str8_node_from_str8(STRING) wapp_str8_list_node(&(STRING))
|
||||||
u64 wapp_str8_list_total_size(const Str8List *list);
|
u64 wapp_str8_list_total_size(const Str8List *list);
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
|
@ -3,7 +3,6 @@
|
|||||||
|
|
||||||
#include "wapp_core.h"
|
#include "wapp_core.h"
|
||||||
#include "strings/str8/str8.c"
|
#include "strings/str8/str8.c"
|
||||||
#include "strings/str8/str8_list.c"
|
|
||||||
#include "os/shell/termcolour/posix/termcolour_posix.c"
|
#include "os/shell/termcolour/posix/termcolour_posix.c"
|
||||||
#include "os/shell/termcolour/win/termcolour_win.c"
|
#include "os/shell/termcolour/win/termcolour_win.c"
|
||||||
#include "os/shell/termcolour/termcolour.c"
|
#include "os/shell/termcolour/termcolour.c"
|
||||||
@ -18,5 +17,6 @@
|
|||||||
#include "mem/allocator/mem_allocator.c"
|
#include "mem/allocator/mem_allocator.c"
|
||||||
#include "mem/arena/mem_arena.c"
|
#include "mem/arena/mem_arena.c"
|
||||||
#include "mem/arena/mem_arena_allocator.c"
|
#include "mem/arena/mem_arena_allocator.c"
|
||||||
|
#include "../containers/wapp_containers.c"
|
||||||
|
|
||||||
#endif // !WAPP_CORE_C
|
#endif // !WAPP_CORE_C
|
||||||
|
@ -2,7 +2,6 @@
|
|||||||
#define WAPP_CORE_H
|
#define WAPP_CORE_H
|
||||||
|
|
||||||
#include "strings/str8/str8.h"
|
#include "strings/str8/str8.h"
|
||||||
#include "strings/str8/str8_list.h"
|
|
||||||
#include "os/shell/termcolour/termcolour.h"
|
#include "os/shell/termcolour/termcolour.h"
|
||||||
#include "os/shell/termcolour/terminal_colours.h"
|
#include "os/shell/termcolour/terminal_colours.h"
|
||||||
#include "os/shell/commander/commander.h"
|
#include "os/shell/commander/commander.h"
|
||||||
@ -18,5 +17,6 @@
|
|||||||
#include "mem/arena/mem_arena_allocator.h"
|
#include "mem/arena/mem_arena_allocator.h"
|
||||||
#include "mem/arena/mem_arena.h"
|
#include "mem/arena/mem_arena.h"
|
||||||
#include "../common/wapp_common.h"
|
#include "../common/wapp_common.h"
|
||||||
|
#include "../containers/wapp_containers.h"
|
||||||
|
|
||||||
#endif // !WAPP_CORE_H
|
#endif // !WAPP_CORE_H
|
||||||
|
Loading…
Reference in New Issue
Block a user