123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903 |
- #include <stdio.h>
- #include "zend.h"
- #include "zend_alloc.h"
- #include "zend_compile.h"
- #include "zend_extensions.h"
- #include "zend_API.h"
- #include "zend_vm.h"
- static void zend_extension_op_array_ctor_handler(zend_extension *extension, zend_op_array *op_array TSRMLS_DC)
- {
- if (extension->op_array_ctor) {
- extension->op_array_ctor(op_array);
- }
- }
- static void zend_extension_op_array_dtor_handler(zend_extension *extension, zend_op_array *op_array TSRMLS_DC)
- {
- if (extension->op_array_dtor) {
- extension->op_array_dtor(op_array);
- }
- }
- static void op_array_alloc_ops(zend_op_array *op_array, zend_uint size)
- {
- op_array->opcodes = erealloc(op_array->opcodes, size * sizeof(zend_op));
- }
- void init_op_array(zend_op_array *op_array, zend_uchar type, int initial_ops_size TSRMLS_DC)
- {
- op_array->type = type;
- if (CG(interactive)) {
-
- initial_ops_size = INITIAL_INTERACTIVE_OP_ARRAY_SIZE;
- }
- op_array->refcount = (zend_uint *) emalloc(sizeof(zend_uint));
- *op_array->refcount = 1;
- op_array->last = 0;
- op_array->opcodes = NULL;
- op_array_alloc_ops(op_array, initial_ops_size);
- op_array->last_var = 0;
- op_array->vars = NULL;
- op_array->T = 0;
- op_array->nested_calls = 0;
- op_array->used_stack = 0;
- op_array->function_name = NULL;
- op_array->filename = zend_get_compiled_filename(TSRMLS_C);
- op_array->doc_comment = NULL;
- op_array->doc_comment_len = 0;
- op_array->arg_info = NULL;
- op_array->num_args = 0;
- op_array->required_num_args = 0;
- op_array->scope = NULL;
- op_array->brk_cont_array = NULL;
- op_array->try_catch_array = NULL;
- op_array->last_brk_cont = 0;
- op_array->static_variables = NULL;
- op_array->last_try_catch = 0;
- op_array->has_finally_block = 0;
- op_array->this_var = -1;
- op_array->fn_flags = CG(interactive)?ZEND_ACC_INTERACTIVE:0;
- op_array->early_binding = -1;
- op_array->last_literal = 0;
- op_array->literals = NULL;
- op_array->run_time_cache = NULL;
- op_array->last_cache_slot = 0;
- memset(op_array->reserved, 0, ZEND_MAX_RESERVED_RESOURCES * sizeof(void*));
- zend_llist_apply_with_argument(&zend_extensions, (llist_apply_with_arg_func_t) zend_extension_op_array_ctor_handler, op_array TSRMLS_CC);
- }
- ZEND_API void destroy_zend_function(zend_function *function TSRMLS_DC)
- {
- switch (function->type) {
- case ZEND_USER_FUNCTION:
- destroy_op_array((zend_op_array *) function TSRMLS_CC);
- break;
- case ZEND_INTERNAL_FUNCTION:
-
- break;
- }
- }
- ZEND_API void zend_function_dtor(zend_function *function)
- {
- TSRMLS_FETCH();
- destroy_zend_function(function TSRMLS_CC);
- }
- static void zend_cleanup_op_array_data(zend_op_array *op_array)
- {
- if (op_array->static_variables) {
- zend_hash_clean(op_array->static_variables);
- }
- }
- ZEND_API int zend_cleanup_function_data(zend_function *function TSRMLS_DC)
- {
- if (function->type == ZEND_USER_FUNCTION) {
- zend_cleanup_op_array_data((zend_op_array *) function);
- return ZEND_HASH_APPLY_KEEP;
- } else {
- return ZEND_HASH_APPLY_STOP;
- }
- }
- ZEND_API int zend_cleanup_function_data_full(zend_function *function TSRMLS_DC)
- {
- if (function->type == ZEND_USER_FUNCTION) {
- zend_cleanup_op_array_data((zend_op_array *) function);
- }
- return 0;
- }
- static inline void cleanup_user_class_data(zend_class_entry *ce TSRMLS_DC)
- {
-
-
- if (ce->ce_flags & ZEND_HAS_STATIC_IN_METHODS) {
- zend_hash_apply(&ce->function_table, (apply_func_t) zend_cleanup_function_data_full TSRMLS_CC);
- }
- if (ce->static_members_table) {
- zval **static_members = ce->static_members_table;
- int count = ce->default_static_members_count;
- int i;
- ce->default_static_members_count = 0;
- ce->default_static_members_table = ce->static_members_table = NULL;
- for (i = 0; i < count; i++) {
- zval_ptr_dtor(&static_members[i]);
- }
- efree(static_members);
- }
- }
- static inline void cleanup_internal_class_data(zend_class_entry *ce TSRMLS_DC)
- {
- if (CE_STATIC_MEMBERS(ce)) {
- int i;
-
- for (i = 0; i < ce->default_static_members_count; i++) {
- zval_ptr_dtor(&CE_STATIC_MEMBERS(ce)[i]);
- }
- efree(CE_STATIC_MEMBERS(ce));
- #ifdef ZTS
- CG(static_members_table)[(zend_intptr_t)(ce->static_members_table)] = NULL;
- #else
- ce->static_members_table = NULL;
- #endif
- }
- }
- ZEND_API void zend_cleanup_internal_class_data(zend_class_entry *ce TSRMLS_DC)
- {
- cleanup_internal_class_data(ce TSRMLS_CC);
- }
- ZEND_API int zend_cleanup_user_class_data(zend_class_entry **pce TSRMLS_DC)
- {
- if ((*pce)->type == ZEND_USER_CLASS) {
- cleanup_user_class_data(*pce TSRMLS_CC);
- return ZEND_HASH_APPLY_KEEP;
- } else {
- return ZEND_HASH_APPLY_STOP;
- }
- }
- ZEND_API int zend_cleanup_class_data(zend_class_entry **pce TSRMLS_DC)
- {
- if ((*pce)->type == ZEND_USER_CLASS) {
- cleanup_user_class_data(*pce TSRMLS_CC);
- } else {
- cleanup_internal_class_data(*pce TSRMLS_CC);
- }
- return 0;
- }
- void _destroy_zend_class_traits_info(zend_class_entry *ce)
- {
- if (ce->num_traits > 0 && ce->traits) {
- efree(ce->traits);
- }
-
- if (ce->trait_aliases) {
- size_t i = 0;
- while (ce->trait_aliases[i]) {
- if (ce->trait_aliases[i]->trait_method) {
- if (ce->trait_aliases[i]->trait_method->method_name) {
- efree((char*)ce->trait_aliases[i]->trait_method->method_name);
- }
- if (ce->trait_aliases[i]->trait_method->class_name) {
- efree((char*)ce->trait_aliases[i]->trait_method->class_name);
- }
- efree(ce->trait_aliases[i]->trait_method);
- }
-
- if (ce->trait_aliases[i]->alias) {
- efree((char*)ce->trait_aliases[i]->alias);
- }
-
- efree(ce->trait_aliases[i]);
- i++;
- }
-
- efree(ce->trait_aliases);
- }
- if (ce->trait_precedences) {
- size_t i = 0;
-
- while (ce->trait_precedences[i]) {
- efree((char*)ce->trait_precedences[i]->trait_method->method_name);
- efree((char*)ce->trait_precedences[i]->trait_method->class_name);
- efree(ce->trait_precedences[i]->trait_method);
- if (ce->trait_precedences[i]->exclude_from_classes) {
- zend_uint j = 0;
- zend_trait_precedence *cur_precedence = ce->trait_precedences[i];
- while (cur_precedence->exclude_from_classes[j]) {
- efree(cur_precedence->exclude_from_classes[j]);
- j++;
- }
- efree(ce->trait_precedences[i]->exclude_from_classes);
- }
- efree(ce->trait_precedences[i]);
- i++;
- }
- efree(ce->trait_precedences);
- }
- }
- ZEND_API void destroy_zend_class(zend_class_entry **pce)
- {
- zend_class_entry *ce = *pce;
-
- if (--ce->refcount > 0) {
- return;
- }
- switch (ce->type) {
- case ZEND_USER_CLASS:
- if (ce->default_properties_table) {
- int i;
- for (i = 0; i < ce->default_properties_count; i++) {
- if (ce->default_properties_table[i]) {
- zval_ptr_dtor(&ce->default_properties_table[i]);
- }
- }
- efree(ce->default_properties_table);
- }
- if (ce->default_static_members_table) {
- int i;
- for (i = 0; i < ce->default_static_members_count; i++) {
- if (ce->default_static_members_table[i]) {
- zval_ptr_dtor(&ce->default_static_members_table[i]);
- }
- }
- efree(ce->default_static_members_table);
- }
- zend_hash_destroy(&ce->properties_info);
- str_efree(ce->name);
- zend_hash_destroy(&ce->function_table);
- zend_hash_destroy(&ce->constants_table);
- if (ce->num_interfaces > 0 && ce->interfaces) {
- efree(ce->interfaces);
- }
- if (ce->info.user.doc_comment) {
- efree((char*)ce->info.user.doc_comment);
- }
-
- _destroy_zend_class_traits_info(ce);
-
- efree(ce);
- break;
- case ZEND_INTERNAL_CLASS:
- if (ce->default_properties_table) {
- int i;
- for (i = 0; i < ce->default_properties_count; i++) {
- if (ce->default_properties_table[i]) {
- zval_internal_ptr_dtor(&ce->default_properties_table[i]);
- }
- }
- free(ce->default_properties_table);
- }
- if (ce->default_static_members_table) {
- int i;
- for (i = 0; i < ce->default_static_members_count; i++) {
- zval_internal_ptr_dtor(&ce->default_static_members_table[i]);
- }
- free(ce->default_static_members_table);
- }
- zend_hash_destroy(&ce->properties_info);
- str_free(ce->name);
- zend_hash_destroy(&ce->function_table);
- zend_hash_destroy(&ce->constants_table);
- if (ce->num_interfaces > 0) {
- free(ce->interfaces);
- }
- free(ce);
- break;
- }
- }
- void zend_class_add_ref(zend_class_entry **ce)
- {
- (*ce)->refcount++;
- }
- ZEND_API void destroy_op_array(zend_op_array *op_array TSRMLS_DC)
- {
- zend_literal *literal = op_array->literals;
- zend_literal *end;
- zend_uint i;
- if (op_array->static_variables) {
- zend_hash_destroy(op_array->static_variables);
- FREE_HASHTABLE(op_array->static_variables);
- }
- if (op_array->run_time_cache) {
- efree(op_array->run_time_cache);
- }
- if (--(*op_array->refcount)>0) {
- return;
- }
- efree(op_array->refcount);
- if (op_array->vars) {
- i = op_array->last_var;
- while (i > 0) {
- i--;
- str_efree(op_array->vars[i].name);
- }
- efree(op_array->vars);
- }
- if (literal) {
- end = literal + op_array->last_literal;
- while (literal < end) {
- zval_dtor(&literal->constant);
- literal++;
- }
- efree(op_array->literals);
- }
- efree(op_array->opcodes);
- if (op_array->function_name) {
- efree((char*)op_array->function_name);
- }
- if (op_array->doc_comment) {
- efree((char*)op_array->doc_comment);
- }
- if (op_array->brk_cont_array) {
- efree(op_array->brk_cont_array);
- }
- if (op_array->try_catch_array) {
- efree(op_array->try_catch_array);
- }
- if (op_array->fn_flags & ZEND_ACC_DONE_PASS_TWO) {
- zend_llist_apply_with_argument(&zend_extensions, (llist_apply_with_arg_func_t) zend_extension_op_array_dtor_handler, op_array TSRMLS_CC);
- }
- if (op_array->arg_info) {
- for (i=0; i<op_array->num_args; i++) {
- str_efree(op_array->arg_info[i].name);
- if (op_array->arg_info[i].class_name) {
- str_efree(op_array->arg_info[i].class_name);
- }
- }
- efree(op_array->arg_info);
- }
- }
- void init_op(zend_op *op TSRMLS_DC)
- {
- memset(op, 0, sizeof(zend_op));
- op->lineno = CG(zend_lineno);
- SET_UNUSED(op->result);
- }
- zend_op *get_next_op(zend_op_array *op_array TSRMLS_DC)
- {
- zend_uint next_op_num = op_array->last++;
- zend_op *next_op;
- if (next_op_num >= CG(context).opcodes_size) {
- if (op_array->fn_flags & ZEND_ACC_INTERACTIVE) {
-
- zend_printf("Ran out of opcode space!\n"
- "You should probably consider writing this huge script into a file!\n");
- zend_bailout();
- }
- CG(context).opcodes_size *= 4;
- op_array_alloc_ops(op_array, CG(context).opcodes_size);
- }
-
- next_op = &(op_array->opcodes[next_op_num]);
-
- init_op(next_op TSRMLS_CC);
- return next_op;
- }
- int get_next_op_number(zend_op_array *op_array)
- {
- return op_array->last;
- }
- zend_brk_cont_element *get_next_brk_cont_element(zend_op_array *op_array)
- {
- op_array->last_brk_cont++;
- op_array->brk_cont_array = erealloc(op_array->brk_cont_array, sizeof(zend_brk_cont_element)*op_array->last_brk_cont);
- return &op_array->brk_cont_array[op_array->last_brk_cont-1];
- }
- static void zend_update_extended_info(zend_op_array *op_array TSRMLS_DC)
- {
- zend_op *opline = op_array->opcodes, *end=opline+op_array->last;
- while (opline<end) {
- if (opline->opcode == ZEND_EXT_STMT) {
- if (opline+1<end) {
- if ((opline+1)->opcode == ZEND_EXT_STMT) {
- opline->opcode = ZEND_NOP;
- opline++;
- continue;
- }
- if (opline+1<end) {
- opline->lineno = (opline+1)->lineno;
- }
- } else {
- opline->opcode = ZEND_NOP;
- }
- }
- opline++;
- }
- }
- static void zend_extension_op_array_handler(zend_extension *extension, zend_op_array *op_array TSRMLS_DC)
- {
- if (extension->op_array_handler) {
- extension->op_array_handler(op_array);
- }
- }
- static void zend_check_finally_breakout(zend_op_array *op_array, zend_uint op_num, zend_uint dst_num TSRMLS_DC)
- {
- zend_uint i;
- for (i = 0; i < op_array->last_try_catch; i++) {
- if ((op_num < op_array->try_catch_array[i].finally_op ||
- op_num >= op_array->try_catch_array[i].finally_end)
- && (dst_num >= op_array->try_catch_array[i].finally_op &&
- dst_num <= op_array->try_catch_array[i].finally_end)) {
- CG(in_compilation) = 1;
- CG(active_op_array) = op_array;
- CG(zend_lineno) = op_array->opcodes[op_num].lineno;
- zend_error_noreturn(E_COMPILE_ERROR, "jump into a finally block is disallowed");
- } else if ((op_num >= op_array->try_catch_array[i].finally_op
- && op_num <= op_array->try_catch_array[i].finally_end)
- && (dst_num > op_array->try_catch_array[i].finally_end
- || dst_num < op_array->try_catch_array[i].finally_op)) {
- CG(in_compilation) = 1;
- CG(active_op_array) = op_array;
- CG(zend_lineno) = op_array->opcodes[op_num].lineno;
- zend_error_noreturn(E_COMPILE_ERROR, "jump out of a finally block is disallowed");
- }
- }
- }
- static void zend_adjust_fast_call(zend_op_array *op_array, zend_uint fast_call, zend_uint start, zend_uint end TSRMLS_DC)
- {
- int i;
- zend_uint op_num = 0;
- for (i = 0; i < op_array->last_try_catch; i++) {
- if (op_array->try_catch_array[i].finally_op > start
- && op_array->try_catch_array[i].finally_end < end) {
- op_num = op_array->try_catch_array[i].finally_op;
- start = op_array->try_catch_array[i].finally_end;
- }
- }
- if (op_num) {
-
- ZEND_ASSERT(op_array->opcodes[op_num - 2].opcode == ZEND_FAST_CALL);
- op_array->opcodes[op_num - 2].extended_value = ZEND_FAST_CALL_FROM_FINALLY;
- op_array->opcodes[op_num - 2].op2.opline_num = fast_call;
- }
- }
- static void zend_resolve_fast_call(zend_op_array *op_array, zend_uint fast_call, zend_uint op_num TSRMLS_DC)
- {
- int i;
- zend_uint finally_op_num = 0;
- for (i = 0; i < op_array->last_try_catch; i++) {
- if (op_num >= op_array->try_catch_array[i].finally_op
- && op_num < op_array->try_catch_array[i].finally_end) {
- finally_op_num = op_array->try_catch_array[i].finally_op;
- }
- }
- if (finally_op_num) {
-
- ZEND_ASSERT(op_array->opcodes[finally_op_num - 2].opcode == ZEND_FAST_CALL);
- if (op_array->opcodes[fast_call].extended_value == 0) {
- op_array->opcodes[fast_call].extended_value = ZEND_FAST_CALL_FROM_FINALLY;
- op_array->opcodes[fast_call].op2.opline_num = finally_op_num - 2;
- }
- }
- }
- static void zend_resolve_finally_call(zend_op_array *op_array, zend_uint op_num, zend_uint dst_num TSRMLS_DC)
- {
- zend_uint start_op;
- zend_op *opline;
- zend_uint i = op_array->last_try_catch;
- if (dst_num != (zend_uint)-1) {
- zend_check_finally_breakout(op_array, op_num, dst_num TSRMLS_CC);
- }
-
- while (i > 0) {
- i--;
- if (op_array->try_catch_array[i].finally_op &&
- op_num >= op_array->try_catch_array[i].try_op &&
- op_num < op_array->try_catch_array[i].finally_op - 1 &&
- (dst_num < op_array->try_catch_array[i].try_op ||
- dst_num > op_array->try_catch_array[i].finally_end)) {
-
-
- start_op = get_next_op_number(op_array);
- opline = get_next_op(op_array TSRMLS_CC);
- opline->opcode = ZEND_FAST_CALL;
- SET_UNUSED(opline->op1);
- SET_UNUSED(opline->op2);
- zend_adjust_fast_call(op_array, start_op,
- op_array->try_catch_array[i].finally_op,
- op_array->try_catch_array[i].finally_end TSRMLS_CC);
- if (op_array->try_catch_array[i].catch_op) {
- opline->extended_value = ZEND_FAST_CALL_FROM_CATCH;
- opline->op2.opline_num = op_array->try_catch_array[i].catch_op;
- opline->op1.opline_num = get_next_op_number(op_array);
-
- opline = get_next_op(op_array TSRMLS_CC);
- opline->opcode = ZEND_FAST_CALL;
- SET_UNUSED(opline->op1);
- SET_UNUSED(opline->op2);
- zend_resolve_fast_call(op_array, start_op + 1, op_array->try_catch_array[i].finally_op - 2 TSRMLS_CC);
- } else {
- zend_resolve_fast_call(op_array, start_op, op_array->try_catch_array[i].finally_op - 2 TSRMLS_CC);
- }
- opline->op1.opline_num = op_array->try_catch_array[i].finally_op;
-
- while (i > 0) {
- i--;
- if (op_array->try_catch_array[i].finally_op &&
- op_num >= op_array->try_catch_array[i].try_op &&
- op_num < op_array->try_catch_array[i].finally_op - 1 &&
- (dst_num < op_array->try_catch_array[i].try_op ||
- dst_num > op_array->try_catch_array[i].finally_end)) {
- opline = get_next_op(op_array TSRMLS_CC);
- opline->opcode = ZEND_FAST_CALL;
- SET_UNUSED(opline->op1);
- SET_UNUSED(opline->op2);
- opline->op1.opline_num = op_array->try_catch_array[i].finally_op;
- }
- }
-
- opline = get_next_op(op_array TSRMLS_CC);
- *opline = op_array->opcodes[op_num];
-
- opline = op_array->opcodes + op_num;
- opline->opcode = ZEND_JMP;
- SET_UNUSED(opline->op1);
- SET_UNUSED(opline->op2);
- opline->op1.opline_num = start_op;
- break;
- }
- }
- }
- static void zend_resolve_finally_ret(zend_op_array *op_array, zend_uint op_num TSRMLS_DC)
- {
- int i;
- zend_uint catch_op_num = 0, finally_op_num = 0;
- for (i = 0; i < op_array->last_try_catch; i++) {
- if (op_array->try_catch_array[i].try_op > op_num) {
- break;
- }
- if (op_num < op_array->try_catch_array[i].finally_op) {
- finally_op_num = op_array->try_catch_array[i].finally_op;
- }
- if (op_num < op_array->try_catch_array[i].catch_op) {
- catch_op_num = op_array->try_catch_array[i].catch_op;
- }
- }
- if (finally_op_num && (!catch_op_num || catch_op_num >= finally_op_num)) {
-
- op_array->opcodes[op_num].extended_value = ZEND_FAST_RET_TO_FINALLY;
- op_array->opcodes[op_num].op2.opline_num = finally_op_num;
- } else if (catch_op_num) {
-
- op_array->opcodes[op_num].extended_value = ZEND_FAST_RET_TO_CATCH;
- op_array->opcodes[op_num].op2.opline_num = catch_op_num;
- }
- }
- static void zend_resolve_finally_calls(zend_op_array *op_array TSRMLS_DC)
- {
- zend_uint i, j;
- zend_op *opline;
- for (i = 0, j = op_array->last; i < j; i++) {
- opline = op_array->opcodes + i;
- switch (opline->opcode) {
- case ZEND_RETURN:
- case ZEND_RETURN_BY_REF:
- case ZEND_GENERATOR_RETURN:
- zend_resolve_finally_call(op_array, i, (zend_uint)-1 TSRMLS_CC);
- break;
- case ZEND_BRK:
- case ZEND_CONT:
- {
- int nest_levels, array_offset;
- zend_brk_cont_element *jmp_to;
- nest_levels = Z_LVAL(op_array->literals[opline->op2.constant].constant);
- if ((array_offset = opline->op1.opline_num) != -1) {
- do {
- jmp_to = &op_array->brk_cont_array[array_offset];
- if (nest_levels > 1) {
- array_offset = jmp_to->parent;
- }
- } while (--nest_levels > 0);
- zend_resolve_finally_call(op_array, i, opline->opcode == ZEND_BRK ? jmp_to->brk : jmp_to->cont TSRMLS_CC);
- break;
- }
- }
- case ZEND_GOTO:
- if (Z_TYPE(op_array->literals[opline->op2.constant].constant) != IS_LONG) {
- zend_uint num = opline->op2.constant;
- opline->op2.zv = &op_array->literals[opline->op2.constant].constant;
- zend_resolve_goto_label(op_array, opline, 1 TSRMLS_CC);
- opline->op2.constant = num;
- }
-
- case ZEND_JMP:
- zend_resolve_finally_call(op_array, i, opline->op1.opline_num TSRMLS_CC);
- break;
- case ZEND_FAST_CALL:
- zend_resolve_fast_call(op_array, i, i TSRMLS_CC);
- break;
- case ZEND_FAST_RET:
- zend_resolve_finally_ret(op_array, i TSRMLS_CC);
- break;
- default:
- break;
- }
- }
- }
- ZEND_API int pass_two(zend_op_array *op_array TSRMLS_DC)
- {
- zend_op *opline, *end;
- if (op_array->type!=ZEND_USER_FUNCTION && op_array->type!=ZEND_EVAL_CODE) {
- return 0;
- }
- if (op_array->has_finally_block) {
- zend_resolve_finally_calls(op_array TSRMLS_CC);
- }
- if (CG(compiler_options) & ZEND_COMPILE_EXTENDED_INFO) {
- zend_update_extended_info(op_array TSRMLS_CC);
- }
- if (CG(compiler_options) & ZEND_COMPILE_HANDLE_OP_ARRAY) {
- zend_llist_apply_with_argument(&zend_extensions, (llist_apply_with_arg_func_t) zend_extension_op_array_handler, op_array TSRMLS_CC);
- }
- if (!(op_array->fn_flags & ZEND_ACC_INTERACTIVE) && CG(context).vars_size != op_array->last_var) {
- op_array->vars = (zend_compiled_variable *) erealloc(op_array->vars, sizeof(zend_compiled_variable)*op_array->last_var);
- CG(context).vars_size = op_array->last_var;
- }
- if (!(op_array->fn_flags & ZEND_ACC_INTERACTIVE) && CG(context).opcodes_size != op_array->last) {
- op_array->opcodes = (zend_op *) erealloc(op_array->opcodes, sizeof(zend_op)*op_array->last);
- CG(context).opcodes_size = op_array->last;
- }
- if (!(op_array->fn_flags & ZEND_ACC_INTERACTIVE) && CG(context).literals_size != op_array->last_literal) {
- op_array->literals = (zend_literal*)erealloc(op_array->literals, sizeof(zend_literal) * op_array->last_literal);
- CG(context).literals_size = op_array->last_literal;
- }
- opline = op_array->opcodes;
- end = opline + op_array->last;
- while (opline < end) {
- if (opline->op1_type == IS_CONST) {
- opline->op1.zv = &op_array->literals[opline->op1.constant].constant;
- }
- if (opline->op2_type == IS_CONST) {
- opline->op2.zv = &op_array->literals[opline->op2.constant].constant;
- }
- switch (opline->opcode) {
- case ZEND_GOTO:
- if (Z_TYPE_P(opline->op2.zv) != IS_LONG) {
- zend_resolve_goto_label(op_array, opline, 1 TSRMLS_CC);
- }
-
- case ZEND_JMP:
- case ZEND_FAST_CALL:
- opline->op1.jmp_addr = &op_array->opcodes[opline->op1.opline_num];
- break;
- case ZEND_JMPZ:
- case ZEND_JMPNZ:
- case ZEND_JMPZ_EX:
- case ZEND_JMPNZ_EX:
- case ZEND_JMP_SET:
- case ZEND_JMP_SET_VAR:
- opline->op2.jmp_addr = &op_array->opcodes[opline->op2.opline_num];
- break;
- case ZEND_RETURN:
- case ZEND_RETURN_BY_REF:
- if (op_array->fn_flags & ZEND_ACC_GENERATOR) {
- if (opline->op1_type != IS_CONST || Z_TYPE_P(opline->op1.zv) != IS_NULL) {
- CG(zend_lineno) = opline->lineno;
- zend_error_noreturn(E_COMPILE_ERROR, "Generators cannot return values using \"return\"");
- }
- opline->opcode = ZEND_GENERATOR_RETURN;
- }
- break;
- }
- ZEND_VM_SET_OPCODE_HANDLER(opline);
- opline++;
- }
- op_array->fn_flags |= ZEND_ACC_DONE_PASS_TWO;
- return 0;
- }
- int print_class(zend_class_entry *class_entry TSRMLS_DC)
- {
- printf("Class %s:\n", class_entry->name);
- zend_hash_apply(&class_entry->function_table, (apply_func_t) pass_two TSRMLS_CC);
- printf("End of class %s.\n\n", class_entry->name);
- return 0;
- }
- ZEND_API unary_op_type get_unary_op(int opcode)
- {
- switch (opcode) {
- case ZEND_BW_NOT:
- return (unary_op_type) bitwise_not_function;
- break;
- case ZEND_BOOL_NOT:
- return (unary_op_type) boolean_not_function;
- break;
- default:
- return (unary_op_type) NULL;
- break;
- }
- }
- ZEND_API binary_op_type get_binary_op(int opcode)
- {
- switch (opcode) {
- case ZEND_ADD:
- case ZEND_ASSIGN_ADD:
- return (binary_op_type) add_function;
- break;
- case ZEND_SUB:
- case ZEND_ASSIGN_SUB:
- return (binary_op_type) sub_function;
- break;
- case ZEND_MUL:
- case ZEND_ASSIGN_MUL:
- return (binary_op_type) mul_function;
- break;
- case ZEND_POW:
- return (binary_op_type) pow_function;
- break;
- case ZEND_DIV:
- case ZEND_ASSIGN_DIV:
- return (binary_op_type) div_function;
- break;
- case ZEND_MOD:
- case ZEND_ASSIGN_MOD:
- return (binary_op_type) mod_function;
- break;
- case ZEND_SL:
- case ZEND_ASSIGN_SL:
- return (binary_op_type) shift_left_function;
- break;
- case ZEND_SR:
- case ZEND_ASSIGN_SR:
- return (binary_op_type) shift_right_function;
- break;
- case ZEND_CONCAT:
- case ZEND_ASSIGN_CONCAT:
- return (binary_op_type) concat_function;
- break;
- case ZEND_IS_IDENTICAL:
- return (binary_op_type) is_identical_function;
- break;
- case ZEND_IS_NOT_IDENTICAL:
- return (binary_op_type) is_not_identical_function;
- break;
- case ZEND_IS_EQUAL:
- return (binary_op_type) is_equal_function;
- break;
- case ZEND_IS_NOT_EQUAL:
- return (binary_op_type) is_not_equal_function;
- break;
- case ZEND_IS_SMALLER:
- return (binary_op_type) is_smaller_function;
- break;
- case ZEND_IS_SMALLER_OR_EQUAL:
- return (binary_op_type) is_smaller_or_equal_function;
- break;
- case ZEND_BW_OR:
- case ZEND_ASSIGN_BW_OR:
- return (binary_op_type) bitwise_or_function;
- break;
- case ZEND_BW_AND:
- case ZEND_ASSIGN_BW_AND:
- return (binary_op_type) bitwise_and_function;
- break;
- case ZEND_BW_XOR:
- case ZEND_ASSIGN_BW_XOR:
- return (binary_op_type) bitwise_xor_function;
- break;
- case ZEND_BOOL_XOR:
- return (binary_op_type) boolean_xor_function;
- break;
- default:
- return (binary_op_type) NULL;
- break;
- }
- }
|