diff --git a/cppygen/component.py b/cppygen/component.py index 04e641b..1cd4cf6 100644 --- a/cppygen/component.py +++ b/cppygen/component.py @@ -1,4 +1,4 @@ -from typing import Dict, List, Tuple +from typing import Dict, List, Tuple, cast class Function(object): @@ -77,6 +77,10 @@ def to_decl_string(self): f'{{ {self._return_type} {self._name}({", ".join(args)}); }}' ) + def signature(self) -> str: + args = [f"{i[1]} {i[0]}" for i in self._arguments] + return f'{"::".join(self._namespace)}::{self._name}({", ".join(args)}) -> {self._return_type}' + def __eq__(self, obj): if isinstance(obj, Function): return self._full_name == obj._full_name @@ -175,6 +179,9 @@ def to_pybind_string(self): + ";" ) + def signature(self) -> str: + return f"{self._full_name}" + class Submodule: """ @@ -218,6 +225,7 @@ def to_pybind_string(self): def __eq__(self, obj): if isinstance(obj, Submodule): - return self._name == obj._name + return self.cpp_name == obj.cpp_name else: return False + diff --git a/cppygen/cppygen_parser.py b/cppygen/cppygen_parser.py index c5108d8..65d5dba 100644 --- a/cppygen/cppygen_parser.py +++ b/cppygen/cppygen_parser.py @@ -1,6 +1,7 @@ import copy import os import re +import sys from typing import List from clang.cindex import AccessSpecifier, Config, Cursor, CursorKind, TranslationUnit @@ -83,6 +84,7 @@ def _extract_functions(self, cu: Cursor, namespace: List[str], module_name: str) j: Cursor if j.kind == CursorKind.PARM_DECL: # type: ignore func.add_argument_type((j.spelling, j.type.spelling)) + print("\t| Function | " + func.signature()) self._funcitons.append(func) def _extract_struct_and_class( @@ -121,6 +123,7 @@ def _extract_struct_and_class( j.brief_comment or "", j.access_specifier == AccessSpecifier.PRIVATE, # type: ignore ) + print("\t| Class | " + struct_or_class.signature()) self._structs_and_classes.append(struct_or_class) def add_hpp_includes(self, hpp: str): @@ -143,10 +146,6 @@ def parse( logger.error( f"{diag.location.file}:{diag.location.line}:{diag.location.column}: error: {diag.spelling} [{diag.option}]" ) - if diag.severity == diag.Warning: - logger.warn( - f"{diag.location.file}:{diag.location.line}:{diag.location.column}: warining: {diag.spelling} [{diag.option}]" - ) if has_error: exit(1) root: Cursor = tu.cursor @@ -161,13 +160,14 @@ def visit(x: Cursor, namespace: List[str], module_name: str): self._extract_struct_and_class(x, namespace, module_name) for i in list(x.get_children()): i: Cursor - namespace_in = copy.copy(namespace) + namespace_in = copy.deepcopy(namespace) if i.kind == CursorKind.NAMESPACE: # type: ignore submod = Submodule() submod.set_name(i.spelling) submod.set_description(i.brief_comment or "") - submod.set_parent(copy.copy(namespace_in)) + submod.set_parent(copy.deepcopy(namespace_in)) if not submod in self._submodules: + print(f"\t| Submodule | {submod.cpp_name}") self._submodules.append(submod) namespace_in.append(i.spelling) visit(i, namespace_in, submod.cpp_name) diff --git a/cppygen/logging.py b/cppygen/logging.py index 7d917f2..16b5bcc 100644 --- a/cppygen/logging.py +++ b/cppygen/logging.py @@ -13,6 +13,7 @@ def create_default_formatter() -> colorlog.ColoredFormatter: return colorlog.ColoredFormatter( "%(log_color)s%(message)s", no_color=False if _color_supported() else True, + stream=sys.stdout ) @@ -29,7 +30,7 @@ def _color_supported() -> bool: def get_logger(name: str) -> Logger: - handler = colorlog.StreamHandler() + handler = colorlog.StreamHandler(sys.stdout) handler.setFormatter(create_default_formatter()) logger = colorlog.getLogger(name) logger.addHandler(handler) diff --git a/example/.clang_format b/example/.clang_format new file mode 100644 index 0000000..67451b6 --- /dev/null +++ b/example/.clang_format @@ -0,0 +1 @@ +style: Google diff --git a/example/shell/piyo.cpp b/example/shell/piyo.cpp index dbeeca5..b74ef31 100644 --- a/example/shell/piyo.cpp +++ b/example/shell/piyo.cpp @@ -1,19 +1,13 @@ -#include "hoge.hpp" #include "piyo.hpp" +#include "hoge.hpp" #include -namespace Shell -{ -Piyoyo make_piyoyo() -{ - Piyoyo tmp; - tmp.setValue(-5); - return tmp; +namespace Shell::piyo { +Piyoyo make_piyoyo() { + Piyoyo tmp; + tmp.setValue(-5); + return tmp; } -std::vector fugafuga() -{ - return {3, 4, 5, 6}; -} - +std::vector fugafuga() { return {3, 4, 5, 6}; } -} // namespace Shell +} // namespace Shell::piyo diff --git a/example/src/main.cpp b/example/src/main.cpp index 548bf92..fabc546 100644 --- a/example/src/main.cpp +++ b/example/src/main.cpp @@ -7,6 +7,4 @@ void main_impl([[maybe_unused]] int argc, [[maybe_unused]] char *argv[]) {} -PYBIND11_MODULE(pyshell, m) { - CPPyGen::CPPyGenExport(m); -} +PYBIND11_MODULE(pyshell, m) { CPPyGen::CPPyGenExport(m); }