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

Generated by: LCOV version 1.10

Generated at Tue, 14 Oct 2014 07:25:37 +0000 (5 days ago)

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