Index: /trunk/Decompiler.class.php
===================================================================
--- /trunk/Decompiler.class.php	(revision 731)
+++ /trunk/Decompiler.class.php	(revision 732)
@@ -9,5 +9,5 @@
 }
 
-function str($src, $indent = '') // {{{
+function toCode($src, $indent = '') // {{{
 {
 	if (is_array($indent)) {
@@ -15,28 +15,10 @@
 	}
 
-	/*
-	$e = xcache_get_special_value($src);
-	if (isset($e)) {
-		if (is_array($e)) {
-			$src = $e;
-		}
-		else {
-			return $e;
-		}
-	}
-	*/
-
-	if (is_array($src)) {
-		exit('array str');
-		$src = new Decompiler_Array($src, $indent);
-		return $src->__toString();
-	}
-
 	if (is_object($src)) {
-		if (!method_exists($src, '__toString')) {
+		if (!method_exists($src, 'toCode')) {
 			var_dump($src);
-			exit('no __toString');
-		}
-		return $src->__toString();
+			exit('no toCode');
+		}
+		return $src->toCode($indent);
 	}
 
@@ -80,5 +62,5 @@
 	}
 
-	function __toString()
+	function toCode($indent)
 	{
 		return var_export($this->value, true);
@@ -95,5 +77,5 @@
 	}
 
-	function __toString()
+	function toCode($indent)
 	{
 		return $this->src;
@@ -107,4 +89,5 @@
 	var $op2;
 	var $parent;
+	var $indent;
 
 	function Decompiler_Binop($parent, $op1, $opc, $op2)
@@ -116,7 +99,7 @@
 	}
 
-	function __toString()
-	{
-		$op1 = str($this->op1);
+	function toCode($indent)
+	{
+		$op1 = toCode($this->op1, $indent);
 		if (is_a($this->op1, 'Decompiler_Binop') && $this->op1->opc != $this->opc) {
 			$op1 = "($op1)";
@@ -124,7 +107,7 @@
 		$opstr = $this->parent->binops[$this->opc];
 		if ($op1 == '0' && $this->opc == XC_SUB) {
-			return $opstr . str($this->op2);
-		}
-		return $op1 . ' ' . $opstr . ' ' . str($this->op2);
+			return $opstr . toCode($this->op2, $indent);
+		}
+		return $op1 . ' ' . $opstr . ' ' . toCode($this->op2, $indent);
 	}
 }
@@ -142,5 +125,5 @@
 	}
 
-	function __toString()
+	function toCode($indent)
 	{
 		switch ($this->fetchType) {
@@ -168,7 +151,7 @@
 	}
 
-	function __toString()
-	{
-		return $this->obj->__toString();
+	function toCode($indent)
+	{
+		return $this->obj->toCode($indent);
 	}
 }
@@ -180,14 +163,14 @@
 	var $assign = null;
 
-	function __toString()
+	function toCode($indent)
 	{
 		if (is_a($this->value, 'Decompiler_ListBox')) {
-			$exp = str($this->value->obj->src);
+			$exp = toCode($this->value->obj->src, $indent);
 		}
 		else {
-			$exp = str($this->value);
+			$exp = toCode($this->value, $indent);
 		}
 		foreach ($this->offsets as $dim) {
-			$exp .= '[' . str($dim) . ']';
+			$exp .= '[' . toCode($dim, $indent) . ']';
 		}
 		return $exp;
@@ -205,5 +188,5 @@
 	var $everLocked = false;
 
-	function __toString()
+	function toCode($indent)
 	{
 		if (count($this->dims) == 1 && !$this->everLocked) {
@@ -212,7 +195,7 @@
 			$dim->value = $this->src;
 			if (!isset($dim->assign)) {
-				return str($dim);
-			}
-			return str($this->dims[0]->assign) . ' = ' . str($dim);
+				return toCode($dim, $indent);
+			}
+			return toCode($this->dims[0]->assign, $indent) . ' = ' . toCode($dim, $indent);
 		}
 		/* flatten dims */
@@ -223,7 +206,7 @@
 				$assign = &$assign[$offset];
 			}
-			$assign = str($dim->assign);
-		}
-		return $this->toList($assigns) . ' = ' . str($this->src);
+			$assign = toCode($dim->assign, $indent);
+		}
+		return $this->toList($assigns) . ' = ' . toCode($this->src, $indent);
 	}
 
