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