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