1/*
2   +----------------------------------------------------------------------+
3   | Zend Engine                                                          |
4   +----------------------------------------------------------------------+
5   | Copyright (c) 1998-2014 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@zend.com>                                |
16   |          Zeev Suraski <zeev@zend.com>                                |
17   +----------------------------------------------------------------------+
18*/
19
20/* $Id$ */
21
22#ifndef ZEND_COMPILE_H
23#define ZEND_COMPILE_H
24
25#include "zend.h"
26#include "zend_ast.h"
27
28#ifdef HAVE_STDARG_H
29# include <stdarg.h>
30#endif
31
32#include "zend_llist.h"
33
34#define DEBUG_ZEND 0
35
36#define SET_UNUSED(op)  op ## _type = IS_UNUSED
37
38#define RESET_DOC_COMMENT() do { \
39    if (CG(doc_comment)) { \
40        zend_string_release(CG(doc_comment)); \
41        CG(doc_comment) = NULL; \
42    } \
43} while (0)
44
45typedef struct _zend_op_array zend_op_array;
46typedef struct _zend_op zend_op;
47
48typedef struct _zend_compiler_context {
49    uint32_t  opcodes_size;
50    int        vars_size;
51    int        literals_size;
52    int        current_brk_cont;
53    int        backpatch_count;
54    int        in_finally;
55    uint32_t   fast_call_var;
56    HashTable *labels;
57} zend_compiler_context;
58
59typedef union _znode_op {
60    uint32_t      constant;
61    uint32_t      var;
62    uint32_t      num;
63    uint32_t      opline_num; /*  Needs to be signed */
64    zend_op       *jmp_addr;
65    zval          *zv;
66} znode_op;
67
68typedef struct _znode { /* used only during compilation */
69    int op_type;
70    union {
71        znode_op op;
72        zval constant; /* replaced by literal/zv */
73    } u;
74} znode;
75
76/* Temporarily defined here, to avoid header ordering issues */
77typedef struct _zend_ast_znode {
78    zend_ast_kind kind;
79    zend_ast_attr attr;
80    uint32_t lineno;
81    znode node;
82} zend_ast_znode;
83ZEND_API zend_ast *zend_ast_create_znode(znode *node);
84
85static zend_always_inline znode *zend_ast_get_znode(zend_ast *ast) {
86    return &((zend_ast_znode *) ast)->node;
87}
88
89typedef union _zend_parser_stack_elem {
90    zend_ast *ast;
91    zend_string *str;
92    zend_ulong num;
93} zend_parser_stack_elem;
94
95void zend_compile_top_stmt(zend_ast *ast TSRMLS_DC);
96void zend_compile_stmt(zend_ast *ast TSRMLS_DC);
97void zend_compile_expr(znode *node, zend_ast *ast TSRMLS_DC);
98void zend_compile_var(znode *node, zend_ast *ast, uint32_t type TSRMLS_DC);
99void zend_eval_const_expr(zend_ast **ast_ptr TSRMLS_DC);
100void zend_const_expr_to_zval(zval *result, zend_ast *ast TSRMLS_DC);
101
102#define ZEND_OPCODE_HANDLER_ARGS zend_execute_data *execute_data TSRMLS_DC
103#define ZEND_OPCODE_HANDLER_ARGS_PASSTHRU execute_data TSRMLS_CC
104
105typedef int (*user_opcode_handler_t) (ZEND_OPCODE_HANDLER_ARGS);
106typedef int (ZEND_FASTCALL *opcode_handler_t) (ZEND_OPCODE_HANDLER_ARGS);
107
108extern ZEND_API opcode_handler_t *zend_opcode_handlers;
109
110struct _zend_op {
111    opcode_handler_t handler;
112    znode_op op1;
113    znode_op op2;
114    znode_op result;
115    zend_ulong extended_value;
116    uint lineno;
117    zend_uchar opcode;
118    zend_uchar op1_type;
119    zend_uchar op2_type;
120    zend_uchar result_type;
121};
122
123
124typedef struct _zend_brk_cont_element {
125    int start;
126    int cont;
127    int brk;
128    int parent;
129} zend_brk_cont_element;
130
131typedef struct _zend_label {
132    int brk_cont;
133    uint32_t opline_num;
134} zend_label;
135
136typedef struct _zend_try_catch_element {
137    uint32_t try_op;
138    uint32_t catch_op;  /* ketchup! */
139    uint32_t finally_op;
140    uint32_t finally_end;
141} zend_try_catch_element;
142
143#if SIZEOF_ZEND_LONG == 8
144# ifdef _WIN32
145#  define THIS_HASHVAL 6385726429Ui64
146# else
147#  define THIS_HASHVAL 6385726429ULL
148# endif
149#else
150#define THIS_HASHVAL 2090759133UL
151#endif
152
153/* method flags (types) */
154#define ZEND_ACC_STATIC         0x01
155#define ZEND_ACC_ABSTRACT       0x02
156#define ZEND_ACC_FINAL          0x04
157#define ZEND_ACC_IMPLEMENTED_ABSTRACT       0x08
158
159/* class flags (types) */
160/* ZEND_ACC_IMPLICIT_ABSTRACT_CLASS is used for abstract classes (since it is set by any abstract method even interfaces MAY have it set, too). */
161/* ZEND_ACC_EXPLICIT_ABSTRACT_CLASS denotes that a class was explicitly defined as abstract by using the keyword. */
162#define ZEND_ACC_IMPLICIT_ABSTRACT_CLASS    0x10
163#define ZEND_ACC_EXPLICIT_ABSTRACT_CLASS    0x20
164#define ZEND_ACC_FINAL_CLASS                0x40
165#define ZEND_ACC_INTERFACE                  0x80
166#define ZEND_ACC_TRAIT                      0x120
167
168/* method flags (visibility) */
169/* The order of those must be kept - public < protected < private */
170#define ZEND_ACC_PUBLIC     0x100
171#define ZEND_ACC_PROTECTED  0x200
172#define ZEND_ACC_PRIVATE    0x400
173#define ZEND_ACC_PPP_MASK  (ZEND_ACC_PUBLIC | ZEND_ACC_PROTECTED | ZEND_ACC_PRIVATE)
174
175#define ZEND_ACC_CHANGED    0x800
176#define ZEND_ACC_IMPLICIT_PUBLIC    0x1000
177
178/* method flags (special method detection) */
179#define ZEND_ACC_CTOR       0x2000
180#define ZEND_ACC_DTOR       0x4000
181#define ZEND_ACC_CLONE      0x8000
182
183/* method flag (bc only), any method that has this flag can be used statically and non statically. */
184#define ZEND_ACC_ALLOW_STATIC   0x10000
185
186/* shadow of parent's private method/property */
187#define ZEND_ACC_SHADOW 0x20000
188
189/* deprecation flag */
190#define ZEND_ACC_DEPRECATED 0x40000
191
192/* class implement interface(s) flag */
193#define ZEND_ACC_IMPLEMENT_INTERFACES 0x80000
194#define ZEND_ACC_IMPLEMENT_TRAITS     0x400000
195
196/* class constants updated */
197#define ZEND_ACC_CONSTANTS_UPDATED    0x100000
198
199/* user class has methods with static variables */
200#define ZEND_HAS_STATIC_IN_METHODS    0x800000
201
202
203#define ZEND_ACC_CLOSURE              0x100000
204#define ZEND_ACC_GENERATOR            0x800000
205
206/* function flag for internal user call handlers __call, __callstatic */
207#define ZEND_ACC_CALL_VIA_HANDLER     0x200000
208
209/* disable inline caching */
210#define ZEND_ACC_NEVER_CACHE          0x400000
211
212#define ZEND_ACC_VARIADIC               0x1000000
213
214#define ZEND_ACC_RETURN_REFERENCE       0x4000000
215#define ZEND_ACC_DONE_PASS_TWO          0x8000000
216
217/* function has arguments with type hinting */
218#define ZEND_ACC_HAS_TYPE_HINTS         0x10000000
219
220/* op_array has finally blocks */
221#define ZEND_ACC_HAS_FINALLY_BLOCK      0x20000000
222
223/* internal function is allocated at arena */
224#define ZEND_ACC_ARENA_ALLOCATED        0x20000000
225
226#define ZEND_CE_IS_TRAIT(ce) (((ce)->ce_flags & ZEND_ACC_TRAIT) == ZEND_ACC_TRAIT)
227
228char *zend_visibility_string(uint32_t fn_flags);
229
230typedef struct _zend_property_info {
231    uint32_t offset; /* property offset for object properties or
232                          property index for static properties */
233    uint32_t flags;
234    zend_string *name;
235    zend_string *doc_comment;
236    zend_class_entry *ce;
237} zend_property_info;
238
239#define OBJ_PROP(obj, offset) \
240    ((zval*)((char*)(obj) + offset))
241#define OBJ_PROP_NUM(obj, num) \
242    (&(obj)->properties_table[(num)])
243#define OBJ_PROP_TO_OFFSET(num) \
244    ((uint32_t)(zend_uintptr_t)OBJ_PROP_NUM(((zend_object*)NULL), num))
245#define OBJ_PROP_TO_NUM(offset) \
246    ((offset - OBJ_PROP_TO_OFFSET(0)) / sizeof(zval))
247
248typedef struct _zend_arg_info {
249    const char *name;           // TODO: convert into zend_string ???
250    uint32_t name_len;
251    const char *class_name;     // TODO: convert into zend_string ???
252    uint32_t class_name_len;
253    zend_uchar type_hint;
254    zend_uchar pass_by_reference;
255    zend_bool allow_null;
256    zend_bool is_variadic;
257} zend_arg_info;
258
259/* the following structure repeats the layout of zend_arg_info,
260 * but its fields have different meaning. It's used as the first element of
261 * arg_info array to define properties of internal functions.
262 */
263typedef struct _zend_internal_function_info {
264    const char *_name;
265    uint32_t _name_len;
266    const char *_class_name;
267    uint32_t required_num_args;
268    zend_uchar _type_hint;
269    zend_bool return_reference;
270    zend_bool _allow_null;
271    zend_bool _is_variadic;
272} zend_internal_function_info;
273
274struct _zend_op_array {
275    /* Common elements */
276    zend_uchar type;
277    uint32_t fn_flags;
278    zend_string *function_name;
279    zend_class_entry *scope;
280    zend_function *prototype;
281    uint32_t num_args;
282    uint32_t required_num_args;
283    zend_arg_info *arg_info;
284    /* END of common elements */
285
286    uint32_t *refcount;
287
288    uint32_t this_var;
289
290    uint32_t last;
291    zend_op *opcodes;
292
293    int last_var;
294    uint32_t T;
295    zend_string **vars;
296
297    int last_brk_cont;
298    int last_try_catch;
299    zend_brk_cont_element *brk_cont_array;
300    zend_try_catch_element *try_catch_array;
301
302    /* static variables support */
303    HashTable *static_variables;
304
305    zend_string *filename;
306    uint32_t line_start;
307    uint32_t line_end;
308    zend_string *doc_comment;
309    uint32_t early_binding; /* the linked list of delayed declarations */
310
311    int last_literal;
312    zval *literals;
313
314    int  last_cache_slot;
315    void **run_time_cache;
316
317    void *reserved[ZEND_MAX_RESERVED_RESOURCES];
318};
319
320
321#define ZEND_RETURN_VALUE               0
322#define ZEND_RETURN_REFERENCE           1
323
324typedef struct _zend_internal_function {
325    /* Common elements */
326    zend_uchar type;
327    uint32_t fn_flags;
328    zend_string* function_name;
329    zend_class_entry *scope;
330    zend_function *prototype;
331    uint32_t num_args;
332    uint32_t required_num_args;
333    zend_arg_info *arg_info;
334    /* END of common elements */
335
336    void (*handler)(INTERNAL_FUNCTION_PARAMETERS);
337    struct _zend_module_entry *module;
338} zend_internal_function;
339
340#define ZEND_FN_SCOPE_NAME(function)  ((function) && (function)->common.scope ? (function)->common.scope->name->val : "")
341
342union _zend_function {
343    zend_uchar type;    /* MUST be the first element of this struct! */
344
345    struct {
346        zend_uchar type;  /* never used */
347        uint32_t fn_flags;
348        zend_string *function_name;
349        zend_class_entry *scope;
350        union _zend_function *prototype;
351        uint32_t num_args;
352        uint32_t required_num_args;
353        zend_arg_info *arg_info;
354    } common;
355
356    zend_op_array op_array;
357    zend_internal_function internal_function;
358};
359
360typedef enum _vm_frame_kind {
361    VM_FRAME_NESTED_FUNCTION,   /* stackless VM call to function */
362    VM_FRAME_NESTED_CODE,       /* stackless VM call to include/require/eval */
363    VM_FRAME_TOP_FUNCTION,      /* direct VM call to function from external C code */
364    VM_FRAME_TOP_CODE           /* direct VM call to "main" code from external C code */
365} vm_frame_kind;
366
367struct _zend_execute_data {
368    const zend_op       *opline;           /* executed opline                */
369    zend_execute_data   *call;             /* current call                   */
370    void               **run_time_cache;
371    zend_function       *func;             /* executed op_array              */
372    zval                 This;
373    zend_class_entry    *called_scope;
374    zend_execute_data   *prev_execute_data;
375    uint32_t             frame_info;
376    uint32_t             num_args;
377    zval                *return_value;
378    zend_class_entry    *scope;            /* function scope (self)          */
379    zend_array          *symbol_table;
380};
381
382#define VM_FRAME_KIND_MASK           0x000000ff
383#define VM_FRAME_FLAGS_MASK          0xffffff00
384
385#define ZEND_CALL_CTOR               (1 << 8)
386#define ZEND_CALL_CTOR_RESULT_UNUSED (1 << 9)
387
388#define VM_FRAME_INFO(kind, flags)   ((kind) | (flags))
389#define VM_FRAME_KIND(info)          ((info) & VM_FRAME_KIND_MASK)
390#define VM_FRAME_FLAGS(info)         ((info) & VM_FRAME_FLAGS_MASK)
391
392#define ZEND_CALL_FRAME_SLOT \
393    ((ZEND_MM_ALIGNED_SIZE(sizeof(zend_execute_data)) + ZEND_MM_ALIGNED_SIZE(sizeof(zval)) - 1) / ZEND_MM_ALIGNED_SIZE(sizeof(zval)))
394
395#define ZEND_CALL_ARG(call, n) \
396    (((zval*)(call)) + ((n) + (ZEND_CALL_FRAME_SLOT - 1)))
397
398#define EX(element)             ((execute_data)->element)
399
400#define EX_VAR_2(ex, n)         ((zval*)(((char*)(ex)) + ((int)(n))))
401#define EX_VAR_NUM_2(ex, n)     (((zval*)(ex)) + (ZEND_CALL_FRAME_SLOT + ((int)(n))))
402
403#define EX_VAR(n)               EX_VAR_2(execute_data, n)
404#define EX_VAR_NUM(n)           EX_VAR_NUM_2(execute_data, n)
405
406#define EX_VAR_TO_NUM(n)        (EX_VAR_2(NULL, n) - EX_VAR_NUM_2(NULL, 0))
407
408#define IS_CONST    (1<<0)
409#define IS_TMP_VAR  (1<<1)
410#define IS_VAR      (1<<2)
411#define IS_UNUSED   (1<<3)  /* Unused variable */
412#define IS_CV       (1<<4)  /* Compiled variable */
413
414#define EXT_TYPE_UNUSED (1<<5)
415
416#include "zend_globals.h"
417
418BEGIN_EXTERN_C()
419
420void init_compiler(TSRMLS_D);
421void shutdown_compiler(TSRMLS_D);
422void zend_init_compiler_data_structures(TSRMLS_D);
423void zend_init_compiler_context(TSRMLS_D);
424
425extern ZEND_API zend_op_array *(*zend_compile_file)(zend_file_handle *file_handle, int type TSRMLS_DC);
426extern ZEND_API zend_op_array *(*zend_compile_string)(zval *source_string, char *filename TSRMLS_DC);
427
428ZEND_API int lex_scan(zval *zendlval TSRMLS_DC);
429void startup_scanner(TSRMLS_D);
430void shutdown_scanner(TSRMLS_D);
431
432ZEND_API zend_string *zend_set_compiled_filename(zend_string *new_compiled_filename TSRMLS_DC);
433ZEND_API void zend_restore_compiled_filename(zend_string *original_compiled_filename TSRMLS_DC);
434ZEND_API zend_string *zend_get_compiled_filename(TSRMLS_D);
435ZEND_API int zend_get_compiled_lineno(TSRMLS_D);
436ZEND_API size_t zend_get_scanned_file_offset(TSRMLS_D);
437
438ZEND_API zend_string *zend_get_compiled_variable_name(const zend_op_array *op_array, uint32_t var);
439
440#ifdef ZTS
441const char *zend_get_zendtext(TSRMLS_D);
442int zend_get_zendleng(TSRMLS_D);
443#endif
444
445
446typedef int (*unary_op_type)(zval *, zval * TSRMLS_DC);
447typedef int (*binary_op_type)(zval *, zval *, zval * TSRMLS_DC);
448ZEND_API unary_op_type get_unary_op(int opcode);
449ZEND_API binary_op_type get_binary_op(int opcode);
450
451void zend_stop_lexing(TSRMLS_D);
452void zend_emit_final_return(zval *zv TSRMLS_DC);
453zend_ast *zend_ast_append_str(zend_ast *left, zend_ast *right);
454uint32_t zend_add_member_modifier(uint32_t flags, uint32_t new_flag);
455zend_ast *zend_ast_append_doc_comment(zend_ast *list TSRMLS_DC);
456void zend_handle_encoding_declaration(zend_ast *ast TSRMLS_DC);
457
458/* parser-driven code generators */
459void zend_do_free(znode *op1 TSRMLS_DC);
460
461ZEND_API int do_bind_function(const zend_op_array *op_array, const zend_op *opline, HashTable *function_table, zend_bool compile_time TSRMLS_DC);
462ZEND_API zend_class_entry *do_bind_class(const zend_op_array *op_array, const zend_op *opline, HashTable *class_table, zend_bool compile_time TSRMLS_DC);
463ZEND_API zend_class_entry *do_bind_inherited_class(const zend_op_array *op_array, const zend_op *opline, HashTable *class_table, zend_class_entry *parent_ce, zend_bool compile_time TSRMLS_DC);
464ZEND_API void zend_do_delayed_early_binding(const zend_op_array *op_array TSRMLS_DC);
465
466/* Functions for a null terminated pointer list, used for traits parsing and compilation */
467void zend_init_list(void *result, void *item TSRMLS_DC);
468void zend_add_to_list(void *result, void *item TSRMLS_DC);
469
470void zend_do_extended_info(TSRMLS_D);
471void zend_do_extended_fcall_begin(TSRMLS_D);
472void zend_do_extended_fcall_end(TSRMLS_D);
473
474void zend_verify_namespace(TSRMLS_D);
475void zend_do_end_compilation(TSRMLS_D);
476
477void zend_resolve_goto_label(zend_op_array *op_array, zend_op *opline, int pass2 TSRMLS_DC);
478void zend_release_labels(int temporary TSRMLS_DC);
479
480ZEND_API void function_add_ref(zend_function *function);
481
482#define INITIAL_OP_ARRAY_SIZE 64
483
484
485/* helper functions in zend_language_scanner.l */
486ZEND_API zend_op_array *compile_file(zend_file_handle *file_handle, int type TSRMLS_DC);
487ZEND_API zend_op_array *compile_string(zval *source_string, char *filename TSRMLS_DC);
488ZEND_API zend_op_array *compile_filename(int type, zval *filename TSRMLS_DC);
489ZEND_API int zend_execute_scripts(int type TSRMLS_DC, zval *retval, int file_count, ...);
490ZEND_API int open_file_for_scanning(zend_file_handle *file_handle TSRMLS_DC);
491ZEND_API void init_op_array(zend_op_array *op_array, zend_uchar type, int initial_ops_size TSRMLS_DC);
492ZEND_API void destroy_op_array(zend_op_array *op_array TSRMLS_DC);
493ZEND_API void zend_destroy_file_handle(zend_file_handle *file_handle TSRMLS_DC);
494ZEND_API void zend_cleanup_user_class_data(zend_class_entry *ce TSRMLS_DC);
495ZEND_API void zend_cleanup_internal_class_data(zend_class_entry *ce TSRMLS_DC);
496ZEND_API void zend_cleanup_internal_classes(TSRMLS_D);
497ZEND_API void zend_cleanup_op_array_data(zend_op_array *op_array);
498ZEND_API int clean_non_persistent_function_full(zval *zv TSRMLS_DC);
499ZEND_API int clean_non_persistent_class_full(zval *zv TSRMLS_DC);
500
501ZEND_API void destroy_zend_function(zend_function *function TSRMLS_DC);
502ZEND_API void zend_function_dtor(zval *zv);
503ZEND_API void destroy_zend_class(zval *zv);
504void zend_class_add_ref(zval *zv);
505
506ZEND_API zend_string *zend_mangle_property_name(const char *src1, size_t src1_length, const char *src2, size_t src2_length, int internal);
507#define zend_unmangle_property_name(mangled_property, class_name, prop_name) \
508        zend_unmangle_property_name_ex(mangled_property, class_name, prop_name, NULL)
509ZEND_API int zend_unmangle_property_name_ex(const zend_string *name, const char **class_name, const char **prop_name, size_t *prop_len);
510
511#define ZEND_FUNCTION_DTOR zend_function_dtor
512#define ZEND_CLASS_DTOR destroy_zend_class
513
514zend_op *get_next_op(zend_op_array *op_array TSRMLS_DC);
515void init_op(zend_op *op TSRMLS_DC);
516int get_next_op_number(zend_op_array *op_array);
517int print_class(zend_class_entry *class_entry TSRMLS_DC);
518void print_op_array(zend_op_array *op_array, int optimizations);
519ZEND_API int pass_two(zend_op_array *op_array TSRMLS_DC);
520zend_brk_cont_element *get_next_brk_cont_element(zend_op_array *op_array);
521ZEND_API zend_bool zend_is_compiling(TSRMLS_D);
522ZEND_API char *zend_make_compiled_string_description(const char *name TSRMLS_DC);
523ZEND_API void zend_initialize_class_data(zend_class_entry *ce, zend_bool nullify_handlers TSRMLS_DC);
524uint32_t zend_get_class_fetch_type(zend_string *name);
525
526typedef zend_bool (*zend_auto_global_callback)(zend_string *name TSRMLS_DC);
527typedef struct _zend_auto_global {
528    zend_string *name;
529    zend_auto_global_callback auto_global_callback;
530    zend_bool jit;
531    zend_bool armed;
532} zend_auto_global;
533
534ZEND_API int zend_register_auto_global(zend_string *name, zend_bool jit, zend_auto_global_callback auto_global_callback TSRMLS_DC);
535ZEND_API void zend_activate_auto_globals(TSRMLS_D);
536ZEND_API zend_bool zend_is_auto_global(zend_string *name TSRMLS_DC);
537ZEND_API size_t zend_dirname(char *path, size_t len);
538
539int zendlex(zend_parser_stack_elem *elem TSRMLS_DC);
540
541int zend_add_literal(zend_op_array *op_array, zval *zv TSRMLS_DC);
542
543/* BEGIN: OPCODES */
544
545#include "zend_vm_opcodes.h"
546
547#define ZEND_OP_DATA                137
548
549/* END: OPCODES */
550
551/* class fetches */
552#define ZEND_FETCH_CLASS_DEFAULT    0
553#define ZEND_FETCH_CLASS_SELF       1
554#define ZEND_FETCH_CLASS_PARENT     2
555#define ZEND_FETCH_CLASS_STATIC     3
556#define ZEND_FETCH_CLASS_AUTO       4
557#define ZEND_FETCH_CLASS_INTERFACE  5
558#define ZEND_FETCH_CLASS_TRAIT      6
559#define ZEND_FETCH_CLASS_MASK        0x0f
560#define ZEND_FETCH_CLASS_NO_AUTOLOAD 0x80
561#define ZEND_FETCH_CLASS_SILENT      0x0100
562
563/* variable parsing type (compile-time) */
564#define ZEND_PARSED_MEMBER              (1<<0)
565#define ZEND_PARSED_METHOD_CALL         (1<<1)
566#define ZEND_PARSED_STATIC_MEMBER       (1<<2)
567#define ZEND_PARSED_FUNCTION_CALL       (1<<3)
568#define ZEND_PARSED_VARIABLE            (1<<4)
569#define ZEND_PARSED_REFERENCE_VARIABLE  (1<<5)
570#define ZEND_PARSED_NEW                 (1<<6)
571#define ZEND_PARSED_LIST_EXPR           (1<<7)
572
573#define ZEND_PARAM_REF      (1<<0)
574#define ZEND_PARAM_VARIADIC (1<<1)
575
576#define ZEND_NAME_FQ       0
577#define ZEND_NAME_NOT_FQ   1
578#define ZEND_NAME_RELATIVE 2
579
580/* unset types */
581#define ZEND_UNSET_REG 0
582
583/* var status for backpatching */
584#define BP_VAR_R            0
585#define BP_VAR_W            1
586#define BP_VAR_RW           2
587#define BP_VAR_IS           3
588#define BP_VAR_FUNC_ARG     4
589#define BP_VAR_UNSET        5
590#define BP_VAR_REF          6   /* right-hand side of by-ref assignment */
591
592/* Bottom 3 bits are the type, top bits are arg num for BP_VAR_FUNC_ARG */
593#define BP_VAR_SHIFT 3
594#define BP_VAR_MASK  7
595
596
597#define ZEND_INTERNAL_FUNCTION              1
598#define ZEND_USER_FUNCTION                  2
599#define ZEND_OVERLOADED_FUNCTION            3
600#define ZEND_EVAL_CODE                      4
601#define ZEND_OVERLOADED_FUNCTION_TEMPORARY  5
602
603/* A quick check (type == ZEND_USER_FUNCTION || type == ZEND_EVAL_CODE) */
604#define ZEND_USER_CODE(type) ((type & 1) == 0)
605
606#define ZEND_INTERNAL_CLASS         1
607#define ZEND_USER_CLASS             2
608
609#define ZEND_EVAL               (1<<0)
610#define ZEND_INCLUDE            (1<<1)
611#define ZEND_INCLUDE_ONCE       (1<<2)
612#define ZEND_REQUIRE            (1<<3)
613#define ZEND_REQUIRE_ONCE       (1<<4)
614
615#define ZEND_CT (1<<0)
616#define ZEND_RT (1<<1)
617
618/* global/local fetches */
619#define ZEND_FETCH_GLOBAL           0x00000000
620#define ZEND_FETCH_LOCAL            0x10000000
621#define ZEND_FETCH_STATIC           0x20000000
622#define ZEND_FETCH_STATIC_MEMBER    0x30000000
623#define ZEND_FETCH_GLOBAL_LOCK      0x40000000
624#define ZEND_FETCH_LEXICAL          0x50000000
625
626#define ZEND_FETCH_TYPE_MASK        0x70000000
627
628#define ZEND_FETCH_STANDARD         0x00000000
629
630#define ZEND_ISSET                  0x02000000
631#define ZEND_ISEMPTY                0x01000000
632#define ZEND_ISSET_ISEMPTY_MASK     (ZEND_ISSET | ZEND_ISEMPTY)
633#define ZEND_QUICK_SET              0x00800000
634
635#define ZEND_FETCH_ARG_MASK         0x000fffff
636
637#define ZEND_FE_FETCH_BYREF 1
638#define ZEND_FE_FETCH_WITH_KEY  2
639
640#define EXT_TYPE_FREE_ON_RETURN     (1<<2)
641
642#define ZEND_MEMBER_FUNC_CALL   1<<0
643
644#define ZEND_ARG_SEND_BY_REF (1<<0)
645#define ZEND_ARG_COMPILE_TIME_BOUND (1<<1)
646#define ZEND_ARG_SEND_FUNCTION (1<<2)
647#define ZEND_ARG_SEND_SILENT   (1<<3)
648
649#define ZEND_SEND_BY_VAL     0
650#define ZEND_SEND_BY_REF     1
651#define ZEND_SEND_PREFER_REF 2
652
653static zend_always_inline int zend_check_arg_send_type(const zend_function *zf, uint32_t arg_num, uint32_t mask)
654{
655    if (UNEXPECTED(zf->common.arg_info == NULL)) {
656        return 0;
657    }
658    if (UNEXPECTED(arg_num > zf->common.num_args)) {
659        if (EXPECTED((zf->common.fn_flags & ZEND_ACC_VARIADIC) == 0)) {
660            return 0;
661        }
662        arg_num = zf->common.num_args;
663    }
664    return UNEXPECTED((zf->common.arg_info[arg_num-1].pass_by_reference & mask) != 0);
665}
666
667#define ARG_MUST_BE_SENT_BY_REF(zf, arg_num) \
668    zend_check_arg_send_type(zf, arg_num, ZEND_SEND_BY_REF)
669
670#define ARG_SHOULD_BE_SENT_BY_REF(zf, arg_num) \
671    zend_check_arg_send_type(zf, arg_num, ZEND_SEND_BY_REF|ZEND_SEND_PREFER_REF)
672
673#define ARG_MAY_BE_SENT_BY_REF(zf, arg_num) \
674    zend_check_arg_send_type(zf, arg_num, ZEND_SEND_PREFER_REF)
675
676#define ZEND_RETURN_VAL 0
677#define ZEND_RETURN_REF 1
678
679
680#define ZEND_RETURNS_FUNCTION 1<<0
681#define ZEND_RETURNS_NEW      1<<1
682#define ZEND_RETURNS_VALUE    1<<2
683
684#define ZEND_FAST_RET_TO_CATCH      1
685#define ZEND_FAST_RET_TO_FINALLY    2
686
687#define ZEND_FAST_CALL_FROM_CATCH   1
688#define ZEND_FAST_CALL_FROM_FINALLY 2
689
690#define ZEND_ARRAY_ELEMENT_REF      (1<<0)
691#define ZEND_ARRAY_NOT_PACKED       (1<<1)
692#define ZEND_ARRAY_SIZE_SHIFT       2
693
694END_EXTERN_C()
695
696#define ZEND_CLONE_FUNC_NAME        "__clone"
697#define ZEND_CONSTRUCTOR_FUNC_NAME  "__construct"
698#define ZEND_DESTRUCTOR_FUNC_NAME   "__destruct"
699#define ZEND_GET_FUNC_NAME          "__get"
700#define ZEND_SET_FUNC_NAME          "__set"
701#define ZEND_UNSET_FUNC_NAME        "__unset"
702#define ZEND_ISSET_FUNC_NAME        "__isset"
703#define ZEND_CALL_FUNC_NAME         "__call"
704#define ZEND_CALLSTATIC_FUNC_NAME   "__callstatic"
705#define ZEND_TOSTRING_FUNC_NAME     "__tostring"
706#define ZEND_AUTOLOAD_FUNC_NAME     "__autoload"
707#define ZEND_INVOKE_FUNC_NAME       "__invoke"
708#define ZEND_DEBUGINFO_FUNC_NAME    "__debuginfo"
709
710/* The following constants may be combined in CG(compiler_options)
711 * to change the default compiler behavior */
712
713/* generate extended debug information */
714#define ZEND_COMPILE_EXTENDED_INFO              (1<<0)
715
716/* call op_array handler of extendions */
717#define ZEND_COMPILE_HANDLE_OP_ARRAY            (1<<1)
718
719/* generate ZEND_INIT_FCALL_BY_NAME for internal functions instead of ZEND_INIT_FCALL */
720#define ZEND_COMPILE_IGNORE_INTERNAL_FUNCTIONS  (1<<2)
721
722/* don't perform early binding for classes inherited form internal ones;
723 * in namespaces assume that internal class that doesn't exist at compile-time
724 * may apper in run-time */
725#define ZEND_COMPILE_IGNORE_INTERNAL_CLASSES    (1<<3)
726
727/* generate ZEND_DECLARE_INHERITED_CLASS_DELAYED opcode to delay early binding */
728#define ZEND_COMPILE_DELAYED_BINDING            (1<<4)
729
730/* disable constant substitution at compile-time */
731#define ZEND_COMPILE_NO_CONSTANT_SUBSTITUTION   (1<<5)
732
733/* disable usage of builtin instruction for strlen() */
734#define ZEND_COMPILE_NO_BUILTIN_STRLEN          (1<<6)
735
736/* The default value for CG(compiler_options) */
737#define ZEND_COMPILE_DEFAULT                    ZEND_COMPILE_HANDLE_OP_ARRAY
738
739/* The default value for CG(compiler_options) during eval() */
740#define ZEND_COMPILE_DEFAULT_FOR_EVAL           0
741
742#endif /* ZEND_COMPILE_H */
743
744/*
745 * Local variables:
746 * tab-width: 4
747 * c-basic-offset: 4
748 * indent-tabs-mode: t
749 * End:
750 */
751