Cover Parser.php as much as possible

This commit is contained in:
nikic 2011-12-07 18:17:05 +01:00
parent 80065965d3
commit 8bdb478785
16 changed files with 647 additions and 190 deletions

View File

@ -732,7 +732,7 @@ object_access:
{ $$ = Expr_PropertyFetch[$1, $3]; }
| variable_or_new_expr T_OBJECT_OPERATOR object_property '(' argument_list ')'
{ $$ = Expr_MethodCall[$1, $3, $5]; }
| object_access '(' argument_list ')' { $$ = Expr_FuncCall[$1, $3]; }
| object_access '(' argument_list ')' { $$ = Expr_FuncCall[$1, $3]; }
| object_access '[' dim_offset ']' { $$ = Expr_ArrayDimFetch[$1, $3]; }
| object_access '{' expr '}' { $$ = Expr_ArrayDimFetch[$1, $3]; }
;

View File

@ -3,11 +3,12 @@ Array definitions
<?php
array();
array(1, 2, 3);
array('a' => 'b');
array('a' => 'b', 'c');
array('a' => &$b);
array('a');
array('a', );
array('a', 'b');
array('a', &$b, 'c' => 'd', 'e' => &$f);
// short array syntax
[];
[1, 2, 3];
['a' => 'b'];
@ -21,22 +22,8 @@ array(
items: array(
0: Expr_ArrayItem(
key: null
value: Scalar_LNumber(
value: 1
)
byRef: false
)
1: Expr_ArrayItem(
key: null
value: Scalar_LNumber(
value: 2
)
byRef: false
)
2: Expr_ArrayItem(
key: null
value: Scalar_LNumber(
value: 3
value: Scalar_String(
value: a
)
byRef: false
)
@ -45,11 +32,9 @@ array(
2: Expr_Array(
items: array(
0: Expr_ArrayItem(
key: Scalar_String(
value: a
)
key: null
value: Scalar_String(
value: b
value: a
)
byRef: false
)
@ -58,18 +43,16 @@ array(
3: Expr_Array(
items: array(
0: Expr_ArrayItem(
key: Scalar_String(
value: a
)
key: null
value: Scalar_String(
value: b
value: a
)
byRef: false
)
1: Expr_ArrayItem(
key: null
value: Scalar_String(
value: c
value: b
)
byRef: false
)
@ -78,14 +61,37 @@ array(
4: Expr_Array(
items: array(
0: Expr_ArrayItem(
key: Scalar_String(
key: null
value: Scalar_String(
value: a
)
byRef: false
)
1: Expr_ArrayItem(
key: null
value: Expr_Variable(
name: b
)
byRef: true
)
2: Expr_ArrayItem(
key: Scalar_String(
value: c
)
value: Scalar_String(
value: d
)
byRef: false
)
3: Expr_ArrayItem(
key: Scalar_String(
value: e
)
value: Expr_Variable(
name: f
)
byRef: true
)
)
)
5: Expr_Array(

View File

@ -0,0 +1,24 @@
Constant fetches
-----
<?php
A;
A::B;
-----
array(
0: Expr_ConstFetch(
name: Name(
parts: array(
0: A
)
)
)
1: Expr_ClassConstFetch(
class: Name(
parts: array(
0: A
)
)
name: B
)
)

View File

@ -10,6 +10,7 @@ $$a();
$$$a();
$a['b']();
$a{'b'}();
$a->b['c']();
// array dereferencing
a()['b'];
@ -84,7 +85,22 @@ array(
args: array(
)
)
7: Expr_ArrayDimFetch(
7: Expr_FuncCall(
name: Expr_ArrayDimFetch(
var: Expr_PropertyFetch(
var: Expr_Variable(
name: a
)
name: b
)
dim: Scalar_String(
value: c
)
)
args: array(
)
)
8: Expr_ArrayDimFetch(
var: Expr_FuncCall(
name: Name(
parts: array(

View File

@ -0,0 +1,70 @@
New expression dereferencing
-----
<?php
(new A)->b;
(new A)->b();
(new A)['b'];
(new A)['b']['c'];
-----
array(
0: Expr_PropertyFetch(
var: Expr_New(
class: Name(
parts: array(
0: A
)
)
args: array(
)
)
name: b
)
1: Expr_MethodCall(
var: Expr_New(
class: Name(
parts: array(
0: A
)
)
args: array(
)
)
name: b
args: array(
)
)
2: Expr_ArrayDimFetch(
var: Expr_New(
class: Name(
parts: array(
0: A
)
)
args: array(
)
)
dim: Scalar_String(
value: b
)
)
3: Expr_ArrayDimFetch(
var: Expr_ArrayDimFetch(
var: Expr_New(
class: Name(
parts: array(
0: A
)
)
args: array(
)
)
dim: Scalar_String(
value: b
)
)
dim: Scalar_String(
value: c
)
)
)

View File

@ -0,0 +1,118 @@
Object access
-----
<?php
// property fetch variations
$a->b;
$a->b['c'];
$a->b{'c'};
// method call variations
$a->b();
$a->{'b'}();
$a->$b();
$a->$b['c']();
// array dereferencing
$a->b()['c'];
$a->b(){'c'}; // invalid PHP: drop Support?
-----
array(
0: Expr_PropertyFetch(
var: Expr_Variable(
name: a
)
name: b
)
1: Expr_ArrayDimFetch(
var: Expr_PropertyFetch(
var: Expr_Variable(
name: a
)
name: b
)
dim: Scalar_String(
value: c
)
)
2: Expr_ArrayDimFetch(
var: Expr_PropertyFetch(
var: Expr_Variable(
name: a
)
name: b
)
dim: Scalar_String(
value: c
)
)
3: Expr_MethodCall(
var: Expr_Variable(
name: a
)
name: b
args: array(
)
)
4: Expr_MethodCall(
var: Expr_Variable(
name: a
)
name: Scalar_String(
value: b
)
args: array(
)
)
5: Expr_MethodCall(
var: Expr_Variable(
name: a
)
name: Expr_Variable(
name: b
)
args: array(
)
)
6: Expr_MethodCall(
var: Expr_Variable(
name: a
)
name: Expr_ArrayDimFetch(
var: Expr_Variable(
name: b
)
dim: Scalar_String(
value: c
)
)
args: array(
)
)
7: Expr_ArrayDimFetch(
var: Expr_MethodCall(
var: Expr_Variable(
name: a
)
name: b
args: array(
)
)
dim: Scalar_String(
value: c
)
)
8: Expr_ArrayDimFetch(
var: Expr_MethodCall(
var: Expr_Variable(
name: a
)
name: b
args: array(
)
)
dim: Scalar_String(
value: c
)
)
)

View File

@ -1,74 +0,0 @@
Simple fetches (array, property, constant) and calls
-----
<?php
// simple calls
$a->b();
// simple properties
$a->b;
A::$b;
// simple array access
$a[$b];
$a{$b};
// simple constants
A;
A::B;
-----
array(
0: Expr_MethodCall(
var: Expr_Variable(
name: a
)
name: b
args: array(
)
)
1: Expr_PropertyFetch(
var: Expr_Variable(
name: a
)
name: b
)
2: Expr_StaticPropertyFetch(
class: Name(
parts: array(
0: A
)
)
name: b
)
3: Expr_ArrayDimFetch(
var: Expr_Variable(
name: a
)
dim: Expr_Variable(
name: b
)
)
4: Expr_ArrayDimFetch(
var: Expr_Variable(
name: a
)
dim: Expr_Variable(
name: b
)
)
5: Expr_ConstFetch(
name: Name(
parts: array(
0: A
)
)
)
6: Expr_ClassConstFetch(
class: Name(
parts: array(
0: A
)
)
name: B
)
)

View File

@ -0,0 +1,62 @@
Simple array access
-----
<?php
$a['b'];
$a['b']['c'];
$a[] = $b;
$a{'b'};
${$a}['b'];
-----
array(
0: Expr_ArrayDimFetch(
var: Expr_Variable(
name: a
)
dim: Scalar_String(
value: b
)
)
1: Expr_ArrayDimFetch(
var: Expr_ArrayDimFetch(
var: Expr_Variable(
name: a
)
dim: Scalar_String(
value: b
)
)
dim: Scalar_String(
value: c
)
)
2: Expr_Assign(
var: Expr_ArrayDimFetch(
var: Expr_Variable(
name: a
)
dim: null
)
expr: Expr_Variable(
name: b
)
)
3: Expr_ArrayDimFetch(
var: Expr_Variable(
name: a
)
dim: Scalar_String(
value: b
)
)
4: Expr_ArrayDimFetch(
var: Expr_Variable(
name: Expr_Variable(
name: a
)
)
dim: Scalar_String(
value: b
)
)
)

View File

@ -0,0 +1,71 @@
Static property fetches
-----
<?php
// property name variations
A::$b;
A::$$b;
A::${'b'};
// array access
A::$b['c'];
A::$b{'c'};
// class name variations can be found in staticCall.test
-----
array(
0: Expr_StaticPropertyFetch(
class: Name(
parts: array(
0: A
)
)
name: b
)
1: Expr_StaticPropertyFetch(
class: Name(
parts: array(
0: A
)
)
name: Expr_Variable(
name: b
)
)
2: Expr_StaticPropertyFetch(
class: Name(
parts: array(
0: A
)
)
name: Scalar_String(
value: b
)
)
3: Expr_ArrayDimFetch(
var: Expr_StaticPropertyFetch(
class: Name(
parts: array(
0: A
)
)
name: b
)
dim: Scalar_String(
value: c
)
)
4: Expr_ArrayDimFetch(
var: Expr_StaticPropertyFetch(
class: Name(
parts: array(
0: A
)
)
name: b
)
dim: Scalar_String(
value: c
)
)
)

View File

@ -5,8 +5,9 @@ Variable syntaxes
$a;
${'a'};
${foo()};
$$b;
$$$c;
$$a;
$$$a;
$$a['b'];
-----
array(
0: Expr_Variable(
@ -30,13 +31,23 @@ array(
)
3: Expr_Variable(
name: Expr_Variable(
name: b
name: a
)
)
4: Expr_Variable(
name: Expr_Variable(
name: Expr_Variable(
name: c
name: a
)
)
)
5: Expr_Variable(
name: Expr_ArrayDimFetch(
var: Expr_Variable(
name: a
)
dim: Scalar_String(
value: b
)
)
)

View File

@ -7,6 +7,7 @@ Encapsed strings
"$A[B]";
"$A[0]";
"$A[0x0]";
"$A[$B]";
"{$A}";
"{$A['B']}";
"${A}";
@ -71,12 +72,24 @@ array(
)
5: Scalar_Encapsed(
parts: array(
0: Expr_Variable(
name: A
0: Expr_ArrayDimFetch(
var: Expr_Variable(
name: A
)
dim: Expr_Variable(
name: B
)
)
)
)
6: Scalar_Encapsed(
parts: array(
0: Expr_Variable(
name: A
)
)
)
7: Scalar_Encapsed(
parts: array(
0: Expr_ArrayDimFetch(
var: Expr_Variable(
@ -88,14 +101,14 @@ array(
)
)
)
7: Scalar_Encapsed(
8: Scalar_Encapsed(
parts: array(
0: Expr_Variable(
name: A
)
)
)
8: Scalar_Encapsed(
9: Scalar_Encapsed(
parts: array(
0: Expr_ArrayDimFetch(
var: Expr_Variable(
@ -107,7 +120,7 @@ array(
)
)
)
9: Scalar_Encapsed(
10: Scalar_Encapsed(
parts: array(
0: Expr_Variable(
name: Expr_Variable(
@ -116,7 +129,7 @@ array(
)
)
)
10: Scalar_Encapsed(
11: Scalar_Encapsed(
parts: array(
0: A
1: Expr_Variable(
@ -125,7 +138,7 @@ array(
2: C
)
)
11: Scalar_Encapsed(
12: Scalar_Encapsed(
parts: array(
0: Expr_Variable(
name: A

View File

@ -0,0 +1,37 @@
Return and pass by ref
-----
<?php
function a(&$b) {}
function &a($b) {}
-----
array(
0: Stmt_Function(
byRef: false
params: array(
0: Param(
name: b
default: null
type: null
byRef: true
)
)
stmts: array(
)
name: a
)
1: Stmt_Function(
byRef: true
params: array(
0: Param(
name: b
default: null
type: null
byRef: false
)
)
stmts: array(
)
name: a
)
)

View File

@ -0,0 +1,138 @@
Default values (static scalar tests)
-----
<?php
function a(
$b = null,
$c = 'foo',
$d = A::B,
$f = +1,
$g = -1.0,
$h = array(),
$i = [],
$j = ['foo'],
$k = ['foo', 'bar' => 'baz']
) {}
-----
array(
0: Stmt_Function(
byRef: false
params: array(
0: Param(
name: b
default: Expr_ConstFetch(
name: Name(
parts: array(
0: null
)
)
)
type: null
byRef: false
)
1: Param(
name: c
default: Scalar_String(
value: foo
)
type: null
byRef: false
)
2: Param(
name: d
default: Expr_ClassConstFetch(
class: Name(
parts: array(
0: A
)
)
name: B
)
type: null
byRef: false
)
3: Param(
name: f
default: Expr_UnaryPlus(
expr: Scalar_LNumber(
value: 1
)
)
type: null
byRef: false
)
4: Param(
name: g
default: Expr_UnaryMinus(
expr: Scalar_DNumber(
value: 1
)
)
type: null
byRef: false
)
5: Param(
name: h
default: Expr_Array(
items: array(
)
)
type: null
byRef: false
)
6: Param(
name: i
default: Expr_Array(
items: array(
)
)
type: null
byRef: false
)
7: Param(
name: j
default: Expr_Array(
items: array(
0: Expr_ArrayItem(
key: null
value: Scalar_String(
value: foo
)
byRef: false
)
)
)
type: null
byRef: false
)
8: Param(
name: k
default: Expr_Array(
items: array(
0: Expr_ArrayItem(
key: null
value: Scalar_String(
value: foo
)
byRef: false
)
1: Expr_ArrayItem(
key: Scalar_String(
value: bar
)
value: Scalar_String(
value: baz
)
byRef: false
)
)
)
type: null
byRef: false
)
)
stmts: array(
)
name: a
)
)

View File

@ -1,73 +0,0 @@
Function parameters
-----
<?php
function a($b, &$c, array $d, A $e, $f = 'g', H &$i = 'j') {}
function &a() {}
-----
array(
0: Stmt_Function(
byRef: false
params: array(
0: Param(
name: b
default: null
type: null
byRef: false
)
1: Param(
name: c
default: null
type: null
byRef: true
)
2: Param(
name: d
default: null
type: array
byRef: false
)
3: Param(
name: e
default: null
type: Name(
parts: array(
0: A
)
)
byRef: false
)
4: Param(
name: f
default: Scalar_String(
value: g
)
type: null
byRef: false
)
5: Param(
name: i
default: Scalar_String(
value: j
)
type: Name(
parts: array(
0: H
)
)
byRef: true
)
)
stmts: array(
)
name: a
)
1: Stmt_Function(
byRef: true
params: array(
)
stmts: array(
)
name: a
)
)

View File

@ -0,0 +1,38 @@
Type hints
-----
<?php
function a($b, array $c, D $e) {}
-----
array(
0: Stmt_Function(
byRef: false
params: array(
0: Param(
name: b
default: null
type: null
byRef: false
)
1: Param(
name: c
default: null
type: array
byRef: false
)
2: Param(
name: e
default: null
type: Name(
parts: array(
0: D
)
)
byRef: false
)
)
stmts: array(
)
name: a
)
)