xref: /PHP-5.5/Zend/zend_compile.h (revision cc70a465)
1 /*
2    +----------------------------------------------------------------------+
3    | Zend Engine                                                          |
4    +----------------------------------------------------------------------+
5    | Copyright (c) 1998-2015 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 
53 typedef struct _zend_op_array zend_op_array;
54 typedef struct _zend_op zend_op;
55 
56 typedef 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 
68 typedef 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 
77 typedef 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 
89 typedef 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 
99 typedef 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 
104 typedef int (*user_opcode_handler_t) (ZEND_OPCODE_HANDLER_ARGS);
105 typedef int (ZEND_FASTCALL *opcode_handler_t) (ZEND_OPCODE_HANDLER_ARGS);
106 
107 extern ZEND_API opcode_handler_t *zend_opcode_handlers;
108 
109 struct _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 
123 typedef struct _zend_brk_cont_element {
124 	int start;
125 	int cont;
126 	int brk;
127 	int parent;
128 } zend_brk_cont_element;
129 
130 typedef struct _zend_label {
131 	int brk_cont;
132 	zend_uint opline_num;
133 } zend_label;
134 
135 typedef 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 
216 char *zend_visibility_string(zend_uint fn_flags);
217 
218 
219 typedef 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 
231 typedef 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  */
245 typedef 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 
255 typedef struct _zend_compiled_variable {
256 	const char *name;
257 	int name_len;
258 	ulong hash_value;
259 } zend_compiled_variable;
260 
261 struct _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 
318 typedef 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 
336 typedef 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 
355 typedef struct _zend_function_state {
356 	zend_function *function;
357 	void **arguments;
358 } zend_function_state;
359 
360 
361 typedef struct _zend_switch_entry {
362 	znode cond;
363 	int default_case;
364 	int control_var;
365 } zend_switch_entry;
366 
367 
368 typedef struct _list_llist_element {
369 	znode var;
370 	zend_llist dimensions;
371 	znode value;
372 } list_llist_element;
373 
374 union _temp_variable;
375 
376 typedef 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 
384 struct _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 
420 BEGIN_EXTERN_C()
421 
422 void init_compiler(TSRMLS_D);
423 void shutdown_compiler(TSRMLS_D);
424 void zend_init_compiler_data_structures(TSRMLS_D);
425 void zend_init_compiler_context(TSRMLS_D);
426 
427 extern ZEND_API zend_op_array *(*zend_compile_file)(zend_file_handle *file_handle, int type TSRMLS_DC);
428 extern ZEND_API zend_op_array *(*zend_compile_string)(zval *source_string, char *filename TSRMLS_DC);
429 
430 ZEND_API int lex_scan(zval *zendlval TSRMLS_DC);
431 void startup_scanner(TSRMLS_D);
432 void shutdown_scanner(TSRMLS_D);
433 
434 ZEND_API char *zend_set_compiled_filename(const char *new_compiled_filename TSRMLS_DC);
435 ZEND_API void zend_restore_compiled_filename(char *original_compiled_filename TSRMLS_DC);
436 ZEND_API char *zend_get_compiled_filename(TSRMLS_D);
437 ZEND_API int zend_get_compiled_lineno(TSRMLS_D);
438 ZEND_API size_t zend_get_scanned_file_offset(TSRMLS_D);
439 
440 void zend_resolve_non_class_name(znode *element_name, zend_bool check_namespace TSRMLS_DC);
441 void zend_resolve_class_name(znode *class_name, ulong fetch_type, int check_ns_name TSRMLS_DC);
442 ZEND_API const char* zend_get_compiled_variable_name(const zend_op_array *op_array, zend_uint var, int* name_len);
443 
444 #ifdef ZTS
445 const char *zend_get_zendtext(TSRMLS_D);
446 int zend_get_zendleng(TSRMLS_D);
447 #endif
448 
449 
450 /* parser-driven code generators */
451 void zend_do_binary_op(zend_uchar op, znode *result, const znode *op1, const znode *op2 TSRMLS_DC);
452 void zend_do_unary_op(zend_uchar op, znode *result, const znode *op1 TSRMLS_DC);
453 void zend_do_binary_assign_op(zend_uchar op, znode *result, const znode *op1, const znode *op2 TSRMLS_DC);
454 void zend_do_assign(znode *result, znode *variable, znode *value TSRMLS_DC);
455 void zend_do_assign_ref(znode *result, const znode *lvar, const znode *rvar TSRMLS_DC);
456 void fetch_simple_variable(znode *result, znode *varname, int bp TSRMLS_DC);
457 void fetch_simple_variable_ex(znode *result, znode *varname, int bp, zend_uchar op TSRMLS_DC);
458 void zend_do_indirect_references(znode *result, const znode *num_references, znode *variable TSRMLS_DC);
459 void zend_do_fetch_static_variable(znode *varname, const znode *static_assignment, int fetch_type TSRMLS_DC);
460 void zend_do_fetch_global_variable(znode *varname, const znode *static_assignment, int fetch_type TSRMLS_DC);
461 
462 void fetch_array_begin(znode *result, znode *varname, znode *first_dim TSRMLS_DC);
463 void fetch_array_dim(znode *result, const znode *parent, const znode *dim TSRMLS_DC);
464 void fetch_string_offset(znode *result, const znode *parent, const znode *offset TSRMLS_DC);
465 void zend_do_fetch_static_member(znode *result, znode *class_znode TSRMLS_DC);
466 void zend_do_print(znode *result, const znode *arg TSRMLS_DC);
467 void zend_do_echo(const znode *arg TSRMLS_DC);
468 typedef int (*unary_op_type)(zval *, zval * TSRMLS_DC);
469 typedef int (*binary_op_type)(zval *, zval *, zval * TSRMLS_DC);
470 ZEND_API unary_op_type get_unary_op(int opcode);
471 ZEND_API binary_op_type get_binary_op(int opcode);
472 
473 void zend_do_while_cond(const znode *expr, znode *close_bracket_token TSRMLS_DC);
474 void zend_do_while_end(const znode *while_token, const znode *close_bracket_token TSRMLS_DC);
475 void zend_do_do_while_begin(TSRMLS_D);
476 void zend_do_do_while_end(const znode *do_token, const znode *expr_open_bracket, const znode *expr TSRMLS_DC);
477 
478 
479 void zend_do_if_cond(const znode *cond, znode *closing_bracket_token TSRMLS_DC);
480 void zend_do_if_after_statement(const znode *closing_bracket_token, unsigned char initialize TSRMLS_DC);
481 void zend_do_if_end(TSRMLS_D);
482 
483 void zend_do_for_cond(const znode *expr, znode *second_semicolon_token TSRMLS_DC);
484 void zend_do_for_before_statement(const znode *cond_start, const znode *second_semicolon_token TSRMLS_DC);
485 void zend_do_for_end(const znode *second_semicolon_token TSRMLS_DC);
486 
487 void zend_do_pre_incdec(znode *result, const znode *op1, zend_uchar op TSRMLS_DC);
488 void zend_do_post_incdec(znode *result, const znode *op1, zend_uchar op TSRMLS_DC);
489 
490 void zend_do_begin_variable_parse(TSRMLS_D);
491 void zend_do_end_variable_parse(znode *variable, int type, int arg_offset TSRMLS_DC);
492 
493 void zend_check_writable_variable(const znode *variable);
494 
495 void zend_do_free(znode *op1 TSRMLS_DC);
496 
497 void zend_do_add_string(znode *result, const znode *op1, znode *op2 TSRMLS_DC);
498 void zend_do_add_variable(znode *result, const znode *op1, const znode *op2 TSRMLS_DC);
499 
500 int zend_do_verify_access_types(const znode *current_access_type, const znode *new_modifier);
501 void zend_do_begin_function_declaration(znode *function_token, znode *function_name, int is_method, int return_reference, znode *fn_flags_znode TSRMLS_DC);
502 void zend_do_end_function_declaration(const znode *function_token TSRMLS_DC);
503 void 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);
504 int zend_do_begin_function_call(znode *function_name, zend_bool check_namespace TSRMLS_DC);
505 void zend_do_begin_method_call(znode *left_bracket TSRMLS_DC);
506 void zend_do_clone(znode *result, const znode *expr TSRMLS_DC);
507 void zend_do_begin_dynamic_function_call(znode *function_name, int prefix_len TSRMLS_DC);
508 void zend_do_fetch_class(znode *result, znode *class_name TSRMLS_DC);
509 void zend_do_build_full_name(znode *result, znode *prefix, znode *name, int is_class_member TSRMLS_DC);
510 int zend_do_begin_class_member_function_call(znode *class_name, znode *method_name TSRMLS_DC);
511 void zend_do_end_function_call(znode *function_name, znode *result, const znode *argument_list, int is_method, int is_dynamic_fcall TSRMLS_DC);
512 void zend_do_return(znode *expr, int do_end_vparse TSRMLS_DC);
513 void zend_do_yield(znode *result, znode *value, const znode *key, zend_bool is_variable TSRMLS_DC);
514 void zend_do_handle_exception(TSRMLS_D);
515 
516 void zend_do_begin_lambda_function_declaration(znode *result, znode *function_token, int return_reference, int is_static TSRMLS_DC);
517 void zend_do_fetch_lexical_variable(znode *varname, zend_bool is_ref TSRMLS_DC);
518 
519 void zend_do_try(znode *try_token TSRMLS_DC);
520 void zend_do_begin_catch(znode *try_token, znode *catch_class, znode *catch_var, znode *first_catch TSRMLS_DC);
521 void zend_do_bind_catch(znode *try_token, znode *catch_token TSRMLS_DC);
522 void zend_do_end_catch(znode *catch_token TSRMLS_DC);
523 void zend_do_finally(znode *finally_token TSRMLS_DC);
524 void zend_do_end_finally(znode *try_token, znode* catch_token, znode *finally_token TSRMLS_DC);
525 void zend_do_throw(const znode *expr TSRMLS_DC);
526 
527 ZEND_API int do_bind_function(const zend_op_array *op_array, zend_op *opline, HashTable *function_table, zend_bool compile_time);
528 ZEND_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);
529 ZEND_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);
530 ZEND_API void zend_do_inherit_interfaces(zend_class_entry *ce, const zend_class_entry *iface TSRMLS_DC);
531 ZEND_API void zend_do_implement_interface(zend_class_entry *ce, zend_class_entry *iface TSRMLS_DC);
532 void zend_do_implements_interface(znode *interface_znode TSRMLS_DC);
533 
534 /* Trait related functions */
535 void zend_do_use_trait(znode *trait_znode TSRMLS_DC);
536 void zend_prepare_reference(znode *result, znode *class_name, znode *method_name TSRMLS_DC);
537 void zend_add_trait_precedence(znode *method_reference, znode *trait_list TSRMLS_DC);
538 void zend_add_trait_alias(znode *method_reference, znode *modifiers, znode *alias TSRMLS_DC);
539 
540 ZEND_API void zend_do_implement_trait(zend_class_entry *ce, zend_class_entry *trait TSRMLS_DC);
541 ZEND_API void zend_do_bind_traits(zend_class_entry *ce TSRMLS_DC);
542 
543 ZEND_API void zend_do_inheritance(zend_class_entry *ce, zend_class_entry *parent_ce TSRMLS_DC);
544 void zend_do_early_binding(TSRMLS_D);
545 ZEND_API void zend_do_delayed_early_binding(const zend_op_array *op_array TSRMLS_DC);
546 
547 void zend_do_pass_param(znode *param, zend_uchar op, int offset TSRMLS_DC);
548 
549 
550 void zend_do_boolean_or_begin(znode *expr1, znode *op_token TSRMLS_DC);
551 void zend_do_boolean_or_end(znode *result, const znode *expr1, const znode *expr2, znode *op_token TSRMLS_DC);
552 void zend_do_boolean_and_begin(znode *expr1, znode *op_token TSRMLS_DC);
553 void zend_do_boolean_and_end(znode *result, const znode *expr1, const znode *expr2, const znode *op_token TSRMLS_DC);
554 
555 void zend_do_brk_cont(zend_uchar op, const znode *expr TSRMLS_DC);
556 
557 void zend_do_switch_cond(const znode *cond TSRMLS_DC);
558 void zend_do_switch_end(const znode *case_list TSRMLS_DC);
559 void zend_do_case_before_statement(const znode *case_list, znode *case_token, const znode *case_expr TSRMLS_DC);
560 void zend_do_case_after_statement(znode *result, const znode *case_token TSRMLS_DC);
561 void zend_do_default_before_statement(const znode *case_list, znode *default_token TSRMLS_DC);
562 
563 void zend_do_begin_class_declaration(const znode *class_token, znode *class_name, const znode *parent_class_name TSRMLS_DC);
564 void zend_do_end_class_declaration(const znode *class_token, const znode *parent_token TSRMLS_DC);
565 void zend_do_declare_property(const znode *var_name, const znode *value, zend_uint access_type TSRMLS_DC);
566 void zend_do_declare_class_constant(znode *var_name, const znode *value TSRMLS_DC);
567 
568 void zend_do_fetch_property(znode *result, znode *object, const znode *property TSRMLS_DC);
569 
570 void zend_do_halt_compiler_register(TSRMLS_D);
571 
572 void zend_do_push_object(const znode *object TSRMLS_DC);
573 void zend_do_pop_object(znode *object TSRMLS_DC);
574 
575 
576 void zend_do_begin_new_object(znode *new_token, znode *class_type TSRMLS_DC);
577 void zend_do_end_new_object(znode *result, const znode *new_token, const znode *argument_list TSRMLS_DC);
578 
579 void zend_do_fetch_constant(znode *result, znode *constant_container, znode *constant_name, int mode, zend_bool check_namespace TSRMLS_DC);
580 
581 void zend_do_shell_exec(znode *result, const znode *cmd TSRMLS_DC);
582 
583 void zend_do_init_array(znode *result, const znode *expr, const znode *offset, zend_bool is_ref TSRMLS_DC);
584 void zend_do_add_array_element(znode *result, const znode *expr, const znode *offset, zend_bool is_ref TSRMLS_DC);
585 void zend_do_add_static_array_element(znode *result, znode *offset, const znode *expr);
586 void zend_do_list_init(TSRMLS_D);
587 void zend_do_list_end(znode *result, znode *expr TSRMLS_DC);
588 void zend_do_add_list_element(const znode *element TSRMLS_DC);
589 void zend_do_new_list_begin(TSRMLS_D);
590 void zend_do_new_list_end(TSRMLS_D);
591 
592 /* Functions for a null terminated pointer list, used for traits parsing and compilation */
593 void zend_init_list(void *result, void *item TSRMLS_DC);
594 void zend_add_to_list(void *result, void *item TSRMLS_DC);
595 
596 
597 void zend_do_cast(znode *result, const znode *expr, int type TSRMLS_DC);
598 void zend_do_include_or_eval(int type, znode *result, const znode *op1 TSRMLS_DC);
599 
600 void zend_do_unset(const znode *variable TSRMLS_DC);
601 void zend_do_isset_or_isempty(int type, znode *result, znode *variable TSRMLS_DC);
602 
603 void zend_do_instanceof(znode *result, const znode *expr, const znode *class_znode, int type TSRMLS_DC);
604 
605 void zend_do_foreach_begin(znode *foreach_token, znode *open_brackets_token, znode *array, znode *as_token, int variable TSRMLS_DC);
606 void zend_do_foreach_cont(znode *foreach_token, const znode *open_brackets_token, const znode *as_token, znode *value, znode *key TSRMLS_DC);
607 void zend_do_foreach_end(const znode *foreach_token, const znode *as_token TSRMLS_DC);
608 
609 void zend_do_declare_begin(TSRMLS_D);
610 void zend_do_declare_stmt(znode *var, znode *val TSRMLS_DC);
611 void zend_do_declare_end(const znode *declare_token TSRMLS_DC);
612 
613 void zend_do_exit(znode *result, const znode *message TSRMLS_DC);
614 
615 void zend_do_begin_silence(znode *strudel_token TSRMLS_DC);
616 void zend_do_end_silence(const znode *strudel_token TSRMLS_DC);
617 
618 void zend_do_jmp_set(const znode *value, znode *jmp_token, znode *colon_token TSRMLS_DC);
619 void zend_do_jmp_set_else(znode *result, const znode *false_value, const znode *jmp_token, const znode *colon_token TSRMLS_DC);
620 
621 void zend_do_begin_qm_op(const znode *cond, znode *qm_token TSRMLS_DC);
622 void zend_do_qm_true(const znode *true_value, znode *qm_token, znode *colon_token TSRMLS_DC);
623 void zend_do_qm_false(znode *result, const znode *false_value, const znode *qm_token, const znode *colon_token TSRMLS_DC);
624 
625 void zend_do_extended_info(TSRMLS_D);
626 void zend_do_extended_fcall_begin(TSRMLS_D);
627 void zend_do_extended_fcall_end(TSRMLS_D);
628 
629 void zend_do_ticks(TSRMLS_D);
630 
631 void zend_do_abstract_method(const znode *function_name, znode *modifiers, const znode *body TSRMLS_DC);
632 
633 void zend_do_declare_constant(znode *name, znode *value TSRMLS_DC);
634 void zend_do_build_namespace_name(znode *result, znode *prefix, znode *name TSRMLS_DC);
635 void zend_do_begin_namespace(const znode *name, zend_bool with_brackets TSRMLS_DC);
636 void zend_do_end_namespace(TSRMLS_D);
637 void zend_verify_namespace(TSRMLS_D);
638 void zend_do_use(znode *name, znode *new_name TSRMLS_DC);
639 void zend_do_end_compilation(TSRMLS_D);
640 
641 void zend_do_resolve_class_name(znode *result, znode *class_name, int is_static TSRMLS_DC);
642 
643 void zend_do_label(znode *label TSRMLS_DC);
644 void zend_do_goto(const znode *label TSRMLS_DC);
645 void zend_resolve_goto_label(zend_op_array *op_array, zend_op *opline, int pass2 TSRMLS_DC);
646 void zend_release_labels(int temporary TSRMLS_DC);
647 
648 ZEND_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 */
655 ZEND_API zend_op_array *compile_file(zend_file_handle *file_handle, int type TSRMLS_DC);
656 ZEND_API zend_op_array *compile_string(zval *source_string, char *filename TSRMLS_DC);
657 ZEND_API zend_op_array *compile_filename(int type, zval *filename TSRMLS_DC);
658 ZEND_API int zend_execute_scripts(int type TSRMLS_DC, zval **retval, int file_count, ...);
659 ZEND_API int open_file_for_scanning(zend_file_handle *file_handle TSRMLS_DC);
660 ZEND_API void init_op_array(zend_op_array *op_array, zend_uchar type, int initial_ops_size TSRMLS_DC);
661 ZEND_API void destroy_op_array(zend_op_array *op_array TSRMLS_DC);
662 ZEND_API void zend_destroy_file_handle(zend_file_handle *file_handle TSRMLS_DC);
663 ZEND_API int zend_cleanup_class_data(zend_class_entry **pce TSRMLS_DC);
664 ZEND_API int zend_cleanup_user_class_data(zend_class_entry **pce TSRMLS_DC);
665 ZEND_API void zend_cleanup_internal_class_data(zend_class_entry *ce TSRMLS_DC);
666 ZEND_API void zend_cleanup_internal_classes(TSRMLS_D);
667 ZEND_API int zend_cleanup_function_data(zend_function *function TSRMLS_DC);
668 ZEND_API int zend_cleanup_function_data_full(zend_function *function TSRMLS_DC);
669 ZEND_API int clean_non_persistent_function_full(zend_function *function TSRMLS_DC);
670 ZEND_API int clean_non_persistent_class_full(zend_class_entry **ce TSRMLS_DC);
671 
672 ZEND_API void destroy_zend_function(zend_function *function TSRMLS_DC);
673 ZEND_API void zend_function_dtor(zend_function *function);
674 ZEND_API void destroy_zend_class(zend_class_entry **pce);
675 void zend_class_add_ref(zend_class_entry **ce);
676 
677 ZEND_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);
678 #define zend_unmangle_property_name(mangled_property, mangled_property_len, class_name, prop_name) \
679         zend_unmangle_property_name_ex(mangled_property, mangled_property_len, class_name, prop_name, NULL)
680 ZEND_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);
681 
682 #define ZEND_FUNCTION_DTOR (void (*)(void *)) zend_function_dtor
683 #define ZEND_CLASS_DTOR (void (*)(void *)) destroy_zend_class
684 
685 zend_op *get_next_op(zend_op_array *op_array TSRMLS_DC);
686 void init_op(zend_op *op TSRMLS_DC);
687 int get_next_op_number(zend_op_array *op_array);
688 int print_class(zend_class_entry *class_entry TSRMLS_DC);
689 void print_op_array(zend_op_array *op_array, int optimizations);
690 ZEND_API int pass_two(zend_op_array *op_array TSRMLS_DC);
691 zend_brk_cont_element *get_next_brk_cont_element(zend_op_array *op_array);
692 void zend_do_first_catch(znode *open_parentheses TSRMLS_DC);
693 void zend_initialize_try_catch_element(znode *catch_token TSRMLS_DC);
694 void zend_do_mark_last_catch(const znode *first_catch, const znode *last_additional_catch TSRMLS_DC);
695 ZEND_API zend_bool zend_is_compiling(TSRMLS_D);
696 ZEND_API char *zend_make_compiled_string_description(const char *name TSRMLS_DC);
697 ZEND_API void zend_initialize_class_data(zend_class_entry *ce, zend_bool nullify_handlers TSRMLS_DC);
698 int zend_get_class_fetch_type(const char *class_name, uint class_name_len);
699 
700 typedef zend_bool (*zend_auto_global_callback)(const char *name, uint name_len TSRMLS_DC);
701 typedef struct _zend_auto_global {
702 	const char *name;
703 	uint name_len;
704 	zend_auto_global_callback auto_global_callback;
705 	zend_bool jit;
706 	zend_bool armed;
707 } zend_auto_global;
708 
709 ZEND_API int zend_register_auto_global(const char *name, uint name_len, zend_bool jit, zend_auto_global_callback auto_global_callback TSRMLS_DC);
710 ZEND_API void zend_activate_auto_globals(TSRMLS_D);
711 ZEND_API zend_bool zend_is_auto_global(const char *name, uint name_len TSRMLS_DC);
712 ZEND_API zend_bool zend_is_auto_global_quick(const char *name, uint name_len, ulong hashval TSRMLS_DC);
713 ZEND_API size_t zend_dirname(char *path, size_t len);
714 
715 int zendlex(znode *zendlval TSRMLS_DC);
716 
717 int zend_add_literal(zend_op_array *op_array, const zval *zv TSRMLS_DC);
718 
719 /* BEGIN: OPCODES */
720 
721 #include "zend_vm_opcodes.h"
722 
723 #define ZEND_OP_DATA				137
724 
725 /* END: OPCODES */
726 
727 /* class fetches */
728 #define ZEND_FETCH_CLASS_DEFAULT	0
729 #define ZEND_FETCH_CLASS_SELF		1
730 #define ZEND_FETCH_CLASS_PARENT		2
731 #define ZEND_FETCH_CLASS_MAIN		3
732 #define ZEND_FETCH_CLASS_GLOBAL		4
733 #define ZEND_FETCH_CLASS_AUTO		5
734 #define ZEND_FETCH_CLASS_INTERFACE	6
735 #define ZEND_FETCH_CLASS_STATIC		7
736 #define ZEND_FETCH_CLASS_TRAIT		14
737 #define ZEND_FETCH_CLASS_MASK        0x0f
738 #define ZEND_FETCH_CLASS_NO_AUTOLOAD 0x80
739 #define ZEND_FETCH_CLASS_SILENT      0x0100
740 
741 /* variable parsing type (compile-time) */
742 #define ZEND_PARSED_MEMBER				(1<<0)
743 #define ZEND_PARSED_METHOD_CALL			(1<<1)
744 #define ZEND_PARSED_STATIC_MEMBER		(1<<2)
745 #define ZEND_PARSED_FUNCTION_CALL		(1<<3)
746 #define ZEND_PARSED_VARIABLE			(1<<4)
747 #define ZEND_PARSED_REFERENCE_VARIABLE	(1<<5)
748 #define ZEND_PARSED_NEW					(1<<6)
749 #define ZEND_PARSED_LIST_EXPR			(1<<7)
750 
751 
752 /* unset types */
753 #define ZEND_UNSET_REG 0
754 
755 /* var status for backpatching */
756 #define BP_VAR_R			0
757 #define BP_VAR_W			1
758 #define BP_VAR_RW			2
759 #define BP_VAR_IS			3
760 #define BP_VAR_NA			4	/* if not applicable */
761 #define BP_VAR_FUNC_ARG		5
762 #define BP_VAR_UNSET		6
763 
764 
765 #define ZEND_INTERNAL_FUNCTION				1
766 #define ZEND_USER_FUNCTION					2
767 #define ZEND_OVERLOADED_FUNCTION			3
768 #define	ZEND_EVAL_CODE						4
769 #define ZEND_OVERLOADED_FUNCTION_TEMPORARY	5
770 
771 #define ZEND_INTERNAL_CLASS         1
772 #define ZEND_USER_CLASS             2
773 
774 #define ZEND_EVAL				(1<<0)
775 #define ZEND_INCLUDE			(1<<1)
776 #define ZEND_INCLUDE_ONCE		(1<<2)
777 #define ZEND_REQUIRE			(1<<3)
778 #define ZEND_REQUIRE_ONCE		(1<<4)
779 
780 #define ZEND_CT	(1<<0)
781 #define ZEND_RT (1<<1)
782 
783 /* global/local fetches */
784 #define ZEND_FETCH_GLOBAL			0x00000000
785 #define ZEND_FETCH_LOCAL			0x10000000
786 #define ZEND_FETCH_STATIC			0x20000000
787 #define ZEND_FETCH_STATIC_MEMBER	0x30000000
788 #define ZEND_FETCH_GLOBAL_LOCK		0x40000000
789 #define ZEND_FETCH_LEXICAL			0x50000000
790 
791 #define ZEND_FETCH_TYPE_MASK		0x70000000
792 
793 #define ZEND_FETCH_STANDARD		    0x00000000
794 #define ZEND_FETCH_ADD_LOCK		    0x08000000
795 #define ZEND_FETCH_MAKE_REF		    0x04000000
796 
797 #define ZEND_ISSET				    0x02000000
798 #define ZEND_ISEMPTY			    0x01000000
799 #define ZEND_ISSET_ISEMPTY_MASK	    (ZEND_ISSET | ZEND_ISEMPTY)
800 #define ZEND_QUICK_SET			    0x00800000
801 
802 #define ZEND_FETCH_ARG_MASK         0x000fffff
803 
804 #define ZEND_FE_FETCH_BYREF	1
805 #define ZEND_FE_FETCH_WITH_KEY	2
806 
807 #define ZEND_FE_RESET_VARIABLE 		(1<<0)
808 #define ZEND_FE_RESET_REFERENCE		(1<<1)
809 #define EXT_TYPE_FREE_ON_RETURN		(1<<2)
810 
811 #define ZEND_MEMBER_FUNC_CALL	1<<0
812 
813 #define ZEND_ARG_SEND_BY_REF (1<<0)
814 #define ZEND_ARG_COMPILE_TIME_BOUND (1<<1)
815 #define ZEND_ARG_SEND_FUNCTION (1<<2)
816 #define ZEND_ARG_SEND_SILENT   (1<<3)
817 
818 #define ZEND_SEND_BY_VAL     0
819 #define ZEND_SEND_BY_REF     1
820 #define ZEND_SEND_PREFER_REF 2
821 
822 #define CHECK_ARG_SEND_TYPE(zf, arg_num, m1, m2)											\
823 	((zf) &&																				\
824 	  ((((zend_function*)(zf))->common.arg_info && 											\
825 	    arg_num <= ((zend_function*)(zf))->common.num_args) ?								\
826 	   (((zend_function *)(zf))->common.arg_info[arg_num-1].pass_by_reference & (m1)) :		\
827        (((zend_function *)(zf))->common.fn_flags & (m2))))
828 
829 #define ARG_MUST_BE_SENT_BY_REF(zf, arg_num) \
830 	CHECK_ARG_SEND_TYPE(zf, arg_num, ZEND_SEND_BY_REF, ZEND_ACC_PASS_REST_BY_REFERENCE)
831 
832 #define ARG_SHOULD_BE_SENT_BY_REF(zf, arg_num) \
833 	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)
834 
835 #define ARG_MAY_BE_SENT_BY_REF(zf, arg_num) \
836 	CHECK_ARG_SEND_TYPE(zf, arg_num, ZEND_SEND_PREFER_REF, ZEND_ACC_PASS_REST_PREFER_REF)
837 
838 #define ZEND_RETURN_VAL 0
839 #define ZEND_RETURN_REF 1
840 
841 
842 #define ZEND_RETURNS_FUNCTION 1<<0
843 #define ZEND_RETURNS_NEW      1<<1
844 
845 #define ZEND_FAST_RET_TO_CATCH		1
846 #define ZEND_FAST_RET_TO_FINALLY	2
847 
848 #define ZEND_FAST_CALL_FROM_CATCH	1
849 #define ZEND_FAST_CALL_FROM_FINALLY	2
850 
851 END_EXTERN_C()
852 
853 #define ZEND_CLONE_FUNC_NAME		"__clone"
854 #define ZEND_CONSTRUCTOR_FUNC_NAME	"__construct"
855 #define ZEND_DESTRUCTOR_FUNC_NAME	"__destruct"
856 #define ZEND_GET_FUNC_NAME          "__get"
857 #define ZEND_SET_FUNC_NAME          "__set"
858 #define ZEND_UNSET_FUNC_NAME        "__unset"
859 #define ZEND_ISSET_FUNC_NAME        "__isset"
860 #define ZEND_CALL_FUNC_NAME         "__call"
861 #define ZEND_CALLSTATIC_FUNC_NAME   "__callstatic"
862 #define ZEND_TOSTRING_FUNC_NAME     "__tostring"
863 #define ZEND_AUTOLOAD_FUNC_NAME     "__autoload"
864 #define ZEND_INVOKE_FUNC_NAME       "__invoke"
865 
866 /* The following constants may be combined in CG(compiler_options)
867  * to change the default compiler behavior */
868 
869 /* generate extended debug information */
870 #define ZEND_COMPILE_EXTENDED_INFO				(1<<0)
871 
872 /* call op_array handler of extendions */
873 #define ZEND_COMPILE_HANDLE_OP_ARRAY            (1<<1)
874 
875 /* generate ZEND_DO_FCALL_BY_NAME for internal functions instead of ZEND_DO_FCALL */
876 #define ZEND_COMPILE_IGNORE_INTERNAL_FUNCTIONS	(1<<2)
877 
878 /* don't perform early binding for classes inherited form internal ones;
879  * in namespaces assume that internal class that doesn't exist at compile-time
880  * may apper in run-time */
881 #define ZEND_COMPILE_IGNORE_INTERNAL_CLASSES	(1<<3)
882 
883 /* generate ZEND_DECLARE_INHERITED_CLASS_DELAYED opcode to delay early binding */
884 #define ZEND_COMPILE_DELAYED_BINDING			(1<<4)
885 
886 /* disable constant substitution at compile-time */
887 #define ZEND_COMPILE_NO_CONSTANT_SUBSTITUTION	(1<<5)
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