@@ -872,14 +872,14 @@ def generate_builtin_class_header(builtin_api, size, used_classes, fully_used_cl
872
872
873
873
if "operators" in builtin_api :
874
874
for operator in builtin_api ["operators" ]:
875
- if operator ["name" ] not in [ "in" , "xor" ] :
875
+ if is_valid_cpp_operator ( operator ["name" ]) :
876
876
if "right_type" in operator :
877
877
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;'
879
879
)
880
880
else :
881
881
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;'
883
883
)
884
884
885
885
# Copy assignment.
@@ -1316,10 +1316,10 @@ def generate_builtin_class_source(builtin_api, size, used_classes, fully_used_cl
1316
1316
1317
1317
if "operators" in builtin_api :
1318
1318
for operator in builtin_api ["operators" ]:
1319
- if operator ["name" ] not in [ "in" , "xor" ] :
1319
+ if is_valid_cpp_operator ( operator ["name" ]) :
1320
1320
if "right_type" in operator :
1321
1321
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 {{'
1323
1323
)
1324
1324
(encode , arg_name ) = get_encoded_arg ("other" , operator ["right_type" ], None )
1325
1325
result += encode
@@ -1329,7 +1329,7 @@ def generate_builtin_class_source(builtin_api, size, used_classes, fully_used_cl
1329
1329
result .append ("}" )
1330
1330
else :
1331
1331
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 {{'
1333
1333
)
1334
1334
result .append (
1335
1335
f'\t return 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);'
@@ -2881,6 +2881,38 @@ def get_operator_id_name(op):
2881
2881
return op_id_map [op ]
2882
2882
2883
2883
2884
+ def get_operator_cpp_name (op ):
2885
+ op_cpp_map = {
2886
+ "==" : "==" ,
2887
+ "!=" : "!=" ,
2888
+ "<" : "<" ,
2889
+ "<=" : "<=" ,
2890
+ ">" : ">" ,
2891
+ ">=" : ">=" ,
2892
+ "+" : "+" ,
2893
+ "-" : "-" ,
2894
+ "*" : "*" ,
2895
+ "/" : "/" ,
2896
+ "unary-" : "-" ,
2897
+ "unary+" : "+" ,
2898
+ "%" : "%" ,
2899
+ "<<" : "<<" ,
2900
+ ">>" : ">>" ,
2901
+ "&" : "&" ,
2902
+ "|" : "|" ,
2903
+ "^" : "^" ,
2904
+ "~" : "~" ,
2905
+ "and" : "&&" ,
2906
+ "or" : "||" ,
2907
+ "not" : "!" ,
2908
+ }
2909
+ return op_cpp_map [op ]
2910
+
2911
+
2912
+ def is_valid_cpp_operator (op ):
2913
+ return op not in ["**" , "xor" , "in" ]
2914
+
2915
+
2884
2916
def get_default_value_for_type (type_name ):
2885
2917
if type_name == "int" :
2886
2918
return "0"
0 commit comments