""" interface_declaration.py """ from dataclasses import dataclass, asdict from pathlib import Path @dataclass class InterfaceDeclaration: """interface declaration class""" name: str license_hdr: str system_includes: list[str] types: list[dict] functions: list[dict] def read_license(self, path: Path): """read and starrify a license""" if path is None: self.license_hdr = "" return 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": [ "int fd", "int (*putc)(const struct kstdio_File*, const char)", "int (*puts)(const struct kstdio_File*, const char*)", ], }, ] self.functions = [ { "name": "printf", "return": "int", "arguments": ["const char* format"], "argument_names": ["format"], }, ] def into_dict(self) -> dict: """create a dictionary for use in mako""" return asdict(self)