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