@@ -260,16 +243,13 @@
 class Decompiler_Array extends Decompiler_Value // {{{
 {
-	var $indent = '';
-
-	function Decompiler_Array($value = array(), $indent = '')
+	function Decompiler_Array($value = array())
 	{
 		$this->value = $value;
-		$this->indent = $indent;
-	}
-
-	function __toString()
+	}
+
+	function toCode($indent)
 	{
 		$exp = "array(";
-		$indent = $this->indent . INDENT;
+		$indent = $indent . INDENT;
 		$assoclen = 0;
 		$multiline = 0;
@@ -282,5 +262,6 @@
 				}
 			}
-			if (is_array(value($v))) {
+			$spec = xcache_get_special_value($v);
+			if (is_array(isset($spec) ? $spec : $v)) {
 				$multiline ++;
 			}
@@ -315,10 +296,10 @@
 			}
 
-			$exp .= str(value($v), $subindent);
+			$exp .= toCode(value($v), $subindent);
 
 			$i ++;
 		}
 		if ($multiline) {
-			$exp .= "$indent);";
+			$exp .= "\n$indent)";
 		}
 		else {
@@ -333,5 +314,5 @@
 	var $iskey;
 
-	function __toString()
+	function toCode($indent)
 	{
 		return 'foreach (' . '';
@@ -417,5 +398,5 @@
 					$curticks = $toticks;
 				}
-				echo $indent, str($op['php']), ";\n";
+				echo $indent, toCode($op['php'], $indent), ";\n";
 			}
 		}
@@ -429,5 +410,5 @@
 		switch ($op['op_type']) {
 		case XC_IS_CONST:
-			return str(value($op['constant']));
+			return toCode(value($op['constant']), $EX);
 
 		case XC_IS_VAR:
@@ -436,5 +417,5 @@
 			$ret = $T[$op['var']];
 			if ($tostr) {
-				$ret = str($ret, $EX);
+				$ret = toCode($ret, $EX);
 			}
 			if ($free) {
@@ -641,9 +622,9 @@
 			$body = ob_get_clean();
 
-			$as = str($op['fe_as']);
+			$as = toCode($op['fe_as'], $EX);
 			if (isset($op['fe_key'])) {
-				$as = str($op['fe_key']) . ' => ' . $as;
-			}
-			echo "{$indent}foreach (" . str($op['fe_src']) . " as $as) {\n";
+				$as = toCode($op['fe_key'], $EX) . ' => ' . $as;
+			}
+			echo "{$indent}foreach (" . toCode($op['fe_src'], $EX) . " as $as) {\n";
 			echo $body;
 			echo "{$indent}}";
@@ -869,5 +850,5 @@
 					}
 					if ($opc == XC_UNSET_VAR) {
-						$op['php'] = "unset(" . str($rvalue) . ")";
+						$op['php'] = "unset(" . toCode($rvalue, $EX) . ")";
 						$lastphpop = &$op;
 					}
@@ -930,8 +911,8 @@
 						++ $i;
 						$rvalue = $this->getOpVal($opcodes[$i]['op1'], $EX);
-						$resvar = str($lvalue) . ' = ' . $rvalue;
+						$resvar = toCode($lvalue, $EX) . ' = ' . $rvalue;
 					}
 					else if ($opc == XC_UNSET_DIM) {
-						$op['php'] = "unset(" . str($rvalue) . ")";
+						$op['php'] = "unset(" . toCode($rvalue, $EX) . ")";
 						$lastphpop = &$op;
 					}
