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