Changeset 6e4375d in git
- Timestamp:
- 2011-04-11T04:41:04Z (9 years ago)
- Branches:
- 3.0, 3.1, 3.2, master, trunk
- Children:
- 7cfae16
- Parents:
- 8d18908
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
Decompiler.class.php
r8d18908 r6e4375d 9 9 } 10 10 11 function str($code, $indent = '') // {{{ 12 { 13 if (is_object($code)) { 14 if (get_class($code) != 'Decompiler_Code') { 15 $code = toCode($code, $indent); 16 } 17 return $code->__toString(); 18 } 19 20 return (string) $code; 21 } 22 // }}} 11 23 function toCode($src, $indent = '') // {{{ 12 24 { … … 20 32 exit('no toCode'); 21 33 } 22 return $src->toCode($indent);23 } 24 25 return $src;34 return new Decompiler_Code($src->toCode($indent)); 35 } 36 37 return new Decompiler_Code($src); 26 38 } 27 39 // }}} … … 37 49 } 38 50 39 if ( $value instanceof Decompiler_Object) {51 if (is_a($value, 'Decompiler_Object')) { 40 52 // use as is 41 53 } 42 54 else if (is_array($value)) { 43 $value = new Decompiler_ Array($value);55 $value = new Decompiler_ConstArray($value); 44 56 } 45 57 else { … … 78 90 79 91 function toCode($indent) 92 { 93 return $this; 94 } 95 96 function __toString() 80 97 { 81 98 return $this->src; … … 243 260 class Decompiler_Array extends Decompiler_Value // {{{ 244 261 { 245 function Decompiler_Array($value = array()) 246 { 247 $this->value = $value; 262 // emenets 263 function Decompiler_Array() 264 { 265 $this->value = array(); 248 266 } 249 267 250 268 function toCode($indent) 251 269 { 270 $subindent = $indent . INDENT; 271 272 $elementsCode = array(); 273 $index = 0; 274 foreach ($this->value as $element) { 275 list($key, $value) = $element; 276 if (!isset($key)) { 277 $key = $index++; 278 } 279 $elementsCode[] = array(str($key, $subindent), str($value, $subindent), $key, $value); 280 } 281 252 282 $exp = "array("; 253 283 $indent = $indent . INDENT; … … 255 285 $multiline = 0; 256 286 $i = 0; 257 foreach ($this->value as $k => $v) { 258 if ($i !== $k) { 287 foreach ($elementsCode as $element) { 288 list($keyCode, $valueCode) = $element; 289 if ((string) $i !== $keyCode) { 259 290 $assocWidth = 1; 291 break; 260 292 } 261 293 ++$i; 262 294 } 263 foreach ($this->value as $k => $v) { 295 foreach ($elementsCode as $element) { 296 list($keyCode, $valueCode, $key, $value) = $element; 264 297 if ($assocWidth) { 265 $len = strlen($k );298 $len = strlen($keyCode); 266 299 if ($assocWidth < $len) { 267 300 $assocWidth = $len; 268 301 } 269 302 } 270 $spec = xcache_get_special_value($v); 271 if (is_array(isset($spec) ? $spec : $v)) { 303 if (is_array($value) || is_a($value, 'Decompiler_Array')) { 272 304 $multiline ++; 273 305 } 274 306 } 275 if ($assocWidth) {276 $assocWidth += 2;277 }278 307 279 308 $i = 0; 280 $subindent = $indent . INDENT;281 foreach ($this->value as $k => $v) {309 foreach ($elementsCode as $element) { 310 list($keyCode, $value) = $element; 282 311 if ($multiline) { 283 312 if ($i) { … … 293 322 } 294 323 295 $k = var_export($k, true);296 324 if ($assocWidth) { 297 325 if ($multiline) { 298 $exp .= sprintf("% {$assocWidth}s => ", $k);326 $exp .= sprintf("%-{$assocWidth}s => ", $keyCode); 299 327 } 300 328 else { 301 $exp .= $k . ' => ';302 } 303 } 304 305 $exp .= toCode(value($v), $subindent);329 $exp .= $keyCode . ' => '; 330 } 331 } 332 333 $exp .= $value; 306 334 307 335 $i ++; … … 314 342 } 315 343 return $exp; 344 } 345 } 346 // }}} 347 class Decompiler_ConstArray extends Decompiler_Array // {{{ 348 { 349 function Decompiler_ConstArray($array) 350 { 351 $elements = array(); 352 foreach ($array as $key => $value) { 353 $elements[] = array(value($key), value($value)); 354 } 355 $this->value = $elements; 316 356 } 317 357 } … … 1239 1279 1240 1280 if ($opc == XC_ADD_ARRAY_ELEMENT) { 1241 $ offset= $this->getOpVal($op2, $EX);1242 if (isset($ offset)) {1243 $T[$res['var']]->value[ $offset] = $rvalue;1281 $assoc = $this->getOpVal($op2, $EX); 1282 if (isset($assoc)) { 1283 $T[$res['var']]->value[] = array($assoc, $rvalue); 1244 1284 } 1245 1285 else { 1246 $T[$res['var']]->value[] = $rvalue;1286 $T[$res['var']]->value[] = array(null, $rvalue); 1247 1287 } 1248 1288 } … … 1255 1295 } 1256 1296 1257 $ offset= $this->getOpVal($op2, $EX);1258 if (isset($ offset)) {1259 $resvar->value[ $offset] = $rvalue;1297 $assoc = $this->getOpVal($op2, $EX); 1298 if (isset($assoc)) { 1299 $resvar->value[] = array($assoc, $rvalue); 1260 1300 } 1261 1301 else { 1262 $resvar->value[] = $rvalue;1302 $resvar->value[] = array(null, $rvalue); 1263 1303 } 1264 1304 } … … 1373 1413 $default = null; 1374 1414 } 1375 $EX['recvs'][ $offset] = array($lvalue, $default);1415 $EX['recvs'][str($offset)] = array($lvalue, $default); 1376 1416 break; 1377 1417 case XC_POST_DEC: -
decompilesample.php
r8d18908 r6e4375d 46 46 )) 47 47 { 48 $runtimeArray = array('1'); 49 $runtimeArray2 = array( 50 '1', 51 array() 52 ); 53 $runtimeArray3 = array( 54 'a' => '1', 55 2 => array() 56 ); 48 57 return 'protected'; 49 58 } -
processor/head.m4
r369b9ea r6e4375d 141 141 #define C_RELAYLINE , __LINE__ 142 142 ') 143 static inline void xc_calc_string_n(xc_processor_t *processor, zend_uchar type, const zstr str, long size IFASSERT(`, int relayline')) {143 static inline void xc_calc_string_n(xc_processor_t *processor, zend_uchar type, const zstr const str, long size IFASSERT(`, int relayline')) { 144 144 pushdef(`__LINE__', `relayline') 145 145 int realsize = UNISW(size, (type == IS_UNICODE) ? UBYTES(size) : size); … … 163 163 /* {{{ xc_store_string_n */ 164 164 REDEF(`KIND', `store') 165 static inline zstr xc_store_string_n(xc_processor_t *processor, zend_uchar type, const zstr str, long size IFASSERT(`, int relayline')) {165 static inline zstr xc_store_string_n(xc_processor_t *processor, zend_uchar type, const zstr const str, long size IFASSERT(`, int relayline')) { 166 166 pushdef(`__LINE__', `relayline') 167 167 int realsize = UNISW(size, (type == IS_UNICODE) ? UBYTES(size) : size);
Note: See TracChangeset
for help on using the changeset viewer.