Skip to content

Commit 51c179b

Browse files
author
Richard van Velzen
committed
Support class const dereferencing in xhpast
Summary: Ref T4334. As it turns out, a major overhaul of the syntax wasn't needed. This adds support for stuff like `SomeClass::SOME_CONST[$idx]` which was introduced in PHP 7. Test Plan: Added a test case. Ran tests on libphutil and arcanist with both PHP 5 and PHP 7. Reviewers: epriestley, #blessed_reviewers Reviewed By: epriestley, #blessed_reviewers Subscribers: Korvin, Firehed Maniphest Tasks: T4334 Differential Revision: https://secure.phabricator.com/D16138
1 parent 1390fd2 commit 51c179b

File tree

5 files changed

+1588
-1387
lines changed

5 files changed

+1588
-1387
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,153 @@
1+
<?php
2+
XHPASTNode::NODE_TYPES['n_PROGRAM'];
3+
PHP_VERSION[0];
4+
~~~~~~~~~~
5+
pass
6+
~~~~~~~~~~
7+
{
8+
"tree": [
9+
9000,
10+
0,
11+
15,
12+
[
13+
[
14+
9006,
15+
0,
16+
14,
17+
[
18+
[
19+
9007,
20+
0,
21+
0
22+
],
23+
[
24+
9004,
25+
2,
26+
8,
27+
[
28+
[
29+
9100,
30+
2,
31+
7,
32+
[
33+
[
34+
9089,
35+
2,
36+
4,
37+
[
38+
[
39+
9090,
40+
2,
41+
2
42+
],
43+
[
44+
9013,
45+
4,
46+
4
47+
]
48+
]
49+
],
50+
[
51+
9087,
52+
6,
53+
6
54+
]
55+
]
56+
]
57+
]
58+
],
59+
[
60+
9004,
61+
10,
62+
14,
63+
[
64+
[
65+
9100,
66+
10,
67+
13,
68+
[
69+
[
70+
9013,
71+
10,
72+
10
73+
],
74+
[
75+
9086,
76+
12,
77+
12
78+
]
79+
]
80+
]
81+
]
82+
]
83+
]
84+
]
85+
]
86+
],
87+
"stream": [
88+
[
89+
373,
90+
5
91+
],
92+
[
93+
377,
94+
1
95+
],
96+
[
97+
311,
98+
10
99+
],
100+
[
101+
383,
102+
2
103+
],
104+
[
105+
311,
106+
10
107+
],
108+
[
109+
91,
110+
1
111+
],
112+
[
113+
319,
114+
11
115+
],
116+
[
117+
93,
118+
1
119+
],
120+
[
121+
59,
122+
1
123+
],
124+
[
125+
377,
126+
1
127+
],
128+
[
129+
311,
130+
11
131+
],
132+
[
133+
91,
134+
1
135+
],
136+
[
137+
309,
138+
1
139+
],
140+
[
141+
93,
142+
1
143+
],
144+
[
145+
59,
146+
1
147+
],
148+
[
149+
377,
150+
1
151+
]
152+
]
153+
}

src/parser/xhpast/bin/PhutilXHPASTBinary.php

+1-1
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ final class PhutilXHPASTBinary extends Phobject {
88
* This is the version that would be obtained with an up-to-date XHPAST
99
* build. The //actual// XHPAST build version may vary.
1010
*/
11-
const EXPECTED_VERSION = '7.0.2';
11+
const EXPECTED_VERSION = '7.0.3';
1212

1313
/**
1414
* The XHPAST build version.

support/xhpast/parser.y

+12
Original file line numberDiff line numberDiff line change
@@ -2707,6 +2707,18 @@ combined_scalar_offset:
27072707
$$->appendChild($3);
27082708
NMORE($$, $4);
27092709
}
2710+
| class_constant '[' dim_offset ']' {
2711+
$$ = NNEW(n_INDEX_ACCESS);
2712+
$$->appendChild($1);
2713+
$$->appendChild($3);
2714+
NMORE($$, $4);
2715+
}
2716+
| T_STRING '[' dim_offset ']' {
2717+
$$ = NNEW(n_INDEX_ACCESS);
2718+
$$->appendChild(NTYPE($1, n_STRING));
2719+
$$->appendChild($3);
2720+
NMORE($$, $4);
2721+
}
27102722
;
27112723

27122724
combined_scalar:

0 commit comments

Comments
 (0)