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

Generated by: LCOV version 1.10

Generated at Sat, 13 Dec 2014 06:16:09 +0000 (6 days ago)

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