Skip to content

Commit ea2156d

Browse files
Enforce p_ prefixes for arguments in binds
1 parent ee9acbc commit ea2156d

File tree

1 file changed

+41
-35
lines changed

1 file changed

+41
-35
lines changed

binding_generator.py

Lines changed: 41 additions & 35 deletions
Original file line numberDiff line numberDiff line change
@@ -661,17 +661,17 @@ def generate_builtin_class_header(builtin_api, size, used_classes, fully_used_cl
661661
result.append(method_signature)
662662

663663
# Move constructor.
664-
result.append(f"\t{class_name}({class_name} &&other);")
664+
result.append(f"\t{class_name}({class_name} &&p_other);")
665665

666666
# Special cases.
667667
if class_name == "String" or class_name == "StringName" or class_name == "NodePath":
668668
if class_name == "StringName":
669-
result.append(f"\t{class_name}(const char *from, bool p_static = false);")
669+
result.append(f"\t{class_name}(const char *p_from, bool p_static = false);")
670670
else:
671-
result.append(f"\t{class_name}(const char *from);")
672-
result.append(f"\t{class_name}(const wchar_t *from);")
673-
result.append(f"\t{class_name}(const char16_t *from);")
674-
result.append(f"\t{class_name}(const char32_t *from);")
671+
result.append(f"\t{class_name}(const char *p_from);")
672+
result.append(f"\t{class_name}(const wchar_t *p_from);")
673+
result.append(f"\t{class_name}(const char16_t *p_from);")
674+
result.append(f"\t{class_name}(const char32_t *p_from);")
675675
if class_name == "Callable":
676676
result.append("\tCallable(CallableCustom *p_custom);")
677677
result.append("\tCallableCustom *get_custom() const;")
@@ -732,10 +732,10 @@ def generate_builtin_class_header(builtin_api, size, used_classes, fully_used_cl
732732

733733
# Special cases.
734734
if class_name == "String":
735-
result.append("\tstatic String utf8(const char *from, int64_t len = -1);")
736-
result.append("\tError parse_utf8(const char *from, int64_t len = -1);")
737-
result.append("\tstatic String utf16(const char16_t *from, int64_t len = -1);")
738-
result.append("\tError parse_utf16(const char16_t *from, int64_t len = -1, bool default_little_endian = true);")
735+
result.append("\tstatic String utf8(const char *p_from, int64_t p_len = -1);")
736+
result.append("\tError parse_utf8(const char *p_from, int64_t p_len = -1);")
737+
result.append("\tstatic String utf16(const char16_t *p_from, int64_t p_len = -1);")
738+
result.append("\tError parse_utf16(const char16_t *p_from, int64_t p_len = -1, bool p_default_little_endian = true);")
739739
result.append("\tCharString utf8() const;")
740740
result.append("\tCharString ascii() const;")
741741
result.append("\tChar16String utf16() const;")
@@ -756,7 +756,7 @@ def generate_builtin_class_header(builtin_api, size, used_classes, fully_used_cl
756756
if operator["name"] not in ["in", "xor"]:
757757
if "right_type" in operator:
758758
result.append(
759-
f'\t{correct_type(operator["return_type"])} operator{operator["name"]}({type_for_parameter(operator["right_type"])}other) const;'
759+
f'\t{correct_type(operator["return_type"])} operator{operator["name"]}({type_for_parameter(operator["right_type"])}p_other) const;'
760760
)
761761
else:
762762
result.append(
@@ -765,10 +765,10 @@ def generate_builtin_class_header(builtin_api, size, used_classes, fully_used_cl
765765

766766
# Copy assignment.
767767
if copy_constructor_index >= 0:
768-
result.append(f"\t{class_name} &operator=(const {class_name} &other);")
768+
result.append(f"\t{class_name} &operator=(const {class_name} &p_other);")
769769

770770
# Move assignment.
771-
result.append(f"\t{class_name} &operator=({class_name} &&other);")
771+
result.append(f"\t{class_name} &operator=({class_name} &&p_other);")
772772

773773
# Special cases.
774774
if class_name == "String":
@@ -802,8 +802,8 @@ def generate_builtin_class_header(builtin_api, size, used_classes, fully_used_cl
802802

803803
if class_name == "Array":
804804
result.append("\ttemplate <typename... Args>")
805-
result.append("\tstatic Array make(Args... args) {")
806-
result.append("\t\treturn helpers::append_all(Array(), args...);")
805+
result.append("\tstatic Array make(Args... p_args) {")
806+
result.append("\t\treturn helpers::append_all(Array(), p_args...);")
807807
result.append("\t}")
808808

809809
if is_packed_array(class_name):
@@ -1098,13 +1098,13 @@ def generate_builtin_class_source(builtin_api, size, used_classes, fully_used_cl
10981098
result.append("")
10991099

11001100
# Move constructor.
1101-
result.append(f"{class_name}::{class_name}({class_name} &&other) {{")
1101+
result.append(f"{class_name}::{class_name}({class_name} &&p_other) {{")
11021102
if needs_copy_instead_of_move(class_name) and copy_constructor_index >= 0:
11031103
result.append(
1104-
f"\tinternal::_call_builtin_constructor(_method_bindings.constructor_{copy_constructor_index}, &opaque, &other);"
1104+
f"\tinternal::_call_builtin_constructor(_method_bindings.constructor_{copy_constructor_index}, &opaque, &p_other);"
11051105
)
11061106
else:
1107-
result.append("\tstd::swap(opaque, other.opaque);")
1107+
result.append("\tstd::swap(opaque, p_other.opaque);")
11081108
result.append("}")
11091109
result.append("")
11101110

@@ -1195,7 +1195,7 @@ def generate_builtin_class_source(builtin_api, size, used_classes, fully_used_cl
11951195
if operator["name"] not in ["in", "xor"]:
11961196
if "right_type" in operator:
11971197
result.append(
1198-
f'{correct_type(operator["return_type"])} {class_name}::operator{operator["name"]}({type_for_parameter(operator["right_type"])}other) const {{'
1198+
f'{correct_type(operator["return_type"])} {class_name}::operator{operator["name"]}({type_for_parameter(operator["right_type"])}p_other) const {{'
11991199
)
12001200
(encode, arg_name) = get_encoded_arg("other", operator["right_type"], None)
12011201
result += encode
@@ -1215,7 +1215,7 @@ def generate_builtin_class_source(builtin_api, size, used_classes, fully_used_cl
12151215

12161216
# Copy assignment.
12171217
if copy_constructor_index >= 0:
1218-
result.append(f"{class_name} &{class_name}::operator=(const {class_name} &other) {{")
1218+
result.append(f"{class_name} &{class_name}::operator=(const {class_name} &p_other) {{")
12191219
if builtin_api["has_destructor"]:
12201220
result.append("\t_method_bindings.destructor(&opaque);")
12211221
(encode, arg_name) = get_encoded_arg(
@@ -1232,13 +1232,13 @@ def generate_builtin_class_source(builtin_api, size, used_classes, fully_used_cl
12321232
result.append("")
12331233

12341234
# Move assignment.
1235-
result.append(f"{class_name} &{class_name}::operator=({class_name} &&other) {{")
1235+
result.append(f"{class_name} &{class_name}::operator=({class_name} &&p_other) {{")
12361236
if needs_copy_instead_of_move(class_name) and copy_constructor_index >= 0:
12371237
result.append(
1238-
f"\tinternal::_call_builtin_constructor(_method_bindings.constructor_{copy_constructor_index}, &opaque, &other);"
1238+
f"\tinternal::_call_builtin_constructor(_method_bindings.constructor_{copy_constructor_index}, &opaque, &p_other);"
12391239
)
12401240
else:
1241-
result.append("\tstd::swap(opaque, other.opaque);")
1241+
result.append("\tstd::swap(opaque, p_other.opaque);")
12421242
result.append("\treturn *this;")
12431243
result.append("}")
12441244

@@ -1714,9 +1714,9 @@ def generate_engine_class_header(class_api, used_classes, fully_used_classes, us
17141714
if "alias_for" in class_api and return_type.startswith(class_api["alias_for"] + "::"):
17151715
method_body += f"({return_type})"
17161716
method_body += f'ClassDBSingleton::get_singleton()->{method["name"]}('
1717-
method_body += ", ".join(map(lambda x: escape_identifier(x["name"]), method_arguments))
1717+
method_body += ", ".join(map(lambda x: escape_argument(x["name"]), method_arguments))
17181718
if vararg:
1719-
method_body += ", args..."
1719+
method_body += ", p_args..."
17201720
method_body += "); \\"
17211721

17221722
result.append(method_body)
@@ -1878,7 +1878,7 @@ def generate_engine_class_source(class_api, used_classes, fully_used_classes, us
18781878
else: # vararg.
18791879
result.append("\tGDExtensionCallError error;")
18801880
result.append("\tVariant ret;")
1881-
method_call += "internal::gdextension_interface_object_method_bind_call(_gde_method_bind, _owner, reinterpret_cast<GDExtensionConstVariantPtr *>(args), arg_count, &ret, &error"
1881+
method_call += "internal::gdextension_interface_object_method_bind_call(_gde_method_bind, _owner, reinterpret_cast<GDExtensionConstVariantPtr *>(p_args), p_arg_count, &ret, &error"
18821882

18831883
if is_ref:
18841884
method_call += ")" # Close Ref<> constructor.
@@ -2147,7 +2147,7 @@ def generate_utility_functions(api, output_dir):
21472147
source.append(f'\t{get_gdextension_type(correct_type(function["return_type"]))} ret;')
21482148
else:
21492149
source.append("\tVariant ret;")
2150-
function_call += "_gde_function(&ret, reinterpret_cast<GDExtensionConstVariantPtr *>(args), arg_count"
2150+
function_call += "_gde_function(&ret, reinterpret_cast<GDExtensionConstVariantPtr *>(p_args), p_arg_count"
21512151

21522152
function_call += ");"
21532153
source.append(function_call)
@@ -2178,9 +2178,9 @@ def make_function_parameters(parameters, include_default=False, for_builtin=Fals
21782178

21792179
for index, par in enumerate(parameters):
21802180
parameter = type_for_parameter(par["type"], par["meta"] if "meta" in par else None)
2181-
parameter_name = escape_identifier(par["name"])
2181+
parameter_name = escape_argument(par["name"])
21822182
if len(parameter_name) == 0:
2183-
parameter_name = "arg_" + str(index + 1)
2183+
parameter_name = "p_arg_" + str(index + 1)
21842184
parameter += parameter_name
21852185

21862186
if include_default and "default_value" in par and (not for_builtin or par["type"] != "Variant"):
@@ -2194,7 +2194,7 @@ def make_function_parameters(parameters, include_default=False, for_builtin=Fals
21942194
signature.append(parameter)
21952195

21962196
if is_vararg:
2197-
signature.append("const Args&... args")
2197+
signature.append("const Args&... p_args")
21982198

21992199
return ", ".join(signature)
22002200

@@ -2225,7 +2225,7 @@ def get_include_path(type_name):
22252225
def get_encoded_arg(arg_name, type_name, type_meta):
22262226
result = []
22272227

2228-
name = escape_identifier(arg_name)
2228+
name = escape_argument(arg_name)
22292229
arg_type = correct_type(type_name)
22302230
if is_pod_type(arg_type):
22312231
result.append(f"\t{get_gdextension_type(arg_type)} {name}_encoded;")
@@ -2291,7 +2291,7 @@ def make_signature(
22912291
if not is_vararg:
22922292
function_signature += make_function_parameters(arguments, for_header, for_builtin, is_vararg)
22932293
else:
2294-
function_signature += "const Variant **args, GDExtensionInt arg_count"
2294+
function_signature += "const Variant **p_args, GDExtensionInt p_arg_count"
22952295

22962296
function_signature += ")"
22972297

@@ -2364,12 +2364,12 @@ def make_varargs_template(
23642364
args_array = f"\tstd::array<Variant, {len(method_arguments)} + sizeof...(Args)> variant_args {{ "
23652365
for argument in method_arguments:
23662366
if argument["type"] == "Variant":
2367-
args_array += escape_identifier(argument["name"])
2367+
args_array += escape_argument(argument["name"])
23682368
else:
2369-
args_array += f'Variant({escape_identifier(argument["name"])})'
2369+
args_array += f'Variant({escape_argument(argument["name"])})'
23702370
args_array += ", "
23712371

2372-
args_array += "Variant(args)... };"
2372+
args_array += "Variant(p_args)... };"
23732373
result.append(args_array)
23742374
result.append(f"\tstd::array<const Variant *, {len(method_arguments)} + sizeof...(Args)> call_args;")
23752375
result.append("\tfor(size_t i = 0; i < variant_args.size(); i++) {")
@@ -2673,6 +2673,12 @@ def escape_identifier(id):
26732673
return id
26742674

26752675

2676+
def escape_argument(id):
2677+
if id.startswith("p_"):
2678+
return id
2679+
return "p_" + id
2680+
2681+
26762682
def get_operator_id_name(op):
26772683
op_id_map = {
26782684
"==": "equal",

0 commit comments

Comments
 (0)