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 FREE_PNODE(znode)   zval_dtor(&znode->u.constant);
37
38#define SET_UNUSED(op)  op ## _type = IS_UNUSED
39
40#define INC_BPC(op_array)   if (op_array->fn_flags & ZEND_ACC_INTERACTIVE) { (CG(context).backpatch_count++); }
41#define DEC_BPC(op_array)   if (op_array->fn_flags & ZEND_ACC_INTERACTIVE) { (CG(context).backpatch_count--); }
42#define HANDLE_INTERACTIVE()  if (CG(active_op_array)->fn_flags & ZEND_ACC_INTERACTIVE) { execute_new_code(TSRMLS_C); }
43#define DO_TICKS()            if (Z_LVAL(CG(declarables).ticks)) { zend_do_ticks(TSRMLS_C); }
44
45#define RESET_DOC_COMMENT()        \
46    {                              \
47        if (CG(doc_comment)) {     \
48          STR_RELEASE(CG(doc_comment));  \
49          CG(doc_comment) = NULL;  \
50        }                          \
51    }
52
53typedef struct _zend_op_array zend_op_array;
54typedef struct _zend_op zend_op;
55
56typedef struct _zend_compiler_context {
57    zend_uint  opcodes_size;
58    int        vars_size;
59    int        literals_size;
60    int        current_brk_cont;
61    int        backpatch_count;
62    int        in_finally;
63    HashTable *labels;
64} zend_compiler_context;
65
66typedef union _znode_op {
67    zend_uint      constant;
68    zend_uint      var;
69    zend_uint      num;
70    zend_ulong     hash;
71    zend_uint      opline_num; /*  Needs to be signed */
72    zend_op       *jmp_addr;
73    zval          *zv;
74    void          *ptr;        /* Used for passing pointers from the compile to execution phase, currently used for traits */
75} znode_op;
76
77typedef struct _znode { /* used only during compilation */
78    int op_type;
79    union {
80        znode_op op;
81        zval constant; /* replaced by literal/zv */
82        zend_op_array *op_array;
83        zend_ast *ast;
84    } u;
85    zend_uint EA;      /* extended attributes */
86} znode;
87
88typedef struct _zend_execute_data zend_execute_data;
89
90#define ZEND_OPCODE_HANDLER_ARGS zend_execute_data *execute_data TSRMLS_DC
91#define ZEND_OPCODE_HANDLER_ARGS_PASSTHRU execute_data TSRMLS_CC
92
93typedef int (*user_opcode_handler_t) (ZEND_OPCODE_HANDLER_ARGS);
94typedef int (ZEND_FASTCALL *opcode_handler_t) (ZEND_OPCODE_HANDLER_ARGS);
95
96extern ZEND_API opcode_handler_t *zend_opcode_handlers;
97
98struct _zend_op {
99    opcode_handler_t handler;
100    znode_op op1;
101    znode_op op2;
102    znode_op result;
103    ulong extended_value;
104    uint lineno;
105    zend_uchar opcode;
106    zend_uchar op1_type;
107    zend_uchar op2_type;
108    zend_uchar result_type;
109};
110
111
112typedef struct _zend_brk_cont_element {
113    int start;
114    int cont;
115    int brk;
116    int parent;
117} zend_brk_cont_element;
118
119typedef struct _zend_label {
120    int brk_cont;
121    zend_uint opline_num;
122} zend_label;
123
124typedef struct _zend_try_catch_element {
125    zend_uint try_op;
126    zend_uint catch_op;  /* ketchup! */
127    zend_uint finally_op;
128    zend_uint finally_end;
129} zend_try_catch_element;
130
131#if SIZEOF_LONG == 8
132#define THIS_HASHVAL 6385726429UL
133#else
134#define THIS_HASHVAL 2090759133UL
135#endif
136
137/* method flags (types) */
138#define ZEND_ACC_STATIC         0x01
139#define ZEND_ACC_ABSTRACT       0x02
140#define ZEND_ACC_FINAL          0x04
141#define ZEND_ACC_IMPLEMENTED_ABSTRACT       0x08
142
143/* class flags (types) */
144/* 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). */
145/* ZEND_ACC_EXPLICIT_ABSTRACT_CLASS denotes that a class was explicitly defined as abstract by using the keyword. */
146#define ZEND_ACC_IMPLICIT_ABSTRACT_CLASS    0x10
147#define ZEND_ACC_EXPLICIT_ABSTRACT_CLASS    0x20
148#define ZEND_ACC_FINAL_CLASS                0x40
149#define ZEND_ACC_INTERFACE                  0x80
150#define ZEND_ACC_TRAIT                      0x120
151
152/* op_array flags */
153#define ZEND_ACC_INTERACTIVE                0x10
154
155/* method flags (visibility) */
156/* The order of those must be kept - public < protected < private */
157#define ZEND_ACC_PUBLIC     0x100
158#define ZEND_ACC_PROTECTED  0x200
159#define ZEND_ACC_PRIVATE    0x400
160#define ZEND_ACC_PPP_MASK  (ZEND_ACC_PUBLIC | ZEND_ACC_PROTECTED | ZEND_ACC_PRIVATE)
161
162#define ZEND_ACC_CHANGED    0x800
163#define ZEND_ACC_IMPLICIT_PUBLIC    0x1000
164
165/* method flags (special method detection) */
166#define ZEND_ACC_CTOR       0x2000
167#define ZEND_ACC_DTOR       0x4000
168#define ZEND_ACC_CLONE      0x8000
169
170/* method flag (bc only), any method that has this flag can be used statically and non statically. */
171#define ZEND_ACC_ALLOW_STATIC   0x10000
172
173/* shadow of parent's private method/property */
174#define ZEND_ACC_SHADOW 0x20000
175
176/* deprecation flag */
177#define ZEND_ACC_DEPRECATED 0x40000
178
179/* class implement interface(s) flag */
180#define ZEND_ACC_IMPLEMENT_INTERFACES 0x80000
181#define ZEND_ACC_IMPLEMENT_TRAITS     0x400000
182
183/* class constants updated */
184#define ZEND_ACC_CONSTANTS_UPDATED    0x100000
185
186/* user class has methods with static variables */
187#define ZEND_HAS_STATIC_IN_METHODS    0x800000
188
189
190#define ZEND_ACC_CLOSURE              0x100000
191#define ZEND_ACC_GENERATOR            0x800000
192
193/* function flag for internal user call handlers __call, __callstatic */
194#define ZEND_ACC_CALL_VIA_HANDLER     0x200000
195
196/* disable inline caching */
197#define ZEND_ACC_NEVER_CACHE          0x400000
198
199#define ZEND_ACC_VARIADIC               0x1000000
200
201#define ZEND_ACC_RETURN_REFERENCE       0x4000000
202#define ZEND_ACC_DONE_PASS_TWO          0x8000000
203
204/* function has arguments with type hinting */
205#define ZEND_ACC_HAS_TYPE_HINTS         0x10000000
206
207char *zend_visibility_string(zend_uint fn_flags);
208
209
210typedef struct _zend_property_info {
211    zend_uint flags;
212    zend_string *name;
213    ulong h;
214    int offset;
215    zend_string *doc_comment;
216    zend_class_entry *ce;
217} zend_property_info;
218
219typedef struct _zend_arg_info {
220    const char *name;           // TODO: convert into zend_string ???
221    zend_uint name_len;
222    const char *class_name;     // TODO: convert into zend_string ???
223    zend_uint class_name_len;
224    zend_uchar type_hint;
225    zend_uchar pass_by_reference;
226    zend_bool allow_null;
227    zend_bool is_variadic;
228} zend_arg_info;
229
230/* the following structure repeats the layout of zend_arg_info,
231 * but its fields have different meaning. It's used as the first element of
232 * arg_info array to define properties of internal functions.
233 */
234typedef struct _zend_internal_function_info {
235    const char *_name;
236    zend_uint _name_len;
237    const char *_class_name;
238    zend_uint required_num_args;
239    zend_uchar _type_hint;
240    zend_bool return_reference;
241    zend_bool _allow_null;
242    zend_bool _is_variadic;
243} zend_internal_function_info;
244
245struct _zend_op_array {
246    /* Common elements */
247    zend_uchar type;
248    zend_string *function_name;
249    zend_class_entry *scope;
250    zend_uint fn_flags;
251    zend_function *prototype;
252    zend_uint num_args;
253    zend_uint required_num_args;
254    zend_arg_info *arg_info;
255    /* END of common elements */
256
257    zend_uint *refcount;
258
259    zend_op *opcodes;
260    zend_uint last;
261
262    zend_string **vars;
263    int last_var;
264
265    zend_uint T;
266
267    zend_brk_cont_element *brk_cont_array;
268    int last_brk_cont;
269
270    zend_try_catch_element *try_catch_array;
271    int last_try_catch;
272    zend_bool has_finally_block;
273
274    /* static variables support */
275    HashTable *static_variables;
276
277    zend_uint this_var;
278
279    zend_string *filename;
280    zend_uint line_start;
281    zend_uint line_end;
282    zend_string *doc_comment;
283    zend_uint early_binding; /* the linked list of delayed declarations */
284
285    zval *literals;
286    int last_literal;
287
288    void **run_time_cache;
289    int  last_cache_slot;
290
291    void *reserved[ZEND_MAX_RESERVED_RESOURCES];
292};
293
294
295#define ZEND_RETURN_VALUE               0
296#define ZEND_RETURN_REFERENCE           1
297
298typedef struct _zend_internal_function {
299    /* Common elements */
300    zend_uchar type;
301    zend_string* function_name;
302    zend_class_entry *scope;
303    zend_uint fn_flags;
304    zend_function *prototype;
305    zend_uint num_args;
306    zend_uint required_num_args;
307    zend_arg_info *arg_info;
308    /* END of common elements */
309
310    void (*handler)(INTERNAL_FUNCTION_PARAMETERS);
311    struct _zend_module_entry *module;
312} zend_internal_function;
313
314#define ZEND_FN_SCOPE_NAME(function)  ((function) && (function)->common.scope ? (function)->common.scope->name->val : "")
315
316union _zend_function {
317    zend_uchar type;    /* MUST be the first element of this struct! */
318
319    struct {
320        zend_uchar type;  /* never used */
321        zend_string *function_name;
322        zend_class_entry *scope;
323        zend_uint fn_flags;
324        union _zend_function *prototype;
325        zend_uint num_args;
326        zend_uint required_num_args;
327        zend_arg_info *arg_info;
328    } common;
329
330    zend_op_array op_array;
331    zend_internal_function internal_function;
332};
333
334typedef struct _zend_function_call_entry {
335    zend_function *fbc;
336    zend_uint op_number;
337    zend_uint arg_num;
338    zend_bool uses_argument_unpacking;
339} zend_function_call_entry;
340
341typedef struct _zend_switch_entry {
342    znode cond;
343    int default_case;
344    int control_var;
345} zend_switch_entry;
346
347
348typedef struct _list_llist_element {
349    znode var;
350    zend_llist dimensions;
351    znode value;
352} list_llist_element;
353
354typedef enum _vm_frame_kind {
355    VM_FRAME_NESTED_FUNCTION,   /* stackless VM call to function */
356    VM_FRAME_NESTED_CODE,       /* stackless VM call to include/require/eval */
357    VM_FRAME_TOP_FUNCTION,      /* direct VM call to function from external C code */
358    VM_FRAME_TOP_CODE           /* direct VM call to "main" code from external C code */
359} vm_frame_kind;
360
361struct _zend_execute_data {
362    struct _zend_op     *opline;           /* executed opline                */
363    zend_execute_data   *call;             /* current call                   */
364    void               **run_time_cache;
365    zend_function       *func;             /* executed op_array              */
366    zend_uint            num_args;
367    zend_uchar           flags;
368    zend_uchar           frame_kind;
369    zend_class_entry    *called_scope;
370    zend_object         *object;
371    zend_execute_data   *prev_nested_call;
372    zend_execute_data   *prev_execute_data;
373    zval                *return_value;
374    zend_class_entry    *scope;            /* function scope (self)          */
375    zend_array          *symbol_table;
376    struct _zend_op     *fast_ret; /* used by FAST_CALL/FAST_RET (finally keyword) */
377    zend_object         *delayed_exception;
378    zval                 old_error_reporting;
379};
380
381#define ZEND_CALL_CTOR               (1 << 0)
382#define ZEND_CALL_CTOR_RESULT_UNUSED (1 << 1)
383
384#define ZEND_CALL_FRAME_SLOT \
385    ((ZEND_MM_ALIGNED_SIZE(sizeof(zend_execute_data)) + ZEND_MM_ALIGNED_SIZE(sizeof(zval)) - 1) / ZEND_MM_ALIGNED_SIZE(sizeof(zval)))
386
387#define ZEND_CALL_ARG(call, n) \
388    (((zval*)(call)) + ((n) + (ZEND_CALL_FRAME_SLOT - 1)))
389
390#define EX(element) execute_data.element
391
392#define EX_VAR_2(ex, n)         ((zval*)(((char*)(ex)) + ((int)(n))))
393#define EX_VAR_NUM_2(ex, n)     (((zval*)(ex)) + (ZEND_CALL_FRAME_SLOT + ((int)(n))))
394
395#define EX_VAR(n)               EX_VAR_2(execute_data, n)
396#define EX_VAR_NUM(n)           EX_VAR_NUM_2(execute_data, n)
397
398#define EX_VAR_TO_NUM(n)        (EX_VAR_2(NULL, n) - EX_VAR_NUM_2(NULL, 0))
399
400#define IS_CONST    (1<<0)
401#define IS_TMP_VAR  (1<<1)
402#define IS_VAR      (1<<2)
403#define IS_UNUSED   (1<<3)  /* Unused variable */
404#define IS_CV       (1<<4)  /* Compiled variable */
405
406#define EXT_TYPE_UNUSED (1<<5)
407
408#include "zend_globals.h"
409
410BEGIN_EXTERN_C()
411
412void init_compiler(TSRMLS_D);
413void shutdown_compiler(TSRMLS_D);
414void zend_init_compiler_data_structures(TSRMLS_D);
415void zend_init_compiler_context(TSRMLS_D);
416
417extern ZEND_API zend_op_array *(*zend_compile_file)(zend_file_handle *file_handle, int type TSRMLS_DC);
418extern ZEND_API zend_op_array *(*zend_compile_string)(zval *source_string, char *filename TSRMLS_DC);
419
420ZEND_API int lex_scan(zval *zendlval TSRMLS_DC);
421void startup_scanner(TSRMLS_D);
422void shutdown_scanner(TSRMLS_D);
423
424ZEND_API zend_string *zend_set_compiled_filename(zend_string *new_compiled_filename TSRMLS_DC);
425ZEND_API void zend_restore_compiled_filename(zend_string *original_compiled_filename TSRMLS_DC);
426ZEND_API zend_string *zend_get_compiled_filename(TSRMLS_D);
427ZEND_API int zend_get_compiled_lineno(TSRMLS_D);
428ZEND_API size_t zend_get_scanned_file_offset(TSRMLS_D);
429
430void zend_resolve_non_class_name(znode *element_name, zend_bool *check_namespace, zend_bool case_sensitive, HashTable *current_import_sub TSRMLS_DC);
431void zend_resolve_function_name(znode *element_name, zend_bool *check_namespace TSRMLS_DC);
432void zend_resolve_const_name(znode *element_name, zend_bool *check_namespace TSRMLS_DC);
433void zend_resolve_class_name(znode *class_name TSRMLS_DC);
434ZEND_API zend_string *zend_get_compiled_variable_name(const zend_op_array *op_array, zend_uint var);
435
436#ifdef ZTS
437const char *zend_get_zendtext(TSRMLS_D);
438int zend_get_zendleng(TSRMLS_D);
439#endif
440
441
442/* parser-driven code generators */
443void zend_do_binary_op(zend_uchar op, znode *result, znode *op1, znode *op2 TSRMLS_DC);
444void zend_do_unary_op(zend_uchar op, znode *result, znode *op1 TSRMLS_DC);
445void zend_do_binary_assign_op(zend_uchar op, znode *result, znode *op1, znode *op2 TSRMLS_DC);
446void zend_do_assign(znode *result, znode *variable, znode *value TSRMLS_DC);
447void zend_do_assign_ref(znode *result, znode *lvar, znode *rvar TSRMLS_DC);
448void fetch_simple_variable(znode *result, znode *varname, int bp TSRMLS_DC);
449void fetch_simple_variable_ex(znode *result, znode *varname, int bp, zend_uchar op TSRMLS_DC);
450void zend_do_indirect_references(znode *result, const znode *num_references, znode *variable TSRMLS_DC);
451void zend_do_fetch_static_variable(znode *varname, znode *static_assignment, int fetch_type TSRMLS_DC);
452void zend_do_fetch_global_variable(znode *varname, const znode *static_assignment, int fetch_type TSRMLS_DC);
453
454void fetch_array_begin(znode *result, znode *varname, znode *first_dim TSRMLS_DC);
455void fetch_array_dim(znode *result, znode *parent, znode *dim TSRMLS_DC);
456void fetch_string_offset(znode *result, znode *parent, znode *offset TSRMLS_DC);
457void zend_do_fetch_static_member(znode *result, znode *class_znode TSRMLS_DC);
458void zend_do_print(znode *result, znode *arg TSRMLS_DC);
459void zend_do_echo(znode *arg TSRMLS_DC);
460typedef int (*unary_op_type)(zval *, zval * TSRMLS_DC);
461typedef int (*binary_op_type)(zval *, zval *, zval * TSRMLS_DC);
462ZEND_API unary_op_type get_unary_op(int opcode);
463ZEND_API binary_op_type get_binary_op(int opcode);
464
465void zend_do_while_cond(znode *expr, znode *close_bracket_token TSRMLS_DC);
466void zend_do_while_end(const znode *while_token, const znode *close_bracket_token TSRMLS_DC);
467void zend_do_do_while_begin(TSRMLS_D);
468void zend_do_do_while_end(const znode *do_token, const znode *expr_open_bracket, znode *expr TSRMLS_DC);
469
470
471void zend_do_if_cond(znode *cond, znode *closing_bracket_token TSRMLS_DC);
472void zend_do_if_after_statement(const znode *closing_bracket_token, unsigned char initialize TSRMLS_DC);
473void zend_do_if_end(TSRMLS_D);
474
475void zend_do_for_cond(znode *expr, znode *second_semicolon_token TSRMLS_DC);
476void zend_do_for_before_statement(const znode *cond_start, const znode *second_semicolon_token TSRMLS_DC);
477void zend_do_for_end(const znode *second_semicolon_token TSRMLS_DC);
478
479void zend_do_pre_incdec(znode *result, znode *op1, zend_uchar op TSRMLS_DC);
480void zend_do_post_incdec(znode *result, znode *op1, zend_uchar op TSRMLS_DC);
481
482void zend_do_begin_variable_parse(TSRMLS_D);
483void zend_do_end_variable_parse(znode *variable, int type, int arg_offset TSRMLS_DC);
484
485void zend_check_writable_variable(const znode *variable);
486
487void zend_do_free(znode *op1 TSRMLS_DC);
488
489void zend_do_add_string(znode *result, znode *op1, znode *op2 TSRMLS_DC);
490void zend_do_add_variable(znode *result, znode *op1, znode *op2 TSRMLS_DC);
491
492int zend_do_verify_access_types(const znode *current_access_type, const znode *new_modifier);
493void zend_do_begin_function_declaration(znode *function_token, znode *function_name, int is_method, int return_reference, znode *fn_flags_znode TSRMLS_DC);
494void zend_do_end_function_declaration(const znode *function_token TSRMLS_DC);
495void zend_do_receive_param(zend_uchar op, znode *varname, znode *initialization, znode *class_type, zend_bool pass_by_reference, zend_bool is_variadic TSRMLS_DC);
496int zend_do_begin_function_call(znode *function_name, zend_bool check_namespace TSRMLS_DC);
497void zend_do_begin_method_call(znode *left_bracket TSRMLS_DC);
498void zend_do_clone(znode *result, znode *expr TSRMLS_DC);
499void zend_do_begin_dynamic_function_call(znode *function_name, int prefix_len TSRMLS_DC);
500void zend_do_fetch_class(znode *result, znode *class_name TSRMLS_DC);
501void zend_do_build_full_name(znode *result, znode *prefix, znode *name, int is_class_member TSRMLS_DC);
502int zend_do_begin_class_member_function_call(znode *class_name, znode *method_name TSRMLS_DC);
503void zend_do_end_function_call(znode *function_name, znode *result, int is_method, int is_dynamic_fcall TSRMLS_DC);
504void zend_do_return(znode *expr, int do_end_vparse TSRMLS_DC);
505void zend_do_yield(znode *result, znode *value, znode *key, zend_bool is_variable TSRMLS_DC);
506void zend_do_handle_exception(TSRMLS_D);
507
508void zend_do_begin_lambda_function_declaration(znode *result, znode *function_token, int return_reference, int is_static TSRMLS_DC);
509void zend_do_fetch_lexical_variable(znode *varname, zend_bool is_ref TSRMLS_DC);
510
511void zend_do_try(znode *try_token TSRMLS_DC);
512void zend_do_begin_catch(znode *try_token, znode *catch_class, znode *catch_var, znode *first_catch TSRMLS_DC);
513void zend_do_bind_catch(znode *try_token, znode *catch_token TSRMLS_DC);
514void zend_do_end_catch(znode *catch_token TSRMLS_DC);
515void zend_do_finally(znode *finally_token TSRMLS_DC);
516void zend_do_end_finally(znode *try_token, znode* catch_token, znode *finally_token TSRMLS_DC);
517void zend_do_throw(znode *expr TSRMLS_DC);
518
519ZEND_API int do_bind_function(const zend_op_array *op_array, zend_op *opline, HashTable *function_table, zend_bool compile_time TSRMLS_DC);
520ZEND_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);
521ZEND_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);
522ZEND_API void zend_do_inherit_interfaces(zend_class_entry *ce, const zend_class_entry *iface TSRMLS_DC);
523ZEND_API void zend_do_implement_interface(zend_class_entry *ce, zend_class_entry *iface TSRMLS_DC);
524void zend_do_implements_interface(znode *interface_znode TSRMLS_DC);
525
526/* Trait related functions */
527void zend_do_use_trait(znode *trait_znode TSRMLS_DC);
528void zend_prepare_reference(znode *result, znode *class_name, znode *method_name TSRMLS_DC);
529void zend_add_trait_precedence(znode *method_reference, znode *trait_list TSRMLS_DC);
530void zend_add_trait_alias(znode *method_reference, znode *modifiers, znode *alias TSRMLS_DC);
531
532ZEND_API void zend_do_implement_trait(zend_class_entry *ce, zend_class_entry *trait TSRMLS_DC);
533ZEND_API void zend_do_bind_traits(zend_class_entry *ce TSRMLS_DC);
534
535ZEND_API void zend_do_inheritance(zend_class_entry *ce, zend_class_entry *parent_ce TSRMLS_DC);
536void zend_do_early_binding(TSRMLS_D);
537ZEND_API void zend_do_delayed_early_binding(const zend_op_array *op_array TSRMLS_DC);
538
539void zend_do_pass_param(znode *param, zend_uchar op TSRMLS_DC);
540void zend_do_unpack_params(znode *params TSRMLS_DC);
541
542
543void zend_do_boolean_or_begin(znode *expr1, znode *op_token TSRMLS_DC);
544void zend_do_boolean_or_end(znode *result, znode *expr1, znode *expr2, const znode *op_token TSRMLS_DC);
545void zend_do_boolean_and_begin(znode *expr1, znode *op_token TSRMLS_DC);
546void zend_do_boolean_and_end(znode *result, znode *expr1, znode *expr2, const znode *op_token TSRMLS_DC);
547
548void zend_do_brk_cont(zend_uchar op, znode *expr TSRMLS_DC);
549
550void zend_do_switch_cond(const znode *cond TSRMLS_DC);
551void zend_do_switch_end(const znode *case_list TSRMLS_DC);
552void zend_do_case_before_statement(const znode *case_list, znode *case_token, znode *case_expr TSRMLS_DC);
553void zend_do_case_after_statement(znode *result, const znode *case_token TSRMLS_DC);
554void zend_do_default_before_statement(const znode *case_list, znode *default_token TSRMLS_DC);
555
556void zend_do_begin_class_declaration(const znode *class_token, znode *class_name, const znode *parent_class_name TSRMLS_DC);
557void zend_do_end_class_declaration(const znode *class_token, const znode *parent_token TSRMLS_DC);
558void zend_do_declare_property(znode *var_name, znode *value, zend_uint access_type TSRMLS_DC);
559void zend_do_declare_class_constant(znode *var_name, znode *value TSRMLS_DC);
560
561void zend_do_fetch_property(znode *result, znode *object, znode *property TSRMLS_DC);
562
563void zend_do_halt_compiler_register(TSRMLS_D);
564
565void zend_do_push_object(const znode *object TSRMLS_DC);
566void zend_do_pop_object(znode *object TSRMLS_DC);
567
568
569void zend_do_begin_new_object(znode *new_token, znode *class_type TSRMLS_DC);
570void zend_do_end_new_object(znode *result, const znode *new_token TSRMLS_DC);
571
572void zend_do_fetch_constant(znode *result, znode *constant_container, znode *constant_name, int mode, zend_bool check_namespace TSRMLS_DC);
573
574void zend_do_shell_exec(znode *result, znode *cmd TSRMLS_DC);
575
576void zend_do_init_array(znode *result, znode *expr, znode *offset, zend_bool is_ref TSRMLS_DC);
577void zend_do_add_array_element(znode *result, znode *expr, znode *offset, zend_bool is_ref TSRMLS_DC);
578void zend_do_end_array(znode *result, const znode *array_node TSRMLS_DC);
579void zend_do_list_init(TSRMLS_D);
580void zend_do_list_end(znode *result, znode *expr TSRMLS_DC);
581void zend_do_add_list_element(const znode *element TSRMLS_DC);
582void zend_do_new_list_begin(TSRMLS_D);
583void zend_do_new_list_end(TSRMLS_D);
584
585/* Functions for a null terminated pointer list, used for traits parsing and compilation */
586void zend_init_list(void *result, void *item TSRMLS_DC);
587void zend_add_to_list(void *result, void *item TSRMLS_DC);
588
589
590void zend_do_cast(znode *result, znode *expr, int type TSRMLS_DC);
591void zend_do_include_or_eval(int type, znode *result, znode *op1 TSRMLS_DC);
592
593void zend_do_unset(znode *variable TSRMLS_DC);
594void zend_do_isset_or_isempty(int type, znode *result, znode *variable TSRMLS_DC);
595
596void zend_do_instanceof(znode *result, znode *expr, znode *class_znode, int type TSRMLS_DC);
597
598void zend_do_foreach_begin(znode *foreach_token, znode *open_brackets_token, znode *array, znode *as_token, int variable TSRMLS_DC);
599void zend_do_foreach_cont(znode *foreach_token, const znode *open_brackets_token, const znode *as_token, znode *value, znode *key TSRMLS_DC);
600void zend_do_foreach_end(const znode *foreach_token, const znode *as_token TSRMLS_DC);
601
602void zend_do_declare_begin(TSRMLS_D);
603void zend_do_declare_stmt(znode *var, znode *val TSRMLS_DC);
604void zend_do_declare_end(const znode *declare_token TSRMLS_DC);
605
606void zend_do_exit(znode *result, znode *message TSRMLS_DC);
607
608void zend_do_begin_silence(znode *strudel_token TSRMLS_DC);
609void zend_do_end_silence(znode *strudel_token TSRMLS_DC);
610
611void zend_do_jmp_set(znode *value, znode *jmp_token, znode *colon_token TSRMLS_DC);
612void zend_do_jmp_set_else(znode *result, znode *false_value, const znode *jmp_token, znode *colon_token TSRMLS_DC);
613
614void zend_do_begin_qm_op(znode *cond, znode *qm_token TSRMLS_DC);
615void zend_do_qm_true(znode *true_value, znode *qm_token, znode *colon_token TSRMLS_DC);
616void zend_do_qm_false(znode *result, znode *false_value, znode *qm_token, const znode *colon_token TSRMLS_DC);
617
618void zend_do_extended_info(TSRMLS_D);
619void zend_do_extended_fcall_begin(TSRMLS_D);
620void zend_do_extended_fcall_end(TSRMLS_D);
621
622void zend_do_ticks(TSRMLS_D);
623
624void zend_do_abstract_method(const znode *function_name, znode *modifiers, const znode *body TSRMLS_DC);
625
626void zend_do_declare_constant(znode *name, znode *value TSRMLS_DC);
627void zend_do_build_namespace_name(znode *result, znode *prefix, znode *name TSRMLS_DC);
628void zend_do_begin_namespace(znode *name, zend_bool with_brackets TSRMLS_DC);
629void zend_do_end_namespace(TSRMLS_D);
630void zend_verify_namespace(TSRMLS_D);
631void zend_do_use(znode *name, znode *new_name, int is_global TSRMLS_DC);
632void zend_do_use_non_class(znode *ns_name, znode *new_name, int is_global, int is_function, zend_bool case_sensitive, HashTable *current_import_sub, HashTable *lookup_table TSRMLS_DC);
633void zend_do_use_function(znode *name, znode *new_name, int is_global TSRMLS_DC);
634void zend_do_use_const(znode *name, znode *new_name, int is_global TSRMLS_DC);
635void zend_do_end_compilation(TSRMLS_D);
636void zend_do_constant_expression(znode *result, zend_ast *ast TSRMLS_DC);
637
638void zend_do_resolve_class_name(znode *result, znode *class_name, int is_static TSRMLS_DC);
639
640void zend_do_label(znode *label TSRMLS_DC);
641void zend_do_goto(znode *label TSRMLS_DC);
642void zend_resolve_goto_label(zend_op_array *op_array, zend_op *opline, int pass2 TSRMLS_DC);
643void zend_release_labels(int temporary TSRMLS_DC);
644
645ZEND_API void function_add_ref(zend_function *function);
646
647#define INITIAL_OP_ARRAY_SIZE 64
648#define INITIAL_INTERACTIVE_OP_ARRAY_SIZE 8192
649
650
651/* helper functions in zend_language_scanner.l */
652ZEND_API zend_op_array *compile_file(zend_file_handle *file_handle, int type TSRMLS_DC);
653ZEND_API zend_op_array *compile_string(zval *source_string, char *filename TSRMLS_DC);
654ZEND_API zend_op_array *compile_filename(int type, zval *filename TSRMLS_DC);
655ZEND_API int zend_execute_scripts(int type TSRMLS_DC, zval *retval, int file_count, ...);
656ZEND_API int open_file_for_scanning(zend_file_handle *file_handle TSRMLS_DC);
657ZEND_API void init_op_array(zend_op_array *op_array, zend_uchar type, int initial_ops_size TSRMLS_DC);
658ZEND_API void destroy_op_array(zend_op_array *op_array TSRMLS_DC);
659ZEND_API void zend_destroy_file_handle(zend_file_handle *file_handle TSRMLS_DC);
660ZEND_API void zend_cleanup_user_class_data(zend_class_entry *ce TSRMLS_DC);
661ZEND_API void zend_cleanup_internal_class_data(zend_class_entry *ce TSRMLS_DC);
662ZEND_API void zend_cleanup_internal_classes(TSRMLS_D);
663ZEND_API void zend_cleanup_op_array_data(zend_op_array *op_array);
664
665ZEND_API void destroy_zend_function(zend_function *function TSRMLS_DC);
666ZEND_API void zend_function_dtor(zval *zv);
667ZEND_API void destroy_zend_class(zval *zv);
668void zend_class_add_ref(zval *zv);
669
670ZEND_API zend_string *zend_mangle_property_name(const char *src1, int src1_length, const char *src2, int src2_length, int internal);
671#define zend_unmangle_property_name(mangled_property, mangled_property_len, class_name, prop_name) \
672        zend_unmangle_property_name_ex(mangled_property, mangled_property_len, class_name, prop_name, NULL)
673ZEND_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);
674
675#define ZEND_FUNCTION_DTOR zend_function_dtor
676#define ZEND_CLASS_DTOR destroy_zend_class
677
678zend_op *get_next_op(zend_op_array *op_array TSRMLS_DC);
679void init_op(zend_op *op TSRMLS_DC);
680int get_next_op_number(zend_op_array *op_array);
681int print_class(zend_class_entry *class_entry TSRMLS_DC);
682void print_op_array(zend_op_array *op_array, int optimizations);
683ZEND_API int pass_two(zend_op_array *op_array TSRMLS_DC);
684zend_brk_cont_element *get_next_brk_cont_element(zend_op_array *op_array);
685void zend_do_first_catch(znode *open_parentheses TSRMLS_DC);
686void zend_initialize_try_catch_element(znode *catch_token TSRMLS_DC);
687void zend_do_mark_last_catch(const znode *first_catch, const znode *last_additional_catch TSRMLS_DC);
688ZEND_API zend_bool zend_is_compiling(TSRMLS_D);
689ZEND_API char *zend_make_compiled_string_description(const char *name TSRMLS_DC);
690ZEND_API void zend_initialize_class_data(zend_class_entry *ce, zend_bool nullify_handlers TSRMLS_DC);
691int zend_get_class_fetch_type(const char *class_name, uint class_name_len);
692
693typedef zend_bool (*zend_auto_global_callback)(zend_string *name TSRMLS_DC);
694typedef struct _zend_auto_global {
695    zend_string *name;
696    zend_auto_global_callback auto_global_callback;
697    zend_bool jit;
698    zend_bool armed;
699} zend_auto_global;
700
701ZEND_API int zend_register_auto_global(zend_string *name, zend_bool jit, zend_auto_global_callback auto_global_callback TSRMLS_DC);
702ZEND_API void zend_activate_auto_globals(TSRMLS_D);
703ZEND_API zend_bool zend_is_auto_global(zend_string *name TSRMLS_DC);
704ZEND_API size_t zend_dirname(char *path, size_t len);
705
706int zendlex(znode *zendlval TSRMLS_DC);
707
708int zend_add_literal(zend_op_array *op_array, zval *zv TSRMLS_DC);
709
710/* BEGIN: OPCODES */
711
712#include "zend_vm_opcodes.h"
713
714#define ZEND_OP_DATA                137
715
716/* END: OPCODES */
717
718/* class fetches */
719#define ZEND_FETCH_CLASS_DEFAULT    0
720#define ZEND_FETCH_CLASS_SELF       1
721#define ZEND_FETCH_CLASS_PARENT     2
722#define ZEND_FETCH_CLASS_STATIC     3
723#define ZEND_FETCH_CLASS_AUTO       4
724#define ZEND_FETCH_CLASS_INTERFACE  5
725#define ZEND_FETCH_CLASS_TRAIT      6
726#define ZEND_FETCH_CLASS_MASK        0x0f
727#define ZEND_FETCH_CLASS_NO_AUTOLOAD 0x80
728#define ZEND_FETCH_CLASS_SILENT      0x0100
729
730/* variable parsing type (compile-time) */
731#define ZEND_PARSED_MEMBER              (1<<0)
732#define ZEND_PARSED_METHOD_CALL         (1<<1)
733#define ZEND_PARSED_STATIC_MEMBER       (1<<2)
734#define ZEND_PARSED_FUNCTION_CALL       (1<<3)
735#define ZEND_PARSED_VARIABLE            (1<<4)
736#define ZEND_PARSED_REFERENCE_VARIABLE  (1<<5)
737#define ZEND_PARSED_NEW                 (1<<6)
738#define ZEND_PARSED_LIST_EXPR           (1<<7)
739
740/* unset types */
741#define ZEND_UNSET_REG 0
742
743/* var status for backpatching */
744#define BP_VAR_R            0
745#define BP_VAR_W            1
746#define BP_VAR_RW           2
747#define BP_VAR_IS           3
748#define BP_VAR_NA           4   /* if not applicable */
749#define BP_VAR_FUNC_ARG     5
750#define BP_VAR_UNSET        6
751
752
753#define ZEND_INTERNAL_FUNCTION              1
754#define ZEND_USER_FUNCTION                  2
755#define ZEND_OVERLOADED_FUNCTION            3
756#define ZEND_EVAL_CODE                      4
757#define ZEND_OVERLOADED_FUNCTION_TEMPORARY  5
758
759/* A quick check (type == ZEND_USER_FUNCTION || type == ZEND_EVAL_CODE) */
760#define ZEND_USER_CODE(type) ((type & 1) == 0)
761
762#define ZEND_INTERNAL_CLASS         1
763#define ZEND_USER_CLASS             2
764
765#define ZEND_EVAL               (1<<0)
766#define ZEND_INCLUDE            (1<<1)
767#define ZEND_INCLUDE_ONCE       (1<<2)
768#define ZEND_REQUIRE            (1<<3)
769#define ZEND_REQUIRE_ONCE       (1<<4)
770
771#define ZEND_CT (1<<0)
772#define ZEND_RT (1<<1)
773
774/* global/local fetches */
775#define ZEND_FETCH_GLOBAL           0x00000000
776#define ZEND_FETCH_LOCAL            0x10000000
777#define ZEND_FETCH_STATIC           0x20000000
778#define ZEND_FETCH_STATIC_MEMBER    0x30000000
779#define ZEND_FETCH_GLOBAL_LOCK      0x40000000
780#define ZEND_FETCH_LEXICAL          0x50000000
781
782#define ZEND_FETCH_TYPE_MASK        0x70000000
783
784#define ZEND_FETCH_STANDARD         0x00000000
785#define ZEND_FETCH_ADD_LOCK         0x08000000
786#define ZEND_FETCH_MAKE_REF         0x04000000
787
788#define ZEND_ISSET                  0x02000000
789#define ZEND_ISEMPTY                0x01000000
790#define ZEND_ISSET_ISEMPTY_MASK     (ZEND_ISSET | ZEND_ISEMPTY)
791#define ZEND_QUICK_SET              0x00800000
792
793#define ZEND_FETCH_ARG_MASK         0x000fffff
794
795#define ZEND_FE_FETCH_BYREF 1
796#define ZEND_FE_FETCH_WITH_KEY  2
797
798#define ZEND_FE_RESET_VARIABLE      (1<<0)
799#define ZEND_FE_RESET_REFERENCE     (1<<1)
800#define EXT_TYPE_FREE_ON_RETURN     (1<<2)
801
802#define ZEND_MEMBER_FUNC_CALL   1<<0
803
804#define ZEND_ARG_SEND_BY_REF (1<<0)
805#define ZEND_ARG_COMPILE_TIME_BOUND (1<<1)
806#define ZEND_ARG_SEND_FUNCTION (1<<2)
807#define ZEND_ARG_SEND_SILENT   (1<<3)
808
809#define ZEND_SEND_BY_VAL     0
810#define ZEND_SEND_BY_REF     1
811#define ZEND_SEND_PREFER_REF 2
812
813#define CHECK_ARG_SEND_TYPE(zf, arg_num, m) \
814    (EXPECTED((zf)->common.arg_info != NULL) && \
815    (EXPECTED(arg_num <= (zf)->common.num_args) \
816        ? ((zf)->common.arg_info[arg_num-1].pass_by_reference & (m)) \
817        : (UNEXPECTED((zf)->common.fn_flags & ZEND_ACC_VARIADIC) != 0) && \
818           ((zf)->common.arg_info[(zf)->common.num_args-1].pass_by_reference & (m))))
819
820#define ARG_MUST_BE_SENT_BY_REF(zf, arg_num) \
821    CHECK_ARG_SEND_TYPE(zf, arg_num, ZEND_SEND_BY_REF)
822
823#define ARG_SHOULD_BE_SENT_BY_REF(zf, arg_num) \
824    CHECK_ARG_SEND_TYPE(zf, arg_num, ZEND_SEND_BY_REF|ZEND_SEND_PREFER_REF)
825
826#define ARG_MAY_BE_SENT_BY_REF(zf, arg_num) \
827    CHECK_ARG_SEND_TYPE(zf, arg_num, ZEND_SEND_PREFER_REF)
828
829#define ZEND_RETURN_VAL 0
830#define ZEND_RETURN_REF 1
831
832
833#define ZEND_RETURNS_FUNCTION 1<<0
834#define ZEND_RETURNS_NEW      1<<1
835#define ZEND_RETURNS_VALUE    1<<2
836
837#define ZEND_FAST_RET_TO_CATCH      1
838#define ZEND_FAST_RET_TO_FINALLY    2
839
840#define ZEND_FAST_CALL_FROM_CATCH   1
841#define ZEND_FAST_CALL_FROM_FINALLY 2
842
843#define ZEND_ARRAY_ELEMENT_REF      (1<<0)
844#define ZEND_ARRAY_NOT_PACKED       (1<<1)
845#define ZEND_ARRAY_SIZE_SHIFT       2
846
847END_EXTERN_C()
848
849#define ZEND_CLONE_FUNC_NAME        "__clone"
850#define ZEND_CONSTRUCTOR_FUNC_NAME  "__construct"
851#define ZEND_DESTRUCTOR_FUNC_NAME   "__destruct"
852#define ZEND_GET_FUNC_NAME          "__get"
853#define ZEND_SET_FUNC_NAME          "__set"
854#define ZEND_UNSET_FUNC_NAME        "__unset"
855#define ZEND_ISSET_FUNC_NAME        "__isset"
856#define ZEND_CALL_FUNC_NAME         "__call"
857#define ZEND_CALLSTATIC_FUNC_NAME   "__callstatic"
858#define ZEND_TOSTRING_FUNC_NAME     "__tostring"
859#define ZEND_AUTOLOAD_FUNC_NAME     "__autoload"
860#define ZEND_INVOKE_FUNC_NAME       "__invoke"
861#define ZEND_DEBUGINFO_FUNC_NAME    "__debuginfo"
862
863/* The following constants may be combined in CG(compiler_options)
864 * to change the default compiler behavior */
865
866/* generate extended debug information */
867#define ZEND_COMPILE_EXTENDED_INFO              (1<<0)
868
869/* call op_array handler of extendions */
870#define ZEND_COMPILE_HANDLE_OP_ARRAY            (1<<1)
871
872/* generate ZEND_INIT_FCALL_BY_NAME for internal functions instead of ZEND_INIT_FCALL */
873#define ZEND_COMPILE_IGNORE_INTERNAL_FUNCTIONS  (1<<2)
874
875/* don't perform early binding for classes inherited form internal ones;
876 * in namespaces assume that internal class that doesn't exist at compile-time
877 * may apper in run-time */
878#define ZEND_COMPILE_IGNORE_INTERNAL_CLASSES    (1<<3)
879
880/* generate ZEND_DECLARE_INHERITED_CLASS_DELAYED opcode to delay early binding */
881#define ZEND_COMPILE_DELAYED_BINDING            (1<<4)
882
883/* disable constant substitution at compile-time */
884#define ZEND_COMPILE_NO_CONSTANT_SUBSTITUTION   (1<<5)
885
886/* disable usage of builtin instruction for strlen() */
887#define ZEND_COMPILE_NO_BUILTIN_STRLEN          (1<<6)
888
889/* The default value for CG(compiler_options) */
890#define ZEND_COMPILE_DEFAULT                    ZEND_COMPILE_HANDLE_OP_ARRAY
891
892/* The default value for CG(compiler_options) during eval() */
893#define ZEND_COMPILE_DEFAULT_FOR_EVAL           0
894
895#endif /* ZEND_COMPILE_H */
896
897/*
898 * Local variables:
899 * tab-width: 4
900 * c-basic-offset: 4
901 * indent-tabs-mode: t
902 * End:
903 */
904