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