1
1
<?php namespace lang \ast \emit ;
2
2
3
- use ReflectionProperty ;
4
3
use lang \ast \nodes \{
5
4
Assignment ,
6
5
Block ,
@@ -71,15 +70,15 @@ protected function withScopeCheck($modifiers, $nodes) {
71
70
}
72
71
}
73
72
74
- protected function emitEmulatedHooks ($ result , $ property ) {
73
+ protected function emitProperty ($ result , $ property ) {
75
74
static $ lookup = [
76
75
'public ' => MODIFIER_PUBLIC ,
77
76
'protected ' => MODIFIER_PROTECTED ,
78
77
'private ' => MODIFIER_PRIVATE ,
79
78
'static ' => MODIFIER_STATIC ,
80
79
'final ' => MODIFIER_FINAL ,
81
80
'abstract ' => MODIFIER_ABSTRACT ,
82
- 'readonly ' => 0x0080 , // XP 10.13: MODIFIER_READONLY
81
+ 'readonly ' => MODIFIER_READONLY ,
83
82
];
84
83
85
84
// Emit XP meta information for the reflection API
@@ -157,63 +156,4 @@ protected function emitEmulatedHooks($result, $property) {
157
156
$ scope ->init [sprintf ('$this->__virtual["%s"] ' , $ property ->name )]= $ property ->expression ;
158
157
}
159
158
}
160
-
161
- protected function emitNativeHooks ($ result , $ property ) {
162
- $ result ->codegen ->scope [0 ]->meta [self ::PROPERTY ][$ property ->name ]= [
163
- DETAIL_RETURNS => $ property ->type ? $ property ->type ->name () : 'var ' ,
164
- DETAIL_ANNOTATIONS => $ property ->annotations ,
165
- DETAIL_COMMENT => $ property ->comment ,
166
- DETAIL_TARGET_ANNO => [],
167
- DETAIL_ARGUMENTS => []
168
- ];
169
-
170
- $ property ->comment && $ this ->emitOne ($ result , $ property ->comment );
171
- $ property ->annotations && $ this ->emitOne ($ result , $ property ->annotations );
172
- $ result ->at ($ property ->declared )->out ->write (implode (' ' , $ property ->modifiers ).' ' .$ this ->propertyType ($ property ->type ).' $ ' .$ property ->name );
173
- if (isset ($ property ->expression )) {
174
- if ($ this ->isConstant ($ result , $ property ->expression )) {
175
- $ result ->out ->write ('= ' );
176
- $ this ->emitOne ($ result , $ property ->expression );
177
- } else if (in_array ('static ' , $ property ->modifiers )) {
178
- $ result ->codegen ->scope [0 ]->statics ['self::$ ' .$ property ->name ]= $ property ->expression ;
179
- } else {
180
- $ result ->codegen ->scope [0 ]->init ['$this-> ' .$ property ->name ]= $ property ->expression ;
181
- }
182
- }
183
-
184
- // TODO move this to lang.ast.emit.PHP once https://github.com/php/php-src/pull/13455 is merged
185
- $ result ->out ->write ('{ ' );
186
- foreach ($ property ->hooks as $ type => $ hook ) {
187
- $ hook ->byref && $ result ->out ->write ('& ' );
188
- $ result ->out ->write ($ type );
189
- if ($ hook ->parameter ) {
190
- $ result ->out ->write ('( ' );
191
- $ this ->emitOne ($ result , $ hook ->parameter );
192
- $ result ->out ->write (') ' );
193
- }
194
-
195
- if (null === $ hook ->expression ) {
196
- $ result ->out ->write ('; ' );
197
- } else if ($ hook ->expression instanceof Block) {
198
- $ this ->emitOne ($ result , $ hook ->expression );
199
- } else {
200
- $ result ->out ->write ('=> ' );
201
- $ this ->emitOne ($ result , $ hook ->expression );
202
- $ result ->out ->write ('; ' );
203
- }
204
- }
205
- $ result ->out ->write ('} ' );
206
- }
207
-
208
- protected function emitProperty ($ result , $ property ) {
209
- static $ hooks = null ;
210
-
211
- if (empty ($ property ->hooks )) {
212
- parent ::emitProperty ($ result , $ property );
213
- } else if ($ hooks ?? $ hooks = method_exists (ReflectionProperty::class, 'getHooks ' )) {
214
- $ this ->emitNativeHooks ($ result , $ property );
215
- } else {
216
- $ this ->emitEmulatedHooks ($ result , $ property );
217
- }
218
- }
219
159
}
0 commit comments