11from typing import List , Dict
2+ import logging
23
34from clang import cindex
45
56from . import entity_base
67from pybind11_weaver .utils import fn
78
8- import logging
9-
109from pybind11_weaver import gen_unit
1110
1211_logger = logging .getLogger (__name__ )
@@ -74,16 +73,23 @@ def update_stmts(self, pybind11_obj_sym: str) -> List[str]:
7473 codes = []
7574
7675 def is_pubic (cursor ):
77- return cursor .access_specifier == cindex .AccessSpecifier .PUBLIC and self .gu .is_visible (cursor )
76+ return cursor .access_specifier == cindex .AccessSpecifier .PUBLIC and not cursor .is_deleted_method ()
77+
78+ def not_operator (cursor ):
79+ is_operator = "operator" in cursor .spelling
80+ if is_operator :
81+ _logger .warning (f"Operator overloading not supported `{ cursor .spelling } `" )
82+ return not is_operator
7883
7984 # generate constructor binding
8085 ctor_found = False
8186 for cursor in self .cursor .get_children ():
82- if cursor .kind == cindex .CursorKind .CONSTRUCTOR and is_pubic ( cursor ) :
87+ if cursor .kind == cindex .CursorKind .CONSTRUCTOR :
8388 ctor_found = True
84- param_types = fn .fn_arg_type (cursor )
85- codes .append (
86- f"{ pybind11_obj_sym } .def(pybind11::init<{ ',' .join (param_types )} >());" )
89+ if is_pubic (cursor ) and not (cursor .is_move_constructor () or cursor .is_copy_constructor ()):
90+ param_types = fn .fn_arg_type (cursor )
91+ codes .append (
92+ f"{ pybind11_obj_sym } .def(pybind11::init<{ ',' .join (param_types )} >());" )
8793 if not ctor_found :
8894 codes .append (f"{ pybind11_obj_sym } .def(pybind11::init<>());" )
8995 if self .gu .io_config .gen_docstring :
@@ -93,7 +99,7 @@ def is_pubic(cursor):
9399 # generate method binding
94100 methods : Dict [str , MethodCoder ] = dict ()
95101 for cursor in self .cursor .get_children ():
96- if cursor .kind == cindex .CursorKind .CXX_METHOD and is_pubic (cursor ):
102+ if cursor .kind == cindex .CursorKind .CXX_METHOD and is_pubic (cursor ) and not_operator ( cursor ) :
97103 if not cursor .spelling in methods :
98104 methods [cursor .spelling ] = MethodCoder (cursor , self .qualified_name (),
99105 self .gu .io_config .gen_docstring )
@@ -118,9 +124,14 @@ def is_pubic(cursor):
118124
119125 # generate field binding
120126 for cursor in self .cursor .get_children ():
121- if cursor .kind == cindex .CursorKind .FIELD_DECL and is_pubic (cursor ):
127+ if cursor .kind == cindex .CursorKind .FIELD_DECL and \
128+ is_pubic (cursor ) and \
129+ cursor .type .kind != cindex .TypeKind .CONSTANTARRAY :
130+ filed_binder = "def_readwrite"
131+ if cursor .type .is_const_qualified ():
132+ filed_binder = "def_readonly"
122133 codes .append (
123- f"{ pybind11_obj_sym } .def_readwrite (\" { cursor .spelling } \" ,&{ self .qualified_name ()} ::{ cursor .spelling } );" )
134+ f"{ pybind11_obj_sym } .{ filed_binder } (\" { cursor .spelling } \" ,&{ self .qualified_name ()} ::{ cursor .spelling } );" )
124135 if self .gu .io_config .gen_docstring :
125136 codes [- 1 ] = entity_base ._inject_docstring (codes [- 1 ], cursor , "last_arg" )
126137
0 commit comments