@@ -954,10 +935,10 @@
 						$dim->assign = $lvalue;
 						if ($dim->isLast) {
-							$resvar = str($dim->value);
+							$resvar = toCode($dim->value, $EX);
 						}
 						unset($dim);
 						break;
 					}
-					$resvar = "$lvalue = " . str($rvalue, $EX);
+					$resvar = "$lvalue = " . toCode($rvalue, $EX);
 					break;
 					// }}}
@@ -966,5 +947,5 @@
 					$rvalue = $this->getOpVal($op2, $EX, false);
 					if (is_a($rvalue, 'Decompiler_Fetch')) {
-						$src = str($rvalue->src);
+						$src = toCode($rvalue->src, $EX);
 						if (substr($src, 1, -1) == substr($lvalue, 1)) {
 							switch ($rvalue->fetchType) {
@@ -980,5 +961,5 @@
 									$var = $statics[$name];
 									$resvar .= ' = ';
-									$resvar .= str(value($var), $EX);
+									$resvar .= toCode(value($var), $EX);
 								}
 								unset($statics);
@@ -989,5 +970,5 @@
 					}
 					// TODO: PHP_6 global
-					$rvalue = str($rvalue);
+					$rvalue = toCode($rvalue, $EX);
 					$resvar = "$lvalue = &$rvalue";
 					break;
@@ -1202,8 +1183,8 @@
 					switch ($opc) {
 					case XC_ADD_CHAR:
-						$op2val = str(chr($op2val), $EX);
+						$op2val = toCode(chr($op2val), $EX);
 						break;
 					case XC_ADD_STRING:
-						$op2val = str($op2val, $EX);
+						$op2val = toCode($op2val, $EX);
 						break;
 					case XC_ADD_VAR:
@@ -1345,8 +1326,8 @@
 						$targetop = &$EX['opcodes'][$op2['opline_num']];
 						if ($opc == XC_JMPNZ_EX) {
-							$targetop['cond_true'][] = str($rvalue);
+							$targetop['cond_true'][] = toCode($rvalue, $EX);
 						}
 						else {
-							$targetop['cond_false'][] = str($rvalue);
+							$targetop['cond_false'][] = toCode($rvalue, $EX);
 						}
 						unset($targetop);
@@ -1416,5 +1397,5 @@
 				case XC_END_SILENCE: // {{{
 					$EX['silence'] --;
-					$lastresvar = '@' . str($lastresvar);
+					$lastresvar = '@' . toCode($lastresvar, $EX);
 					break;
 					// }}}
@@ -1486,5 +1467,5 @@
 			$a = array_pop($EX['argstack']);
 			if (is_array($a)) {
-				array_unshift($args, str($a, $EX));
+				array_unshift($args, toCode($a, $EX));
 			}
 			else {
@@ -1543,5 +1524,4 @@
 	function dargs(&$EX, $indent) // {{{
 	{
-		$EX['indent'] = $indent;
 		$op_array = &$EX['op_array'];
 
@@ -1602,7 +1582,7 @@
 				}
 				$arg = $EX['recvs'][$i + 1];
-				echo str($arg[0]);
+				echo toCode($arg[0], $indent);
 				if (isset($arg[1])) {
-					echo ' = ', str($arg[1]);
+					echo ' = ', toCode($arg[1], $indent);
 				}
 			}
@@ -1681,5 +1661,5 @@
 					echo $newindent;
 					echo $prefix, $name, ' = ';
-					echo str(value($v), $EX);
+					echo toCode(value($v), $newindent);
 					echo ";\n";
 				}
@@ -1755,5 +1735,5 @@
 				if (isset($value)) {
 					echo ' = ';
-					echo str(value($value));
+					echo toCode(value($value), $newindent);
 				}
 				echo ";\n";
