ソースを参照

Use Array<Dynamic> for all object arrays, and cast output of the getting functions

Hugh Sanderson 12 年 前
コミット
ad35ad5af6
1 ファイル変更36 行追加4 行削除
  1. 36 4
      gencpp.ml

+ 36 - 4
gencpp.ml

@@ -376,7 +376,7 @@ let gen_close_namespace output class_path =
 
 (* The basic types can have default values and are passesby value *)
 let cant_be_null = function
-	| "Int" | "Bool" | "Float" |  "::haxe::io::Unsigned_char__" -> true
+	| "Int" | "Bool" | "Float" |  "::haxe::io::Unsigned_char__" | "unsigned char" -> true
 	| "int" | "bool" | "double" | "float" -> true
 	| _ -> false
 
@@ -388,7 +388,7 @@ let rec class_string klass suffix params =
 	(* Array class *)
 	|  ([],"Array") when is_dynamic_array_param (List.hd params) -> "Dynamic"
 	|  ([],"Array") -> (snd klass.cl_path) ^ suffix ^ "< " ^ (String.concat ","
-					 (List.map type_string  params) ) ^ " >"
+					 (List.map array_element_type params) ) ^ " >"
 	(* FastIterator class *)
 	|  (["cpp"],"FastIterator") -> "::cpp::FastIterator" ^ suffix ^ "< " ^ (String.concat ","
 					 (List.map type_string  params) ) ^ " >"
@@ -469,6 +469,11 @@ and type_string_suff suffix haxe_type =
 	)
 and type_string haxe_type =
 	type_string_suff "" haxe_type
+and array_element_type haxe_type =
+   match type_string haxe_type with
+   | x when cant_be_null x -> x
+   | "::String" -> "::String"
+   | _ -> "::Dynamic"
 
 and is_dynamic_array_param haxe_type =
    if (type_string (follow haxe_type)) = "Dynamic" then true
@@ -1429,6 +1434,16 @@ and gen_expression ctx retval expression =
 		| _ ->  gen_bin_op_string expr1 (Ast.s_binop op) expr2
 		in
 
+	let gen_array_cast array_type cast_name call =
+	   match follow array_type with
+	   | TInst (klass,[element]) ->
+         ( match type_string element with
+           | x when cant_be_null x -> ()
+           | "::String" | "Dynamic" -> ()
+           | real_type -> output (cast_name ^ "< " ^ real_type ^ " >" ^ call)
+         )
+      | _ -> ()
+   in
 	let rec gen_tfield field_object field =
       let member = (field_name field) in
 		let remap_name = keyword_remap member in
@@ -1467,9 +1482,12 @@ and gen_expression ctx retval expression =
             else begin
                cast_if_required ctx field_object (type_string field_object.etype);
                output ( "->" ^ remap_name );
-               already_dynamic := match field with
+               if (calling && (is_array field_object.etype) && remap_name="iterator" ) then
+                  gen_array_cast field_object.etype "Fast" "";
+
+               already_dynamic := (match field with
                   | FInstance(_,var) when is_var_field var -> true
-                  | _ -> false
+                  | _ -> false);
             end;
          end;
       );
@@ -1564,6 +1582,19 @@ and gen_expression ctx retval expression =
       if (cast_result) then output (")");
       if ( (is_variable func) && (expr_type<>"Dynamic") && (not is_super) && (not is_block_call)) then
          ctx.ctx_output (".Cast< " ^ expr_type ^ " >()" );
+
+      let rec cast_array_output func =
+         match func.eexpr with
+            | TField(obj,field) when is_array obj.etype ->
+               (match field_name field with
+                  | "pop" | "shift" -> gen_array_cast obj.etype ".StaticCast" "()"
+                  | _ -> ()
+               )
+            | TParenthesis p -> cast_array_output p
+            | _ -> ()
+      in
+      cast_array_output func;
+
 	| TBlock expr_list ->
 		if (retval) then
          gen_local_block_call()
@@ -1661,6 +1692,7 @@ and gen_expression ctx retval expression =
 			output "->__get(";
 			gen_expression ctx true index;
 			output ")";
+			gen_array_cast array_expr.etype ".StaticCast" "()";
 		end
 	(* Get precidence matching haxe ? *)
 	| TBinop (op,expr1,expr2) -> gen_bin_op op expr1 expr2