diff options
Diffstat (limited to 'tools/interface_generator/bin/interface_definition.py')
-rw-r--r-- | tools/interface_generator/bin/interface_definition.py | 57 |
1 files changed, 34 insertions, 23 deletions
diff --git a/tools/interface_generator/bin/interface_definition.py b/tools/interface_generator/bin/interface_definition.py index 3b9c4a3..2fd7e9a 100644 --- a/tools/interface_generator/bin/interface_definition.py +++ b/tools/interface_generator/bin/interface_definition.py @@ -2,29 +2,39 @@ interface_definition.py """ +from dataclasses import dataclass, asdict +from pathlib import Path -def __read_license(path): - """read and starrify a license""" - license_text = "" - with open(path, encoding="utf-8") as license_file: - license_text = "".join( - [ - f" * { line.rstrip().ljust(72)[:72] } * \n" - for line in license_file.readlines() - ] - ).rstrip() - return license_text +@dataclass +class InterfaceDefinition: + """interface definition class""" + name: str + license_hdr: str + system_includes: list[str] + types: list[dict] + functions: list[dict] -def parse(args): - """return a mock interface definition""" + def read_license(self, path: Path): + """read and starrify a license""" + if path is None: + self.license_hdr = "" + return - interface_dict = { - "name": "kstdio", - "license": __read_license(args.license), - "system_includes": ["stdarg.h"], - "types": [ + with open(path, encoding="utf-8") as license_file: + self.license_hdr = "".join( + [ + f" * { line.rstrip().ljust(72)[:72] } * \n" + for line in license_file.readlines() + ] + ).rstrip() + + def __init__(self, name: str, license_path: Path): + self.name = name if name is not None else "kstdio" + self.read_license(license_path) + self.system_includes = ["stdarg.h"] + self.types = [ { "name": "File", "members": [ @@ -33,15 +43,16 @@ def parse(args): "int (*puts)(const struct kstdio_File*, const char*)", ], }, - ], - "functions": [ + ] + self.functions = [ { "name": "printf", "return": "int", "arguments": ["const char* format"], "argument_names": ["format"], }, - ], - } + ] - return interface_dict + def into_dict(self) -> dict: + """create a dictionary for use in mako""" + return asdict(self) |