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 flags;
231    int offset;
232    zend_string *name;
233    zend_string *doc_comment;
234    zend_class_entry *ce;
235} zend_property_info;
236
237typedef struct _zend_arg_info {
238    const char *name;           // TODO: convert into zend_string ???
239    uint32_t name_len;
240    const char *class_name;     // TODO: convert into zend_string ???
241    uint32_t class_name_len;
242    zend_uchar type_hint;
243    zend_uchar pass_by_reference;
244    zend_bool allow_null;
245    zend_bool is_variadic;
246} zend_arg_info;
247
248/* the following structure repeats the layout of zend_arg_info,
249 * but its fields have different meaning. It's used as the first element of
250 * arg_info array to define properties of internal functions.
251 */
252typedef struct _zend_internal_function_info {
253    const char *_name;
254    uint32_t _name_len;
255    const char *_class_name;
256    uint32_t required_num_args;
257    zend_uchar _type_hint;
258    zend_bool return_reference;
259    zend_bool _allow_null;
260    zend_bool _is_variadic;
261} zend_internal_function_info;
262
263struct _zend_op_array {
264    /* Common elements */
265    zend_uchar type;
266    uint32_t fn_flags;
267    zend_string *function_name;
268    zend_class_entry *scope;
269    zend_function *prototype;
270    uint32_t num_args;
271    uint32_t required_num_args;
272    zend_arg_info *arg_info;
273    /* END of common elements */
274
275    uint32_t *refcount;
276
277    uint32_t this_var;
278
279    uint32_t last;
280    zend_op *opcodes;
281
282    int last_var;
283    uint32_t T;
284    zend_string **vars;
285
286    int last_brk_cont;
287    int last_try_catch;
288    zend_brk_cont_element *brk_cont_array;
289    zend_try_catch_element *try_catch_array;
290
291    /* static variables support */
292    HashTable *static_variables;
293
294    zend_string *filename;
295    uint32_t line_start;
296    uint32_t line_end;
297    zend_string *doc_comment;
298    uint32_t early_binding; /* the linked list of delayed declarations */
299
300    int last_literal;
301    zval *literals;
302
303    int  last_cache_slot;
304    void **run_time_cache;
305
306    void *reserved[ZEND_MAX_RESERVED_RESOURCES];
307};
308
309
310#define ZEND_RETURN_VALUE               0
311#define ZEND_RETURN_REFERENCE           1
312
313typedef struct _zend_internal_function {
314    /* Common elements */
315    zend_uchar type;
316    uint32_t fn_flags;
317    zend_string* function_name;
318    zend_class_entry *scope;
319    zend_function *prototype;
320    uint32_t num_args;
321    uint32_t required_num_args;
322    zend_arg_info *arg_info;
323    /* END of common elements */
324
325    void (*handler)(INTERNAL_FUNCTION_PARAMETERS);
326    struct _zend_module_entry *module;
327} zend_internal_function;
328
329#define ZEND_FN_SCOPE_NAME(function)  ((function) && (function)->common.scope ? (function)->common.scope->name->val : "")
330
331union _zend_function {
332    zend_uchar type;    /* MUST be the first element of this struct! */
333
334    struct {
335        zend_uchar type;  /* never used */
336        uint32_t fn_flags;
337        zend_string *function_name;
338        zend_class_entry *scope;
339        union _zend_function *prototype;
340        uint32_t num_args;
341        uint32_t required_num_args;
342        zend_arg_info *arg_info;
343    } common;
344
345    zend_op_array op_array;
346    zend_internal_function internal_function;
347};
348
349typedef enum _vm_frame_kind {
350    VM_FRAME_NESTED_FUNCTION,   /* stackless VM call to function */
351    VM_FRAME_NESTED_CODE,       /* stackless VM call to include/require/eval */
352    VM_FRAME_TOP_FUNCTION,      /* direct VM call to function from external C code */
353    VM_FRAME_TOP_CODE           /* direct VM call to "main" code from external C code */
354} vm_frame_kind;
355
356struct _zend_execute_data {
357    const zend_op       *opline;           /* executed opline                */
358    zend_execute_data   *call;             /* current call                   */
359    void               **run_time_cache;
360    zend_function       *func;             /* executed op_array              */
361    zval                 This;
362    zend_class_entry    *called_scope;
363    zend_execute_data   *prev_execute_data;
364    uint32_t             frame_info;
365    uint32_t             num_args;
366    zval                *return_value;
367    zend_class_entry    *scope;            /* function scope (self)          */
368    zend_array          *symbol_table;
369    const zend_op       *fast_ret; /* used by FAST_CALL/FAST_RET (finally keyword) */
370    zend_object         *delayed_exception;
371    uint32_t             silence_op_num;
372    uint32_t             old_error_reporting;
373};
374
375#define VM_FRAME_KIND_MASK           0x000000ff
376#define VM_FRAME_FLAGS_MASK          0xffffff00
377
378#define ZEND_CALL_CTOR               (1 << 8)
379#define ZEND_CALL_CTOR_RESULT_UNUSED (1 << 9)
380
381#define VM_FRAME_INFO(kind, flags)   ((kind) | (flags))
382#define VM_FRAME_KIND(info)          ((info) & VM_FRAME_KIND_MASK)
383#define VM_FRAME_FLAGS(info)         ((info) & VM_FRAME_FLAGS_MASK)
384
385#define ZEND_CALL_FRAME_SLOT \
386    ((ZEND_MM_ALIGNED_SIZE(sizeof(zend_execute_data)) + ZEND_MM_ALIGNED_SIZE(sizeof(zval)) - 1) / ZEND_MM_ALIGNED_SIZE(sizeof(zval)))
387
388#define ZEND_CALL_ARG(call, n) \
389    (((zval*)(call)) + ((n) + (ZEND_CALL_FRAME_SLOT - 1)))
390
391#define EX(element)             ((execute_data)->element)
392
393#define EX_VAR_2(ex, n)         ((zval*)(((char*)(ex)) + ((int)(n))))
394#define EX_VAR_NUM_2(ex, n)     (((zval*)(ex)) + (ZEND_CALL_FRAME_SLOT + ((int)(n))))
395
396#define EX_VAR(n)               EX_VAR_2(execute_data, n)
397#define EX_VAR_NUM(n)           EX_VAR_NUM_2(execute_data, n)
398
399#define EX_VAR_TO_NUM(n)        (EX_VAR_2(NULL, n) - EX_VAR_NUM_2(NULL, 0))
400
401#define IS_CONST    (1<<0)
402#define IS_TMP_VAR  (1<<1)
403#define IS_VAR      (1<<2)
404#define IS_UNUSED   (1<<3)  /* Unused variable */
405#define IS_CV       (1<<4)  /* Compiled variable */
406
407#define EXT_TYPE_UNUSED (1<<5)
408
409#include "zend_globals.h"
410
411BEGIN_EXTERN_C()
412
413void init_compiler(TSRMLS_D);
414void shutdown_compiler(TSRMLS_D);
415void zend_init_compiler_data_structures(TSRMLS_D);
416void zend_init_compiler_context(TSRMLS_D);
417
418extern ZEND_API zend_op_array *(*zend_compile_file)(zend_file_handle *file_handle, int type TSRMLS_DC);
419extern ZEND_API zend_op_array *(*zend_compile_string)(zval *source_string, char *filename TSRMLS_DC);
420
421ZEND_API int lex_scan(zval *zendlval TSRMLS_DC);
422void startup_scanner(TSRMLS_D);
423void shutdown_scanner(TSRMLS_D);
424
425ZEND_API zend_string *zend_set_compiled_filename(zend_string *new_compiled_filename TSRMLS_DC);
426ZEND_API void zend_restore_compiled_filename(zend_string *original_compiled_filename TSRMLS_DC);
427ZEND_API zend_string *zend_get_compiled_filename(TSRMLS_D);
428ZEND_API int zend_get_compiled_lineno(TSRMLS_D);
429ZEND_API size_t zend_get_scanned_file_offset(TSRMLS_D);
430
431ZEND_API zend_string *zend_get_compiled_variable_name(const zend_op_array *op_array, uint32_t var);
432
433#ifdef ZTS
434const char *zend_get_zendtext(TSRMLS_D);
435int zend_get_zendleng(TSRMLS_D);
436#endif
437
438
439typedef int (*unary_op_type)(zval *, zval * TSRMLS_DC);
440typedef int (*binary_op_type)(zval *, zval *, zval * TSRMLS_DC);
441ZEND_API unary_op_type get_unary_op(int opcode);
442ZEND_API binary_op_type get_binary_op(int opcode);
443
444void zend_stop_lexing(TSRMLS_D);
445void zend_emit_final_return(zval *zv TSRMLS_DC);
446zend_ast *zend_ast_append_str(zend_ast *left, zend_ast *right);
447uint32_t zend_add_member_modifier(uint32_t flags, uint32_t new_flag);
448zend_ast *zend_ast_append_doc_comment(zend_ast *list TSRMLS_DC);
449void zend_handle_encoding_declaration(zend_ast *ast TSRMLS_DC);
450
451/* parser-driven code generators */
452void zend_do_free(znode *op1 TSRMLS_DC);
453
454ZEND_API int do_bind_function(const zend_op_array *op_array, const zend_op *opline, HashTable *function_table, zend_bool compile_time TSRMLS_DC);
455ZEND_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);
456ZEND_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);
457ZEND_API void zend_do_delayed_early_binding(const zend_op_array *op_array TSRMLS_DC);
458
459/* Functions for a null terminated pointer list, used for traits parsing and compilation */
460void zend_init_list(void *result, void *item TSRMLS_DC);
461void zend_add_to_list(void *result, void *item TSRMLS_DC);
462
463void zend_do_extended_info(TSRMLS_D);
464void zend_do_extended_fcall_begin(TSRMLS_D);
465void zend_do_extended_fcall_end(TSRMLS_D);
466
467void zend_verify_namespace(TSRMLS_D);
468void zend_do_end_compilation(TSRMLS_D);
469
470void zend_resolve_goto_label(zend_op_array *op_array, zend_op *opline, int pass2 TSRMLS_DC);
471void zend_release_labels(int temporary TSRMLS_DC);
472
473ZEND_API void function_add_ref(zend_function *function);
474
475#define INITIAL_OP_ARRAY_SIZE 64
476
477
478/* helper functions in zend_language_scanner.l */
479ZEND_API zend_op_array *compile_file(zend_file_handle *file_handle, int type TSRMLS_DC);
480ZEND_API zend_op_array *compile_string(zval *source_string, char *filename TSRMLS_DC);
481ZEND_API zend_op_array *compile_filename(int type, zval *filename TSRMLS_DC);
482ZEND_API int zend_execute_scripts(int type TSRMLS_DC, zval *retval, int file_count, ...);
483ZEND_API int open_file_for_scanning(zend_file_handle *file_handle TSRMLS_DC);
484ZEND_API void init_op_array(zend_op_array *op_array, zend_uchar type, int initial_ops_size TSRMLS_DC);
485ZEND_API void destroy_op_array(zend_op_array *op_array TSRMLS_DC);
486ZEND_API void zend_destroy_file_handle(zend_file_handle *file_handle TSRMLS_DC);
487ZEND_API void zend_cleanup_user_class_data(zend_class_entry *ce TSRMLS_DC);
488ZEND_API void zend_cleanup_internal_class_data(zend_class_entry *ce TSRMLS_DC);
489ZEND_API void zend_cleanup_internal_classes(TSRMLS_D);
490ZEND_API void zend_cleanup_op_array_data(zend_op_array *op_array);
491ZEND_API int clean_non_persistent_function_full(zval *zv TSRMLS_DC);
492ZEND_API int clean_non_persistent_class_full(zval *zv TSRMLS_DC);
493
494ZEND_API void destroy_zend_function(zend_function *function TSRMLS_DC);
495ZEND_API void zend_function_dtor(zval *zv);
496ZEND_API void destroy_zend_class(zval *zv);
497void zend_class_add_ref(zval *zv);
498
499ZEND_API zend_string *zend_mangle_property_name(const char *src1, size_t src1_length, const char *src2, size_t src2_length, int internal);
500#define zend_unmangle_property_name(mangled_property, class_name, prop_name) \
501        zend_unmangle_property_name_ex(mangled_property, class_name, prop_name, NULL)
502ZEND_API int zend_unmangle_property_name_ex(const zend_string *name, const char **class_name, const char **prop_name, size_t *prop_len);
503
504#define ZEND_FUNCTION_DTOR zend_function_dtor
505#define ZEND_CLASS_DTOR destroy_zend_class
506
507zend_op *get_next_op(zend_op_array *op_array TSRMLS_DC);
508void init_op(zend_op *op TSRMLS_DC);
509int get_next_op_number(zend_op_array *op_array);
510int print_class(zend_class_entry *class_entry TSRMLS_DC);
511void print_op_array(zend_op_array *op_array, int optimizations);
512ZEND_API int pass_two(zend_op_array *op_array TSRMLS_DC);
513zend_brk_cont_element *get_next_brk_cont_element(zend_op_array *op_array);
514ZEND_API zend_bool zend_is_compiling(TSRMLS_D);
515ZEND_API char *zend_make_compiled_string_description(const char *name TSRMLS_DC);
516ZEND_API void zend_initialize_class_data(zend_class_entry *ce, zend_bool nullify_handlers TSRMLS_DC);
517uint32_t zend_get_class_fetch_type(zend_string *name);
518
519typedef zend_bool (*zend_auto_global_callback)(zend_string *name TSRMLS_DC);
520typedef struct _zend_auto_global {
521    zend_string *name;
522    zend_auto_global_callback auto_global_callback;
523    zend_bool jit;
524    zend_bool armed;
525} zend_auto_global;
526
527ZEND_API int zend_register_auto_global(zend_string *name, zend_bool jit, zend_auto_global_callback auto_global_callback TSRMLS_DC);
528ZEND_API void zend_activate_auto_globals(TSRMLS_D);
529ZEND_API zend_bool zend_is_auto_global(zend_string *name TSRMLS_DC);
530ZEND_API size_t zend_dirname(char *path, size_t len);
531
532int zendlex(zend_parser_stack_elem *elem TSRMLS_DC);
533
534int zend_add_literal(zend_op_array *op_array, zval *zv TSRMLS_DC);
535
536/* BEGIN: OPCODES */
537
538#include "zend_vm_opcodes.h"
539
540#define ZEND_OP_DATA                137
541
542/* END: OPCODES */
543
544/* class fetches */
545#define ZEND_FETCH_CLASS_DEFAULT    0
546#define ZEND_FETCH_CLASS_SELF       1
547#define ZEND_FETCH_CLASS_PARENT     2
548#define ZEND_FETCH_CLASS_STATIC     3
549#define ZEND_FETCH_CLASS_AUTO       4
550#define ZEND_FETCH_CLASS_INTERFACE  5
551#define ZEND_FETCH_CLASS_TRAIT      6
552#define ZEND_FETCH_CLASS_MASK        0x0f
553#define ZEND_FETCH_CLASS_NO_AUTOLOAD 0x80
554#define ZEND_FETCH_CLASS_SILENT      0x0100
555
556/* variable parsing type (compile-time) */
557#define ZEND_PARSED_MEMBER              (1<<0)
558#define ZEND_PARSED_METHOD_CALL         (1<<1)
559#define ZEND_PARSED_STATIC_MEMBER       (1<<2)
560#define ZEND_PARSED_FUNCTION_CALL       (1<<3)
561#define ZEND_PARSED_VARIABLE            (1<<4)
562#define ZEND_PARSED_REFERENCE_VARIABLE  (1<<5)
563#define ZEND_PARSED_NEW                 (1<<6)
564#define ZEND_PARSED_LIST_EXPR           (1<<7)
565
566#define ZEND_PARAM_REF      (1<<0)
567#define ZEND_PARAM_VARIADIC (1<<1)
568
569#define ZEND_NAME_FQ       0
570#define ZEND_NAME_NOT_FQ   1
571#define ZEND_NAME_RELATIVE 2
572
573/* unset types */
574#define ZEND_UNSET_REG 0
575
576/* var status for backpatching */
577#define BP_VAR_R            0
578#define BP_VAR_W            1
579#define BP_VAR_RW           2
580#define BP_VAR_IS           3
581#define BP_VAR_FUNC_ARG     4
582#define BP_VAR_UNSET        5
583#define BP_VAR_REF          6   /* right-hand side of by-ref assignment */
584
585/* Bottom 3 bits are the type, top bits are arg num for BP_VAR_FUNC_ARG */
586#define BP_VAR_SHIFT 3
587#define BP_VAR_MASK  7
588
589
590#define ZEND_INTERNAL_FUNCTION              1
591#define ZEND_USER_FUNCTION                  2
592#define ZEND_OVERLOADED_FUNCTION            3
593#define ZEND_EVAL_CODE                      4
594#define ZEND_OVERLOADED_FUNCTION_TEMPORARY  5
595
596/* A quick check (type == ZEND_USER_FUNCTION || type == ZEND_EVAL_CODE) */
597#define ZEND_USER_CODE(type) ((type & 1) == 0)
598
599#define ZEND_INTERNAL_CLASS         1
600#define ZEND_USER_CLASS             2
601
602#define ZEND_EVAL               (1<<0)
603#define ZEND_INCLUDE            (1<<1)
604#define ZEND_INCLUDE_ONCE       (1<<2)
605#define ZEND_REQUIRE            (1<<3)
606#define ZEND_REQUIRE_ONCE       (1<<4)
607
608#define ZEND_CT (1<<0)
609#define ZEND_RT (1<<1)
610
611/* global/local fetches */
612#define ZEND_FETCH_GLOBAL           0x00000000
613#define ZEND_FETCH_LOCAL            0x10000000
614#define ZEND_FETCH_STATIC           0x20000000
615#define ZEND_FETCH_STATIC_MEMBER    0x30000000
616#define ZEND_FETCH_GLOBAL_LOCK      0x40000000
617#define ZEND_FETCH_LEXICAL          0x50000000
618
619#define ZEND_FETCH_TYPE_MASK        0x70000000
620
621#define ZEND_FETCH_STANDARD         0x00000000
622#define ZEND_FETCH_MAKE_REF         0x04000000
623
624#define ZEND_ISSET                  0x02000000
625#define ZEND_ISEMPTY                0x01000000
626#define ZEND_ISSET_ISEMPTY_MASK     (ZEND_ISSET | ZEND_ISEMPTY)
627#define ZEND_QUICK_SET              0x00800000
628
629#define ZEND_FETCH_ARG_MASK         0x000fffff
630
631#define ZEND_FE_FETCH_BYREF 1
632#define ZEND_FE_FETCH_WITH_KEY  2
633
634#define EXT_TYPE_FREE_ON_RETURN     (1<<2)
635
636#define ZEND_MEMBER_FUNC_CALL   1<<0
637
638#define ZEND_ARG_SEND_BY_REF (1<<0)
639#define ZEND_ARG_COMPILE_TIME_BOUND (1<<1)
640#define ZEND_ARG_SEND_FUNCTION (1<<2)
641#define ZEND_ARG_SEND_SILENT   (1<<3)
642
643#define ZEND_SEND_BY_VAL     0
644#define ZEND_SEND_BY_REF     1
645#define ZEND_SEND_PREFER_REF 2
646
647static zend_always_inline int zend_check_arg_send_type(const zend_function *zf, uint32_t arg_num, uint32_t mask)
648{
649    if (UNEXPECTED(zf->common.arg_info == NULL)) {
650        return 0;
651    }
652    if (UNEXPECTED(arg_num > zf->common.num_args)) {
653        if (EXPECTED((zf->common.fn_flags & ZEND_ACC_VARIADIC) == 0)) {
654            return 0;
655        }
656        arg_num = zf->common.num_args;
657    }
658    return UNEXPECTED((zf->common.arg_info[arg_num-1].pass_by_reference & mask) != 0);
659}
660
661#define ARG_MUST_BE_SENT_BY_REF(zf, arg_num) \
662    zend_check_arg_send_type(zf, arg_num, ZEND_SEND_BY_REF)
663
664#define ARG_SHOULD_BE_SENT_BY_REF(zf, arg_num) \
665    zend_check_arg_send_type(zf, arg_num, ZEND_SEND_BY_REF|ZEND_SEND_PREFER_REF)
666
667#define ARG_MAY_BE_SENT_BY_REF(zf, arg_num) \
668    zend_check_arg_send_type(zf, arg_num, ZEND_SEND_PREFER_REF)
669
670#define ZEND_RETURN_VAL 0
671#define ZEND_RETURN_REF 1
672
673
674#define ZEND_RETURNS_FUNCTION 1<<0
675#define ZEND_RETURNS_NEW      1<<1
676#define ZEND_RETURNS_VALUE    1<<2
677
678#define ZEND_FAST_RET_TO_CATCH      1
679#define ZEND_FAST_RET_TO_FINALLY    2
680
681#define ZEND_FAST_CALL_FROM_CATCH   1
682#define ZEND_FAST_CALL_FROM_FINALLY 2
683
684#define ZEND_ARRAY_ELEMENT_REF      (1<<0)
685#define ZEND_ARRAY_NOT_PACKED       (1<<1)
686#define ZEND_ARRAY_SIZE_SHIFT       2
687
688END_EXTERN_C()
689
690#define ZEND_CLONE_FUNC_NAME        "__clone"
691#define ZEND_CONSTRUCTOR_FUNC_NAME  "__construct"
692#define ZEND_DESTRUCTOR_FUNC_NAME   "__destruct"
693#define ZEND_GET_FUNC_NAME          "__get"
694#define ZEND_SET_FUNC_NAME          "__set"
695#define ZEND_UNSET_FUNC_NAME        "__unset"
696#define ZEND_ISSET_FUNC_NAME        "__isset"
697#define ZEND_CALL_FUNC_NAME         "__call"
698#define ZEND_CALLSTATIC_FUNC_NAME   "__callstatic"
699#define ZEND_TOSTRING_FUNC_NAME     "__tostring"
700#define ZEND_AUTOLOAD_FUNC_NAME     "__autoload"
701#define ZEND_INVOKE_FUNC_NAME       "__invoke"
702#define ZEND_DEBUGINFO_FUNC_NAME    "__debuginfo"
703
704/* The following constants may be combined in CG(compiler_options)
705 * to change the default compiler behavior */
706
707/* generate extended debug information */
708#define ZEND_COMPILE_EXTENDED_INFO              (1<<0)
709
710/* call op_array handler of extendions */
711#define ZEND_COMPILE_HANDLE_OP_ARRAY            (1<<1)
712
713/* generate ZEND_INIT_FCALL_BY_NAME for internal functions instead of ZEND_INIT_FCALL */
714#define ZEND_COMPILE_IGNORE_INTERNAL_FUNCTIONS  (1<<2)
715
716/* don't perform early binding for classes inherited form internal ones;
717 * in namespaces assume that internal class that doesn't exist at compile-time
718 * may apper in run-time */
719#define ZEND_COMPILE_IGNORE_INTERNAL_CLASSES    (1<<3)
720
721/* generate ZEND_DECLARE_INHERITED_CLASS_DELAYED opcode to delay early binding */
722#define ZEND_COMPILE_DELAYED_BINDING            (1<<4)
723
724/* disable constant substitution at compile-time */
725#define ZEND_COMPILE_NO_CONSTANT_SUBSTITUTION   (1<<5)
726
727/* disable usage of builtin instruction for strlen() */
728#define ZEND_COMPILE_NO_BUILTIN_STRLEN          (1<<6)
729
730/* The default value for CG(compiler_options) */
731#define ZEND_COMPILE_DEFAULT                    ZEND_COMPILE_HANDLE_OP_ARRAY
732
733/* The default value for CG(compiler_options) during eval() */
734#define ZEND_COMPILE_DEFAULT_FOR_EVAL           0
735
736#endif /* ZEND_COMPILE_H */
737
738/*
739 * Local variables:
740 * tab-width: 4
741 * c-basic-offset: 4
742 * indent-tabs-mode: t
743 * End:
744 */
745