Browse Source

fixed assignament of field length in anonym objects (haXe/PHP)

Franco Ponticelli 17 years ago
parent
commit
c68db0a473
3 changed files with 74 additions and 27 deletions
  1. 1 0
      doc/CHANGES.txt
  2. 39 8
      genphp.ml
  3. 34 19
      std/php/Boot.hx

+ 1 - 0
doc/CHANGES.txt

@@ -13,6 +13,7 @@ TODO :
 	fixed bug in haxe.io.BytesInput.readBytes in Flash9 (was throwing Eof if full buffer can't be readed)
 	fixed bug in haxe.io.BytesInput.readBytes in Flash9 (was throwing Eof if full buffer can't be readed)
 	fixed implements/extends special classes when they are imported
 	fixed implements/extends special classes when they are imported
 	StringBuf now uses an array for JS implementation (around same on FF, faster on IE)
 	StringBuf now uses an array for JS implementation (around same on FF, faster on IE)
+	fixed assignament of field length in anonym objects (haXe/PHP)
 
 
 2008-11-23: 2.02
 2008-11-23: 2.02
 	Std.is(MyInterface, Class) now returns true (haXe/PHP)
 	Std.is(MyInterface, Class) now returns true (haXe/PHP)

+ 39 - 8
genphp.ml

@@ -877,6 +877,24 @@ and gen_expr ctx e =
 				spr ctx "]";
 				spr ctx "]";
 			| _ ->
 			| _ ->
 				gen_field_op ctx e1;) in
 				gen_field_op ctx e1;) in
+		let leftsidec e =
+			(match e.eexpr with
+			| TArray(te1, te2) ->
+				gen_value ctx te1;
+				spr ctx "->__a[";
+				gen_value ctx te2;
+				spr ctx "]";
+			| TField (e1,s) ->
+				gen_field_access ctx true e1 s
+			| _ ->
+				gen_field_op ctx e1;) in
+		let leftsidef e =
+			(match e.eexpr with
+			| TField (e1,s) ->
+				gen_field_access ctx true e1 s;
+			| _ ->
+				gen_field_op ctx e1;
+				) in
 		(match op with
 		(match op with
 		| Ast.OpAssign ->
 		| Ast.OpAssign ->
 			(match e1.eexpr with
 			(match e1.eexpr with
@@ -889,25 +907,22 @@ and gen_expr ctx e =
 				gen_value_op ctx e2;
 				gen_value_op ctx e2;
 				spr ctx ")";
 				spr ctx ")";
 			| _ ->
 			| _ ->
+(*
 				gen_field_op ctx e1;
 				gen_field_op ctx e1;
+*)
+
+				leftsidef e1;
 				spr ctx " = ";
 				spr ctx " = ";
+				
 				gen_value_op ctx e2;)
 				gen_value_op ctx e2;)
 		| Ast.OpAssignOp(Ast.OpAdd) when (is_string_expr e1 || is_string_expr e2) ->
 		| Ast.OpAssignOp(Ast.OpAdd) when (is_string_expr e1 || is_string_expr e2) ->
 			leftside e1;
 			leftside e1;
 			spr ctx " .= ";
 			spr ctx " .= ";
 			gen_value_op ctx e2;
 			gen_value_op ctx e2;
-		| Ast.OpAdd when (is_string_expr e1 || is_string_expr e2) ->
-			gen_value_op ctx e1;
-			spr ctx " . ";
-			gen_value_op ctx e2;
 		| Ast.OpAssignOp(Ast.OpShl) ->
 		| Ast.OpAssignOp(Ast.OpShl) ->
 			leftside e1;
 			leftside e1;
 			spr ctx " <<= ";
 			spr ctx " <<= ";
 			gen_value_op ctx e2;
 			gen_value_op ctx e2;
-		| Ast.OpShl ->
-			gen_value_op ctx e1;
-			spr ctx " << ";
-			gen_value_op ctx e2;
 		| Ast.OpAssignOp(Ast.OpUShr) ->
 		| Ast.OpAssignOp(Ast.OpUShr) ->
 			leftside e1;
 			leftside e1;
 			spr ctx " = ";
 			spr ctx " = ";
@@ -916,6 +931,18 @@ and gen_expr ctx e =
 			spr ctx ", ";
 			spr ctx ", ";
 			gen_value_op ctx e2;
 			gen_value_op ctx e2;
 			spr ctx ")";
 			spr ctx ")";
+		| Ast.OpAssignOp(_) ->
+			leftsidec e1;
+			print ctx " %s " (Ast.s_binop op);
+			gen_value_op ctx e2;
+		| Ast.OpAdd when (is_string_expr e1 || is_string_expr e2) ->
+			gen_value_op ctx e1;
+			spr ctx " . ";
+			gen_value_op ctx e2;
+		| Ast.OpShl ->
+			gen_value_op ctx e1;
+			spr ctx " << ";
+			gen_value_op ctx e2;
 		| Ast.OpUShr ->
 		| Ast.OpUShr ->
 			spr ctx "_hx_shift_right(";
 			spr ctx "_hx_shift_right(";
 			gen_value_op ctx e1;
 			gen_value_op ctx e1;
@@ -1202,6 +1229,8 @@ and gen_expr ctx e =
 			spr ctx "->__a[";
 			spr ctx "->__a[";
 			gen_value ctx te2;
 			gen_value ctx te2;
 			spr ctx "]";
 			spr ctx "]";
+		| TField (e1,s) ->
+			gen_field_access ctx true e1 s
 		| _ ->
 		| _ ->
 			gen_value ctx e)
 			gen_value ctx e)
 	| TUnop (op,Ast.Postfix,e) ->
 	| TUnop (op,Ast.Postfix,e) ->
