Index: /trunk/Decompiler.class.php
===================================================================
--- /trunk/Decompiler.class.php	(revision 743)
+++ /trunk/Decompiler.class.php	(revision 744)
@@ -11,7 +11,14 @@
 function str($code, $indent = '') // {{{
 {
+	if (is_array($code)) {
+		$array = array();
+		foreach ($code as $key => $value) {
+			$array[$key] = str($value, $indent);
+		}
+		return $array;
+	}
 	if (is_object($code)) {
-		$code = toCode($code, $indent);
-		return $code->__toString();
+		$code = foldToCode($code, $indent);
+		return $code->toCode($indent);
 	}
 
@@ -19,5 +26,5 @@
 }
 // }}}
-function toCode($src, $indent = '') // {{{ wrap or rewrap anything to Decompiler_Code
+function foldToCode($src, $indent = '') // {{{ wrap or rewrap anything to Decompiler_Code
 {
 	if (is_array($indent)) {
@@ -97,9 +104,4 @@
 		return $this->src;
 	}
-
-	function __toString()
-	{
-		return $this->src;
-	}
 }
 // }}}
@@ -122,5 +124,5 @@
 	function toCode($indent)
 	{
-		$op1 = toCode($this->op1, $indent);
+		$op1 = foldToCode($this->op1, $indent);
 		if (is_a($this->op1, 'Decompiler_Binop') && $this->op1->opc != $this->opc) {
 			$op1 = "($op1)";
@@ -128,7 +130,7 @@
 		$opstr = $this->parent->binops[$this->opc];
 		if ($op1 == '0' && $this->opc == XC_SUB) {
-			return $opstr . toCode($this->op2, $indent);
-		}
-		return $op1 . ' ' . $opstr . ' ' . toCode($this->op2, $indent);
+			return $opstr . str($this->op2, $indent);
+		}
+		return $op1 . ' ' . $opstr . ' ' . foldToCodfoldToCode($this->op2, $indent);
 	}
 }
@@ -187,11 +189,11 @@
 	{
 		if (is_a($this->value, 'Decompiler_ListBox')) {
-			$exp = toCode($this->value->obj->src, $indent);
+			$exp = foldToCode($this->value->obj->src, $indent);
 		}
 		else {
-			$exp = toCode($this->value, $indent);
+			$exp = foldToCode($this->value, $indent);
 		}
 		foreach ($this->offsets as $dim) {
-			$exp .= '[' . toCode($dim, $indent) . ']';
+			$exp .= '[' . foldToCode($dim, $indent) . ']';
 		}
 		return $exp;
@@ -216,7 +218,7 @@
 			$dim->value = $this->src;
 			if (!isset($dim->assign)) {
-				return toCode($dim, $indent);
-			}
-			return toCode($this->dims[0]->assign, $indent) . ' = ' . toCode($dim, $indent);
+				return foldToCode($dim, $indent);
+			}
+			return foldToCode($this->dims[0]->assign, $indent) . ' = ' . foldToCode($dim, $indent);
 		}
 		/* flatten dims */
@@ -227,7 +229,7 @@
 				$assign = &$assign[$offset];
 			}
-			$assign = toCode($dim->assign, $indent);
-		}
-		return $this->toList($assigns) . ' = ' . toCode($this->src, $indent);
+			$assign = foldToCode($dim->assign, $indent);
+		}
+		return $this->toList($assigns) . ' = ' . foldToCode($this->src, $indent);
 	}
 
@@ -449,5 +451,5 @@
 					$curticks = $toticks;
 				}
-				echo $indent, toCode($op['php'], $indent), ";\n";
+				echo $indent, str($op['php'], $indent), ";\n";
 			}
 		}
