Browse Source

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

Nicolas Cannasse 12 years ago
parent
commit
c18937fc1e
1 changed files with 8 additions and 1 deletions
  1. 8 1
      genxml.ml

+ 8 - 1
genxml.ml

@@ -339,7 +339,14 @@ let generate_type com t =
 		| None ->
 			n ^ " : " ^ stype t
 		| 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 ->
 			n ^ " : " ^ stype t ^ " = " ^ (match s_constant v with "nan" -> "0./*NaN*/" | v -> v)
 	in