PHP  
 PHP: Test and Code Coverage Analysis
downloads | QA | documentation | faq | getting help | mailing lists | reporting bugs | php.net sites | links | my php.net 
 

LCOV - code coverage report
Current view: top level - Zend - zend_compile.c (source / functions) Hit Total Coverage
Test: PHP Code Coverage Lines: 4088 4288 95.3 %
Date: 2016-08-28 Functions: 260 263 98.9 %
Legend: Lines: hit not hit

          Line data    Source code
       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             :    |          Nikita Popov <nikic@php.net>                                |
      18             :    +----------------------------------------------------------------------+
      19             : */
      20             : 
      21             : /* $Id$ */
      22             : 
      23             : #include <zend_language_parser.h>
      24             : #include "zend.h"
      25             : #include "zend_compile.h"
      26             : #include "zend_constants.h"
      27             : #include "zend_llist.h"
      28             : #include "zend_API.h"
      29             : #include "zend_exceptions.h"
      30             : #include "zend_interfaces.h"
      31             : #include "zend_virtual_cwd.h"
      32             : #include "zend_multibyte.h"
      33             : #include "zend_language_scanner.h"
      34             : #include "zend_inheritance.h"
      35             : #include "zend_vm.h"
      36             : 
      37             : #define SET_NODE(target, src) do { \
      38             :                 target ## _type = (src)->op_type; \
      39             :                 if ((src)->op_type == IS_CONST) { \
      40             :                         target.constant = zend_add_literal(CG(active_op_array), &(src)->u.constant); \
      41             :                 } else { \
      42             :                         target = (src)->u.op; \
      43             :                 } \
      44             :         } while (0)
      45             : 
      46             : #define GET_NODE(target, src) do { \
      47             :                 (target)->op_type = src ## _type; \
      48             :                 if ((target)->op_type == IS_CONST) { \
      49             :                         ZVAL_COPY_VALUE(&(target)->u.constant, CT_CONSTANT(src)); \
      50             :                 } else { \
      51             :                         (target)->u.op = src; \
      52             :                 } \
      53             :         } while (0)
      54             : 
      55             : #define FC(member) (CG(file_context).member)
      56             : 
      57             : typedef struct _zend_loop_var {
      58             :         zend_uchar opcode;
      59             :         zend_uchar var_type;
      60             :         uint32_t   var_num;
      61             :         union {
      62             :                 uint32_t try_catch_offset;
      63             :                 uint32_t live_range_offset;
      64             :         } u;
      65             : } zend_loop_var;
      66             : 
      67      322111 : static inline void zend_alloc_cache_slot(uint32_t literal) {
      68      322111 :         zend_op_array *op_array = CG(active_op_array);
      69      322111 :         Z_CACHE_SLOT(op_array->literals[literal]) = op_array->cache_size;
      70      322111 :         op_array->cache_size += sizeof(void*);
      71      322111 : }
      72             : 
      73             : #define POLYMORPHIC_CACHE_SLOT_SIZE 2
      74             : 
      75       54961 : static inline void zend_alloc_polymorphic_cache_slot(uint32_t literal) {
      76       54961 :         zend_op_array *op_array = CG(active_op_array);
      77       54961 :         Z_CACHE_SLOT(op_array->literals[literal]) = op_array->cache_size;
      78       54961 :         op_array->cache_size += POLYMORPHIC_CACHE_SLOT_SIZE * sizeof(void*);
      79       54961 : }
      80             : 
      81             : ZEND_API zend_op_array *(*zend_compile_file)(zend_file_handle *file_handle, int type);
      82             : ZEND_API zend_op_array *(*zend_compile_string)(zval *source_string, char *filename);
      83             : 
      84             : #ifndef ZTS
      85             : ZEND_API zend_compiler_globals compiler_globals;
      86             : ZEND_API zend_executor_globals executor_globals;
      87             : #endif
      88             : 
      89             : static zend_op *zend_emit_op(znode *result, zend_uchar opcode, znode *op1, znode *op2);
      90             : 
      91     6639248 : static void zend_destroy_property_info_internal(zval *zv) /* {{{ */
      92             : {
      93     6639248 :         zend_property_info *property_info = Z_PTR_P(zv);
      94             : 
      95     6639248 :         zend_string_release(property_info->name);
      96     6639248 :         free(property_info);
      97     6639248 : }
      98             : /* }}} */
      99             : 
     100    27946728 : static void zend_destroy_class_constant_internal(zval *zv) /* {{{ */
     101             : {
     102    27946728 :         free(Z_PTR_P(zv));
     103    27946728 : }
     104             : /* }}} */
     105             : 
     106        3083 : static zend_string *zend_new_interned_string_safe(zend_string *str) /* {{{ */ {
     107             :         zend_string *interned_str;
     108             : 
     109             :         zend_string_addref(str);
     110        3083 :         interned_str = zend_new_interned_string(str);
     111        3083 :         if (str != interned_str) {
     112         761 :                 return interned_str;
     113             :         } else {
     114             :                 zend_string_release(str);
     115        2322 :                 return str;
     116             :         }
     117             : }
     118             : /* }}} */
     119             : 
     120       28934 : static zend_string *zend_build_runtime_definition_key(zend_string *name, unsigned char *lex_pos) /* {{{ */
     121             : {
     122             :         zend_string *result;
     123             :         char char_pos_buf[32];
     124       28934 :         size_t char_pos_len = zend_sprintf(char_pos_buf, "%p", lex_pos);
     125       28934 :         zend_string *filename = CG(active_op_array)->filename;
     126             : 
     127             :         /* NULL, name length, filename length, last accepting char position length */
     128       57868 :         result = zend_string_alloc(1 + ZSTR_LEN(name) + ZSTR_LEN(filename) + char_pos_len, 0);
     129       28934 :         sprintf(ZSTR_VAL(result), "%c%s%s%s", '\0', ZSTR_VAL(name), ZSTR_VAL(filename), char_pos_buf);
     130       28934 :         return zend_new_interned_string(result);
     131             : }
     132             : /* }}} */
     133             : 
     134       39522 : static zend_bool zend_get_unqualified_name(const zend_string *name, const char **result, size_t *result_len) /* {{{ */
     135             : {
     136       79044 :         const char *ns_separator = zend_memrchr(ZSTR_VAL(name), '\\', ZSTR_LEN(name));
     137       39522 :         if (ns_separator != NULL) {
     138         596 :                 *result = ns_separator + 1;
     139         596 :                 *result_len = ZSTR_VAL(name) + ZSTR_LEN(name) - *result;
     140         596 :                 return 1;
     141             :         }
     142             : 
     143       38926 :         return 0;
     144             : }
     145             : /* }}} */
     146             : 
     147             : struct reserved_class_name {
     148             :         const char *name;
     149             :         size_t len;
     150             : };
     151             : static const struct reserved_class_name reserved_class_names[] = {
     152             :         {ZEND_STRL("bool")},
     153             :         {ZEND_STRL("false")},
     154             :         {ZEND_STRL("float")},
     155             :         {ZEND_STRL("int")},
     156             :         {ZEND_STRL("null")},
     157             :         {ZEND_STRL("parent")},
     158             :         {ZEND_STRL("self")},
     159             :         {ZEND_STRL("static")},
     160             :         {ZEND_STRL("string")},
     161             :         {ZEND_STRL("true")},
     162             :         {ZEND_STRL("void")},
     163             :         {ZEND_STRL("iterable")},
     164             :         {NULL, 0}
     165             : };
     166             : 
     167        8442 : static zend_bool zend_is_reserved_class_name(const zend_string *name) /* {{{ */
     168             : {
     169        8442 :         const struct reserved_class_name *reserved = reserved_class_names;
     170             : 
     171        8442 :         const char *uqname = ZSTR_VAL(name);
     172        8442 :         size_t uqname_len = ZSTR_LEN(name);
     173        8442 :         zend_get_unqualified_name(name, &uqname, &uqname_len);
     174             : 
     175      109598 :         for (; reserved->name; ++reserved) {
     176      107212 :                 if (uqname_len == reserved->len
     177      107212 :                         && zend_binary_strcasecmp(uqname, uqname_len, reserved->name, reserved->len) == 0
     178             :                 ) {
     179          18 :                         return 1;
     180             :                 }
     181             :         }
     182             : 
     183        8424 :         return 0;
     184             : }
     185             : /* }}} */
     186             : 
     187        8360 : ZEND_API void zend_assert_valid_class_name(const zend_string *name) /* {{{ */
     188             : {
     189        8360 :         if (zend_is_reserved_class_name(name)) {
     190          13 :                 zend_error_noreturn(E_COMPILE_ERROR,
     191             :                         "Cannot use '%s' as class name as it is reserved", ZSTR_VAL(name));
     192             :         }
     193        8347 : }
     194             : /* }}} */
     195             : 
     196             : typedef struct _builtin_type_info {
     197             :         const char* name;
     198             :         const size_t name_len;
     199             :         const zend_uchar type;
     200             : } builtin_type_info;
     201             : 
     202             : static const builtin_type_info builtin_types[] = {
     203             :         {ZEND_STRL("int"), IS_LONG},
     204             :         {ZEND_STRL("float"), IS_DOUBLE},
     205             :         {ZEND_STRL("string"), IS_STRING},
     206             :         {ZEND_STRL("bool"), _IS_BOOL},
     207             :         {ZEND_STRL("void"), IS_VOID},
     208             :         {ZEND_STRL("iterable"), IS_ITERABLE},
     209             :         {NULL, 0, IS_UNDEF}
     210             : };
     211             : 
     212             : 
     213             : static zend_always_inline zend_uchar zend_lookup_builtin_type_by_name(const zend_string *name) /* {{{ */
     214             : {
     215         465 :         const builtin_type_info *info = &builtin_types[0];
     216             : 
     217        1843 :         for (; info->name; ++info) {
     218        2453 :                 if (ZSTR_LEN(name) == info->name_len
     219        2453 :                         && zend_binary_strcasecmp(ZSTR_VAL(name), ZSTR_LEN(name), info->name, info->name_len) == 0
     220             :                 ) {
     221         207 :                         return info->type;
     222             :                 }
     223             :         }
     224             : 
     225         258 :         return 0;
     226             : }
     227             : /* }}} */
     228             : 
     229             : 
     230       74391 : void zend_oparray_context_begin(zend_oparray_context *prev_context) /* {{{ */
     231             : {
     232       74391 :         *prev_context = CG(context);
     233       74391 :         CG(context).opcodes_size = INITIAL_OP_ARRAY_SIZE;
     234       74391 :         CG(context).vars_size = 0;
     235       74391 :         CG(context).literals_size = 0;
     236       74391 :         CG(context).backpatch_count = 0;
     237       74391 :         CG(context).in_finally = 0;
     238       74391 :         CG(context).fast_call_var = -1;
     239       74391 :         CG(context).try_catch_offset = -1;
     240       74391 :         CG(context).current_brk_cont = -1;
     241       74391 :         CG(context).last_brk_cont = 0;
     242       74391 :         CG(context).brk_cont_array = NULL;
     243       74391 :         CG(context).labels = NULL;
     244       74391 : }
     245             : /* }}} */
     246             : 
     247       74038 : void zend_oparray_context_end(zend_oparray_context *prev_context) /* {{{ */
     248             : {
     249       74038 :         if (CG(context).brk_cont_array) {
     250       12501 :                 efree(CG(context).brk_cont_array);
     251       12501 :                 CG(context).brk_cont_array = NULL;
     252             :         }
     253       74038 :         if (CG(context).labels) {
     254          22 :                 zend_hash_destroy(CG(context).labels);
     255          22 :                 FREE_HASHTABLE(CG(context).labels);
     256          22 :                 CG(context).labels = NULL;
     257             :         }
     258       74038 :         CG(context) = *prev_context;
     259       74038 : }
     260             : /* }}} */
     261             : 
     262       34517 : static void zend_reset_import_tables(void) /* {{{ */
     263             : {
     264       34517 :         if (FC(imports)) {
     265          44 :                 zend_hash_destroy(FC(imports));
     266          44 :                 efree(FC(imports));
     267          44 :                 FC(imports) = NULL;
     268             :         }
     269             : 
     270       34517 :         if (FC(imports_function)) {
     271          15 :                 zend_hash_destroy(FC(imports_function));
     272          15 :                 efree(FC(imports_function));
     273          15 :                 FC(imports_function) = NULL;
     274             :         }
     275             : 
     276       34517 :         if (FC(imports_const)) {
     277          13 :                 zend_hash_destroy(FC(imports_const));
     278          13 :                 efree(FC(imports_const));
     279          13 :                 FC(imports_const) = NULL;
     280             :         }
     281       34517 : }
     282             : /* }}} */
     283             : 
     284       34260 : static void zend_end_namespace(void) /* {{{ */ {
     285       34260 :         FC(in_namespace) = 0;
     286       34260 :         zend_reset_import_tables();
     287       34260 :         if (FC(current_namespace)) {
     288         193 :                 zend_string_release(FC(current_namespace));
     289         193 :                 FC(current_namespace) = NULL;
     290             :         }
     291       34260 : }
     292             : /* }}} */
     293             : 
     294       34440 : void zend_file_context_begin(zend_file_context *prev_context) /* {{{ */
     295             : {
     296       34440 :         *prev_context = CG(file_context);
     297       34440 :         FC(imports) = NULL;
     298       34440 :         FC(imports_function) = NULL;
     299       34440 :         FC(imports_const) = NULL;
     300       34440 :         FC(current_namespace) = NULL;
     301       34440 :         FC(in_namespace) = 0;
     302       34440 :         FC(has_bracketed_namespaces) = 0;
     303       34440 :         FC(declarables).ticks = 0;
     304       34440 : }
     305             : /* }}} */
     306             : 
     307       34164 : void zend_file_context_end(zend_file_context *prev_context) /* {{{ */
     308             : {
     309       34164 :         zend_end_namespace();
     310       34164 :         CG(file_context) = *prev_context;
     311       34164 : }
     312             : /* }}} */
     313             : 
     314       23458 : void zend_init_compiler_data_structures(void) /* {{{ */
     315             : {
     316       23458 :         zend_stack_init(&CG(loop_var_stack), sizeof(zend_loop_var));
     317       23458 :         zend_stack_init(&CG(delayed_oplines_stack), sizeof(zend_op));
     318       23458 :         CG(active_class_entry) = NULL;
     319       23458 :         CG(in_compilation) = 0;
     320       23458 :         CG(start_lineno) = 0;
     321       23458 :         zend_hash_init(&CG(const_filenames), 8, NULL, NULL, 0);
     322             : 
     323       23458 :         CG(encoding_declared) = 0;
     324       23458 : }
     325             : /* }}} */
     326             : 
     327       33339 : ZEND_API void file_handle_dtor(zend_file_handle *fh) /* {{{ */
     328             : {
     329             : 
     330       33339 :         zend_file_handle_dtor(fh);
     331       33339 : }
     332             : /* }}} */
     333             : 
     334       23458 : void init_compiler(void) /* {{{ */
     335             : {
     336       23458 :         CG(arena) = zend_arena_create(64 * 1024);
     337       23458 :         CG(active_op_array) = NULL;
     338       23458 :         memset(&CG(context), 0, sizeof(CG(context)));
     339       23458 :         zend_init_compiler_data_structures();
     340       23458 :         zend_init_rsrc_list();
     341       23458 :         zend_hash_init(&CG(filenames_table), 8, NULL, ZVAL_PTR_DTOR, 0);
     342       23458 :         zend_llist_init(&CG(open_files), sizeof(zend_file_handle), (void (*)(void *)) file_handle_dtor, 0);
     343       23458 :         CG(unclean_shutdown) = 0;
     344       23458 : }
     345             : /* }}} */
     346             : 
     347       23500 : void shutdown_compiler(void) /* {{{ */
     348             : {
     349       23500 :         zend_stack_destroy(&CG(loop_var_stack));
     350       23500 :         zend_stack_destroy(&CG(delayed_oplines_stack));
     351       23500 :         zend_hash_destroy(&CG(filenames_table));
     352       23500 :         zend_hash_destroy(&CG(const_filenames));
     353       23500 :         zend_arena_destroy(CG(arena));
     354       23500 : }
     355             : /* }}} */
     356             : 
     357       34651 : ZEND_API zend_string *zend_set_compiled_filename(zend_string *new_compiled_filename) /* {{{ */
     358             : {
     359             :         zval *p, rv;
     360             : 
     361       34651 :         if ((p = zend_hash_find(&CG(filenames_table), new_compiled_filename))) {
     362             :                 ZEND_ASSERT(Z_TYPE_P(p) == IS_STRING);
     363         880 :                 CG(compiled_filename) = Z_STR_P(p);
     364         880 :                 return Z_STR_P(p);
     365             :         }
     366             : 
     367       33771 :         ZVAL_STR_COPY(&rv, new_compiled_filename);
     368       33771 :         zend_hash_update(&CG(filenames_table), new_compiled_filename, &rv);
     369             : 
     370       33771 :         CG(compiled_filename) = new_compiled_filename;
     371       33771 :         return new_compiled_filename;
     372             : }
     373             : /* }}} */
     374             : 
     375       34381 : ZEND_API void zend_restore_compiled_filename(zend_string *original_compiled_filename) /* {{{ */
     376             : {
     377       34381 :         CG(compiled_filename) = original_compiled_filename;
     378       34381 : }
     379             : /* }}} */
     380             : 
     381      118317 : ZEND_API zend_string *zend_get_compiled_filename(void) /* {{{ */
     382             : {
     383      118317 :         return CG(compiled_filename);
     384             : }
     385             : /* }}} */
     386             : 
     387         842 : ZEND_API int zend_get_compiled_lineno(void) /* {{{ */
     388             : {
     389         842 :         return CG(zend_lineno);
     390             : }
     391             : /* }}} */
     392             : 
     393      451005 : ZEND_API zend_bool zend_is_compiling(void) /* {{{ */
     394             : {
     395      451005 :         return CG(in_compilation);
     396             : }
     397             : /* }}} */
     398             : 
     399      980354 : static uint32_t get_temporary_variable(zend_op_array *op_array) /* {{{ */
     400             : {
     401      980354 :         return (uint32_t)op_array->T++;
     402             : }
     403             : /* }}} */
     404             : 
     405      773887 : static int lookup_cv(zend_op_array *op_array, zend_string* name) /* {{{ */{
     406      773887 :         int i = 0;
     407      773887 :         zend_ulong hash_value = zend_string_hash_val(name);
     408             : 
     409   138624608 :         while (i < op_array->last_var) {
     410   276309626 :                 if (ZSTR_VAL(op_array->vars[i]) == ZSTR_VAL(name) ||
     411   137615819 :                     (ZSTR_H(op_array->vars[i]) == hash_value &&
     412      538985 :                      ZSTR_LEN(op_array->vars[i]) == ZSTR_LEN(name) &&
     413      538985 :                      memcmp(ZSTR_VAL(op_array->vars[i]), ZSTR_VAL(name), ZSTR_LEN(name)) == 0)) {
     414             :                         zend_string_release(name);
     415      539003 :                         return (int)(zend_intptr_t)ZEND_CALL_VAR_NUM(NULL, i);
     416             :                 }
     417   137076834 :                 i++;
     418             :         }
     419      234884 :         i = op_array->last_var;
     420      234884 :         op_array->last_var++;
     421      234884 :         if (op_array->last_var > CG(context).vars_size) {
     422       55700 :                 CG(context).vars_size += 16; /* FIXME */
     423       55700 :                 op_array->vars = erealloc(op_array->vars, CG(context).vars_size * sizeof(zend_string*));
     424             :         }
     425             : 
     426      234884 :         op_array->vars[i] = zend_new_interned_string(name);
     427      234884 :         return (int)(zend_intptr_t)ZEND_CALL_VAR_NUM(NULL, i);
     428             : }
     429             : /* }}} */
     430             : 
     431       44565 : void zend_del_literal(zend_op_array *op_array, int n) /* {{{ */
     432             : {
     433       44565 :         zval_dtor(CT_CONSTANT_EX(op_array, n));
     434       44565 :         if (n + 1 == op_array->last_literal) {
     435       43436 :                 op_array->last_literal--;
     436             :         } else {
     437        1129 :                 ZVAL_UNDEF(CT_CONSTANT_EX(op_array, n));
     438             :         }
     439       44565 : }
     440             : /* }}} */
     441             : 
     442             : /* Common part of zend_add_literal and zend_append_individual_literal */
     443     1265491 : static inline void zend_insert_literal(zend_op_array *op_array, zval *zv, int literal_position) /* {{{ */
     444             : {
     445     1595709 :         if (Z_TYPE_P(zv) == IS_STRING || Z_TYPE_P(zv) == IS_CONSTANT) {
     446      935641 :                 zend_string_hash_val(Z_STR_P(zv));
     447      935641 :                 Z_STR_P(zv) = zend_new_interned_string(Z_STR_P(zv));
     448      935641 :                 if (ZSTR_IS_INTERNED(Z_STR_P(zv))) {
     449      931693 :                         Z_TYPE_FLAGS_P(zv) &= ~ (IS_TYPE_REFCOUNTED | IS_TYPE_COPYABLE);
     450             :                 }
     451             :         }
     452     1265491 :         ZVAL_COPY_VALUE(CT_CONSTANT_EX(op_array, literal_position), zv);
     453     1265491 :         Z_CACHE_SLOT(op_array->literals[literal_position]) = -1;
     454     1265491 : }
     455             : /* }}} */
     456             : 
     457             : /* Is used while compiling a function, using the context to keep track
     458             :    of an approximate size to avoid to relocate to often.
     459             :    Literals are truncated to actual size in the second compiler pass (pass_two()). */
     460     1265491 : int zend_add_literal(zend_op_array *op_array, zval *zv) /* {{{ */
     461             : {
     462     1265491 :         int i = op_array->last_literal;
     463     1265491 :         op_array->last_literal++;
     464     1265491 :         if (i >= CG(context).literals_size) {
     465      360270 :                 while (i >= CG(context).literals_size) {
     466      120090 :                         CG(context).literals_size += 16; /* FIXME */
     467             :                 }
     468      120090 :                 op_array->literals = (zval*)erealloc(op_array->literals, CG(context).literals_size * sizeof(zval));
     469             :         }
     470     1265491 :         zend_insert_literal(op_array, zv, i);
     471     1265491 :         return i;
     472             : }
     473             : /* }}} */
     474             : 
     475      209468 : static inline int zend_add_literal_string(zend_op_array *op_array, zend_string **str) /* {{{ */
     476             : {
     477             :         int ret;
     478             :         zval zv;
     479      209468 :         ZVAL_STR(&zv, *str);
     480      209468 :         ret = zend_add_literal(op_array, &zv);
     481      209468 :         *str = Z_STR(zv);
     482      209468 :         return ret;
     483             : }
     484             : /* }}} */
     485             : 
     486       54724 : static int zend_add_func_name_literal(zend_op_array *op_array, zend_string *name) /* {{{ */
     487             : {
     488             :         /* Original name */
     489       54724 :         int ret = zend_add_literal_string(op_array, &name);
     490             : 
     491             :         /* Lowercased name */
     492       54724 :         zend_string *lc_name = zend_string_tolower(name);
     493       54724 :         zend_add_literal_string(op_array, &lc_name);
     494             : 
     495       54724 :         return ret;
     496             : }
     497             : /* }}} */
     498             : 
     499         375 : static int zend_add_ns_func_name_literal(zend_op_array *op_array, zend_string *name) /* {{{ */
     500             : {
     501             :         const char *unqualified_name;
     502             :         size_t unqualified_name_len;
     503             : 
     504             :         /* Original name */
     505         375 :         int ret = zend_add_literal_string(op_array, &name);
     506             : 
     507             :         /* Lowercased name */
     508         375 :         zend_string *lc_name = zend_string_tolower(name);
     509         375 :         zend_add_literal_string(op_array, &lc_name);
     510             : 
     511             :         /* Lowercased unqualfied name */
     512         375 :         if (zend_get_unqualified_name(name, &unqualified_name, &unqualified_name_len)) {
     513         750 :                 lc_name = zend_string_alloc(unqualified_name_len, 0);
     514         375 :                 zend_str_tolower_copy(ZSTR_VAL(lc_name), unqualified_name, unqualified_name_len);
     515         375 :                 zend_add_literal_string(op_array, &lc_name);
     516             :         }
     517             : 
     518         375 :         return ret;
     519             : }
     520             : /* }}} */
     521             : 
     522       26684 : static int zend_add_class_name_literal(zend_op_array *op_array, zend_string *name) /* {{{ */
     523             : {
     524             :         /* Original name */
     525       26684 :         int ret = zend_add_literal_string(op_array, &name);
     526             : 
     527             :         /* Lowercased name */
     528       26684 :         zend_string *lc_name = zend_string_tolower(name);
     529       26684 :         zend_add_literal_string(op_array, &lc_name);
     530             : 
     531       26684 :         zend_alloc_cache_slot(ret);
     532             : 
     533       26684 :         return ret;
     534             : }
     535             : /* }}} */
     536             : 
     537        5708 : static int zend_add_const_name_literal(zend_op_array *op_array, zend_string *name, zend_bool unqualified) /* {{{ */
     538             : {
     539             :         zend_string *tmp_name;
     540             : 
     541        5708 :         int ret = zend_add_literal_string(op_array, &name);
     542             : 
     543        5708 :         size_t ns_len = 0, after_ns_len = ZSTR_LEN(name);
     544       11416 :         const char *after_ns = zend_memrchr(ZSTR_VAL(name), '\\', ZSTR_LEN(name));
     545        5708 :         if (after_ns) {
     546          87 :                 after_ns += 1;
     547          87 :                 ns_len = after_ns - ZSTR_VAL(name) - 1;
     548          87 :                 after_ns_len = ZSTR_LEN(name) - ns_len - 1;
     549             : 
     550             :                 /* lowercased namespace name & original constant name */
     551         174 :                 tmp_name = zend_string_init(ZSTR_VAL(name), ZSTR_LEN(name), 0);
     552          87 :                 zend_str_tolower(ZSTR_VAL(tmp_name), ns_len);
     553          87 :                 zend_add_literal_string(op_array, &tmp_name);
     554             : 
     555             :                 /* lowercased namespace name & lowercased constant name */
     556          87 :                 tmp_name = zend_string_tolower(name);
     557          87 :                 zend_add_literal_string(op_array, &tmp_name);
     558             : 
     559          87 :                 if (!unqualified) {
     560          60 :                         return ret;
     561             :                 }
     562             :         } else {
     563        5621 :                 after_ns = ZSTR_VAL(name);
     564             :         }
     565             : 
     566             :         /* original unqualified constant name */
     567        5648 :         tmp_name = zend_string_init(after_ns, after_ns_len, 0);
     568        5648 :         zend_add_literal_string(op_array, &tmp_name);
     569             : 
     570             :         /* lowercased unqualified constant name */
     571        5648 :         tmp_name = zend_string_alloc(after_ns_len, 0);
     572        5648 :         zend_str_tolower_copy(ZSTR_VAL(tmp_name), after_ns, after_ns_len);
     573        5648 :         zend_add_literal_string(op_array, &tmp_name);
     574             : 
     575        5648 :         return ret;
     576             : }
     577             : /* }}} */
     578             : 
     579             : #define LITERAL_STR(op, str) do { \
     580             :                 zval _c; \
     581             :                 ZVAL_STR(&_c, str); \
     582             :                 op.constant = zend_add_literal(CG(active_op_array), &_c); \
     583             :         } while (0)
     584             : 
     585         277 : void zend_stop_lexing(void)
     586             : {
     587         277 :         if (LANG_SCNG(on_event)) {
     588           0 :                 LANG_SCNG(on_event)(ON_STOP, END, 0, LANG_SCNG(on_event_context));
     589             :         }
     590             : 
     591         277 :         LANG_SCNG(yy_cursor) = LANG_SCNG(yy_limit);
     592         277 : }
     593             : 
     594       46031 : static uint32_t zend_start_live_range(zend_op_array *op_array, uint32_t start) /* {{{ */
     595             : {
     596             :         zend_live_range *range;
     597             : 
     598       46031 :         op_array->last_live_range++;
     599       46031 :         op_array->live_range = erealloc(op_array->live_range, sizeof(zend_live_range) * op_array->last_live_range);
     600       46031 :         range = op_array->live_range + op_array->last_live_range - 1;
     601       46031 :         range->start = start;
     602       46031 :         return op_array->last_live_range - 1;
     603             : }
     604             : /* }}} */
     605             : 
     606       14816 : static uint32_t zend_start_live_range_ex(zend_op_array *op_array, uint32_t start) /* {{{ */
     607             : {
     608       24936 :         if (op_array->last_live_range == 0 ||
     609       10120 :             op_array->live_range[op_array->last_live_range - 1].start <= start) {
     610       13903 :                 return zend_start_live_range(op_array, start);
     611             :         } else {
     612             :                 /* Live ranges have to be sorted by "start" field */
     613         913 :                 uint32_t n = op_array->last_live_range;
     614             : 
     615             :                 /* move early ranges to make a room */
     616         913 :                 op_array->last_live_range = n + 1;
     617         913 :                 op_array->live_range = erealloc(op_array->live_range, sizeof(zend_live_range) * op_array->last_live_range);
     618             :                 do {
     619        2324 :                         op_array->live_range[n] = op_array->live_range[n-1];
     620        2324 :                         n--;
     621        2324 :                 } while (n != 0 && op_array->live_range[n-1].start > start);
     622             : 
     623             :             /* initialize new range */
     624         913 :                 op_array->live_range[n].start = start;
     625             : 
     626             :                 /* update referens to live-ranges from stack */
     627         913 :                 if (!zend_stack_is_empty(&CG(loop_var_stack))) {
     628          70 :                         zend_loop_var *loop_var = zend_stack_top(&CG(loop_var_stack));
     629          70 :                         zend_loop_var *base = zend_stack_base(&CG(loop_var_stack));
     630          70 :                         int check_opcodes = 0;
     631             : 
     632          71 :                         for (; loop_var >= base; loop_var--) {
     633          70 :                                 if (loop_var->opcode == ZEND_RETURN) {
     634             :                                         /* Stack separator */
     635          63 :                                         break;
     636          14 :                                 } else if (loop_var->opcode == ZEND_FREE ||
     637           7 :                                    loop_var->opcode == ZEND_FE_FREE) {
     638           6 :                                         if (loop_var->u.live_range_offset >= n) {
     639           0 :                                                 loop_var->u.live_range_offset++;
     640           0 :                                                 check_opcodes = 1;
     641             :                                         } else {
     642           6 :                                                 break;
     643             :                                         }
     644             :                                 }
     645             :                         }
     646             : 
     647             :                         /* update previously generated FREE/FE_FREE opcodes */
     648          70 :                         if (check_opcodes) {
     649           0 :                                 zend_op *opline = op_array->opcodes + op_array->live_range[n+1].start;
     650           0 :                                 zend_op *end = op_array->opcodes + op_array->last;
     651             : 
     652           0 :                                 while (opline < end) {
     653           0 :                                         if ((opline->opcode == ZEND_FREE ||
     654           0 :                                              opline->opcode == ZEND_FE_FREE) &&
     655           0 :                                             (opline->extended_value & ZEND_FREE_ON_RETURN) &&
     656           0 :                                             opline->op2.num >= n) {
     657           0 :                                                 opline->op2.num++;
     658             :                                         }
     659           0 :                                         opline++;
     660             :                                 }
     661             :                         }
     662             :                 }
     663         913 :                 return n;
     664             :         }
     665             : }
     666             : /* }}} */
     667             : 
     668       46939 : static void zend_end_live_range(zend_op_array *op_array, uint32_t offset, uint32_t end, uint32_t kind, uint32_t var) /* {{{ */
     669             : {
     670       46939 :         zend_live_range *range = op_array->live_range + offset;
     671             : 
     672       46939 :         if (range->start == end && offset == (uint32_t)op_array->last_live_range - 1) {
     673           0 :                 op_array->last_live_range--;
     674             :         } else {
     675       46939 :                 range->end = end;
     676       46939 :                 range->var = (var * sizeof(zval)) | kind;
     677             :         }
     678       46939 : }
     679             : /* }}} */
     680             : 
     681       17180 : static inline void zend_begin_loop(zend_uchar free_opcode, const znode *loop_var) /* {{{ */
     682             : {
     683             :         zend_brk_cont_element *brk_cont_element;
     684       17180 :         int parent = CG(context).current_brk_cont;
     685       17180 :         zend_loop_var info = {0};
     686             : 
     687       17180 :         CG(context).current_brk_cont = CG(context).last_brk_cont;
     688       17180 :         brk_cont_element = get_next_brk_cont_element();
     689       17180 :         brk_cont_element->parent = parent;
     690             : 
     691       29305 :         if (loop_var && (loop_var->op_type & (IS_VAR|IS_TMP_VAR))) {
     692       12125 :                 uint32_t start = get_next_op_number(CG(active_op_array));
     693             : 
     694       12125 :                 info.opcode = free_opcode;
     695       12125 :                 info.var_type = loop_var->op_type;
     696       12125 :                 info.var_num = loop_var->u.op.var;
     697       12125 :                 info.u.live_range_offset = zend_start_live_range(CG(active_op_array), start);
     698       12125 :                 brk_cont_element->start = start;
     699             :         } else {
     700        5055 :                 info.opcode = ZEND_NOP;
     701             :                 /* The start field is used to free temporary variables in case of exceptions.
     702             :                  * We won't try to free something of we don't have loop variable.  */
     703        5055 :                 brk_cont_element->start = -1;
     704             :         }
     705             : 
     706       17180 :         zend_stack_push(&CG(loop_var_stack), &info);
     707       17180 : }
     708             : /* }}} */
     709             : 
     710       17173 : static inline void zend_end_loop(int cont_addr, const znode *var_node) /* {{{ */
     711             : {
     712       17173 :         uint32_t end = get_next_op_number(CG(active_op_array));
     713             :         zend_brk_cont_element *brk_cont_element
     714       17173 :                 = &CG(context).brk_cont_array[CG(context).current_brk_cont];
     715       17173 :         brk_cont_element->cont = cont_addr;
     716       17173 :         brk_cont_element->brk = end;
     717       17173 :         CG(context).current_brk_cont = brk_cont_element->parent;
     718             : 
     719       17173 :         if (brk_cont_element->start != -1) {
     720       12120 :                 zend_loop_var *loop_var = zend_stack_top(&CG(loop_var_stack));
     721       12120 :                 zend_end_live_range(CG(active_op_array), loop_var->u.live_range_offset, end,
     722             :                         loop_var->opcode == ZEND_FE_FREE ? ZEND_LIVE_LOOP : ZEND_LIVE_TMPVAR,
     723             :                         var_node->u.op.var);
     724             :         }
     725             : 
     726       17173 :         zend_stack_del_top(&CG(loop_var_stack));
     727       17173 : }
     728             : /* }}} */
     729             : 
     730      330538 : void zend_do_free(znode *op1) /* {{{ */
     731             : {
     732      330538 :         if (op1->op_type == IS_TMP_VAR) {
     733        7039 :                 zend_op *opline = &CG(active_op_array)->opcodes[CG(active_op_array)->last-1];
     734             : 
     735       14080 :                 while (opline->opcode == ZEND_END_SILENCE) {
     736           2 :                         opline--;
     737             :                 }
     738             : 
     739        7039 :                 if (opline->result_type == IS_TMP_VAR && opline->result.var == op1->u.op.var) {
     740        7004 :                         if (opline->opcode == ZEND_BOOL || opline->opcode == ZEND_BOOL_NOT) {
     741         914 :                                 return;
     742             :                         }
     743             :                 }
     744             : 
     745        6125 :                 zend_emit_op(NULL, ZEND_FREE, op1, NULL);
     746      323499 :         } else if (op1->op_type == IS_VAR) {
     747      296409 :                 zend_op *opline = &CG(active_op_array)->opcodes[CG(active_op_array)->last-1];
     748     1221909 :                 while (opline->opcode == ZEND_END_SILENCE ||
     749      307946 :                                 opline->opcode == ZEND_EXT_FCALL_END ||
     750      307946 :                                 opline->opcode == ZEND_OP_DATA) {
     751       13199 :                         opline--;
     752             :                 }
     753      888537 :                 if (opline->result_type == IS_VAR
     754      592473 :                         && opline->result.var == op1->u.op.var) {
     755     1184238 :                         if (opline->opcode == ZEND_FETCH_R ||
     756      296062 :                             opline->opcode == ZEND_FETCH_DIM_R ||
     757      296043 :                             opline->opcode == ZEND_FETCH_OBJ_R ||
     758      296024 :                             opline->opcode == ZEND_FETCH_STATIC_PROP_R) {
     759             :                                 /* It's very rare and useless case. It's better to use
     760             :                                    additional FREE opcode and simplify the FETCH handlers
     761             :                                    their selves */
     762          45 :                                 zend_emit_op(NULL, ZEND_FREE, op1, NULL);
     763      296019 :                         } else if (opline->opcode == ZEND_FETCH_THIS) {
     764           1 :                                 opline->opcode = ZEND_NOP;
     765           1 :                                 opline->result_type = IS_UNUSED;
     766             :                         } else {
     767      296018 :                                 opline->result_type = IS_UNUSED;
     768             :                         }
     769             :                 } else {
     770        1353 :                         while (opline >= CG(active_op_array)->opcodes) {
     771        1272 :                                 if (opline->opcode == ZEND_FETCH_LIST &&
     772         132 :                                     opline->op1_type == IS_VAR &&
     773         132 :                                     opline->op1.var == op1->u.op.var) {
     774         119 :                                         zend_emit_op(NULL, ZEND_FREE, op1, NULL);
     775         119 :                                         return;
     776             :                                 }
     777        1170 :                                 if (opline->result_type == IS_VAR
     778        1170 :                                         && opline->result.var == op1->u.op.var) {
     779         226 :                                         if (opline->opcode == ZEND_NEW) {
     780         226 :                                                 zend_emit_op(NULL, ZEND_FREE, op1, NULL);
     781             :                                         }
     782         226 :                                         break;
     783             :                                 }
     784         663 :                                 opline--;
     785             :                         }
     786             :                 }
     787       27090 :         } else if (op1->op_type == IS_CONST) {
     788             :                 /* Destroy value without using GC: When opcache moves arrays into SHM it will
     789             :                  * free the zend_array structure, so references to it from outside the op array
     790             :                  * become invalid. GC would cause such a reference in the root buffer. */
     791       26783 :                 zval_ptr_dtor_nogc(&op1->u.constant);
     792             :         }
     793             : }
     794             : /* }}} */
     795             : 
     796           2 : uint32_t zend_add_class_modifier(uint32_t flags, uint32_t new_flag) /* {{{ */
     797             : {
     798           2 :         uint32_t new_flags = flags | new_flag;
     799           2 :         if ((flags & ZEND_ACC_EXPLICIT_ABSTRACT_CLASS) && (new_flag & ZEND_ACC_EXPLICIT_ABSTRACT_CLASS)) {
     800           0 :                 zend_error_noreturn(E_COMPILE_ERROR, "Multiple abstract modifiers are not allowed");
     801             :         }
     802           2 :         if ((flags & ZEND_ACC_FINAL) && (new_flag & ZEND_ACC_FINAL)) {
     803           1 :                 zend_error_noreturn(E_COMPILE_ERROR, "Multiple final modifiers are not allowed");
     804             :         }
     805           1 :         if ((new_flags & ZEND_ACC_EXPLICIT_ABSTRACT_CLASS) && (new_flags & ZEND_ACC_FINAL)) {
     806           1 :                 zend_error_noreturn(E_COMPILE_ERROR, "Cannot use the final modifier on an abstract class");
     807             :         }
     808           0 :         return new_flags;
     809             : }
     810             : /* }}} */
     811             : 
     812         824 : uint32_t zend_add_member_modifier(uint32_t flags, uint32_t new_flag) /* {{{ */
     813             : {
     814         824 :         uint32_t new_flags = flags | new_flag;
     815         824 :         if ((flags & ZEND_ACC_PPP_MASK) && (new_flag & ZEND_ACC_PPP_MASK)) {
     816           4 :                 zend_error_noreturn(E_COMPILE_ERROR, "Multiple access type modifiers are not allowed");
     817             :         }
     818         820 :         if ((flags & ZEND_ACC_ABSTRACT) && (new_flag & ZEND_ACC_ABSTRACT)) {
     819           1 :                 zend_error_noreturn(E_COMPILE_ERROR, "Multiple abstract modifiers are not allowed");
     820             :         }
     821         819 :         if ((flags & ZEND_ACC_STATIC) && (new_flag & ZEND_ACC_STATIC)) {
     822           1 :                 zend_error_noreturn(E_COMPILE_ERROR, "Multiple static modifiers are not allowed");
     823             :         }
     824         818 :         if ((flags & ZEND_ACC_FINAL) && (new_flag & ZEND_ACC_FINAL)) {
     825           1 :                 zend_error_noreturn(E_COMPILE_ERROR, "Multiple final modifiers are not allowed");
     826             :         }
     827         817 :         if ((new_flags & ZEND_ACC_ABSTRACT) && (new_flags & ZEND_ACC_FINAL)) {
     828           4 :                 zend_error_noreturn(E_COMPILE_ERROR, "Cannot use the final modifier on an abstract class member");
     829             :         }
     830         813 :         return new_flags;
     831             : }
     832             : /* }}} */
     833             : 
     834        2392 : zend_string *zend_concat3(char *str1, size_t str1_len, char *str2, size_t str2_len, char *str3, size_t str3_len) /* {{{ */
     835             : {
     836        2392 :         size_t len = str1_len + str2_len + str3_len;
     837        2392 :         zend_string *res = zend_string_alloc(len, 0);
     838             : 
     839        2392 :         memcpy(ZSTR_VAL(res), str1, str1_len);
     840        2392 :         memcpy(ZSTR_VAL(res) + str1_len, str2, str2_len);
     841        2392 :         memcpy(ZSTR_VAL(res) + str1_len + str2_len, str3, str3_len);
     842        2392 :         ZSTR_VAL(res)[len] = '\0';
     843             : 
     844        2392 :         return res;
     845             : }
     846             : 
     847        1131 : zend_string *zend_concat_names(char *name1, size_t name1_len, char *name2, size_t name2_len) {
     848        1131 :         return zend_concat3(name1, name1_len, "\\", 1, name2, name2_len);
     849             : }
     850             : 
     851      447471 : zend_string *zend_prefix_with_ns(zend_string *name) {
     852      447471 :         if (FC(current_namespace)) {
     853        1061 :                 zend_string *ns = FC(current_namespace);
     854        1061 :                 return zend_concat_names(ZSTR_VAL(ns), ZSTR_LEN(ns), ZSTR_VAL(name), ZSTR_LEN(name));
     855             :         } else {
     856      446410 :                 return zend_string_copy(name);
     857             :         }
     858             : }
     859             : 
     860       41739 : void *zend_hash_find_ptr_lc(HashTable *ht, const char *str, size_t len) {
     861             :         void *result;
     862             :         zend_string *lcname;
     863             :         ALLOCA_FLAG(use_heap);
     864             : 
     865       83478 :         ZSTR_ALLOCA_ALLOC(lcname, len, use_heap);
     866       41739 :         zend_str_tolower_copy(ZSTR_VAL(lcname), str, len);
     867       41739 :         result = zend_hash_find_ptr(ht, lcname);
     868       41739 :         ZSTR_ALLOCA_FREE(lcname, use_heap);
     869             : 
     870       41739 :         return result;
     871             : }
     872             : 
     873      380744 : zend_string *zend_resolve_non_class_name(
     874             :         zend_string *name, uint32_t type, zend_bool *is_fully_qualified,
     875             :         zend_bool case_sensitive, HashTable *current_import_sub
     876             : ) {
     877             :         char *compound;
     878      380744 :         *is_fully_qualified = 0;
     879             : 
     880      380744 :         if (ZSTR_VAL(name)[0] == '\\') {
     881             :                 /* Remove \ prefix (only relevant if this is a string rather than a label) */
     882           2 :                 *is_fully_qualified = 1;
     883           4 :                 return zend_string_init(ZSTR_VAL(name) + 1, ZSTR_LEN(name) - 1, 0);
     884             :         }
     885             : 
     886      380742 :         if (type == ZEND_NAME_FQ) {
     887         188 :                 *is_fully_qualified = 1;
     888         188 :                 return zend_string_copy(name);
     889             :         }
     890             : 
     891      380554 :         if (type == ZEND_NAME_RELATIVE) {
     892          46 :                 *is_fully_qualified = 1;
     893          46 :                 return zend_prefix_with_ns(name);
     894             :         }
     895             : 
     896      380508 :         if (current_import_sub) {
     897             :                 /* If an unqualified name is a function/const alias, replace it. */
     898             :                 zend_string *import_name;
     899          78 :                 if (case_sensitive) {
     900          22 :                         import_name = zend_hash_find_ptr(current_import_sub, name);
     901             :                 } else {
     902          56 :                         import_name = zend_hash_find_ptr_lc(current_import_sub, ZSTR_VAL(name), ZSTR_LEN(name));
     903             :                 }
     904             : 
     905          78 :                 if (import_name) {
     906          40 :                         *is_fully_qualified = 1;
     907          40 :                         return zend_string_copy(import_name);
     908             :                 }
     909             :         }
     910             : 
     911      380468 :         compound = memchr(ZSTR_VAL(name), '\\', ZSTR_LEN(name));
     912      380468 :         if (compound) {
     913          71 :                 *is_fully_qualified = 1;
     914             :         }
     915             : 
     916      380468 :         if (compound && FC(imports)) {
     917             :                 /* If the first part of a qualified name is an alias, substitute it. */
     918          42 :                 size_t len = compound - ZSTR_VAL(name);
     919          42 :                 zend_string *import_name = zend_hash_find_ptr_lc(FC(imports), ZSTR_VAL(name), len);
     920             : 
     921          42 :                 if (import_name) {
     922          13 :                         return zend_concat_names(
     923          13 :                                 ZSTR_VAL(import_name), ZSTR_LEN(import_name), ZSTR_VAL(name) + len + 1, ZSTR_LEN(name) - len - 1);
     924             :                 }
     925             :         }
     926             : 
     927      380455 :         return zend_prefix_with_ns(name);
     928             : }
     929             : /* }}} */
     930             : 
     931      288585 : zend_string *zend_resolve_function_name(zend_string *name, uint32_t type, zend_bool *is_fully_qualified) /* {{{ */
     932             : {
     933      288585 :         return zend_resolve_non_class_name(
     934             :                 name, type, is_fully_qualified, 0, FC(imports_function));
     935             : }
     936             : /* }}} */
     937             : 
     938       92159 : zend_string *zend_resolve_const_name(zend_string *name, uint32_t type, zend_bool *is_fully_qualified) /* {{{ */ {
     939       92159 :         return zend_resolve_non_class_name(
     940             :                 name, type, is_fully_qualified, 1, FC(imports_const));
     941             : }
     942             : /* }}} */
     943             : 
     944       38226 : zend_string *zend_resolve_class_name(zend_string *name, uint32_t type) /* {{{ */
     945             : {
     946             :         char *compound;
     947             : 
     948       38226 :         if (type == ZEND_NAME_RELATIVE) {
     949          26 :                 return zend_prefix_with_ns(name);
     950             :         }
     951             : 
     952       38200 :         if (type == ZEND_NAME_FQ || ZSTR_VAL(name)[0] == '\\') {
     953             :                 /* Remove \ prefix (only relevant if this is a string rather than a label) */
     954         321 :                 if (ZSTR_VAL(name)[0] == '\\') {
     955           2 :                         name = zend_string_init(ZSTR_VAL(name) + 1, ZSTR_LEN(name) - 1, 0);
     956             :                 } else {
     957             :                         zend_string_addref(name);
     958             :                 }
     959             :                 /* Ensure that \self, \parent and \static are not used */
     960         321 :                 if (ZEND_FETCH_CLASS_DEFAULT != zend_get_class_fetch_type(name)) {
     961           1 :                         zend_error_noreturn(E_COMPILE_ERROR, "'\\%s' is an invalid class name", ZSTR_VAL(name));
     962             :                 }
     963         320 :                 return name;
     964             :         }
     965             : 
     966       37879 :         if (FC(imports)) {
     967         190 :                 compound = memchr(ZSTR_VAL(name), '\\', ZSTR_LEN(name));
     968         190 :                 if (compound) {
     969             :                         /* If the first part of a qualified name is an alias, substitute it. */
     970          26 :                         size_t len = compound - ZSTR_VAL(name);
     971             :                         zend_string *import_name =
     972          26 :                                 zend_hash_find_ptr_lc(FC(imports), ZSTR_VAL(name), len);
     973             : 
     974          26 :                         if (import_name) {
     975          16 :                                 return zend_concat_names(
     976          16 :                                         ZSTR_VAL(import_name), ZSTR_LEN(import_name), ZSTR_VAL(name) + len + 1, ZSTR_LEN(name) - len - 1);
     977             :                         }
     978             :                 } else {
     979             :                         /* If an unqualified name is an alias, replace it. */
     980             :                         zend_string *import_name
     981         164 :                                 = zend_hash_find_ptr_lc(FC(imports), ZSTR_VAL(name), ZSTR_LEN(name));
     982             : 
     983         164 :                         if (import_name) {
     984          72 :                                 return zend_string_copy(import_name);
     985             :                         }
     986             :                 }
     987             :         }
     988             : 
     989             :         /* If not fully qualified and not an alias, prepend the current namespace */
     990       37791 :         return zend_prefix_with_ns(name);
     991             : }
     992             : /* }}} */
     993             : 
     994       35720 : zend_string *zend_resolve_class_name_ast(zend_ast *ast) /* {{{ */
     995             : {
     996       35720 :         zval *class_name = zend_ast_get_zval(ast);
     997       35720 :         if (Z_TYPE_P(class_name) != IS_STRING) {
     998           1 :                 zend_error_noreturn(E_COMPILE_ERROR, "Illegal class name");
     999             :         }
    1000       35719 :         return zend_resolve_class_name(Z_STR_P(class_name), ast->attr);
    1001             : }
    1002             : /* }}} */
    1003             : 
    1004          37 : static void label_ptr_dtor(zval *zv) /* {{{ */
    1005             : {
    1006          37 :         efree_size(Z_PTR_P(zv), sizeof(zend_label));
    1007          37 : }
    1008             : /* }}} */
    1009             : 
    1010         119 : static void str_dtor(zval *zv)  /* {{{ */ {
    1011         119 :         zend_string_release(Z_STR_P(zv));
    1012         119 : }
    1013             : /* }}} */
    1014             : 
    1015             : static zend_bool zend_is_call(zend_ast *ast);
    1016             : 
    1017        2942 : static uint32_t zend_add_try_element(uint32_t try_op) /* {{{ */
    1018             : {
    1019        2942 :         zend_op_array *op_array = CG(active_op_array);
    1020        2942 :         uint32_t try_catch_offset = op_array->last_try_catch++;
    1021             :         zend_try_catch_element *elem;
    1022             : 
    1023        2942 :         op_array->try_catch_array = safe_erealloc(
    1024             :                 op_array->try_catch_array, sizeof(zend_try_catch_element), op_array->last_try_catch, 0);
    1025             : 
    1026        2942 :         elem = &op_array->try_catch_array[try_catch_offset];
    1027        2942 :         elem->try_op = try_op;
    1028        2942 :         elem->catch_op = 0;
    1029        2942 :         elem->finally_op = 0;
    1030        2942 :         elem->finally_end = 0;
    1031             : 
    1032        2942 :         return try_catch_offset;
    1033             : }
    1034             : /* }}} */
    1035             : 
    1036         553 : ZEND_API void function_add_ref(zend_function *function) /* {{{ */
    1037             : {
    1038         553 :         if (function->type == ZEND_USER_FUNCTION) {
    1039         247 :                 zend_op_array *op_array = &function->op_array;
    1040             : 
    1041         247 :                 if (op_array->refcount) {
    1042         247 :                         (*op_array->refcount)++;
    1043             :                 }
    1044         247 :                 if (op_array->static_variables) {
    1045           4 :                         if (!(GC_FLAGS(op_array->static_variables) & IS_ARRAY_IMMUTABLE)) {
    1046           4 :                                 GC_REFCOUNT(op_array->static_variables)++;
    1047             :                         }
    1048             :                 }
    1049         247 :                 op_array->run_time_cache = NULL;
    1050         306 :         } else if (function->type == ZEND_INTERNAL_FUNCTION) {
    1051         306 :                 if (function->common.function_name) {
    1052         306 :                         zend_string_addref(function->common.function_name);
    1053             :                 }
    1054             :         }
    1055         553 : }
    1056             : /* }}} */
    1057             : 
    1058       19031 : ZEND_API int do_bind_function(const zend_op_array *op_array, const zend_op *opline, HashTable *function_table, zend_bool compile_time) /* {{{ */
    1059             : {
    1060             :         zend_function *function, *new_function;
    1061             :         zval *lcname, *rtd_key;
    1062             : 
    1063       19031 :         if (compile_time) {
    1064       15566 :                 lcname = CT_CONSTANT_EX(op_array, opline->op1.constant);
    1065       15566 :                 rtd_key = lcname + 1;
    1066             :         } else {
    1067        3465 :                 lcname = RT_CONSTANT(op_array, opline->op1);
    1068        3465 :                 rtd_key = lcname + 1;
    1069             :         }
    1070             : 
    1071       38062 :         function = zend_hash_find_ptr(function_table, Z_STR_P(rtd_key));
    1072       19031 :         new_function = zend_arena_alloc(&CG(arena), sizeof(zend_op_array));
    1073       19031 :         memcpy(new_function, function, sizeof(zend_op_array));
    1074       38062 :         if (zend_hash_add_ptr(function_table, Z_STR_P(lcname), new_function) == NULL) {
    1075           1 :                 int error_level = compile_time ? E_COMPILE_ERROR : E_ERROR;
    1076             :                 zend_function *old_function;
    1077             : 
    1078           4 :                 if ((old_function = zend_hash_find_ptr(function_table, Z_STR_P(lcname))) != NULL
    1079             :                         && old_function->type == ZEND_USER_FUNCTION
    1080           2 :                         && old_function->op_array.last > 0) {
    1081           3 :                         zend_error_noreturn(error_level, "Cannot redeclare %s() (previously declared in %s:%d)",
    1082           1 :                                                 ZSTR_VAL(function->common.function_name),
    1083           1 :                                                 ZSTR_VAL(old_function->op_array.filename),
    1084           1 :                                                 old_function->op_array.opcodes[0].lineno);
    1085             :                 } else {
    1086           0 :                         zend_error_noreturn(error_level, "Cannot redeclare %s()", ZSTR_VAL(function->common.function_name));
    1087             :                 }
    1088             :                 return FAILURE;
    1089             :         } else {
    1090       19030 :                 if (function->op_array.refcount) {
    1091       19030 :                         (*function->op_array.refcount)++;
    1092             :                 }
    1093       19030 :                 function->op_array.static_variables = NULL; /* NULL out the unbound function */
    1094       19030 :                 return SUCCESS;
    1095             :         }
    1096             : }
    1097             : /* }}} */
    1098             : 
    1099        5513 : 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) /* {{{ */
    1100             : {
    1101             :         zend_class_entry *ce;
    1102             :         zval *lcname, *rtd_key;
    1103             : 
    1104        5513 :         if (compile_time) {
    1105        5035 :                 lcname = CT_CONSTANT_EX(op_array, opline->op1.constant);
    1106        5035 :                 rtd_key = lcname + 1;
    1107             :         } else {
    1108         478 :                 lcname = RT_CONSTANT(op_array, opline->op1);
    1109         478 :                 rtd_key = lcname + 1;
    1110             :         }
    1111       11026 :         if ((ce = zend_hash_find_ptr(class_table, Z_STR_P(rtd_key))) == NULL) {
    1112           0 :                 zend_error_noreturn(E_COMPILE_ERROR, "Internal Zend error - Missing class information for %s", Z_STRVAL_P(rtd_key));
    1113             :                 return NULL;
    1114             :         }
    1115        5513 :         ce->refcount++;
    1116       11026 :         if (zend_hash_add_ptr(class_table, Z_STR_P(lcname), ce) == NULL) {
    1117          16 :                 ce->refcount--;
    1118          16 :                 if (!compile_time) {
    1119             :                         /* If we're in compile time, in practice, it's quite possible
    1120             :                          * that we'll never reach this class declaration at runtime,
    1121             :                          * so we shut up about it.  This allows the if (!defined('FOO')) { return; }
    1122             :                          * approach to work.
    1123             :                          */
    1124           8 :                         zend_error_noreturn(E_COMPILE_ERROR, "Cannot declare %s %s, because the name is already in use", zend_get_object_type(ce), ZSTR_VAL(ce->name));
    1125             :                 }
    1126           8 :                 return NULL;
    1127             :         } else {
    1128        5497 :                 if (!(ce->ce_flags & (ZEND_ACC_INTERFACE|ZEND_ACC_IMPLEMENT_INTERFACES|ZEND_ACC_IMPLEMENT_TRAITS))) {
    1129        4869 :                         zend_verify_abstract_class(ce);
    1130             :                 }
    1131        5494 :                 return ce;
    1132             :         }
    1133             : }
    1134             : /* }}} */
    1135             : 
    1136        2499 : 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) /* {{{ */
    1137             : {
    1138             :         zend_class_entry *ce;
    1139             :         zval *lcname, *rtd_key;
    1140             : 
    1141        2499 :         if (compile_time) {
    1142        1181 :                 lcname = CT_CONSTANT_EX(op_array, opline->op1.constant);
    1143        1181 :                 rtd_key = lcname + 1;
    1144             :         } else {
    1145        1318 :                 lcname = RT_CONSTANT(op_array, opline->op1);
    1146        1318 :                 rtd_key = lcname + 1;
    1147             :         }
    1148             : 
    1149        4998 :         ce = zend_hash_find_ptr(class_table, Z_STR_P(rtd_key));
    1150             : 
    1151        2499 :         if (!ce) {
    1152           0 :                 if (!compile_time) {
    1153             :                         /* If we're in compile time, in practice, it's quite possible
    1154             :                          * that we'll never reach this class declaration at runtime,
    1155             :                          * so we shut up about it.  This allows the if (!defined('FOO')) { return; }
    1156             :                          * approach to work.
    1157             :                          */
    1158           0 :                         zend_error_noreturn(E_COMPILE_ERROR, "Cannot declare  %s, because the name is already in use", zend_get_object_type(Z_OBJCE_P(lcname)));
    1159             :                 }
    1160           0 :                 return NULL;
    1161             :         }
    1162             : 
    1163        2499 :         if (zend_hash_exists(class_table, Z_STR_P(lcname))) {
    1164           0 :                 zend_error_noreturn(E_COMPILE_ERROR, "Cannot declare %s %s, because the name is already in use", zend_get_object_type(ce), ZSTR_VAL(ce->name));
    1165             :         }
    1166             : 
    1167        2499 :         zend_do_inheritance(ce, parent_ce);
    1168             : 
    1169        2443 :         ce->refcount++;
    1170             : 
    1171             :         /* Register the derived class */
    1172        4886 :         if (zend_hash_add_ptr(class_table, Z_STR_P(lcname), ce) == NULL) {
    1173           0 :                 zend_error_noreturn(E_COMPILE_ERROR, "Cannot declare %s %s, because the name is already in use", zend_get_object_type(ce), ZSTR_VAL(ce->name));
    1174             :         }
    1175        2443 :         return ce;
    1176             : }
    1177             : /* }}} */
    1178             : 
    1179       22634 : void zend_do_early_binding(void) /* {{{ */
    1180             : {
    1181       22634 :         zend_op *opline = &CG(active_op_array)->opcodes[CG(active_op_array)->last-1];
    1182             :         HashTable *table;
    1183             : 
    1184       45268 :         while (opline->opcode == ZEND_TICKS && opline > CG(active_op_array)->opcodes) {
    1185           0 :                 opline--;
    1186             :         }
    1187             : 
    1188       22634 :         switch (opline->opcode) {
    1189             :                 case ZEND_DECLARE_FUNCTION:
    1190       15566 :                         if (do_bind_function(CG(active_op_array), opline, CG(function_table), 1) == FAILURE) {
    1191           0 :                                 return;
    1192             :                         }
    1193       15565 :                         table = CG(function_table);
    1194       15565 :                         break;
    1195             :                 case ZEND_DECLARE_CLASS:
    1196        5035 :                         if (do_bind_class(CG(active_op_array), opline, CG(class_table), 1) == NULL) {
    1197           8 :                                 return;
    1198             :                         }
    1199        5024 :                         table = CG(class_table);
    1200        5024 :                         break;
    1201             :                 case ZEND_DECLARE_INHERITED_CLASS:
    1202             :                         {
    1203        1483 :                                 zend_op *fetch_class_opline = opline-1;
    1204             :                                 zval *parent_name;
    1205             :                                 zend_class_entry *ce;
    1206             : 
    1207        1483 :                                 parent_name = CT_CONSTANT(fetch_class_opline->op2);
    1208        2669 :                                 if (((ce = zend_lookup_class_ex(Z_STR_P(parent_name), parent_name + 1, 0)) == NULL) ||
    1209        1181 :                                     ((CG(compiler_options) & ZEND_COMPILE_IGNORE_INTERNAL_CLASSES) &&
    1210           5 :                                      (ce->type == ZEND_INTERNAL_CLASS))) {
    1211         302 :                                         if (CG(compiler_options) & ZEND_COMPILE_DELAYED_BINDING) {
    1212           0 :                                                 uint32_t *opline_num = &CG(active_op_array)->early_binding;
    1213             : 
    1214           0 :                                                 while (*opline_num != (uint32_t)-1) {
    1215           0 :                                                         opline_num = &CG(active_op_array)->opcodes[*opline_num].result.opline_num;
    1216             :                                                 }
    1217           0 :                                                 *opline_num = opline - CG(active_op_array)->opcodes;
    1218           0 :                                                 opline->opcode = ZEND_DECLARE_INHERITED_CLASS_DELAYED;
    1219           0 :                                                 opline->result_type = IS_UNUSED;
    1220           0 :                                                 opline->result.opline_num = -1;
    1221             :                                         }
    1222         302 :                                         return;
    1223             :                                 }
    1224        1181 :                                 if (do_bind_inherited_class(CG(active_op_array), opline, CG(class_table), ce, 1) == NULL) {
    1225           0 :                                         return;
    1226             :                                 }
    1227             :                                 /* clear unnecessary ZEND_FETCH_CLASS opcode */
    1228        1129 :                                 zend_del_literal(CG(active_op_array), fetch_class_opline->op2.constant);
    1229        1129 :                                 MAKE_NOP(fetch_class_opline);
    1230             : 
    1231        1129 :                                 table = CG(class_table);
    1232        1129 :                                 break;
    1233             :                         }
    1234             :                 case ZEND_VERIFY_ABSTRACT_CLASS:
    1235             :                 case ZEND_ADD_INTERFACE:
    1236             :                 case ZEND_ADD_TRAIT:
    1237             :                 case ZEND_BIND_TRAITS:
    1238             :                         /* We currently don't early-bind classes that implement interfaces */
    1239             :                         /* Classes with traits are handled exactly the same, no early-bind here */
    1240         550 :                         return;
    1241             :                 default:
    1242           0 :                         zend_error_noreturn(E_COMPILE_ERROR, "Invalid binding type");
    1243             :                         return;
    1244             :         }
    1245             : 
    1246       21718 :         zend_hash_del(table, Z_STR_P(CT_CONSTANT(opline->op1)+1));
    1247       21718 :         zend_del_literal(CG(active_op_array), opline->op1.constant+1);
    1248       21718 :         zend_del_literal(CG(active_op_array), opline->op1.constant);
    1249       21718 :         MAKE_NOP(opline);
    1250             : }
    1251             : /* }}} */
    1252             : 
    1253         508 : static void zend_mark_function_as_generator() /* {{{ */
    1254             : {
    1255         508 :         if (!CG(active_op_array)->function_name) {
    1256           1 :                 zend_error_noreturn(E_COMPILE_ERROR,
    1257             :                         "The \"yield\" expression can only be used inside a function");
    1258             :         }
    1259             : 
    1260         507 :         if (CG(active_op_array)->fn_flags & ZEND_ACC_HAS_RETURN_TYPE) {
    1261          25 :                 zend_arg_info return_info = CG(active_op_array)->arg_info[-1];
    1262             : 
    1263          25 :                 if (return_info.type_hint != IS_ITERABLE) {
    1264          25 :                         const char *msg = "Generators may only declare a return type of Generator, Iterator, Traversable, or iterable, %s is not permitted";
    1265             :                         
    1266          25 :                         if (!return_info.class_name) {
    1267           0 :                                 zend_error_noreturn(E_COMPILE_ERROR, msg, zend_get_type_by_const(return_info.type_hint));
    1268             :                         }
    1269             : 
    1270         111 :                         if (!zend_string_equals_literal_ci(return_info.class_name, "Traversable")
    1271          37 :                                 && !zend_string_equals_literal_ci(return_info.class_name, "Iterator")
    1272          49 :                                 && !zend_string_equals_literal_ci(return_info.class_name, "Generator")) {
    1273           1 :                                 zend_error_noreturn(E_COMPILE_ERROR, msg, ZSTR_VAL(return_info.class_name));
    1274             :                         }
    1275             :                 }
    1276             :         }
    1277             : 
    1278         506 :         CG(active_op_array)->fn_flags |= ZEND_ACC_GENERATOR;
    1279         506 : }
    1280             : /* }}} */
    1281             : 
    1282           0 : ZEND_API void zend_do_delayed_early_binding(const zend_op_array *op_array) /* {{{ */
    1283             : {
    1284           0 :         if (op_array->early_binding != (uint32_t)-1) {
    1285           0 :                 zend_bool orig_in_compilation = CG(in_compilation);
    1286           0 :                 uint32_t opline_num = op_array->early_binding;
    1287             :                 zend_class_entry *ce;
    1288             : 
    1289           0 :                 CG(in_compilation) = 1;
    1290           0 :                 while (opline_num != (uint32_t)-1) {
    1291           0 :                         zval *parent_name = RT_CONSTANT(op_array, op_array->opcodes[opline_num-1].op2);
    1292           0 :                         if ((ce = zend_lookup_class_ex(Z_STR_P(parent_name), parent_name + 1, 0)) != NULL) {
    1293           0 :                                 do_bind_inherited_class(op_array, &op_array->opcodes[opline_num], EG(class_table), ce, 0);
    1294             :                         }
    1295           0 :                         opline_num = op_array->opcodes[opline_num].result.opline_num;
    1296             :                 }
    1297           0 :                 CG(in_compilation) = orig_in_compilation;
    1298             :         }
    1299           0 : }
    1300             : /* }}} */
    1301             : 
    1302      401993 : ZEND_API zend_string *zend_mangle_property_name(const char *src1, size_t src1_length, const char *src2, size_t src2_length, int internal) /* {{{ */
    1303             : {
    1304      401993 :         size_t prop_name_length = 1 + src1_length + 1 + src2_length;
    1305      401993 :         zend_string *prop_name = zend_string_alloc(prop_name_length, internal);
    1306             : 
    1307      401993 :         ZSTR_VAL(prop_name)[0] = '\0';
    1308      401993 :         memcpy(ZSTR_VAL(prop_name) + 1, src1, src1_length+1);
    1309      401993 :         memcpy(ZSTR_VAL(prop_name) + 1 + src1_length + 1, src2, src2_length+1);
    1310      401993 :         return prop_name;
    1311             : }
    1312             : /* }}} */
    1313             : 
    1314             : static zend_always_inline size_t zend_strnlen(const char* s, size_t maxlen) /* {{{ */
    1315             : {
    1316        4272 :         size_t len = 0;
    1317       27203 :         while (*s++ && maxlen--) len++;
    1318        4272 :         return len;
    1319             : }
    1320             : /* }}} */
    1321             : 
    1322        9516 : ZEND_API int zend_unmangle_property_name_ex(const zend_string *name, const char **class_name, const char **prop_name, size_t *prop_len) /* {{{ */
    1323             : {
    1324             :         size_t class_name_len;
    1325             :         size_t anonclass_src_len;
    1326             : 
    1327        9516 :         *class_name = NULL;
    1328             : 
    1329        9516 :         if (!ZSTR_LEN(name) || ZSTR_VAL(name)[0] != '\0') {
    1330        7380 :                 *prop_name = ZSTR_VAL(name);
    1331        7380 :                 if (prop_len) {
    1332        1005 :                         *prop_len = ZSTR_LEN(name);
    1333             :                 }
    1334        7380 :                 return SUCCESS;
    1335             :         }
    1336        2136 :         if (ZSTR_LEN(name) < 3 || ZSTR_VAL(name)[1] == '\0') {
    1337           0 :                 zend_error(E_NOTICE, "Illegal member variable name");
    1338           0 :                 *prop_name = ZSTR_VAL(name);
    1339           0 :                 if (prop_len) {
    1340           0 :                         *prop_len = ZSTR_LEN(name);
    1341             :                 }
    1342           0 :                 return FAILURE;
    1343             :         }
    1344             : 
    1345        4272 :         class_name_len = zend_strnlen(ZSTR_VAL(name) + 1, ZSTR_LEN(name) - 2);
    1346        2136 :         if (class_name_len >= ZSTR_LEN(name) - 2 || ZSTR_VAL(name)[class_name_len + 1] != '\0') {
    1347           0 :                 zend_error(E_NOTICE, "Corrupt member variable name");
    1348           0 :                 *prop_name = ZSTR_VAL(name);
    1349           0 :                 if (prop_len) {
    1350           0 :                         *prop_len = ZSTR_LEN(name);
    1351             :                 }
    1352           0 :                 return FAILURE;
    1353             :         }
    1354             : 
    1355        2136 :         *class_name = ZSTR_VAL(name) + 1;
    1356        4272 :         anonclass_src_len = zend_strnlen(*class_name + class_name_len + 1, ZSTR_LEN(name) - class_name_len - 2);
    1357        2136 :         if (class_name_len + anonclass_src_len + 2 != ZSTR_LEN(name)) {
    1358           1 :                 class_name_len += anonclass_src_len + 1;
    1359             :         }
    1360        2136 :         *prop_name = ZSTR_VAL(name) + class_name_len + 2;
    1361        2136 :         if (prop_len) {
    1362         966 :                 *prop_len = ZSTR_LEN(name) - class_name_len - 2;
    1363             :         }
    1364        2136 :         return SUCCESS;
    1365             : }
    1366             : /* }}} */
    1367             : 
    1368       30988 : static zend_constant *zend_lookup_reserved_const(const char *name, size_t len) /* {{{ */
    1369             : {
    1370       30988 :         zend_constant *c = zend_hash_find_ptr_lc(EG(zend_constants), name, len);
    1371       30988 :         if (c && !(c->flags & CONST_CS) && (c->flags & CONST_CT_SUBST)) {
    1372       23041 :                 return c;
    1373             :         }
    1374        7947 :         return NULL;
    1375             : }
    1376             : /* }}} */
    1377             : 
    1378       92351 : static zend_bool zend_try_ct_eval_const(zval *zv, zend_string *name, zend_bool is_fully_qualified) /* {{{ */
    1379             : {
    1380             :         zend_constant *c;
    1381             : 
    1382             :         /* Substitute case-sensitive (or lowercase) constants */
    1383      184702 :         c = zend_hash_find_ptr(EG(zend_constants), name);
    1384      244214 :         if (c && (
    1385      137389 :               ((c->flags & CONST_PERSISTENT) && !(CG(compiler_options) & ZEND_COMPILE_NO_PERSISTENT_CONSTANT_SUBSTITUTION))
    1386       14474 :            || (Z_TYPE(c->value) < IS_OBJECT && !(CG(compiler_options) & ZEND_COMPILE_NO_CONSTANT_SUBSTITUTION))
    1387             :         )) {
    1388       61576 :                 ZVAL_DUP(zv, &c->value);
    1389       61576 :                 return 1;
    1390             :         }
    1391             : 
    1392             :         {
    1393             :                 /* Substitute true, false and null (including unqualified usage in namespaces) */
    1394       30775 :                 const char *lookup_name = ZSTR_VAL(name);
    1395       30775 :                 size_t lookup_len = ZSTR_LEN(name);
    1396             : 
    1397       30775 :                 if (!is_fully_qualified) {
    1398       30621 :                         zend_get_unqualified_name(name, &lookup_name, &lookup_len);
    1399             :                 }
    1400             : 
    1401       30775 :                 c = zend_lookup_reserved_const(lookup_name, lookup_len);
    1402       30775 :                 if (c) {
    1403       23040 :                         ZVAL_DUP(zv, &c->value);
    1404       23040 :                         return 1;
    1405             :                 }
    1406             :         }
    1407             : 
    1408        7735 :         return 0;
    1409             : }
    1410             : /* }}} */
    1411             : 
    1412        4781 : static inline zend_bool zend_is_scope_known() /* {{{ */
    1413             : {
    1414        4781 :         if (CG(active_op_array)->fn_flags & ZEND_ACC_CLOSURE) {
    1415             :                 /* Closures can be rebound to a different scope */
    1416          21 :                 return 0;
    1417             :         }
    1418             : 
    1419        4760 :         if (!CG(active_class_entry)) {
    1420             :                 /* The scope is known if we're in a free function (no scope), but not if we're in
    1421             :                  * a file/eval (which inherits including/eval'ing scope). */
    1422          16 :                 return CG(active_op_array)->function_name != NULL;
    1423             :         }
    1424             : 
    1425             :         /* For traits self etc refers to the using class, not the trait itself */
    1426        4744 :         return (CG(active_class_entry)->ce_flags & ZEND_ACC_TRAIT) == 0;
    1427             : }
    1428             : /* }}} */
    1429             : 
    1430       10939 : static inline zend_bool class_name_refers_to_active_ce(zend_string *class_name, uint32_t fetch_type) /* {{{ */
    1431             : {
    1432       10939 :         if (!CG(active_class_entry)) {
    1433        3788 :                 return 0;
    1434             :         }
    1435        7151 :         if (fetch_type == ZEND_FETCH_CLASS_SELF && zend_is_scope_known()) {
    1436         109 :                 return 1;
    1437             :         }
    1438       14093 :         return fetch_type == ZEND_FETCH_CLASS_DEFAULT
    1439        7051 :                 && zend_string_equals_ci(class_name, CG(active_class_entry)->name);
    1440             : }
    1441             : /* }}} */
    1442             : 
    1443       48700 : uint32_t zend_get_class_fetch_type(zend_string *name) /* {{{ */
    1444             : {
    1445       48700 :         if (zend_string_equals_literal_ci(name, "self")) {
    1446        3935 :                 return ZEND_FETCH_CLASS_SELF;
    1447       44765 :         } else if (zend_string_equals_literal_ci(name, "parent")) {
    1448        2325 :                 return ZEND_FETCH_CLASS_PARENT;
    1449       42440 :         } else if (zend_string_equals_literal_ci(name, "static")) {
    1450         110 :                 return ZEND_FETCH_CLASS_STATIC;
    1451             :         } else {
    1452       42330 :                 return ZEND_FETCH_CLASS_DEFAULT;
    1453             :         }
    1454             : }
    1455             : /* }}} */
    1456             : 
    1457        6057 : static uint32_t zend_get_class_fetch_type_ast(zend_ast *name_ast) /* {{{ */
    1458             : {
    1459             :         /* Fully qualified names are always default refs */
    1460        6057 :         if (name_ast->attr == ZEND_NAME_FQ) {
    1461          91 :                 return ZEND_FETCH_CLASS_DEFAULT;
    1462             :         }
    1463             : 
    1464        5966 :         return zend_get_class_fetch_type(zend_ast_get_str(name_ast));
    1465             : }
    1466             : /* }}} */
    1467             : 
    1468        6171 : static void zend_ensure_valid_class_fetch_type(uint32_t fetch_type) /* {{{ */
    1469             : {
    1470        6171 :         if (fetch_type != ZEND_FETCH_CLASS_DEFAULT && !CG(active_class_entry) && zend_is_scope_known()) {
    1471           3 :                 zend_error_noreturn(E_COMPILE_ERROR, "Cannot use \"%s\" when no class scope is active",
    1472             :                         fetch_type == ZEND_FETCH_CLASS_SELF ? "self" :
    1473             :                         fetch_type == ZEND_FETCH_CLASS_PARENT ? "parent" : "static");
    1474             :         }
    1475        6168 : }
    1476             : /* }}} */
    1477             : 
    1478       11327 : static zend_bool zend_try_compile_const_expr_resolve_class_name(zval *zv, zend_ast *class_ast, zend_ast *name_ast, zend_bool constant) /* {{{ */
    1479             : {
    1480             :         uint32_t fetch_type;
    1481             : 
    1482       11327 :         if (name_ast->kind != ZEND_AST_ZVAL) {
    1483           0 :                 return 0;
    1484             :         }
    1485             : 
    1486       11667 :         if (!zend_string_equals_literal_ci(zend_ast_get_str(name_ast), "class")) {
    1487       11253 :                 return 0;
    1488             :         }
    1489             : 
    1490          74 :         if (class_ast->kind != ZEND_AST_ZVAL) {
    1491           0 :                 zend_error_noreturn(E_COMPILE_ERROR,
    1492             :                         "Dynamic class names are not allowed in compile-time ::class fetch");
    1493             :         }
    1494             : 
    1495          74 :         fetch_type = zend_get_class_fetch_type(zend_ast_get_str(class_ast));
    1496          74 :         zend_ensure_valid_class_fetch_type(fetch_type);
    1497             : 
    1498          74 :         switch (fetch_type) {
    1499             :                 case ZEND_FETCH_CLASS_SELF:
    1500          21 :                         if (constant || (CG(active_class_entry) && zend_is_scope_known())) {
    1501           5 :                                 ZVAL_STR_COPY(zv, CG(active_class_entry)->name);
    1502             :                         } else {
    1503          11 :                                 ZVAL_NULL(zv);
    1504             :                         }
    1505          16 :                         return 1;
    1506             :                 case ZEND_FETCH_CLASS_STATIC:
    1507             :                 case ZEND_FETCH_CLASS_PARENT:
    1508          27 :                         if (constant) {
    1509           4 :                                 zend_error_noreturn(E_COMPILE_ERROR,
    1510             :                                         "%s::class cannot be used for compile-time class name resolution",
    1511             :                                         fetch_type == ZEND_FETCH_CLASS_STATIC ? "static" : "parent"
    1512             :                                 );
    1513             :                         } else {
    1514          23 :                                 ZVAL_NULL(zv);
    1515             :                         }
    1516          23 :                         return 1;
    1517             :                 case ZEND_FETCH_CLASS_DEFAULT:
    1518          31 :                         ZVAL_STR(zv, zend_resolve_class_name_ast(class_ast));
    1519          31 :                         return 1;
    1520             :                 EMPTY_SWITCH_DEFAULT_CASE()
    1521             :         }
    1522           0 : }
    1523             : /* }}} */
    1524             : 
    1525       10939 : static zend_bool zend_try_ct_eval_class_const(zval *zv, zend_string *class_name, zend_string *name) /* {{{ */
    1526             : {
    1527       10939 :         uint32_t fetch_type = zend_get_class_fetch_type(class_name);
    1528             :         zend_class_constant *cc;
    1529             :         zval *c;
    1530             : 
    1531       10939 :         if (class_name_refers_to_active_ce(class_name, fetch_type)) {
    1532         240 :                 cc = zend_hash_find_ptr(&CG(active_class_entry)->constants_table, name);
    1533       21217 :         } else if (fetch_type == ZEND_FETCH_CLASS_DEFAULT && !(CG(compiler_options) & ZEND_COMPILE_NO_CONSTANT_SUBSTITUTION)) {
    1534       10428 :                 zend_class_entry *ce = zend_hash_find_ptr_lc(CG(class_table), ZSTR_VAL(class_name), ZSTR_LEN(class_name));
    1535       10428 :                 if (ce) {
    1536       20796 :                         cc = zend_hash_find_ptr(&ce->constants_table, name);
    1537             :                 } else {
    1538          30 :                         return 0;
    1539             :                 }
    1540             :         } else {
    1541         391 :                 return 0;
    1542             :         }
    1543             : 
    1544       10518 :         if (CG(compiler_options) & ZEND_COMPILE_NO_PERSISTENT_CONSTANT_SUBSTITUTION) {
    1545          12 :                 return 0;
    1546             :         }
    1547             : 
    1548       10506 :         if (!cc || !zend_verify_const_access(cc, CG(active_class_entry))) {
    1549          26 :                 return 0;
    1550             :         }
    1551             : 
    1552       10480 :         c = &cc->value;
    1553             : 
    1554             :         /* Substitute case-sensitive (or lowercase) persistent class constants */
    1555       10480 :         if (Z_TYPE_P(c) < IS_OBJECT) {
    1556       10457 :                 ZVAL_DUP(zv, c);
    1557       10457 :                 return 1;
    1558             :         }
    1559             : 
    1560          23 :         return 0;
    1561             : }
    1562             : /* }}} */
    1563             : 
    1564          95 : static void zend_add_to_list(void *result, void *item) /* {{{ */
    1565             : {
    1566          95 :         void** list = *(void**)result;
    1567          95 :         size_t n = 0;
    1568             : 
    1569          95 :         if (list) {
    1570         127 :                 while (list[n]) {
    1571          67 :                         n++;
    1572             :                 }
    1573             :         }
    1574             : 
    1575          95 :         list = erealloc(list, sizeof(void*) * (n+2));
    1576             : 
    1577          95 :         list[n]   = item;
    1578          95 :         list[n+1] = NULL;
    1579             : 
    1580          95 :         *(void**)result = list;
    1581          95 : }
    1582             : /* }}} */
    1583             : 
    1584       42153 : void zend_do_extended_info(void) /* {{{ */
    1585             : {
    1586             :         zend_op *opline;
    1587             : 
    1588       42153 :         if (!(CG(compiler_options) & ZEND_COMPILE_EXTENDED_INFO)) {
    1589       42153 :                 return;
    1590             :         }
    1591             : 
    1592           0 :         opline = get_next_op(CG(active_op_array));
    1593             : 
    1594           0 :         opline->opcode = ZEND_EXT_STMT;
    1595           0 :         SET_UNUSED(opline->op1);
    1596           0 :         SET_UNUSED(opline->op2);
    1597             : }
    1598             : /* }}} */
    1599             : 
    1600      359993 : void zend_do_extended_fcall_begin(void) /* {{{ */
    1601             : {
    1602             :         zend_op *opline;
    1603             : 
    1604      359993 :         if (!(CG(compiler_options) & ZEND_COMPILE_EXTENDED_INFO)) {
    1605      359993 :                 return;
    1606             :         }
    1607             : 
    1608           0 :         opline = get_next_op(CG(active_op_array));
    1609             : 
    1610           0 :         opline->opcode = ZEND_EXT_FCALL_BEGIN;
    1611           0 :         SET_UNUSED(opline->op1);
    1612           0 :         SET_UNUSED(opline->op2);
    1613             : }
    1614             : /* }}} */
    1615             : 
    1616      359977 : void zend_do_extended_fcall_end(void) /* {{{ */
    1617             : {
    1618             :         zend_op *opline;
    1619             : 
    1620      359977 :         if (!(CG(compiler_options) & ZEND_COMPILE_EXTENDED_INFO)) {
    1621      359977 :                 return;
    1622             :         }
    1623             : 
    1624           0 :         opline = get_next_op(CG(active_op_array));
    1625             : 
    1626           0 :         opline->opcode = ZEND_EXT_FCALL_END;
    1627           0 :         SET_UNUSED(opline->op1);
    1628           0 :         SET_UNUSED(opline->op2);
    1629             : }
    1630             : /* }}} */
    1631             : 
    1632       23015 : zend_bool zend_is_auto_global_str(char *name, size_t len) /* {{{ */ {
    1633             :         zend_auto_global *auto_global;
    1634             : 
    1635       46030 :         if ((auto_global = zend_hash_str_find_ptr(CG(auto_globals), name, len)) != NULL) {
    1636       23008 :                 if (auto_global->armed) {
    1637       22993 :                         auto_global->armed = auto_global->auto_global_callback(auto_global->name);
    1638             :                 }
    1639       23008 :                 return 1;
    1640             :         }
    1641           7 :         return 0;
    1642             : }
    1643             : /* }}} */
    1644             : 
    1645      806007 : zend_bool zend_is_auto_global(zend_string *name) /* {{{ */
    1646             : {
    1647             :         zend_auto_global *auto_global;
    1648             : 
    1649     1612014 :         if ((auto_global = zend_hash_find_ptr(CG(auto_globals), name)) != NULL) {
    1650       35812 :                 if (auto_global->armed) {
    1651        1642 :                         auto_global->armed = auto_global->auto_global_callback(auto_global->name);
    1652             :                 }
    1653       35812 :                 return 1;
    1654             :         }
    1655      770195 :         return 0;
    1656             : }
    1657             : /* }}} */
    1658             : 
    1659      211536 : int zend_register_auto_global(zend_string *name, zend_bool jit, zend_auto_global_callback auto_global_callback) /* {{{ */
    1660             : {
    1661             :         zend_auto_global auto_global;
    1662             :         int retval;
    1663             : 
    1664      211536 :         auto_global.name = zend_new_interned_string(name);
    1665      211536 :         auto_global.auto_global_callback = auto_global_callback;
    1666      211536 :         auto_global.jit = jit;
    1667             : 
    1668      423072 :         retval = zend_hash_add_mem(CG(auto_globals), auto_global.name, &auto_global, sizeof(zend_auto_global)) != NULL ? SUCCESS : FAILURE;
    1669             : 
    1670             :         zend_string_release(name);
    1671      211536 :         return retval;
    1672             : }
    1673             : /* }}} */
    1674             : 
    1675       23458 : ZEND_API void zend_activate_auto_globals(void) /* {{{ */
    1676             : {
    1677             :         zend_auto_global *auto_global;
    1678             : 
    1679      445702 :         ZEND_HASH_FOREACH_PTR(CG(auto_globals), auto_global) {
    1680      211122 :                 if (auto_global->jit) {
    1681       93826 :                         auto_global->armed = 1;
    1682      117296 :                 } else if (auto_global->auto_global_callback) {
    1683       93838 :                         auto_global->armed = auto_global->auto_global_callback(auto_global->name);
    1684             :                 } else {
    1685       23458 :                         auto_global->armed = 0;
    1686             :                 }
    1687             :         } ZEND_HASH_FOREACH_END();
    1688       23458 : }
    1689             : /* }}} */
    1690             : 
    1691     5579874 : int zendlex(zend_parser_stack_elem *elem) /* {{{ */
    1692             : {
    1693             :         zval zv;
    1694             :         int retval;
    1695             : 
    1696     5579874 :         if (CG(increment_lineno)) {
    1697       29839 :                 CG(zend_lineno)++;
    1698       29839 :                 CG(increment_lineno) = 0;
    1699             :         }
    1700             : 
    1701             : again:
    1702     8117585 :         ZVAL_UNDEF(&zv);
    1703     8117585 :         retval = lex_scan(&zv);
    1704     8117585 :         if (EG(exception)) {
    1705          14 :                 return T_ERROR;
    1706             :         }
    1707             : 
    1708     8117571 :         switch (retval) {
    1709             :                 case T_COMMENT:
    1710             :                 case T_DOC_COMMENT:
    1711             :                 case T_OPEN_TAG:
    1712             :                 case T_WHITESPACE:
    1713     2537711 :                         goto again;
    1714             : 
    1715             :                 case T_CLOSE_TAG:
    1716       31175 :                         if (LANG_SCNG(yy_text)[LANG_SCNG(yy_leng)-1] != '>') {
    1717       28302 :                                 CG(increment_lineno) = 1;
    1718             :                         }
    1719       31175 :                         retval = ';'; /* implicit ; */
    1720       31175 :                         break;
    1721             :                 case T_OPEN_TAG_WITH_ECHO:
    1722           3 :                         retval = T_ECHO;
    1723             :                         break;
    1724             :         }
    1725     5579860 :         if (Z_TYPE(zv) != IS_UNDEF) {
    1726     1961560 :                 elem->ast = zend_ast_create_zval(&zv);
    1727             :         }
    1728             : 
    1729     5579860 :         return retval;
    1730             : }
    1731             : /* }}} */
    1732             : 
    1733     4544391 : ZEND_API void zend_initialize_class_data(zend_class_entry *ce, zend_bool nullify_handlers) /* {{{ */
    1734             : {
    1735     4544391 :         zend_bool persistent_hashes = (ce->type == ZEND_INTERNAL_CLASS) ? 1 : 0;
    1736             : 
    1737     4544391 :         ce->refcount = 1;
    1738     4544391 :         ce->ce_flags = ZEND_ACC_CONSTANTS_UPDATED;
    1739             : 
    1740     4544391 :         if (CG(compiler_options) & ZEND_COMPILE_GUARDS) {
    1741           0 :                 ce->ce_flags |= ZEND_ACC_USE_GUARDS;
    1742             :         }
    1743             : 
    1744     4544391 :         ce->default_properties_table = NULL;
    1745     4544391 :         ce->default_static_members_table = NULL;
    1746     4544391 :         zend_hash_init_ex(&ce->properties_info, 8, NULL, (persistent_hashes ? zend_destroy_property_info_internal : NULL), persistent_hashes, 0);
    1747     4544391 :         zend_hash_init_ex(&ce->constants_table, 8, NULL, (persistent_hashes ? zend_destroy_class_constant_internal : NULL), persistent_hashes, 0);
    1748     4544391 :         zend_hash_init_ex(&ce->function_table, 8, NULL, ZEND_FUNCTION_DTOR, persistent_hashes, 0);
    1749             : 
    1750     4544391 :         if (ce->type == ZEND_INTERNAL_CLASS) {
    1751             : #ifdef ZTS
    1752             :                 int n = zend_hash_num_elements(CG(class_table));
    1753             : 
    1754             :                 if (CG(static_members_table) && n >= CG(last_static_member)) {
    1755             :                         /* Support for run-time declaration: dl() */
    1756             :                         CG(last_static_member) = n+1;
    1757             :                         CG(static_members_table) = realloc(CG(static_members_table), (n+1)*sizeof(zval*));
    1758             :                         CG(static_members_table)[n] = NULL;
    1759             :                 }
    1760             :                 ce->static_members_table = (zval*)(zend_intptr_t)n;
    1761             : #else
    1762     4536272 :                 ce->static_members_table = NULL;
    1763             : #endif
    1764             :         } else {
    1765        8119 :                 ce->static_members_table = ce->default_static_members_table;
    1766        8119 :                 ce->info.user.doc_comment = NULL;
    1767             :         }
    1768             : 
    1769     4544391 :         ce->default_properties_count = 0;
    1770     4544391 :         ce->default_static_members_count = 0;
    1771             : 
    1772     4544391 :         if (nullify_handlers) {
    1773        8119 :                 ce->constructor = NULL;
    1774        8119 :                 ce->destructor = NULL;
    1775        8119 :                 ce->clone = NULL;
    1776        8119 :                 ce->__get = NULL;
    1777        8119 :                 ce->__set = NULL;
    1778        8119 :                 ce->__unset = NULL;
    1779        8119 :                 ce->__isset = NULL;
    1780        8119 :                 ce->__call = NULL;
    1781        8119 :                 ce->__callstatic = NULL;
    1782        8119 :                 ce->__tostring = NULL;
    1783        8119 :                 ce->create_object = NULL;
    1784        8119 :                 ce->get_iterator = NULL;
    1785        8119 :                 ce->iterator_funcs.funcs = NULL;
    1786        8119 :                 ce->interface_gets_implemented = NULL;
    1787        8119 :                 ce->get_static_method = NULL;
    1788        8119 :                 ce->parent = NULL;
    1789        8119 :                 ce->num_interfaces = 0;
    1790        8119 :                 ce->interfaces = NULL;
    1791        8119 :                 ce->num_traits = 0;
    1792        8119 :                 ce->traits = NULL;
    1793        8119 :                 ce->trait_aliases = NULL;
    1794        8119 :                 ce->trait_precedences = NULL;
    1795        8119 :                 ce->serialize = NULL;
    1796        8119 :                 ce->unserialize = NULL;
    1797        8119 :                 ce->serialize_func = NULL;
    1798        8119 :                 ce->unserialize_func = NULL;
    1799        8119 :                 ce->__debugInfo = NULL;
    1800        8119 :                 if (ce->type == ZEND_INTERNAL_CLASS) {
    1801           0 :                         ce->info.internal.module = NULL;
    1802           0 :                         ce->info.internal.builtin_functions = NULL;
    1803             :                 }
    1804             :         }
    1805     4544391 : }
    1806             : /* }}} */
    1807             : 
    1808           0 : ZEND_API zend_string *zend_get_compiled_variable_name(const zend_op_array *op_array, uint32_t var) /* {{{ */
    1809             : {
    1810           0 :         return op_array->vars[EX_VAR_TO_NUM(var)];
    1811             : }
    1812             : /* }}} */
    1813             : 
    1814         452 : zend_ast *zend_ast_append_str(zend_ast *left_ast, zend_ast *right_ast) /* {{{ */
    1815             : {
    1816         452 :         zval *left_zv = zend_ast_get_zval(left_ast);
    1817         452 :         zend_string *left = Z_STR_P(left_zv);
    1818         452 :         zend_string *right = zend_ast_get_str(right_ast);
    1819             : 
    1820             :         zend_string *result;
    1821         452 :         size_t left_len = ZSTR_LEN(left);
    1822         452 :         size_t len = left_len + ZSTR_LEN(right) + 1; /* left\right */
    1823             : 
    1824         452 :         result = zend_string_extend(left, len, 0);
    1825         452 :         ZSTR_VAL(result)[left_len] = '\\';
    1826         452 :         memcpy(&ZSTR_VAL(result)[left_len + 1], ZSTR_VAL(right), ZSTR_LEN(right));
    1827         452 :         ZSTR_VAL(result)[len] = '\0';
    1828             :         zend_string_release(right);
    1829             : 
    1830         452 :         ZVAL_STR(left_zv, result);
    1831         452 :         return left_ast;
    1832             : }
    1833             : /* }}} */
    1834             : 
    1835      212527 : void zend_verify_namespace(void) /* {{{ */
    1836             : {
    1837      212527 :         if (FC(has_bracketed_namespaces) && !FC(in_namespace)) {
    1838           1 :                 zend_error_noreturn(E_COMPILE_ERROR, "No code may exist outside of namespace {}");
    1839             :         }
    1840      212526 : }
    1841             : /* }}} */
    1842             : 
    1843             : /* {{{ zend_dirname
    1844             :    Returns directory name component of path */
    1845       29610 : ZEND_API size_t zend_dirname(char *path, size_t len)
    1846             : {
    1847       29610 :         register char *end = path + len - 1;
    1848       29610 :         unsigned int len_adjust = 0;
    1849             : 
    1850             : #ifdef ZEND_WIN32
    1851             :         /* Note that on Win32 CWD is per drive (heritage from CP/M).
    1852             :          * This means dirname("c:foo") maps to "c:." or "c:" - which means CWD on C: drive.
    1853             :          */
    1854             :         if ((2 <= len) && isalpha((int)((unsigned char *)path)[0]) && (':' == path[1])) {
    1855             :                 /* Skip over the drive spec (if any) so as not to change */
    1856             :                 path += 2;
    1857             :                 len_adjust += 2;
    1858             :                 if (2 == len) {
    1859             :                         /* Return "c:" on Win32 for dirname("c:").
    1860             :                          * It would be more consistent to return "c:."
    1861             :                          * but that would require making the string *longer*.
    1862             :                          */
    1863             :                         return len;
    1864             :                 }
    1865             :         }
    1866             : #elif defined(NETWARE)
    1867             :         /*
    1868             :          * Find the first occurrence of : from the left
    1869             :          * move the path pointer to the position just after :
    1870             :          * increment the len_adjust to the length of path till colon character(inclusive)
    1871             :          * If there is no character beyond : simple return len
    1872             :          */
    1873             :         char *colonpos = NULL;
    1874             :         colonpos = strchr(path, ':');
    1875             :         if (colonpos != NULL) {
    1876             :                 len_adjust = ((colonpos - path) + 1);
    1877             :                 path += len_adjust;
    1878             :                 if (len_adjust == len) {
    1879             :                         return len;
    1880             :                 }
    1881             :         }
    1882             : #endif
    1883             : 
    1884       29610 :         if (len == 0) {
    1885             :                 /* Illegal use of this function */
    1886          36 :                 return 0;
    1887             :         }
    1888             : 
    1889             :         /* Strip trailing slashes */
    1890       59241 :         while (end >= path && IS_SLASH_P(end)) {
    1891          93 :                 end--;
    1892             :         }
    1893       29574 :         if (end < path) {
    1894             :                 /* The path only contained slashes */
    1895          13 :                 path[0] = DEFAULT_SLASH;
    1896          13 :                 path[1] = '\0';
    1897          13 :                 return 1 + len_adjust;
    1898             :         }
    1899             : 
    1900             :         /* Strip filename */
    1901      665824 :         while (end >= path && !IS_SLASH_P(end)) {
    1902      606702 :                 end--;
    1903             :         }
    1904       29561 :         if (end < path) {
    1905             :                 /* No slash found, therefore return '.' */
    1906             : #ifdef NETWARE
    1907             :                 if (len_adjust == 0) {
    1908             :                         path[0] = '.';
    1909             :                         path[1] = '\0';
    1910             :                         return 1; /* only one character */
    1911             :                 } else {
    1912             :                         path[0] = '\0';
    1913             :                         return len_adjust;
    1914             :                 }
    1915             : #else
    1916         174 :                 path[0] = '.';
    1917         174 :                 path[1] = '\0';
    1918         174 :                 return 1 + len_adjust;
    1919             : #endif
    1920             :         }
    1921             : 
    1922             :         /* Strip slashes which came before the file name */
    1923       88176 :         while (end >= path && IS_SLASH_P(end)) {
    1924       29402 :                 end--;
    1925             :         }
    1926       29387 :         if (end < path) {
    1927          26 :                 path[0] = DEFAULT_SLASH;
    1928          26 :                 path[1] = '\0';
    1929          26 :                 return 1 + len_adjust;
    1930             :         }
    1931       29361 :         *(end+1) = '\0';
    1932             : 
    1933       29361 :         return (size_t)(end + 1 - path) + len_adjust;
    1934             : }
    1935             : /* }}} */
    1936             : 
    1937      139138 : static void zend_adjust_for_fetch_type(zend_op *opline, uint32_t type) /* {{{ */
    1938             : {
    1939      139138 :         zend_uchar factor = (opline->opcode == ZEND_FETCH_STATIC_PROP_R) ? 1 : 3;
    1940             :         
    1941      139138 :         if (opline->opcode == ZEND_FETCH_THIS) {
    1942         367 :                 return;
    1943             :         }
    1944             : 
    1945      138771 :         switch (type & BP_VAR_MASK) {
    1946             :                 case BP_VAR_R:
    1947       60219 :                         return;
    1948             :                 case BP_VAR_W:
    1949       70139 :                         opline->opcode += 1 * factor;
    1950       70139 :                         return;
    1951             :                 case BP_VAR_RW:
    1952        1188 :                         opline->opcode += 2 * factor;
    1953        1188 :                         return;
    1954             :                 case BP_VAR_IS:
    1955        4696 :                         opline->opcode += 3 * factor;
    1956        4696 :                         return;
    1957             :                 case BP_VAR_FUNC_ARG:
    1958        2444 :                         opline->opcode += 4 * factor;
    1959        2444 :                         opline->extended_value |= type >> BP_VAR_SHIFT;
    1960        2444 :                         return;
    1961             :                 case BP_VAR_UNSET:
    1962          85 :                         opline->opcode += 5 * factor;
    1963          85 :                         return;
    1964             :                 EMPTY_SWITCH_DEFAULT_CASE()
    1965             :         }
    1966             : }
    1967             : /* }}} */
    1968             : 
    1969      723638 : static inline void zend_make_var_result(znode *result, zend_op *opline) /* {{{ */
    1970             : {
    1971      723638 :         opline->result_type = IS_VAR;
    1972      723638 :         opline->result.var = get_temporary_variable(CG(active_op_array));
    1973      723638 :         GET_NODE(result, opline->result);
    1974      723638 : }
    1975             : /* }}} */
    1976             : 
    1977      204111 : static inline void zend_make_tmp_result(znode *result, zend_op *opline) /* {{{ */
    1978             : {
    1979      204111 :         opline->result_type = IS_TMP_VAR;
    1980      204111 :         opline->result.var = get_temporary_variable(CG(active_op_array));
    1981      204111 :         GET_NODE(result, opline->result);
    1982      204111 : }
    1983             : /* }}} */
    1984             : 
    1985       30121 : static void zend_find_live_range(zend_op *opline, zend_uchar type, uint32_t var) /* {{{ */
    1986             : {
    1987       30121 :         zend_op *def = opline;
    1988             : 
    1989      166582 :         while (def != CG(active_op_array)->opcodes) {
    1990      136445 :                 def--;
    1991      136445 :                 if (def->result_type == type && def->result.var == var) {
    1992       86733 :                         if (def->opcode == ZEND_ADD_ARRAY_ELEMENT ||
    1993       30105 :                             def->opcode == ZEND_ROPE_ADD) {
    1994             :                             /* not a real definition */
    1995       26523 :                                 continue;
    1996      120420 :                         } else if (def->opcode == ZEND_JMPZ_EX ||
    1997       30105 :                                    def->opcode == ZEND_JMPNZ_EX ||
    1998       30105 :                                    def->opcode == ZEND_BOOL ||
    1999       30105 :                                    def->opcode == ZEND_BOOL_NOT) {
    2000             :                                 /* result IS_BOOL, it does't have to be destroyed */
    2001             :                                 break;
    2002      150525 :                         } else if (def->opcode == ZEND_DECLARE_CLASS ||
    2003       30105 :                                    def->opcode == ZEND_DECLARE_INHERITED_CLASS ||
    2004       30105 :                                    def->opcode == ZEND_DECLARE_INHERITED_CLASS_DELAYED ||
    2005       30105 :                                    def->opcode == ZEND_DECLARE_ANON_CLASS ||
    2006       30105 :                                    def->opcode == ZEND_DECLARE_ANON_INHERITED_CLASS) {
    2007             :                                 /* classes don't have to be destroyed */
    2008             :                                 break;
    2009       30105 :                         } else if (def->opcode == ZEND_FAST_CALL) {
    2010             :                                 /* fast_calls don't have to be destroyed */
    2011           0 :                                 break;
    2012       30105 :                         } else if (def->opcode == ZEND_NEW) {
    2013             :                                 /* Objects created via ZEND_NEW are only fully initialized
    2014             :                                  * after the DO_FCALL (constructor call) */
    2015       15445 :                                 def = CG(active_op_array)->opcodes + def->op2.opline_num - 1;
    2016       15445 :                                 if (def + 1 == opline) {
    2017       15289 :                                         break;
    2018             :                                 }
    2019             :                         }
    2020             : 
    2021       29632 :                 zend_end_live_range(CG(active_op_array),
    2022             :                                 zend_start_live_range_ex(CG(active_op_array),
    2023       14816 :                                         def + 1 - CG(active_op_array)->opcodes),
    2024       14816 :                                 opline - CG(active_op_array)->opcodes,
    2025             :                                 ZEND_LIVE_TMPVAR, var);
    2026       14816 :                     break;
    2027             :                 }
    2028             :         }
    2029       30121 : }
    2030             : /* }}} */
    2031             : 
    2032             : static zend_always_inline int zend_is_def_range(zend_op *opline, zend_uchar type, uint32_t var) /* {{{ */
    2033             : {
    2034             :         while (1) {
    2035      675424 :                 if (opline->result_type == type && opline->result.var == var) {
    2036     1234701 :                         return opline->opcode != ZEND_ADD_ARRAY_ELEMENT &&
    2037      615634 :                                 opline->opcode != ZEND_ROPE_ADD;
    2038       56357 :                 } else if (opline->opcode == ZEND_OP_DATA) {
    2039         220 :                         return (opline-1)->result_type == type &&
    2040          96 :                                 (opline-1)->result.var == var;
    2041      360475 :                 } else if (opline->opcode == ZEND_END_SILENCE ||
    2042       50707 :                            opline->opcode == ZEND_NOP ||
    2043       50707 :                        opline->opcode == ZEND_EXT_NOP ||
    2044       50707 :                            opline->opcode == ZEND_EXT_STMT ||
    2045       50707 :                            opline->opcode == ZEND_EXT_FCALL_BEGIN ||
    2046       50707 :                            opline->opcode == ZEND_EXT_FCALL_END ||
    2047       50707 :                            opline->opcode == ZEND_TICKS) {
    2048        5526 :                         opline--;
    2049             :                 } else {
    2050       50707 :                         return 0;
    2051             :                 }
    2052             :         }
    2053             : }
    2054             : /* }}} */
    2055             : 
    2056     2430372 : static void zend_check_live_ranges(zend_op *opline) /* {{{ */
    2057             : {
    2058     2961576 :         if ((opline->op1_type & (IS_VAR|IS_TMP_VAR)) &&
    2059      531204 :                 !zend_is_def_range(opline - 1, opline->op1_type, opline->op1.var)) {
    2060             : 
    2061       38696 :                 if (opline->opcode == ZEND_OP_DATA) {
    2062        7242 :                         if (!zend_is_def_range(opline - 2, opline->op1_type, opline->op1.var)) {
    2063        2072 :                                 zend_find_live_range(opline - 1, opline->op1_type, opline->op1.var);
    2064             :                         }
    2065      245160 :                 } else if (opline->opcode == ZEND_INIT_STATIC_METHOD_CALL ||
    2066       35074 :                            opline->opcode == ZEND_NEW ||
    2067       35074 :                            opline->opcode == ZEND_FETCH_CLASS_CONSTANT ||
    2068       35074 :                            opline->opcode == ZEND_ADD_INTERFACE ||
    2069       35020 :                            opline->opcode == ZEND_ADD_TRAIT ||
    2070       35020 :                            opline->opcode == ZEND_BIND_TRAITS ||
    2071       34823 :                            opline->opcode == ZEND_VERIFY_ABSTRACT_CLASS) {
    2072             :                         /* classes don't have to be destroyed */
    2073       34496 :                 } else if (opline->opcode == ZEND_FAST_RET) {
    2074             :                         /* fast_calls don't have to be destroyed */
    2075      247435 :                 } else if (opline->opcode == ZEND_CASE ||
    2076       34111 :                            opline->opcode == ZEND_FE_FETCH_R ||
    2077       34111 :                            opline->opcode == ZEND_FE_FETCH_RW ||
    2078       34111 :                                opline->opcode == ZEND_FE_FREE ||
    2079       22117 :                                opline->opcode == ZEND_ROPE_ADD ||
    2080       22117 :                                opline->opcode == ZEND_ROPE_END ||
    2081       22117 :                                opline->opcode == ZEND_END_SILENCE ||
    2082       14930 :                                opline->opcode == ZEND_FETCH_LIST ||
    2083       14674 :                                opline->opcode == ZEND_VERIFY_RETURN_TYPE ||
    2084       14651 :                                opline->opcode == ZEND_BIND_LEXICAL) {
    2085             :                         /* these opcodes are handled separately */
    2086             :                 } else {
    2087       14640 :                         zend_find_live_range(opline, opline->op1_type, opline->op1.var);
    2088             :                 }
    2089             :         }
    2090             : 
    2091     2565445 :         if ((opline->op2_type & (IS_VAR|IS_TMP_VAR)) &&
    2092      135073 :                 !zend_is_def_range(opline - 1, opline->op2_type, opline->op2.var)) {
    2093             : 
    2094       13409 :                 if (opline->opcode == ZEND_OP_DATA) {
    2095           0 :                         if (!zend_is_def_range(opline - 2, opline->op2_type, opline->op2.var)) {
    2096           0 :                                 zend_find_live_range(opline-1, opline->op2_type, opline->op2.var);
    2097             :                         }
    2098      120681 :                 } else if (opline->opcode == ZEND_FETCH_STATIC_PROP_R ||
    2099       13409 :                            opline->opcode == ZEND_FETCH_STATIC_PROP_W ||
    2100       13409 :                            opline->opcode == ZEND_FETCH_STATIC_PROP_RW ||
    2101       13409 :                            opline->opcode == ZEND_FETCH_STATIC_PROP_IS ||
    2102       13409 :                            opline->opcode == ZEND_FETCH_STATIC_PROP_FUNC_ARG ||
    2103       13409 :                            opline->opcode == ZEND_FETCH_STATIC_PROP_UNSET ||
    2104       13409 :                            opline->opcode == ZEND_UNSET_STATIC_PROP ||
    2105       13409 :                            opline->opcode == ZEND_ISSET_ISEMPTY_STATIC_PROP ||
    2106       13409 :                            opline->opcode == ZEND_INSTANCEOF) {
    2107             :                         /* classes don't have to be destroyed */
    2108             :                 } else {
    2109       13409 :                         zend_find_live_range(opline, opline->op2_type, opline->op2.var);
    2110             :                 }
    2111             :         }
    2112     2430372 : }
    2113             : /* }}} */
    2114             : 
    2115     2060435 : static zend_op *zend_emit_op(znode *result, zend_uchar opcode, znode *op1, znode *op2) /* {{{ */
    2116             : {
    2117     2060435 :         zend_op *opline = get_next_op(CG(active_op_array));
    2118     2060435 :         opline->opcode = opcode;
    2119             : 
    2120     2060435 :         if (op1 == NULL) {
    2121      806081 :                 SET_UNUSED(opline->op1);
    2122             :         } else {
    2123     1254354 :                 SET_NODE(opline->op1, op1);
    2124             :         }
    2125             : 
    2126     2060435 :         if (op2 == NULL) {
    2127     1519743 :                 SET_UNUSED(opline->op2);
    2128             :         } else {
    2129      540692 :                 SET_NODE(opline->op2, op2);
    2130             :         }
    2131             : 
    2132     2060435 :         zend_check_live_ranges(opline);
    2133             : 
    2134     2060435 :         if (result) {
    2135      556775 :                 zend_make_var_result(result, opline);
    2136             :         }
    2137     2060435 :         return opline;
    2138             : }
    2139             : /* }}} */
    2140             : 
    2141      199068 : static zend_op *zend_emit_op_tmp(znode *result, zend_uchar opcode, znode *op1, znode *op2) /* {{{ */
    2142             : {
    2143      199068 :         zend_op *opline = get_next_op(CG(active_op_array));
    2144      199068 :         opline->opcode = opcode;
    2145             : 
    2146      199068 :         if (op1 == NULL) {
    2147       13686 :                 SET_UNUSED(opline->op1);
    2148             :         } else {
    2149      185382 :                 SET_NODE(opline->op1, op1);
    2150             :         }
    2151             : 
    2152      199068 :         if (op2 == NULL) {
    2153      100502 :                 SET_UNUSED(opline->op2);
    2154             :         } else {
    2155       98566 :                 SET_NODE(opline->op2, op2);
    2156             :         }
    2157             : 
    2158      199068 :         zend_check_live_ranges(opline);
    2159             : 
    2160      199068 :         if (result) {
    2161      198827 :                 zend_make_tmp_result(result, opline);
    2162             :         }
    2163             : 
    2164      199068 :         return opline;
    2165             : }
    2166             : /* }}} */
    2167             : 
    2168          31 : static void zend_emit_tick(void) /* {{{ */
    2169             : {
    2170             :         zend_op *opline;
    2171             : 
    2172             :         /* This prevents a double TICK generated by the parser statement of "declare()" */
    2173          31 :         if (CG(active_op_array)->last && CG(active_op_array)->opcodes[CG(active_op_array)->last - 1].opcode == ZEND_TICKS) {
    2174           1 :                 return;
    2175             :         }
    2176             :         
    2177          30 :         opline = get_next_op(CG(active_op_array));
    2178             : 
    2179          30 :         opline->opcode = ZEND_TICKS;
    2180          30 :         SET_UNUSED(opline->op1);
    2181          30 :         SET_UNUSED(opline->op2);
    2182          30 :         opline->extended_value = FC(declarables).ticks;
    2183             : }
    2184             : /* }}} */
    2185             : 
    2186       11629 : static inline zend_op *zend_emit_op_data(znode *value) /* {{{ */
    2187             : {
    2188       11629 :         return zend_emit_op(NULL, ZEND_OP_DATA, value, NULL);
    2189             : }
    2190             : /* }}} */
    2191             : 
    2192       68970 : static inline uint32_t zend_emit_jump(uint32_t opnum_target) /* {{{ */
    2193             : {
    2194       68970 :         uint32_t opnum = get_next_op_number(CG(active_op_array));
    2195       68970 :         zend_op *opline = zend_emit_op(NULL, ZEND_JMP, NULL, NULL);
    2196       68970 :         opline->op1.opline_num = opnum_target;
    2197       68970 :         return opnum;
    2198             : }
    2199             : /* }}} */
    2200             : 
    2201      114777 : static inline uint32_t zend_emit_cond_jump(zend_uchar opcode, znode *cond, uint32_t opnum_target) /* {{{ */
    2202             : {
    2203      114777 :         uint32_t opnum = get_next_op_number(CG(active_op_array));
    2204      114777 :         zend_op *opline = zend_emit_op(NULL, opcode, cond, NULL);
    2205      114777 :         opline->op2.opline_num = opnum_target;
    2206      114777 :         return opnum;
    2207             : }
    2208             : /* }}} */
    2209             : 
    2210      181224 : static inline void zend_update_jump_target(uint32_t opnum_jump, uint32_t opnum_target) /* {{{ */
    2211             : {
    2212      181224 :         zend_op *opline = &CG(active_op_array)->opcodes[opnum_jump];
    2213      181224 :         switch (opline->opcode) {
    2214             :                 case ZEND_JMP:
    2215       57132 :                         opline->op1.opline_num = opnum_target;
    2216       57132 :                         break;
    2217             :                 case ZEND_JMPZ:
    2218             :                 case ZEND_JMPNZ:
    2219             :                 case ZEND_JMPZ_EX:
    2220             :                 case ZEND_JMPNZ_EX:
    2221             :                 case ZEND_JMP_SET:
    2222      124092 :                         opline->op2.opline_num = opnum_target;
    2223             :                         break;
    2224             :                 EMPTY_SWITCH_DEFAULT_CASE()
    2225             :         }
    2226      181224 : }
    2227             : /* }}} */
    2228             : 
    2229      179145 : static inline void zend_update_jump_target_to_next(uint32_t opnum_jump) /* {{{ */
    2230             : {
    2231      179145 :         zend_update_jump_target(opnum_jump, get_next_op_number(CG(active_op_array)));
    2232      179145 : }
    2233             : /* }}} */
    2234             : 
    2235      159151 : static inline zend_op *zend_delayed_emit_op(znode *result, zend_uchar opcode, znode *op1, znode *op2) /* {{{ */
    2236             : {
    2237             :         zend_op tmp_opline;
    2238      159151 :         init_op(&tmp_opline);
    2239      159151 :         tmp_opline.opcode = opcode;
    2240      159151 :         if (op1 == NULL) {
    2241           0 :                 SET_UNUSED(tmp_opline.op1);
    2242             :         } else {
    2243      159151 :                 SET_NODE(tmp_opline.op1, op1);
    2244             :         }
    2245      159151 :         if (op2 == NULL) {
    2246       17206 :                 SET_UNUSED(tmp_opline.op2);
    2247             :         } else {
    2248      141945 :                 SET_NODE(tmp_opline.op2, op2);
    2249             :         }
    2250      159151 :         if (result) {
    2251      158746 :                 zend_make_var_result(result, &tmp_opline);
    2252             :         }
    2253             : 
    2254      159151 :         zend_stack_push(&CG(delayed_oplines_stack), &tmp_opline);
    2255      159151 :         return zend_stack_top(&CG(delayed_oplines_stack));
    2256             : }
    2257             : /* }}} */
    2258             : 
    2259      292200 : static inline uint32_t zend_delayed_compile_begin(void) /* {{{ */
    2260             : {
    2261      292200 :         return zend_stack_count(&CG(delayed_oplines_stack));
    2262             : }
    2263             : /* }}} */
    2264             : 
    2265      292186 : static zend_op *zend_delayed_compile_end(uint32_t offset) /* {{{ */
    2266             : {
    2267      292186 :         zend_op *opline = NULL, *oplines = zend_stack_base(&CG(delayed_oplines_stack));
    2268      292186 :         uint32_t i, count = zend_stack_count(&CG(delayed_oplines_stack));
    2269             : 
    2270             :         ZEND_ASSERT(count >= offset);
    2271      451336 :         for (i = offset; i < count; ++i) {
    2272      159150 :                 opline = get_next_op(CG(active_op_array));
    2273      159150 :                 memcpy(opline, &oplines[i], sizeof(zend_op));
    2274      159150 :                 zend_check_live_ranges(opline);
    2275             :         }
    2276      292186 :         CG(delayed_oplines_stack).top = offset;
    2277      292186 :         return opline;
    2278             : }
    2279             : /* }}} */
    2280             : 
    2281         233 : static void zend_emit_return_type_check(
    2282             :                 znode *expr, zend_arg_info *return_info, zend_bool implicit) /* {{{ */
    2283             : {
    2284             :         /* `return ...;` is illegal in a void function (but `return;` isn't) */
    2285         233 :         if (return_info->type_hint == IS_VOID) {
    2286          10 :                 if (expr) {
    2287           4 :                         if (expr->op_type == IS_CONST && Z_TYPE(expr->u.constant) == IS_NULL) {
    2288           1 :                                 zend_error_noreturn(E_COMPILE_ERROR,
    2289             :                                         "A void function must not return a value "
    2290             :                                         "(did you mean \"return;\" instead of \"return null;\"?)");
    2291             :                         } else {
    2292           1 :                                 zend_error_noreturn(E_COMPILE_ERROR, "A void function must not return a value");
    2293             :                         }
    2294             :                 }
    2295             :                 /* we don't need run-time check */
    2296           8 :                 return;
    2297             :         }
    2298             : 
    2299         223 :         if (return_info->type_hint != IS_UNDEF) {
    2300             :                 zend_op *opline;
    2301             : 
    2302         223 :                 if (!expr && !implicit) {
    2303           2 :                         if (return_info->allow_null) {
    2304           1 :                                 zend_error_noreturn(E_COMPILE_ERROR,
    2305             :                                         "A function with return type must return a value "
    2306             :                                         "(did you mean \"return null;\" instead of \"return;\"?)");
    2307             :                         } else {
    2308           1 :                                 zend_error_noreturn(E_COMPILE_ERROR,
    2309             :                                         "A function with return type must return a value");
    2310             :                         }
    2311             :                 }
    2312             : 
    2313         221 :                 if (expr && expr->op_type == IS_CONST) {
    2314          62 :                         if ((return_info->type_hint == Z_TYPE(expr->u.constant))
    2315          13 :                          ||((return_info->type_hint == _IS_BOOL)
    2316           0 :                           && (Z_TYPE(expr->u.constant) == IS_FALSE
    2317           0 :                            || Z_TYPE(expr->u.constant) == IS_TRUE))
    2318             :                          || (return_info->allow_null
    2319          13 :                           && Z_TYPE(expr->u.constant) == IS_NULL)) {
    2320             :                                 /* we don't need run-time check */
    2321           5 :                                 return;
    2322             :                         }
    2323             :                 }
    2324             : 
    2325         216 :                 opline = zend_emit_op(NULL, ZEND_VERIFY_RETURN_TYPE, expr, NULL);
    2326         216 :                 if (expr && expr->op_type == IS_CONST) {
    2327          13 :                         opline->result_type = expr->op_type = IS_TMP_VAR;
    2328          13 :                         opline->result.var = expr->u.op.var = get_temporary_variable(CG(active_op_array));
    2329             :                 }
    2330         216 :                 if (return_info->class_name) {
    2331          89 :                         opline->op2.num = CG(active_op_array)->cache_size;
    2332          89 :                         CG(active_op_array)->cache_size += sizeof(void*);
    2333             :                 } else {
    2334         127 :                         opline->op2.num = -1;
    2335             :                 }
    2336             :         }
    2337             : }
    2338             : /* }}} */
    2339             : 
    2340       74050 : void zend_emit_final_return(int return_one) /* {{{ */
    2341             : {
    2342             :         znode zn;
    2343             :         zend_op *ret;
    2344       74050 :         zend_bool returns_reference = (CG(active_op_array)->fn_flags & ZEND_ACC_RETURN_REFERENCE) != 0;
    2345             : 
    2346      148250 :         if (CG(active_op_array)->fn_flags & ZEND_ACC_HAS_RETURN_TYPE
    2347       74200 :                         && !(CG(active_op_array)->fn_flags & ZEND_ACC_GENERATOR)) {
    2348         139 :                 zend_emit_return_type_check(NULL, CG(active_op_array)->arg_info - 1, 1);
    2349             :         }
    2350             : 
    2351       74050 :         zn.op_type = IS_CONST;
    2352       74050 :         if (return_one) {
    2353       32978 :                 ZVAL_LONG(&zn.u.constant, 1);
    2354             :         } else {
    2355       41072 :                 ZVAL_NULL(&zn.u.constant);
    2356             :         }
    2357             : 
    2358       74050 :         ret = zend_emit_op(NULL, returns_reference ? ZEND_RETURN_BY_REF : ZEND_RETURN, &zn, NULL);
    2359       74050 :         ret->extended_value = -1;
    2360       74050 : }
    2361             : /* }}} */
    2362             : 
    2363      629233 : static inline zend_bool zend_is_variable(zend_ast *ast) /* {{{ */
    2364             : {
    2365     2485900 :         return ast->kind == ZEND_AST_VAR || ast->kind == ZEND_AST_DIM
    2366      716059 :                 || ast->kind == ZEND_AST_PROP || ast->kind == ZEND_AST_STATIC_PROP
    2367      619769 :                 || ast->kind == ZEND_AST_CALL || ast->kind == ZEND_AST_METHOD_CALL
    2368      520839 :                 || ast->kind == ZEND_AST_STATIC_CALL;
    2369             : }
    2370             : /* }}} */
    2371             : 
    2372      441878 : static inline zend_bool zend_is_call(zend_ast *ast) /* {{{ */
    2373             : {
    2374     1226816 :         return ast->kind == ZEND_AST_CALL
    2375      441878 :                 || ast->kind == ZEND_AST_METHOD_CALL
    2376      784938 :                 || ast->kind == ZEND_AST_STATIC_CALL;
    2377             : }
    2378             : /* }}} */
    2379             : 
    2380          41 : static inline zend_bool zend_is_unticked_stmt(zend_ast *ast) /* {{{ */
    2381             : {
    2382         197 :         return ast->kind == ZEND_AST_STMT_LIST || ast->kind == ZEND_AST_LABEL
    2383          63 :                 || ast->kind == ZEND_AST_PROP_DECL || ast->kind == ZEND_AST_CLASS_CONST_DECL
    2384          93 :                 || ast->kind == ZEND_AST_USE_TRAIT || ast->kind == ZEND_AST_METHOD;
    2385             : }
    2386             : /* }}} */
    2387             : 
    2388       10359 : static inline zend_bool zend_can_write_to_variable(zend_ast *ast) /* {{{ */
    2389             : {
    2390       23313 :         while (ast->kind == ZEND_AST_DIM || ast->kind == ZEND_AST_PROP) {
    2391        2595 :                 ast = ast->child[0];
    2392             :         }
    2393             : 
    2394       10359 :         return zend_is_variable(ast);
    2395             : }
    2396             : /* }}} */
    2397             : 
    2398        5799 : static inline zend_bool zend_is_const_default_class_ref(zend_ast *name_ast) /* {{{ */
    2399             : {
    2400        5799 :         if (name_ast->kind != ZEND_AST_ZVAL) {
    2401           0 :                 return 0;
    2402             :         }
    2403             : 
    2404        5799 :         return ZEND_FETCH_CLASS_DEFAULT == zend_get_class_fetch_type_ast(name_ast);
    2405             : }
    2406             : /* }}} */
    2407             : 
    2408      141240 : static inline void zend_handle_numeric_op(znode *node) /* {{{ */
    2409             : {
    2410      273445 :         if (node->op_type == IS_CONST && Z_TYPE(node->u.constant) == IS_STRING) {
    2411             :                 zend_ulong index;
    2412             : 
    2413      103320 :                 if (ZEND_HANDLE_NUMERIC(Z_STR(node->u.constant), index)) {
    2414          65 :                         zval_ptr_dtor(&node->u.constant);
    2415          65 :                         ZVAL_LONG(&node->u.constant, index);
    2416             :                 }
    2417             :         }
    2418      141240 : }
    2419             : /* }}} */
    2420             : 
    2421       11842 : static inline void zend_set_class_name_op1(zend_op *opline, znode *class_node) /* {{{ */
    2422             : {
    2423       11842 :         if (class_node->op_type == IS_CONST) {
    2424        6286 :                 opline->op1_type = IS_CONST;
    2425        6286 :                 opline->op1.constant = zend_add_class_name_literal(
    2426             :                         CG(active_op_array), Z_STR(class_node->u.constant));
    2427             :         } else {
    2428        5556 :                 SET_NODE(opline->op1, class_node);
    2429             :         }
    2430       11842 : }
    2431             : /* }}} */
    2432             : 
    2433        2506 : static zend_op *zend_compile_class_ref(znode *result, zend_ast *name_ast, int throw_exception) /* {{{ */
    2434             : {
    2435             :         zend_op *opline;
    2436             :         znode name_node;
    2437        2506 :         zend_compile_expr(&name_node, name_ast);
    2438             : 
    2439        2506 :         if (name_node.op_type == IS_CONST) {
    2440             :                 zend_string *name;
    2441             :                 uint32_t fetch_type;
    2442             : 
    2443        2506 :                 if (Z_TYPE(name_node.u.constant) != IS_STRING) {
    2444           0 :                         zend_error_noreturn(E_COMPILE_ERROR, "Illegal class name");
    2445             :                 }
    2446             : 
    2447        2506 :                 name = Z_STR(name_node.u.constant);
    2448        2506 :                 fetch_type = zend_get_class_fetch_type(name);
    2449             : 
    2450        2506 :                 opline = zend_emit_op(result, ZEND_FETCH_CLASS, NULL, NULL);
    2451        2506 :                 opline->extended_value = fetch_type | (throw_exception ? ZEND_FETCH_CLASS_EXCEPTION : 0);
    2452             : 
    2453        2506 :                 if (fetch_type == ZEND_FETCH_CLASS_DEFAULT) {
    2454        2506 :                         uint32_t type = name_ast->kind == ZEND_AST_ZVAL ? name_ast->attr : ZEND_NAME_FQ;
    2455        2506 :                         opline->op2_type = IS_CONST;
    2456        2506 :                         opline->op2.constant = zend_add_class_name_literal(CG(active_op_array),
    2457             :                                 zend_resolve_class_name(name, type));
    2458             :                 } else {
    2459           0 :                         zend_ensure_valid_class_fetch_type(fetch_type);
    2460             :                 }
    2461             : 
    2462             :                 zend_string_release(name);
    2463             :         } else {
    2464           0 :                 opline = zend_emit_op(result, ZEND_FETCH_CLASS, NULL, &name_node);
    2465           0 :                 opline->extended_value = ZEND_FETCH_CLASS_DEFAULT | (throw_exception ? ZEND_FETCH_CLASS_EXCEPTION : 0);
    2466             :         }
    2467             : 
    2468        2506 :         return opline;
    2469             : }
    2470             : /* }}} */
    2471             : 
    2472       28134 : static void zend_compile_class_ref_ex(znode *result, zend_ast *name_ast, uint32_t fetch_flags) /* {{{ */
    2473             : {
    2474             :         uint32_t fetch_type;
    2475             : 
    2476       28134 :         if (name_ast->kind != ZEND_AST_ZVAL) {
    2477             :                 znode name_node;
    2478             : 
    2479        1444 :                 zend_compile_expr(&name_node, name_ast);
    2480             : 
    2481        1444 :                 if (name_node.op_type == IS_CONST) {
    2482             :                         zend_string *name;
    2483             : 
    2484           2 :                         if (Z_TYPE(name_node.u.constant) != IS_STRING) {
    2485           1 :                                 zend_error_noreturn(E_COMPILE_ERROR, "Illegal class name");
    2486             :                         }
    2487             : 
    2488           1 :                         name = Z_STR(name_node.u.constant);
    2489           1 :                         fetch_type = zend_get_class_fetch_type(name);
    2490             : 
    2491           1 :                         if (fetch_type == ZEND_FETCH_CLASS_DEFAULT) {
    2492           1 :                                 result->op_type = IS_CONST;
    2493           1 :                                 ZVAL_STR(&result->u.constant, zend_resolve_class_name(name, ZEND_NAME_FQ));
    2494             :                         } else {
    2495           0 :                                 zend_ensure_valid_class_fetch_type(fetch_type);
    2496           0 :                                 result->op_type = IS_UNUSED;
    2497           0 :                                 result->u.op.num = fetch_type | fetch_flags;
    2498             :                         }
    2499             : 
    2500             :                         zend_string_release(name);
    2501             :                 } else {
    2502        1442 :                         zend_op *opline = zend_emit_op(result, ZEND_FETCH_CLASS, NULL, &name_node);
    2503        1442 :                         opline->extended_value = ZEND_FETCH_CLASS_DEFAULT | fetch_flags;
    2504             :                 }
    2505        1443 :                 return;
    2506             :         }
    2507             : 
    2508             :         /* Fully qualified names are always default refs */
    2509       26690 :         if (name_ast->attr == ZEND_NAME_FQ) {
    2510         110 :                 result->op_type = IS_CONST;
    2511         110 :                 ZVAL_STR(&result->u.constant, zend_resolve_class_name_ast(name_ast));
    2512         110 :                 return;
    2513             :         }
    2514             : 
    2515       26580 :         fetch_type = zend_get_class_fetch_type(zend_ast_get_str(name_ast));
    2516       26580 :         if (ZEND_FETCH_CLASS_DEFAULT == fetch_type) {
    2517       20511 :                 result->op_type = IS_CONST;
    2518       20511 :                 ZVAL_STR(&result->u.constant, zend_resolve_class_name_ast(name_ast));
    2519             :         } else {
    2520        6069 :                 zend_ensure_valid_class_fetch_type(fetch_type);
    2521        6068 :                 result->op_type = IS_UNUSED;
    2522        6068 :                 result->u.op.num = fetch_type | fetch_flags;
    2523             :         }
    2524             : }
    2525             : /* }}} */
    2526             : 
    2527      696648 : static int zend_try_compile_cv(znode *result, zend_ast *ast) /* {{{ */
    2528             : {
    2529      696648 :         zend_ast *name_ast = ast->child[0];
    2530      696648 :         if (name_ast->kind == ZEND_AST_ZVAL) {
    2531      696439 :                 zend_string *name = zval_get_string(zend_ast_get_zval(name_ast));
    2532             : 
    2533      696439 :                 if (zend_is_auto_global(name)) {
    2534             :                         zend_string_release(name);
    2535       17316 :                         return FAILURE;
    2536             :                 }
    2537             : 
    2538      679123 :                 result->op_type = IS_CV;
    2539      679123 :                 result->u.op.var = lookup_cv(CG(active_op_array), name);
    2540             : 
    2541             :                 /* lookup_cv may be using another zend_string instance  */
    2542      679123 :                 name = CG(active_op_array)->vars[EX_VAR_TO_NUM(result->u.op.var)];
    2543             : 
    2544      679123 :                 return SUCCESS;
    2545             :         }
    2546             : 
    2547         209 :         return FAILURE;
    2548             : }
    2549             : /* }}} */
    2550             : 
    2551       19023 : static zend_op *zend_compile_simple_var_no_cv(znode *result, zend_ast *ast, uint32_t type, int delayed) /* {{{ */
    2552             : {
    2553       19023 :         zend_ast *name_ast = ast->child[0];
    2554             :         znode name_node;
    2555             :         zend_op *opline;
    2556             : 
    2557       19023 :         zend_compile_expr(&name_node, name_ast);
    2558       19023 :         if (name_node.op_type == IS_CONST) {
    2559       18820 :                 convert_to_string(&name_node.u.constant);
    2560             :         }
    2561             : 
    2562       19023 :         if (delayed) {
    2563       16972 :                 opline = zend_delayed_emit_op(result, ZEND_FETCH_R, &name_node, NULL);
    2564             :         } else {
    2565        2051 :                 opline = zend_emit_op(result, ZEND_FETCH_R, &name_node, NULL);
    2566             :         }
    2567             : 
    2568       55159 :         if (name_node.op_type == IS_CONST && 
    2569       18820 :             zend_is_auto_global(Z_STR(name_node.u.constant))) {
    2570             : 
    2571       17316 :                 opline->extended_value = ZEND_FETCH_GLOBAL;
    2572             :         } else {
    2573        1707 :                 opline->extended_value = ZEND_FETCH_LOCAL;
    2574             :         }
    2575             : 
    2576       19023 :         return opline;
    2577             : }
    2578             : /* }}} */
    2579             : 
    2580      910982 : static zend_bool is_this_fetch(zend_ast *ast) /* {{{ */
    2581             : {
    2582      910982 :         if (ast->kind == ZEND_AST_VAR && ast->child[0]->kind == ZEND_AST_ZVAL) {
    2583     1792090 :                 zval *name = zend_ast_get_zval(ast->child[0]);
    2584      896045 :                 return Z_TYPE_P(name) == IS_STRING && zend_string_equals_literal(Z_STR_P(name), "this");
    2585             :         }
    2586             : 
    2587       14937 :         return 0;
    2588             : }
    2589             : /* }}} */
    2590             : 
    2591      674000 : static void zend_compile_simple_var(znode *result, zend_ast *ast, uint32_t type, int delayed) /* {{{ */
    2592             : {
    2593             :         zend_op *opline;
    2594             : 
    2595      674000 :         if (is_this_fetch(ast)) {
    2596         367 :                 opline = zend_emit_op(result, ZEND_FETCH_THIS, NULL, NULL);
    2597         367 :                 zend_adjust_for_fetch_type(opline, type);
    2598      673633 :         } else if (zend_try_compile_cv(result, ast) == FAILURE) {
    2599       17492 :                 zend_op *opline = zend_compile_simple_var_no_cv(result, ast, type, delayed);
    2600       17492 :                 zend_adjust_for_fetch_type(opline, type);
    2601             :         }
    2602      674000 : }
    2603             : /* }}} */
    2604             : 
    2605      138506 : static void zend_separate_if_call_and_write(znode *node, zend_ast *ast, uint32_t type) /* {{{ */
    2606             : {
    2607      138506 :         if (type != BP_VAR_R && type != BP_VAR_IS && zend_is_call(ast)) {
    2608          57 :                 if (node->op_type == IS_VAR) {
    2609          56 :                         zend_op *opline = zend_emit_op(NULL, ZEND_SEPARATE, node, NULL);
    2610          56 :                         opline->result_type = IS_VAR;
    2611          56 :                         opline->result.var = opline->op1.var;
    2612             :                 } else {
    2613           1 :                         zend_error_noreturn(E_COMPILE_ERROR, "Cannot use result of built-in function in write context");
    2614             :                 }
    2615             :         }
    2616      138505 : }
    2617             : /* }}} */
    2618             : 
    2619             : void zend_delayed_compile_var(znode *result, zend_ast *ast, uint32_t type);
    2620             : void zend_compile_assign(znode *result, zend_ast *ast);
    2621             : static void zend_compile_list_assign(znode *result, zend_ast *ast, znode *expr_node, zend_bool old_style);
    2622             : 
    2623        5753 : static inline void zend_emit_assign_znode(zend_ast *var_ast, znode *value_node) /* {{{ */
    2624             : {
    2625             :         znode dummy_node;
    2626        5753 :         if (var_ast->kind == ZEND_AST_ARRAY) {
    2627          43 :                 zend_compile_list_assign(&dummy_node, var_ast, value_node, var_ast->attr);
    2628             :         } else {
    2629        5710 :                 zend_ast *assign_ast = zend_ast_create(ZEND_AST_ASSIGN, var_ast,
    2630        5710 :                         zend_ast_create_znode(value_node));
    2631        5710 :                 zend_compile_assign(&dummy_node, assign_ast);
    2632             :         }
    2633        5749 :         zend_do_free(&dummy_node);
    2634        5749 : }
    2635             : /* }}} */
    2636             : 
    2637      130960 : static zend_op *zend_delayed_compile_dim(znode *result, zend_ast *ast, uint32_t type) /* {{{ */
    2638             : {
    2639      130960 :         zend_ast *var_ast = ast->child[0];
    2640      130960 :         zend_ast *dim_ast = ast->child[1];
    2641             : 
    2642             :         znode var_node, dim_node;
    2643             : 
    2644      130960 :         zend_delayed_compile_var(&var_node, var_ast, type);
    2645      130958 :         zend_separate_if_call_and_write(&var_node, var_ast, type);
    2646             : 
    2647      130957 :         if (dim_ast == NULL) {
    2648         623 :                 if (type == BP_VAR_R || type == BP_VAR_IS) {
    2649           7 :                         zend_error_noreturn(E_COMPILE_ERROR, "Cannot use [] for reading");
    2650             :                 }
    2651         616 :                 if (type == BP_VAR_UNSET) {
    2652           1 :                         zend_error_noreturn(E_COMPILE_ERROR, "Cannot use [] for unsetting");
    2653             :                 }
    2654         615 :                 dim_node.op_type = IS_UNUSED;
    2655             :         } else {
    2656      130334 :                 zend_compile_expr(&dim_node, dim_ast);
    2657      130334 :                 zend_handle_numeric_op(&dim_node);
    2658             :         }
    2659             : 
    2660      130949 :         return zend_delayed_emit_op(result, ZEND_FETCH_DIM_R, &var_node, &dim_node);
    2661             : }
    2662             : /* }}} */
    2663             : 
    2664      116770 : static inline zend_op *zend_compile_dim_common(znode *result, zend_ast *ast, uint32_t type) /* {{{ */
    2665             : {
    2666      116770 :         uint32_t offset = zend_delayed_compile_begin();
    2667      116770 :         zend_delayed_compile_dim(result, ast, type);
    2668      116762 :         return zend_delayed_compile_end(offset);
    2669             : }
    2670             : /* }}} */
    2671             : 
    2672      108001 : void zend_compile_dim(znode *result, zend_ast *ast, uint32_t type) /* {{{ */
    2673             : {
    2674      108001 :         zend_op *opline = zend_compile_dim_common(result, ast, type);
    2675      107995 :         zend_adjust_for_fetch_type(opline, type);
    2676      107995 : }
    2677             : /* }}} */
    2678             : 
    2679       10996 : static zend_op *zend_delayed_compile_prop(znode *result, zend_ast *ast, uint32_t type) /* {{{ */
    2680             : {
    2681       10996 :         zend_ast *obj_ast = ast->child[0];
    2682       10996 :         zend_ast *prop_ast = ast->child[1];
    2683             : 
    2684             :         znode obj_node, prop_node;
    2685             :         zend_op *opline;
    2686             : 
    2687       10996 :         if (is_this_fetch(obj_ast)) {
    2688        3560 :                 obj_node.op_type = IS_UNUSED;
    2689             :         } else {
    2690        7436 :                 zend_delayed_compile_var(&obj_node, obj_ast, type);
    2691        7436 :                 zend_separate_if_call_and_write(&obj_node, obj_ast, type);
    2692             :         }
    2693       10996 :         zend_compile_expr(&prop_node, prop_ast);
    2694             : 
    2695       10996 :         opline = zend_delayed_emit_op(result, ZEND_FETCH_OBJ_R, &obj_node, &prop_node);
    2696       10996 :         if (opline->op2_type == IS_CONST) {
    2697       21656 :                 convert_to_string(CT_CONSTANT(opline->op2));
    2698       10828 :                 zend_alloc_polymorphic_cache_slot(opline->op2.constant);
    2699             :         }
    2700             : 
    2701       10996 :         return opline;
    2702             : }
    2703             : /* }}} */
    2704             : 
    2705        7470 : static zend_op *zend_compile_prop_common(znode *result, zend_ast *ast, uint32_t type) /* {{{ */
    2706             : {
    2707        7470 :         uint32_t offset = zend_delayed_compile_begin();
    2708        7470 :         zend_delayed_compile_prop(result, ast, type);
    2709        7470 :         return zend_delayed_compile_end(offset);
    2710             : }
    2711             : /* }}} */
    2712             : 
    2713        6538 : void zend_compile_prop(znode *result, zend_ast *ast, uint32_t type) /* {{{ */
    2714             : {
    2715        6538 :         zend_op *opline = zend_compile_prop_common(result, ast, type);
    2716        6538 :         zend_adjust_for_fetch_type(opline, type);
    2717        6538 : }
    2718             : /* }}} */
    2719             : 
    2720         801 : zend_op *zend_compile_static_prop_common(znode *result, zend_ast *ast, uint32_t type, int delayed) /* {{{ */
    2721             : {
    2722         801 :         zend_ast *class_ast = ast->child[0];
    2723         801 :         zend_ast *prop_ast = ast->child[1];
    2724             : 
    2725             :         znode class_node, prop_node;
    2726             :         zend_op *opline;
    2727             : 
    2728         801 :         zend_compile_class_ref_ex(&class_node, class_ast, ZEND_FETCH_CLASS_EXCEPTION);
    2729             : 
    2730         800 :         zend_compile_expr(&prop_node, prop_ast);
    2731             : 
    2732         800 :         if (delayed) {
    2733         234 :                 opline = zend_delayed_emit_op(result, ZEND_FETCH_STATIC_PROP_R, &prop_node, NULL);
    2734             :         } else {
    2735         566 :                 opline = zend_emit_op(result, ZEND_FETCH_STATIC_PROP_R, &prop_node, NULL);
    2736             :         }
    2737         800 :         if (opline->op1_type == IS_CONST) {
    2738        1582 :                 convert_to_string(CT_CONSTANT(opline->op1));
    2739         791 :                 zend_alloc_polymorphic_cache_slot(opline->op1.constant);
    2740             :         }
    2741         800 :         if (class_node.op_type == IS_CONST) {
    2742         323 :                 opline->op2_type = IS_CONST;
    2743         323 :                 opline->op2.constant = zend_add_class_name_literal(
    2744             :                         CG(active_op_array), Z_STR(class_node.u.constant));
    2745             :         } else {
    2746         477 :                 SET_NODE(opline->op2, &class_node);
    2747             :         }
    2748             : 
    2749         800 :         return opline;
    2750             : }
    2751             : /* }}} */
    2752             : 
    2753         663 : void zend_compile_static_prop(znode *result, zend_ast *ast, uint32_t type, int delayed) /* {{{ */
    2754             : {
    2755         663 :         zend_op *opline = zend_compile_static_prop_common(result, ast, type, delayed);
    2756         662 :         zend_adjust_for_fetch_type(opline, type);
    2757         662 : }
    2758             : /* }}} */
    2759             : 
    2760         513 : static void zend_verify_list_assign_target(zend_ast *var_ast, zend_bool old_style) /* {{{ */ {
    2761         513 :         if (var_ast->kind == ZEND_AST_ARRAY) {
    2762          33 :                 if (var_ast->attr == ZEND_ARRAY_SYNTAX_LONG) {
    2763           1 :                         zend_error_noreturn(E_COMPILE_ERROR, "Cannot assign to array(), use [] instead");
    2764             :                 }
    2765          32 :                 if (old_style != var_ast->attr) {
    2766           1 :                         zend_error_noreturn(E_COMPILE_ERROR, "Cannot mix [] and list()");
    2767             :                 }
    2768         480 :         } else if (!zend_can_write_to_variable(var_ast)) {
    2769           1 :                 zend_error_noreturn(E_COMPILE_ERROR, "Assignments can only happen to writable values");
    2770             :         }
    2771         510 : }
    2772             : /* }}} */
    2773             : 
    2774         206 : static void zend_compile_unkeyed_list_assign(zend_ast_list *list, znode *expr_node, zend_bool old_style) /* {{{ */
    2775             : {
    2776             :         uint32_t i;
    2777         206 :         zend_bool has_elems = 0;
    2778             : 
    2779         672 :         for (i = 0; i < list->children; ++i) {
    2780         472 :                 zend_ast *elem_ast = list->child[i];
    2781             :                 zend_ast *var_ast;
    2782             :                 znode fetch_result, dim_node;
    2783             : 
    2784         472 :                 if (elem_ast == NULL) {
    2785          31 :                         continue;
    2786             :                 }
    2787         441 :                 if (elem_ast->attr) {
    2788           1 :                         zend_error(E_COMPILE_ERROR, "[] and list() assignments cannot be by reference");
    2789             :                 }
    2790             : 
    2791         440 :                 var_ast = elem_ast->child[0];
    2792         440 :                 has_elems = 1;
    2793             : 
    2794         440 :                 dim_node.op_type = IS_CONST;
    2795         440 :                 ZVAL_LONG(&dim_node.u.constant, i);
    2796             : 
    2797         440 :                 if (expr_node->op_type == IS_CONST) {
    2798          38 :                         Z_TRY_ADDREF(expr_node->u.constant);
    2799             :                 }
    2800             : 
    2801         440 :                 if (elem_ast->child[1] != NULL) {
    2802           1 :                         zend_error(E_COMPILE_ERROR, "Cannot mix keyed and unkeyed array entries in assignments");
    2803             :                 }
    2804             : 
    2805         439 :                 zend_verify_list_assign_target(var_ast, old_style);
    2806             : 
    2807         436 :                 zend_emit_op(&fetch_result, ZEND_FETCH_LIST, expr_node, &dim_node);
    2808         436 :                 zend_emit_assign_znode(var_ast, &fetch_result);
    2809             :         }
    2810             : 
    2811         200 :         if (has_elems == 0) {
    2812           2 :                 zend_error_noreturn(E_COMPILE_ERROR, "Cannot use empty list");
    2813             :         }
    2814             : 
    2815         198 : }
    2816             : /* }}} */
    2817             : 
    2818          36 : static void zend_compile_keyed_list_assign(zend_ast_list *list, znode *expr_node, zend_bool old_style) /* {{{ */
    2819             : {
    2820             :         uint32_t i;
    2821             : 
    2822         110 :         for (i = 0; i < list->children; ++i) {
    2823          75 :                 zend_ast *pair_ast = list->child[i];
    2824          75 :                 zend_ast *var_ast = pair_ast->child[0];
    2825          75 :                 zend_ast *key_ast = pair_ast->child[1];
    2826             :                 znode fetch_result, dim_node;
    2827             : 
    2828          75 :                 if (pair_ast->attr) {
    2829           0 :                         zend_error(E_COMPILE_ERROR, "[] and list() assignments cannot be by reference");
    2830             :                 }
    2831             : 
    2832          75 :                 if (key_ast == NULL) {
    2833           1 :                         zend_error(E_COMPILE_ERROR, "Cannot mix keyed and unkeyed array entries in assignments");
    2834             :                 }
    2835             : 
    2836          74 :                 zend_compile_expr(&dim_node, key_ast);
    2837             : 
    2838          74 :                 if (expr_node->op_type == IS_CONST) {
    2839          14 :                         Z_TRY_ADDREF(expr_node->u.constant);
    2840             :                 }
    2841             : 
    2842          74 :                 if (var_ast == NULL) {
    2843           0 :                         zend_error(E_COMPILE_ERROR, "Cannot use empty array entries in keyed array");
    2844             :                 }
    2845             : 
    2846          74 :                 zend_verify_list_assign_target(var_ast, old_style);
    2847             : 
    2848          74 :                 zend_emit_op(&fetch_result, ZEND_FETCH_LIST, expr_node, &dim_node);
    2849          74 :                 zend_emit_assign_znode(var_ast, &fetch_result);
    2850             :         }
    2851          35 : }
    2852             : /* }}} */
    2853             : 
    2854         242 : static void zend_compile_list_assign(znode *result, zend_ast *ast, znode *expr_node, zend_bool old_style) /* {{{ */
    2855             : {
    2856         242 :         zend_ast_list *list = zend_ast_get_list(ast);
    2857             : 
    2858         277 :         if (list->children > 0 && list->child[0] != NULL && list->child[0]->child[1] != NULL /* has key */) {
    2859          36 :                 zend_compile_keyed_list_assign(list, expr_node, old_style);
    2860             :         } else {
    2861         206 :                 zend_compile_unkeyed_list_assign(list, expr_node, old_style);
    2862             :         }
    2863             : 
    2864         233 :         *result = *expr_node;
    2865         233 : }
    2866             : /* }}} */
    2867             : 
    2868      176737 : static void zend_ensure_writable_variable(const zend_ast *ast) /* {{{ */
    2869             : {
    2870      176737 :         if (ast->kind == ZEND_AST_CALL) {
    2871           3 :                 zend_error_noreturn(E_COMPILE_ERROR, "Can't use function return value in write context");
    2872             :         }
    2873      176734 :         if (ast->kind == ZEND_AST_METHOD_CALL || ast->kind == ZEND_AST_STATIC_CALL) {
    2874           1 :                 zend_error_noreturn(E_COMPILE_ERROR, "Can't use method return value in write context");
    2875             :         }
    2876      176733 : }
    2877             : /* }}} */
    2878             : 
    2879             : /* Detects $a... = $a pattern */
    2880        9397 : zend_bool zend_is_assign_to_self(zend_ast *var_ast, zend_ast *expr_ast) /* {{{ */
    2881             : {
    2882        9397 :         if (expr_ast->kind != ZEND_AST_VAR || expr_ast->child[0]->kind != ZEND_AST_ZVAL) {
    2883        7371 :                 return 0;
    2884             :         }
    2885             : 
    2886        6166 :         while (zend_is_variable(var_ast) && var_ast->kind != ZEND_AST_VAR) {
    2887        2114 :                 var_ast = var_ast->child[0];
    2888             :         }
    2889             : 
    2890        2026 :         if (var_ast->kind != ZEND_AST_VAR || var_ast->child[0]->kind != ZEND_AST_ZVAL) {
    2891           2 :                 return 0;
    2892             :         }
    2893             : 
    2894             :         {
    2895        4048 :                 zend_string *name1 = zval_get_string(zend_ast_get_zval(var_ast->child[0]));
    2896        4048 :                 zend_string *name2 = zval_get_string(zend_ast_get_zval(expr_ast->child[0]));
    2897        2024 :                 zend_bool result = zend_string_equals(name1, name2);
    2898             :                 zend_string_release(name1);
    2899             :                 zend_string_release(name2);
    2900        2024 :                 return result;
    2901             :         }
    2902             : }
    2903             : /* }}} */
    2904             : 
    2905             : /* Detects if list($a, $b, $c) contains variable with given name */
    2906          59 : zend_bool zend_list_has_assign_to(zend_ast *list_ast, zend_string *name) /* {{{ */
    2907             : {
    2908          59 :         zend_ast_list *list = zend_ast_get_list(list_ast);
    2909             :         uint32_t i;
    2910         181 :         for (i = 0; i < list->children; i++) {
    2911         133 :                 zend_ast *elem_ast = list->child[i];
    2912             :                 zend_ast *var_ast;
    2913             : 
    2914         133 :                 if (!elem_ast) {
    2915           5 :                         continue;
    2916             :                 }
    2917         128 :                 var_ast = elem_ast->child[0];
    2918             : 
    2919             :                 /* Recursively check nested list()s */
    2920         128 :                 if (var_ast->kind == ZEND_AST_ARRAY && zend_list_has_assign_to(var_ast, name)) {
    2921           4 :                         return 1;
    2922             :                 }
    2923             : 
    2924         124 :                 if (var_ast->kind == ZEND_AST_VAR && var_ast->child[0]->kind == ZEND_AST_ZVAL) {
    2925         226 :                         zend_string *var_name = zval_get_string(zend_ast_get_zval(var_ast->child[0]));
    2926         113 :                         zend_bool result = zend_string_equals(var_name, name);
    2927             :                         zend_string_release(var_name);
    2928         113 :                         if (result) {
    2929           7 :                                 return 1;
    2930             :                         }
    2931             :                 }
    2932             :         }
    2933             : 
    2934          48 :         return 0;
    2935             : }
    2936             : /* }}} */
    2937             : 
    2938             : /* Detects patterns like list($a, $b, $c) = $a */
    2939         199 : zend_bool zend_list_has_assign_to_self(zend_ast *list_ast, zend_ast *expr_ast) /* {{{ */
    2940             : {
    2941             :         /* Only check simple variables on the RHS, as only CVs cause issues with this. */
    2942         199 :         if (expr_ast->kind == ZEND_AST_VAR && expr_ast->child[0]->kind == ZEND_AST_ZVAL) {
    2943          88 :                 zend_string *name = zval_get_string(zend_ast_get_zval(expr_ast->child[0]));
    2944          44 :                 zend_bool result = zend_list_has_assign_to(list_ast, name);
    2945             :                 zend_string_release(name);
    2946          44 :                 return result;
    2947             :         }
    2948         155 :         return 0;
    2949             : }
    2950             : /* }}} */
    2951             : 
    2952      163524 : void zend_compile_assign(znode *result, zend_ast *ast) /* {{{ */
    2953             : {
    2954      163524 :         zend_ast *var_ast = ast->child[0];
    2955      163524 :         zend_ast *expr_ast = ast->child[1];
    2956             : 
    2957             :         znode var_node, expr_node;
    2958             :         zend_op *opline;
    2959             :         uint32_t offset;
    2960             : 
    2961      163524 :         if (is_this_fetch(var_ast)) {
    2962           4 :                 zend_error_noreturn(E_COMPILE_ERROR, "Cannot re-assign $this");
    2963             :         }
    2964             : 
    2965      163520 :         zend_ensure_writable_variable(var_ast);
    2966             : 
    2967      163518 :         switch (var_ast->kind) {
    2968             :                 case ZEND_AST_VAR:
    2969             :                 case ZEND_AST_STATIC_PROP:
    2970      151798 :                         offset = zend_delayed_compile_begin();
    2971      151798 :                         zend_delayed_compile_var(&var_node, var_ast, BP_VAR_W);
    2972      151798 :                         zend_compile_expr(&expr_node, expr_ast);
    2973      151794 :                         zend_delayed_compile_end(offset);
    2974      151794 :                         zend_emit_op(result, ZEND_ASSIGN, &var_node, &expr_node);
    2975      151794 :                         return;
    2976             :                 case ZEND_AST_DIM:
    2977        9399 :                         offset = zend_delayed_compile_begin();
    2978        9399 :                         zend_delayed_compile_dim(result, var_ast, BP_VAR_W);
    2979             : 
    2980        9431 :                         if (zend_is_assign_to_self(var_ast, expr_ast)
    2981        9416 :                          && !is_this_fetch(expr_ast)) {
    2982             :                                 /* $a[0] = $a should evaluate the right $a first */
    2983          15 :                                 zend_compile_simple_var_no_cv(&expr_node, expr_ast, BP_VAR_R, 0);
    2984             :                         } else {
    2985        9382 :                                 zend_compile_expr(&expr_node, expr_ast);
    2986             :                         }
    2987             : 
    2988        9397 :                         opline = zend_delayed_compile_end(offset);
    2989        9397 :                         opline->opcode = ZEND_ASSIGN_DIM;
    2990             : 
    2991        9397 :                         opline = zend_emit_op_data(&expr_node);
    2992        9397 :                         return;
    2993             :                 case ZEND_AST_PROP:
    2994        2122 :                         offset = zend_delayed_compile_begin();
    2995        2122 :                         zend_delayed_compile_prop(result, var_ast, BP_VAR_W);
    2996        2122 :                         zend_compile_expr(&expr_node, expr_ast);
    2997             : 
    2998        2122 :                         opline = zend_delayed_compile_end(offset);
    2999        2122 :                         opline->opcode = ZEND_ASSIGN_OBJ;
    3000             : 
    3001        2122 :                         zend_emit_op_data(&expr_node);
    3002        2122 :                         return;
    3003             :                 case ZEND_AST_ARRAY:
    3004         199 :                         if (zend_list_has_assign_to_self(var_ast, expr_ast)) {
    3005             :                                 /* list($a, $b) = $a should evaluate the right $a first */
    3006           7 :                                 zend_compile_simple_var_no_cv(&expr_node, expr_ast, BP_VAR_R, 0);
    3007             :                         } else {
    3008         192 :                                 zend_compile_expr(&expr_node, expr_ast);
    3009             :                         }
    3010             : 
    3011         199 :                         zend_compile_list_assign(result, var_ast, &expr_node, var_ast->attr);
    3012         192 :                         return;
    3013             :                 EMPTY_SWITCH_DEFAULT_CASE();
    3014             :         }
    3015             : }
    3016             : /* }}} */
    3017             : 
    3018         491 : void zend_compile_assign_ref(znode *result, zend_ast *ast) /* {{{ */
    3019             : {
    3020         491 :         zend_ast *target_ast = ast->child[0];
    3021         491 :         zend_ast *source_ast = ast->child[1];
    3022             : 
    3023             :         znode target_node, source_node;
    3024             :         zend_op *opline;
    3025             :         uint32_t offset;
    3026             : 
    3027         491 :         if (is_this_fetch(target_ast)) {
    3028           1 :                 zend_error_noreturn(E_COMPILE_ERROR, "Cannot re-assign $this");
    3029             :         }
    3030         490 :         zend_ensure_writable_variable(target_ast);
    3031             : 
    3032         490 :         offset = zend_delayed_compile_begin();
    3033         490 :         zend_delayed_compile_var(&target_node, target_ast, BP_VAR_W);
    3034         490 :         zend_compile_var(&source_node, source_ast, BP_VAR_W);
    3035             : 
    3036         984 :         if ((target_ast->kind != ZEND_AST_VAR
    3037         769 :           || target_ast->child[0]->kind != ZEND_AST_ZVAL)
    3038         215 :          && source_node.op_type != IS_CV) {
    3039             :                 /* Both LHS and RHS expressions may modify the same data structure,
    3040             :                  * and the modification during RHS evaluation may dangle the pointer
    3041             :                  * to the result of the LHS evaluation.
    3042             :                  * Use MAKE_REF instruction to replace direct pointer with REFERENCE.
    3043             :                  * See: Bug #71539
    3044             :                  */
    3045          92 :                 zend_emit_op(&source_node, ZEND_MAKE_REF, &source_node, NULL);
    3046             :         }
    3047             : 
    3048         490 :         zend_delayed_compile_end(offset);
    3049             : 
    3050         490 :         if (source_node.op_type != IS_VAR && zend_is_call(source_ast)) {
    3051           1 :                 zend_error_noreturn(E_COMPILE_ERROR, "Cannot use result of built-in function in write context");
    3052             :         }
    3053             : 
    3054         489 :         opline = zend_emit_op(result, ZEND_ASSIGN_REF, &target_node, &source_node);
    3055             : 
    3056         489 :         if (zend_is_call(source_ast)) {
    3057          47 :                 opline->extended_value = ZEND_RETURNS_FUNCTION;
    3058             :         }
    3059         489 : }
    3060             : /* }}} */
    3061             : 
    3062           3 : static inline void zend_emit_assign_ref_znode(zend_ast *var_ast, znode *value_node) /* {{{ */
    3063             : {
    3064           3 :         zend_ast *assign_ast = zend_ast_create(ZEND_AST_ASSIGN_REF, var_ast,
    3065           3 :                 zend_ast_create_znode(value_node));
    3066           3 :         zend_compile_assign_ref(NULL, assign_ast);
    3067           3 : }
    3068             : /* }}} */
    3069             : 
    3070        4151 : void zend_compile_compound_assign(znode *result, zend_ast *ast) /* {{{ */
    3071             : {
    3072        4151 :         zend_ast *var_ast = ast->child[0];
    3073        4151 :         zend_ast *expr_ast = ast->child[1];
    3074        4151 :         uint32_t opcode = ast->attr;
    3075             : 
    3076             :         znode var_node, expr_node;
    3077             :         zend_op *opline;
    3078             :         uint32_t offset;
    3079             : 
    3080        4151 :         zend_ensure_writable_variable(var_ast);
    3081             : 
    3082        4151 :         switch (var_ast->kind) {
    3083             :                 case ZEND_AST_VAR:
    3084             :                 case ZEND_AST_STATIC_PROP:
    3085        4041 :                         offset = zend_delayed_compile_begin();
    3086        4041 :                         zend_delayed_compile_var(&var_node, var_ast, BP_VAR_RW);
    3087        4041 :                         zend_compile_expr(&expr_node, expr_ast);
    3088        4041 :                         zend_delayed_compile_end(offset);
    3089        4041 :                         zend_emit_op(result, opcode, &var_node, &expr_node);
    3090        4041 :                         return;
    3091             :                 case ZEND_AST_DIM:
    3092          55 :                         offset = zend_delayed_compile_begin();
    3093          55 :                         zend_delayed_compile_dim(result, var_ast, BP_VAR_RW);
    3094          55 :                         zend_compile_expr(&expr_node, expr_ast);
    3095             : 
    3096          55 :                         opline = zend_delayed_compile_end(offset);
    3097          55 :                         opline->opcode = opcode;
    3098          55 :                         opline->extended_value = ZEND_ASSIGN_DIM;
    3099             : 
    3100          55 :                         opline = zend_emit_op_data(&expr_node);
    3101          55 :                         return;
    3102             :                 case ZEND_AST_PROP:
    3103          55 :                         offset = zend_delayed_compile_begin();
    3104          55 :                         zend_delayed_compile_prop(result, var_ast, BP_VAR_RW);
    3105          55 :                         zend_compile_expr(&expr_node, expr_ast);
    3106             : 
    3107          55 :                         opline = zend_delayed_compile_end(offset);
    3108          55 :                         opline->opcode = opcode;
    3109          55 :                         opline->extended_value = ZEND_ASSIGN_OBJ;
    3110             : 
    3111          55 :                         zend_emit_op_data(&expr_node);
    3112          55 :                         return;
    3113             :                 EMPTY_SWITCH_DEFAULT_CASE()
    3114             :         }
    3115             : }
    3116             : /* }}} */
    3117             : 
    3118      346389 : uint32_t zend_compile_args(zend_ast *ast, zend_function *fbc) /* {{{ */
    3119             : {
    3120      346389 :         zend_ast_list *args = zend_ast_get_list(ast);
    3121             :         uint32_t i;
    3122      346389 :         zend_bool uses_arg_unpack = 0;
    3123      346389 :         uint32_t arg_count = 0; /* number of arguments not including unpacks */
    3124             : 
    3125      935090 :         for (i = 0; i < args->children; ++i) {
    3126      588717 :                 zend_ast *arg = args->child[i];
    3127      588717 :                 uint32_t arg_num = i + 1;
    3128             : 
    3129             :                 znode arg_node;
    3130             :                 zend_op *opline;
    3131             :                 zend_uchar opcode;
    3132             : 
    3133      588717 :                 if (arg->kind == ZEND_AST_UNPACK) {
    3134          72 :                         uses_arg_unpack = 1;
    3135          72 :                         fbc = NULL;
    3136             : 
    3137          72 :                         zend_compile_expr(&arg_node, arg->child[0]);
    3138          72 :                         opline = zend_emit_op(NULL, ZEND_SEND_UNPACK, &arg_node, NULL);
    3139          72 :                         opline->op2.num = arg_count;
    3140          72 :                         opline->result.var = (uint32_t)(zend_intptr_t)ZEND_CALL_ARG(NULL, arg_count);
    3141          72 :                         continue;
    3142             :                 }
    3143             : 
    3144      588645 :                 if (uses_arg_unpack) {
    3145           1 :                         zend_error_noreturn(E_COMPILE_ERROR,
    3146             :                                 "Cannot use positional argument after argument unpacking");
    3147             :                 }
    3148             : 
    3149      588644 :                 arg_count++;
    3150      588644 :                 if (zend_is_variable(arg)) {
    3151      331948 :                         if (zend_is_call(arg)) {
    3152       50867 :                                 zend_compile_var(&arg_node, arg, BP_VAR_R);
    3153       50864 :                                 if (arg_node.op_type & (IS_CONST|IS_TMP_VAR)) {
    3154             :                                         /* Function call was converted into builtin instruction */
    3155        1752 :                                         opcode = ZEND_SEND_VAL;
    3156             :                                 } else {
    3157       49112 :                                         if (fbc) {
    3158       48131 :                                                 if (ARG_MUST_BE_SENT_BY_REF(fbc, arg_num)) {
    3159          20 :                                                         opcode = ZEND_SEND_VAR_NO_REF;
    3160       48111 :                                                 } else if (ARG_MAY_BE_SENT_BY_REF(fbc, arg_num)) {
    3161           2 :                                                         opcode = ZEND_SEND_VAL;
    3162             :                                                 } else {
    3163       48109 :                                                         opcode = ZEND_SEND_VAR;
    3164             :                                                 }
    3165             :                                         } else {
    3166         981 :                                                 opcode = ZEND_SEND_VAR_NO_REF_EX;
    3167             :                                         }
    3168             :                                 }
    3169      281081 :                         } else if (fbc) {
    3170      238634 :                                 if (ARG_SHOULD_BE_SENT_BY_REF(fbc, arg_num)) {
    3171       74947 :                                         zend_compile_var(&arg_node, arg, BP_VAR_W);
    3172       74947 :                                         opcode = ZEND_SEND_REF;
    3173             :                                 } else {
    3174      163687 :                                         zend_compile_var(&arg_node, arg, BP_VAR_R);
    3175      163686 :                                         opcode = ZEND_SEND_VAR;
    3176             :                                 }
    3177             :                         } else {
    3178       42447 :                                 zend_compile_var(&arg_node, arg,
    3179       42447 :                                         BP_VAR_FUNC_ARG | (arg_num << BP_VAR_SHIFT));
    3180       42447 :                                 opcode = ZEND_SEND_VAR_EX;
    3181             :                         }
    3182             :                 } else {
    3183      256696 :                         zend_compile_expr(&arg_node, arg);
    3184             :                         ZEND_ASSERT(arg_node.op_type != IS_CV);
    3185      256692 :                         if (arg_node.op_type == IS_VAR) {
    3186             :                                 /* pass ++$a or something similar */
    3187        2503 :                                 if (fbc) {
    3188        1682 :                                         if (ARG_MUST_BE_SENT_BY_REF(fbc, arg_num)) {
    3189           4 :                                                 opcode = ZEND_SEND_VAR_NO_REF;
    3190        1678 :                                         } else if (ARG_MAY_BE_SENT_BY_REF(fbc, arg_num)) {
    3191           0 :                                                 opcode = ZEND_SEND_VAL;
    3192             :                                         } else {
    3193        1678 :                                                 opcode = ZEND_SEND_VAR;
    3194             :                                         }
    3195             :                                 } else {
    3196         821 :                                         opcode = ZEND_SEND_VAR_NO_REF_EX;
    3197             :                                 }
    3198             :                         } else {
    3199      254189 :                                 if (fbc) {
    3200      213830 :                                         opcode = ZEND_SEND_VAL;
    3201      213830 :                                         if (ARG_MUST_BE_SENT_BY_REF(fbc, arg_num)) {
    3202           7 :                                                 zend_error_noreturn(E_COMPILE_ERROR, "Only variables can be passed by reference");
    3203             :                                         }
    3204             :                                 } else {
    3205       40359 :                                         opcode = ZEND_SEND_VAL_EX;
    3206             :                                 }
    3207             :                         }
    3208             :                 }
    3209             : 
    3210      588629 :                 opline = zend_emit_op(NULL, opcode, &arg_node, NULL);
    3211      588629 :                 opline->op2.opline_num = arg_num;
    3212      588629 :                 opline->result.var = (uint32_t)(zend_intptr_t)ZEND_CALL_ARG(NULL, arg_num);
    3213             :         }
    3214             : 
    3215      346373 :         return arg_count;
    3216             : }
    3217             : /* }}} */
    3218             : 
    3219      346373 : ZEND_API zend_uchar zend_get_call_op(const zend_op *init_op, zend_function *fbc) /* {{{ */
    3220             : {
    3221      346373 :         if (fbc) {
    3222      278248 :                 if (fbc->type == ZEND_INTERNAL_FUNCTION) {
    3223      266683 :                         if (init_op->opcode == ZEND_INIT_FCALL && !zend_execute_internal) {
    3224      264147 :                                 if (!(fbc->common.fn_flags & (ZEND_ACC_ABSTRACT|ZEND_ACC_DEPRECATED|ZEND_ACC_HAS_TYPE_HINTS|ZEND_ACC_RETURN_REFERENCE))) {
    3225      262803 :                                         return ZEND_DO_ICALL;
    3226             :                                 } else {
    3227        1344 :                                         return ZEND_DO_FCALL_BY_NAME;
    3228             :                                 }
    3229             :                         }
    3230             :                 } else {
    3231       11565 :                         if (zend_execute_ex == execute_ex && !(fbc->common.fn_flags & ZEND_ACC_ABSTRACT)) {
    3232       11550 :                                 return ZEND_DO_UCALL;
    3233             :                         }
    3234             :                 }
    3235      267117 :         } else if (zend_execute_ex == execute_ex &&
    3236       68069 :                    !zend_execute_internal &&
    3237       68069 :                    (init_op->opcode == ZEND_INIT_FCALL_BY_NAME ||
    3238       62854 :                     init_op->opcode == ZEND_INIT_NS_FCALL_BY_NAME)) {
    3239        5584 :                 return ZEND_DO_FCALL_BY_NAME;
    3240             :         }
    3241       65092 :         return ZEND_DO_FCALL;
    3242             : }
    3243             : /* }}} */
    3244             : 
    3245      346389 : void zend_compile_call_common(znode *result, zend_ast *args_ast, zend_function *fbc) /* {{{ */
    3246             : {
    3247             :         zend_op *opline;
    3248      346389 :         uint32_t opnum_init = get_next_op_number(CG(active_op_array)) - 1;
    3249             :         uint32_t arg_count;
    3250             :         uint32_t call_flags;
    3251             : 
    3252      346389 :         zend_do_extended_fcall_begin();
    3253             : 
    3254      346389 :         arg_count = zend_compile_args(args_ast, fbc);
    3255             : 
    3256      346373 :         opline = &CG(active_op_array)->opcodes[opnum_init];
    3257      346373 :         opline->extended_value = arg_count;
    3258             : 
    3259      346373 :         if (opline->opcode == ZEND_INIT_FCALL) {
    3260      272501 :                 opline->op1.num = zend_vm_calc_used_stack(arg_count, fbc);
    3261             :         }
    3262             : 
    3263      346373 :         call_flags = (opline->opcode == ZEND_NEW ? ZEND_CALL_CTOR : 0);
    3264      346373 :         opline = zend_emit_op(result, zend_get_call_op(opline, fbc), NULL, NULL);
    3265      346373 :         opline->op1.num = call_flags;
    3266             : 
    3267      346373 :         zend_do_extended_fcall_end();
    3268      346373 : }
    3269             : /* }}} */
    3270             : 
    3271      288585 : zend_bool zend_compile_function_name(znode *name_node, zend_ast *name_ast) /* {{{ */
    3272             : {
    3273      288585 :         zend_string *orig_name = zend_ast_get_str(name_ast);
    3274             :         zend_bool is_fully_qualified;
    3275             : 
    3276      288585 :         name_node->op_type = IS_CONST;
    3277      288585 :         ZVAL_STR(&name_node->u.constant, zend_resolve_function_name(
    3278             :                 orig_name, name_ast->attr, &is_fully_qualified));
    3279             : 
    3280      288585 :         return !is_fully_qualified && FC(current_namespace);
    3281             : }
    3282             : /* }}} */
    3283             : 
    3284         368 : void zend_compile_ns_call(znode *result, znode *name_node, zend_ast *args_ast) /* {{{ */
    3285             : {
    3286         368 :         zend_op *opline = get_next_op(CG(active_op_array));
    3287         368 :         opline->opcode = ZEND_INIT_NS_FCALL_BY_NAME;
    3288         368 :         SET_UNUSED(opline->op1);
    3289         368 :         opline->op2_type = IS_CONST;
    3290         368 :         opline->op2.constant = zend_add_ns_func_name_literal(
    3291             :                 CG(active_op_array), Z_STR(name_node->u.constant));
    3292         368 :         zend_alloc_cache_slot(opline->op2.constant);
    3293             : 
    3294         368 :         zend_compile_call_common(result, args_ast, NULL);
    3295         368 : }
    3296             : /* }}} */
    3297             : 
    3298        7438 : void zend_compile_dynamic_call(znode *result, znode *name_node, zend_ast *args_ast) /* {{{ */
    3299             : {
    3300       17909 :         if (name_node->op_type == IS_CONST && Z_TYPE(name_node->u.constant) == IS_STRING) {
    3301             :                 const char *colon;
    3302        5234 :                 zend_string *str = Z_STR(name_node->u.constant);
    3303       10470 :                 if ((colon = zend_memrchr(ZSTR_VAL(str), ':', ZSTR_LEN(str))) != NULL && colon > ZSTR_VAL(str) && *(colon - 1) == ':') {
    3304           4 :                         zend_string *class = zend_string_init(ZSTR_VAL(str), colon - ZSTR_VAL(str) - 1, 0);
    3305           4 :                         zend_string *method = zend_string_init(colon + 1, ZSTR_LEN(str) - (colon - ZSTR_VAL(str)) - 1, 0);
    3306           2 :                         zend_op *opline = get_next_op(CG(active_op_array));
    3307             : 
    3308           2 :                         opline->opcode = ZEND_INIT_STATIC_METHOD_CALL;
    3309           2 :                         opline->op1_type = IS_CONST;
    3310           2 :                         opline->op1.constant = zend_add_class_name_literal(CG(active_op_array), class);
    3311           2 :                         opline->op2_type = IS_CONST;
    3312           2 :                         opline->op2.constant = zend_add_func_name_literal(CG(active_op_array), method);
    3313           2 :                         zend_alloc_cache_slot(opline->op2.constant);
    3314           2 :                         zval_ptr_dtor(&name_node->u.constant);
    3315             :                 } else {
    3316        5232 :                         zend_op *opline = get_next_op(CG(active_op_array));
    3317             : 
    3318        5232 :                         opline->opcode = ZEND_INIT_FCALL_BY_NAME;
    3319        5232 :                         SET_UNUSED(opline->op1);
    3320        5232 :                         opline->op2_type = IS_CONST;
    3321        5232 :                         opline->op2.constant = zend_add_func_name_literal(CG(active_op_array), str);
    3322        5232 :                         zend_alloc_cache_slot(opline->op2.constant);
    3323             :                 }
    3324             :         } else {
    3325        2204 :                 zend_emit_op(NULL, ZEND_INIT_DYNAMIC_CALL, NULL, name_node);
    3326             :         }
    3327             : 
    3328        7438 :         zend_compile_call_common(result, args_ast, NULL);
    3329        7438 : }
    3330             : /* }}} */
    3331             : 
    3332         211 : static zend_bool zend_args_contain_unpack(zend_ast_list *args) /* {{{ */
    3333             : {
    3334             :         uint32_t i;
    3335         852 :         for (i = 0; i < args->children; ++i) {
    3336         641 :                 if (args->child[i]->kind == ZEND_AST_UNPACK) {
    3337           0 :                         return 1;
    3338             :                 }
    3339             :         }
    3340         211 :         return 0;
    3341             : }
    3342             : /* }}} */
    3343             : 
    3344        5184 : int zend_compile_func_strlen(znode *result, zend_ast_list *args) /* {{{ */
    3345             : {
    3346             :         znode arg_node;
    3347             : 
    3348       15542 :         if ((CG(compiler_options) & ZEND_COMPILE_NO_BUILTIN_STRLEN)
    3349       10358 :                 || args->children != 1 || args->child[0]->kind == ZEND_AST_UNPACK
    3350             :         ) {
    3351           8 :                 return FAILURE;
    3352             :         }
    3353             : 
    3354        5176 :         zend_compile_expr(&arg_node, args->child[0]);
    3355        5326 :         if (arg_node.op_type == IS_CONST && Z_TYPE(arg_node.u.constant) == IS_STRING) {
    3356          73 :                 result->op_type = IS_CONST;
    3357          73 :                 ZVAL_LONG(&result->u.constant, Z_STRLEN(arg_node.u.constant));
    3358             :                 zval_dtor(&arg_node.u.constant);
    3359             :         } else {
    3360        5103 :                 zend_emit_op_tmp(result, ZEND_STRLEN, &arg_node, NULL);
    3361             :         }
    3362        5176 :         return SUCCESS;
    3363             : }
    3364             : /* }}} */
    3365             : 
    3366        4356 : int zend_compile_func_typecheck(znode *result, zend_ast_list *args, uint32_t type) /* {{{ */
    3367             : {
    3368             :         znode arg_node;
    3369             :         zend_op *opline;
    3370             : 
    3371        4356 :         if (args->children != 1 || args->child[0]->kind == ZEND_AST_UNPACK) {
    3372          24 :                 return FAILURE;
    3373             :         }
    3374             : 
    3375        4332 :         zend_compile_expr(&arg_node, args->child[0]);
    3376        4332 :         opline = zend_emit_op_tmp(result, ZEND_TYPE_CHECK, &arg_node, NULL);
    3377        4332 :         opline->extended_value = type;
    3378        4332 :         return SUCCESS;
    3379             : }
    3380             : /* }}} */
    3381             : 
    3382         212 : int zend_compile_func_defined(znode *result, zend_ast_list *args) /* {{{ */
    3383             : {
    3384             :         zend_string *name;
    3385             :         zend_op *opline;
    3386             : 
    3387         212 :         if (args->children != 1 || args->child[0]->kind != ZEND_AST_ZVAL) {
    3388           1 :                 return FAILURE;
    3389             :         }
    3390             : 
    3391         422 :         name = zval_get_string(zend_ast_get_zval(args->child[0]));
    3392         633 :         if (zend_memrchr(ZSTR_VAL(name), '\\', ZSTR_LEN(name)) || zend_memrchr(ZSTR_VAL(name), ':', ZSTR_LEN(name))) {
    3393             :                 zend_string_release(name);
    3394           8 :                 return FAILURE;
    3395             :         }
    3396             : 
    3397         203 :         if (zend_try_ct_eval_const(&result->u.constant, name, 0)) {
    3398             :                 zend_string_release(name);
    3399         154 :                 zval_ptr_dtor(&result->u.constant);
    3400         154 :                 ZVAL_TRUE(&result->u.constant);
    3401         154 :                 result->op_type = IS_CONST;
    3402         154 :                 return SUCCESS;
    3403             :         }
    3404             : 
    3405          49 :         opline = zend_emit_op_tmp(result, ZEND_DEFINED, NULL, NULL);
    3406          49 :         opline->op1_type = IS_CONST;
    3407          49 :         LITERAL_STR(opline->op1, name);
    3408          49 :         zend_alloc_cache_slot(opline->op1.constant);
    3409             : 
    3410             :         /* Lowercase constant name in a separate literal */
    3411             :         {
    3412             :                 zval c;
    3413          49 :                 zend_string *lcname = zend_string_tolower(name);
    3414          49 :                 ZVAL_NEW_STR(&c, lcname);
    3415          49 :                 zend_add_literal(CG(active_op_array), &c);
    3416             :         }
    3417          49 :         return SUCCESS;
    3418             : }
    3419             : /* }}} */
    3420             : 
    3421         625 : int zend_compile_func_chr(znode *result, zend_ast_list *args) /* {{{ */
    3422             : {
    3423             : 
    3424        1759 :         if (args->children == 1 &&
    3425         621 :             args->child[0]->kind == ZEND_AST_ZVAL &&
    3426         513 :             Z_TYPE_P(zend_ast_get_zval(args->child[0])) == IS_LONG) {
    3427             : 
    3428        1026 :                 zend_long c = Z_LVAL_P(zend_ast_get_zval(args->child[0])) & 0xff;
    3429             : 
    3430         513 :                 result->op_type = IS_CONST;
    3431         513 :                 if (CG(one_char_string)[c]) {
    3432           0 :                         ZVAL_INTERNED_STR(&result->u.constant, CG(one_char_string)[c]);
    3433             :                 } else {
    3434        1026 :                         ZVAL_NEW_STR(&result->u.constant, zend_string_alloc(1, 0));
    3435         513 :                         Z_STRVAL_P(&result->u.constant)[0] = (char)c;
    3436         513 :                         Z_STRVAL_P(&result->u.constant)[1] = '\0';
    3437             :                 }
    3438         513 :                 return SUCCESS;
    3439             :         } else {
    3440         112 :                 return FAILURE;
    3441             :         }
    3442             : }
    3443             : /* }}} */
    3444             : 
    3445          68 : int zend_compile_func_ord(znode *result, zend_ast_list *args) /* {{{ */
    3446             : {
    3447         152 :         if (args->children == 1 &&
    3448          64 :             args->child[0]->kind == ZEND_AST_ZVAL &&
    3449          20 :             Z_TYPE_P(zend_ast_get_zval(args->child[0])) == IS_STRING) {
    3450             : 
    3451          17 :                 result->op_type = IS_CONST;
    3452          34 :                 ZVAL_LONG(&result->u.constant, (unsigned char)Z_STRVAL_P(zend_ast_get_zval(args->child[0]))[0]);
    3453          17 :                 return SUCCESS;
    3454             :         } else {
    3455          51 :                 return FAILURE;
    3456             :         }
    3457             : }
    3458             : /* }}} */
    3459             : 
    3460             : 
    3461         211 : static int zend_try_compile_ct_bound_init_user_func(zend_ast *name_ast, uint32_t num_args) /* {{{ */
    3462             : {
    3463             :         zend_string *name, *lcname;
    3464             :         zend_function *fbc;
    3465             :         zend_op *opline;
    3466             : 
    3467         284 :         if (name_ast->kind != ZEND_AST_ZVAL || Z_TYPE_P(zend_ast_get_zval(name_ast)) != IS_STRING) {
    3468         138 :                 return FAILURE;
    3469             :         }
    3470             : 
    3471          73 :         name = zend_ast_get_str(name_ast);
    3472          73 :         lcname = zend_string_tolower(name);
    3473             : 
    3474         146 :         fbc = zend_hash_find_ptr(CG(function_table), lcname);
    3475         226 :         if (!fbc
    3476          71 :          || (fbc->type == ZEND_INTERNAL_FUNCTION && (CG(compiler_options) & ZEND_COMPILE_IGNORE_INTERNAL_FUNCTIONS))
    3477          82 :          || (fbc->type == ZEND_USER_FUNCTION && (CG(compiler_options) & ZEND_COMPILE_IGNORE_USER_FUNCTIONS))
    3478             :         ) {
    3479             :                 zend_string_release(lcname);
    3480          22 :                 return FAILURE;
    3481             :         }
    3482             : 
    3483          51 :         opline = zend_emit_op(NULL, ZEND_INIT_FCALL, NULL, NULL);
    3484          51 :         opline->extended_value = num_args;
    3485          51 :         opline->op1.num = zend_vm_calc_used_stack(num_args, fbc);
    3486          51 :         opline->op2_type = IS_CONST;
    3487          51 :         LITERAL_STR(opline->op2, lcname);
    3488          51 :         zend_alloc_cache_slot(opline->op2.constant);
    3489             : 
    3490          51 :         return SUCCESS;
    3491             : }
    3492             : /* }}} */
    3493             : 
    3494         211 : static void zend_compile_init_user_func(zend_ast *name_ast, uint32_t num_args, zend_string *orig_func_name) /* {{{ */
    3495             : {
    3496             :         zend_op *opline;
    3497             :         znode name_node;
    3498             : 
    3499         211 :         if (zend_try_compile_ct_bound_init_user_func(name_ast, num_args) == SUCCESS) {
    3500          51 :                 return;
    3501             :         }
    3502             : 
    3503         160 :         zend_compile_expr(&name_node, name_ast);
    3504             : 
    3505         160 :         opline = zend_emit_op(NULL, ZEND_INIT_USER_CALL, NULL, &name_node);
    3506         160 :         opline->op1_type = IS_CONST;
    3507         320 :         LITERAL_STR(opline->op1, zend_string_copy(orig_func_name));
    3508         160 :         opline->extended_value = num_args;
    3509             : }
    3510             : /* }}} */
    3511             : 
    3512             : /* cufa = call_user_func_array */
    3513          73 : int zend_compile_func_cufa(znode *result, zend_ast_list *args, zend_string *lcname) /* {{{ */
    3514             : {
    3515             :         znode arg_node;
    3516             : 
    3517          73 :         if (args->children != 2 || zend_args_contain_unpack(args)) {
    3518           0 :                 return FAILURE;
    3519             :         }
    3520             : 
    3521          73 :         zend_compile_init_user_func(args->child[0], 0, lcname);
    3522          73 :         zend_compile_expr(&arg_node, args->child[1]);
    3523          73 :         zend_emit_op(NULL, ZEND_SEND_ARRAY, &arg_node, NULL);
    3524          73 :         zend_emit_op(result, ZEND_DO_FCALL, NULL, NULL);
    3525             : 
    3526          73 :         return SUCCESS;
    3527             : }
    3528             : /* }}} */
    3529             : 
    3530             : /* cuf = call_user_func */
    3531         138 : int zend_compile_func_cuf(znode *result, zend_ast_list *args, zend_string *lcname) /* {{{ */
    3532             : {
    3533             :         uint32_t i;
    3534             : 
    3535         138 :         if (args->children < 1 || zend_args_contain_unpack(args)) {
    3536           0 :                 return FAILURE;
    3537             :         }
    3538             : 
    3539         138 :         zend_compile_init_user_func(args->child[0], args->children - 1, lcname);
    3540         495 :         for (i = 1; i < args->children; ++i) {
    3541         357 :                 zend_ast *arg_ast = args->child[i];
    3542             :                 znode arg_node;
    3543             :                 zend_op *opline;
    3544             : 
    3545         357 :                 zend_compile_expr(&arg_node, arg_ast);
    3546         357 :                 if (arg_node.op_type & (IS_VAR|IS_CV)) {
    3547         273 :                         opline = zend_emit_op(NULL, ZEND_SEND_USER, &arg_node, NULL);
    3548             :                 } else {
    3549          84 :                         opline = zend_emit_op(NULL, ZEND_SEND_VAL, &arg_node, NULL);
    3550             :                 }
    3551             : 
    3552         357 :                 opline->op2.num = i;
    3553         357 :                 opline->result.var = (uint32_t)(zend_intptr_t)ZEND_CALL_ARG(NULL, i);
    3554             :         }
    3555         138 :         zend_emit_op(result, ZEND_DO_FCALL, NULL, NULL);
    3556             : 
    3557         138 :         return SUCCESS;
    3558             : }
    3559             : /* }}} */
    3560             : 
    3561         240 : static int zend_compile_assert(znode *result, zend_ast_list *args, zend_string *name, zend_function *fbc) /* {{{ */
    3562             : {
    3563         240 :         if (EG(assertions) >= 0) {
    3564             :                 znode name_node;
    3565             :                 zend_op *opline;
    3566         232 :                 uint32_t check_op_number = get_next_op_number(CG(active_op_array));
    3567             : 
    3568         232 :                 zend_emit_op(NULL, ZEND_ASSERT_CHECK, NULL, NULL);
    3569             : 
    3570         232 :                 if (fbc) {
    3571         225 :                         name_node.op_type = IS_CONST;
    3572         225 :                         ZVAL_STR_COPY(&name_node.u.constant, name);
    3573             : 
    3574         225 :                         opline = zend_emit_op(NULL, ZEND_INIT_FCALL, NULL, &name_node);
    3575             :                 } else {
    3576           7 :                         opline = zend_emit_op(NULL, ZEND_INIT_NS_FCALL_BY_NAME, NULL, NULL);
    3577           7 :                         opline->op2_type = IS_CONST;
    3578           7 :                         opline->op2.constant = zend_add_ns_func_name_literal(
    3579             :                                 CG(active_op_array), name);
    3580             :                 }
    3581         232 :                 zend_alloc_cache_slot(opline->op2.constant);
    3582             : 
    3583         519 :                 if (args->children == 1 &&
    3584         218 :                     (args->child[0]->kind != ZEND_AST_ZVAL ||
    3585          69 :                      Z_TYPE_P(zend_ast_get_zval(args->child[0])) != IS_STRING)) {
    3586             :                         /* add "assert(condition) as assertion message */
    3587         320 :                         zend_ast_list_add((zend_ast*)args,
    3588             :                                 zend_ast_create_zval_from_str(
    3589             :                                         zend_ast_export("assert(", args->child[0], ")")));
    3590             :                 }
    3591             : 
    3592         232 :                 zend_compile_call_common(result, (zend_ast*)args, fbc);
    3593             : 
    3594         232 :                 opline = &CG(active_op_array)->opcodes[check_op_number];
    3595         232 :                 opline->op2.opline_num = get_next_op_number(CG(active_op_array));
    3596         232 :                 SET_NODE(opline->result, result);
    3597             :         } else {
    3598           8 :                 if (!fbc) {
    3599             :                         zend_string_release(name);
    3600             :                 }
    3601           8 :                 result->op_type = IS_CONST;
    3602           8 :                 ZVAL_TRUE(&result->u.constant);
    3603             :         }
    3604             : 
    3605         240 :         return SUCCESS;
    3606             : }
    3607             : /* }}} */
    3608             : 
    3609      282975 : int zend_try_compile_special_func(znode *result, zend_string *lcname, zend_ast_list *args, zend_function *fbc, uint32_t type) /* {{{ */
    3610             : {
    3611      282975 :         if (fbc->internal_function.handler == ZEND_FN(display_disabled_function)) {
    3612           6 :                 return FAILURE;
    3613             :         }
    3614             : 
    3615      282969 :         if (zend_string_equals_literal(lcname, "assert")) {
    3616         231 :                 return zend_compile_assert(result, args, lcname, fbc);
    3617             :         }
    3618             : 
    3619      282738 :         if (CG(compiler_options) & ZEND_COMPILE_NO_BUILTINS) {
    3620           0 :                 return FAILURE;
    3621             :         }
    3622             : 
    3623      282738 :         if (zend_string_equals_literal(lcname, "strlen")) {
    3624        5184 :                 return zend_compile_func_strlen(result, args);
    3625      277554 :         } else if (zend_string_equals_literal(lcname, "is_null")) {
    3626         876 :                 return zend_compile_func_typecheck(result, args, IS_NULL);
    3627      276678 :         } else if (zend_string_equals_literal(lcname, "is_bool")) {
    3628          23 :                 return zend_compile_func_typecheck(result, args, _IS_BOOL);
    3629      917357 :         } else if (zend_string_equals_literal(lcname, "is_long")
    3630      352269 :                 || zend_string_equals_literal(lcname, "is_int")
    3631      288433 :                 || zend_string_equals_literal(lcname, "is_integer")
    3632             :         ) {
    3633         342 :                 return zend_compile_func_typecheck(result, args, IS_LONG);
    3634      865685 :         } else if (zend_string_equals_literal(lcname, "is_float")
    3635      287915 :                 || zend_string_equals_literal(lcname, "is_double")
    3636      301457 :                 || zend_string_equals_literal(lcname, "is_real")
    3637             :         ) {
    3638          35 :                 return zend_compile_func_typecheck(result, args, IS_DOUBLE);
    3639      276278 :         } else if (zend_string_equals_literal(lcname, "is_string")) {
    3640        1504 :                 return zend_compile_func_typecheck(result, args, IS_STRING);
    3641      274774 :         } else if (zend_string_equals_literal(lcname, "is_array")) {
    3642         818 :                 return zend_compile_func_typecheck(result, args, IS_ARRAY);
    3643      273956 :         } else if (zend_string_equals_literal(lcname, "is_object")) {
    3644         526 :                 return zend_compile_func_typecheck(result, args, IS_OBJECT);
    3645      273430 :         } else if (zend_string_equals_literal(lcname, "is_resource")) {
    3646         232 :                 return zend_compile_func_typecheck(result, args, IS_RESOURCE);
    3647      273198 :         } else if (zend_string_equals_literal(lcname, "defined")) {
    3648         212 :                 return zend_compile_func_defined(result, args);
    3649      272986 :         } else if (zend_string_equals_literal(lcname, "chr") && type == BP_VAR_R) {
    3650         625 :                 return zend_compile_func_chr(result, args);
    3651      272361 :         } else if (zend_string_equals_literal(lcname, "ord") && type == BP_VAR_R) {
    3652          68 :                 return zend_compile_func_ord(result, args);
    3653      272293 :         } else if (zend_string_equals_literal(lcname, "call_user_func_array")) {
    3654          73 :                 return zend_compile_func_cufa(result, args, lcname);
    3655      272220 :         } else if (zend_string_equals_literal(lcname, "call_user_func")) {
    3656         138 :                 return zend_compile_func_cuf(result, args, lcname);
    3657             :         } else {
    3658      272082 :                 return FAILURE;
    3659             :         }
    3660             : }
    3661             : /* }}} */
    3662             : 
    3663      290790 : void zend_compile_call(znode *result, zend_ast *ast, uint32_t type) /* {{{ */
    3664             : {
    3665      290790 :         zend_ast *name_ast = ast->child[0];
    3666      290790 :         zend_ast *args_ast = ast->child[1];
    3667             : 
    3668             :         znode name_node;
    3669             : 
    3670      579375 :         if (name_ast->kind != ZEND_AST_ZVAL || Z_TYPE_P(zend_ast_get_zval(name_ast)) != IS_STRING) {
    3671        2205 :                 zend_compile_expr(&name_node, name_ast);
    3672        2205 :                 zend_compile_dynamic_call(result, &name_node, args_ast);
    3673        2205 :                 return;
    3674             :         }
    3675             : 
    3676             :         {
    3677      288585 :                 zend_bool runtime_resolution = zend_compile_function_name(&name_node, name_ast);
    3678      288585 :                 if (runtime_resolution) {
    3679         424 :                         if (zend_string_equals_literal_ci(zend_ast_get_str(name_ast), "assert")) {
    3680          18 :                                 zend_compile_assert(result, zend_ast_get_list(args_ast), Z_STR(name_node.u.constant), NULL);
    3681             :                         } else {
    3682         368 :                                 zend_compile_ns_call(result, &name_node, args_ast);
    3683             :                         }
    3684         377 :                         return;
    3685             :                 }
    3686             :         }
    3687             : 
    3688             :         {
    3689      288208 :                 zval *name = &name_node.u.constant;
    3690             :                 zend_string *lcname;
    3691             :                 zend_function *fbc;
    3692             :                 zend_op *opline;
    3693             : 
    3694      288208 :                 lcname = zend_string_tolower(Z_STR_P(name));
    3695             : 
    3696      576416 :                 fbc = zend_hash_find_ptr(CG(function_table), lcname);
    3697     1137133 :                 if (!fbc
    3698      557591 :                  || (fbc->type == ZEND_INTERNAL_FUNCTION && (CG(compiler_options) & ZEND_COMPILE_IGNORE_INTERNAL_FUNCTIONS))
    3699      291334 :                  || (fbc->type == ZEND_USER_FUNCTION && (CG(compiler_options) & ZEND_COMPILE_IGNORE_USER_FUNCTIONS))
    3700             :                 ) {
    3701             :                         zend_string_release(lcname);
    3702        5233 :                         zend_compile_dynamic_call(result, &name_node, args_ast);
    3703        5233 :                         return;
    3704             :                 }
    3705             : 
    3706      282975 :                 if (zend_try_compile_special_func(result, lcname,
    3707             :                                 zend_ast_get_list(args_ast), fbc, type) == SUCCESS
    3708             :                 ) {
    3709             :                         zend_string_release(lcname);
    3710       10683 :                         zval_ptr_dtor(&name_node.u.constant);
    3711       10683 :                         return;
    3712             :                 }
    3713             : 
    3714      272292 :                 zval_ptr_dtor(&name_node.u.constant);
    3715      272292 :                 ZVAL_NEW_STR(&name_node.u.constant, lcname);
    3716             : 
    3717      272292 :                 opline = zend_emit_op(NULL, ZEND_INIT_FCALL, NULL, &name_node);
    3718      272292 :                 zend_alloc_cache_slot(opline->op2.constant);
    3719             : 
    3720      272292 :                 zend_compile_call_common(result, args_ast, fbc);
    3721             :         }
    3722             : }
    3723             : /* }}} */
    3724             : 
    3725       38897 : void zend_compile_method_call(znode *result, zend_ast *ast, uint32_t type) /* {{{ */
    3726             : {
    3727       38897 :         zend_ast *obj_ast = ast->child[0];
    3728       38897 :         zend_ast *method_ast = ast->child[1];
    3729       38897 :         zend_ast *args_ast = ast->child[2];
    3730             : 
    3731             :         znode obj_node, method_node;
    3732             :         zend_op *opline;
    3733       38897 :         zend_function *fbc = NULL;
    3734             : 
    3735       38897 :         if (is_this_fetch(obj_ast)) {
    3736        1434 :                 obj_node.op_type = IS_UNUSED;
    3737             :         } else {
    3738       37463 :                 zend_compile_expr(&obj_node, obj_ast);
    3739             :         }
    3740             : 
    3741       38897 :         zend_compile_expr(&method_node, method_ast);
    3742       38897 :         opline = zend_emit_op(NULL, ZEND_INIT_METHOD_CALL, &obj_node, NULL);
    3743             : 
    3744       38897 :         if (method_node.op_type == IS_CONST) {
    3745       38869 :                 if (Z_TYPE(method_node.u.constant) != IS_STRING) {
    3746           2 :                         zend_error_noreturn(E_COMPILE_ERROR, "Method name must be a string");
    3747             :                 }
    3748             : 
    3749       38867 :                 opline->op2_type = IS_CONST;
    3750       38867 :                 opline->op2.constant = zend_add_func_name_literal(CG(active_op_array),
    3751             :                         Z_STR(method_node.u.constant));
    3752       38867 :                 zend_alloc_polymorphic_cache_slot(opline->op2.constant);
    3753             :         } else {
    3754          28 :                 SET_NODE(opline->op2, &method_node);
    3755             :         }
    3756             : 
    3757             :         /* Check if this calls a known method on $this */
    3758       41755 :         if (opline->op1_type == IS_UNUSED && opline->op2_type == IS_CONST &&
    3759        2860 :                         CG(active_class_entry) && zend_is_scope_known()) {
    3760        1424 :                 zend_string *lcname = Z_STR_P(CT_CONSTANT(opline->op2) + 1);
    3761        2848 :                 fbc = zend_hash_find_ptr(&CG(active_class_entry)->function_table, lcname);
    3762             : 
    3763             :                 /* We only know the exact method that is being called if it is either private or final.
    3764             :                  * Otherwise an overriding method in a child class may be called. */
    3765        1424 :                 if (fbc && !(fbc->common.fn_flags & (ZEND_ACC_PRIVATE|ZEND_ACC_FINAL))) {
    3766          87 :                         fbc = NULL;
    3767             :                 }
    3768             :         }
    3769             : 
    3770       38895 :         zend_compile_call_common(result, args_ast, fbc);
    3771       38895 : }
    3772             : /* }}} */
    3773             : 
    3774       11683 : static zend_bool zend_is_constructor(zend_string *name) /* {{{ */
    3775             : {
    3776       11683 :         return zend_string_equals_literal_ci(name, ZEND_CONSTRUCTOR_FUNC_NAME);
    3777             : }
    3778             : /* }}} */
    3779             : 
    3780       11719 : void zend_compile_static_call(znode *result, zend_ast *ast, uint32_t type) /* {{{ */
    3781             : {
    3782       11719 :         zend_ast *class_ast = ast->child[0];
    3783       11719 :         zend_ast *method_ast = ast->child[1];
    3784       11719 :         zend_ast *args_ast = ast->child[2];
    3785             : 
    3786             :         znode class_node, method_node;
    3787             :         zend_op *opline;
    3788       11719 :         zend_function *fbc = NULL;
    3789             : 
    3790       11719 :         zend_compile_class_ref_ex(&class_node, class_ast, ZEND_FETCH_CLASS_EXCEPTION);
    3791             : 
    3792       11719 :         zend_compile_expr(&method_node, method_ast);
    3793       11719 :         if (method_node.op_type == IS_CONST) {
    3794       11683 :                 zval *name = &method_node.u.constant;
    3795       11683 :                 if (Z_TYPE_P(name) != IS_STRING) {
    3796           0 :                         zend_error_noreturn(E_COMPILE_ERROR, "Method name must be a string");
    3797             :                 }
    3798       11683 :                 if (zend_is_constructor(Z_STR_P(name))) {
    3799        1060 :                         zval_ptr_dtor(name);
    3800        1060 :                         method_node.op_type = IS_UNUSED;
    3801             :                 }
    3802             :         }
    3803             : 
    3804       11719 :         opline = get_next_op(CG(active_op_array));
    3805       11719 :         opline->opcode = ZEND_INIT_STATIC_METHOD_CALL;
    3806             : 
    3807       11719 :         zend_set_class_name_op1(opline, &class_node);
    3808             : 
    3809       11719 :         if (method_node.op_type == IS_CONST) {
    3810       10623 :                 opline->op2_type = IS_CONST;
    3811       10623 :                 opline->op2.constant = zend_add_func_name_literal(CG(active_op_array),
    3812             :                         Z_STR(method_node.u.constant));
    3813       10623 :                 if (opline->op1_type == IS_CONST) {
    3814        6176 :                         zend_alloc_cache_slot(opline->op2.constant);
    3815             :                 } else {
    3816        4447 :                         zend_alloc_polymorphic_cache_slot(opline->op2.constant);
    3817             :                 }
    3818             :         } else {
    3819        1096 :                 SET_NODE(opline->op2, &method_node);
    3820             :         }
    3821       11719 :         zend_check_live_ranges(opline);
    3822             : 
    3823             :         /* Check if we already know which method we're calling */
    3824       11719 :         if (opline->op2_type == IS_CONST) {
    3825       10623 :                 zend_class_entry *ce = NULL;
    3826       10623 :                 if (opline->op1_type == IS_CONST) {
    3827        6176 :                         zend_string *lcname = Z_STR_P(CT_CONSTANT(opline->op1) + 1);
    3828       12352 :                         ce = zend_hash_find_ptr(CG(class_table), lcname);
    3829        8440 :                         if (!ce && CG(active_class_entry)
    3830        2264 :                                         && zend_string_equals_ci(CG(active_class_entry)->name, lcname)) {
    3831        1115 :                                 ce = CG(active_class_entry);
    3832             :                         }
    3833       12077 :                 } else if (opline->op1_type == IS_UNUSED
    3834        8875 :                                 && (opline->op1.num & ZEND_FETCH_CLASS_MASK) == ZEND_FETCH_CLASS_SELF
    3835        3202 :                                 && zend_is_scope_known()) {
    3836        3198 :                         ce = CG(active_class_entry);
    3837             :                 }
    3838       10623 :                 if (ce) {
    3839        7654 :                         zend_string *lcname = Z_STR_P(CT_CONSTANT(opline->op2) + 1);
    3840       15308 :                         fbc = zend_hash_find_ptr(&ce->function_table, lcname);
    3841             :                 }
    3842             :         }
    3843             : 
    3844       11719 :         zend_compile_call_common(result, args_ast, fbc);
    3845       11719 : }
    3846             : /* }}} */
    3847             : 
    3848             : void zend_compile_class_decl(zend_ast *ast);
    3849             : 
    3850       15445 : void zend_compile_new(znode *result, zend_ast *ast) /* {{{ */
    3851             : {
    3852       15445 :         zend_ast *class_ast = ast->child[0];
    3853       15445 :         zend_ast *args_ast = ast->child[1];
    3854             : 
    3855             :         znode class_node, ctor_result;
    3856             :         zend_op *opline;
    3857             :         uint32_t opnum;
    3858             : 
    3859       15445 :         if (class_ast->kind == ZEND_AST_CLASS) {
    3860          29 :                 uint32_t dcl_opnum = get_next_op_number(CG(active_op_array));
    3861          29 :                 zend_compile_class_decl(class_ast);
    3862             :                 /* jump over anon class declaration */
    3863          29 :                 opline = &CG(active_op_array)->opcodes[dcl_opnum];
    3864          29 :                 if (opline->opcode == ZEND_FETCH_CLASS) {
    3865           3 :                         opline++;
    3866             :                 }
    3867          29 :                 class_node.op_type = opline->result_type;
    3868          29 :                 class_node.u.op.var = opline->result.var;
    3869          29 :                 opline->extended_value = get_next_op_number(CG(active_op_array));
    3870             :         } else {
    3871       15416 :                 zend_compile_class_ref_ex(&class_node, class_ast, ZEND_FETCH_CLASS_EXCEPTION);
    3872             :         }
    3873             : 
    3874       15445 :         opnum = get_next_op_number(CG(active_op_array));
    3875       15445 :         opline = zend_emit_op(result, ZEND_NEW, NULL, NULL);
    3876             : 
    3877       15445 :         if (class_node.op_type == IS_CONST) {
    3878       13945 :                 opline->op1_type = IS_CONST;
    3879       13945 :                 opline->op1.constant = zend_add_class_name_literal(
    3880             :                         CG(active_op_array), Z_STR(class_node.u.constant));
    3881             :         } else {
    3882        1500 :                 SET_NODE(opline->op1, &class_node);
    3883             :         }
    3884             : 
    3885       15445 :         zend_compile_call_common(&ctor_result, args_ast, NULL);
    3886       15445 :         zend_do_free(&ctor_result);
    3887             : 
    3888             :         /* We save the position of DO_FCALL for convenience in find_live_range().
    3889             :          * This info is not preserved for runtime. */
    3890       15445 :         opline = &CG(active_op_array)->opcodes[opnum];
    3891       15445 :         opline->op2.opline_num = get_next_op_number(CG(active_op_array));
    3892       15445 : }
    3893             : /* }}} */
    3894             : 
    3895         122 : void zend_compile_clone(znode *result, zend_ast *ast) /* {{{ */
    3896             : {
    3897         122 :         zend_ast *obj_ast = ast->child[0];
    3898             : 
    3899             :         znode obj_node;
    3900         122 :         zend_compile_expr(&obj_node, obj_ast);
    3901             : 
    3902         122 :         zend_emit_op_tmp(result, ZEND_CLONE, &obj_node, NULL);
    3903         122 : }
    3904             : /* }}} */
    3905             : 
    3906        5206 : void zend_compile_global_var(zend_ast *ast) /* {{{ */
    3907             : {
    3908        5206 :         zend_ast *var_ast = ast->child[0];
    3909        5206 :         zend_ast *name_ast = var_ast->child[0];
    3910             : 
    3911             :         znode name_node, result;
    3912             : 
    3913        5206 :         zend_compile_expr(&name_node, name_ast);
    3914        5206 :         if (name_node.op_type == IS_CONST) {
    3915        5203 :                 convert_to_string(&name_node.u.constant);
    3916             :         }
    3917             : 
    3918        5206 :         if (is_this_fetch(var_ast)) {
    3919           1 :                 zend_error_noreturn(E_COMPILE_ERROR, "Cannot use $this as global variable");
    3920        5205 :         } else if (zend_try_compile_cv(&result, var_ast) == SUCCESS) {
    3921        5202 :                 zend_op *opline = zend_emit_op(NULL, ZEND_BIND_GLOBAL, &result, &name_node);
    3922        5202 :                 zend_alloc_cache_slot(opline->op2.constant);
    3923             :         } else {
    3924             :                 /* name_ast should be evaluated only. FETCH_GLOBAL_LOCK instructs FETCH_W
    3925             :                  * to not free the name_node operand, so it can be reused in the following
    3926             :                  * ASSIGN_REF, which then frees it. */
    3927           3 :                 zend_op *opline = zend_emit_op(&result, ZEND_FETCH_W, &name_node, NULL);
    3928           3 :                 opline->extended_value = ZEND_FETCH_GLOBAL_LOCK;
    3929             : 
    3930           3 :                 if (name_node.op_type == IS_CONST) {
    3931           0 :                         zend_string_addref(Z_STR(name_node.u.constant));
    3932             :                 }
    3933             : 
    3934           3 :                 zend_emit_assign_ref_znode(
    3935             :                         zend_ast_create(ZEND_AST_VAR, zend_ast_create_znode(&name_node)),
    3936             :                         &result
    3937             :                 );
    3938             :         }
    3939        5205 : }
    3940             : /* }}} */
    3941             : 
    3942        2329 : static void zend_compile_static_var_common(zend_ast *var_ast, zval *value, zend_bool by_ref) /* {{{ */
    3943             : {
    3944             :         znode var_node;
    3945             :         zend_op *opline;
    3946             : 
    3947        2329 :         zend_compile_expr(&var_node, var_ast);
    3948             : 
    3949        2329 :         if (!CG(active_op_array)->static_variables) {
    3950        2294 :                 if (CG(active_op_array)->scope) {
    3951        1112 :                         CG(active_op_array)->scope->ce_flags |= ZEND_HAS_STATIC_IN_METHODS;
    3952             :                 }
    3953        2294 :                 ALLOC_HASHTABLE(CG(active_op_array)->static_variables);
    3954        2294 :                 zend_hash_init(CG(active_op_array)->static_variables, 8, NULL, ZVAL_PTR_DTOR, 0);
    3955             :         }
    3956             : 
    3957        2329 :         if (GC_REFCOUNT(CG(active_op_array)->static_variables) > 1) {
    3958           0 :                 if (!(GC_FLAGS(CG(active_op_array)->static_variables) & IS_ARRAY_IMMUTABLE)) {
    3959           0 :                         GC_REFCOUNT(CG(active_op_array)->static_variables)--;
    3960             :                 }
    3961           0 :                 CG(active_op_array)->static_variables = zend_array_dup(CG(active_op_array)->static_variables);
    3962             :         }
    3963        2329 :         zend_hash_update(CG(active_op_array)->static_variables, Z_STR(var_node.u.constant), value);
    3964             : 
    3965        2329 :         if (zend_string_equals_literal(Z_STR(var_node.u.constant), "this")) {
    3966           1 :                 zend_error_noreturn(E_COMPILE_ERROR, "Cannot use $this as static variable");
    3967             :         }
    3968             : 
    3969        2328 :         opline = zend_emit_op(NULL, ZEND_BIND_STATIC, NULL, &var_node);
    3970        2328 :         opline->op1_type = IS_CV;
    3971        4656 :         opline->op1.var = lookup_cv(CG(active_op_array), zend_string_copy(Z_STR(var_node.u.constant)));
    3972        2328 :         opline->extended_value = by_ref;
    3973        2328 : }
    3974             : /* }}} */
    3975             : 
    3976        2132 : void zend_compile_static_var(zend_ast *ast) /* {{{ */
    3977             : {
    3978        2132 :         zend_ast *var_ast = ast->child[0];
    3979        2132 :         zend_ast *value_ast = ast->child[1];
    3980             :         zval value_zv;
    3981             : 
    3982        2132 :         if (value_ast) {
    3983        2111 :                 zend_const_expr_to_zval(&value_zv, value_ast);
    3984             :         } else {
    3985          21 :                 ZVAL_NULL(&value_zv);
    3986             :         }
    3987             : 
    3988        2132 :         zend_compile_static_var_common(var_ast, &value_zv, 1);
    3989        2131 : }
    3990             : /* }}} */
    3991             : 
    3992        1691 : void zend_compile_unset(zend_ast *ast) /* {{{ */
    3993             : {
    3994        1691 :         zend_ast *var_ast = ast->child[0];
    3995             :         znode var_node;
    3996             :         zend_op *opline;
    3997             : 
    3998        1691 :         zend_ensure_writable_variable(var_ast);
    3999             : 
    4000        1690 :         switch (var_ast->kind) {
    4001             :                 case ZEND_AST_VAR:
    4002        1340 :                         if (is_this_fetch(var_ast)) {
    4003           2 :                                 zend_error_noreturn(E_COMPILE_ERROR, "Cannot unset $this");
    4004        1338 :                         } else if (zend_try_compile_cv(&var_node, var_ast) == SUCCESS) {
    4005        1328 :                                 opline = zend_emit_op(NULL, ZEND_UNSET_VAR, &var_node, NULL);
    4006        1328 :                                 opline->extended_value = ZEND_FETCH_LOCAL | ZEND_QUICK_SET;
    4007             :                         } else {
    4008          10 :                                 opline = zend_compile_simple_var_no_cv(NULL, var_ast, BP_VAR_UNSET, 0);
    4009          10 :                                 opline->opcode = ZEND_UNSET_VAR;
    4010             :                         }
    4011        1338 :                         return;
    4012             :                 case ZEND_AST_DIM:
    4013         254 :                         opline = zend_compile_dim_common(NULL, var_ast, BP_VAR_UNSET);
    4014         253 :                         opline->opcode = ZEND_UNSET_DIM;
    4015         253 :                         return;
    4016             :                 case ZEND_AST_PROP:
    4017          93 :                         opline = zend_compile_prop_common(NULL, var_ast, BP_VAR_UNSET);
    4018          93 :                         opline->opcode = ZEND_UNSET_OBJ;
    4019          93 :                         return;
    4020             :                 case ZEND_AST_STATIC_PROP:
    4021           3 :                         opline = zend_compile_static_prop_common(NULL, var_ast, BP_VAR_UNSET, 0);
    4022           3 :                         opline->opcode = ZEND_UNSET_STATIC_PROP;
    4023           3 :                         return;
    4024             :                 EMPTY_SWITCH_DEFAULT_CASE()
    4025             :         }
    4026             : }
    4027             : /* }}} */
    4028             : 
    4029       48780 : static int zend_handle_loops_and_finally_ex(zend_long depth, znode *return_value) /* {{{ */
    4030             : {
    4031             :         zend_loop_var *base;
    4032       48780 :         zend_loop_var *loop_var = zend_stack_top(&CG(loop_var_stack));
    4033             : 
    4034       48780 :         if (!loop_var) {
    4035         724 :                 return 1;
    4036             :         }
    4037       48056 :         base = zend_stack_base(&CG(loop_var_stack));
    4038       51202 :         for (; loop_var >= base; loop_var--) {
    4039       51184 :                 if (loop_var->opcode == ZEND_FAST_CALL) {
    4040          61 :                         zend_op *opline = get_next_op(CG(active_op_array));
    4041             : 
    4042          61 :                         opline->opcode = ZEND_FAST_CALL;
    4043          61 :                         opline->result_type = IS_TMP_VAR;
    4044          61 :                         opline->result.var = loop_var->var_num;
    4045          61 :                         SET_UNUSED(opline->op1);
    4046          61 :                         if (return_value) {
    4047          15 :                                 SET_NODE(opline->op2, return_value);
    4048             :                         } else {
    4049          46 :                                 SET_UNUSED(opline->op2);
    4050             :                         }
    4051          61 :                         opline->op1.num = loop_var->u.try_catch_offset;
    4052       51123 :                 } else if (loop_var->opcode == ZEND_DISCARD_EXCEPTION) {
    4053          34 :                         zend_op *opline = get_next_op(CG(active_op_array));
    4054          34 :                         opline->opcode = ZEND_DISCARD_EXCEPTION;
    4055          34 :                         opline->op1_type = IS_TMP_VAR;
    4056          34 :                         opline->op1.var = loop_var->var_num;
    4057          34 :                         SET_UNUSED(opline->op2);
    4058       51089 :                 } else if (loop_var->opcode == ZEND_RETURN) {
    4059             :                         /* Stack separator */
    4060       45678 :                         break;
    4061        5411 :                 } else if (depth <= 1) {
    4062        2360 :                         return 1;
    4063        3051 :                 } else if (loop_var->opcode == ZEND_NOP) {
    4064             :                         /* Loop doesn't have freeable variable */
    4065        2455 :                         depth--;
    4066             :                 } else {
    4067             :                         zend_op *opline;
    4068             : 
    4069             :                         ZEND_ASSERT(loop_var->var_type & (IS_VAR|IS_TMP_VAR));
    4070         596 :                         opline = get_next_op(CG(active_op_array));
    4071         596 :                         opline->opcode = loop_var->opcode;
    4072         596 :                         opline->op1_type = loop_var->var_type;
    4073         596 :                         opline->op1.var = loop_var->var_num;
    4074         596 :                         SET_UNUSED(opline->op2);
    4075         596 :                         opline->op2.num = loop_var->u.live_range_offset;
    4076         596 :                         opline->extended_value = ZEND_FREE_ON_RETURN;
    4077         596 :                         depth--;
    4078             :             }
    4079             :         }
    4080       45696 :         return (depth == 0);
    4081             : }
    4082             : /* }}} */
    4083             : 
    4084       46419 : static int zend_handle_loops_and_finally(znode *return_value) /* {{{ */
    4085             : {
    4086       46419 :         return zend_handle_loops_and_finally_ex(zend_stack_count(&CG(loop_var_stack)) + 1, return_value);
    4087             : }
    4088             : /* }}} */
    4089             : 
    4090          10 : static int zend_has_finally_ex(zend_long depth) /* {{{ */
    4091             : {
    4092             :         zend_loop_var *base;
    4093          10 :         zend_loop_var *loop_var = zend_stack_top(&CG(loop_var_stack));
    4094             : 
    4095          10 :         if (!loop_var) {
    4096           0 :                 return 0;
    4097             :         }
    4098          10 :         base = zend_stack_base(&CG(loop_var_stack));
    4099          11 :         for (; loop_var >= base; loop_var--) {
    4100          11 :                 if (loop_var->opcode == ZEND_FAST_CALL) {
    4101           8 :                         return 1;
    4102           3 :                 } else if (loop_var->opcode == ZEND_DISCARD_EXCEPTION) {
    4103           2 :                 } else if (loop_var->opcode == ZEND_RETURN) {
    4104             :                         /* Stack separator */
    4105           2 :                         return 0;
    4106           0 :                 } else if (depth <= 1) {
    4107           0 :                         return 0;
    4108             :                 } else {
    4109           0 :                         depth--;
    4110             :             }
    4111             :         }
    4112           0 :         return 0;
    4113             : }
    4114             : /* }}} */
    4115             : 
    4116          10 : static int zend_has_finally(void) /* {{{ */
    4117             : {
    4118          10 :         return zend_has_finally_ex(zend_stack_count(&CG(loop_var_stack)) + 1);
    4119             : }
    4120             : /* }}} */
    4121             : 
    4122       46378 : void zend_compile_return(zend_ast *ast) /* {{{ */
    4123             : {
    4124       46378 :         zend_ast *expr_ast = ast->child[0];
    4125       46378 :         zend_bool is_generator = (CG(active_op_array)->fn_flags & ZEND_ACC_GENERATOR) != 0;
    4126       46378 :         zend_bool by_ref = (CG(active_op_array)->fn_flags & ZEND_ACC_RETURN_REFERENCE) != 0;
    4127             : 
    4128             :         znode expr_node;
    4129             :         zend_op *opline;
    4130             : 
    4131       46378 :         if (is_generator) {
    4132             :                 /* For generators the by-ref flag refers to yields, not returns */
    4133          32 :                 by_ref = 0;
    4134             :         }
    4135             : 
    4136       46378 :         if (!expr_ast) {
    4137         527 :                 expr_node.op_type = IS_CONST;
    4138         527 :                 ZVAL_NULL(&expr_node.u.constant);
    4139       45913 :         } else if (by_ref && zend_is_variable(expr_ast) && !zend_is_call(expr_ast)) {
    4140          62 :                 zend_compile_var(&expr_node, expr_ast, BP_VAR_W);
    4141             :         } else {
    4142       45789 :                 zend_compile_expr(&expr_node, expr_ast);
    4143             :         }
    4144             : 
    4145       46455 :         if ((CG(active_op_array)->fn_flags & ZEND_ACC_HAS_FINALLY_BLOCK)
    4146          69 :          && (expr_node.op_type == IS_CV || (by_ref && expr_node.op_type == IS_VAR))
    4147          10 :          && zend_has_finally()) {
    4148             :                 /* Copy return value into temporary VAR to avoid modification in finally code */
    4149           8 :                 if (by_ref) {
    4150           4 :                         zend_emit_op(&expr_node, ZEND_MAKE_REF, &expr_node, NULL);
    4151             :                 } else {
    4152           4 :                         zend_emit_op_tmp(&expr_node, ZEND_QM_ASSIGN, &expr_node, NULL);
    4153             :                 }
    4154             :         }
    4155             : 
    4156             :         /* Generator return types are handled separately */
    4157       46376 :         if (!is_generator && CG(active_op_array)->fn_flags & ZEND_ACC_HAS_RETURN_TYPE) {
    4158          94 :                 zend_emit_return_type_check(
    4159          94 :                         expr_ast ? &expr_node : NULL, CG(active_op_array)->arg_info - 1, 0);
    4160             :         }
    4161             : 
    4162       46372 :         zend_handle_loops_and_finally((expr_node.op_type & (IS_TMP_VAR | IS_VAR)) ? &expr_node : NULL);
    4163             : 
    4164       46372 :         opline = zend_emit_op(NULL, by_ref ? ZEND_RETURN_BY_REF : ZEND_RETURN,
    4165             :                 &expr_node, NULL);
    4166             : 
    4167       46372 :         if (by_ref && expr_ast) {
    4168          82 :                 if (zend_is_call(expr_ast)) {
    4169           9 :                         opline->extended_value = ZEND_RETURNS_FUNCTION;
    4170          73 :                 } else if (!zend_is_variable(expr_ast)) {
    4171          11 :                         opline->extended_value = ZEND_RETURNS_VALUE;
    4172             :                 }
    4173             :         }
    4174       46372 : }
    4175             : /* }}} */
    4176             : 
    4177       41085 : void zend_compile_echo(zend_ast *ast) /* {{{ */
    4178             : {
    4179             :         zend_op *opline;
    4180       41085 :         zend_ast *expr_ast = ast->child[0];
    4181             : 
    4182             :         znode expr_node;
    4183       41085 :         zend_compile_expr(&expr_node, expr_ast);
    4184             : 
    4185       41085 :         opline = zend_emit_op(NULL, ZEND_ECHO, &expr_node, NULL);
    4186       41085 :         opline->extended_value = 0;
    4187       41085 : }
    4188             : /* }}} */
    4189             : 
    4190         444 : void zend_compile_throw(zend_ast *ast) /* {{{ */
    4191             : {
    4192         444 :         zend_ast *expr_ast = ast->child[0];
    4193             : 
    4194             :         znode expr_node;
    4195         444 :         zend_compile_expr(&expr_node, expr_ast);
    4196             : 
    4197         444 :         zend_emit_op(NULL, ZEND_THROW, &expr_node, NULL);
    4198         444 : }
    4199             : /* }}} */
    4200             : 
    4201        2365 : void zend_compile_break_continue(zend_ast *ast) /* {{{ */
    4202             : {
    4203        2365 :         zend_ast *depth_ast = ast->child[0];
    4204             : 
    4205             :         zend_op *opline;
    4206             :         int depth;
    4207             : 
    4208             :         ZEND_ASSERT(ast->kind == ZEND_AST_BREAK || ast->kind == ZEND_AST_CONTINUE);
    4209             : 
    4210        2365 :         if (depth_ast) {
    4211             :                 zval *depth_zv;
    4212          29 :                 if (depth_ast->kind != ZEND_AST_ZVAL) {
    4213           1 :                         zend_error_noreturn(E_COMPILE_ERROR, "'%s' operator with non-constant operand "
    4214           1 :                                 "is no longer supported", ast->kind == ZEND_AST_BREAK ? "break" : "continue");
    4215             :                 }
    4216             : 
    4217          28 :                 depth_zv = zend_ast_get_zval(depth_ast);
    4218          28 :                 if (Z_TYPE_P(depth_zv) != IS_LONG || Z_LVAL_P(depth_zv) < 1) {
    4219           1 :                         zend_error_noreturn(E_COMPILE_ERROR, "'%s' operator accepts only positive numbers",
    4220           1 :                                 ast->kind == ZEND_AST_BREAK ? "break" : "continue");
    4221             :                 }
    4222             : 
    4223          27 :                 depth = Z_LVAL_P(depth_zv);
    4224             :         } else {
    4225        2336 :                 depth = 1;
    4226             :         }
    4227             : 
    4228        2363 :         if (CG(context).current_brk_cont == -1) {
    4229           2 :                 zend_error_noreturn(E_COMPILE_ERROR, "'%s' not in the 'loop' or 'switch' context",
    4230           2 :                         ast->kind == ZEND_AST_BREAK ? "break" : "continue");
    4231             :         } else {
    4232        2361 :                 if (!zend_handle_loops_and_finally_ex(depth, NULL)) {
    4233           2 :                         zend_error_noreturn(E_COMPILE_ERROR, "Cannot '%s' %d level%s",
    4234           1 :                                 ast->kind == ZEND_AST_BREAK ? "break" : "continue",
    4235             :                                 depth, depth == 1 ? "" : "s");
    4236             :                 }
    4237             :         }
    4238        2360 :         opline = zend_emit_op(NULL, ast->kind == ZEND_AST_BREAK ? ZEND_BRK : ZEND_CONT, NULL, NULL);
    4239        2360 :         opline->op1.num = CG(context).current_brk_cont;
    4240        2360 :         opline->op2.num = depth;
    4241        2360 : }
    4242             : /* }}} */
    4243             : 
    4244          47 : void zend_resolve_goto_label(zend_op_array *op_array, zend_op *opline) /* {{{ */
    4245             : {
    4246             :         zend_label *dest;
    4247          47 :         int current, remove_oplines = opline->op1.num;
    4248             :         zval *label;
    4249          47 :         uint32_t opnum = opline - op_array->opcodes;
    4250             : 
    4251          47 :         label = CT_CONSTANT_EX(op_array, opline->op2.constant);
    4252          93 :         if (CG(context).labels == NULL ||
    4253          46 :             (dest = zend_hash_find_ptr(CG(context).labels, Z_STR_P(label))) == NULL
    4254             :         ) {
    4255           1 :                 CG(in_compilation) = 1;
    4256           1 :                 CG(active_op_array) = op_array;
    4257           1 :                 CG(zend_lineno) = opline->lineno;
    4258           1 :                 zend_error_noreturn(E_COMPILE_ERROR, "'goto' to undefined label '%s'", Z_STRVAL_P(label));
    4259             :         }
    4260             : 
    4261             :         zval_dtor(label);
    4262          46 :         ZVAL_NULL(label);
    4263             : 
    4264          46 :         current = opline->extended_value;
    4265          56 :         for (; current != dest->brk_cont; current = CG(context).brk_cont_array[current].parent) {
    4266          14 :                 if (current == -1) {
    4267           4 :                         CG(in_compilation) = 1;
    4268           4 :                         CG(active_op_array) = op_array;
    4269           4 :                         CG(zend_lineno) = opline->lineno;
    4270           4 :                         zend_error_noreturn(E_COMPILE_ERROR, "'goto' into loop or switch statement is disallowed");
    4271             :                 }
    4272          10 :                 if (CG(context).brk_cont_array[current].start >= 0) {
    4273           6 :                         remove_oplines--;
    4274             :                 }
    4275             :         }
    4276             : 
    4277          69 :         for (current = 0; current < op_array->last_try_catch; ++current) {
    4278          35 :                 zend_try_catch_element *elem = &op_array->try_catch_array[current];
    4279          35 :                 if (elem->try_op > opnum) {
    4280           8 :                         break;
    4281             :                 }
    4282          64 :                 if (elem->finally_op && opnum < elem->finally_op - 1
    4283          37 :                         && (dest->opline_num > elem->finally_end || dest->opline_num < elem->try_op)
    4284             :                 ) {
    4285           7 :                         remove_oplines--;
    4286             :                 }
    4287             :         }
    4288             : 
    4289          42 :         opline->opcode = ZEND_JMP;
    4290          42 :         opline->op1.opline_num = dest->opline_num;
    4291          42 :         opline->extended_value = 0;
    4292          42 :         SET_UNUSED(opline->op1);
    4293          42 :         SET_UNUSED(opline->op2);
    4294          42 :         SET_UNUSED(opline->result);
    4295             : 
    4296             :         ZEND_ASSERT(remove_oplines >= 0);
    4297          99 :         while (remove_oplines--) {
    4298          15 :                 opline--;
    4299          15 :                 MAKE_NOP(opline);
    4300          15 :                 ZEND_VM_SET_OPCODE_HANDLER(opline);
    4301             :         }
    4302          42 : }
    4303             : /* }}} */
    4304             : 
    4305          47 : void zend_compile_goto(zend_ast *ast) /* {{{ */
    4306             : {
    4307          47 :         zend_ast *label_ast = ast->child[0];
    4308             :         znode label_node;
    4309             :         zend_op *opline;
    4310          47 :         uint32_t opnum_start = get_next_op_number(CG(active_op_array));
    4311             : 
    4312          47 :         zend_compile_expr(&label_node, label_ast);
    4313             : 
    4314             :         /* Label resolution and unwinding adjustments happen in pass two. */
    4315          47 :         zend_handle_loops_and_finally(NULL);
    4316          47 :         opline = zend_emit_op(NULL, ZEND_GOTO, NULL, &label_node);
    4317          47 :         opline->op1.num = get_next_op_number(CG(active_op_array)) - opnum_start - 1;
    4318          47 :         opline->extended_value = CG(context).current_brk_cont;
    4319          47 : }
    4320             : /* }}} */
    4321             : 
    4322          48 : void zend_compile_label(zend_ast *ast) /* {{{ */
    4323             : {
    4324          96 :         zend_string *label = zend_ast_get_str(ast->child[0]);
    4325             :         zend_label dest;
    4326             : 
    4327          48 :         if (!CG(context).labels) {
    4328          32 :                 ALLOC_HASHTABLE(CG(context).labels);
    4329          32 :                 zend_hash_init(CG(context).labels, 8, NULL, label_ptr_dtor, 0);
    4330             :         }
    4331             : 
    4332          48 :         dest.brk_cont = CG(context).current_brk_cont;
    4333          48 :         dest.opline_num = get_next_op_number(CG(active_op_array));
    4334             : 
    4335          96 :         if (!zend_hash_add_mem(CG(context).labels, label, &dest, sizeof(zend_label))) {
    4336           1 :                 zend_error_noreturn(E_COMPILE_ERROR, "Label '%s' already defined", ZSTR_VAL(label));
    4337             :         }
    4338          47 : }
    4339             : /* }}} */
    4340             : 
    4341        2080 : void zend_compile_while(zend_ast *ast) /* {{{ */
    4342             : {
    4343        2080 :         zend_ast *cond_ast = ast->child[0];
    4344        2080 :         zend_ast *stmt_ast = ast->child[1];
    4345             :         znode cond_node;
    4346             :         uint32_t opnum_start, opnum_jmp, opnum_cond;
    4347             : 
    4348        2080 :         opnum_jmp = zend_emit_jump(0);
    4349             : 
    4350        2080 :         zend_begin_loop(ZEND_NOP, NULL);
    4351             : 
    4352        2080 :         opnum_start = get_next_op_number(CG(active_op_array));
    4353        2080 :         zend_compile_stmt(stmt_ast);
    4354             : 
    4355        2079 :         opnum_cond = get_next_op_number(CG(active_op_array));
    4356        2079 :         zend_update_jump_target(opnum_jmp, opnum_cond);
    4357        2079 :         zend_compile_expr(&cond_node, cond_ast);
    4358             : 
    4359        2079 :         zend_emit_cond_jump(ZEND_JMPNZ, &cond_node, opnum_start);
    4360             : 
    4361        2079 :         zend_end_loop(opnum_cond, NULL);
    4362        2079 : }
    4363             : /* }}} */
    4364             : 
    4365         319 : void zend_compile_do_while(zend_ast *ast) /* {{{ */
    4366             : {
    4367         319 :         zend_ast *stmt_ast = ast->child[0];
    4368         319 :         zend_ast *cond_ast = ast->child[1];
    4369             : 
    4370             :         znode cond_node;
    4371             :         uint32_t opnum_start, opnum_cond;
    4372             : 
    4373         319 :         zend_begin_loop(ZEND_NOP, NULL);
    4374             : 
    4375         319 :         opnum_start = get_next_op_number(CG(active_op_array));
    4376         319 :         zend_compile_stmt(stmt_ast);
    4377             : 
    4378         319 :         opnum_cond = get_next_op_number(CG(active_op_array));
    4379         319 :         zend_compile_expr(&cond_node, cond_ast);
    4380             : 
    4381         319 :         zend_emit_cond_jump(ZEND_JMPNZ, &cond_node, opnum_start);
    4382             : 
    4383         319 :         zend_end_loop(opnum_cond, NULL);
    4384         319 : }
    4385             : /* }}} */
    4386             : 
    4387        6816 : void zend_compile_expr_list(znode *result, zend_ast *ast) /* {{{ */
    4388             : {
    4389             :         zend_ast_list *list;
    4390             :         uint32_t i;
    4391             : 
    4392        6816 :         result->op_type = IS_CONST;
    4393        6816 :         ZVAL_TRUE(&result->u.constant);
    4394             : 
    4395        6816 :         if (!ast) {
    4396           7 :                 return;
    4397             :         }
    4398             : 
    4399        6809 :         list = zend_ast_get_list(ast);
    4400       13629 :         for (i = 0; i < list->children; ++i) {
    4401        6820 :                 zend_ast *expr_ast = list->child[i];
    4402             : 
    4403        6820 :                 zend_do_free(result);
    4404        6820 :                 zend_compile_expr(result, expr_ast);
    4405             :         }
    4406             : }
    4407             : /* }}} */
    4408             : 
    4409        2272 : void zend_compile_for(zend_ast *ast) /* {{{ */
    4410             : {
    4411        2272 :         zend_ast *init_ast = ast->child[0];
    4412        2272 :         zend_ast *cond_ast = ast->child[1];
    4413        2272 :         zend_ast *loop_ast = ast->child[2];
    4414        2272 :         zend_ast *stmt_ast = ast->child[3];
    4415             : 
    4416             :         znode result;
    4417             :         uint32_t opnum_start, opnum_jmp, opnum_loop;
    4418             : 
    4419        2272 :         zend_compile_expr_list(&result, init_ast);
    4420        2272 :         zend_do_free(&result);
    4421             : 
    4422        2272 :         opnum_jmp = zend_emit_jump(0);
    4423             : 
    4424        2272 :         zend_begin_loop(ZEND_NOP, NULL);
    4425             : 
    4426        2272 :         opnum_start = get_next_op_number(CG(active_op_array));
    4427        2272 :         zend_compile_stmt(stmt_ast);
    4428             : 
    4429        2272 :         opnum_loop = get_next_op_number(CG(active_op_array));
    4430        2272 :         zend_compile_expr_list(&result, loop_ast);
    4431        2272 :         zend_do_free(&result);
    4432             : 
    4433        2272 :         zend_update_jump_target_to_next(opnum_jmp);
    4434        2272 :         zend_compile_expr_list(&result, cond_ast);
    4435        2272 :         zend_do_extended_info();
    4436             : 
    4437        2272 :         zend_emit_cond_jump(ZEND_JMPNZ, &result, opnum_start);
    4438             : 
    4439        2272 :         zend_end_loop(opnum_loop, NULL);
    4440        2272 : }
    4441             : /* }}} */
    4442             : 
    4443       12005 : void zend_compile_foreach(zend_ast *ast) /* {{{ */
    4444             : {
    4445       12005 :         zend_ast *expr_ast = ast->child[0];
    4446       12005 :         zend_ast *value_ast = ast->child[1];
    4447       12005 :         zend_ast *key_ast = ast->child[2];
    4448       12005 :         zend_ast *stmt_ast = ast->child[3];
    4449       12005 :         zend_bool by_ref = value_ast->kind == ZEND_AST_REF;
    4450       21884 :         zend_bool is_variable = zend_is_variable(expr_ast) && !zend_is_call(expr_ast)
    4451       21884 :                 && zend_can_write_to_variable(expr_ast);
    4452             : 
    4453             :         znode expr_node, reset_node, value_node, key_node;
    4454             :         zend_op *opline;
    4455             :         uint32_t opnum_reset, opnum_fetch;
    4456             : 
    4457       12005 :         if (key_ast) {
    4458        5229 :                 if (key_ast->kind == ZEND_AST_REF) {
    4459           2 :                         zend_error_noreturn(E_COMPILE_ERROR, "Key element cannot be a reference");
    4460             :                 }
    4461        5227 :                 if (key_ast->kind == ZEND_AST_ARRAY) {
    4462           1 :                         zend_error_noreturn(E_COMPILE_ERROR, "Cannot use list as key element");
    4463             :                 }
    4464             :         }
    4465             : 
    4466       12002 :         if (by_ref) {
    4467         112 :                 value_ast = value_ast->child[0];
    4468             :         }
    4469             : 
    4470       12106 :         if (by_ref && is_variable) {
    4471         104 :                 zend_compile_var(&expr_node, expr_ast, BP_VAR_W);
    4472             :         } else {
    4473       11898 :                 zend_compile_expr(&expr_node, expr_ast);
    4474             :         }
    4475             : 
    4476       11999 :         if (by_ref) {
    4477         112 :                 zend_separate_if_call_and_write(&expr_node, expr_ast, BP_VAR_W);
    4478             :         }
    4479             : 
    4480       11999 :         opnum_reset = get_next_op_number(CG(active_op_array));
    4481       11999 :         opline = zend_emit_op(&reset_node, by_ref ? ZEND_FE_RESET_RW : ZEND_FE_RESET_R, &expr_node, NULL);
    4482             : 
    4483       11999 :         zend_begin_loop(ZEND_FE_FREE, &reset_node);
    4484             : 
    4485       11999 :         opnum_fetch = get_next_op_number(CG(active_op_array));
    4486       11999 :         opline = zend_emit_op(NULL, by_ref ? ZEND_FE_FETCH_RW : ZEND_FE_FETCH_R, &reset_node, NULL);
    4487             : 
    4488       11999 :         if (is_this_fetch(value_ast)) {
    4489           2 :                 zend_error_noreturn(E_COMPILE_ERROR, "Cannot re-assign $this");
    4490       35955 :         } else if (value_ast->kind == ZEND_AST_VAR &&
    4491       11979 :             zend_try_compile_cv(&value_node, value_ast) == SUCCESS) {
    4492       11979 :                 SET_NODE(opline->op2, &value_node);
    4493             :         } else {
    4494          18 :                 opline->op2_type = IS_VAR;
    4495          18 :                 opline->op2.var = get_temporary_variable(CG(active_op_array));
    4496          18 :                 GET_NODE(&value_node, opline->op2);
    4497          18 :                 if (by_ref) {
    4498           0 :                         zend_emit_assign_ref_znode(value_ast, &value_node);
    4499             :                 } else {
    4500          18 :                         zend_emit_assign_znode(value_ast, &value_node);
    4501             :                 }
    4502             :         }
    4503             : 
    4504       11995 :         if (key_ast) {
    4505        5225 :                 opline = &CG(active_op_array)->opcodes[opnum_fetch];
    4506        5225 :                 zend_make_tmp_result(&key_node, opline);
    4507        5225 :                 zend_emit_assign_znode(key_ast, &key_node);
    4508             :         }
    4509             : 
    4510       11994 :         zend_compile_stmt(stmt_ast);
    4511             : 
    4512       11994 :         zend_emit_jump(opnum_fetch);
    4513             : 
    4514       11994 :         opline = &CG(active_op_array)->opcodes[opnum_reset];
    4515       11994 :         opline->op2.opline_num = get_next_op_number(CG(active_op_array));
    4516             : 
    4517       11994 :         opline = &CG(active_op_array)->opcodes[opnum_fetch];
    4518       11994 :         opline->extended_value = get_next_op_number(CG(active_op_array));
    4519             : 
    4520       11994 :         zend_end_loop(opnum_fetch, &reset_node);
    4521             : 
    4522       11994 :         opline = zend_emit_op(NULL, ZEND_FE_FREE, &reset_node, NULL);
    4523       11994 : }
    4524             : /* }}} */
    4525             : 
    4526       80589 : void zend_compile_if(zend_ast *ast) /* {{{ */
    4527             : {
    4528       80589 :         zend_ast_list *list = zend_ast_get_list(ast);
    4529             :         uint32_t i;
    4530       80589 :         uint32_t *jmp_opnums = NULL;
    4531             : 
    4532       80589 :         if (list->children > 1) {
    4533       22597 :                 jmp_opnums = safe_emalloc(sizeof(uint32_t), list->children - 1, 0);
    4534             :         }
    4535             : 
    4536      184742 :         for (i = 0; i < list->children; ++i) {
    4537      104153 :                 zend_ast *elem_ast = list->child[i];
    4538      104153 :                 zend_ast *cond_ast = elem_ast->child[0];
    4539      104153 :                 zend_ast *stmt_ast = elem_ast->child[1];
    4540             : 
    4541             :                 znode cond_node;
    4542             :                 uint32_t opnum_jmpz;
    4543      104153 :                 if (cond_ast) {
    4544       82690 :                         zend_compile_expr(&cond_node, cond_ast);
    4545       82690 :                         opnum_jmpz = zend_emit_cond_jump(ZEND_JMPZ, &cond_node, 0);
    4546             :                 }
    4547             : 
    4548      104153 :                 zend_compile_stmt(stmt_ast);
    4549             : 
    4550      104153 :                 if (i != list->children - 1) {
    4551       23564 :                         jmp_opnums[i] = zend_emit_jump(0);
    4552             :                 }
    4553             : 
    4554      104153 :                 if (cond_ast) {
    4555       82690 :                         zend_update_jump_target_to_next(opnum_jmpz);
    4556             :                 }
    4557             :         }
    4558             : 
    4559       80589 :         if (list->children > 1) {
    4560       46161 :                 for (i = 0; i < list->children - 1; ++i) {
    4561       23564 :                         zend_update_jump_target_to_next(jmp_opnums[i]);
    4562             :                 }
    4563       22597 :                 efree(jmp_opnums);
    4564             :         }
    4565       80589 : }
    4566             : /* }}} */
    4567             : 
    4568         510 : void zend_compile_switch(zend_ast *ast) /* {{{ */
    4569             : {
    4570         510 :         zend_ast *expr_ast = ast->child[0];
    4571        1020 :         zend_ast_list *cases = zend_ast_get_list(ast->child[1]);
    4572             : 
    4573             :         uint32_t i;
    4574         510 :         zend_bool has_default_case = 0;
    4575             : 
    4576             :         znode expr_node, case_node;
    4577             :         zend_op *opline;
    4578             :         uint32_t *jmpnz_opnums, opnum_default_jmp;
    4579             : 
    4580         510 :         zend_compile_expr(&expr_node, expr_ast);
    4581             : 
    4582         510 :         zend_begin_loop(ZEND_FREE, &expr_node);
    4583             : 
    4584         510 :         case_node.op_type = IS_TMP_VAR;
    4585         510 :         case_node.u.op.var = get_temporary_variable(CG(active_op_array));
    4586             : 
    4587         510 :         jmpnz_opnums = safe_emalloc(sizeof(uint32_t), cases->children, 0);
    4588        2547 :         for (i = 0; i < cases->children; ++i) {
    4589        2038 :                 zend_ast *case_ast = cases->child[i];
    4590        2038 :                 zend_ast *cond_ast = case_ast->child[0];
    4591             :                 znode cond_node;
    4592             : 
    4593        2038 :                 if (!cond_ast) {
    4594         299 :                         if (has_default_case) {
    4595           1 :                                 CG(zend_lineno) = case_ast->lineno;
    4596           1 :                                 zend_error_noreturn(E_COMPILE_ERROR,
    4597             :                                         "Switch statements may only contain one default clause");
    4598             :                         }
    4599         298 :                         has_default_case = 1;
    4600         298 :                         continue;
    4601             :                 }
    4602             : 
    4603        1739 :                 zend_compile_expr(&cond_node, cond_ast);
    4604             : 
    4605        1753 :                 if (expr_node.op_type == IS_CONST
    4606        1739 :                         && Z_TYPE(expr_node.u.constant) == IS_FALSE) {
    4607           0 :                         jmpnz_opnums[i] = zend_emit_cond_jump(ZEND_JMPZ, &cond_node, 0);
    4608        1759 :                 } else if (expr_node.op_type == IS_CONST
    4609        1739 :                         && Z_TYPE(expr_node.u.constant) == IS_TRUE) {
    4610           6 :                         jmpnz_opnums[i] = zend_emit_cond_jump(ZEND_JMPNZ, &cond_node, 0);
    4611             :                 } else {                    
    4612        1733 :                         opline = zend_emit_op(NULL, ZEND_CASE, &expr_node, &cond_node);
    4613        1733 :                         SET_NODE(opline->result, &case_node);
    4614        1733 :                         if (opline->op1_type == IS_CONST) {
    4615           8 :                                 zval_copy_ctor(CT_CONSTANT(opline->op1));
    4616             :                         }
    4617             : 
    4618        1733 :                         jmpnz_opnums[i] = zend_emit_cond_jump(ZEND_JMPNZ, &case_node, 0);
    4619             :                 }
    4620             :         }
    4621             : 
    4622         509 :         opnum_default_jmp = zend_emit_jump(0);
    4623             : 
    4624        2543 :         for (i = 0; i < cases->children; ++i) {
    4625        2034 :                 zend_ast *case_ast = cases->child[i];
    4626        2034 :                 zend_ast *cond_ast = case_ast->child[0];
    4627        2034 :                 zend_ast *stmt_ast = case_ast->child[1];
    4628             : 
    4629        2034 :                 if (cond_ast) {
    4630        1737 :                         zend_update_jump_target_to_next(jmpnz_opnums[i]);
    4631             :                 } else {
    4632         297 :                         zend_update_jump_target_to_next(opnum_default_jmp);
    4633             :                 }
    4634             : 
    4635        2034 :                 zend_compile_stmt(stmt_ast);
    4636             :         }
    4637             : 
    4638         509 :         if (!has_default_case) {
    4639         212 :                 zend_update_jump_target_to_next(opnum_default_jmp);
    4640             :         }
    4641             : 
    4642         509 :         zend_end_loop(get_next_op_number(CG(active_op_array)), &expr_node);
    4643             : 
    4644         509 :         if (expr_node.op_type & (IS_VAR|IS_TMP_VAR)) {
    4645             :                 /* don't use emit_op() to prevent automatic live-range construction */
    4646         126 :                 opline = get_next_op(CG(active_op_array));
    4647         126 :                 opline->opcode = ZEND_FREE;
    4648         126 :                 SET_NODE(opline->op1, &expr_node);
    4649         126 :                 SET_UNUSED(opline->op2);
    4650         383 :         } else if (expr_node.op_type == IS_CONST) {
    4651             :                 zval_dtor(&expr_node.u.constant);
    4652             :         }
    4653             : 
    4654         509 :         efree(jmpnz_opnums);
    4655         509 : }
    4656             : /* }}} */
    4657             : 
    4658        2943 : void zend_compile_try(zend_ast *ast) /* {{{ */
    4659             : {
    4660        2943 :         zend_ast *try_ast = ast->child[0];
    4661        5886 :         zend_ast_list *catches = zend_ast_get_list(ast->child[1]);
    4662        2943 :         zend_ast *finally_ast = ast->child[2];
    4663             : 
    4664             :         uint32_t i, j;
    4665             :         zend_op *opline;
    4666             :         uint32_t try_catch_offset;
    4667        2943 :         uint32_t *jmp_opnums = safe_emalloc(sizeof(uint32_t), catches->children, 0);
    4668        2943 :         uint32_t orig_fast_call_var = CG(context).fast_call_var;
    4669        2943 :         uint32_t orig_try_catch_offset = CG(context).try_catch_offset;
    4670             : 
    4671        2943 :         if (catches->children == 0 && !finally_ast) {
    4672           1 :                 zend_error_noreturn(E_COMPILE_ERROR, "Cannot use try without catch or finally");
    4673             :         }
    4674             : 
    4675             :         /* label: try { } must not be equal to try { label: } */
    4676        2942 :         if (CG(context).labels) {
    4677             :                 zend_label *label;
    4678          18 :                 ZEND_HASH_REVERSE_FOREACH_PTR(CG(context).labels, label) {
    4679           6 :                         if (label->opline_num == get_next_op_number(CG(active_op_array))) {
    4680           2 :                                 zend_emit_op(NULL, ZEND_NOP, NULL, NULL);
    4681             :                         }
    4682           6 :                         break;
    4683             :                 } ZEND_HASH_FOREACH_END();
    4684             :         }
    4685             : 
    4686        2942 :         try_catch_offset = zend_add_try_element(get_next_op_number(CG(active_op_array)));
    4687             : 
    4688        2942 :         if (finally_ast) {
    4689             :                 zend_loop_var fast_call;
    4690         160 :                 if (!(CG(active_op_array)->fn_flags & ZEND_ACC_HAS_FINALLY_BLOCK)) {
    4691         108 :                         CG(active_op_array)->fn_flags |= ZEND_ACC_HAS_FINALLY_BLOCK;
    4692             :                 }
    4693         160 :                 CG(context).fast_call_var = get_temporary_variable(CG(active_op_array));
    4694             : 
    4695             :                 /* Push FAST_CALL on unwind stack */
    4696         160 :                 fast_call.opcode = ZEND_FAST_CALL;
    4697         160 :                 fast_call.var_type = IS_TMP_VAR;
    4698         160 :                 fast_call.var_num = CG(context).fast_call_var;
    4699         160 :                 fast_call.u.try_catch_offset = try_catch_offset;
    4700         160 :                 zend_stack_push(&CG(loop_var_stack), &fast_call);
    4701             :         }
    4702             : 
    4703        2942 :         CG(context).try_catch_offset = try_catch_offset;
    4704             : 
    4705        2942 :         zend_compile_stmt(try_ast);
    4706             : 
    4707        2941 :         if (catches->children != 0) {
    4708        2828 :                 jmp_opnums[0] = zend_emit_jump(0);
    4709             :         }
    4710             : 
    4711        5799 :         for (i = 0; i < catches->children; ++i) {
    4712        2860 :                 zend_ast *catch_ast = catches->child[i];
    4713        5720 :                 zend_ast_list *classes = zend_ast_get_list(catch_ast->child[0]);
    4714        2860 :                 zend_ast *var_ast = catch_ast->child[1];
    4715        2860 :                 zend_ast *stmt_ast = catch_ast->child[2];
    4716        2860 :                 zval *var_name = zend_ast_get_zval(var_ast);
    4717        2860 :                 zend_bool is_last_catch = (i + 1 == catches->children);
    4718             : 
    4719        2860 :                 uint32_t *jmp_multicatch = safe_emalloc(sizeof(uint32_t), classes->children - 1, 0);
    4720             :                 uint32_t opnum_catch;
    4721             : 
    4722        2860 :                 CG(zend_lineno) = catch_ast->lineno;
    4723             : 
    4724        5731 :                 for (j = 0; j < classes->children; j++) {
    4725             : 
    4726        2873 :                         zend_ast *class_ast = classes->child[j];
    4727        2873 :                         zend_bool is_last_class = (j + 1 == classes->children);
    4728             : 
    4729        2873 :                         if (!zend_is_const_default_class_ref(class_ast)) {
    4730           0 :                                 zend_error_noreturn(E_COMPILE_ERROR, "Bad class name in the catch statement");
    4731             :                         }
    4732             : 
    4733        2873 :                         opnum_catch = get_next_op_number(CG(active_op_array));
    4734        2873 :                         if (i == 0 && j == 0) {
    4735        2828 :                                 CG(active_op_array)->try_catch_array[try_catch_offset].catch_op = opnum_catch;
    4736             :                         }
    4737             : 
    4738        2873 :                         opline = get_next_op(CG(active_op_array));
    4739        2873 :                         opline->opcode = ZEND_CATCH;
    4740        2873 :                         opline->op1_type = IS_CONST;
    4741        2873 :                         opline->op1.constant = zend_add_class_name_literal(CG(active_op_array),
    4742             :                                         zend_resolve_class_name_ast(class_ast));
    4743             : 
    4744        2873 :                         if (zend_string_equals_literal(Z_STR_P(var_name), "this")) {
    4745           2 :                                 zend_error_noreturn(E_COMPILE_ERROR, "Cannot re-assign $this");
    4746             :                         }
    4747             : 
    4748        2871 :                         opline->op2_type = IS_CV;
    4749        5742 :                         opline->op2.var = lookup_cv(CG(active_op_array), zend_string_copy(Z_STR_P(var_name)));
    4750             : 
    4751        2871 :                         opline->result.num = is_last_catch && is_last_class;
    4752             : 
    4753        2871 :                         if (!is_last_class) {
    4754          13 :                                 jmp_multicatch[j] = zend_emit_jump(0);
    4755          13 :                                 opline->extended_value = get_next_op_number(CG(active_op_array));
    4756             :                         }
    4757             :                 }
    4758             : 
    4759        2871 :                 for (j = 0; j < classes->children - 1; j++) {
    4760          13 :                         zend_update_jump_target_to_next(jmp_multicatch[j]);
    4761             :                 }
    4762             : 
    4763        2858 :                 efree(jmp_multicatch);
    4764             : 
    4765        2858 :                 zend_compile_stmt(stmt_ast);
    4766             : 
    4767        2858 :                 if (!is_last_catch) {
    4768          32 :                         jmp_opnums[i + 1] = zend_emit_jump(0);
    4769             :                 }
    4770             : 
    4771        2858 :                 opline = &CG(active_op_array)->opcodes[opnum_catch];
    4772        2858 :                 if (!is_last_catch) {
    4773          32 :                         opline->extended_value = get_next_op_number(CG(active_op_array));
    4774             :                 }
    4775             :         }
    4776             : 
    4777        5797 :         for (i = 0; i < catches->children; ++i) {
    4778        2858 :                 zend_update_jump_target_to_next(jmp_opnums[i]);
    4779             :         }
    4780             : 
    4781        2939 :         if (finally_ast) {
    4782             :                 zend_loop_var discard_exception;
    4783         159 :                 uint32_t opnum_jmp = get_next_op_number(CG(active_op_array)) + 1;
    4784             :                 
    4785             :                 /* Pop FAST_CALL from unwind stack */
    4786         159 :                 zend_stack_del_top(&CG(loop_var_stack));
    4787             : 
    4788             :                 /* Push DISCARD_EXCEPTION on unwind stack */
    4789         159 :                 discard_exception.opcode = ZEND_DISCARD_EXCEPTION;
    4790         159 :                 discard_exception.var_type = IS_TMP_VAR;
    4791         159 :                 discard_exception.var_num = CG(context).fast_call_var;
    4792         159 :                 zend_stack_push(&CG(loop_var_stack), &discard_exception);
    4793             : 
    4794         159 :                 CG(zend_lineno) = finally_ast->lineno;
    4795             : 
    4796         159 :                 opline = zend_emit_op(NULL, ZEND_FAST_CALL, NULL, NULL);
    4797         159 :                 opline->op1.num = try_catch_offset;
    4798         159 :                 opline->result_type = IS_TMP_VAR;
    4799         159 :                 opline->result.var = CG(context).fast_call_var;
    4800             : 
    4801         159 :                 zend_emit_op(NULL, ZEND_JMP, NULL, NULL);
    4802             : 
    4803         159 :                 CG(context).in_finally++;
    4804         159 :                 zend_compile_stmt(finally_ast);
    4805         159 :                 CG(context).in_finally--;
    4806             : 
    4807         159 :                 CG(active_op_array)->try_catch_array[try_catch_offset].finally_op = opnum_jmp + 1;
    4808         318 :                 CG(active_op_array)->try_catch_array[try_catch_offset].finally_end
    4809         159 :                         = get_next_op_number(CG(active_op_array));
    4810             : 
    4811         159 :                 opline = zend_emit_op(NULL, ZEND_FAST_RET, NULL, NULL);
    4812         159 :                 opline->op1_type = IS_TMP_VAR;
    4813         159 :                 opline->op1.var = CG(context).fast_call_var;
    4814         159 :                 opline->op2.num = orig_try_catch_offset;
    4815             : 
    4816         159 :                 zend_update_jump_target_to_next(opnum_jmp);
    4817             : 
    4818         159 :                 CG(context).fast_call_var = orig_fast_call_var;
    4819             : 
    4820             :                 /* Pop DISCARD_EXCEPTION from unwind stack */
    4821         159 :                 zend_stack_del_top(&CG(loop_var_stack));
    4822             :         }
    4823             : 
    4824        2939 :         CG(context).try_catch_offset = orig_try_catch_offset;
    4825             : 
    4826        2939 :         efree(jmp_opnums);
    4827        2939 : }
    4828             : /* }}} */
    4829             : 
    4830             : /* Encoding declarations must already be handled during parsing */
    4831          70 : void zend_handle_encoding_declaration(zend_ast *ast) /* {{{ */
    4832             : {
    4833          70 :         zend_ast_list *declares = zend_ast_get_list(ast);
    4834             :         uint32_t i;
    4835         137 :         for (i = 0; i < declares->children; ++i) {
    4836          71 :                 zend_ast *declare_ast = declares->child[i];
    4837          71 :                 zend_ast *name_ast = declare_ast->child[0];
    4838          71 :                 zend_ast *value_ast = declare_ast->child[1];
    4839          71 :                 zend_string *name = zend_ast_get_str(name_ast);
    4840             : 
    4841          71 :                 if (zend_string_equals_literal_ci(name, "encoding")) {
    4842          33 :                         if (value_ast->kind != ZEND_AST_ZVAL) {
    4843           4 :                                 zend_error_noreturn(E_COMPILE_ERROR, "Encoding must be a literal");
    4844             :                         }
    4845             : 
    4846          29 :                         if (CG(multibyte)) {
    4847          28 :                                 zend_string *encoding_name = zval_get_string(zend_ast_get_zval(value_ast));
    4848             : 
    4849             :                                 const zend_encoding *new_encoding, *old_encoding;
    4850             :                                 zend_encoding_filter old_input_filter;
    4851             : 
    4852          28 :                                 CG(encoding_declared) = 1;
    4853             : 
    4854          28 :                                 new_encoding = zend_multibyte_fetch_encoding(ZSTR_VAL(encoding_name));
    4855          28 :                                 if (!new_encoding) {
    4856           8 :                                         zend_error(E_COMPILE_WARNING, "Unsupported encoding [%s]", ZSTR_VAL(encoding_name));
    4857             :                                 } else {
    4858          20 :                                         old_input_filter = LANG_SCNG(input_filter);
    4859          20 :                                         old_encoding = LANG_SCNG(script_encoding);
    4860          20 :                                         zend_multibyte_set_filter(new_encoding);
    4861             : 
    4862             :                                         /* need to re-scan if input filter changed */
    4863          20 :                                         if (old_input_filter != LANG_SCNG(input_filter) ||
    4864             :                                                  (old_input_filter && new_encoding != old_encoding)) {
    4865          14 :                                                 zend_multibyte_yyinput_again(old_input_filter, old_encoding);
    4866             :                                         }
    4867             :                                 }
    4868             : 
    4869             :                                 zend_string_release(encoding_name);
    4870             :                         } else {
    4871           1 :                                 zend_error(E_COMPILE_WARNING, "declare(encoding=...) ignored because "
    4872             :                                         "Zend multibyte feature is turned off by settings");
    4873             :                         }
    4874             :                 }
    4875             :         }
    4876          66 : }
    4877             : /* }}} */
    4878             : 
    4879          46 : static int zend_declare_is_first_statement(zend_ast *ast) /* {{{ */
    4880             : {
    4881          46 :         uint32_t i = 0;
    4882          92 :         zend_ast_list *file_ast = zend_ast_get_list(CG(ast));
    4883             : 
    4884             :         /* Check to see if this declare is preceeded only by declare statements */
    4885          98 :         while (i < file_ast->children) {
    4886          52 :                 if (file_ast->child[i] == ast) {
    4887          38 :                         return SUCCESS;
    4888          14 :                 } else if (file_ast->child[i] == NULL) {
    4889             :                         /* Empty statements are not allowed prior to a declare */
    4890           1 :                         return FAILURE;
    4891          13 :                 } else if (file_ast->child[i]->kind != ZEND_AST_DECLARE) {
    4892             :                         /* declares can only be preceeded by other declares */
    4893           7 :                         return FAILURE;
    4894             :                 }
    4895           6 :                 i++;
    4896             :         }
    4897           0 :         return FAILURE;
    4898             : }
    4899             : /* }}} */
    4900             : 
    4901          53 : void zend_compile_declare(zend_ast *ast) /* {{{ */
    4902             : {
    4903         106 :         zend_ast_list *declares = zend_ast_get_list(ast->child[0]);
    4904          53 :         zend_ast *stmt_ast = ast->child[1];
    4905          53 :         zend_declarables orig_declarables = FC(declarables);
    4906             :         uint32_t i;
    4907             : 
    4908          97 :         for (i = 0; i < declares->children; ++i) {
    4909          53 :                 zend_ast *declare_ast = declares->child[i];
    4910          53 :                 zend_ast *name_ast = declare_ast->child[0];
    4911          53 :                 zend_ast *value_ast = declare_ast->child[1];
    4912             : 
    4913          53 :                 zend_string *name = zend_ast_get_str(name_ast);
    4914          60 :                 if (zend_string_equals_literal_ci(name, "ticks")) {
    4915             :                         zval value_zv;
    4916           7 :                         zend_const_expr_to_zval(&value_zv, value_ast);
    4917           7 :                         FC(declarables).ticks = zval_get_long(&value_zv);
    4918             :                         zval_dtor(&value_zv);
    4919          61 :                 } else if (zend_string_equals_literal_ci(name, "encoding")) {
    4920             : 
    4921          19 :                         if (FAILURE == zend_declare_is_first_statement(ast)) {
    4922           4 :                                 zend_error_noreturn(E_COMPILE_ERROR, "Encoding declaration pragma must be "
    4923             :                                         "the very first statement in the script");
    4924             :                         }
    4925          49 :                 } else if (zend_string_equals_literal_ci(name, "strict_types")) {
    4926             :                         zval value_zv;
    4927             : 
    4928          27 :                         if (FAILURE == zend_declare_is_first_statement(ast)) {
    4929           4 :                                 zend_error_noreturn(E_COMPILE_ERROR, "strict_types declaration must be "
    4930             :                                         "the very first statement in the script");
    4931             :                         }
    4932             : 
    4933          23 :                         if (ast->child[1] != NULL) {
    4934           1 :                                 zend_error_noreturn(E_COMPILE_ERROR, "strict_types declaration must not "
    4935             :                                         "use block mode");
    4936             :                         }
    4937             : 
    4938          22 :                         zend_const_expr_to_zval(&value_zv, value_ast);
    4939             : 
    4940          22 :                         if (Z_TYPE(value_zv) != IS_LONG || (Z_LVAL(value_zv) != 0 && Z_LVAL(value_zv) != 1)) {
    4941           0 :                                 zend_error_noreturn(E_COMPILE_ERROR, "strict_types declaration must have 0 or 1 as its value");
    4942             :                         }
    4943             : 
    4944          22 :                         if (Z_LVAL(value_zv) == 1) {
    4945          18 :                                 CG(active_op_array)->fn_flags |= ZEND_ACC_STRICT_TYPES;
    4946             :                         }
    4947             : 
    4948             :                 } else {
    4949           0 :                         zend_error(E_COMPILE_WARNING, "Unsupported declare '%s'", ZSTR_VAL(name));
    4950             :                 }
    4951             :         }
    4952             : 
    4953          44 :         if (stmt_ast) {
    4954           7 :                 zend_compile_stmt(stmt_ast);
    4955             : 
    4956           6 :                 FC(declarables) = orig_declarables;
    4957             :         }
    4958          43 : }
    4959             : /* }}} */
    4960             : 
    4961      163164 : void zend_compile_stmt_list(zend_ast *ast) /* {{{ */
    4962             : {
    4963      163164 :         zend_ast_list *list = zend_ast_get_list(ast);
    4964             :         uint32_t i;
    4965      486260 :         for (i = 0; i < list->children; ++i) {
    4966      323193 :                 zend_compile_stmt(list->child[i]);
    4967             :         }
    4968      163067 : }
    4969             : /* }}} */
    4970             : 
    4971    90379296 : ZEND_API void zend_set_function_arg_flags(zend_function *func) /* {{{ */
    4972             : {
    4973             :         uint32_t i, n;
    4974             : 
    4975    90379296 :         func->common.arg_flags[0] = 0;
    4976    90379296 :         func->common.arg_flags[1] = 0;
    4977    90379296 :         func->common.arg_flags[2] = 0;
    4978    90379296 :         if (func->common.arg_info) {
    4979    88122831 :                 n = MIN(func->common.num_args, MAX_ARG_FLAG_NUM);
    4980    88122831 :                 i = 0;
    4981   315696340 :                 while (i < n) {
    4982   139450678 :                         ZEND_SET_ARG_FLAG(func, i + 1, func->common.arg_info[i].pass_by_reference);
    4983   139450678 :                         i++;
    4984             :                 }
    4985    88122831 :                 if (UNEXPECTED(func->common.fn_flags & ZEND_ACC_VARIADIC && func->common.arg_info[i].pass_by_reference)) {
    4986      211543 :                         uint32_t pass_by_reference = func->common.arg_info[i].pass_by_reference;
    4987     2632544 :                         while (i < MAX_ARG_FLAG_NUM) {
    4988     2209458 :                                 ZEND_SET_ARG_FLAG(func, i + 1, pass_by_reference);
    4989     2209458 :                                 i++;
    4990             :                         }
    4991             :                 }
    4992             :         }
    4993    90379296 : }
    4994             : /* }}} */
    4995             : 
    4996         766 : static void zend_compile_typename(zend_ast *ast, zend_arg_info *arg_info) /* {{{ */
    4997             : {
    4998         766 :         if (ast->kind == ZEND_AST_TYPE) {
    4999         301 :                 arg_info->type_hint = ast->attr;
    5000             :         } else {
    5001         465 :                 zend_string *class_name = zend_ast_get_str(ast);
    5002         465 :                 zend_uchar type = zend_lookup_builtin_type_by_name(class_name);
    5003             : 
    5004         465 :                 if (type != 0) {
    5005         207 :                         if ((ast->attr & ZEND_NAME_NOT_FQ) != ZEND_NAME_NOT_FQ) {
    5006           2 :                                 zend_error_noreturn(E_COMPILE_ERROR,
    5007             :                                         "Scalar type declaration '%s' must be unqualified",
    5008           2 :                                         ZSTR_VAL(zend_string_tolower(class_name)));
    5009             :                         }
    5010         205 :                         arg_info->type_hint = type;
    5011             :                 } else {
    5012         258 :                         uint32_t fetch_type = zend_get_class_fetch_type_ast(ast);
    5013         258 :                         if (fetch_type == ZEND_FETCH_CLASS_DEFAULT) {
    5014         230 :                                 class_name = zend_resolve_class_name_ast(ast);
    5015         229 :                                 zend_assert_valid_class_name(class_name);
    5016             :                         } else {
    5017          28 :                                 zend_ensure_valid_class_fetch_type(fetch_type);
    5018             :                                 zend_string_addref(class_name);
    5019             :                         }
    5020             : 
    5021         254 :                         arg_info->type_hint = IS_OBJECT;
    5022         254 :                         arg_info->class_name = class_name;
    5023             :                 }
    5024             :         }
    5025         760 : }
    5026             : /* }}} */
    5027             : 
    5028       39951 : void zend_compile_params(zend_ast *ast, zend_ast *return_type_ast) /* {{{ */
    5029             : {
    5030       39951 :         zend_ast_list *list = zend_ast_get_list(ast);
    5031             :         uint32_t i;
    5032       39951 :         zend_op_array *op_array = CG(active_op_array);
    5033             :         zend_arg_info *arg_infos;
    5034             :         
    5035       39951 :         if (return_type_ast) {
    5036             :                 /* Use op_array->arg_info[-1] for return type */
    5037         159 :                 arg_infos = safe_emalloc(sizeof(zend_arg_info), list->children + 1, 0);
    5038         159 :                 arg_infos->name = NULL;
    5039         159 :                 arg_infos->pass_by_reference = (op_array->fn_flags & ZEND_ACC_RETURN_REFERENCE) != 0;
    5040         159 :                 arg_infos->is_variadic = 0;
    5041         159 :                 arg_infos->type_hint = 0;
    5042         159 :                 arg_infos->allow_null = 0;
    5043         159 :                 arg_infos->class_name = NULL;
    5044             : 
    5045         159 :                 if (return_type_ast->attr & ZEND_TYPE_NULLABLE) {
    5046          13 :                         arg_infos->allow_null = 1;
    5047          13 :                         return_type_ast->attr &= ~ZEND_TYPE_NULLABLE;
    5048             :                 }
    5049             : 
    5050         159 :                 zend_compile_typename(return_type_ast, arg_infos);
    5051             : 
    5052         157 :                 if (arg_infos->type_hint == IS_VOID && arg_infos->allow_null) {
    5053           1 :                         zend_error_noreturn(E_COMPILE_ERROR, "Void type cannot be nullable");
    5054             :                 }
    5055             : 
    5056         156 :                 arg_infos++;
    5057         156 :                 op_array->fn_flags |= ZEND_ACC_HAS_RETURN_TYPE;
    5058             :         } else {
    5059       39792 :                 if (list->children == 0) {
    5060       10143 :                         return;
    5061             :                 }
    5062       29649 :                 arg_infos = safe_emalloc(sizeof(zend_arg_info), list->children, 0);
    5063             :         }
    5064             : 
    5065      119151 :         for (i = 0; i < list->children; ++i) {
    5066       89366 :                 zend_ast *param_ast = list->child[i];
    5067       89366 :                 zend_ast *type_ast = param_ast->child[0];
    5068       89366 :                 zend_ast *var_ast = param_ast->child[1];
    5069       89366 :                 zend_ast *default_ast = param_ast->child[2];
    5070       89366 :                 zend_string *name = zend_ast_get_str(var_ast);
    5071       89366 :                 zend_bool is_ref = (param_ast->attr & ZEND_PARAM_REF) != 0;
    5072       89366 :                 zend_bool is_variadic = (param_ast->attr & ZEND_PARAM_VARIADIC) != 0;
    5073             : 
    5074             :                 znode var_node, default_node;
    5075             :                 zend_uchar opcode;
    5076             :                 zend_op *opline;
    5077             :                 zend_arg_info *arg_info;
    5078             : 
    5079       89366 :                 if (zend_is_auto_global(name)) {
    5080           0 :                         zend_error_noreturn(E_COMPILE_ERROR, "Cannot re-assign auto-global variable %s",
    5081             :                                 ZSTR_VAL(name));
    5082             :                 }
    5083             : 
    5084       89366 :                 var_node.op_type = IS_CV;
    5085       89366 :                 var_node.u.op.var = lookup_cv(CG(active_op_array), zend_string_copy(name));
    5086             : 
    5087       89366 :                 if (EX_VAR_TO_NUM(var_node.u.op.var) != i) {
    5088           2 :                         zend_error_noreturn(E_COMPILE_ERROR, "Redefinition of parameter $%s",
    5089             :                                 ZSTR_VAL(name));
    5090       89364 :                 } else if (zend_string_equals_literal(name, "this")) {
    5091           4 :                         zend_error_noreturn(E_COMPILE_ERROR, "Cannot use $this as parameter");
    5092             :                 }
    5093             : 
    5094       89360 :                 if (op_array->fn_flags & ZEND_ACC_VARIADIC) {
    5095           1 :                         zend_error_noreturn(E_COMPILE_ERROR, "Only the last parameter can be variadic");
    5096             :                 }
    5097             : 
    5098       89359 :                 if (is_variadic) {
    5099          42 :                         opcode = ZEND_RECV_VARIADIC;
    5100          42 :                         default_node.op_type = IS_UNUSED;
    5101          42 :                         op_array->fn_flags |= ZEND_ACC_VARIADIC;
    5102             : 
    5103          42 :                         if (default_ast) {
    5104           1 :                                 zend_error_noreturn(E_COMPILE_ERROR,
    5105             :                                         "Variadic parameter cannot have a default value");
    5106             :                         }
    5107       89317 :                 } else if (default_ast) {
    5108             :                         /* we cannot substitute constants here or it will break ReflectionParameter::getDefaultValueConstantName() and ReflectionParameter::isDefaultValueConstant() */
    5109       16540 :                         uint32_t cops = CG(compiler_options);
    5110       16540 :                         CG(compiler_options) |= ZEND_COMPILE_NO_CONSTANT_SUBSTITUTION | ZEND_COMPILE_NO_PERSISTENT_CONSTANT_SUBSTITUTION;
    5111       16540 :                         opcode = ZEND_RECV_INIT;
    5112       16540 :                         default_node.op_type = IS_CONST;
    5113       16540 :                         zend_const_expr_to_zval(&default_node.u.constant, default_ast);
    5114       16538 :                         CG(compiler_options) = cops;
    5115             :                 } else {
    5116       72777 :                         opcode = ZEND_RECV;
    5117       72777 :                         default_node.op_type = IS_UNUSED;
    5118       72777 :                         op_array->required_num_args = i + 1;
    5119             :                 }
    5120             : 
    5121       89356 :                 opline = zend_emit_op(NULL, opcode, NULL, &default_node);
    5122       89356 :                 SET_NODE(opline->result, &var_node);
    5123       89356 :                 opline->op1.num = i + 1;
    5124             : 
    5125       89356 :                 arg_info = &arg_infos[i];
    5126       89356 :                 arg_info->name = zend_string_copy(name);
    5127       89356 :                 arg_info->pass_by_reference = is_ref;
    5128       89356 :                 arg_info->is_variadic = is_variadic;
    5129       89356 :                 arg_info->type_hint = 0;
    5130       89356 :                 arg_info->allow_null = 1;
    5131       89356 :                 arg_info->class_name = NULL;
    5132             : 
    5133       89356 :                 if (type_ast) {
    5134         715 :                         zend_bool has_null_default = default_ast
    5135             :                                 && (Z_TYPE(default_node.u.constant) == IS_NULL
    5136             :                                         || (Z_TYPE(default_node.u.constant) == IS_CONSTANT
    5137         617 :                                                 && strcasecmp(Z_STRVAL(default_node.u.constant), "NULL") == 0));
    5138         607 :                         zend_bool is_explicitly_nullable = (type_ast->attr & ZEND_TYPE_NULLABLE) == ZEND_TYPE_NULLABLE;
    5139             : 
    5140         607 :                         op_array->fn_flags |= ZEND_ACC_HAS_TYPE_HINTS;
    5141         607 :                         arg_info->allow_null = has_null_default || is_explicitly_nullable;
    5142             : 
    5143         607 :                         zend_compile_typename(type_ast, arg_info);
    5144             : 
    5145         603 :                         if (arg_info->type_hint == IS_VOID) {
    5146           1 :                                 zend_error_noreturn(E_COMPILE_ERROR, "void cannot be used as a parameter type");
    5147             :                         }
    5148             : 
    5149         602 :                         if (type_ast->kind == ZEND_AST_TYPE) {
    5150         278 :                                 if (arg_info->type_hint == IS_ARRAY) {
    5151         280 :                                         if (default_ast && !has_null_default
    5152             :                                                 && Z_TYPE(default_node.u.constant) != IS_ARRAY
    5153           3 :                                                 && !Z_CONSTANT(default_node.u.constant)
    5154             :                                         ) {
    5155           1 :                                                 zend_error_noreturn(E_COMPILE_ERROR, "Default value for parameters "
    5156             :                                                         "with array type can only be an array or NULL");
    5157             :                                         }
    5158          12 :                                 } else if (arg_info->type_hint == IS_CALLABLE && default_ast) {
    5159           1 :                                         if (!has_null_default && !Z_CONSTANT(default_node.u.constant)) {
    5160           0 :                                                 zend_error_noreturn(E_COMPILE_ERROR, "Default value for parameters "
    5161             :                                                         "with callable type can only be NULL");
    5162             :                                         }
    5163             :                                 }
    5164             :                         } else {
    5165         324 :                                 if (default_ast && !has_null_default && !Z_CONSTANT(default_node.u.constant)) {
    5166           9 :                                         if (arg_info->class_name) {
    5167           1 :                                                 zend_error_noreturn(E_COMPILE_ERROR, "Default value for parameters "
    5168             :                                                         "with a class type can only be NULL");
    5169           8 :                                         } else switch (arg_info->type_hint) {
    5170             :                                                 case IS_DOUBLE:
    5171           6 :                                                         if (Z_TYPE(default_node.u.constant) != IS_DOUBLE && Z_TYPE(default_node.u.constant) != IS_LONG) {
    5172           1 :                                                                 zend_error_noreturn(E_COMPILE_ERROR, "Default value for parameters "
    5173             :                                                                         "with a float type can only be float, integer, or NULL");
    5174             :                                                         }
    5175           2 :                                                         break;
    5176             :                                                 
    5177             :                                                 case IS_ITERABLE:
    5178           2 :                                                         if (Z_TYPE(default_node.u.constant) != IS_ARRAY) {
    5179           1 :                                                                 zend_error_noreturn(E_COMPILE_ERROR, "Default value for parameters "
    5180             :                                                                         "with iterable type can only be an array or NULL");
    5181             :                                                         }
    5182           1 :                                                         break;
    5183             :                                                         
    5184             :                                                 default:
    5185           9 :                                                         if (!ZEND_SAME_FAKE_TYPE(arg_info->type_hint, Z_TYPE(default_node.u.constant))) {
    5186           2 :                                                                 zend_error_noreturn(E_COMPILE_ERROR, "Default value for parameters "
    5187             :                                                                         "with a %s type can only be %s or NULL",
    5188           2 :                                                                         zend_get_type_by_const(arg_info->type_hint), zend_get_type_by_const(arg_info->type_hint));
    5189             :                                                         }
    5190             :                                                         break;
    5191             :                                         }
    5192             :                                 }
    5193             :                         }
    5194             : 
    5195             :                         /* Allocate cache slot to speed-up run-time class resolution */
    5196         597 :                         if (opline->opcode == ZEND_RECV_INIT) {
    5197          65 :                                 if (arg_info->class_name) {
    5198          20 :                                         zend_alloc_cache_slot(opline->op2.constant);
    5199             :                                 } else {
    5200          45 :                                         Z_CACHE_SLOT(op_array->literals[opline->op2.constant]) = -1;
    5201             :                                 }
    5202             :                         } else {
    5203         532 :                                 if (arg_info->class_name) {
    5204         167 :                                         opline->op2.num = op_array->cache_size;
    5205         167 :                                         op_array->cache_size += sizeof(void*);
    5206             :                                 } else {
    5207         365 :                                         opline->op2.num = -1;
    5208             :                                 }
    5209             :                         }
    5210             :                 } else {
    5211       88749 :                         if (opline->opcode == ZEND_RECV_INIT) {
    5212       16468 :                                 Z_CACHE_SLOT(op_array->literals[opline->op2.constant]) = -1;
    5213             :                         } else {
    5214       72281 :                                 opline->op2.num = -1;
    5215             :                         }
    5216             :                 }       
    5217             :         }
    5218             : 
    5219             :         /* These are assigned at the end to avoid unitialized memory in case of an error */
    5220       29785 :         op_array->num_args = list->children;
    5221       29785 :         op_array->arg_info = arg_infos;
    5222             : 
    5223             :         /* Don't count the variadic argument */
    5224       29785 :         if (op_array->fn_flags & ZEND_ACC_VARIADIC) {
    5225          40 :                 op_array->num_args--;
    5226             :         }
    5227       29785 :         zend_set_function_arg_flags((zend_function*)op_array);
    5228             : }
    5229             : /* }}} */
    5230             : 
    5231         190 : static void zend_compile_closure_binding(znode *closure, zend_ast *uses_ast) /* {{{ */
    5232             : {
    5233         190 :         zend_ast_list *list = zend_ast_get_list(uses_ast);
    5234             :         uint32_t i;
    5235             : 
    5236         389 :         for (i = 0; i < list->children; ++i) {
    5237         201 :                 zend_ast *var_name_ast = list->child[i];
    5238         201 :                 zend_string *var_name = zend_ast_get_str(var_name_ast);
    5239         201 :                 zend_bool by_ref = var_name_ast->attr;
    5240             :                 zend_op *opline;
    5241             : 
    5242         201 :                 if (zend_string_equals_literal(var_name, "this")) {
    5243           1 :                         zend_error_noreturn(E_COMPILE_ERROR, "Cannot use $this as lexical variable");
    5244             :                 }
    5245             : 
    5246         200 :                 if (zend_is_auto_global(var_name)) {
    5247           1 :                         zend_error_noreturn(E_COMPILE_ERROR, "Cannot use auto-global as lexical variable");
    5248             :                 }
    5249             : 
    5250         199 :                 opline = zend_emit_op(NULL, ZEND_BIND_LEXICAL, closure, NULL);
    5251         199 :                 opline->op2_type = IS_CV;
    5252         199 :                 opline->op2.var = lookup_cv(CG(active_op_array), zend_string_copy(var_name));
    5253         199 :                 opline->extended_value = by_ref;
    5254             :         }
    5255         188 : }
    5256             : /* }}} */
    5257             : 
    5258         188 : void zend_compile_closure_uses(zend_ast *ast) /* {{{ */
    5259             : {
    5260         188 :         zend_op_array *op_array = CG(active_op_array);
    5261         188 :         zend_ast_list *list = zend_ast_get_list(ast);
    5262             :         uint32_t i;
    5263             : 
    5264         385 :         for (i = 0; i < list->children; ++i) {
    5265         199 :                 zend_ast *var_ast = list->child[i];
    5266         199 :                 zend_string *var_name = zend_ast_get_str(var_ast);
    5267         199 :                 zend_bool by_ref = var_ast->attr;
    5268             :                 zval zv;
    5269         199 :                 ZVAL_NULL(&zv);
    5270             : 
    5271         210 :                 if (op_array->static_variables
    5272         210 :                                 && zend_hash_exists(op_array->static_variables, var_name)) {
    5273           1 :                         zend_error_noreturn(E_COMPILE_ERROR,
    5274             :                                 "Cannot use variable $%s twice", ZSTR_VAL(var_name));
    5275             :                 }
    5276             : 
    5277             :                 {
    5278             :                         int i;
    5279         388 :                         for (i = 0; i < op_array->last_var; i++) {
    5280         382 :                                 if (zend_string_equals(op_array->vars[i], var_name)) {
    5281           1 :                                         zend_error_noreturn(E_COMPILE_ERROR,
    5282             :                                                 "Cannot use lexical variable $%s as a parameter name", ZSTR_VAL(var_name));
    5283             :                                 }
    5284             :                         }
    5285             :                 }
    5286             : 
    5287         197 :                 zend_compile_static_var_common(var_ast, &zv, by_ref);
    5288             :         }
    5289         186 : }
    5290             : /* }}} */
    5291             : 
    5292       19114 : void zend_begin_method_decl(zend_op_array *op_array, zend_string *name, zend_bool has_body) /* {{{ */
    5293             : {
    5294       19114 :         zend_class_entry *ce = CG(active_class_entry);
    5295       19114 :         zend_bool in_interface = (ce->ce_flags & ZEND_ACC_INTERFACE) != 0;
    5296       19114 :         zend_bool in_trait = (ce->ce_flags & ZEND_ACC_TRAIT) != 0;
    5297       19114 :         zend_bool is_public = (op_array->fn_flags & ZEND_ACC_PUBLIC) != 0;
    5298       19114 :         zend_bool is_static = (op_array->fn_flags & ZEND_ACC_STATIC) != 0;
    5299             : 
    5300             :         zend_string *lcname;
    5301             : 
    5302       19114 :         if (in_interface) {
    5303         134 :                 if (!is_public || (op_array->fn_flags & (ZEND_ACC_FINAL|ZEND_ACC_ABSTRACT))) {
    5304           6 :                         zend_error_noreturn(E_COMPILE_ERROR, "Access type for interface method "
    5305           3 :                                 "%s::%s() must be omitted", ZSTR_VAL(ce->name), ZSTR_VAL(name));
    5306             :                 }
    5307         131 :                 op_array->fn_flags |= ZEND_ACC_ABSTRACT;
    5308             :         }
    5309             : 
    5310       19111 :         if (op_array->fn_flags & ZEND_ACC_ABSTRACT) {
    5311         200 :                 if (op_array->fn_flags & ZEND_ACC_PRIVATE) {
    5312           2 :                         zend_error_noreturn(E_COMPILE_ERROR, "%s function %s::%s() cannot be declared private",
    5313           1 :                                 in_interface ? "Interface" : "Abstract", ZSTR_VAL(ce->name), ZSTR_VAL(name));
    5314             :                 }
    5315             : 
    5316         199 :                 if (has_body) {
    5317           2 :                         zend_error_noreturn(E_COMPILE_ERROR, "%s function %s::%s() cannot contain body",
    5318           1 :                                 in_interface ? "Interface" : "Abstract", ZSTR_VAL(ce->name), ZSTR_VAL(name));
    5319             :                 }
    5320             : 
    5321         198 :                 ce->ce_flags |= ZEND_ACC_IMPLICIT_ABSTRACT_CLASS;
    5322       18911 :         } else if (!has_body) {
    5323           2 :                 zend_error_noreturn(E_COMPILE_ERROR, "Non-abstract method %s::%s() must contain body",
    5324           1 :                         ZSTR_VAL(ce->name), ZSTR_VAL(name));
    5325             :         }
    5326             : 
    5327       19108 :         op_array->scope = ce;
    5328       19108 :         op_array->function_name = zend_string_copy(name);
    5329             : 
    5330       19108 :         lcname = zend_string_tolower(name);
    5331       19108 :         lcname = zend_new_interned_string(lcname);
    5332             : 
    5333       38216 :         if (zend_hash_add_ptr(&ce->function_table, lcname, op_array) == NULL) {
    5334           2 :                 zend_error_noreturn(E_COMPILE_ERROR, "Cannot redeclare %s::%s()",
    5335           1 :                         ZSTR_VAL(ce->name), ZSTR_VAL(name));
    5336             :         }
    5337             : 
    5338       19107 :         if (in_interface) {
    5339         131 :                 if (zend_string_equals_literal(lcname, ZEND_CALL_FUNC_NAME)) {
    5340           1 :                         if (!is_public || is_static) {
    5341           1 :                                 zend_error(E_WARNING, "The magic method __call() must have "
    5342             :                                         "public visibility and cannot be static");
    5343             :                         }
    5344         130 :                 } else if (zend_string_equals_literal(lcname, ZEND_CALLSTATIC_FUNC_NAME)) {
    5345           1 :                         if (!is_public || !is_static) {
    5346           1 :                                 zend_error(E_WARNING, "The magic method __callStatic() must have "
    5347             :                                         "public visibility and be static");
    5348             :                         }
    5349         128 :                 } else if (zend_string_equals_literal(lcname, ZEND_GET_FUNC_NAME)) {
    5350           0 :                         if (!is_public || is_static) {
    5351           0 :                                 zend_error(E_WARNING, "The magic method __get() must have "
    5352             :                                         "public visibility and cannot be static");
    5353             :                         }
    5354         128 :                 } else if (zend_string_equals_literal(lcname, ZEND_SET_FUNC_NAME)) {
    5355           0 :                         if (!is_public || is_static) {
    5356           0 :                                 zend_error(E_WARNING, "The magic method __set() must have "
    5357             :                                         "public visibility and cannot be static");
    5358             :                         }
    5359         128 :                 } else if (zend_string_equals_literal(lcname, ZEND_UNSET_FUNC_NAME)) {
    5360           0 :                         if (!is_public || is_static) {
    5361           0 :                                 zend_error(E_WARNING, "The magic method __unset() must have "
    5362             :                                         "public visibility and cannot be static");
    5363             :                         }
    5364         128 :                 } else if (zend_string_equals_literal(lcname, ZEND_ISSET_FUNC_NAME)) {
    5365           0 :                         if (!is_public || is_static) {
    5366           0 :                                 zend_error(E_WARNING, "The magic method __isset() must have "
    5367             :                                         "public visibility and cannot be static");
    5368             :                         }
    5369         128 :                 } else if (zend_string_equals_literal(lcname, ZEND_TOSTRING_FUNC_NAME)) {
    5370           0 :                         if (!is_public || is_static) {
    5371           0 :                                 zend_error(E_WARNING, "The magic method __toString() must have "
    5372             :                                         "public visibility and cannot be static");
    5373             :                         }
    5374         129 :                 } else if (zend_string_equals_literal(lcname, ZEND_INVOKE_FUNC_NAME)) {
    5375           1 :                         if (!is_public || is_static) {
    5376           1 :                                 zend_error(E_WARNING, "The magic method __invoke() must have "
    5377             :                                         "public visibility and cannot be static");
    5378             :                         }
    5379         127 :                 } else if (zend_string_equals_literal(lcname, ZEND_DEBUGINFO_FUNC_NAME)) {
    5380           0 :                         if (!is_public || is_static) {
    5381           0 :                                 zend_error(E_WARNING, "The magic method __debugInfo() must have "
    5382             :                                         "public visibility and cannot be static");
    5383             :                         }
    5384             :                 }
    5385             :         } else {
    5386       19040 :                 if (!in_trait && zend_string_equals_ci(lcname, ce->name)) {
    5387          63 :                         if (!ce->constructor) {
    5388          53 :                                 ce->constructor = (zend_function *) op_array;
    5389             :                         }
    5390       20874 :                 } else if (zend_string_equals_literal(lcname, ZEND_CONSTRUCTOR_FUNC_NAME)) {
    5391        1960 :                         ce->constructor = (zend_function *) op_array;
    5392       17131 :                 } else if (zend_string_equals_literal(lcname, ZEND_DESTRUCTOR_FUNC_NAME)) {
    5393         177 :                         ce->destructor = (zend_function *) op_array;
    5394       16806 :                 } else if (zend_string_equals_literal(lcname, ZEND_CLONE_FUNC_NAME)) {
    5395          29 :                         ce->clone = (zend_function *) op_array;
    5396       16824 :                 } else if (zend_string_equals_literal(lcname, ZEND_CALL_FUNC_NAME)) {
    5397          76 :                         if (!is_public || is_static) {
    5398           2 :                                 zend_error(E_WARNING, "The magic method __call() must have "
    5399             :                                         "public visibility and cannot be static");
    5400             :                         }
    5401          76 :                         ce->__call = (zend_function *) op_array;
    5402       16704 :                 } else if (zend_string_equals_literal(lcname, ZEND_CALLSTATIC_FUNC_NAME)) {
    5403          32 :                         if (!is_public || !is_static) {
    5404           1 :                                 zend_error(E_WARNING, "The magic method __callStatic() must have "
    5405             :                                         "public visibility and be static");
    5406             :                         }
    5407          32 :                         ce->__callstatic = (zend_function *) op_array;
    5408       16717 :                 } else if (zend_string_equals_literal(lcname, ZEND_GET_FUNC_NAME)) {
    5409          77 :                         if (!is_public || is_static) {
    5410           0 :                                 zend_error(E_WARNING, "The magic method __get() must have "
    5411             :                                         "public visibility and cannot be static");
    5412             :                         }
    5413          77 :                         ce->__get = (zend_function *) op_array;
    5414          77 :                         ce->ce_flags |= ZEND_ACC_USE_GUARDS;
    5415       16626 :                 } else if (zend_string_equals_literal(lcname, ZEND_SET_FUNC_NAME)) {
    5416          63 :                         if (!is_public || is_static) {
    5417           2 :                                 zend_error(E_WARNING, "The magic method __set() must have "
    5418             :                                         "public visibility and cannot be static");
    5419             :                         }
    5420          63 :                         ce->__set = (zend_function *) op_array;
    5421          63 :                         ce->ce_flags |= ZEND_ACC_USE_GUARDS;
    5422       16518 :                 } else if (zend_string_equals_literal(lcname, ZEND_UNSET_FUNC_NAME)) {
    5423          18 :                         if (!is_public || is_static) {
    5424           3 :                                 zend_error(E_WARNING, "The magic method __unset() must have "
    5425             :                                         "public visibility and cannot be static");
    5426             :                         }
    5427          18 :                         ce->__unset = (zend_function *) op_array;
    5428          18 :                         ce->ce_flags |= ZEND_ACC_USE_GUARDS;
    5429       16502 :                 } else if (zend_string_equals_literal(lcname, ZEND_ISSET_FUNC_NAME)) {
    5430          20 :                         if (!is_public || is_static) {
    5431           0 :                                 zend_error(E_WARNING, "The magic method __isset() must have "
    5432             :                                         "public visibility and cannot be static");
    5433             :                         }
    5434          20 :                         ce->__isset = (zend_function *) op_array;
    5435          20 :                         ce->ce_flags |= ZEND_ACC_USE_GUARDS;
    5436       17174 :                 } else if (zend_string_equals_literal(lcname, ZEND_TOSTRING_FUNC_NAME)) {
    5437         712 :                         if (!is_public || is_static) {
    5438           1 :                                 zend_error(E_WARNING, "The magic method __toString() must have "
    5439             :                                         "public visibility and cannot be static");
    5440             :                         }
    5441         712 :                         ce->__tostring = (zend_function *) op_array;
    5442       15768 :                 } else if (zend_string_equals_literal(lcname, ZEND_INVOKE_FUNC_NAME)) {
    5443          18 :                         if (!is_public || is_static) {
    5444           2 :                                 zend_error(E_WARNING, "The magic method __invoke() must have "
    5445             :                                         "public visibility and cannot be static");
    5446             :                         }
    5447       15746 :                 } else if (zend_string_equals_literal(lcname, ZEND_DEBUGINFO_FUNC_NAME)) {
    5448          14 :                         if (!is_public || is_static) {
    5449           0 :                                 zend_error(E_WARNING, "The magic method __debugInfo() must have "
    5450             :                                         "public visibility and cannot be static");
    5451             :                         }
    5452          14 :                         ce->__debugInfo = (zend_function *) op_array;
    5453       15718 :                 } else if (!is_static) {
    5454        8009 :                         op_array->fn_flags |= ZEND_ACC_ALLOW_STATIC;
    5455             :                 }
    5456             :         }
    5457             : 
    5458             :         zend_string_release(lcname);
    5459       19107 : }
    5460             : /* }}} */
    5461             : 
    5462       20849 : static void zend_begin_func_decl(znode *result, zend_op_array *op_array, zend_ast_decl *decl) /* {{{ */
    5463             : {
    5464       20849 :         zend_ast *params_ast = decl->child[0];
    5465             :         zend_string *unqualified_name, *name, *lcname, *key;
    5466             :         zend_op *opline;
    5467             : 
    5468       20849 :         unqualified_name = decl->name;
    5469       20849 :         op_array->function_name = name = zend_prefix_with_ns(unqualified_name);
    5470       20849 :         lcname = zend_string_tolower(name);
    5471             : 
    5472       20849 :         if (FC(imports_function)) {
    5473           5 :                 zend_string *import_name = zend_hash_find_ptr_lc(
    5474           5 :                         FC(imports_function), ZSTR_VAL(unqualified_name), ZSTR_LEN(unqualified_name));
    5475           5 :                 if (import_name && !zend_string_equals_ci(lcname, import_name)) {
    5476           2 :                         zend_error_noreturn(E_COMPILE_ERROR, "Cannot declare function %s "
    5477             :                                 "because the name is already in use", ZSTR_VAL(name));
    5478             :                 }
    5479             :         }
    5480             : 
    5481       20924 :         if (zend_string_equals_literal(lcname, ZEND_AUTOLOAD_FUNC_NAME)
    5482          77 :                 && zend_ast_get_list(params_ast)->children != 1
    5483             :         ) {
    5484           1 :                 zend_error_noreturn(E_COMPILE_ERROR, "%s() must take exactly 1 argument",
    5485             :                         ZEND_AUTOLOAD_FUNC_NAME);
    5486             :         }
    5487             : 
    5488       20846 :         key = zend_build_runtime_definition_key(lcname, decl->lex_pos);
    5489       20846 :         zend_hash_update_ptr(CG(function_table), key, op_array);
    5490             : 
    5491       20846 :         if (op_array->fn_flags & ZEND_ACC_CLOSURE) {
    5492         585 :                 opline = zend_emit_op_tmp(result, ZEND_DECLARE_LAMBDA_FUNCTION, NULL, NULL);
    5493         585 :                 opline->op1_type = IS_CONST;
    5494         585 :                 LITERAL_STR(opline->op1, key);
    5495             :         } else {
    5496       20261 :                 opline = get_next_op(CG(active_op_array));
    5497       20261 :                 opline->opcode = ZEND_DECLARE_FUNCTION;
    5498       20261 :                 opline->op1_type = IS_CONST;
    5499       40522 :                 LITERAL_STR(opline->op1, zend_string_copy(lcname));
    5500             :                 /* RTD key is placed after lcname literal in op1 */
    5501       20261 :                 zend_add_literal_string(CG(active_op_array), &key);
    5502       20261 :                 SET_UNUSED(opline->op2);
    5503             :         }
    5504             : 
    5505             :         zend_string_release(lcname);
    5506       20846 : }
    5507             : /* }}} */
    5508             : 
    5509       39963 : void zend_compile_func_decl(znode *result, zend_ast *ast) /* {{{ */
    5510             : {
    5511       39963 :         zend_ast_decl *decl = (zend_ast_decl *) ast;
    5512       39963 :         zend_ast *params_ast = decl->child[0];
    5513       39963 :         zend_ast *uses_ast = decl->child[1];
    5514       39963 :         zend_ast *stmt_ast = decl->child[2];
    5515       39963 :         zend_ast *return_type_ast = decl->child[3];
    5516       39963 :         zend_bool is_method = decl->kind == ZEND_AST_METHOD;
    5517             : 
    5518       39963 :         zend_op_array *orig_op_array = CG(active_op_array);
    5519       39963 :         zend_op_array *op_array = zend_arena_alloc(&CG(arena), sizeof(zend_op_array));
    5520             :         zend_oparray_context orig_oparray_context;
    5521             : 
    5522       39963 :         init_op_array(op_array, ZEND_USER_FUNCTION, INITIAL_OP_ARRAY_SIZE);
    5523             : 
    5524       39963 :         op_array->fn_flags |= (orig_op_array->fn_flags & ZEND_ACC_STRICT_TYPES);
    5525       39963 :         op_array->fn_flags |= decl->flags;
    5526       39963 :         op_array->line_start = decl->start_lineno;
    5527       39963 :         op_array->line_end = decl->end_lineno;
    5528       39963 :         if (decl->doc_comment) {
    5529        4856 :                 op_array->doc_comment = zend_string_copy(decl->doc_comment);
    5530             :         }
    5531       39963 :         if (decl->kind == ZEND_AST_CLOSURE) {
    5532         585 :                 op_array->fn_flags |= ZEND_ACC_CLOSURE;
    5533             :         }
    5534             : 
    5535       39963 :         if (is_method) {
    5536       19114 :                 zend_bool has_body = stmt_ast != NULL;
    5537       19114 :                 zend_begin_method_decl(op_array, decl->name, has_body);
    5538             :         } else {
    5539       20849 :                 zend_begin_func_decl(result, op_array, decl);
    5540       20846 :                 if (uses_ast) {
    5541         190 :                         zend_compile_closure_binding(result, uses_ast);
    5542             :                 }
    5543             :         }
    5544             : 
    5545       39951 :         CG(active_op_array) = op_array;
    5546             : 
    5547       39951 :         zend_oparray_context_begin(&orig_oparray_context);
    5548             : 
    5549       39951 :         if (CG(compiler_options) & ZEND_COMPILE_EXTENDED_INFO) {
    5550           0 :                 zend_op *opline_ext = zend_emit_op(NULL, ZEND_EXT_NOP, NULL, NULL);
    5551           0 :                 opline_ext->lineno = decl->start_lineno;
    5552             :         }
    5553             : 
    5554             :         {
    5555             :                 /* Push a separator to the loop variable stack */
    5556             :                 zend_loop_var dummy_var;
    5557       39951 :                 dummy_var.opcode = ZEND_RETURN;
    5558             : 
    5559       39951 :                 zend_stack_push(&CG(loop_var_stack), (void *) &dummy_var);
    5560             :         }
    5561             : 
    5562       39951 :         zend_compile_params(params_ast, return_type_ast);
    5563       39928 :         if (CG(active_op_array)->fn_flags & ZEND_ACC_GENERATOR) {
    5564         206 :                 zend_mark_function_as_generator();
    5565         205 :                 zend_emit_op(NULL, ZEND_GENERATOR_CREATE, NULL, NULL);
    5566             :         }
    5567       39927 :         if (uses_ast) {
    5568         188 :                 zend_compile_closure_uses(uses_ast);
    5569             :         }
    5570       39925 :         zend_compile_stmt(stmt_ast);
    5571             : 
    5572       39897 :         if (is_method) {
    5573       38176 :                 zend_check_magic_method_implementation(
    5574       19088 :                         CG(active_class_entry), (zend_function *) op_array, E_COMPILE_ERROR);
    5575             :         }
    5576             : 
    5577             :         /* put the implicit return on the really last line */
    5578       39881 :         CG(zend_lineno) = decl->end_lineno;
    5579             : 
    5580       39881 :         zend_do_extended_info();
    5581       39881 :         zend_emit_final_return(0);
    5582             : 
    5583       39881 :         pass_two(CG(active_op_array));
    5584       39874 :         zend_oparray_context_end(&orig_oparray_context);
    5585             : 
    5586             :         /* Pop the loop variable stack separator */
    5587       39874 :         zend_stack_del_top(&CG(loop_var_stack));
    5588             : 
    5589       39874 :         CG(active_op_array) = orig_op_array;
    5590       39874 : }
    5591             : /* }}} */
    5592             : 
    5593        2670 : void zend_compile_prop_decl(zend_ast *ast) /* {{{ */
    5594             : {
    5595        2670 :         zend_ast_list *list = zend_ast_get_list(ast);
    5596        2670 :         uint32_t flags = list->attr;
    5597        2670 :         zend_class_entry *ce = CG(active_class_entry);
    5598        2670 :         uint32_t i, children = list->children;
    5599             : 
    5600        2670 :         if (ce->ce_flags & ZEND_ACC_INTERFACE) {
    5601           1 :                 zend_error_noreturn(E_COMPILE_ERROR, "Interfaces may not include member variables");
    5602             :         }
    5603             : 
    5604        2669 :         if (flags & ZEND_ACC_ABSTRACT) {
    5605           1 :                 zend_error_noreturn(E_COMPILE_ERROR, "Properties cannot be declared abstract");
    5606             :         }
    5607             : 
    5608        5381 :         for (i = 0; i < children; ++i) {
    5609        2716 :                 zend_ast *prop_ast = list->child[i];
    5610        2716 :                 zend_ast *name_ast = prop_ast->child[0];
    5611        2716 :                 zend_ast *value_ast = prop_ast->child[1];
    5612        2716 :                 zend_ast *doc_comment_ast = prop_ast->child[2];
    5613        2716 :                 zend_string *name = zend_ast_get_str(name_ast);
    5614        2716 :                 zend_string *doc_comment = NULL;
    5615             :                 zval value_zv;
    5616             : 
    5617             :                 /* Doc comment has been appended as last element in ZEND_AST_PROP_ELEM ast */
    5618        2716 :                 if (doc_comment_ast) {
    5619          55 :                         doc_comment = zend_string_copy(zend_ast_get_str(doc_comment_ast));
    5620             :                 }
    5621             : 
    5622        2716 :                 if (flags & ZEND_ACC_FINAL) {
    5623           2 :                         zend_error_noreturn(E_COMPILE_ERROR, "Cannot declare property %s::$%s final, "
    5624             :                                 "the final modifier is allowed only for methods and classes",
    5625           1 :                                 ZSTR_VAL(ce->name), ZSTR_VAL(name));
    5626             :                 }
    5627             : 
    5628        2715 :                 if (zend_hash_exists(&ce->properties_info, name)) {
    5629           2 :                         zend_error_noreturn(E_COMPILE_ERROR, "Cannot redeclare %s::$%s",
    5630           1 :                                 ZSTR_VAL(ce->name), ZSTR_VAL(name));
    5631             :                 }
    5632             : 
    5633        2714 :                 if (value_ast) {
    5634        1469 :                         zend_const_expr_to_zval(&value_zv, value_ast);
    5635             :                 } else {
    5636        1245 :                         ZVAL_NULL(&value_zv);
    5637             :                 }
    5638             : 
    5639        2713 :                 name = zend_new_interned_string_safe(name);
    5640        2713 :                 zend_declare_property_ex(ce, name, &value_zv, flags, doc_comment);
    5641             :         }
    5642        2665 : }
    5643             : /* }}} */
    5644             : 
    5645         371 : void zend_compile_class_const_decl(zend_ast *ast) /* {{{ */
    5646             : {
    5647         371 :         zend_ast_list *list = zend_ast_get_list(ast);
    5648         371 :         zend_class_entry *ce = CG(active_class_entry);
    5649             :         uint32_t i;
    5650             : 
    5651         371 :         if ((ce->ce_flags & ZEND_ACC_TRAIT) != 0) {
    5652           1 :                 zend_error_noreturn(E_COMPILE_ERROR, "Traits cannot have constants");
    5653             :                 return;
    5654             :         }
    5655             : 
    5656         735 :         for (i = 0; i < list->children; ++i) {
    5657         376 :                 zend_ast *const_ast = list->child[i];
    5658         376 :                 zend_ast *name_ast = const_ast->child[0];
    5659         376 :                 zend_ast *value_ast = const_ast->child[1];
    5660         376 :                 zend_ast *doc_comment_ast = const_ast->child[2];
    5661         376 :                 zend_string *name = zend_ast_get_str(name_ast);
    5662         384 :                 zend_string *doc_comment = doc_comment_ast ? zend_string_copy(zend_ast_get_str(doc_comment_ast)) : NULL;
    5663             :                 zval value_zv;
    5664             : 
    5665         376 :                 if (UNEXPECTED(ast->attr & (ZEND_ACC_STATIC|ZEND_ACC_ABSTRACT|ZEND_ACC_FINAL))) {
    5666           3 :                         if (ast->attr & ZEND_ACC_STATIC) {
    5667           1 :                                 zend_error_noreturn(E_COMPILE_ERROR, "Cannot use 'static' as constant modifier");
    5668           2 :                         } else if (ast->attr & ZEND_ACC_ABSTRACT) {
    5669           1 :                                 zend_error_noreturn(E_COMPILE_ERROR, "Cannot use 'abstract' as constant modifier");
    5670           1 :                         } else if (ast->attr & ZEND_ACC_FINAL) {
    5671           1 :                                 zend_error_noreturn(E_COMPILE_ERROR, "Cannot use 'final' as constant modifier");
    5672             :                         }
    5673             :                 }
    5674             : 
    5675         373 :                 zend_const_expr_to_zval(&value_zv, value_ast);
    5676             : 
    5677         370 :                 name = zend_new_interned_string_safe(name);
    5678         370 :                 zend_declare_class_constant_ex(ce, name, &value_zv, ast->attr, doc_comment);
    5679             :         }
    5680             : }
    5681             : /* }}} */
    5682             : 
    5683          95 : static zend_trait_method_reference *zend_compile_method_ref(zend_ast *ast) /* {{{ */
    5684             : {
    5685          95 :         zend_ast *class_ast = ast->child[0];
    5686          95 :         zend_ast *method_ast = ast->child[1];
    5687             : 
    5688          95 :         zend_trait_method_reference *method_ref = emalloc(sizeof(zend_trait_method_reference));
    5689          95 :         method_ref->ce = NULL;
    5690          95 :         method_ref->method_name = zend_string_copy(zend_ast_get_str(method_ast));
    5691             : 
    5692          95 :         if (class_ast) {
    5693          53 :                 method_ref->class_name = zend_resolve_class_name_ast(class_ast);
    5694             :         } else {
    5695          42 :                 method_ref->class_name = NULL;
    5696             :         }
    5697             : 
    5698          95 :         return method_ref;
    5699             : }
    5700             : /* }}} */
    5701             : 
    5702          22 : static zend_string **zend_compile_name_list(zend_ast *ast) /* {{{ */
    5703             : {
    5704          22 :         zend_ast_list *list = zend_ast_get_list(ast);
    5705          22 :         zend_string **names = safe_emalloc(sizeof(zend_string *), list->children + 1, 0);
    5706             :         uint32_t i;
    5707             : 
    5708          45 :         for (i = 0; i < list->children; ++i) {
    5709          23 :                 zend_ast *name_ast = list->child[i];
    5710          23 :                 names[i] = zend_resolve_class_name_ast(name_ast);
    5711             :         }
    5712             : 
    5713          22 :         names[list->children] = NULL;
    5714             : 
    5715          22 :         return names;
    5716             : }
    5717             : /* }}} */
    5718             : 
    5719          22 : static void zend_compile_trait_precedence(zend_ast *ast) /* {{{ */
    5720             : {
    5721          22 :         zend_ast *method_ref_ast = ast->child[0];
    5722          22 :         zend_ast *insteadof_ast = ast->child[1];
    5723             : 
    5724          22 :         zend_trait_precedence *precedence = emalloc(sizeof(zend_trait_precedence));
    5725          22 :         precedence->trait_method = zend_compile_method_ref(method_ref_ast);
    5726          22 :         precedence->exclude_from_classes
    5727             :                 = (void *) zend_compile_name_list(insteadof_ast);
    5728             : 
    5729          22 :         zend_add_to_list(&CG(active_class_entry)->trait_precedences, precedence);
    5730          22 : }
    5731             : /* }}} */
    5732             : 
    5733          76 : static void zend_compile_trait_alias(zend_ast *ast) /* {{{ */
    5734             : {
    5735          76 :         zend_ast *method_ref_ast = ast->child[0];
    5736          76 :         zend_ast *alias_ast = ast->child[1];
    5737          76 :         uint32_t modifiers = ast->attr;
    5738             : 
    5739             :         zend_trait_alias *alias;
    5740             : 
    5741          76 :         if (modifiers == ZEND_ACC_STATIC) {
    5742           1 :                 zend_error_noreturn(E_COMPILE_ERROR, "Cannot use 'static' as method modifier");
    5743          75 :         } else if (modifiers == ZEND_ACC_ABSTRACT) {
    5744           1 :                 zend_error_noreturn(E_COMPILE_ERROR, "Cannot use 'abstract' as method modifier");
    5745          74 :         } else if (modifiers == ZEND_ACC_FINAL) {
    5746           1 :                 zend_error_noreturn(E_COMPILE_ERROR, "Cannot use 'final' as method modifier");
    5747             :         }
    5748             : 
    5749          73 :         alias = emalloc(sizeof(zend_trait_alias));
    5750          73 :         alias->trait_method = zend_compile_method_ref(method_ref_ast);
    5751          73 :         alias->modifiers = modifiers;
    5752             : 
    5753          73 :         if (alias_ast) {
    5754          62 :                 alias->alias = zend_string_copy(zend_ast_get_str(alias_ast));
    5755             :         } else {
    5756          11 :                 alias->alias = NULL;
    5757             :         }
    5758             : 
    5759          73 :         zend_add_to_list(&CG(active_class_entry)->trait_aliases, alias);
    5760          73 : }
    5761             : /* }}} */
    5762             : 
    5763         223 : void zend_compile_use_trait(zend_ast *ast) /* {{{ */
    5764             : {
    5765         446 :         zend_ast_list *traits = zend_ast_get_list(ast->child[0]);
    5766         289 :         zend_ast_list *adaptations = ast->child[1] ? zend_ast_get_list(ast->child[1]) : NULL;
    5767         223 :         zend_class_entry *ce = CG(active_class_entry);
    5768             :         zend_op *opline;
    5769             :         uint32_t i;
    5770             : 
    5771         488 :         for (i = 0; i < traits->children; ++i) {
    5772         266 :                 zend_ast *trait_ast = traits->child[i];
    5773         266 :                 zend_string *name = zend_ast_get_str(trait_ast);
    5774             : 
    5775         266 :                 if (ce->ce_flags & ZEND_ACC_INTERFACE) {
    5776           1 :                         zend_error_noreturn(E_COMPILE_ERROR, "Cannot use traits inside of interfaces. "
    5777           1 :                                 "%s is used in %s", ZSTR_VAL(name), ZSTR_VAL(ce->name));
    5778             :                 }
    5779             : 
    5780         265 :                 switch (zend_get_class_fetch_type(name)) {
    5781             :                         case ZEND_FETCH_CLASS_SELF:
    5782             :                         case ZEND_FETCH_CLASS_PARENT:
    5783             :                         case ZEND_FETCH_CLASS_STATIC:
    5784           0 :                                 zend_error_noreturn(E_COMPILE_ERROR, "Cannot use '%s' as trait name "
    5785             :                                         "as it is reserved", ZSTR_VAL(name));
    5786             :                                 break;
    5787             :                 }
    5788             : 
    5789         265 :                 opline = get_next_op(CG(active_op_array));
    5790         265 :                 opline->opcode = ZEND_ADD_TRAIT;
    5791         265 :                 SET_NODE(opline->op1, &FC(implementing_class));
    5792         265 :                 opline->op2_type = IS_CONST;
    5793         265 :                 opline->op2.constant = zend_add_class_name_literal(CG(active_op_array),
    5794             :                         zend_resolve_class_name_ast(trait_ast));
    5795             : 
    5796         265 :                 ce->num_traits++;
    5797             :         }
    5798             : 
    5799         222 :         if (!adaptations) {
    5800         156 :                 return;
    5801             :         }
    5802             : 
    5803         161 :         for (i = 0; i < adaptations->children; ++i) {
    5804          98 :                 zend_ast *adaptation_ast = adaptations->child[i];
    5805          98 :                 switch (adaptation_ast->kind) {
    5806             :                         case ZEND_AST_TRAIT_PRECEDENCE:
    5807          22 :                                 zend_compile_trait_precedence(adaptation_ast);
    5808          22 :                                 break;
    5809             :                         case ZEND_AST_TRAIT_ALIAS:
    5810          76 :                                 zend_compile_trait_alias(adaptation_ast);
    5811             :                                 break;
    5812             :                         EMPTY_SWITCH_DEFAULT_CASE()
    5813             :                 }
    5814             :         }
    5815             : }
    5816             : /* }}} */
    5817             : 
    5818         378 : void zend_compile_implements(znode *class_node, zend_ast *ast) /* {{{ */
    5819             : {
    5820         378 :         zend_ast_list *list = zend_ast_get_list(ast);
    5821             :         uint32_t i;
    5822         794 :         for (i = 0; i < list->children; ++i) {
    5823         418 :                 zend_ast *class_ast = list->child[i];
    5824         418 :                 zend_string *name = zend_ast_get_str(class_ast);
    5825             : 
    5826             :                 zend_op *opline;
    5827             : 
    5828         418 :                 if (!zend_is_const_default_class_ref(class_ast)) {
    5829           2 :                         zend_error_noreturn(E_COMPILE_ERROR,
    5830             :                                 "Cannot use '%s' as interface name as it is reserved", ZSTR_VAL(name));
    5831             :                 }
    5832             : 
    5833         416 :                 opline = zend_emit_op(NULL, ZEND_ADD_INTERFACE, class_node, NULL);
    5834         416 :                 opline->op2_type = IS_CONST;
    5835         416 :                 opline->op2.constant = zend_add_class_name_literal(CG(active_op_array),
    5836             :                         zend_resolve_class_name_ast(class_ast));
    5837             : 
    5838         416 :                 CG(active_class_entry)->num_interfaces++;
    5839             :         }
    5840         376 : }
    5841             : /* }}} */
    5842             : 
    5843          29 : static zend_string *zend_generate_anon_class_name(unsigned char *lex_pos) /* {{{ */
    5844             : {
    5845             :         zend_string *result;
    5846             :         char char_pos_buf[32];
    5847          29 :         size_t char_pos_len = zend_sprintf(char_pos_buf, "%p", lex_pos);
    5848          29 :         zend_string *filename = CG(active_op_array)->filename;
    5849             : 
    5850             :         /* NULL, name length, filename length, last accepting char position length */
    5851          58 :         result = zend_string_alloc(sizeof("class@anonymous") + ZSTR_LEN(filename) + char_pos_len, 0);
    5852          29 :         sprintf(ZSTR_VAL(result), "class@anonymous%c%s%s", '\0', ZSTR_VAL(filename), char_pos_buf);
    5853          29 :         return zend_new_interned_string(result);
    5854             : }
    5855             : /* }}} */
    5856             : 
    5857        8130 : void zend_compile_class_decl(zend_ast *ast) /* {{{ */
    5858             : {
    5859        8130 :         zend_ast_decl *decl = (zend_ast_decl *) ast;
    5860        8130 :         zend_ast *extends_ast = decl->child[0];
    5861        8130 :         zend_ast *implements_ast = decl->child[1];
    5862        8130 :         zend_ast *stmt_ast = decl->child[2];
    5863             :         zend_string *name, *lcname;
    5864        8130 :         zend_class_entry *ce = zend_arena_alloc(&CG(arena), sizeof(zend_class_entry));
    5865             :         zend_op *opline;
    5866             :         znode declare_node, extends_node;
    5867             : 
    5868        8130 :         zend_class_entry *original_ce = CG(active_class_entry);
    5869        8130 :         znode original_implementing_class = FC(implementing_class);
    5870             : 
    5871        8130 :         if (EXPECTED((decl->flags & ZEND_ACC_ANON_CLASS) == 0)) {
    5872        8101 :                 zend_string *unqualified_name = decl->name;
    5873             : 
    5874        8101 :                 if (CG(active_class_entry)) {
    5875           1 :                         zend_error_noreturn(E_COMPILE_ERROR, "Class declarations may not be nested");
    5876             :                 }
    5877             : 
    5878        8100 :                 zend_assert_valid_class_name(unqualified_name);
    5879        8092 :                 name = zend_prefix_with_ns(unqualified_name);
    5880        8092 :                 name = zend_new_interned_string(name);
    5881        8092 :                 lcname = zend_string_tolower(name);
    5882             : 
    5883        8092 :                 if (FC(imports)) {
    5884          30 :                         zend_string *import_name = zend_hash_find_ptr_lc(
    5885          30 :                                 FC(imports), ZSTR_VAL(unqualified_name), ZSTR_LEN(unqualified_name));
    5886          30 :                         if (import_name && !zend_string_equals_ci(lcname, import_name)) {
    5887           2 :                                 zend_error_noreturn(E_COMPILE_ERROR, "Cannot declare class %s "
    5888             :                                                 "because the name is already in use", ZSTR_VAL(name));
    5889             :                         }
    5890             :                 }
    5891             :         } else {
    5892          29 :                 name = zend_generate_anon_class_name(decl->lex_pos);
    5893          29 :                 lcname = zend_string_tolower(name);
    5894             :         }
    5895        8119 :         lcname = zend_new_interned_string(lcname);
    5896             : 
    5897        8119 :         ce->type = ZEND_USER_CLASS;
    5898        8119 :         ce->name = name;
    5899        8119 :         zend_initialize_class_data(ce, 1);
    5900             : 
    5901        8119 :         ce->ce_flags |= decl->flags;
    5902        8119 :         ce->info.user.filename = zend_get_compiled_filename();
    5903        8119 :         ce->info.user.line_start = decl->start_lineno;
    5904        8119 :         ce->info.user.line_end = decl->end_lineno;
    5905             : 
    5906        8119 :         if (decl->doc_comment) {
    5907         146 :                 ce->info.user.doc_comment = zend_string_copy(decl->doc_comment);
    5908             :         }
    5909             : 
    5910        8119 :         if (UNEXPECTED((decl->flags & ZEND_ACC_ANON_CLASS))) {
    5911             :                 /* Serialization is not supported for anonymous classes */
    5912          29 :                 ce->serialize = zend_class_serialize_deny;
    5913          29 :                 ce->unserialize = zend_class_unserialize_deny;
    5914             :         }
    5915             : 
    5916        8119 :         if (extends_ast) {
    5917        2508 :                 if (!zend_is_const_default_class_ref(extends_ast)) {
    5918           2 :                         zend_string *extends_name = zend_ast_get_str(extends_ast);
    5919           2 :                         zend_error_noreturn(E_COMPILE_ERROR,
    5920             :                                 "Cannot use '%s' as class name as it is reserved", ZSTR_VAL(extends_name));
    5921             :                 }
    5922             : 
    5923        2506 :                 zend_compile_class_ref(&extends_node, extends_ast, 0);
    5924             :         }
    5925             : 
    5926        8117 :         opline = get_next_op(CG(active_op_array));
    5927        8117 :         zend_make_var_result(&declare_node, opline);
    5928             : 
    5929        8117 :         GET_NODE(&FC(implementing_class), opline->result);
    5930             : 
    5931        8117 :         opline->op1_type = IS_CONST;
    5932        8117 :         LITERAL_STR(opline->op1, lcname);
    5933             : 
    5934        8117 :         if (decl->flags & ZEND_ACC_ANON_CLASS) {
    5935          29 :                 if (extends_ast) {
    5936           3 :                         opline->opcode = ZEND_DECLARE_ANON_INHERITED_CLASS;
    5937           3 :                         SET_NODE(opline->op2, &extends_node);
    5938             :                 } else {
    5939          26 :                         opline->opcode = ZEND_DECLARE_ANON_CLASS;
    5940             :                 }
    5941             : 
    5942          29 :                 if (!zend_hash_exists(CG(class_table), lcname)) {
    5943          28 :                         zend_hash_add_ptr(CG(class_table), lcname, ce);
    5944             :                 } else {
    5945             :                         /* this anonymous class has been included */
    5946             :                         zval zv;
    5947           1 :                         ZVAL_PTR(&zv, ce);
    5948           1 :                         destroy_zend_class(&zv);
    5949           1 :                         return;
    5950             :                 }
    5951             :         } else {
    5952             :                 zend_string *key;
    5953             : 
    5954        8088 :                 if (extends_ast) {
    5955        2503 :                         opline->opcode = ZEND_DECLARE_INHERITED_CLASS;
    5956        2503 :                         SET_NODE(opline->op2, &extends_node);
    5957             :                 } else {
    5958        5585 :                         opline->opcode = ZEND_DECLARE_CLASS;
    5959        5585 :                         SET_UNUSED(opline->op2);
    5960             :                 }
    5961             : 
    5962        8088 :                 key = zend_build_runtime_definition_key(lcname, decl->lex_pos);
    5963             :                 /* RTD key is placed after lcname literal in op1 */
    5964        8088 :                 zend_add_literal_string(CG(active_op_array), &key);
    5965             : 
    5966        8088 :                 zend_hash_update_ptr(CG(class_table), key, ce);
    5967             :         }
    5968             : 
    5969        8116 :         CG(active_class_entry) = ce;
    5970             : 
    5971        8116 :         zend_compile_stmt(stmt_ast);
    5972             : 
    5973             :         /* Reset lineno for final opcodes and errors */
    5974        8053 :         CG(zend_lineno) = ast->lineno;
    5975             : 
    5976        8053 :         if (ce->num_traits == 0) {
    5977             :                 /* For traits this check is delayed until after trait binding */
    5978        7856 :                 zend_check_deprecated_constructor(ce);
    5979             :         }
    5980             : 
    5981        8053 :         if (ce->constructor) {
    5982        2005 :                 ce->constructor->common.fn_flags |= ZEND_ACC_CTOR;
    5983        2005 :                 if (ce->constructor->common.fn_flags & ZEND_ACC_STATIC) {
    5984           4 :                         zend_error_noreturn(E_COMPILE_ERROR, "Constructor %s::%s() cannot be static",
    5985           4 :                                 ZSTR_VAL(ce->name), ZSTR_VAL(ce->constructor->common.function_name));
    5986             :                 }
    5987        2003 :                 if (ce->constructor->common.fn_flags & ZEND_ACC_HAS_RETURN_TYPE) {
    5988           4 :                         zend_error_noreturn(E_COMPILE_ERROR,
    5989             :                                 "Constructor %s::%s() cannot declare a return type",
    5990           4 :                                 ZSTR_VAL(ce->name), ZSTR_VAL(ce->constructor->common.function_name));
    5991             :                 }
    5992             :         }
    5993        8049 :         if (ce->destructor) {
    5994         176 :                 ce->destructor->common.fn_flags |= ZEND_ACC_DTOR;
    5995         176 :                 if (ce->destructor->common.fn_flags & ZEND_ACC_STATIC) {
    5996           2 :                         zend_error_noreturn(E_COMPILE_ERROR, "Destructor %s::%s() cannot be static",
    5997           2 :                                 ZSTR_VAL(ce->name), ZSTR_VAL(ce->destructor->common.function_name));
    5998         175 :                 } else if (ce->destructor->common.fn_flags & ZEND_ACC_HAS_RETURN_TYPE) {
    5999           2 :                         zend_error_noreturn(E_COMPILE_ERROR,
    6000             :                                 "Destructor %s::%s() cannot declare a return type",
    6001           2 :                                 ZSTR_VAL(ce->name), ZSTR_VAL(ce->destructor->common.function_name));
    6002             :                 }
    6003             :         }
    6004        8047 :         if (ce->clone) {
    6005          28 :                 ce->clone->common.fn_flags |= ZEND_ACC_CLONE;
    6006          28 :                 if (ce->clone->common.fn_flags & ZEND_ACC_STATIC) {
    6007           2 :                         zend_error_noreturn(E_COMPILE_ERROR, "Clone method %s::%s() cannot be static",
    6008           2 :                                 ZSTR_VAL(ce->name), ZSTR_VAL(ce->clone->common.function_name));
    6009          27 :                 } else if (ce->clone->common.fn_flags & ZEND_ACC_HAS_RETURN_TYPE) {
    6010           2 :                         zend_error_noreturn(E_COMPILE_ERROR,
    6011             :                                 "%s::%s() cannot declare a return type",
    6012           2 :                                 ZSTR_VAL(ce->name), ZSTR_VAL(ce->clone->common.function_name));
    6013             :                 }
    6014             :         }
    6015             : 
    6016             :         /* Check for traits and proceed like with interfaces.
    6017             :          * The only difference will be a combined handling of them in the end.
    6018             :          * Thus, we need another opcode here. */
    6019        8045 :         if (ce->num_traits > 0) {
    6020         197 :                 ce->traits = NULL;
    6021         197 :                 ce->num_traits = 0;
    6022         197 :                 ce->ce_flags |= ZEND_ACC_IMPLEMENT_TRAITS;
    6023             : 
    6024         197 :                 zend_emit_op(NULL, ZEND_BIND_TRAITS, &declare_node, NULL);
    6025             :         }
    6026             : 
    6027        8045 :         if (implements_ast) {
    6028         378 :                 zend_compile_implements(&declare_node, implements_ast);
    6029             :         }
    6030             : 
    6031        8043 :         if (!(ce->ce_flags & (ZEND_ACC_INTERFACE|ZEND_ACC_EXPLICIT_ABSTRACT_CLASS))
    6032             :                 && (extends_ast || implements_ast)
    6033             :         ) {
    6034        2764 :                 zend_verify_abstract_class(ce);
    6035        2762 :                 if (implements_ast) {
    6036         327 :                         zend_emit_op(NULL, ZEND_VERIFY_ABSTRACT_CLASS, &declare_node, NULL);
    6037             :                 }
    6038             :         }
    6039             : 
    6040             :         /* Inherit interfaces; reset number to zero, we need it for above check and
    6041             :          * will restore it during actual implementation.
    6042             :          * The ZEND_ACC_IMPLEMENT_INTERFACES flag disables double call to
    6043             :          * zend_verify_abstract_class() */
    6044        8041 :         if (ce->num_interfaces > 0) {
    6045         376 :                 ce->interfaces = NULL;
    6046         376 :                 ce->num_interfaces = 0;
    6047         376 :                 ce->ce_flags |= ZEND_ACC_IMPLEMENT_INTERFACES;
    6048             :         }
    6049             : 
    6050        8041 :         FC(implementing_class) = original_implementing_class;
    6051        8041 :         CG(active_class_entry) = original_ce;
    6052             : }
    6053             : /* }}} */
    6054             : 
    6055         135 : static HashTable *zend_get_import_ht(uint32_t type) /* {{{ */
    6056             : {
    6057         135 :         switch (type) {
    6058             :                 case T_CLASS:
    6059          80 :                         if (!FC(imports)) {
    6060          55 :                                 FC(imports) = emalloc(sizeof(HashTable));
    6061          55 :                                 zend_hash_init(FC(imports), 8, NULL, str_dtor, 0);
    6062             :                         }
    6063          80 :                         return FC(imports);
    6064             :                 case T_FUNCTION:
    6065          29 :                         if (!FC(imports_function)) {
    6066          20 :                                 FC(imports_function) = emalloc(sizeof(HashTable));
    6067          20 :                                 zend_hash_init(FC(imports_function), 8, NULL, str_dtor, 0);
    6068             :                         }
    6069          29 :                         return FC(imports_function);
    6070             :                 case T_CONST:
    6071          26 :                         if (!FC(imports_const)) {
    6072          17 :                                 FC(imports_const) = emalloc(sizeof(HashTable));
    6073          17 :                                 zend_hash_init(FC(imports_const), 8, NULL, str_dtor, 0);
    6074             :                         }
    6075          26 :                         return FC(imports_const);
    6076             :                 EMPTY_SWITCH_DEFAULT_CASE()
    6077             :         }
    6078             : 
    6079           0 :         return NULL;
    6080             : }
    6081             : /* }}} */
    6082             : 
    6083           7 : static char *zend_get_use_type_str(uint32_t type) /* {{{ */
    6084             : {
    6085           7 :         switch (type) {
    6086             :                 case T_CLASS:
    6087           2 :                         return "";
    6088             :                 case T_FUNCTION:
    6089           3 :                         return " function";
    6090             :                 case T_CONST:
    6091           2 :                         return " const";
    6092             :                 EMPTY_SWITCH_DEFAULT_CASE()
    6093             :         }
    6094             : 
    6095           0 :         return " unknown";
    6096             : }
    6097             : /* }}} */
    6098             : 
    6099           5 : static void zend_check_already_in_use(uint32_t type, zend_string *old_name, zend_string *new_name, zend_string *check_name) /* {{{ */
    6100             : {
    6101           5 :         if (zend_string_equals_ci(old_name, check_name)) {
    6102           1 :                 return;
    6103             :         }
    6104             : 
    6105           4 :         zend_error_noreturn(E_COMPILE_ERROR, "Cannot use%s %s as %s because the name "
    6106             :                 "is already in use", zend_get_use_type_str(type), ZSTR_VAL(old_name), ZSTR_VAL(new_name));
    6107             : }
    6108             : /* }}} */
    6109             : 
    6110         135 : void zend_compile_use(zend_ast *ast) /* {{{ */
    6111             : {
    6112         135 :         zend_ast_list *list = zend_ast_get_list(ast);
    6113             :         uint32_t i;
    6114         135 :         zend_string *current_ns = FC(current_namespace);
    6115         135 :         uint32_t type = ast->attr;
    6116         135 :         HashTable *current_import = zend_get_import_ht(type);
    6117         135 :         zend_bool case_sensitive = type == T_CONST;
    6118             : 
    6119         266 :         for (i = 0; i < list->children; ++i) {
    6120         143 :                 zend_ast *use_ast = list->child[i];
    6121         143 :                 zend_ast *old_name_ast = use_ast->child[0];
    6122         143 :                 zend_ast *new_name_ast = use_ast->child[1];
    6123         143 :                 zend_string *old_name = zend_ast_get_str(old_name_ast);
    6124             :                 zend_string *new_name, *lookup_name;
    6125             : 
    6126         143 :                 if (new_name_ast) {
    6127          59 :                         new_name = zend_string_copy(zend_ast_get_str(new_name_ast));
    6128             :                 } else {
    6129             :                         const char *unqualified_name;
    6130             :                         size_t unqualified_name_len;
    6131          84 :                         if (zend_get_unqualified_name(old_name, &unqualified_name, &unqualified_name_len)) {
    6132             :                                 /* The form "use A\B" is equivalent to "use A\B as B" */
    6133         142 :                                 new_name = zend_string_init(unqualified_name, unqualified_name_len, 0);
    6134             :                         } else {
    6135          13 :                                 new_name = zend_string_copy(old_name);
    6136             : 
    6137          13 :                                 if (!current_ns) {
    6138           4 :                                         if (type == T_CLASS && zend_string_equals_literal(new_name, "strict")) {
    6139           0 :                                                 zend_error_noreturn(E_COMPILE_ERROR,
    6140             :                                                         "You seem to be trying to use a different language...");
    6141             :                                         }
    6142             : 
    6143           4 :                                         zend_error(E_WARNING, "The use statement with non-compound name '%s' "
    6144             :                                                 "has no effect", ZSTR_VAL(new_name));
    6145             :                                 }
    6146             :                         }
    6147             :                 }
    6148             : 
    6149         143 :                 if (case_sensitive) {
    6150          29 :                         lookup_name = zend_string_copy(new_name);
    6151             :                 } else {
    6152         114 :                         lookup_name = zend_string_tolower(new_name);
    6153             :                 }
    6154             : 
    6155         143 :                 if (type == T_CLASS && zend_is_reserved_class_name(new_name)) {
    6156           5 :                         zend_error_noreturn(E_COMPILE_ERROR, "Cannot use %s as %s because '%s' "
    6157             :                                 "is a special class name", ZSTR_VAL(old_name), ZSTR_VAL(new_name), ZSTR_VAL(new_name));
    6158             :                 }
    6159             : 
    6160         138 :                 if (current_ns) {
    6161         170 :                         zend_string *ns_name = zend_string_alloc(ZSTR_LEN(current_ns) + 1 + ZSTR_LEN(new_name), 0);
    6162          85 :                         zend_str_tolower_copy(ZSTR_VAL(ns_name), ZSTR_VAL(current_ns), ZSTR_LEN(current_ns));
    6163          85 :                         ZSTR_VAL(ns_name)[ZSTR_LEN(current_ns)] = '\\';
    6164          85 :                         memcpy(ZSTR_VAL(ns_name) + ZSTR_LEN(current_ns) + 1, ZSTR_VAL(lookup_name), ZSTR_LEN(lookup_name));
    6165             : 
    6166          85 :                         if (zend_hash_exists(CG(class_table), ns_name)) {
    6167           2 :                                 zend_check_already_in_use(type, old_name, new_name, ns_name);
    6168             :                         }
    6169             : 
    6170             :                         zend_string_free(ns_name);
    6171             :                 } else {
    6172          53 :                         switch (type) {
    6173             :                                 case T_CLASS:
    6174             :                                 {
    6175          42 :                                         zend_class_entry *ce = zend_hash_find_ptr(CG(class_table), lookup_name);
    6176          28 :                                         if (ce && ce->type == ZEND_USER_CLASS
    6177           7 :                                                 && ce->info.user.filename == CG(compiled_filename)
    6178             :                                         ) {
    6179           1 :                                                 zend_check_already_in_use(type, old_name, new_name, lookup_name);
    6180             :                                         }
    6181          20 :                                         break;
    6182             :                                 }
    6183             :                                 case T_FUNCTION:
    6184             :                                 {
    6185          34 :                                         zend_function *fn = zend_hash_find_ptr(CG(function_table), lookup_name);
    6186          20 :                                         if (fn && fn->type == ZEND_USER_FUNCTION
    6187           3 :                                                 && fn->op_array.filename == CG(compiled_filename)
    6188             :                                         ) {
    6189           1 :                                                 zend_check_already_in_use(type, old_name, new_name, lookup_name);
    6190             :                                         }
    6191          16 :                                         break;
    6192             :                                 }
    6193             :                                 case T_CONST:
    6194             :                                 {
    6195          15 :                                         zend_string *filename = zend_hash_find_ptr(&CG(const_filenames), lookup_name);
    6196          15 :                                         if (filename && filename == CG(compiled_filename)) {
    6197           1 :                                                 zend_check_already_in_use(type, old_name, new_name, lookup_name);
    6198             :                                         }
    6199             :                                         break;
    6200             :                                 }
    6201             :                                 EMPTY_SWITCH_DEFAULT_CASE()
    6202             :                         }
    6203             :                 }
    6204             : 
    6205             :                 zend_string_addref(old_name);
    6206         134 :                 if (!zend_hash_add_ptr(current_import, lookup_name, old_name)) {
    6207           3 :                         zend_error_noreturn(E_COMPILE_ERROR, "Cannot use%s %s as %s because the name "
    6208             :                                 "is already in use", zend_get_use_type_str(type), ZSTR_VAL(old_name), ZSTR_VAL(new_name));
    6209             :                 }
    6210             : 
    6211             :                 zend_string_release(lookup_name);
    6212             :                 zend_string_release(new_name);
    6213             :         }
    6214         123 : }
    6215             : /* }}} */
    6216             : 
    6217          14 : void zend_compile_group_use(zend_ast *ast) /* {{{ */
    6218             : {
    6219             :         uint32_t i;
    6220          28 :         zend_string *ns = zend_ast_get_str(ast->child[0]);
    6221          28 :         zend_ast_list *list = zend_ast_get_list(ast->child[1]);
    6222             : 
    6223          55 :         for (i = 0; i < list->children; i++) {
    6224          41 :                 zend_ast *inline_use, *use = list->child[i];
    6225          82 :                 zval *name_zval = zend_ast_get_zval(use->child[0]);
    6226          41 :                 zend_string *name = Z_STR_P(name_zval);
    6227          41 :                 zend_string *compound_ns = zend_concat_names(ZSTR_VAL(ns), ZSTR_LEN(ns), ZSTR_VAL(name), ZSTR_LEN(name));
    6228             :                 zend_string_release(name);
    6229          41 :                 ZVAL_STR(name_zval, compound_ns);
    6230          41 :                 inline_use = zend_ast_create_list(1, ZEND_AST_USE, use);
    6231          41 :                 inline_use->attr = ast->attr ? ast->attr : use->attr;
    6232          41 :                 zend_compile_use(inline_use);
    6233             :         }
    6234          14 : }
    6235             : /* }}} */
    6236             : 
    6237         217 : void zend_compile_const_decl(zend_ast *ast) /* {{{ */
    6238             : {
    6239         217 :         zend_ast_list *list = zend_ast_get_list(ast);
    6240             :         uint32_t i;
    6241         427 :         for (i = 0; i < list->children; ++i) {
    6242         218 :                 zend_ast *const_ast = list->child[i];
    6243         218 :                 zend_ast *name_ast = const_ast->child[0];
    6244         218 :                 zend_ast *value_ast = const_ast->child[1];
    6245         218 :                 zend_string *unqualified_name = zend_ast_get_str(name_ast);
    6246             : 
    6247             :                 zend_string *name;
    6248             :                 znode name_node, value_node;
    6249         218 :                 zval *value_zv = &value_node.u.constant;
    6250             : 
    6251         218 :                 value_node.op_type = IS_CONST;
    6252         218 :                 zend_const_expr_to_zval(value_zv, value_ast);
    6253             : 
    6254         213 :                 if (zend_lookup_reserved_const(ZSTR_VAL(unqualified_name), ZSTR_LEN(unqualified_name))) {
    6255           1 :                         zend_error_noreturn(E_COMPILE_ERROR,
    6256             :                                 "Cannot redeclare constant '%s'", ZSTR_VAL(unqualified_name));
    6257             :                 }
    6258             : 
    6259         212 :                 name = zend_prefix_with_ns(unqualified_name);
    6260         212 :                 name = zend_new_interned_string(name);
    6261             : 
    6262         212 :                 if (FC(imports_const)) {
    6263          10 :                         zend_string *import_name = zend_hash_find_ptr(FC(imports_const), unqualified_name);
    6264           7 :                         if (import_name && !zend_string_equals(import_name, name)) {
    6265           2 :                                 zend_error_noreturn(E_COMPILE_ERROR, "Cannot declare const %s because "
    6266             :                                         "the name is already in use", ZSTR_VAL(name));
    6267             :                         }
    6268             :                 }
    6269             : 
    6270         210 :                 name_node.op_type = IS_CONST;
    6271         210 :                 ZVAL_STR(&name_node.u.constant, name);
    6272             : 
    6273         210 :                 zend_emit_op(NULL, ZEND_DECLARE_CONST, &name_node, &value_node);
    6274             : 
    6275         210 :                 zend_hash_add_ptr(&CG(const_filenames), name, CG(compiled_filename));
    6276             :         }
    6277         209 : }
    6278             : /* }}}*/
    6279             : 
    6280         263 : void zend_compile_namespace(zend_ast *ast) /* {{{ */
    6281             : {
    6282         263 :         zend_ast *name_ast = ast->child[0];
    6283         263 :         zend_ast *stmt_ast = ast->child[1];
    6284             :         zend_string *name;
    6285         263 :         zend_bool with_bracket = stmt_ast != NULL;
    6286             : 
    6287             :         /* handle mixed syntax declaration or nested namespaces */
    6288         263 :         if (!FC(has_bracketed_namespaces)) {
    6289         213 :                 if (FC(current_namespace)) {
    6290             :                         /* previous namespace declarations were unbracketed */
    6291           7 :                         if (with_bracket) {
    6292           1 :                                 zend_error_noreturn(E_COMPILE_ERROR, "Cannot mix bracketed namespace declarations "
    6293             :                                         "with unbracketed namespace declarations");
    6294             :                         }
    6295             :                 }
    6296             :         } else {
    6297             :                 /* previous namespace declarations were bracketed */
    6298          50 :                 if (!with_bracket) {
    6299           1 :                         zend_error_noreturn(E_COMPILE_ERROR, "Cannot mix bracketed namespace declarations "
    6300             :                                 "with unbracketed namespace declarations");
    6301          49 :                 } else if (FC(current_namespace) || FC(in_namespace)) {
    6302           1 :                         zend_error_noreturn(E_COMPILE_ERROR, "Namespace declarations cannot be nested");
    6303             :                 }
    6304             :         }
    6305             : 
    6306         579 :         if (((!with_bracket && !FC(current_namespace))
    6307         319 :                  || (with_bracket && !FC(has_bracketed_namespaces))) && CG(active_op_array)->last > 0
    6308             :         ) {
    6309             :                 /* ignore ZEND_EXT_STMT and ZEND_TICKS */
    6310           3 :                 uint32_t num = CG(active_op_array)->last;
    6311          13 :                 while (num > 0 &&
    6312           3 :                        (CG(active_op_array)->opcodes[num-1].opcode == ZEND_EXT_STMT ||
    6313           3 :                         CG(active_op_array)->opcodes[num-1].opcode == ZEND_TICKS)) {
    6314           1 :                         --num;
    6315             :                 }
    6316           3 :                 if (num > 0) {
    6317           2 :                         zend_error_noreturn(E_COMPILE_ERROR, "Namespace declaration statement has to be "
    6318             :                                 "the very first statement or after any declare call in the script");
    6319             :                 }
    6320             :         }
    6321             : 
    6322         258 :         if (FC(current_namespace)) {
    6323           6 :                 zend_string_release(FC(current_namespace));
    6324             :         }
    6325             : 
    6326         258 :         if (name_ast) {
    6327         215 :                 name = zend_ast_get_str(name_ast);
    6328             : 
    6329         215 :                 if (ZEND_FETCH_CLASS_DEFAULT != zend_get_class_fetch_type(name)) {
    6330           1 :                         zend_error_noreturn(E_COMPILE_ERROR, "Cannot use '%s' as namespace name", ZSTR_VAL(name));
    6331             :                 }
    6332             : 
    6333         214 :                 FC(current_namespace) = zend_string_copy(name);
    6334             :         } else {
    6335          43 :                 FC(current_namespace) = NULL;
    6336             :         }
    6337             : 
    6338         257 :         zend_reset_import_tables();
    6339             : 
    6340         257 :         FC(in_namespace) = 1;
    6341         257 :         if (with_bracket) {
    6342         112 :                 FC(has_bracketed_namespaces) = 1;
    6343             :         }
    6344             : 
    6345         257 :         if (stmt_ast) {
    6346         112 :                 zend_compile_top_stmt(stmt_ast);
    6347          96 :                 zend_end_namespace();
    6348             :         }
    6349         241 : }
    6350             : /* }}} */
    6351             : 
    6352         276 : void zend_compile_halt_compiler(zend_ast *ast) /* {{{ */
    6353             : {
    6354         276 :         zend_ast *offset_ast = ast->child[0];
    6355         276 :         zend_long offset = Z_LVAL_P(zend_ast_get_zval(offset_ast));
    6356             : 
    6357             :         zend_string *filename, *name;
    6358         276 :         const char const_name[] = "__COMPILER_HALT_OFFSET__";
    6359             : 
    6360         276 :         if (FC(has_bracketed_namespaces) && FC(in_namespace)) {
    6361           0 :                 zend_error_noreturn(E_COMPILE_ERROR,
    6362             :                         "__HALT_COMPILER() can only be used from the outermost scope");
    6363             :         }
    6364             : 
    6365         276 :         filename = zend_get_compiled_filename();
    6366         276 :         name = zend_mangle_property_name(const_name, sizeof(const_name) - 1,
    6367             :                 ZSTR_VAL(filename), ZSTR_LEN(filename), 0);
    6368             : 
    6369         276 :         zend_register_long_constant(ZSTR_VAL(name), ZSTR_LEN(name), offset, CONST_CS, 0);
    6370             :         zend_string_release(name);
    6371         276 : }
    6372             : /* }}} */
    6373             : 
    6374       12196 : static zend_bool zend_try_ct_eval_magic_const(zval *zv, zend_ast *ast) /* {{{ */
    6375             : {
    6376       12196 :         zend_op_array *op_array = CG(active_op_array);
    6377       12196 :         zend_class_entry *ce = CG(active_class_entry);
    6378             : 
    6379       12196 :         switch (ast->attr) {
    6380             :                 case T_LINE:
    6381          25 :                         ZVAL_LONG(zv, ast->lineno);
    6382          25 :                         break;
    6383             :                 case T_FILE:
    6384       10205 :                         ZVAL_STR_COPY(zv, CG(compiled_filename));
    6385       10205 :                         break;
    6386             :                 case T_DIR:
    6387             :                 {
    6388         712 :                         zend_string *filename = CG(compiled_filename);
    6389        1424 :                         zend_string *dirname = zend_string_init(ZSTR_VAL(filename), ZSTR_LEN(filename), 0);
    6390         712 :                         zend_dirname(ZSTR_VAL(dirname), ZSTR_LEN(dirname));
    6391             : 
    6392         712 :                         if (strcmp(ZSTR_VAL(dirname), ".") == 0) {
    6393           0 :                                 dirname = zend_string_extend(dirname, MAXPATHLEN, 0);
    6394             : #if HAVE_GETCWD
    6395           0 :                                 ZEND_IGNORE_VALUE(VCWD_GETCWD(ZSTR_VAL(dirname), MAXPATHLEN));
    6396             : #elif HAVE_GETWD
    6397             :                                 ZEND_IGNORE_VALUE(VCWD_GETWD(ZSTR_VAL(dirname)));
    6398             : #endif
    6399             :                         }
    6400             : 
    6401         712 :                         ZSTR_LEN(dirname) = strlen(ZSTR_VAL(dirname));
    6402         712 :                         ZVAL_STR(zv, dirname);
    6403         712 :                         break;
    6404             :                 }
    6405             :                 case T_FUNC_C:
    6406         262 :                         if (op_array && op_array->function_name) {
    6407         130 :                                 ZVAL_STR_COPY(zv, op_array->function_name);
    6408             :                         } else {
    6409           2 :                                 ZVAL_EMPTY_STRING(zv);
    6410             :                         }
    6411         132 :                         break;
    6412             :                 case T_METHOD_C:
    6413        1007 :                         if ((op_array && !op_array->scope && op_array->function_name) || (op_array->fn_flags & ZEND_ACC_CLOSURE)) {
    6414          25 :                                 ZVAL_STR_COPY(zv, op_array->function_name);
    6415         957 :                         } else if (ce) {
    6416        1911 :                                 if (op_array && op_array->function_name) {
    6417         955 :                                         ZVAL_NEW_STR(zv, zend_concat3(ZSTR_VAL(ce->name), ZSTR_LEN(ce->name), "::", 2,
    6418             :                                                 ZSTR_VAL(op_array->function_name), ZSTR_LEN(op_array->function_name)));
    6419             :                                 } else {
    6420           1 :                                         ZVAL_STR_COPY(zv, ce->name);
    6421             :                                 }
    6422           1 :                         } else if (op_array && op_array->function_name) {
    6423           0 :                                 ZVAL_STR_COPY(zv, op_array->function_name);
    6424             :                         } else {
    6425           1 :                                 ZVAL_EMPTY_STRING(zv);
    6426             :                         }
    6427         982 :                         break;
    6428             :                 case T_CLASS_C:
    6429         101 :                         if (ce) {
    6430         100 :                                 if ((ce->ce_flags & ZEND_ACC_TRAIT) != 0) {
    6431           6 :                                         return 0;
    6432             :                                 } else {
    6433          94 :                                         ZVAL_STR_COPY(zv, ce->name);
    6434             :                                 }
    6435             :                         } else {
    6436           1 :                                 ZVAL_EMPTY_STRING(zv);
    6437             :                         }
    6438          95 :                         break;
    6439             :                 case T_TRAIT_C:
    6440           6 :                         if (ce && (ce->ce_flags & ZEND_ACC_TRAIT) != 0) {
    6441           1 :                                 ZVAL_STR_COPY(zv, ce->name);
    6442             :                         } else {
    6443           4 :                                 ZVAL_EMPTY_STRING(zv);
    6444             :                         }
    6445           5 :                         break;
    6446             :                 case T_NS_C:
    6447          34 :                         if (FC(current_namespace)) {
    6448          25 :                                 ZVAL_STR_COPY(zv, FC(current_namespace));
    6449             :                         } else {
    6450           9 :                                 ZVAL_EMPTY_STRING(zv);
    6451             :                         }
    6452             :                         break;
    6453             :                 EMPTY_SWITCH_DEFAULT_CASE()
    6454             :         }
    6455             : 
    6456       12190 :         return 1;
    6457             : }
    6458             : /* }}} */
    6459             : 
    6460       12882 : ZEND_API zend_bool zend_binary_op_produces_numeric_string_error(uint32_t opcode, zval *op1, zval *op2) /* {{{ */
    6461             : {
    6462       12882 :         if (!(opcode == ZEND_ADD || opcode == ZEND_SUB || opcode == ZEND_MUL || opcode == ZEND_DIV
    6463             :                 || opcode == ZEND_POW || opcode == ZEND_MOD || opcode == ZEND_SL || opcode == ZEND_SR
    6464             :                 || opcode == ZEND_BW_OR || opcode == ZEND_BW_AND || opcode == ZEND_BW_XOR)) {
    6465        4666 :                 return 0;
    6466             :         }
    6467             : 
    6468             :         /* While basic arithmetic operators always produce numeric string errors,
    6469             :          * bitwise operators don't produce errors if both operands are strings */
    6470        8903 :         if ((opcode == ZEND_BW_OR || opcode == ZEND_BW_AND || opcode == ZEND_BW_XOR)
    6471             :                 && Z_TYPE_P(op1) == IS_STRING && Z_TYPE_P(op2) == IS_STRING) {
    6472           0 :                 return 0;
    6473             :         }
    6474             : 
    6475        8266 :         if (Z_TYPE_P(op1) == IS_STRING
    6476          50 :                 && !is_numeric_string(Z_STRVAL_P(op1), Z_STRLEN_P(op1), NULL, NULL, 0)) {
    6477          32 :                 return 1;
    6478             :         }
    6479             : 
    6480        8208 :         if (Z_TYPE_P(op2) == IS_STRING
    6481          24 :                 && !is_numeric_string(Z_STRVAL_P(op2), Z_STRLEN_P(op2), NULL, NULL, 0)) {
    6482          10 :                 return 1;
    6483             :         }
    6484             : 
    6485        8174 :         return 0;
    6486             : }
    6487             : /* }}} */
    6488             : 
    6489       12887 : static inline zend_bool zend_try_ct_eval_binary_op(zval *result, uint32_t opcode, zval *op1, zval *op2) /* {{{ */
    6490             : {
    6491       12887 :         binary_op_type fn = get_binary_op(opcode);
    6492             : 
    6493             :         /* don't evaluate division by zero at compile-time */
    6494       12934 :         if ((opcode == ZEND_DIV || opcode == ZEND_MOD) &&
    6495             :             zval_get_long(op2) == 0) {
    6496          12 :                 return 0;
    6497       12917 :         } else if ((opcode == ZEND_SL || opcode == ZEND_SR) &&
    6498             :             zval_get_long(op2) < 0) {
    6499           0 :                 return 0;
    6500             :         }
    6501             : 
    6502             :         /* don't evaluate numeric string error-producing operations at compile-time */
    6503       12875 :         if (zend_binary_op_produces_numeric_string_error(opcode, op1, op2)) {
    6504          42 :                 return 0;
    6505             :         }
    6506             : 
    6507       12833 :         fn(result, op1, op2);
    6508       12831 :         return 1;
    6509             : }
    6510             : /* }}} */
    6511             : 
    6512         251 : static inline void zend_ct_eval_unary_op(zval *result, uint32_t opcode, zval *op) /* {{{ */
    6513             : {
    6514         251 :         unary_op_type fn = get_unary_op(opcode);
    6515         251 :         fn(result, op);
    6516         251 : }
    6517             : /* }}} */
    6518             : 
    6519        6905 : static inline zend_bool zend_try_ct_eval_unary_pm(zval *result, zend_ast_kind kind, zval *op) /* {{{ */
    6520             : {
    6521             :         zval left;
    6522        6905 :         ZVAL_LONG(&left, (kind == ZEND_AST_UNARY_PLUS) ? 1 : -1);
    6523        6905 :         return zend_try_ct_eval_binary_op(result, ZEND_MUL, &left, op);
    6524             : }
    6525             : /* }}} */
    6526             : 
    6527          25 : static inline void zend_ct_eval_greater(zval *result, zend_ast_kind kind, zval *op1, zval *op2) /* {{{ */
    6528             : {
    6529             :         binary_op_type fn = kind == ZEND_AST_GREATER
    6530          25 :                 ? is_smaller_function : is_smaller_or_equal_function;
    6531          25 :         fn(result, op2, op1);
    6532          25 : }
    6533             : /* }}} */
    6534             : 
    6535       30878 : static zend_bool zend_try_ct_eval_array(zval *result, zend_ast *ast) /* {{{ */
    6536             : {
    6537       30878 :         zend_ast_list *list = zend_ast_get_list(ast);
    6538             :         uint32_t i;
    6539       30878 :         zend_bool is_constant = 1;
    6540             : 
    6541       30878 :         if (ast->attr == ZEND_ARRAY_SYNTAX_LIST) {
    6542           0 :                 zend_error(E_COMPILE_ERROR, "Cannot use list() as standalone expression");
    6543             :         }
    6544             : 
    6545             :         /* First ensure that *all* child nodes are constant and by-val */
    6546      141770 :         for (i = 0; i < list->children; ++i) {
    6547      110895 :                 zend_ast *elem_ast = list->child[i];
    6548             : 
    6549      110895 :                 if (elem_ast == NULL) {
    6550           2 :                         zend_error(E_COMPILE_ERROR, "Cannot use empty array elements in arrays");
    6551             :                 }
    6552             : 
    6553      110893 :                 zend_eval_const_expr(&elem_ast->child[0]);
    6554      110892 :                 zend_eval_const_expr(&elem_ast->child[1]);
    6555             : 
    6556      342650 :                 if (elem_ast->attr /* by_ref */ || elem_ast->child[0]->kind != ZEND_AST_ZVAL
    6557      231758 :                         || (elem_ast->child[1] && elem_ast->child[1]->kind != ZEND_AST_ZVAL)
    6558             :                 ) {
    6559       14225 :                         is_constant = 0;
    6560             :                 }
    6561             :         }
    6562             : 
    6563       30875 :         if (!is_constant) {
    6564        6119 :                 return 0;
    6565             :         }
    6566             : 
    6567       24756 :         array_init_size(result, list->children);
    6568      101259 :         for (i = 0; i < list->children; ++i) {
    6569       76503 :                 zend_ast *elem_ast = list->child[i];
    6570       76503 :                 zend_ast *value_ast = elem_ast->child[0];
    6571       76503 :                 zend_ast *key_ast = elem_ast->child[1];
    6572             : 
    6573       76503 :                 zval *value = zend_ast_get_zval(value_ast);
    6574       76503 :                 if (Z_REFCOUNTED_P(value)) Z_ADDREF_P(value);
    6575             : 
    6576       76503 :                 if (key_ast) {
    6577       18010 :                         zval *key = zend_ast_get_zval(key_ast);
    6578       18010 :                         switch (Z_TYPE_P(key)) {
    6579             :                                 case IS_LONG:
    6580        3075 :                                         zend_hash_index_update(Z_ARRVAL_P(result), Z_LVAL_P(key), value);
    6581        3075 :                                         break;
    6582             :                                 case IS_STRING:
    6583       14411 :                                         zend_symtable_update(Z_ARRVAL_P(result), Z_STR_P(key), value);
    6584       14411 :                                         break;
    6585             :                                 case IS_DOUBLE:
    6586         524 :                                         zend_hash_index_update(Z_ARRVAL_P(result),
    6587             :                                                 zend_dval_to_lval(Z_DVAL_P(key)), value);
    6588         262 :                                         break;
    6589             :                                 case IS_FALSE:
    6590          72 :                                         zend_hash_index_update(Z_ARRVAL_P(result), 0, value);
    6591          72 :                                         break;
    6592             :                                 case IS_TRUE:
    6593          76 :                                         zend_hash_index_update(Z_ARRVAL_P(result), 1, value);
    6594          76 :                                         break;
    6595             :                                 case IS_NULL:
    6596         114 :                                         zend_hash_update(Z_ARRVAL_P(result), ZSTR_EMPTY_ALLOC(), value);
    6597         114 :                                         break;
    6598             :                                 default:
    6599           0 :                                         zend_error_noreturn(E_COMPILE_ERROR, "Illegal offset type");
    6600             :                                         break;
    6601             :                         }
    6602             :                 } else {
    6603       58493 :                         zend_hash_next_index_insert(Z_ARRVAL_P(result), value);
    6604             :                 }
    6605             :         }
    6606             : 
    6607       24756 :         return 1;
    6608             : }
    6609             : /* }}} */
    6610             : 
    6611      102099 : void zend_compile_binary_op(znode *result, zend_ast *ast) /* {{{ */
    6612             : {
    6613      102099 :         zend_ast *left_ast = ast->child[0];
    6614      102099 :         zend_ast *right_ast = ast->child[1];
    6615      102099 :         uint32_t opcode = ast->attr;
    6616             : 
    6617             :         znode left_node, right_node;
    6618      102099 :         zend_compile_expr(&left_node, left_ast);
    6619      102099 :         zend_compile_expr(&right_node, right_ast);
    6620             : 
    6621      102099 :         if (left_node.op_type == IS_CONST && right_node.op_type == IS_CONST) {
    6622        5518 :                 if (zend_try_ct_eval_binary_op(&result->u.constant, opcode,
    6623             :                                 &left_node.u.constant, &right_node.u.constant)
    6624             :                 ) {
    6625        5474 :                         result->op_type = IS_CONST;
    6626        5474 :                         zval_ptr_dtor(&left_node.u.constant);
    6627        5474 :                         zval_ptr_dtor(&right_node.u.constant);
    6628        5474 :                         return;
    6629             :                 }
    6630             :         }
    6631             : 
    6632             :         do {
    6633       96625 :                 if (opcode == ZEND_IS_EQUAL || opcode == ZEND_IS_NOT_EQUAL) {
    6634       20569 :                         if (left_node.op_type == IS_CONST) {
    6635        5665 :                                 if (Z_TYPE(left_node.u.constant) == IS_FALSE) {
    6636         476 :                                         opcode = (opcode == ZEND_IS_NOT_EQUAL) ? ZEND_BOOL : ZEND_BOOL_NOT;
    6637         476 :                                         zend_emit_op_tmp(result, opcode, &right_node, NULL);
    6638         476 :                                         break;
    6639        5189 :                                 } else if (Z_TYPE(left_node.u.constant) == IS_TRUE) {
    6640           2 :                                         opcode = (opcode == ZEND_IS_EQUAL) ? ZEND_BOOL : ZEND_BOOL_NOT;
    6641           2 :                                         zend_emit_op_tmp(result, opcode, &right_node, NULL);
    6642           2 :                                         break;
    6643             :                                 }
    6644       14904 :                         } else if (right_node.op_type == IS_CONST) {
    6645       12693 :                                 if (Z_TYPE(right_node.u.constant) == IS_FALSE) {
    6646        1013 :                                         opcode = (opcode == ZEND_IS_NOT_EQUAL) ? ZEND_BOOL : ZEND_BOOL_NOT;
    6647        1013 :                                         zend_emit_op_tmp(result, opcode, &left_node, NULL);
    6648        1013 :                                         break;
    6649       11680 :                                 } else if (Z_TYPE(right_node.u.constant) == IS_TRUE) {
    6650         588 :                                         opcode = (opcode == ZEND_IS_EQUAL) ? ZEND_BOOL : ZEND_BOOL_NOT;
    6651         588 :                                         zend_emit_op_tmp(result, opcode, &left_node, NULL);
    6652         588 :                                         break;
    6653             :                                 }
    6654             :                         }
    6655             :                 }
    6656       94546 :                 if (opcode == ZEND_CONCAT) {
    6657             :                         /* convert constant operands to strings at compile-time */
    6658       44248 :                         if (left_node.op_type == IS_CONST) {
    6659        8122 :                                 convert_to_string(&left_node.u.constant);
    6660             :                         }
    6661       44248 :                         if (right_node.op_type == IS_CONST) {
    6662       25567 :                                 convert_to_string(&right_node.u.constant);
    6663             :                         }
    6664             :                 }
    6665       94546 :                 zend_emit_op_tmp(result, opcode, &left_node, &right_node);
    6666             :         } while (0);
    6667             : }
    6668             : /* }}} */
    6669             : 
    6670             : /* We do not use zend_compile_binary_op for this because we want to retain the left-to-right
    6671             :  * evaluation order. */
    6672        1583 : void zend_compile_greater(znode *result, zend_ast *ast) /* {{{ */
    6673             : {
    6674        1583 :         zend_ast *left_ast = ast->child[0];
    6675        1583 :         zend_ast *right_ast = ast->child[1];
    6676             :         znode left_node, right_node;
    6677             : 
    6678             :         ZEND_ASSERT(ast->kind == ZEND_AST_GREATER || ast->kind == ZEND_AST_GREATER_EQUAL);
    6679             : 
    6680        1583 :         zend_compile_expr(&left_node, left_ast);
    6681        1583 :         zend_compile_expr(&right_node, right_ast);
    6682             : 
    6683        1583 :         if (left_node.op_type == IS_CONST && right_node.op_type == IS_CONST) {
    6684          23 :                 result->op_type = IS_CONST;
    6685          23 :                 zend_ct_eval_greater(&result->u.constant, ast->kind,
    6686             :                         &left_node.u.constant, &right_node.u.constant);
    6687          23 :                 zval_ptr_dtor(&left_node.u.constant);
    6688          23 :                 zval_ptr_dtor(&right_node.u.constant);
    6689          23 :                 return;
    6690             :         }
    6691             : 
    6692        1560 :         zend_emit_op_tmp(result,
    6693        1560 :                 ast->kind == ZEND_AST_GREATER ? ZEND_IS_SMALLER : ZEND_IS_SMALLER_OR_EQUAL,
    6694             :                 &right_node, &left_node);
    6695             : }
    6696             : /* }}} */
    6697             : 
    6698       33844 : void zend_compile_unary_op(znode *result, zend_ast *ast) /* {{{ */
    6699             : {
    6700       33844 :         zend_ast *expr_ast = ast->child[0];
    6701       33844 :         uint32_t opcode = ast->attr;
    6702             : 
    6703             :         znode expr_node;
    6704       33844 :         zend_compile_expr(&expr_node, expr_ast);
    6705             : 
    6706       33844 :         if (expr_node.op_type == IS_CONST) {
    6707         249 :                 result->op_type = IS_CONST;
    6708         249 :                 zend_ct_eval_unary_op(&result->u.constant, opcode,
    6709             :                         &expr_node.u.constant);
    6710         249 :                 zval_ptr_dtor(&expr_node.u.constant);
    6711         249 :                 return;
    6712             :         }
    6713             : 
    6714       33595 :         zend_emit_op_tmp(result, opcode, &expr_node, NULL);
    6715             : }
    6716             : /* }}} */
    6717             : 
    6718        3485 : void zend_compile_unary_pm(znode *result, zend_ast *ast) /* {{{ */
    6719             : {
    6720        3485 :         zend_ast *expr_ast = ast->child[0];
    6721             :         znode expr_node;
    6722             :         znode lefthand_node;
    6723             : 
    6724             :         ZEND_ASSERT(ast->kind == ZEND_AST_UNARY_PLUS || ast->kind == ZEND_AST_UNARY_MINUS);
    6725             : 
    6726        3485 :         zend_compile_expr(&expr_node, expr_ast);
    6727             : 
    6728        3485 :         if (expr_node.op_type == IS_CONST) {
    6729        3431 :                 if (zend_try_ct_eval_unary_pm(&result->u.constant, ast->kind, &expr_node.u.constant)) {
    6730        3427 :                         result->op_type = IS_CONST;
    6731        3427 :                         zval_ptr_dtor(&expr_node.u.constant);
    6732        3427 :                         return;
    6733             :                 }
    6734             :         }
    6735             : 
    6736          58 :         lefthand_node.op_type = IS_CONST;
    6737          58 :         ZVAL_LONG(&lefthand_node.u.constant, (ast->kind == ZEND_AST_UNARY_PLUS) ? 1 : -1);
    6738          58 :         zend_emit_op_tmp(result, ZEND_MUL, &lefthand_node, &expr_node);
    6739             : }
    6740             : /* }}} */
    6741             : 
    6742       13832 : void zend_compile_short_circuiting(znode *result, zend_ast *ast) /* {{{ */
    6743             : {
    6744       13832 :         zend_ast *left_ast = ast->child[0];
    6745       13832 :         zend_ast *right_ast = ast->child[1];
    6746             : 
    6747             :         znode left_node, right_node;
    6748             :         zend_op *opline_jmpz, *opline_bool;
    6749             :         uint32_t opnum_jmpz;
    6750             : 
    6751             :         ZEND_ASSERT(ast->kind == ZEND_AST_AND || ast->kind == ZEND_AST_OR);
    6752             : 
    6753       13832 :         zend_compile_expr(&left_node, left_ast);
    6754             : 
    6755       13832 :         if (left_node.op_type == IS_CONST) {
    6756         150 :                 if ((ast->kind == ZEND_AST_AND && !zend_is_true(&left_node.u.constant))
    6757          77 :                  || (ast->kind == ZEND_AST_OR && zend_is_true(&left_node.u.constant))) {
    6758          14 :                         result->op_type = IS_CONST;
    6759          14 :                         ZVAL_BOOL(&result->u.constant, zend_is_true(&left_node.u.constant));
    6760             :                 } else {
    6761          45 :                         zend_compile_expr(&right_node, right_ast);
    6762             : 
    6763          45 :                         if (right_node.op_type == IS_CONST) {
    6764          37 :                                 result->op_type = IS_CONST;
    6765          37 :                                 ZVAL_BOOL(&result->u.constant, zend_is_true(&right_node.u.constant));
    6766             : 
    6767          37 :                                 zval_ptr_dtor(&right_node.u.constant);
    6768             :                         } else {
    6769           8 :                                 zend_emit_op_tmp(result, ZEND_BOOL, &right_node, NULL);
    6770             :                         }
    6771             :                 }
    6772             : 
    6773          59 :                 zval_ptr_dtor(&left_node.u.constant);
    6774          59 :                 return;
    6775             :         }
    6776             : 
    6777       13773 :         opnum_jmpz = get_next_op_number(CG(active_op_array));
    6778       13773 :         opline_jmpz = zend_emit_op(NULL, ast->kind == ZEND_AST_AND ? ZEND_JMPZ_EX : ZEND_JMPNZ_EX,
    6779             :                 &left_node, NULL);
    6780             : 
    6781       13773 :         if (left_node.op_type == IS_TMP_VAR) {
    6782       11131 :                 SET_NODE(opline_jmpz->result, &left_node);
    6783             :         } else {
    6784        2642 :                 opline_jmpz->result.var = get_temporary_variable(CG(active_op_array));
    6785        2642 :                 opline_jmpz->result_type = IS_TMP_VAR;
    6786             :         }
    6787             : 
    6788       13773 :         GET_NODE(result, opline_jmpz->result);
    6789       13773 :         zend_compile_expr(&right_node, right_ast);
    6790             : 
    6791       13773 :         opline_bool = zend_emit_op(NULL, ZEND_BOOL, &right_node, NULL);
    6792       13773 :         SET_NODE(opline_bool->result, result);
    6793             : 
    6794       13773 :         zend_update_jump_target_to_next(opnum_jmpz);
    6795             : }
    6796             : /* }}} */
    6797             : 
    6798        6145 : void zend_compile_post_incdec(znode *result, zend_ast *ast) /* {{{ */
    6799             : {
    6800        6145 :         zend_ast *var_ast = ast->child[0];
    6801             :         ZEND_ASSERT(ast->kind == ZEND_AST_POST_INC || ast->kind == ZEND_AST_POST_DEC);
    6802             : 
    6803        6145 :         zend_ensure_writable_variable(var_ast);
    6804             : 
    6805        6145 :         if (var_ast->kind == ZEND_AST_PROP) {
    6806          59 :                 zend_op *opline = zend_compile_prop_common(NULL, var_ast, BP_VAR_RW);
    6807          59 :                 opline->opcode = ast->kind == ZEND_AST_POST_INC ? ZEND_POST_INC_OBJ : ZEND_POST_DEC_OBJ;
    6808          59 :                 zend_make_tmp_result(result, opline);
    6809             :         } else {
    6810             :                 znode var_node;
    6811        6086 :                 zend_compile_var(&var_node, var_ast, BP_VAR_RW);
    6812        6086 :                 zend_emit_op_tmp(result, ast->kind == ZEND_AST_POST_INC ? ZEND_POST_INC : ZEND_POST_DEC,
    6813             :                         &var_node, NULL);
    6814             :         }
    6815        6145 : }
    6816             : /* }}} */
    6817             : 
    6818         581 : void zend_compile_pre_incdec(znode *result, zend_ast *ast) /* {{{ */
    6819             : {
    6820         581 :         zend_ast *var_ast = ast->child[0];
    6821             :         ZEND_ASSERT(ast->kind == ZEND_AST_PRE_INC || ast->kind == ZEND_AST_PRE_DEC);
    6822             : 
    6823         581 :         zend_ensure_writable_variable(var_ast);
    6824             : 
    6825         580 :         if (var_ast->kind == ZEND_AST_PROP) {
    6826          36 :                 zend_op *opline = zend_compile_prop_common(result, var_ast, BP_VAR_RW);
    6827          36 :                 opline->opcode = ast->kind == ZEND_AST_PRE_INC ? ZEND_PRE_INC_OBJ : ZEND_PRE_DEC_OBJ;
    6828             :         } else {
    6829             :                 znode var_node;
    6830         544 :                 zend_compile_var(&var_node, var_ast, BP_VAR_RW);
    6831         544 :                 zend_emit_op(result, ast->kind == ZEND_AST_PRE_INC ? ZEND_PRE_INC : ZEND_PRE_DEC,
    6832             :                         &var_node, NULL);
    6833             :         }
    6834         580 : }
    6835             : /* }}} */
    6836             : 
    6837        6601 : void zend_compile_cast(znode *result, zend_ast *ast) /* {{{ */
    6838             : {
    6839        6601 :         zend_ast *expr_ast = ast->child[0];
    6840             :         znode expr_node;
    6841             :         zend_op *opline;
    6842             : 
    6843        6601 :         zend_compile_expr(&expr_node, expr_ast);
    6844             : 
    6845        6601 :         opline = zend_emit_op_tmp(result, ZEND_CAST, &expr_node, NULL);
    6846        6601 :         opline->extended_value = ast->attr;
    6847        6601 : }
    6848             : /* }}} */
    6849             : 
    6850         214 : static void zend_compile_shorthand_conditional(znode *result, zend_ast *ast) /* {{{ */
    6851             : {
    6852         214 :         zend_ast *cond_ast = ast->child[0];
    6853         214 :         zend_ast *false_ast = ast->child[2];
    6854             : 
    6855             :         znode cond_node, false_node;
    6856             :         zend_op *opline_qm_assign;
    6857             :         uint32_t opnum_jmp_set;
    6858             : 
    6859             :         ZEND_ASSERT(ast->child[1] == NULL);
    6860             : 
    6861         214 :         zend_compile_expr(&cond_node, cond_ast);
    6862             : 
    6863         214 :         opnum_jmp_set = get_next_op_number(CG(active_op_array));
    6864         214 :         zend_emit_op_tmp(result, ZEND_JMP_SET, &cond_node, NULL);
    6865             : 
    6866         214 :         zend_compile_expr(&false_node, false_ast);
    6867             : 
    6868         214 :         opline_qm_assign = zend_emit_op_tmp(NULL, ZEND_QM_ASSIGN, &false_node, NULL);
    6869         214 :         SET_NODE(opline_qm_assign->result, result);
    6870             : 
    6871         214 :         zend_update_jump_target_to_next(opnum_jmp_set);
    6872         214 : }
    6873             : /* }}} */
    6874             : 
    6875       25892 : void zend_compile_conditional(znode *result, zend_ast *ast) /* {{{ */
    6876             : {
    6877       25892 :         zend_ast *cond_ast = ast->child[0];
    6878       25892 :         zend_ast *true_ast = ast->child[1];
    6879       25892 :         zend_ast *false_ast = ast->child[2];
    6880             : 
    6881             :         znode cond_node, true_node, false_node;
    6882             :         zend_op *opline_qm_assign2;
    6883             :         uint32_t opnum_jmpz, opnum_jmp;
    6884             : 
    6885       25892 :         if (!true_ast) {
    6886         214 :                 zend_compile_shorthand_conditional(result, ast);
    6887         214 :                 return;
    6888             :         }
    6889             : 
    6890       25678 :         zend_compile_expr(&cond_node, cond_ast);
    6891             : 
    6892       25678 :         opnum_jmpz = zend_emit_cond_jump(ZEND_JMPZ, &cond_node, 0);
    6893             : 
    6894       25678 :         zend_compile_expr(&true_node, true_ast);
    6895             : 
    6896       25678 :         zend_emit_op_tmp(result, ZEND_QM_ASSIGN, &true_node, NULL);
    6897             : 
    6898       25678 :         opnum_jmp = zend_emit_jump(0);
    6899             : 
    6900       25678 :         zend_update_jump_target_to_next(opnum_jmpz);
    6901             : 
    6902       25678 :         zend_compile_expr(&false_node, false_ast);
    6903             : 
    6904       25678 :         opline_qm_assign2 = zend_emit_op(NULL, ZEND_QM_ASSIGN, &false_node, NULL);
    6905       25678 :         SET_NODE(opline_qm_assign2->result, result);
    6906             : 
    6907       25678 :         zend_update_jump_target_to_next(opnum_jmp);
    6908             : }
    6909             : /* }}} */
    6910             : 
    6911          27 : void zend_compile_coalesce(znode *result, zend_ast *ast) /* {{{ */
    6912             : {
    6913          27 :         zend_ast *expr_ast = ast->child[0];
    6914          27 :         zend_ast *default_ast = ast->child[1];
    6915             : 
    6916             :         znode expr_node, default_node;
    6917             :         zend_op *opline;
    6918             :         uint32_t opnum;
    6919             : 
    6920          27 :         zend_compile_var(&expr_node, expr_ast, BP_VAR_IS);
    6921             : 
    6922          27 :         opnum = get_next_op_number(CG(active_op_array));
    6923          27 :         zend_emit_op_tmp(result, ZEND_COALESCE, &expr_node, NULL);
    6924             : 
    6925          27 :         zend_compile_expr(&default_node, default_ast);
    6926             : 
    6927          27 :         opline = zend_emit_op_tmp(NULL, ZEND_QM_ASSIGN, &default_node, NULL);
    6928          27 :         SET_NODE(opline->result, result);
    6929             : 
    6930          27 :         opline = &CG(active_op_array)->opcodes[opnum];
    6931          27 :         opline->op2.opline_num = get_next_op_number(CG(active_op_array));
    6932          27 : }
    6933             : /* }}} */
    6934             : 
    6935        3539 : void zend_compile_print(znode *result, zend_ast *ast) /* {{{ */
    6936             : {
    6937             :         zend_op *opline;
    6938        3539 :         zend_ast *expr_ast = ast->child[0];
    6939             : 
    6940             :         znode expr_node;
    6941        3539 :         zend_compile_expr(&expr_node, expr_ast);
    6942             : 
    6943        3539 :         opline = zend_emit_op(NULL, ZEND_ECHO, &expr_node, NULL);
    6944        3539 :         opline->extended_value = 1;
    6945             : 
    6946        3539 :         result->op_type = IS_CONST;
    6947        3539 :         ZVAL_LONG(&result->u.constant, 1);
    6948        3539 : }
    6949             : /* }}} */
    6950             : 
    6951       17475 : void zend_compile_exit(znode *result, zend_ast *ast) /* {{{ */
    6952             : {
    6953       17475 :         zend_ast *expr_ast = ast->child[0];
    6954             : 
    6955       17475 :         if (expr_ast) {
    6956             :                 znode expr_node;
    6957       16892 :                 zend_compile_expr(&expr_node, expr_ast);
    6958       16892 :                 zend_emit_op(NULL, ZEND_EXIT, &expr_node, NULL);
    6959             :         } else {
    6960         583 :                 zend_emit_op(NULL, ZEND_EXIT, NULL, NULL);
    6961             :         }
    6962             : 
    6963       17475 :         result->op_type = IS_CONST;
    6964       17475 :         ZVAL_BOOL(&result->u.constant, 1);
    6965       17475 : }
    6966             : /* }}} */
    6967             : 
    6968         261 : void zend_compile_yield(znode *result, zend_ast *ast) /* {{{ */
    6969             : {
    6970         261 :         zend_ast *value_ast = ast->child[0];
    6971         261 :         zend_ast *key_ast = ast->child[1];
    6972             : 
    6973             :         znode value_node, key_node;
    6974         261 :         znode *value_node_ptr = NULL, *key_node_ptr = NULL;
    6975             :         zend_op *opline;
    6976         261 :         zend_bool returns_by_ref = (CG(active_op_array)->fn_flags & ZEND_ACC_RETURN_REFERENCE) != 0;
    6977             : 
    6978         261 :         zend_mark_function_as_generator();
    6979             : 
    6980         260 :         if (key_ast) {
    6981          32 :                 zend_compile_expr(&key_node, key_ast);
    6982          32 :                 key_node_ptr = &key_node;
    6983             :         }
    6984             : 
    6985         260 :         if (value_ast) {
    6986         178 :                 if (returns_by_ref && zend_is_variable(value_ast) && !zend_is_call(value_ast)) {
    6987           7 :                         zend_compile_var(&value_node, value_ast, BP_VAR_W);
    6988             :                 } else {
    6989         164 :                         zend_compile_expr(&value_node, value_ast);
    6990             :                 }
    6991         171 :                 value_node_ptr = &value_node;
    6992             :         }
    6993             : 
    6994         260 :         opline = zend_emit_op(result, ZEND_YIELD, value_node_ptr, key_node_ptr);
    6995             : 
    6996         260 :         if (value_ast && returns_by_ref && zend_is_call(value_ast)) {
    6997           2 :                 opline->extended_value = ZEND_RETURNS_FUNCTION;
    6998             :         }
    6999         260 : }
    7000             : /* }}} */
    7001             : 
    7002          41 : void zend_compile_yield_from(znode *result, zend_ast *ast) /* {{{ */
    7003             : {
    7004          41 :         zend_ast *expr_ast = ast->child[0];
    7005             :         znode expr_node;
    7006             : 
    7007          41 :         zend_mark_function_as_generator();
    7008             : 
    7009          41 :         if (CG(active_op_array)->fn_flags & ZEND_ACC_RETURN_REFERENCE) {
    7010           1 :                 zend_error_noreturn(E_COMPILE_ERROR,
    7011             :                         "Cannot use \"yield from\" inside a by-reference generator");
    7012             :         }
    7013             : 
    7014          40 :         zend_compile_expr(&expr_node, expr_ast);
    7015          40 :         zend_emit_op_tmp(result, ZEND_YIELD_FROM, &expr_node, NULL);
    7016          40 : }
    7017             : /* }}} */
    7018             : 
    7019          75 : void zend_compile_instanceof(znode *result, zend_ast *ast) /* {{{ */
    7020             : {
    7021          75 :         zend_ast *obj_ast = ast->child[0];
    7022          75 :         zend_ast *class_ast = ast->child[1];
    7023             : 
    7024             :         znode obj_node, class_node;
    7025             :         zend_op *opline;
    7026             : 
    7027          75 :         zend_compile_expr(&obj_node, obj_ast);
    7028          75 :         if (obj_node.op_type == IS_CONST) {
    7029           1 :                 zend_error_noreturn(E_COMPILE_ERROR,
    7030             :                         "instanceof expects an object instance, constant given");
    7031             :         }
    7032             : 
    7033          74 :         zend_compile_class_ref_ex(&class_node, class_ast,
    7034             :                 ZEND_FETCH_CLASS_NO_AUTOLOAD | ZEND_FETCH_CLASS_EXCEPTION);
    7035             : 
    7036          74 :         opline = zend_emit_op_tmp(result, ZEND_INSTANCEOF, &obj_node, NULL);
    7037             : 
    7038          74 :         if (class_node.op_type == IS_CONST) {
    7039          68 :                 opline->op2_type = IS_CONST;
    7040          68 :                 opline->op2.constant = zend_add_class_name_literal(
    7041             :                         CG(active_op_array), Z_STR(class_node.u.constant));
    7042             :         } else {
    7043           6 :                 SET_NODE(opline->op2, &class_node);
    7044             :         }
    7045          74 : }
    7046             : /* }}} */
    7047             : 
    7048       13604 : void zend_compile_include_or_eval(znode *result, zend_ast *ast) /* {{{ */
    7049             : {
    7050       13604 :         zend_ast *expr_ast = ast->child[0];
    7051             :         znode expr_node;
    7052             :         zend_op *opline;
    7053             : 
    7054       13604 :         zend_do_extended_fcall_begin();
    7055       13604 :         zend_compile_expr(&expr_node, expr_ast);
    7056             : 
    7057       13604 :         opline = zend_emit_op(result, ZEND_INCLUDE_OR_EVAL, &expr_node, NULL);
    7058       13604 :         opline->extended_value = ast->attr;
    7059             : 
    7060       13604 :         zend_do_extended_fcall_end();
    7061       13604 : }
    7062             : /* }}} */
    7063             : 
    7064       13920 : void zend_compile_isset_or_empty(znode *result, zend_ast *ast) /* {{{ */
    7065             : {
    7066       13920 :         zend_ast *var_ast = ast->child[0];
    7067             : 
    7068             :         znode var_node;
    7069       13920 :         zend_op *opline = NULL;
    7070             : 
    7071             :         ZEND_ASSERT(ast->kind == ZEND_AST_ISSET || ast->kind == ZEND_AST_EMPTY);
    7072             : 
    7073       13920 :         if (!zend_is_variable(var_ast) || zend_is_call(var_ast)) {
    7074          16 :                 if (ast->kind == ZEND_AST_EMPTY) {
    7075             :                         /* empty(expr) can be transformed to !expr */
    7076          14 :                         zend_ast *not_ast = zend_ast_create_ex(ZEND_AST_UNARY_OP, ZEND_BOOL_NOT, var_ast);
    7077          14 :                         zend_compile_expr(result, not_ast);
    7078          14 :                         return;
    7079             :                 } else {
    7080           2 :                         zend_error_noreturn(E_COMPILE_ERROR,
    7081             :                                 "Cannot use isset() on the result of an expression "
    7082             :                                 "(you can use \"null !== expression\" instead)");
    7083             :                 }
    7084             :         }
    7085             : 
    7086       13904 :         switch (var_ast->kind) {
    7087             :                 case ZEND_AST_VAR:
    7088        4510 :                         if (is_this_fetch(var_ast)) {
    7089          17 :                                 opline = zend_emit_op(result, ZEND_ISSET_ISEMPTY_THIS, NULL, NULL);
    7090        4493 :                         } else if (zend_try_compile_cv(&var_node, var_ast) == SUCCESS) {
    7091        4473 :                                 opline = zend_emit_op(result, ZEND_ISSET_ISEMPTY_VAR, &var_node, NULL);
    7092        4473 :                                 opline->extended_value = ZEND_FETCH_LOCAL | ZEND_QUICK_SET;
    7093             :                         } else {
    7094          20 :                                 opline = zend_compile_simple_var_no_cv(result, var_ast, BP_VAR_IS, 0);
    7095          20 :                                 opline->opcode = ZEND_ISSET_ISEMPTY_VAR;
    7096             :                         }
    7097        4510 :                         break;
    7098             :                 case ZEND_AST_DIM:
    7099        8515 :                         opline = zend_compile_dim_common(result, var_ast, BP_VAR_IS);
    7100        8514 :                         opline->opcode = ZEND_ISSET_ISEMPTY_DIM_OBJ;
    7101        8514 :                         break;
    7102             :                 case ZEND_AST_PROP:
    7103         744 :                         opline = zend_compile_prop_common(result, var_ast, BP_VAR_IS);
    7104         744 :                         opline->opcode = ZEND_ISSET_ISEMPTY_PROP_OBJ;
    7105         744 :                         break;
    7106             :                 case ZEND_AST_STATIC_PROP:
    7107         135 :                         opline = zend_compile_static_prop_common(result, var_ast, BP_VAR_IS, 0);
    7108         135 :                         opline->opcode = ZEND_ISSET_ISEMPTY_STATIC_PROP;
    7109             :                         break;
    7110             :                 EMPTY_SWITCH_DEFAULT_CASE()
    7111             :         }
    7112             : 
    7113       13903 :         result->op_type = opline->result_type = IS_TMP_VAR;
    7114       13903 :         opline->extended_value |= ast->kind == ZEND_AST_ISSET ? ZEND_ISSET : ZEND_ISEMPTY;
    7115             : }
    7116             : /* }}} */
    7117             : 
    7118        7190 : void zend_compile_silence(znode *result, zend_ast *ast) /* {{{ */
    7119             : {
    7120        7190 :         zend_ast *expr_ast = ast->child[0];
    7121             :         znode silence_node;
    7122             :         uint32_t range;
    7123             : 
    7124        7190 :         range = zend_start_live_range(CG(active_op_array), get_next_op_number(CG(active_op_array)));
    7125        7190 :         zend_emit_op_tmp(&silence_node, ZEND_BEGIN_SILENCE, NULL, NULL);
    7126             : 
    7127        7190 :         if (expr_ast->kind == ZEND_AST_VAR) {
    7128             :                 /* For @$var we need to force a FETCH instruction, otherwise the CV access will
    7129             :                  * happen outside the silenced section. */
    7130        1479 :                 zend_compile_simple_var_no_cv(result, expr_ast, BP_VAR_R, 0 );
    7131             :         } else {
    7132        5711 :                 zend_compile_expr(result, expr_ast);
    7133             :         }
    7134             : 
    7135             :         /* Store BEGIN_SILENCE/END_SILENCE pair to restore previous
    7136             :          * EG(error_reporting) value on exception */
    7137        7190 :         zend_end_live_range(CG(active_op_array), range, get_next_op_number(CG(active_op_array)),
    7138             :                 ZEND_LIVE_SILENCE, silence_node.u.op.var);
    7139             : 
    7140        7190 :         zend_emit_op(NULL, ZEND_END_SILENCE, &silence_node, NULL);
    7141        7190 : }
    7142             : /* }}} */
    7143             : 
    7144         121 : void zend_compile_shell_exec(znode *result, zend_ast *ast) /* {{{ */
    7145             : {
    7146         121 :         zend_ast *expr_ast = ast->child[0];
    7147             : 
    7148             :         zval fn_name;
    7149             :         zend_ast *name_ast, *args_ast, *call_ast;
    7150             : 
    7151         242 :         ZVAL_STRING(&fn_name, "shell_exec");
    7152         121 :         name_ast = zend_ast_create_zval(&fn_name);
    7153         121 :         args_ast = zend_ast_create_list(1, ZEND_AST_ARG_LIST, expr_ast);
    7154         121 :         call_ast = zend_ast_create(ZEND_AST_CALL, name_ast, args_ast);
    7155             : 
    7156         121 :         zend_compile_expr(result, call_ast);
    7157             : 
    7158         121 :         zval_ptr_dtor(&fn_name);
    7159         121 : }
    7160             : /* }}} */
    7161             : 
    7162       19061 : void zend_compile_array(znode *result, zend_ast *ast) /* {{{ */
    7163             : {
    7164       19061 :         zend_ast_list *list = zend_ast_get_list(ast);
    7165             :         zend_op *opline;
    7166       19061 :         uint32_t i, opnum_init = -1;
    7167       19061 :         zend_bool packed = 1;
    7168             : 
    7169       19061 :         if (zend_try_ct_eval_array(&result->u.constant, ast)) {
    7170       14044 :                 result->op_type = IS_CONST;
    7171       14044 :                 return;
    7172             :         }
    7173             : 
    7174       36551 :         for (i = 0; i < list->children; ++i) {
    7175       31537 :                 zend_ast *elem_ast = list->child[i];
    7176             :                 zend_ast *value_ast, *key_ast;
    7177             :                 zend_bool by_ref;
    7178       31537 :                 znode value_node, key_node, *key_node_ptr = NULL;
    7179             : 
    7180       31537 :                 if (elem_ast == NULL) {
    7181           0 :                         zend_error(E_COMPILE_ERROR, "Cannot use empty array elements in arrays");
    7182             :                 }
    7183             : 
    7184       31537 :                 value_ast = elem_ast->child[0];
    7185       31537 :                 key_ast = elem_ast->child[1];
    7186       31537 :                 by_ref = elem_ast->attr;
    7187             : 
    7188       31537 :                 if (key_ast) {
    7189       10906 :                         zend_compile_expr(&key_node, key_ast);
    7190       10906 :                         zend_handle_numeric_op(&key_node);
    7191       10906 :                         key_node_ptr = &key_node;
    7192             :                 }
    7193             : 
    7194       31537 :                 if (by_ref) {
    7195         159 :                         zend_ensure_writable_variable(value_ast);
    7196         159 :                         zend_compile_var(&value_node, value_ast, BP_VAR_W);
    7197             :                 } else {
    7198       31378 :                         zend_compile_expr(&value_node, value_ast);
    7199             :                 }
    7200             : 
    7201       31537 :                 if (i == 0) {
    7202        5014 :                         opnum_init = get_next_op_number(CG(active_op_array));
    7203        5014 :                         opline = zend_emit_op_tmp(result, ZEND_INIT_ARRAY, &value_node, key_node_ptr);
    7204        5014 :                         opline->extended_value = list->children << ZEND_ARRAY_SIZE_SHIFT;
    7205             :                 } else {
    7206       26523 :                         opline = zend_emit_op(NULL, ZEND_ADD_ARRAY_ELEMENT,
    7207             :                                 &value_node, key_node_ptr);
    7208       26523 :                         SET_NODE(opline->result, result);
    7209             :                 }
    7210       31537 :                 opline->extended_value |= by_ref;
    7211             : 
    7212       42230 :                 if (key_ast && key_node.op_type == IS_CONST && Z_TYPE(key_node.u.constant) == IS_STRING) {
    7213        9922 :                         packed = 0;
    7214             :                 }
    7215             :         }
    7216             : 
    7217             :         /* Handle empty array */
    7218        5014 :         if (!list->children) {
    7219           0 :                 zend_emit_op_tmp(result, ZEND_INIT_ARRAY, NULL, NULL);
    7220             :         }
    7221             : 
    7222             :         /* Add a flag to INIT_ARRAY if we know this array cannot be packed */
    7223        5014 :         if (!packed) {
    7224             :                 ZEND_ASSERT(opnum_init != (uint32_t)-1);
    7225        2018 :                 opline = &CG(active_op_array)->opcodes[opnum_init];
    7226        2018 :                 opline->extended_value |= ZEND_ARRAY_NOT_PACKED;
    7227             :         }
    7228             : }
    7229             : /* }}} */
    7230             : 
    7231       75033 : void zend_compile_const(znode *result, zend_ast *ast) /* {{{ */
    7232             : {
    7233       75033 :         zend_ast *name_ast = ast->child[0];
    7234             : 
    7235             :         zend_op *opline;
    7236             : 
    7237             :         zend_bool is_fully_qualified;
    7238       75033 :         zend_string *orig_name = zend_ast_get_str(name_ast);
    7239       75033 :         zend_string *resolved_name = zend_resolve_const_name(orig_name, name_ast->attr, &is_fully_qualified);
    7240             : 
    7241       75033 :         if (zend_string_equals_literal(resolved_name, "__COMPILER_HALT_OFFSET__") || (name_ast->attr != ZEND_NAME_RELATIVE && zend_string_equals_literal(orig_name, "__COMPILER_HALT_OFFSET__"))) {
    7242          11 :                 zend_ast *last = CG(ast);
    7243             : 
    7244          33 :                 while (last->kind == ZEND_AST_STMT_LIST) {
    7245          11 :                         zend_ast_list *list = zend_ast_get_list(last);
    7246          11 :                         last = list->child[list->children-1];
    7247             :                 }
    7248          11 :                 if (last->kind == ZEND_AST_HALT_COMPILER) {
    7249          11 :                         result->op_type = IS_CONST;
    7250          22 :                         ZVAL_LONG(&result->u.constant, Z_LVAL_P(zend_ast_get_zval(last->child[0])));
    7251             :                         zend_string_release(resolved_name);
    7252          11 :                         return;
    7253             :                 }
    7254             :         }
    7255             : 
    7256       75022 :         if (zend_try_ct_eval_const(&result->u.constant, resolved_name, is_fully_qualified)) {
    7257       69314 :                 result->op_type = IS_CONST;
    7258             :                 zend_string_release(resolved_name);
    7259       69314 :                 return;
    7260             :         }
    7261             : 
    7262        5708 :         opline = zend_emit_op_tmp(result, ZEND_FETCH_CONSTANT, NULL, NULL);
    7263        5708 :         opline->op2_type = IS_CONST;
    7264             : 
    7265        5708 :         if (is_fully_qualified) {
    7266          68 :                 opline->op2.constant = zend_add_const_name_literal(
    7267             :                         CG(active_op_array), resolved_name, 0);
    7268             :         } else {
    7269        5640 :                 opline->extended_value = IS_CONSTANT_UNQUALIFIED;
    7270        5640 :                 if (FC(current_namespace)) {
    7271          27 :                         opline->extended_value |= IS_CONSTANT_IN_NAMESPACE;
    7272          27 :                         opline->op2.constant = zend_add_const_name_literal(
    7273             :                                 CG(active_op_array), resolved_name, 1);
    7274             :                 } else {
    7275        5613 :                         opline->op2.constant = zend_add_const_name_literal(
    7276             :                                 CG(active_op_array), resolved_name, 0);
    7277             :                 }
    7278             :         }
    7279        5708 :         zend_alloc_cache_slot(opline->op2.constant);
    7280             : }
    7281             : /* }}} */
    7282             : 
    7283       10178 : void zend_compile_class_const(znode *result, zend_ast *ast) /* {{{ */
    7284             : {
    7285       10178 :         zend_ast *class_ast = ast->child[0];
    7286       10178 :         zend_ast *const_ast = ast->child[1];
    7287             : 
    7288             :         znode class_node, const_node;
    7289             :         zend_op *opline;
    7290             : 
    7291       10178 :         if (zend_try_compile_const_expr_resolve_class_name(&result->u.constant, class_ast, const_ast, 0)) {
    7292         104 :                 if (Z_TYPE(result->u.constant) == IS_NULL) {
    7293          27 :                         zend_op *opline = zend_emit_op_tmp(result, ZEND_FETCH_CLASS_NAME, NULL, NULL);
    7294          54 :                         opline->extended_value = zend_get_class_fetch_type(zend_ast_get_str(class_ast));
    7295             :                 } else {
    7296          25 :                         result->op_type = IS_CONST;
    7297             :                 }
    7298          52 :                 return;
    7299             :         }
    7300             : 
    7301       10126 :         zend_eval_const_expr(&class_ast);
    7302       10126 :         zend_eval_const_expr(&const_ast);
    7303             : 
    7304       10126 :         if (class_ast->kind == ZEND_AST_ZVAL) {
    7305             :                 zend_string *resolved_name;
    7306             : 
    7307       10121 :                 resolved_name = zend_resolve_class_name_ast(class_ast);
    7308       20240 :                 if (const_ast->kind == ZEND_AST_ZVAL && zend_try_ct_eval_class_const(&result->u.constant, resolved_name, zend_ast_get_str(const_ast))) {
    7309       10001 :                         result->op_type = IS_CONST;
    7310             :                         zend_string_release(resolved_name);
    7311       10001 :                         return;
    7312             :                 }
    7313             :                 zend_string_release(resolved_name);
    7314             :         }
    7315         254 :         if (const_ast->kind == ZEND_AST_ZVAL && zend_string_equals_literal_ci(zend_ast_get_str(const_ast), "class")) {
    7316           0 :                 zend_error_noreturn(E_COMPILE_ERROR,
    7317             :                         "Dynamic class names are not allowed in compile-time ::class fetch");
    7318             :         }
    7319             : 
    7320         124 :         zend_compile_class_ref_ex(&class_node, class_ast, ZEND_FETCH_CLASS_EXCEPTION);
    7321             : 
    7322         123 :         zend_compile_expr(&const_node, const_ast);
    7323             : 
    7324         123 :         opline = zend_emit_op_tmp(result, ZEND_FETCH_CLASS_CONSTANT, NULL, &const_node);
    7325             : 
    7326         123 :         zend_set_class_name_op1(opline, &class_node);
    7327             : 
    7328         123 :         if (opline->op1_type == IS_CONST) {
    7329          95 :                 zend_alloc_cache_slot(opline->op2.constant);
    7330             :         } else {
    7331          28 :                 zend_alloc_polymorphic_cache_slot(opline->op2.constant);
    7332             :         }
    7333             : }
    7334             : /* }}} */
    7335             : 
    7336           0 : void zend_compile_resolve_class_name(znode *result, zend_ast *ast) /* {{{ */
    7337             : {
    7338           0 :         zend_ast *name_ast = ast->child[0];
    7339           0 :         uint32_t fetch_type = zend_get_class_fetch_type(zend_ast_get_str(name_ast));
    7340           0 :         zend_ensure_valid_class_fetch_type(fetch_type);
    7341             : 
    7342           0 :         switch (fetch_type) {
    7343             :                 case ZEND_FETCH_CLASS_SELF:
    7344           0 :                         if (CG(active_class_entry) && zend_is_scope_known()) {
    7345           0 :                                 result->op_type = IS_CONST;
    7346           0 :                                 ZVAL_STR_COPY(&result->u.constant, CG(active_class_entry)->name);
    7347             :                         } else {
    7348           0 :                                 zend_op *opline = zend_emit_op_tmp(result, ZEND_FETCH_CLASS_NAME, NULL, NULL);
    7349           0 :                                 opline->extended_value = fetch_type;
    7350             :                         }
    7351           0 :                         break;
    7352             :                 case ZEND_FETCH_CLASS_STATIC:
    7353             :                 case ZEND_FETCH_CLASS_PARENT:
    7354             :                         {
    7355           0 :                                 zend_op *opline = zend_emit_op_tmp(result, ZEND_FETCH_CLASS_NAME, NULL, NULL);
    7356           0 :                                 opline->extended_value = fetch_type;
    7357             :                         }
    7358           0 :                         break;
    7359             :                 case ZEND_FETCH_CLASS_DEFAULT:
    7360           0 :                         result->op_type = IS_CONST;
    7361           0 :                         ZVAL_STR(&result->u.constant, zend_resolve_class_name_ast(name_ast));
    7362             :                         break;
    7363             :                 EMPTY_SWITCH_DEFAULT_CASE()
    7364             :         }
    7365           0 : }
    7366             : /* }}} */
    7367             : 
    7368       60437 : static zend_op *zend_compile_rope_add(znode *result, uint32_t num, znode *elem_node) /* {{{ */
    7369             : {
    7370       60437 :         zend_op *opline = get_next_op(CG(active_op_array));
    7371             : 
    7372       60437 :         if (num == 0) {
    7373       19367 :                 result->op_type = IS_TMP_VAR;
    7374       19367 :                 result->u.op.var = -1;
    7375       19367 :                 opline->opcode = ZEND_ROPE_INIT;
    7376       19367 :                 SET_UNUSED(opline->op1);
    7377             :         } else {
    7378       41070 :                 opline->opcode = ZEND_ROPE_ADD;
    7379       41070 :                 SET_NODE(opline->op1, result);
    7380             :         }
    7381       60437 :         SET_NODE(opline->op2, elem_node);
    7382       60437 :         SET_NODE(opline->result, result);
    7383       60437 :         opline->extended_value = num;
    7384       60437 :         return opline;
    7385             : }
    7386             : /* }}} */
    7387             : 
    7388       19367 : static void zend_compile_encaps_list(znode *result, zend_ast *ast) /* {{{ */
    7389             : {
    7390             :         uint32_t i, j;
    7391       19367 :         uint32_t rope_init_lineno = -1;
    7392       19367 :         zend_op *opline = NULL, *init_opline;
    7393             :         znode elem_node, last_const_node;
    7394       19367 :         zend_ast_list *list = zend_ast_get_list(ast);
    7395             : 
    7396             :         ZEND_ASSERT(list->children > 0);
    7397             : 
    7398       19367 :         j = 0;
    7399       19367 :         last_const_node.op_type = IS_UNUSED;
    7400       79813 :         for (i = 0; i < list->children; i++) {
    7401       60446 :                 zend_compile_expr(&elem_node, list->child[i]);
    7402             : 
    7403       60446 :                 if (elem_node.op_type == IS_CONST) {
    7404       33158 :                         convert_to_string(&elem_node.u.constant);
    7405             : 
    7406       33158 :                         if (Z_STRLEN(elem_node.u.constant) == 0) {
    7407           9 :                                 zval_ptr_dtor(&elem_node.u.constant);
    7408       33149 :                         } else if (last_const_node.op_type == IS_CONST) {
    7409           0 :                                 concat_function(&last_const_node.u.constant, &last_const_node.u.constant, &elem_node.u.constant);
    7410           0 :                                 zval_ptr_dtor(&elem_node.u.constant);
    7411             :                         } else {
    7412       33149 :                                 last_const_node.op_type = IS_CONST;
    7413       33149 :                                 ZVAL_COPY_VALUE(&last_const_node.u.constant, &elem_node.u.constant);
    7414             :                         }
    7415       33158 :                         continue;
    7416             :                 } else {
    7417       27288 :                         if (j == 0) {
    7418       19367 :                                 rope_init_lineno = get_next_op_number(CG(active_op_array));
    7419             :                         }
    7420       27288 :                         if (last_const_node.op_type == IS_CONST) {
    7421       21857 :                                 zend_compile_rope_add(result, j++, &last_const_node);
    7422       21857 :                                 last_const_node.op_type = IS_UNUSED;
    7423             :                         }
    7424       27288 :                         opline = zend_compile_rope_add(result, j++, &elem_node);
    7425             :                 }
    7426             :         }
    7427             : 
    7428       19367 :         if (j == 0) {
    7429           0 :                 result->op_type = IS_CONST;
    7430           0 :                 if (last_const_node.op_type == IS_CONST) {
    7431           0 :                         ZVAL_COPY_VALUE(&result->u.constant, &last_const_node.u.constant);
    7432             :                 } else {
    7433           0 :                         ZVAL_EMPTY_STRING(&result->u.constant);
    7434             :                         /* empty string */
    7435             :                 }
    7436           0 :                 return;
    7437       19367 :         } else if (last_const_node.op_type == IS_CONST) {
    7438       11292 :                 opline = zend_compile_rope_add(result, j++, &last_const_node);
    7439             :         }
    7440       19367 :         init_opline = CG(active_op_array)->opcodes + rope_init_lineno;
    7441       19367 :         if (j == 1) {
    7442         423 :                 if (opline->op2_type == IS_CONST) {
    7443           0 :                         GET_NODE(result, opline->op2);
    7444           0 :                         MAKE_NOP(opline);
    7445             :                 } else {
    7446         423 :                         opline->opcode = ZEND_CAST;
    7447         423 :                         opline->extended_value = IS_STRING;
    7448         423 :                         opline->op1_type = opline->op2_type;
    7449         423 :                         opline->op1 = opline->op2;
    7450         423 :                         opline->result_type = IS_TMP_VAR;
    7451         423 :                         opline->result.var = get_temporary_variable(CG(active_op_array));
    7452         423 :                         SET_UNUSED(opline->op2);
    7453         423 :                         GET_NODE(result, opline->result);
    7454             :                 }
    7455       18944 :         } else if (j == 2) {
    7456        6131 :                 opline->opcode = ZEND_FAST_CONCAT;
    7457        6131 :                 opline->extended_value = 0;
    7458        6131 :                 opline->op1_type = init_opline->op2_type;
    7459        6131 :                 opline->op1 = init_opline->op2;
    7460        6131 :                 opline->result_type = IS_TMP_VAR;
    7461        6131 :                 opline->result.var = get_temporary_variable(CG(active_op_array));
    7462        6131 :                 MAKE_NOP(init_opline);
    7463        6131 :                 GET_NODE(result, opline->result);
    7464             :         } else {
    7465             :                 uint32_t var;
    7466       12813 :                 uint32_t range = zend_start_live_range(CG(active_op_array), rope_init_lineno);
    7467             : 
    7468       12813 :                 init_opline->extended_value = j;
    7469       12813 :                 opline->opcode = ZEND_ROPE_END;
    7470       12813 :                 opline->result.var = get_temporary_variable(CG(active_op_array));
    7471       12813 :                 var = opline->op1.var = get_temporary_variable(CG(active_op_array));
    7472       12813 :                 GET_NODE(result, opline->result);
    7473             : 
    7474             :                 /* Allocates the necessary number of zval slots to keep the rope */
    7475       12813 :                 i = ((j * sizeof(zend_string*)) + (sizeof(zval) - 1)) / sizeof(zval);
    7476       42708 :                 while (i > 1) {
    7477       17082 :                         get_temporary_variable(CG(active_op_array));
    7478       17082 :                         i--;                    
    7479             :                 }
    7480             : 
    7481       12813 :                 zend_end_live_range(CG(active_op_array), range, opline - CG(active_op_array)->opcodes,
    7482             :                         ZEND_LIVE_ROPE, var);
    7483             : 
    7484             :                 /* Update all the previous opcodes to use the same variable */
    7485       60901 :                 while (opline != init_opline) {
    7486       35275 :                         opline--;
    7487       79528 :                         if (opline->opcode == ZEND_ROPE_ADD &&
    7488       22127 :                             opline->result.var == (uint32_t)-1) {
    7489       22126 :                                 opline->op1.var = var;
    7490       22126 :                                 opline->result.var = var;
    7491       25963 :                         } else if (opline->opcode == ZEND_ROPE_INIT &&
    7492       12814 :                                    opline->result.var == (uint32_t)-1) {
    7493       12813 :                                 opline->result.var = var;
    7494             :                         }
    7495             :                 }
    7496             :         }
    7497             : }
    7498             : /* }}} */
    7499             : 
    7500       12003 : void zend_compile_magic_const(znode *result, zend_ast *ast) /* {{{ */
    7501             : {
    7502             :         zend_op *opline;
    7503             : 
    7504       12003 :         if (zend_try_ct_eval_magic_const(&result->u.constant, ast)) {
    7505       11999 :                 result->op_type = IS_CONST;
    7506       11999 :                 return;
    7507             :         }
    7508             : 
    7509             :         ZEND_ASSERT(ast->attr == T_CLASS_C &&
    7510             :                     CG(active_class_entry) &&
    7511             :                     (CG(active_class_entry)->ce_flags & ZEND_ACC_TRAIT) != 0);
    7512             : 
    7513           4 :         opline = zend_emit_op_tmp(result, ZEND_FETCH_CLASS_NAME, NULL, NULL);
    7514           4 :         opline->extended_value = ZEND_FETCH_CLASS_SELF;
    7515             : }
    7516             : /* }}} */
    7517             : 
    7518         813 : zend_bool zend_is_allowed_in_const_expr(zend_ast_kind kind) /* {{{ */
    7519             : {
    7520         813 :         return kind == ZEND_AST_ZVAL || kind == ZEND_AST_BINARY_OP
    7521             :                 || kind == ZEND_AST_GREATER || kind == ZEND_AST_GREATER_EQUAL
    7522             :                 || kind == ZEND_AST_AND || kind == ZEND_AST_OR
    7523             :                 || kind == ZEND_AST_UNARY_OP
    7524             :                 || kind == ZEND_AST_UNARY_PLUS || kind == ZEND_AST_UNARY_MINUS
    7525             :                 || kind == ZEND_AST_CONDITIONAL || kind == ZEND_AST_DIM
    7526             :                 || kind == ZEND_AST_ARRAY || kind == ZEND_AST_ARRAY_ELEM
    7527             :                 || kind == ZEND_AST_CONST || kind == ZEND_AST_CLASS_CONST
    7528             :                 || kind == ZEND_AST_MAGIC_CONST || kind == ZEND_AST_COALESCE;
    7529             : }
    7530             : /* }}} */
    7531             : 
    7532         312 : void zend_compile_const_expr_class_const(zend_ast **ast_ptr) /* {{{ */
    7533             : {
    7534         312 :         zend_ast *ast = *ast_ptr;
    7535         312 :         zend_ast *class_ast = ast->child[0];
    7536         312 :         zend_ast *const_ast = ast->child[1];
    7537             :         zend_string *class_name;
    7538         312 :         zend_string *const_name = zend_ast_get_str(const_ast);
    7539             :         zval result;
    7540             :         int fetch_type;
    7541             : 
    7542         312 :         if (class_ast->kind != ZEND_AST_ZVAL) {
    7543           1 :                 zend_error_noreturn(E_COMPILE_ERROR,
    7544             :                         "Dynamic class names are not allowed in compile-time class constant references");
    7545             :         }
    7546             : 
    7547         311 :         if (zend_try_compile_const_expr_resolve_class_name(&result, class_ast, const_ast, 1)) {
    7548           0 :                 *ast_ptr = zend_ast_create_zval(&result);
    7549           0 :                 return;
    7550             :         }
    7551             : 
    7552         307 :         class_name = zend_ast_get_str(class_ast);
    7553         307 :         fetch_type = zend_get_class_fetch_type(class_name);
    7554             : 
    7555         307 :         if (ZEND_FETCH_CLASS_STATIC == fetch_type) {
    7556           1 :                 zend_error_noreturn(E_COMPILE_ERROR,
    7557             :                         "\"static::\" is not allowed in compile-time constants");
    7558             :         }
    7559             : 
    7560         306 :         if (ZEND_FETCH_CLASS_DEFAULT == fetch_type) {
    7561         268 :                 class_name = zend_resolve_class_name_ast(class_ast);
    7562             :         } else {
    7563             :                 zend_string_addref(class_name);
    7564             :         }
    7565             : 
    7566         306 :         Z_STR(result) = zend_concat3(
    7567             :                 ZSTR_VAL(class_name), ZSTR_LEN(class_name), "::", 2, ZSTR_VAL(const_name), ZSTR_LEN(const_name));
    7568             : 
    7569         306 :         Z_TYPE_INFO(result) = IS_CONSTANT_EX;
    7570         306 :         Z_CONST_FLAGS(result) = fetch_type;
    7571             : 
    7572         306 :         zend_ast_destroy(ast);
    7573             :         zend_string_release(class_name);
    7574             : 
    7575         306 :         *ast_ptr = zend_ast_create_zval(&result);
    7576             : }
    7577             : /* }}} */
    7578             : 
    7579         243 : void zend_compile_const_expr_const(zend_ast **ast_ptr) /* {{{ */
    7580             : {
    7581         243 :         zend_ast *ast = *ast_ptr;
    7582         243 :         zend_ast *name_ast = ast->child[0];
    7583         243 :         zend_string *orig_name = zend_ast_get_str(name_ast);
    7584             :         zend_bool is_fully_qualified;
    7585             : 
    7586             :         zval result, resolved_name;
    7587         243 :         ZVAL_STR(&resolved_name, zend_resolve_const_name(
    7588             :                 orig_name, name_ast->attr, &is_fully_qualified));
    7589             : 
    7590         243 :         if (zend_try_ct_eval_const(&result, Z_STR(resolved_name), is_fully_qualified)) {
    7591           0 :                 zend_string_release(Z_STR(resolved_name));
    7592           0 :                 zend_ast_destroy(ast);
    7593           0 :                 *ast_ptr = zend_ast_create_zval(&result);
    7594           0 :                 return;
    7595             :         }
    7596             : 
    7597         243 :         Z_TYPE_INFO(resolved_name) = IS_CONSTANT_EX;
    7598         243 :         if (!is_fully_qualified) {
    7599         200 :                 Z_CONST_FLAGS(resolved_name) = IS_CONSTANT_UNQUALIFIED;
    7600             :         }
    7601             : 
    7602         243 :         zend_ast_destroy(ast);
    7603         243 :         *ast_ptr = zend_ast_create_zval(&resolved_name);
    7604             : }
    7605             : /* }}} */
    7606             : 
    7607           4 : void zend_compile_const_expr_magic_const(zend_ast **ast_ptr) /* {{{ */
    7608             : {
    7609           4 :         zend_ast *ast = *ast_ptr;
    7610             : 
    7611             :         /* Other cases already resolved by constant folding */
    7612             :         ZEND_ASSERT(ast->attr == T_CLASS_C &&
    7613             :                     CG(active_class_entry) &&
    7614             :                     (CG(active_class_entry)->ce_flags & ZEND_ACC_TRAIT) != 0);
    7615             : 
    7616             :         {
    7617             :                 zval const_zv;
    7618           4 :                 Z_STR(const_zv) = zend_string_init("__CLASS__", sizeof("__CLASS__")-1, 0);
    7619           4 :                 Z_TYPE_INFO(const_zv) = IS_CONSTANT_EX | (IS_CONSTANT_CLASS << Z_CONST_FLAGS_SHIFT);
    7620             : 
    7621           4 :                 zend_ast_destroy(ast);
    7622           4 :                 *ast_ptr = zend_ast_create_zval(&const_zv);
    7623             :         }
    7624           4 : }
    7625             : /* }}} */
    7626             : 
    7627       21190 : void zend_compile_const_expr(zend_ast **ast_ptr) /* {{{ */
    7628             : {
    7629       21190 :         zend_ast *ast = *ast_ptr;
    7630       21190 :         if (ast == NULL || ast->kind == ZEND_AST_ZVAL) {
    7631       20377 :                 return;
    7632             :         }
    7633             : 
    7634         813 :         if (!zend_is_allowed_in_const_expr(ast->kind)) {
    7635           1 :                 zend_error_noreturn(E_COMPILE_ERROR, "Constant expression contains invalid operations");
    7636             :         }
    7637             : 
    7638         812 :         switch (ast->kind) {
    7639             :                 case ZEND_AST_CLASS_CONST:
    7640         312 :                         zend_compile_const_expr_class_const(ast_ptr);
    7641         306 :                         break;
    7642             :                 case ZEND_AST_CONST:
    7643         243 :                         zend_compile_const_expr_const(ast_ptr);
    7644         243 :                         break;
    7645             :                 case ZEND_AST_MAGIC_CONST:
    7646           4 :                         zend_compile_const_expr_magic_const(ast_ptr);
    7647           4 :                         break;
    7648             :                 default:
    7649         253 :                         zend_ast_apply(ast, zend_compile_const_expr);
    7650             :                         break;
    7651             :         }
    7652             : }
    7653             : /* }}} */
    7654             : 
    7655       20740 : void zend_const_expr_to_zval(zval *result, zend_ast *ast) /* {{{ */
    7656             : {
    7657       20740 :         zend_ast *orig_ast = ast;
    7658       20740 :         zend_eval_const_expr(&ast);
    7659       20736 :         zend_compile_const_expr(&ast);
    7660       20729 :         if (ast->kind == ZEND_AST_ZVAL) {
    7661       41210 :                 ZVAL_COPY_VALUE(result, zend_ast_get_zval(ast));
    7662             :         } else {
    7663         124 :                 ZVAL_NEW_AST(result, zend_ast_copy(ast));
    7664             :                 /* destroy the ast here, it might have been replaced */
    7665         124 :                 zend_ast_destroy(ast);
    7666             :         }
    7667             : 
    7668             :         /* Kill this branch of the original AST, as it was already destroyed.
    7669             :          * It would be nice to find a better solution to this problem in the
    7670             :          * future. */
    7671       20729 :         orig_ast->kind = 0;
    7672       20729 : }
    7673             : /* }}} */
    7674             : 
    7675             : /* Same as compile_stmt, but with early binding */
    7676      300838 : void zend_compile_top_stmt(zend_ast *ast) /* {{{ */
    7677             : {
    7678      300838 :         if (!ast) {
    7679       31447 :                 return;
    7680             :         }
    7681             : 
    7682      269391 :         if (ast->kind == ZEND_AST_STMT_LIST) {
    7683       56117 :                 zend_ast_list *list = zend_ast_get_list(ast);
    7684             :                 uint32_t i;
    7685      322113 :                 for (i = 0; i < list->children; ++i) {
    7686      266286 :                         zend_compile_top_stmt(list->child[i]);
    7687             :                 }
    7688       55827 :                 return;
    7689             :         }
    7690             : 
    7691      213274 :         zend_compile_stmt(ast);
    7692             : 
    7693      213044 :         if (ast->kind != ZEND_AST_NAMESPACE && ast->kind != ZEND_AST_HALT_COMPILER) {
    7694      212527 :                 zend_verify_namespace();
    7695             :         }
    7696      213043 :         if (ast->kind == ZEND_AST_FUNC_DECL || ast->kind == ZEND_AST_CLASS) {
    7697       22634 :                 CG(zend_lineno) = ((zend_ast_decl *) ast)->end_lineno;
    7698       22634 :                 zend_do_early_binding();
    7699             :         }
    7700             : }
    7701             : /* }}} */
    7702             : 
    7703      713326 : void zend_compile_stmt(zend_ast *ast) /* {{{ */
    7704             : {
    7705      713326 :         if (!ast) {
    7706         364 :                 return;
    7707             :         }
    7708             : 
    7709      712962 :         CG(zend_lineno) = ast->lineno;
    7710             : 
    7711      712962 :         if ((CG(compiler_options) & ZEND_COMPILE_EXTENDED_INFO) && !zend_is_unticked_stmt(ast)) {
    7712           0 :                 zend_do_extended_info();
    7713             :         }
    7714             : 
    7715      712962 :         switch (ast->kind) {
    7716             :                 case ZEND_AST_STMT_LIST:
    7717      163164 :                         zend_compile_stmt_list(ast);
    7718      163067 :                         break;
    7719             :                 case ZEND_AST_GLOBAL:
    7720        5206 :                         zend_compile_global_var(ast);
    7721        5205 :                         break;
    7722             :                 case ZEND_AST_STATIC:
    7723        2132 :                         zend_compile_static_var(ast);
    7724        2131 :                         break;
    7725             :                 case ZEND_AST_UNSET:
    7726        1691 :                         zend_compile_unset(ast);
    7727        1687 :                         break;
    7728             :                 case ZEND_AST_RETURN:
    7729       46378 :                         zend_compile_return(ast);
    7730       46372 :                         break;
    7731             :                 case ZEND_AST_ECHO:
    7732       41085 :                         zend_compile_echo(ast);
    7733       41085 :                         break;
    7734             :                 case ZEND_AST_THROW:
    7735         444 :                         zend_compile_throw(ast);
    7736         444 :                         break;
    7737             :                 case ZEND_AST_BREAK:
    7738             :                 case ZEND_AST_CONTINUE:
    7739        2365 :                         zend_compile_break_continue(ast);
    7740        2360 :                         break;
    7741             :                 case ZEND_AST_GOTO:
    7742          47 :                         zend_compile_goto(ast);
    7743          47 :                         break;
    7744             :                 case ZEND_AST_LABEL:
    7745          48 :                         zend_compile_label(ast);
    7746          47 :                         break;
    7747             :                 case ZEND_AST_WHILE:
    7748        2080 :                         zend_compile_while(ast);
    7749        2079 :                         break;
    7750             :                 case ZEND_AST_DO_WHILE:
    7751         319 :                         zend_compile_do_while(ast);
    7752         319 :                         break;
    7753             :                 case ZEND_AST_FOR:
    7754        2272 :                         zend_compile_for(ast);
    7755        2272 :                         break;
    7756             :                 case ZEND_AST_FOREACH:
    7757       12005 :                         zend_compile_foreach(ast);
    7758       11994 :                         break;
    7759             :                 case ZEND_AST_IF:
    7760       80589 :                         zend_compile_if(ast);
    7761       80589 :                         break;
    7762             :                 case ZEND_AST_SWITCH:
    7763         510 :                         zend_compile_switch(ast);
    7764         509 :                         break;
    7765             :                 case ZEND_AST_TRY:
    7766        2943 :                         zend_compile_try(ast);
    7767        2939 :                         break;
    7768             :                 case ZEND_AST_DECLARE:
    7769          53 :                         zend_compile_declare(ast);
    7770          43 :                         break;
    7771             :                 case ZEND_AST_FUNC_DECL:
    7772             :                 case ZEND_AST_METHOD:
    7773       39378 :                         zend_compile_func_decl(NULL, ast);
    7774       39294 :                         break;
    7775             :                 case ZEND_AST_PROP_DECL:
    7776        2670 :                         zend_compile_prop_decl(ast);
    7777        2665 :                         break;
    7778             :                 case ZEND_AST_CLASS_CONST_DECL:
    7779         371 :                         zend_compile_class_const_decl(ast);
    7780         359 :                         break;
    7781             :                 case ZEND_AST_USE_TRAIT:
    7782         223 :                         zend_compile_use_trait(ast);
    7783         219 :                         break;
    7784             :                 case ZEND_AST_CLASS:
    7785        8101 :                         zend_compile_class_decl(ast);
    7786        8013 :                         break;
    7787             :                 case ZEND_AST_GROUP_USE:
    7788          14 :                         zend_compile_group_use(ast);
    7789          14 :                         break;
    7790             :                 case ZEND_AST_USE:
    7791          94 :                         zend_compile_use(ast);
    7792          82 :                         break;
    7793             :                 case ZEND_AST_CONST_DECL:
    7794         217 :                         zend_compile_const_decl(ast);
    7795         209 :                         break;
    7796             :                 case ZEND_AST_NAMESPACE:
    7797         263 :                         zend_compile_namespace(ast);
    7798         241 :                         break;
    7799             :                 case ZEND_AST_HALT_COMPILER:
    7800         276 :                         zend_compile_halt_compiler(ast);
    7801         276 :                         break;
    7802             :                 default:
    7803             :                 {
    7804             :                         znode result;
    7805      298024 :                         zend_compile_expr(&result, ast);
    7806      297980 :                         zend_do_free(&result);
    7807             :                 }
    7808             :         }
    7809             : 
    7810      712541 :         if (FC(declarables).ticks && !zend_is_unticked_stmt(ast)) {
    7811          31 :                 zend_emit_tick();
    7812             :         }
    7813             : }
    7814             : /* }}} */
    7815             : 
    7816     1688598 : void zend_compile_expr(znode *result, zend_ast *ast) /* {{{ */
    7817             : {
    7818             :         /* CG(zend_lineno) = ast->lineno; */
    7819     1688598 :         CG(zend_lineno) = zend_ast_get_lineno(ast);
    7820             : 
    7821     1688598 :         switch (ast->kind) {
    7822             :                 case ZEND_AST_ZVAL:
    7823     1231466 :                         ZVAL_COPY(&result->u.constant, zend_ast_get_zval(ast));
    7824      615733 :                         result->op_type = IS_CONST;
    7825      615733 :                         return;
    7826             :                 case ZEND_AST_ZNODE:
    7827        5711 :                         *result = *zend_ast_get_znode(ast);
    7828        5711 :                         return;
    7829             :                 case ZEND_AST_VAR:
    7830             :                 case ZEND_AST_DIM:
    7831             :                 case ZEND_AST_PROP:
    7832             :                 case ZEND_AST_STATIC_PROP:
    7833             :                 case ZEND_AST_CALL:
    7834             :                 case ZEND_AST_METHOD_CALL:
    7835             :                 case ZEND_AST_STATIC_CALL:
    7836      502592 :                         zend_compile_var(result, ast, BP_VAR_R);
    7837      502571 :                         return;
    7838             :                 case ZEND_AST_ASSIGN:
    7839      157814 :                         zend_compile_assign(result, ast);
    7840      157797 :                         return;
    7841             :                 case ZEND_AST_ASSIGN_REF:
    7842         488 :                         zend_compile_assign_ref(result, ast);
    7843         486 :                         return;
    7844             :                 case ZEND_AST_NEW:
    7845       15445 :                         zend_compile_new(result, ast);
    7846       15445 :                         return;
    7847             :                 case ZEND_AST_CLONE:
    7848         122 :                         zend_compile_clone(result, ast);
    7849         122 :                         return;
    7850             :                 case ZEND_AST_ASSIGN_OP:
    7851        4151 :                         zend_compile_compound_assign(result, ast);
    7852        4151 :                         return;
    7853             :                 case ZEND_AST_BINARY_OP:
    7854      102099 :                         zend_compile_binary_op(result, ast);
    7855      102099 :                         return;
    7856             :                 case ZEND_AST_GREATER:
    7857             :                 case ZEND_AST_GREATER_EQUAL:
    7858        1583 :                         zend_compile_greater(result, ast);
    7859        1583 :                         return;
    7860             :                 case ZEND_AST_UNARY_OP:
    7861       33844 :                         zend_compile_unary_op(result, ast);
    7862       33844 :                         return;
    7863             :                 case ZEND_AST_UNARY_PLUS:
    7864             :                 case ZEND_AST_UNARY_MINUS:
    7865        3485 :                         zend_compile_unary_pm(result, ast);
    7866        3485 :                         return;
    7867             :                 case ZEND_AST_AND:
    7868             :                 case ZEND_AST_OR:
    7869       13832 :                         zend_compile_short_circuiting(result, ast);
    7870       13832 :                         return;
    7871             :                 case ZEND_AST_POST_INC:
    7872             :                 case ZEND_AST_POST_DEC:
    7873        6145 :                         zend_compile_post_incdec(result, ast);
    7874        6145 :                         return;
    7875             :                 case ZEND_AST_PRE_INC:
    7876             :                 case ZEND_AST_PRE_DEC:
    7877         581 :                         zend_compile_pre_incdec(result, ast);
    7878         580 :                         return;
    7879             :                 case ZEND_AST_CAST:
    7880        6601 :                         zend_compile_cast(result, ast);
    7881        6601 :                         return;
    7882             :                 case ZEND_AST_CONDITIONAL:
    7883       25892 :                         zend_compile_conditional(result, ast);
    7884       25892 :                         return;
    7885             :                 case ZEND_AST_COALESCE:
    7886          27 :                         zend_compile_coalesce(result, ast);
    7887          27 :                         return;
    7888             :                 case ZEND_AST_PRINT:
    7889        3539 :                         zend_compile_print(result, ast);
    7890        3539 :                         return;
    7891             :                 case ZEND_AST_EXIT:
    7892       17475 :                         zend_compile_exit(result, ast);
    7893       17475 :                         return;
    7894             :                 case ZEND_AST_YIELD:
    7895         261 :                         zend_compile_yield(result, ast);
    7896         260 :                         return;
    7897             :                 case ZEND_AST_YIELD_FROM:
    7898          41 :                         zend_compile_yield_from(result, ast);
    7899          40 :                         return;
    7900             :                 case ZEND_AST_INSTANCEOF:
    7901          75 :                         zend_compile_instanceof(result, ast);
    7902          74 :                         return;
    7903             :                 case ZEND_AST_INCLUDE_OR_EVAL:
    7904       13604 :                         zend_compile_include_or_eval(result, ast);
    7905       13604 :                         return;
    7906             :                 case ZEND_AST_ISSET:
    7907             :                 case ZEND_AST_EMPTY:
    7908       13920 :                         zend_compile_isset_or_empty(result, ast);
    7909       13917 :                         return;
    7910             :                 case ZEND_AST_SILENCE:
    7911        7190 :                         zend_compile_silence(result, ast);
    7912        7190 :                         return;
    7913             :                 case ZEND_AST_SHELL_EXEC:
    7914         121 :                         zend_compile_shell_exec(result, ast);
    7915         121 :                         return;
    7916             :                 case ZEND_AST_ARRAY:
    7917       19061 :                         zend_compile_array(result, ast);
    7918       19058 :                         return;
    7919             :                 case ZEND_AST_CONST:
    7920       75033 :                         zend_compile_const(result, ast);
    7921       75033 :                         return;
    7922             :                 case ZEND_AST_CLASS_CONST:
    7923       10178 :                         zend_compile_class_const(result, ast);
    7924       10176 :                         return;
    7925             :                 case ZEND_AST_ENCAPS_LIST:
    7926       19367 :                         zend_compile_encaps_list(result, ast);
    7927       19367 :                         return;
    7928             :                 case ZEND_AST_MAGIC_CONST:
    7929       12003 :                         zend_compile_magic_const(result, ast);
    7930       12003 :                         return;
    7931             :                 case ZEND_AST_CLOSURE:
    7932         585 :                         zend_compile_func_decl(result, ast);
    7933         580 :                         return;
    7934             :                 default:
    7935             :                         ZEND_ASSERT(0 /* not supported */);
    7936             :         }
    7937             : }
    7938             : /* }}} */
    7939             : 
    7940      842324 : void zend_compile_var(znode *result, zend_ast *ast, uint32_t type) /* {{{ */
    7941             : {
    7942      842324 :         switch (ast->kind) {
    7943             :                 case ZEND_AST_VAR:
    7944      385899 :                         zend_compile_simple_var(result, ast, type, 0);
    7945      385899 :                         return;
    7946             :                 case ZEND_AST_DIM:
    7947      108001 :                         zend_compile_dim(result, ast, type);
    7948      107995 :                         return;
    7949             :                 case ZEND_AST_PROP:
    7950        6538 :                         zend_compile_prop(result, ast, type);
    7951        6538 :                         return;
    7952             :                 case ZEND_AST_STATIC_PROP:
    7953         429 :                         zend_compile_static_prop(result, ast, type, 0);
    7954         428 :                         return;
    7955             :                 case ZEND_AST_CALL:
    7956      290790 :                         zend_compile_call(result, ast, type);
    7957      290774 :                         return;
    7958             :                 case ZEND_AST_METHOD_CALL:
    7959       38897 :                         zend_compile_method_call(result, ast, type);
    7960       38895 :                         return;
    7961             :                 case ZEND_AST_STATIC_CALL:
    7962       11719 :                         zend_compile_static_call(result, ast, type);
    7963       11719 :                         return;
    7964             :                 case ZEND_AST_ZNODE:
    7965           3 :                         *result = *zend_ast_get_znode(ast);
    7966           3 :                         return;
    7967             :                 default:
    7968          48 :                         if (type == BP_VAR_W || type == BP_VAR_RW || type == BP_VAR_UNSET) {
    7969           1 :                                 zend_error_noreturn(E_COMPILE_ERROR,
    7970             :                                         "Cannot use temporary expression in write context");
    7971             :                         }
    7972             : 
    7973          47 :                         zend_compile_expr(result, ast);
    7974          47 :                         return;
    7975             :         }
    7976             : }
    7977             : /* }}} */
    7978             : 
    7979      294725 : void zend_delayed_compile_var(znode *result, zend_ast *ast, uint32_t type) /* {{{ */
    7980             : {
    7981             :         zend_op *opline;
    7982      294725 :         switch (ast->kind) {
    7983             :                 case ZEND_AST_VAR:
    7984      288101 :                         zend_compile_simple_var(result, ast, type, 1);
    7985      288101 :                         return;
    7986             :                 case ZEND_AST_DIM:
    7987        4736 :                         opline = zend_delayed_compile_dim(result, ast, type);
    7988        4735 :                         zend_adjust_for_fetch_type(opline, type);
    7989        4735 :                         return;
    7990             :                 case ZEND_AST_PROP:
    7991        1349 :                         opline = zend_delayed_compile_prop(result, ast, type);
    7992        1349 :                         zend_adjust_for_fetch_type(opline, type);
    7993        1349 :                         return;
    7994             :                 case ZEND_AST_STATIC_PROP:
    7995         234 :                         zend_compile_static_prop(result, ast, type, 1);
    7996         234 :                         return;
    7997             :                 default:
    7998         305 :                         zend_compile_var(result, ast, type);
    7999         304 :                         return;
    8000             :         }
    8001             : }
    8002             : /* }}} */
    8003             : 
    8004      276834 : void zend_eval_const_expr(zend_ast **ast_ptr) /* {{{ */
    8005             : {
    8006      276834 :         zend_ast *ast = *ast_ptr;
    8007             :         zval result;
    8008             : 
    8009      276834 :         if (!ast) {
    8010       81487 :                 return;
    8011             :         }
    8012             : 
    8013      195347 :         switch (ast->kind) {
    8014             :                 case ZEND_AST_BINARY_OP:
    8015        4267 :                         zend_eval_const_expr(&ast->child[0]);
    8016        4267 :                         zend_eval_const_expr(&ast->child[1]);
    8017        4267 :                         if (ast->child[0]->kind != ZEND_AST_ZVAL || ast->child[1]->kind != ZEND_AST_ZVAL) {
    8018        3803 :                                 return;
    8019             :                         }
    8020             : 
    8021        1392 :                         if (!zend_try_ct_eval_binary_op(&result, ast->attr,
    8022             :                                         zend_ast_get_zval(ast->child[0]), zend_ast_get_zval(ast->child[1]))
    8023             :                         ) {
    8024           6 :                                 return;
    8025             :                         }
    8026         456 :                         break;
    8027             :                 case ZEND_AST_GREATER:
    8028             :                 case ZEND_AST_GREATER_EQUAL:
    8029           4 :                         zend_eval_const_expr(&ast->child[0]);
    8030           4 :                         zend_eval_const_expr(&ast->child[1]);
    8031           4 :                         if (ast->child[0]->kind != ZEND_AST_ZVAL || ast->child[1]->kind != ZEND_AST_ZVAL) {
    8032           2 :                                 return;
    8033             :                         }
    8034             : 
    8035           6 :                         zend_ct_eval_greater(&result, ast->kind,
    8036             :                                 zend_ast_get_zval(ast->child[0]), zend_ast_get_zval(ast->child[1]));
    8037           2 :                         break;
    8038             :                 case ZEND_AST_AND:
    8039             :                 case ZEND_AST_OR:
    8040             :                 {
    8041             :                         int i;
    8042          24 :                         for (i = 0; i <= 1; i++) {
    8043          17 :                                 zend_eval_const_expr(&ast->child[i]);
    8044          17 :                                 if (ast->child[i]->kind == ZEND_AST_ZVAL) {
    8045          24 :                                         if (zend_is_true(zend_ast_get_zval(ast->child[i])) == (ast->kind == ZEND_AST_OR)) {
    8046           2 :                                                 ZVAL_BOOL(&result, ast->kind == ZEND_AST_OR);
    8047           2 :                                                 return;
    8048             :                                         }
    8049             :                                 }
    8050             :                         }
    8051             : 
    8052           7 :                         if (ast->child[0]->kind != ZEND_AST_ZVAL || ast->child[1]->kind != ZEND_AST_ZVAL) {
    8053           5 :                                 return;
    8054             :                         }
    8055             : 
    8056           2 :                         if (ast->kind == ZEND_AST_OR) {
    8057           3 :                                 ZVAL_BOOL(&result, zend_is_true(zend_ast_get_zval(ast->child[0])) || zend_is_true(zend_ast_get_zval(ast->child[1])));
    8058             :                         } else {
    8059           3 :                                 ZVAL_BOOL(&result, zend_is_true(zend_ast_get_zval(ast->child[0])) && zend_is_true(zend_ast_get_zval(ast->child[1])));
    8060             :                         }
    8061           2 :                         break;
    8062             :                 }
    8063             :                 case ZEND_AST_UNARY_OP:
    8064           3 :                         zend_eval_const_expr(&ast->child[0]);
    8065           3 :                         if (ast->child[0]->kind != ZEND_AST_ZVAL) {
    8066           1 :                                 return;
    8067             :                         }
    8068             : 
    8069           4 :                         zend_ct_eval_unary_op(&result, ast->attr, zend_ast_get_zval(ast->child[0]));
    8070           2 :                         break;
    8071             :                 case ZEND_AST_UNARY_PLUS:
    8072             :                 case ZEND_AST_UNARY_MINUS:
    8073        3478 :                         zend_eval_const_expr(&ast->child[0]);
    8074        3478 :                         if (ast->child[0]->kind != ZEND_AST_ZVAL) {
    8075           4 :                                 return;
    8076             :                         }
    8077             : 
    8078        6948 :                         if (!zend_try_ct_eval_unary_pm(&result, ast->kind, zend_ast_get_zval(ast->child[0]))) {
    8079           0 :                                 return;
    8080             :                         }
    8081        3474 :                         break;
    8082             :                 case ZEND_AST_COALESCE:
    8083             :                         /* Set isset fetch indicator here, opcache disallows runtime altering of the AST */
    8084          24 :                         if (ast->child[0]->kind == ZEND_AST_DIM) {
    8085          13 :                                 ast->child[0]->attr = ZEND_DIM_IS;
    8086             :                         }
    8087          24 :                         zend_eval_const_expr(&ast->child[0]);
    8088             : 
    8089          23 :                         if (ast->child[0]->kind != ZEND_AST_ZVAL) {
    8090             :                                 /* ensure everything was compile-time evaluated at least once */
    8091          12 :                                 zend_eval_const_expr(&ast->child[1]);
    8092          12 :                                 return;
    8093             :                         }
    8094             : 
    8095          22 :                         if (Z_TYPE_P(zend_ast_get_zval(ast->child[0])) == IS_NULL) {
    8096          10 :                                 zend_eval_const_expr(&ast->child[1]);
    8097          10 :                                 *ast_ptr = ast->child[1];
    8098          10 :                                 ast->child[1] = NULL;
    8099          10 :                                 zend_ast_destroy(ast);
    8100             :                         } else {
    8101           1 :                                 *ast_ptr = ast->child[0];
    8102           1 :                                 ast->child[0] = NULL;
    8103           1 :                                 zend_ast_destroy(ast);
    8104             :                         }
    8105          11 :                         return;
    8106             :                 case ZEND_AST_CONDITIONAL:
    8107             :                 {
    8108             :                         zend_ast **child, *child_ast;
    8109          35 :                         zend_eval_const_expr(&ast->child[0]);
    8110          35 :                         if (ast->child[0]->kind != ZEND_AST_ZVAL) {
    8111             :                                 /* ensure everything was compile-time evaluated at least once */
    8112          32 :                                 if (ast->child[1]) {
    8113          29 :                                         zend_eval_const_expr(&ast->child[1]);
    8114             :                                 }
    8115          32 :                                 zend_eval_const_expr(&ast->child[2]);
    8116          32 :                                 return;
    8117             :                         }
    8118             : 
    8119           6 :                         child = &ast->child[2 - zend_is_true(zend_ast_get_zval(ast->child[0]))];
    8120           3 :                         if (*child == NULL) {
    8121           1 :                                 child--;
    8122             :                         }
    8123           3 :                         child_ast = *child;
    8124           3 :                         *child = NULL;
    8125           3 :                         zend_ast_destroy(ast);
    8126           3 :                         *ast_ptr = child_ast;
    8127           3 :                         zend_eval_const_expr(ast_ptr);
    8128           3 :                         return;
    8129             :                 }
    8130             :                 case ZEND_AST_DIM:
    8131             :                 {
    8132             :                         /* constant expression should be always read context ... */
    8133             :                         zval *container, *dim;
    8134             : 
    8135         119 :                         if (ast->child[1] == NULL) {
    8136           3 :                                 zend_error_noreturn(E_COMPILE_ERROR, "Cannot use [] for reading");
    8137             :                         }
    8138             : 
    8139             :                         /* Set isset fetch indicator here, opcache disallows runtime altering of the AST */
    8140         116 :                         if (ast->attr == ZEND_DIM_IS && ast->child[0]->kind == ZEND_AST_DIM) {
    8141          21 :                                 ast->child[0]->attr = ZEND_DIM_IS;
    8142             :                         }
    8143             : 
    8144         116 :                         zend_eval_const_expr(&ast->child[0]);
    8145         116 :                         zend_eval_const_expr(&ast->child[1]);
    8146         116 :                         if (ast->child[0]->kind != ZEND_AST_ZVAL || ast->child[1]->kind != ZEND_AST_ZVAL) {
    8147         112 :                                 return;
    8148             :                         }
    8149             : 
    8150           8 :                         container = zend_ast_get_zval(ast->child[0]);
    8151           8 :                         dim = zend_ast_get_zval(ast->child[1]);
    8152             : 
    8153           4 :                         if (Z_TYPE_P(container) == IS_ARRAY) {
    8154             :                                 zval *el;
    8155           4 :                                 if (Z_TYPE_P(dim) == IS_LONG) {
    8156           2 :                                         el = zend_hash_index_find(Z_ARR_P(container), Z_LVAL_P(dim));
    8157           2 :                                         if (el) {
    8158           2 :                                                 ZVAL_COPY(&result, el);
    8159             :                                         } else {
    8160           0 :                                                 return;
    8161             :                                         }
    8162           2 :                                 } else if (Z_TYPE_P(dim) == IS_STRING) {
    8163           4 :                                         el = zend_symtable_find(Z_ARR_P(container), Z_STR_P(dim));
    8164           2 :                                         if (el) {
    8165           2 :                                                 ZVAL_COPY(&result, el);
    8166             :                                         } else {
    8167           0 :                                                 return;
    8168             :                                         }
    8169             :                                 } else {
    8170           0 :                                         return; /* warning... handle at runtime */
    8171             :                                 }
    8172           0 :                         } else if (Z_TYPE_P(container) == IS_STRING) {
    8173             :                                 zend_long offset;
    8174             :                                 zend_uchar c;
    8175           0 :                                 if (Z_TYPE_P(dim) == IS_LONG) {
    8176           0 :                                         offset = Z_LVAL_P(dim);
    8177           0 :                                 } else if (Z_TYPE_P(dim) != IS_STRING || is_numeric_string(Z_STRVAL_P(dim), Z_STRLEN_P(dim), &offset, NULL, 1) != IS_LONG) {
    8178           0 :                                         return;
    8179             :                                 }
    8180           0 :                                 if (offset < 0 || (size_t)offset >= Z_STRLEN_P(container)) {
    8181           0 :                                         return;
    8182             :                                 }
    8183           0 :                                 c = (zend_uchar) Z_STRVAL_P(container)[offset];
    8184           0 :                                 if (CG(one_char_string)[c]) {
    8185           0 :                                         ZVAL_INTERNED_STR(&result, CG(one_char_string)[c]);
    8186             :                                 } else {
    8187           0 :                                         ZVAL_NEW_STR(&result, zend_string_init((char *) &c, 1, 0));
    8188             :                                 }
    8189           0 :                         } else if (Z_TYPE_P(container) <= IS_FALSE) {
    8190           0 :                                 ZVAL_NULL(&result);
    8191             :                         } else {
    8192           0 :                                 return;
    8193             :                         }
    8194           4 :                         break;
    8195             :                 }
    8196             :                 case ZEND_AST_ARRAY:
    8197       11817 :                         if (!zend_try_ct_eval_array(&result, ast)) {
    8198        1105 :                                 return;
    8199             :                         }
    8200       10712 :                         break;
    8201             :                 case ZEND_AST_MAGIC_CONST:
    8202         193 :                         if (!zend_try_ct_eval_magic_const(&result, ast)) {
    8203           2 :                                 return;
    8204             :                         }
    8205         191 :                         break;
    8206             :                 case ZEND_AST_CONST:
    8207             :                 {
    8208       16883 :                         zend_ast *name_ast = ast->child[0];
    8209             :                         zend_bool is_fully_qualified;
    8210       33766 :                         zend_string *resolved_name = zend_resolve_const_name(
    8211       33766 :                                 zend_ast_get_str(name_ast), name_ast->attr, &is_fully_qualified);
    8212             : 
    8213       16883 :                         if (!zend_try_ct_eval_const(&result, resolved_name, is_fully_qualified)) {
    8214             :                                 zend_string_release(resolved_name);
    8215        1735 :                                 return;
    8216             :                         }
    8217             : 
    8218             :                         zend_string_release(resolved_name);
    8219       15148 :                         break;
    8220             :                 }
    8221             :                 case ZEND_AST_CLASS_CONST:
    8222             :                 {
    8223         838 :                         zend_ast *class_ast = ast->child[0];
    8224         838 :                         zend_ast *name_ast = ast->child[1];
    8225             :                         zend_string *resolved_name;
    8226             : 
    8227         838 :                         if (zend_try_compile_const_expr_resolve_class_name(&result, class_ast, name_ast, 0)) {
    8228          18 :                                 if (Z_TYPE(result) == IS_NULL) {
    8229          14 :                                         if (zend_get_class_fetch_type(zend_ast_get_str(class_ast)) == ZEND_FETCH_CLASS_SELF) {
    8230           2 :                                                 zend_ast_destroy(ast);
    8231           2 :                                                 *ast_ptr = zend_ast_create_ex(ZEND_AST_MAGIC_CONST, T_CLASS_C);
    8232             :                                         }
    8233           7 :                                         return;
    8234             :                                 }
    8235          11 :                                 break;
    8236             :                         }
    8237             : 
    8238         820 :                         zend_eval_const_expr(&class_ast);
    8239         820 :                         zend_eval_const_expr(&name_ast);
    8240             : 
    8241        1698 :                         if (name_ast->kind == ZEND_AST_ZVAL && zend_string_equals_literal_ci(zend_ast_get_str(name_ast), "class")) {
    8242           0 :                                 zend_error_noreturn(E_COMPILE_ERROR,
    8243             :                                         "Dynamic class names are not allowed in compile-time ::class fetch");
    8244             :                         }
    8245             : 
    8246         820 :                         if (class_ast->kind != ZEND_AST_ZVAL || name_ast->kind != ZEND_AST_ZVAL) {
    8247           1 :                                 return;
    8248             :                         }
    8249             : 
    8250         819 :                         resolved_name = zend_resolve_class_name_ast(class_ast);
    8251             : 
    8252        1638 :                         if (!zend_try_ct_eval_class_const(&result, resolved_name, zend_ast_get_str(name_ast))) {
    8253             :                                 zend_string_release(resolved_name);
    8254         363 :                                 return;
    8255             :                         }
    8256             : 
    8257             :                         zend_string_release(resolved_name);
    8258         456 :                         break;
    8259             :                 }
    8260             : 
    8261             :                 default:
    8262      157677 :                         return;
    8263             :         }
    8264             : 
    8265       30458 :         zend_ast_destroy(ast);
    8266       30458 :         *ast_ptr = zend_ast_create_zval(&result);
    8267             : }
    8268             : /* }}} */
    8269             : 
    8270             : /*
    8271             :  * Local variables:
    8272             :  * tab-width: 4
    8273             :  * c-basic-offset: 4
    8274             :  * indent-tabs-mode: t
    8275             :  * End:
    8276             :  */

Generated by: LCOV version 1.10

Generated at Sun, 28 Aug 2016 17:09:58 +0000 (2 days ago)

Copyright © 2005-2016 The PHP Group
All rights reserved.