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: 3153 3268 96.5 %
Date: 2014-11-22 Functions: 226 229 98.7 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /*
       2             :    +----------------------------------------------------------------------+
       3             :    | Zend Engine                                                          |
       4             :    +----------------------------------------------------------------------+
       5             :    | Copyright (c) 1998-2014 Zend Technologies Ltd. (http://www.zend.com) |
       6             :    +----------------------------------------------------------------------+
       7             :    | This source file is subject to version 2.00 of the Zend license,     |
       8             :    | that is bundled with this package in the file LICENSE, and is        |
       9             :    | available through the world-wide-web at the following url:           |
      10             :    | http://www.zend.com/license/2_00.txt.                                |
      11             :    | If you did not receive a copy of the Zend license and are unable to  |
      12             :    | obtain it through the world-wide-web, please send a note to          |
      13             :    | license@zend.com so we can mail you a copy immediately.              |
      14             :    +----------------------------------------------------------------------+
      15             :    | Authors: Andi Gutmans <andi@zend.com>                                |
      16             :    |          Zeev Suraski <zeev@zend.com>                                |
      17             :    |          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_virtual_cwd.h"
      31             : #include "zend_multibyte.h"
      32             : #include "zend_language_scanner.h"
      33             : #include "zend_inheritance.h"
      34             : 
      35             : #define CONSTANT_EX(op_array, op) \
      36             :         (op_array)->literals[op]
      37             : 
      38             : #define CONSTANT(op) \
      39             :         CONSTANT_EX(CG(active_op_array), op)
      40             : 
      41             : #define SET_NODE(target, src) do { \
      42             :                 target ## _type = (src)->op_type; \
      43             :                 if ((src)->op_type == IS_CONST) { \
      44             :                         target.constant = zend_add_literal(CG(active_op_array), &(src)->u.constant TSRMLS_CC); \
      45             :                 } else { \
      46             :                         target = (src)->u.op; \
      47             :                 } \
      48             :         } while (0)
      49             : 
      50             : #define GET_NODE(target, src) do { \
      51             :                 (target)->op_type = src ## _type; \
      52             :                 if ((target)->op_type == IS_CONST) { \
      53             :                         (target)->u.constant = CONSTANT(src.constant); \
      54             :                 } else { \
      55             :                         (target)->u.op = src; \
      56             :                 } \
      57             :         } while (0)
      58             : 
      59      302822 : static inline void zend_alloc_cache_slot(uint32_t literal TSRMLS_DC) {
      60      302822 :         zend_op_array *op_array = CG(active_op_array);
      61      302822 :         Z_CACHE_SLOT(op_array->literals[literal]) = op_array->last_cache_slot++;
      62      302822 : }
      63             : 
      64             : #define POLYMORPHIC_CACHE_SLOT_SIZE 2
      65             : 
      66       48949 : static inline void zend_alloc_polymorphic_cache_slot(uint32_t literal TSRMLS_DC) {
      67       48949 :         zend_op_array *op_array = CG(active_op_array);
      68       48949 :         Z_CACHE_SLOT(op_array->literals[literal]) = op_array->last_cache_slot;
      69       48949 :         op_array->last_cache_slot += POLYMORPHIC_CACHE_SLOT_SIZE;
      70       48949 : }
      71             : 
      72             : ZEND_API zend_op_array *(*zend_compile_file)(zend_file_handle *file_handle, int type TSRMLS_DC);
      73             : ZEND_API zend_op_array *(*zend_compile_string)(zval *source_string, char *filename TSRMLS_DC);
      74             : 
      75             : #ifndef ZTS
      76             : ZEND_API zend_compiler_globals compiler_globals;
      77             : ZEND_API zend_executor_globals executor_globals;
      78             : #endif
      79             : 
      80       20558 : static void zend_destroy_property_info(zval *zv) /* {{{ */
      81             : {
      82       20558 :         zend_property_info *property_info = Z_PTR_P(zv);
      83             : 
      84       20558 :         zend_string_release(property_info->name);
      85       20558 :         if (property_info->doc_comment) {
      86          59 :                 zend_string_release(property_info->doc_comment);
      87             :         }
      88       20558 : }
      89             : /* }}} */
      90             : 
      91     4744835 : static void zend_destroy_property_info_internal(zval *zv) /* {{{ */
      92             : {
      93     4744835 :         zend_property_info *property_info = Z_PTR_P(zv);
      94             : 
      95     4744835 :         zend_string_release(property_info->name);
      96     4744835 :         free(property_info);
      97     4744835 : }
      98             : /* }}} */
      99             : 
     100        2584 : static zend_string *zend_new_interned_string_safe(zend_string *str TSRMLS_DC) /* {{{ */ {
     101             :         zend_string *interned_str;
     102             : 
     103             :         zend_string_addref(str);
     104        2584 :         interned_str = zend_new_interned_string(str TSRMLS_CC);
     105        2584 :         if (str != interned_str) {
     106         672 :                 return interned_str;
     107             :         } else {
     108             :                 zend_string_release(str);
     109        1912 :                 return str;
     110             :         }
     111             : }
     112             : /* }}} */
     113             : 
     114       25440 : static zend_string *zend_build_runtime_definition_key(zend_string *name, unsigned char *lex_pos TSRMLS_DC) /* {{{ */
     115             : {
     116             :         zend_string *result;
     117             :         char char_pos_buf[32];
     118       25440 :         size_t filename_len, char_pos_len = zend_sprintf(char_pos_buf, "%p", lex_pos);
     119             : 
     120             :         const char *filename;
     121       25440 :         if (CG(active_op_array)->filename) {
     122       25440 :                 filename = CG(active_op_array)->filename->val;
     123       25440 :                 filename_len = CG(active_op_array)->filename->len;
     124             :         } else {
     125           0 :                 filename = "-";
     126           0 :                 filename_len = sizeof("-") - 1;
     127             :         }
     128             :         /* NULL, name length, filename length, last accepting char position length */
     129       50880 :         result = zend_string_alloc(1 + name->len + filename_len + char_pos_len, 0);
     130       25440 :         sprintf(result->val, "%c%s%s%s", '\0', name->val, filename, char_pos_buf);
     131       25440 :         return zend_new_interned_string(result TSRMLS_CC);
     132             : }
     133             : /* }}} */
     134             : 
     135       21014 : static zend_bool zend_get_unqualified_name(const zend_string *name, const char **result, size_t *result_len) /* {{{ */
     136             : {
     137       42028 :         const char *ns_separator = zend_memrchr(name->val, '\\', name->len);
     138       21014 :         if (ns_separator != NULL) {
     139         451 :                 *result = ns_separator + 1;
     140         451 :                 *result_len = name->val + name->len - *result;
     141         451 :                 return 1;
     142             :         }
     143             : 
     144       20563 :         return 0;
     145             : }
     146             : /* }}} */
     147             : 
     148       20464 : static void init_compiler_declarables(TSRMLS_D) /* {{{ */
     149             : {
     150       20464 :         ZVAL_LONG(&CG(declarables).ticks, 0);
     151       20464 : }
     152             : /* }}} */
     153             : 
     154       64969 : void zend_init_compiler_context(TSRMLS_D) /* {{{ */
     155             : {
     156       64969 :         CG(context).opcodes_size = INITIAL_OP_ARRAY_SIZE;
     157       64969 :         CG(context).vars_size = 0;
     158       64969 :         CG(context).literals_size = 0;
     159       64969 :         CG(context).current_brk_cont = -1;
     160       64969 :         CG(context).backpatch_count = 0;
     161       64969 :         CG(context).in_finally = 0;
     162       64969 :         CG(context).labels = NULL;
     163       64969 : }
     164             : /* }}} */
     165             : 
     166       20464 : void zend_init_compiler_data_structures(TSRMLS_D) /* {{{ */
     167             : {
     168       20464 :         zend_stack_init(&CG(loop_var_stack), sizeof(znode));
     169       20464 :         zend_stack_init(&CG(delayed_oplines_stack), sizeof(zend_op));
     170       20464 :         CG(active_class_entry) = NULL;
     171       20464 :         CG(in_compilation) = 0;
     172       20464 :         CG(start_lineno) = 0;
     173       20464 :         CG(current_namespace) = NULL;
     174       20464 :         CG(in_namespace) = 0;
     175       20464 :         CG(has_bracketed_namespaces) = 0;
     176       20464 :         CG(current_import) = NULL;
     177       20464 :         CG(current_import_function) = NULL;
     178       20464 :         CG(current_import_const) = NULL;
     179       20464 :         zend_hash_init(&CG(const_filenames), 8, NULL, NULL, 0);
     180       20464 :         init_compiler_declarables(TSRMLS_C);
     181       20464 :         zend_stack_init(&CG(context_stack), sizeof(CG(context)));
     182             : 
     183       20464 :         CG(encoding_declared) = 0;
     184       20464 : }
     185             : /* }}} */
     186             : 
     187       28611 : ZEND_API void file_handle_dtor(zend_file_handle *fh) /* {{{ */
     188             : {
     189             :         TSRMLS_FETCH();
     190             : 
     191       28611 :         zend_file_handle_dtor(fh TSRMLS_CC);
     192       28611 : }
     193             : /* }}} */
     194             : 
     195       20464 : void init_compiler(TSRMLS_D) /* {{{ */
     196             : {
     197       20464 :         CG(arena) = zend_arena_create(64 * 1024);
     198       20464 :         CG(active_op_array) = NULL;
     199       20464 :         memset(&CG(context), 0, sizeof(CG(context)));
     200       20464 :         zend_init_compiler_data_structures(TSRMLS_C);
     201       20464 :         zend_init_rsrc_list(TSRMLS_C);
     202       20464 :         zend_hash_init(&CG(filenames_table), 8, NULL, free_string_zval, 0);
     203       20464 :         zend_llist_init(&CG(open_files), sizeof(zend_file_handle), (void (*)(void *)) file_handle_dtor, 0);
     204       20464 :         CG(unclean_shutdown) = 0;
     205       20464 : }
     206             : /* }}} */
     207             : 
     208       20500 : void shutdown_compiler(TSRMLS_D) /* {{{ */
     209             : {
     210       20500 :         zend_stack_destroy(&CG(loop_var_stack));
     211       20500 :         zend_stack_destroy(&CG(delayed_oplines_stack));
     212       20500 :         zend_hash_destroy(&CG(filenames_table));
     213       20500 :         zend_hash_destroy(&CG(const_filenames));
     214       20500 :         zend_stack_destroy(&CG(context_stack));
     215       20500 :         zend_arena_destroy(CG(arena));
     216       20500 : }
     217             : /* }}} */
     218             : 
     219       29801 : ZEND_API zend_string *zend_set_compiled_filename(zend_string *new_compiled_filename TSRMLS_DC) /* {{{ */
     220             : {
     221             :         zend_string *p;
     222             : 
     223       29801 :         p = zend_hash_find_ptr(&CG(filenames_table), new_compiled_filename);
     224       29801 :         if (p != NULL) {
     225         877 :                 CG(compiled_filename) = p;
     226         877 :                 return p;
     227             :         }
     228       28924 :         p = zend_string_copy(new_compiled_filename);
     229             :         zend_hash_update_ptr(&CG(filenames_table), new_compiled_filename, p);
     230       28924 :         CG(compiled_filename) = p;
     231       28924 :         return p;
     232             : }
     233             : /* }}} */
     234             : 
     235       29601 : ZEND_API void zend_restore_compiled_filename(zend_string *original_compiled_filename TSRMLS_DC) /* {{{ */
     236             : {
     237       29601 :         CG(compiled_filename) = original_compiled_filename;
     238       29601 : }
     239             : /* }}} */
     240             : 
     241      102928 : ZEND_API zend_string *zend_get_compiled_filename(TSRMLS_D) /* {{{ */
     242             : {
     243      102928 :         return CG(compiled_filename);
     244             : }
     245             : /* }}} */
     246             : 
     247         583 : ZEND_API int zend_get_compiled_lineno(TSRMLS_D) /* {{{ */
     248             : {
     249         583 :         return CG(zend_lineno);
     250             : }
     251             : /* }}} */
     252             : 
     253      396411 : ZEND_API zend_bool zend_is_compiling(TSRMLS_D) /* {{{ */
     254             : {
     255      396411 :         return CG(in_compilation);
     256             : }
     257             : /* }}} */
     258             : 
     259      888272 : static uint32_t get_temporary_variable(zend_op_array *op_array) /* {{{ */
     260             : {
     261      888272 :         return (uint32_t)op_array->T++;
     262             : }
     263             : /* }}} */
     264             : 
     265      678206 : static int lookup_cv(zend_op_array *op_array, zend_string* name TSRMLS_DC) /* {{{ */{
     266      678206 :         int i = 0;
     267      678206 :         zend_ulong hash_value = zend_string_hash_val(name);
     268             : 
     269   138162863 :         while (i < op_array->last_var) {
     270   275504082 :                 if (op_array->vars[i]->val == name->val ||
     271   137279246 :                     (op_array->vars[i]->h == hash_value &&
     272      472795 :                      op_array->vars[i]->len == name->len &&
     273      472795 :                      memcmp(op_array->vars[i]->val, name->val, name->len) == 0)) {
     274             :                         zend_string_release(name);
     275      472795 :                         return (int)(zend_intptr_t)EX_VAR_NUM_2(NULL, i);
     276             :                 }
     277   136806451 :                 i++;
     278             :         }
     279      205411 :         i = op_array->last_var;
     280      205411 :         op_array->last_var++;
     281      205411 :         if (op_array->last_var > CG(context).vars_size) {
     282       48719 :                 CG(context).vars_size += 16; /* FIXME */
     283       48719 :                 op_array->vars = erealloc(op_array->vars, CG(context).vars_size * sizeof(zend_string*));
     284             :         }
     285             : 
     286      205411 :         op_array->vars[i] = zend_new_interned_string(name TSRMLS_CC);
     287      205411 :         return (int)(zend_intptr_t)EX_VAR_NUM_2(NULL, i);
     288             : }
     289             : /* }}} */
     290             : 
     291       38709 : void zend_del_literal(zend_op_array *op_array, int n) /* {{{ */
     292             : {
     293       38709 :         zval_dtor(&CONSTANT_EX(op_array, n));
     294       38709 :         if (n + 1 == op_array->last_literal) {
     295       37712 :                 op_array->last_literal--;
     296             :         } else {
     297         997 :                 ZVAL_UNDEF(&CONSTANT_EX(op_array, n));
     298             :         }
     299       38709 : }
     300             : /* }}} */
     301             : 
     302             : /* Common part of zend_add_literal and zend_append_individual_literal */
     303     1139828 : static inline void zend_insert_literal(zend_op_array *op_array, zval *zv, int literal_position TSRMLS_DC) /* {{{ */
     304             : {
     305     1436943 :         if (Z_TYPE_P(zv) == IS_STRING || Z_TYPE_P(zv) == IS_CONSTANT) {
     306      842990 :                 zend_string_hash_val(Z_STR_P(zv));
     307      842990 :                 Z_STR_P(zv) = zend_new_interned_string(Z_STR_P(zv) TSRMLS_CC);
     308      842990 :                 if (IS_INTERNED(Z_STR_P(zv))) {
     309      838867 :                         Z_TYPE_FLAGS_P(zv) &= ~ (IS_TYPE_REFCOUNTED | IS_TYPE_COPYABLE);
     310             :                 }
     311             :         }
     312     1139828 :         ZVAL_COPY_VALUE(&CONSTANT_EX(op_array, literal_position), zv);
     313     1139828 :         Z_CACHE_SLOT(op_array->literals[literal_position]) = -1;
     314     1139828 : }
     315             : /* }}} */
     316             : 
     317             : /* Is used while compiling a function, using the context to keep track
     318             :    of an approximate size to avoid to relocate to often.
     319             :    Literals are truncated to actual size in the second compiler pass (pass_two()). */
     320     1139828 : int zend_add_literal(zend_op_array *op_array, zval *zv TSRMLS_DC) /* {{{ */
     321             : {
     322     1139828 :         int i = op_array->last_literal;
     323     1139828 :         op_array->last_literal++;
     324     1139828 :         if (i >= CG(context).literals_size) {
     325      321549 :                 while (i >= CG(context).literals_size) {
     326      107183 :                         CG(context).literals_size += 16; /* FIXME */
     327             :                 }
     328      107183 :                 op_array->literals = (zval*)erealloc(op_array->literals, CG(context).literals_size * sizeof(zval));
     329             :         }
     330     1139828 :         zend_insert_literal(op_array, zv, i TSRMLS_CC);
     331     1139828 :         return i;
     332             : }
     333             : /* }}} */
     334             : 
     335      176436 : static inline int zend_add_literal_string(zend_op_array *op_array, zend_string **str TSRMLS_DC) /* {{{ */
     336             : {
     337             :         int ret;
     338             :         zval zv;
     339      176436 :         ZVAL_STR(&zv, *str);
     340      176436 :         ret = zend_add_literal(op_array, &zv TSRMLS_CC);
     341      176436 :         *str = Z_STR(zv);
     342      176436 :         return ret;
     343             : }
     344             : 
     345       47474 : static int zend_add_func_name_literal(zend_op_array *op_array, zend_string *name TSRMLS_DC) /* {{{ */
     346             : {
     347             :         /* Original name */
     348       47474 :         int ret = zend_add_literal_string(op_array, &name TSRMLS_CC);
     349             : 
     350             :         /* Lowercased name */
     351       94948 :         zend_string *lc_name = zend_string_alloc(name->len, 0);
     352       47474 :         zend_str_tolower_copy(lc_name->val, name->val, name->len);
     353       47474 :         zend_add_literal_string(op_array, &lc_name TSRMLS_CC);
     354             : 
     355       47474 :         return ret;
     356             : }
     357             : /* }}} */
     358             : 
     359         297 : static int zend_add_ns_func_name_literal(zend_op_array *op_array, zend_string *name TSRMLS_DC) /* {{{ */
     360             : {
     361             :         const char *unqualified_name;
     362             :         size_t unqualified_name_len;
     363             : 
     364             :         /* Original name */
     365         297 :         int ret = zend_add_literal_string(op_array, &name TSRMLS_CC);
     366             : 
     367             :         /* Lowercased name */
     368         594 :         zend_string *lc_name = zend_string_alloc(name->len, 0);
     369         297 :         zend_str_tolower_copy(lc_name->val, name->val, name->len);
     370         297 :         zend_add_literal_string(op_array, &lc_name TSRMLS_CC);
     371             : 
     372             :         /* Lowercased unqualfied name */
     373         297 :         if (zend_get_unqualified_name(name, &unqualified_name, &unqualified_name_len)) {
     374         594 :                 lc_name = zend_string_alloc(unqualified_name_len, 0);
     375         297 :                 zend_str_tolower_copy(lc_name->val, unqualified_name, unqualified_name_len);
     376         297 :                 zend_add_literal_string(op_array, &lc_name TSRMLS_CC);
     377             :         }
     378             : 
     379         297 :         return ret;
     380             : }
     381             : /* }}} */
     382             : 
     383       32035 : static int zend_add_class_name_literal(zend_op_array *op_array, zend_string *name TSRMLS_DC) /* {{{ */
     384             : {
     385             :         /* Original name */
     386       32035 :         int ret = zend_add_literal_string(op_array, &name TSRMLS_CC);
     387             : 
     388             :         /* Lowercased name */
     389       64070 :         zend_string *lc_name = zend_string_alloc(name->len, 0);
     390       32035 :         zend_str_tolower_copy(lc_name->val, name->val, name->len);
     391       32035 :         zend_add_literal_string(op_array, &lc_name TSRMLS_CC);
     392             : 
     393       32035 :         zend_alloc_cache_slot(ret TSRMLS_CC);
     394             : 
     395       32035 :         return ret;
     396             : }
     397             : /* }}} */
     398             : 
     399        5495 : static int zend_add_const_name_literal(zend_op_array *op_array, zend_string *name, zend_bool unqualified TSRMLS_DC) /* {{{ */
     400             : {
     401             :         zend_string *tmp_name;
     402             : 
     403        5495 :         int ret = zend_add_literal_string(op_array, &name TSRMLS_CC);
     404             : 
     405        5495 :         size_t ns_len = 0, after_ns_len = name->len;
     406       10990 :         const char *after_ns = zend_memrchr(name->val, '\\', name->len);
     407        5495 :         if (after_ns) {
     408          70 :                 after_ns += 1;
     409          70 :                 ns_len = after_ns - name->val - 1;
     410          70 :                 after_ns_len = name->len - ns_len - 1;
     411             : 
     412             :                 /* lowercased namespace name & original constant name */
     413         140 :                 tmp_name = zend_string_init(name->val, name->len, 0);
     414          70 :                 zend_str_tolower(tmp_name->val, ns_len);
     415          70 :                 zend_add_literal_string(op_array, &tmp_name TSRMLS_CC);
     416             : 
     417             :                 /* lowercased namespace name & lowercased constant name */
     418         140 :                 tmp_name = zend_string_alloc(name->len, 0);
     419          70 :                 zend_str_tolower_copy(tmp_name->val, name->val, name->len);
     420          70 :                 zend_add_literal_string(op_array, &tmp_name TSRMLS_CC);
     421             : 
     422          70 :                 if (!unqualified) {
     423          49 :                         return ret;
     424             :                 }
     425             :         } else {
     426        5425 :                 after_ns = name->val;
     427             :         }
     428             : 
     429             :         /* original unqualified constant name */
     430        5446 :         tmp_name = zend_string_init(after_ns, after_ns_len, 0);
     431        5446 :         zend_add_literal_string(op_array, &tmp_name TSRMLS_CC);
     432             : 
     433             :         /* lowercased unqualified constant name */
     434        5446 :         tmp_name = zend_string_alloc(after_ns_len, 0);
     435        5446 :         zend_str_tolower_copy(tmp_name->val, after_ns, after_ns_len);
     436        5446 :         zend_add_literal_string(op_array, &tmp_name TSRMLS_CC);
     437             : 
     438        5446 :         return ret;
     439             : }
     440             : /* }}} */
     441             : 
     442             : #define LITERAL_STR(op, str) do { \
     443             :                 zval _c; \
     444             :                 ZVAL_STR(&_c, str); \
     445             :                 op.constant = zend_add_literal(CG(active_op_array), &_c TSRMLS_CC); \
     446             :         } while (0)
     447             : 
     448             : #define MAKE_NOP(opline) do { \
     449             :         opline->opcode = ZEND_NOP; \
     450             :         memset(&opline->result, 0, sizeof(opline->result)); \
     451             :         memset(&opline->op1, 0, sizeof(opline->op1)); \
     452             :         memset(&opline->op2, 0, sizeof(opline->op2)); \
     453             :         opline->result_type = opline->op1_type = opline->op2_type = IS_UNUSED; \
     454             : } while (0)
     455             : 
     456         275 : void zend_stop_lexing(TSRMLS_D) {
     457         275 :         LANG_SCNG(yy_cursor) = LANG_SCNG(yy_limit);
     458         275 : }
     459             : 
     460       14340 : static inline void zend_begin_loop(TSRMLS_D) /* {{{ */
     461             : {
     462             :         zend_brk_cont_element *brk_cont_element;
     463             :         int parent;
     464             : 
     465       14340 :         parent = CG(context).current_brk_cont;
     466       14340 :         CG(context).current_brk_cont = CG(active_op_array)->last_brk_cont;
     467       14340 :         brk_cont_element = get_next_brk_cont_element(CG(active_op_array));
     468       14340 :         brk_cont_element->start = get_next_op_number(CG(active_op_array));
     469       14340 :         brk_cont_element->parent = parent;
     470       14340 : }
     471             : /* }}} */
     472             : 
     473       14339 : static inline void zend_end_loop(int cont_addr, int has_loop_var TSRMLS_DC) /* {{{ */
     474             : {
     475       14339 :         if (!has_loop_var) {
     476             :                 /* The start fileld is used to free temporary variables in case of exceptions.
     477             :                  * We won't try to free something of we don't have loop variable.
     478             :                  */
     479        4141 :                 CG(active_op_array)->brk_cont_array[CG(context).current_brk_cont].start = -1;
     480             :         }
     481       14339 :         CG(active_op_array)->brk_cont_array[CG(context).current_brk_cont].cont = cont_addr;
     482       14339 :         CG(active_op_array)->brk_cont_array[CG(context).current_brk_cont].brk = get_next_op_number(CG(active_op_array));
     483       14339 :         CG(context).current_brk_cont = CG(active_op_array)->brk_cont_array[CG(context).current_brk_cont].parent;
     484       14339 : }
     485             : /* }}} */
     486             : 
     487      291762 : void zend_do_free(znode *op1 TSRMLS_DC) /* {{{ */
     488             : {
     489      291762 :         if (op1->op_type==IS_TMP_VAR) {
     490       10468 :                 zend_op *opline = get_next_op(CG(active_op_array) TSRMLS_CC);
     491             : 
     492       10468 :                 opline->opcode = ZEND_FREE;
     493       10468 :                 SET_NODE(opline->op1, op1);
     494       10468 :                 SET_UNUSED(opline->op2);
     495      281294 :         } else if (op1->op_type==IS_VAR) {
     496      261634 :                 zend_op *opline = &CG(active_op_array)->opcodes[CG(active_op_array)->last-1];
     497             : 
     498      533247 :                 while (opline->opcode == ZEND_END_SILENCE || opline->opcode == ZEND_EXT_FCALL_END || opline->opcode == ZEND_OP_DATA) {
     499        9979 :                         opline--;
     500             :                 }
     501      784358 :                 if (opline->result_type == IS_VAR
     502      522996 :                         && opline->result.var == op1->u.op.var) {
     503      784101 :                         if (opline->opcode == ZEND_FETCH_R ||
     504      261358 :                             opline->opcode == ZEND_FETCH_DIM_R ||
     505      261343 :                             opline->opcode == ZEND_FETCH_OBJ_R) {
     506             :                                 /* It's very rare and useless case. It's better to use
     507             :                                    additional FREE opcode and simplify the FETCH handlers
     508             :                                    their selves */
     509          38 :                                 opline = get_next_op(CG(active_op_array) TSRMLS_CC);
     510          38 :                                 opline->opcode = ZEND_FREE;
     511          38 :                                 SET_NODE(opline->op1, op1);
     512          38 :                                 SET_UNUSED(opline->op2);
     513             :                         } else {
     514      261324 :                                 opline->result_type |= EXT_TYPE_UNUSED;
     515             :                         }
     516             :                 } else {
     517        1089 :                         while (opline >= CG(active_op_array)->opcodes) {
     518        1003 :                                 if (opline->opcode == ZEND_FETCH_LIST &&
     519          93 :                                     opline->op1_type == IS_VAR &&
     520          93 :                                     opline->op1.var == op1->u.op.var) {
     521          86 :                                         opline = get_next_op(CG(active_op_array) TSRMLS_CC);
     522             : 
     523          86 :                                         opline->opcode = ZEND_FREE;
     524          86 :                                         SET_NODE(opline->op1, op1);
     525          86 :                                         SET_UNUSED(opline->op2);
     526          86 :                                         return;
     527             :                                 }
     528         966 :                                 if (opline->result_type==IS_VAR
     529         966 :                                         && opline->result.var == op1->u.op.var) {
     530         186 :                                         if (opline->opcode == ZEND_NEW) {
     531         186 :                                                 opline->result_type |= EXT_TYPE_UNUSED;
     532         186 :                                                 opline = &CG(active_op_array)->opcodes[CG(active_op_array)->last-1];
     533         372 :                                                 while (opline->opcode != ZEND_DO_FCALL || opline->op1.num != ZEND_CALL_CTOR) {
     534           0 :                                                         opline--;
     535             :                                                 }
     536         186 :                                                 opline->op1.num |= ZEND_CALL_CTOR_RESULT_UNUSED;
     537             :                                         }
     538         186 :                                         break;
     539             :                                 }
     540         545 :                                 opline--;
     541             :                         }
     542             :                 }
     543       19660 :         } else if (op1->op_type == IS_CONST) {
     544             :                 /* Destroy value without using GC: When opcache moves arrays into SHM it will
     545             :                  * free the zend_array structure, so references to it from outside the op array
     546             :                  * become invalid. GC would cause such a reference in the root buffer. */
     547       19383 :                 zval_ptr_dtor_nogc(&op1->u.constant);
     548             :         }
     549             : }
     550             : /* }}} */
     551             : 
     552         705 : uint32_t zend_add_member_modifier(uint32_t flags, uint32_t new_flag) /* {{{ */
     553             : {
     554         705 :         uint32_t new_flags = flags | new_flag;
     555         705 :         if ((flags & ZEND_ACC_PPP_MASK) && (new_flag & ZEND_ACC_PPP_MASK)) {
     556           4 :                 zend_error_noreturn(E_COMPILE_ERROR, "Multiple access type modifiers are not allowed");
     557             :         }
     558         701 :         if ((flags & ZEND_ACC_ABSTRACT) && (new_flag & ZEND_ACC_ABSTRACT)) {
     559           1 :                 zend_error_noreturn(E_COMPILE_ERROR, "Multiple abstract modifiers are not allowed");
     560             :         }
     561         700 :         if ((flags & ZEND_ACC_STATIC) && (new_flag & ZEND_ACC_STATIC)) {
     562           1 :                 zend_error_noreturn(E_COMPILE_ERROR, "Multiple static modifiers are not allowed");
     563             :         }
     564         699 :         if ((flags & ZEND_ACC_FINAL) && (new_flag & ZEND_ACC_FINAL)) {
     565           1 :                 zend_error_noreturn(E_COMPILE_ERROR, "Multiple final modifiers are not allowed");
     566             :         }
     567         698 :         if ((new_flags & ZEND_ACC_ABSTRACT) && (new_flags & ZEND_ACC_FINAL)) {
     568           4 :                 zend_error_noreturn(E_COMPILE_ERROR, "Cannot use the final modifier on an abstract class member");
     569             :         }
     570         694 :         return new_flags;
     571             : }
     572             : /* }}} */
     573             : 
     574        1982 : zend_string *zend_concat3(char *str1, size_t str1_len, char *str2, size_t str2_len, char *str3, size_t str3_len) /* {{{ */
     575             : {
     576        1982 :         size_t len = str1_len + str2_len + str3_len;
     577        1982 :         zend_string *res = zend_string_alloc(len, 0);
     578             : 
     579        1982 :         memcpy(res->val, str1, str1_len);
     580        1982 :         memcpy(res->val + str1_len, str2, str2_len);
     581        1982 :         memcpy(res->val + str1_len + str2_len, str3, str3_len);
     582        1982 :         res->val[len] = '\0';
     583             : 
     584        1982 :         return res;
     585             : }
     586             : 
     587         897 : zend_string *zend_concat_names(char *name1, size_t name1_len, char *name2, size_t name2_len) {
     588         897 :         return zend_concat3(name1, name1_len, "\\", 1, name2, name2_len);
     589             : }
     590             : 
     591      383759 : zend_string *zend_prefix_with_ns(zend_string *name TSRMLS_DC) {
     592      383759 :         if (CG(current_namespace)) {
     593         870 :                 zend_string *ns = CG(current_namespace);
     594         870 :                 return zend_concat_names(ns->val, ns->len, name->val, name->len);
     595             :         } else {
     596      382889 :                 return zend_string_copy(name);
     597             :         }
     598             : }
     599             : 
     600       21174 : void *zend_hash_find_ptr_lc(HashTable *ht, const char *str, size_t len) {
     601             :         void *result;
     602             :         zend_string *lcname;
     603             :         ALLOCA_FLAG(use_heap);
     604             : 
     605       21174 :         STR_ALLOCA_ALLOC(lcname, len, use_heap);
     606       21174 :         zend_str_tolower_copy(lcname->val, str, len);
     607       21174 :         result = zend_hash_find_ptr(ht, lcname);
     608       21174 :         STR_ALLOCA_FREE(lcname, use_heap);
     609             : 
     610       21174 :         return result;
     611             : }
     612             : 
     613      333171 : zend_string *zend_resolve_non_class_name(
     614             :         zend_string *name, uint32_t type, zend_bool *is_fully_qualified,
     615             :         zend_bool case_sensitive, HashTable *current_import_sub TSRMLS_DC
     616             : ) {
     617             :         char *compound;
     618      333171 :         *is_fully_qualified = 0;
     619             : 
     620      333171 :         if (name->val[0] == '\\') {
     621             :                 /* Remove \ prefix (only relevant if this is a string rather than a label) */
     622           2 :                 return zend_string_init(name->val + 1, name->len - 1, 0);
     623             :         }
     624             : 
     625      333170 :         if (type == ZEND_NAME_FQ) {
     626         170 :                 *is_fully_qualified = 1;
     627         170 :                 return zend_string_copy(name);
     628             :         }
     629             : 
     630      333000 :         if (type == ZEND_NAME_RELATIVE) {
     631          45 :                 *is_fully_qualified = 1;
     632          45 :                 return zend_prefix_with_ns(name TSRMLS_CC);
     633             :         }
     634             : 
     635      332955 :         if (current_import_sub) {
     636             :                 /* If an unqualified name is a function/const alias, replace it. */
     637             :                 zend_string *import_name;
     638          30 :                 if (case_sensitive) {
     639           9 :                         import_name = zend_hash_find_ptr(current_import_sub, name);
     640             :                 } else {
     641          21 :                         import_name = zend_hash_find_ptr_lc(current_import_sub, name->val, name->len);
     642             :                 }
     643             : 
     644          30 :                 if (import_name) {
     645          19 :                         *is_fully_qualified = 1;
     646          19 :                         return zend_string_copy(import_name);
     647             :                 }
     648             :         }
     649             : 
     650      332936 :         compound = memchr(name->val, '\\', name->len);
     651      332936 :         if (compound) {
     652          70 :                 *is_fully_qualified = 1;
     653             :         }
     654             : 
     655      332936 :         if (compound && CG(current_import)) {
     656             :                 /* If the first part of a qualified name is an alias, substitute it. */
     657          42 :                 size_t len = compound - name->val;
     658          42 :                 zend_string *import_name = zend_hash_find_ptr_lc(CG(current_import), name->val, len);
     659             : 
     660          42 :                 if (import_name) {
     661          13 :                         return zend_concat_names(
     662          13 :                                 import_name->val, import_name->len, name->val + len + 1, name->len - len - 1);
     663             :                 }
     664             :         }
     665             : 
     666      332923 :         return zend_prefix_with_ns(name TSRMLS_CC);
     667             : }
     668             : /* }}} */
     669             : 
     670      255423 : zend_string *zend_resolve_function_name(zend_string *name, uint32_t type, zend_bool *is_fully_qualified TSRMLS_DC) /* {{{ */
     671             : {
     672      255423 :         return zend_resolve_non_class_name(
     673             :                 name, type, is_fully_qualified, 0, CG(current_import_function) TSRMLS_CC);
     674             : }
     675             : /* }}} */
     676             : 
     677       77748 : zend_string *zend_resolve_const_name(zend_string *name, uint32_t type, zend_bool *is_fully_qualified TSRMLS_DC) /* {{{ */ {
     678       77748 :         return zend_resolve_non_class_name(
     679             :                 name, type, is_fully_qualified, 1, CG(current_import_const) TSRMLS_CC);
     680             : }
     681             : /* }}} */
     682             : 
     683       32558 : zend_string *zend_resolve_class_name(zend_string *name, uint32_t type TSRMLS_DC) /* {{{ */
     684             : {
     685             :         char *compound;
     686             : 
     687       32558 :         if (type == ZEND_NAME_RELATIVE) {
     688          18 :                 return zend_prefix_with_ns(name TSRMLS_CC);
     689             :         }
     690             : 
     691       32540 :         if (type == ZEND_NAME_FQ || name->val[0] == '\\') {
     692             :                 /* Remove \ prefix (only relevant if this is a string rather than a label) */
     693         159 :                 if (name->val[0] == '\\') {
     694           2 :                         name = zend_string_init(name->val + 1, name->len - 1, 0);
     695             :                 } else {
     696             :                         zend_string_addref(name);
     697             :                 }
     698             :                 /* Ensure that \self, \parent and \static are not used */
     699         159 :                 if (ZEND_FETCH_CLASS_DEFAULT != zend_get_class_fetch_type(name)) {
     700           1 :                         zend_error_noreturn(E_COMPILE_ERROR, "'\\%s' is an invalid class name", name->val);
     701             :                 }
     702         158 :                 return name;
     703             :         }
     704             : 
     705       32381 :         if (CG(current_import)) {
     706         135 :                 compound = memchr(name->val, '\\', name->len);
     707         135 :                 if (compound) {
     708             :                         /* If the first part of a qualified name is an alias, substitute it. */
     709          24 :                         size_t len = compound - name->val;
     710          24 :                         zend_string *import_name = zend_hash_find_ptr_lc(CG(current_import), name->val, len);
     711             : 
     712          24 :                         if (import_name) {
     713          14 :                                 return zend_concat_names(
     714          14 :                                         import_name->val, import_name->len, name->val + len + 1, name->len - len - 1);
     715             :                         }
     716             :                 } else {
     717             :                         /* If an unqualified name is an alias, replace it. */
     718             :                         zend_string *import_name
     719         111 :                                 = zend_hash_find_ptr_lc(CG(current_import), name->val, name->len);
     720             : 
     721         111 :                         if (import_name) {
     722          48 :                                 return zend_string_copy(import_name);
     723             :                         }
     724             :                 }
     725             :         }
     726             : 
     727             :         /* If not fully qualified and not an alias, prepend the current namespace */
     728       32319 :         return zend_prefix_with_ns(name TSRMLS_CC);
     729             : }
     730             : /* }}} */
     731             : 
     732       30236 : zend_string *zend_resolve_class_name_ast(zend_ast *ast TSRMLS_DC) /* {{{ */
     733             : {
     734       30236 :         zend_string *name = zend_ast_get_str(ast);
     735       30236 :         return zend_resolve_class_name(name, ast->attr TSRMLS_CC);
     736             : }
     737             : /* }}} */
     738             : 
     739          26 : static void ptr_dtor(zval *zv) /* {{{ */
     740             : {
     741          26 :         efree(Z_PTR_P(zv));
     742          26 : }
     743             : /* }}} */
     744             : 
     745          73 : static void str_dtor(zval *zv)  /* {{{ */ {
     746          73 :         zend_string_release(Z_STR_P(zv));
     747          73 : }
     748             : /* }}} */
     749             : 
     750          58 : void zend_resolve_goto_label(zend_op_array *op_array, zend_op *opline, int pass2 TSRMLS_DC) /* {{{ */
     751             : {
     752             :         zend_label *dest;
     753             :         zend_long current, distance;
     754             :         zval *label;
     755             : 
     756          58 :         if (pass2) {
     757          23 :                 label = opline->op2.zv;
     758             :         } else {
     759          35 :                 label = &CONSTANT_EX(op_array, opline->op2.constant);
     760             :         }
     761          99 :         if (CG(context).labels == NULL ||
     762          41 :             (dest = zend_hash_find_ptr(CG(context).labels, Z_STR_P(label))) == NULL) {
     763             : 
     764          24 :                 if (pass2) {
     765           1 :                         CG(in_compilation) = 1;
     766           1 :                         CG(active_op_array) = op_array;
     767           1 :                         CG(zend_lineno) = opline->lineno;
     768           1 :                         zend_error_noreturn(E_COMPILE_ERROR, "'goto' to undefined label '%s'", Z_STRVAL_P(label));
     769             :                 } else {
     770             :                         /* Label is not defined. Delay to pass 2. */
     771          23 :                         return;
     772             :                 }
     773             :         }
     774             : 
     775          34 :         opline->op1.opline_num = dest->opline_num;
     776             :         zval_dtor(label);
     777          34 :         ZVAL_NULL(label);
     778             : 
     779             :         /* Check that we are not moving into loop or switch */
     780          34 :         current = opline->extended_value;
     781          38 :         for (distance = 0; current != dest->brk_cont; distance++) {
     782           8 :                 if (current == -1) {
     783           4 :                         if (pass2) {
     784           2 :                                 CG(in_compilation) = 1;
     785           2 :                                 CG(active_op_array) = op_array;
     786           2 :                                 CG(zend_lineno) = opline->lineno;
     787             :                         }
     788           4 :                         zend_error_noreturn(E_COMPILE_ERROR, "'goto' into loop or switch statement is disallowed");
     789             :                 }
     790           4 :                 current = op_array->brk_cont_array[current].parent;
     791             :         }
     792             : 
     793          30 :         if (distance == 0) {
     794             :                 /* Nothing to break out of, optimize to ZEND_JMP */
     795          27 :                 opline->opcode = ZEND_JMP;
     796          27 :                 opline->extended_value = 0;
     797          27 :                 SET_UNUSED(opline->op2);
     798             :         } else {
     799             :                 /* Set real break distance */
     800           3 :                 ZVAL_LONG(label, distance);
     801             :         }
     802             : }
     803             : /* }}} */
     804             : 
     805       64701 : void zend_release_labels(int temporary TSRMLS_DC) /* {{{ */
     806             : {
     807       64701 :         if (CG(context).labels) {
     808          14 :                 zend_hash_destroy(CG(context).labels);
     809          14 :                 FREE_HASHTABLE(CG(context).labels);
     810          14 :                 CG(context).labels = NULL;
     811             :         }
     812       64701 :         if (!temporary && !zend_stack_is_empty(&CG(context_stack))) {
     813       64701 :                 zend_compiler_context *ctx = zend_stack_top(&CG(context_stack));
     814       64701 :                 CG(context) = *ctx;
     815       64701 :                 zend_stack_del_top(&CG(context_stack));
     816             :         }
     817       64701 : }
     818             : /* }}} */
     819             : 
     820             : static zend_bool zend_is_call(zend_ast *ast);
     821             : 
     822       53415 : static int generate_free_loop_var(znode *var TSRMLS_DC) /* {{{ */
     823             : {
     824       53415 :         switch (var->op_type) {
     825             :                 case IS_UNUSED:
     826             :                         /* Stack separator on function boundary, stop applying */
     827       43056 :                         return 1;
     828             :                 case IS_VAR:
     829             :                 case IS_TMP_VAR:
     830             :                 {
     831       10262 :                         zend_op *opline = get_next_op(CG(active_op_array) TSRMLS_CC);
     832             : 
     833       10262 :                         opline->opcode = ZEND_FREE;
     834       10262 :                         SET_NODE(opline->op1, var);
     835       10262 :                         SET_UNUSED(opline->op2);
     836             :                 }
     837             :         }
     838             : 
     839       10359 :         return 0;
     840             : }
     841             : /* }}} */
     842             : 
     843        1998 : static uint32_t zend_add_try_element(uint32_t try_op TSRMLS_DC) /* {{{ */
     844             : {
     845        1998 :         zend_op_array *op_array = CG(active_op_array);
     846        1998 :         uint32_t try_catch_offset = op_array->last_try_catch++;
     847             :         zend_try_catch_element *elem;
     848             : 
     849        1998 :         op_array->try_catch_array = safe_erealloc(
     850             :                 op_array->try_catch_array, sizeof(zend_try_catch_element), op_array->last_try_catch, 0);
     851             : 
     852        1998 :         elem = &op_array->try_catch_array[try_catch_offset];
     853        1998 :         elem->try_op = try_op;
     854        1998 :         elem->catch_op = 0;
     855        1998 :         elem->finally_op = 0;
     856        1998 :         elem->finally_end = 0;
     857             : 
     858        1998 :         return try_catch_offset;
     859             : }
     860             : /* }}} */
     861             : 
     862    25764998 : ZEND_API void function_add_ref(zend_function *function) /* {{{ */
     863             : {
     864    25764998 :         if (function->type == ZEND_USER_FUNCTION) {
     865        1601 :                 zend_op_array *op_array = &function->op_array;
     866             : 
     867        1601 :                 (*op_array->refcount)++;
     868        1601 :                 if (op_array->static_variables) {
     869           5 :                         HashTable *static_variables = op_array->static_variables;
     870             : 
     871           5 :                         ALLOC_HASHTABLE(op_array->static_variables);
     872           5 :                         zend_array_dup(op_array->static_variables, static_variables);
     873             :                 }
     874        1601 :                 op_array->run_time_cache = NULL;
     875    25763397 :         } else if (function->type == ZEND_INTERNAL_FUNCTION) {
     876    25763397 :                 if (function->common.function_name) {
     877    25763397 :                         zend_string_addref(function->common.function_name);
     878             :                 }
     879             :         }
     880    25764998 : }
     881             : /* }}} */
     882             : 
     883       16448 : ZEND_API int do_bind_function(const zend_op_array *op_array, const zend_op *opline, HashTable *function_table, zend_bool compile_time TSRMLS_DC) /* {{{ */
     884             : {
     885             :         zend_function *function, *new_function;
     886             :         zval *op1, *op2;
     887             : 
     888       16448 :         if (compile_time) {
     889       13394 :                 op1 = &CONSTANT_EX(op_array, opline->op1.constant);
     890       13394 :                 op2 = &CONSTANT_EX(op_array, opline->op2.constant);
     891             :         } else {
     892        3054 :                 op1 = opline->op1.zv;
     893        3054 :                 op2 = opline->op2.zv;
     894             :         }
     895             : 
     896       32896 :         function = zend_hash_find_ptr(function_table, Z_STR_P(op1));
     897       16448 :         new_function = zend_arena_alloc(&CG(arena), sizeof(zend_op_array));
     898       16448 :         memcpy(new_function, function, sizeof(zend_op_array));
     899       32896 :         if (zend_hash_add_ptr(function_table, Z_STR_P(op2), new_function) == NULL) {
     900           0 :                 int error_level = compile_time ? E_COMPILE_ERROR : E_ERROR;
     901             :                 zend_function *old_function;
     902             : 
     903           0 :                 efree_size(new_function, sizeof(zend_op_array));
     904           0 :                 if ((old_function = zend_hash_find_ptr(function_table, Z_STR_P(op2))) != NULL
     905             :                         && old_function->type == ZEND_USER_FUNCTION
     906           0 :                         && old_function->op_array.last > 0) {
     907           0 :                         zend_error(error_level, "Cannot redeclare %s() (previously declared in %s:%d)",
     908           0 :                                                 function->common.function_name->val,
     909           0 :                                                 old_function->op_array.filename->val,
     910           0 :                                                 old_function->op_array.opcodes[0].lineno);
     911             :                 } else {
     912           0 :                         zend_error(error_level, "Cannot redeclare %s()", function->common.function_name->val);
     913             :                 }
     914           0 :                 return FAILURE;
     915             :         } else {
     916       16448 :                 (*function->op_array.refcount)++;
     917       16448 :                 function->op_array.static_variables = NULL; /* NULL out the unbound function */
     918       16448 :                 return SUCCESS;
     919             :         }
     920             : }
     921             : /* }}} */
     922             : 
     923        4886 : ZEND_API zend_class_entry *do_bind_class(const zend_op_array* op_array, const zend_op *opline, HashTable *class_table, zend_bool compile_time TSRMLS_DC) /* {{{ */
     924             : {
     925             :         zend_class_entry *ce;
     926             :         zval *op1, *op2;
     927             : 
     928        4886 :         if (compile_time) {
     929        4470 :                 op1 = &CONSTANT_EX(op_array, opline->op1.constant);
     930        4470 :                 op2 = &CONSTANT_EX(op_array, opline->op2.constant);
     931             :         } else {
     932         416 :                 op1 = opline->op1.zv;
     933         416 :                 op2 = opline->op2.zv;
     934             :         }
     935        9772 :         if ((ce = zend_hash_find_ptr(class_table, Z_STR_P(op1))) == NULL) {
     936           0 :                 zend_error_noreturn(E_COMPILE_ERROR, "Internal Zend error - Missing class information for %s", Z_STRVAL_P(op1));
     937             :                 return NULL;
     938             :         }
     939        4886 :         ce->refcount++;
     940        9772 :         if (zend_hash_add_ptr(class_table, Z_STR_P(op2), ce) == NULL) {
     941           4 :                 ce->refcount--;
     942           4 :                 if (!compile_time) {
     943             :                         /* If we're in compile time, in practice, it's quite possible
     944             :                          * that we'll never reach this class declaration at runtime,
     945             :                          * so we shut up about it.  This allows the if (!defined('FOO')) { return; }
     946             :                          * approach to work.
     947             :                          */
     948           2 :                         zend_error_noreturn(E_COMPILE_ERROR, "Cannot redeclare class %s", ce->name->val);
     949             :                 }
     950           2 :                 return NULL;
     951             :         } else {
     952        4882 :                 if (!(ce->ce_flags & (ZEND_ACC_INTERFACE|ZEND_ACC_IMPLEMENT_INTERFACES|ZEND_ACC_IMPLEMENT_TRAITS))) {
     953        4332 :                         zend_verify_abstract_class(ce TSRMLS_CC);
     954             :                 }
     955        4879 :                 return ce;
     956             :         }
     957             : }
     958             : /* }}} */
     959             : 
     960        2317 : ZEND_API zend_class_entry *do_bind_inherited_class(const zend_op_array *op_array, const zend_op *opline, HashTable *class_table, zend_class_entry *parent_ce, zend_bool compile_time TSRMLS_DC) /* {{{ */
     961             : {
     962             :         zend_class_entry *ce;
     963             :         zval *op1, *op2;
     964             : 
     965        2317 :         if (compile_time) {
     966        1038 :                 op1 = &CONSTANT_EX(op_array, opline->op1.constant);
     967        1038 :                 op2 = &CONSTANT_EX(op_array, opline->op2.constant);
     968             :         } else {
     969        1279 :                 op1 = opline->op1.zv;
     970        1279 :                 op2 = opline->op2.zv;
     971             :         }
     972             : 
     973        4634 :         ce = zend_hash_find_ptr(class_table, Z_STR_P(op1));
     974             : 
     975        2317 :         if (!ce) {
     976           0 :                 if (!compile_time) {
     977             :                         /* If we're in compile time, in practice, it's quite possible
     978             :                          * that we'll never reach this class declaration at runtime,
     979             :                          * so we shut up about it.  This allows the if (!defined('FOO')) { return; }
     980             :                          * approach to work.
     981             :                          */
     982           0 :                         zend_error_noreturn(E_COMPILE_ERROR, "Cannot redeclare class %s", Z_STRVAL_P(op2));
     983             :                 }
     984           0 :                 return NULL;
     985             :         }
     986             : 
     987        2317 :         if (parent_ce->ce_flags & ZEND_ACC_INTERFACE) {
     988           1 :                 zend_error_noreturn(E_COMPILE_ERROR, "Class %s cannot extend from interface %s", ce->name->val, parent_ce->name->val);
     989        2316 :         } else if ((parent_ce->ce_flags & ZEND_ACC_TRAIT) == ZEND_ACC_TRAIT) {
     990           2 :                 zend_error_noreturn(E_COMPILE_ERROR, "Class %s cannot extend from trait %s", ce->name->val, parent_ce->name->val);
     991             :         }
     992             : 
     993        2314 :         zend_do_inheritance(ce, parent_ce TSRMLS_CC);
     994             : 
     995        2273 :         ce->refcount++;
     996             : 
     997             :         /* Register the derived class */
     998        4546 :         if (zend_hash_add_ptr(class_table, Z_STR_P(op2), ce) == NULL) {
     999           0 :                 zend_error_noreturn(E_COMPILE_ERROR, "Cannot redeclare class %s", ce->name->val);
    1000             :         }
    1001        2273 :         return ce;
    1002             : }
    1003             : /* }}} */
    1004             : 
    1005       19672 : void zend_do_early_binding(TSRMLS_D) /* {{{ */
    1006             : {
    1007       19672 :         zend_op *opline = &CG(active_op_array)->opcodes[CG(active_op_array)->last-1];
    1008             :         HashTable *table;
    1009             : 
    1010       39344 :         while (opline->opcode == ZEND_TICKS && opline > CG(active_op_array)->opcodes) {
    1011           0 :                 opline--;
    1012             :         }
    1013             : 
    1014       19672 :         switch (opline->opcode) {
    1015             :                 case ZEND_DECLARE_FUNCTION:
    1016       13394 :                         if (do_bind_function(CG(active_op_array), opline, CG(function_table), 1 TSRMLS_CC) == FAILURE) {
    1017           0 :                                 return;
    1018             :                         }
    1019       13394 :                         table = CG(function_table);
    1020       13394 :                         break;
    1021             :                 case ZEND_DECLARE_CLASS:
    1022        4470 :                         if (do_bind_class(CG(active_op_array), opline, CG(class_table), 1 TSRMLS_CC) == NULL) {
    1023           2 :                                 return;
    1024             :                         }
    1025        4465 :                         table = CG(class_table);
    1026        4465 :                         break;
    1027             :                 case ZEND_DECLARE_INHERITED_CLASS:
    1028             :                         {
    1029        1323 :                                 zend_op *fetch_class_opline = opline-1;
    1030             :                                 zval *parent_name;
    1031             :                                 zend_class_entry *ce;
    1032             : 
    1033        1323 :                                 parent_name = &CONSTANT(fetch_class_opline->op2.constant);
    1034        2361 :                                 if (((ce = zend_lookup_class(Z_STR_P(parent_name) TSRMLS_CC)) == NULL) ||
    1035        1038 :                                     ((CG(compiler_options) & ZEND_COMPILE_IGNORE_INTERNAL_CLASSES) &&
    1036           0 :                                      (ce->type == ZEND_INTERNAL_CLASS))) {
    1037         285 :                                     if (CG(compiler_options) & ZEND_COMPILE_DELAYED_BINDING) {
    1038           0 :                                                 uint32_t *opline_num = &CG(active_op_array)->early_binding;
    1039             : 
    1040           0 :                                                 while (*opline_num != -1) {
    1041           0 :                                                         opline_num = &CG(active_op_array)->opcodes[*opline_num].result.opline_num;
    1042             :                                                 }
    1043           0 :                                                 *opline_num = opline - CG(active_op_array)->opcodes;
    1044           0 :                                                 opline->opcode = ZEND_DECLARE_INHERITED_CLASS_DELAYED;
    1045           0 :                                                 opline->result_type = IS_UNUSED;
    1046           0 :                                                 opline->result.opline_num = -1;
    1047             :                                         }
    1048         285 :                                         return;
    1049             :                                 }
    1050        1038 :                                 if (do_bind_inherited_class(CG(active_op_array), opline, CG(class_table), ce, 1 TSRMLS_CC) == NULL) {
    1051           0 :                                         return;
    1052             :                                 }
    1053             :                                 /* clear unnecessary ZEND_FETCH_CLASS opcode */
    1054         997 :                                 zend_del_literal(CG(active_op_array), fetch_class_opline->op2.constant);
    1055         997 :                                 MAKE_NOP(fetch_class_opline);
    1056             : 
    1057         997 :                                 table = CG(class_table);
    1058         997 :                                 break;
    1059             :                         }
    1060             :                 case ZEND_VERIFY_ABSTRACT_CLASS:
    1061             :                 case ZEND_ADD_INTERFACE:
    1062             :                 case ZEND_ADD_TRAIT:
    1063             :                 case ZEND_BIND_TRAITS:
    1064             :                         /* We currently don't early-bind classes that implement interfaces */
    1065             :                         /* Classes with traits are handled exactly the same, no early-bind here */
    1066         485 :                         return;
    1067             :                 default:
    1068           0 :                         zend_error_noreturn(E_COMPILE_ERROR, "Invalid binding type");
    1069             :                         return;
    1070             :         }
    1071             : 
    1072       18856 :         zend_hash_del(table, Z_STR(CONSTANT(opline->op1.constant)));
    1073       18856 :         zend_del_literal(CG(active_op_array), opline->op1.constant);
    1074       18856 :         zend_del_literal(CG(active_op_array), opline->op2.constant);
    1075       18856 :         MAKE_NOP(opline);
    1076             : }
    1077             : /* }}} */
    1078             : 
    1079           0 : ZEND_API void zend_do_delayed_early_binding(const zend_op_array *op_array TSRMLS_DC) /* {{{ */
    1080             : {
    1081           0 :         if (op_array->early_binding != -1) {
    1082           0 :                 zend_bool orig_in_compilation = CG(in_compilation);
    1083           0 :                 uint32_t opline_num = op_array->early_binding;
    1084             :                 zend_class_entry *ce;
    1085             : 
    1086           0 :                 CG(in_compilation) = 1;
    1087           0 :                 while (opline_num != -1) {
    1088           0 :                         if ((ce = zend_lookup_class(Z_STR_P(op_array->opcodes[opline_num-1].op2.zv) TSRMLS_CC)) != NULL) {
    1089           0 :                                 do_bind_inherited_class(op_array, &op_array->opcodes[opline_num], EG(class_table), ce, 0 TSRMLS_CC);
    1090             :                         }
    1091           0 :                         opline_num = op_array->opcodes[opline_num].result.opline_num;
    1092             :                 }
    1093           0 :                 CG(in_compilation) = orig_in_compilation;
    1094             :         }
    1095           0 : }
    1096             : /* }}} */
    1097             : 
    1098      207340 : ZEND_API zend_string *zend_mangle_property_name(const char *src1, size_t src1_length, const char *src2, size_t src2_length, int internal) /* {{{ */
    1099             : {
    1100      207340 :         size_t prop_name_length = 1 + src1_length + 1 + src2_length;
    1101      207340 :         zend_string *prop_name = zend_string_alloc(prop_name_length, internal);
    1102             : 
    1103      207340 :         prop_name->val[0] = '\0';
    1104      207340 :         memcpy(prop_name->val + 1, src1, src1_length+1);
    1105      207340 :         memcpy(prop_name->val + 1 + src1_length + 1, src2, src2_length+1);
    1106      207340 :         return prop_name;
    1107             : }
    1108             : /* }}} */
    1109             : 
    1110        2036 : static size_t zend_strnlen(const char* s, size_t maxlen) /* {{{ */
    1111             : {
    1112        2036 :         size_t len = 0;
    1113        2036 :         while (*s++ && maxlen--) len++;
    1114        2036 :         return len;
    1115             : }
    1116             : /* }}} */
    1117             : 
    1118        9035 : ZEND_API int zend_unmangle_property_name_ex(const zend_string *name, const char **class_name, const char **prop_name, size_t *prop_len) /* {{{ */
    1119             : {
    1120             :         size_t class_name_len;
    1121             : 
    1122        9035 :         *class_name = NULL;
    1123             : 
    1124        9035 :         if (name->val[0] != '\0') {
    1125        6999 :                 *prop_name = name->val;
    1126        6999 :                 if (prop_len) {
    1127         950 :                         *prop_len = name->len;
    1128             :                 }
    1129        6999 :                 return SUCCESS;
    1130             :         }
    1131        2036 :         if (name->len < 3 || name->val[1] == '\0') {
    1132           0 :                 zend_error(E_NOTICE, "Illegal member variable name");
    1133           0 :                 *prop_name = name->val;
    1134           0 :                 if (prop_len) {
    1135           0 :                         *prop_len = name->len;
    1136             :                 }
    1137           0 :                 return FAILURE;
    1138             :         }
    1139             : 
    1140        2036 :         class_name_len = zend_strnlen(name->val + 1, name->len - 2);
    1141        2036 :         if (class_name_len >= name->len - 2 || name->val[class_name_len + 1] != '\0') {
    1142           0 :                 zend_error(E_NOTICE, "Corrupt member variable name");
    1143           0 :                 *prop_name = name->val;
    1144           0 :                 if (prop_len) {
    1145           0 :                         *prop_len = name->len;
    1146             :                 }
    1147           0 :                 return FAILURE;
    1148             :         }
    1149             : 
    1150        2036 :         *class_name = name->val + 1;
    1151        2036 :         *prop_name = name->val + class_name_len + 2;
    1152        2036 :         if (prop_len) {
    1153         924 :                 *prop_len = name->len - class_name_len - 2;
    1154             :         }
    1155        2036 :         return SUCCESS;
    1156             : }
    1157             : /* }}} */
    1158             : 
    1159       20976 : static zend_constant *zend_lookup_reserved_const(const char *name, size_t len TSRMLS_DC) /* {{{ */
    1160             : {
    1161       20976 :         zend_constant *c = zend_hash_find_ptr_lc(EG(zend_constants), name, len);
    1162       20976 :         if (c && !(c->flags & CONST_CS) && (c->flags & CONST_CT_SUBST)) {
    1163       14791 :                 return c;
    1164             :         }
    1165        6185 :         return NULL;
    1166             : }
    1167             : /* }}} */
    1168             : 
    1169       77748 : static zend_bool zend_try_ct_eval_const(zval *zv, zend_string *name, zend_bool is_fully_qualified TSRMLS_DC) /* {{{ */
    1170             : {
    1171             :         zend_constant *c;
    1172             : 
    1173       77748 :         if (!(CG(compiler_options) & ZEND_COMPILE_NO_CONSTANT_SUBSTITUTION)) {
    1174             :                 /* Substitute case-sensitive (or lowercase) persistent constants */
    1175      155114 :                 c = zend_hash_find_ptr(EG(zend_constants), name);
    1176       77557 :                 if (c && (c->flags & CONST_PERSISTENT)) {
    1177       56932 :                         ZVAL_DUP(zv, &c->value);
    1178       56932 :                         return 1;
    1179             :                 }
    1180             :         }
    1181             : 
    1182             :         {
    1183             :                 /* Substitute true, false and null (including unqualified usage in namespaces) */
    1184       20816 :                 const char *lookup_name = name->val;
    1185       20816 :                 size_t lookup_len = name->len;
    1186             : 
    1187       20816 :                 if (!is_fully_qualified) {
    1188       20672 :                         zend_get_unqualified_name(name, &lookup_name, &lookup_len);
    1189             :                 }
    1190             : 
    1191       20816 :                 c = zend_lookup_reserved_const(lookup_name, lookup_len TSRMLS_CC);
    1192       20816 :                 if (c) {
    1193       14790 :                         ZVAL_DUP(zv, &c->value);
    1194       14790 :                         return 1;
    1195             :                 }
    1196             :         }
    1197             : 
    1198        6026 :         return 0;
    1199             : }
    1200             : /* }}} */
    1201             : 
    1202           0 : void zend_init_list(void *result, void *item TSRMLS_DC) /* {{{ */
    1203             : {
    1204           0 :         void** list = emalloc(sizeof(void*) * 2);
    1205             : 
    1206           0 :         list[0] = item;
    1207           0 :         list[1] = NULL;
    1208             : 
    1209           0 :         *(void**)result = list;
    1210           0 : }
    1211             : /* }}} */
    1212             : 
    1213          73 : void zend_add_to_list(void *result, void *item TSRMLS_DC) /* {{{ */
    1214             : {
    1215          73 :         void** list = *(void**)result;
    1216          73 :         size_t n = 0;
    1217             : 
    1218          73 :         if (list) {
    1219          54 :                 while (list[n]) {
    1220          22 :                         n++;
    1221             :                 }
    1222             :         }
    1223             : 
    1224          73 :         list = erealloc(list, sizeof(void*) * (n+2));
    1225             : 
    1226          73 :         list[n]   = item;
    1227          73 :         list[n+1] = NULL;
    1228             : 
    1229          73 :         *(void**)result = list;
    1230          73 : }
    1231             : /* }}} */
    1232             : 
    1233       37190 : void zend_do_extended_info(TSRMLS_D) /* {{{ */
    1234             : {
    1235             :         zend_op *opline;
    1236             : 
    1237       37190 :         if (!(CG(compiler_options) & ZEND_COMPILE_EXTENDED_INFO)) {
    1238       37190 :                 return;
    1239             :         }
    1240             : 
    1241           0 :         opline = get_next_op(CG(active_op_array) TSRMLS_CC);
    1242             : 
    1243           0 :         opline->opcode = ZEND_EXT_STMT;
    1244           0 :         SET_UNUSED(opline->op1);
    1245           0 :         SET_UNUSED(opline->op2);
    1246             : }
    1247             : /* }}} */
    1248             : 
    1249      318339 : void zend_do_extended_fcall_begin(TSRMLS_D) /* {{{ */
    1250             : {
    1251             :         zend_op *opline;
    1252             : 
    1253      318339 :         if (!(CG(compiler_options) & ZEND_COMPILE_EXTENDED_INFO)) {
    1254      318339 :                 return;
    1255             :         }
    1256             : 
    1257           0 :         opline = get_next_op(CG(active_op_array) TSRMLS_CC);
    1258             : 
    1259           0 :         opline->opcode = ZEND_EXT_FCALL_BEGIN;
    1260           0 :         SET_UNUSED(opline->op1);
    1261           0 :         SET_UNUSED(opline->op2);
    1262             : }
    1263             : /* }}} */
    1264             : 
    1265      318325 : void zend_do_extended_fcall_end(TSRMLS_D) /* {{{ */
    1266             : {
    1267             :         zend_op *opline;
    1268             : 
    1269      318325 :         if (!(CG(compiler_options) & ZEND_COMPILE_EXTENDED_INFO)) {
    1270      318325 :                 return;
    1271             :         }
    1272             : 
    1273           0 :         opline = get_next_op(CG(active_op_array) TSRMLS_CC);
    1274             : 
    1275           0 :         opline->opcode = ZEND_EXT_FCALL_END;
    1276           0 :         SET_UNUSED(opline->op1);
    1277           0 :         SET_UNUSED(opline->op2);
    1278             : }
    1279             : /* }}} */
    1280             : 
    1281      734219 : zend_bool zend_is_auto_global(zend_string *name TSRMLS_DC) /* {{{ */
    1282             : {
    1283             :         zend_auto_global *auto_global;
    1284             : 
    1285     1468438 :         if ((auto_global = zend_hash_find_ptr(CG(auto_globals), name)) != NULL) {
    1286       56739 :                 if (auto_global->armed) {
    1287       21832 :                         auto_global->armed = auto_global->auto_global_callback(auto_global->name TSRMLS_CC);
    1288             :                 }
    1289       56739 :                 return 1;
    1290             :         }
    1291      677480 :         return 0;
    1292             : }
    1293             : /* }}} */
    1294             : 
    1295      184563 : int zend_register_auto_global(zend_string *name, zend_bool jit, zend_auto_global_callback auto_global_callback TSRMLS_DC) /* {{{ */
    1296             : {
    1297             :         zend_auto_global auto_global;
    1298             :         int retval;
    1299             : 
    1300      184563 :         auto_global.name = zend_new_interned_string(name TSRMLS_CC);
    1301      184563 :         auto_global.auto_global_callback = auto_global_callback;
    1302      184563 :         auto_global.jit = jit;
    1303             : 
    1304      369126 :         retval = zend_hash_add_mem(CG(auto_globals), name, &auto_global, sizeof(zend_auto_global)) != NULL ? SUCCESS : FAILURE;
    1305             : 
    1306      184563 :         zend_string_release(auto_global.name);
    1307      184563 :         return retval;
    1308             : }
    1309             : /* }}} */
    1310             : 
    1311       20464 : ZEND_API void zend_activate_auto_globals(TSRMLS_D) /* {{{ */
    1312             : {
    1313             :         zend_auto_global *auto_global;
    1314             : 
    1315      388816 :         ZEND_HASH_FOREACH_PTR(CG(auto_globals), auto_global) {
    1316      184176 :                 if (auto_global->jit) {
    1317       81856 :                         auto_global->armed = 1;
    1318      102320 :                 } else if (auto_global->auto_global_callback) {
    1319       81856 :                         auto_global->armed = auto_global->auto_global_callback(auto_global->name TSRMLS_CC);
    1320             :                 } else {
    1321       20464 :                         auto_global->armed = 0;
    1322             :                 }
    1323             :         } ZEND_HASH_FOREACH_END();
    1324       20464 : }
    1325             : /* }}} */
    1326             : 
    1327     4893762 : int zendlex(zend_parser_stack_elem *elem TSRMLS_DC) /* {{{ */
    1328             : {
    1329             :         zval zv;
    1330             :         int retval;
    1331             : 
    1332     4893762 :         if (CG(increment_lineno)) {
    1333       25703 :                 CG(zend_lineno)++;
    1334       25703 :                 CG(increment_lineno) = 0;
    1335             :         }
    1336             : 
    1337             : again:
    1338     7093942 :         ZVAL_UNDEF(&zv);
    1339     7093942 :         retval = lex_scan(&zv TSRMLS_CC);
    1340     7093942 :         switch (retval) {
    1341             :                 case T_COMMENT:
    1342             :                 case T_DOC_COMMENT:
    1343             :                 case T_OPEN_TAG:
    1344             :                 case T_WHITESPACE:
    1345     2200180 :                         goto again;
    1346             : 
    1347             :                 case T_CLOSE_TAG:
    1348       26939 :                         if (LANG_SCNG(yy_text)[LANG_SCNG(yy_leng)-1] != '>') {
    1349       24228 :                                 CG(increment_lineno) = 1;
    1350             :                         }
    1351       26939 :                         retval = ';'; /* implicit ; */
    1352       26939 :                         break;
    1353             :                 case T_OPEN_TAG_WITH_ECHO:
    1354           3 :                         retval = T_ECHO;
    1355             :                         break;
    1356             :         }
    1357     4893762 :         if (Z_TYPE(zv) != IS_UNDEF) {
    1358     1726389 :                 elem->ast = zend_ast_create_zval(&zv);
    1359             :         }
    1360             : 
    1361     4893762 :         return retval;
    1362             : }
    1363             : /* }}} */
    1364             : 
    1365     3657514 : ZEND_API void zend_initialize_class_data(zend_class_entry *ce, zend_bool nullify_handlers TSRMLS_DC) /* {{{ */
    1366             : {
    1367     3657514 :         zend_bool persistent_hashes = (ce->type == ZEND_INTERNAL_CLASS) ? 1 : 0;
    1368     3657514 :         dtor_func_t zval_ptr_dtor_func = ((persistent_hashes) ? ZVAL_INTERNAL_PTR_DTOR : ZVAL_PTR_DTOR);
    1369             : 
    1370     3657514 :         ce->refcount = 1;
    1371     3657514 :         ce->ce_flags = ZEND_ACC_CONSTANTS_UPDATED;
    1372             : 
    1373     3657514 :         ce->default_properties_table = NULL;
    1374     3657514 :         ce->default_static_members_table = NULL;
    1375     3657514 :         zend_hash_init_ex(&ce->properties_info, 8, NULL, (persistent_hashes ? zend_destroy_property_info_internal : zend_destroy_property_info), persistent_hashes, 0);
    1376     3657514 :         zend_hash_init_ex(&ce->constants_table, 8, NULL, zval_ptr_dtor_func, persistent_hashes, 0);
    1377     3657514 :         zend_hash_init_ex(&ce->function_table, 8, NULL, ZEND_FUNCTION_DTOR, persistent_hashes, 0);
    1378             : 
    1379     3657514 :         if (ce->type == ZEND_INTERNAL_CLASS) {
    1380             : #ifdef ZTS
    1381             :                 int n = zend_hash_num_elements(CG(class_table));
    1382             : 
    1383             :                 if (CG(static_members_table) && n >= CG(last_static_member)) {
    1384             :                         /* Support for run-time declaration: dl() */
    1385             :                         CG(last_static_member) = n+1;
    1386             :                         CG(static_members_table) = realloc(CG(static_members_table), (n+1)*sizeof(zval*));
    1387             :                         CG(static_members_table)[n] = NULL;
    1388             :                 }
    1389             :                 ce->static_members_table = (zval*)(zend_intptr_t)n;
    1390             : #else
    1391     3650246 :                 ce->static_members_table = NULL;
    1392             : #endif
    1393             :         } else {
    1394        7268 :                 ce->static_members_table = ce->default_static_members_table;
    1395        7268 :                 ce->info.user.doc_comment = NULL;
    1396             :         }
    1397             : 
    1398     3657514 :         ce->default_properties_count = 0;
    1399     3657514 :         ce->default_static_members_count = 0;
    1400             : 
    1401     3657514 :         if (nullify_handlers) {
    1402        7268 :                 ce->constructor = NULL;
    1403        7268 :                 ce->destructor = NULL;
    1404        7268 :                 ce->clone = NULL;
    1405        7268 :                 ce->__get = NULL;
    1406        7268 :                 ce->__set = NULL;
    1407        7268 :                 ce->__unset = NULL;
    1408        7268 :                 ce->__isset = NULL;
    1409        7268 :                 ce->__call = NULL;
    1410        7268 :                 ce->__callstatic = NULL;
    1411        7268 :                 ce->__tostring = NULL;
    1412        7268 :                 ce->create_object = NULL;
    1413        7268 :                 ce->get_iterator = NULL;
    1414        7268 :                 ce->iterator_funcs.funcs = NULL;
    1415        7268 :                 ce->interface_gets_implemented = NULL;
    1416        7268 :                 ce->get_static_method = NULL;
    1417        7268 :                 ce->parent = NULL;
    1418        7268 :                 ce->num_interfaces = 0;
    1419        7268 :                 ce->interfaces = NULL;
    1420        7268 :                 ce->num_traits = 0;
    1421        7268 :                 ce->traits = NULL;
    1422        7268 :                 ce->trait_aliases = NULL;
    1423        7268 :                 ce->trait_precedences = NULL;
    1424        7268 :                 ce->serialize = NULL;
    1425        7268 :                 ce->unserialize = NULL;
    1426        7268 :                 ce->serialize_func = NULL;
    1427        7268 :                 ce->unserialize_func = NULL;
    1428        7268 :                 ce->__debugInfo = NULL;
    1429        7268 :                 if (ce->type == ZEND_INTERNAL_CLASS) {
    1430           0 :                         ce->info.internal.module = NULL;
    1431           0 :                         ce->info.internal.builtin_functions = NULL;
    1432             :                 }
    1433             :         }
    1434     3657514 : }
    1435             : /* }}} */
    1436             : 
    1437      142351 : uint32_t zend_get_class_fetch_type(zend_string *name) /* {{{ */ 
    1438             : {
    1439      142351 :         if (zend_string_equals_literal_ci(name, "self")) {
    1440        6406 :                 return ZEND_FETCH_CLASS_SELF;
    1441      135945 :         } else if (zend_string_equals_literal_ci(name, "parent")) {
    1442        4405 :                 return ZEND_FETCH_CLASS_PARENT;
    1443      131540 :         } else if (zend_string_equals_literal_ci(name, "static")) {
    1444         121 :                 return ZEND_FETCH_CLASS_STATIC;
    1445             :         } else {
    1446      131419 :                 return ZEND_FETCH_CLASS_DEFAULT;
    1447             :         }
    1448             : }
    1449             : /* }}} */
    1450             : 
    1451           0 : ZEND_API zend_string *zend_get_compiled_variable_name(const zend_op_array *op_array, uint32_t var) /* {{{ */
    1452             : {
    1453           0 :         return op_array->vars[EX_VAR_TO_NUM(var)];
    1454             : }
    1455             : /* }}} */
    1456             : 
    1457         382 : zend_ast *zend_ast_append_str(zend_ast *left_ast, zend_ast *right_ast) /* {{{ */
    1458             : {
    1459         382 :         zval *left_zv = zend_ast_get_zval(left_ast);
    1460         382 :         zend_string *left = Z_STR_P(left_zv);
    1461         382 :         zend_string *right = zend_ast_get_str(right_ast);
    1462             : 
    1463             :         zend_string *result;
    1464         382 :         size_t left_len = left->len;
    1465         382 :         size_t len = left_len + right->len + 1; /* left\right */
    1466             : 
    1467         382 :         result = zend_string_realloc(left, len, 0);
    1468         382 :         result->val[left_len] = '\\';
    1469         382 :         memcpy(&result->val[left_len + 1], right->val, right->len);
    1470         382 :         result->val[len] = '\0';
    1471             :         zend_string_release(right);
    1472             : 
    1473         382 :         ZVAL_STR(left_zv, result);
    1474         382 :         return left_ast;
    1475             : }
    1476             : /* }}} */
    1477             : 
    1478             : /* A hacky way that is used to store the doc comment for properties */
    1479        2314 : zend_ast *zend_ast_append_doc_comment(zend_ast *list TSRMLS_DC) /* {{{ */
    1480             : {
    1481        2314 :         if (CG(doc_comment)) {
    1482         102 :                 list = zend_ast_list_add(list, zend_ast_create_zval_from_str(CG(doc_comment)));
    1483          51 :                 CG(doc_comment) = NULL;
    1484             :         }
    1485             : 
    1486        2314 :         return list;
    1487             : }
    1488             : /* }}} */
    1489             : 
    1490      188344 : void zend_verify_namespace(TSRMLS_D) /* {{{ */
    1491             : {
    1492      188344 :         if (CG(has_bracketed_namespaces) && !CG(in_namespace)) {
    1493           1 :                 zend_error_noreturn(E_COMPILE_ERROR, "No code may exist outside of namespace {}");
    1494             :         }
    1495      188343 : }
    1496             : /* }}} */
    1497             : 
    1498       29696 : static void zend_reset_import_tables(TSRMLS_D) /* {{{ */
    1499             : {
    1500       29696 :         if (CG(current_import)) {
    1501          34 :                 zend_hash_destroy(CG(current_import));
    1502          34 :                 efree(CG(current_import));
    1503          34 :                 CG(current_import) = NULL;
    1504             :         }
    1505             : 
    1506       29696 :         if (CG(current_import_function)) {
    1507          11 :                 zend_hash_destroy(CG(current_import_function));
    1508          11 :                 efree(CG(current_import_function));
    1509          11 :                 CG(current_import_function) = NULL;
    1510             :         }
    1511             : 
    1512       29696 :         if (CG(current_import_const)) {
    1513           9 :                 zend_hash_destroy(CG(current_import_const));
    1514           9 :                 efree(CG(current_import_const));
    1515           9 :                 CG(current_import_const) = NULL;
    1516             :         }
    1517       29696 : }
    1518             : /* }}} */
    1519             : 
    1520       29501 : static void zend_end_namespace(TSRMLS_D) /* {{{ */ {
    1521       29501 :         CG(in_namespace) = 0;
    1522       29501 :         zend_reset_import_tables(TSRMLS_C);
    1523       29501 :         if (CG(current_namespace)) {
    1524         149 :                 zend_string_release(CG(current_namespace));
    1525         149 :                 CG(current_namespace) = NULL;
    1526             :         }
    1527       29501 : }
    1528             : /* }}} */
    1529             : 
    1530       29446 : void zend_do_end_compilation(TSRMLS_D) /* {{{ */
    1531             : {
    1532       29446 :         CG(has_bracketed_namespaces) = 0;
    1533       29446 :         zend_end_namespace(TSRMLS_C);
    1534       29446 : }
    1535             : /* }}} */
    1536             : 
    1537             : /* {{{ zend_dirname
    1538             :    Returns directory name component of path */
    1539       24963 : ZEND_API size_t zend_dirname(char *path, size_t len)
    1540             : {
    1541       24963 :         register char *end = path + len - 1;
    1542       24963 :         unsigned int len_adjust = 0;
    1543             : 
    1544             : #ifdef PHP_WIN32
    1545             :         /* Note that on Win32 CWD is per drive (heritage from CP/M).
    1546             :          * This means dirname("c:foo") maps to "c:." or "c:" - which means CWD on C: drive.
    1547             :          */
    1548             :         if ((2 <= len) && isalpha((int)((unsigned char *)path)[0]) && (':' == path[1])) {
    1549             :                 /* Skip over the drive spec (if any) so as not to change */
    1550             :                 path += 2;
    1551             :                 len_adjust += 2;
    1552             :                 if (2 == len) {
    1553             :                         /* Return "c:" on Win32 for dirname("c:").
    1554             :                          * It would be more consistent to return "c:."
    1555             :                          * but that would require making the string *longer*.
    1556             :                          */
    1557             :                         return len;
    1558             :                 }
    1559             :         }
    1560             : #elif defined(NETWARE)
    1561             :         /*
    1562             :          * Find the first occurrence of : from the left
    1563             :          * move the path pointer to the position just after :
    1564             :          * increment the len_adjust to the length of path till colon character(inclusive)
    1565             :          * If there is no character beyond : simple return len
    1566             :          */
    1567             :         char *colonpos = NULL;
    1568             :         colonpos = strchr(path, ':');
    1569             :         if (colonpos != NULL) {
    1570             :                 len_adjust = ((colonpos - path) + 1);
    1571             :                 path += len_adjust;
    1572             :                 if (len_adjust == len) {
    1573             :                         return len;
    1574             :                 }
    1575             :         }
    1576             : #endif
    1577             : 
    1578       24963 :         if (len == 0) {
    1579             :                 /* Illegal use of this function */
    1580          36 :                 return 0;
    1581             :         }
    1582             : 
    1583             :         /* Strip trailing slashes */
    1584       49945 :         while (end >= path && IS_SLASH_P(end)) {
    1585          91 :                 end--;
    1586             :         }
    1587       24927 :         if (end < path) {
    1588             :                 /* The path only contained slashes */
    1589          11 :                 path[0] = DEFAULT_SLASH;
    1590          11 :                 path[1] = '\0';
    1591          11 :                 return 1 + len_adjust;
    1592             :         }
    1593             : 
    1594             :         /* Strip filename */
    1595      573513 :         while (end >= path && !IS_SLASH_P(end)) {
    1596      523681 :                 end--;
    1597             :         }
    1598       24916 :         if (end < path) {
    1599             :                 /* No slash found, therefore return '.' */
    1600             : #ifdef NETWARE
    1601             :                 if (len_adjust == 0) {
    1602             :                         path[0] = '.';
    1603             :                         path[1] = '\0';
    1604             :                         return 1; /* only one character */
    1605             :                 } else {
    1606             :                         path[0] = '\0';
    1607             :                         return len_adjust;
    1608             :                 }
    1609             : #else
    1610         173 :                 path[0] = '.';
    1611         173 :                 path[1] = '\0';
    1612         173 :                 return 1 + len_adjust;
    1613             : #endif
    1614             :         }
    1615             : 
    1616             :         /* Strip slashes which came before the file name */
    1617       74244 :         while (end >= path && IS_SLASH_P(end)) {
    1618       24758 :                 end--;
    1619             :         }
    1620       24743 :         if (end < path) {
    1621          23 :                 path[0] = DEFAULT_SLASH;
    1622          23 :                 path[1] = '\0';
    1623          23 :                 return 1 + len_adjust;
    1624             :         }
    1625       24720 :         *(end+1) = '\0';
    1626             : 
    1627       24720 :         return (size_t)(end + 1 - path) + len_adjust;
    1628             : }
    1629             : /* }}} */
    1630             : 
    1631       16844 : static inline zend_bool zend_string_equals_str_ci(zend_string *str1, zend_string *str2) /* {{{ */
    1632             : {
    1633       19281 :         return str1->len == str2->len
    1634       19281 :                 && !zend_binary_strcasecmp(str1->val, str1->len, str2->val, str2->len);
    1635             : }
    1636             : /* }}} */
    1637             : 
    1638      132544 : static void zend_adjust_for_fetch_type(zend_op *opline, uint32_t type) /* {{{ */ 
    1639             : {
    1640      132544 :         switch (type & BP_VAR_MASK) {
    1641             :                 case BP_VAR_R:
    1642       54558 :                         return;
    1643             :                 case BP_VAR_W:
    1644             :                 case BP_VAR_REF:
    1645       69344 :                         opline->opcode += 3;
    1646       69344 :                         return;
    1647             :                 case BP_VAR_RW:
    1648        1102 :                         opline->opcode += 6;
    1649        1102 :                         return;
    1650             :                 case BP_VAR_IS:
    1651        5041 :                         opline->opcode += 9;
    1652        5041 :                         return;
    1653             :                 case BP_VAR_FUNC_ARG:
    1654        2432 :                         opline->opcode += 12;
    1655        2432 :                         opline->extended_value |= type >> BP_VAR_SHIFT;
    1656        2432 :                         return;
    1657             :                 case BP_VAR_UNSET:
    1658          67 :                         opline->opcode += 15;
    1659          67 :                         return;
    1660             :                 EMPTY_SWITCH_DEFAULT_CASE()
    1661             :         }
    1662             : }
    1663             : /* }}} */
    1664             : 
    1665      668012 : static inline void zend_make_var_result(znode *result, zend_op *opline TSRMLS_DC) /* {{{ */ 
    1666             : {
    1667      668012 :         opline->result_type = IS_VAR;
    1668      668012 :         opline->result.var = get_temporary_variable(CG(active_op_array));
    1669      668012 :         GET_NODE(result, opline->result);
    1670      668012 : }
    1671             : /* }}} */
    1672             : 
    1673      185309 : static inline void zend_make_tmp_result(znode *result, zend_op *opline TSRMLS_DC) /* {{{ */
    1674             : {
    1675      185309 :         opline->result_type = IS_TMP_VAR;
    1676      185309 :         opline->result.var = get_temporary_variable(CG(active_op_array));
    1677      185309 :         GET_NODE(result, opline->result);
    1678      185309 : }
    1679             : /* }}} */
    1680             : 
    1681     1325989 : static zend_op *zend_emit_op(znode *result, zend_uchar opcode, znode *op1, znode *op2 TSRMLS_DC) /* {{{ */ 
    1682             : {
    1683     1325989 :         zend_op *opline = get_next_op(CG(active_op_array) TSRMLS_CC);
    1684     1325989 :         opline->opcode = opcode;
    1685             : 
    1686     1325989 :         if (op1 == NULL) {
    1687      730887 :                 SET_UNUSED(opline->op1);
    1688             :         } else {
    1689      595102 :                 SET_NODE(opline->op1, op1);
    1690             :         }
    1691             : 
    1692     1325989 :         if (op2 == NULL) {
    1693      839050 :                 SET_UNUSED(opline->op2);
    1694             :         } else {
    1695      486939 :                 SET_NODE(opline->op2, op2);
    1696             :         }
    1697             : 
    1698     1325989 :         if (result) {
    1699      528504 :                 zend_make_var_result(result, opline TSRMLS_CC);
    1700             :         }
    1701     1325989 :         return opline;
    1702             : }
    1703             : /* }}} */
    1704             : 
    1705      180778 : static zend_op *zend_emit_op_tmp(znode *result, zend_uchar opcode, znode *op1, znode *op2 TSRMLS_DC) /* {{{ */
    1706             : {
    1707      180778 :         zend_op *opline = get_next_op(CG(active_op_array) TSRMLS_CC);
    1708      180778 :         opline->opcode = opcode;
    1709             : 
    1710      180778 :         if (op1 == NULL) {
    1711       20306 :                 SET_UNUSED(opline->op1);
    1712             :         } else {
    1713      160472 :                 SET_NODE(opline->op1, op1);
    1714             :         }
    1715             : 
    1716      180778 :         if (op2 == NULL) {
    1717       94912 :                 SET_UNUSED(opline->op2);
    1718             :         } else {
    1719       85866 :                 SET_NODE(opline->op2, op2);
    1720             :         }
    1721             : 
    1722      180778 :         if (result) {
    1723      180613 :                 zend_make_tmp_result(result, opline TSRMLS_CC);
    1724             :         }
    1725             : 
    1726      180778 :         return opline;
    1727             : }
    1728             : /* }}} */
    1729             : 
    1730          29 : static void zend_emit_tick(TSRMLS_D) /* {{{ */
    1731             : {
    1732          29 :         zend_op *opline = get_next_op(CG(active_op_array) TSRMLS_CC);
    1733             : 
    1734          29 :         opline->opcode = ZEND_TICKS;
    1735          29 :         SET_UNUSED(opline->op1);
    1736          29 :         SET_UNUSED(opline->op2);
    1737          29 :         opline->extended_value = Z_LVAL(CG(declarables).ticks);
    1738          29 : }
    1739             : /* }}} */
    1740             : 
    1741        8647 : static inline zend_op *zend_emit_op_data(znode *value TSRMLS_DC) /* {{{ */
    1742             : {
    1743        8647 :         return zend_emit_op(NULL, ZEND_OP_DATA, value, NULL TSRMLS_CC);
    1744             : }
    1745             : /* }}} */
    1746             : 
    1747       61927 : static inline uint32_t zend_emit_jump(uint32_t opnum_target TSRMLS_DC) /* {{{ */
    1748             : {
    1749       61927 :         uint32_t opnum = get_next_op_number(CG(active_op_array));
    1750       61927 :         zend_op *opline = zend_emit_op(NULL, ZEND_JMP, NULL, NULL TSRMLS_CC);
    1751       61927 :         opline->op1.opline_num = opnum_target;
    1752       61927 :         return opnum;
    1753             : }
    1754             : /* }}} */
    1755             : 
    1756      103264 : static inline uint32_t zend_emit_cond_jump(zend_uchar opcode, znode *cond, uint32_t opnum_target TSRMLS_DC) /* {{{ */
    1757             : {
    1758      103264 :         uint32_t opnum = get_next_op_number(CG(active_op_array));
    1759      103264 :         zend_op *opline = zend_emit_op(NULL, opcode, cond, NULL TSRMLS_CC);
    1760      103264 :         opline->op2.opline_num = opnum_target;
    1761      103264 :         return opnum;
    1762             : }
    1763             : /* }}} */
    1764             : 
    1765      163156 : static inline void zend_update_jump_target(uint32_t opnum_jump, uint32_t opnum_target TSRMLS_DC) /* {{{ */
    1766             : {
    1767      163156 :         zend_op *opline = &CG(active_op_array)->opcodes[opnum_jump];
    1768      163156 :         switch (opline->opcode) {
    1769             :                 case ZEND_JMP:
    1770       48397 :                         opline->op1.opline_num = opnum_target;
    1771       48397 :                         break;
    1772             :                 case ZEND_JMPZ:
    1773             :                 case ZEND_JMPNZ:
    1774             :                 case ZEND_JMPZ_EX:
    1775             :                 case ZEND_JMPNZ_EX:
    1776      114759 :                         opline->op2.opline_num = opnum_target;
    1777             :                         break;
    1778             :                 EMPTY_SWITCH_DEFAULT_CASE()
    1779             :         }
    1780      163156 : }
    1781             : /* }}} */
    1782             : 
    1783      163156 : static inline void zend_update_jump_target_to_next(uint32_t opnum_jump TSRMLS_DC) /* {{{ */ 
    1784             : {
    1785      163156 :         zend_update_jump_target(opnum_jump, get_next_op_number(CG(active_op_array)) TSRMLS_CC);
    1786      163156 : }
    1787             : /* }}} */
    1788             : 
    1789      132600 : static inline zend_op *zend_delayed_emit_op(znode *result, zend_uchar opcode, znode *op1, znode *op2 TSRMLS_DC) /* {{{ */
    1790             : {
    1791             :         zend_op tmp_opline;
    1792      132600 :         init_op(&tmp_opline TSRMLS_CC);
    1793      132600 :         tmp_opline.opcode = opcode;
    1794      132600 :         SET_NODE(tmp_opline.op1, op1);
    1795      132600 :         SET_NODE(tmp_opline.op2, op2);
    1796      132600 :         if (result) {
    1797      132243 :                 zend_make_var_result(result, &tmp_opline TSRMLS_CC);
    1798             :         }
    1799             : 
    1800      132600 :         zend_stack_push(&CG(delayed_oplines_stack), &tmp_opline);
    1801      132600 :         return zend_stack_top(&CG(delayed_oplines_stack));
    1802             : }
    1803             : /* }}} */
    1804             : 
    1805      127632 : static inline uint32_t zend_delayed_compile_begin(TSRMLS_D) /* {{{ */
    1806             : {
    1807      127632 :         return zend_stack_count(&CG(delayed_oplines_stack));
    1808             : }
    1809             : /* }}} */
    1810             : 
    1811      127622 : static zend_op *zend_delayed_compile_end(uint32_t offset TSRMLS_DC) /* {{{ */
    1812             : {
    1813      127622 :         zend_op *opline, *oplines = zend_stack_base(&CG(delayed_oplines_stack));
    1814      127622 :         uint32_t i, count = zend_stack_count(&CG(delayed_oplines_stack));
    1815             : 
    1816             :         ZEND_ASSERT(count > offset);
    1817      260221 :         for (i = offset; i < count; ++i) {
    1818      132599 :                 opline = get_next_op(CG(active_op_array) TSRMLS_CC);
    1819      132599 :                 memcpy(opline, &oplines[i], sizeof(zend_op));
    1820             :         }
    1821      127622 :         CG(delayed_oplines_stack).top = offset;
    1822      127622 :         return opline;
    1823             : }
    1824             : /* }}} */
    1825             : 
    1826       64713 : void zend_emit_final_return(zval *zv TSRMLS_DC) /* {{{ */
    1827             : {
    1828             :         znode zn;
    1829       64713 :         zend_bool returns_reference = (CG(active_op_array)->fn_flags & ZEND_ACC_RETURN_REFERENCE) != 0;
    1830             : 
    1831       64713 :         zn.op_type = IS_CONST;
    1832       64713 :         if (zv) {
    1833       28365 :                 ZVAL_COPY_VALUE(&zn.u.constant, zv);
    1834             :         } else {
    1835       36348 :                 ZVAL_NULL(&zn.u.constant);
    1836             :         }
    1837             : 
    1838       64713 :         zend_emit_op(NULL, returns_reference ? ZEND_RETURN_BY_REF : ZEND_RETURN, &zn, NULL TSRMLS_CC);
    1839       64713 : }
    1840             : /* }}} */
    1841             : 
    1842      570170 : static inline zend_bool zend_is_variable(zend_ast *ast) /* {{{ */
    1843             : {
    1844     2242801 :         return ast->kind == ZEND_AST_VAR || ast->kind == ZEND_AST_DIM
    1845      652032 :                 || ast->kind == ZEND_AST_PROP || ast->kind == ZEND_AST_STATIC_PROP
    1846      557704 :                 || ast->kind == ZEND_AST_CALL || ast->kind == ZEND_AST_METHOD_CALL
    1847      462895 :                 || ast->kind == ZEND_AST_STATIC_CALL;
    1848             : }
    1849             : /* }}} */
    1850             : 
    1851      455922 : static inline zend_bool zend_is_call(zend_ast *ast) /* {{{ */
    1852             : {
    1853     1259352 :         return ast->kind == ZEND_AST_CALL
    1854      455922 :                 || ast->kind == ZEND_AST_METHOD_CALL
    1855      803430 :                 || ast->kind == ZEND_AST_STATIC_CALL;
    1856             : }
    1857             : /* }}} */
    1858             : 
    1859          38 : static inline zend_bool zend_is_unticked_stmt(zend_ast *ast) /* {{{ */
    1860             : {
    1861          38 :         return ast->kind == ZEND_AST_STMT_LIST || ast->kind == ZEND_AST_LABEL;
    1862             : }
    1863             : /* }}} */
    1864             : 
    1865        8059 : static inline zend_bool zend_can_write_to_variable(zend_ast *ast) /* {{{ */
    1866             : {
    1867       18177 :         while (ast->kind == ZEND_AST_DIM || ast->kind == ZEND_AST_PROP) {
    1868        2059 :                 ast = ast->child[0];
    1869             :         }
    1870             : 
    1871        8059 :         return zend_is_variable(ast);
    1872             : }
    1873             : /* }}} */
    1874             : 
    1875       38575 : static inline zend_bool zend_is_const_default_class_ref(zend_ast *name_ast) /* {{{ */
    1876             : {
    1877             :         zend_string *name;
    1878             : 
    1879       38575 :         if (name_ast->kind != ZEND_AST_ZVAL) {
    1880        1190 :                 return 0;
    1881             :         }
    1882             : 
    1883             :         /* Fully qualified names are always default refs */
    1884       37385 :         if (!name_ast->attr) {
    1885         145 :                 return 1;
    1886             :         }
    1887             : 
    1888       37240 :         name = zend_ast_get_str(name_ast);
    1889       37240 :         return ZEND_FETCH_CLASS_DEFAULT == zend_get_class_fetch_type(name);
    1890             : }
    1891             : /* }}} */
    1892             : 
    1893      133382 : static inline void zend_handle_numeric_op(znode *node TSRMLS_DC) /* {{{ */
    1894             : {
    1895      258222 :         if (node->op_type == IS_CONST && Z_TYPE(node->u.constant) == IS_STRING) {
    1896             :                 zend_ulong index;
    1897             : 
    1898       92550 :                 if (ZEND_HANDLE_NUMERIC(Z_STR(node->u.constant), index)) {
    1899          57 :                         zval_ptr_dtor(&node->u.constant);
    1900          57 :                         ZVAL_LONG(&node->u.constant, index);
    1901             :                 }
    1902             :         }
    1903      133382 : }
    1904             : /* }}} */
    1905             : 
    1906       18915 : static inline void zend_set_class_name_op1(zend_op *opline, znode *class_node TSRMLS_DC) /* {{{ */
    1907             : {
    1908       18915 :         if (class_node->op_type == IS_CONST) {
    1909       13929 :                 opline->op1_type = IS_CONST;
    1910       13929 :                 opline->op1.constant = zend_add_class_name_literal(
    1911             :                         CG(active_op_array), Z_STR(class_node->u.constant) TSRMLS_CC);
    1912             :         } else {
    1913        4986 :                 SET_NODE(opline->op1, class_node);
    1914             :         }
    1915       18915 : }
    1916             : /* }}} */
    1917             : 
    1918        8921 : static zend_op *zend_compile_class_ref(znode *result, zend_ast *name_ast TSRMLS_DC) /* {{{ */
    1919             : {
    1920             :         zend_op *opline;
    1921             :         znode name_node;
    1922        8921 :         zend_compile_expr(&name_node, name_ast TSRMLS_CC);
    1923             : 
    1924        8921 :         if (name_node.op_type == IS_CONST) {
    1925        7732 :                 zend_string *name = Z_STR(name_node.u.constant);
    1926        7732 :                 uint32_t fetch_type = zend_get_class_fetch_type(name);
    1927             : 
    1928        7732 :                 opline = zend_emit_op(result, ZEND_FETCH_CLASS, NULL, NULL TSRMLS_CC);
    1929        7732 :                 opline->extended_value = fetch_type;
    1930             : 
    1931        7732 :                 if (fetch_type == ZEND_FETCH_CLASS_DEFAULT) {
    1932        2322 :                         uint32_t type = name_ast->kind == ZEND_AST_ZVAL ? name_ast->attr : ZEND_NAME_FQ;
    1933        2322 :                         opline->op2_type = IS_CONST;
    1934        2322 :                         opline->op2.constant = zend_add_class_name_literal(CG(active_op_array),
    1935             :                                 zend_resolve_class_name(name, type TSRMLS_CC) TSRMLS_CC);
    1936             :                 }
    1937             : 
    1938             :                 zend_string_release(name);
    1939             :         } else {
    1940        1189 :                 opline = zend_emit_op(result, ZEND_FETCH_CLASS, NULL, &name_node TSRMLS_CC);
    1941        1189 :                 opline->extended_value = ZEND_FETCH_CLASS_DEFAULT;
    1942             :         }
    1943             : 
    1944        8921 :         return opline;
    1945             : }
    1946             : /* }}} */
    1947             : 
    1948      610955 : static int zend_try_compile_cv(znode *result, zend_ast *ast TSRMLS_DC) /* {{{ */ 
    1949             : {
    1950      610955 :         zend_ast *name_ast = ast->child[0];
    1951      610955 :         if (name_ast->kind == ZEND_AST_ZVAL) {
    1952      610772 :                 zend_string *name = zval_get_string(zend_ast_get_zval(name_ast));
    1953             : 
    1954      610772 :                 if (zend_is_auto_global(name TSRMLS_CC)) {
    1955             :                         zend_string_release(name);
    1956       17694 :                         return FAILURE;
    1957             :                 }
    1958             : 
    1959      593078 :                 result->op_type = IS_CV;
    1960      593078 :                 result->u.op.var = lookup_cv(CG(active_op_array), name TSRMLS_CC);
    1961             : 
    1962      593078 :                 if (zend_string_equals_literal(name, "this")) {
    1963         324 :                         CG(active_op_array)->this_var = result->u.op.var;
    1964             :                 }
    1965      593078 :                 return SUCCESS;
    1966             :         }
    1967             : 
    1968         183 :         return FAILURE;
    1969             : }
    1970             : /* }}} */
    1971             : 
    1972       19401 : static zend_op *zend_compile_simple_var_no_cv(znode *result, zend_ast *ast, uint32_t type TSRMLS_DC) /* {{{ */
    1973             : {
    1974       19401 :         zend_ast *name_ast = ast->child[0];
    1975             :         znode name_node;
    1976             :         zend_op *opline;
    1977             : 
    1978             :         /* there is a chance someone is accessing $this */
    1979       40264 :         if (ast->kind != ZEND_AST_ZVAL
    1980       40264 :                 && CG(active_op_array)->scope && CG(active_op_array)->this_var == -1
    1981             :         ) {
    1982         288 :                 zend_string *key = zend_string_init("this", sizeof("this") - 1, 0);
    1983         288 :                 CG(active_op_array)->this_var = lookup_cv(CG(active_op_array), key TSRMLS_CC);
    1984             :         }
    1985             : 
    1986       19401 :         zend_compile_expr(&name_node, name_ast TSRMLS_CC);
    1987             : 
    1988       19401 :         opline = zend_emit_op(result, ZEND_FETCH_R, &name_node, NULL TSRMLS_CC);
    1989             : 
    1990       19401 :         opline->extended_value = ZEND_FETCH_LOCAL;
    1991       19401 :         if (name_node.op_type == IS_CONST) {
    1992       19220 :                 if (zend_is_auto_global(Z_STR(name_node.u.constant) TSRMLS_CC)) {
    1993       17694 :                         opline->extended_value = ZEND_FETCH_GLOBAL;
    1994             :                 }
    1995             :         }
    1996             : 
    1997       19401 :         return opline;
    1998             : }
    1999             : /* }}} */
    2000             : 
    2001      601357 : static void zend_compile_simple_var(znode *result, zend_ast *ast, uint32_t type TSRMLS_DC) /* {{{ */
    2002             : {
    2003      601357 :         if (zend_try_compile_cv(result, ast TSRMLS_CC) == FAILURE) {
    2004       17845 :                 zend_op *opline = zend_compile_simple_var_no_cv(result, ast, type TSRMLS_CC);
    2005       17845 :                 zend_adjust_for_fetch_type(opline, type);
    2006             :         }
    2007      601357 : }
    2008             : /* }}} */
    2009             : 
    2010      129437 : static void zend_separate_if_call_and_write(znode *node, zend_ast *ast, uint32_t type TSRMLS_DC) /* {{{ */
    2011             : {
    2012      129437 :         if (type != BP_VAR_R && type != BP_VAR_IS && zend_is_call(ast)) {
    2013          48 :                 if (node->op_type == IS_VAR) {
    2014          47 :                         zend_op *opline = zend_emit_op(NULL, ZEND_SEPARATE, node, NULL TSRMLS_CC);
    2015          47 :                         opline->result_type = IS_VAR;
    2016          47 :                         opline->result.var = opline->op1.var;
    2017             :                 } else {
    2018           1 :                         zend_error_noreturn(E_COMPILE_ERROR, "Cannot use result of built-in function in write context");
    2019             :                 }
    2020             :         }
    2021      129436 : }
    2022             : /* }}} */
    2023             : 
    2024             : void zend_delayed_compile_var(znode *result, zend_ast *ast, uint32_t type TSRMLS_DC);
    2025             : void zend_compile_assign(znode *result, zend_ast *ast TSRMLS_DC);
    2026             : static void zend_compile_list_assign(znode *result, zend_ast *ast, znode *expr_node TSRMLS_DC);
    2027             : 
    2028       14811 : static inline void zend_emit_assign_znode(zend_ast *var_ast, znode *value_node TSRMLS_DC) /* {{{ */
    2029             : {
    2030             :         znode dummy_node;
    2031       14811 :         if (var_ast->kind == ZEND_AST_LIST) {
    2032          23 :                 zend_compile_list_assign(&dummy_node, var_ast, value_node TSRMLS_CC);
    2033             :         } else {
    2034       14788 :                 zend_ast *assign_ast = zend_ast_create(ZEND_AST_ASSIGN, var_ast,
    2035       14788 :                         zend_ast_create_znode(value_node));
    2036       14788 :                 zend_compile_assign(&dummy_node, assign_ast TSRMLS_CC);
    2037             :         }
    2038       14810 :         zend_do_free(&dummy_node TSRMLS_CC);
    2039       14810 : }
    2040             : /* }}} */
    2041             : 
    2042      122594 : static zend_op *zend_delayed_compile_dim(znode *result, zend_ast *ast, uint32_t type TSRMLS_DC) /* {{{ */
    2043             : {
    2044      122594 :         zend_ast *var_ast = ast->child[0];
    2045      122594 :         zend_ast *dim_ast = ast->child[1];
    2046             : 
    2047             :         znode var_node, dim_node;
    2048             : 
    2049      122594 :         zend_delayed_compile_var(&var_node, var_ast, type TSRMLS_CC);
    2050      122592 :         zend_separate_if_call_and_write(&var_node, var_ast, type TSRMLS_CC);
    2051             : 
    2052      122591 :         if (dim_ast == NULL) {
    2053         420 :                 if (type == BP_VAR_R || type == BP_VAR_IS) {
    2054           7 :                         zend_error_noreturn(E_COMPILE_ERROR, "Cannot use [] for reading");
    2055             :                 }
    2056         413 :                 if (type == BP_VAR_UNSET) {
    2057           1 :                         zend_error_noreturn(E_COMPILE_ERROR, "Cannot use [] for unsetting");
    2058             :                 }
    2059         412 :                 dim_node.op_type = IS_UNUSED;
    2060             :         } else {
    2061      122171 :                 zend_compile_expr(&dim_node, dim_ast TSRMLS_CC);
    2062      122171 :                 zend_handle_numeric_op(&dim_node TSRMLS_CC);
    2063             :         }
    2064             : 
    2065      122583 :         return zend_delayed_emit_op(result, ZEND_FETCH_DIM_R, &var_node, &dim_node TSRMLS_CC);
    2066             : }
    2067             : /* }}} */
    2068             : 
    2069      112161 : static inline zend_op *zend_compile_dim_common(znode *result, zend_ast *ast, uint32_t type TSRMLS_DC) /* {{{ */
    2070             : {
    2071      112161 :         uint32_t offset = zend_delayed_compile_begin(TSRMLS_C);
    2072      112161 :         zend_delayed_compile_dim(result, ast, type TSRMLS_CC);
    2073      112153 :         return zend_delayed_compile_end(offset TSRMLS_CC);
    2074             : }
    2075             : /* }}} */
    2076             : 
    2077      103274 : void zend_compile_dim(znode *result, zend_ast *ast, uint32_t type TSRMLS_DC) /* {{{ */
    2078             : {
    2079      103274 :         zend_op *opline = zend_compile_dim_common(result, ast, type TSRMLS_CC);
    2080      103268 :         zend_adjust_for_fetch_type(opline, type);
    2081      103268 : }
    2082             : /* }}} */
    2083             : 
    2084      192058 : static zend_bool is_this_fetch(zend_ast *ast) /* {{{ */
    2085             : {
    2086      192058 :         if (ast->kind == ZEND_AST_VAR && ast->child[0]->kind == ZEND_AST_ZVAL) {
    2087      361426 :                 zval *name = zend_ast_get_zval(ast->child[0]);
    2088      180713 :                 return Z_TYPE_P(name) == IS_STRING && zend_string_equals_literal(Z_STR_P(name), "this");
    2089             :         }
    2090             : 
    2091       11345 :         return 0;
    2092             : }
    2093             : /* }}} */
    2094             : 
    2095       10017 : static zend_op *zend_delayed_compile_prop(znode *result, zend_ast *ast, uint32_t type TSRMLS_DC) /* {{{ */
    2096             : {
    2097       10017 :         zend_ast *obj_ast = ast->child[0];
    2098       10017 :         zend_ast *prop_ast = ast->child[1];
    2099             : 
    2100             :         znode obj_node, prop_node;
    2101             :         zend_op *opline;
    2102             : 
    2103       10017 :         if (is_this_fetch(obj_ast)) {
    2104        3249 :                 obj_node.op_type = IS_UNUSED;
    2105             :         } else {
    2106        6768 :                 zend_delayed_compile_var(&obj_node, obj_ast, type TSRMLS_CC);
    2107        6768 :                 zend_separate_if_call_and_write(&obj_node, obj_ast, type TSRMLS_CC);
    2108             :         }
    2109       10017 :         zend_compile_expr(&prop_node, prop_ast TSRMLS_CC);
    2110             : 
    2111       10017 :         opline = zend_delayed_emit_op(result, ZEND_FETCH_OBJ_R, &obj_node, &prop_node TSRMLS_CC);
    2112       10017 :         if (opline->op2_type == IS_CONST) {
    2113       19866 :                 convert_to_string(&CONSTANT(opline->op2.constant));
    2114        9933 :                 zend_alloc_polymorphic_cache_slot(opline->op2.constant TSRMLS_CC);
    2115             :         }
    2116             : 
    2117       10017 :         return opline;
    2118             : }
    2119             : /* }}} */
    2120             : 
    2121        6822 : static zend_op *zend_compile_prop_common(znode *result, zend_ast *ast, uint32_t type TSRMLS_DC) /* {{{ */
    2122             : {
    2123        6822 :         uint32_t offset = zend_delayed_compile_begin(TSRMLS_C);
    2124        6822 :         zend_delayed_compile_prop(result, ast, type TSRMLS_CC);
    2125        6822 :         return zend_delayed_compile_end(offset TSRMLS_CC);
    2126             : }
    2127             : /* }}} */
    2128             : 
    2129        5936 : void zend_compile_prop(znode *result, zend_ast *ast, uint32_t type TSRMLS_DC) /* {{{ */
    2130             : {
    2131        5936 :         zend_op *opline = zend_compile_prop_common(result, ast, type TSRMLS_CC);
    2132        5936 :         zend_adjust_for_fetch_type(opline, type);
    2133        5936 : }
    2134             : /* }}} */
    2135             : 
    2136         628 : zend_op *zend_compile_static_prop_common(znode *result, zend_ast *ast, uint32_t type TSRMLS_DC) /* {{{ */
    2137             : {
    2138         628 :         zend_ast *class_ast = ast->child[0];
    2139         628 :         zend_ast *prop_ast = ast->child[1];
    2140             : 
    2141             :         znode class_node, prop_node;
    2142             :         zend_op *opline;
    2143             : 
    2144         628 :         if (zend_is_const_default_class_ref(class_ast)) {
    2145         228 :                 class_node.op_type = IS_CONST;
    2146         228 :                 ZVAL_STR(&class_node.u.constant, zend_resolve_class_name_ast(class_ast TSRMLS_CC));
    2147             :         } else {
    2148         400 :                 zend_compile_class_ref(&class_node, class_ast TSRMLS_CC);
    2149             :         }
    2150             : 
    2151         628 :         zend_compile_expr(&prop_node, prop_ast TSRMLS_CC);
    2152             : 
    2153         628 :         opline = zend_emit_op(result, ZEND_FETCH_R, &prop_node, NULL TSRMLS_CC);
    2154         628 :         if (opline->op1_type == IS_CONST) {
    2155         624 :                 zend_alloc_polymorphic_cache_slot(opline->op1.constant TSRMLS_CC);
    2156             :         }
    2157         628 :         if (class_node.op_type == IS_CONST) {
    2158         228 :                 opline->op2_type = IS_CONST;
    2159         228 :                 opline->op2.constant = zend_add_class_name_literal(
    2160             :                         CG(active_op_array), Z_STR(class_node.u.constant) TSRMLS_CC);
    2161             :         } else {
    2162         400 :                 SET_NODE(opline->op2, &class_node);
    2163             :         }
    2164         628 :         opline->extended_value |= ZEND_FETCH_STATIC_MEMBER;
    2165             : 
    2166         628 :         return opline;
    2167             : }
    2168             : /* }}} */
    2169             : 
    2170         517 : void zend_compile_static_prop(znode *result, zend_ast *ast, uint32_t type TSRMLS_DC) /* {{{ */
    2171             : {
    2172         517 :         zend_op *opline = zend_compile_static_prop_common(result, ast, type TSRMLS_CC);
    2173         517 :         zend_adjust_for_fetch_type(opline, type);
    2174         517 : }
    2175             : /* }}} */
    2176             : 
    2177         171 : static void zend_compile_list_assign(znode *result, zend_ast *ast, znode *expr_node TSRMLS_DC) /* {{{ */
    2178             : {
    2179         171 :         zend_ast_list *list = zend_ast_get_list(ast);
    2180             :         uint32_t i;
    2181             : 
    2182         171 :         if (list->children == 1 && !list->child[0]) {
    2183           1 :                 zend_error_noreturn(E_COMPILE_ERROR, "Cannot use empty list");
    2184             :         }
    2185             : 
    2186         558 :         for (i = 0; i < list->children; ++i) {
    2187         388 :                 zend_ast *var_ast = list->child[i];
    2188             :                 znode fetch_result, dim_node;
    2189             : 
    2190         388 :                 if (var_ast == NULL) {
    2191          19 :                         continue;
    2192             :                 }
    2193             : 
    2194         369 :                 dim_node.op_type = IS_CONST;
    2195         369 :                 ZVAL_LONG(&dim_node.u.constant, i);
    2196             : 
    2197         369 :                 if (expr_node->op_type == IS_CONST) {
    2198          27 :                         Z_TRY_ADDREF(expr_node->u.constant);
    2199             :                 }
    2200             : 
    2201         369 :                 zend_emit_op(&fetch_result, ZEND_FETCH_LIST, expr_node, &dim_node TSRMLS_CC);
    2202         369 :                 zend_emit_assign_znode(var_ast, &fetch_result TSRMLS_CC);
    2203             :         }
    2204         170 :         *result = *expr_node;
    2205         170 : }
    2206             : /* }}} */
    2207             : 
    2208      151466 : void zend_ensure_writable_variable(const zend_ast *ast) /* {{{ */
    2209             : {
    2210      151466 :         if (ast->kind == ZEND_AST_CALL) {
    2211           1 :                 zend_error_noreturn(E_COMPILE_ERROR, "Can't use function return value in write context");
    2212             :         }
    2213      151465 :         if (ast->kind == ZEND_AST_METHOD_CALL || ast->kind == ZEND_AST_STATIC_CALL) {
    2214           1 :                 zend_error_noreturn(E_COMPILE_ERROR, "Can't use method return value in write context");
    2215             :         }
    2216      151464 : }
    2217             : /* }}} */
    2218             : 
    2219             : /* Detects $a... = $a pattern */
    2220        6599 : zend_bool zend_is_assign_to_self(zend_ast *var_ast, zend_ast *expr_ast TSRMLS_DC) /* {{{ */
    2221             : {
    2222        6599 :         if (expr_ast->kind != ZEND_AST_VAR || expr_ast->child[0]->kind != ZEND_AST_ZVAL) {
    2223        4957 :                 return 0;
    2224             :         }
    2225             : 
    2226        5002 :         while (zend_is_variable(var_ast) && var_ast->kind != ZEND_AST_VAR) {
    2227        1718 :                 var_ast = var_ast->child[0];
    2228             :         }
    2229             : 
    2230        1642 :         if (var_ast->kind != ZEND_AST_VAR || var_ast->child[0]->kind != ZEND_AST_ZVAL) {
    2231           2 :                 return 0;
    2232             :         }
    2233             : 
    2234             :         {
    2235        3280 :                 zend_string *name1 = zval_get_string(zend_ast_get_zval(var_ast->child[0]));
    2236        3280 :                 zend_string *name2 = zval_get_string(zend_ast_get_zval(expr_ast->child[0]));
    2237        1640 :                 zend_bool result = zend_string_equals(name1, name2);
    2238             :                 zend_string_release(name1);
    2239             :                 zend_string_release(name2);
    2240        1640 :                 return result;
    2241             :         }
    2242             : }
    2243             : /* }}} */
    2244             : 
    2245      145156 : void zend_compile_assign(znode *result, zend_ast *ast TSRMLS_DC) /* {{{ */
    2246             : {
    2247      145156 :         zend_ast *var_ast = ast->child[0];
    2248      145156 :         zend_ast *expr_ast = ast->child[1];
    2249             : 
    2250             :         znode var_node, expr_node;
    2251             :         zend_op *opline;
    2252             :         uint32_t offset;
    2253             : 
    2254      145156 :         if (is_this_fetch(var_ast)) {
    2255           2 :                 zend_error_noreturn(E_COMPILE_ERROR, "Cannot re-assign $this");
    2256             :         }
    2257             : 
    2258      145154 :         zend_ensure_writable_variable(var_ast);
    2259             : 
    2260      145152 :         switch (var_ast->kind) {
    2261             :                 case ZEND_AST_VAR:
    2262             :                 case ZEND_AST_STATIC_PROP:
    2263      136451 :                         zend_compile_var(&var_node, var_ast, BP_VAR_W TSRMLS_CC);
    2264      136451 :                         zend_compile_expr(&expr_node, expr_ast TSRMLS_CC);
    2265      136448 :                         zend_emit_op(result, ZEND_ASSIGN, &var_node, &expr_node TSRMLS_CC);
    2266      136448 :                         return;
    2267             :                 case ZEND_AST_DIM:
    2268        6601 :                         offset = zend_delayed_compile_begin(TSRMLS_C);
    2269        6601 :                         zend_delayed_compile_dim(result, var_ast, BP_VAR_W TSRMLS_CC);
    2270             : 
    2271        6599 :                         if (zend_is_assign_to_self(var_ast, expr_ast TSRMLS_CC)) {
    2272             :                                 /* $a[0] = $a should evaluate the right $a first */
    2273          16 :                                 zend_compile_simple_var_no_cv(&expr_node, expr_ast, BP_VAR_R TSRMLS_CC);
    2274             :                         } else {
    2275        6583 :                                 zend_compile_expr(&expr_node, expr_ast TSRMLS_CC);
    2276             :                         }
    2277             : 
    2278        6599 :                         opline = zend_delayed_compile_end(offset TSRMLS_CC);
    2279        6599 :                         opline->opcode = ZEND_ASSIGN_DIM;
    2280             : 
    2281        6599 :                         opline = zend_emit_op_data(&expr_node TSRMLS_CC);
    2282        6599 :                         return;
    2283             :                 case ZEND_AST_PROP:
    2284        1952 :                         offset = zend_delayed_compile_begin(TSRMLS_C);
    2285        1952 :                         zend_delayed_compile_prop(result, var_ast, BP_VAR_W TSRMLS_CC);
    2286        1952 :                         zend_compile_expr(&expr_node, expr_ast TSRMLS_CC);
    2287             : 
    2288        1952 :                         opline = zend_delayed_compile_end(offset TSRMLS_CC);
    2289        1952 :                         opline->opcode = ZEND_ASSIGN_OBJ;
    2290             : 
    2291        1952 :                         zend_emit_op_data(&expr_node TSRMLS_CC);
    2292        1952 :                         return;
    2293             :                 case ZEND_AST_LIST:
    2294         148 :                         zend_compile_expr(&expr_node, expr_ast TSRMLS_CC);
    2295         148 :                         zend_compile_list_assign(result, var_ast, &expr_node TSRMLS_CC);
    2296         148 :                         return;
    2297             :                 EMPTY_SWITCH_DEFAULT_CASE();
    2298             :         }
    2299             : }
    2300             : /* }}} */
    2301             : 
    2302        2407 : void zend_compile_assign_ref(znode *result, zend_ast *ast TSRMLS_DC) /* {{{ */
    2303             : {
    2304        2407 :         zend_ast *target_ast = ast->child[0];
    2305        2407 :         zend_ast *source_ast = ast->child[1];
    2306             : 
    2307             :         znode target_node, source_node;
    2308             :         zend_op *opline;
    2309             : 
    2310        2407 :         if (is_this_fetch(target_ast)) {
    2311           1 :                 zend_error_noreturn(E_COMPILE_ERROR, "Cannot re-assign $this");
    2312             :         }
    2313        2406 :         zend_ensure_writable_variable(target_ast);
    2314             : 
    2315        2406 :         zend_compile_var(&target_node, target_ast, BP_VAR_W TSRMLS_CC);
    2316        2406 :         zend_compile_var(&source_node, source_ast, BP_VAR_REF TSRMLS_CC);
    2317             : 
    2318        2406 :         if (source_node.op_type != IS_VAR && zend_is_call(source_ast)) {
    2319           1 :                 zend_error_noreturn(E_COMPILE_ERROR, "Cannot use result of built-in function in write context");
    2320             :         }
    2321             : 
    2322        2405 :         opline = zend_emit_op(result, ZEND_ASSIGN_REF, &target_node, &source_node TSRMLS_CC);
    2323        2405 :         if (!result) {
    2324        1993 :                 opline->result_type |= EXT_TYPE_UNUSED;
    2325             :         }
    2326             : 
    2327        2405 :         if (zend_is_call(source_ast)) {
    2328          43 :                 opline->extended_value = ZEND_RETURNS_FUNCTION;
    2329        2362 :         } else if (source_ast->kind == ZEND_AST_NEW) {
    2330          10 :                 zend_error(E_DEPRECATED, "Assigning the return value of new by reference is deprecated");
    2331          10 :                 opline->extended_value = ZEND_RETURNS_NEW;
    2332             :         }
    2333        2405 : }
    2334             : /* }}} */
    2335             : 
    2336        1993 : static inline void zend_emit_assign_ref_znode(zend_ast *var_ast, znode *value_node TSRMLS_DC) /* {{{ */
    2337             : {
    2338        1993 :         zend_ast *assign_ast = zend_ast_create(ZEND_AST_ASSIGN_REF, var_ast,
    2339        1993 :                 zend_ast_create_znode(value_node));
    2340        1993 :         zend_compile_assign_ref(NULL, assign_ast TSRMLS_CC);
    2341        1993 : }
    2342             : /* }}} */
    2343             : 
    2344        3755 : void zend_compile_compound_assign(znode *result, zend_ast *ast TSRMLS_DC) /* {{{ */
    2345             : {
    2346        3755 :         zend_ast *var_ast = ast->child[0];
    2347        3755 :         zend_ast *expr_ast = ast->child[1];
    2348        3755 :         uint32_t opcode = ast->attr;
    2349             : 
    2350             :         znode var_node, expr_node;
    2351             :         zend_op *opline;
    2352             :         uint32_t offset;
    2353             : 
    2354        3755 :         zend_ensure_writable_variable(var_ast);
    2355             : 
    2356        3755 :         switch (var_ast->kind) {
    2357             :                 case ZEND_AST_VAR:
    2358             :                 case ZEND_AST_STATIC_PROP:
    2359        3659 :                         zend_compile_var(&var_node, var_ast, BP_VAR_RW TSRMLS_CC);
    2360        3659 :                         zend_compile_expr(&expr_node, expr_ast TSRMLS_CC);
    2361        3659 :                         zend_emit_op(result, opcode, &var_node, &expr_node TSRMLS_CC);
    2362        3659 :                         return;
    2363             :                 case ZEND_AST_DIM:
    2364          48 :                         offset = zend_delayed_compile_begin(TSRMLS_C);
    2365          48 :                         zend_delayed_compile_dim(result, var_ast, BP_VAR_RW TSRMLS_CC);
    2366          48 :                         zend_compile_expr(&expr_node, expr_ast TSRMLS_CC);
    2367             : 
    2368          48 :                         opline = zend_delayed_compile_end(offset TSRMLS_CC);
    2369          48 :                         opline->opcode = opcode;
    2370          48 :                         opline->extended_value = ZEND_ASSIGN_DIM;
    2371             : 
    2372          48 :                         opline = zend_emit_op_data(&expr_node TSRMLS_CC);
    2373          48 :                         return;
    2374             :                 case ZEND_AST_PROP:
    2375          48 :                         offset = zend_delayed_compile_begin(TSRMLS_C);
    2376          48 :                         zend_delayed_compile_prop(result, var_ast, BP_VAR_RW TSRMLS_CC);
    2377          48 :                         zend_compile_expr(&expr_node, expr_ast TSRMLS_CC);
    2378             : 
    2379          48 :                         opline = zend_delayed_compile_end(offset TSRMLS_CC);
    2380          48 :                         opline->opcode = opcode;
    2381          48 :                         opline->extended_value = ZEND_ASSIGN_OBJ;
    2382             : 
    2383          48 :                         zend_emit_op_data(&expr_node TSRMLS_CC);
    2384          48 :                         return;
    2385             :                 EMPTY_SWITCH_DEFAULT_CASE()
    2386             :         }
    2387             : }
    2388             : /* }}} */
    2389             : 
    2390      307511 : uint32_t zend_compile_args(zend_ast *ast, zend_function *fbc TSRMLS_DC) /* {{{ */
    2391             : {
    2392             :         /* TODO.AST &var error */
    2393      307511 :         zend_ast_list *args = zend_ast_get_list(ast);
    2394             :         uint32_t i;
    2395      307511 :         zend_bool uses_arg_unpack = 0;
    2396      307511 :         uint32_t arg_count = 0; /* number of arguments not including unpacks */
    2397             : 
    2398      842826 :         for (i = 0; i < args->children; ++i) {
    2399      535329 :                 zend_ast *arg = args->child[i];
    2400      535329 :                 uint32_t arg_num = i + 1;
    2401             : 
    2402             :                 znode arg_node;
    2403             :                 zend_op *opline;
    2404             :                 zend_uchar opcode;
    2405      535329 :                 zend_ulong flags = 0;
    2406             : 
    2407      535329 :                 if (arg->kind == ZEND_AST_UNPACK) {
    2408          64 :                         uses_arg_unpack = 1;
    2409          64 :                         fbc = NULL;
    2410             :                         
    2411          64 :                         zend_compile_expr(&arg_node, arg->child[0] TSRMLS_CC);
    2412          64 :                         opline = zend_emit_op(NULL, ZEND_SEND_UNPACK, &arg_node, NULL TSRMLS_CC);
    2413          64 :                         opline->op2.num = arg_count;
    2414          64 :                         continue;
    2415             :                 }
    2416             : 
    2417      535265 :                 if (uses_arg_unpack) {
    2418           1 :                         zend_error_noreturn(E_COMPILE_ERROR,
    2419             :                                 "Cannot use positional argument after argument unpacking");
    2420             :                 }
    2421             : 
    2422      535264 :                 arg_count++;
    2423      535264 :                 if (zend_is_variable(arg)) {
    2424      307094 :                         if (zend_is_call(arg)) {
    2425       48728 :                                 zend_compile_var(&arg_node, arg, BP_VAR_R TSRMLS_CC);
    2426       48725 :                                 if (arg_node.op_type & (IS_CONST|IS_TMP_VAR)) {
    2427             :                                         /* Function call was converted into builtin instruction */
    2428        1513 :                                         opcode = ZEND_SEND_VAL;
    2429             :                                 } else {
    2430       47212 :                                         opcode = ZEND_SEND_VAR_NO_REF;
    2431       47212 :                                         flags |= ZEND_ARG_SEND_FUNCTION;
    2432       93428 :                                         if (fbc && ARG_SHOULD_BE_SENT_BY_REF(fbc, arg_num)) {
    2433          56 :                                                 flags |= ZEND_ARG_SEND_BY_REF;
    2434          56 :                                                 if (ARG_MAY_BE_SENT_BY_REF(fbc, arg_num)) {
    2435          34 :                                                         flags |= ZEND_ARG_SEND_SILENT;
    2436             :                                                 }
    2437             :                                         }
    2438             :                                 }
    2439      258366 :                         } else if (fbc) {
    2440      216554 :                                 if (ARG_SHOULD_BE_SENT_BY_REF(fbc, arg_num)) {
    2441       73593 :                                         zend_compile_var(&arg_node, arg, BP_VAR_W TSRMLS_CC);
    2442       73593 :                                         opcode = ZEND_SEND_REF;
    2443             :                                 } else {
    2444      142961 :                                         zend_compile_var(&arg_node, arg, BP_VAR_R TSRMLS_CC);
    2445      142960 :                                         opcode = ZEND_SEND_VAR;
    2446             :                                 }
    2447             :                         } else {
    2448       41812 :                                 zend_compile_var(&arg_node, arg,
    2449       41812 :                                         BP_VAR_FUNC_ARG | (arg_num << BP_VAR_SHIFT) TSRMLS_CC);
    2450       41812 :                                 opcode = ZEND_SEND_VAR_EX;
    2451             :                         }
    2452             :                 } else {
    2453      228170 :                         zend_compile_expr(&arg_node, arg TSRMLS_CC);
    2454      228168 :                         if (arg_node.op_type & (IS_VAR|IS_CV)) {
    2455        2212 :                                 opcode = ZEND_SEND_VAR_NO_REF;
    2456        3641 :                                 if (fbc && ARG_MUST_BE_SENT_BY_REF(fbc, arg_num)) {
    2457           9 :                                         flags |= ZEND_ARG_SEND_BY_REF;
    2458             :                                 }
    2459             :                         } else {
    2460      225956 :                                 if (fbc) {
    2461      189428 :                                         opcode = ZEND_SEND_VAL;
    2462      189428 :                                         if (ARG_MUST_BE_SENT_BY_REF(fbc, arg_num)) {
    2463           7 :                                                 zend_error_noreturn(E_COMPILE_ERROR, "Only variables can be passed by reference");
    2464             :                                         }
    2465             :                                 } else {
    2466       36528 :                                         opcode = ZEND_SEND_VAL_EX;
    2467             :                                 }
    2468             :                         }
    2469             :                 }
    2470             : 
    2471      535251 :                 opline = get_next_op(CG(active_op_array) TSRMLS_CC);
    2472      535251 :                 opline->opcode = opcode;
    2473      535251 :                 SET_NODE(opline->op1, &arg_node);
    2474      535251 :                 SET_UNUSED(opline->op2);
    2475      535251 :                 opline->op2.opline_num = arg_num;
    2476             : 
    2477      535251 :                 if (opcode == ZEND_SEND_VAR_NO_REF) {
    2478       49424 :                         if (fbc) {
    2479       47645 :                                 flags |= ZEND_ARG_COMPILE_TIME_BOUND;
    2480             :                         }
    2481       97004 :                         if ((flags & ZEND_ARG_COMPILE_TIME_BOUND) && !(flags & ZEND_ARG_SEND_BY_REF)) {
    2482       47580 :                                 opline->opcode = ZEND_SEND_VAR;
    2483       47580 :                                 opline->extended_value = ZEND_ARG_COMPILE_TIME_BOUND;
    2484             :                         } else {
    2485        1844 :                                 opline->extended_value = flags;
    2486             :                         }
    2487      485827 :                 } else if (fbc) {
    2488      407484 :                         opline->extended_value = ZEND_ARG_COMPILE_TIME_BOUND;
    2489             :                 }
    2490             :         }
    2491             : 
    2492      307497 :         return arg_count;
    2493             : }
    2494             : /* }}} */
    2495             : 
    2496      307511 : void zend_compile_call_common(znode *result, zend_ast *args_ast, zend_function *fbc TSRMLS_DC) /* {{{ */
    2497             : {
    2498             :         zend_op *opline;
    2499      307511 :         uint32_t opnum_init = get_next_op_number(CG(active_op_array)) - 1;
    2500             :         uint32_t arg_count;
    2501             :         uint32_t call_flags;
    2502             : 
    2503      307511 :         zend_do_extended_fcall_begin(TSRMLS_C);
    2504             : 
    2505      307511 :         arg_count = zend_compile_args(args_ast, fbc TSRMLS_CC);
    2506             : 
    2507      307497 :         opline = &CG(active_op_array)->opcodes[opnum_init];
    2508      307497 :         opline->extended_value = arg_count;
    2509             : 
    2510      307497 :         call_flags = (opline->opcode == ZEND_NEW ? ZEND_CALL_CTOR : 0);
    2511      307497 :         opline = zend_emit_op(result, ZEND_DO_FCALL, NULL, NULL TSRMLS_CC);
    2512      307497 :         opline->op1.num = call_flags;
    2513             : 
    2514      307497 :         zend_do_extended_fcall_end(TSRMLS_C);
    2515      307497 : }
    2516             : /* }}} */
    2517             : 
    2518      255423 : zend_bool zend_compile_function_name(znode *name_node, zend_ast *name_ast TSRMLS_DC) /* {{{ */
    2519             : {
    2520      255423 :         zend_string *orig_name = zend_ast_get_str(name_ast);
    2521             :         zend_bool is_fully_qualified;
    2522             : 
    2523      255423 :         name_node->op_type = IS_CONST;
    2524      255423 :         ZVAL_STR(&name_node->u.constant, zend_resolve_function_name(
    2525             :                 orig_name, name_ast->attr, &is_fully_qualified TSRMLS_CC));
    2526             : 
    2527      255423 :         return !is_fully_qualified && CG(current_namespace);
    2528             : }
    2529             : /* }}} */
    2530             : 
    2531         297 : void zend_compile_ns_call(znode *result, znode *name_node, zend_ast *args_ast TSRMLS_DC) /* {{{ */
    2532             : {
    2533         297 :         zend_op *opline = get_next_op(CG(active_op_array) TSRMLS_CC);
    2534         297 :         opline->opcode = ZEND_INIT_NS_FCALL_BY_NAME;
    2535         297 :         SET_UNUSED(opline->op1);
    2536         297 :         opline->op2_type = IS_CONST;
    2537         297 :         opline->op2.constant = zend_add_ns_func_name_literal(
    2538             :                 CG(active_op_array), Z_STR(name_node->u.constant) TSRMLS_CC);
    2539         297 :         zend_alloc_cache_slot(opline->op2.constant TSRMLS_CC);
    2540             : 
    2541         297 :         zend_compile_call_common(result, args_ast, NULL TSRMLS_CC);
    2542         297 : }
    2543             : /* }}} */
    2544             : 
    2545        5946 : void zend_compile_dynamic_call(znode *result, znode *name_node, zend_ast *args_ast TSRMLS_DC) /* {{{ */
    2546             : {
    2547        5946 :         zend_op *opline = get_next_op(CG(active_op_array) TSRMLS_CC);
    2548        5946 :         opline->opcode = ZEND_INIT_FCALL_BY_NAME;
    2549        5946 :         SET_UNUSED(opline->op1);
    2550       13681 :         if (name_node->op_type == IS_CONST && Z_TYPE(name_node->u.constant) == IS_STRING) {
    2551        3867 :                 opline->op2_type = IS_CONST;
    2552        3867 :                 opline->op2.constant = zend_add_func_name_literal(CG(active_op_array),
    2553             :                         Z_STR(name_node->u.constant) TSRMLS_CC);
    2554        3867 :                 zend_alloc_cache_slot(opline->op2.constant TSRMLS_CC);
    2555             :         } else {
    2556        2079 :                 SET_NODE(opline->op2, name_node);
    2557             :         }
    2558             : 
    2559        5946 :         zend_compile_call_common(result, args_ast, NULL TSRMLS_CC);
    2560        5946 : }
    2561             : /* }}} */
    2562             : 
    2563         196 : static zend_bool zend_args_contain_unpack(zend_ast_list *args) /* {{{ */
    2564             : {
    2565             :         uint32_t i;
    2566         809 :         for (i = 0; i < args->children; ++i) {
    2567         613 :                 if (args->child[i]->kind == ZEND_AST_UNPACK) {
    2568           0 :                         return 1;
    2569             :                 }
    2570             :         }
    2571         196 :         return 0;
    2572             : }
    2573             : /* }}} */
    2574             : 
    2575        4598 : int zend_compile_func_strlen(znode *result, zend_ast_list *args TSRMLS_DC) /* {{{ */
    2576             : {
    2577             :         znode arg_node;
    2578             : 
    2579       13784 :         if ((CG(compiler_options) & ZEND_COMPILE_NO_BUILTIN_STRLEN)
    2580        9186 :                 || args->children != 1 || args->child[0]->kind == ZEND_AST_UNPACK
    2581             :         ) {
    2582           8 :                 return FAILURE;
    2583             :         }
    2584             : 
    2585        4590 :         zend_compile_expr(&arg_node, args->child[0] TSRMLS_CC);
    2586        4590 :         zend_emit_op_tmp(result, ZEND_STRLEN, &arg_node, NULL TSRMLS_CC);
    2587        4590 :         return SUCCESS;
    2588             : }
    2589             : /* }}} */
    2590             : 
    2591        3896 : int zend_compile_func_typecheck(znode *result, zend_ast_list *args, uint32_t type TSRMLS_DC) /* {{{ */
    2592             : {
    2593             :         znode arg_node;
    2594             :         zend_op *opline;
    2595             : 
    2596        3896 :         if (args->children != 1 || args->child[0]->kind == ZEND_AST_UNPACK) {
    2597          24 :                 return FAILURE;
    2598             :         }
    2599             :         
    2600        3872 :         zend_compile_expr(&arg_node, args->child[0] TSRMLS_CC);
    2601        3872 :         opline = zend_emit_op_tmp(result, ZEND_TYPE_CHECK, &arg_node, NULL TSRMLS_CC);
    2602        3872 :         opline->extended_value = type;
    2603        3872 :         return SUCCESS;
    2604             : }
    2605             : /* }}} */
    2606             : 
    2607         174 : int zend_compile_func_defined(znode *result, zend_ast_list *args TSRMLS_DC) /* {{{ */
    2608             : {
    2609             :         zend_string *name;
    2610             :         zend_op *opline;
    2611             : 
    2612         174 :         if (args->children != 1 || args->child[0]->kind != ZEND_AST_ZVAL) {
    2613           1 :                 return FAILURE;
    2614             :         }
    2615             : 
    2616         346 :         name = zval_get_string(zend_ast_get_zval(args->child[0]));
    2617         519 :         if (zend_memrchr(name->val, '\\', name->len) || zend_memrchr(name->val, ':', name->len)) {
    2618             :                 zend_string_release(name);
    2619           8 :                 return FAILURE;
    2620             :         }
    2621             : 
    2622         165 :         opline = zend_emit_op_tmp(result, ZEND_DEFINED, NULL, NULL TSRMLS_CC);
    2623         165 :         opline->op1_type = IS_CONST;
    2624         165 :         LITERAL_STR(opline->op1, name);
    2625         165 :         zend_alloc_cache_slot(opline->op1.constant TSRMLS_CC);
    2626             : 
    2627             :         /* Lowercase constant name in a separate literal */
    2628             :         {
    2629             :                 zval c;
    2630         330 :                 zend_string *lcname = zend_string_alloc(name->len, 0);
    2631         165 :                 zend_str_tolower_copy(lcname->val, name->val, name->len);
    2632         165 :                 ZVAL_NEW_STR(&c, lcname);
    2633         165 :                 zend_add_literal(CG(active_op_array), &c TSRMLS_CC);
    2634             :         }
    2635         165 :         return SUCCESS;
    2636             : }
    2637             : /* }}} */
    2638             : 
    2639         196 : static int zend_try_compile_ct_bound_init_user_func(zend_ast *name_ast, uint32_t num_args TSRMLS_DC) /* {{{ */
    2640             : {
    2641             :         zend_string *name, *lcname;
    2642             :         zend_function *fbc;
    2643             :         zend_op *opline;
    2644             : 
    2645         266 :         if (name_ast->kind != ZEND_AST_ZVAL || Z_TYPE_P(zend_ast_get_zval(name_ast)) != IS_STRING) {
    2646         126 :                 return FAILURE;
    2647             :         }
    2648             : 
    2649          70 :         name = zend_ast_get_str(name_ast);
    2650         140 :         lcname = zend_string_alloc(name->len, 0);
    2651          70 :         zend_str_tolower_copy(lcname->val, name->val, name->len);
    2652             : 
    2653         140 :         fbc = zend_hash_find_ptr(CG(function_table), lcname);
    2654          87 :         if (!fbc || (fbc->type == ZEND_INTERNAL_FUNCTION &&
    2655          17 :                 (CG(compiler_options) & ZEND_COMPILE_IGNORE_INTERNAL_FUNCTIONS))
    2656             :         ) {
    2657             :                 zend_string_free(lcname);
    2658          24 :                 return FAILURE;
    2659             :         }
    2660             : 
    2661          46 :         opline = zend_emit_op(NULL, ZEND_INIT_FCALL, NULL, NULL TSRMLS_CC);
    2662          46 :         opline->extended_value = num_args;
    2663             : 
    2664          46 :         opline->op2_type = IS_CONST;
    2665          46 :         LITERAL_STR(opline->op2, lcname);
    2666          46 :         zend_alloc_cache_slot(opline->op2.constant TSRMLS_CC);
    2667             : 
    2668          46 :         return SUCCESS;
    2669             : }
    2670             : /* }}} */
    2671             : 
    2672         196 : static void zend_compile_init_user_func(zend_ast *name_ast, uint32_t num_args, zend_string *orig_func_name TSRMLS_DC) /* {{{ */
    2673             : {
    2674             :         zend_op *opline;
    2675             :         znode name_node;
    2676             : 
    2677         196 :         if (zend_try_compile_ct_bound_init_user_func(name_ast, num_args TSRMLS_CC) == SUCCESS) {
    2678          46 :                 return;
    2679             :         }
    2680             : 
    2681         150 :         zend_compile_expr(&name_node, name_ast TSRMLS_CC);
    2682             : 
    2683         150 :         opline = zend_emit_op(NULL, ZEND_INIT_USER_CALL, NULL, &name_node TSRMLS_CC);
    2684         150 :         opline->op1_type = IS_CONST;
    2685         300 :         LITERAL_STR(opline->op1, zend_string_copy(orig_func_name));
    2686         150 :         opline->extended_value = num_args;
    2687             : }
    2688             : /* }}} */
    2689             : 
    2690             : /* cufa = call_user_func_array */
    2691          69 : int zend_compile_func_cufa(znode *result, zend_ast_list *args, zend_string *lcname TSRMLS_DC) /* {{{ */
    2692             : {
    2693             :         znode arg_node;
    2694             : 
    2695          69 :         if (args->children != 2 || zend_args_contain_unpack(args)) {
    2696           0 :                 return FAILURE;
    2697             :         }
    2698             : 
    2699          69 :         zend_compile_init_user_func(args->child[0], 1, lcname TSRMLS_CC);
    2700          69 :         zend_compile_expr(&arg_node, args->child[1] TSRMLS_CC);
    2701          69 :         zend_emit_op(NULL, ZEND_SEND_ARRAY, &arg_node, NULL TSRMLS_CC);
    2702          69 :         zend_emit_op(result, ZEND_DO_FCALL, NULL, NULL TSRMLS_CC);
    2703             : 
    2704          69 :         return SUCCESS;
    2705             : }
    2706             : /* }}} */
    2707             : 
    2708             : /* cuf = call_user_func */
    2709         127 : int zend_compile_func_cuf(znode *result, zend_ast_list *args, zend_string *lcname TSRMLS_DC) /* {{{ */
    2710             : {
    2711             :         uint32_t i;
    2712             : 
    2713         127 :         if (args->children < 1 || zend_args_contain_unpack(args)) {
    2714           0 :                 return FAILURE;
    2715             :         }
    2716             : 
    2717         127 :         zend_compile_init_user_func(args->child[0], args->children - 1, lcname TSRMLS_CC);
    2718         475 :         for (i = 1; i < args->children; ++i) {
    2719         348 :                 zend_ast *arg_ast = args->child[i];
    2720             :                 znode arg_node;
    2721             :                 zend_op *opline;
    2722         348 :                 zend_bool send_user = 0;
    2723             : 
    2724         609 :                 if (zend_is_variable(arg_ast) && !zend_is_call(arg_ast)) {
    2725         261 :                         zend_compile_var(&arg_node, arg_ast, BP_VAR_FUNC_ARG | (i << BP_VAR_SHIFT) TSRMLS_CC);
    2726         261 :                         send_user = 1;
    2727             :                 } else {
    2728          87 :                         zend_compile_expr(&arg_node, arg_ast TSRMLS_CC);
    2729          87 :                         if (arg_node.op_type & (IS_VAR|IS_CV)) {
    2730           6 :                                 send_user = 1;
    2731             :                         }
    2732             :                 }
    2733             : 
    2734         348 :                 if (send_user) {
    2735         267 :                         opline = zend_emit_op(NULL, ZEND_SEND_USER, &arg_node, NULL TSRMLS_CC);
    2736             :                 } else {
    2737          81 :                         opline = zend_emit_op(NULL, ZEND_SEND_VAL, &arg_node, NULL TSRMLS_CC);
    2738             :                 }
    2739             : 
    2740         348 :                 opline->op2.opline_num = i;
    2741             :         }
    2742         127 :         zend_emit_op(result, ZEND_DO_FCALL, NULL, NULL TSRMLS_CC);
    2743             : 
    2744         127 :         return SUCCESS;
    2745             : }
    2746             : /* }}} */
    2747             : 
    2748      251260 : int zend_try_compile_special_func(znode *result, zend_string *lcname, zend_ast_list *args TSRMLS_DC) /* {{{ */
    2749             : {
    2750      251260 :         if (zend_string_equals_literal(lcname, "strlen")) {
    2751        4598 :                 return zend_compile_func_strlen(result, args TSRMLS_CC);
    2752      246662 :         } else if (zend_string_equals_literal(lcname, "is_null")) {
    2753         806 :                 return zend_compile_func_typecheck(result, args, IS_NULL TSRMLS_CC);
    2754      245856 :         } else if (zend_string_equals_literal(lcname, "is_bool")) {
    2755          22 :                 return zend_compile_func_typecheck(result, args, _IS_BOOL TSRMLS_CC);
    2756      817839 :         } else if (zend_string_equals_literal(lcname, "is_long")
    2757      316917 :                 || zend_string_equals_literal(lcname, "is_int")
    2758      255088 :                 || zend_string_equals_literal(lcname, "is_integer")
    2759             :         ) {
    2760         324 :                 return zend_compile_func_typecheck(result, args, IS_LONG TSRMLS_CC);
    2761      765726 :         } else if (zend_string_equals_literal(lcname, "is_float")
    2762      251690 :                 || zend_string_equals_literal(lcname, "is_double")
    2763      268526 :                 || zend_string_equals_literal(lcname, "is_real")
    2764             :         ) {
    2765          34 :                 return zend_compile_func_typecheck(result, args, IS_DOUBLE TSRMLS_CC);
    2766      245476 :         } else if (zend_string_equals_literal(lcname, "is_string")) {
    2767        1245 :                 return zend_compile_func_typecheck(result, args, IS_STRING TSRMLS_CC);
    2768      244231 :         } else if (zend_string_equals_literal(lcname, "is_array")) {
    2769         782 :                 return zend_compile_func_typecheck(result, args, IS_ARRAY TSRMLS_CC);
    2770      243449 :         } else if (zend_string_equals_literal(lcname, "is_object")) {
    2771         511 :                 return zend_compile_func_typecheck(result, args, IS_OBJECT TSRMLS_CC);
    2772      242938 :         } else if (zend_string_equals_literal(lcname, "is_resource")) {
    2773         172 :                 return zend_compile_func_typecheck(result, args, IS_RESOURCE TSRMLS_CC);
    2774      242766 :         } else if (zend_string_equals_literal(lcname, "defined")) {
    2775         174 :                 return zend_compile_func_defined(result, args TSRMLS_CC);
    2776      242592 :         } else if (zend_string_equals_literal(lcname, "call_user_func_array")) {
    2777          69 :                 return zend_compile_func_cufa(result, args, lcname TSRMLS_CC);
    2778      242523 :         } else if (zend_string_equals_literal(lcname, "call_user_func")) {
    2779         127 :                 return zend_compile_func_cuf(result, args, lcname TSRMLS_CC);
    2780             :         } else {
    2781      242396 :                 return FAILURE;
    2782             :         }
    2783             : }
    2784             : /* }}} */
    2785             : 
    2786      257503 : void zend_compile_call(znode *result, zend_ast *ast, uint32_t type TSRMLS_DC) /* {{{ */
    2787             : {
    2788      257503 :         zend_ast *name_ast = ast->child[0];
    2789      257503 :         zend_ast *args_ast = ast->child[1];
    2790             : 
    2791             :         znode name_node;
    2792             : 
    2793      512926 :         if (name_ast->kind != ZEND_AST_ZVAL || Z_TYPE_P(zend_ast_get_zval(name_ast)) != IS_STRING) {
    2794        2080 :                 zend_compile_expr(&name_node, name_ast TSRMLS_CC);
    2795        2080 :                 zend_compile_dynamic_call(result, &name_node, args_ast TSRMLS_CC);
    2796        2080 :                 return;
    2797             :         }
    2798             : 
    2799             :         {
    2800      255423 :                 zend_bool runtime_resolution = zend_compile_function_name(&name_node, name_ast TSRMLS_CC);
    2801      255423 :                 if (runtime_resolution) {
    2802         297 :                         zend_compile_ns_call(result, &name_node, args_ast TSRMLS_CC);
    2803         297 :                         return;
    2804             :                 }
    2805             :         }
    2806             : 
    2807             :         {
    2808      255126 :                 zval *name = &name_node.u.constant;
    2809      510252 :                 zend_string *lcname = zend_string_alloc(Z_STRLEN_P(name), 0);
    2810             :                 zend_function *fbc;
    2811             :                 zend_op *opline;
    2812             : 
    2813      255126 :                 zend_str_tolower_copy(lcname->val, Z_STRVAL_P(name), Z_STRLEN_P(name));
    2814             : 
    2815      510252 :                 fbc = zend_hash_find_ptr(CG(function_table), lcname);
    2816      499465 :                 if (!fbc || (fbc->type == ZEND_INTERNAL_FUNCTION &&
    2817      244339 :                         (CG(compiler_options) & ZEND_COMPILE_IGNORE_INTERNAL_FUNCTIONS))
    2818             :                 ) {
    2819             :                         zend_string_release(lcname);
    2820        3866 :                         zend_compile_dynamic_call(result, &name_node, args_ast TSRMLS_CC);
    2821        3866 :                         return;
    2822             :                 }
    2823             : 
    2824      251260 :                 if (zend_try_compile_special_func(result, lcname,
    2825             :                                 zend_ast_get_list(args_ast) TSRMLS_CC) == SUCCESS
    2826             :                 ) {
    2827             :                         zend_string_release(lcname);
    2828        8823 :                         zval_ptr_dtor(&name_node.u.constant);
    2829        8823 :                         return;
    2830             :                 }
    2831             : 
    2832      242437 :                 zval_ptr_dtor(&name_node.u.constant);
    2833      242437 :                 ZVAL_NEW_STR(&name_node.u.constant, lcname);
    2834             : 
    2835      242437 :                 opline = zend_emit_op(NULL, ZEND_INIT_FCALL, NULL, &name_node TSRMLS_CC);
    2836      242437 :                 zend_alloc_cache_slot(opline->op2.constant TSRMLS_CC);
    2837             : 
    2838      242437 :                 zend_compile_call_common(result, args_ast, fbc TSRMLS_CC);
    2839             :         }
    2840             : }
    2841             : /* }}} */
    2842             : 
    2843       34478 : void zend_compile_method_call(znode *result, zend_ast *ast, uint32_t type TSRMLS_DC) /* {{{ */
    2844             : {
    2845       34478 :         zend_ast *obj_ast = ast->child[0];
    2846       34478 :         zend_ast *method_ast = ast->child[1];
    2847       34478 :         zend_ast *args_ast = ast->child[2];
    2848             : 
    2849             :         znode obj_node, method_node;
    2850             :         zend_op *opline;
    2851             : 
    2852       34478 :         if (is_this_fetch(obj_ast)) {
    2853        1374 :                 obj_node.op_type = IS_UNUSED;
    2854             :         } else {
    2855       33104 :                 zend_compile_expr(&obj_node, obj_ast TSRMLS_CC);
    2856             :         }
    2857             : 
    2858       34478 :         zend_compile_expr(&method_node, method_ast TSRMLS_CC);
    2859       34478 :         opline = zend_emit_op(NULL, ZEND_INIT_METHOD_CALL, &obj_node, NULL TSRMLS_CC);
    2860             :         
    2861       34478 :         if (method_node.op_type == IS_CONST) {
    2862       34452 :                 if (Z_TYPE(method_node.u.constant) != IS_STRING) {
    2863           2 :                         zend_error_noreturn(E_COMPILE_ERROR, "Method name must be a string");
    2864             :                 }
    2865             : 
    2866       34450 :                 opline->op2_type = IS_CONST;
    2867       34450 :                 opline->op2.constant = zend_add_func_name_literal(CG(active_op_array),
    2868             :                         Z_STR(method_node.u.constant) TSRMLS_CC);
    2869       34450 :                 zend_alloc_polymorphic_cache_slot(opline->op2.constant TSRMLS_CC);
    2870             :         } else {
    2871          26 :                 SET_NODE(opline->op2, &method_node);
    2872             :         }
    2873             : 
    2874       34476 :         zend_compile_call_common(result, args_ast, NULL TSRMLS_CC);
    2875       34476 : }
    2876             : /* }}} */
    2877             : 
    2878       10181 : zend_bool zend_is_constructor(zend_string *name) /* {{{ */
    2879             : {
    2880       10181 :         return zend_string_equals_literal_ci(name, ZEND_CONSTRUCTOR_FUNC_NAME);
    2881             : }
    2882             : /* }}} */
    2883             : 
    2884       10215 : void zend_compile_static_call(znode *result, zend_ast *ast, uint32_t type TSRMLS_DC) /* {{{ */
    2885             : {
    2886       10215 :         zend_ast *class_ast = ast->child[0];
    2887       10215 :         zend_ast *method_ast = ast->child[1];
    2888       10215 :         zend_ast *args_ast = ast->child[2];
    2889             : 
    2890             :         znode class_node, method_node;
    2891             :         zend_op *opline;
    2892       10215 :         zend_ulong extended_value = 0;
    2893             : 
    2894       10215 :         if (zend_is_const_default_class_ref(class_ast)) {
    2895        5286 :                 class_node.op_type = IS_CONST;
    2896        5286 :                 ZVAL_STR(&class_node.u.constant, zend_resolve_class_name_ast(class_ast TSRMLS_CC));
    2897             :         } else {
    2898        4929 :                 opline = zend_compile_class_ref(&class_node, class_ast TSRMLS_CC);
    2899        4929 :                 extended_value = opline->extended_value;
    2900             :         }
    2901             : 
    2902       10215 :         zend_compile_expr(&method_node, method_ast TSRMLS_CC);
    2903       10215 :         if (method_node.op_type == IS_CONST) {
    2904       10181 :                 zval *name = &method_node.u.constant;
    2905       10181 :                 if (Z_TYPE_P(name) != IS_STRING) {
    2906           0 :                         zend_error_noreturn(E_COMPILE_ERROR, "Method name must be a string");
    2907             :                 }
    2908       10181 :                 if (zend_is_constructor(Z_STR_P(name))) {
    2909        1024 :                         zval_ptr_dtor(name);
    2910        1024 :                         method_node.op_type = IS_UNUSED;
    2911             :                 }
    2912             :         }
    2913             : 
    2914       10215 :         opline = get_next_op(CG(active_op_array) TSRMLS_CC);
    2915       10215 :         opline->opcode = ZEND_INIT_STATIC_METHOD_CALL;
    2916       10215 :         opline->extended_value = extended_value;
    2917             : 
    2918       10215 :         zend_set_class_name_op1(opline, &class_node TSRMLS_CC);
    2919             : 
    2920       10215 :         if (method_node.op_type == IS_CONST) {
    2921        9157 :                 opline->op2_type = IS_CONST;
    2922        9157 :                 opline->op2.constant = zend_add_func_name_literal(CG(active_op_array),
    2923             :                         Z_STR(method_node.u.constant) TSRMLS_CC);
    2924        9157 :                 if (opline->op1_type == IS_CONST) {
    2925        5272 :                         zend_alloc_cache_slot(opline->op2.constant TSRMLS_CC);
    2926             :                 } else {
    2927        3885 :                         zend_alloc_polymorphic_cache_slot(opline->op2.constant TSRMLS_CC);
    2928             :                 }
    2929             :         } else {
    2930        1058 :                 SET_NODE(opline->op2, &method_node);
    2931             :         }
    2932             : 
    2933       10215 :         zend_compile_call_common(result, args_ast, NULL TSRMLS_CC);
    2934       10215 : }
    2935             : /* }}} */
    2936             : 
    2937       14140 : void zend_compile_new(znode *result, zend_ast *ast TSRMLS_DC) /* {{{ */
    2938             : {
    2939       14140 :         zend_ast *class_ast = ast->child[0];
    2940       14140 :         zend_ast *args_ast = ast->child[1];
    2941             : 
    2942             :         znode class_node, ctor_result;
    2943             :         zend_op *opline;
    2944             :         uint32_t opnum;
    2945             : 
    2946       14140 :         if (zend_is_const_default_class_ref(class_ast)) {
    2947       12930 :                 class_node.op_type = IS_CONST;
    2948       12930 :                 ZVAL_STR(&class_node.u.constant, zend_resolve_class_name_ast(class_ast TSRMLS_CC));
    2949             :         } else {
    2950        1210 :                 zend_compile_class_ref(&class_node, class_ast TSRMLS_CC);
    2951             :         }
    2952             : 
    2953       14140 :         opnum = get_next_op_number(CG(active_op_array));
    2954       14140 :         opline = zend_emit_op(result, ZEND_NEW, NULL, NULL TSRMLS_CC);
    2955             : 
    2956       14140 :         if (class_node.op_type == IS_CONST) {
    2957       12930 :                 opline->op1_type = IS_CONST;
    2958       12930 :                 opline->op1.constant = zend_add_class_name_literal(
    2959             :                         CG(active_op_array), Z_STR(class_node.u.constant) TSRMLS_CC);
    2960             :         } else {
    2961        1210 :                 SET_NODE(opline->op1, &class_node);
    2962             :         }
    2963             : 
    2964       14140 :         zend_compile_call_common(&ctor_result, args_ast, NULL TSRMLS_CC);
    2965       14140 :         zend_do_free(&ctor_result TSRMLS_CC);
    2966             : 
    2967             :         /* New jumps over ctor call if ctor does not exist */
    2968       14140 :         opline = &CG(active_op_array)->opcodes[opnum];
    2969       14140 :         opline->op2.opline_num = get_next_op_number(CG(active_op_array));
    2970       14140 : }
    2971             : /* }}} */
    2972             : 
    2973         115 : void zend_compile_clone(znode *result, zend_ast *ast TSRMLS_DC) /* {{{ */
    2974             : {
    2975         115 :         zend_ast *obj_ast = ast->child[0];
    2976             : 
    2977             :         znode obj_node;
    2978         115 :         zend_compile_expr(&obj_node, obj_ast TSRMLS_CC);
    2979             : 
    2980         115 :         zend_emit_op(result, ZEND_CLONE, &obj_node, NULL TSRMLS_CC);
    2981         115 : }
    2982             : /* }}} */
    2983             : 
    2984        4567 : void zend_compile_global_var(zend_ast *ast TSRMLS_DC) /* {{{ */
    2985             : {
    2986        4567 :         zend_ast *var_ast = ast->child[0];
    2987        4567 :         zend_ast *name_ast = var_ast->child[0];
    2988             : 
    2989             :         znode name_node, result;
    2990             : 
    2991        4567 :         zend_compile_expr(&name_node, name_ast TSRMLS_CC);
    2992        4567 :         if (name_node.op_type == IS_CONST) {
    2993        4565 :                 convert_to_string(&name_node.u.constant);
    2994             :         }
    2995             : 
    2996        4567 :         if (zend_try_compile_cv(&result, var_ast TSRMLS_CC) == SUCCESS) {
    2997        4565 :                 zend_op *opline = zend_emit_op(NULL, ZEND_BIND_GLOBAL, &result, &name_node TSRMLS_CC);
    2998        4565 :                 zend_alloc_cache_slot(opline->op2.constant TSRMLS_CC);
    2999             :         } else {
    3000           2 :                 zend_emit_op(&result, ZEND_FETCH_W, &name_node, NULL TSRMLS_CC);
    3001             : 
    3002             :                 // TODO.AST Avoid double fetch
    3003             :                 //opline->extended_value = ZEND_FETCH_GLOBAL_LOCK;
    3004             : 
    3005           2 :                 zend_emit_assign_ref_znode(var_ast, &result TSRMLS_CC);
    3006             :         }
    3007        4567 : }
    3008             : /* }}} */
    3009             : 
    3010        2039 : static void zend_compile_static_var_common(zend_ast *var_ast, zval *value, zend_bool by_ref TSRMLS_DC) /* {{{ */
    3011             : {
    3012             :         znode var_node, result;
    3013             :         zend_op *opline;
    3014             : 
    3015        2039 :         zend_compile_expr(&var_node, var_ast TSRMLS_CC);
    3016             : 
    3017        2039 :         if (!CG(active_op_array)->static_variables) {
    3018        2007 :                 if (CG(active_op_array)->scope) {
    3019         879 :                         CG(active_op_array)->scope->ce_flags |= ZEND_HAS_STATIC_IN_METHODS;
    3020             :                 }
    3021        2007 :                 ALLOC_HASHTABLE(CG(active_op_array)->static_variables);
    3022        2007 :                 zend_hash_init(CG(active_op_array)->static_variables, 8, NULL, ZVAL_PTR_DTOR, 0);
    3023             :         }
    3024             : 
    3025        2039 :         zend_hash_update(CG(active_op_array)->static_variables, Z_STR(var_node.u.constant), value);
    3026             : 
    3027        2039 :         opline = zend_emit_op(&result, by_ref ? ZEND_FETCH_W : ZEND_FETCH_R, &var_node, NULL TSRMLS_CC);
    3028        2039 :         opline->extended_value = ZEND_FETCH_STATIC;
    3029             : 
    3030        2039 :         if (by_ref) {
    3031        1914 :                 zend_ast *fetch_ast = zend_ast_create(ZEND_AST_VAR, var_ast);
    3032        1914 :                 zend_emit_assign_ref_znode(fetch_ast, &result TSRMLS_CC);
    3033             :         } else {
    3034         125 :                 zend_ast *fetch_ast = zend_ast_create(ZEND_AST_VAR, var_ast);
    3035         125 :                 zend_emit_assign_znode(fetch_ast, &result TSRMLS_CC);
    3036             :         }
    3037        2039 : }
    3038             : /* }}} */
    3039             : 
    3040        1887 : void zend_compile_static_var(zend_ast *ast TSRMLS_DC) /* {{{ */
    3041             : {
    3042        1887 :         zend_ast *var_ast = ast->child[0];
    3043        1887 :         zend_ast *value_ast = ast->child[1];
    3044             :         zval value_zv;
    3045             : 
    3046        1887 :         if (value_ast) {
    3047        1867 :                 zend_const_expr_to_zval(&value_zv, value_ast TSRMLS_CC);
    3048             :         } else {
    3049          20 :                 ZVAL_NULL(&value_zv);
    3050             :         }
    3051             : 
    3052        1887 :         zend_compile_static_var_common(var_ast, &value_zv, 1 TSRMLS_CC);
    3053        1887 : }
    3054             : /* }}} */
    3055             : 
    3056        1584 : void zend_compile_unset(zend_ast *ast TSRMLS_DC) /* {{{ */
    3057             : {
    3058        1584 :         zend_ast *var_ast = ast->child[0];
    3059             : 
    3060             :         znode var_node;
    3061             :         zend_op *opline;
    3062        1584 :         switch (var_ast->kind) {
    3063             :                 case ZEND_AST_VAR:
    3064        1276 :                         if (zend_try_compile_cv(&var_node, var_ast TSRMLS_CC) == SUCCESS) {
    3065        1266 :                                 opline = zend_emit_op(NULL, ZEND_UNSET_VAR, &var_node, NULL TSRMLS_CC);
    3066        1266 :                                 opline->extended_value = ZEND_FETCH_LOCAL | ZEND_QUICK_SET;
    3067             :                         } else {
    3068          10 :                                 opline = zend_compile_simple_var_no_cv(NULL, var_ast, BP_VAR_UNSET TSRMLS_CC);
    3069          10 :                                 opline->opcode = ZEND_UNSET_VAR;
    3070             :                         }
    3071        1276 :                         return;
    3072             :                 case ZEND_AST_DIM:
    3073         233 :                         opline = zend_compile_dim_common(NULL, var_ast, BP_VAR_UNSET TSRMLS_CC);
    3074         232 :                         opline->opcode = ZEND_UNSET_DIM;
    3075         232 :                         return;
    3076             :                 case ZEND_AST_PROP:
    3077          74 :                         opline = zend_compile_prop_common(NULL, var_ast, BP_VAR_UNSET TSRMLS_CC);
    3078          74 :                         opline->opcode = ZEND_UNSET_OBJ;
    3079          74 :                         return;
    3080             :                 case ZEND_AST_STATIC_PROP:
    3081           1 :                         opline = zend_compile_static_prop_common(NULL, var_ast, BP_VAR_UNSET TSRMLS_CC);
    3082           1 :                         opline->opcode = ZEND_UNSET_VAR;
    3083           1 :                         return;
    3084             :                 EMPTY_SWITCH_DEFAULT_CASE()
    3085             :         }
    3086             : }
    3087             : /* }}} */
    3088             : 
    3089       43662 : static void zend_free_foreach_and_switch_variables(TSRMLS_D) /* {{{ */
    3090             : {
    3091             :         uint32_t opnum_start, opnum_end, i;
    3092             : 
    3093       43662 :         opnum_start = get_next_op_number(CG(active_op_array));
    3094             : 
    3095             : #ifdef ZTS
    3096             :         zend_stack_apply_with_argument(&CG(loop_var_stack), ZEND_STACK_APPLY_TOPDOWN, (int (*)(void *element, void *)) generate_free_loop_var TSRMLS_CC);
    3097             : #else
    3098       43662 :         zend_stack_apply(&CG(loop_var_stack), ZEND_STACK_APPLY_TOPDOWN, (int (*)(void *element)) generate_free_loop_var);
    3099             : #endif
    3100             : 
    3101       43662 :         opnum_end = get_next_op_number(CG(active_op_array));
    3102             : 
    3103       44175 :         for (i = opnum_start; i < opnum_end; ++i) {
    3104         513 :                 CG(active_op_array)->opcodes[i].extended_value |= EXT_TYPE_FREE_ON_RETURN;
    3105             :         }
    3106       43662 : }
    3107             : /* }}} */
    3108             : 
    3109       43663 : void zend_compile_return(zend_ast *ast TSRMLS_DC) /* {{{ */
    3110             : {
    3111       43663 :         zend_ast *expr_ast = ast->child[0];
    3112       43663 :         zend_bool by_ref = (CG(active_op_array)->fn_flags & ZEND_ACC_RETURN_REFERENCE) != 0;
    3113             : 
    3114             :         znode expr_node;
    3115             :         zend_op *opline;
    3116             : 
    3117       43663 :         if (!expr_ast) {
    3118         210 :                 expr_node.op_type = IS_CONST;
    3119         210 :                 ZVAL_NULL(&expr_node.u.constant);
    3120       43492 :         } else if (by_ref && zend_is_variable(expr_ast) && !zend_is_call(expr_ast)) {
    3121          39 :                 zend_compile_var(&expr_node, expr_ast, BP_VAR_REF TSRMLS_CC);
    3122             :         } else {
    3123       43414 :                 zend_compile_expr(&expr_node, expr_ast TSRMLS_CC);
    3124             :         }
    3125             : 
    3126       43662 :         zend_free_foreach_and_switch_variables(TSRMLS_C);
    3127             : 
    3128       43662 :         if (CG(context).in_finally) {
    3129           7 :                 zend_emit_op(NULL, ZEND_DISCARD_EXCEPTION, NULL, NULL TSRMLS_CC);
    3130             :         }
    3131             : 
    3132       43662 :         opline = zend_emit_op(NULL, by_ref ? ZEND_RETURN_BY_REF : ZEND_RETURN,
    3133             :                 &expr_node, NULL TSRMLS_CC);
    3134             : 
    3135       43662 :         if (expr_ast) {
    3136       43452 :                 if (zend_is_call(expr_ast)) {
    3137        8345 :                         opline->extended_value = ZEND_RETURNS_FUNCTION;
    3138       35107 :                 } else if (by_ref && !zend_is_variable(expr_ast)) {
    3139          10 :                         opline->extended_value = ZEND_RETURNS_VALUE;
    3140             :                 }
    3141             :         }
    3142       43662 : }
    3143             : /* }}} */
    3144             : 
    3145       34025 : void zend_compile_echo(zend_ast *ast TSRMLS_DC) /* {{{ */
    3146             : {
    3147       34025 :         zend_ast *expr_ast = ast->child[0];
    3148             : 
    3149             :         znode expr_node;
    3150       34025 :         zend_compile_expr(&expr_node, expr_ast TSRMLS_CC);
    3151             : 
    3152       34025 :         zend_emit_op(NULL, ZEND_ECHO, &expr_node, NULL TSRMLS_CC);
    3153       34025 : }
    3154             : /* }}} */
    3155             : 
    3156         317 : void zend_compile_throw(zend_ast *ast TSRMLS_DC) /* {{{ */
    3157             : {
    3158         317 :         zend_ast *expr_ast = ast->child[0];
    3159             : 
    3160             :         znode expr_node;
    3161         317 :         zend_compile_expr(&expr_node, expr_ast TSRMLS_CC);
    3162             : 
    3163         317 :         zend_emit_op(NULL, ZEND_THROW, &expr_node, NULL TSRMLS_CC);
    3164         317 : }
    3165             : /* }}} */
    3166             : 
    3167        2132 : void zend_compile_break_continue(zend_ast *ast TSRMLS_DC) /* {{{ */
    3168             : {
    3169        2132 :         zend_ast *depth_ast = ast->child[0];
    3170             : 
    3171             :         znode depth_node;
    3172             :         zend_op *opline;
    3173             : 
    3174             :         ZEND_ASSERT(ast->kind == ZEND_AST_BREAK || ast->kind == ZEND_AST_CONTINUE);
    3175             : 
    3176        2132 :         if (depth_ast) {
    3177          19 :                 if (depth_ast->kind != ZEND_AST_ZVAL) {
    3178           0 :                         zend_error_noreturn(E_COMPILE_ERROR, "'%s' operator with non-constant operand "
    3179           0 :                                 "is no longer supported", ast->kind == ZEND_AST_BREAK ? "break" : "continue");
    3180             :                 }
    3181             : 
    3182          19 :                 zend_compile_expr(&depth_node, depth_ast TSRMLS_CC);
    3183             : 
    3184          19 :                 if (Z_TYPE(depth_node.u.constant) != IS_LONG || Z_LVAL(depth_node.u.constant) < 1) {
    3185           0 :                         zend_error_noreturn(E_COMPILE_ERROR, "'%s' operator accepts only positive numbers",
    3186           0 :                                 ast->kind == ZEND_AST_BREAK ? "break" : "continue");
    3187             :                 }
    3188             :         } else {
    3189        2113 :                 depth_node.op_type = IS_CONST;
    3190        2113 :                 ZVAL_LONG(&depth_node.u.constant, 1);
    3191             :         }
    3192             : 
    3193        2132 :         opline = zend_emit_op(NULL, ast->kind == ZEND_AST_BREAK ? ZEND_BRK : ZEND_CONT,
    3194             :                 NULL, &depth_node TSRMLS_CC);
    3195        2132 :         opline->op1.opline_num = CG(context).current_brk_cont;
    3196        2132 : }
    3197             : /* }}} */
    3198             : 
    3199          35 : void zend_compile_goto(zend_ast *ast TSRMLS_DC) /* {{{ */
    3200             : {
    3201          35 :         zend_ast *label_ast = ast->child[0];
    3202             :         znode label_node;
    3203             :         zend_op *opline;
    3204             : 
    3205          35 :         zend_compile_expr(&label_node, label_ast TSRMLS_CC);
    3206          35 :         opline = zend_emit_op(NULL, ZEND_GOTO, NULL, &label_node TSRMLS_CC);
    3207          35 :         opline->extended_value = CG(context).current_brk_cont;
    3208          35 :         zend_resolve_goto_label(CG(active_op_array), opline, 0 TSRMLS_CC);
    3209          33 : }
    3210             : /* }}} */
    3211             : 
    3212          37 : void zend_compile_label(zend_ast *ast TSRMLS_DC) /* {{{ */
    3213             : {
    3214          74 :         zend_string *label = zend_ast_get_str(ast->child[0]);
    3215             :         zend_label dest;
    3216             : 
    3217          37 :         if (!CG(context).labels) {
    3218          24 :                 ALLOC_HASHTABLE(CG(context).labels);
    3219          24 :                 zend_hash_init(CG(context).labels, 8, NULL, ptr_dtor, 0);
    3220             :         }
    3221             : 
    3222          37 :         dest.brk_cont = CG(context).current_brk_cont;
    3223          37 :         dest.opline_num = get_next_op_number(CG(active_op_array));
    3224             : 
    3225          74 :         if (!zend_hash_add_mem(CG(context).labels, label, &dest, sizeof(zend_label))) {
    3226           1 :                 zend_error_noreturn(E_COMPILE_ERROR, "Label '%s' already defined", label->val);
    3227             :         }
    3228          36 : }
    3229             : /* }}} */
    3230             : 
    3231        1928 : void zend_compile_while(zend_ast *ast TSRMLS_DC) /* {{{ */
    3232             : {
    3233        1928 :         zend_ast *cond_ast = ast->child[0];
    3234        1928 :         zend_ast *stmt_ast = ast->child[1];
    3235             : 
    3236             :         znode cond_node;
    3237             :         uint32_t opnum_start, opnum_jmpz;
    3238             : 
    3239        1928 :         opnum_start = get_next_op_number(CG(active_op_array));
    3240        1928 :         zend_compile_expr(&cond_node, cond_ast TSRMLS_CC);
    3241             : 
    3242        1928 :         opnum_jmpz = zend_emit_cond_jump(ZEND_JMPZ, &cond_node, 0 TSRMLS_CC);
    3243        1928 :         zend_begin_loop(TSRMLS_C);
    3244             : 
    3245        1928 :         zend_compile_stmt(stmt_ast TSRMLS_CC);
    3246             : 
    3247        1928 :         zend_emit_jump(opnum_start TSRMLS_CC);
    3248             : 
    3249        1928 :         zend_update_jump_target_to_next(opnum_jmpz TSRMLS_CC);
    3250             : 
    3251        1928 :         zend_end_loop(opnum_start, 0 TSRMLS_CC);
    3252        1928 : }
    3253             : /* }}} */
    3254             : 
    3255         290 : void zend_compile_do_while(zend_ast *ast TSRMLS_DC) /* {{{ */
    3256             : {
    3257         290 :         zend_ast *stmt_ast = ast->child[0];
    3258         290 :         zend_ast *cond_ast = ast->child[1];
    3259             : 
    3260             :         znode cond_node;
    3261             :         uint32_t opnum_start, opnum_cond;
    3262             : 
    3263         290 :         zend_begin_loop(TSRMLS_C);
    3264             : 
    3265         290 :         opnum_start = get_next_op_number(CG(active_op_array));
    3266         290 :         zend_compile_stmt(stmt_ast TSRMLS_CC);
    3267             : 
    3268         290 :         opnum_cond = get_next_op_number(CG(active_op_array));
    3269         290 :         zend_compile_expr(&cond_node, cond_ast TSRMLS_CC);
    3270             : 
    3271         290 :         zend_emit_cond_jump(ZEND_JMPNZ, &cond_node, opnum_start TSRMLS_CC);
    3272             : 
    3273         290 :         zend_end_loop(opnum_cond, 0 TSRMLS_CC);
    3274         290 : }
    3275             : /* }}} */
    3276             : 
    3277        5769 : void zend_compile_expr_list(znode *result, zend_ast *ast TSRMLS_DC) /* {{{ */
    3278             : {
    3279             :         zend_ast_list *list;
    3280             :         uint32_t i;
    3281             : 
    3282        5769 :         result->op_type = IS_CONST;
    3283        5769 :         ZVAL_TRUE(&result->u.constant);
    3284             : 
    3285        5769 :         if (!ast) {
    3286           7 :                 return;
    3287             :         }
    3288             : 
    3289        5762 :         list = zend_ast_get_list(ast);
    3290       11529 :         for (i = 0; i < list->children; ++i) {
    3291        5767 :                 zend_ast *expr_ast = list->child[i];
    3292             : 
    3293        5767 :                 zend_do_free(result TSRMLS_CC);
    3294        5767 :                 zend_compile_expr(result, expr_ast TSRMLS_CC);
    3295             :         }
    3296             : }
    3297             : /* }}} */
    3298             : 
    3299        1923 : void zend_compile_for(zend_ast *ast TSRMLS_DC) /* {{{ */
    3300             : {
    3301        1923 :         zend_ast *init_ast = ast->child[0];
    3302        1923 :         zend_ast *cond_ast = ast->child[1];
    3303        1923 :         zend_ast *loop_ast = ast->child[2];
    3304        1923 :         zend_ast *stmt_ast = ast->child[3];
    3305             : 
    3306             :         znode result;
    3307             :         uint32_t opnum_cond, opnum_jmpz, opnum_loop;
    3308             : 
    3309        1923 :         zend_compile_expr_list(&result, init_ast TSRMLS_CC);
    3310        1923 :         zend_do_free(&result TSRMLS_CC);
    3311             : 
    3312        1923 :         opnum_cond = get_next_op_number(CG(active_op_array));
    3313        1923 :         zend_compile_expr_list(&result, cond_ast TSRMLS_CC);
    3314        1923 :         zend_do_extended_info(TSRMLS_C);
    3315             : 
    3316        1923 :         opnum_jmpz = zend_emit_cond_jump(ZEND_JMPZ, &result, 0 TSRMLS_CC);
    3317        1923 :         zend_begin_loop(TSRMLS_C);
    3318             : 
    3319        1923 :         zend_compile_stmt(stmt_ast TSRMLS_CC);
    3320             : 
    3321        1923 :         opnum_loop = get_next_op_number(CG(active_op_array));
    3322        1923 :         zend_compile_expr_list(&result, loop_ast TSRMLS_CC);
    3323        1923 :         zend_do_free(&result TSRMLS_CC);
    3324             : 
    3325        1923 :         zend_emit_jump(opnum_cond TSRMLS_CC);
    3326             : 
    3327        1923 :         zend_update_jump_target_to_next(opnum_jmpz TSRMLS_CC);
    3328             : 
    3329        1923 :         zend_end_loop(opnum_loop, 0 TSRMLS_CC);
    3330        1923 : }
    3331             : /* }}} */
    3332             : 
    3333        9756 : void zend_compile_foreach(zend_ast *ast TSRMLS_DC) /* {{{ */
    3334             : {
    3335        9756 :         zend_ast *expr_ast = ast->child[0];
    3336        9756 :         zend_ast *value_ast = ast->child[1];
    3337        9756 :         zend_ast *key_ast = ast->child[2];
    3338        9756 :         zend_ast *stmt_ast = ast->child[3];
    3339        9756 :         zend_bool by_ref = value_ast->kind == ZEND_AST_REF;
    3340       17815 :         zend_bool is_variable = zend_is_variable(expr_ast) && !zend_is_call(expr_ast)
    3341       17815 :                 && zend_can_write_to_variable(expr_ast);
    3342             : 
    3343             :         znode expr_node, reset_node, value_node, key_node;
    3344             :         zend_op *opline;
    3345             :         uint32_t opnum_reset, opnum_fetch;
    3346             : 
    3347        9756 :         if (key_ast) {
    3348        4648 :                 if (key_ast->kind == ZEND_AST_REF) {
    3349           2 :                         zend_error_noreturn(E_COMPILE_ERROR, "Key element cannot be a reference");
    3350             :                 }
    3351        4646 :                 if (key_ast->kind == ZEND_AST_LIST) {
    3352           1 :                         zend_error_noreturn(E_COMPILE_ERROR, "Cannot use list as key element");
    3353             :                 }
    3354             :         }
    3355             : 
    3356        9753 :         if (by_ref) {
    3357          77 :                 value_ast = value_ast->child[0];
    3358             :         }
    3359             : 
    3360        9826 :         if (by_ref && is_variable) {
    3361          73 :                 zend_compile_var(&expr_node, expr_ast, BP_VAR_W TSRMLS_CC);
    3362             :         } else {
    3363        9680 :                 zend_compile_expr(&expr_node, expr_ast TSRMLS_CC);
    3364             :         }
    3365             : 
    3366        9750 :         if (by_ref) {
    3367          77 :                 zend_separate_if_call_and_write(&expr_node, expr_ast, BP_VAR_W TSRMLS_CC);
    3368             :         }
    3369             : 
    3370        9750 :         opnum_reset = get_next_op_number(CG(active_op_array));
    3371        9750 :         opline = zend_emit_op(&reset_node, ZEND_FE_RESET, &expr_node, NULL TSRMLS_CC);
    3372        9750 :         if (by_ref && is_variable) {
    3373          73 :                 opline->extended_value = ZEND_FE_FETCH_BYREF;
    3374             :         }
    3375             : 
    3376        9750 :         zend_stack_push(&CG(loop_var_stack), &reset_node);
    3377             : 
    3378        9750 :         opnum_fetch = get_next_op_number(CG(active_op_array));
    3379        9750 :         opline = zend_emit_op(&value_node, ZEND_FE_FETCH, &reset_node, NULL TSRMLS_CC);
    3380        9750 :         if (by_ref) {
    3381          77 :                 opline->extended_value |= ZEND_FE_FETCH_BYREF;
    3382             :         }
    3383        9750 :         if (key_ast) {
    3384        4645 :                 opline->extended_value |= ZEND_FE_FETCH_WITH_KEY;
    3385             :         }
    3386             : 
    3387        9750 :         opline = zend_emit_op(NULL, ZEND_OP_DATA, NULL, NULL TSRMLS_CC);
    3388             : 
    3389             :         /* Allocate enough space to keep HashPointer on VM stack */
    3390        9750 :         opline->op1_type = IS_TMP_VAR;
    3391        9750 :         opline->op1.var = get_temporary_variable(CG(active_op_array));
    3392             :         if (sizeof(HashPointer) > sizeof(zval)) {
    3393             :                 /* Make sure 1 zval is enough for HashPointer (2 must be enough) */
    3394        9750 :                 get_temporary_variable(CG(active_op_array));
    3395             :         }
    3396             : 
    3397        9750 :         if (key_ast) {
    3398        4645 :                 zend_make_tmp_result(&key_node, opline TSRMLS_CC);
    3399             :         }
    3400             : 
    3401        9750 :         if (by_ref) {
    3402          77 :                 zend_emit_assign_ref_znode(value_ast, &value_node TSRMLS_CC);
    3403             :         } else {
    3404        9673 :                 zend_emit_assign_znode(value_ast, &value_node TSRMLS_CC);
    3405             :         }
    3406             : 
    3407        9749 :         if (key_ast) {
    3408        4644 :                 zend_emit_assign_znode(key_ast, &key_node TSRMLS_CC);
    3409             :         }
    3410             : 
    3411        9749 :         zend_begin_loop(TSRMLS_C);
    3412             : 
    3413        9749 :         zend_compile_stmt(stmt_ast TSRMLS_CC);
    3414             : 
    3415        9749 :         zend_emit_jump(opnum_fetch TSRMLS_CC);
    3416             : 
    3417        9749 :         opline = &CG(active_op_array)->opcodes[opnum_reset];
    3418        9749 :         opline->op2.opline_num = get_next_op_number(CG(active_op_array));
    3419             : 
    3420        9749 :         opline = &CG(active_op_array)->opcodes[opnum_fetch];
    3421        9749 :         opline->op2.opline_num = get_next_op_number(CG(active_op_array));
    3422             : 
    3423        9749 :         zend_end_loop(opnum_fetch, 1 TSRMLS_CC);
    3424             : 
    3425        9749 :         generate_free_loop_var(&reset_node TSRMLS_CC);
    3426        9749 :         zend_stack_del_top(&CG(loop_var_stack));
    3427        9749 : }
    3428             : /* }}} */
    3429             : 
    3430       68601 : void zend_compile_if(zend_ast *ast TSRMLS_DC) /* {{{ */
    3431             : {
    3432       68601 :         zend_ast_list *list = zend_ast_get_list(ast);
    3433             :         uint32_t i;
    3434             :         uint32_t *jmp_opnums;
    3435             :         
    3436       68601 :         if (list->children > 1) {
    3437       17883 :                 jmp_opnums = safe_emalloc(sizeof(uint32_t), list->children - 1, 0);
    3438             :         }
    3439             : 
    3440      155914 :         for (i = 0; i < list->children; ++i) {
    3441       87313 :                 zend_ast *elem_ast = list->child[i];
    3442       87313 :                 zend_ast *cond_ast = elem_ast->child[0];
    3443       87313 :                 zend_ast *stmt_ast = elem_ast->child[1];
    3444             : 
    3445             :                 znode cond_node;
    3446             :                 uint32_t opnum_jmpz;
    3447       87313 :                 if (cond_ast) {
    3448       70330 :                         zend_compile_expr(&cond_node, cond_ast TSRMLS_CC);
    3449       70330 :                         opnum_jmpz = zend_emit_cond_jump(ZEND_JMPZ, &cond_node, 0 TSRMLS_CC);
    3450             :                 }
    3451             : 
    3452       87313 :                 zend_compile_stmt(stmt_ast TSRMLS_CC);
    3453             : 
    3454       87313 :                 if (i != list->children - 1) {
    3455       18712 :                         jmp_opnums[i] = zend_emit_jump(0 TSRMLS_CC);
    3456             :                 }
    3457             : 
    3458       87313 :                 if (cond_ast) {
    3459       70330 :                         zend_update_jump_target_to_next(opnum_jmpz TSRMLS_CC);
    3460             :                 }
    3461             :         }
    3462             : 
    3463       68601 :         if (list->children > 1) {
    3464       36595 :                 for (i = 0; i < list->children - 1; ++i) {
    3465       18712 :                         zend_update_jump_target_to_next(jmp_opnums[i] TSRMLS_CC);
    3466             :                 }
    3467       17883 :                 efree(jmp_opnums);
    3468             :         }
    3469       68601 : }
    3470             : /* }}} */
    3471             : 
    3472         450 : void zend_compile_switch(zend_ast *ast TSRMLS_DC) /* {{{ */
    3473             : {
    3474         450 :         zend_ast *expr_ast = ast->child[0];
    3475         900 :         zend_ast_list *cases = zend_ast_get_list(ast->child[1]);
    3476             : 
    3477             :         uint32_t i;
    3478         450 :         zend_bool has_default_case = 0;
    3479             : 
    3480             :         znode expr_node, case_node;
    3481             :         zend_op *opline;
    3482         450 :         uint32_t *jmpnz_opnums = safe_emalloc(sizeof(uint32_t), cases->children, 0);
    3483             :         uint32_t opnum_default_jmp;
    3484             : 
    3485         450 :         zend_compile_expr(&expr_node, expr_ast TSRMLS_CC);
    3486             : 
    3487         450 :         zend_stack_push(&CG(loop_var_stack), &expr_node);
    3488             : 
    3489         450 :         zend_begin_loop(TSRMLS_C);
    3490             : 
    3491         450 :         case_node.op_type = IS_TMP_VAR;
    3492         450 :         case_node.u.op.var = get_temporary_variable(CG(active_op_array));
    3493             : 
    3494        2306 :         for (i = 0; i < cases->children; ++i) {
    3495        1857 :                 zend_ast *case_ast = cases->child[i];
    3496        1857 :                 zend_ast *cond_ast = case_ast->child[0];
    3497             :                 znode cond_node;
    3498             : 
    3499        1857 :                 if (!cond_ast) {
    3500         266 :                         if (has_default_case) {
    3501           1 :                                 CG(zend_lineno) = case_ast->lineno;
    3502           1 :                                 zend_error_noreturn(E_COMPILE_ERROR,
    3503             :                                         "Switch statements may only contain one default clause");
    3504             :                         }
    3505         265 :                         has_default_case = 1;
    3506         265 :                         continue;
    3507             :                 }
    3508             : 
    3509        1591 :                 zend_compile_expr(&cond_node, cond_ast TSRMLS_CC);
    3510             : 
    3511        1591 :                 opline = zend_emit_op(NULL, ZEND_CASE, &expr_node, &cond_node TSRMLS_CC);
    3512        1591 :                 SET_NODE(opline->result, &case_node);
    3513        1591 :                 if (opline->op1_type == IS_CONST) {
    3514          14 :                         zval_copy_ctor(&CONSTANT(opline->op1.constant));
    3515             :                 }
    3516             : 
    3517        1591 :                 jmpnz_opnums[i] = zend_emit_cond_jump(ZEND_JMPNZ, &case_node, 0 TSRMLS_CC);
    3518             :         }
    3519             : 
    3520         449 :         opnum_default_jmp = zend_emit_jump(0 TSRMLS_CC);
    3521             : 
    3522        2302 :         for (i = 0; i < cases->children; ++i) {
    3523        1853 :                 zend_ast *case_ast = cases->child[i];
    3524        1853 :                 zend_ast *cond_ast = case_ast->child[0];
    3525        1853 :                 zend_ast *stmt_ast = case_ast->child[1];
    3526             : 
    3527        1853 :                 if (cond_ast) {
    3528        1589 :                         zend_update_jump_target_to_next(jmpnz_opnums[i] TSRMLS_CC);
    3529             :                 } else {
    3530         264 :                         zend_update_jump_target_to_next(opnum_default_jmp TSRMLS_CC);
    3531             :                 }
    3532             : 
    3533        1853 :                 zend_compile_stmt(stmt_ast TSRMLS_CC);
    3534             :         }
    3535             : 
    3536         449 :         if (!has_default_case) {
    3537         185 :                 zend_update_jump_target_to_next(opnum_default_jmp TSRMLS_CC);
    3538             :         }
    3539             : 
    3540         449 :         zend_end_loop(get_next_op_number(CG(active_op_array)), 1 TSRMLS_CC);
    3541             : 
    3542         556 :         if (expr_node.op_type == IS_VAR || expr_node.op_type == IS_TMP_VAR) {
    3543         107 :                 zend_emit_op(NULL, ZEND_FREE,
    3544             :                         &expr_node, NULL TSRMLS_CC);
    3545         342 :         } else if (expr_node.op_type == IS_CONST) {
    3546             :                 zval_dtor(&expr_node.u.constant);
    3547             :         }
    3548             : 
    3549         449 :         zend_stack_del_top(&CG(loop_var_stack));
    3550         449 :         efree(jmpnz_opnums);
    3551         449 : }
    3552             : /* }}} */
    3553             : 
    3554        1998 : void zend_compile_try(zend_ast *ast TSRMLS_DC) /* {{{ */
    3555             : {
    3556        1998 :         zend_ast *try_ast = ast->child[0];
    3557        3996 :         zend_ast_list *catches = zend_ast_get_list(ast->child[1]);
    3558        1998 :         zend_ast *finally_ast = ast->child[2];
    3559             : 
    3560             :         uint32_t i;
    3561             :         zend_op *opline;
    3562        1998 :         uint32_t try_catch_offset = zend_add_try_element(
    3563        3996 :                 get_next_op_number(CG(active_op_array)) TSRMLS_CC);
    3564        1998 :         uint32_t *jmp_opnums = safe_emalloc(sizeof(uint32_t), catches->children, 0);
    3565             : 
    3566        1998 :         if (catches->children == 0 && !finally_ast) {
    3567           1 :                 zend_error_noreturn(E_COMPILE_ERROR, "Cannot use try without catch or finally");
    3568             :         }
    3569             : 
    3570        1997 :         zend_compile_stmt(try_ast TSRMLS_CC);
    3571             : 
    3572        1997 :         if (catches->children != 0) {
    3573        1953 :                 jmp_opnums[0] = zend_emit_jump(0 TSRMLS_CC);
    3574             :         }
    3575             : 
    3576        3961 :         for (i = 0; i < catches->children; ++i) {
    3577        1964 :                 zend_ast *catch_ast = catches->child[i];
    3578        1964 :                 zend_ast *class_ast = catch_ast->child[0];
    3579        1964 :                 zend_ast *var_ast = catch_ast->child[1];
    3580        1964 :                 zend_ast *stmt_ast = catch_ast->child[2];
    3581        1964 :                 zval *var_name = zend_ast_get_zval(var_ast);
    3582        1964 :                 zend_bool is_last_catch = (i + 1 == catches->children);
    3583             : 
    3584             :                 uint32_t opnum_catch;
    3585             : 
    3586        1964 :                 if (!zend_is_const_default_class_ref(class_ast)) {
    3587           0 :                         zend_error_noreturn(E_COMPILE_ERROR, "Bad class name in the catch statement");
    3588             :                 }
    3589             : 
    3590        1964 :                 opnum_catch = get_next_op_number(CG(active_op_array));
    3591        1964 :                 if (i == 0) {
    3592        1953 :                         CG(active_op_array)->try_catch_array[try_catch_offset].catch_op = opnum_catch;
    3593             :                 }
    3594             : 
    3595        1964 :                 CG(zend_lineno) = catch_ast->lineno;
    3596             : 
    3597        1964 :                 opline = get_next_op(CG(active_op_array) TSRMLS_CC);
    3598        1964 :                 opline->opcode = ZEND_CATCH;
    3599        1964 :                 opline->op1_type = IS_CONST;
    3600        1964 :                 opline->op1.constant = zend_add_class_name_literal(CG(active_op_array),
    3601             :                         zend_resolve_class_name_ast(class_ast TSRMLS_CC) TSRMLS_CC);
    3602             : 
    3603        1964 :                 opline->op2_type = IS_CV;
    3604        3928 :                 opline->op2.var = lookup_cv(CG(active_op_array), zend_string_copy(Z_STR_P(var_name)) TSRMLS_CC);
    3605        1964 :                 opline->result.num = is_last_catch;
    3606             : 
    3607        1964 :                 zend_compile_stmt(stmt_ast TSRMLS_CC);
    3608             : 
    3609        1964 :                 if (!is_last_catch) {
    3610          11 :                         jmp_opnums[i + 1] = zend_emit_jump(0 TSRMLS_CC);
    3611             :                 }
    3612             : 
    3613        1964 :                 opline = &CG(active_op_array)->opcodes[opnum_catch];
    3614        1964 :                 opline->extended_value = get_next_op_number(CG(active_op_array));
    3615             :         }
    3616             : 
    3617        3961 :         for (i = 0; i < catches->children; ++i) {
    3618        1964 :                 zend_update_jump_target_to_next(jmp_opnums[i] TSRMLS_CC);
    3619             :         }
    3620             : 
    3621        1997 :         if (finally_ast) {
    3622          70 :                 uint32_t opnum_jmp = get_next_op_number(CG(active_op_array)) + 1;
    3623             : 
    3624          70 :                 opline = zend_emit_op(NULL, ZEND_FAST_CALL, NULL, NULL TSRMLS_CC);
    3625          70 :                 opline->op1.opline_num = opnum_jmp + 1;
    3626             : 
    3627          70 :                 zend_emit_op(NULL, ZEND_JMP, NULL, NULL TSRMLS_CC);
    3628             : 
    3629          70 :                 CG(context).in_finally++;
    3630          70 :                 zend_compile_stmt(finally_ast TSRMLS_CC);
    3631          70 :                 CG(context).in_finally--;
    3632             : 
    3633          70 :                 CG(active_op_array)->try_catch_array[try_catch_offset].finally_op = opnum_jmp + 1;
    3634         140 :                 CG(active_op_array)->try_catch_array[try_catch_offset].finally_end
    3635          70 :                         = get_next_op_number(CG(active_op_array));
    3636          70 :                 CG(active_op_array)->fn_flags |= ZEND_ACC_HAS_FINALLY_BLOCK;
    3637             : 
    3638          70 :                 zend_emit_op(NULL, ZEND_FAST_RET, NULL, NULL TSRMLS_CC);
    3639             : 
    3640          70 :                 zend_update_jump_target_to_next(opnum_jmp TSRMLS_CC);
    3641             :         }
    3642             : 
    3643        1997 :         efree(jmp_opnums);
    3644        1997 : }
    3645             : /* }}} */
    3646             : 
    3647             : /* Encoding declarations must already be handled during parsing */
    3648          25 : void zend_handle_encoding_declaration(zend_ast *ast TSRMLS_DC) /* {{{ */
    3649             : {
    3650          25 :         zend_ast_list *declares = zend_ast_get_list(ast);
    3651             :         uint32_t i;
    3652          48 :         for (i = 0; i < declares->children; ++i) {
    3653          25 :                 zend_ast *declare_ast = declares->child[i];
    3654          25 :                 zend_ast *name_ast = declare_ast->child[0];
    3655          25 :                 zend_ast *value_ast = declare_ast->child[1];
    3656          25 :                 zend_string *name = zend_ast_get_str(name_ast);
    3657             : 
    3658          25 :                 if (zend_string_equals_literal_ci(name, "encoding")) {
    3659          19 :                         if (value_ast->kind != ZEND_AST_ZVAL) {
    3660           2 :                                 zend_error_noreturn(E_COMPILE_ERROR, "Encoding must be a literal");
    3661             :                         }
    3662             : 
    3663          17 :                         if (CG(multibyte)) {
    3664          17 :                                 zend_string *encoding_name = zval_get_string(zend_ast_get_zval(value_ast));
    3665             : 
    3666             :                                 const zend_encoding *new_encoding, *old_encoding;
    3667             :                                 zend_encoding_filter old_input_filter;
    3668             : 
    3669          17 :                                 CG(encoding_declared) = 1;
    3670             : 
    3671          17 :                                 new_encoding = zend_multibyte_fetch_encoding(encoding_name->val TSRMLS_CC);
    3672          17 :                                 if (!new_encoding) {
    3673           4 :                                         zend_error(E_COMPILE_WARNING, "Unsupported encoding [%s]", encoding_name->val);
    3674             :                                 } else {
    3675          13 :                                         old_input_filter = LANG_SCNG(input_filter);
    3676          13 :                                         old_encoding = LANG_SCNG(script_encoding);
    3677          13 :                                         zend_multibyte_set_filter(new_encoding TSRMLS_CC);
    3678             : 
    3679             :                                         /* need to re-scan if input filter changed */
    3680          13 :                                         if (old_input_filter != LANG_SCNG(input_filter) ||
    3681             :                                                  (old_input_filter && new_encoding != old_encoding)) {
    3682          10 :                                                 zend_multibyte_yyinput_again(old_input_filter, old_encoding TSRMLS_CC);
    3683             :                                         }
    3684             :                                 }
    3685             : 
    3686             :                                 zend_string_release(encoding_name);
    3687             :                         } else {
    3688           0 :                                 zend_error(E_COMPILE_WARNING, "declare(encoding=...) ignored because "
    3689             :                                         "Zend multibyte feature is turned off by settings");
    3690             :                         }
    3691             :                 }
    3692             :         }
    3693          23 : }
    3694             : /* }}} */
    3695             : 
    3696          18 : void zend_compile_declare(zend_ast *ast TSRMLS_DC) /* {{{ */
    3697             : {
    3698          36 :         zend_ast_list *declares = zend_ast_get_list(ast->child[0]);
    3699          18 :         zend_ast *stmt_ast = ast->child[1];
    3700          18 :         zend_declarables orig_declarables = CG(declarables);
    3701             :         uint32_t i;
    3702             : 
    3703          35 :         for (i = 0; i < declares->children; ++i) {
    3704          18 :                 zend_ast *declare_ast = declares->child[i];
    3705          18 :                 zend_ast *name_ast = declare_ast->child[0];
    3706          18 :                 zend_ast *value_ast = declare_ast->child[1];
    3707             : 
    3708          18 :                 zend_string *name = zend_ast_get_str(name_ast);
    3709          24 :                 if (zend_string_equals_literal_ci(name, "ticks")) {
    3710             :                         zval value_zv;
    3711           6 :                         zend_const_expr_to_zval(&value_zv, value_ast TSRMLS_CC);
    3712           6 :                         convert_to_long(&value_zv);
    3713           6 :                         ZVAL_COPY_VALUE(&CG(declarables).ticks, &value_zv);
    3714             :                         zval_dtor(&value_zv);
    3715          23 :                 } else if (zend_string_equals_literal_ci(name, "encoding")) {
    3716             :                         /* Encoding declaration was already handled during parsing. Here we
    3717             :                          * only check that it is the first statement in the file. */
    3718          12 :                         uint32_t num = CG(active_op_array)->last;
    3719          26 :                         while (num > 0 &&
    3720           1 :                                    (CG(active_op_array)->opcodes[num-1].opcode == ZEND_EXT_STMT ||
    3721           1 :                                         CG(active_op_array)->opcodes[num-1].opcode == ZEND_TICKS)) {
    3722           0 :                                 --num;
    3723             :                         }
    3724             : 
    3725          12 :                         if (num > 0) {
    3726           1 :                                 zend_error_noreturn(E_COMPILE_ERROR, "Encoding declaration pragma must be "
    3727             :                                         "the very first statement in the script");
    3728             :                         }
    3729             :                 } else {
    3730           0 :                         zend_error(E_COMPILE_WARNING, "Unsupported declare '%s'", name->val);
    3731             :                 }
    3732             :         }
    3733             : 
    3734          17 :         if (stmt_ast) {
    3735           3 :                 zend_compile_stmt(stmt_ast TSRMLS_CC);
    3736             : 
    3737           3 :                 CG(declarables) = orig_declarables;
    3738             :         }
    3739          17 : }
    3740             : /* }}} */
    3741             : 
    3742      134411 : void zend_compile_stmt_list(zend_ast *ast TSRMLS_DC) /* {{{ */
    3743             : {
    3744      134411 :         zend_ast_list *list = zend_ast_get_list(ast);
    3745             :         uint32_t i;
    3746      402595 :         for (i = 0; i < list->children; ++i) {
    3747      268239 :                 zend_compile_stmt(list->child[i] TSRMLS_CC);
    3748             :         }
    3749      134356 : }
    3750             : /* }}} */
    3751             : 
    3752       35301 : void zend_compile_params(zend_ast *ast TSRMLS_DC) /* {{{ */
    3753             : {
    3754       35301 :         zend_ast_list *list = zend_ast_get_list(ast);
    3755             :         uint32_t i;
    3756       35301 :         zend_op_array *op_array = CG(active_op_array);
    3757             :         zend_arg_info *arg_infos;
    3758             : 
    3759       35301 :         if (list->children == 0) {
    3760        9009 :                 return;
    3761             :         }
    3762             :         
    3763       26292 :         arg_infos = safe_emalloc(sizeof(zend_arg_info), list->children, 0);
    3764      109158 :         for (i = 0; i < list->children; ++i) {
    3765       82876 :                 zend_ast *param_ast = list->child[i];
    3766       82876 :                 zend_ast *type_ast = param_ast->child[0];
    3767       82876 :                 zend_ast *var_ast = param_ast->child[1];
    3768       82876 :                 zend_ast *default_ast = param_ast->child[2];
    3769       82876 :                 zend_string *name = zend_ast_get_str(var_ast);
    3770       82876 :                 zend_bool is_ref = (param_ast->attr & ZEND_PARAM_REF) != 0;
    3771       82876 :                 zend_bool is_variadic = (param_ast->attr & ZEND_PARAM_VARIADIC) != 0;
    3772             : 
    3773             :                 znode var_node, default_node;
    3774             :                 zend_uchar opcode;
    3775             :                 zend_op *opline;
    3776             :                 zend_arg_info *arg_info;
    3777             : 
    3778       82876 :                 if (zend_is_auto_global(name TSRMLS_CC)) {
    3779           0 :                         zend_error_noreturn(E_COMPILE_ERROR, "Cannot re-assign auto-global variable %s",
    3780             :                                 name->val);
    3781             :                 }
    3782             : 
    3783       82876 :                 var_node.op_type = IS_CV;
    3784       82876 :                 var_node.u.op.var = lookup_cv(CG(active_op_array), zend_string_copy(name) TSRMLS_CC);
    3785             : 
    3786       82876 :                 if (EX_VAR_TO_NUM(var_node.u.op.var) != i) {
    3787           2 :                         zend_error_noreturn(E_COMPILE_ERROR, "Redefinition of parameter $%s",
    3788             :                                 name->val);
    3789       82874 :                 } else if (zend_string_equals_literal(name, "this")) {
    3790           2 :                         if (op_array->scope && (op_array->fn_flags & ZEND_ACC_STATIC) == 0) {
    3791           1 :                                 zend_error_noreturn(E_COMPILE_ERROR, "Cannot re-assign $this");
    3792             :                         }
    3793           1 :                         op_array->this_var = var_node.u.op.var;
    3794             :                 }
    3795             : 
    3796       82873 :                 if (op_array->fn_flags & ZEND_ACC_VARIADIC) {
    3797           1 :                         zend_error_noreturn(E_COMPILE_ERROR, "Only the last parameter can be variadic");
    3798             :                 }
    3799             : 
    3800       82872 :                 if (is_variadic) {
    3801          38 :                         opcode = ZEND_RECV_VARIADIC;
    3802          38 :                         default_node.op_type = IS_UNUSED;
    3803          38 :                         op_array->fn_flags |= ZEND_ACC_VARIADIC;
    3804             : 
    3805          38 :                         if (default_ast) {
    3806           1 :                                 zend_error_noreturn(E_COMPILE_ERROR,
    3807             :                                         "Variadic parameter cannot have a default value");
    3808             :                         }
    3809       82834 :                 } else if (default_ast) {
    3810       14250 :                         opcode = ZEND_RECV_INIT;
    3811       14250 :                         default_node.op_type = IS_CONST;
    3812       14250 :                         zend_const_expr_to_zval(&default_node.u.constant, default_ast TSRMLS_CC);
    3813             :                 } else {
    3814       68584 :                         opcode = ZEND_RECV;
    3815       68584 :                         default_node.op_type = IS_UNUSED;
    3816       68584 :                         op_array->required_num_args = i + 1;
    3817             :                 }
    3818             : 
    3819       82869 :                 opline = zend_emit_op(NULL, opcode, NULL, &default_node TSRMLS_CC);
    3820       82869 :                 SET_NODE(opline->result, &var_node);
    3821       82869 :                 opline->op1.num = i + 1;
    3822             : 
    3823       82869 :                 arg_info = &arg_infos[i];
    3824       82869 :                 arg_info->name = estrndup(name->val, name->len);
    3825       82869 :                 arg_info->name_len = (uint32_t)name->len;
    3826       82869 :                 arg_info->pass_by_reference = is_ref;
    3827       82869 :                 arg_info->is_variadic = is_variadic;
    3828       82869 :                 arg_info->type_hint = 0;
    3829       82869 :                 arg_info->allow_null = 1;
    3830       82869 :                 arg_info->class_name = NULL;
    3831       82869 :                 arg_info->class_name_len = 0;
    3832             : 
    3833       82869 :                 if (type_ast) {
    3834         453 :                         zend_bool has_null_default = default_ast
    3835             :                                 && (Z_TYPE(default_node.u.constant) == IS_NULL
    3836             :                                         || (Z_TYPE(default_node.u.constant) == IS_CONSTANT
    3837           0 :                                                 && strcasecmp(Z_STRVAL(default_node.u.constant), "NULL") == 0)
    3838         402 :                                         || Z_TYPE(default_node.u.constant) == IS_CONSTANT_AST); // ???
    3839             : 
    3840         402 :                         op_array->fn_flags |= ZEND_ACC_HAS_TYPE_HINTS;
    3841         402 :                         arg_info->allow_null = has_null_default;
    3842             : 
    3843         402 :                         if (type_ast->kind == ZEND_AST_TYPE) {
    3844         228 :                                 arg_info->type_hint = type_ast->attr;
    3845         228 :                                 if (arg_info->type_hint == IS_ARRAY) {
    3846         227 :                                         if (default_ast && !has_null_default
    3847             :                                                 && Z_TYPE(default_node.u.constant) != IS_ARRAY
    3848             :                                         ) {
    3849           1 :                                                 zend_error_noreturn(E_COMPILE_ERROR, "Default value for parameters "
    3850             :                                                         "with array type hint can only be an array or NULL");
    3851             :                                         }
    3852           8 :                                 } else if (arg_info->type_hint == IS_CALLABLE && default_ast) {
    3853           1 :                                         if (!has_null_default) {
    3854           0 :                                                 zend_error_noreturn(E_COMPILE_ERROR, "Default value for parameters "
    3855             :                                                         "with callable type hint can only be NULL");
    3856             :                                         }
    3857             :                                 }
    3858             :                         } else {
    3859         174 :                                 zend_string *class_name = zend_ast_get_str(type_ast);
    3860             : 
    3861         174 :                                 if (zend_is_const_default_class_ref(type_ast)) {
    3862         161 :                                         class_name = zend_resolve_class_name_ast(type_ast TSRMLS_CC);
    3863             :                                 } else {
    3864             :                                         zend_string_addref(class_name);
    3865             :                                 }
    3866             : 
    3867         173 :                                 arg_info->type_hint = IS_OBJECT;
    3868         173 :                                 arg_info->class_name = estrndup(class_name->val, class_name->len);
    3869         173 :                                 arg_info->class_name_len = (uint32_t)class_name->len;
    3870             : 
    3871             :                                 zend_string_release(class_name);
    3872             : 
    3873         173 :                                 if (default_ast && !has_null_default) {
    3874           1 :                                                 zend_error_noreturn(E_COMPILE_ERROR, "Default value for parameters "
    3875             :                                                         "with a class type hint can only be NULL");
    3876             :                                 }
    3877             :                         }
    3878             :                 }
    3879             :         }
    3880             : 
    3881             :         /* These are assigned at the end to avoid unitialized memory in case of an error */
    3882       26282 :         op_array->num_args = list->children;
    3883       26282 :         op_array->arg_info = arg_infos;
    3884             : }
    3885             : /* }}} */
    3886             : 
    3887         146 : void zend_compile_closure_uses(zend_ast *ast TSRMLS_DC) /* {{{ */
    3888             : {
    3889         146 :         zend_ast_list *list = zend_ast_get_list(ast);
    3890             :         uint32_t i;
    3891             : 
    3892         298 :         for (i = 0; i < list->children; ++i) {
    3893         153 :                 zend_ast *var_ast = list->child[i];
    3894         153 :                 zend_string *name = zend_ast_get_str(var_ast);
    3895         153 :                 zend_bool by_ref = var_ast->attr;
    3896             :                 zval zv;
    3897             : 
    3898         153 :                 if (zend_string_equals_literal(name, "this")) {
    3899           1 :                         zend_error_noreturn(E_COMPILE_ERROR, "Cannot use $this as lexical variable");
    3900             :                 }
    3901             : 
    3902         152 :                 ZVAL_NULL(&zv);
    3903         152 :                 Z_CONST_FLAGS(zv) = by_ref ? IS_LEXICAL_REF : IS_LEXICAL_VAR;
    3904             : 
    3905         152 :                 zend_compile_static_var_common(var_ast, &zv, by_ref TSRMLS_CC);
    3906             :         }
    3907         145 : }
    3908             : /* }}} */
    3909             : 
    3910       17131 : void zend_begin_method_decl(zend_op_array *op_array, zend_string *name, zend_bool has_body TSRMLS_DC) /* {{{ */
    3911             : {
    3912       17131 :         zend_class_entry *ce = CG(active_class_entry);
    3913       17131 :         zend_bool in_interface = (ce->ce_flags & ZEND_ACC_INTERFACE) != 0;
    3914       17131 :         zend_bool in_trait = ZEND_CE_IS_TRAIT(ce);
    3915       17131 :         zend_bool is_public = (op_array->fn_flags & ZEND_ACC_PUBLIC) != 0;
    3916       17131 :         zend_bool is_static = (op_array->fn_flags & ZEND_ACC_STATIC) != 0;
    3917             : 
    3918             :         zend_string *lcname;
    3919             : 
    3920       17131 :         if (in_interface) {
    3921         103 :                 if ((op_array->fn_flags & ZEND_ACC_PPP_MASK) != ZEND_ACC_PUBLIC) {
    3922           2 :                         zend_error_noreturn(E_COMPILE_ERROR, "Access type for interface method "
    3923           1 :                                 "%s::%s() must be omitted", ce->name->val, name->val);
    3924             :                 }
    3925         102 :                 op_array->fn_flags |= ZEND_ACC_ABSTRACT;
    3926       17028 :         } else if (is_static && (op_array->fn_flags & ZEND_ACC_ABSTRACT)) {
    3927           8 :                 zend_error(E_STRICT, "Static function %s::%s() should not be abstract",
    3928           4 :                         ce->name->val, name->val);
    3929             :         }
    3930             : 
    3931       17130 :         if (op_array->fn_flags & ZEND_ACC_ABSTRACT) {
    3932         168 :                 if (op_array->fn_flags & ZEND_ACC_PRIVATE) {
    3933           2 :                         zend_error_noreturn(E_COMPILE_ERROR, "%s function %s::%s() cannot be declared private",
    3934           1 :                                 in_interface ? "Interface" : "Abstract", ce->name->val, name->val);
    3935             :                 }
    3936             : 
    3937         167 :                 if (has_body) {
    3938           2 :                         zend_error_noreturn(E_COMPILE_ERROR, "%s function %s::%s() cannot contain body",
    3939           1 :                                 in_interface ? "Interface" : "Abstract", ce->name->val, name->val);
    3940             :                 }
    3941             : 
    3942         166 :                 ce->ce_flags |= ZEND_ACC_IMPLICIT_ABSTRACT_CLASS;
    3943       16962 :         } else if (!has_body) {
    3944           2 :                 zend_error_noreturn(E_COMPILE_ERROR, "Non-abstract method %s::%s() must contain body",
    3945           1 :                         ce->name->val, name->val);
    3946             :         }
    3947             : 
    3948       17127 :         op_array->scope = ce;
    3949       17127 :         op_array->function_name = zend_string_copy(name);
    3950             : 
    3951       34254 :         lcname = zend_string_alloc(name->len, 0);
    3952       17127 :         zend_str_tolower_copy(lcname->val, name->val, name->len);
    3953       17127 :         lcname = zend_new_interned_string(lcname TSRMLS_CC);
    3954             : 
    3955       34254 :         if (zend_hash_add_ptr(&ce->function_table, lcname, op_array) == NULL) {
    3956           2 :                 zend_error_noreturn(E_COMPILE_ERROR, "Cannot redeclare %s::%s()",
    3957           1 :                         ce->name->val, name->val);
    3958             :         }
    3959             : 
    3960       17126 :         if (in_interface) {
    3961         102 :                 if (zend_string_equals_literal(lcname, ZEND_CALL_FUNC_NAME)) {
    3962           1 :                         if (!is_public || is_static) {
    3963           1 :                                 zend_error(E_WARNING, "The magic method __call() must have "
    3964             :                                         "public visibility and cannot be static");
    3965             :                         }
    3966         101 :                 } else if (zend_string_equals_literal(lcname, ZEND_CALLSTATIC_FUNC_NAME)) {
    3967           1 :                         if (!is_public || !is_static) {
    3968           1 :                                 zend_error(E_WARNING, "The magic method __callStatic() must have "
    3969             :                                         "public visibility and be static");
    3970             :                         }
    3971          99 :                 } else if (zend_string_equals_literal(lcname, ZEND_GET_FUNC_NAME)) {
    3972           0 :                         if (!is_public || is_static) {
    3973           0 :                                 zend_error(E_WARNING, "The magic method __get() must have "
    3974             :                                         "public visibility and cannot be static");
    3975             :                         }
    3976          99 :                 } else if (zend_string_equals_literal(lcname, ZEND_SET_FUNC_NAME)) {
    3977           0 :                         if (!is_public || is_static) {
    3978           0 :                                 zend_error(E_WARNING, "The magic method __set() must have "
    3979             :                                         "public visibility and cannot be static");
    3980             :                         }
    3981          99 :                 } else if (zend_string_equals_literal(lcname, ZEND_UNSET_FUNC_NAME)) {
    3982           0 :                         if (!is_public || is_static) {
    3983           0 :                                 zend_error(E_WARNING, "The magic method __unset() must have "
    3984             :                                         "public visibility and cannot be static");
    3985             :                         }
    3986          99 :                 } else if (zend_string_equals_literal(lcname, ZEND_ISSET_FUNC_NAME)) {
    3987           0 :                         if (!is_public || is_static) {
    3988           0 :                                 zend_error(E_WARNING, "The magic method __isset() must have "
    3989             :                                         "public visibility and cannot be static");
    3990             :                         }
    3991          99 :                 } else if (zend_string_equals_literal(lcname, ZEND_TOSTRING_FUNC_NAME)) {
    3992           0 :                         if (!is_public || is_static) {
    3993           0 :                                 zend_error(E_WARNING, "The magic method __toString() must have "
    3994             :                                         "public visibility and cannot be static");
    3995             :                         }
    3996         100 :                 } else if (zend_string_equals_literal(lcname, ZEND_INVOKE_FUNC_NAME)) {
    3997           1 :                         if (!is_public || is_static) {
    3998           1 :                                 zend_error(E_WARNING, "The magic method __invoke() must have "
    3999             :                                         "public visibility and cannot be static");
    4000             :                         }
    4001          98 :                 } else if (zend_string_equals_literal(lcname, ZEND_DEBUGINFO_FUNC_NAME)) {
    4002           0 :                         if (!is_public || is_static) {
    4003           0 :                                 zend_error(E_WARNING, "The magic method __debugInfo() must have "
    4004             :                                         "public visibility and cannot be static");
    4005             :                         }
    4006             :                 }
    4007             :         } else {
    4008       17270 :                 if (!in_trait && zend_string_equals_str_ci(lcname, ce->name)) {
    4009         245 :                         if (!ce->constructor) {
    4010         235 :                                 ce->constructor = (zend_function *) op_array;
    4011             :                         }
    4012       18450 :                 } else if (zend_string_equals_literal(lcname, ZEND_CONSTRUCTOR_FUNC_NAME)) {
    4013        1670 :                         if (CG(active_class_entry)->constructor) {
    4014           8 :                                 zend_error(E_STRICT, "Redefining already defined constructor for class %s",
    4015           8 :                                         ce->name->val);
    4016             :                         }
    4017        1670 :                         ce->constructor = (zend_function *) op_array;
    4018       15254 :                 } else if (zend_string_equals_literal(lcname, ZEND_DESTRUCTOR_FUNC_NAME)) {
    4019         144 :                         ce->destructor = (zend_function *) op_array;
    4020       14992 :                 } else if (zend_string_equals_literal(lcname, ZEND_CLONE_FUNC_NAME)) {
    4021          26 :                         ce->clone = (zend_function *) op_array;
    4022       15003 :                 } else if (zend_string_equals_literal(lcname, ZEND_CALL_FUNC_NAME)) {
    4023          63 :                         if (!is_public || is_static) {
    4024           2 :                                 zend_error(E_WARNING, "The magic method __call() must have "
    4025             :                                         "public visibility and cannot be static");
    4026             :                         }
    4027          63 :                         ce->__call = (zend_function *) op_array;
    4028       14905 :                 } else if (zend_string_equals_literal(lcname, ZEND_CALLSTATIC_FUNC_NAME)) {
    4029          28 :                         if (!is_public || !is_static) {
    4030           1 :                                 zend_error(E_WARNING, "The magic method __callStatic() must have "
    4031             :                                         "public visibility and be static");
    4032             :                         }
    4033          28 :                         ce->__callstatic = (zend_function *) op_array;
    4034       14910 :                 } else if (zend_string_equals_literal(lcname, ZEND_GET_FUNC_NAME)) {
    4035          61 :                         if (!is_public || is_static) {
    4036           0 :                                 zend_error(E_WARNING, "The magic method __get() must have "
    4037             :                                         "public visibility and cannot be static");
    4038             :                         }
    4039          61 :                         ce->__get = (zend_function *) op_array;
    4040       14849 :                 } else if (zend_string_equals_literal(lcname, ZEND_SET_FUNC_NAME)) {
    4041          61 :                         if (!is_public || is_static) {
    4042           2 :                                 zend_error(E_WARNING, "The magic method __set() must have "
    4043             :                                         "public visibility and cannot be static");
    4044             :                         }
    4045          61 :                         ce->__set = (zend_function *) op_array;
    4046       14744 :                 } else if (zend_string_equals_literal(lcname, ZEND_UNSET_FUNC_NAME)) {
    4047          17 :                         if (!is_public || is_static) {
    4048           3 :                                 zend_error(E_WARNING, "The magic method __unset() must have "
    4049             :                                         "public visibility and cannot be static");
    4050             :                         }
    4051          17 :                         ce->__unset = (zend_function *) op_array;
    4052       14726 :                 } else if (zend_string_equals_literal(lcname, ZEND_ISSET_FUNC_NAME)) {
    4053          16 :                         if (!is_public || is_static) {
    4054           0 :                                 zend_error(E_WARNING, "The magic method __isset() must have "
    4055             :                                         "public visibility and cannot be static");
    4056             :                         }
    4057          16 :                         ce->__isset = (zend_function *) op_array;
    4058       15408 :                 } else if (zend_string_equals_literal(lcname, ZEND_TOSTRING_FUNC_NAME)) {
    4059         714 :                         if (!is_public || is_static) {
    4060           1 :                                 zend_error(E_WARNING, "The magic method __toString() must have "
    4061             :                                         "public visibility and cannot be static");
    4062             :                         }
    4063         714 :                         ce->__tostring = (zend_function *) op_array;
    4064       13993 :                 } else if (zend_string_equals_literal(lcname, ZEND_INVOKE_FUNC_NAME)) {
    4065          13 :                         if (!is_public || is_static) {
    4066           1 :                                 zend_error(E_WARNING, "The magic method __invoke() must have "
    4067             :                                         "public visibility and cannot be static");
    4068             :                         }
    4069       13979 :                 } else if (zend_string_equals_literal(lcname, ZEND_DEBUGINFO_FUNC_NAME)) {
    4070          12 :                         if (!is_public || is_static) {
    4071           0 :                                 zend_error(E_WARNING, "The magic method __debugInfo() must have "
    4072             :                                         "public visibility and cannot be static");
    4073             :                         }
    4074          12 :                         ce->__debugInfo = (zend_function *) op_array;
    4075       13955 :                 } else if (!is_static) {
    4076        7485 :                         op_array->fn_flags |= ZEND_ACC_ALLOW_STATIC;
    4077             :                 }
    4078             :         }
    4079             : 
    4080             :         zend_string_release(lcname);
    4081       17126 : }
    4082             : /* }}} */
    4083             : 
    4084       18177 : static void zend_begin_func_decl(znode *result, zend_op_array *op_array, zend_ast_decl *decl TSRMLS_DC) /* {{{ */
    4085             : {
    4086       18177 :         zend_ast *params_ast = decl->child[0];
    4087       18177 :         zend_string *name = decl->name, *lcname;
    4088             :         zend_op *opline;
    4089             : 
    4090       18177 :         op_array->function_name = name = zend_prefix_with_ns(name TSRMLS_CC);
    4091             : 
    4092       36354 :         lcname = zend_string_alloc(name->len, 0);
    4093       18177 :         zend_str_tolower_copy(lcname->val, name->val, name->len);
    4094             : 
    4095       18177 :         if (CG(current_import_function)) {
    4096           2 :                 zend_string *import_name = zend_hash_find_ptr(CG(current_import_function), lcname);
    4097           1 :                 if (import_name && !zend_string_equals_str_ci(lcname, import_name)) {
    4098           1 :                         zend_error(E_COMPILE_ERROR, "Cannot declare function %s "
    4099             :                                 "because the name is already in use", name->val);
    4100             :                 }
    4101             :         }
    4102             : 
    4103       18252 :         if (zend_string_equals_literal(lcname, ZEND_AUTOLOAD_FUNC_NAME)
    4104          76 :                 && zend_ast_get_list(params_ast)->children != 1
    4105             :         ) {
    4106           1 :                 zend_error_noreturn(E_COMPILE_ERROR, "%s() must take exactly 1 argument",
    4107             :                         ZEND_AUTOLOAD_FUNC_NAME);
    4108             :         }
    4109             : 
    4110       18175 :         if (op_array->fn_flags & ZEND_ACC_CLOSURE) {
    4111         375 :                 opline = zend_emit_op_tmp(result, ZEND_DECLARE_LAMBDA_FUNCTION, NULL, NULL TSRMLS_CC);
    4112             :         } else {
    4113       17800 :                 opline = get_next_op(CG(active_op_array) TSRMLS_CC);
    4114       17800 :                 opline->opcode = ZEND_DECLARE_FUNCTION;
    4115       17800 :                 opline->op2_type = IS_CONST;
    4116       35600 :                 LITERAL_STR(opline->op2, zend_string_copy(lcname));
    4117             :         }
    4118             : 
    4119             :         {
    4120       18175 :                 zend_string *key = zend_build_runtime_definition_key(lcname, decl->lex_pos TSRMLS_CC);
    4121             : 
    4122       18175 :                 opline->op1_type = IS_CONST;
    4123       18175 :                 LITERAL_STR(opline->op1, key);
    4124             : 
    4125       18175 :                 zend_hash_update_ptr(CG(function_table), key, op_array);
    4126             :         }
    4127             : 
    4128             :         zend_string_release(lcname);
    4129       18175 : }
    4130             : /* }}} */
    4131             : 
    4132       35308 : void zend_compile_func_decl(znode *result, zend_ast *ast TSRMLS_DC) /* {{{ */
    4133             : {
    4134       35308 :         zend_ast_decl *decl = (zend_ast_decl *) ast;
    4135       35308 :         zend_ast *params_ast = decl->child[0];
    4136       35308 :         zend_ast *uses_ast = decl->child[1];
    4137       35308 :         zend_ast *stmt_ast = decl->child[2];
    4138       35308 :         zend_bool is_method = decl->kind == ZEND_AST_METHOD;
    4139             : 
    4140       35308 :         zend_op_array *orig_op_array = CG(active_op_array);
    4141       35308 :         zend_op_array *op_array = zend_arena_alloc(&CG(arena), sizeof(zend_op_array));
    4142             : 
    4143             :         // TODO.AST interactive (not just here - also bpc etc!)
    4144             :         
    4145       35308 :         init_op_array(op_array, ZEND_USER_FUNCTION, INITIAL_OP_ARRAY_SIZE TSRMLS_CC);
    4146             : 
    4147       35308 :         op_array->fn_flags |= decl->flags;
    4148       35308 :         op_array->line_start = decl->start_lineno;
    4149       35308 :         op_array->line_end = decl->end_lineno;
    4150       35308 :         if (decl->doc_comment) {
    4151        4000 :                 op_array->doc_comment = zend_string_copy(decl->doc_comment);
    4152             :         }
    4153       35308 :         if (decl->kind == ZEND_AST_CLOSURE) {
    4154         375 :                 op_array->fn_flags |= ZEND_ACC_CLOSURE;
    4155             :         }
    4156             : 
    4157       35308 :         if (is_method) {
    4158       17131 :                 zend_bool has_body = stmt_ast != NULL;
    4159       17131 :                 zend_begin_method_decl(op_array, decl->name, has_body TSRMLS_CC);
    4160             :         } else {
    4161       18177 :                 zend_begin_func_decl(result, op_array, decl TSRMLS_CC);
    4162             :         }
    4163             : 
    4164       35301 :         CG(active_op_array) = op_array;
    4165       35301 :         zend_stack_push(&CG(context_stack), (void *) &CG(context));
    4166       35301 :         zend_init_compiler_context(TSRMLS_C);
    4167             : 
    4168       35301 :         if (CG(compiler_options) & ZEND_COMPILE_EXTENDED_INFO) {
    4169           0 :                 zend_op *opline_ext = zend_emit_op(NULL, ZEND_EXT_NOP, NULL, NULL TSRMLS_CC);
    4170           0 :                 opline_ext->lineno = decl->start_lineno;
    4171             :         }
    4172             : 
    4173             :         {
    4174             :                 /* Push a separator to the loop variable stack */
    4175             :                 znode dummy_var;
    4176       35301 :                 dummy_var.op_type = IS_UNUSED;
    4177             : 
    4178       35301 :                 zend_stack_push(&CG(loop_var_stack), (void *) &dummy_var);
    4179             :         }
    4180             : 
    4181       35301 :         zend_compile_params(params_ast TSRMLS_CC);
    4182       35291 :         if (uses_ast) {
    4183         146 :                 zend_compile_closure_uses(uses_ast TSRMLS_CC);
    4184             :         }
    4185       35290 :         zend_compile_stmt(stmt_ast TSRMLS_CC);
    4186             : 
    4187       35283 :         if (is_method) {
    4188       34226 :                 zend_check_magic_method_implementation(
    4189       17113 :                         CG(active_class_entry), (zend_function *) op_array, E_COMPILE_ERROR TSRMLS_CC);
    4190             :         }
    4191             : 
    4192       35267 :         zend_do_extended_info(TSRMLS_C);
    4193       35267 :         zend_emit_final_return(NULL TSRMLS_CC);
    4194             : 
    4195       35267 :         pass_two(CG(active_op_array) TSRMLS_CC);
    4196       35258 :         zend_release_labels(0 TSRMLS_CC);
    4197             : 
    4198             :         /* Pop the loop variable stack separator */
    4199       35258 :         zend_stack_del_top(&CG(loop_var_stack));
    4200             : 
    4201       35258 :         CG(active_op_array) = orig_op_array;
    4202       35258 : }
    4203             : /* }}} */
    4204             : 
    4205        2309 : void zend_compile_prop_decl(zend_ast *ast TSRMLS_DC) /* {{{ */
    4206             : {
    4207        2309 :         zend_ast_list *list = zend_ast_get_list(ast);
    4208        2309 :         uint32_t flags = list->attr;
    4209        2309 :         zend_class_entry *ce = CG(active_class_entry);
    4210        2309 :         uint32_t i, children = list->children;
    4211        2309 :         zend_string *doc_comment = NULL;
    4212             : 
    4213        2309 :         if (ce->ce_flags & ZEND_ACC_INTERFACE) {
    4214           1 :                 zend_error_noreturn(E_COMPILE_ERROR, "Interfaces may not include member variables");
    4215             :         }
    4216             : 
    4217        2308 :         if (flags & ZEND_ACC_ABSTRACT) {
    4218           1 :                 zend_error_noreturn(E_COMPILE_ERROR, "Properties cannot be declared abstract");
    4219             :         }
    4220             : 
    4221             :         /* Doc comment has been appended as last element in property list */
    4222        2307 :         if (list->child[children - 1]->kind == ZEND_AST_ZVAL) {
    4223         102 :                 doc_comment = zend_string_copy(zend_ast_get_str(list->child[children - 1]));
    4224          51 :                 children -= 1;
    4225             :         }
    4226             : 
    4227        4653 :         for (i = 0; i < children; ++i) {
    4228        2348 :                 zend_ast *prop_ast = list->child[i];
    4229        2348 :                 zend_ast *name_ast = prop_ast->child[0];
    4230        2348 :                 zend_ast *value_ast = prop_ast->child[1];
    4231        2348 :                 zend_string *name = zend_ast_get_str(name_ast);
    4232             :                 zval value_zv;
    4233             : 
    4234        2348 :                 if (flags & ZEND_ACC_FINAL) {
    4235           2 :                         zend_error_noreturn(E_COMPILE_ERROR, "Cannot declare property %s::$%s final, "
    4236             :                                 "the final modifier is allowed only for methods and classes",
    4237           1 :                                 ce->name->val, name->val);
    4238             :                 }
    4239             : 
    4240        2347 :                 if (zend_hash_exists(&ce->properties_info, name)) {
    4241           2 :                         zend_error_noreturn(E_COMPILE_ERROR, "Cannot redeclare %s::$%s",
    4242           1 :                                 ce->name->val, name->val);
    4243             :                 }
    4244             : 
    4245        2346 :                 if (value_ast) {
    4246        1223 :                         zend_const_expr_to_zval(&value_zv, value_ast TSRMLS_CC);
    4247             :                 } else {
    4248        1123 :                         ZVAL_NULL(&value_zv);
    4249             :                 }
    4250             : 
    4251        2346 :                 name = zend_new_interned_string_safe(name TSRMLS_CC);
    4252        2346 :                 zend_declare_property_ex(ce, name, &value_zv, flags, doc_comment TSRMLS_CC);
    4253             : 
    4254             :                 /* Doc comment is only assigned to first property */
    4255        2346 :                 doc_comment = NULL;
    4256             :         }
    4257        2305 : }
    4258             : /* }}} */
    4259             : 
    4260         239 : void zend_compile_class_const_decl(zend_ast *ast TSRMLS_DC) /* {{{ */
    4261             : {
    4262         239 :         zend_ast_list *list = zend_ast_get_list(ast);
    4263         239 :         zend_class_entry *ce = CG(active_class_entry);
    4264             :         uint32_t i;
    4265             : 
    4266         475 :         for (i = 0; i < list->children; ++i) {
    4267         242 :                 zend_ast *const_ast = list->child[i];
    4268         242 :                 zend_ast *name_ast = const_ast->child[0];
    4269         242 :                 zend_ast *value_ast = const_ast->child[1];
    4270         242 :                 zend_string *name = zend_ast_get_str(name_ast);
    4271             :                 zval value_zv;
    4272             : 
    4273         242 :                 if (ZEND_CE_IS_TRAIT(ce)) {
    4274           1 :                         zend_error_noreturn(E_COMPILE_ERROR, "Traits cannot have constants");
    4275             :                         return;
    4276             :                 }
    4277             : 
    4278         241 :                 zend_const_expr_to_zval(&value_zv, value_ast TSRMLS_CC);
    4279             : 
    4280         238 :                 name = zend_new_interned_string_safe(name TSRMLS_CC);
    4281         238 :                 if (zend_hash_add(&ce->constants_table, name, &value_zv) == NULL) {
    4282           4 :                         zend_error_noreturn(E_COMPILE_ERROR, "Cannot redefine class constant %s::%s",
    4283           2 :                                 ce->name->val, name->val);
    4284             :                 }
    4285             : 
    4286         236 :                 if (Z_CONSTANT(value_zv)) {
    4287          41 :                         ce->ce_flags &= ~ZEND_ACC_CONSTANTS_UPDATED;
    4288             :                 }
    4289             :         }
    4290             : }
    4291             : /* }}} */
    4292             : 
    4293          73 : static zend_trait_method_reference *zend_compile_method_ref(zend_ast *ast TSRMLS_DC) /* {{{ */
    4294             : {
    4295          73 :         zend_ast *class_ast = ast->child[0];
    4296          73 :         zend_ast *method_ast = ast->child[1];
    4297             : 
    4298          73 :         zend_trait_method_reference *method_ref = emalloc(sizeof(zend_trait_method_reference));
    4299          73 :         method_ref->ce = NULL;
    4300          73 :         method_ref->method_name = zend_string_copy(zend_ast_get_str(method_ast));
    4301             : 
    4302          73 :         if (class_ast) {
    4303          38 :                 method_ref->class_name = zend_resolve_class_name_ast(class_ast TSRMLS_CC);
    4304             :         } else {
    4305          35 :                 method_ref->class_name = NULL;
    4306             :         }
    4307             : 
    4308          73 :         return method_ref;
    4309             : }
    4310             : /* }}} */
    4311             : 
    4312          17 : static zend_string **zend_compile_name_list(zend_ast *ast TSRMLS_DC) /* {{{ */
    4313             : {
    4314          17 :         zend_ast_list *list = zend_ast_get_list(ast);
    4315          17 :         zend_string **names = safe_emalloc(sizeof(zend_string *), list->children + 1, 0);
    4316             :         uint32_t i;
    4317             : 
    4318          35 :         for (i = 0; i < list->children; ++i) {
    4319          18 :                 zend_ast *name_ast = list->child[i];
    4320          18 :                 names[i] = zend_resolve_class_name_ast(name_ast TSRMLS_CC);
    4321             :         }
    4322             : 
    4323          17 :         names[list->children] = NULL;
    4324             : 
    4325          17 :         return names;
    4326             : }
    4327             : /* }}} */
    4328             : 
    4329          17 : static void zend_compile_trait_precedence(zend_ast *ast TSRMLS_DC) /* {{{ */
    4330             : {
    4331          17 :         zend_ast *method_ref_ast = ast->child[0];
    4332          17 :         zend_ast *insteadof_ast = ast->child[1];
    4333             :         
    4334          17 :         zend_trait_precedence *precedence = emalloc(sizeof(zend_trait_precedence));
    4335          17 :         precedence->trait_method = zend_compile_method_ref(method_ref_ast TSRMLS_CC);
    4336          17 :         precedence->exclude_from_classes
    4337             :                 = (void *) zend_compile_name_list(insteadof_ast TSRMLS_CC);
    4338             : 
    4339          17 :         zend_add_to_list(&CG(active_class_entry)->trait_precedences, precedence TSRMLS_CC);
    4340          17 : }
    4341             : /* }}} */
    4342             : 
    4343          59 : static void zend_compile_trait_alias(zend_ast *ast TSRMLS_DC) /* {{{ */
    4344             : {
    4345          59 :         zend_ast *method_ref_ast = ast->child[0];
    4346          59 :         zend_ast *alias_ast = ast->child[1];
    4347          59 :         uint32_t modifiers = ast->attr;
    4348             : 
    4349             :         zend_trait_alias *alias;
    4350             : 
    4351          59 :         if (modifiers == ZEND_ACC_STATIC) {
    4352           1 :                 zend_error_noreturn(E_COMPILE_ERROR, "Cannot use 'static' as method modifier");
    4353          58 :         } else if (modifiers == ZEND_ACC_ABSTRACT) {
    4354           1 :                 zend_error_noreturn(E_COMPILE_ERROR, "Cannot use 'abstract' as method modifier");
    4355          57 :         } else if (modifiers == ZEND_ACC_FINAL) {
    4356           1 :                 zend_error_noreturn(E_COMPILE_ERROR, "Cannot use 'final' as method modifier");
    4357             :         }
    4358             : 
    4359          56 :         alias = emalloc(sizeof(zend_trait_alias));
    4360          56 :         alias->trait_method = zend_compile_method_ref(method_ref_ast TSRMLS_CC);
    4361          56 :         alias->modifiers = modifiers;
    4362             : 
    4363          56 :         if (alias_ast) {
    4364          48 :                 alias->alias = zend_string_copy(zend_ast_get_str(alias_ast));
    4365             :         } else {
    4366           8 :                 alias->alias = NULL;
    4367             :         }
    4368             : 
    4369          56 :         zend_add_to_list(&CG(active_class_entry)->trait_aliases, alias TSRMLS_CC);
    4370          56 : }
    4371             : /* }}} */
    4372             : 
    4373         198 : void zend_compile_use_trait(zend_ast *ast TSRMLS_DC) /* {{{ */
    4374             : {
    4375         396 :         zend_ast_list *traits = zend_ast_get_list(ast->child[0]);
    4376         255 :         zend_ast_list *adaptations = ast->child[1] ? zend_ast_get_list(ast->child[1]) : NULL;
    4377         198 :         zend_class_entry *ce = CG(active_class_entry);
    4378             :         zend_op *opline;
    4379             :         uint32_t i;
    4380             : 
    4381         435 :         for (i = 0; i < traits->children; ++i) {
    4382         238 :                 zend_ast *trait_ast = traits->child[i];
    4383         238 :                 zend_string *name = zend_ast_get_str(trait_ast);
    4384             : 
    4385         238 :                 if (ce->ce_flags & ZEND_ACC_INTERFACE) {
    4386           1 :                         zend_error_noreturn(E_COMPILE_ERROR, "Cannot use traits inside of interfaces. "
    4387           1 :                                 "%s is used in %s", name->val, ce->name->val);
    4388             :                 }
    4389             : 
    4390         237 :                 switch (zend_get_class_fetch_type(name)) {
    4391             :                         case ZEND_FETCH_CLASS_SELF:
    4392             :                         case ZEND_FETCH_CLASS_PARENT:
    4393             :                         case ZEND_FETCH_CLASS_STATIC:
    4394           0 :                                 zend_error_noreturn(E_COMPILE_ERROR, "Cannot use '%s' as trait name "
    4395             :                                         "as it is reserved", name->val);
    4396             :                                 break;
    4397             :                 }
    4398             : 
    4399         237 :                 opline = get_next_op(CG(active_op_array) TSRMLS_CC);
    4400         237 :                 opline->opcode = ZEND_ADD_TRAIT;
    4401         237 :                 SET_NODE(opline->op1, &CG(implementing_class));
    4402         237 :                 opline->op2_type = IS_CONST;
    4403         237 :                 opline->op2.constant = zend_add_class_name_literal(CG(active_op_array),
    4404             :                         zend_resolve_class_name_ast(trait_ast TSRMLS_CC) TSRMLS_CC);
    4405             : 
    4406         237 :                 ce->num_traits++;
    4407             :         }
    4408             : 
    4409         197 :         if (!adaptations) {
    4410         140 :                 return;
    4411             :         }
    4412             : 
    4413         130 :         for (i = 0; i < adaptations->children; ++i) {
    4414          76 :                 zend_ast *adaptation_ast = adaptations->child[i];
    4415          76 :                 switch (adaptation_ast->kind) {
    4416             :                         case ZEND_AST_TRAIT_PRECEDENCE:
    4417          17 :                                 zend_compile_trait_precedence(adaptation_ast TSRMLS_CC);
    4418          17 :                                 break;
    4419             :                         case ZEND_AST_TRAIT_ALIAS:
    4420          59 :                                 zend_compile_trait_alias(adaptation_ast TSRMLS_CC);
    4421             :                                 break;
    4422             :                         EMPTY_SWITCH_DEFAULT_CASE()
    4423             :                 }
    4424             :         }
    4425             : }
    4426             : /* }}} */
    4427             : 
    4428         328 : void zend_compile_implements(znode *class_node, zend_ast *ast TSRMLS_DC) /* {{{ */
    4429             : {
    4430         328 :         zend_ast_list *list = zend_ast_get_list(ast);
    4431             :         uint32_t i;
    4432         693 :         for (i = 0; i < list->children; ++i) {
    4433         368 :                 zend_ast *class_ast = list->child[i];
    4434         368 :                 zend_string *name = zend_ast_get_str(class_ast);
    4435             : 
    4436             :                 zend_op *opline;
    4437             : 
    4438             :                 /* Traits can not implement interfaces */
    4439         368 :                 if (ZEND_CE_IS_TRAIT(CG(active_class_entry))) {
    4440           1 :                         zend_error_noreturn(E_COMPILE_ERROR, "Cannot use '%s' as interface on '%s' "
    4441           1 :                                 "since it is a Trait", name->val, CG(active_class_entry)->name->val);
    4442             :                 }
    4443             : 
    4444         367 :                 if (!zend_is_const_default_class_ref(class_ast)) {
    4445           2 :                         zend_error_noreturn(E_COMPILE_ERROR,
    4446             :                                 "Cannot use '%s' as interface name as it is reserved", name->val);
    4447             :                 }
    4448             : 
    4449         365 :                 opline = zend_emit_op(NULL, ZEND_ADD_INTERFACE, class_node, NULL TSRMLS_CC);
    4450         365 :                 opline->op2_type = IS_CONST;
    4451         365 :                 opline->op2.constant = zend_add_class_name_literal(CG(active_op_array),
    4452             :                         zend_resolve_class_name_ast(class_ast TSRMLS_CC) TSRMLS_CC);
    4453             : 
    4454         365 :                 CG(active_class_entry)->num_interfaces++;
    4455             :         }
    4456         325 : }
    4457             : /* }}} */
    4458             : 
    4459        7273 : void zend_compile_class_decl(zend_ast *ast TSRMLS_DC) /* {{{ */
    4460             : {
    4461        7273 :         zend_ast_decl *decl = (zend_ast_decl *) ast;
    4462        7273 :         zend_ast *extends_ast = decl->child[0];
    4463        7273 :         zend_ast *implements_ast = decl->child[1];
    4464        7273 :         zend_ast *stmt_ast = decl->child[2];
    4465             : 
    4466        7273 :         zend_string *name = decl->name, *lcname, *import_name = NULL;
    4467        7273 :         zend_class_entry *ce = zend_arena_alloc(&CG(arena), sizeof(zend_class_entry));
    4468             :         zend_op *opline;
    4469             :         znode declare_node, extends_node;
    4470             : 
    4471        7273 :         if (CG(active_class_entry)) {
    4472           1 :                 zend_error_noreturn(E_COMPILE_ERROR, "Class declarations may not be nested");
    4473             :                 return;
    4474             :         }
    4475             : 
    4476        7272 :         if (ZEND_FETCH_CLASS_DEFAULT != zend_get_class_fetch_type(name)) {
    4477           3 :                 zend_error_noreturn(E_COMPILE_ERROR, "Cannot use '%s' as class name as it is reserved",
    4478             :                         name->val);
    4479             :         }
    4480             : 
    4481       14538 :         lcname = zend_string_alloc(name->len, 0);
    4482        7269 :         zend_str_tolower_copy(lcname->val, name->val, name->len);
    4483             : 
    4484        7269 :         if (CG(current_import)) {
    4485          46 :                 import_name = zend_hash_find_ptr(CG(current_import), lcname);
    4486             :         }
    4487             : 
    4488        7269 :         if (CG(current_namespace)) {
    4489         118 :                 name = zend_prefix_with_ns(name TSRMLS_CC);
    4490             : 
    4491             :                 zend_string_release(lcname);
    4492         236 :                 lcname = zend_string_alloc(name->len, 0);
    4493         118 :                 zend_str_tolower_copy(lcname->val, name->val, name->len);
    4494             :         } else {
    4495             :                 zend_string_addref(name);
    4496             :         }
    4497             : 
    4498        7269 :         if (import_name && !zend_string_equals_str_ci(lcname, import_name)) {
    4499           1 :                 zend_error_noreturn(E_COMPILE_ERROR, "Cannot declare class %s "
    4500             :                         "because the name is already in use", name->val);
    4501             :         }
    4502             : 
    4503        7268 :         name = zend_new_interned_string(name TSRMLS_CC);
    4504        7268 :         lcname = zend_new_interned_string(lcname TSRMLS_CC);
    4505             : 
    4506        7268 :         ce->type = ZEND_USER_CLASS;
    4507        7268 :         ce->name = name;
    4508        7268 :         zend_initialize_class_data(ce, 1 TSRMLS_CC);
    4509             : 
    4510        7268 :         ce->ce_flags |= decl->flags;
    4511        7268 :         ce->info.user.filename = zend_get_compiled_filename(TSRMLS_C);
    4512        7268 :         ce->info.user.line_start = decl->start_lineno;
    4513        7268 :         ce->info.user.line_end = decl->end_lineno;
    4514        7268 :         if (decl->doc_comment) {
    4515         126 :                 ce->info.user.doc_comment = zend_string_copy(decl->doc_comment);
    4516             :         }
    4517             : 
    4518        7268 :         if (extends_ast) {
    4519        2324 :                 if (ZEND_CE_IS_TRAIT(ce)) {
    4520           1 :                         zend_error_noreturn(E_COMPILE_ERROR, "A trait (%s) cannot extend a class. "
    4521             :                                 "Traits can only be composed from other traits with the 'use' keyword. Error",
    4522             :                                 name->val);
    4523             :                 }
    4524             : 
    4525        2323 :                 if (!zend_is_const_default_class_ref(extends_ast)) {
    4526           2 :                         zend_string *extends_name = zend_ast_get_str(extends_ast);
    4527           2 :                         zend_error_noreturn(E_COMPILE_ERROR,
    4528             :                                 "Cannot use '%s' as class name as it is reserved", extends_name->val);
    4529             :                 }
    4530             : 
    4531        2321 :                 zend_compile_class_ref(&extends_node, extends_ast TSRMLS_CC);
    4532             :         }
    4533             : 
    4534        7265 :         opline = get_next_op(CG(active_op_array) TSRMLS_CC);
    4535        7265 :         zend_make_var_result(&declare_node, opline TSRMLS_CC);
    4536             : 
    4537             :         // TODO.AST drop this
    4538        7265 :         GET_NODE(&CG(implementing_class), opline->result);
    4539             : 
    4540        7265 :         opline->op2_type = IS_CONST;
    4541        7265 :         LITERAL_STR(opline->op2, lcname);
    4542             : 
    4543        7265 :         if (extends_ast) {
    4544        2321 :                 opline->opcode = ZEND_DECLARE_INHERITED_CLASS;
    4545        2321 :                 opline->extended_value = extends_node.u.op.var;
    4546             :         } else {
    4547        4944 :                 opline->opcode = ZEND_DECLARE_CLASS;
    4548             :         }
    4549             : 
    4550             :         {
    4551        7265 :                 zend_string *key = zend_build_runtime_definition_key(lcname, decl->lex_pos TSRMLS_CC);
    4552             : 
    4553        7265 :                 opline->op1_type = IS_CONST;
    4554        7265 :                 LITERAL_STR(opline->op1, key);
    4555             : 
    4556        7265 :                 zend_hash_update_ptr(CG(class_table), key, ce);
    4557             :         }
    4558             : 
    4559        7265 :         CG(active_class_entry) = ce;
    4560             : 
    4561        7265 :         if (implements_ast) {
    4562         328 :                 zend_compile_implements(&declare_node, implements_ast TSRMLS_CC);
    4563             :         }
    4564             : 
    4565        7262 :         zend_compile_stmt(stmt_ast TSRMLS_CC);
    4566             : 
    4567        7214 :         if (ce->constructor) {
    4568        1896 :                 ce->constructor->common.fn_flags |= ZEND_ACC_CTOR;
    4569        1896 :                 if (ce->constructor->common.fn_flags & ZEND_ACC_STATIC) {
    4570           4 :                         zend_error_noreturn(E_COMPILE_ERROR, "Constructor %s::%s() cannot be static",
    4571           4 :                                 ce->name->val, ce->constructor->common.function_name->val);
    4572             :                 }
    4573             :         }
    4574        7212 :         if (ce->destructor) {
    4575         143 :                 ce->destructor->common.fn_flags |= ZEND_ACC_DTOR;
    4576         143 :                 if (ce->destructor->common.fn_flags & ZEND_ACC_STATIC) {
    4577           2 :                         zend_error_noreturn(E_COMPILE_ERROR, "Destructor %s::%s() cannot be static",
    4578           2 :                                 ce->name->val, ce->destructor->common.function_name->val);
    4579             :                 }
    4580             :         }
    4581        7211 :         if (ce->clone) {
    4582          25 :                 ce->clone->common.fn_flags |= ZEND_ACC_CLONE;
    4583          25 :                 if (ce->clone->common.fn_flags & ZEND_ACC_STATIC) {
    4584           2 :                         zend_error_noreturn(E_COMPILE_ERROR, "Clone method %s::%s() cannot be static",
    4585           2 :                                 ce->name->val, ce->clone->common.function_name->val);
    4586             :                 }
    4587             :         }
    4588             : 
    4589             :         /* Check for traits and proceed like with interfaces.
    4590             :          * The only difference will be a combined handling of them in the end.
    4591             :          * Thus, we need another opcode here. */
    4592        7210 :         if (ce->num_traits > 0) {
    4593         175 :                 ce->traits = NULL;
    4594         175 :                 ce->num_traits = 0;
    4595         175 :                 ce->ce_flags |= ZEND_ACC_IMPLEMENT_TRAITS;
    4596             : 
    4597         175 :                 zend_emit_op(NULL, ZEND_BIND_TRAITS, &declare_node, NULL TSRMLS_CC);
    4598             :         }
    4599             : 
    4600       11633 :         if (!(ce->ce_flags & (ZEND_ACC_INTERFACE|ZEND_ACC_EXPLICIT_ABSTRACT_CLASS))
    4601        4423 :                 && (extends_ast || ce->num_interfaces > 0)
    4602             :         ) {
    4603        2542 :                 zend_verify_abstract_class(ce TSRMLS_CC);
    4604        2540 :                 if (ce->num_interfaces && !(ce->ce_flags & ZEND_ACC_IMPLEMENT_TRAITS)) {
    4605         270 :                         zend_emit_op(NULL, ZEND_VERIFY_ABSTRACT_CLASS, &declare_node, NULL TSRMLS_CC);
    4606             :                 }
    4607             :         }
    4608             : 
    4609             :         /* Inherit interfaces; reset number to zero, we need it for above check and
    4610             :          * will restore it during actual implementation.
    4611             :          * The ZEND_ACC_IMPLEMENT_INTERFACES flag disables double call to
    4612             :          * zend_verify_abstract_class() */
    4613        7208 :         if (ce->num_interfaces > 0) {
    4614         325 :                 ce->interfaces = NULL;
    4615         325 :                 ce->num_interfaces = 0;
    4616         325 :                 ce->ce_flags |= ZEND_ACC_IMPLEMENT_INTERFACES;
    4617             :         }
    4618             : 
    4619        7208 :         CG(active_class_entry) = NULL;
    4620             : }
    4621             : /* }}} */
    4622             : 
    4623          82 : static HashTable *zend_get_import_ht(uint32_t type TSRMLS_DC) /* {{{ */
    4624             : {
    4625          82 :         switch (type) {
    4626             :                 case T_CLASS:
    4627          51 :                         if (!CG(current_import)) {
    4628          40 :                                 CG(current_import) = emalloc(sizeof(HashTable));
    4629          40 :                                 zend_hash_init(CG(current_import), 8, NULL, str_dtor, 0);
    4630             :                         }
    4631          51 :                         return CG(current_import);
    4632             :                 case T_FUNCTION:
    4633          17 :                         if (!CG(current_import_function)) {
    4634          15 :                                 CG(current_import_function) = emalloc(sizeof(HashTable));
    4635          15 :                                 zend_hash_init(CG(current_import_function), 8, NULL, str_dtor, 0);
    4636             :                         }
    4637          17 :                         return CG(current_import_function);
    4638             :                 case T_CONST:
    4639          14 :                         if (!CG(current_import_const)) {
    4640          12 :                                 CG(current_import_const) = emalloc(sizeof(HashTable));
    4641          12 :                                 zend_hash_init(CG(current_import_const), 8, NULL, str_dtor, 0);
    4642             :                         }
    4643          14 :                         return CG(current_import_const);
    4644             :                 EMPTY_SWITCH_DEFAULT_CASE()
    4645             :         }
    4646             : 
    4647           0 :         return NULL;
    4648             : }
    4649             : /* }}} */
    4650             : 
    4651           7 : static char *zend_get_use_type_str(uint32_t type) /* {{{ */
    4652             : {
    4653           7 :         switch (type) {
    4654             :                 case T_CLASS:
    4655           2 :                         return "";
    4656             :                 case T_FUNCTION:
    4657           3 :                         return " function";
    4658             :                 case T_CONST:
    4659           2 :                         return " const";
    4660             :                 EMPTY_SWITCH_DEFAULT_CASE()
    4661             :         }
    4662             : 
    4663           0 :         return " unknown";
    4664             : }
    4665             : /* }}} */
    4666             : 
    4667           5 : static void zend_check_already_in_use(uint32_t type, zend_string *old_name, zend_string *new_name, zend_string *check_name) /* {{{ */
    4668             : {
    4669           5 :         if (zend_string_equals_str_ci(old_name, check_name)) {
    4670           1 :                 return;
    4671             :         }
    4672             : 
    4673           4 :         zend_error_noreturn(E_COMPILE_ERROR, "Cannot use%s %s as %s because the name "
    4674             :                 "is already in use", zend_get_use_type_str(type), old_name->val, new_name->val);
    4675             : }
    4676             : /* }}} */
    4677             : 
    4678          82 : void zend_compile_use(zend_ast *ast TSRMLS_DC) /* {{{ */
    4679             : {
    4680          82 :         zend_ast_list *list = zend_ast_get_list(ast);
    4681             :         uint32_t i;
    4682          82 :         zend_string *current_ns = CG(current_namespace);
    4683          82 :         uint32_t type = ast->attr;
    4684          82 :         HashTable *current_import = zend_get_import_ht(type TSRMLS_CC);
    4685          82 :         zend_bool case_sensitive = type == T_CONST;
    4686             : 
    4687         164 :         for (i = 0; i < list->children; ++i) {
    4688          90 :                 zend_ast *use_ast = list->child[i];
    4689          90 :                 zend_ast *old_name_ast = use_ast->child[0];
    4690          90 :                 zend_ast *new_name_ast = use_ast->child[1];
    4691          90 :                 zend_string *old_name = zend_ast_get_str(old_name_ast);
    4692             :                 zend_string *new_name, *lookup_name;
    4693             : 
    4694          90 :                 if (new_name_ast) {
    4695          45 :                         new_name = zend_string_copy(zend_ast_get_str(new_name_ast));
    4696             :                 } else {
    4697             :                         const char *unqualified_name;
    4698             :                         size_t unqualified_name_len;
    4699          45 :                         if (zend_get_unqualified_name(old_name, &unqualified_name, &unqualified_name_len)) {
    4700             :                                 /* The form "use A\B" is eqivalent to "use A\B as B" */
    4701          70 :                                 new_name = zend_string_init(unqualified_name, unqualified_name_len, 0);
    4702             :                         } else {
    4703          10 :                                 new_name = zend_string_copy(old_name);
    4704             : 
    4705          10 :                                 if (!current_ns) {
    4706           1 :                                         if (type == T_CLASS && zend_string_equals_literal(new_name, "strict")) {
    4707           0 :                                                 zend_error_noreturn(E_COMPILE_ERROR,
    4708             :                                                         "You seem to be trying to use a different language...");
    4709             :                                         }
    4710             : 
    4711           1 :                                         zend_error(E_WARNING, "The use statement with non-compound name '%s' "
    4712             :                                                 "has no effect", new_name->val);
    4713             :                                 }
    4714             :                         }
    4715             :                 }
    4716             : 
    4717          90 :                 if (case_sensitive) {
    4718          17 :                         lookup_name = zend_string_copy(new_name);
    4719             :                 } else {
    4720         146 :                         lookup_name = zend_string_alloc(new_name->len, 0);
    4721          73 :                         zend_str_tolower_copy(lookup_name->val, new_name->val, new_name->len);
    4722             :                 }
    4723             : 
    4724         142 :                 if (type == T_CLASS && (zend_string_equals_literal(lookup_name, "self")
    4725          52 :                         || zend_string_equals_literal(lookup_name, "parent"))
    4726             :                 ) {
    4727           1 :                         zend_error_noreturn(E_COMPILE_ERROR, "Cannot use %s as %s because '%s' "
    4728             :                                 "is a special class name", old_name->val, new_name->val, new_name->val);
    4729             :                 }
    4730             : 
    4731          89 :                 if (current_ns) {
    4732          90 :                         zend_string *ns_name = zend_string_alloc(current_ns->len + 1 + new_name->len, 0);
    4733          45 :                         zend_str_tolower_copy(ns_name->val, current_ns->val, current_ns->len);
    4734          45 :                         ns_name->val[current_ns->len] = '\\';
    4735          45 :                         memcpy(ns_name->val + current_ns->len + 1, lookup_name->val, lookup_name->len);
    4736             : 
    4737          45 :                         if (zend_hash_exists(CG(class_table), ns_name)) {
    4738           2 :                                 zend_check_already_in_use(type, old_name, new_name, ns_name);
    4739             :                         }
    4740             : 
    4741             :                         zend_string_free(ns_name);
    4742             :                 } else {
    4743          44 :                         switch (type) {
    4744             :                                 case T_CLASS:
    4745             :                                 {
    4746          24 :                                         zend_class_entry *ce = zend_hash_find_ptr(CG(class_table), lookup_name);
    4747          17 :                                         if (ce && ce->type == ZEND_USER_CLASS
    4748           5 :                                                 && ce->info.user.filename == CG(compiled_filename)
    4749             :                                         ) {
    4750           1 :                                                 zend_check_already_in_use(type, old_name, new_name, lookup_name);
    4751             :                                         }
    4752          11 :                                         break;
    4753             :                                 }
    4754             :                                 case T_FUNCTION:
    4755             :                                 {
    4756          34 :                                         zend_function *fn = zend_hash_find_ptr(CG(function_table), lookup_name);
    4757          20 :                                         if (fn && fn->type == ZEND_USER_FUNCTION
    4758           3 :                                                 && fn->op_array.filename == CG(compiled_filename)
    4759             :                                         ) {
    4760           1 :                                                 zend_check_already_in_use(type, old_name, new_name, lookup_name);
    4761             :                                         }
    4762          16 :                                         break;
    4763             :                                 }
    4764             :                                 case T_CONST:
    4765             :                                 {
    4766          15 :                                         zend_string *filename = zend_hash_find_ptr(&CG(const_filenames), lookup_name);
    4767          15 :                                         if (filename && filename == CG(compiled_filename)) {
    4768           1 :                                                 zend_check_already_in_use(type, old_name, new_name, lookup_name);
    4769             :                                         }
    4770             :                                         break;
    4771             :                                 }
    4772             :                                 EMPTY_SWITCH_DEFAULT_CASE()
    4773             :                         }
    4774             :                 }
    4775             : 
    4776             :                 zend_string_addref(old_name);
    4777          85 :                 if (!zend_hash_add_ptr(current_import, lookup_name, old_name)) {
    4778           3 :                         zend_error_noreturn(E_COMPILE_ERROR, "Cannot use%s %s as %s because the name "
    4779             :                                 "is already in use", zend_get_use_type_str(type), old_name->val, new_name->val);
    4780             :                 }
    4781             : 
    4782             :                 zend_string_release(lookup_name);
    4783             :                 zend_string_release(new_name);
    4784             :         }
    4785          74 : }
    4786             : /* }}} */
    4787             : 
    4788         161 : void zend_compile_const_decl(zend_ast *ast TSRMLS_DC) /* {{{ */
    4789             : {
    4790         161 :         zend_ast_list *list = zend_ast_get_list(ast);
    4791             :         uint32_t i;
    4792         319 :         for (i = 0; i < list->children; ++i) {
    4793         162 :                 zend_ast *const_ast = list->child[i];
    4794         162 :                 zend_ast *name_ast = const_ast->child[0];
    4795         162 :                 zend_ast *value_ast = const_ast->child[1];
    4796         162 :                 zend_string *name = zend_ast_get_str(name_ast);
    4797             : 
    4798             :                 zend_string *import_name;
    4799             :                 znode name_node, value_node;
    4800         162 :                 zval *value_zv = &value_node.u.constant;
    4801             : 
    4802         162 :                 value_node.op_type = IS_CONST;
    4803         162 :                 zend_const_expr_to_zval(value_zv, value_ast TSRMLS_CC);
    4804             : 
    4805         160 :                 if (zend_lookup_reserved_const(name->val, name->len TSRMLS_CC)) {
    4806           1 :                         zend_error_noreturn(E_COMPILE_ERROR, "Cannot redeclare constant '%s'", name->val);
    4807             :                 }
    4808             : 
    4809         159 :                 name = zend_prefix_with_ns(name TSRMLS_CC);
    4810         159 :                 name = zend_new_interned_string(name TSRMLS_CC);
    4811             : 
    4812         160 :                 if (CG(current_import_const)
    4813           1 :                         && (import_name = zend_hash_find_ptr(CG(current_import_const), name))
    4814             :                 ) {
    4815           1 :                         if (!zend_string_equals(import_name, name)) {
    4816           1 :                                 zend_error(E_COMPILE_ERROR, "Cannot declare const %s because "
    4817             :                                         "the name is already in use", name->val);
    4818             :                         }
    4819             :                 }
    4820             : 
    4821         158 :                 name_node.op_type = IS_CONST;
    4822         158 :                 ZVAL_STR(&name_node.u.constant, name);
    4823             : 
    4824         158 :                 zend_emit_op(NULL, ZEND_DECLARE_CONST, &name_node, &value_node TSRMLS_CC);
    4825             : 
    4826         158 :                 zend_hash_add_ptr(&CG(const_filenames), name, CG(compiled_filename));
    4827             :         }
    4828         157 : }
    4829             : /* }}}*/
    4830             : 
    4831         201 : void zend_compile_namespace(zend_ast *ast TSRMLS_DC) /* {{{ */
    4832             : {
    4833         201 :         zend_ast *name_ast = ast->child[0];
    4834         201 :         zend_ast *stmt_ast = ast->child[1];
    4835             :         zend_string *name;
    4836         201 :         zend_bool with_bracket = stmt_ast != NULL;
    4837             : 
    4838             :         /* handle mixed syntax declaration or nested namespaces */
    4839         201 :         if (!CG(has_bracketed_namespaces)) {
    4840         172 :                 if (CG(current_namespace)) {
    4841             :                         /* previous namespace declarations were unbracketed */
    4842           7 :                         if (with_bracket) {
    4843           1 :                                 zend_error_noreturn(E_COMPILE_ERROR, "Cannot mix bracketed namespace declarations "
    4844             :                                         "with unbracketed namespace declarations");
    4845             :                         }
    4846             :                 }
    4847             :         } else {
    4848             :                 /* previous namespace declarations were bracketed */
    4849          29 :                 if (!with_bracket) {
    4850           1 :                         zend_error_noreturn(E_COMPILE_ERROR, "Cannot mix bracketed namespace declarations "
    4851             :                                 "with unbracketed namespace declarations");
    4852          28 :                 } else if (CG(current_namespace) || CG(in_namespace)) {
    4853           1 :                         zend_error_noreturn(E_COMPILE_ERROR, "Namespace declarations cannot be nested");
    4854             :                 }
    4855             :         }
    4856             : 
    4857         432 :         if (((!with_bracket && !CG(current_namespace))
    4858         234 :                  || (with_bracket && !CG(has_bracketed_namespaces))) && CG(active_op_array)->last > 0
    4859             :         ) {
    4860             :                 /* ignore ZEND_EXT_STMT and ZEND_TICKS */
    4861           3 :                 uint32_t num = CG(active_op_array)->last;
    4862          13 :                 while (num > 0 &&
    4863           3 :                        (CG(active_op_array)->opcodes[num-1].opcode == ZEND_EXT_STMT ||
    4864           3 :                         CG(active_op_array)->opcodes[num-1].opcode == ZEND_TICKS)) {
    4865           1 :                         --num;
    4866             :                 }
    4867           3 :                 if (num > 0) {
    4868           2 :                         zend_error_noreturn(E_COMPILE_ERROR, "Namespace declaration statement has to be "
    4869             :                                 "the very first statement in the script");
    4870             :                 }
    4871             :         }
    4872             : 
    4873         196 :         if (CG(current_namespace)) {
    4874           6 :                 zend_string_release(CG(current_namespace));
    4875             :         }
    4876             : 
    4877         196 :         if (name_ast) {
    4878         166 :                 name = zend_ast_get_str(name_ast);
    4879             : 
    4880         166 :                 if (ZEND_FETCH_CLASS_DEFAULT != zend_get_class_fetch_type(name)) {
    4881           1 :                         zend_error_noreturn(E_COMPILE_ERROR, "Cannot use '%s' as namespace name", name->val);
    4882             :                 }
    4883             : 
    4884         165 :                 CG(current_namespace) = zend_string_copy(name);
    4885             :         } else {
    4886          30 :                 CG(current_namespace) = NULL;
    4887             :         }
    4888             : 
    4889         195 :         zend_reset_import_tables(TSRMLS_C);
    4890             : 
    4891         195 :         CG(in_namespace) = 1;
    4892         195 :         if (with_bracket) {
    4893          68 :                 CG(has_bracketed_namespaces) = 1;
    4894             :         }
    4895             : 
    4896         195 :         if (stmt_ast) {
    4897          68 :                 zend_compile_top_stmt(stmt_ast TSRMLS_CC);
    4898          55 :                 zend_end_namespace(TSRMLS_C);
    4899             :         }
    4900         182 : }
    4901             : /* }}} */
    4902             : 
    4903         274 : void zend_compile_halt_compiler(zend_ast *ast TSRMLS_DC) /* {{{ */
    4904             : {
    4905         274 :         zend_ast *offset_ast = ast->child[0];
    4906         274 :         zend_long offset = Z_LVAL_P(zend_ast_get_zval(offset_ast));
    4907             : 
    4908             :         zend_string *filename, *name;
    4909         274 :         const char const_name[] = "__COMPILER_HALT_OFFSET__";
    4910             : 
    4911         274 :         if (CG(has_bracketed_namespaces) && CG(in_namespace)) {
    4912           0 :                 zend_error_noreturn(E_COMPILE_ERROR,
    4913             :                         "__HALT_COMPILER() can only be used from the outermost scope");
    4914             :         }
    4915             : 
    4916         274 :         filename = zend_get_compiled_filename(TSRMLS_C);
    4917         274 :         name = zend_mangle_property_name(const_name, sizeof(const_name) - 1,
    4918             :                 filename->val, filename->len, 0);
    4919             : 
    4920         274 :         zend_register_long_constant(name->val, name->len, offset, CONST_CS, 0 TSRMLS_CC);
    4921             :         zend_string_release(name);
    4922         274 : }
    4923             : /* }}} */
    4924             : 
    4925        8662 : static zend_bool zend_try_ct_eval_magic_const(zval *zv, zend_ast *ast TSRMLS_DC) /* {{{ */
    4926             : {
    4927        8662 :         zend_op_array *op_array = CG(active_op_array);
    4928        8662 :         zend_class_entry *ce = CG(active_class_entry);
    4929             : 
    4930        8662 :         switch (ast->attr) {
    4931             :                 case T_LINE:
    4932          15 :                         ZVAL_LONG(zv, ast->lineno);
    4933          15 :                         break;
    4934             :                 case T_FILE:
    4935        7229 :                         ZVAL_STR_COPY(zv, CG(compiled_filename));
    4936        7229 :                         break;
    4937             :                 case T_DIR:
    4938             :                 {
    4939         444 :                         zend_string *filename = CG(compiled_filename);
    4940         888 :                         zend_string *dirname = zend_string_init(filename->val, filename->len, 0);
    4941         444 :                         zend_dirname(dirname->val, dirname->len);
    4942             : 
    4943         444 :                         if (strcmp(dirname->val, ".") == 0) {
    4944           0 :                                 dirname = zend_string_realloc(dirname, MAXPATHLEN, 0);
    4945             : #if HAVE_GETCWD
    4946           0 :                                 VCWD_GETCWD(dirname->val, MAXPATHLEN);
    4947             : #elif HAVE_GETWD
    4948             :                                 VCWD_GETWD(dirname->val);
    4949             : #endif
    4950             :                         }
    4951             : 
    4952         444 :                         dirname->len = strlen(dirname->val);
    4953         444 :                         ZVAL_STR(zv, dirname);
    4954         444 :                         break;
    4955             :                 }
    4956             :                 case T_FUNC_C:
    4957         208 :                         if (op_array && op_array->function_name) {
    4958         103 :                                 ZVAL_STR_COPY(zv, op_array->function_name);
    4959             :                         } else {
    4960           2 :                                 ZVAL_EMPTY_STRING(zv);
    4961             :                         }
    4962         105 :                         break;
    4963             :                 case T_METHOD_C:
    4964         748 :                         if (ce) {
    4965        1451 :                                 if (op_array && op_array->function_name) {
    4966         725 :                                         ZVAL_NEW_STR(zv, zend_concat3(ce->name->val, ce->name->len, "::", 2,
    4967             :                                                 op_array->function_name->val, op_array->function_name->len));
    4968             :                                 } else {
    4969           1 :                                         ZVAL_STR_COPY(zv, ce->name);
    4970             :                                 }
    4971          43 :                         } else if (op_array && op_array->function_name) {
    4972          21 :                                 ZVAL_STR_COPY(zv, op_array->function_name);
    4973             :                         } else {
    4974           1 :                                 ZVAL_EMPTY_STRING(zv);
    4975             :                         }
    4976         748 :                         break;
    4977             :                 case T_CLASS_C:
    4978          82 :                         if (ce) {
    4979          81 :                                 if (ZEND_CE_IS_TRAIT(ce)) {
    4980           5 :                                         return 0;
    4981             :                                 } else {
    4982          76 :                                         ZVAL_STR_COPY(zv, ce->name);
    4983             :                                 }
    4984             :                         } else {
    4985           1 :                                 ZVAL_EMPTY_STRING(zv);
    4986             :                         }
    4987          77 :                         break;
    4988             :                 case T_TRAIT_C:
    4989           6 :                         if (ce && ZEND_CE_IS_TRAIT(ce)) {
    4990           1 :                                 ZVAL_STR_COPY(zv, ce->name);
    4991             :                         } else {
    4992           4 :                                 ZVAL_EMPTY_STRING(zv);
    4993             :                         }
    4994           5 :                         break;
    4995             :                 case T_NS_C:
    4996          34 :                         if (CG(current_namespace)) {
    4997          25 :                                 ZVAL_STR_COPY(zv, CG(current_namespace));
    4998             :                         } else {
    4999           9 :                                 ZVAL_EMPTY_STRING(zv);
    5000             :                         }
    5001             :                         break;
    5002             :                 EMPTY_SWITCH_DEFAULT_CASE()
    5003             :         }
    5004             : 
    5005        8657 :         return 1;
    5006             : }
    5007             : /* }}} */
    5008             : 
    5009        3037 : static inline void zend_ct_eval_binary_op(zval *result, uint32_t opcode, zval *op1, zval *op2 TSRMLS_DC) /* {{{ */
    5010             : {
    5011        3037 :         binary_op_type fn = get_binary_op(opcode);
    5012        3037 :         fn(result, op1, op2 TSRMLS_CC);
    5013        3037 : }
    5014             : /* }}} */
    5015             : 
    5016        6549 : static inline void zend_ct_eval_unary_pm(zval *result, zend_ast_kind kind, zval *op TSRMLS_DC) /* {{{ */
    5017             : {
    5018             :         binary_op_type fn = kind == ZEND_AST_UNARY_PLUS
    5019        6549 :                 ? add_function : sub_function;
    5020             : 
    5021             :         zval left;
    5022        6549 :         ZVAL_LONG(&left, 0);
    5023        6549 :         fn(result, &left, op TSRMLS_CC);
    5024        6549 : }
    5025             : /* }}} */
    5026             : 
    5027          16 : static inline void zend_ct_eval_greater(zval *result, zend_ast_kind kind, zval *op1, zval *op2 TSRMLS_DC) /* {{{ */
    5028             : {
    5029             :         binary_op_type fn = kind == ZEND_AST_GREATER
    5030          16 :                 ? is_smaller_function : is_smaller_or_equal_function;
    5031          16 :         fn(result, op2, op1 TSRMLS_CC);
    5032          16 : }
    5033             : /* }}} */
    5034             : 
    5035       25796 : static zend_bool zend_try_ct_eval_array(zval *result, zend_ast *ast TSRMLS_DC) /* {{{ */
    5036             : {
    5037       25796 :         zend_ast_list *list = zend_ast_get_list(ast);
    5038             :         uint32_t i;
    5039             : 
    5040             :         /* First ensure that *all* child nodes are constant and by-val */
    5041      105847 :         for (i = 0; i < list->children; ++i) {
    5042       85156 :                 zend_ast *elem_ast = list->child[i];
    5043       85156 :                 zend_bool by_ref = elem_ast->attr;
    5044       85156 :                 zend_eval_const_expr(&elem_ast->child[0] TSRMLS_CC);
    5045       85156 :                 zend_eval_const_expr(&elem_ast->child[1] TSRMLS_CC);
    5046             : 
    5047      270304 :                 if (by_ref || elem_ast->child[0]->kind != ZEND_AST_ZVAL
    5048      185148 :                         || (elem_ast->child[1] && elem_ast->child[1]->kind != ZEND_AST_ZVAL)
    5049             :                 ) {
    5050        5105 :                         return 0;
    5051             :                 }
    5052             :         }
    5053             : 
    5054       20691 :         array_init_size(result, list->children);
    5055       85424 :         for (i = 0; i < list->children; ++i) {
    5056       64733 :                 zend_ast *elem_ast = list->child[i];
    5057       64733 :                 zend_ast *value_ast = elem_ast->child[0];
    5058       64733 :                 zend_ast *key_ast = elem_ast->child[1];
    5059             : 
    5060       64733 :                 zval *value = zend_ast_get_zval(value_ast);
    5061       64733 :                 if (Z_REFCOUNTED_P(value)) Z_ADDREF_P(value);
    5062             : 
    5063       64733 :                 if (key_ast) {
    5064       16005 :                         zval *key = zend_ast_get_zval(key_ast);
    5065       16005 :                         switch (Z_TYPE_P(key)) {
    5066             :                                 case IS_LONG:
    5067        2735 :                                         zend_hash_index_update(Z_ARRVAL_P(result), Z_LVAL_P(key), value);
    5068        2735 :                                         break;
    5069             :                                 case IS_STRING:
    5070       12745 :                                         zend_symtable_update(Z_ARRVAL_P(result), Z_STR_P(key), value);
    5071       12745 :                                         break;
    5072             :                                 case IS_DOUBLE:
    5073         524 :                                         zend_hash_index_update(Z_ARRVAL_P(result),
    5074             :                                                 zend_dval_to_lval(Z_DVAL_P(key)), value);
    5075         262 :                                         break;
    5076             :                                 case IS_FALSE:
    5077          72 :                                         zend_hash_index_update(Z_ARRVAL_P(result), 0, value);
    5078          72 :                                         break;
    5079             :                                 case IS_TRUE:
    5080          76 :                                         zend_hash_index_update(Z_ARRVAL_P(result), 1, value);
    5081          76 :                                         break;
    5082             :                                 case IS_NULL:
    5083         115 :                                         zend_hash_update(Z_ARRVAL_P(result), STR_EMPTY_ALLOC(), value);
    5084         115 :                                         break;
    5085             :                                 default:
    5086           0 :                                         zend_error(E_COMPILE_ERROR, "Illegal offset type");
    5087             :                                         break;
    5088             :                         }
    5089             :                 } else {
    5090       48728 :                         zend_hash_next_index_insert(Z_ARRVAL_P(result), value);
    5091             :                 }
    5092             :         }
    5093             : 
    5094       20691 :         return 1;
    5095             : }
    5096             : /* }}} */
    5097             : 
    5098       76513 : void zend_compile_binary_op(znode *result, zend_ast *ast TSRMLS_DC) /* {{{ */
    5099             : {
    5100       76513 :         zend_ast *left_ast = ast->child[0];
    5101       76513 :         zend_ast *right_ast = ast->child[1];
    5102       76513 :         uint32_t opcode = ast->attr;
    5103             : 
    5104             :         znode left_node, right_node;
    5105       76513 :         zend_compile_expr(&left_node, left_ast TSRMLS_CC);
    5106       76513 :         zend_compile_expr(&right_node, right_ast TSRMLS_CC);
    5107             : 
    5108       76513 :         if (left_node.op_type == IS_CONST && right_node.op_type == IS_CONST) {
    5109        2810 :                 result->op_type = IS_CONST;
    5110        2810 :                 zend_ct_eval_binary_op(&result->u.constant, opcode,
    5111             :                         &left_node.u.constant, &right_node.u.constant TSRMLS_CC);
    5112        2810 :                 zval_ptr_dtor(&left_node.u.constant);
    5113        2810 :                 zval_ptr_dtor(&right_node.u.constant);
    5114        2810 :                 return;
    5115             :         }
    5116             : 
    5117       73703 :         zend_emit_op_tmp(result, opcode, &left_node, &right_node TSRMLS_CC);
    5118             : }
    5119             : /* }}} */
    5120             : 
    5121             : /* We do not use zend_compile_binary_op for this because we want to retain the left-to-right
    5122             :  * evaluation order. */
    5123        1137 : void zend_compile_greater(znode *result, zend_ast *ast TSRMLS_DC) /* {{{ */
    5124             : {
    5125        1137 :         zend_ast *left_ast = ast->child[0];
    5126        1137 :         zend_ast *right_ast = ast->child[1];
    5127             :         znode left_node, right_node;
    5128             : 
    5129             :         ZEND_ASSERT(ast->kind == ZEND_AST_GREATER || ast->kind == ZEND_AST_GREATER_EQUAL);
    5130             : 
    5131        1137 :         zend_compile_expr(&left_node, left_ast TSRMLS_CC);
    5132        1137 :         zend_compile_expr(&right_node, right_ast TSRMLS_CC);
    5133             : 
    5134        1137 :         if (left_node.op_type == IS_CONST && right_node.op_type == IS_CONST) {
    5135          14 :                 result->op_type = IS_CONST;
    5136          14 :                 zend_ct_eval_greater(&result->u.constant, ast->kind,
    5137             :                         &left_node.u.constant, &right_node.u.constant TSRMLS_CC);
    5138          14 :                 zval_ptr_dtor(&left_node.u.constant);
    5139          14 :                 zval_ptr_dtor(&right_node.u.constant);
    5140          14 :                 return;
    5141             :         }
    5142             : 
    5143        1123 :         zend_emit_op_tmp(result,
    5144        1123 :                 ast->kind == ZEND_AST_GREATER ? ZEND_IS_SMALLER : ZEND_IS_SMALLER_OR_EQUAL,
    5145             :                 &right_node, &left_node TSRMLS_CC);
    5146             : }
    5147             : /* }}} */
    5148             : 
    5149       29327 : void zend_compile_unary_op(znode *result, zend_ast *ast TSRMLS_DC) /* {{{ */
    5150             : {
    5151       29327 :         zend_ast *expr_ast = ast->child[0];
    5152       29327 :         uint32_t opcode = ast->attr;
    5153             : 
    5154             :         znode expr_node;
    5155       29327 :         zend_compile_expr(&expr_node, expr_ast TSRMLS_CC);
    5156             : 
    5157       29327 :         zend_emit_op_tmp(result, opcode, &expr_node, NULL TSRMLS_CC);
    5158       29327 : }
    5159             : /* }}} */
    5160             : 
    5161        3179 : void zend_compile_unary_pm(znode *result, zend_ast *ast TSRMLS_DC) /* {{{ */
    5162             : {
    5163        3179 :         zend_ast *expr_ast = ast->child[0];
    5164             :         znode zero_node, expr_node;
    5165             : 
    5166             :         ZEND_ASSERT(ast->kind == ZEND_AST_UNARY_PLUS || ast->kind == ZEND_AST_UNARY_MINUS);
    5167             : 
    5168        3179 :         zend_compile_expr(&expr_node, expr_ast TSRMLS_CC);
    5169             : 
    5170        3179 :         if (expr_node.op_type == IS_CONST) {
    5171        3135 :                 result->op_type = IS_CONST;
    5172        3135 :                 zend_ct_eval_unary_pm(&result->u.constant, ast->kind, &expr_node.u.constant TSRMLS_CC);
    5173        3135 :                 zval_ptr_dtor(&expr_node.u.constant);
    5174        3135 :                 return;
    5175             :         }
    5176             : 
    5177          44 :         zero_node.op_type = IS_CONST;
    5178          44 :         ZVAL_LONG(&zero_node.u.constant, 0);
    5179             : 
    5180          44 :         zend_emit_op_tmp(result, ast->kind == ZEND_AST_UNARY_PLUS ? ZEND_ADD : ZEND_SUB,
    5181             :                 &zero_node, &expr_node TSRMLS_CC);
    5182             : }
    5183             : /* }}} */
    5184             : 
    5185       11787 : void zend_compile_short_circuiting(znode *result, zend_ast *ast TSRMLS_DC) /* {{{ */
    5186             : {
    5187       11787 :         zend_ast *left_ast = ast->child[0];
    5188       11787 :         zend_ast *right_ast = ast->child[1];
    5189             : 
    5190             :         znode left_node, right_node;
    5191             :         zend_op *opline_jmpz, *opline_bool;
    5192             :         uint32_t opnum_jmpz;
    5193             : 
    5194             :         ZEND_ASSERT(ast->kind == ZEND_AST_AND || ast->kind == ZEND_AST_OR);
    5195             : 
    5196       11787 :         zend_compile_expr(&left_node, left_ast TSRMLS_CC);
    5197             : 
    5198       11787 :         opnum_jmpz = get_next_op_number(CG(active_op_array));
    5199       11787 :         opline_jmpz = zend_emit_op(NULL, ast->kind == ZEND_AST_AND ? ZEND_JMPZ_EX : ZEND_JMPNZ_EX,
    5200             :                 &left_node, NULL TSRMLS_CC);
    5201             : 
    5202       11787 :         if (left_node.op_type == IS_TMP_VAR) {
    5203        9301 :                 SET_NODE(opline_jmpz->result, &left_node);
    5204             :         } else {
    5205        2486 :                 opline_jmpz->result.var = get_temporary_variable(CG(active_op_array));
    5206        2486 :                 opline_jmpz->result_type = IS_TMP_VAR;
    5207             :         }
    5208       11787 :         GET_NODE(result, opline_jmpz->result);
    5209             : 
    5210       11787 :         zend_compile_expr(&right_node, right_ast TSRMLS_CC);
    5211             : 
    5212       11787 :         opline_bool = zend_emit_op(NULL, ZEND_BOOL, &right_node, NULL TSRMLS_CC);
    5213       11787 :         SET_NODE(opline_bool->result, result);
    5214             : 
    5215       11787 :         zend_update_jump_target_to_next(opnum_jmpz TSRMLS_CC);
    5216       11787 : }
    5217             : /* }}} */
    5218             : 
    5219        5542 : void zend_compile_post_incdec(znode *result, zend_ast *ast TSRMLS_DC) /* {{{ */
    5220             : {
    5221        5542 :         zend_ast *var_ast = ast->child[0];
    5222             :         ZEND_ASSERT(ast->kind == ZEND_AST_POST_INC || ast->kind == ZEND_AST_POST_DEC);
    5223             : 
    5224        5542 :         if (var_ast->kind == ZEND_AST_PROP) {
    5225          51 :                 zend_op *opline = zend_compile_prop_common(NULL, var_ast, BP_VAR_RW TSRMLS_CC);
    5226          51 :                 opline->opcode = ast->kind == ZEND_AST_POST_INC ? ZEND_POST_INC_OBJ : ZEND_POST_DEC_OBJ;
    5227          51 :                 zend_make_tmp_result(result, opline TSRMLS_CC);
    5228             :         } else {
    5229             :                 znode var_node;
    5230        5491 :                 zend_compile_var(&var_node, var_ast, BP_VAR_RW TSRMLS_CC);
    5231        5491 :                 zend_emit_op_tmp(result, ast->kind == ZEND_AST_POST_INC ? ZEND_POST_INC : ZEND_POST_DEC,
    5232             :                         &var_node, NULL TSRMLS_CC);
    5233             :         }
    5234        5542 : }
    5235             : /* }}} */
    5236             : 
    5237         532 : void zend_compile_pre_incdec(znode *result, zend_ast *ast TSRMLS_DC) /* {{{ */
    5238             : {
    5239         532 :         zend_ast *var_ast = ast->child[0];
    5240             :         ZEND_ASSERT(ast->kind == ZEND_AST_PRE_INC || ast->kind == ZEND_AST_PRE_DEC);
    5241             : 
    5242         532 :         if (var_ast->kind == ZEND_AST_PROP) {
    5243          27 :                 zend_op *opline = zend_compile_prop_common(result, var_ast, BP_VAR_RW TSRMLS_CC);
    5244          27 :                 opline->opcode = ast->kind == ZEND_AST_PRE_INC ? ZEND_PRE_INC_OBJ : ZEND_PRE_DEC_OBJ;
    5245             :         } else {
    5246             :                 znode var_node;
    5247         505 :                 zend_compile_var(&var_node, var_ast, BP_VAR_RW TSRMLS_CC);
    5248         505 :                 zend_emit_op(result, ast->kind == ZEND_AST_PRE_INC ? ZEND_PRE_INC : ZEND_PRE_DEC,
    5249             :                         &var_node, NULL TSRMLS_CC);
    5250             :         }
    5251         532 : }
    5252             : /* }}} */
    5253             : 
    5254        6549 : void zend_compile_cast(znode *result, zend_ast *ast TSRMLS_DC) /* {{{ */
    5255             : {
    5256        6549 :         zend_ast *expr_ast = ast->child[0];
    5257             :         znode expr_node;
    5258             :         zend_op *opline;
    5259             : 
    5260        6549 :         zend_compile_expr(&expr_node, expr_ast TSRMLS_CC);
    5261             : 
    5262        6549 :         opline = zend_emit_op_tmp(result, ZEND_CAST, &expr_node, NULL TSRMLS_CC);
    5263        6549 :         opline->extended_value = ast->attr;
    5264        6549 : }
    5265             : /* }}} */
    5266             : 
    5267         149 : static void zend_compile_shorthand_conditional(znode *result, zend_ast *ast TSRMLS_DC) /* {{{ */
    5268             : {
    5269         149 :         zend_ast *cond_ast = ast->child[0];
    5270         149 :         zend_ast *false_ast = ast->child[2];
    5271             : 
    5272             :         znode cond_node, false_node;
    5273             :         zend_op *opline_jmp_set, *opline_qm_assign;
    5274             :         uint32_t opnum_jmp_set;
    5275             : 
    5276             :         ZEND_ASSERT(ast->child[1] == NULL);
    5277             : 
    5278         149 :         zend_compile_expr(&cond_node, cond_ast TSRMLS_CC);
    5279             : 
    5280         149 :         opnum_jmp_set = get_next_op_number(CG(active_op_array));
    5281         149 :         zend_emit_op_tmp(result, ZEND_JMP_SET, &cond_node, NULL TSRMLS_CC);
    5282             : 
    5283         149 :         zend_compile_expr(&false_node, false_ast TSRMLS_CC);
    5284             : 
    5285         149 :         opline_jmp_set = &CG(active_op_array)->opcodes[opnum_jmp_set];
    5286         149 :         opline_jmp_set->op2.opline_num = get_next_op_number(CG(active_op_array)) + 1;
    5287         149 :         opline_qm_assign = zend_emit_op_tmp(NULL, ZEND_QM_ASSIGN, &false_node, NULL TSRMLS_CC);
    5288         149 :         SET_NODE(opline_qm_assign->result, result);
    5289         149 : }
    5290             : /* }}} */
    5291             : 
    5292       27351 : void zend_compile_conditional(znode *result, zend_ast *ast TSRMLS_DC) /* {{{ */
    5293             : {
    5294       27351 :         zend_ast *cond_ast = ast->child[0];
    5295       27351 :         zend_ast *true_ast = ast->child[1];
    5296       27351 :         zend_ast *false_ast = ast->child[2];
    5297             : 
    5298             :         znode cond_node, true_node, false_node;
    5299             :         zend_op *opline_qm_assign1, *opline_qm_assign2;
    5300             :         uint32_t opnum_jmpz, opnum_jmp, opnum_qm_assign1;
    5301             : 
    5302       27351 :         if (!true_ast) {
    5303         149 :                 zend_compile_shorthand_conditional(result, ast TSRMLS_CC);
    5304         149 :                 return;
    5305             :         }
    5306             :         
    5307       27202 :         zend_compile_expr(&cond_node, cond_ast TSRMLS_CC);
    5308             : 
    5309       27202 :         opnum_jmpz = zend_emit_cond_jump(ZEND_JMPZ, &cond_node, 0 TSRMLS_CC);
    5310             : 
    5311       27202 :         zend_compile_expr(&true_node, true_ast TSRMLS_CC);
    5312             : 
    5313       27202 :         opnum_qm_assign1 = get_next_op_number(CG(active_op_array));
    5314       27202 :         zend_emit_op_tmp(result, ZEND_QM_ASSIGN, &true_node, NULL TSRMLS_CC);
    5315             : 
    5316       27202 :         opnum_jmp = zend_emit_jump(0 TSRMLS_CC);
    5317             : 
    5318       27202 :         zend_update_jump_target_to_next(opnum_jmpz TSRMLS_CC);
    5319             : 
    5320       27202 :         zend_compile_expr(&false_node, false_ast TSRMLS_CC);
    5321             : 
    5322       27202 :         opline_qm_assign1 = &CG(active_op_array)->opcodes[opnum_qm_assign1];
    5323       27202 :         opline_qm_assign2 = zend_emit_op(NULL, opline_qm_assign1->opcode, &false_node, NULL TSRMLS_CC);
    5324       27202 :         SET_NODE(opline_qm_assign2->result, result);
    5325             : 
    5326       27202 :         zend_update_jump_target_to_next(opnum_jmp TSRMLS_CC);
    5327             : }
    5328             : /* }}} */
    5329             : 
    5330          16 : void zend_compile_coalesce(znode *result, zend_ast *ast TSRMLS_DC) /* {{{ */
    5331             : {
    5332          16 :         zend_ast *expr_ast = ast->child[0];
    5333          16 :         zend_ast *default_ast = ast->child[1];
    5334             : 
    5335             :         znode expr_node, default_node;
    5336             :         zend_op *opline;
    5337             :         uint32_t opnum;
    5338             : 
    5339          16 :         zend_compile_var(&expr_node, expr_ast, BP_VAR_IS TSRMLS_CC);
    5340             : 
    5341          16 :         opnum = get_next_op_number(CG(active_op_array));
    5342          16 :         zend_emit_op_tmp(result, ZEND_COALESCE, &expr_node, NULL TSRMLS_CC);
    5343             : 
    5344          16 :         zend_compile_expr(&default_node, default_ast TSRMLS_CC);
    5345             : 
    5346          16 :         opline = zend_emit_op_tmp(NULL, ZEND_QM_ASSIGN, &default_node, NULL TSRMLS_CC);
    5347          16 :         SET_NODE(opline->result, result);
    5348             : 
    5349          16 :         opline = &CG(active_op_array)->opcodes[opnum];
    5350          16 :         opline->op2.opline_num = get_next_op_number(CG(active_op_array));
    5351          16 : }
    5352             : /* }}} */
    5353             : 
    5354        3397 : void zend_compile_print(znode *result, zend_ast *ast TSRMLS_DC) /* {{{ */
    5355             : {
    5356        3397 :         zend_ast *expr_ast = ast->child[0];
    5357             : 
    5358             :         znode expr_node;
    5359        3397 :         zend_compile_expr(&expr_node, expr_ast TSRMLS_CC);
    5360             : 
    5361        3397 :         zend_emit_op_tmp(result, ZEND_PRINT, &expr_node, NULL TSRMLS_CC);
    5362        3397 : }
    5363             : /* }}} */
    5364             : 
    5365       14439 : void zend_compile_exit(znode *result, zend_ast *ast TSRMLS_DC) /* {{{ */
    5366             : {
    5367       14439 :         zend_ast *expr_ast = ast->child[0];
    5368             : 
    5369       14439 :         if (expr_ast) {
    5370             :                 znode expr_node;
    5371       13905 :                 zend_compile_expr(&expr_node, expr_ast TSRMLS_CC);
    5372       13905 :                 zend_emit_op(NULL, ZEND_EXIT, &expr_node, NULL TSRMLS_CC);
    5373             :         } else {
    5374         534 :                 zend_emit_op(NULL, ZEND_EXIT, NULL, NULL TSRMLS_CC);
    5375             :         }
    5376             : 
    5377       14439 :         result->op_type = IS_CONST;
    5378       14439 :         ZVAL_BOOL(&result->u.constant, 1);
    5379       14439 : }
    5380             : /* }}} */
    5381             : 
    5382         121 : void zend_compile_yield(znode *result, zend_ast *ast TSRMLS_DC) /* {{{ */
    5383             : {
    5384         121 :         zend_ast *value_ast = ast->child[0];
    5385         121 :         zend_ast *key_ast = ast->child[1];
    5386             : 
    5387             :         znode value_node, key_node;
    5388         121 :         znode *value_node_ptr = NULL, *key_node_ptr = NULL;
    5389             :         zend_op *opline;
    5390         121 :         zend_bool returns_by_ref = (CG(active_op_array)->fn_flags & ZEND_ACC_RETURN_REFERENCE) != 0;
    5391             : 
    5392         121 :         if (!CG(active_op_array)->function_name) {
    5393           1 :                 zend_error_noreturn(E_COMPILE_ERROR,
    5394             :                         "The \"yield\" expression can only be used inside a function");
    5395             :         }
    5396             : 
    5397         120 :         CG(active_op_array)->fn_flags |= ZEND_ACC_GENERATOR;
    5398             : 
    5399         120 :         if (key_ast) {
    5400          17 :                 zend_compile_expr(&key_node, key_ast TSRMLS_CC);
    5401          17 :                 key_node_ptr = &key_node;
    5402             :         }
    5403             : 
    5404         120 :         if (value_ast) {
    5405          89 :                 if (returns_by_ref && zend_is_variable(value_ast) && !zend_is_call(value_ast)) {
    5406           5 :                         zend_compile_var(&value_node, value_ast, BP_VAR_REF TSRMLS_CC);
    5407             :                 } else {
    5408          79 :                         zend_compile_expr(&value_node, value_ast TSRMLS_CC);
    5409             :                 }
    5410          84 :                 value_node_ptr = &value_node;
    5411             :         }
    5412             : 
    5413         120 :         opline = zend_emit_op(result, ZEND_YIELD, value_node_ptr, key_node_ptr TSRMLS_CC);
    5414             : 
    5415         120 :         if (value_ast && returns_by_ref && zend_is_call(value_ast)) {
    5416           2 :                 opline->extended_value = ZEND_RETURNS_FUNCTION;
    5417             :         }
    5418         120 : }
    5419             : /* }}} */
    5420             : 
    5421          65 : void zend_compile_instanceof(znode *result, zend_ast *ast TSRMLS_DC) /* {{{ */
    5422             : {
    5423          65 :         zend_ast *obj_ast = ast->child[0];
    5424          65 :         zend_ast *class_ast = ast->child[1];
    5425             : 
    5426             :         znode obj_node, class_node;
    5427             :         zend_op *opline;
    5428             : 
    5429          65 :         zend_compile_expr(&obj_node, obj_ast TSRMLS_CC);
    5430          65 :         if (obj_node.op_type == IS_CONST) {
    5431           1 :                 zend_error_noreturn(E_COMPILE_ERROR,
    5432             :                         "instanceof expects an object instance, constant given");
    5433             :         }
    5434             : 
    5435          64 :         if (zend_is_const_default_class_ref(class_ast)) {
    5436          60 :                 class_node.op_type = IS_CONST;
    5437          60 :                 ZVAL_STR(&class_node.u.constant, zend_resolve_class_name_ast(class_ast TSRMLS_CC));
    5438             :         } else {
    5439           4 :                 opline = zend_compile_class_ref(&class_node, class_ast TSRMLS_CC);
    5440           4 :                 opline->extended_value |= ZEND_FETCH_CLASS_NO_AUTOLOAD;
    5441             :         }
    5442             : 
    5443          64 :         opline = zend_emit_op_tmp(result, ZEND_INSTANCEOF, &obj_node, NULL TSRMLS_CC);
    5444             : 
    5445          64 :         if (class_node.op_type == IS_CONST) {
    5446          60 :                 opline->op2_type = IS_CONST;
    5447          60 :                 opline->op2.constant = zend_add_class_name_literal(
    5448             :                         CG(active_op_array), Z_STR(class_node.u.constant) TSRMLS_CC);
    5449             :         } else {
    5450           4 :                 SET_NODE(opline->op2, &class_node);
    5451             :         }
    5452          64 : }
    5453             : /* }}} */
    5454             : 
    5455       10828 : void zend_compile_include_or_eval(znode *result, zend_ast *ast TSRMLS_DC) /* {{{ */
    5456             : {
    5457       10828 :         zend_ast *expr_ast = ast->child[0];
    5458             :         znode expr_node;
    5459             :         zend_op *opline;
    5460             : 
    5461       10828 :         zend_do_extended_fcall_begin(TSRMLS_C);
    5462       10828 :         zend_compile_expr(&expr_node, expr_ast TSRMLS_CC);
    5463             : 
    5464       10828 :         opline = zend_emit_op(result, ZEND_INCLUDE_OR_EVAL, &expr_node, NULL TSRMLS_CC);
    5465       10828 :         opline->extended_value = ast->attr;
    5466             : 
    5467       10828 :         zend_do_extended_fcall_end(TSRMLS_C);
    5468       10828 : }
    5469             : /* }}} */
    5470             : 
    5471       13269 : void zend_compile_isset_or_empty(znode *result, zend_ast *ast TSRMLS_DC) /* {{{ */
    5472             : {
    5473       13269 :         zend_ast *var_ast = ast->child[0];
    5474             : 
    5475             :         znode var_node;
    5476       13269 :         zend_op *opline = NULL;
    5477             : 
    5478             :         ZEND_ASSERT(ast->kind == ZEND_AST_ISSET || ast->kind == ZEND_AST_EMPTY);
    5479             : 
    5480       13269 :         if (!zend_is_variable(var_ast) || zend_is_call(var_ast)) {
    5481          16 :                 if (ast->kind == ZEND_AST_EMPTY) {
    5482             :                         /* empty(expr) can be transformed to !expr */
    5483          14 :                         zend_ast *not_ast = zend_ast_create_ex(ZEND_AST_UNARY_OP, ZEND_BOOL_NOT, var_ast);
    5484          14 :                         zend_compile_expr(result, not_ast TSRMLS_CC);
    5485          14 :                         return;
    5486             :                 } else {
    5487           2 :                         zend_error_noreturn(E_COMPILE_ERROR,
    5488             :                                 "Cannot use isset() on the result of an expression "
    5489             :                                 "(you can use \"null !== expression\" instead)");
    5490             :                 }
    5491             :         }
    5492             : 
    5493       13253 :         switch (var_ast->kind) {
    5494             :                 case ZEND_AST_VAR:
    5495        3755 :                         if (zend_try_compile_cv(&var_node, var_ast TSRMLS_CC) == SUCCESS) {
    5496        3735 :                                 opline = zend_emit_op(result, ZEND_ISSET_ISEMPTY_VAR, &var_node, NULL TSRMLS_CC);
    5497        3735 :                                 opline->extended_value = ZEND_FETCH_LOCAL | ZEND_QUICK_SET;
    5498             :                         } else {
    5499          20 :                                 opline = zend_compile_simple_var_no_cv(result, var_ast, BP_VAR_IS TSRMLS_CC);
    5500          20 :                                 opline->opcode = ZEND_ISSET_ISEMPTY_VAR;
    5501             :                         }
    5502        3755 :                         break;
    5503             :                 case ZEND_AST_DIM:
    5504        8654 :                         opline = zend_compile_dim_common(result, var_ast, BP_VAR_IS TSRMLS_CC);
    5505        8653 :                         opline->opcode = ZEND_ISSET_ISEMPTY_DIM_OBJ;
    5506        8653 :                         break;
    5507             :                 case ZEND_AST_PROP:
    5508         734 :                         opline = zend_compile_prop_common(result, var_ast, BP_VAR_IS TSRMLS_CC);
    5509         734 :                         opline->opcode = ZEND_ISSET_ISEMPTY_PROP_OBJ;
    5510         734 :                         break;
    5511             :                 case ZEND_AST_STATIC_PROP:
    5512         110 :                         opline = zend_compile_static_prop_common(result, var_ast, BP_VAR_IS TSRMLS_CC);
    5513         110 :                         opline->opcode = ZEND_ISSET_ISEMPTY_VAR;
    5514             :                         break;
    5515             :                 EMPTY_SWITCH_DEFAULT_CASE()
    5516             :         }
    5517             : 
    5518       13252 :         result->op_type = opline->result_type = IS_TMP_VAR;
    5519       13252 :         opline->extended_value |= ast->kind == ZEND_AST_ISSET ? ZEND_ISSET : ZEND_ISEMPTY;
    5520             : }
    5521             : /* }}} */
    5522             : 
    5523        5571 : void zend_compile_silence(znode *result, zend_ast *ast TSRMLS_DC) /* {{{ */
    5524             : {
    5525        5571 :         zend_ast *expr_ast = ast->child[0];
    5526             :         znode silence_node;
    5527             :         uint32_t opline_num;
    5528             :         zend_op *begin_silence, *end_silence;
    5529             : 
    5530        5571 :         opline_num = get_next_op_number(CG(active_op_array));
    5531        5571 :         begin_silence = zend_emit_op_tmp(&silence_node, ZEND_BEGIN_SILENCE, NULL, NULL TSRMLS_CC);
    5532             :         /* pair BEGIN_SILENCE and END_SILENCE opcodes */
    5533        5571 :         begin_silence->op2.num = opline_num;
    5534             : 
    5535        5571 :         if (expr_ast->kind == ZEND_AST_VAR) {
    5536             :                 /* For @$var we need to force a FETCH instruction, otherwise the CV access will
    5537             :                  * happen outside the silenced section. */
    5538        1510 :                 zend_compile_simple_var_no_cv(result, expr_ast, BP_VAR_R TSRMLS_CC);
    5539             :         } else {
    5540        4061 :                 zend_compile_expr(result, expr_ast TSRMLS_CC);
    5541             :         }
    5542             : 
    5543        5571 :         end_silence = zend_emit_op(NULL, ZEND_END_SILENCE, &silence_node, NULL TSRMLS_CC);
    5544             :         /* pair BEGIN_SILENCE and END_SILENCE opcodes */
    5545        5571 :         end_silence->op2.num = opline_num;
    5546        5571 : }
    5547             : /* }}} */
    5548             : 
    5549         113 : void zend_compile_shell_exec(znode *result, zend_ast *ast TSRMLS_DC) /* {{{ */
    5550             : {
    5551         113 :         zend_ast *expr_ast = ast->child[0];
    5552             : 
    5553             :         zval fn_name;
    5554             :         zend_ast *name_ast, *args_ast, *call_ast;
    5555             : 
    5556         226 :         ZVAL_STRING(&fn_name, "shell_exec");
    5557         113 :         name_ast = zend_ast_create_zval(&fn_name);
    5558         113 :         args_ast = zend_ast_create_list(1, ZEND_AST_ARG_LIST, expr_ast);
    5559         113 :         call_ast = zend_ast_create(ZEND_AST_CALL, name_ast, args_ast);
    5560             : 
    5561         113 :         zend_compile_expr(result, call_ast TSRMLS_CC);
    5562             : 
    5563         113 :         zval_ptr_dtor(&fn_name);
    5564         113 : }
    5565             : /* }}} */
    5566             : 
    5567       15704 : void zend_compile_array(znode *result, zend_ast *ast TSRMLS_DC) /* {{{ */
    5568             : {
    5569       15704 :         zend_ast_list *list = zend_ast_get_list(ast);
    5570             :         zend_op *opline;
    5571       15704 :         uint32_t i, opnum_init = -1;
    5572       15704 :         zend_bool packed = 1;
    5573             : 
    5574       15704 :         if (zend_try_ct_eval_array(&result->u.constant, ast TSRMLS_CC)) {
    5575       10924 :                 result->op_type = IS_CONST;
    5576       10924 :                 return;
    5577             :         }
    5578             : 
    5579       36561 :         for (i = 0; i < list->children; ++i) {
    5580       31781 :                 zend_ast *elem_ast = list->child[i];
    5581       31781 :                 zend_ast *value_ast = elem_ast->child[0];
    5582       31781 :                 zend_ast *key_ast = elem_ast->child[1];
    5583       31781 :                 zend_bool by_ref = elem_ast->attr;
    5584             : 
    5585       31781 :                 znode value_node, key_node, *key_node_ptr = NULL;
    5586             : 
    5587       31781 :                 if (key_ast) {
    5588       11211 :                         zend_compile_expr(&key_node, key_ast TSRMLS_CC);
    5589       11211 :                         zend_handle_numeric_op(&key_node TSRMLS_CC);
    5590       11211 :                         key_node_ptr = &key_node;
    5591             :                 }
    5592             : 
    5593       31781 :                 if (by_ref) {
    5594         151 :                         zend_ensure_writable_variable(value_ast);
    5595         151 :                         zend_compile_var(&value_node, value_ast, BP_VAR_W TSRMLS_CC);
    5596             :                 } else {
    5597       31630 :                         zend_compile_expr(&value_node, value_ast TSRMLS_CC);
    5598             :                 }
    5599             : 
    5600       31781 :                 if (i == 0) {
    5601        4780 :                         opnum_init = get_next_op_number(CG(active_op_array));
    5602        4780 :                         opline = zend_emit_op_tmp(result, ZEND_INIT_ARRAY, &value_node, key_node_ptr TSRMLS_CC);
    5603        4780 :                         opline->extended_value = list->children << ZEND_ARRAY_SIZE_SHIFT;
    5604             :                 } else {
    5605       27001 :                         opline = zend_emit_op(NULL, ZEND_ADD_ARRAY_ELEMENT,
    5606             :                                 &value_node, key_node_ptr TSRMLS_CC);
    5607       27001 :                         SET_NODE(opline->result, result);
    5608             :                 }
    5609       31781 :                 opline->extended_value |= by_ref;
    5610             : 
    5611       42623 :                 if (key_ast && key_node.op_type == IS_CONST && Z_TYPE(key_node.u.constant) == IS_STRING) {
    5612       10147 :                         packed = 0;
    5613             :                 }
    5614             :         }
    5615             : 
    5616             :         /* Handle empty array */
    5617        4780 :         if (!list->children) {
    5618           0 :                 zend_emit_op_tmp(result, ZEND_INIT_ARRAY, NULL, NULL TSRMLS_CC);
    5619             :         }
    5620             : 
    5621             :         /* Add a flag to INIT_ARRAY if we know this array cannot be packed */
    5622        4780 :         if (!packed) {
    5623             :                 ZEND_ASSERT(opnum_init != -1);
    5624        1987 :                 opline = &CG(active_op_array)->opcodes[opnum_init];
    5625        1987 :                 opline->extended_value |= ZEND_ARRAY_NOT_PACKED;
    5626             :         }
    5627             : }
    5628             : /* }}} */
    5629             : 
    5630       64634 : void zend_compile_const(znode *result, zend_ast *ast TSRMLS_DC) /* {{{ */
    5631             : {
    5632       64634 :         zend_ast *name_ast = ast->child[0];
    5633             : 
    5634             :         zend_op *opline;
    5635             : 
    5636             :         zend_bool is_fully_qualified;
    5637       64634 :         zend_string *orig_name = zend_ast_get_str(name_ast);
    5638       64634 :         zend_string *resolved_name = zend_resolve_const_name(
    5639      129268 :                 orig_name, name_ast->attr, &is_fully_qualified TSRMLS_CC);
    5640             : 
    5641       64634 :         if (zend_try_ct_eval_const(&result->u.constant, resolved_name, is_fully_qualified TSRMLS_CC)) {
    5642       59139 :                 result->op_type = IS_CONST;
    5643             :                 zend_string_release(resolved_name);
    5644       59139 :                 return;
    5645             :         }
    5646             : 
    5647        5495 :         opline = zend_emit_op_tmp(result, ZEND_FETCH_CONSTANT, NULL, NULL TSRMLS_CC);
    5648        5495 :         opline->op2_type = IS_CONST;
    5649             : 
    5650        5495 :         if (is_fully_qualified) {
    5651          60 :                 opline->op2.constant = zend_add_const_name_literal(
    5652             :                         CG(active_op_array), resolved_name, 0 TSRMLS_CC);
    5653             :         } else {
    5654        5435 :                 opline->extended_value = IS_CONSTANT_UNQUALIFIED;
    5655        5435 :                 if (CG(current_namespace)) {
    5656          21 :                         opline->extended_value |= IS_CONSTANT_IN_NAMESPACE;
    5657          21 :                         opline->op2.constant = zend_add_const_name_literal(
    5658             :                                 CG(active_op_array), resolved_name, 1 TSRMLS_CC);
    5659             :                 } else {
    5660        5414 :                         opline->op2.constant = zend_add_const_name_literal(
    5661             :                                 CG(active_op_array), resolved_name, 0 TSRMLS_CC);
    5662             :                 }
    5663             :         }
    5664        5495 :         zend_alloc_cache_slot(opline->op2.constant TSRMLS_CC);
    5665             : }
    5666             : /* }}} */
    5667             : 
    5668        8700 : void zend_compile_class_const(znode *result, zend_ast *ast TSRMLS_DC) /* {{{ */
    5669             : {
    5670        8700 :         zend_ast *class_ast = ast->child[0];
    5671        8700 :         zend_ast *const_ast = ast->child[1];
    5672             : 
    5673             :         znode class_node, const_node;
    5674             :         zend_op *opline;
    5675             : 
    5676        8700 :         if (zend_is_const_default_class_ref(class_ast)) {
    5677        8643 :                 class_node.op_type = IS_CONST;
    5678        8643 :                 ZVAL_STR(&class_node.u.constant, zend_resolve_class_name_ast(class_ast TSRMLS_CC));
    5679             :         } else {
    5680          57 :                 zend_compile_class_ref(&class_node, class_ast TSRMLS_CC);
    5681             :         }
    5682             : 
    5683        8700 :         zend_compile_expr(&const_node, const_ast TSRMLS_CC);
    5684             : 
    5685        8700 :         opline = zend_emit_op_tmp(result, ZEND_FETCH_CONSTANT, NULL, &const_node TSRMLS_CC);
    5686             : 
    5687        8700 :         zend_set_class_name_op1(opline, &class_node TSRMLS_CC);
    5688             : 
    5689        8700 :         if (opline->op1_type == IS_CONST) {
    5690        8643 :                 zend_alloc_cache_slot(opline->op2.constant TSRMLS_CC);
    5691             :         } else {
    5692          57 :                 zend_alloc_polymorphic_cache_slot(opline->op2.constant TSRMLS_CC);
    5693             :         }
    5694        8700 : }
    5695             : /* }}} */
    5696             : 
    5697          21 : void zend_compile_resolve_class_name(znode *result, zend_ast *ast TSRMLS_DC) /* {{{ */
    5698             : {
    5699          21 :         zend_ast *name_ast = ast->child[0];
    5700          21 :         uint32_t fetch_type = zend_get_class_fetch_type(zend_ast_get_str(name_ast));
    5701             : 
    5702          21 :         switch (fetch_type) {
    5703             :                 case ZEND_FETCH_CLASS_SELF:
    5704           6 :                         if (!CG(active_class_entry)) {
    5705           1 :                                 zend_error_noreturn(E_COMPILE_ERROR,
    5706             :                                         "Cannot access self::class when no class scope is active");
    5707             :                         }
    5708           5 :                         result->op_type = IS_CONST;
    5709           5 :                         ZVAL_STR_COPY(&result->u.constant, CG(active_class_entry)->name);
    5710           5 :                         break;
    5711             :         case ZEND_FETCH_CLASS_STATIC:
    5712             :         case ZEND_FETCH_CLASS_PARENT:
    5713           8 :                         if (!CG(active_class_entry)) {
    5714           2 :                                 zend_error_noreturn(E_COMPILE_ERROR,
    5715             :                                         "Cannot access %s::class when no class scope is active",
    5716             :                                         fetch_type == ZEND_FETCH_CLASS_STATIC ? "static" : "parent");
    5717             :                         } else {
    5718             :                                 zval class_str_zv;
    5719             :                                 zend_ast *class_str_ast, *class_const_ast;
    5720             : 
    5721          12 :                                 ZVAL_STRING(&class_str_zv, "class");
    5722           6 :                                 class_str_ast = zend_ast_create_zval(&class_str_zv);
    5723           6 :                                 class_const_ast = zend_ast_create(
    5724             :                                         ZEND_AST_CLASS_CONST, name_ast, class_str_ast);
    5725             : 
    5726           6 :                                 zend_compile_expr(result, class_const_ast TSRMLS_CC);
    5727             : 
    5728           6 :                                 zval_ptr_dtor(&class_str_zv);
    5729             :                         }
    5730           6 :                         break;
    5731             :                 case ZEND_FETCH_CLASS_DEFAULT:
    5732           7 :                         result->op_type = IS_CONST;
    5733           7 :                         ZVAL_STR(&result->u.constant, zend_resolve_class_name_ast(name_ast TSRMLS_CC));
    5734             :                         break;
    5735             :                 EMPTY_SWITCH_DEFAULT_CASE()
    5736             :         }
    5737          18 : }
    5738             : /* }}} */
    5739             : 
    5740       12515 : void zend_compile_encaps_list(znode *result, zend_ast *ast TSRMLS_DC) /* {{{ */
    5741             : {
    5742       12515 :         zend_ast_list *list = zend_ast_get_list(ast);
    5743             :         uint32_t i;
    5744             : 
    5745             :         ZEND_ASSERT(list->children > 0);
    5746             : 
    5747       12515 :         result->op_type = IS_TMP_VAR;
    5748       12515 :         result->u.op.var = get_temporary_variable(CG(active_op_array));
    5749             : 
    5750       53720 :         for (i = 0; i < list->children; ++i) {
    5751       41205 :                 zend_ast *elem_ast = list->child[i];
    5752             :                 znode elem_node;
    5753             :                 zend_op *opline;
    5754             : 
    5755       41205 :                 zend_compile_expr(&elem_node, elem_ast TSRMLS_CC);
    5756             : 
    5757       41205 :                 if (elem_ast->kind == ZEND_AST_ZVAL) {
    5758       22723 :                         zval *zv = &elem_node.u.constant;
    5759             :                         ZEND_ASSERT(Z_TYPE_P(zv) == IS_STRING);
    5760             : 
    5761       22723 :                         if (Z_STRLEN_P(zv) > 1) {
    5762       17783 :                                 opline = get_next_op(CG(active_op_array) TSRMLS_CC);
    5763       17783 :                                 opline->opcode = ZEND_ADD_STRING;
    5764        4940 :                         } else if (Z_STRLEN_P(zv) == 1) {
    5765        4932 :                                 char ch = *Z_STRVAL_P(zv);
    5766        4932 :                                 zend_string_release(Z_STR_P(zv));
    5767        4932 :                                 ZVAL_LONG(zv, ch);
    5768             : 
    5769        4932 :                                 opline = get_next_op(CG(active_op_array) TSRMLS_CC);
    5770        4932 :                                 opline->opcode = ZEND_ADD_CHAR;
    5771             :                         } else {
    5772             :                                 /* String can be empty after a variable at the end of a heredoc */
    5773           8 :                                 zend_string_release(Z_STR_P(zv));
    5774           8 :                                 continue;
    5775             :                         }
    5776             :                 } else {
    5777       18482 :                         opline = get_next_op(CG(active_op_array) TSRMLS_CC);
    5778       18482 :                         opline->opcode = ZEND_ADD_VAR;
    5779             :                         ZEND_ASSERT(elem_node.op_type != IS_CONST);
    5780             :                 }
    5781             : 
    5782       41197 :                 if (i == 0) {
    5783       12515 :                         SET_UNUSED(opline->op1);
    5784             :                 } else {
    5785       28682 :                         SET_NODE(opline->op1, result);
    5786             :                 }
    5787       41197 :                 SET_NODE(opline->op2, &elem_node);
    5788       41197 :                 SET_NODE(opline->result, result);
    5789             :         }
    5790       12515 : }
    5791             : /* }}} */
    5792             : 
    5793        8559 : void zend_compile_magic_const(znode *result, zend_ast *ast TSRMLS_DC) /* {{{ */
    5794             : {
    5795        8559 :         zend_class_entry *ce = CG(active_class_entry);
    5796             : 
    5797        8559 :         if (zend_try_ct_eval_magic_const(&result->u.constant, ast TSRMLS_CC)) {
    5798        8556 :                 result->op_type = IS_CONST;
    5799        8556 :                 return;
    5800             :         }
    5801             : 
    5802             :         ZEND_ASSERT(ast->attr == T_CLASS_C && ce && ZEND_CE_IS_TRAIT(ce));
    5803             : 
    5804             :         {
    5805           3 :                 zend_ast *const_ast = zend_ast_create(ZEND_AST_CONST,
    5806           3 :                         zend_ast_create_zval_from_str(zend_string_init("__CLASS__", sizeof("__CLASS__") - 1, 0)));
    5807           3 :                 zend_compile_const(result, const_ast TSRMLS_CC);
    5808           3 :                 zend_ast_destroy(const_ast);
    5809             :         }
    5810             : }
    5811             : /* }}} */
    5812             : 
    5813         797 : zend_bool zend_is_allowed_in_const_expr(zend_ast_kind kind) /* {{{ */
    5814             : {
    5815         797 :         return kind == ZEND_AST_ZVAL || kind == ZEND_AST_BINARY_OP
    5816             :                 || kind == ZEND_AST_GREATER || kind == ZEND_AST_GREATER_EQUAL
    5817             :                 || kind == ZEND_AST_AND || kind == ZEND_AST_OR
    5818             :                 || kind == ZEND_AST_UNARY_OP
    5819             :                 || kind == ZEND_AST_UNARY_PLUS || kind == ZEND_AST_UNARY_MINUS
    5820             :                 || kind == ZEND_AST_CONDITIONAL || kind == ZEND_AST_DIM
    5821             :                 || kind == ZEND_AST_ARRAY || kind == ZEND_AST_ARRAY_ELEM
    5822             :                 || kind == ZEND_AST_CONST || kind == ZEND_AST_CLASS_CONST
    5823             :                 || kind == ZEND_AST_RESOLVE_CLASS_NAME || kind == ZEND_AST_MAGIC_CONST;
    5824             : }
    5825             : /* }}} */
    5826             : 
    5827         362 : void zend_compile_const_expr_class_const(zend_ast **ast_ptr TSRMLS_DC) /* {{{ */
    5828             : {
    5829         362 :         zend_ast *ast = *ast_ptr;
    5830         362 :         zend_ast *class_ast = ast->child[0];
    5831         362 :         zend_ast *const_ast = ast->child[1];
    5832             :         zend_string *class_name;
    5833         362 :         zend_string *const_name = zend_ast_get_str(const_ast);
    5834             :         zval result;
    5835             :         int fetch_type;
    5836             : 
    5837         362 :         if (class_ast->kind != ZEND_AST_ZVAL) {
    5838           1 :                 zend_error_noreturn(E_COMPILE_ERROR,
    5839             :                         "Dynamic class names are not allowed in compile-time class constant references");
    5840             :         }
    5841             : 
    5842         361 :         class_name = zend_ast_get_str(class_ast);
    5843         361 :         fetch_type = zend_get_class_fetch_type(class_name);
    5844             : 
    5845         361 :         if (ZEND_FETCH_CLASS_STATIC == fetch_type) {
    5846           1 :                 zend_error_noreturn(E_COMPILE_ERROR,
    5847             :                         "\"static::\" is not allowed in compile-time constants");
    5848             :         }
    5849             :         
    5850         360 :         if (ZEND_FETCH_CLASS_DEFAULT == fetch_type) {
    5851         297 :                 class_name = zend_resolve_class_name_ast(class_ast TSRMLS_CC);
    5852             :         } else {
    5853             :                 zend_string_addref(class_name);
    5854             :         }
    5855             : 
    5856         360 :         Z_STR(result) = zend_concat3(
    5857             :                 class_name->val, class_name->len, "::", 2, const_name->val, const_name->len);
    5858             : 
    5859         360 :         Z_TYPE_INFO(result) = IS_CONSTANT_EX;
    5860         360 :         Z_CONST_FLAGS(result) = fetch_type;
    5861             : 
    5862         360 :         zend_ast_destroy(ast);
    5863             :         zend_string_release(class_name);
    5864             : 
    5865         360 :         *ast_ptr = zend_ast_create_zval(&result);
    5866         360 : }
    5867             : /* }}} */
    5868             : 
    5869         149 : void zend_compile_const_expr_const(zend_ast **ast_ptr TSRMLS_DC) /* {{{ */
    5870             : {
    5871         149 :         zend_ast *ast = *ast_ptr;
    5872         149 :         zend_ast *name_ast = ast->child[0];
    5873         149 :         zend_string *orig_name = zend_ast_get_str(name_ast);
    5874             :         zend_bool is_fully_qualified;
    5875             : 
    5876             :         zval result, resolved_name;
    5877         149 :         ZVAL_STR(&resolved_name, zend_resolve_const_name(
    5878             :                 orig_name, name_ast->attr, &is_fully_qualified TSRMLS_CC));
    5879             : 
    5880         149 :         if (zend_try_ct_eval_const(&result, Z_STR(resolved_name), is_fully_qualified TSRMLS_CC)) {
    5881           6 :                 zend_string_release(Z_STR(resolved_name));
    5882           6 :                 zend_ast_destroy(ast);
    5883           6 :                 *ast_ptr = zend_ast_create_zval(&result);
    5884           6 :                 return;
    5885             :         }
    5886             : 
    5887         143 :         Z_TYPE_INFO(resolved_name) = IS_CONSTANT_EX;
    5888         143 :         if (!is_fully_qualified) {
    5889         101 :                 Z_CONST_FLAGS(resolved_name) = IS_CONSTANT_UNQUALIFIED;
    5890             :         }
    5891             : 
    5892         143 :         zend_ast_destroy(ast);
    5893         143 :         *ast_ptr = zend_ast_create_zval(&resolved_name);
    5894             : }
    5895             : /* }}} */
    5896             : 
    5897           8 : void zend_compile_const_expr_resolve_class_name(zend_ast **ast_ptr TSRMLS_DC) /* {{{ */
    5898             : {
    5899           8 :         zend_ast *ast = *ast_ptr;
    5900           8 :         zend_ast *name_ast = ast->child[0];
    5901           8 :         uint32_t fetch_type = zend_get_class_fetch_type(zend_ast_get_str(name_ast));
    5902             :         zval result;
    5903             : 
    5904           8 :         switch (fetch_type) {
    5905             :                 case ZEND_FETCH_CLASS_SELF:
    5906           2 :                         if (!CG(active_class_entry)) {
    5907           0 :                                 zend_error_noreturn(E_COMPILE_ERROR,
    5908             :                                         "Cannot access self::class when no class scope is active");
    5909             :                         }
    5910           2 :                         ZVAL_STR_COPY(&result, CG(active_class_entry)->name);
    5911           2 :                         break;
    5912             :         case ZEND_FETCH_CLASS_STATIC:
    5913             :         case ZEND_FETCH_CLASS_PARENT:
    5914           4 :                         zend_error_noreturn(E_COMPILE_ERROR,
    5915             :                                 "%s::class cannot be used for compile-time class name resolution",
    5916             :                                 fetch_type == ZEND_FETCH_CLASS_STATIC ? "static" : "parent"
    5917             :                         );
    5918             :                         break;
    5919             :                 case ZEND_FETCH_CLASS_DEFAULT:
    5920           2 :                         ZVAL_STR(&result, zend_resolve_class_name_ast(name_ast TSRMLS_CC));
    5921             :                         break;
    5922             :                 EMPTY_SWITCH_DEFAULT_CASE()
    5923             :         }
    5924             : 
    5925           4 :         zend_ast_destroy(ast);
    5926           4 :         *ast_ptr = zend_ast_create_zval(&result);
    5927           4 : }
    5928             : /* }}} */
    5929             : 
    5930           2 : void zend_compile_const_expr_magic_const(zend_ast **ast_ptr TSRMLS_DC) /* {{{ */
    5931             : {
    5932           2 :         zend_ast *ast = *ast_ptr;
    5933           2 :         zend_class_entry *ce = CG(active_class_entry);
    5934             : 
    5935             :         /* Other cases already resolved by constant folding */
    5936             :         ZEND_ASSERT(ast->attr == T_CLASS_C && ce && ZEND_CE_IS_TRAIT(ce));
    5937             : 
    5938             :         {
    5939             :                 zval const_zv;
    5940           4 :                 ZVAL_STRING(&const_zv, "__CLASS__");
    5941           2 :                 Z_TYPE_INFO(const_zv) = IS_CONSTANT_EX;
    5942             : 
    5943           2 :                 zend_ast_destroy(ast);
    5944           2 :                 *ast_ptr = zend_ast_create_zval(&const_zv);
    5945             :         }
    5946           2 : }
    5947             : /* }}} */
    5948             : 
    5949       18234 : void zend_compile_const_expr(zend_ast **ast_ptr TSRMLS_DC) /* {{{ */
    5950             : {
    5951       18234 :         zend_ast *ast = *ast_ptr;
    5952       18234 :         if (ast == NULL || ast->kind == ZEND_AST_ZVAL) {
    5953       17437 :                 return;
    5954             :         }
    5955             : 
    5956         797 :         if (!zend_is_allowed_in_const_expr(ast->kind)) {
    5957           1 :                 zend_error_noreturn(E_COMPILE_ERROR, "Constant expression contains invalid operations");
    5958             :         }
    5959             : 
    5960         796 :         switch (ast->kind) {
    5961             :                 case ZEND_AST_CLASS_CONST:
    5962         362 :                         zend_compile_const_expr_class_const(ast_ptr TSRMLS_CC);
    5963         360 :                         break;
    5964             :                 case ZEND_AST_CONST:
    5965         149 :                         zend_compile_const_expr_const(ast_ptr TSRMLS_CC);
    5966         149 :                         break;
    5967             :                 case ZEND_AST_RESOLVE_CLASS_NAME:
    5968           8 :                         zend_compile_const_expr_resolve_class_name(ast_ptr TSRMLS_CC);
    5969           4 :                         break;
    5970             :                 case ZEND_AST_MAGIC_CONST:
    5971           2 :                         zend_compile_const_expr_magic_const(ast_ptr TSRMLS_CC);
    5972           2 :                         break;
    5973             :                 default:
    5974         275 :                         zend_ast_apply(ast, zend_compile_const_expr TSRMLS_CC);
    5975             :                         break;
    5976             :         }
    5977             : }
    5978             : /* }}} */
    5979             : 
    5980       17749 : void zend_const_expr_to_zval(zval *result, zend_ast *ast TSRMLS_DC) /* {{{ */
    5981             : {
    5982       17749 :         zend_ast *orig_ast = ast;
    5983       17749 :         zend_eval_const_expr(&ast TSRMLS_CC);
    5984       17749 :         zend_compile_const_expr(&ast TSRMLS_CC);
    5985       17742 :         if (ast->kind == ZEND_AST_ZVAL) {
    5986       35222 :                 ZVAL_COPY_VALUE(result, zend_ast_get_zval(ast));
    5987             : 
    5988             :                 /* Kill this branch of the original AST, as it was already destroyed.
    5989             :                  * It would be nice to find a better solution to this problem in the
    5990             :                  * future. */
    5991       17611 :                 orig_ast->kind = 0;
    5992             :         } else {
    5993         131 :                 ZVAL_NEW_AST(result, zend_ast_copy(ast));
    5994             :         }
    5995       17742 : }
    5996             : /* }}} */
    5997             : 
    5998             : /* Same as compile_stmt, but with early binding */
    5999      265604 : void zend_compile_top_stmt(zend_ast *ast TSRMLS_DC) /* {{{ */
    6000             : {
    6001      265604 :         if (!ast) {
    6002       27292 :                 return;
    6003             :         }
    6004             : 
    6005      238312 :         if (ast->kind == ZEND_AST_STMT_LIST) {
    6006       49364 :                 zend_ast_list *list = zend_ast_get_list(ast);
    6007             :                 uint32_t i;
    6008      285080 :                 for (i = 0; i < list->children; ++i) {
    6009      235910 :                         zend_compile_top_stmt(list->child[i] TSRMLS_CC);
    6010             :                 }
    6011       49170 :                 return;
    6012             :         }
    6013             : 
    6014      188948 :         zend_compile_stmt(ast TSRMLS_CC);
    6015             : 
    6016      188800 :         if (ast->kind != ZEND_AST_NAMESPACE && ast->kind != ZEND_AST_HALT_COMPILER) {
    6017      188344 :                 zend_verify_namespace(TSRMLS_C);
    6018             :         }
    6019      188799 :         if (ast->kind == ZEND_AST_FUNC_DECL || ast->kind == ZEND_AST_CLASS) {
    6020       19672 :                 CG(zend_lineno) = ((zend_ast_decl *) ast)->end_lineno;
    6021       19672 :                 zend_do_early_binding(TSRMLS_C);
    6022             :         }
    6023             : }
    6024             : /* }}} */
    6025             : 
    6026      606829 : void zend_compile_stmt(zend_ast *ast TSRMLS_DC) /* {{{ */
    6027             : {
    6028      606829 :         if (!ast) {
    6029         309 :                 return;
    6030             :         }
    6031             : 
    6032      606520 :         CG(zend_lineno) = ast->lineno;
    6033             : 
    6034      606520 :         switch (ast->kind) {
    6035             :                 case ZEND_AST_STMT_LIST:
    6036      134411 :                         zend_compile_stmt_list(ast TSRMLS_CC);
    6037      134356 :                         break;
    6038             :                 case ZEND_AST_GLOBAL:
    6039        4567 :                         zend_compile_global_var(ast TSRMLS_CC);
    6040        4567 :                         break;
    6041             :                 case ZEND_AST_STATIC:
    6042        1887 :                         zend_compile_static_var(ast TSRMLS_CC);
    6043        1887 :                         break;
    6044             :                 case ZEND_AST_UNSET:
    6045        1584 :                         zend_compile_unset(ast TSRMLS_CC);
    6046        1583 :                         break;
    6047             :                 case ZEND_AST_RETURN:
    6048       43663 :                         zend_compile_return(ast TSRMLS_CC);
    6049       43662 :                         break;
    6050             :                 case ZEND_AST_ECHO:
    6051       34025 :                         zend_compile_echo(ast TSRMLS_CC);
    6052       34025 :                         break;
    6053             :                 case ZEND_AST_THROW:
    6054         317 :                         zend_compile_throw(ast TSRMLS_CC);
    6055         317 :                         break;
    6056             :                 case ZEND_AST_BREAK:
    6057             :                 case ZEND_AST_CONTINUE:
    6058        2132 :                         zend_compile_break_continue(ast TSRMLS_CC);
    6059        2132 :                         break;
    6060             :                 case ZEND_AST_GOTO:
    6061          35 :                         zend_compile_goto(ast TSRMLS_CC);
    6062          33 :                         break;
    6063             :                 case ZEND_AST_LABEL:
    6064          37 :                         zend_compile_label(ast TSRMLS_CC);
    6065          36 :                         break;
    6066             :                 case ZEND_AST_WHILE:
    6067        1928 :                         zend_compile_while(ast TSRMLS_CC);
    6068        1928 :                         break;
    6069             :                 case ZEND_AST_DO_WHILE:
    6070         290 :                         zend_compile_do_while(ast TSRMLS_CC);
    6071         290 :                         break;
    6072             :                 case ZEND_AST_FOR:
    6073        1923 :                         zend_compile_for(ast TSRMLS_CC);
    6074        1923 :                         break;
    6075             :                 case ZEND_AST_FOREACH:
    6076        9756 :                         zend_compile_foreach(ast TSRMLS_CC);
    6077        9749 :                         break;
    6078             :                 case ZEND_AST_IF:
    6079       68601 :                         zend_compile_if(ast TSRMLS_CC);
    6080       68601 :                         break;
    6081             :                 case ZEND_AST_SWITCH:
    6082         450 :                         zend_compile_switch(ast TSRMLS_CC);
    6083         449 :                         break;
    6084             :                 case ZEND_AST_TRY:
    6085        1998 :                         zend_compile_try(ast TSRMLS_CC);
    6086        1997 :                         break;
    6087             :                 case ZEND_AST_DECLARE:
    6088          18 :                         zend_compile_declare(ast TSRMLS_CC);
    6089          17 :                         break;
    6090             :                 case ZEND_AST_FUNC_DECL:
    6091             :                 case ZEND_AST_METHOD:
    6092       34933 :                         zend_compile_func_decl(NULL, ast TSRMLS_CC);
    6093       34884 :                         break;
    6094             :                 case ZEND_AST_PROP_DECL:
    6095        2309 :                         zend_compile_prop_decl(ast TSRMLS_CC);
    6096        2305 :                         break;
    6097             :                 case ZEND_AST_CLASS_CONST_DECL:
    6098         239 :                         zend_compile_class_const_decl(ast TSRMLS_CC);
    6099         233 :                         break;
    6100             :                 case ZEND_AST_USE_TRAIT:
    6101         198 :                         zend_compile_use_trait(ast TSRMLS_CC);
    6102         194 :                         break;
    6103             :                 case ZEND_AST_CLASS:
    6104        7273 :                         zend_compile_class_decl(ast TSRMLS_CC);
    6105        7208 :                         break;
    6106             :                 case ZEND_AST_USE:
    6107          82 :                         zend_compile_use(ast TSRMLS_CC);
    6108          74 :                         break;
    6109             :                 case ZEND_AST_CONST_DECL:
    6110         161 :                         zend_compile_const_decl(ast TSRMLS_CC);
    6111         157 :                         break;
    6112             :                 case ZEND_AST_NAMESPACE:
    6113         201 :                         zend_compile_namespace(ast TSRMLS_CC);
    6114         182 :                         break;
    6115             :                 case ZEND_AST_HALT_COMPILER:
    6116         274 :                         zend_compile_halt_compiler(ast TSRMLS_CC);
    6117         274 :                         break;
    6118             :                 default:
    6119             :                 {
    6120             :                         znode result;
    6121      253228 :                         zend_compile_expr(&result, ast TSRMLS_CC);
    6122      253199 :                         zend_do_free(&result TSRMLS_CC);
    6123             :                 }
    6124             :         }
    6125             : 
    6126      606262 :         if (Z_LVAL(CG(declarables).ticks) && !zend_is_unticked_stmt(ast)) {
    6127          29 :                 zend_emit_tick(TSRMLS_C);
    6128             :         }
    6129             : }
    6130             : /* }}} */
    6131             : 
    6132     1479827 : void zend_compile_expr(znode *result, zend_ast *ast TSRMLS_DC) /* {{{ */
    6133             : {
    6134             :         /* CG(zend_lineno) = ast->lineno; */
    6135     1479827 :         CG(zend_lineno) = zend_ast_get_lineno(ast);
    6136             : 
    6137     1479827 :         switch (ast->kind) {
    6138             :                 case ZEND_AST_ZVAL:
    6139     1127252 :                         ZVAL_COPY(&result->u.constant, zend_ast_get_zval(ast));
    6140      563626 :                         result->op_type = IS_CONST;
    6141      563626 :                         return;
    6142             :                 case ZEND_AST_ZNODE:
    6143       14788 :                         *result = *zend_ast_get_znode(ast);
    6144       14788 :                         return;
    6145             :                 case ZEND_AST_VAR:
    6146             :                 case ZEND_AST_DIM:
    6147             :                 case ZEND_AST_PROP:
    6148             :                 case ZEND_AST_STATIC_PROP:
    6149             :                 case ZEND_AST_CALL:
    6150             :                 case ZEND_AST_METHOD_CALL:
    6151             :                 case ZEND_AST_STATIC_CALL:
    6152      432380 :                         zend_compile_var(result, ast, BP_VAR_R TSRMLS_CC);
    6153      432362 :                         return;
    6154             :                 case ZEND_AST_ASSIGN:
    6155      130368 :                         zend_compile_assign(result, ast TSRMLS_CC);
    6156      130359 :                         return;
    6157             :                 case ZEND_AST_ASSIGN_REF:
    6158         414 :                         zend_compile_assign_ref(result, ast TSRMLS_CC);
    6159         412 :                         return;
    6160             :                 case ZEND_AST_NEW:
    6161       14140 :                         zend_compile_new(result, ast TSRMLS_CC);
    6162       14140 :                         return;
    6163             :                 case ZEND_AST_CLONE:
    6164         115 :                         zend_compile_clone(result, ast TSRMLS_CC);
    6165         115 :                         return;
    6166             :                 case ZEND_AST_ASSIGN_OP:
    6167        3755 :                         zend_compile_compound_assign(result, ast TSRMLS_CC);
    6168        3755 :                         return;
    6169             :                 case ZEND_AST_BINARY_OP:
    6170       76513 :                         zend_compile_binary_op(result, ast TSRMLS_CC);
    6171       76513 :                         return;
    6172             :                 case ZEND_AST_GREATER:
    6173             :                 case ZEND_AST_GREATER_EQUAL:
    6174        1137 :                         zend_compile_greater(result, ast TSRMLS_CC);
    6175        1137 :                         return;
    6176             :                 case ZEND_AST_UNARY_OP:
    6177       29327 :                         zend_compile_unary_op(result, ast TSRMLS_CC);
    6178       29327 :                         return;
    6179             :                 case ZEND_AST_UNARY_PLUS:
    6180             :                 case ZEND_AST_UNARY_MINUS:
    6181        3179 :                         zend_compile_unary_pm(result, ast TSRMLS_CC);
    6182        3179 :                         return;
    6183             :                 case ZEND_AST_AND:
    6184             :                 case ZEND_AST_OR:
    6185       11787 :                         zend_compile_short_circuiting(result, ast TSRMLS_CC);
    6186       11787 :                         return;
    6187             :                 case ZEND_AST_POST_INC:
    6188             :                 case ZEND_AST_POST_DEC:
    6189        5542 :                         zend_compile_post_incdec(result, ast TSRMLS_CC);
    6190        5542 :                         return;
    6191             :                 case ZEND_AST_PRE_INC:
    6192             :                 case ZEND_AST_PRE_DEC:
    6193         532 :                         zend_compile_pre_incdec(result, ast TSRMLS_CC);
    6194         532 :                         return;
    6195             :                 case ZEND_AST_CAST:
    6196        6549 :                         zend_compile_cast(result, ast TSRMLS_CC);
    6197        6549 :                         return;
    6198             :                 case ZEND_AST_CONDITIONAL:
    6199       27351 :                         zend_compile_conditional(result, ast TSRMLS_CC);
    6200       27351 :                         return;
    6201             :                 case ZEND_AST_COALESCE:
    6202          16 :                         zend_compile_coalesce(result, ast TSRMLS_CC);
    6203          16 :                         return;
    6204             :                 case ZEND_AST_PRINT:
    6205        3397 :                         zend_compile_print(result, ast TSRMLS_CC);
    6206        3397 :                         return;
    6207             :                 case ZEND_AST_EXIT:
    6208       14439 :                         zend_compile_exit(result, ast TSRMLS_CC);
    6209       14439 :                         return;
    6210             :                 case ZEND_AST_YIELD:
    6211         121 :                         zend_compile_yield(result, ast TSRMLS_CC);
    6212         120 :                         return;
    6213             :                 case ZEND_AST_INSTANCEOF:
    6214          65 :                         zend_compile_instanceof(result, ast TSRMLS_CC);
    6215          64 :                         return;
    6216             :                 case ZEND_AST_INCLUDE_OR_EVAL:
    6217       10828 :                         zend_compile_include_or_eval(result, ast TSRMLS_CC);
    6218       10828 :                         return;
    6219             :                 case ZEND_AST_ISSET:
    6220             :                 case ZEND_AST_EMPTY:
    6221       13269 :                         zend_compile_isset_or_empty(result, ast TSRMLS_CC);
    6222       13266 :                         return;
    6223             :                 case ZEND_AST_SILENCE:
    6224        5571 :                         zend_compile_silence(result, ast TSRMLS_CC);
    6225        5571 :                         return;
    6226             :                 case ZEND_AST_SHELL_EXEC:
    6227         113 :                         zend_compile_shell_exec(result, ast TSRMLS_CC);
    6228         113 :                         return;
    6229             :                 case ZEND_AST_ARRAY:
    6230       15704 :                         zend_compile_array(result, ast TSRMLS_CC);
    6231       15704 :                         return;
    6232             :                 case ZEND_AST_CONST:
    6233       64631 :                         zend_compile_const(result, ast TSRMLS_CC);
    6234       64631 :                         return;
    6235             :                 case ZEND_AST_CLASS_CONST:
    6236        8700 :                         zend_compile_class_const(result, ast TSRMLS_CC);
    6237        8700 :                         return;
    6238             :                 case ZEND_AST_RESOLVE_CLASS_NAME:
    6239          21 :                         zend_compile_resolve_class_name(result, ast TSRMLS_CC);
    6240          18 :                         return;
    6241             :                 case ZEND_AST_ENCAPS_LIST:
    6242       12515 :                         zend_compile_encaps_list(result, ast TSRMLS_CC);
    6243       12515 :                         return;
    6244             :                 case ZEND_AST_MAGIC_CONST:
    6245        8559 :                         zend_compile_magic_const(result, ast TSRMLS_CC);
    6246        8559 :                         return;
    6247             :                 case ZEND_AST_CLOSURE:
    6248         375 :                         zend_compile_func_decl(result, ast TSRMLS_CC);
    6249         374 :                         return;
    6250             :                 default:
    6251             :                         ZEND_ASSERT(0 /* not supported */);
    6252             :         }
    6253             : }
    6254             : /* }}} */
    6255             : 
    6256     1015320 : void zend_compile_var(znode *result, zend_ast *ast, uint32_t type TSRMLS_DC) /* {{{ */
    6257             : {
    6258     1015320 :         switch (ast->kind) {
    6259             :                 case ZEND_AST_VAR:
    6260      601357 :                         zend_compile_simple_var(result, ast, type TSRMLS_CC);
    6261      601357 :                         return;
    6262             :                 case ZEND_AST_DIM:
    6263      103274 :                         zend_compile_dim(result, ast, type TSRMLS_CC);
    6264      103268 :                         return;
    6265             :                 case ZEND_AST_PROP:
    6266        5936 :                         zend_compile_prop(result, ast, type TSRMLS_CC);
    6267        5936 :                         return;
    6268             :                 case ZEND_AST_STATIC_PROP:
    6269         517 :                         zend_compile_static_prop(result, ast, type TSRMLS_CC);
    6270         517 :                         return;
    6271             :                 case ZEND_AST_CALL:
    6272      257503 :                         zend_compile_call(result, ast, type TSRMLS_CC);
    6273      257489 :                         return;
    6274             :                 case ZEND_AST_METHOD_CALL:
    6275       34478 :                         zend_compile_method_call(result, ast, type TSRMLS_CC);
    6276       34476 :                         return;
    6277             :                 case ZEND_AST_STATIC_CALL:
    6278       10215 :                         zend_compile_static_call(result, ast, type TSRMLS_CC);
    6279       10215 :                         return;
    6280             :                 case ZEND_AST_ZNODE:
    6281        1993 :                         *result = *zend_ast_get_znode(ast);
    6282        1993 :                         return;
    6283             :                 default:
    6284          47 :                         if (type == BP_VAR_W || type == BP_VAR_REF
    6285             :                                 || type == BP_VAR_RW || type == BP_VAR_UNSET
    6286             :                         ) {
    6287             :                                 /* For BC reasons =& new Foo is allowed */
    6288          11 :                                 if (type != BP_VAR_REF || ast->kind != ZEND_AST_NEW) {
    6289           1 :                                         zend_error_noreturn(E_COMPILE_ERROR,
    6290             :                                                 "Cannot use temporary expression in write context");
    6291             :                                 }
    6292             :                         }
    6293             : 
    6294          46 :                         zend_compile_expr(result, ast TSRMLS_CC);
    6295          46 :                         return;
    6296             :         }
    6297             : }
    6298             : /* }}} */
    6299             : 
    6300      129362 : void zend_delayed_compile_var(znode *result, zend_ast *ast, uint32_t type TSRMLS_DC) /* {{{ */
    6301             : {
    6302             :         zend_op *opline;
    6303      129362 :         switch (ast->kind) {
    6304             :                 case ZEND_AST_DIM:
    6305        3784 :                         opline = zend_delayed_compile_dim(result, ast, type TSRMLS_CC);
    6306        3783 :                         zend_adjust_for_fetch_type(opline, type);
    6307        3783 :                         return;
    6308             :                 case ZEND_AST_PROP:
    6309        1195 :                         opline = zend_delayed_compile_prop(result, ast, type TSRMLS_CC);
    6310        1195 :                         zend_adjust_for_fetch_type(opline, type);
    6311        1195 :                         return;
    6312             :                 default:
    6313      124383 :                         zend_compile_var(result, ast, type TSRMLS_CC);
    6314      124382 :                         return;
    6315             :         }
    6316             : }
    6317             : /* }}} */
    6318             : 
    6319      193874 : void zend_eval_const_expr(zend_ast **ast_ptr TSRMLS_DC) /* {{{ */
    6320             : {
    6321      193874 :         zend_ast *ast = *ast_ptr;
    6322             :         zval result;
    6323             : 
    6324      193874 :         if (!ast) {
    6325       63081 :                 return;
    6326             :         }
    6327             : 
    6328      130793 :         switch (ast->kind) {
    6329             :                 case ZEND_AST_BINARY_OP:
    6330        1194 :                         zend_eval_const_expr(&ast->child[0] TSRMLS_CC);
    6331        1194 :                         zend_eval_const_expr(&ast->child[1] TSRMLS_CC);
    6332        1194 :                         if (ast->child[0]->kind != ZEND_AST_ZVAL || ast->child[1]->kind != ZEND_AST_ZVAL) {
    6333         967 :                                 return;
    6334             :                         }
    6335             : 
    6336         681 :                         zend_ct_eval_binary_op(&result, ast->attr,
    6337             :                                 zend_ast_get_zval(ast->child[0]), zend_ast_get_zval(ast->child[1]) TSRMLS_CC);
    6338         227 :                         break;
    6339             :                 case ZEND_AST_GREATER:
    6340             :                 case ZEND_AST_GREATER_EQUAL:
    6341           4 :                         zend_eval_const_expr(&ast->child[0] TSRMLS_CC);
    6342           4 :                         zend_eval_const_expr(&ast->child[1] TSRMLS_CC);
    6343           4 :                         if (ast->child[0]->kind != ZEND_AST_ZVAL || ast->child[1]->kind != ZEND_AST_ZVAL) {
    6344           2 :                                 return;
    6345             :                         }
    6346             : 
    6347           6 :                         zend_ct_eval_greater(&result, ast->kind,
    6348             :                                 zend_ast_get_zval(ast->child[0]), zend_ast_get_zval(ast->child[1]) TSRMLS_CC);
    6349           2 :                         break;
    6350             :                 case ZEND_AST_UNARY_PLUS:
    6351             :                 case ZEND_AST_UNARY_MINUS:
    6352        3417 :                         zend_eval_const_expr(&ast->child[0] TSRMLS_CC);
    6353        3417 :                         if (ast->child[0]->kind != ZEND_AST_ZVAL) {
    6354           3 :                                 return;
    6355             :                         }
    6356             : 
    6357        6828 :                         zend_ct_eval_unary_pm(&result, ast->kind,
    6358             :                                 zend_ast_get_zval(ast->child[0]) TSRMLS_CC);
    6359        3414 :                         break;
    6360             :                 case ZEND_AST_ARRAY:
    6361       10092 :                         if (!zend_try_ct_eval_array(&result, ast TSRMLS_CC)) {
    6362         325 :                                 return;
    6363             :                         }
    6364        9767 :                         break;
    6365             :                 case ZEND_AST_MAGIC_CONST:
    6366         103 :                         if (!zend_try_ct_eval_magic_const(&result, ast TSRMLS_CC)) {
    6367           2 :                                 return;
    6368             :                         }
    6369         101 :                         break;
    6370             :                 case ZEND_AST_CONST:
    6371             :                 {
    6372       12965 :                         zend_ast *name_ast = ast->child[0];
    6373             :                         zend_bool is_fully_qualified;
    6374       25930 :                         zend_string *resolved_name = zend_resolve_const_name(
    6375       25930 :                                 zend_ast_get_str(name_ast), name_ast->attr, &is_fully_qualified TSRMLS_CC);
    6376             : 
    6377       12965 :                         if (!zend_try_ct_eval_const(&result, resolved_name, is_fully_qualified TSRMLS_CC)) {
    6378             :                                 zend_string_release(resolved_name);
    6379         388 :                                 return;
    6380             :                         }
    6381             : 
    6382             :                         zend_string_release(resolved_name);
    6383       12577 :                         break;
    6384             :                 }
    6385             :                 default:
    6386      103018 :                         return;
    6387             :         }
    6388             : 
    6389       26088 :         zend_ast_destroy(ast);
    6390       26088 :         *ast_ptr = zend_ast_create_zval(&result);
    6391             : }
    6392             : /* }}} */
    6393             : 
    6394             : /*
    6395             :  * Local variables:
    6396             :  * tab-width: 4
    6397             :  * c-basic-offset: 4
    6398             :  * indent-tabs-mode: t
    6399             :  * End:
    6400             :  */

Generated by: LCOV version 1.10

Generated at Sat, 22 Nov 2014 23:01:12 +0000 (4 days ago)

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