Add aliases.h and platform.h by default in codegen
This commit is contained in:
parent
9e34b37d8d
commit
0d541f6ee8
@ -3,6 +3,9 @@ from pathlib import Path
|
|||||||
from typing import Optional, Union, List
|
from typing import Optional, Union, List
|
||||||
from dataclasses import dataclass, field
|
from dataclasses import dataclass, field
|
||||||
|
|
||||||
|
from codegen.constants import WAPP_SRC_ROOT
|
||||||
|
from codegen.utils import convert_to_relative
|
||||||
|
|
||||||
|
|
||||||
class CType(Enum):
|
class CType(Enum):
|
||||||
VOID = "void"
|
VOID = "void"
|
||||||
@ -203,10 +206,25 @@ class CInclude:
|
|||||||
class CFile:
|
class CFile:
|
||||||
name: str
|
name: str
|
||||||
extension: str
|
extension: str
|
||||||
|
includes: List[CInclude] = field(default_factory=list)
|
||||||
|
types: List[CUserType] = field(default_factory=list)
|
||||||
|
funcs: List[CFunc] = field(default_factory=list)
|
||||||
decl_types: List[CStruct] = field(default_factory=list)
|
decl_types: List[CStruct] = field(default_factory=list)
|
||||||
macros: List[CMacro] = field(default_factory=list)
|
macros: List[CMacro] = field(default_factory=list)
|
||||||
|
|
||||||
def save(self, output_dir: Path):
|
def save(self, output_dir: Path):
|
||||||
|
self.includes.extend(
|
||||||
|
[
|
||||||
|
CInclude(
|
||||||
|
header=str(convert_to_relative(WAPP_SRC_ROOT / "common" / "aliases" / "aliases.h", output_dir)).replace("\\", "/"),
|
||||||
|
local=True,
|
||||||
|
),
|
||||||
|
CInclude(
|
||||||
|
header=str(convert_to_relative(WAPP_SRC_ROOT / "common" / "platform" / "platform.h", output_dir)).replace("\\", "/"),
|
||||||
|
local=True,
|
||||||
|
)
|
||||||
|
]
|
||||||
|
)
|
||||||
output_file = output_dir / f"{self.name}.{self.extension}"
|
output_file = output_dir / f"{self.name}.{self.extension}"
|
||||||
with open(output_file, "w+") as outfile:
|
with open(output_file, "w+") as outfile:
|
||||||
outfile.write(str(self))
|
outfile.write(str(self))
|
||||||
@ -223,9 +241,6 @@ class CFile:
|
|||||||
@dataclass
|
@dataclass
|
||||||
class CHeader(CFile):
|
class CHeader(CFile):
|
||||||
extension: str = "h"
|
extension: str = "h"
|
||||||
includes: List[CInclude] = field(default_factory=list)
|
|
||||||
types: List[CUserType] = field(default_factory=list)
|
|
||||||
funcs: List[CFunc] = field(default_factory=list)
|
|
||||||
|
|
||||||
def __str__(self) -> str:
|
def __str__(self) -> str:
|
||||||
name_upper = self.name.upper()
|
name_upper = self.name.upper()
|
||||||
@ -275,10 +290,7 @@ class CHeader(CFile):
|
|||||||
@dataclass
|
@dataclass
|
||||||
class CSource(CFile):
|
class CSource(CFile):
|
||||||
extension: str = "c"
|
extension: str = "c"
|
||||||
includes: List[CInclude] = field(default_factory=list)
|
|
||||||
types: List[CUserType] = field(default_factory=list)
|
|
||||||
internal_funcs: List[CFunc] = field(default_factory=list)
|
internal_funcs: List[CFunc] = field(default_factory=list)
|
||||||
funcs: List[CFunc] = field(default_factory=list)
|
|
||||||
|
|
||||||
def __str__(self) -> str:
|
def __str__(self) -> str:
|
||||||
includes = _get_includes_string(self.includes)
|
includes = _get_includes_string(self.includes)
|
||||||
|
@ -2,7 +2,7 @@ from pathlib import Path
|
|||||||
from dataclasses import dataclass, field
|
from dataclasses import dataclass, field
|
||||||
from typing import List, Dict
|
from typing import List, Dict
|
||||||
from codegen.constants import WAPP_SRC_ROOT
|
from codegen.constants import WAPP_SRC_ROOT
|
||||||
from codegen.utils import load_func_body_from_file, convert_to_relative
|
from codegen.utils import load_func_body_from_file
|
||||||
from codegen.datatypes import (
|
from codegen.datatypes import (
|
||||||
CDataType,
|
CDataType,
|
||||||
CMacro,
|
CMacro,
|
||||||
@ -48,19 +48,9 @@ def make_dbl_list(user_datatypes: Dict[CDataType, DblListData] = {}):
|
|||||||
out_dir = WAPP_SRC_ROOT / "containers" / "dbl_list"
|
out_dir = WAPP_SRC_ROOT / "containers" / "dbl_list"
|
||||||
out_dir.mkdir(parents=True, exist_ok=True)
|
out_dir.mkdir(parents=True, exist_ok=True)
|
||||||
|
|
||||||
common_local_include_files = [
|
|
||||||
(WAPP_SRC_ROOT / "common" / "aliases" / "aliases.h")
|
|
||||||
]
|
|
||||||
common_includes: List[CInclude] = [
|
common_includes: List[CInclude] = [
|
||||||
CInclude(header="stdbool.h")
|
CInclude(header="stdbool.h")
|
||||||
]
|
]
|
||||||
for local_file in common_local_include_files:
|
|
||||||
common_includes.append(
|
|
||||||
CInclude(
|
|
||||||
header=str(convert_to_relative(local_file, out_dir)).replace("\\", "/"),
|
|
||||||
local=True,
|
|
||||||
)
|
|
||||||
)
|
|
||||||
|
|
||||||
common_decl_types: List[CStruct] = []
|
common_decl_types: List[CStruct] = []
|
||||||
|
|
||||||
@ -101,15 +91,7 @@ def make_dbl_list(user_datatypes: Dict[CDataType, DblListData] = {}):
|
|||||||
header = CHeader(
|
header = CHeader(
|
||||||
name="dbl_list",
|
name="dbl_list",
|
||||||
decl_types=[*common_decl_types],
|
decl_types=[*common_decl_types],
|
||||||
includes=[
|
includes=[],
|
||||||
CInclude(
|
|
||||||
header=str(convert_to_relative(
|
|
||||||
WAPP_SRC_ROOT / "common" / "platform" / "platform.h",
|
|
||||||
out_dir
|
|
||||||
)).replace("\\", "/"),
|
|
||||||
local=True,
|
|
||||||
)
|
|
||||||
],
|
|
||||||
types=[],
|
types=[],
|
||||||
funcs=[]
|
funcs=[]
|
||||||
)
|
)
|
||||||
|
@ -4,6 +4,7 @@
|
|||||||
|
|
||||||
#include "./dbl_list.h"
|
#include "./dbl_list.h"
|
||||||
#include "../../common/aliases/aliases.h"
|
#include "../../common/aliases/aliases.h"
|
||||||
|
#include "../../common/platform/platform.h"
|
||||||
#include <stddef.h>
|
#include <stddef.h>
|
||||||
#include <stdbool.h>
|
#include <stdbool.h>
|
||||||
|
|
||||||
|
@ -5,8 +5,8 @@
|
|||||||
#ifndef DBL_LIST_H
|
#ifndef DBL_LIST_H
|
||||||
#define DBL_LIST_H
|
#define DBL_LIST_H
|
||||||
|
|
||||||
#include "../../common/platform/platform.h"
|
|
||||||
#include "../../common/aliases/aliases.h"
|
#include "../../common/aliases/aliases.h"
|
||||||
|
#include "../../common/platform/platform.h"
|
||||||
#include <stdbool.h>
|
#include <stdbool.h>
|
||||||
|
|
||||||
#ifdef WAPP_PLATFORM_CPP
|
#ifdef WAPP_PLATFORM_CPP
|
||||||
|
Loading…
x
Reference in New Issue
Block a user