@@ -461,5 +463,5 @@
 		switch ($op['op_type']) {
 		case XC_IS_CONST:
-			return toCode(value($op['constant']), $EX);
+			return foldToCode(value($op['constant']), $EX);
 
 		case XC_IS_VAR:
@@ -468,5 +470,5 @@
 			$ret = $T[$op['var']];
 			if ($tostr) {
-				$ret = toCode($ret, $EX);
+				$ret = foldToCode($ret, $EX);
 			}
 			if ($free) {
@@ -682,9 +684,9 @@
 			$body = ob_get_clean();
 
-			$as = toCode($op['fe_as'], $EX);
+			$as = foldToCode($op['fe_as'], $EX);
 			if (isset($op['fe_key'])) {
-				$as = toCode($op['fe_key'], $EX) . ' => ' . $as;
-			}
-			echo "{$indent}foreach (" . toCode($op['fe_src'], $EX) . " as $as) {\n";
+				$as = str($op['fe_key'], $EX) . ' => ' . str($as);
+			}
+			echo "{$indent}foreach (" . str($op['fe_src'], $EX) . " as $as) {\n";
 			echo $body;
 			echo "{$indent}}";
@@ -755,5 +757,5 @@
 			// $this->dumpop($op, $EX);
 			// any true comes here, so it's a "or"
-			$cond = implode(' and ', $op['cond_false']);
+			$cond = implode(' and ', str($op['cond_false']));
 			// var_dump($op['cond'] = $cond);
 			/*
@@ -771,4 +773,5 @@
 	function unquoteName($str) // {{{
 	{
+		$str = str($str);
 		if (preg_match($this->rQuotedName, $str)) {
 			$str = substr($str, 1, -1);
@@ -910,5 +913,5 @@
 					}
 					if ($opc == XC_UNSET_VAR) {
-						$op['php'] = "unset(" . toCode($rvalue, $EX) . ")";
+						$op['php'] = "unset(" . str($rvalue, $EX) . ")";
 						$lastphpop = &$op;
 					}
@@ -971,8 +974,8 @@
 						++ $i;
 						$rvalue = $this->getOpVal($opcodes[$i]['op1'], $EX);
-						$resvar = toCode($lvalue, $EX) . ' = ' . $rvalue;
+						$resvar = str($lvalue, $EX) . ' = ' . $rvalue;
 					}
 					else if ($opc == XC_UNSET_DIM) {
-						$op['php'] = "unset(" . toCode($rvalue, $EX) . ")";
+						$op['php'] = "unset(" . str($rvalue, $EX) . ")";
 						$lastphpop = &$op;
 					}
@@ -995,10 +998,10 @@
 						$dim->assign = $lvalue;
 						if ($dim->isLast) {
-							$resvar = toCode($dim->value, $EX);
+							$resvar = foldToCode($dim->value, $EX);
 						}
 						unset($dim);
 						break;
 					}
-					$resvar = "$lvalue = " . toCode($rvalue, $EX);
+					$resvar = "$lvalue = " . str($rvalue, $EX);
 					break;
 					// }}}
@@ -1007,5 +1010,5 @@
 					$rvalue = $this->getOpVal($op2, $EX, false);
 					if (is_a($rvalue, 'Decompiler_Fetch')) {
-						$src = toCode($rvalue->src, $EX);
+						$src = foldToCode($rvalue->src, $EX);
 						if (substr($src, 1, -1) == substr($lvalue, 1)) {
 							switch ($rvalue->fetchType) {
@@ -1021,5 +1024,5 @@
 									$var = $statics[$name];
 									$resvar .= ' = ';
-									$resvar .= toCode(value($var), $EX);
+									$resvar .= str(value($var), $EX);
 								}
 								unset($statics);
@@ -1030,5 +1033,5 @@
 					}
 					// TODO: PHP_6 global
-					$rvalue = toCode($rvalue, $EX);
+					$rvalue = foldToCode($rvalue, $EX);
 					$resvar = "$lvalue = &$rvalue";
 					break;
@@ -1117,5 +1120,5 @@
 				case XC_SEND_VAR: // {{{
 					$ref = ($opc == XC_SEND_REF ? '&' : '');
-					$EX['argstack'][] = $ref . $this->getOpVal($op1, $EX);
+					$EX['argstack'][] = $ref . str($this->getOpVal($op1, $EX));
 					break;
 					// }}}
@@ -1243,8 +1246,8 @@
 					switch ($opc) {
 					case XC_ADD_CHAR:
-						$op2val = toCode(chr($op2val), $EX);
+						$op2val = foldToCode(chr($op2val), $EX);
 						break;
 					case XC_ADD_STRING:
-						$op2val = toCode($op2val, $EX);
+						$op2val = foldToCode($op2val, $EX);
 						break;
 					case XC_ADD_VAR:
@@ -1258,5 +1261,5 @@
 					}
 					else {
-						$rvalue = $op1val . ' . ' . $op2val;
+						$rvalue = str($op1val) . ' . ' . str($op2val);
 					}
 					$resvar = $rvalue;
@@ -1270,5 +1273,5 @@
 				case XC_ECHO: // {{{
 					$op1val = $this->getOpVal($op1, $EX);
-					$resvar = "echo $op1val";
+					$resvar = "echo " . str($op1val);
 					break;
 					// }}}
@@ -1318,5 +1321,5 @@
 					// }}}
 				case XC_RETURN: // {{{
-					$resvar = "return " . $this->getOpVal($op1, $EX);
+					$resvar = "return " . str($this->getOpVal($op1, $EX));
 					break;
 					// }}}
@@ -1386,8 +1389,8 @@
 						$targetop = &$EX['opcodes'][$op2['opline_num']];
 						if ($opc == XC_JMPNZ_EX) {
-							$targetop['cond_true'][] = toCode($rvalue, $EX);
+							$targetop['cond_true'][] = foldToCode($rvalue, $EX);
 						}
 						else {
-							$targetop['cond_false'][] = toCode($rvalue, $EX);
+							$targetop['cond_false'][] = foldToCode($rvalue, $EX);
 						}
 						unset($targetop);
@@ -1407,5 +1410,5 @@
 					$switchValue = $this->getOpVal($op1, $EX);
 					$caseValue = $this->getOpVal($op2, $EX);
-					$resvar = $switchValue . ' == ' . $caseValue;
+					$resvar = str($switchValue) . ' == ' . str($caseValue);
 					break;
 				case XC_BRK:
@@ -1461,5 +1464,5 @@
 				case XC_END_SILENCE: // {{{
 					$EX['silence'] --;
-					$lastresvar = '@' . toCode($lastresvar, $EX);
+					$lastresvar = '@' . str($lastresvar, $EX);
 					break;
 					// }}}
@@ -1531,5 +1534,5 @@
 			$a = array_pop($EX['argstack']);
 			if (is_array($a)) {
-				array_unshift($args, toCode($a, $EX));
+				array_unshift($args, foldToCode($a, $EX));
 			}
 			else {
@@ -1646,8 +1649,8 @@
 					}
 				}
-				echo toCode($arg[0], $indent);
+				echo str($arg[0], $indent);
 			}
 			if (isset($arg[1])) {
-				echo ' = ', toCode($arg[1], $indent);
+				echo ' = ', str($arg[1], $indent);
 			}
 		}
@@ -1725,5 +1728,5 @@
 					echo $newindent;
 					echo $prefix, $name, ' = ';
-					echo toCode(value($v), $newindent);
+					echo str(value($v), $newindent);
 					echo ";\n";
 				}
@@ -1799,5 +1802,5 @@
 				if (isset($value)) {
 					echo ' = ';
-					echo toCode(value($value), $newindent);
+					echo str(value($value), $newindent);
 				}
 				echo ";\n";
