Changeset 732 for trunk/Decompiler.class.php
- Timestamp:
- 04/10/2011 11:31:17 AM (2 years ago)
- Files:
-
- 1 modified
-
trunk/Decompiler.class.php (modified) (35 diffs)
Legend:
- Unmodified
- Added
- Removed
-
trunk/Decompiler.class.php
r731 r732 9 9 } 10 10 11 function str($src, $indent = '') // {{{11 function toCode($src, $indent = '') // {{{ 12 12 { 13 13 if (is_array($indent)) { … … 15 15 } 16 16 17 /*18 $e = xcache_get_special_value($src);19 if (isset($e)) {20 if (is_array($e)) {21 $src = $e;22 }23 else {24 return $e;25 }26 }27 */28 29 if (is_array($src)) {30 exit('array str');31 $src = new Decompiler_Array($src, $indent);32 return $src->__toString();33 }34 35 17 if (is_object($src)) { 36 if (!method_exists($src, ' __toString')) {18 if (!method_exists($src, 'toCode')) { 37 19 var_dump($src); 38 exit('no __toString');39 } 40 return $src-> __toString();20 exit('no toCode'); 21 } 22 return $src->toCode($indent); 41 23 } 42 24 … … 80 62 } 81 63 82 function __toString()64 function toCode($indent) 83 65 { 84 66 return var_export($this->value, true); … … 95 77 } 96 78 97 function __toString()79 function toCode($indent) 98 80 { 99 81 return $this->src; … … 107 89 var $op2; 108 90 var $parent; 91 var $indent; 109 92 110 93 function Decompiler_Binop($parent, $op1, $opc, $op2) … … 116 99 } 117 100 118 function __toString()119 { 120 $op1 = str($this->op1);101 function toCode($indent) 102 { 103 $op1 = toCode($this->op1, $indent); 121 104 if (is_a($this->op1, 'Decompiler_Binop') && $this->op1->opc != $this->opc) { 122 105 $op1 = "($op1)"; … … 124 107 $opstr = $this->parent->binops[$this->opc]; 125 108 if ($op1 == '0' && $this->opc == XC_SUB) { 126 return $opstr . str($this->op2);127 } 128 return $op1 . ' ' . $opstr . ' ' . str($this->op2);109 return $opstr . toCode($this->op2, $indent); 110 } 111 return $op1 . ' ' . $opstr . ' ' . toCode($this->op2, $indent); 129 112 } 130 113 } … … 142 125 } 143 126 144 function __toString()127 function toCode($indent) 145 128 { 146 129 switch ($this->fetchType) { … … 168 151 } 169 152 170 function __toString()171 { 172 return $this->obj-> __toString();153 function toCode($indent) 154 { 155 return $this->obj->toCode($indent); 173 156 } 174 157 } … … 180 163 var $assign = null; 181 164 182 function __toString()165 function toCode($indent) 183 166 { 184 167 if (is_a($this->value, 'Decompiler_ListBox')) { 185 $exp = str($this->value->obj->src);168 $exp = toCode($this->value->obj->src, $indent); 186 169 } 187 170 else { 188 $exp = str($this->value);171 $exp = toCode($this->value, $indent); 189 172 } 190 173 foreach ($this->offsets as $dim) { 191 $exp .= '[' . str($dim) . ']';174 $exp .= '[' . toCode($dim, $indent) . ']'; 192 175 } 193 176 return $exp; … … 205 188 var $everLocked = false; 206 189 207 function __toString()190 function toCode($indent) 208 191 { 209 192 if (count($this->dims) == 1 && !$this->everLocked) { … … 212 195 $dim->value = $this->src; 213 196 if (!isset($dim->assign)) { 214 return str($dim);215 } 216 return str($this->dims[0]->assign) . ' = ' . str($dim);197 return toCode($dim, $indent); 198 } 199 return toCode($this->dims[0]->assign, $indent) . ' = ' . toCode($dim, $indent); 217 200 } 218 201 /* flatten dims */ … … 223 206 $assign = &$assign[$offset]; 224 207 } 225 $assign = str($dim->assign);226 } 227 return $this->toList($assigns) . ' = ' . str($this->src);208 $assign = toCode($dim->assign, $indent); 209 } 210 return $this->toList($assigns) . ' = ' . toCode($this->src, $indent); 228 211 } 229 212 … … 260 243 class Decompiler_Array extends Decompiler_Value // {{{ 261 244 { 262 var $indent = ''; 263 264 function Decompiler_Array($value = array(), $indent = '') 245 function Decompiler_Array($value = array()) 265 246 { 266 247 $this->value = $value; 267 $this->indent = $indent; 268 } 269 270 function __toString() 248 } 249 250 function toCode($indent) 271 251 { 272 252 $exp = "array("; 273 $indent = $ this->indent . INDENT;253 $indent = $indent . INDENT; 274 254 $assoclen = 0; 275 255 $multiline = 0; … … 282 262 } 283 263 } 284 if (is_array(value($v))) { 264 $spec = xcache_get_special_value($v); 265 if (is_array(isset($spec) ? $spec : $v)) { 285 266 $multiline ++; 286 267 } … … 315 296 } 316 297 317 $exp .= str(value($v), $subindent);298 $exp .= toCode(value($v), $subindent); 318 299 319 300 $i ++; 320 301 } 321 302 if ($multiline) { 322 $exp .= " $indent);";303 $exp .= "\n$indent)"; 323 304 } 324 305 else { … … 333 314 var $iskey; 334 315 335 function __toString()316 function toCode($indent) 336 317 { 337 318 return 'foreach (' . ''; … … 417 398 $curticks = $toticks; 418 399 } 419 echo $indent, str($op['php']), ";\n";400 echo $indent, toCode($op['php'], $indent), ";\n"; 420 401 } 421 402 } … … 429 410 switch ($op['op_type']) { 430 411 case XC_IS_CONST: 431 return str(value($op['constant']));412 return toCode(value($op['constant']), $EX); 432 413 433 414 case XC_IS_VAR: … … 436 417 $ret = $T[$op['var']]; 437 418 if ($tostr) { 438 $ret = str($ret, $EX);419 $ret = toCode($ret, $EX); 439 420 } 440 421 if ($free) { … … 641 622 $body = ob_get_clean(); 642 623 643 $as = str($op['fe_as']);624 $as = toCode($op['fe_as'], $EX); 644 625 if (isset($op['fe_key'])) { 645 $as = str($op['fe_key']) . ' => ' . $as;646 } 647 echo "{$indent}foreach (" . str($op['fe_src']) . " as $as) {\n";626 $as = toCode($op['fe_key'], $EX) . ' => ' . $as; 627 } 628 echo "{$indent}foreach (" . toCode($op['fe_src'], $EX) . " as $as) {\n"; 648 629 echo $body; 649 630 echo "{$indent}}"; … … 869 850 } 870 851 if ($opc == XC_UNSET_VAR) { 871 $op['php'] = "unset(" . str($rvalue) . ")";852 $op['php'] = "unset(" . toCode($rvalue, $EX) . ")"; 872 853 $lastphpop = &$op; 873 854 } … … 930 911 ++ $i; 931 912 $rvalue = $this->getOpVal($opcodes[$i]['op1'], $EX); 932 $resvar = str($lvalue) . ' = ' . $rvalue;913 $resvar = toCode($lvalue, $EX) . ' = ' . $rvalue; 933 914 } 934 915 else if ($opc == XC_UNSET_DIM) { 935 $op['php'] = "unset(" . str($rvalue) . ")";916 $op['php'] = "unset(" . toCode($rvalue, $EX) . ")"; 936 917 $lastphpop = &$op; 937 918 } … … 954 935 $dim->assign = $lvalue; 955 936 if ($dim->isLast) { 956 $resvar = str($dim->value);937 $resvar = toCode($dim->value, $EX); 957 938 } 958 939 unset($dim); 959 940 break; 960 941 } 961 $resvar = "$lvalue = " . str($rvalue, $EX);942 $resvar = "$lvalue = " . toCode($rvalue, $EX); 962 943 break; 963 944 // }}} … … 966 947 $rvalue = $this->getOpVal($op2, $EX, false); 967 948 if (is_a($rvalue, 'Decompiler_Fetch')) { 968 $src = str($rvalue->src);949 $src = toCode($rvalue->src, $EX); 969 950 if (substr($src, 1, -1) == substr($lvalue, 1)) { 970 951 switch ($rvalue->fetchType) { … … 980 961 $var = $statics[$name]; 981 962 $resvar .= ' = '; 982 $resvar .= str(value($var), $EX);963 $resvar .= toCode(value($var), $EX); 983 964 } 984 965 unset($statics); … … 989 970 } 990 971 // TODO: PHP_6 global 991 $rvalue = str($rvalue);972 $rvalue = toCode($rvalue, $EX); 992 973 $resvar = "$lvalue = &$rvalue"; 993 974 break; … … 1202 1183 switch ($opc) { 1203 1184 case XC_ADD_CHAR: 1204 $op2val = str(chr($op2val), $EX);1185 $op2val = toCode(chr($op2val), $EX); 1205 1186 break; 1206 1187 case XC_ADD_STRING: 1207 $op2val = str($op2val, $EX);1188 $op2val = toCode($op2val, $EX); 1208 1189 break; 1209 1190 case XC_ADD_VAR: … … 1345 1326 $targetop = &$EX['opcodes'][$op2['opline_num']]; 1346 1327 if ($opc == XC_JMPNZ_EX) { 1347 $targetop['cond_true'][] = str($rvalue);1328 $targetop['cond_true'][] = toCode($rvalue, $EX); 1348 1329 } 1349 1330 else { 1350 $targetop['cond_false'][] = str($rvalue);1331 $targetop['cond_false'][] = toCode($rvalue, $EX); 1351 1332 } 1352 1333 unset($targetop); … … 1416 1397 case XC_END_SILENCE: // {{{ 1417 1398 $EX['silence'] --; 1418 $lastresvar = '@' . str($lastresvar);1399 $lastresvar = '@' . toCode($lastresvar, $EX); 1419 1400 break; 1420 1401 // }}} … … 1486 1467 $a = array_pop($EX['argstack']); 1487 1468 if (is_array($a)) { 1488 array_unshift($args, str($a, $EX));1469 array_unshift($args, toCode($a, $EX)); 1489 1470 } 1490 1471 else { … … 1543 1524 function dargs(&$EX, $indent) // {{{ 1544 1525 { 1545 $EX['indent'] = $indent;1546 1526 $op_array = &$EX['op_array']; 1547 1527 … … 1602 1582 } 1603 1583 $arg = $EX['recvs'][$i + 1]; 1604 echo str($arg[0]);1584 echo toCode($arg[0], $indent); 1605 1585 if (isset($arg[1])) { 1606 echo ' = ', str($arg[1]);1586 echo ' = ', toCode($arg[1], $indent); 1607 1587 } 1608 1588 } … … 1681 1661 echo $newindent; 1682 1662 echo $prefix, $name, ' = '; 1683 echo str(value($v), $EX);1663 echo toCode(value($v), $newindent); 1684 1664 echo ";\n"; 1685 1665 } … … 1755 1735 if (isset($value)) { 1756 1736 echo ' = '; 1757 echo str(value($value));1737 echo toCode(value($value), $newindent); 1758 1738 } 1759 1739 echo ";\n";

