@@ -852,14 +852,14 @@ def generate_builtin_class_header(builtin_api, size, used_classes, fully_used_cl
852852
853853 if "operators" in builtin_api :
854854 for operator in builtin_api ["operators" ]:
855- if operator ["name" ] not in [ "in" , "xor" ] :
855+ if is_valid_cpp_operator ( operator ["name" ]) :
856856 if "right_type" in operator :
857857 result .append (
858- f'\t { correct_type (operator ["return_type" ])} operator{ operator ["name" ]} ({ type_for_parameter (operator ["right_type" ])} p_other) const;'
858+ f'\t { correct_type (operator ["return_type" ])} operator{ get_operator_cpp_name ( operator ["name" ]) } ({ type_for_parameter (operator ["right_type" ])} p_other) const;'
859859 )
860860 else :
861861 result .append (
862- f'\t { correct_type (operator ["return_type" ])} operator{ operator ["name" ]. replace ( "unary" , "" )} () const;'
862+ f'\t { correct_type (operator ["return_type" ])} operator{ get_operator_cpp_name ( operator ["name" ])} () const;'
863863 )
864864
865865 # Copy assignment.
@@ -1291,10 +1291,10 @@ def generate_builtin_class_source(builtin_api, size, used_classes, fully_used_cl
12911291
12921292 if "operators" in builtin_api :
12931293 for operator in builtin_api ["operators" ]:
1294- if operator ["name" ] not in [ "in" , "xor" ] :
1294+ if is_valid_cpp_operator ( operator ["name" ]) :
12951295 if "right_type" in operator :
12961296 result .append (
1297- f'{ correct_type (operator ["return_type" ])} { class_name } ::operator{ operator ["name" ]} ({ type_for_parameter (operator ["right_type" ])} p_other) const {{'
1297+ f'{ correct_type (operator ["return_type" ])} { class_name } ::operator{ get_operator_cpp_name ( operator ["name" ]) } ({ type_for_parameter (operator ["right_type" ])} p_other) const {{'
12981298 )
12991299 (encode , arg_name ) = get_encoded_arg ("other" , operator ["right_type" ], None )
13001300 result += encode
@@ -1304,7 +1304,7 @@ def generate_builtin_class_source(builtin_api, size, used_classes, fully_used_cl
13041304 result .append ("}" )
13051305 else :
13061306 result .append (
1307- f'{ correct_type (operator ["return_type" ])} { class_name } ::operator{ operator ["name" ]. replace ( "unary" , "" )} () const {{'
1307+ f'{ correct_type (operator ["return_type" ])} { class_name } ::operator{ get_operator_cpp_name ( operator ["name" ])} () const {{'
13081308 )
13091309 result .append (
13101310 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);'
@@ -2719,8 +2719,8 @@ def correct_type(type_name, meta=None, use_alias=True):
27192719 if meta is not None :
27202720 if "int" in meta :
27212721 return f"{ meta } _t"
2722- elif meta in type_conversion :
2723- return type_conversion [ type_name ]
2722+ elif "char" in meta :
2723+ return f" { meta } _t"
27242724 else :
27252725 return meta
27262726 if type_name in type_conversion :
@@ -2832,6 +2832,38 @@ def get_operator_id_name(op):
28322832 return op_id_map [op ]
28332833
28342834
2835+ def get_operator_cpp_name (op ):
2836+ op_cpp_map = {
2837+ "==" : "==" ,
2838+ "!=" : "!=" ,
2839+ "<" : "<" ,
2840+ "<=" : "<=" ,
2841+ ">" : ">" ,
2842+ ">=" : ">=" ,
2843+ "+" : "+" ,
2844+ "-" : "-" ,
2845+ "*" : "*" ,
2846+ "/" : "/" ,
2847+ "unary-" : "-" ,
2848+ "unary+" : "+" ,
2849+ "%" : "%" ,
2850+ "<<" : "<<" ,
2851+ ">>" : ">>" ,
2852+ "&" : "&" ,
2853+ "|" : "|" ,
2854+ "^" : "^" ,
2855+ "~" : "~" ,
2856+ "and" : "&&" ,
2857+ "or" : "||" ,
2858+ "not" : "!" ,
2859+ }
2860+ return op_cpp_map [op ]
2861+
2862+
2863+ def is_valid_cpp_operator (op ):
2864+ return op not in ["**" , "xor" , "in" ]
2865+
2866+
28352867def get_default_value_for_type (type_name ):
28362868 if type_name == "int" :
28372869 return "0"
0 commit comments