@@ -148,10 +148,14 @@ def get_fields_from_anonymous(item: dict) -> list:
148148 fields = []
149149 for sub_item in item ["members" ]:
150150 # base condition
151- if sub_item ["kind " ] == "FIELD_DECL" :
151+ if sub_item ["cursor_kind" ][ "name " ] == "FIELD_DECL" :
152152 fields .append (sub_item )
153153 # recurse
154- elif sub_item ["kind" ] in ("ANONYMOUS_UNION_DECL" , "ANONYMOUS_STRUCT_DECL" ):
154+ # @TODO Fix this, `ANONYMOUS_kind` was removed, now test via `is_anonymous`
155+ elif sub_item ["cursor_kind" ]["name" ] in (
156+ "ANONYMOUS_UNION_DECL" ,
157+ "ANONYMOUS_STRUCT_DECL" ,
158+ ):
155159 fields += bind .get_fields_from_anonymous (item = sub_item )
156160 return fields
157161
@@ -173,8 +177,8 @@ def handle_node(self, item: dict) -> None:
173177 """
174178
175179 self .item = item
176- self .kind = self .item ["kind " ]
177- self .name = self .item ["name " ]
180+ self .kind = self .item ["cursor_kind" ][ "name " ]
181+ self .name = self .item ["cursor" ][ "spelling " ]
178182 self .members = self .item ["members" ]
179183 self .depth = self .item ["depth" ]
180184
@@ -218,17 +222,21 @@ def handle_struct_decl(self) -> None:
218222 template_class_name = None
219223 template_class_name_python = None
220224 for sub_item in self .members :
221- if sub_item ["kind " ] == "TYPE_REF" :
225+ if sub_item ["cursor_kind" ][ "name " ] == "TYPE_REF" :
222226 # TODO: Will this case only apply to templates?
223227 # @TODO: Make more robust
224- type_ref = sub_item ["name" ].replace ("struct " , "" ).replace ("pcl::" , "" )
228+ type_ref = (
229+ sub_item ["cursor" ]["spelling" ]
230+ .replace ("struct " , "" )
231+ .replace ("pcl::" , "" )
232+ )
225233 template_class_name = f"{ self .name } <{ type_ref } >"
226234 template_class_name_python = f"{ self .name } _{ type_ref } "
227235
228236 base_class_list = [
229- sub_item ["name " ]
237+ sub_item ["cursor" ][ "spelling " ]
230238 for sub_item in self .members
231- if sub_item ["kind " ] == "CXX_BASE_SPECIFIER"
239+ if sub_item ["cursor_kind" ][ "name " ] == "CXX_BASE_SPECIFIER"
232240 ]
233241
234242 base_class_list_string = [
@@ -253,35 +261,35 @@ def handle_struct_decl(self) -> None:
253261 for sub_item in self .members :
254262 fields = self .get_fields_from_anonymous (sub_item )
255263 for field in fields :
256- if field ["element_type " ] == "ConstantArray" :
264+ if field ["type" ][ "kind " ] == "ConstantArray" :
257265 # TODO: FIX: readwrite, not readonly
258266 self ._linelist .append (
259- f'.def_property_readonly("{ field ["name" ] } ", []({ self .name } & obj) {{return obj.{ field ["name" ] } ; }})' # float[ ' + f'obj.{sub_item["name "]}' + '.size()];} )'
267+ f'.def_property_readonly("{ field ["cursor" ][ "spelling" ] } ", []({ self .name } & obj) {{return obj.{ field ["cursor" ][ "spelling" ] } ; }})' # float[ ' + f'obj.{sub_item["cursor"]["spelling "]}' + '.size()];} )'
260268 )
261269 else :
262270 self ._linelist .append (
263- f'.def_readwrite("{ field ["name" ] } ", &{ self .name } ::{ field ["name " ]} )'
271+ f'.def_readwrite("{ field ["cursor" ][ "spelling" ] } ", &{ self .name } ::{ field ["cursor" ][ "spelling " ]} )'
264272 )
265273
266274 for sub_item in self .members :
267275
268276 # handle field declarations
269- if sub_item ["kind " ] == "FIELD_DECL" :
270- if sub_item ["element_type " ] == "ConstantArray" :
277+ if sub_item ["cursor_kind" ][ "name " ] == "FIELD_DECL" :
278+ if sub_item ["type" ][ "kind " ] == "ConstantArray" :
271279 self ._linelist .append (
272- f'.def_property_readonly("{ sub_item ["name" ] } ", []({ self .name } & obj) {{return obj.{ sub_item ["name" ] } ; }})' # float[ ' + f'obj.{sub_item["name "]}' + '.size()];} )'
280+ f'.def_property_readonly("{ sub_item ["cursor" ][ "spelling" ] } ", []({ self .name } & obj) {{return obj.{ sub_item ["cursor" ][ "spelling" ] } ; }})' # float[ ' + f'obj.{sub_item["cursor"]["spelling "]}' + '.size()];} )'
273281 )
274282 else :
275283 self ._linelist .append (
276- f'.def_readwrite("{ sub_item ["name" ] } ", &{ self .name } ::{ sub_item ["name " ]} )'
284+ f'.def_readwrite("{ sub_item ["cursor" ][ "spelling" ] } ", &{ self .name } ::{ sub_item ["cursor" ][ "spelling " ]} )'
277285 )
278286
279287 # handle class methods
280- elif sub_item ["kind " ] == "CXX_METHOD" :
288+ elif sub_item ["cursor_kind" ][ "name " ] == "CXX_METHOD" :
281289 # TODO: Add template args, currently blank
282- if sub_item ["name " ] not in ("PCL_DEPRECATED" ):
290+ if sub_item ["cursor" ][ "spelling " ] not in ("PCL_DEPRECATED" ):
283291 self ._linelist .append (
284- f'.def("{ sub_item ["name" ] } ", py::overload_cast<>(&{ self .name } ::{ sub_item ["name " ]} ))'
292+ f'.def("{ sub_item ["cursor" ][ "spelling" ] } ", py::overload_cast<>(&{ self .name } ::{ sub_item ["cursor" ][ "spelling " ]} ))'
285293 )
286294
287295 def handle_function (self ) -> None :
@@ -293,8 +301,8 @@ def handle_function(self) -> None:
293301 parameter_type_list = []
294302 details = self ._state_stack [- 1 ]
295303 for sub_item in self .members :
296- if sub_item ["kind " ] == "PARM_DECL" :
297- parameter_type_list .append (f'"{ sub_item ["name " ]} "_a' )
304+ if sub_item ["cursor_kind" ][ "name " ] == "PARM_DECL" :
305+ parameter_type_list .append (f'"{ sub_item ["cursor" ][ "spelling " ]} "_a' )
298306
299307 parameter_type_list = "," .join (parameter_type_list )
300308 if parameter_type_list :
@@ -317,7 +325,7 @@ def handle_constructor(self) -> None:
317325
318326 # generate parameter type list
319327 for sub_item in self .members :
320- if sub_item ["kind " ] == "PARM_DECL" :
328+ if sub_item ["cursor_kind" ][ "name " ] == "PARM_DECL" :
321329 parameter_type_list .append (self .get_parm_types (sub_item ))
322330 parameter_type_list = "," .join (parameter_type_list )
323331
@@ -326,25 +334,29 @@ def handle_constructor(self) -> None:
326334 self ._linelist .append (f".def(py::init<{ parameter_type_list } >())" )
327335
328336 def get_parm_types (self , item : Dict [str , Any ]) -> List [str ]:
329- if item ["element_type " ] == "LValueReference" :
337+ if item ["type" ][ "kind " ] == "LValueReference" :
330338 for sub_item in item ["members" ]:
331- if sub_item ["kind " ] == "TYPE_REF" :
339+ if sub_item ["cursor_kind" ][ "name " ] == "TYPE_REF" :
332340 # @TODO: Make more robust
333341 type_ref = (
334- sub_item ["name" ].replace ("struct " , "" ).replace ("pcl::" , "" )
342+ sub_item ["cursor" ]["spelling" ]
343+ .replace ("struct " , "" )
344+ .replace ("pcl::" , "" )
335345 )
336346 parameter_type_list = f"{ type_ref } &"
337- elif item ["element_type " ] == "Elaborated" :
347+ elif item ["type" ][ "kind " ] == "Elaborated" :
338348 namespace_ref = ""
339349 for sub_item in item ["members" ]:
340- if sub_item ["kind" ] == "NAMESPACE_REF" :
341- namespace_ref += f'{ sub_item ["name" ]} ::'
342- if sub_item ["kind" ] == "TYPE_REF" :
343- parameter_type_list = f'{ namespace_ref } { sub_item ["name" ]} '
344- elif item ["element_type" ] in ("Float" , "Double" , "Int" ):
345- parameter_type_list = f'{ item ["element_type" ].lower ()} '
350+ if sub_item ["cursor_kind" ]["name" ] == "NAMESPACE_REF" :
351+ namespace_ref += f'{ sub_item ["cursor" ]["spelling" ]} ::'
352+ if sub_item ["cursor_kind" ]["name" ] == "TYPE_REF" :
353+ parameter_type_list = (
354+ f'{ namespace_ref } { sub_item ["cursor" ]["spelling" ]} '
355+ )
356+ elif item ["type" ]["kind" ] in ("Float" , "Double" , "Int" ):
357+ parameter_type_list = f'{ item ["type" ]["kind" ].lower ()} '
346358 else :
347- parameter_type_list = f'{ item ["element_type " ]} '
359+ parameter_type_list = f'{ item ["type" ][ "kind " ]} '
348360 return parameter_type_list
349361
350362 def handle_inclusion_directive (self ) -> None :
@@ -417,7 +429,7 @@ def combine_lines() -> list or Exception:
417429 if parsed_info :
418430 bind_object = bind (root = parsed_info , module_name = module_name )
419431 # Extract filename from parsed_info (TRANSLATION_UNIT's name contains the filepath)
420- filename = "pcl" + parsed_info ["name " ].rsplit ("pcl" )[- 1 ]
432+ filename = "pcl" + parsed_info ["cursor" ][ "spelling " ].rsplit ("pcl" )[- 1 ]
421433 return combine_lines ()
422434 else :
423435 raise Exception ("Empty dict: parsed_info" )
0 commit comments