Skip to content

Commit 9949d09

Browse files
committed
Fix incorrect generation of some C++ operators
1 parent 8b80d91 commit 9949d09

File tree

1 file changed

+38
-6
lines changed

1 file changed

+38
-6
lines changed

binding_generator.py

Lines changed: 38 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -872,14 +872,14 @@ def generate_builtin_class_header(builtin_api, size, used_classes, fully_used_cl
872872

873873
if "operators" in builtin_api:
874874
for operator in builtin_api["operators"]:
875-
if operator["name"] not in ["in", "xor"]:
875+
if is_valid_cpp_operator(operator["name"]):
876876
if "right_type" in operator:
877877
result.append(
878-
f'\t{correct_type(operator["return_type"])} operator{operator["name"]}({type_for_parameter(operator["right_type"])}p_other) const;'
878+
f'\t{correct_type(operator["return_type"])} operator{get_operator_cpp_name(operator["name"])}({type_for_parameter(operator["right_type"])}p_other) const;'
879879
)
880880
else:
881881
result.append(
882-
f'\t{correct_type(operator["return_type"])} operator{operator["name"].replace("unary", "")}() const;'
882+
f'\t{correct_type(operator["return_type"])} operator{get_operator_cpp_name(operator["name"])}() const;'
883883
)
884884

885885
# Copy assignment.
@@ -1316,10 +1316,10 @@ def generate_builtin_class_source(builtin_api, size, used_classes, fully_used_cl
13161316

13171317
if "operators" in builtin_api:
13181318
for operator in builtin_api["operators"]:
1319-
if operator["name"] not in ["in", "xor"]:
1319+
if is_valid_cpp_operator(operator["name"]):
13201320
if "right_type" in operator:
13211321
result.append(
1322-
f'{correct_type(operator["return_type"])} {class_name}::operator{operator["name"]}({type_for_parameter(operator["right_type"])}p_other) const {{'
1322+
f'{correct_type(operator["return_type"])} {class_name}::operator{get_operator_cpp_name(operator["name"])}({type_for_parameter(operator["right_type"])}p_other) const {{'
13231323
)
13241324
(encode, arg_name) = get_encoded_arg("other", operator["right_type"], None)
13251325
result += encode
@@ -1329,7 +1329,7 @@ def generate_builtin_class_source(builtin_api, size, used_classes, fully_used_cl
13291329
result.append("}")
13301330
else:
13311331
result.append(
1332-
f'{correct_type(operator["return_type"])} {class_name}::operator{operator["name"].replace("unary", "")}() const {{'
1332+
f'{correct_type(operator["return_type"])} {class_name}::operator{get_operator_cpp_name(operator["name"])}() const {{'
13331333
)
13341334
result.append(
13351335
f'\treturn internal::_call_builtin_operator_ptr<{get_gdextension_type(correct_type(operator["return_type"]))}>(_method_bindings.operator_{get_operator_id_name(operator["name"])}, (GDExtensionConstTypePtr)&opaque, (GDExtensionConstTypePtr) nullptr);'
@@ -2883,6 +2883,38 @@ def get_operator_id_name(op):
28832883
return op_id_map[op]
28842884

28852885

2886+
def get_operator_cpp_name(op):
2887+
op_cpp_map = {
2888+
"==": "==",
2889+
"!=": "!=",
2890+
"<": "<",
2891+
"<=": "<=",
2892+
">": ">",
2893+
">=": ">=",
2894+
"+": "+",
2895+
"-": "-",
2896+
"*": "*",
2897+
"/": "/",
2898+
"unary-": "-",
2899+
"unary+": "+",
2900+
"%": "%",
2901+
"<<": "<<",
2902+
">>": ">>",
2903+
"&": "&",
2904+
"|": "|",
2905+
"^": "^",
2906+
"~": "~",
2907+
"and": "&&",
2908+
"or": "||",
2909+
"not": "!",
2910+
}
2911+
return op_cpp_map[op]
2912+
2913+
2914+
def is_valid_cpp_operator(op):
2915+
return op not in ["**", "xor", "in"]
2916+
2917+
28862918
def get_default_value_for_type(type_name):
28872919
if type_name == "int":
28882920
return "0"

0 commit comments

Comments
 (0)