Index: /trunk/Decompiler.class.php
===================================================================
--- /trunk/Decompiler.class.php	(revision 799)
+++ /trunk/Decompiler.class.php	(revision 800)
@@ -555,10 +555,10 @@
 	}
 	// }}}
-	function outputPhp(&$EX, $opline, $last, $indent) // {{{
+	function outputPhp(&$EX, $range, $indent) // {{{
 	{
 		$needBlankline = isset($EX['lastBlock']);
 		$origindent = $indent;
 		$curticks = 0;
-		for ($i = $opline; $i <= $last; $i ++) {
+		for ($i = $range[0]; $i <= $range[1]; $i ++) {
 			$op = $EX['opcodes'][$i];
 			if (isset($op['gofrom'])) {
@@ -699,9 +699,9 @@
 	}
 	// }}}
-	function decompileBasicBlock(&$EX, $first, $last, $indent) // {{{
-	{
-		$this->dasmBasicBlock($EX, $first, $last);
-		// $this->dumpRange($EX, $first, $last, $indent);
-		$this->outputPhp($EX, $first, $last, $indent);
+	function decompileBasicBlock(&$EX, $range, $indent) // {{{
+	{
+		$this->dasmBasicBlock($EX, $range);
+		// $this->dumpRange($EX, $range, $indent);
+		$this->outputPhp($EX, $range, $indent);
 	}
 	// }}}
@@ -732,31 +732,29 @@
 	}
 	// }}}
-	function decompileComplexBlock(&$EX, $first, $last, $indent) // {{{
+	function decompileComplexBlock(&$EX, $range, $indent) // {{{
 	{
 		$T = &$EX['Ts'];
 		$opcodes = &$EX['opcodes'];
 
-		$firstOp = &$opcodes[$first];
-		$lastOp = &$opcodes[$last];
+		$firstOp = &$opcodes[$range[0]];
+		$lastOp = &$opcodes[$range[1]];
 
 		// {{{ ?: excludign JMP_SET
 		if ($firstOp['opcode'] == XC_JMPZ && !empty($firstOp['jmpouts'])
-		 && $last >= $first + 3
+		 && $range[1] >= $range[0] + 3
 		 && $opcodes[$firstOp['jmpouts'][0] - 2]['opcode'] == XC_QM_ASSIGN
-		 && $opcodes[$firstOp['jmpouts'][0] - 1]['opcode'] == XC_JMP && $opcodes[$firstOp['jmpouts'][0] - 1]['jmpouts'][0] == $last + 1
+		 && $opcodes[$firstOp['jmpouts'][0] - 1]['opcode'] == XC_JMP && $opcodes[$firstOp['jmpouts'][0] - 1]['jmpouts'][0] == $range[1] + 1
 		 && $lastOp['opcode'] == XC_QM_ASSIGN
 		) {
-			$trueFirst = $first + 1;
-			$trueLast = $firstOp['jmpouts'][0] - 2;
-			$falseFirst = $firstOp['jmpouts'][0];
-			$falseLast = $last;
-			$this->removeJmpInfo($EX, $first);
+			$trueRange = array($range[0] + 1, $firstOp['jmpouts'][0] - 2);
+			$falseRange = array($firstOp['jmpouts'][0], $range[1]);
+			$this->removeJmpInfo($EX, $range[0]);
 
 			$condition = $this->getOpVal($firstOp['op1'], $EX);
-			$this->recognizeAndDecompileClosedBlocks($EX, $trueFirst, $trueLast, $indent . INDENT);
-			$trueValue = $this->getOpVal($opcodes[$trueLast]['op1'], $EX, false, true);
-			$this->recognizeAndDecompileClosedBlocks($EX, $falseFirst, $falseLast, $indent . INDENT);
-			$falseValue = $this->getOpVal($opcodes[$falseLast]['op1'], $EX, false, true);
-			$T[$opcodes[$trueLast]['result']['var']] = new Decompiler_TriOp($condition, $trueValue, $falseValue);
+			$this->recognizeAndDecompileClosedBlocks($EX, $trueRange, $indent . INDENT);
+			$trueValue = $this->getOpVal($opcodes[$trueRange[1]]['op1'], $EX, false, true);
+			$this->recognizeAndDecompileClosedBlocks($EX, $falseRange, $indent . INDENT);
+			$falseValue = $this->getOpVal($opcodes[$falseRange[1]]['op1'], $EX, false, true);
+			$T[$opcodes[$trueRange[1]]['result']['var']] = new Decompiler_TriOp($condition, $trueValue, $falseValue);
 			return false;
 		}
@@ -767,10 +765,9 @@
 			$catchFirst = $firstOp['jmpins'][0];
 
-			$tryFirst = $first;
-			$tryLast = $catchFirst - 1;
+			$tryRange = array($range[0], $catchFirst - 1);
 
 			// search for XC_CATCH
 			$this->removeJmpInfo($EX, $catchFirst);
-			for ($i = $catchFirst; $i <= $last; ) {
+			for ($i = $catchFirst; $i <= $range[1]; ) {
 				if ($opcodes[$i]['opcode'] == XC_CATCH) {
 					$catchOpLine = $i;
@@ -792,16 +789,16 @@
 			}
 
-			if ($opcodes[$tryLast]['opcode'] == XC_JMP) {
-				--$tryLast;
+			if ($opcodes[$tryRange[1]]['opcode'] == XC_JMP) {
+				--$tryRange[1];
 			}
 
 			$this->beginComplexBlock($EX);
 			echo $indent, "try {", PHP_EOL;
-			$this->recognizeAndDecompileClosedBlocks($EX, $tryFirst, $tryLast, $indent . INDENT);
+			$this->recognizeAndDecompileClosedBlocks($EX, $tryRange, $indent . INDENT);
 			echo $indent, '}', PHP_EOL;
 			foreach ($catchBlocks as $catchFirst => $catchInfo) {
 				list($catchOpLine, $catchBodyLast) = $catchInfo;
 				$catchBodyFirst = $catchOpLine + 1;
-				$this->recognizeAndDecompileClosedBlocks($EX, $catchFirst, $catchOpLine, $indent);
+				$this->recognizeAndDecompileClosedBlocks($EX, array($catchFirst, $catchOpLine), $indent);
 				$catchOp = &$opcodes[$catchOpLine];
 				echo $indent, 'catch (', str($this->getOpVal($catchOp['op1'], $EX)), ' ', str($this->getOpVal($catchOp['op2'], $EX)), ") {", PHP_EOL;
@@ -809,5 +806,5 @@
 
 				$EX['lastBlock'] = null;
-				$this->recognizeAndDecompileClosedBlocks($EX, $catchBodyFirst, $catchBodyLast, $indent . INDENT);
+				$this->recognizeAndDecompileClosedBlocks($EX, array($catchBodyFirst, $catchBodyLast), $indent . INDENT);
 				echo $indent, '}', PHP_EOL;
 			}
@@ -835,5 +832,5 @@
 			$caseDefault = null;
 			$caseOp = null;
-			for ($i = $first; $i <= $last; ) {
+			for ($i = $range[0]; $i <= $range[1]; ) {
 				$op = $opcodes[$i];
 				if ($op['opcode'] == XC_CASE) {
@@ -907,5 +904,5 @@
 				}
 
-				$this->recognizeAndDecompileClosedBlocks($EX, $caseFirst, $caseLast, $indent . INDENT);
+				$this->recognizeAndDecompileClosedBlocks($EX, array($caseFirst, $caseLast), $indent . INDENT);
 				$caseIsOut = true;
 			}
@@ -918,10 +915,10 @@
 		// {{{ do/while
 		if ($lastOp['opcode'] == XC_JMPNZ && !empty($lastOp['jmpouts'])
-		 && $lastOp['jmpouts'][0] == $first) {
-			$this->removeJmpInfo($EX, $last);
+		 && $lastOp['jmpouts'][0] == $range[0]) {
+			$this->removeJmpInfo($EX, $range[1]);
 			$this->beginComplexBlock($EX);
 
 			echo $indent, "do {", PHP_EOL;
-			$this->recognizeAndDecompileClosedBlocks($EX, $first, $last, $indent . INDENT);
+			$this->recognizeAndDecompileClosedBlocks($EX, $range, $indent . INDENT);
 			echo $indent, "} while (", str($this->getOpVal($lastOp['op1'], $EX)), ');', PHP_EOL;
 
@@ -934,5 +931,5 @@
 		$firstJmp = null;
 		$firstJmpOp = null;
-		for ($i = $first; $i <= $last; ++$i) {
+		for ($i = $range[0]; $i <= $range[1]; ++$i) {
 			if (!empty($opcodes[$i]['jmpouts'])) {
 				$firstJmp = $i;
@@ -946,13 +943,13 @@
 		if (isset($firstJmpOp)
 		 && $firstJmpOp['opcode'] == XC_JMPZ
-		 && $firstJmpOp['jmpouts'][0] > $last
+		 && $firstJmpOp['jmpouts'][0] > $range[1]
 		 && $lastOp['opcode'] == XC_JMP && !empty($lastOp['jmpouts'])
-		 && $lastOp['jmpouts'][0] == $first) {
+		 && $lastOp['jmpouts'][0] == $range[0]) {
 			$this->removeJmpInfo($EX, $firstJmp);
-			$this->removeJmpInfo($EX, $last);
+			$this->removeJmpInfo($EX, $range[1]);
 			$this->beginComplexBlock($EX);
 
 			ob_start();
-			$this->recognizeAndDecompileClosedBlocks($EX, $first, $last, $indent . INDENT);
+			$this->recognizeAndDecompileClosedBlocks($EX, $range, $indent . INDENT);
 			$body = ob_get_clean();
 
@@ -968,13 +965,13 @@
 		if (isset($firstJmpOp)
 		 && $firstJmpOp['opcode'] == XC_FE_FETCH
-		 && $firstJmpOp['jmpouts'][0] > $last
+		 && $firstJmpOp['jmpouts'][0] > $range[1]
 		 && $lastOp['opcode'] == XC_JMP && !empty($lastOp['jmpouts'])
 		 && $lastOp['jmpouts'][0] == $firstJmp) {
 			$this->removeJmpInfo($EX, $firstJmp);
-			$this->removeJmpInfo($EX, $last);
+			$this->removeJmpInfo($EX, $range[1]);
 			$this->beginComplexBlock($EX);
 
 			ob_start();
-			$this->recognizeAndDecompileClosedBlocks($EX, $first, $last, $indent . INDENT);
+			$this->recognizeAndDecompileClosedBlocks($EX, $range, $indent . INDENT);
 			$body = ob_get_clean();
 
@@ -993,13 +990,13 @@
 		// }}}
 
-		$this->decompileBasicBlock($EX, $first, $last, $indent);
+		$this->decompileBasicBlock($EX, $range, $indent);
 	}
 	// }}}
-	function recognizeAndDecompileClosedBlocks(&$EX, $first, $last, $indent) // {{{ decompile in a tree way
+	function recognizeAndDecompileClosedBlocks(&$EX, $range, $indent) // {{{ decompile in a tree way
 	{
 		$opcodes = &$EX['opcodes'];
 
-		$starti = $first;
-		for ($i = $starti; $i <= $last; ) {
+		$starti = $range[0];
+		for ($i = $starti; $i <= $range[1]; ) {
 			if (!empty($opcodes[$i]['jmpins']) || !empty($opcodes[$i]['jmpouts'])) {
 				$blockFirst = $i;
@@ -1011,5 +1008,5 @@
 						// care about jumping from blocks behind, not before
 						foreach ($op['jmpins'] as $oplineNumber) {
-							if ($oplineNumber <= $last && $blockLast < $oplineNumber) {
+							if ($oplineNumber <= $range[1] && $blockLast < $oplineNumber) {
 								$blockLast = $oplineNumber;
 							}
@@ -1021,13 +1018,13 @@
 					++$j;
 				} while ($j <= $blockLast);
-				if (!assert('$blockLast <= $last')) {
-					var_dump($blockLast, $last);
+				if (!assert('$blockLast <= $range[1]')) {
+					var_dump($blockLast, $range[1]);
 				}
 
 				if ($blockLast >= $blockFirst) {
 					if ($blockFirst > $starti) {
-						$this->decompileBasicBlock($EX, $starti, $blockFirst - 1, $indent);
-					}
-					if ($this->decompileComplexBlock($EX, $blockFirst, $blockLast, $indent) === false) {
+						$this->decompileBasicBlock($EX, array($starti, $blockFirst - 1), $indent);
+					}
+					if ($this->decompileComplexBlock($EX, array($blockFirst, $blockLast), $indent) === false) {
 						if ($EX['lastBlock'] == 'complex') {
 							echo PHP_EOL;
@@ -1046,6 +1043,6 @@
 			}
 		}
-		if ($starti <= $last) {
-			$this->decompileBasicBlock($EX, $starti, $last, $indent);
+		if ($starti <= $range[1]) {
+			$this->decompileBasicBlock($EX, array($starti, $range[1]), $indent);
 		}
 	}
@@ -1161,4 +1158,5 @@
 		$EX['op_array'] = &$op_array;
 		$EX['opcodes'] = &$opcodes;
+		$EX['range'] = array(0, count($opcodes) - 1);
 		// func call
 		$EX['object'] = null;
@@ -1167,5 +1165,4 @@
 		$EX['argstack'] = array();
 		$EX['arg_types_stack'] = array();
-		$EX['last'] = count($opcodes) - 1;
 		$EX['silence'] = 0;
 		$EX['recvs'] = array();
@@ -1173,27 +1170,24 @@
 		$EX['lastBlock'] = null;
 
-		$first = 0;
-		$last = count($opcodes) - 1;
-
 		/* dump whole array
 		$this->keepTs = true;
-		$this->dasmBasicBlock($EX, $first, $last);
-		for ($i = $first; $i <= $last; ++$i) {
+		$this->dasmBasicBlock($EX, $range);
+		for ($i = $range[0]; $i <= $range[1]; ++$i) {
 			echo $i, "\t", $this->dumpop($opcodes[$i], $EX);
 		}
 		// */
 		// decompile in a tree way
-		$this->recognizeAndDecompileClosedBlocks($EX, $first, $last, $EX['indent']);
+		$this->recognizeAndDecompileClosedBlocks($EX, $EX['range'], $EX['indent']);
 		return $EX;
 	}
 	// }}}
-	function outputCode(&$EX, $opline, $last, $indent, $loop = false) // {{{
-	{
-		$op = &$EX['opcodes'][$opline];
-		$next = $EX['nextbbs'][$opline];
+	function outputCode(&$EX, $range, $indent, $loop = false) // {{{
+	{
+		$op = &$EX['opcodes'][$range[0]];
+		$next = $EX['nextbbs'][$range[0]];
 
 		$end = $next - 1;
-		if ($end > $last) {
-			$end = $last;
+		if ($end > $range[1]) {
+			$end = $range[1];
 		}
 
@@ -1204,6 +1198,6 @@
 			// echo ";;;\n";
 		}
-		$this->dasmBasicBlock($EX, $opline, $end);
-		$this->outputPhp($EX, $opline, $end, $indent);
+		$this->dasmBasicBlock($EX, array($opline, $end));
+		$this->outputPhp($EX, array($opline, $end), $indent);
 		// jmpout op
 		$op = &$EX['opcodes'][$end];
@@ -1214,5 +1208,5 @@
 
 		if (isset($EX['opcodes'][$next])) {
-			if (isset($last) && $next > $last) {
+			if (isset($range[1]) && $next > $range[1]) {
 				$next = null;
 			}
@@ -1232,7 +1226,7 @@
 						$cond = $op['cond'];
 						echo "{$indent}if ($cond) {\n";
-						$this->outputCode($EX, $next, $last, INDENT . $indent);
+						$this->outputCode($EX, $next, $range[1], INDENT . $indent);
 						echo "$indent}\n";
-						$this->outputCode($EX, $target, $last, $indent);
+						$this->outputCode($EX, $target, $range[1], $indent);
 						return;
 					}
@@ -1284,5 +1278,5 @@
 				$EX['Ts'][$var] = '(' . $fromop['and_or'] . " $opstr " . $EX['Ts'][$var] . ')';
 			}
-			#$this->outputCode($EX, $next, $last, $indent);
+			#$this->outputCode($EX, $next, $range[1], $indent);
 			#return;
 		}
@@ -1299,11 +1293,12 @@
 		}
 
+		$nextRange = array($next, $range[1]);
 		if ($loop) {
-			return array($next, $last);
-		}
-		$this->outputCode($EX, $next, $last, $indent);
+			return $nextRange;
+		}
+		$this->outputCode($EX, $nextRange, $indent);
 	}
 	// }}}
-	function dasmBasicBlock(&$EX, $opline, $last) // {{{
+	function dasmBasicBlock(&$EX, $range) // {{{
 	{
 		$T = &$EX['Ts'];
@@ -1311,5 +1306,5 @@
 		$lastphpop = null;
 
-		for ($i = $opline; $i <= $last; $i ++) {
+		for ($i = $range[0]; $i <= $range[1]; $i ++) {
 			// {{{ prepair
 			$op = &$opcodes[$i];
@@ -1802,10 +1797,10 @@
 
 					for (;;) {
-						if ($i + 1 <= $last
+						if ($i + 1 <= $range[1]
 						 && $opcodes[$i + 1]['opcode'] == XC_ADD_INTERFACE
 						 && $opcodes[$i + 1]['op1']['var'] == $res['var']) {
 							// continue
 						}
-						else if ($i + 2 <= $last
+						else if ($i + 2 <= $range[1]
 						 && $opcodes[$i + 2]['opcode'] == XC_ADD_INTERFACE
 						 && $opcodes[$i + 2]['op1']['var'] == $res['var']
@@ -2230,7 +2225,7 @@
 	}
 	// }}}
-	function dumpRange(&$EX, $first, $last, $indent = '') // {{{
-	{
-		for ($i = $first; $i <= $last; ++$i) {
+	function dumpRange(&$EX, $range, $indent = '') // {{{
+	{
+		for ($i = $range[0]; $i <= $range[1]; ++$i) {
 			echo $indent, $i, "\t"; $this->dumpop($EX['opcodes'][$i], $EX);
 		}
