Browse Source

[cpp] Make sure that the function vtable entries are set in the correct order

Closes #5351
Supersedes #5353
Cauê Waneck 9 years ago
parent
commit
1a39cf6367

+ 7 - 7
src/generators/gencpp.ml

@@ -3665,16 +3665,16 @@ let is_override class_def field =
 ;;
 ;;
 
 
 let all_virtual_functions clazz =
 let all_virtual_functions clazz =
-  let rec all_virtual_functions_rev clazz =
+  let rec all_virtual_functions clazz =
    (match clazz.cl_super with
    (match clazz.cl_super with
-   | Some def -> all_virtual_functions_rev (fst def)
+   | Some def -> all_virtual_functions (fst def)
    | _ -> [] ) @
    | _ -> [] ) @
-   (List.fold_left (fun result elem -> match follow elem.cf_type, elem.cf_kind  with
+   List.rev (List.fold_left (fun result elem -> match follow elem.cf_type, elem.cf_kind  with
       | _, Method MethDynamic -> result
       | _, Method MethDynamic -> result
       | TFun (args,return_type), Method _  when not (is_override clazz elem.cf_name ) -> (elem,args,return_type) :: result
       | TFun (args,return_type), Method _  when not (is_override clazz elem.cf_name ) -> (elem,args,return_type) :: result
       | _,_ -> result ) [] clazz.cl_ordered_fields)
       | _,_ -> result ) [] clazz.cl_ordered_fields)
    in
    in
-   List.rev (all_virtual_functions_rev clazz)
+   all_virtual_functions clazz
 ;;
 ;;
 
 
 
 
@@ -4958,10 +4958,10 @@ let generate_class_files baseCtx super_deps constructor_deps class_def inScripta
                             output_cpp ("	" ^ cast ^ "&" ^ implname ^ "::" ^ realName ^ ",\n");
                             output_cpp ("	" ^ cast ^ "&" ^ implname ^ "::" ^ realName ^ ",\n");
                       | _ -> () )
                       | _ -> () )
                       in
                       in
-                      List.iter gen_field interface.cl_ordered_fields;
-                      match interface.cl_super with
+                      (match interface.cl_super with
                       | Some super -> gen_interface_funcs (fst super)
                       | Some super -> gen_interface_funcs (fst super)
-                      | _ -> ()
+                      | _ -> ());
+                      List.iter gen_field interface.cl_ordered_fields;
                       in
                       in
                    gen_interface_funcs interface;
                    gen_interface_funcs interface;
                    output_cpp "};\n\n";
                    output_cpp "};\n\n";

+ 1 - 1
std/cpp/_std/Type.hx

@@ -143,7 +143,7 @@ enum ValueType {
    @:extern @:native("_hx_getEnumValueIndex")
    @:extern @:native("_hx_getEnumValueIndex")
 	private static function getEnumValueIndex( e : EnumValue ) : Int return 0;
 	private static function getEnumValueIndex( e : EnumValue ) : Int return 0;
 
 
-	public inline static function enumIndex( e : EnumValue ) : Int {
+	#if !cppia inline #end public static function enumIndex( e : EnumValue ) : Int {
 			return getEnumValueIndex(e);
 			return getEnumValueIndex(e);
 	}
 	}
 
 

+ 4 - 0
tests/RunCi.hx

@@ -994,6 +994,10 @@ class RunCi {
 								runCommand("rm", ["-rf", "cpp"]);
 								runCommand("rm", ["-rf", "cpp"]);
 								runCommand("haxe", ["compile-cpp.hxml", "-D", "HXCPP_M64"].concat(args));
 								runCommand("haxe", ["compile-cpp.hxml", "-D", "HXCPP_M64"].concat(args));
 								runCpp("bin/cpp/Test-debug", []);
 								runCpp("bin/cpp/Test-debug", []);
+
+								runCommand("haxe", ["compile-cppia-host.hxml"]);
+								runCommand("haxe", ["compile-cppia.hxml"]);
+								runCpp("bin/cppia/Host-debug", ["bin/unit.cppia"]);
 						}
 						}
 
 
 						changeDirectory(sysDir);
 						changeDirectory(sysDir);

+ 2 - 0
tests/unit/compile-cppia-host.hxml

@@ -4,3 +4,5 @@
 -debug
 -debug
 -dce no
 -dce no
 -cpp bin/cppia
 -cpp bin/cppia
+-cp src
+--macro include("scripthost")

+ 21 - 0
tests/unit/src/scripthost/Issue5351.hx

@@ -0,0 +1,21 @@
+package scripthost;
+
+@:keep class Issue5351 {
+	public function new() {
+		//initialize variables
+	}
+
+	public function doTest1() {
+		return 'doTest1';
+	}
+
+	public function doTest2() {
+		return 'doTest2';
+	}
+}
+
+@:keep class Issue5351_2 extends Issue5351 {
+	public function doTest3() {
+		return 'doTest3';
+	}
+}

+ 17 - 0
tests/unit/src/unit/issues/Issue5351.hx

@@ -0,0 +1,17 @@
+package unit.issues;
+import scripthost.Issue5351;
+
+class Issue5351 extends Test {
+	public function test() {
+		var t3:Issue5351_2 = Type.createInstance(Type.resolveClass('unit.issues.Issue5351_3'), []);
+		eq(t3.doTest1(), 'doTest1 override');
+		eq(t3.doTest2(), 'doTest2');
+		eq(t3.doTest3(), 'doTest3');
+	}
+}
+
+@:keep class Issue5351_3 extends Issue5351_2 {
+	override public function doTest1() {
+		return 'doTest1 override';
+	}
+}