From e8600f7d4a339b17a3f7544aa8066e6533af1a91 Mon Sep 17 00:00:00 2001 From: Xuefer Date: Fri, 19 Jul 2013 05:03:07 +0000 Subject: [PATCH] devel: use cpp to generate samples for different php version git-svn-id: svn://svn.lighttpd.net/xcache/trunk@1334 c26eb9a1-5813-0410-bd6c-c2e55f420ca7 --- devel/run | 20 +- .../{sample5.php => sample.cpp.php} | 110 ++++-- mod_disassembler/sample4.php | 360 ------------------ 3 files changed, 106 insertions(+), 384 deletions(-) rename mod_disassembler/{sample5.php => sample.cpp.php} (84%) delete mode 100644 mod_disassembler/sample4.php diff --git a/devel/run b/devel/run index 81d3915..1e56817 100755 --- a/devel/run +++ b/devel/run @@ -241,7 +241,17 @@ run() { case "$1" in dc) shift - ./php-cli -c devel.ini ./bin/phpdc.phpr $@ | tee decompiled.php + case "$1" in + *.cpp.php) + cpp -C -P -traditional-cpp -DPHP_VERSION=$phpVersion $1 \ + | sed -r -e 's#^ +##g' -e 's#\t +#\t#g' -e 's#____#__#g' > sample.php || exit $? + shift + ./php-cli -c devel.ini ./bin/phpdc.phpr sample.php "$@" | tee decompiled.php + ;; + *) + ./php-cli -c devel.ini ./bin/phpdc.phpr "$@" | tee decompiled.php + ;; + esac return ;; retest) @@ -347,6 +357,14 @@ run() { } for phpbasename in "${dirs[@]}"; do + phpVersion=${phpbasename%%-*} + phpVersion=${phpVersion##php} + phpVersion=${phpVersion/./} + case "$phpVersion" in + ??) phpVersion="${phpVersion}0";; + ?) phpVersion="${phpVersion}00";; + esac + # devel actions case "$1" in prep*) shift; prep "$@"; exit;; diff --git a/mod_disassembler/sample5.php b/mod_disassembler/sample.cpp.php similarity index 84% rename from mod_disassembler/sample5.php rename to mod_disassembler/sample.cpp.php index 9d8c358..2670159 100644 --- a/mod_disassembler/sample5.php +++ b/mod_disassembler/sample.cpp.php @@ -1,11 +1,28 @@ = 500 +# define ClassClassName ClassName +# define PublicMethod public +#else +# define ClassClassName classname +# define PublicMethod +# define abstract +# define innerIf_ innerif_ +# define emptySwitch emptyswitch +# define defaultSwitch defaultswitch +#endif +#if PHP_VERSION >= 520 +#else +# define __callStatic __callstatic +# define __toString __tostring +#endif +#if PHP_VERSION >= 530 -/* >= PHP 5.3 namespace ns; -// */ +#endif -abstract class ClassName +abstract class ClassClassName { +#if PHP_VERSION >= 500 const CONST_VALUE = 'A constant value'; /** doc */ @@ -30,28 +47,44 @@ abstract class ClassName private $private_property = array(2, 'str'); /** doc */ protected $protected_property = array(2, 'str'); +#else + var $property = array( + array('array'), + 'str' + ); +#endif +#if PHP_VERSION >= 500 /** doc */ - public function __construct($a, $b) +#endif + PublicMethod function __construct($a, $b) { echo CONST_VALUE; +#if PHP_VERSION >= 500 echo ClassName::CONST_VALUE; empty(ClassName::$classProp); isset(ClassName::$classProp); unset(ClassName::$classProp); ClassName::$classProp = 1; echo ClassName::$classProp; +#endif empty($obj->objProp); isset($obj->objProp); +#if PHP_VERSION >= 500 unset($obj->objProp); +#endif $obj->objProp = 1; echo $obj->objProp; empty($this->thisProp); isset($this->thisProp); +#if PHP_VERSION >= 500 unset($this->thisProp); +#endif $this->thisProp = 1; echo $this->thisProp; +#if PHP_VERSION >= 500 unset($array['index']->valueProp); +#endif unset($obj->array['index']); unset($this->array['index']); empty($_GET['get']); @@ -71,28 +104,41 @@ abstract class ClassName echo $array['index']; empty($array['index']->indexProp); isset($array['index']->indexProp); +#if PHP_VERSION >= 500 unset($array['index']->indexProp); +#endif $array['index']->indexProp = 1; echo $array['index']->indexProp; empty($GLOBALS['var']->indexProp); isset($GLOBALS['var']->indexProp); +#if PHP_VERSION >= 500 unset($GLOBALS['var']->indexProp); +#endif $GLOBALS['var']->indexProp = 1; echo $GLOBALS['var']->indexProp; + ClassName::__construct(); + echo __CLASS__; + echo __METHOD__; + echo __FUNCTION__; + $this->methodCall(); +#if PHP_VERSION >= 500 + throw new Exception(); + new Exception(); +#endif } +#if PHP_VERSION >= 500 /** doc */ abstract public function abastractMethod(); +#endif +#if PHP_VERSION >= 500 /** doc */ - public function method($a = NULL, $b = NULL) - { - } - - /** doc */ - public function publicMethod(ClassName $a = NULL, $b = 2) +#endif + PublicMethod function method($a = NULL, $b = NULL) { } +#if PHP_VERSION >= 500 /** doc */ protected function protectedMethod(ClassName $a, $b = array( @@ -116,36 +162,36 @@ abstract class ClassName { return 'private'; } +#endif } +#if PHP_VERSION >= 500 interface IInterface { public function nothing(); } +#endif function f1($f) { echo __FUNCTION__; echo $f; +#if PHP_VERSION > 550 foreach ($a as $b) { yield($b); } yield($f); +#endif } +#if PHP_VERSION >= 500 final class Child extends ClassName implements IInterface { public function __construct() { parent::__construct(); - ClassName::__construct(); - echo __CLASS__; - echo __METHOD__; - echo __FUNCTION__; - throw new Exception(); - $this->methodCall(); } public function __destruct() @@ -193,11 +239,12 @@ final class Child extends ClassName implements IInterface return array(); } } +#endif if ($late) { class LateBindingClass { - public function __construct() + PublicMethod function __construct() { } } @@ -215,8 +262,10 @@ echo "\n"; echo str_replace(array('a' => 'a', 'b' => 'c'), 'b'); $object = new ClassName(); $object = new $className(); +#if PHP_VERSION >= 500 $result = $object instanceof ClassName; $cloned = clone $object; +#endif $a = 1; $a = $b + $c; $a = $b + 1; @@ -283,13 +332,17 @@ $a = empty($array['index']); unset($array['index']); $a = isset($object->prop); $a = empty($object->prop); +#if PHP_VERSION >= 500 unset($object->prop); +#endif $a = isset($this->prop); $a = empty($this->prop); +#if PHP_VERSION >= 500 unset($this->prop); $a = isset(ClassName::$prop); $a = empty(ClassName::$prop); unset(ClassName::$prop); +#endif $a = (int) $b; $a = (double) $b; $a = (string) $b; @@ -306,6 +359,7 @@ $a = (f1() ? f2() : f3()); ($a = $b) or $c; $a = $b && $c; $a = $b || $c; +#if PHP_VERSION >= 500 do { try { @@ -317,13 +371,24 @@ do { catch (InnerException $e) { echo $e; } +#if PHP_VERSION >= 550 + finally { + echo 'inner finally'; + } +#endif echo 'outer try 2'; } catch (OuterException $e) { echo $e; } +#if PHP_VERSION >= 550 + finally { + echo 'outer finally'; + } +#endif } while (0); +#endif if (if_()) { echo 'if'; @@ -434,7 +499,7 @@ case 'case2': switch (emptySwitch()) { } -switch (emptySwitch()) { +switch (defaultSwitch()) { default: } @@ -452,10 +517,9 @@ require 'require.php'; require_once 'require_once.php'; include 'include.php'; include_once 'include_once.php'; -echo __FILE__; -echo __LINE__; - -/* +echo ____FILE____; +echo ____LINE____; +#if PHP_VERSION >= 530 echo 'PHP 5.3+ code testing'; const CONST_VALUE = 1; echo $this::CONST_VALUE; @@ -513,7 +577,7 @@ $callback = function($quantity, $product) use($tax, &$total) { $pricePerItem = constant('PRICE_' . strtoupper($product)); $total += $pricePerItem * $quantity * ($tax + 1); }; -// */ +#endif exit(); ?> diff --git a/mod_disassembler/sample4.php b/mod_disassembler/sample4.php deleted file mode 100644 index 109c0a3..0000000 --- a/mod_disassembler/sample4.php +++ /dev/null @@ -1,360 +0,0 @@ -objProp); - isset($obj->objProp); - $obj->objProp = 1; - echo $obj->objProp; - empty($this->thisProp); - isset($this->thisProp); - $this->thisProp = 1; - echo $this->thisProp; - unset($obj->array['index']); - unset($this->array['index']); - empty($_GET['get']); - isset($_GET['get']); - unset($_GET['get']); - $_GET['get'] = 1; - echo $_GET['get']; - isset($GLOBALS['global']); - empty($GLOBALS['global']); - unset($GLOBALS['global']); - $GLOBALS['global'] = 1; - echo $GLOBALS['global']; - empty($array['index']); - isset($array['index']); - unset($array['index']); - $array['index'] = 1; - echo $array['index']; - empty($array['index']->indexProp); - isset($array['index']->indexProp); - $array['index']->indexProp = 1; - echo $array['index']->indexProp; - empty($GLOBALS['var']->indexProp); - isset($GLOBALS['var']->indexProp); - $GLOBALS['var']->indexProp = 1; - echo $GLOBALS['var']->indexProp; - } - - function method($a = NULL, $b = NULL) - { - $runtimeArray = array('1'); - $runtimeArray2 = array( - '1', - array() - ); - $runtimeArray3 = array( - 'a' => '1', - 2 => array() - ); - return 'm'; - } -} - -class child extends classname -{ - function __construct() - { - parent::__construct(); - ClassName::__construct(); - echo __CLASS__; - echo __METHOD__; - echo __FUNCTION__; - new Exception(); - $this->methodCall(); - } - - function __destruct() - { - parent::__destruct(); - functioncall(); - } - - function __tostring() - { - parent::__toString(); - } - - function __set($name, $value) - { - } - - function __get($name) - { - } - - function __isset($name) - { - } - - function __unset($name) - { - } - - function __sleep() - { - } - - function __wakeup() - { - } - - function __clone() - { - return array(); - } -} - -function f1($f) -{ - echo __FUNCTION__; - echo $f; -} - -if ($late) { - class LateBindingClass - { - function __construct() - { - } - } - - function lateBindingFunction($arg) - { - echo 'lateFunction'; - return new lateBindingFunction(); - } -} - -echo "\r\n"; -echo "\r"; -echo "\n"; -echo str_replace(array('a' => 'a', 'b' => 'c'), 'b'); -$object = new ClassName(); -$object = new $className(); -$a = 1; -$a = $b + $c; -$a = $b + 1; -$a = 1 + $b; -$a = $b - $c; -$a = $b * $c; -$a = $b / $c; -$a = $b % $c; -$a = $b . $c; -$a = $b = $c; -$a = $b & $c; -$a = $b | $c; -$a = $b ^ $c; -$a = ~$b; -$a = -$b; -$a = +$b; -$a = $b >> $c; -$a = $b >> $c; -$a = $b == $c; -$a = $b === $c; -$a = $b != $c; -$a = $b < $c; -$a = $b <= $c; -$a = $b <= $c; -$a = $b++; -$a = ++$b; -$a = $obj->b++; -$a = ++$obj->b; -$a = $b--; -$a = --$b; -$a = $obj->b--; -$a = --$obj->b; -$a = !$b; -$a = $b === $c; -$a = $b !== $c; -$a = $b << 2; -$a = $b >> 3; -$a += $b; -$a -= $b; -$a *= $b; -$a /= $b; -$a <<= $b; -$a >>= $b; -$a &= $b; -$a |= $b; -$a .= $b; -$a %= $b; -$a ^= $b; -$a = 'a' . 'b'; -$a = 'a' . 'abc'; -@f1(); -print('1'); -$a = $array['index']; -$a = $object->prop; -$a = $this->prop; -$array['index'] = 1; -$object->prop = 1; -$this->prop = 1; -$a = isset($b); -$a = empty($b); -unset($b); -$a = isset($array['index']); -$a = empty($array['index']); -unset($array['index']); -$a = isset($object->prop); -$a = empty($object->prop); -$a = isset($this->prop); -$a = empty($this->prop); -$a = (int) $b; -$a = (double) $b; -$a = (string) $b; -$a = (array) $b; -$a = (object) $b; -$a = (bool) $b; -$a = (unset) $b; -$a = (array) $b; -$a = (object) $b; -$a = ($b ? $c : $d); -$a = (f1() ? f2() : f3()); -($a = $b) xor $c; -($a = $b) and $c; -($a = $b) or $c; -$a = $b && $c; -$a = $b || $c; - -if (if_()) { - echo 'if'; - - if (innerif_()) { - echo 'if innerIf'; - } -} -else if (elseif_()) { - echo 'else if'; - - if (innerif_()) { - echo 'if innerIf'; - } -} -else { - if (innerif_()) { - echo 'if innerIf'; - } - - echo 'else'; -} - -while (false) { - echo 'while'; -} - -do { - echo 'do/while'; -} while (false); - -$i = 1; - -for (; $i < 10; ++$i) { - echo $i; - break; -} - -foreach ($array as $value) { - foreach ($value as $key => $value) { - echo $key . ' = ' . $value . "\n"; - break 2; - continue; - } -} - -switch ($normalSwitch) { -case 'case1': - echo 'case1'; - - switch ($nestedSwitch) { - case 1: - } - - break; - -case 'case2': - echo 'case2'; - break; - -default: - switch ($nestedSwitch) { - case 1: - } - - echo 'default'; - break; -} - -switch ($switchWithoutDefault) { -case 'case1': - echo 'case1'; - break; - -case 'case2': - echo 'case2'; - break; -} - -switch ($switchWithMiddleDefault) { -case 'case1': - echo 'case1'; - break; - -default: - echo 'default'; - break; - -case 'case2': - echo 'case2'; - break; -} - -switch ($switchWithInitialDefault) { -default: - echo 'default'; - break; - -case 'case1': - echo 'case1'; - break; - -case 'case2': - echo 'case2'; - break; -} - -switch (emptyswitch()) { -} - -switch (emptyswitch()) { -default: -} - -declare (ticks=1) { - echo 1; -} - -while (1) { - declare (ticks=1) { - echo 2; - } -} - -require 'require.php'; -require_once 'require_once.php'; -include 'include.php'; -include_once 'include_once.php'; -echo __FILE__; -echo __LINE__; -exit(); - -?>