@@ -1211,6 +1240,8 @@ and gen_expr ctx e =
 			spr ctx "->__a[";
 			spr ctx "->__a[";
 			gen_value ctx te2;
 			gen_value ctx te2;
 			spr ctx "]";
 			spr ctx "]";
+		| TField (e1,s) ->
+			gen_field_access ctx true e1 s
 		| _ ->
 		| _ ->
 			gen_value ctx e);
 			gen_value ctx e);
 		spr ctx (Ast.s_unop op)
 		spr ctx (Ast.s_unop op)

+ 34 - 19
std/php/Boot.hx

@@ -143,6 +143,24 @@ class _hx_array implements ArrayAccess {
 	}
 	}
 }
 }
 
 
+class _hx_array_iterator {
+	private $a;
+	private $i;
+	public function __construct($a) {
+		$this->__a = $a;
+		$this->i = 0;
+	}
+
+	public function next() {
+		if(!$this->hasNext()) return null;
+		return $this->__a[$this->i++];
+	}
+
+	public function hasNext() {
+		return $this->i < count($this->__a);
+	}
+}
+
 function _hx_array_get($a, $pos) {
 function _hx_array_get($a, $pos) {
 	return $a[$pos];
 	return $a[$pos];
 }
 }
@@ -294,6 +312,21 @@ function _hx_null() {
 	return null;
 	return null;
 }
 }
 
 
+class _hx_nullob {
+	function _throw()       { throw new HException('Null object'); }
+	function __call($f, $a) { $this->_throw(); }
+	function __get($f)      { $this->_throw(); }
+	function __set($f, $v)  { $this->_throw(); }
+	function __isset($f)    { $this->_throw(); }
+	function __unset($f)    { $this->_throw(); }
+	function __toString()   { return 'null'; }
+	static $inst;
+}
+
+_hx_nullob::$inst = new _hx_nullob();
+
+function _hx_nullob() { return _hx_nullob::$inst; }
+
 function _hx_qtype($n) {
 function _hx_qtype($n) {
 	return isset(php_Boot::$qtypes[$n]) ? php_Boot::$qtypes[$n] : null;
 	return isset(php_Boot::$qtypes[$n]) ? php_Boot::$qtypes[$n] : null;
 }
 }
@@ -528,25 +561,7 @@ class _hx_class extends _hx_type {}
 
 
 class _hx_enum extends _hx_type {}
 class _hx_enum extends _hx_type {}
 
 
-class _hx_interface extends _hx_type { }
-
-class _hx_array_iterator {
-	private $a;
-	private $i;
-	public function __construct($a) {
-		$this->__a = $a;
-		$this->i = 0;
-	}
-
-	public function next() {
-		if(!$this->hasNext()) return null;
-		return $this->__a[$this->i++];
-	}
-
-	public function hasNext() {
-		return $this->i < count($this->__a);
-	}
-}
+class _hx_interface extends _hx_type {}
 
 
 class HException extends Exception {
 class HException extends Exception {
 	public function __construct($e, $message = null, $code = null, $p = null) {
 	public function __construct($e, $message = null, $code = null, $p = null) {