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