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