zend_compile.h 35 KB

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