浏览代码

make distinction between ?x:Int and x=0 in --gen-hx-classes (close #2134)

Nicolas Cannasse 12 年之前
父节点
当前提交
c18937fc1e
共有 1 个文件被更改,包括 8 次插入1 次删除
  1. 8 1
      genxml.ml

+ 8 - 1
genxml.ml

@@ -339,7 +339,14 @@ let generate_type com t =
 		| None ->
 		| None ->
 			n ^ " : " ^ stype t
 			n ^ " : " ^ stype t
 		| Some (Ident "null") ->
 		| Some (Ident "null") ->
-			"?" ^ n ^ " : " ^ stype (notnull t)
+			if is_null t then
+				"?" ^ n ^ " : " ^ stype (notnull t)
+			else
+				(* we have not found a default value stored in metadata, let's generate it *)
+				n ^ " : " ^ stype t ^ " = " ^ (match follow t with
+					| TAbstract ({ a_path = [],("Int"|"Float"|"UInt") },_) -> "0"
+					| TAbstract ({ a_path = [],"Bool" },_) -> "false"
+					| _ -> "null")
 		| Some v ->
 		| Some v ->
 			n ^ " : " ^ stype t ^ " = " ^ (match s_constant v with "nan" -> "0./*NaN*/" | v -> v)
 			n ^ " : " ^ stype t ^ " = " ^ (match s_constant v with "nan" -> "0./*NaN*/" | v -> v)
 	in
 	in