xref: /php-src/Zend/zend_compile.h (revision 462da6e0)
1 /*
2    +----------------------------------------------------------------------+
3    | Zend Engine                                                          |
4    +----------------------------------------------------------------------+
5    | Copyright (c) Zend Technologies Ltd. (http://www.zend.com)           |
6    +----------------------------------------------------------------------+
7    | This source file is subject to version 2.00 of the Zend license,     |
8    | that is bundled with this package in the file LICENSE, and is        |
9    | available through the world-wide-web at the following url:           |
10    | http://www.zend.com/license/2_00.txt.                                |
11    | If you did not receive a copy of the Zend license and are unable to  |
12    | obtain it through the world-wide-web, please send a note to          |
13    | license@zend.com so we can mail you a copy immediately.              |
14    +----------------------------------------------------------------------+
15    | Authors: Andi Gutmans <andi@php.net>                                 |
16    |          Zeev Suraski <zeev@php.net>                                 |
17    +----------------------------------------------------------------------+
18 */
19 
20 #ifndef ZEND_COMPILE_H
21 #define ZEND_COMPILE_H
22 
23 #include "zend.h"
24 #include "zend_ast.h"
25 
26 #include <stdarg.h>
27 
28 #include "zend_llist.h"
29 
30 #define SET_UNUSED(op)  op ## _type = IS_UNUSED
31 
32 #define MAKE_NOP(opline) do { \
33 	(opline)->op1.num = 0; \
34 	(opline)->op2.num = 0; \
35 	(opline)->result.num = 0; \
36 	(opline)->opcode = ZEND_NOP; \
37 	(opline)->op1_type =  IS_UNUSED; \
38 	(opline)->op2_type = IS_UNUSED; \
39 	(opline)->result_type = IS_UNUSED; \
40 } while (0)
41 
42 #define RESET_DOC_COMMENT() do { \
43 	if (CG(doc_comment)) { \
44 		zend_string_release_ex(CG(doc_comment), 0); \
45 		CG(doc_comment) = NULL; \
46 	} \
47 } while (0)
48 
49 typedef struct _zend_op_array zend_op_array;
50 typedef struct _zend_op zend_op;
51 
52 /* On 64-bit systems less optimal, but more compact VM code leads to better
53  * performance. So on 32-bit systems we use absolute addresses for jump
54  * targets and constants, but on 64-bit systems relative 32-bit offsets */
55 #if SIZEOF_SIZE_T == 4
56 # define ZEND_USE_ABS_JMP_ADDR      1
57 # define ZEND_USE_ABS_CONST_ADDR    1
58 #else
59 # define ZEND_USE_ABS_JMP_ADDR      0
60 # define ZEND_USE_ABS_CONST_ADDR    0
61 #endif
62 
63 typedef union _znode_op {
64 	uint32_t      constant;
65 	uint32_t      var;
66 	uint32_t      num;
67 	uint32_t      opline_num; /*  Needs to be signed */
68 #if ZEND_USE_ABS_JMP_ADDR
69 	zend_op       *jmp_addr;
70 #else
71 	uint32_t      jmp_offset;
72 #endif
73 #if ZEND_USE_ABS_CONST_ADDR
74 	zval          *zv;
75 #endif
76 } znode_op;
77 
78 typedef struct _znode { /* used only during compilation */
79 	zend_uchar op_type;
80 	zend_uchar flag;
81 	union {
82 		znode_op op;
83 		zval constant; /* replaced by literal/zv */
84 	} u;
85 } znode;
86 
87 /* Temporarily defined here, to avoid header ordering issues */
88 typedef struct _zend_ast_znode {
89 	zend_ast_kind kind;
90 	zend_ast_attr attr;
91 	uint32_t lineno;
92 	znode node;
93 } zend_ast_znode;
94 
95 ZEND_API zend_ast * ZEND_FASTCALL zend_ast_create_znode(znode *node);
96 
97 static zend_always_inline znode *zend_ast_get_znode(zend_ast *ast) {
98 	return &((zend_ast_znode *) ast)->node;
99 }
100 
101 typedef struct _zend_declarables {
102 	zend_long ticks;
103 } zend_declarables;
104 
105 /* Compilation context that is different for each file, but shared between op arrays. */
106 typedef struct _zend_file_context {
107 	zend_declarables declarables;
108 
109 	zend_string *current_namespace;
110 	bool in_namespace;
111 	bool has_bracketed_namespaces;
112 
113 	HashTable *imports;
114 	HashTable *imports_function;
115 	HashTable *imports_const;
116 
117 	HashTable seen_symbols;
118 } zend_file_context;
119 
120 typedef union _zend_parser_stack_elem {
121 	zend_ast *ast;
122 	zend_string *str;
123 	zend_ulong num;
124 	unsigned char *ptr;
125 	unsigned char *ident;
126 } zend_parser_stack_elem;
127 
128 void zend_compile_top_stmt(zend_ast *ast);
129 void zend_compile_stmt(zend_ast *ast);
130 void zend_compile_expr(znode *node, zend_ast *ast);
131 zend_op *zend_compile_var(znode *node, zend_ast *ast, uint32_t type, bool by_ref);
132 void zend_eval_const_expr(zend_ast **ast_ptr);
133 void zend_const_expr_to_zval(zval *result, zend_ast **ast_ptr);
134 
135 typedef int (*user_opcode_handler_t) (zend_execute_data *execute_data);
136 
137 struct _zend_op {
138 	const void *handler;
139 	znode_op op1;
140 	znode_op op2;
141 	znode_op result;
142 	uint32_t extended_value;
143 	uint32_t lineno;
144 	zend_uchar opcode;
145 	zend_uchar op1_type;
146 	zend_uchar op2_type;
147 	zend_uchar result_type;
148 };
149 
150 
151 typedef struct _zend_brk_cont_element {
152 	int start;
153 	int cont;
154 	int brk;
155 	int parent;
156 	bool is_switch;
157 } zend_brk_cont_element;
158 
159 typedef struct _zend_label {
160 	int brk_cont;
161 	uint32_t opline_num;
162 } zend_label;
163 
164 typedef struct _zend_try_catch_element {
165 	uint32_t try_op;
166 	uint32_t catch_op;  /* ketchup! */
167 	uint32_t finally_op;
168 	uint32_t finally_end;
169 } zend_try_catch_element;
170 
171 #define ZEND_LIVE_TMPVAR  0
172 #define ZEND_LIVE_LOOP    1
173 #define ZEND_LIVE_SILENCE 2
174 #define ZEND_LIVE_ROPE    3
175 #define ZEND_LIVE_NEW     4
176 #define ZEND_LIVE_MASK    7
177 
178 typedef struct _zend_live_range {
179 	uint32_t var; /* low bits are used for variable type (ZEND_LIVE_* macros) */
180 	uint32_t start;
181 	uint32_t end;
182 } zend_live_range;
183 
184 /* Compilation context that is different for each op array. */
185 typedef struct _zend_oparray_context {
186 	uint32_t   opcodes_size;
187 	int        vars_size;
188 	int        literals_size;
189 	uint32_t   fast_call_var;
190 	uint32_t   try_catch_offset;
191 	int        current_brk_cont;
192 	int        last_brk_cont;
193 	zend_brk_cont_element *brk_cont_array;
194 	HashTable *labels;
195 } zend_oparray_context;
196 
197 /* Class, property and method flags                  class|meth.|prop.|const*/
198 /*                                                        |     |     |     */
199 /* Common flags                                           |     |     |     */
200 /* ============                                           |     |     |     */
201 /*                                                        |     |     |     */
202 /* Visibility flags (public < protected < private)        |     |     |     */
203 #define ZEND_ACC_PUBLIC                  (1 <<  0) /*     |  X  |  X  |  X  */
204 #define ZEND_ACC_PROTECTED               (1 <<  1) /*     |  X  |  X  |  X  */
205 #define ZEND_ACC_PRIVATE                 (1 <<  2) /*     |  X  |  X  |  X  */
206 /*                                                        |     |     |     */
207 /* Property or method overrides private one               |     |     |     */
208 #define ZEND_ACC_CHANGED                 (1 <<  3) /*     |  X  |  X  |     */
209 /*                                                        |     |     |     */
210 /* Static method or property                              |     |     |     */
211 #define ZEND_ACC_STATIC                  (1 <<  4) /*     |  X  |  X  |     */
212 /*                                                        |     |     |     */
213 /* Promoted property / parameter                          |     |     |     */
214 #define ZEND_ACC_PROMOTED                (1 <<  5) /*     |     |  X  |  X  */
215 /*                                                        |     |     |     */
216 /* Final class or method                                  |     |     |     */
217 #define ZEND_ACC_FINAL                   (1 <<  5) /*  X  |  X  |     |     */
218 /*                                                        |     |     |     */
219 /* Abstract method                                        |     |     |     */
220 #define ZEND_ACC_ABSTRACT                (1 <<  6) /*  X  |  X  |     |     */
221 #define ZEND_ACC_EXPLICIT_ABSTRACT_CLASS (1 <<  6) /*  X  |     |     |     */
222 /*                                                        |     |     |     */
223 /* Immutable op_array and class_entries                   |     |     |     */
224 /* (implemented only for lazy loading of op_arrays)       |     |     |     */
225 #define ZEND_ACC_IMMUTABLE               (1 <<  7) /*  X  |  X  |     |     */
226 /*                                                        |     |     |     */
227 /* Function has typed arguments / class has typed props   |     |     |     */
228 #define ZEND_ACC_HAS_TYPE_HINTS          (1 <<  8) /*  X  |  X  |     |     */
229 /*                                                        |     |     |     */
230 /* Top-level class or function declaration                |     |     |     */
231 #define ZEND_ACC_TOP_LEVEL               (1 <<  9) /*  X  |  X  |     |     */
232 /*                                                        |     |     |     */
233 /* op_array or class is preloaded                         |     |     |     */
234 #define ZEND_ACC_PRELOADED               (1 << 10) /*  X  |  X  |     |     */
235 /*                                                        |     |     |     */
236 /* Flag to differentiate cases from constants.            |     |     |     */
237 /* Stored in Z_ACCESS_FLAGS, must not conflict with       |     |     |     */
238 /* ZEND_ACC_ visibility flags or IS_CONSTANT_VISITED_MARK |     |     |     */
239 #define ZEND_CLASS_CONST_IS_CASE         (1 << 6)  /*     |     |     |  X  */
240 /*                                                        |     |     |     */
241 /* Class Flags (unused: 29...)                            |     |     |     */
242 /* ===========                                            |     |     |     */
243 /*                                                        |     |     |     */
244 /* Special class types                                    |     |     |     */
245 #define ZEND_ACC_INTERFACE               (1 <<  0) /*  X  |     |     |     */
246 #define ZEND_ACC_TRAIT                   (1 <<  1) /*  X  |     |     |     */
247 #define ZEND_ACC_ANON_CLASS              (1 <<  2) /*  X  |     |     |     */
248 #define ZEND_ACC_ENUM                    (1 << 28) /*  X  |     |     |     */
249 /*                                                        |     |     |     */
250 /* Class linked with parent, interfaces and traits        |     |     |     */
251 #define ZEND_ACC_LINKED                  (1 <<  3) /*  X  |     |     |     */
252 /*                                                        |     |     |     */
253 /* Class is abstract, since it is set by any              |     |     |     */
254 /* abstract method                                        |     |     |     */
255 #define ZEND_ACC_IMPLICIT_ABSTRACT_CLASS (1 <<  4) /*  X  |     |     |     */
256 /*                                                        |     |     |     */
257 /* Class has magic methods __get/__set/__unset/           |     |     |     */
258 /* __isset that use guards                                |     |     |     */
259 #define ZEND_ACC_USE_GUARDS              (1 << 11) /*  X  |     |     |     */
260 /*                                                        |     |     |     */
261 /* Class constants updated                                |     |     |     */
262 #define ZEND_ACC_CONSTANTS_UPDATED       (1 << 12) /*  X  |     |     |     */
263 /*                                                        |     |     |     */
264 /* Objects of this class may not have dynamic properties  |     |     |     */
265 #define ZEND_ACC_NO_DYNAMIC_PROPERTIES   (1 << 13) /*  X  |     |     |     */
266 /*                                                        |     |     |     */
267 /* User class has methods with static variables           |     |     |     */
268 #define ZEND_HAS_STATIC_IN_METHODS       (1 << 14) /*  X  |     |     |     */
269 /*                                                        |     |     |     */
270 /* Whether all property types are resolved to CEs         |     |     |     */
271 #define ZEND_ACC_PROPERTY_TYPES_RESOLVED (1 << 15) /*  X  |     |     |     */
272 /*                                                        |     |     |     */
273 /* Children must reuse parent get_iterator()              |     |     |     */
274 #define ZEND_ACC_REUSE_GET_ITERATOR      (1 << 16) /*  X  |     |     |     */
275 /*                                                        |     |     |     */
276 /* Parent class is resolved (CE).                         |     |     |     */
277 #define ZEND_ACC_RESOLVED_PARENT         (1 << 17) /*  X  |     |     |     */
278 /*                                                        |     |     |     */
279 /* Interfaces are resolved (CEs).                         |     |     |     */
280 #define ZEND_ACC_RESOLVED_INTERFACES     (1 << 18) /*  X  |     |     |     */
281 /*                                                        |     |     |     */
282 /* Class has unresolved variance obligations.             |     |     |     */
283 #define ZEND_ACC_UNRESOLVED_VARIANCE     (1 << 19) /*  X  |     |     |     */
284 /*                                                        |     |     |     */
285 /* Class is linked apart from variance obligations.       |     |     |     */
286 #define ZEND_ACC_NEARLY_LINKED           (1 << 20) /*  X  |     |     |     */
287 /*                                                        |     |     |     */
288 /* Whether this class was used in its unlinked state.     |     |     |     */
289 #define ZEND_ACC_HAS_UNLINKED_USES       (1 << 21) /*  X  |     |     |     */
290 /*                                                        |     |     |     */
291 /* stored in opcache (may be partially)                   |     |     |     */
292 #define ZEND_ACC_CACHED                  (1 << 22) /*  X  |     |     |     */
293 /*                                                        |     |     |     */
294 /* temporary flag used during delayed variance checks     |     |     |     */
295 #define ZEND_ACC_CACHEABLE               (1 << 23) /*  X  |     |     |     */
296 /*                                                        |     |     |     */
297 #define ZEND_ACC_HAS_AST_CONSTANTS       (1 << 24) /*  X  |     |     |     */
298 #define ZEND_ACC_HAS_AST_PROPERTIES      (1 << 25) /*  X  |     |     |     */
299 #define ZEND_ACC_HAS_AST_STATICS         (1 << 26) /*  X  |     |     |     */
300 /*                                                        |     |     |     */
301 /* loaded from file cache to process memory               |     |     |     */
302 #define ZEND_ACC_FILE_CACHED             (1 << 27) /*  X  |     |     |     */
303 /*                                                        |     |     |     */
304 /* Function Flags (unused: 27-30)                         |     |     |     */
305 /* ==============                                         |     |     |     */
306 /*                                                        |     |     |     */
307 /* deprecation flag                                       |     |     |     */
308 #define ZEND_ACC_DEPRECATED              (1 << 11) /*     |  X  |     |     */
309 /*                                                        |     |     |     */
310 /* Function returning by reference                        |     |     |     */
311 #define ZEND_ACC_RETURN_REFERENCE        (1 << 12) /*     |  X  |     |     */
312 /*                                                        |     |     |     */
313 /* Function has a return type                             |     |     |     */
314 #define ZEND_ACC_HAS_RETURN_TYPE         (1 << 13) /*     |  X  |     |     */
315 /*                                                        |     |     |     */
316 /* Function with variable number of arguments             |     |     |     */
317 #define ZEND_ACC_VARIADIC                (1 << 14) /*     |  X  |     |     */
318 /*                                                        |     |     |     */
319 /* op_array has finally blocks (user only)                |     |     |     */
320 #define ZEND_ACC_HAS_FINALLY_BLOCK       (1 << 15) /*     |  X  |     |     */
321 /*                                                        |     |     |     */
322 /* "main" op_array with                                   |     |     |     */
323 /* ZEND_DECLARE_CLASS_DELAYED opcodes                     |     |     |     */
324 #define ZEND_ACC_EARLY_BINDING           (1 << 16) /*     |  X  |     |     */
325 /*                                                        |     |     |     */
326 /* closure uses $this                                     |     |     |     */
327 #define ZEND_ACC_USES_THIS               (1 << 17) /*     |  X  |     |     */
328 /*                                                        |     |     |     */
329 /* call through user function trampoline. e.g.            |     |     |     */
330 /* __call, __callstatic                                   |     |     |     */
331 #define ZEND_ACC_CALL_VIA_TRAMPOLINE     (1 << 18) /*     |  X  |     |     */
332 /*                                                        |     |     |     */
333 /* disable inline caching                                 |     |     |     */
334 #define ZEND_ACC_NEVER_CACHE             (1 << 19) /*     |  X  |     |     */
335 /*                                                        |     |     |     */
336 /* op_array is a clone of trait method                    |     |     |     */
337 #define ZEND_ACC_TRAIT_CLONE             (1 << 20) /*     |  X  |     |     */
338 /*                                                        |     |     |     */
339 /* functions is a constructor                             |     |     |     */
340 #define ZEND_ACC_CTOR                    (1 << 21) /*     |  X  |     |     */
341 /*                                                        |     |     |     */
342 /* Closure related                                        |     |     |     */
343 #define ZEND_ACC_CLOSURE                 (1 << 22) /*     |  X  |     |     */
344 #define ZEND_ACC_FAKE_CLOSURE            (1 << 23) /*     |  X  |     |     */ /* Same as ZEND_CALL_FAKE_CLOSURE */
345 /*                                                        |     |     |     */
346 #define ZEND_ACC_GENERATOR               (1 << 24) /*     |  X  |     |     */
347 /*                                                        |     |     |     */
348 /* function was processed by pass two (user only)         |     |     |     */
349 #define ZEND_ACC_DONE_PASS_TWO           (1 << 25) /*     |  X  |     |     */
350 /*                                                        |     |     |     */
351 /* internal function is allocated at arena (int only)     |     |     |     */
352 #define ZEND_ACC_ARENA_ALLOCATED         (1 << 25) /*     |  X  |     |     */
353 /*                                                        |     |     |     */
354 /* run_time_cache allocated on heap (user only)           |     |     |     */
355 #define ZEND_ACC_HEAP_RT_CACHE           (1 << 26) /*     |  X  |     |     */
356 /*                                                        |     |     |     */
357 /* method flag used by Closure::__invoke() (int only)     |     |     |     */
358 #define ZEND_ACC_USER_ARG_INFO           (1 << 26) /*     |  X  |     |     */
359 /*                                                        |     |     |     */
360 /* op_array uses strict mode types                        |     |     |     */
361 #define ZEND_ACC_STRICT_TYPES            (1U << 31) /*    |  X  |     |     */
362 
363 
364 #define ZEND_ACC_PPP_MASK  (ZEND_ACC_PUBLIC | ZEND_ACC_PROTECTED | ZEND_ACC_PRIVATE)
365 
366 /* call through internal function handler. e.g. Closure::invoke() */
367 #define ZEND_ACC_CALL_VIA_HANDLER     ZEND_ACC_CALL_VIA_TRAMPOLINE
368 
369 #define ZEND_SHORT_CIRCUITING_CHAIN_EXPR 0
370 #define ZEND_SHORT_CIRCUITING_CHAIN_ISSET 1
371 #define ZEND_SHORT_CIRCUITING_CHAIN_EMPTY 2
372 
373 char *zend_visibility_string(uint32_t fn_flags);
374 
375 typedef struct _zend_property_info {
376 	uint32_t offset; /* property offset for object properties or
377 	                      property index for static properties */
378 	uint32_t flags;
379 	zend_string *name;
380 	zend_string *doc_comment;
381 	HashTable *attributes;
382 	zend_class_entry *ce;
383 	zend_type type;
384 } zend_property_info;
385 
386 #define OBJ_PROP(obj, offset) \
387 	((zval*)((char*)(obj) + offset))
388 #define OBJ_PROP_NUM(obj, num) \
389 	(&(obj)->properties_table[(num)])
390 #define OBJ_PROP_TO_OFFSET(num) \
391 	((uint32_t)(XtOffsetOf(zend_object, properties_table) + sizeof(zval) * (num)))
392 #define OBJ_PROP_TO_NUM(offset) \
393 	((offset - OBJ_PROP_TO_OFFSET(0)) / sizeof(zval))
394 
395 typedef struct _zend_class_constant {
396 	zval value; /* access flags and other constant flags are stored in reserved: zval.u2.access_flags */
397 	zend_string *doc_comment;
398 	HashTable *attributes;
399 	zend_class_entry *ce;
400 } zend_class_constant;
401 
402 /* arg_info for internal functions */
403 typedef struct _zend_internal_arg_info {
404 	const char *name;
405 	zend_type type;
406 	const char *default_value;
407 } zend_internal_arg_info;
408 
409 /* arg_info for user functions */
410 typedef struct _zend_arg_info {
411 	zend_string *name;
412 	zend_type type;
413 	zend_string *default_value;
414 } zend_arg_info;
415 
416 /* the following structure repeats the layout of zend_internal_arg_info,
417  * but its fields have different meaning. It's used as the first element of
418  * arg_info array to define properties of internal functions.
419  * It's also used for the return type.
420  */
421 typedef struct _zend_internal_function_info {
422 	zend_uintptr_t required_num_args;
423 	zend_type type;
424 	const char *default_value;
425 } zend_internal_function_info;
426 
427 struct _zend_op_array {
428 	/* Common elements */
429 	zend_uchar type;
430 	zend_uchar arg_flags[3]; /* bitset of arg_info.pass_by_reference */
431 	uint32_t fn_flags;
432 	zend_string *function_name;
433 	zend_class_entry *scope;
434 	zend_function *prototype;
435 	uint32_t num_args;
436 	uint32_t required_num_args;
437 	zend_arg_info *arg_info;
438 	HashTable *attributes;
439 	/* END of common elements */
440 
441 	int cache_size;     /* number of run_time_cache_slots * sizeof(void*) */
442 	int last_var;       /* number of CV variables */
443 	uint32_t T;         /* number of temporary variables */
444 	uint32_t last;      /* number of opcodes */
445 
446 	zend_op *opcodes;
447 	ZEND_MAP_PTR_DEF(void **, run_time_cache);
448 	ZEND_MAP_PTR_DEF(HashTable *, static_variables_ptr);
449 	HashTable *static_variables;
450 	zend_string **vars; /* names of CV variables */
451 
452 	uint32_t *refcount;
453 
454 	int last_live_range;
455 	int last_try_catch;
456 	zend_live_range *live_range;
457 	zend_try_catch_element *try_catch_array;
458 
459 	zend_string *filename;
460 	uint32_t line_start;
461 	uint32_t line_end;
462 	zend_string *doc_comment;
463 
464 	int last_literal;
465 	uint32_t num_dynamic_func_defs;
466 	zval *literals;
467 
468 	/* Functions that are declared dynamically are stored here and
469 	 * referenced by index from opcodes. */
470 	zend_op_array **dynamic_func_defs;
471 
472 	void *reserved[ZEND_MAX_RESERVED_RESOURCES];
473 };
474 
475 
476 #define ZEND_RETURN_VALUE				0
477 #define ZEND_RETURN_REFERENCE			1
478 
479 /* zend_internal_function_handler */
480 typedef void (ZEND_FASTCALL *zif_handler)(INTERNAL_FUNCTION_PARAMETERS);
481 
482 typedef struct _zend_internal_function {
483 	/* Common elements */
484 	zend_uchar type;
485 	zend_uchar arg_flags[3]; /* bitset of arg_info.pass_by_reference */
486 	uint32_t fn_flags;
487 	zend_string* function_name;
488 	zend_class_entry *scope;
489 	zend_function *prototype;
490 	uint32_t num_args;
491 	uint32_t required_num_args;
492 	zend_internal_arg_info *arg_info;
493 	HashTable *attributes;
494 	/* END of common elements */
495 
496 	zif_handler handler;
497 	struct _zend_module_entry *module;
498 	void *reserved[ZEND_MAX_RESERVED_RESOURCES];
499 } zend_internal_function;
500 
501 #define ZEND_FN_SCOPE_NAME(function)  ((function) && (function)->common.scope ? ZSTR_VAL((function)->common.scope->name) : "")
502 
503 union _zend_function {
504 	zend_uchar type;	/* MUST be the first element of this struct! */
505 	uint32_t   quick_arg_flags;
506 
507 	struct {
508 		zend_uchar type;  /* never used */
509 		zend_uchar arg_flags[3]; /* bitset of arg_info.pass_by_reference */
510 		uint32_t fn_flags;
511 		zend_string *function_name;
512 		zend_class_entry *scope;
513 		zend_function *prototype;
514 		uint32_t num_args;
515 		uint32_t required_num_args;
516 		zend_arg_info *arg_info;  /* index -1 represents the return value info, if any */
517 		HashTable   *attributes;
518 	} common;
519 
520 	zend_op_array op_array;
521 	zend_internal_function internal_function;
522 };
523 
524 struct _zend_execute_data {
525 	const zend_op       *opline;           /* executed opline                */
526 	zend_execute_data   *call;             /* current call                   */
527 	zval                *return_value;
528 	zend_function       *func;             /* executed function              */
529 	zval                 This;             /* this + call_info + num_args    */
530 	zend_execute_data   *prev_execute_data;
531 	zend_array          *symbol_table;
532 	void               **run_time_cache;   /* cache op_array->run_time_cache */
533 	zend_array          *extra_named_params;
534 };
535 
536 #define ZEND_CALL_HAS_THIS           IS_OBJECT_EX
537 
538 /* Top 16 bits of Z_TYPE_INFO(EX(This)) are used as call_info flags */
539 #define ZEND_CALL_FUNCTION           (0 << 16)
540 #define ZEND_CALL_CODE               (1 << 16)
541 #define ZEND_CALL_NESTED             (0 << 17)
542 #define ZEND_CALL_TOP                (1 << 17)
543 #define ZEND_CALL_ALLOCATED          (1 << 18)
544 #define ZEND_CALL_FREE_EXTRA_ARGS    (1 << 19)
545 #define ZEND_CALL_HAS_SYMBOL_TABLE   (1 << 20)
546 #define ZEND_CALL_RELEASE_THIS       (1 << 21)
547 #define ZEND_CALL_CLOSURE            (1 << 22)
548 #define ZEND_CALL_FAKE_CLOSURE       (1 << 23) /* Same as ZEND_ACC_FAKE_CLOSURE */
549 #define ZEND_CALL_GENERATOR          (1 << 24)
550 #define ZEND_CALL_DYNAMIC            (1 << 25)
551 #define ZEND_CALL_MAY_HAVE_UNDEF     (1 << 26)
552 #define ZEND_CALL_HAS_EXTRA_NAMED_PARAMS (1 << 27)
553 #define ZEND_CALL_OBSERVED           (1 << 28) /* "fcall_begin" observer handler may set this flag */
554                                                /* to prevent optimization in RETURN handler and    */
555                                                /* keep all local variables for "fcall_end" handler */
556 #define ZEND_CALL_SEND_ARG_BY_REF    (1u << 31)
557 
558 #define ZEND_CALL_NESTED_FUNCTION    (ZEND_CALL_FUNCTION | ZEND_CALL_NESTED)
559 #define ZEND_CALL_NESTED_CODE        (ZEND_CALL_CODE | ZEND_CALL_NESTED)
560 #define ZEND_CALL_TOP_FUNCTION       (ZEND_CALL_TOP | ZEND_CALL_FUNCTION)
561 #define ZEND_CALL_TOP_CODE           (ZEND_CALL_CODE | ZEND_CALL_TOP)
562 
563 #define ZEND_CALL_INFO(call) \
564 	Z_TYPE_INFO((call)->This)
565 
566 #define ZEND_CALL_KIND_EX(call_info) \
567 	(call_info & (ZEND_CALL_CODE | ZEND_CALL_TOP))
568 
569 #define ZEND_CALL_KIND(call) \
570 	ZEND_CALL_KIND_EX(ZEND_CALL_INFO(call))
571 
572 #define ZEND_ADD_CALL_FLAG_EX(call_info, flag) do { \
573 		call_info |= (flag); \
574 	} while (0)
575 
576 #define ZEND_DEL_CALL_FLAG_EX(call_info, flag) do { \
577 		call_info &= ~(flag); \
578 	} while (0)
579 
580 #define ZEND_ADD_CALL_FLAG(call, flag) do { \
581 		ZEND_ADD_CALL_FLAG_EX(Z_TYPE_INFO((call)->This), flag); \
582 	} while (0)
583 
584 #define ZEND_DEL_CALL_FLAG(call, flag) do { \
585 		ZEND_DEL_CALL_FLAG_EX(Z_TYPE_INFO((call)->This), flag); \
586 	} while (0)
587 
588 #define ZEND_CALL_NUM_ARGS(call) \
589 	(call)->This.u2.num_args
590 
591 #define ZEND_CALL_FRAME_SLOT \
592 	((int)((ZEND_MM_ALIGNED_SIZE(sizeof(zend_execute_data)) + ZEND_MM_ALIGNED_SIZE(sizeof(zval)) - 1) / ZEND_MM_ALIGNED_SIZE(sizeof(zval))))
593 
594 #define ZEND_CALL_VAR(call, n) \
595 	((zval*)(((char*)(call)) + ((int)(n))))
596 
597 #define ZEND_CALL_VAR_NUM(call, n) \
598 	(((zval*)(call)) + (ZEND_CALL_FRAME_SLOT + ((int)(n))))
599 
600 #define ZEND_CALL_ARG(call, n) \
601 	ZEND_CALL_VAR_NUM(call, ((int)(n)) - 1)
602 
603 #define EX(element) 			((execute_data)->element)
604 
605 #define EX_CALL_INFO()			ZEND_CALL_INFO(execute_data)
606 #define EX_CALL_KIND()			ZEND_CALL_KIND(execute_data)
607 #define EX_NUM_ARGS()			ZEND_CALL_NUM_ARGS(execute_data)
608 
609 #define ZEND_CALL_USES_STRICT_TYPES(call) \
610 	(((call)->func->common.fn_flags & ZEND_ACC_STRICT_TYPES) != 0)
611 
612 #define EX_USES_STRICT_TYPES() \
613 	ZEND_CALL_USES_STRICT_TYPES(execute_data)
614 
615 #define ZEND_ARG_USES_STRICT_TYPES() \
616 	(EG(current_execute_data)->prev_execute_data && \
617 	 EG(current_execute_data)->prev_execute_data->func && \
618 	 ZEND_CALL_USES_STRICT_TYPES(EG(current_execute_data)->prev_execute_data))
619 
620 #define ZEND_RET_USES_STRICT_TYPES() \
621 	ZEND_CALL_USES_STRICT_TYPES(EG(current_execute_data))
622 
623 #define EX_VAR(n)				ZEND_CALL_VAR(execute_data, n)
624 #define EX_VAR_NUM(n)			ZEND_CALL_VAR_NUM(execute_data, n)
625 
626 #define EX_VAR_TO_NUM(n)		((uint32_t)((n) / sizeof(zval) - ZEND_CALL_FRAME_SLOT))
627 #define EX_NUM_TO_VAR(n)		((uint32_t)(((n) + ZEND_CALL_FRAME_SLOT) * sizeof(zval)))
628 
629 #define ZEND_OPLINE_TO_OFFSET(opline, target) \
630 	((char*)(target) - (char*)(opline))
631 
632 #define ZEND_OPLINE_NUM_TO_OFFSET(op_array, opline, opline_num) \
633 	((char*)&(op_array)->opcodes[opline_num] - (char*)(opline))
634 
635 #define ZEND_OFFSET_TO_OPLINE(base, offset) \
636 	((zend_op*)(((char*)(base)) + (int)offset))
637 
638 #define ZEND_OFFSET_TO_OPLINE_NUM(op_array, base, offset) \
639 	(ZEND_OFFSET_TO_OPLINE(base, offset) - op_array->opcodes)
640 
641 #if ZEND_USE_ABS_JMP_ADDR
642 
643 /* run-time jump target */
644 # define OP_JMP_ADDR(opline, node) \
645 	(node).jmp_addr
646 
647 # define ZEND_SET_OP_JMP_ADDR(opline, node, val) do { \
648 		(node).jmp_addr = (val); \
649 	} while (0)
650 
651 /* convert jump target from compile-time to run-time */
652 # define ZEND_PASS_TWO_UPDATE_JMP_TARGET(op_array, opline, node) do { \
653 		(node).jmp_addr = (op_array)->opcodes + (node).opline_num; \
654 	} while (0)
655 
656 /* convert jump target back from run-time to compile-time */
657 # define ZEND_PASS_TWO_UNDO_JMP_TARGET(op_array, opline, node) do { \
658 		(node).opline_num = (node).jmp_addr - (op_array)->opcodes; \
659 	} while (0)
660 
661 #else
662 
663 /* run-time jump target */
664 # define OP_JMP_ADDR(opline, node) \
665 	ZEND_OFFSET_TO_OPLINE(opline, (node).jmp_offset)
666 
667 # define ZEND_SET_OP_JMP_ADDR(opline, node, val) do { \
668 		(node).jmp_offset = ZEND_OPLINE_TO_OFFSET(opline, val); \
669 	} while (0)
670 
671 /* convert jump target from compile-time to run-time */
672 # define ZEND_PASS_TWO_UPDATE_JMP_TARGET(op_array, opline, node) do { \
673 		(node).jmp_offset = ZEND_OPLINE_NUM_TO_OFFSET(op_array, opline, (node).opline_num); \
674 	} while (0)
675 
676 /* convert jump target back from run-time to compile-time */
677 # define ZEND_PASS_TWO_UNDO_JMP_TARGET(op_array, opline, node) do { \
678 		(node).opline_num = ZEND_OFFSET_TO_OPLINE_NUM(op_array, opline, (node).jmp_offset); \
679 	} while (0)
680 
681 #endif
682 
683 /* constant-time constant */
684 # define CT_CONSTANT_EX(op_array, num) \
685 	((op_array)->literals + (num))
686 
687 # define CT_CONSTANT(node) \
688 	CT_CONSTANT_EX(CG(active_op_array), (node).constant)
689 
690 #if ZEND_USE_ABS_CONST_ADDR
691 
692 /* run-time constant */
693 # define RT_CONSTANT(opline, node) \
694 	(node).zv
695 
696 /* convert constant from compile-time to run-time */
697 # define ZEND_PASS_TWO_UPDATE_CONSTANT(op_array, opline, node) do { \
698 		(node).zv = CT_CONSTANT_EX(op_array, (node).constant); \
699 	} while (0)
700 
701 #else
702 
703 /* At run-time, constants are allocated together with op_array->opcodes
704  * and addressed relatively to current opline.
705  */
706 
707 /* run-time constant */
708 # define RT_CONSTANT(opline, node) \
709 	((zval*)(((char*)(opline)) + (int32_t)(node).constant))
710 
711 /* convert constant from compile-time to run-time */
712 # define ZEND_PASS_TWO_UPDATE_CONSTANT(op_array, opline, node) do { \
713 		(node).constant = \
714 			(((char*)CT_CONSTANT_EX(op_array, (node).constant)) - \
715 			((char*)opline)); \
716 	} while (0)
717 
718 #endif
719 
720 /* convert constant back from run-time to compile-time */
721 #define ZEND_PASS_TWO_UNDO_CONSTANT(op_array, opline, node) do { \
722 		(node).constant = RT_CONSTANT(opline, node) - (op_array)->literals; \
723 	} while (0)
724 
725 #define RUN_TIME_CACHE(op_array) \
726 	ZEND_MAP_PTR_GET((op_array)->run_time_cache)
727 
728 #define ZEND_OP_ARRAY_EXTENSION(op_array, handle) \
729 	((void**)RUN_TIME_CACHE(op_array))[handle]
730 
731 #define IS_UNUSED	0		/* Unused operand */
732 #define IS_CONST	(1<<0)
733 #define IS_TMP_VAR	(1<<1)
734 #define IS_VAR		(1<<2)
735 #define IS_CV		(1<<3)	/* Compiled variable */
736 
737 /* Used for result.type of smart branch instructions */
738 #define IS_SMART_BRANCH_JMPZ  (1<<4)
739 #define IS_SMART_BRANCH_JMPNZ (1<<5)
740 
741 #define ZEND_EXTRA_VALUE 1
742 
743 #include "zend_globals.h"
744 
745 BEGIN_EXTERN_C()
746 
747 void init_compiler(void);
748 void shutdown_compiler(void);
749 void zend_init_compiler_data_structures(void);
750 
751 void zend_oparray_context_begin(zend_oparray_context *prev_context);
752 void zend_oparray_context_end(zend_oparray_context *prev_context);
753 void zend_file_context_begin(zend_file_context *prev_context);
754 void zend_file_context_end(zend_file_context *prev_context);
755 
756 extern ZEND_API zend_op_array *(*zend_compile_file)(zend_file_handle *file_handle, int type);
757 extern ZEND_API zend_op_array *(*zend_compile_string)(zend_string *source_string, const char *filename);
758 
759 ZEND_API int ZEND_FASTCALL lex_scan(zval *zendlval, zend_parser_stack_elem *elem);
760 void startup_scanner(void);
761 void shutdown_scanner(void);
762 
763 ZEND_API zend_string *zend_set_compiled_filename(zend_string *new_compiled_filename);
764 ZEND_API void zend_restore_compiled_filename(zend_string *original_compiled_filename);
765 ZEND_API zend_string *zend_get_compiled_filename(void);
766 ZEND_API int zend_get_compiled_lineno(void);
767 ZEND_API size_t zend_get_scanned_file_offset(void);
768 
769 ZEND_API zend_string *zend_get_compiled_variable_name(const zend_op_array *op_array, uint32_t var);
770 
771 #ifdef ZTS
772 const char *zend_get_zendtext(void);
773 int zend_get_zendleng(void);
774 #endif
775 
776 typedef zend_result (ZEND_FASTCALL *unary_op_type)(zval *, zval *);
777 typedef zend_result (ZEND_FASTCALL *binary_op_type)(zval *, zval *, zval *);
778 
779 ZEND_API unary_op_type get_unary_op(int opcode);
780 ZEND_API binary_op_type get_binary_op(int opcode);
781 
782 void zend_stop_lexing(void);
783 void zend_emit_final_return(bool return_one);
784 
785 /* Used during AST construction */
786 zend_ast *zend_ast_append_str(zend_ast *left, zend_ast *right);
787 zend_ast *zend_negate_num_string(zend_ast *ast);
788 uint32_t zend_add_class_modifier(uint32_t flags, uint32_t new_flag);
789 uint32_t zend_add_member_modifier(uint32_t flags, uint32_t new_flag);
790 bool zend_handle_encoding_declaration(zend_ast *ast);
791 
792 /* parser-driven code generators */
793 void zend_do_free(znode *op1);
794 
795 ZEND_API zend_result do_bind_function(zend_function *func, zval *lcname);
796 ZEND_API zend_result do_bind_class(zval *lcname, zend_string *lc_parent_name);
797 ZEND_API uint32_t zend_build_delayed_early_binding_list(const zend_op_array *op_array);
798 ZEND_API void zend_do_delayed_early_binding(zend_op_array *op_array, uint32_t first_early_binding_opline);
799 
800 void zend_do_extended_info(void);
801 void zend_do_extended_fcall_begin(void);
802 void zend_do_extended_fcall_end(void);
803 
804 void zend_verify_namespace(void);
805 
806 void zend_resolve_goto_label(zend_op_array *op_array, zend_op *opline);
807 
808 ZEND_API void function_add_ref(zend_function *function);
809 void zend_init_static_variables_map_ptr(zend_op_array *op_array);
810 
811 #define INITIAL_OP_ARRAY_SIZE 64
812 
813 
814 /* helper functions in zend_language_scanner.l */
815 struct _zend_arena;
816 
817 ZEND_API zend_op_array *compile_file(zend_file_handle *file_handle, int type);
818 ZEND_API zend_op_array *compile_string(zend_string *source_string, const char *filename);
819 ZEND_API zend_op_array *compile_filename(int type, zend_string *filename);
820 ZEND_API zend_ast *zend_compile_string_to_ast(
821 		zend_string *code, struct _zend_arena **ast_arena, zend_string *filename);
822 ZEND_API int zend_execute_scripts(int type, zval *retval, int file_count, ...);
823 ZEND_API int open_file_for_scanning(zend_file_handle *file_handle);
824 ZEND_API void init_op_array(zend_op_array *op_array, zend_uchar type, int initial_ops_size);
825 ZEND_API void destroy_op_array(zend_op_array *op_array);
826 ZEND_API void zend_destroy_static_vars(zend_op_array *op_array);
827 ZEND_API void zend_destroy_file_handle(zend_file_handle *file_handle);
828 ZEND_API void zend_cleanup_mutable_class_data(zend_class_entry *ce);
829 ZEND_API void zend_cleanup_internal_class_data(zend_class_entry *ce);
830 ZEND_API void zend_cleanup_internal_classes(void);
831 ZEND_API void zend_type_release(zend_type type, bool persistent);
832 ZEND_API zend_string *zend_create_member_string(zend_string *class_name, zend_string *member_name);
833 
834 
835 ZEND_API ZEND_COLD void zend_user_exception_handler(void);
836 
837 #define zend_try_exception_handler() do { \
838 		if (UNEXPECTED(EG(exception))) { \
839 			if (Z_TYPE(EG(user_exception_handler)) != IS_UNDEF) { \
840 				zend_user_exception_handler(); \
841 			} \
842 		} \
843 	} while (0)
844 
845 void zend_free_internal_arg_info(zend_internal_function *function);
846 ZEND_API void destroy_zend_function(zend_function *function);
847 ZEND_API void zend_function_dtor(zval *zv);
848 ZEND_API void destroy_zend_class(zval *zv);
849 void zend_class_add_ref(zval *zv);
850 
851 ZEND_API zend_string *zend_mangle_property_name(const char *src1, size_t src1_length, const char *src2, size_t src2_length, bool internal);
852 #define zend_unmangle_property_name(mangled_property, class_name, prop_name) \
853         zend_unmangle_property_name_ex(mangled_property, class_name, prop_name, NULL)
854 ZEND_API zend_result zend_unmangle_property_name_ex(const zend_string *name, const char **class_name, const char **prop_name, size_t *prop_len);
855 
856 static zend_always_inline const char *zend_get_unmangled_property_name(const zend_string *mangled_prop) {
857 	const char *class_name, *prop_name;
858 	zend_unmangle_property_name(mangled_prop, &class_name, &prop_name);
859 	return prop_name;
860 }
861 
862 #define ZEND_FUNCTION_DTOR zend_function_dtor
863 #define ZEND_CLASS_DTOR destroy_zend_class
864 
865 typedef bool (*zend_needs_live_range_cb)(zend_op_array *op_array, zend_op *opline);
866 ZEND_API void zend_recalc_live_ranges(
867 	zend_op_array *op_array, zend_needs_live_range_cb needs_live_range);
868 
869 ZEND_API void pass_two(zend_op_array *op_array);
870 ZEND_API bool zend_is_compiling(void);
871 ZEND_API char *zend_make_compiled_string_description(const char *name);
872 ZEND_API void zend_initialize_class_data(zend_class_entry *ce, bool nullify_handlers);
873 uint32_t zend_get_class_fetch_type(zend_string *name);
874 ZEND_API zend_uchar zend_get_call_op(const zend_op *init_op, zend_function *fbc);
875 ZEND_API bool zend_is_smart_branch(const zend_op *opline);
876 
877 typedef bool (*zend_auto_global_callback)(zend_string *name);
878 typedef struct _zend_auto_global {
879 	zend_string *name;
880 	zend_auto_global_callback auto_global_callback;
881 	bool jit;
882 	bool armed;
883 } zend_auto_global;
884 
885 ZEND_API zend_result zend_register_auto_global(zend_string *name, bool jit, zend_auto_global_callback auto_global_callback);
886 ZEND_API void zend_activate_auto_globals(void);
887 ZEND_API bool zend_is_auto_global(zend_string *name);
888 ZEND_API bool zend_is_auto_global_str(const char *name, size_t len);
889 ZEND_API size_t zend_dirname(char *path, size_t len);
890 ZEND_API void zend_set_function_arg_flags(zend_function *func);
891 
892 int ZEND_FASTCALL zendlex(zend_parser_stack_elem *elem);
893 
894 void zend_assert_valid_class_name(const zend_string *const_name);
895 
896 zend_string *zend_type_to_string_resolved(zend_type type, zend_class_entry *scope);
897 ZEND_API zend_string *zend_type_to_string(zend_type type);
898 
899 /* BEGIN: OPCODES */
900 
901 #include "zend_vm_opcodes.h"
902 
903 /* END: OPCODES */
904 
905 /* class fetches */
906 #define ZEND_FETCH_CLASS_DEFAULT	0
907 #define ZEND_FETCH_CLASS_SELF		1
908 #define ZEND_FETCH_CLASS_PARENT		2
909 #define ZEND_FETCH_CLASS_STATIC		3
910 #define ZEND_FETCH_CLASS_AUTO		4
911 #define ZEND_FETCH_CLASS_INTERFACE	5
912 #define ZEND_FETCH_CLASS_TRAIT		6
913 #define ZEND_FETCH_CLASS_MASK        0x0f
914 #define ZEND_FETCH_CLASS_NO_AUTOLOAD 0x80
915 #define ZEND_FETCH_CLASS_SILENT      0x0100
916 #define ZEND_FETCH_CLASS_EXCEPTION   0x0200
917 #define ZEND_FETCH_CLASS_ALLOW_UNLINKED 0x0400
918 #define ZEND_FETCH_CLASS_ALLOW_NEARLY_LINKED 0x0800
919 
920 /* These should not clash with ZEND_ACC_(PUBLIC|PROTECTED|PRIVATE) */
921 #define ZEND_PARAM_REF      (1<<3)
922 #define ZEND_PARAM_VARIADIC (1<<4)
923 
924 #define ZEND_NAME_FQ       0
925 #define ZEND_NAME_NOT_FQ   1
926 #define ZEND_NAME_RELATIVE 2
927 
928 #define ZEND_TYPE_NULLABLE (1<<8)
929 
930 #define ZEND_ARRAY_SYNTAX_LIST 1  /* list() */
931 #define ZEND_ARRAY_SYNTAX_LONG 2  /* array() */
932 #define ZEND_ARRAY_SYNTAX_SHORT 3 /* [] */
933 
934 /* var status for backpatching */
935 #define BP_VAR_R			0
936 #define BP_VAR_W			1
937 #define BP_VAR_RW			2
938 #define BP_VAR_IS			3
939 #define BP_VAR_FUNC_ARG		4
940 #define BP_VAR_UNSET		5
941 
942 #define ZEND_INTERNAL_FUNCTION		1
943 #define ZEND_USER_FUNCTION			2
944 #define ZEND_EVAL_CODE				4
945 
946 #define ZEND_USER_CODE(type)		((type) != ZEND_INTERNAL_FUNCTION)
947 
948 #define ZEND_INTERNAL_CLASS         1
949 #define ZEND_USER_CLASS             2
950 
951 #define ZEND_EVAL				(1<<0)
952 #define ZEND_INCLUDE			(1<<1)
953 #define ZEND_INCLUDE_ONCE		(1<<2)
954 #define ZEND_REQUIRE			(1<<3)
955 #define ZEND_REQUIRE_ONCE		(1<<4)
956 
957 /* global/local fetches */
958 #define ZEND_FETCH_GLOBAL		(1<<1)
959 #define ZEND_FETCH_LOCAL		(1<<2)
960 #define ZEND_FETCH_GLOBAL_LOCK	(1<<3)
961 
962 #define ZEND_FETCH_TYPE_MASK	0xe
963 
964 /* Only one of these can ever be in use */
965 #define ZEND_FETCH_REF			1
966 #define ZEND_FETCH_DIM_WRITE	2
967 #define ZEND_FETCH_OBJ_FLAGS	3
968 
969 #define ZEND_ISEMPTY			(1<<0)
970 
971 #define ZEND_LAST_CATCH			(1<<0)
972 
973 #define ZEND_FREE_ON_RETURN     (1<<0)
974 #define ZEND_FREE_SWITCH        (1<<1)
975 
976 #define ZEND_SEND_BY_VAL     0u
977 #define ZEND_SEND_BY_REF     1u
978 #define ZEND_SEND_PREFER_REF 2u
979 
980 #define ZEND_THROW_IS_EXPR 1u
981 
982 #define ZEND_FCALL_MAY_HAVE_EXTRA_NAMED_PARAMS 1
983 
984 /* The send mode and is_variadic flag are stored as part of zend_type */
985 #define _ZEND_SEND_MODE_SHIFT _ZEND_TYPE_EXTRA_FLAGS_SHIFT
986 #define _ZEND_IS_VARIADIC_BIT (1 << (_ZEND_TYPE_EXTRA_FLAGS_SHIFT + 2))
987 #define _ZEND_IS_PROMOTED_BIT (1 << (_ZEND_TYPE_EXTRA_FLAGS_SHIFT + 3))
988 #define ZEND_ARG_SEND_MODE(arg_info) \
989 	((ZEND_TYPE_FULL_MASK((arg_info)->type) >> _ZEND_SEND_MODE_SHIFT) & 3)
990 #define ZEND_ARG_IS_VARIADIC(arg_info) \
991 	((ZEND_TYPE_FULL_MASK((arg_info)->type) & _ZEND_IS_VARIADIC_BIT) != 0)
992 #define ZEND_ARG_IS_PROMOTED(arg_info) \
993 	((ZEND_TYPE_FULL_MASK((arg_info)->type) & _ZEND_IS_PROMOTED_BIT) != 0)
994 
995 #define ZEND_DIM_IS					(1 << 0) /* isset fetch needed for null coalesce */
996 #define ZEND_DIM_ALTERNATIVE_SYNTAX	(1 << 1) /* deprecated curly brace usage */
997 
998 /* Make sure these don't clash with ZEND_FETCH_CLASS_* flags. */
999 #define IS_CONSTANT_CLASS                    0x400 /* __CLASS__ in trait */
1000 #define IS_CONSTANT_UNQUALIFIED_IN_NAMESPACE 0x800
1001 
1002 static zend_always_inline bool zend_check_arg_send_type(const zend_function *zf, uint32_t arg_num, uint32_t mask)
1003 {
1004 	arg_num--;
1005 	if (UNEXPECTED(arg_num >= zf->common.num_args)) {
1006 		if (EXPECTED((zf->common.fn_flags & ZEND_ACC_VARIADIC) == 0)) {
1007 			return 0;
1008 		}
1009 		arg_num = zf->common.num_args;
1010 	}
1011 	return UNEXPECTED((ZEND_ARG_SEND_MODE(&zf->common.arg_info[arg_num]) & mask) != 0);
1012 }
1013 
1014 #define ARG_MUST_BE_SENT_BY_REF(zf, arg_num) \
1015 	zend_check_arg_send_type(zf, arg_num, ZEND_SEND_BY_REF)
1016 
1017 #define ARG_SHOULD_BE_SENT_BY_REF(zf, arg_num) \
1018 	zend_check_arg_send_type(zf, arg_num, ZEND_SEND_BY_REF|ZEND_SEND_PREFER_REF)
1019 
1020 #define ARG_MAY_BE_SENT_BY_REF(zf, arg_num) \
1021 	zend_check_arg_send_type(zf, arg_num, ZEND_SEND_PREFER_REF)
1022 
1023 /* Quick API to check first 12 arguments */
1024 #define MAX_ARG_FLAG_NUM 12
1025 
1026 #ifdef WORDS_BIGENDIAN
1027 # define ZEND_SET_ARG_FLAG(zf, arg_num, mask) do { \
1028 		(zf)->quick_arg_flags |= ((mask) << ((arg_num) - 1) * 2); \
1029 	} while (0)
1030 # define ZEND_CHECK_ARG_FLAG(zf, arg_num, mask) \
1031 	(((zf)->quick_arg_flags >> (((arg_num) - 1) * 2)) & (mask))
1032 #else
1033 # define ZEND_SET_ARG_FLAG(zf, arg_num, mask) do { \
1034 		(zf)->quick_arg_flags |= (((mask) << 6) << (arg_num) * 2); \
1035 	} while (0)
1036 # define ZEND_CHECK_ARG_FLAG(zf, arg_num, mask) \
1037 	(((zf)->quick_arg_flags >> (((arg_num) + 3) * 2)) & (mask))
1038 #endif
1039 
1040 #define QUICK_ARG_MUST_BE_SENT_BY_REF(zf, arg_num) \
1041 	ZEND_CHECK_ARG_FLAG(zf, arg_num, ZEND_SEND_BY_REF)
1042 
1043 #define QUICK_ARG_SHOULD_BE_SENT_BY_REF(zf, arg_num) \
1044 	ZEND_CHECK_ARG_FLAG(zf, arg_num, ZEND_SEND_BY_REF|ZEND_SEND_PREFER_REF)
1045 
1046 #define QUICK_ARG_MAY_BE_SENT_BY_REF(zf, arg_num) \
1047 	ZEND_CHECK_ARG_FLAG(zf, arg_num, ZEND_SEND_PREFER_REF)
1048 
1049 #define ZEND_RETURN_VAL 0
1050 #define ZEND_RETURN_REF 1
1051 
1052 #define ZEND_BIND_VAL      0
1053 #define ZEND_BIND_REF      1
1054 #define ZEND_BIND_IMPLICIT 2
1055 
1056 #define ZEND_RETURNS_FUNCTION (1<<0)
1057 #define ZEND_RETURNS_VALUE    (1<<1)
1058 
1059 #define ZEND_ARRAY_ELEMENT_REF		(1<<0)
1060 #define ZEND_ARRAY_NOT_PACKED		(1<<1)
1061 #define ZEND_ARRAY_SIZE_SHIFT		2
1062 
1063 /* Attribute for ternary inside parentheses */
1064 #define ZEND_PARENTHESIZED_CONDITIONAL 1
1065 
1066 /* For "use" AST nodes and the seen symbol table */
1067 #define ZEND_SYMBOL_CLASS    (1<<0)
1068 #define ZEND_SYMBOL_FUNCTION (1<<1)
1069 #define ZEND_SYMBOL_CONST    (1<<2)
1070 
1071 /* All increment opcodes are even (decrement are odd) */
1072 #define ZEND_IS_INCREMENT(opcode) (((opcode) & 1) == 0)
1073 
1074 #define ZEND_IS_BINARY_ASSIGN_OP_OPCODE(opcode) \
1075 	(((opcode) >= ZEND_ADD) && ((opcode) <= ZEND_POW))
1076 
1077 /* Pseudo-opcodes that are used only temporarily during compilation */
1078 #define ZEND_GOTO  253
1079 #define ZEND_BRK   254
1080 #define ZEND_CONT  255
1081 
1082 
1083 END_EXTERN_C()
1084 
1085 #define ZEND_CLONE_FUNC_NAME		"__clone"
1086 #define ZEND_CONSTRUCTOR_FUNC_NAME	"__construct"
1087 #define ZEND_DESTRUCTOR_FUNC_NAME	"__destruct"
1088 #define ZEND_GET_FUNC_NAME          "__get"
1089 #define ZEND_SET_FUNC_NAME          "__set"
1090 #define ZEND_UNSET_FUNC_NAME        "__unset"
1091 #define ZEND_ISSET_FUNC_NAME        "__isset"
1092 #define ZEND_CALL_FUNC_NAME         "__call"
1093 #define ZEND_CALLSTATIC_FUNC_NAME   "__callstatic"
1094 #define ZEND_TOSTRING_FUNC_NAME     "__tostring"
1095 #define ZEND_INVOKE_FUNC_NAME       "__invoke"
1096 #define ZEND_DEBUGINFO_FUNC_NAME    "__debuginfo"
1097 
1098 /* The following constants may be combined in CG(compiler_options)
1099  * to change the default compiler behavior */
1100 
1101 /* generate extended debug information */
1102 #define ZEND_COMPILE_EXTENDED_STMT              (1<<0)
1103 #define ZEND_COMPILE_EXTENDED_FCALL             (1<<1)
1104 #define ZEND_COMPILE_EXTENDED_INFO              (ZEND_COMPILE_EXTENDED_STMT|ZEND_COMPILE_EXTENDED_FCALL)
1105 
1106 /* call op_array handler of extensions */
1107 #define ZEND_COMPILE_HANDLE_OP_ARRAY            (1<<2)
1108 
1109 /* generate ZEND_INIT_FCALL_BY_NAME for internal functions instead of ZEND_INIT_FCALL */
1110 #define ZEND_COMPILE_IGNORE_INTERNAL_FUNCTIONS  (1<<3)
1111 
1112 /* don't perform early binding for classes inherited form internal ones;
1113  * in namespaces assume that internal class that doesn't exist at compile-time
1114  * may appear in run-time */
1115 #define ZEND_COMPILE_IGNORE_INTERNAL_CLASSES    (1<<4)
1116 
1117 /* generate ZEND_DECLARE_CLASS_DELAYED opcode to delay early binding */
1118 #define ZEND_COMPILE_DELAYED_BINDING            (1<<5)
1119 
1120 /* disable constant substitution at compile-time */
1121 #define ZEND_COMPILE_NO_CONSTANT_SUBSTITUTION   (1<<6)
1122 
1123 /* disable substitution of persistent constants at compile-time */
1124 #define ZEND_COMPILE_NO_PERSISTENT_CONSTANT_SUBSTITUTION	(1<<8)
1125 
1126 /* generate ZEND_INIT_FCALL_BY_NAME for userland functions instead of ZEND_INIT_FCALL */
1127 #define ZEND_COMPILE_IGNORE_USER_FUNCTIONS      (1<<9)
1128 
1129 /* force ZEND_ACC_USE_GUARDS for all classes */
1130 #define ZEND_COMPILE_GUARDS						(1<<10)
1131 
1132 /* disable builtin special case function calls */
1133 #define ZEND_COMPILE_NO_BUILTINS				(1<<11)
1134 
1135 /* result of compilation may be stored in file cache */
1136 #define ZEND_COMPILE_WITH_FILE_CACHE			(1<<12)
1137 
1138 /* ignore functions and classes declared in other files */
1139 #define ZEND_COMPILE_IGNORE_OTHER_FILES			(1<<13)
1140 
1141 /* this flag is set when compiler invoked by opcache_compile_file() */
1142 #define ZEND_COMPILE_WITHOUT_EXECUTION          (1<<14)
1143 
1144 /* this flag is set when compiler invoked during preloading */
1145 #define ZEND_COMPILE_PRELOAD                    (1<<15)
1146 
1147 /* disable jumptable optimization for switch statements */
1148 #define ZEND_COMPILE_NO_JUMPTABLES				(1<<16)
1149 
1150 /* this flag is set when compiler invoked during preloading in separate process */
1151 #define ZEND_COMPILE_PRELOAD_IN_CHILD           (1<<17)
1152 
1153 /* The default value for CG(compiler_options) */
1154 #define ZEND_COMPILE_DEFAULT					ZEND_COMPILE_HANDLE_OP_ARRAY
1155 
1156 /* The default value for CG(compiler_options) during eval() */
1157 #define ZEND_COMPILE_DEFAULT_FOR_EVAL			0
1158 
1159 ZEND_API bool zend_binary_op_produces_error(uint32_t opcode, zval *op1, zval *op2);
1160 
1161 #endif /* ZEND_COMPILE_H */
1162