Browse Source

[cpp] Implement virtual __Compare function when __compare function is implemented. Fixes https://github.com/HaxeFoundation/hxcpp/issues/745

hughsando 6 years ago
parent
commit
649e09a6ea
1 changed files with 7 additions and 0 deletions
  1. 7 0
      src/generators/gencpp.ml

+ 7 - 0
src/generators/gencpp.ml

@@ -5288,6 +5288,9 @@ let has_get_static_field class_def =
       List.exists (is_readable class_def) reflect_fields
       List.exists (is_readable class_def) reflect_fields
 ;;
 ;;
 
 
+let has_compare_field class_def =
+    List.exists (fun f -> f.cf_name="__compare") class_def.cl_ordered_fields
+;;
 
 
 
 
 let has_boot_field class_def =
 let has_boot_field class_def =
@@ -6524,6 +6527,10 @@ let generate_class_files baseCtx super_deps constructor_deps class_def inScripta
       if (has_get_fields class_def) then
       if (has_get_fields class_def) then
          output_h ("\t\tvoid __GetFields(Array< ::String> &outFields);\n");
          output_h ("\t\tvoid __GetFields(Array< ::String> &outFields);\n");
 
 
+      if (has_compare_field class_def) then
+         output_h ("\t\tint __Compare(const hx::Object *inRHS) const { " ^
+                           "return const_cast<" ^ class_name ^ " *>(this)->__compare(Dynamic((hx::Object *)inRHS)); }\n");
+
       output_h ("\t\tstatic void __register();\n");
       output_h ("\t\tstatic void __register();\n");
       if (override_iteration) then begin
       if (override_iteration) then begin
          output_h ("\t\tvoid __Mark(HX_MARK_PARAMS);\n");
          output_h ("\t\tvoid __Mark(HX_MARK_PARAMS);\n");