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