Skip to content

Commit 53b2884

Browse files
committed
refactor: dictionary keys case correction to lowercase
1 parent d484636 commit 53b2884

File tree

4 files changed

+132
-132
lines changed

4 files changed

+132
-132
lines changed

bindings/python/scripts/generate.py

Lines changed: 33 additions & 33 deletions
Original file line numberDiff line numberDiff line change
@@ -146,11 +146,11 @@ def get_fields_from_anonymous(item: dict) -> list:
146146
fields = []
147147
for sub_item in item["members"]:
148148
# base condition
149-
if sub_item["CursorKind"]["name"] == "FIELD_DECL":
149+
if sub_item["cursor_kind"]["name"] == "FIELD_DECL":
150150
fields.append(sub_item)
151151
# recurse
152152
# @TODO Fix this, `ANONYMOUS_kind` was removed, now test via `is_anonymous`
153-
elif sub_item["CursorKind"]["name"] in (
153+
elif sub_item["cursor_kind"]["name"] in (
154154
"ANONYMOUS_UNION_DECL",
155155
"ANONYMOUS_STRUCT_DECL",
156156
):
@@ -175,8 +175,8 @@ def handle_node(self, item: dict) -> None:
175175
"""
176176

177177
self.item = item
178-
self.kind = self.item["CursorKind"]["name"]
179-
self.name = self.item["Cursor"]["spelling"]
178+
self.kind = self.item["cursor_kind"]["name"]
179+
self.name = self.item["cursor"]["spelling"]
180180
self.members = self.item["members"]
181181
self.depth = self.item["depth"]
182182

@@ -220,21 +220,21 @@ def handle_struct_decl(self) -> None:
220220
template_class_name = None
221221
template_class_name_python = None
222222
for sub_item in self.members:
223-
if sub_item["CursorKind"]["name"] == "TYPE_REF":
223+
if sub_item["cursor_kind"]["name"] == "TYPE_REF":
224224
# TODO: Will this case only apply to templates?
225225
# @TODO: Make more robust
226226
type_ref = (
227-
sub_item["Cursor"]["spelling"]
227+
sub_item["cursor"]["spelling"]
228228
.replace("struct ", "")
229229
.replace("pcl::", "")
230230
)
231231
template_class_name = f"{self.name}<{type_ref}>"
232232
template_class_name_python = f"{self.name}_{type_ref}"
233233

234234
base_class_list = [
235-
sub_item["Cursor"]["spelling"]
235+
sub_item["cursor"]["spelling"]
236236
for sub_item in self.members
237-
if sub_item["CursorKind"]["name"] == "CXX_BASE_SPECIFIER"
237+
if sub_item["cursor_kind"]["name"] == "CXX_BASE_SPECIFIER"
238238
]
239239

240240
base_class_list_string = [
@@ -259,35 +259,35 @@ def handle_struct_decl(self) -> None:
259259
for sub_item in self.members:
260260
fields = self.get_fields_from_anonymous(sub_item)
261261
for field in fields:
262-
if field["Type"]["kind"] == "ConstantArray":
262+
if field["type"]["kind"] == "ConstantArray":
263263
# TODO: FIX: readwrite, not readonly
264264
self._linelist.append(
265-
f'.def_property_readonly("{field["Cursor"]["spelling"]}", []({self.name}& obj) {{return obj.{field["Cursor"]["spelling"]}; }})' # float[ ' + f'obj.{sub_item["Cursor"]["spelling"]}' + '.size()];} )'
265+
f'.def_property_readonly("{field["cursor"]["spelling"]}", []({self.name}& obj) {{return obj.{field["cursor"]["spelling"]}; }})' # float[ ' + f'obj.{sub_item["cursor"]["spelling"]}' + '.size()];} )'
266266
)
267267
else:
268268
self._linelist.append(
269-
f'.def_readwrite("{field["Cursor"]["spelling"]}", &{self.name}::{field["Cursor"]["spelling"]})'
269+
f'.def_readwrite("{field["cursor"]["spelling"]}", &{self.name}::{field["cursor"]["spelling"]})'
270270
)
271271

272272
for sub_item in self.members:
273273

274274
# handle field declarations
275-
if sub_item["CursorKind"]["name"] == "FIELD_DECL":
276-
if sub_item["Type"]["kind"] == "ConstantArray":
275+
if sub_item["cursor_kind"]["name"] == "FIELD_DECL":
276+
if sub_item["type"]["kind"] == "ConstantArray":
277277
self._linelist.append(
278-
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()];} )'
278+
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()];} )'
279279
)
280280
else:
281281
self._linelist.append(
282-
f'.def_readwrite("{sub_item["Cursor"]["spelling"]}", &{self.name}::{sub_item["Cursor"]["spelling"]})'
282+
f'.def_readwrite("{sub_item["cursor"]["spelling"]}", &{self.name}::{sub_item["cursor"]["spelling"]})'
283283
)
284284

285285
# handle class methods
286-
elif sub_item["CursorKind"]["name"] == "CXX_METHOD":
286+
elif sub_item["cursor_kind"]["name"] == "CXX_METHOD":
287287
# TODO: Add template args, currently blank
288-
if sub_item["Cursor"]["spelling"] not in ("PCL_DEPRECATED"):
288+
if sub_item["cursor"]["spelling"] not in ("PCL_DEPRECATED"):
289289
self._linelist.append(
290-
f'.def("{sub_item["Cursor"]["spelling"]}", py::overload_cast<>(&{self.name}::{sub_item["Cursor"]["spelling"]}))'
290+
f'.def("{sub_item["cursor"]["spelling"]}", py::overload_cast<>(&{self.name}::{sub_item["cursor"]["spelling"]}))'
291291
)
292292

293293
def handle_function(self) -> None:
@@ -299,8 +299,8 @@ def handle_function(self) -> None:
299299
parameter_type_list = []
300300
details = self._state_stack[-1]
301301
for sub_item in self.members:
302-
if sub_item["CursorKind"]["name"] == "PARM_DECL":
303-
parameter_type_list.append(f'"{sub_item["Cursor"]["spelling"]}"_a')
302+
if sub_item["cursor_kind"]["name"] == "PARM_DECL":
303+
parameter_type_list.append(f'"{sub_item["cursor"]["spelling"]}"_a')
304304

305305
parameter_type_list = ",".join(parameter_type_list)
306306
if parameter_type_list:
@@ -323,7 +323,7 @@ def handle_constructor(self) -> None:
323323

324324
# generate parameter type list
325325
for sub_item in self.members:
326-
if sub_item["CursorKind"]["name"] == "PARM_DECL":
326+
if sub_item["cursor_kind"]["name"] == "PARM_DECL":
327327
parameter_type_list.append(self.get_parm_types(sub_item))
328328
parameter_type_list = ",".join(parameter_type_list)
329329

@@ -332,29 +332,29 @@ def handle_constructor(self) -> None:
332332
self._linelist.append(f".def(py::init<{parameter_type_list}>())")
333333

334334
def get_parm_types(self, item: Dict[str, Any]) -> List[str]:
335-
if item["Type"]["kind"] == "LValueReference":
335+
if item["type"]["kind"] == "LValueReference":
336336
for sub_item in item["members"]:
337-
if sub_item["CursorKind"]["name"] == "TYPE_REF":
337+
if sub_item["cursor_kind"]["name"] == "TYPE_REF":
338338
# @TODO: Make more robust
339339
type_ref = (
340-
sub_item["Cursor"]["spelling"]
340+
sub_item["cursor"]["spelling"]
341341
.replace("struct ", "")
342342
.replace("pcl::", "")
343343
)
344344
parameter_type_list = f"{type_ref} &"
345-
elif item["Type"]["kind"] == "Elaborated":
345+
elif item["type"]["kind"] == "Elaborated":
346346
namespace_ref = ""
347347
for sub_item in item["members"]:
348-
if sub_item["CursorKind"]["name"] == "NAMESPACE_REF":
349-
namespace_ref += f'{sub_item["Cursor"]["spelling"]}::'
350-
if sub_item["CursorKind"]["name"] == "TYPE_REF":
348+
if sub_item["cursor_kind"]["name"] == "NAMESPACE_REF":
349+
namespace_ref += f'{sub_item["cursor"]["spelling"]}::'
350+
if sub_item["cursor_kind"]["name"] == "TYPE_REF":
351351
parameter_type_list = (
352-
f'{namespace_ref}{sub_item["Cursor"]["spelling"]}'
352+
f'{namespace_ref}{sub_item["cursor"]["spelling"]}'
353353
)
354-
elif item["Type"]["kind"] in ("Float", "Double", "Int"):
355-
parameter_type_list = f'{item["Type"]["kind"].lower()}'
354+
elif item["type"]["kind"] in ("Float", "Double", "Int"):
355+
parameter_type_list = f'{item["type"]["kind"].lower()}'
356356
else:
357-
parameter_type_list = f'{item["Type"]["kind"]}'
357+
parameter_type_list = f'{item["type"]["kind"]}'
358358
return parameter_type_list
359359

360360
def handle_inclusion_directive(self) -> None:
@@ -427,7 +427,7 @@ def combine_lines() -> list or Exception:
427427
if parsed_info:
428428
bind_object = bind(root=parsed_info, module_name=module_name)
429429
# Extract filename from parsed_info (TRANSLATION_UNIT's name contains the filepath)
430-
filename = "pcl" + parsed_info["Cursor"]["spelling"].rsplit("pcl")[-1]
430+
filename = "pcl" + parsed_info["cursor"]["spelling"].rsplit("pcl")[-1]
431431
return combine_lines()
432432
else:
433433
raise Exception("Empty dict: parsed_info")

bindings/python/scripts/parse.py

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -102,9 +102,9 @@ def generate_parsed_info(node):
102102

103103
# add result of various kinds of checks available in cindex.py via clang_utils.py
104104
for key, object in (
105-
("CursorKind", CursorKindUtils(cursor_kind=cursor.kind)),
106-
("Cursor", CursorUtils(cursor=cursor)),
107-
("Type", TypeUtils(cursor_type=cursor.type)),
105+
("cursor_kind", CursorKindUtils(cursor_kind=cursor.kind)),
106+
("cursor", CursorUtils(cursor=cursor)),
107+
("type", TypeUtils(cursor_type=cursor.type)),
108108
):
109109
parsed_info[key] = {
110110
**object.check_functions_dict,
@@ -115,15 +115,15 @@ def generate_parsed_info(node):
115115
# Hacky fixes
116116

117117
# get spelling from object
118-
parsed_info["Cursor"]["result_type"] = parsed_info["Cursor"]["result_type"].spelling
118+
parsed_info["cursor"]["result_type"] = parsed_info["cursor"]["result_type"].spelling
119119

120120
# replace `AccessSpecifier.value` with just `value`
121-
parsed_info["Cursor"]["access_specifier"] = parsed_info["Cursor"][
121+
parsed_info["cursor"]["access_specifier"] = parsed_info["cursor"][
122122
"access_specifier"
123123
].name
124124

125125
# replace `TypeKind.value` with just `value`
126-
parsed_info["Type"]["kind"] = parsed_info["Type"]["kind"].name
126+
parsed_info["type"]["kind"] = parsed_info["type"]["kind"].name
127127

128128
# Get cursor's children and recursively add their info to a dictionary, as members of the parent
129129
for child_node in valid_children(node):

bindings/python/tests/test_generate.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,7 @@ def generate_bindings(cpp_code_block, module_name, tmp_path):
4949
tmp_path=tmp_path, file_contents=cpp_code_block
5050
)
5151

52-
file_include = "pcl" + parsed_info["Cursor"]["spelling"].rsplit("pcl")[-1]
52+
file_include = "pcl" + parsed_info["cursor"]["spelling"].rsplit("pcl")[-1]
5353

5454
# Get the binded code
5555
binded_code = generate.generate(module_name=module_name, parsed_info=parsed_info)

0 commit comments

Comments
 (0)