Skip to content

Commit 87f5c1e

Browse files
committed
Update
1 parent 43f012f commit 87f5c1e

File tree

6 files changed

+28
-26
lines changed

6 files changed

+28
-26
lines changed

cppygen/component.py

+10-2
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,4 @@
1-
from typing import Dict, List, Tuple
1+
from typing import Dict, List, Tuple, cast
22

33

44
class Function(object):
@@ -77,6 +77,10 @@ def to_decl_string(self):
7777
f'{{ {self._return_type} {self._name}({", ".join(args)}); }}'
7878
)
7979

80+
def signature(self) -> str:
81+
args = [f"{i[1]} {i[0]}" for i in self._arguments]
82+
return f'{"::".join(self._namespace)}::{self._name}({", ".join(args)}) -> {self._return_type}'
83+
8084
def __eq__(self, obj):
8185
if isinstance(obj, Function):
8286
return self._full_name == obj._full_name
@@ -175,6 +179,9 @@ def to_pybind_string(self):
175179
+ ";"
176180
)
177181

182+
def signature(self) -> str:
183+
return f"{self._full_name}"
184+
178185

179186
class Submodule:
180187
"""
@@ -218,6 +225,7 @@ def to_pybind_string(self):
218225

219226
def __eq__(self, obj):
220227
if isinstance(obj, Submodule):
221-
return self._name == obj._name
228+
return self.cpp_name == obj.cpp_name
222229
else:
223230
return False
231+

cppygen/cppygen_parser.py

+6-6
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
import copy
22
import os
33
import re
4+
import sys
45
from typing import List
56

67
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)
8384
j: Cursor
8485
if j.kind == CursorKind.PARM_DECL: # type: ignore
8586
func.add_argument_type((j.spelling, j.type.spelling))
87+
print("\t| Function | " + func.signature())
8688
self._funcitons.append(func)
8789

8890
def _extract_struct_and_class(
@@ -121,6 +123,7 @@ def _extract_struct_and_class(
121123
j.brief_comment or "",
122124
j.access_specifier == AccessSpecifier.PRIVATE, # type: ignore
123125
)
126+
print("\t| Class | " + struct_or_class.signature())
124127
self._structs_and_classes.append(struct_or_class)
125128

126129
def add_hpp_includes(self, hpp: str):
@@ -143,10 +146,6 @@ def parse(
143146
logger.error(
144147
f"{diag.location.file}:{diag.location.line}:{diag.location.column}: error: {diag.spelling} [{diag.option}]"
145148
)
146-
if diag.severity == diag.Warning:
147-
logger.warn(
148-
f"{diag.location.file}:{diag.location.line}:{diag.location.column}: warining: {diag.spelling} [{diag.option}]"
149-
)
150149
if has_error:
151150
exit(1)
152151
root: Cursor = tu.cursor
@@ -161,13 +160,14 @@ def visit(x: Cursor, namespace: List[str], module_name: str):
161160
self._extract_struct_and_class(x, namespace, module_name)
162161
for i in list(x.get_children()):
163162
i: Cursor
164-
namespace_in = copy.copy(namespace)
163+
namespace_in = copy.deepcopy(namespace)
165164
if i.kind == CursorKind.NAMESPACE: # type: ignore
166165
submod = Submodule()
167166
submod.set_name(i.spelling)
168167
submod.set_description(i.brief_comment or "")
169-
submod.set_parent(copy.copy(namespace_in))
168+
submod.set_parent(copy.deepcopy(namespace_in))
170169
if not submod in self._submodules:
170+
print(f"\t| Submodule | {submod.cpp_name}")
171171
self._submodules.append(submod)
172172
namespace_in.append(i.spelling)
173173
visit(i, namespace_in, submod.cpp_name)

cppygen/logging.py

+2-1
Original file line numberDiff line numberDiff line change
@@ -13,6 +13,7 @@ def create_default_formatter() -> colorlog.ColoredFormatter:
1313
return colorlog.ColoredFormatter(
1414
"%(log_color)s%(message)s",
1515
no_color=False if _color_supported() else True,
16+
stream=sys.stdout
1617
)
1718

1819

@@ -29,7 +30,7 @@ def _color_supported() -> bool:
2930

3031

3132
def get_logger(name: str) -> Logger:
32-
handler = colorlog.StreamHandler()
33+
handler = colorlog.StreamHandler(sys.stdout)
3334
handler.setFormatter(create_default_formatter())
3435
logger = colorlog.getLogger(name)
3536
logger.addHandler(handler)

example/.clang_format

+1
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
style: Google

example/shell/piyo.cpp

+8-14
Original file line numberDiff line numberDiff line change
@@ -1,19 +1,13 @@
1-
#include "hoge.hpp"
21
#include "piyo.hpp"
2+
#include "hoge.hpp"
33
#include <vector>
44

5-
namespace Shell
6-
{
7-
Piyoyo make_piyoyo()
8-
{
9-
Piyoyo tmp;
10-
tmp.setValue(-5);
11-
return tmp;
5+
namespace Shell::piyo {
6+
Piyoyo make_piyoyo() {
7+
Piyoyo tmp;
8+
tmp.setValue(-5);
9+
return tmp;
1210
}
13-
std::vector<double> fugafuga()
14-
{
15-
return {3, 4, 5, 6};
16-
}
17-
11+
std::vector<double> fugafuga() { return {3, 4, 5, 6}; }
1812

19-
} // namespace Shell
13+
} // namespace Shell::piyo

example/src/main.cpp

+1-3
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,4 @@
77

88
void main_impl([[maybe_unused]] int argc, [[maybe_unused]] char *argv[]) {}
99

10-
PYBIND11_MODULE(pyshell, m) {
11-
CPPyGen::CPPyGenExport(m);
12-
}
10+
PYBIND11_MODULE(pyshell, m) { CPPyGen::CPPyGenExport(m); }

0 commit comments

Comments
 (0)