summaryrefslogtreecommitdiff
path: root/devel
diff options
context:
space:
mode:
authorXuefer <xuefer@gmail.com>2013-11-06 15:45:19 +0000
committerXuefer <xuefer@gmail.com>2013-11-06 15:45:19 +0000
commite3f86745b07413f21573cc2404f2faf073d4718f (patch)
tree10e3d20e5c1ed20cea3b7a1981beee8c77398f8b /devel
parent9563ceb3c169ca13cbca6186c46e63e267f210f4 (diff)
downloadxcache-e3f86745b07413f21573cc2404f2faf073d4718f.tar.gz
xcache-e3f86745b07413f21573cc2404f2faf073d4718f.zip
make sample work for all beside decompiler
git-svn-id: svn://svn.lighttpd.net/xcache/trunk@1441 c26eb9a1-5813-0410-bd6c-c2e55f420ca7
Diffstat (limited to 'devel')
-rwxr-xr-xdevel/run52
-rw-r--r--devel/sample.cpp.php670
2 files changed, 697 insertions, 25 deletions
diff --git a/devel/run b/devel/run
index 1942380..b50ef2e 100755
--- a/devel/run
+++ b/devel/run
@@ -129,7 +129,7 @@ hiecho "Loading config devel/run.cfg"
PHPSDIR=${PHPSDIR:-$HOME/test}
if [[ $# -eq 0 ]]; then
- set -- $action "${args[@]}"
+ set -- "${args[@]}"
fi
basename=$(basename $(pwd))
@@ -233,31 +233,15 @@ run() {
# }}}1
if [[ -z $1 ]]; then
- set -- devel.php
+ set -- devel/sample.cpp.php
fi
cmd=()
+ phpApp=()
tracer=()
# run utils {{{1
case "$1" in
- dc)
- shift
- case "$1" in
- *.cpp.php)
- < "$1" \
- sed -r -e 's#__#____#g' \
- | cpp -C -P -traditional-cpp -DPHP_VERSION=$phpVersion \
- | 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)
shift
lastResult=$(ls php_test_results_*.txt | LANG=C sort | tail -n1)
@@ -318,10 +302,15 @@ run() {
;;
*)
case "$1" in
+ dc)
+ shift
+ cmd=(./php-cli -c devel.ini)
+ phpApp=(./bin/phpdc.phpr)
+ ;;
dop)
shift
cmd=(./php-cli -c devel.ini)
- set -- ./bin/phpdop.phpr "$@"
+ phpApp=(./bin/phpdop.phpr)
;;
fcgi)
shift
@@ -341,22 +330,35 @@ run() {
"${cmd[@]}" -v || true
esac
+ # hack sample.cpp.php {{{1
+ case "$1" in
+ *.cpp.php)
+ < "$1" \
+ sed -r -e 's#__#____#g' \
+ | cpp -C -P -traditional-cpp -DPHP_VERSION=$phpVersion \
+ | sed -r -e 's#^ +##g' -e 's#\t +#\t#g' -e 's#____#__#g' > devel.php || exit $?
+ shift
+ set -- devel.php "$@"
+ ;;
+ esac
+
# run {{{1
- commandLine=("${tracer[@]}" "${cmd[@]}" "$@")
+ set -- "${tracer[@]}" "${cmd[@]}" "${phpApp[@]}" "$@"
case "${cmd[0]}" in
*php-fpm*)
stopfpm
- hiecho Starting fpm "${commandLine[@]}" ...
- "${commandLine[@]}"
+ hiecho Starting fpm "$@" ...
+ "$@" | tee output.php
echo -n "Ctrl-C to stop"
trap cleanfpm SIGINT SIGTERM exit
cat > /dev/null || true
stopfpm
+ return
;;
*)
- hiecho "${commandLine[@]}"
- "${commandLine[@]}"
+ hiecho "$@"
+ "$@" | tee output.php
;;
esac
# }}}
diff --git a/devel/sample.cpp.php b/devel/sample.cpp.php
new file mode 100644
index 0000000..1fd29d4
--- /dev/null
+++ b/devel/sample.cpp.php
@@ -0,0 +1,670 @@
+<?php
+#if PHP_VERSION >= 500
+# define PublicMethod public
+#else
+# define ClassName 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
+
+namespace ns;
+#define _Exception \Exception
+#endif
+
+abstract class ClassName
+{
+#if PHP_VERSION >= 500
+ const CONST_VALUE = 'A constant value';
+
+ /** doc */
+ static public $static = array(
+ 0 => array('array'),
+ 1 => 'str',
+ CONST_VALUE => CONST_VALUE
+ );
+ static public $classProp;
+ static public $static_const1 = CONST_VALUE;
+ static public $static_const2 = self::CONST_VALUE;
+ static public $static_const3 = ClassName::CONST_VALUE;
+ static public $static_const4 = array(CONST_VALUE => 'test');
+ static public $static_const5 = array(self::CONST_VALUE => 'test');
+ static public $static_const6 = array(ClassName::CONST_VALUE => 'test');
+ static public $static_const7 = array('test' => CONST_VALUE);
+ static public $static_const8 = array('test' => self::CONST_VALUE);
+ static public $static_const9 = array('test' => ClassName::CONST_VALUE);
+ static public $static_const10 = array(CONST_VALUE => CONST_VALUE);
+ static public $static_const11 = array(self::CONST_VALUE => self::CONST_VALUE);
+ static public $static_const12 = array(ClassName::CONST_VALUE => ClassName::CONST_VALUE);
+ /** doc */
+ static public $public_static = array(2, 'str');
+ /** doc */
+ static private $private_static = array(2, 'str');
+ static private $private_static2 = array(self::CONST_VALUE => self::CONST_VALUE);
+ /** doc */
+ static protected $protected_static = array(2, 'str');
+ static protected $protected_static2 = array(self::CONST_VALUE => self::CONST_VALUE);
+ /** doc */
+ public $property = array(
+ array('array'),
+ 'str'
+ );
+ /** doc */
+ public $public_property = array(2, 'str');
+ /** doc */
+ private $private_property = array(2, 'str');
+ /** doc */
+ protected $protected_property = array(2, 'str');
+ public $array = array();
+#else
+ var $property = array(
+ array('array'),
+ 'str'
+ );
+#endif
+
+#if PHP_VERSION >= 500
+ /** doc */
+#endif
+ PublicMethod function f1()
+ {
+ }
+
+ PublicMethod function f2()
+ {
+ }
+
+ PublicMethod function __construct($arg1, $arg2)
+ {
+ static $array = array(
+ 0 => array('array'),
+ 1 => 'str',
+ CONST_VALUE => CONST_VALUE
+ );
+ static $static = 1;
+ static $str = 'string';
+ echo CONST_VALUE;
+#if PHP_VERSION >= 500
+ echo ClassName::CONST_VALUE;
+ empty(ClassName::$classProp);
+ isset(ClassName::$classProp);
+ ClassName::$classProp = 1;
+ echo ClassName::$classProp;
+#endif
+ $object = $this;
+ $object->a = 1;
+ $object->b = 2;
+ $object->prop = 'prop';
+ empty($object->objProp);
+ isset($object->objProp);
+#if PHP_VERSION >= 500
+ unset($object->objProp);
+#endif
+ $object->objProp = 1;
+ echo $object->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($object->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);
+#if PHP_VERSION >= 500
+ unset($array['index']->indexProp);
+#endif
+ $array['index'] = $object;
+ $array['index']->indexProp = 1;
+ echo $array['index']->indexProp;
+ $GLOBALS['var'] = $object;
+ 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;
+
+ if (0) {
+ ClassName::__construct();
+ }
+
+ $method = 'method';
+ ClassName::$method();
+ echo __CLASS__;
+ echo __METHOD__;
+ echo __FUNCTION__;
+ $this->method();
+#if PHP_VERSION >= 500
+ try {
+ throw new _Exception();
+ new _Exception();
+ }
+ catch (_Exception $e) {
+ }
+#endif
+
+ $a = 1;
+ $b = $c = 2;
+ $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 = $object->b++;
+ $a = ++$object->b;
+ $a = $b--;
+ $a = --$b;
+ $a = $object->b--;
+ $a = --$object->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');
+ $array = array('index' => 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);
+ $b = 1;
+ $a = isset($array['index']);
+ $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);
+#endif
+ $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 PHP_VERSION >= 530
+ echo $this::CONST_VALUE;
+ echo $object::CONST_VALUE;
+ echo CONST_VALUE;
+ $this::method();
+ $object::method();
+ $a = $b ?: $d;
+ $a = ($b ?: $d) + $c;
+ $a = f1() ?: f2();
+ $a = ClassName::f1() ?: ClassName::f2();
+ $a = ($b ? $c : $d);
+ $a = ($b ? $c : $d) + $c;
+ $a = (f1() ? f3() : f2());
+
+ if ($b ?: $d) {
+ echo 'if ($b ?: $d)';
+ }
+
+ if (($b ?: $d) + $c) {
+ echo 'if (($b ?: $d) + $c)';
+ }
+
+ if (f1() ?: f2()) {
+ echo 'if (f1() ?: f2())';
+ }
+#endif
+ }
+
+ public function __destruct()
+ {
+ }
+#if PHP_VERSION >= 500
+
+ /** doc */
+ abstract public function abstractMethod();
+#endif
+
+#if PHP_VERSION >= 500
+ /** doc */
+#endif
+ PublicMethod function method($a = NULL, $b = NULL)
+ {
+ }
+#if PHP_VERSION >= 500
+
+ /** doc */
+ protected function protectedMethod(ClassName $a, $b = array(
+ array('array')
+ ))
+ {
+ $runtimeArray = array('1');
+ $runtimeArray2 = array(
+ '1',
+ array()
+ );
+ $runtimeArray3 = array(
+ 'a' => '1',
+ 2 => array()
+ );
+ return 'protected';
+ }
+
+ /** doc */
+ private function privateMethod(ClassName $a, $b = NULL)
+ {
+ return 'private';
+ }
+#endif
+}
+#if PHP_VERSION >= 500
+
+interface IInterface
+{
+ public function nothing();
+}
+#endif
+
+function f1()
+{
+}
+
+function f2()
+{
+}
+
+function f3()
+{
+}
+
+function generator($f)
+{
+ echo __FUNCTION__;
+ echo $f;
+#if PHP_VERSION >= 550
+
+ foreach ($a as $b) {
+ yield $b;
+ }
+
+ yield f1($b);
+#endif
+}
+#if PHP_VERSION >= 500
+
+final class Child extends ClassName implements IInterface
+{
+ public function __construct()
+ {
+ parent::__construct('a', 'b');
+ }
+
+ public function __destruct()
+ {
+ parent::__destruct();
+ }
+
+ static public function __callStatic($name, $args)
+ {
+ parent::__callStatic($name, $args);
+ }
+
+ public function abstractMethod()
+ {
+ }
+
+ public function nothing()
+ {
+ }
+
+ public function __toString()
+ {
+ parent::__toString();
+ }
+
+ public function __set($name, $value)
+ {
+ }
+
+ public function __get($name)
+ {
+ }
+
+ public function __isset($name)
+ {
+ }
+
+ public function __unset($name)
+ {
+ }
+
+ public function __sleep()
+ {
+ }
+
+ public function __wakeup()
+ {
+ }
+
+ public function __clone()
+ {
+ return array();
+ }
+}
+#endif
+
+define('CONST_VALUE', 'const value');
+$late = isset($_ENV['LATE']);
+
+if ($late) {
+ class LateBindingClass
+ {
+ PublicMethod function __construct()
+ {
+ }
+ }
+
+ function lateBindingFunction($arg)
+ {
+ echo 'lateFunction';
+ return new lateBindingFunction();
+ }
+}
+
+echo "\r\n";
+echo "\r";
+echo "\n";
+var_dump(array('a' => 'a', 'b' => 'c'), 'b');
+$object = new Child();
+$className = 'ns\\Child';
+$object = new $className();
+#if PHP_VERSION >= 500
+$result = $object instanceof Child;
+$cloned = clone $object;
+#endif
+#if PHP_VERSION >= 500
+
+do {
+ try {
+ echo 'outer try 1';
+
+ try {
+ echo 'inner try';
+ }
+ catch (InnerException $e) {
+ echo $e;
+ }
+ catch (InnerException2 $e2) {
+ echo $e2;
+ }
+#if PHP_VERSION >= 550
+ finally {
+ echo 'inner finally';
+ }
+#endif
+
+ echo 'outer try 2';
+ }
+ catch (OuterException $e) {
+ echo $e;
+ }
+ catch (OuterException2 $e2) {
+ echo $e2;
+ }
+#if PHP_VERSION >= 550
+ finally {
+ echo 'outer finally';
+ }
+#endif
+} while (0);
+#endif
+
+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;
+}
+
+$array = array(
+ array('a' => 'b')
+ );
+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 ('defaultSwitch()') {
+default:
+}
+
+declare (ticks=1) {
+ echo 1;
+}
+
+$a = true;
+while ($a) {
+ declare (ticks=1) {
+ echo 2;
+ }
+ $a = false;
+}
+
+require 'require.php';
+require_once 'require_once.php';
+include 'include.php';
+include_once 'include_once.php';
+echo __FILE__;
+echo __LINE__;
+#if PHP_VERSION >= 530
+echo 'goto a';
+goto a;
+
+$i = 1;
+
+for (; $i <= 2; ++$i) {
+ goto a;
+}
+
+a:
+echo 'label a';
+echo preg_replace_callback('~-([a-z])~', function($match) {
+ return strtoupper($match[1]);
+}, 'hello-world');
+$greet = function($name) {
+ printf('Hello %s' . "\r\n" . '', $name);
+};
+$greet('World');
+$greet('PHP');
+$total = 0;
+$tax = 1;
+$callback = function($quantity, $product) use($tax, &$total) {
+ $tax = 'tax';
+ static $static1 = array(1);
+ static $static2;
+ $tax = 'tax';
+ $tax = --$tax;
+ $pricePerItem = constant('PRICE_' . strtoupper($product));
+ $total += $pricePerItem * $quantity * ($tax + 1);
+};
+#endif
+exit();
+
+?>