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 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_inherit_interfaces(zend_class_entry *ce, const zend_class_entry *iface TSRMLS_DC);
453ZEND_API void zend_do_implement_interface(zend_class_entry *ce, zend_class_entry *iface TSRMLS_DC);
454
455ZEND_API void zend_do_implement_trait(zend_class_entry *ce, zend_class_entry *trait TSRMLS_DC);
456ZEND_API void zend_do_bind_traits(zend_class_entry *ce TSRMLS_DC);
457
458ZEND_API void zend_do_inheritance(zend_class_entry *ce, zend_class_entry *parent_ce TSRMLS_DC);
459void zend_do_early_binding(TSRMLS_D);
460ZEND_API void zend_do_delayed_early_binding(const zend_op_array *op_array TSRMLS_DC);
461
462/* Functions for a null terminated pointer list, used for traits parsing and compilation */
463void zend_init_list(void *result, void *item TSRMLS_DC);
464void zend_add_to_list(void *result, void *item TSRMLS_DC);
465
466void zend_do_extended_info(TSRMLS_D);
467void zend_do_extended_fcall_begin(TSRMLS_D);
468void zend_do_extended_fcall_end(TSRMLS_D);
469
470void zend_verify_namespace(TSRMLS_D);
471void zend_do_end_compilation(TSRMLS_D);
472
473void zend_resolve_goto_label(zend_op_array *op_array, zend_op *opline, int pass2 TSRMLS_DC);
474void zend_release_labels(int temporary TSRMLS_DC);
475
476ZEND_API void function_add_ref(zend_function *function);
477
478#define INITIAL_OP_ARRAY_SIZE 64
479
480
481/* helper functions in zend_language_scanner.l */
482ZEND_API zend_op_array *compile_file(zend_file_handle *file_handle, int type TSRMLS_DC);
483ZEND_API zend_op_array *compile_string(zval *source_string, char *filename TSRMLS_DC);
484ZEND_API zend_op_array *compile_filename(int type, zval *filename TSRMLS_DC);
485ZEND_API int zend_execute_scripts(int type TSRMLS_DC, zval *retval, int file_count, ...);
486ZEND_API int open_file_for_scanning(zend_file_handle *file_handle TSRMLS_DC);
487ZEND_API void init_op_array(zend_op_array *op_array, zend_uchar type, int initial_ops_size TSRMLS_DC);
488ZEND_API void destroy_op_array(zend_op_array *op_array TSRMLS_DC);
489ZEND_API void zend_destroy_file_handle(zend_file_handle *file_handle TSRMLS_DC);
490ZEND_API void zend_cleanup_user_class_data(zend_class_entry *ce TSRMLS_DC);
491ZEND_API void zend_cleanup_internal_class_data(zend_class_entry *ce TSRMLS_DC);
492ZEND_API void zend_cleanup_internal_classes(TSRMLS_D);
493ZEND_API void zend_cleanup_op_array_data(zend_op_array *op_array);
494ZEND_API int clean_non_persistent_function_full(zval *zv TSRMLS_DC);
495ZEND_API int clean_non_persistent_class_full(zval *zv TSRMLS_DC);
496
497ZEND_API void destroy_zend_function(zend_function *function TSRMLS_DC);
498ZEND_API void zend_function_dtor(zval *zv);
499ZEND_API void destroy_zend_class(zval *zv);
500void zend_class_add_ref(zval *zv);
501
502ZEND_API zend_string *zend_mangle_property_name(const char *src1, int src1_length, const char *src2, int src2_length, int internal);
503#define zend_unmangle_property_name(mangled_property, mangled_property_len, class_name, prop_name) \
504        zend_unmangle_property_name_ex(mangled_property, mangled_property_len, class_name, prop_name, NULL)
505ZEND_API int zend_unmangle_property_name_ex(const char *mangled_property, int mangled_property_len, const char **class_name, const char **prop_name, int *prop_len);
506
507#define ZEND_FUNCTION_DTOR zend_function_dtor
508#define ZEND_CLASS_DTOR destroy_zend_class
509
510zend_op *get_next_op(zend_op_array *op_array TSRMLS_DC);
511void init_op(zend_op *op TSRMLS_DC);
512int get_next_op_number(zend_op_array *op_array);
513int print_class(zend_class_entry *class_entry TSRMLS_DC);
514void print_op_array(zend_op_array *op_array, int optimizations);
515ZEND_API int pass_two(zend_op_array *op_array TSRMLS_DC);
516zend_brk_cont_element *get_next_brk_cont_element(zend_op_array *op_array);
517ZEND_API zend_bool zend_is_compiling(TSRMLS_D);
518ZEND_API char *zend_make_compiled_string_description(const char *name TSRMLS_DC);
519ZEND_API void zend_initialize_class_data(zend_class_entry *ce, zend_bool nullify_handlers TSRMLS_DC);
520uint32_t zend_get_class_fetch_type(zend_string *name);
521
522typedef zend_bool (*zend_auto_global_callback)(zend_string *name TSRMLS_DC);
523typedef struct _zend_auto_global {
524    zend_string *name;
525    zend_auto_global_callback auto_global_callback;
526    zend_bool jit;
527    zend_bool armed;
528} zend_auto_global;
529
530ZEND_API int zend_register_auto_global(zend_string *name, zend_bool jit, zend_auto_global_callback auto_global_callback TSRMLS_DC);
531ZEND_API void zend_activate_auto_globals(TSRMLS_D);
532ZEND_API zend_bool zend_is_auto_global(zend_string *name TSRMLS_DC);
533ZEND_API size_t zend_dirname(char *path, size_t len);
534
535int zendlex(zend_parser_stack_elem *elem TSRMLS_DC);
536
537int zend_add_literal(zend_op_array *op_array, zval *zv TSRMLS_DC);
538
539/* BEGIN: OPCODES */
540
541#include "zend_vm_opcodes.h"
542
543#define ZEND_OP_DATA                137
544
545/* END: OPCODES */
546
547/* class fetches */
548#define ZEND_FETCH_CLASS_DEFAULT    0
549#define ZEND_FETCH_CLASS_SELF       1
550#define ZEND_FETCH_CLASS_PARENT     2
551#define ZEND_FETCH_CLASS_STATIC     3
552#define ZEND_FETCH_CLASS_AUTO       4
553#define ZEND_FETCH_CLASS_INTERFACE  5
554#define ZEND_FETCH_CLASS_TRAIT      6
555#define ZEND_FETCH_CLASS_MASK        0x0f
556#define ZEND_FETCH_CLASS_NO_AUTOLOAD 0x80
557#define ZEND_FETCH_CLASS_SILENT      0x0100
558
559/* variable parsing type (compile-time) */
560#define ZEND_PARSED_MEMBER              (1<<0)
561#define ZEND_PARSED_METHOD_CALL         (1<<1)
562#define ZEND_PARSED_STATIC_MEMBER       (1<<2)
563#define ZEND_PARSED_FUNCTION_CALL       (1<<3)
564#define ZEND_PARSED_VARIABLE            (1<<4)
565#define ZEND_PARSED_REFERENCE_VARIABLE  (1<<5)
566#define ZEND_PARSED_NEW                 (1<<6)
567#define ZEND_PARSED_LIST_EXPR           (1<<7)
568
569#define ZEND_PARAM_REF      (1<<0)
570#define ZEND_PARAM_VARIADIC (1<<1)
571
572#define ZEND_NAME_FQ       0
573#define ZEND_NAME_NOT_FQ   1
574#define ZEND_NAME_RELATIVE 2
575
576/* unset types */
577#define ZEND_UNSET_REG 0
578
579/* var status for backpatching */
580#define BP_VAR_R            0
581#define BP_VAR_W            1
582#define BP_VAR_RW           2
583#define BP_VAR_IS           3
584#define BP_VAR_FUNC_ARG     4
585#define BP_VAR_UNSET        5
586#define BP_VAR_REF          6   /* right-hand side of by-ref assignment */
587
588/* Bottom 3 bits are the type, top bits are arg num for BP_VAR_FUNC_ARG */
589#define BP_VAR_SHIFT 3
590#define BP_VAR_MASK  7
591
592
593#define ZEND_INTERNAL_FUNCTION              1
594#define ZEND_USER_FUNCTION                  2
595#define ZEND_OVERLOADED_FUNCTION            3
596#define ZEND_EVAL_CODE                      4
597#define ZEND_OVERLOADED_FUNCTION_TEMPORARY  5
598
599/* A quick check (type == ZEND_USER_FUNCTION || type == ZEND_EVAL_CODE) */
600#define ZEND_USER_CODE(type) ((type & 1) == 0)
601
602#define ZEND_INTERNAL_CLASS         1
603#define ZEND_USER_CLASS             2
604
605#define ZEND_EVAL               (1<<0)
606#define ZEND_INCLUDE            (1<<1)
607#define ZEND_INCLUDE_ONCE       (1<<2)
608#define ZEND_REQUIRE            (1<<3)
609#define ZEND_REQUIRE_ONCE       (1<<4)
610
611#define ZEND_CT (1<<0)
612#define ZEND_RT (1<<1)
613
614/* global/local fetches */
615#define ZEND_FETCH_GLOBAL           0x00000000
616#define ZEND_FETCH_LOCAL            0x10000000
617#define ZEND_FETCH_STATIC           0x20000000
618#define ZEND_FETCH_STATIC_MEMBER    0x30000000
619#define ZEND_FETCH_GLOBAL_LOCK      0x40000000
620#define ZEND_FETCH_LEXICAL          0x50000000
621
622#define ZEND_FETCH_TYPE_MASK        0x70000000
623
624#define ZEND_FETCH_STANDARD         0x00000000
625#define ZEND_FETCH_ADD_LOCK         0x08000000
626#define ZEND_FETCH_MAKE_REF         0x04000000
627
628#define ZEND_ISSET                  0x02000000
629#define ZEND_ISEMPTY                0x01000000
630#define ZEND_ISSET_ISEMPTY_MASK     (ZEND_ISSET | ZEND_ISEMPTY)
631#define ZEND_QUICK_SET              0x00800000
632
633#define ZEND_FETCH_ARG_MASK         0x000fffff
634
635#define ZEND_FE_FETCH_BYREF 1
636#define ZEND_FE_FETCH_WITH_KEY  2
637
638#define ZEND_FE_RESET_VARIABLE      (1<<0)
639#define ZEND_FE_RESET_REFERENCE     (1<<1)
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
653#define CHECK_ARG_SEND_TYPE(zf, arg_num, m) \
654    (EXPECTED((zf)->common.arg_info != NULL) && \
655    (EXPECTED(arg_num <= (zf)->common.num_args) \
656        ? ((zf)->common.arg_info[arg_num-1].pass_by_reference & (m)) \
657        : (UNEXPECTED((zf)->common.fn_flags & ZEND_ACC_VARIADIC) != 0) && \
658           ((zf)->common.arg_info[(zf)->common.num_args-1].pass_by_reference & (m))))
659
660#define ARG_MUST_BE_SENT_BY_REF(zf, arg_num) \
661    CHECK_ARG_SEND_TYPE(zf, arg_num, ZEND_SEND_BY_REF)
662
663#define ARG_SHOULD_BE_SENT_BY_REF(zf, arg_num) \
664    CHECK_ARG_SEND_TYPE(zf, arg_num, ZEND_SEND_BY_REF|ZEND_SEND_PREFER_REF)
665
666#define ARG_MAY_BE_SENT_BY_REF(zf, arg_num) \
667    CHECK_ARG_SEND_TYPE(zf, arg_num, ZEND_SEND_PREFER_REF)
668
669#define ZEND_RETURN_VAL 0
670#define ZEND_RETURN_REF 1
671
672
673#define ZEND_RETURNS_FUNCTION 1<<0
674#define ZEND_RETURNS_NEW      1<<1
675#define ZEND_RETURNS_VALUE    1<<2
676
677#define ZEND_FAST_RET_TO_CATCH      1
678#define ZEND_FAST_RET_TO_FINALLY    2
679
680#define ZEND_FAST_CALL_FROM_CATCH   1
681#define ZEND_FAST_CALL_FROM_FINALLY 2
682
683#define ZEND_ARRAY_ELEMENT_REF      (1<<0)
684#define ZEND_ARRAY_NOT_PACKED       (1<<1)
685#define ZEND_ARRAY_SIZE_SHIFT       2
686
687END_EXTERN_C()
688
689#define ZEND_CLONE_FUNC_NAME        "__clone"
690#define ZEND_CONSTRUCTOR_FUNC_NAME  "__construct"
691#define ZEND_DESTRUCTOR_FUNC_NAME   "__destruct"
692#define ZEND_GET_FUNC_NAME          "__get"
693#define ZEND_SET_FUNC_NAME          "__set"
694#define ZEND_UNSET_FUNC_NAME        "__unset"
695#define ZEND_ISSET_FUNC_NAME        "__isset"
696#define ZEND_CALL_FUNC_NAME         "__call"
697#define ZEND_CALLSTATIC_FUNC_NAME   "__callstatic"
698#define ZEND_TOSTRING_FUNC_NAME     "__tostring"
699#define ZEND_AUTOLOAD_FUNC_NAME     "__autoload"
700#define ZEND_INVOKE_FUNC_NAME       "__invoke"
701#define ZEND_DEBUGINFO_FUNC_NAME    "__debuginfo"
702
703/* The following constants may be combined in CG(compiler_options)
704 * to change the default compiler behavior */
705
706/* generate extended debug information */
707#define ZEND_COMPILE_EXTENDED_INFO              (1<<0)
708
709/* call op_array handler of extendions */
710#define ZEND_COMPILE_HANDLE_OP_ARRAY            (1<<1)
711
712/* generate ZEND_INIT_FCALL_BY_NAME for internal functions instead of ZEND_INIT_FCALL */
713#define ZEND_COMPILE_IGNORE_INTERNAL_FUNCTIONS  (1<<2)
714
715/* don't perform early binding for classes inherited form internal ones;
716 * in namespaces assume that internal class that doesn't exist at compile-time
717 * may apper in run-time */
718#define ZEND_COMPILE_IGNORE_INTERNAL_CLASSES    (1<<3)
719
720/* generate ZEND_DECLARE_INHERITED_CLASS_DELAYED opcode to delay early binding */
721#define ZEND_COMPILE_DELAYED_BINDING            (1<<4)
722
723/* disable constant substitution at compile-time */
724#define ZEND_COMPILE_NO_CONSTANT_SUBSTITUTION   (1<<5)
725
726/* disable usage of builtin instruction for strlen() */
727#define ZEND_COMPILE_NO_BUILTIN_STRLEN          (1<<6)
728
729/* The default value for CG(compiler_options) */
730#define ZEND_COMPILE_DEFAULT                    ZEND_COMPILE_HANDLE_OP_ARRAY
731
732/* The default value for CG(compiler_options) during eval() */
733#define ZEND_COMPILE_DEFAULT_FOR_EVAL           0
734
735#endif /* ZEND_COMPILE_H */
736
737/*
738 * Local variables:
739 * tab-width: 4
740 * c-basic-offset: 4
741 * indent-tabs-mode: t
742 * End:
743 */
744