Просмотр исходного кода

added array comprehension, fixed issue #1308

Nicolas Cannasse 12 лет назад
Родитель
Сommit
8c957bb3cb
2 измененных файлов с 14 добавлено и 1 удалено
  1. 1 1
      doc/CHANGES.txt
  2. 13 0
      typer.ml

+ 1 - 1
doc/CHANGES.txt

@@ -43,7 +43,7 @@
 	all : changed callback(func, args) to func.callback(args)
 	macro : added haxe.macro.ExprTools/ComplexTypeTools/TypeTools
 	macro : changed reification syntax
-
+	all : added array comprehension
 
 2012-07-16: 2.10
 	java/cs : added two new targets (beta)

+ 13 - 0
typer.ml

@@ -2042,6 +2042,19 @@ and type_expr ctx (e,p) (with_type:with_type) =
 			end;
 			a.a_status := Closed;
 			mk (TObjectDecl fl) t p)
+	| EArrayDecl [(EFor(it,e2),fp)] ->
+		let ea = type_expr ctx (EArrayDecl [],p) Value in
+		let v = gen_local ctx ea.etype in
+		let push e =
+			let p = snd e in
+			(ECall ((EField ((EConst (Ident v.v_name),p),"push"),p),[e]),p)
+		in
+		let efor = type_expr ctx (EFor (it,(match e2 with (EIf (cond,e1,None),p) -> (EIf (cond,push e1,None),p) | _ -> push e2)),fp) NoValue in
+		mk (TBlock [
+			mk (TVars [v,Some ea]) ctx.t.tvoid p;
+			efor;
+			mk (TLocal v) v.v_type p;
+		]) v.v_type p
 	| EArrayDecl el ->
 		let tp = (match with_type with
 		| WithType t ->