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: 3148 3264 96.4 %
Date: 2014-10-30 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      301338 : static inline void zend_alloc_cache_slot(uint32_t literal TSRMLS_DC) {
      60      301338 :         zend_op_array *op_array = CG(active_op_array);
      61      301338 :         Z_CACHE_SLOT(op_array->literals[literal]) = op_array->last_cache_slot++;
      62      301338 : }
      63             : 
      64             : #define POLYMORPHIC_CACHE_SLOT_SIZE 2
      65             : 
      66       48861 : static inline void zend_alloc_polymorphic_cache_slot(uint32_t literal TSRMLS_DC) {
      67       48861 :         zend_op_array *op_array = CG(active_op_array);
      68       48861 :         Z_CACHE_SLOT(op_array->literals[literal]) = op_array->last_cache_slot;
      69       48861 :         op_array->last_cache_slot += POLYMORPHIC_CACHE_SLOT_SIZE;
      70       48861 : }
      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       20557 : static void zend_destroy_property_info(zval *zv) /* {{{ */
      81             : {
      82       20557 :         zend_property_info *property_info = Z_PTR_P(zv);
      83             : 
      84       20557 :         zend_string_release(property_info->name);
      85       20557 :         if (property_info->doc_comment) {
      86          59 :                 zend_string_release(property_info->doc_comment);
      87             :         }
      88       20557 : }
      89             : /* }}} */
      90             : 
      91     4725431 : static void zend_destroy_property_info_internal(zval *zv) /* {{{ */
      92             : {
      93     4725431 :         zend_property_info *property_info = Z_PTR_P(zv);
      94             : 
      95     4725431 :         zend_string_release(property_info->name);
      96     4725431 :         free(property_info);
      97     4725431 : }
      98             : /* }}} */
      99             : 
     100        2583 : 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        2583 :         interned_str = zend_new_interned_string(str TSRMLS_CC);
     105        2583 :         if (str != interned_str) {
     106         671 :                 return interned_str;
     107             :         } else {
     108             :                 zend_string_release(str);
     109        1912 :                 return str;
     110             :         }
     111             : }
     112             : /* }}} */
     113             : 
     114       25338 : 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       25338 :         size_t filename_len, char_pos_len = zend_sprintf(char_pos_buf, "%p", lex_pos);
     119             : 
     120             :         const char *filename;
     121       25338 :         if (CG(active_op_array)->filename) {
     122       25338 :                 filename = CG(active_op_array)->filename->val;
     123       25338 :                 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       50676 :         result = zend_string_alloc(1 + name->len + filename_len + char_pos_len, 0);
     130       25338 :         sprintf(result->val, "%c%s%s%s", '\0', name->val, filename, char_pos_buf);
     131       25338 :         return zend_new_interned_string(result TSRMLS_CC);
     132             : }
     133             : /* }}} */
     134             : 
     135       20977 : static zend_bool zend_get_unqualified_name(const zend_string *name, const char **result, size_t *result_len) /* {{{ */
     136             : {
     137       41954 :         const char *ns_separator = zend_memrchr(name->val, '\\', name->len);
     138       20977 :         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       20526 :         return 0;
     145             : }
     146             : /* }}} */
     147             : 
     148       20380 : static void init_compiler_declarables(TSRMLS_D) /* {{{ */
     149             : {
     150       20380 :         ZVAL_LONG(&CG(declarables).ticks, 0);
     151       20380 : }
     152             : /* }}} */
     153             : 
     154       64680 : void zend_init_compiler_context(TSRMLS_D) /* {{{ */
     155             : {
     156       64680 :         CG(context).opcodes_size = INITIAL_OP_ARRAY_SIZE;
     157       64680 :         CG(context).vars_size = 0;
     158       64680 :         CG(context).literals_size = 0;
     159       64680 :         CG(context).current_brk_cont = -1;
     160       64680 :         CG(context).backpatch_count = 0;
     161       64680 :         CG(context).in_finally = 0;
     162       64680 :         CG(context).labels = NULL;
     163       64680 : }
     164             : /* }}} */
     165             : 
     166       20380 : void zend_init_compiler_data_structures(TSRMLS_D) /* {{{ */
     167             : {
     168       20380 :         zend_stack_init(&CG(loop_var_stack), sizeof(znode));
     169       20380 :         zend_stack_init(&CG(delayed_oplines_stack), sizeof(zend_op));
     170       20380 :         CG(active_class_entry) = NULL;
     171       20380 :         CG(in_compilation) = 0;
     172       20380 :         CG(start_lineno) = 0;
     173       20380 :         CG(current_namespace) = NULL;
     174       20380 :         CG(in_namespace) = 0;
     175       20380 :         CG(has_bracketed_namespaces) = 0;
     176       20380 :         CG(current_import) = NULL;
     177       20380 :         CG(current_import_function) = NULL;
     178       20380 :         CG(current_import_const) = NULL;
     179       20380 :         zend_hash_init(&CG(const_filenames), 8, NULL, NULL, 0);
     180       20380 :         init_compiler_declarables(TSRMLS_C);
     181       20380 :         zend_stack_init(&CG(context_stack), sizeof(CG(context)));
     182             : 
     183       20380 :         CG(encoding_declared) = 0;
     184       20380 : }
     185             : /* }}} */
     186             : 
     187       28439 : ZEND_API void file_handle_dtor(zend_file_handle *fh) /* {{{ */
     188             : {
     189             :         TSRMLS_FETCH();
     190             : 
     191       28439 :         zend_file_handle_dtor(fh TSRMLS_CC);
     192       28439 : }
     193             : /* }}} */
     194             : 
     195       20380 : void init_compiler(TSRMLS_D) /* {{{ */
     196             : {
     197       20380 :         CG(arena) = zend_arena_create(64 * 1024);
     198       20380 :         CG(active_op_array) = NULL;
     199       20380 :         memset(&CG(context), 0, sizeof(CG(context)));
     200       20380 :         zend_init_compiler_data_structures(TSRMLS_C);
     201       20380 :         zend_init_rsrc_list(TSRMLS_C);
     202       20380 :         zend_hash_init(&CG(filenames_table), 8, NULL, free_string_zval, 0);
     203       20380 :         zend_llist_init(&CG(open_files), sizeof(zend_file_handle), (void (*)(void *)) file_handle_dtor, 0);
     204       20380 :         CG(unclean_shutdown) = 0;
     205       20380 : }
     206             : /* }}} */
     207             : 
     208       20416 : void shutdown_compiler(TSRMLS_D) /* {{{ */
     209             : {
     210       20416 :         zend_stack_destroy(&CG(loop_var_stack));
     211       20416 :         zend_stack_destroy(&CG(delayed_oplines_stack));
     212       20416 :         zend_hash_destroy(&CG(filenames_table));
     213       20416 :         zend_hash_destroy(&CG(const_filenames));
     214       20416 :         zend_stack_destroy(&CG(context_stack));
     215       20416 :         zend_arena_destroy(CG(arena));
     216       20416 : }
     217             : /* }}} */
     218             : 
     219       29625 : ZEND_API zend_string *zend_set_compiled_filename(zend_string *new_compiled_filename TSRMLS_DC) /* {{{ */
     220             : {
     221             :         zend_string *p;
     222             : 
     223       29625 :         p = zend_hash_find_ptr(&CG(filenames_table), new_compiled_filename);
     224       29625 :         if (p != NULL) {
     225         877 :                 CG(compiled_filename) = p;
     226         877 :                 return p;
     227             :         }
     228       28748 :         p = zend_string_copy(new_compiled_filename);
     229             :         zend_hash_update_ptr(&CG(filenames_table), new_compiled_filename, p);
     230       28748 :         CG(compiled_filename) = p;
     231       28748 :         return p;
     232             : }
     233             : /* }}} */
     234             : 
     235       29425 : ZEND_API void zend_restore_compiled_filename(zend_string *original_compiled_filename TSRMLS_DC) /* {{{ */
     236             : {
     237       29425 :         CG(compiled_filename) = original_compiled_filename;
     238       29425 : }
     239             : /* }}} */
     240             : 
     241      102453 : ZEND_API zend_string *zend_get_compiled_filename(TSRMLS_D) /* {{{ */
     242             : {
     243      102453 :         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      395576 : ZEND_API zend_bool zend_is_compiling(TSRMLS_D) /* {{{ */
     254             : {
     255      395576 :         return CG(in_compilation);
     256             : }
     257             : /* }}} */
     258             : 
     259      884180 : static uint32_t get_temporary_variable(zend_op_array *op_array) /* {{{ */
     260             : {
     261      884180 :         return (uint32_t)op_array->T++;
     262             : }
     263             : /* }}} */
     264             : 
     265      674835 : static int lookup_cv(zend_op_array *op_array, zend_string* name TSRMLS_DC) /* {{{ */{
     266      674835 :         int i = 0;
     267      674835 :         zend_ulong hash_value = zend_string_hash_val(name);
     268             : 
     269   138147691 :         while (i < op_array->last_var) {
     270   275478446 :                 if (op_array->vars[i]->val == name->val ||
     271   137268622 :                     (op_array->vars[i]->h == hash_value &&
     272      470601 :                      op_array->vars[i]->len == name->len &&
     273      470601 :                      memcmp(op_array->vars[i]->val, name->val, name->len) == 0)) {
     274             :                         zend_string_release(name);
     275      470601 :                         return (int)(zend_intptr_t)EX_VAR_NUM_2(NULL, i);
     276             :                 }
     277   136798021 :                 i++;
     278             :         }
     279      204234 :         i = op_array->last_var;
     280      204234 :         op_array->last_var++;
     281      204234 :         if (op_array->last_var > CG(context).vars_size) {
     282       48486 :                 CG(context).vars_size += 16; /* FIXME */
     283       48486 :                 op_array->vars = erealloc(op_array->vars, CG(context).vars_size * sizeof(zend_string*));
     284             :         }
     285             : 
     286      204234 :         op_array->vars[i] = zend_new_interned_string(name TSRMLS_CC);
     287      204234 :         return (int)(zend_intptr_t)EX_VAR_NUM_2(NULL, i);
     288             : }
     289             : /* }}} */
     290             : 
     291       38531 : void zend_del_literal(zend_op_array *op_array, int n) /* {{{ */
     292             : {
     293       38531 :         zval_dtor(&CONSTANT_EX(op_array, n));
     294       38531 :         if (n + 1 == op_array->last_literal) {
     295       37534 :                 op_array->last_literal--;
     296             :         } else {
     297         997 :                 ZVAL_UNDEF(&CONSTANT_EX(op_array, n));
     298             :         }
     299       38531 : }
     300             : /* }}} */
     301             : 
     302             : /* Common part of zend_add_literal and zend_append_individual_literal */
     303     1134604 : static inline void zend_insert_literal(zend_op_array *op_array, zval *zv, int literal_position TSRMLS_DC) /* {{{ */
     304             : {
     305     1430602 :         if (Z_TYPE_P(zv) == IS_STRING || Z_TYPE_P(zv) == IS_CONSTANT) {
     306      838883 :                 zend_string_hash_val(Z_STR_P(zv));
     307      838883 :                 Z_STR_P(zv) = zend_new_interned_string(Z_STR_P(zv) TSRMLS_CC);
     308      838883 :                 if (IS_INTERNED(Z_STR_P(zv))) {
     309      834760 :                         Z_TYPE_FLAGS_P(zv) &= ~ (IS_TYPE_REFCOUNTED | IS_TYPE_COPYABLE);
     310             :                 }
     311             :         }
     312     1134604 :         ZVAL_COPY_VALUE(&CONSTANT_EX(op_array, literal_position), zv);
     313     1134604 :         Z_CACHE_SLOT(op_array->literals[literal_position]) = -1;
     314     1134604 : }
     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     1134604 : int zend_add_literal(zend_op_array *op_array, zval *zv TSRMLS_DC) /* {{{ */
     321             : {
     322     1134604 :         int i = op_array->last_literal;
     323     1134604 :         op_array->last_literal++;
     324     1134604 :         if (i >= CG(context).literals_size) {
     325      320199 :                 while (i >= CG(context).literals_size) {
     326      106733 :                         CG(context).literals_size += 16; /* FIXME */
     327             :                 }
     328      106733 :                 op_array->literals = (zval*)erealloc(op_array->literals, CG(context).literals_size * sizeof(zval));
     329             :         }
     330     1134604 :         zend_insert_literal(op_array, zv, i TSRMLS_CC);
     331     1134604 :         return i;
     332             : }
     333             : /* }}} */
     334             : 
     335      176092 : 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      176092 :         ZVAL_STR(&zv, *str);
     340      176092 :         ret = zend_add_literal(op_array, &zv TSRMLS_CC);
     341      176092 :         *str = Z_STR(zv);
     342      176092 :         return ret;
     343             : }
     344             : 
     345       47359 : static int zend_add_func_name_literal(zend_op_array *op_array, zend_string *name TSRMLS_DC) /* {{{ */
     346             : {
     347             :         /* Original name */
     348       47359 :         int ret = zend_add_literal_string(op_array, &name TSRMLS_CC);
     349             : 
     350             :         /* Lowercased name */
     351       94718 :         zend_string *lc_name = zend_string_alloc(name->len, 0);
     352       47359 :         zend_str_tolower_copy(lc_name->val, name->val, name->len);
     353       47359 :         zend_add_literal_string(op_array, &lc_name TSRMLS_CC);
     354             : 
     355       47359 :         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       31972 : static int zend_add_class_name_literal(zend_op_array *op_array, zend_string *name TSRMLS_DC) /* {{{ */
     384             : {
     385             :         /* Original name */
     386       31972 :         int ret = zend_add_literal_string(op_array, &name TSRMLS_CC);
     387             : 
     388             :         /* Lowercased name */
     389       63944 :         zend_string *lc_name = zend_string_alloc(name->len, 0);
     390       31972 :         zend_str_tolower_copy(lc_name->val, name->val, name->len);
     391       31972 :         zend_add_literal_string(op_array, &lc_name TSRMLS_CC);
     392             : 
     393       31972 :         zend_alloc_cache_slot(ret TSRMLS_CC);
     394             : 
     395       31972 :         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       14208 : static inline void zend_begin_loop(TSRMLS_D) /* {{{ */
     461             : {
     462             :         zend_brk_cont_element *brk_cont_element;
     463             :         int parent;
     464             : 
     465       14208 :         parent = CG(context).current_brk_cont;
     466       14208 :         CG(context).current_brk_cont = CG(active_op_array)->last_brk_cont;
     467       14208 :         brk_cont_element = get_next_brk_cont_element(CG(active_op_array));
     468       14208 :         brk_cont_element->start = get_next_op_number(CG(active_op_array));
     469       14208 :         brk_cont_element->parent = parent;
     470       14208 : }
     471             : /* }}} */
     472             : 
     473       14207 : static inline void zend_end_loop(int cont_addr, int has_loop_var TSRMLS_DC) /* {{{ */
     474             : {
     475       14207 :         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        4028 :                 CG(active_op_array)->brk_cont_array[CG(context).current_brk_cont].start = -1;
     480             :         }
     481       14207 :         CG(active_op_array)->brk_cont_array[CG(context).current_brk_cont].cont = cont_addr;
     482       14207 :         CG(active_op_array)->brk_cont_array[CG(context).current_brk_cont].brk = get_next_op_number(CG(active_op_array));
     483       14207 :         CG(context).current_brk_cont = CG(active_op_array)->brk_cont_array[CG(context).current_brk_cont].parent;
     484       14207 : }
     485             : /* }}} */
     486             : 
     487      289732 : void zend_do_free(znode *op1 TSRMLS_DC) /* {{{ */
     488             : {
     489      289732 :         if (op1->op_type==IS_TMP_VAR) {
     490       10368 :                 zend_op *opline = get_next_op(CG(active_op_array) TSRMLS_CC);
     491             : 
     492       10368 :                 opline->opcode = ZEND_FREE;
     493       10368 :                 SET_NODE(opline->op1, op1);
     494       10368 :                 SET_UNUSED(opline->op2);
     495      279364 :         } else if (op1->op_type==IS_VAR) {
     496      259951 :                 zend_op *opline = &CG(active_op_array)->opcodes[CG(active_op_array)->last-1];
     497             : 
     498      529821 :                 while (opline->opcode == ZEND_END_SILENCE || opline->opcode == ZEND_EXT_FCALL_END || opline->opcode == ZEND_OP_DATA) {
     499        9919 :                         opline--;
     500             :                 }
     501      779309 :                 if (opline->result_type == IS_VAR
     502      519630 :                         && opline->result.var == op1->u.op.var) {
     503      779052 :                         if (opline->opcode == ZEND_FETCH_R ||
     504      259675 :                             opline->opcode == ZEND_FETCH_DIM_R ||
     505      259660 :                             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      259641 :                                 opline->result_type |= EXT_TYPE_UNUSED;
     515             :                         }
     516             :                 } else {
     517        1089 :                         while (opline >= CG(active_op_array)->opcodes) {
     518        1003 :                                 if (opline->opcode == ZEND_FETCH_LIST &&
     519          93 :                                     opline->op1_type == IS_VAR &&
     520          93 :                                     opline->op1.var == op1->u.op.var) {
     521          86 :                                         opline = get_next_op(CG(active_op_array) TSRMLS_CC);
     522             : 
     523          86 :                                         opline->opcode = ZEND_FREE;
     524          86 :                                         SET_NODE(opline->op1, op1);
     525          86 :                                         SET_UNUSED(opline->op2);
     526          86 :                                         return;
     527             :                                 }
     528         966 :                                 if (opline->result_type==IS_VAR
     529         966 :                                         && opline->result.var == op1->u.op.var) {
     530         186 :                                         if (opline->opcode == ZEND_NEW) {
     531         186 :                                                 opline->result_type |= EXT_TYPE_UNUSED;
     532         186 :                                                 opline = &CG(active_op_array)->opcodes[CG(active_op_array)->last-1];
     533         372 :                                                 while (opline->opcode != ZEND_DO_FCALL || opline->op1.num != ZEND_CALL_CTOR) {
     534           0 :                                                         opline--;
     535             :                                                 }
     536         186 :                                                 opline->op1.num |= ZEND_CALL_CTOR_RESULT_UNUSED;
     537             :                                         }
     538         186 :                                         break;
     539             :                                 }
     540         545 :                                 opline--;
     541             :                         }
     542             :                 }
     543       19413 :         } 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       19136 :                 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      381889 : zend_string *zend_prefix_with_ns(zend_string *name TSRMLS_DC) {
     592      381889 :         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      381019 :                 return zend_string_copy(name);
     597             :         }
     598             : }
     599             : 
     600       21137 : 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       21137 :         STR_ALLOCA_ALLOC(lcname, len, use_heap);
     606       21137 :         zend_str_tolower_copy(lcname->val, str, len);
     607       21137 :         result = zend_hash_find_ptr(ht, lcname);
     608       21137 :         STR_ALLOCA_FREE(lcname, use_heap);
     609             : 
     610       21137 :         return result;
     611             : }
     612             : 
     613      331449 : 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      331449 :         *is_fully_qualified = 0;
     619             : 
     620      331449 :         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      331448 :         if (type == ZEND_NAME_FQ) {
     626         170 :                 *is_fully_qualified = 1;
     627         170 :                 return zend_string_copy(name);
     628             :         }
     629             : 
     630      331278 :         if (type == ZEND_NAME_RELATIVE) {
     631          45 :                 *is_fully_qualified = 1;
     632          45 :                 return zend_prefix_with_ns(name TSRMLS_CC);
     633             :         }
     634             : 
     635      331233 :         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      331214 :         compound = memchr(name->val, '\\', name->len);
     651      331214 :         if (compound) {
     652          70 :                 *is_fully_qualified = 1;
     653             :         }
     654             : 
     655      331214 :         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      331201 :         return zend_prefix_with_ns(name TSRMLS_CC);
     667             : }
     668             : /* }}} */
     669             : 
     670      253987 : zend_string *zend_resolve_function_name(zend_string *name, uint32_t type, zend_bool *is_fully_qualified TSRMLS_DC) /* {{{ */
     671             : {
     672      253987 :         return zend_resolve_non_class_name(
     673             :                 name, type, is_fully_qualified, 0, CG(current_import_function) TSRMLS_CC);
     674             : }
     675             : /* }}} */
     676             : 
     677       77462 : zend_string *zend_resolve_const_name(zend_string *name, uint32_t type, zend_bool *is_fully_qualified TSRMLS_DC) /* {{{ */ {
     678       77462 :         return zend_resolve_non_class_name(
     679             :                 name, type, is_fully_qualified, 1, CG(current_import_const) TSRMLS_CC);
     680             : }
     681             : /* }}} */
     682             : 
     683       32495 : zend_string *zend_resolve_class_name(zend_string *name, uint32_t type TSRMLS_DC) /* {{{ */
     684             : {
     685             :         char *compound;
     686             : 
     687       32495 :         if (type == ZEND_NAME_RELATIVE) {
     688          18 :                 return zend_prefix_with_ns(name TSRMLS_CC);
     689             :         }
     690             : 
     691       32477 :         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       32327 :         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       32265 :         return zend_prefix_with_ns(name TSRMLS_CC);
     729             : }
     730             : /* }}} */
     731             : 
     732       30173 : zend_string *zend_resolve_class_name_ast(zend_ast *ast TSRMLS_DC) /* {{{ */
     733             : {
     734       30173 :         zend_string *name = zend_ast_get_str(ast);
     735       30173 :         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       64412 : void zend_release_labels(int temporary TSRMLS_DC) /* {{{ */
     806             : {
     807       64412 :         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       64412 :         if (!temporary && !zend_stack_is_empty(&CG(context_stack))) {
     813       64412 :                 zend_compiler_context *ctx = zend_stack_top(&CG(context_stack));
     814       64412 :                 CG(context) = *ctx;
     815       64412 :                 zend_stack_del_top(&CG(context_stack));
     816             :         }
     817       64412 : }
     818             : /* }}} */
     819             : 
     820             : static zend_bool zend_is_call(zend_ast *ast);
     821             : 
     822       53305 : static int generate_free_loop_var(znode *var TSRMLS_DC) /* {{{ */
     823             : {
     824       53305 :         switch (var->op_type) {
     825             :                 case IS_UNUSED:
     826             :                         /* Stack separator on function boundary, stop applying */
     827       42964 :                         return 1;
     828             :                 case IS_VAR:
     829             :                 case IS_TMP_VAR:
     830             :                 {
     831       10244 :                         zend_op *opline = get_next_op(CG(active_op_array) TSRMLS_CC);
     832             : 
     833       10244 :                         opline->opcode = ZEND_FREE;
     834       10244 :                         SET_NODE(opline->op1, var);
     835       10244 :                         SET_UNUSED(opline->op2);
     836             :                 }
     837             :         }
     838             : 
     839       10341 :         return 0;
     840             : }
     841             : /* }}} */
     842             : 
     843        1990 : static uint32_t zend_add_try_element(uint32_t try_op TSRMLS_DC) /* {{{ */
     844             : {
     845        1990 :         zend_op_array *op_array = CG(active_op_array);
     846        1990 :         uint32_t try_catch_offset = op_array->last_try_catch++;
     847             :         zend_try_catch_element *elem;
     848             : 
     849        1990 :         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        1990 :         elem = &op_array->try_catch_array[try_catch_offset];
     853        1990 :         elem->try_op = try_op;
     854        1990 :         elem->catch_op = 0;
     855        1990 :         elem->finally_op = 0;
     856        1990 :         elem->finally_end = 0;
     857             : 
     858        1990 :         return try_catch_offset;
     859             : }
     860             : /* }}} */
     861             : 
     862    25659662 : ZEND_API void function_add_ref(zend_function *function) /* {{{ */
     863             : {
     864    25659662 :         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    25658061 :         } else if (function->type == ZEND_INTERNAL_FUNCTION) {
     876    25658061 :                 if (function->common.function_name) {
     877    25658061 :                         zend_string_addref(function->common.function_name);
     878             :                 }
     879             :         }
     880    25659662 : }
     881             : /* }}} */
     882             : 
     883       16367 : 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       16367 :         if (compile_time) {
     889       13313 :                 op1 = &CONSTANT_EX(op_array, opline->op1.constant);
     890       13313 :                 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       32734 :         function = zend_hash_find_ptr(function_table, Z_STR_P(op1));
     897       16367 :         new_function = zend_arena_alloc(&CG(arena), sizeof(zend_op_array));
     898       16367 :         memcpy(new_function, function, sizeof(zend_op_array));
     899       32734 :         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       16367 :                 (*function->op_array.refcount)++;
     917       16367 :                 function->op_array.static_variables = NULL; /* NULL out the unbound function */
     918       16367 :                 return SUCCESS;
     919             :         }
     920             : }
     921             : /* }}} */
     922             : 
     923        4878 : 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        4878 :         if (compile_time) {
     929        4462 :                 op1 = &CONSTANT_EX(op_array, opline->op1.constant);
     930        4462 :                 op2 = &CONSTANT_EX(op_array, opline->op2.constant);
     931             :         } else {
     932         416 :                 op1 = opline->op1.zv;
     933         416 :                 op2 = opline->op2.zv;
     934             :         }
     935        9756 :         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        4878 :         ce->refcount++;
     940        9756 :         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        4874 :                 if (!(ce->ce_flags & (ZEND_ACC_INTERFACE|ZEND_ACC_IMPLEMENT_INTERFACES|ZEND_ACC_IMPLEMENT_TRAITS))) {
     953        4324 :                         zend_verify_abstract_class(ce TSRMLS_CC);
     954             :                 }
     955        4871 :                 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       19583 : void zend_do_early_binding(TSRMLS_D) /* {{{ */
    1006             : {
    1007       19583 :         zend_op *opline = &CG(active_op_array)->opcodes[CG(active_op_array)->last-1];
    1008             :         HashTable *table;
    1009             : 
    1010       39166 :         while (opline->opcode == ZEND_TICKS && opline > CG(active_op_array)->opcodes) {
    1011           0 :                 opline--;
    1012             :         }
    1013             : 
    1014       19583 :         switch (opline->opcode) {
    1015             :                 case ZEND_DECLARE_FUNCTION:
    1016       13313 :                         if (do_bind_function(CG(active_op_array), opline, CG(function_table), 1 TSRMLS_CC) == FAILURE) {
    1017           0 :                                 return;
    1018             :                         }
    1019       13313 :                         table = CG(function_table);
    1020       13313 :                         break;
    1021             :                 case ZEND_DECLARE_CLASS:
    1022        4462 :                         if (do_bind_class(CG(active_op_array), opline, CG(class_table), 1 TSRMLS_CC) == NULL) {
    1023           2 :                                 return;
    1024             :                         }
    1025        4457 :                         table = CG(class_table);
    1026        4457 :                         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       18767 :         zend_hash_del(table, Z_STR(CONSTANT(opline->op1.constant)));
    1073       18767 :         zend_del_literal(CG(active_op_array), opline->op1.constant);
    1074       18767 :         zend_del_literal(CG(active_op_array), opline->op2.constant);
    1075       18767 :         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      206500 : 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      206500 :         size_t prop_name_length = 1 + src1_length + 1 + src2_length;
    1101      206500 :         zend_string *prop_name = zend_string_alloc(prop_name_length, internal);
    1102             : 
    1103      206500 :         prop_name->val[0] = '\0';
    1104      206500 :         memcpy(prop_name->val + 1, src1, src1_length+1);
    1105      206500 :         memcpy(prop_name->val + 1 + src1_length + 1, src2, src2_length+1);
    1106      206500 :         return prop_name;
    1107             : }
    1108             : /* }}} */
    1109             : 
    1110        2036 : static size_t zend_strnlen(const char* s, size_t maxlen) /* {{{ */
    1111             : {
    1112        2036 :         size_t len = 0;
    1113        2036 :         while (*s++ && maxlen--) len++;
    1114        2036 :         return len;
    1115             : }
    1116             : /* }}} */
    1117             : 
    1118        9027 : 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        9027 :         *class_name = NULL;
    1123             : 
    1124        9027 :         if (name->val[0] != '\0') {
    1125        6991 :                 *prop_name = name->val;
    1126        6991 :                 if (prop_len) {
    1127         950 :                         *prop_len = name->len;
    1128             :                 }
    1129        6991 :                 return SUCCESS;
    1130             :         }
    1131        2036 :         if (name->len < 3 || name->val[1] == '\0') {
    1132           0 :                 zend_error(E_NOTICE, "Illegal member variable name");
    1133           0 :                 *prop_name = name->val;
    1134           0 :                 if (prop_len) {
    1135           0 :                         *prop_len = name->len;
    1136             :                 }
    1137           0 :                 return FAILURE;
    1138             :         }
    1139             : 
    1140        2036 :         class_name_len = zend_strnlen(name->val + 1, name->len - 2);
    1141        2036 :         if (class_name_len >= name->len - 2 || name->val[class_name_len + 1] != '\0') {
    1142           0 :                 zend_error(E_NOTICE, "Corrupt member variable name");
    1143           0 :                 *prop_name = name->val;
    1144           0 :                 if (prop_len) {
    1145           0 :                         *prop_len = name->len;
    1146             :                 }
    1147           0 :                 return FAILURE;
    1148             :         }
    1149             : 
    1150        2036 :         *class_name = name->val + 1;
    1151        2036 :         *prop_name = name->val + class_name_len + 2;
    1152        2036 :         if (prop_len) {
    1153         924 :                 *prop_len = name->len - class_name_len - 2;
    1154             :         }
    1155        2036 :         return SUCCESS;
    1156             : }
    1157             : /* }}} */
    1158             : 
    1159       20939 : static zend_constant *zend_lookup_reserved_const(const char *name, size_t len TSRMLS_DC) /* {{{ */
    1160             : {
    1161       20939 :         zend_constant *c = zend_hash_find_ptr_lc(EG(zend_constants), name, len);
    1162       20939 :         if (c && !(c->flags & CONST_CS) && (c->flags & CONST_CT_SUBST)) {
    1163       14750 :                 return c;
    1164             :         }
    1165        6189 :         return NULL;
    1166             : }
    1167             : /* }}} */
    1168             : 
    1169       77462 : 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       77462 :         if (!(CG(compiler_options) & ZEND_COMPILE_NO_CONSTANT_SUBSTITUTION)) {
    1174             :                 /* Substitute case-sensitive (or lowercase) persistent constants */
    1175      154542 :                 c = zend_hash_find_ptr(EG(zend_constants), name);
    1176       77271 :                 if (c && (c->flags & CONST_PERSISTENT)) {
    1177       56683 :                         ZVAL_DUP(zv, &c->value);
    1178       56683 :                         return 1;
    1179             :                 }
    1180             :         }
    1181             : 
    1182             :         {
    1183             :                 /* Substitute true, false and null (including unqualified usage in namespaces) */
    1184       20779 :                 const char *lookup_name = name->val;
    1185       20779 :                 size_t lookup_len = name->len;
    1186             : 
    1187       20779 :                 if (!is_fully_qualified) {
    1188       20635 :                         zend_get_unqualified_name(name, &lookup_name, &lookup_len);
    1189             :                 }
    1190             : 
    1191       20779 :                 c = zend_lookup_reserved_const(lookup_name, lookup_len TSRMLS_CC);
    1192       20779 :                 if (c) {
    1193       14749 :                         ZVAL_DUP(zv, &c->value);
    1194       14749 :                         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       37023 : void zend_do_extended_info(TSRMLS_D) /* {{{ */
    1234             : {
    1235             :         zend_op *opline;
    1236             : 
    1237       37023 :         if (!(CG(compiler_options) & ZEND_COMPILE_EXTENDED_INFO)) {
    1238       37023 :                 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      316719 : void zend_do_extended_fcall_begin(TSRMLS_D) /* {{{ */
    1250             : {
    1251             :         zend_op *opline;
    1252             : 
    1253      316719 :         if (!(CG(compiler_options) & ZEND_COMPILE_EXTENDED_INFO)) {
    1254      316719 :                 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      316705 : void zend_do_extended_fcall_end(TSRMLS_D) /* {{{ */
    1266             : {
    1267             :         zend_op *opline;
    1268             : 
    1269      316705 :         if (!(CG(compiler_options) & ZEND_COMPILE_EXTENDED_INFO)) {
    1270      316705 :                 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      730776 : zend_bool zend_is_auto_global(zend_string *name TSRMLS_DC) /* {{{ */
    1282             : {
    1283             :         zend_auto_global *auto_global;
    1284             : 
    1285     1461552 :         if ((auto_global = zend_hash_find_ptr(CG(auto_globals), name)) != NULL) {
    1286       56659 :                 if (auto_global->armed) {
    1287       21746 :                         auto_global->armed = auto_global->auto_global_callback(auto_global->name TSRMLS_CC);
    1288             :                 }
    1289       56659 :                 return 1;
    1290             :         }
    1291      674117 :         return 0;
    1292             : }
    1293             : /* }}} */
    1294             : 
    1295      183807 : 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      183807 :         auto_global.name = zend_new_interned_string(name TSRMLS_CC);
    1301      183807 :         auto_global.auto_global_callback = auto_global_callback;
    1302      183807 :         auto_global.jit = jit;
    1303             : 
    1304      367614 :         retval = zend_hash_add_mem(CG(auto_globals), name, &auto_global, sizeof(zend_auto_global)) != NULL ? SUCCESS : FAILURE;
    1305             : 
    1306      183807 :         zend_string_release(auto_global.name);
    1307      183807 :         return retval;
    1308             : }
    1309             : /* }}} */
    1310             : 
    1311       20380 : ZEND_API void zend_activate_auto_globals(TSRMLS_D) /* {{{ */
    1312             : {
    1313             :         zend_auto_global *auto_global;
    1314             : 
    1315      387220 :         ZEND_HASH_FOREACH_PTR(CG(auto_globals), auto_global) {
    1316      183420 :                 if (auto_global->jit) {
    1317       81520 :                         auto_global->armed = 1;
    1318      101900 :                 } else if (auto_global->auto_global_callback) {
    1319       81520 :                         auto_global->armed = auto_global->auto_global_callback(auto_global->name TSRMLS_CC);
    1320             :                 } else {
    1321       20380 :                         auto_global->armed = 0;
    1322             :                 }
    1323             :         } ZEND_HASH_FOREACH_END();
    1324       20380 : }
    1325             : /* }}} */
    1326             : 
    1327     4870572 : int zendlex(zend_parser_stack_elem *elem TSRMLS_DC) /* {{{ */
    1328             : {
    1329             :         zval zv;
    1330             :         int retval;
    1331             : 
    1332     4870572 :         if (CG(increment_lineno)) {
    1333       25535 :                 CG(zend_lineno)++;
    1334       25535 :                 CG(increment_lineno) = 0;
    1335             :         }
    1336             : 
    1337             : again:
    1338     7059210 :         ZVAL_UNDEF(&zv);
    1339     7059210 :         retval = lex_scan(&zv TSRMLS_CC);
    1340     7059210 :         switch (retval) {
    1341             :                 case T_COMMENT:
    1342             :                 case T_DOC_COMMENT:
    1343             :                 case T_OPEN_TAG:
    1344             :                 case T_WHITESPACE:
    1345     2188638 :                         goto again;
    1346             : 
    1347             :                 case T_CLOSE_TAG:
    1348       26768 :                         if (LANG_SCNG(yy_text)[LANG_SCNG(yy_leng)-1] != '>') {
    1349       24061 :                                 CG(increment_lineno) = 1;
    1350             :                         }
    1351       26768 :                         retval = ';'; /* implicit ; */
    1352       26768 :                         break;
    1353             :                 case T_OPEN_TAG_WITH_ECHO:
    1354           3 :                         retval = T_ECHO;
    1355             :                         break;
    1356             :         }
    1357     4870572 :         if (Z_TYPE(zv) != IS_UNDEF) {
    1358     1718200 :                 elem->ast = zend_ast_create_zval(&zv);
    1359             :         }
    1360             : 
    1361     4870572 :         return retval;
    1362             : }
    1363             : /* }}} */
    1364             : 
    1365     3642554 : ZEND_API void zend_initialize_class_data(zend_class_entry *ce, zend_bool nullify_handlers TSRMLS_DC) /* {{{ */
    1366             : {
    1367     3642554 :         zend_bool persistent_hashes = (ce->type == ZEND_INTERNAL_CLASS) ? 1 : 0;
    1368     3642554 :         dtor_func_t zval_ptr_dtor_func = ((persistent_hashes) ? ZVAL_INTERNAL_PTR_DTOR : ZVAL_PTR_DTOR);
    1369             : 
    1370     3642554 :         ce->refcount = 1;
    1371     3642554 :         ce->ce_flags = ZEND_ACC_CONSTANTS_UPDATED;
    1372             : 
    1373     3642554 :         ce->default_properties_table = NULL;
    1374     3642554 :         ce->default_static_members_table = NULL;
    1375     3642554 :         zend_hash_init_ex(&ce->properties_info, 8, NULL, (persistent_hashes ? zend_destroy_property_info_internal : zend_destroy_property_info), persistent_hashes, 0);
    1376     3642554 :         zend_hash_init_ex(&ce->constants_table, 8, NULL, zval_ptr_dtor_func, persistent_hashes, 0);
    1377     3642554 :         zend_hash_init_ex(&ce->function_table, 8, NULL, ZEND_FUNCTION_DTOR, persistent_hashes, 0);
    1378             : 
    1379     3642554 :         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     3635294 :                 ce->static_members_table = NULL;
    1392             : #endif
    1393             :         } else {
    1394        7260 :                 ce->static_members_table = ce->default_static_members_table;
    1395        7260 :                 ce->info.user.doc_comment = NULL;
    1396             :         }
    1397             : 
    1398     3642554 :         ce->default_properties_count = 0;
    1399     3642554 :         ce->default_static_members_count = 0;
    1400             : 
    1401     3642554 :         if (nullify_handlers) {
    1402        7260 :                 ce->constructor = NULL;
    1403        7260 :                 ce->destructor = NULL;
    1404        7260 :                 ce->clone = NULL;
    1405        7260 :                 ce->__get = NULL;
    1406        7260 :                 ce->__set = NULL;
    1407        7260 :                 ce->__unset = NULL;
    1408        7260 :                 ce->__isset = NULL;
    1409        7260 :                 ce->__call = NULL;
    1410        7260 :                 ce->__callstatic = NULL;
    1411        7260 :                 ce->__tostring = NULL;
    1412        7260 :                 ce->create_object = NULL;
    1413        7260 :                 ce->get_iterator = NULL;
    1414        7260 :                 ce->iterator_funcs.funcs = NULL;
    1415        7260 :                 ce->interface_gets_implemented = NULL;
    1416        7260 :                 ce->get_static_method = NULL;
    1417        7260 :                 ce->parent = NULL;
    1418        7260 :                 ce->num_interfaces = 0;
    1419        7260 :                 ce->interfaces = NULL;
    1420        7260 :                 ce->num_traits = 0;
    1421        7260 :                 ce->traits = NULL;
    1422        7260 :                 ce->trait_aliases = NULL;
    1423        7260 :                 ce->trait_precedences = NULL;
    1424        7260 :                 ce->serialize = NULL;
    1425        7260 :                 ce->unserialize = NULL;
    1426        7260 :                 ce->serialize_func = NULL;
    1427        7260 :                 ce->unserialize_func = NULL;
    1428        7260 :                 ce->__debugInfo = NULL;
    1429        7260 :                 if (ce->type == ZEND_INTERNAL_CLASS) {
    1430           0 :                         ce->info.internal.module = NULL;
    1431           0 :                         ce->info.internal.builtin_functions = NULL;
    1432             :                 }
    1433             :         }
    1434     3642554 : }
    1435             : /* }}} */
    1436             : 
    1437      142263 : uint32_t zend_get_class_fetch_type(zend_string *name) /* {{{ */ 
    1438             : {
    1439      142263 :         if (zend_string_equals_literal_ci(name, "self")) {
    1440        6390 :                 return ZEND_FETCH_CLASS_SELF;
    1441      135873 :         } else if (zend_string_equals_literal_ci(name, "parent")) {
    1442        4405 :                 return ZEND_FETCH_CLASS_PARENT;
    1443      131468 :         } else if (zend_string_equals_literal_ci(name, "static")) {
    1444         121 :                 return ZEND_FETCH_CLASS_STATIC;
    1445             :         } else {
    1446      131347 :                 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        2313 : zend_ast *zend_ast_append_doc_comment(zend_ast *list TSRMLS_DC) /* {{{ */
    1480             : {
    1481        2313 :         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        2313 :         return list;
    1487             : }
    1488             : /* }}} */
    1489             : 
    1490      187078 : void zend_verify_namespace(TSRMLS_D) /* {{{ */
    1491             : {
    1492      187078 :         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      187077 : }
    1496             : /* }}} */
    1497             : 
    1498       29520 : static void zend_reset_import_tables(TSRMLS_D) /* {{{ */
    1499             : {
    1500       29520 :         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       29520 :         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       29520 :         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       29520 : }
    1518             : /* }}} */
    1519             : 
    1520       29325 : static void zend_end_namespace(TSRMLS_D) /* {{{ */ {
    1521       29325 :         CG(in_namespace) = 0;
    1522       29325 :         zend_reset_import_tables(TSRMLS_C);
    1523       29325 :         if (CG(current_namespace)) {
    1524         149 :                 zend_string_release(CG(current_namespace));
    1525         149 :                 CG(current_namespace) = NULL;
    1526             :         }
    1527       29325 : }
    1528             : /* }}} */
    1529             : 
    1530       29270 : void zend_do_end_compilation(TSRMLS_D) /* {{{ */
    1531             : {
    1532       29270 :         CG(has_bracketed_namespaces) = 0;
    1533       29270 :         zend_end_namespace(TSRMLS_C);
    1534       29270 : }
    1535             : /* }}} */
    1536             : 
    1537             : /* {{{ zend_dirname
    1538             :    Returns directory name component of path */
    1539       24898 : ZEND_API size_t zend_dirname(char *path, size_t len)
    1540             : {
    1541       24898 :         register char *end = path + len - 1;
    1542       24898 :         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       24898 :         if (len == 0) {
    1579             :                 /* Illegal use of this function */
    1580          36 :                 return 0;
    1581             :         }
    1582             : 
    1583             :         /* Strip trailing slashes */
    1584       49815 :         while (end >= path && IS_SLASH_P(end)) {
    1585          91 :                 end--;
    1586             :         }
    1587       24862 :         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      572339 :         while (end >= path && !IS_SLASH_P(end)) {
    1596      522637 :                 end--;
    1597             :         }
    1598       24851 :         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       74049 :         while (end >= path && IS_SLASH_P(end)) {
    1618       24693 :                 end--;
    1619             :         }
    1620       24678 :         if (end < path) {
    1621          23 :                 path[0] = DEFAULT_SLASH;
    1622          23 :                 path[1] = '\0';
    1623          23 :                 return 1 + len_adjust;
    1624             :         }
    1625       24655 :         *(end+1) = '\0';
    1626             : 
    1627       24655 :         return (size_t)(end + 1 - path) + len_adjust;
    1628             : }
    1629             : /* }}} */
    1630             : 
    1631       16825 : static inline zend_bool zend_string_equals_str_ci(zend_string *str1, zend_string *str2) /* {{{ */
    1632             : {
    1633       19258 :         return str1->len == str2->len
    1634       19258 :                 && !zend_binary_strcasecmp(str1->val, str1->len, str2->val, str2->len);
    1635             : }
    1636             : /* }}} */
    1637             : 
    1638      132470 : static void zend_adjust_for_fetch_type(zend_op *opline, uint32_t type) /* {{{ */ 
    1639             : {
    1640      132470 :         switch (type & BP_VAR_MASK) {
    1641             :                 case BP_VAR_R:
    1642       54502 :                         return;
    1643             :                 case BP_VAR_W:
    1644             :                 case BP_VAR_REF:
    1645       69330 :                         opline->opcode += 3;
    1646       69330 :                         return;
    1647             :                 case BP_VAR_RW:
    1648        1098 :                         opline->opcode += 6;
    1649        1098 :                         return;
    1650             :                 case BP_VAR_IS:
    1651        5041 :                         opline->opcode += 9;
    1652        5041 :                         return;
    1653             :                 case BP_VAR_FUNC_ARG:
    1654        2432 :                         opline->opcode += 12;
    1655        2432 :                         opline->extended_value |= type >> BP_VAR_SHIFT;
    1656        2432 :                         return;
    1657             :                 case BP_VAR_UNSET:
    1658          67 :                         opline->opcode += 15;
    1659          67 :                         return;
    1660             :                 EMPTY_SWITCH_DEFAULT_CASE()
    1661             :         }
    1662             : }
    1663             : /* }}} */
    1664             : 
    1665      665211 : static inline void zend_make_var_result(znode *result, zend_op *opline TSRMLS_DC) /* {{{ */ 
    1666             : {
    1667      665211 :         opline->result_type = IS_VAR;
    1668      665211 :         opline->result.var = get_temporary_variable(CG(active_op_array));
    1669      665211 :         GET_NODE(result, opline->result);
    1670      665211 : }
    1671             : /* }}} */
    1672             : 
    1673      184206 : static inline void zend_make_tmp_result(znode *result, zend_op *opline TSRMLS_DC) /* {{{ */
    1674             : {
    1675      184206 :         opline->result_type = IS_TMP_VAR;
    1676      184206 :         opline->result.var = get_temporary_variable(CG(active_op_array));
    1677      184206 :         GET_NODE(result, opline->result);
    1678      184206 : }
    1679             : /* }}} */
    1680             : 
    1681     1319672 : static zend_op *zend_emit_op(znode *result, zend_uchar opcode, znode *op1, znode *op2 TSRMLS_DC) /* {{{ */ 
    1682             : {
    1683     1319672 :         zend_op *opline = get_next_op(CG(active_op_array) TSRMLS_CC);
    1684     1319672 :         opline->opcode = opcode;
    1685             : 
    1686     1319672 :         if (op1 == NULL) {
    1687      727437 :                 SET_UNUSED(opline->op1);
    1688             :         } else {
    1689      592235 :                 SET_NODE(opline->op1, op1);
    1690             :         }
    1691             : 
    1692     1319672 :         if (op2 == NULL) {
    1693      835602 :                 SET_UNUSED(opline->op2);
    1694             :         } else {
    1695      484070 :                 SET_NODE(opline->op2, op2);
    1696             :         }
    1697             : 
    1698     1319672 :         if (result) {
    1699      525807 :                 zend_make_var_result(result, opline TSRMLS_CC);
    1700             :         }
    1701     1319672 :         return opline;
    1702             : }
    1703             : /* }}} */
    1704             : 
    1705      179573 : static zend_op *zend_emit_op_tmp(znode *result, zend_uchar opcode, znode *op1, znode *op2 TSRMLS_DC) /* {{{ */
    1706             : {
    1707      179573 :         zend_op *opline = get_next_op(CG(active_op_array) TSRMLS_CC);
    1708      179573 :         opline->opcode = opcode;
    1709             : 
    1710      179573 :         if (op1 == NULL) {
    1711       20216 :                 SET_UNUSED(opline->op1);
    1712             :         } else {
    1713      159357 :                 SET_NODE(opline->op1, op1);
    1714             :         }
    1715             : 
    1716      179573 :         if (op2 == NULL) {
    1717       94330 :                 SET_UNUSED(opline->op2);
    1718             :         } else {
    1719       85243 :                 SET_NODE(opline->op2, op2);
    1720             :         }
    1721             : 
    1722      179573 :         if (result) {
    1723      179520 :                 zend_make_tmp_result(result, opline TSRMLS_CC);
    1724             :         }
    1725             : 
    1726      179573 :         return opline;
    1727             : }
    1728             : /* }}} */
    1729             : 
    1730          29 : static void zend_emit_tick(TSRMLS_D) /* {{{ */
    1731             : {
    1732          29 :         zend_op *opline = get_next_op(CG(active_op_array) TSRMLS_CC);
    1733             : 
    1734          29 :         opline->opcode = ZEND_TICKS;
    1735          29 :         SET_UNUSED(opline->op1);
    1736          29 :         SET_UNUSED(opline->op2);
    1737          29 :         opline->extended_value = Z_LVAL(CG(declarables).ticks);
    1738          29 : }
    1739             : /* }}} */
    1740             : 
    1741        8629 : static inline zend_op *zend_emit_op_data(znode *value TSRMLS_DC) /* {{{ */
    1742             : {
    1743        8629 :         return zend_emit_op(NULL, ZEND_OP_DATA, value, NULL TSRMLS_CC);
    1744             : }
    1745             : /* }}} */
    1746             : 
    1747       61696 : static inline uint32_t zend_emit_jump(uint32_t opnum_target TSRMLS_DC) /* {{{ */
    1748             : {
    1749       61696 :         uint32_t opnum = get_next_op_number(CG(active_op_array));
    1750       61696 :         zend_op *opline = zend_emit_op(NULL, ZEND_JMP, NULL, NULL TSRMLS_CC);
    1751       61696 :         opline->op1.opline_num = opnum_target;
    1752       61696 :         return opnum;
    1753             : }
    1754             : /* }}} */
    1755             : 
    1756      102753 : static inline uint32_t zend_emit_cond_jump(zend_uchar opcode, znode *cond, uint32_t opnum_target TSRMLS_DC) /* {{{ */
    1757             : {
    1758      102753 :         uint32_t opnum = get_next_op_number(CG(active_op_array));
    1759      102753 :         zend_op *opline = zend_emit_op(NULL, opcode, cond, NULL TSRMLS_CC);
    1760      102753 :         opline->op2.opline_num = opnum_target;
    1761      102753 :         return opnum;
    1762             : }
    1763             : /* }}} */
    1764             : 
    1765      162471 : static inline void zend_update_jump_target(uint32_t opnum_jump, uint32_t opnum_target TSRMLS_DC) /* {{{ */
    1766             : {
    1767      162471 :         zend_op *opline = &CG(active_op_array)->opcodes[opnum_jump];
    1768      162471 :         switch (opline->opcode) {
    1769             :                 case ZEND_JMP:
    1770       48296 :                         opline->op1.opline_num = opnum_target;
    1771       48296 :                         break;
    1772             :                 case ZEND_JMPZ:
    1773             :                 case ZEND_JMPNZ:
    1774             :                 case ZEND_JMPZ_EX:
    1775             :                 case ZEND_JMPNZ_EX:
    1776      114175 :                         opline->op2.opline_num = opnum_target;
    1777             :                         break;
    1778             :                 EMPTY_SWITCH_DEFAULT_CASE()
    1779             :         }
    1780      162471 : }
    1781             : /* }}} */
    1782             : 
    1783      162471 : static inline void zend_update_jump_target_to_next(uint32_t opnum_jump TSRMLS_DC) /* {{{ */ 
    1784             : {
    1785      162471 :         zend_update_jump_target(opnum_jump, get_next_op_number(CG(active_op_array)) TSRMLS_CC);
    1786      162471 : }
    1787             : /* }}} */
    1788             : 
    1789      132504 : static inline zend_op *zend_delayed_emit_op(znode *result, zend_uchar opcode, znode *op1, znode *op2 TSRMLS_DC) /* {{{ */
    1790             : {
    1791             :         zend_op tmp_opline;
    1792      132504 :         init_op(&tmp_opline TSRMLS_CC);
    1793      132504 :         tmp_opline.opcode = opcode;
    1794      132504 :         SET_NODE(tmp_opline.op1, op1);
    1795      132504 :         SET_NODE(tmp_opline.op2, op2);
    1796      132504 :         if (result) {
    1797      132147 :                 zend_make_var_result(result, &tmp_opline TSRMLS_CC);
    1798             :         }
    1799             : 
    1800      132504 :         zend_stack_push(&CG(delayed_oplines_stack), &tmp_opline);
    1801      132504 :         return zend_stack_top(&CG(delayed_oplines_stack));
    1802             : }
    1803             : /* }}} */
    1804             : 
    1805      127558 : static inline uint32_t zend_delayed_compile_begin(TSRMLS_D) /* {{{ */
    1806             : {
    1807      127558 :         return zend_stack_count(&CG(delayed_oplines_stack));
    1808             : }
    1809             : /* }}} */
    1810             : 
    1811      127548 : static zend_op *zend_delayed_compile_end(uint32_t offset TSRMLS_DC) /* {{{ */
    1812             : {
    1813      127548 :         zend_op *opline, *oplines = zend_stack_base(&CG(delayed_oplines_stack));
    1814      127548 :         uint32_t i, count = zend_stack_count(&CG(delayed_oplines_stack));
    1815             : 
    1816             :         ZEND_ASSERT(count > offset);
    1817      260051 :         for (i = offset; i < count; ++i) {
    1818      132503 :                 opline = get_next_op(CG(active_op_array) TSRMLS_CC);
    1819      132503 :                 memcpy(opline, &oplines[i], sizeof(zend_op));
    1820             :         }
    1821      127548 :         CG(delayed_oplines_stack).top = offset;
    1822      127548 :         return opline;
    1823             : }
    1824             : /* }}} */
    1825             : 
    1826       64424 : void zend_emit_final_return(zval *zv TSRMLS_DC) /* {{{ */
    1827             : {
    1828             :         znode zn;
    1829       64424 :         zend_bool returns_reference = (CG(active_op_array)->fn_flags & ZEND_ACC_RETURN_REFERENCE) != 0;
    1830             : 
    1831       64424 :         zn.op_type = IS_CONST;
    1832       64424 :         if (zv) {
    1833       28193 :                 ZVAL_COPY_VALUE(&zn.u.constant, zv);
    1834             :         } else {
    1835       36231 :                 ZVAL_NULL(&zn.u.constant);
    1836             :         }
    1837             : 
    1838       64424 :         zend_emit_op(NULL, returns_reference ? ZEND_RETURN_BY_REF : ZEND_RETURN, &zn, NULL TSRMLS_CC);
    1839       64424 : }
    1840             : /* }}} */
    1841             : 
    1842      567914 : static inline zend_bool zend_is_variable(zend_ast *ast) /* {{{ */
    1843             : {
    1844     2234330 :         return ast->kind == ZEND_AST_VAR || ast->kind == ZEND_AST_DIM
    1845      649888 :                 || ast->kind == ZEND_AST_PROP || ast->kind == ZEND_AST_STATIC_PROP
    1846      555586 :                 || ast->kind == ZEND_AST_CALL || ast->kind == ZEND_AST_METHOD_CALL
    1847      460942 :                 || ast->kind == ZEND_AST_STATIC_CALL;
    1848             : }
    1849             : /* }}} */
    1850             : 
    1851      454513 : static inline zend_bool zend_is_call(zend_ast *ast) /* {{{ */
    1852             : {
    1853     1255288 :         return ast->kind == ZEND_AST_CALL
    1854      454513 :                 || ast->kind == ZEND_AST_METHOD_CALL
    1855      800775 :                 || ast->kind == ZEND_AST_STATIC_CALL;
    1856             : }
    1857             : /* }}} */
    1858             : 
    1859          38 : static inline zend_bool zend_is_unticked_stmt(zend_ast *ast) /* {{{ */
    1860             : {
    1861          38 :         return ast->kind == ZEND_AST_STMT_LIST || ast->kind == ZEND_AST_LABEL;
    1862             : }
    1863             : /* }}} */
    1864             : 
    1865        8045 : static inline zend_bool zend_can_write_to_variable(zend_ast *ast) /* {{{ */
    1866             : {
    1867       18139 :         while (ast->kind == ZEND_AST_DIM || ast->kind == ZEND_AST_PROP) {
    1868        2049 :                 ast = ast->child[0];
    1869             :         }
    1870             : 
    1871        8045 :         return zend_is_variable(ast);
    1872             : }
    1873             : /* }}} */
    1874             : 
    1875       38500 : static inline zend_bool zend_is_const_default_class_ref(zend_ast *name_ast) /* {{{ */
    1876             : {
    1877             :         zend_string *name;
    1878             : 
    1879       38500 :         if (name_ast->kind != ZEND_AST_ZVAL) {
    1880        1186 :                 return 0;
    1881             :         }
    1882             : 
    1883             :         /* Fully qualified names are always default refs */
    1884       37314 :         if (!name_ast->attr) {
    1885         136 :                 return 1;
    1886             :         }
    1887             : 
    1888       37178 :         name = zend_ast_get_str(name_ast);
    1889       37178 :         return ZEND_FETCH_CLASS_DEFAULT == zend_get_class_fetch_type(name);
    1890             : }
    1891             : /* }}} */
    1892             : 
    1893      133036 : static inline void zend_handle_numeric_op(znode *node TSRMLS_DC) /* {{{ */
    1894             : {
    1895      257532 :         if (node->op_type == IS_CONST && Z_TYPE(node->u.constant) == IS_STRING) {
    1896             :                 zend_ulong index;
    1897             : 
    1898       91890 :                 if (ZEND_HANDLE_NUMERIC(Z_STR(node->u.constant), index)) {
    1899          57 :                         zval_ptr_dtor(&node->u.constant);
    1900          57 :                         ZVAL_LONG(&node->u.constant, index);
    1901             :                 }
    1902             :         }
    1903      133036 : }
    1904             : /* }}} */
    1905             : 
    1906       18872 : static inline void zend_set_class_name_op1(zend_op *opline, znode *class_node TSRMLS_DC) /* {{{ */
    1907             : {
    1908       18872 :         if (class_node->op_type == IS_CONST) {
    1909       13894 :                 opline->op1_type = IS_CONST;
    1910       13894 :                 opline->op1.constant = zend_add_class_name_literal(
    1911             :                         CG(active_op_array), Z_STR(class_node->u.constant) TSRMLS_CC);
    1912             :         } else {
    1913        4978 :                 SET_NODE(opline->op1, class_node);
    1914             :         }
    1915       18872 : }
    1916             : /* }}} */
    1917             : 
    1918        8909 : static zend_op *zend_compile_class_ref(znode *result, zend_ast *name_ast TSRMLS_DC) /* {{{ */
    1919             : {
    1920             :         zend_op *opline;
    1921             :         znode name_node;
    1922        8909 :         zend_compile_expr(&name_node, name_ast TSRMLS_CC);
    1923             : 
    1924        8909 :         if (name_node.op_type == IS_CONST) {
    1925        7724 :                 zend_string *name = Z_STR(name_node.u.constant);
    1926        7724 :                 uint32_t fetch_type = zend_get_class_fetch_type(name);
    1927             : 
    1928        7724 :                 opline = zend_emit_op(result, ZEND_FETCH_CLASS, NULL, NULL TSRMLS_CC);
    1929        7724 :                 opline->extended_value = fetch_type;
    1930             : 
    1931        7724 :                 if (fetch_type == ZEND_FETCH_CLASS_DEFAULT) {
    1932        2322 :                         uint32_t type = name_ast->kind == ZEND_AST_ZVAL ? name_ast->attr : ZEND_NAME_FQ;
    1933        2322 :                         opline->op2_type = IS_CONST;
    1934        2322 :                         opline->op2.constant = zend_add_class_name_literal(CG(active_op_array),
    1935             :                                 zend_resolve_class_name(name, type TSRMLS_CC) TSRMLS_CC);
    1936             :                 }
    1937             : 
    1938             :                 zend_string_release(name);
    1939             :         } else {
    1940        1185 :                 opline = zend_emit_op(result, ZEND_FETCH_CLASS, NULL, &name_node TSRMLS_CC);
    1941        1185 :                 opline->extended_value = ZEND_FETCH_CLASS_DEFAULT;
    1942             :         }
    1943             : 
    1944        8909 :         return opline;
    1945             : }
    1946             : /* }}} */
    1947             : 
    1948      607838 : static int zend_try_compile_cv(znode *result, zend_ast *ast TSRMLS_DC) /* {{{ */ 
    1949             : {
    1950      607838 :         zend_ast *name_ast = ast->child[0];
    1951      607838 :         if (name_ast->kind == ZEND_AST_ZVAL) {
    1952      607655 :                 zend_string *name = zval_get_string(zend_ast_get_zval(name_ast));
    1953             : 
    1954      607655 :                 if (zend_is_auto_global(name TSRMLS_CC)) {
    1955             :                         zend_string_release(name);
    1956       17696 :                         return FAILURE;
    1957             :                 }
    1958             : 
    1959      589959 :                 result->op_type = IS_CV;
    1960      589959 :                 result->u.op.var = lookup_cv(CG(active_op_array), name TSRMLS_CC);
    1961             : 
    1962      589959 :                 if (zend_string_equals_literal(name, "this")) {
    1963         323 :                         CG(active_op_array)->this_var = result->u.op.var;
    1964             :                 }
    1965      589959 :                 return SUCCESS;
    1966             :         }
    1967             : 
    1968         183 :         return FAILURE;
    1969             : }
    1970             : /* }}} */
    1971             : 
    1972       19403 : static zend_op *zend_compile_simple_var_no_cv(znode *result, zend_ast *ast, uint32_t type TSRMLS_DC) /* {{{ */
    1973             : {
    1974       19403 :         zend_ast *name_ast = ast->child[0];
    1975             :         znode name_node;
    1976             :         zend_op *opline;
    1977             : 
    1978             :         /* there is a chance someone is accessing $this */
    1979       40268 :         if (ast->kind != ZEND_AST_ZVAL
    1980       40268 :                 && CG(active_op_array)->scope && CG(active_op_array)->this_var == -1
    1981             :         ) {
    1982         288 :                 zend_string *key = zend_string_init("this", sizeof("this") - 1, 0);
    1983         288 :                 CG(active_op_array)->this_var = lookup_cv(CG(active_op_array), key TSRMLS_CC);
    1984             :         }
    1985             : 
    1986       19403 :         zend_compile_expr(&name_node, name_ast TSRMLS_CC);
    1987             : 
    1988       19403 :         opline = zend_emit_op(result, ZEND_FETCH_R, &name_node, NULL TSRMLS_CC);
    1989             : 
    1990       19403 :         opline->extended_value = ZEND_FETCH_LOCAL;
    1991       19403 :         if (name_node.op_type == IS_CONST) {
    1992       19222 :                 if (zend_is_auto_global(Z_STR(name_node.u.constant) TSRMLS_CC)) {
    1993       17696 :                         opline->extended_value = ZEND_FETCH_GLOBAL;
    1994             :                 }
    1995             :         }
    1996             : 
    1997       19403 :         return opline;
    1998             : }
    1999             : /* }}} */
    2000             : 
    2001      598248 : static void zend_compile_simple_var(znode *result, zend_ast *ast, uint32_t type TSRMLS_DC) /* {{{ */
    2002             : {
    2003      598248 :         if (zend_try_compile_cv(result, ast TSRMLS_CC) == FAILURE) {
    2004       17847 :                 zend_op *opline = zend_compile_simple_var_no_cv(result, ast, type TSRMLS_CC);
    2005       17847 :                 zend_adjust_for_fetch_type(opline, type);
    2006             :         }
    2007      598248 : }
    2008             : /* }}} */
    2009             : 
    2010      129341 : static void zend_separate_if_call_and_write(znode *node, zend_ast *ast, uint32_t type TSRMLS_DC) /* {{{ */
    2011             : {
    2012      129341 :         if (type != BP_VAR_R && type != BP_VAR_IS && zend_is_call(ast)) {
    2013          48 :                 if (node->op_type == IS_VAR) {
    2014          47 :                         zend_op *opline = zend_emit_op(NULL, ZEND_SEPARATE, node, NULL TSRMLS_CC);
    2015          47 :                         opline->result_type = IS_VAR;
    2016          47 :                         opline->result.var = opline->op1.var;
    2017             :                 } else {
    2018           1 :                         zend_error_noreturn(E_COMPILE_ERROR, "Cannot use result of built-in function in write context");
    2019             :                 }
    2020             :         }
    2021      129340 : }
    2022             : /* }}} */
    2023             : 
    2024             : void zend_delayed_compile_var(znode *result, zend_ast *ast, uint32_t type TSRMLS_DC);
    2025             : void zend_compile_assign(znode *result, zend_ast *ast TSRMLS_DC);
    2026             : static void zend_compile_list_assign(znode *result, zend_ast *ast, znode *expr_node TSRMLS_DC);
    2027             : 
    2028       14771 : static inline void zend_emit_assign_znode(zend_ast *var_ast, znode *value_node TSRMLS_DC) /* {{{ */
    2029             : {
    2030             :         znode dummy_node;
    2031       14771 :         if (var_ast->kind == ZEND_AST_LIST) {
    2032          23 :                 zend_compile_list_assign(&dummy_node, var_ast, value_node TSRMLS_CC);
    2033             :         } else {
    2034       14748 :                 zend_ast *assign_ast = zend_ast_create(ZEND_AST_ASSIGN, var_ast,
    2035       14748 :                         zend_ast_create_znode(value_node));
    2036       14748 :                 zend_compile_assign(&dummy_node, assign_ast TSRMLS_CC);
    2037             :         }
    2038       14770 :         zend_do_free(&dummy_node TSRMLS_CC);
    2039       14770 : }
    2040             : /* }}} */
    2041             : 
    2042      122502 : static zend_op *zend_delayed_compile_dim(znode *result, zend_ast *ast, uint32_t type TSRMLS_DC) /* {{{ */
    2043             : {
    2044      122502 :         zend_ast *var_ast = ast->child[0];
    2045      122502 :         zend_ast *dim_ast = ast->child[1];
    2046             : 
    2047             :         znode var_node, dim_node;
    2048             : 
    2049      122502 :         zend_delayed_compile_var(&var_node, var_ast, type TSRMLS_CC);
    2050      122500 :         zend_separate_if_call_and_write(&var_node, var_ast, type TSRMLS_CC);
    2051             : 
    2052      122499 :         if (dim_ast == NULL) {
    2053         418 :                 if (type == BP_VAR_R || type == BP_VAR_IS) {
    2054           7 :                         zend_error_noreturn(E_COMPILE_ERROR, "Cannot use [] for reading");
    2055             :                 }
    2056         411 :                 if (type == BP_VAR_UNSET) {
    2057           1 :                         zend_error_noreturn(E_COMPILE_ERROR, "Cannot use [] for unsetting");
    2058             :                 }
    2059         410 :                 dim_node.op_type = IS_UNUSED;
    2060             :         } else {
    2061      122081 :                 zend_compile_expr(&dim_node, dim_ast TSRMLS_CC);
    2062      122081 :                 zend_handle_numeric_op(&dim_node TSRMLS_CC);
    2063             :         }
    2064             : 
    2065      122491 :         return zend_delayed_emit_op(result, ZEND_FETCH_DIM_R, &var_node, &dim_node TSRMLS_CC);
    2066             : }
    2067             : /* }}} */
    2068             : 
    2069      112109 : static inline zend_op *zend_compile_dim_common(znode *result, zend_ast *ast, uint32_t type TSRMLS_DC) /* {{{ */
    2070             : {
    2071      112109 :         uint32_t offset = zend_delayed_compile_begin(TSRMLS_C);
    2072      112109 :         zend_delayed_compile_dim(result, ast, type TSRMLS_CC);
    2073      112101 :         return zend_delayed_compile_end(offset TSRMLS_CC);
    2074             : }
    2075             : /* }}} */
    2076             : 
    2077      103224 : void zend_compile_dim(znode *result, zend_ast *ast, uint32_t type TSRMLS_DC) /* {{{ */
    2078             : {
    2079      103224 :         zend_op *opline = zend_compile_dim_common(result, ast, type TSRMLS_CC);
    2080      103218 :         zend_adjust_for_fetch_type(opline, type);
    2081      103218 : }
    2082             : /* }}} */
    2083             : 
    2084      190997 : static zend_bool is_this_fetch(zend_ast *ast) /* {{{ */
    2085             : {
    2086      190997 :         if (ast->kind == ZEND_AST_VAR && ast->child[0]->kind == ZEND_AST_ZVAL) {
    2087      359338 :                 zval *name = zend_ast_get_zval(ast->child[0]);
    2088      179669 :                 return Z_TYPE_P(name) == IS_STRING && zend_string_equals_literal(Z_STR_P(name), "this");
    2089             :         }
    2090             : 
    2091       11328 :         return 0;
    2092             : }
    2093             : /* }}} */
    2094             : 
    2095       10013 : static zend_op *zend_delayed_compile_prop(znode *result, zend_ast *ast, uint32_t type TSRMLS_DC) /* {{{ */
    2096             : {
    2097       10013 :         zend_ast *obj_ast = ast->child[0];
    2098       10013 :         zend_ast *prop_ast = ast->child[1];
    2099             : 
    2100             :         znode obj_node, prop_node;
    2101             :         zend_op *opline;
    2102             : 
    2103       10013 :         if (is_this_fetch(obj_ast)) {
    2104        3249 :                 obj_node.op_type = IS_UNUSED;
    2105             :         } else {
    2106        6764 :                 zend_delayed_compile_var(&obj_node, obj_ast, type TSRMLS_CC);
    2107        6764 :                 zend_separate_if_call_and_write(&obj_node, obj_ast, type TSRMLS_CC);
    2108             :         }
    2109       10013 :         zend_compile_expr(&prop_node, prop_ast TSRMLS_CC);
    2110             : 
    2111       10013 :         opline = zend_delayed_emit_op(result, ZEND_FETCH_OBJ_R, &obj_node, &prop_node TSRMLS_CC);
    2112       19943 :         if (opline->op2_type == IS_CONST && Z_TYPE(CONSTANT(opline->op2.constant)) == IS_STRING) {
    2113        9920 :                 zend_alloc_polymorphic_cache_slot(opline->op2.constant TSRMLS_CC);
    2114             :         }
    2115             : 
    2116       10013 :         return opline;
    2117             : }
    2118             : /* }}} */
    2119             : 
    2120        6818 : static zend_op *zend_compile_prop_common(znode *result, zend_ast *ast, uint32_t type TSRMLS_DC) /* {{{ */
    2121             : {
    2122        6818 :         uint32_t offset = zend_delayed_compile_begin(TSRMLS_C);
    2123        6818 :         zend_delayed_compile_prop(result, ast, type TSRMLS_CC);
    2124        6818 :         return zend_delayed_compile_end(offset TSRMLS_CC);
    2125             : }
    2126             : /* }}} */
    2127             : 
    2128        5932 : void zend_compile_prop(znode *result, zend_ast *ast, uint32_t type TSRMLS_DC) /* {{{ */
    2129             : {
    2130        5932 :         zend_op *opline = zend_compile_prop_common(result, ast, type TSRMLS_CC);
    2131        5932 :         zend_adjust_for_fetch_type(opline, type);
    2132        5932 : }
    2133             : /* }}} */
    2134             : 
    2135         628 : zend_op *zend_compile_static_prop_common(znode *result, zend_ast *ast, uint32_t type TSRMLS_DC) /* {{{ */
    2136             : {
    2137         628 :         zend_ast *class_ast = ast->child[0];
    2138         628 :         zend_ast *prop_ast = ast->child[1];
    2139             : 
    2140             :         znode class_node, prop_node;
    2141             :         zend_op *opline;
    2142             : 
    2143         628 :         if (zend_is_const_default_class_ref(class_ast)) {
    2144         228 :                 class_node.op_type = IS_CONST;
    2145         228 :                 ZVAL_STR(&class_node.u.constant, zend_resolve_class_name_ast(class_ast TSRMLS_CC));
    2146             :         } else {
    2147         400 :                 zend_compile_class_ref(&class_node, class_ast TSRMLS_CC);
    2148             :         }
    2149             : 
    2150         628 :         zend_compile_expr(&prop_node, prop_ast TSRMLS_CC);
    2151             : 
    2152         628 :         opline = zend_emit_op(result, ZEND_FETCH_R, &prop_node, NULL TSRMLS_CC);
    2153         628 :         if (opline->op1_type == IS_CONST) {
    2154         624 :                 zend_alloc_polymorphic_cache_slot(opline->op1.constant TSRMLS_CC);
    2155             :         }
    2156         628 :         if (class_node.op_type == IS_CONST) {
    2157         228 :                 opline->op2_type = IS_CONST;
    2158         228 :                 opline->op2.constant = zend_add_class_name_literal(
    2159             :                         CG(active_op_array), Z_STR(class_node.u.constant) TSRMLS_CC);
    2160             :         } else {
    2161         400 :                 SET_NODE(opline->op2, &class_node);
    2162             :         }
    2163         628 :         opline->extended_value |= ZEND_FETCH_STATIC_MEMBER;
    2164             : 
    2165         628 :         return opline;
    2166             : }
    2167             : /* }}} */
    2168             : 
    2169         517 : void zend_compile_static_prop(znode *result, zend_ast *ast, uint32_t type TSRMLS_DC) /* {{{ */
    2170             : {
    2171         517 :         zend_op *opline = zend_compile_static_prop_common(result, ast, type TSRMLS_CC);
    2172         517 :         zend_adjust_for_fetch_type(opline, type);
    2173         517 : }
    2174             : /* }}} */
    2175             : 
    2176         171 : static void zend_compile_list_assign(znode *result, zend_ast *ast, znode *expr_node TSRMLS_DC) /* {{{ */
    2177             : {
    2178         171 :         zend_ast_list *list = zend_ast_get_list(ast);
    2179             :         uint32_t i;
    2180             : 
    2181         171 :         if (list->children == 1 && !list->child[0]) {
    2182           1 :                 zend_error_noreturn(E_COMPILE_ERROR, "Cannot use empty list");
    2183             :         }
    2184             : 
    2185         558 :         for (i = 0; i < list->children; ++i) {
    2186         388 :                 zend_ast *var_ast = list->child[i];
    2187             :                 znode fetch_result, dim_node;
    2188             : 
    2189         388 :                 if (var_ast == NULL) {
    2190          19 :                         continue;
    2191             :                 }
    2192             : 
    2193         369 :                 dim_node.op_type = IS_CONST;
    2194         369 :                 ZVAL_LONG(&dim_node.u.constant, i);
    2195             : 
    2196         369 :                 if (expr_node->op_type == IS_CONST) {
    2197          27 :                         Z_TRY_ADDREF(expr_node->u.constant);
    2198             :                 }
    2199             : 
    2200         369 :                 zend_emit_op(&fetch_result, ZEND_FETCH_LIST, expr_node, &dim_node TSRMLS_CC);
    2201         369 :                 zend_emit_assign_znode(var_ast, &fetch_result TSRMLS_CC);
    2202             :         }
    2203         170 :         *result = *expr_node;
    2204         170 : }
    2205             : /* }}} */
    2206             : 
    2207      150471 : void zend_ensure_writable_variable(const zend_ast *ast) /* {{{ */
    2208             : {
    2209      150471 :         if (ast->kind == ZEND_AST_CALL) {
    2210           1 :                 zend_error_noreturn(E_COMPILE_ERROR, "Can't use function return value in write context");
    2211             :         }
    2212      150470 :         if (ast->kind == ZEND_AST_METHOD_CALL || ast->kind == ZEND_AST_STATIC_CALL) {
    2213           1 :                 zend_error_noreturn(E_COMPILE_ERROR, "Can't use method return value in write context");
    2214             :         }
    2215      150469 : }
    2216             : /* }}} */
    2217             : 
    2218             : /* Detects $a... = $a pattern */
    2219        6582 : zend_bool zend_is_assign_to_self(zend_ast *var_ast, zend_ast *expr_ast TSRMLS_DC) /* {{{ */
    2220             : {
    2221        6582 :         if (expr_ast->kind != ZEND_AST_VAR || expr_ast->child[0]->kind != ZEND_AST_ZVAL) {
    2222        4940 :                 return 0;
    2223             :         }
    2224             : 
    2225        5002 :         while (zend_is_variable(var_ast) && var_ast->kind != ZEND_AST_VAR) {
    2226        1718 :                 var_ast = var_ast->child[0];
    2227             :         }
    2228             : 
    2229        1642 :         if (var_ast->kind != ZEND_AST_VAR || var_ast->child[0]->kind != ZEND_AST_ZVAL) {
    2230           2 :                 return 0;
    2231             :         }
    2232             : 
    2233             :         {
    2234        3280 :                 zend_string *name1 = zval_get_string(zend_ast_get_zval(var_ast->child[0]));
    2235        3280 :                 zend_string *name2 = zval_get_string(zend_ast_get_zval(expr_ast->child[0]));
    2236        1640 :                 zend_bool result = zend_string_equals(name1, name2);
    2237             :                 zend_string_release(name1);
    2238             :                 zend_string_release(name2);
    2239        1640 :                 return result;
    2240             :         }
    2241             : }
    2242             : /* }}} */
    2243             : 
    2244      144170 : void zend_compile_assign(znode *result, zend_ast *ast TSRMLS_DC) /* {{{ */
    2245             : {
    2246      144170 :         zend_ast *var_ast = ast->child[0];
    2247      144170 :         zend_ast *expr_ast = ast->child[1];
    2248             : 
    2249             :         znode var_node, expr_node;
    2250             :         zend_op *opline;
    2251             :         uint32_t offset;
    2252             : 
    2253      144170 :         if (is_this_fetch(var_ast)) {
    2254           2 :                 zend_error_noreturn(E_COMPILE_ERROR, "Cannot re-assign $this");
    2255             :         }
    2256             : 
    2257      144168 :         zend_ensure_writable_variable(var_ast);
    2258             : 
    2259      144166 :         switch (var_ast->kind) {
    2260             :                 case ZEND_AST_VAR:
    2261             :                 case ZEND_AST_STATIC_PROP:
    2262      135482 :                         zend_compile_var(&var_node, var_ast, BP_VAR_W TSRMLS_CC);
    2263      135482 :                         zend_compile_expr(&expr_node, expr_ast TSRMLS_CC);
    2264      135479 :                         zend_emit_op(result, ZEND_ASSIGN, &var_node, &expr_node TSRMLS_CC);
    2265      135479 :                         return;
    2266             :                 case ZEND_AST_DIM:
    2267        6584 :                         offset = zend_delayed_compile_begin(TSRMLS_C);
    2268        6584 :                         zend_delayed_compile_dim(result, var_ast, BP_VAR_W TSRMLS_CC);
    2269             : 
    2270        6582 :                         if (zend_is_assign_to_self(var_ast, expr_ast TSRMLS_CC)) {
    2271             :                                 /* $a[0] = $a should evaluate the right $a first */
    2272          16 :                                 zend_compile_simple_var_no_cv(&expr_node, expr_ast, BP_VAR_R TSRMLS_CC);
    2273             :                         } else {
    2274        6566 :                                 zend_compile_expr(&expr_node, expr_ast TSRMLS_CC);
    2275             :                         }
    2276             : 
    2277        6582 :                         opline = zend_delayed_compile_end(offset TSRMLS_CC);
    2278        6582 :                         opline->opcode = ZEND_ASSIGN_DIM;
    2279             : 
    2280        6582 :                         opline = zend_emit_op_data(&expr_node TSRMLS_CC);
    2281        6582 :                         return;
    2282             :                 case ZEND_AST_PROP:
    2283        1952 :                         offset = zend_delayed_compile_begin(TSRMLS_C);
    2284        1952 :                         zend_delayed_compile_prop(result, var_ast, BP_VAR_W TSRMLS_CC);
    2285        1952 :                         zend_compile_expr(&expr_node, expr_ast TSRMLS_CC);
    2286             : 
    2287        1952 :                         opline = zend_delayed_compile_end(offset TSRMLS_CC);
    2288        1952 :                         opline->opcode = ZEND_ASSIGN_OBJ;
    2289             : 
    2290        1952 :                         zend_emit_op_data(&expr_node TSRMLS_CC);
    2291        1952 :                         return;
    2292             :                 case ZEND_AST_LIST:
    2293         148 :                         zend_compile_expr(&expr_node, expr_ast TSRMLS_CC);
    2294         148 :                         zend_compile_list_assign(result, var_ast, &expr_node TSRMLS_CC);
    2295         148 :                         return;
    2296             :                 EMPTY_SWITCH_DEFAULT_CASE();
    2297             :         }
    2298             : }
    2299             : /* }}} */
    2300             : 
    2301        2403 : void zend_compile_assign_ref(znode *result, zend_ast *ast TSRMLS_DC) /* {{{ */
    2302             : {
    2303        2403 :         zend_ast *target_ast = ast->child[0];
    2304        2403 :         zend_ast *source_ast = ast->child[1];
    2305             : 
    2306             :         znode target_node, source_node;
    2307             :         zend_op *opline;
    2308             : 
    2309        2403 :         if (is_this_fetch(target_ast)) {
    2310           1 :                 zend_error_noreturn(E_COMPILE_ERROR, "Cannot re-assign $this");
    2311             :         }
    2312        2402 :         zend_ensure_writable_variable(target_ast);
    2313             : 
    2314        2402 :         zend_compile_var(&target_node, target_ast, BP_VAR_W TSRMLS_CC);
    2315        2402 :         zend_compile_var(&source_node, source_ast, BP_VAR_REF TSRMLS_CC);
    2316             : 
    2317        2402 :         if (source_node.op_type != IS_VAR && zend_is_call(source_ast)) {
    2318           1 :                 zend_error_noreturn(E_COMPILE_ERROR, "Cannot use result of built-in function in write context");
    2319             :         }
    2320             : 
    2321        2401 :         opline = zend_emit_op(result, ZEND_ASSIGN_REF, &target_node, &source_node TSRMLS_CC);
    2322        2401 :         if (!result) {
    2323        1989 :                 opline->result_type |= EXT_TYPE_UNUSED;
    2324             :         }
    2325             : 
    2326        2401 :         if (zend_is_call(source_ast)) {
    2327          43 :                 opline->extended_value = ZEND_RETURNS_FUNCTION;
    2328        2358 :         } else if (source_ast->kind == ZEND_AST_NEW) {
    2329          10 :                 zend_error(E_DEPRECATED, "Assigning the return value of new by reference is deprecated");
    2330          10 :                 opline->extended_value = ZEND_RETURNS_NEW;
    2331             :         }
    2332        2401 : }
    2333             : /* }}} */
    2334             : 
    2335        1989 : static inline void zend_emit_assign_ref_znode(zend_ast *var_ast, znode *value_node TSRMLS_DC) /* {{{ */
    2336             : {
    2337        1989 :         zend_ast *assign_ast = zend_ast_create(ZEND_AST_ASSIGN_REF, var_ast,
    2338        1989 :                 zend_ast_create_znode(value_node));
    2339        1989 :         zend_compile_assign_ref(NULL, assign_ast TSRMLS_CC);
    2340        1989 : }
    2341             : /* }}} */
    2342             : 
    2343        3750 : void zend_compile_compound_assign(znode *result, zend_ast *ast TSRMLS_DC) /* {{{ */
    2344             : {
    2345        3750 :         zend_ast *var_ast = ast->child[0];
    2346        3750 :         zend_ast *expr_ast = ast->child[1];
    2347        3750 :         uint32_t opcode = ast->attr;
    2348             : 
    2349             :         znode var_node, expr_node;
    2350             :         zend_op *opline;
    2351             :         uint32_t offset;
    2352             : 
    2353        3750 :         zend_ensure_writable_variable(var_ast);
    2354             : 
    2355        3750 :         switch (var_ast->kind) {
    2356             :                 case ZEND_AST_VAR:
    2357             :                 case ZEND_AST_STATIC_PROP:
    2358        3655 :                         zend_compile_var(&var_node, var_ast, BP_VAR_RW TSRMLS_CC);
    2359        3655 :                         zend_compile_expr(&expr_node, expr_ast TSRMLS_CC);
    2360        3655 :                         zend_emit_op(result, opcode, &var_node, &expr_node TSRMLS_CC);
    2361        3655 :                         return;
    2362             :                 case ZEND_AST_DIM:
    2363          47 :                         offset = zend_delayed_compile_begin(TSRMLS_C);
    2364          47 :                         zend_delayed_compile_dim(result, var_ast, BP_VAR_RW TSRMLS_CC);
    2365          47 :                         zend_compile_expr(&expr_node, expr_ast TSRMLS_CC);
    2366             : 
    2367          47 :                         opline = zend_delayed_compile_end(offset TSRMLS_CC);
    2368          47 :                         opline->opcode = opcode;
    2369          47 :                         opline->extended_value = ZEND_ASSIGN_DIM;
    2370             : 
    2371          47 :                         opline = zend_emit_op_data(&expr_node TSRMLS_CC);
    2372          47 :                         return;
    2373             :                 case ZEND_AST_PROP:
    2374          48 :                         offset = zend_delayed_compile_begin(TSRMLS_C);
    2375          48 :                         zend_delayed_compile_prop(result, var_ast, BP_VAR_RW TSRMLS_CC);
    2376          48 :                         zend_compile_expr(&expr_node, expr_ast TSRMLS_CC);
    2377             : 
    2378          48 :                         opline = zend_delayed_compile_end(offset TSRMLS_CC);
    2379          48 :                         opline->opcode = opcode;
    2380          48 :                         opline->extended_value = ZEND_ASSIGN_OBJ;
    2381             : 
    2382          48 :                         zend_emit_op_data(&expr_node TSRMLS_CC);
    2383          48 :                         return;
    2384             :                 EMPTY_SWITCH_DEFAULT_CASE()
    2385             :         }
    2386             : }
    2387             : /* }}} */
    2388             : 
    2389      306003 : uint32_t zend_compile_args(zend_ast *ast, zend_function *fbc TSRMLS_DC) /* {{{ */
    2390             : {
    2391             :         /* TODO.AST &var error */
    2392      306003 :         zend_ast_list *args = zend_ast_get_list(ast);
    2393             :         uint32_t i;
    2394      306003 :         zend_bool uses_arg_unpack = 0;
    2395      306003 :         uint32_t arg_count = 0; /* number of arguments not including unpacks */
    2396             : 
    2397      839114 :         for (i = 0; i < args->children; ++i) {
    2398      533125 :                 zend_ast *arg = args->child[i];
    2399      533125 :                 uint32_t arg_num = i + 1;
    2400             : 
    2401             :                 znode arg_node;
    2402             :                 zend_op *opline;
    2403             :                 zend_uchar opcode;
    2404      533125 :                 zend_ulong flags = 0;
    2405             : 
    2406      533125 :                 if (arg->kind == ZEND_AST_UNPACK) {
    2407          64 :                         uses_arg_unpack = 1;
    2408          64 :                         fbc = NULL;
    2409             :                         
    2410          64 :                         zend_compile_expr(&arg_node, arg->child[0] TSRMLS_CC);
    2411          64 :                         opline = zend_emit_op(NULL, ZEND_SEND_UNPACK, &arg_node, NULL TSRMLS_CC);
    2412          64 :                         opline->op2.num = arg_count;
    2413          64 :                         continue;
    2414             :                 }
    2415             : 
    2416      533061 :                 if (uses_arg_unpack) {
    2417           1 :                         zend_error_noreturn(E_COMPILE_ERROR,
    2418             :                                 "Cannot use positional argument after argument unpacking");
    2419             :                 }
    2420             : 
    2421      533060 :                 arg_count++;
    2422      533060 :                 if (zend_is_variable(arg)) {
    2423      305862 :                         if (zend_is_call(arg)) {
    2424       48645 :                                 zend_compile_var(&arg_node, arg, BP_VAR_R TSRMLS_CC);
    2425       48642 :                                 if (arg_node.op_type & (IS_CONST|IS_TMP_VAR)) {
    2426             :                                         /* Function call was converted into builtin instruction */
    2427        1512 :                                         opcode = ZEND_SEND_VAL;
    2428             :                                 } else {
    2429       47130 :                                         opcode = ZEND_SEND_VAR_NO_REF;
    2430       47130 :                                         flags |= ZEND_ARG_SEND_FUNCTION;
    2431       93265 :                                         if (fbc && ARG_SHOULD_BE_SENT_BY_REF(fbc, arg_num)) {
    2432          56 :                                                 flags |= ZEND_ARG_SEND_BY_REF;
    2433          56 :                                                 if (ARG_MAY_BE_SENT_BY_REF(fbc, arg_num)) {
    2434          34 :                                                         flags |= ZEND_ARG_SEND_SILENT;
    2435             :                                                 }
    2436             :                                         }
    2437             :                                 }
    2438      257217 :                         } else if (fbc) {
    2439      215511 :                                 if (ARG_SHOULD_BE_SENT_BY_REF(fbc, arg_num)) {
    2440       73542 :                                         zend_compile_var(&arg_node, arg, BP_VAR_W TSRMLS_CC);
    2441       73542 :                                         opcode = ZEND_SEND_REF;
    2442             :                                 } else {
    2443      141969 :                                         zend_compile_var(&arg_node, arg, BP_VAR_R TSRMLS_CC);
    2444      141968 :                                         opcode = ZEND_SEND_VAR;
    2445             :                                 }
    2446             :                         } else {
    2447       41706 :                                 zend_compile_var(&arg_node, arg,
    2448       41706 :                                         BP_VAR_FUNC_ARG | (arg_num << BP_VAR_SHIFT) TSRMLS_CC);
    2449       41706 :                                 opcode = ZEND_SEND_VAR_EX;
    2450             :                         }
    2451             :                 } else {
    2452      227198 :                         zend_compile_expr(&arg_node, arg TSRMLS_CC);
    2453      227196 :                         if (arg_node.op_type & (IS_VAR|IS_CV)) {
    2454        2210 :                                 opcode = ZEND_SEND_VAR_NO_REF;
    2455        3637 :                                 if (fbc && ARG_MUST_BE_SENT_BY_REF(fbc, arg_num)) {
    2456           9 :                                         flags |= ZEND_ARG_SEND_BY_REF;
    2457             :                                 }
    2458             :                         } else {
    2459      224986 :                                 if (fbc) {
    2460      188523 :                                         opcode = ZEND_SEND_VAL;
    2461      188523 :                                         if (ARG_MUST_BE_SENT_BY_REF(fbc, arg_num)) {
    2462           7 :                                                 zend_error_noreturn(E_COMPILE_ERROR, "Only variables can be passed by reference");
    2463             :                                         }
    2464             :                                 } else {
    2465       36463 :                                         opcode = ZEND_SEND_VAL_EX;
    2466             :                                 }
    2467             :                         }
    2468             :                 }
    2469             : 
    2470      533047 :                 opline = get_next_op(CG(active_op_array) TSRMLS_CC);
    2471      533047 :                 opline->opcode = opcode;
    2472      533047 :                 SET_NODE(opline->op1, &arg_node);
    2473      533047 :                 SET_UNUSED(opline->op2);
    2474      533047 :                 opline->op2.opline_num = arg_num;
    2475             : 
    2476      533047 :                 if (opcode == ZEND_SEND_VAR_NO_REF) {
    2477       49340 :                         if (fbc) {
    2478       47562 :                                 flags |= ZEND_ARG_COMPILE_TIME_BOUND;
    2479             :                         }
    2480       49340 :                         opline->extended_value = flags;
    2481      483707 :                 } else if (fbc) {
    2482      405535 :                         opline->extended_value = ZEND_ARG_COMPILE_TIME_BOUND;
    2483             :                 }
    2484             :         }
    2485             : 
    2486      305989 :         return arg_count;
    2487             : }
    2488             : /* }}} */
    2489             : 
    2490      306003 : void zend_compile_call_common(znode *result, zend_ast *args_ast, zend_function *fbc TSRMLS_DC) /* {{{ */
    2491             : {
    2492             :         zend_op *opline;
    2493      306003 :         uint32_t opnum_init = get_next_op_number(CG(active_op_array)) - 1;
    2494             :         uint32_t arg_count;
    2495             :         uint32_t call_flags;
    2496             : 
    2497      306003 :         zend_do_extended_fcall_begin(TSRMLS_C);
    2498             : 
    2499      306003 :         arg_count = zend_compile_args(args_ast, fbc TSRMLS_CC);
    2500             : 
    2501      305989 :         opline = &CG(active_op_array)->opcodes[opnum_init];
    2502      305989 :         opline->extended_value = arg_count;
    2503             : 
    2504      305989 :         call_flags = (opline->opcode == ZEND_NEW ? ZEND_CALL_CTOR : 0);
    2505      305989 :         opline = zend_emit_op(result, ZEND_DO_FCALL, NULL, NULL TSRMLS_CC);
    2506      305989 :         opline->op1.num = call_flags;
    2507             : 
    2508      305989 :         zend_do_extended_fcall_end(TSRMLS_C);
    2509      305989 : }
    2510             : /* }}} */
    2511             : 
    2512      253987 : zend_bool zend_compile_function_name(znode *name_node, zend_ast *name_ast TSRMLS_DC) /* {{{ */
    2513             : {
    2514      253987 :         zend_string *orig_name = zend_ast_get_str(name_ast);
    2515             :         zend_bool is_fully_qualified;
    2516             : 
    2517      253987 :         name_node->op_type = IS_CONST;
    2518      253987 :         ZVAL_STR(&name_node->u.constant, zend_resolve_function_name(
    2519             :                 orig_name, name_ast->attr, &is_fully_qualified TSRMLS_CC));
    2520             : 
    2521      253987 :         return !is_fully_qualified && CG(current_namespace);
    2522             : }
    2523             : /* }}} */
    2524             : 
    2525         297 : void zend_compile_ns_call(znode *result, znode *name_node, zend_ast *args_ast TSRMLS_DC) /* {{{ */
    2526             : {
    2527         297 :         zend_op *opline = get_next_op(CG(active_op_array) TSRMLS_CC);
    2528         297 :         opline->opcode = ZEND_INIT_NS_FCALL_BY_NAME;
    2529         297 :         SET_UNUSED(opline->op1);
    2530         297 :         opline->op2_type = IS_CONST;
    2531         297 :         opline->op2.constant = zend_add_ns_func_name_literal(
    2532             :                 CG(active_op_array), Z_STR(name_node->u.constant) TSRMLS_CC);
    2533         297 :         zend_alloc_cache_slot(opline->op2.constant TSRMLS_CC);
    2534             : 
    2535         297 :         zend_compile_call_common(result, args_ast, NULL TSRMLS_CC);
    2536         297 : }
    2537             : /* }}} */
    2538             : 
    2539        5914 : void zend_compile_dynamic_call(znode *result, znode *name_node, zend_ast *args_ast TSRMLS_DC) /* {{{ */
    2540             : {
    2541        5914 :         zend_op *opline = get_next_op(CG(active_op_array) TSRMLS_CC);
    2542        5914 :         opline->opcode = ZEND_INIT_FCALL_BY_NAME;
    2543        5914 :         SET_UNUSED(opline->op1);
    2544       13585 :         if (name_node->op_type == IS_CONST && Z_TYPE(name_node->u.constant) == IS_STRING) {
    2545        3835 :                 opline->op2_type = IS_CONST;
    2546        3835 :                 opline->op2.constant = zend_add_func_name_literal(CG(active_op_array),
    2547             :                         Z_STR(name_node->u.constant) TSRMLS_CC);
    2548        3835 :                 zend_alloc_cache_slot(opline->op2.constant TSRMLS_CC);
    2549             :         } else {
    2550        2079 :                 SET_NODE(opline->op2, name_node);
    2551             :         }
    2552             : 
    2553        5914 :         zend_compile_call_common(result, args_ast, NULL TSRMLS_CC);
    2554        5914 : }
    2555             : /* }}} */
    2556             : 
    2557         196 : static zend_bool zend_args_contain_unpack(zend_ast_list *args) /* {{{ */
    2558             : {
    2559             :         uint32_t i;
    2560         809 :         for (i = 0; i < args->children; ++i) {
    2561         613 :                 if (args->child[i]->kind == ZEND_AST_UNPACK) {
    2562           0 :                         return 1;
    2563             :                 }
    2564             :         }
    2565         196 :         return 0;
    2566             : }
    2567             : /* }}} */
    2568             : 
    2569        4594 : int zend_compile_func_strlen(znode *result, zend_ast_list *args TSRMLS_DC) /* {{{ */
    2570             : {
    2571             :         znode arg_node;
    2572             : 
    2573       13772 :         if ((CG(compiler_options) & ZEND_COMPILE_NO_BUILTIN_STRLEN)
    2574        9178 :                 || args->children != 1 || args->child[0]->kind == ZEND_AST_UNPACK
    2575             :         ) {
    2576           8 :                 return FAILURE;
    2577             :         }
    2578             : 
    2579        4586 :         zend_compile_expr(&arg_node, args->child[0] TSRMLS_CC);
    2580        4586 :         zend_emit_op_tmp(result, ZEND_STRLEN, &arg_node, NULL TSRMLS_CC);
    2581        4586 :         return SUCCESS;
    2582             : }
    2583             : /* }}} */
    2584             : 
    2585        3867 : int zend_compile_func_typecheck(znode *result, zend_ast_list *args, uint32_t type TSRMLS_DC) /* {{{ */
    2586             : {
    2587             :         znode arg_node;
    2588             :         zend_op *opline;
    2589             : 
    2590        3867 :         if (args->children != 1 || args->child[0]->kind == ZEND_AST_UNPACK) {
    2591          24 :                 return FAILURE;
    2592             :         }
    2593             :         
    2594        3843 :         zend_compile_expr(&arg_node, args->child[0] TSRMLS_CC);
    2595        3843 :         opline = zend_emit_op_tmp(result, ZEND_TYPE_CHECK, &arg_node, NULL TSRMLS_CC);
    2596        3843 :         opline->extended_value = type;
    2597        3843 :         return SUCCESS;
    2598             : }
    2599             : /* }}} */
    2600             : 
    2601         172 : int zend_compile_func_defined(znode *result, zend_ast_list *args TSRMLS_DC) /* {{{ */
    2602             : {
    2603             :         zend_string *name;
    2604             :         zend_op *opline;
    2605             : 
    2606         172 :         if (args->children != 1 || args->child[0]->kind != ZEND_AST_ZVAL) {
    2607           1 :                 return FAILURE;
    2608             :         }
    2609             : 
    2610         342 :         name = zval_get_string(zend_ast_get_zval(args->child[0]));
    2611         513 :         if (zend_memrchr(name->val, '\\', name->len) || zend_memrchr(name->val, ':', name->len)) {
    2612             :                 zend_string_release(name);
    2613           8 :                 return FAILURE;
    2614             :         }
    2615             : 
    2616         163 :         opline = zend_emit_op_tmp(result, ZEND_DEFINED, NULL, NULL TSRMLS_CC);
    2617         163 :         opline->op1_type = IS_CONST;
    2618         163 :         LITERAL_STR(opline->op1, name);
    2619         163 :         zend_alloc_cache_slot(opline->op1.constant TSRMLS_CC);
    2620             : 
    2621             :         /* Lowercase constant name in a separate literal */
    2622             :         {
    2623             :                 zval c;
    2624         326 :                 zend_string *lcname = zend_string_alloc(name->len, 0);
    2625         163 :                 zend_str_tolower_copy(lcname->val, name->val, name->len);
    2626         163 :                 ZVAL_NEW_STR(&c, lcname);
    2627         163 :                 zend_add_literal(CG(active_op_array), &c TSRMLS_CC);
    2628             :         }
    2629         163 :         return SUCCESS;
    2630             : }
    2631             : /* }}} */
    2632             : 
    2633         196 : static int zend_try_compile_ct_bound_init_user_func(zend_ast *name_ast, uint32_t num_args TSRMLS_DC) /* {{{ */
    2634             : {
    2635             :         zend_string *name, *lcname;
    2636             :         zend_function *fbc;
    2637             :         zend_op *opline;
    2638             : 
    2639         266 :         if (name_ast->kind != ZEND_AST_ZVAL || Z_TYPE_P(zend_ast_get_zval(name_ast)) != IS_STRING) {
    2640         126 :                 return FAILURE;
    2641             :         }
    2642             : 
    2643          70 :         name = zend_ast_get_str(name_ast);
    2644         140 :         lcname = zend_string_alloc(name->len, 0);
    2645          70 :         zend_str_tolower_copy(lcname->val, name->val, name->len);
    2646             : 
    2647         140 :         fbc = zend_hash_find_ptr(CG(function_table), lcname);
    2648          87 :         if (!fbc || (fbc->type == ZEND_INTERNAL_FUNCTION &&
    2649          17 :                 (CG(compiler_options) & ZEND_COMPILE_IGNORE_INTERNAL_FUNCTIONS))
    2650             :         ) {
    2651             :                 zend_string_free(lcname);
    2652          24 :                 return FAILURE;
    2653             :         }
    2654             : 
    2655          46 :         opline = zend_emit_op(NULL, ZEND_INIT_FCALL, NULL, NULL TSRMLS_CC);
    2656          46 :         opline->extended_value = num_args;
    2657             : 
    2658          46 :         opline->op2_type = IS_CONST;
    2659          46 :         LITERAL_STR(opline->op2, lcname);
    2660          46 :         zend_alloc_cache_slot(opline->op2.constant TSRMLS_CC);
    2661             : 
    2662          46 :         return SUCCESS;
    2663             : }
    2664             : /* }}} */
    2665             : 
    2666         196 : static void zend_compile_init_user_func(zend_ast *name_ast, uint32_t num_args, zend_string *orig_func_name TSRMLS_DC) /* {{{ */
    2667             : {
    2668             :         zend_op *opline;
    2669             :         znode name_node;
    2670             : 
    2671         196 :         if (zend_try_compile_ct_bound_init_user_func(name_ast, num_args TSRMLS_CC) == SUCCESS) {
    2672          46 :                 return;
    2673             :         }
    2674             : 
    2675         150 :         zend_compile_expr(&name_node, name_ast TSRMLS_CC);
    2676             : 
    2677         150 :         opline = zend_emit_op(NULL, ZEND_INIT_USER_CALL, NULL, &name_node TSRMLS_CC);
    2678         150 :         opline->op1_type = IS_CONST;
    2679         300 :         LITERAL_STR(opline->op1, zend_string_copy(orig_func_name));
    2680         150 :         opline->extended_value = num_args;
    2681             : }
    2682             : /* }}} */
    2683             : 
    2684             : /* cufa = call_user_func_array */
    2685          69 : int zend_compile_func_cufa(znode *result, zend_ast_list *args, zend_string *lcname TSRMLS_DC) /* {{{ */
    2686             : {
    2687             :         znode arg_node;
    2688             : 
    2689          69 :         if (args->children != 2 || zend_args_contain_unpack(args)) {
    2690           0 :                 return FAILURE;
    2691             :         }
    2692             : 
    2693          69 :         zend_compile_init_user_func(args->child[0], 1, lcname TSRMLS_CC);
    2694          69 :         zend_compile_expr(&arg_node, args->child[1] TSRMLS_CC);
    2695          69 :         zend_emit_op(NULL, ZEND_SEND_ARRAY, &arg_node, NULL TSRMLS_CC);
    2696          69 :         zend_emit_op(result, ZEND_DO_FCALL, NULL, NULL TSRMLS_CC);
    2697             : 
    2698          69 :         return SUCCESS;
    2699             : }
    2700             : /* }}} */
    2701             : 
    2702             : /* cuf = call_user_func */
    2703         127 : int zend_compile_func_cuf(znode *result, zend_ast_list *args, zend_string *lcname TSRMLS_DC) /* {{{ */
    2704             : {
    2705             :         uint32_t i;
    2706             : 
    2707         127 :         if (args->children < 1 || zend_args_contain_unpack(args)) {
    2708           0 :                 return FAILURE;
    2709             :         }
    2710             : 
    2711         127 :         zend_compile_init_user_func(args->child[0], args->children - 1, lcname TSRMLS_CC);
    2712         475 :         for (i = 1; i < args->children; ++i) {
    2713         348 :                 zend_ast *arg_ast = args->child[i];
    2714             :                 znode arg_node;
    2715             :                 zend_op *opline;
    2716         348 :                 zend_bool send_user = 0;
    2717             : 
    2718         609 :                 if (zend_is_variable(arg_ast) && !zend_is_call(arg_ast)) {
    2719         261 :                         zend_compile_var(&arg_node, arg_ast, BP_VAR_FUNC_ARG | (i << BP_VAR_SHIFT) TSRMLS_CC);
    2720         261 :                         send_user = 1;
    2721             :                 } else {
    2722          87 :                         zend_compile_expr(&arg_node, arg_ast TSRMLS_CC);
    2723          87 :                         if (arg_node.op_type & (IS_VAR|IS_CV)) {
    2724           6 :                                 send_user = 1;
    2725             :                         }
    2726             :                 }
    2727             : 
    2728         348 :                 if (send_user) {
    2729         267 :                         opline = zend_emit_op(NULL, ZEND_SEND_USER, &arg_node, NULL TSRMLS_CC);
    2730             :                 } else {
    2731          81 :                         opline = zend_emit_op(NULL, ZEND_SEND_VAL, &arg_node, NULL TSRMLS_CC);
    2732             :                 }
    2733             : 
    2734         348 :                 opline->op2.opline_num = i;
    2735             :         }
    2736         127 :         zend_emit_op(result, ZEND_DO_FCALL, NULL, NULL TSRMLS_CC);
    2737             : 
    2738         127 :         return SUCCESS;
    2739             : }
    2740             : /* }}} */
    2741             : 
    2742      249856 : int zend_try_compile_special_func(znode *result, zend_string *lcname, zend_ast_list *args TSRMLS_DC) /* {{{ */
    2743             : {
    2744      249856 :         if (zend_string_equals_literal(lcname, "strlen")) {
    2745        4594 :                 return zend_compile_func_strlen(result, args TSRMLS_CC);
    2746      245262 :         } else if (zend_string_equals_literal(lcname, "is_null")) {
    2747         806 :                 return zend_compile_func_typecheck(result, args, IS_NULL TSRMLS_CC);
    2748      244456 :         } else if (zend_string_equals_literal(lcname, "is_bool")) {
    2749          22 :                 return zend_compile_func_typecheck(result, args, _IS_BOOL TSRMLS_CC);
    2750      813248 :         } else if (zend_string_equals_literal(lcname, "is_long")
    2751      315242 :                 || zend_string_equals_literal(lcname, "is_int")
    2752      253572 :                 || zend_string_equals_literal(lcname, "is_integer")
    2753             :         ) {
    2754         323 :                 return zend_compile_func_typecheck(result, args, IS_LONG TSRMLS_CC);
    2755      761322 :         } else if (zend_string_equals_literal(lcname, "is_float")
    2756      250192 :                 || zend_string_equals_literal(lcname, "is_double")
    2757      267019 :                 || zend_string_equals_literal(lcname, "is_real")
    2758             :         ) {
    2759          34 :                 return zend_compile_func_typecheck(result, args, IS_DOUBLE TSRMLS_CC);
    2760      244077 :         } else if (zend_string_equals_literal(lcname, "is_string")) {
    2761        1241 :                 return zend_compile_func_typecheck(result, args, IS_STRING TSRMLS_CC);
    2762      242836 :         } else if (zend_string_equals_literal(lcname, "is_array")) {
    2763         782 :                 return zend_compile_func_typecheck(result, args, IS_ARRAY TSRMLS_CC);
    2764      242054 :         } else if (zend_string_equals_literal(lcname, "is_object")) {
    2765         511 :                 return zend_compile_func_typecheck(result, args, IS_OBJECT TSRMLS_CC);
    2766      241543 :         } else if (zend_string_equals_literal(lcname, "is_resource")) {
    2767         148 :                 return zend_compile_func_typecheck(result, args, IS_RESOURCE TSRMLS_CC);
    2768      241395 :         } else if (zend_string_equals_literal(lcname, "defined")) {
    2769         172 :                 return zend_compile_func_defined(result, args TSRMLS_CC);
    2770      241223 :         } else if (zend_string_equals_literal(lcname, "call_user_func_array")) {
    2771          69 :                 return zend_compile_func_cufa(result, args, lcname TSRMLS_CC);
    2772      241154 :         } else if (zend_string_equals_literal(lcname, "call_user_func")) {
    2773         127 :                 return zend_compile_func_cuf(result, args, lcname TSRMLS_CC);
    2774             :         } else {
    2775      241027 :                 return FAILURE;
    2776             :         }
    2777             : }
    2778             : /* }}} */
    2779             : 
    2780      256067 : void zend_compile_call(znode *result, zend_ast *ast, uint32_t type TSRMLS_DC) /* {{{ */
    2781             : {
    2782      256067 :         zend_ast *name_ast = ast->child[0];
    2783      256067 :         zend_ast *args_ast = ast->child[1];
    2784             : 
    2785             :         znode name_node;
    2786             : 
    2787      510054 :         if (name_ast->kind != ZEND_AST_ZVAL || Z_TYPE_P(zend_ast_get_zval(name_ast)) != IS_STRING) {
    2788        2080 :                 zend_compile_expr(&name_node, name_ast TSRMLS_CC);
    2789        2080 :                 zend_compile_dynamic_call(result, &name_node, args_ast TSRMLS_CC);
    2790        2080 :                 return;
    2791             :         }
    2792             : 
    2793             :         {
    2794      253987 :                 zend_bool runtime_resolution = zend_compile_function_name(&name_node, name_ast TSRMLS_CC);
    2795      253987 :                 if (runtime_resolution) {
    2796         297 :                         zend_compile_ns_call(result, &name_node, args_ast TSRMLS_CC);
    2797         297 :                         return;
    2798             :                 }
    2799             :         }
    2800             : 
    2801             :         {
    2802      253690 :                 zval *name = &name_node.u.constant;
    2803      507380 :                 zend_string *lcname = zend_string_alloc(Z_STRLEN_P(name), 0);
    2804             :                 zend_function *fbc;
    2805             :                 zend_op *opline;
    2806             : 
    2807      253690 :                 zend_str_tolower_copy(lcname->val, Z_STRVAL_P(name), Z_STRLEN_P(name));
    2808             : 
    2809      507380 :                 fbc = zend_hash_find_ptr(CG(function_table), lcname);
    2810      496658 :                 if (!fbc || (fbc->type == ZEND_INTERNAL_FUNCTION &&
    2811      242968 :                         (CG(compiler_options) & ZEND_COMPILE_IGNORE_INTERNAL_FUNCTIONS))
    2812             :                 ) {
    2813             :                         zend_string_release(lcname);
    2814        3834 :                         zend_compile_dynamic_call(result, &name_node, args_ast TSRMLS_CC);
    2815        3834 :                         return;
    2816             :                 }
    2817             : 
    2818      249856 :                 if (zend_try_compile_special_func(result, lcname,
    2819             :                                 zend_ast_get_list(args_ast) TSRMLS_CC) == SUCCESS
    2820             :                 ) {
    2821             :                         zend_string_release(lcname);
    2822        8788 :                         zval_ptr_dtor(&name_node.u.constant);
    2823        8788 :                         return;
    2824             :                 }
    2825             : 
    2826      241068 :                 zval_ptr_dtor(&name_node.u.constant);
    2827      241068 :                 ZVAL_NEW_STR(&name_node.u.constant, lcname);
    2828             : 
    2829      241068 :                 opline = zend_emit_op(NULL, ZEND_INIT_FCALL, NULL, &name_node TSRMLS_CC);
    2830      241068 :                 zend_alloc_cache_slot(opline->op2.constant TSRMLS_CC);
    2831             : 
    2832      241068 :                 zend_compile_call_common(result, args_ast, fbc TSRMLS_CC);
    2833             :         }
    2834             : }
    2835             : /* }}} */
    2836             : 
    2837       34411 : void zend_compile_method_call(znode *result, zend_ast *ast, uint32_t type TSRMLS_DC) /* {{{ */
    2838             : {
    2839       34411 :         zend_ast *obj_ast = ast->child[0];
    2840       34411 :         zend_ast *method_ast = ast->child[1];
    2841       34411 :         zend_ast *args_ast = ast->child[2];
    2842             : 
    2843             :         znode obj_node, method_node;
    2844             :         zend_op *opline;
    2845             : 
    2846       34411 :         if (is_this_fetch(obj_ast)) {
    2847        1374 :                 obj_node.op_type = IS_UNUSED;
    2848             :         } else {
    2849       33037 :                 zend_compile_expr(&obj_node, obj_ast TSRMLS_CC);
    2850             :         }
    2851             : 
    2852       34411 :         zend_compile_expr(&method_node, method_ast TSRMLS_CC);
    2853       34411 :         opline = zend_emit_op(NULL, ZEND_INIT_METHOD_CALL, &obj_node, NULL TSRMLS_CC);
    2854             :         
    2855       34411 :         if (method_node.op_type == IS_CONST) {
    2856       34385 :                 if (Z_TYPE(method_node.u.constant) != IS_STRING) {
    2857           2 :                         zend_error_noreturn(E_COMPILE_ERROR, "Method name must be a string");
    2858             :                 }
    2859             : 
    2860       34383 :                 opline->op2_type = IS_CONST;
    2861       34383 :                 opline->op2.constant = zend_add_func_name_literal(CG(active_op_array),
    2862             :                         Z_STR(method_node.u.constant) TSRMLS_CC);
    2863       34383 :                 zend_alloc_polymorphic_cache_slot(opline->op2.constant TSRMLS_CC);
    2864             :         } else {
    2865          26 :                 SET_NODE(opline->op2, &method_node);
    2866             :         }
    2867             : 
    2868       34409 :         zend_compile_call_common(result, args_ast, NULL TSRMLS_CC);
    2869       34409 : }
    2870             : /* }}} */
    2871             : 
    2872       10165 : zend_bool zend_is_constructor(zend_string *name) /* {{{ */
    2873             : {
    2874       10165 :         return zend_string_equals_literal_ci(name, ZEND_CONSTRUCTOR_FUNC_NAME);
    2875             : }
    2876             : /* }}} */
    2877             : 
    2878       10199 : void zend_compile_static_call(znode *result, zend_ast *ast, uint32_t type TSRMLS_DC) /* {{{ */
    2879             : {
    2880       10199 :         zend_ast *class_ast = ast->child[0];
    2881       10199 :         zend_ast *method_ast = ast->child[1];
    2882       10199 :         zend_ast *args_ast = ast->child[2];
    2883             : 
    2884             :         znode class_node, method_node;
    2885             :         zend_op *opline;
    2886       10199 :         zend_ulong extended_value = 0;
    2887             : 
    2888       10199 :         if (zend_is_const_default_class_ref(class_ast)) {
    2889        5278 :                 class_node.op_type = IS_CONST;
    2890        5278 :                 ZVAL_STR(&class_node.u.constant, zend_resolve_class_name_ast(class_ast TSRMLS_CC));
    2891             :         } else {
    2892        4921 :                 opline = zend_compile_class_ref(&class_node, class_ast TSRMLS_CC);
    2893        4921 :                 extended_value = opline->extended_value;
    2894             :         }
    2895             : 
    2896       10199 :         zend_compile_expr(&method_node, method_ast TSRMLS_CC);
    2897       10199 :         if (method_node.op_type == IS_CONST) {
    2898       10165 :                 zval *name = &method_node.u.constant;
    2899       10165 :                 if (Z_TYPE_P(name) != IS_STRING) {
    2900           0 :                         zend_error_noreturn(E_COMPILE_ERROR, "Method name must be a string");
    2901             :                 }
    2902       10165 :                 if (zend_is_constructor(Z_STR_P(name))) {
    2903        1024 :                         zval_ptr_dtor(name);
    2904        1024 :                         method_node.op_type = IS_UNUSED;
    2905             :                 }
    2906             :         }
    2907             : 
    2908       10199 :         opline = get_next_op(CG(active_op_array) TSRMLS_CC);
    2909       10199 :         opline->opcode = ZEND_INIT_STATIC_METHOD_CALL;
    2910       10199 :         opline->extended_value = extended_value;
    2911             : 
    2912       10199 :         zend_set_class_name_op1(opline, &class_node TSRMLS_CC);
    2913             : 
    2914       10199 :         if (method_node.op_type == IS_CONST) {
    2915        9141 :                 opline->op2_type = IS_CONST;
    2916        9141 :                 opline->op2.constant = zend_add_func_name_literal(CG(active_op_array),
    2917             :                         Z_STR(method_node.u.constant) TSRMLS_CC);
    2918        9141 :                 if (opline->op1_type == IS_CONST) {
    2919        5264 :                         zend_alloc_cache_slot(opline->op2.constant TSRMLS_CC);
    2920             :                 } else {
    2921        3877 :                         zend_alloc_polymorphic_cache_slot(opline->op2.constant TSRMLS_CC);
    2922             :                 }
    2923             :         } else {
    2924        1058 :                 SET_NODE(opline->op2, &method_node);
    2925             :         }
    2926             : 
    2927       10199 :         zend_compile_call_common(result, args_ast, NULL TSRMLS_CC);
    2928       10199 : }
    2929             : /* }}} */
    2930             : 
    2931       14116 : void zend_compile_new(znode *result, zend_ast *ast TSRMLS_DC) /* {{{ */
    2932             : {
    2933       14116 :         zend_ast *class_ast = ast->child[0];
    2934       14116 :         zend_ast *args_ast = ast->child[1];
    2935             : 
    2936             :         znode class_node, ctor_result;
    2937             :         zend_op *opline;
    2938             :         uint32_t opnum;
    2939             : 
    2940       14116 :         if (zend_is_const_default_class_ref(class_ast)) {
    2941       12910 :                 class_node.op_type = IS_CONST;
    2942       12910 :                 ZVAL_STR(&class_node.u.constant, zend_resolve_class_name_ast(class_ast TSRMLS_CC));
    2943             :         } else {
    2944        1206 :                 zend_compile_class_ref(&class_node, class_ast TSRMLS_CC);
    2945             :         }
    2946             : 
    2947       14116 :         opnum = get_next_op_number(CG(active_op_array));
    2948       14116 :         opline = zend_emit_op(result, ZEND_NEW, NULL, NULL TSRMLS_CC);
    2949             : 
    2950       14116 :         if (class_node.op_type == IS_CONST) {
    2951       12910 :                 opline->op1_type = IS_CONST;
    2952       12910 :                 opline->op1.constant = zend_add_class_name_literal(
    2953             :                         CG(active_op_array), Z_STR(class_node.u.constant) TSRMLS_CC);
    2954             :         } else {
    2955        1206 :                 SET_NODE(opline->op1, &class_node);
    2956             :         }
    2957             : 
    2958       14116 :         zend_compile_call_common(&ctor_result, args_ast, NULL TSRMLS_CC);
    2959       14116 :         zend_do_free(&ctor_result TSRMLS_CC);
    2960             : 
    2961             :         /* New jumps over ctor call if ctor does not exist */
    2962       14116 :         opline = &CG(active_op_array)->opcodes[opnum];
    2963       14116 :         opline->op2.opline_num = get_next_op_number(CG(active_op_array));
    2964       14116 : }
    2965             : /* }}} */
    2966             : 
    2967         115 : void zend_compile_clone(znode *result, zend_ast *ast TSRMLS_DC) /* {{{ */
    2968             : {
    2969         115 :         zend_ast *obj_ast = ast->child[0];
    2970             : 
    2971             :         znode obj_node;
    2972         115 :         zend_compile_expr(&obj_node, obj_ast TSRMLS_CC);
    2973             : 
    2974         115 :         zend_emit_op(result, ZEND_CLONE, &obj_node, NULL TSRMLS_CC);
    2975         115 : }
    2976             : /* }}} */
    2977             : 
    2978        4580 : void zend_compile_global_var(zend_ast *ast TSRMLS_DC) /* {{{ */
    2979             : {
    2980        4580 :         zend_ast *var_ast = ast->child[0];
    2981        4580 :         zend_ast *name_ast = var_ast->child[0];
    2982             : 
    2983             :         znode name_node, result;
    2984             : 
    2985        4580 :         zend_compile_expr(&name_node, name_ast TSRMLS_CC);
    2986        4580 :         if (name_node.op_type == IS_CONST) {
    2987        4578 :                 if (Z_TYPE(name_node.u.constant) != IS_STRING) {
    2988           0 :                         convert_to_string(&name_node.u.constant);
    2989             :                 }
    2990             :         }
    2991             : 
    2992        4580 :         if (zend_try_compile_cv(&result, var_ast TSRMLS_CC) == SUCCESS) {
    2993        4578 :                 zend_op *opline = zend_emit_op(NULL, ZEND_BIND_GLOBAL, &result, &name_node TSRMLS_CC);
    2994        4578 :                 zend_alloc_cache_slot(opline->op2.constant TSRMLS_CC);
    2995             :         } else {
    2996           2 :                 zend_emit_op(&result, ZEND_FETCH_W, &name_node, NULL TSRMLS_CC);
    2997             : 
    2998             :                 // TODO.AST Avoid double fetch
    2999             :                 //opline->extended_value = ZEND_FETCH_GLOBAL_LOCK;
    3000             : 
    3001           2 :                 zend_emit_assign_ref_znode(var_ast, &result TSRMLS_CC);
    3002             :         }
    3003        4580 : }
    3004             : /* }}} */
    3005             : 
    3006        2023 : static void zend_compile_static_var_common(zend_ast *var_ast, zval *value, zend_bool by_ref TSRMLS_DC) /* {{{ */
    3007             : {
    3008             :         znode var_node, result;
    3009             :         zend_op *opline;
    3010             : 
    3011        2023 :         zend_compile_expr(&var_node, var_ast TSRMLS_CC);
    3012             : 
    3013        2023 :         if (!CG(active_op_array)->static_variables) {
    3014        1991 :                 if (CG(active_op_array)->scope) {
    3015         875 :                         CG(active_op_array)->scope->ce_flags |= ZEND_HAS_STATIC_IN_METHODS;
    3016             :                 }
    3017        1991 :                 ALLOC_HASHTABLE(CG(active_op_array)->static_variables);
    3018        1991 :                 zend_hash_init(CG(active_op_array)->static_variables, 8, NULL, ZVAL_PTR_DTOR, 0);
    3019             :         }
    3020             : 
    3021        2023 :         zend_hash_update(CG(active_op_array)->static_variables, Z_STR(var_node.u.constant), value);
    3022             : 
    3023        2023 :         opline = zend_emit_op(&result, by_ref ? ZEND_FETCH_W : ZEND_FETCH_R, &var_node, NULL TSRMLS_CC);
    3024        2023 :         opline->extended_value = ZEND_FETCH_STATIC;
    3025             : 
    3026        2023 :         if (by_ref) {
    3027        1910 :                 zend_ast *fetch_ast = zend_ast_create(ZEND_AST_VAR, var_ast);
    3028        1910 :                 zend_emit_assign_ref_znode(fetch_ast, &result TSRMLS_CC);
    3029             :         } else {
    3030         113 :                 zend_ast *fetch_ast = zend_ast_create(ZEND_AST_VAR, var_ast);
    3031         113 :                 zend_emit_assign_znode(fetch_ast, &result TSRMLS_CC);
    3032             :         }
    3033        2023 : }
    3034             : /* }}} */
    3035             : 
    3036        1883 : void zend_compile_static_var(zend_ast *ast TSRMLS_DC) /* {{{ */
    3037             : {
    3038        1883 :         zend_ast *var_ast = ast->child[0];
    3039        1883 :         zend_ast *value_ast = ast->child[1];
    3040             :         zval value_zv;
    3041             : 
    3042        1883 :         if (value_ast) {
    3043        1863 :                 zend_const_expr_to_zval(&value_zv, value_ast TSRMLS_CC);
    3044             :         } else {
    3045          20 :                 ZVAL_NULL(&value_zv);
    3046             :         }
    3047             : 
    3048        1883 :         zend_compile_static_var_common(var_ast, &value_zv, 1 TSRMLS_CC);
    3049        1883 : }
    3050             : /* }}} */
    3051             : 
    3052        1581 : void zend_compile_unset(zend_ast *ast TSRMLS_DC) /* {{{ */
    3053             : {
    3054        1581 :         zend_ast *var_ast = ast->child[0];
    3055             : 
    3056             :         znode var_node;
    3057             :         zend_op *opline;
    3058        1581 :         switch (var_ast->kind) {
    3059             :                 case ZEND_AST_VAR:
    3060        1273 :                         if (zend_try_compile_cv(&var_node, var_ast TSRMLS_CC) == SUCCESS) {
    3061        1263 :                                 opline = zend_emit_op(NULL, ZEND_UNSET_VAR, &var_node, NULL TSRMLS_CC);
    3062        1263 :                                 opline->extended_value = ZEND_FETCH_LOCAL | ZEND_QUICK_SET;
    3063             :                         } else {
    3064          10 :                                 opline = zend_compile_simple_var_no_cv(NULL, var_ast, BP_VAR_UNSET TSRMLS_CC);
    3065          10 :                                 opline->opcode = ZEND_UNSET_VAR;
    3066             :                         }
    3067        1273 :                         return;
    3068             :                 case ZEND_AST_DIM:
    3069         233 :                         opline = zend_compile_dim_common(NULL, var_ast, BP_VAR_UNSET TSRMLS_CC);
    3070         232 :                         opline->opcode = ZEND_UNSET_DIM;
    3071         232 :                         return;
    3072             :                 case ZEND_AST_PROP:
    3073          74 :                         opline = zend_compile_prop_common(NULL, var_ast, BP_VAR_UNSET TSRMLS_CC);
    3074          74 :                         opline->opcode = ZEND_UNSET_OBJ;
    3075          74 :                         return;
    3076             :                 case ZEND_AST_STATIC_PROP:
    3077           1 :                         opline = zend_compile_static_prop_common(NULL, var_ast, BP_VAR_UNSET TSRMLS_CC);
    3078           1 :                         opline->opcode = ZEND_UNSET_VAR;
    3079           1 :                         return;
    3080             :                 EMPTY_SWITCH_DEFAULT_CASE()
    3081             :         }
    3082             : }
    3083             : /* }}} */
    3084             : 
    3085       43566 : static void zend_free_foreach_and_switch_variables(TSRMLS_D) /* {{{ */
    3086             : {
    3087             :         uint32_t opnum_start, opnum_end, i;
    3088             : 
    3089       43566 :         opnum_start = get_next_op_number(CG(active_op_array));
    3090             : 
    3091             : #ifdef ZTS
    3092             :         zend_stack_apply_with_argument(&CG(loop_var_stack), ZEND_STACK_APPLY_TOPDOWN, (int (*)(void *element, void *)) generate_free_loop_var TSRMLS_CC);
    3093             : #else
    3094       43566 :         zend_stack_apply(&CG(loop_var_stack), ZEND_STACK_APPLY_TOPDOWN, (int (*)(void *element)) generate_free_loop_var);
    3095             : #endif
    3096             : 
    3097       43566 :         opnum_end = get_next_op_number(CG(active_op_array));
    3098             : 
    3099       44079 :         for (i = opnum_start; i < opnum_end; ++i) {
    3100         513 :                 CG(active_op_array)->opcodes[i].extended_value |= EXT_TYPE_FREE_ON_RETURN;
    3101             :         }
    3102       43566 : }
    3103             : /* }}} */
    3104             : 
    3105       43567 : void zend_compile_return(zend_ast *ast TSRMLS_DC) /* {{{ */
    3106             : {
    3107       43567 :         zend_ast *expr_ast = ast->child[0];
    3108       43567 :         zend_bool by_ref = (CG(active_op_array)->fn_flags & ZEND_ACC_RETURN_REFERENCE) != 0;
    3109             : 
    3110             :         znode expr_node;
    3111             :         zend_op *opline;
    3112             : 
    3113       43567 :         if (!expr_ast) {
    3114         210 :                 expr_node.op_type = IS_CONST;
    3115         210 :                 ZVAL_NULL(&expr_node.u.constant);
    3116       43396 :         } else if (by_ref && zend_is_variable(expr_ast) && !zend_is_call(expr_ast)) {
    3117          39 :                 zend_compile_var(&expr_node, expr_ast, BP_VAR_REF TSRMLS_CC);
    3118             :         } else {
    3119       43318 :                 zend_compile_expr(&expr_node, expr_ast TSRMLS_CC);
    3120             :         }
    3121             : 
    3122       43566 :         zend_free_foreach_and_switch_variables(TSRMLS_C);
    3123             : 
    3124       43566 :         if (CG(context).in_finally) {
    3125           7 :                 zend_emit_op(NULL, ZEND_DISCARD_EXCEPTION, NULL, NULL TSRMLS_CC);
    3126             :         }
    3127             : 
    3128       43566 :         opline = zend_emit_op(NULL, by_ref ? ZEND_RETURN_BY_REF : ZEND_RETURN,
    3129             :                 &expr_node, NULL TSRMLS_CC);
    3130             : 
    3131       43566 :         if (expr_ast) {
    3132       43356 :                 if (zend_is_call(expr_ast)) {
    3133        8342 :                         opline->extended_value = ZEND_RETURNS_FUNCTION;
    3134       35014 :                 } else if (by_ref && !zend_is_variable(expr_ast)) {
    3135          10 :                         opline->extended_value = ZEND_RETURNS_VALUE;
    3136             :                 }
    3137             :         }
    3138       43566 : }
    3139             : /* }}} */
    3140             : 
    3141       33840 : void zend_compile_echo(zend_ast *ast TSRMLS_DC) /* {{{ */
    3142             : {
    3143       33840 :         zend_ast *expr_ast = ast->child[0];
    3144             : 
    3145             :         znode expr_node;
    3146       33840 :         zend_compile_expr(&expr_node, expr_ast TSRMLS_CC);
    3147             : 
    3148       33840 :         zend_emit_op(NULL, ZEND_ECHO, &expr_node, NULL TSRMLS_CC);
    3149       33840 : }
    3150             : /* }}} */
    3151             : 
    3152         317 : void zend_compile_throw(zend_ast *ast TSRMLS_DC) /* {{{ */
    3153             : {
    3154         317 :         zend_ast *expr_ast = ast->child[0];
    3155             : 
    3156             :         znode expr_node;
    3157         317 :         zend_compile_expr(&expr_node, expr_ast TSRMLS_CC);
    3158             : 
    3159         317 :         zend_emit_op(NULL, ZEND_THROW, &expr_node, NULL TSRMLS_CC);
    3160         317 : }
    3161             : /* }}} */
    3162             : 
    3163        2088 : void zend_compile_break_continue(zend_ast *ast TSRMLS_DC) /* {{{ */
    3164             : {
    3165        2088 :         zend_ast *depth_ast = ast->child[0];
    3166             : 
    3167             :         znode depth_node;
    3168             :         zend_op *opline;
    3169             : 
    3170             :         ZEND_ASSERT(ast->kind == ZEND_AST_BREAK || ast->kind == ZEND_AST_CONTINUE);
    3171             : 
    3172        2088 :         if (depth_ast) {
    3173          16 :                 if (depth_ast->kind != ZEND_AST_ZVAL) {
    3174           0 :                         zend_error_noreturn(E_COMPILE_ERROR, "'%s' operator with non-constant operand "
    3175           0 :                                 "is no longer supported", ast->kind == ZEND_AST_BREAK ? "break" : "continue");
    3176             :                 }
    3177             : 
    3178          16 :                 zend_compile_expr(&depth_node, depth_ast TSRMLS_CC);
    3179             : 
    3180          16 :                 if (Z_TYPE(depth_node.u.constant) != IS_LONG || Z_LVAL(depth_node.u.constant) < 1) {
    3181           0 :                         zend_error_noreturn(E_COMPILE_ERROR, "'%s' operator accepts only positive numbers",
    3182           0 :                                 ast->kind == ZEND_AST_BREAK ? "break" : "continue");
    3183             :                 }
    3184             :         } else {
    3185        2072 :                 depth_node.op_type = IS_CONST;
    3186        2072 :                 ZVAL_LONG(&depth_node.u.constant, 1);
    3187             :         }
    3188             : 
    3189        2088 :         opline = zend_emit_op(NULL, ast->kind == ZEND_AST_BREAK ? ZEND_BRK : ZEND_CONT,
    3190             :                 NULL, &depth_node TSRMLS_CC);
    3191        2088 :         opline->op1.opline_num = CG(context).current_brk_cont;
    3192        2088 : }
    3193             : /* }}} */
    3194             : 
    3195          35 : void zend_compile_goto(zend_ast *ast TSRMLS_DC) /* {{{ */
    3196             : {
    3197          35 :         zend_ast *label_ast = ast->child[0];
    3198             :         znode label_node;
    3199             :         zend_op *opline;
    3200             : 
    3201          35 :         zend_compile_expr(&label_node, label_ast TSRMLS_CC);
    3202          35 :         opline = zend_emit_op(NULL, ZEND_GOTO, NULL, &label_node TSRMLS_CC);
    3203          35 :         opline->extended_value = CG(context).current_brk_cont;
    3204          35 :         zend_resolve_goto_label(CG(active_op_array), opline, 0 TSRMLS_CC);
    3205          33 : }
    3206             : /* }}} */
    3207             : 
    3208          37 : void zend_compile_label(zend_ast *ast TSRMLS_DC) /* {{{ */
    3209             : {
    3210          74 :         zend_string *label = zend_ast_get_str(ast->child[0]);
    3211             :         zend_label dest;
    3212             : 
    3213          37 :         if (!CG(context).labels) {
    3214          24 :                 ALLOC_HASHTABLE(CG(context).labels);
    3215          24 :                 zend_hash_init(CG(context).labels, 8, NULL, ptr_dtor, 0);
    3216             :         }
    3217             : 
    3218          37 :         dest.brk_cont = CG(context).current_brk_cont;
    3219          37 :         dest.opline_num = get_next_op_number(CG(active_op_array));
    3220             : 
    3221          74 :         if (!zend_hash_add_mem(CG(context).labels, label, &dest, sizeof(zend_label))) {
    3222           1 :                 zend_error_noreturn(E_COMPILE_ERROR, "Label '%s' already defined", label->val);
    3223             :         }
    3224          36 : }
    3225             : /* }}} */
    3226             : 
    3227        1870 : void zend_compile_while(zend_ast *ast TSRMLS_DC) /* {{{ */
    3228             : {
    3229        1870 :         zend_ast *cond_ast = ast->child[0];
    3230        1870 :         zend_ast *stmt_ast = ast->child[1];
    3231             : 
    3232             :         znode cond_node;
    3233             :         uint32_t opnum_start, opnum_jmpz;
    3234             : 
    3235        1870 :         opnum_start = get_next_op_number(CG(active_op_array));
    3236        1870 :         zend_compile_expr(&cond_node, cond_ast TSRMLS_CC);
    3237             : 
    3238        1870 :         opnum_jmpz = zend_emit_cond_jump(ZEND_JMPZ, &cond_node, 0 TSRMLS_CC);
    3239        1870 :         zend_begin_loop(TSRMLS_C);
    3240             : 
    3241        1870 :         zend_compile_stmt(stmt_ast TSRMLS_CC);
    3242             : 
    3243        1870 :         zend_emit_jump(opnum_start TSRMLS_CC);
    3244             : 
    3245        1870 :         zend_update_jump_target_to_next(opnum_jmpz TSRMLS_CC);
    3246             : 
    3247        1870 :         zend_end_loop(opnum_start, 0 TSRMLS_CC);
    3248        1870 : }
    3249             : /* }}} */
    3250             : 
    3251         289 : void zend_compile_do_while(zend_ast *ast TSRMLS_DC) /* {{{ */
    3252             : {
    3253         289 :         zend_ast *stmt_ast = ast->child[0];
    3254         289 :         zend_ast *cond_ast = ast->child[1];
    3255             : 
    3256             :         znode cond_node;
    3257             :         uint32_t opnum_start, opnum_cond;
    3258             : 
    3259         289 :         zend_begin_loop(TSRMLS_C);
    3260             : 
    3261         289 :         opnum_start = get_next_op_number(CG(active_op_array));
    3262         289 :         zend_compile_stmt(stmt_ast TSRMLS_CC);
    3263             : 
    3264         289 :         opnum_cond = get_next_op_number(CG(active_op_array));
    3265         289 :         zend_compile_expr(&cond_node, cond_ast TSRMLS_CC);
    3266             : 
    3267         289 :         zend_emit_cond_jump(ZEND_JMPNZ, &cond_node, opnum_start TSRMLS_CC);
    3268             : 
    3269         289 :         zend_end_loop(opnum_cond, 0 TSRMLS_CC);
    3270         289 : }
    3271             : /* }}} */
    3272             : 
    3273        5607 : void zend_compile_expr_list(znode *result, zend_ast *ast TSRMLS_DC) /* {{{ */
    3274             : {
    3275             :         zend_ast_list *list;
    3276             :         uint32_t i;
    3277             : 
    3278        5607 :         result->op_type = IS_CONST;
    3279        5607 :         ZVAL_TRUE(&result->u.constant);
    3280             : 
    3281        5607 :         if (!ast) {
    3282           7 :                 return;
    3283             :         }
    3284             : 
    3285        5600 :         list = zend_ast_get_list(ast);
    3286       11205 :         for (i = 0; i < list->children; ++i) {
    3287        5605 :                 zend_ast *expr_ast = list->child[i];
    3288             : 
    3289        5605 :                 zend_do_free(result TSRMLS_CC);
    3290        5605 :                 zend_compile_expr(result, expr_ast TSRMLS_CC);
    3291             :         }
    3292             : }
    3293             : /* }}} */
    3294             : 
    3295        1869 : void zend_compile_for(zend_ast *ast TSRMLS_DC) /* {{{ */
    3296             : {
    3297        1869 :         zend_ast *init_ast = ast->child[0];
    3298        1869 :         zend_ast *cond_ast = ast->child[1];
    3299        1869 :         zend_ast *loop_ast = ast->child[2];
    3300        1869 :         zend_ast *stmt_ast = ast->child[3];
    3301             : 
    3302             :         znode result;
    3303             :         uint32_t opnum_cond, opnum_jmpz, opnum_loop;
    3304             : 
    3305        1869 :         zend_compile_expr_list(&result, init_ast TSRMLS_CC);
    3306        1869 :         zend_do_free(&result TSRMLS_CC);
    3307             : 
    3308        1869 :         opnum_cond = get_next_op_number(CG(active_op_array));
    3309        1869 :         zend_compile_expr_list(&result, cond_ast TSRMLS_CC);
    3310        1869 :         zend_do_extended_info(TSRMLS_C);
    3311             : 
    3312        1869 :         opnum_jmpz = zend_emit_cond_jump(ZEND_JMPZ, &result, 0 TSRMLS_CC);
    3313        1869 :         zend_begin_loop(TSRMLS_C);
    3314             : 
    3315        1869 :         zend_compile_stmt(stmt_ast TSRMLS_CC);
    3316             : 
    3317        1869 :         opnum_loop = get_next_op_number(CG(active_op_array));
    3318        1869 :         zend_compile_expr_list(&result, loop_ast TSRMLS_CC);
    3319        1869 :         zend_do_free(&result TSRMLS_CC);
    3320             : 
    3321        1869 :         zend_emit_jump(opnum_cond TSRMLS_CC);
    3322             : 
    3323        1869 :         zend_update_jump_target_to_next(opnum_jmpz TSRMLS_CC);
    3324             : 
    3325        1869 :         zend_end_loop(opnum_loop, 0 TSRMLS_CC);
    3326        1869 : }
    3327             : /* }}} */
    3328             : 
    3329        9738 : void zend_compile_foreach(zend_ast *ast TSRMLS_DC) /* {{{ */
    3330             : {
    3331        9738 :         zend_ast *expr_ast = ast->child[0];
    3332        9738 :         zend_ast *value_ast = ast->child[1];
    3333        9738 :         zend_ast *key_ast = ast->child[2];
    3334        9738 :         zend_ast *stmt_ast = ast->child[3];
    3335        9738 :         zend_bool by_ref = value_ast->kind == ZEND_AST_REF;
    3336       17783 :         zend_bool is_variable = zend_is_variable(expr_ast) && !zend_is_call(expr_ast)
    3337       17783 :                 && zend_can_write_to_variable(expr_ast);
    3338             : 
    3339             :         znode expr_node, reset_node, value_node, key_node;
    3340             :         zend_op *opline;
    3341             :         uint32_t opnum_reset, opnum_fetch;
    3342             : 
    3343        9738 :         if (key_ast) {
    3344        4638 :                 if (key_ast->kind == ZEND_AST_REF) {
    3345           2 :                         zend_error_noreturn(E_COMPILE_ERROR, "Key element cannot be a reference");
    3346             :                 }
    3347        4636 :                 if (key_ast->kind == ZEND_AST_LIST) {
    3348           1 :                         zend_error_noreturn(E_COMPILE_ERROR, "Cannot use list as key element");
    3349             :                 }
    3350             :         }
    3351             : 
    3352        9735 :         if (by_ref) {
    3353          77 :                 value_ast = value_ast->child[0];
    3354             :         }
    3355             : 
    3356        9808 :         if (by_ref && is_variable) {
    3357          73 :                 zend_compile_var(&expr_node, expr_ast, BP_VAR_W TSRMLS_CC);
    3358             :         } else {
    3359        9662 :                 zend_compile_expr(&expr_node, expr_ast TSRMLS_CC);
    3360             :         }
    3361             : 
    3362        9732 :         if (by_ref) {
    3363          77 :                 zend_separate_if_call_and_write(&expr_node, expr_ast, BP_VAR_W TSRMLS_CC);
    3364             :         }
    3365             : 
    3366        9732 :         opnum_reset = get_next_op_number(CG(active_op_array));
    3367        9732 :         opline = zend_emit_op(&reset_node, ZEND_FE_RESET, &expr_node, NULL TSRMLS_CC);
    3368        9732 :         if (by_ref && is_variable) {
    3369          73 :                 opline->extended_value = ZEND_FE_FETCH_BYREF;
    3370             :         }
    3371             : 
    3372        9732 :         zend_stack_push(&CG(loop_var_stack), &reset_node);
    3373             : 
    3374        9732 :         opnum_fetch = get_next_op_number(CG(active_op_array));
    3375        9732 :         opline = zend_emit_op(&value_node, ZEND_FE_FETCH, &reset_node, NULL TSRMLS_CC);
    3376        9732 :         if (by_ref) {
    3377          77 :                 opline->extended_value |= ZEND_FE_FETCH_BYREF;
    3378             :         }
    3379        9732 :         if (key_ast) {
    3380        4635 :                 opline->extended_value |= ZEND_FE_FETCH_WITH_KEY;
    3381             :         }
    3382             : 
    3383        9732 :         opline = zend_emit_op(NULL, ZEND_OP_DATA, NULL, NULL TSRMLS_CC);
    3384             : 
    3385             :         /* Allocate enough space to keep HashPointer on VM stack */
    3386        9732 :         opline->op1_type = IS_TMP_VAR;
    3387        9732 :         opline->op1.var = get_temporary_variable(CG(active_op_array));
    3388             :         if (sizeof(HashPointer) > sizeof(zval)) {
    3389             :                 /* Make sure 1 zval is enough for HashPointer (2 must be enough) */
    3390        9732 :                 get_temporary_variable(CG(active_op_array));
    3391             :         }
    3392             : 
    3393        9732 :         if (key_ast) {
    3394        4635 :                 zend_make_tmp_result(&key_node, opline TSRMLS_CC);
    3395             :         }
    3396             : 
    3397        9732 :         if (by_ref) {
    3398          77 :                 zend_emit_assign_ref_znode(value_ast, &value_node TSRMLS_CC);
    3399             :         } else {
    3400        9655 :                 zend_emit_assign_znode(value_ast, &value_node TSRMLS_CC);
    3401             :         }
    3402             : 
    3403        9731 :         if (key_ast) {
    3404        4634 :                 zend_emit_assign_znode(key_ast, &key_node TSRMLS_CC);
    3405             :         }
    3406             : 
    3407        9731 :         zend_begin_loop(TSRMLS_C);
    3408             : 
    3409        9731 :         zend_compile_stmt(stmt_ast TSRMLS_CC);
    3410             : 
    3411        9731 :         zend_emit_jump(opnum_fetch TSRMLS_CC);
    3412             : 
    3413        9731 :         opline = &CG(active_op_array)->opcodes[opnum_reset];
    3414        9731 :         opline->op2.opline_num = get_next_op_number(CG(active_op_array));
    3415             : 
    3416        9731 :         opline = &CG(active_op_array)->opcodes[opnum_fetch];
    3417        9731 :         opline->op2.opline_num = get_next_op_number(CG(active_op_array));
    3418             : 
    3419        9731 :         zend_end_loop(opnum_fetch, 1 TSRMLS_CC);
    3420             : 
    3421        9731 :         generate_free_loop_var(&reset_node TSRMLS_CC);
    3422        9731 :         zend_stack_del_top(&CG(loop_var_stack));
    3423        9731 : }
    3424             : /* }}} */
    3425             : 
    3426       68256 : void zend_compile_if(zend_ast *ast TSRMLS_DC) /* {{{ */
    3427             : {
    3428       68256 :         zend_ast_list *list = zend_ast_get_list(ast);
    3429             :         uint32_t i;
    3430             :         uint32_t *jmp_opnums;
    3431             :         
    3432       68256 :         if (list->children > 1) {
    3433       17820 :                 jmp_opnums = safe_emalloc(sizeof(uint32_t), list->children - 1, 0);
    3434             :         }
    3435             : 
    3436      155153 :         for (i = 0; i < list->children; ++i) {
    3437       86897 :                 zend_ast *elem_ast = list->child[i];
    3438       86897 :                 zend_ast *cond_ast = elem_ast->child[0];
    3439       86897 :                 zend_ast *stmt_ast = elem_ast->child[1];
    3440             : 
    3441             :                 znode cond_node;
    3442             :                 uint32_t opnum_jmpz;
    3443       86897 :                 if (cond_ast) {
    3444       69957 :                         zend_compile_expr(&cond_node, cond_ast TSRMLS_CC);
    3445       69957 :                         opnum_jmpz = zend_emit_cond_jump(ZEND_JMPZ, &cond_node, 0 TSRMLS_CC);
    3446             :                 }
    3447             : 
    3448       86897 :                 zend_compile_stmt(stmt_ast TSRMLS_CC);
    3449             : 
    3450       86897 :                 if (i != list->children - 1) {
    3451       18641 :                         jmp_opnums[i] = zend_emit_jump(0 TSRMLS_CC);
    3452             :                 }
    3453             : 
    3454       86897 :                 if (cond_ast) {
    3455       69957 :                         zend_update_jump_target_to_next(opnum_jmpz TSRMLS_CC);
    3456             :                 }
    3457             :         }
    3458             : 
    3459       68256 :         if (list->children > 1) {
    3460       36461 :                 for (i = 0; i < list->children - 1; ++i) {
    3461       18641 :                         zend_update_jump_target_to_next(jmp_opnums[i] TSRMLS_CC);
    3462             :                 }
    3463       17820 :                 efree(jmp_opnums);
    3464             :         }
    3465       68256 : }
    3466             : /* }}} */
    3467             : 
    3468         449 : void zend_compile_switch(zend_ast *ast TSRMLS_DC) /* {{{ */
    3469             : {
    3470         449 :         zend_ast *expr_ast = ast->child[0];
    3471         898 :         zend_ast_list *cases = zend_ast_get_list(ast->child[1]);
    3472             : 
    3473             :         uint32_t i;
    3474         449 :         zend_bool has_default_case = 0;
    3475             : 
    3476             :         znode expr_node, case_node;
    3477             :         zend_op *opline;
    3478         449 :         uint32_t *jmpnz_opnums = safe_emalloc(sizeof(uint32_t), cases->children, 0);
    3479             :         uint32_t opnum_default_jmp;
    3480             : 
    3481         449 :         zend_compile_expr(&expr_node, expr_ast TSRMLS_CC);
    3482             : 
    3483         449 :         zend_stack_push(&CG(loop_var_stack), &expr_node);
    3484             : 
    3485         449 :         zend_begin_loop(TSRMLS_C);
    3486             : 
    3487         449 :         case_node.op_type = IS_TMP_VAR;
    3488         449 :         case_node.u.op.var = get_temporary_variable(CG(active_op_array));
    3489             : 
    3490        2301 :         for (i = 0; i < cases->children; ++i) {
    3491        1853 :                 zend_ast *case_ast = cases->child[i];
    3492        1853 :                 zend_ast *cond_ast = case_ast->child[0];
    3493             :                 znode cond_node;
    3494             : 
    3495        1853 :                 if (!cond_ast) {
    3496         266 :                         if (has_default_case) {
    3497           1 :                                 CG(zend_lineno) = case_ast->lineno;
    3498           1 :                                 zend_error_noreturn(E_COMPILE_ERROR,
    3499             :                                         "Switch statements may only contain one default clause");
    3500             :                         }
    3501         265 :                         has_default_case = 1;
    3502         265 :                         continue;
    3503             :                 }
    3504             : 
    3505        1587 :                 zend_compile_expr(&cond_node, cond_ast TSRMLS_CC);
    3506             : 
    3507        1587 :                 opline = zend_emit_op(NULL, ZEND_CASE, &expr_node, &cond_node TSRMLS_CC);
    3508        1587 :                 SET_NODE(opline->result, &case_node);
    3509        1587 :                 if (opline->op1_type == IS_CONST) {
    3510          14 :                         zval_copy_ctor(&CONSTANT(opline->op1.constant));
    3511             :                 }
    3512             : 
    3513        1587 :                 jmpnz_opnums[i] = zend_emit_cond_jump(ZEND_JMPNZ, &case_node, 0 TSRMLS_CC);
    3514             :         }
    3515             : 
    3516         448 :         opnum_default_jmp = zend_emit_jump(0 TSRMLS_CC);
    3517             : 
    3518        2297 :         for (i = 0; i < cases->children; ++i) {
    3519        1849 :                 zend_ast *case_ast = cases->child[i];
    3520        1849 :                 zend_ast *cond_ast = case_ast->child[0];
    3521        1849 :                 zend_ast *stmt_ast = case_ast->child[1];
    3522             : 
    3523        1849 :                 if (cond_ast) {
    3524        1585 :                         zend_update_jump_target_to_next(jmpnz_opnums[i] TSRMLS_CC);
    3525             :                 } else {
    3526         264 :                         zend_update_jump_target_to_next(opnum_default_jmp TSRMLS_CC);
    3527             :                 }
    3528             : 
    3529        1849 :                 zend_compile_stmt(stmt_ast TSRMLS_CC);
    3530             :         }
    3531             : 
    3532         448 :         if (!has_default_case) {
    3533         184 :                 zend_update_jump_target_to_next(opnum_default_jmp TSRMLS_CC);
    3534             :         }
    3535             : 
    3536         448 :         zend_end_loop(get_next_op_number(CG(active_op_array)), 1 TSRMLS_CC);
    3537             : 
    3538         554 :         if (expr_node.op_type == IS_VAR || expr_node.op_type == IS_TMP_VAR) {
    3539         106 :                 zend_emit_op(NULL, ZEND_FREE,
    3540             :                         &expr_node, NULL TSRMLS_CC);
    3541         342 :         } else if (expr_node.op_type == IS_CONST) {
    3542             :                 zval_dtor(&expr_node.u.constant);
    3543             :         }
    3544             : 
    3545         448 :         zend_stack_del_top(&CG(loop_var_stack));
    3546         448 :         efree(jmpnz_opnums);
    3547         448 : }
    3548             : /* }}} */
    3549             : 
    3550        1990 : void zend_compile_try(zend_ast *ast TSRMLS_DC) /* {{{ */
    3551             : {
    3552        1990 :         zend_ast *try_ast = ast->child[0];
    3553        3980 :         zend_ast_list *catches = zend_ast_get_list(ast->child[1]);
    3554        1990 :         zend_ast *finally_ast = ast->child[2];
    3555             : 
    3556             :         uint32_t i;
    3557             :         zend_op *opline;
    3558        1990 :         uint32_t try_catch_offset = zend_add_try_element(
    3559        3980 :                 get_next_op_number(CG(active_op_array)) TSRMLS_CC);
    3560        1990 :         uint32_t *jmp_opnums = safe_emalloc(sizeof(uint32_t), catches->children, 0);
    3561             : 
    3562        1990 :         if (catches->children == 0 && !finally_ast) {
    3563           1 :                 zend_error_noreturn(E_COMPILE_ERROR, "Cannot use try without catch or finally");
    3564             :         }
    3565             : 
    3566        1989 :         zend_compile_stmt(try_ast TSRMLS_CC);
    3567             : 
    3568        1989 :         if (catches->children != 0) {
    3569        1945 :                 jmp_opnums[0] = zend_emit_jump(0 TSRMLS_CC);
    3570             :         }
    3571             : 
    3572        3945 :         for (i = 0; i < catches->children; ++i) {
    3573        1956 :                 zend_ast *catch_ast = catches->child[i];
    3574        1956 :                 zend_ast *class_ast = catch_ast->child[0];
    3575        1956 :                 zend_ast *var_ast = catch_ast->child[1];
    3576        1956 :                 zend_ast *stmt_ast = catch_ast->child[2];
    3577        1956 :                 zval *var_name = zend_ast_get_zval(var_ast);
    3578        1956 :                 zend_bool is_last_catch = (i + 1 == catches->children);
    3579             : 
    3580             :                 uint32_t opnum_catch;
    3581             : 
    3582        1956 :                 if (!zend_is_const_default_class_ref(class_ast)) {
    3583           0 :                         zend_error_noreturn(E_COMPILE_ERROR, "Bad class name in the catch statement");
    3584             :                 }
    3585             : 
    3586        1956 :                 opnum_catch = get_next_op_number(CG(active_op_array));
    3587        1956 :                 if (i == 0) {
    3588        1945 :                         CG(active_op_array)->try_catch_array[try_catch_offset].catch_op = opnum_catch;
    3589             :                 }
    3590             : 
    3591        1956 :                 CG(zend_lineno) = catch_ast->lineno;
    3592             : 
    3593        1956 :                 opline = get_next_op(CG(active_op_array) TSRMLS_CC);
    3594        1956 :                 opline->opcode = ZEND_CATCH;
    3595        1956 :                 opline->op1_type = IS_CONST;
    3596        1956 :                 opline->op1.constant = zend_add_class_name_literal(CG(active_op_array),
    3597             :                         zend_resolve_class_name_ast(class_ast TSRMLS_CC) TSRMLS_CC);
    3598             : 
    3599        1956 :                 opline->op2_type = IS_CV;
    3600        3912 :                 opline->op2.var = lookup_cv(CG(active_op_array), zend_string_copy(Z_STR_P(var_name)) TSRMLS_CC);
    3601        1956 :                 opline->result.num = is_last_catch;
    3602             : 
    3603        1956 :                 zend_compile_stmt(stmt_ast TSRMLS_CC);
    3604             : 
    3605        1956 :                 if (!is_last_catch) {
    3606          11 :                         jmp_opnums[i + 1] = zend_emit_jump(0 TSRMLS_CC);
    3607             :                 }
    3608             : 
    3609        1956 :                 opline = &CG(active_op_array)->opcodes[opnum_catch];
    3610        1956 :                 opline->extended_value = get_next_op_number(CG(active_op_array));
    3611             :         }
    3612             : 
    3613        3945 :         for (i = 0; i < catches->children; ++i) {
    3614        1956 :                 zend_update_jump_target_to_next(jmp_opnums[i] TSRMLS_CC);
    3615             :         }
    3616             : 
    3617        1989 :         if (finally_ast) {
    3618          70 :                 uint32_t opnum_jmp = get_next_op_number(CG(active_op_array)) + 1;
    3619             : 
    3620          70 :                 opline = zend_emit_op(NULL, ZEND_FAST_CALL, NULL, NULL TSRMLS_CC);
    3621          70 :                 opline->op1.opline_num = opnum_jmp + 1;
    3622             : 
    3623          70 :                 zend_emit_op(NULL, ZEND_JMP, NULL, NULL TSRMLS_CC);
    3624             : 
    3625          70 :                 CG(context).in_finally++;
    3626          70 :                 zend_compile_stmt(finally_ast TSRMLS_CC);
    3627          70 :                 CG(context).in_finally--;
    3628             : 
    3629          70 :                 CG(active_op_array)->try_catch_array[try_catch_offset].finally_op = opnum_jmp + 1;
    3630         140 :                 CG(active_op_array)->try_catch_array[try_catch_offset].finally_end
    3631          70 :                         = get_next_op_number(CG(active_op_array));
    3632          70 :                 CG(active_op_array)->fn_flags |= ZEND_ACC_HAS_FINALLY_BLOCK;
    3633             : 
    3634          70 :                 zend_emit_op(NULL, ZEND_FAST_RET, NULL, NULL TSRMLS_CC);
    3635             : 
    3636          70 :                 zend_update_jump_target_to_next(opnum_jmp TSRMLS_CC);
    3637             :         }
    3638             : 
    3639        1989 :         efree(jmp_opnums);
    3640        1989 : }
    3641             : /* }}} */
    3642             : 
    3643             : /* Encoding declarations must already be handled during parsing */
    3644          25 : void zend_handle_encoding_declaration(zend_ast *ast TSRMLS_DC) /* {{{ */
    3645             : {
    3646          25 :         zend_ast_list *declares = zend_ast_get_list(ast);
    3647             :         uint32_t i;
    3648          48 :         for (i = 0; i < declares->children; ++i) {
    3649          25 :                 zend_ast *declare_ast = declares->child[i];
    3650          25 :                 zend_ast *name_ast = declare_ast->child[0];
    3651          25 :                 zend_ast *value_ast = declare_ast->child[1];
    3652          25 :                 zend_string *name = zend_ast_get_str(name_ast);
    3653             : 
    3654          25 :                 if (zend_string_equals_literal_ci(name, "encoding")) {
    3655          19 :                         if (value_ast->kind != ZEND_AST_ZVAL) {
    3656           2 :                                 zend_error_noreturn(E_COMPILE_ERROR, "Encoding must be a literal");
    3657             :                         }
    3658             : 
    3659          17 :                         if (CG(multibyte)) {
    3660          17 :                                 zend_string *encoding_name = zval_get_string(zend_ast_get_zval(value_ast));
    3661             : 
    3662             :                                 const zend_encoding *new_encoding, *old_encoding;
    3663             :                                 zend_encoding_filter old_input_filter;
    3664             : 
    3665          17 :                                 CG(encoding_declared) = 1;
    3666             : 
    3667          17 :                                 new_encoding = zend_multibyte_fetch_encoding(encoding_name->val TSRMLS_CC);
    3668          17 :                                 if (!new_encoding) {
    3669           4 :                                         zend_error(E_COMPILE_WARNING, "Unsupported encoding [%s]", encoding_name->val);
    3670             :                                 } else {
    3671          13 :                                         old_input_filter = LANG_SCNG(input_filter);
    3672          13 :                                         old_encoding = LANG_SCNG(script_encoding);
    3673          13 :                                         zend_multibyte_set_filter(new_encoding TSRMLS_CC);
    3674             : 
    3675             :                                         /* need to re-scan if input filter changed */
    3676          13 :                                         if (old_input_filter != LANG_SCNG(input_filter) ||
    3677             :                                                  (old_input_filter && new_encoding != old_encoding)) {
    3678          10 :                                                 zend_multibyte_yyinput_again(old_input_filter, old_encoding TSRMLS_CC);
    3679             :                                         }
    3680             :                                 }
    3681             : 
    3682             :                                 zend_string_release(encoding_name);
    3683             :                         } else {
    3684           0 :                                 zend_error(E_COMPILE_WARNING, "declare(encoding=...) ignored because "
    3685             :                                         "Zend multibyte feature is turned off by settings");
    3686             :                         }
    3687             :                 }
    3688             :         }
    3689          23 : }
    3690             : /* }}} */
    3691             : 
    3692          18 : void zend_compile_declare(zend_ast *ast TSRMLS_DC) /* {{{ */
    3693             : {
    3694          36 :         zend_ast_list *declares = zend_ast_get_list(ast->child[0]);
    3695          18 :         zend_ast *stmt_ast = ast->child[1];
    3696          18 :         zend_declarables orig_declarables = CG(declarables);
    3697             :         uint32_t i;
    3698             : 
    3699          35 :         for (i = 0; i < declares->children; ++i) {
    3700          18 :                 zend_ast *declare_ast = declares->child[i];
    3701          18 :                 zend_ast *name_ast = declare_ast->child[0];
    3702          18 :                 zend_ast *value_ast = declare_ast->child[1];
    3703             : 
    3704          18 :                 zend_string *name = zend_ast_get_str(name_ast);
    3705          24 :                 if (zend_string_equals_literal_ci(name, "ticks")) {
    3706             :                         zval value_zv;
    3707           6 :                         zend_const_expr_to_zval(&value_zv, value_ast TSRMLS_CC);
    3708           6 :                         convert_to_long(&value_zv);
    3709           6 :                         ZVAL_COPY_VALUE(&CG(declarables).ticks, &value_zv);
    3710             :                         zval_dtor(&value_zv);
    3711          23 :                 } else if (zend_string_equals_literal_ci(name, "encoding")) {
    3712             :                         /* Encoding declaration was already handled during parsing. Here we
    3713             :                          * only check that it is the first statement in the file. */
    3714          12 :                         uint32_t num = CG(active_op_array)->last;
    3715          26 :                         while (num > 0 &&
    3716           1 :                                    (CG(active_op_array)->opcodes[num-1].opcode == ZEND_EXT_STMT ||
    3717           1 :                                         CG(active_op_array)->opcodes[num-1].opcode == ZEND_TICKS)) {
    3718           0 :                                 --num;
    3719             :                         }
    3720             : 
    3721          12 :                         if (num > 0) {
    3722           1 :                                 zend_error_noreturn(E_COMPILE_ERROR, "Encoding declaration pragma must be "
    3723             :                                         "the very first statement in the script");
    3724             :                         }
    3725             :                 } else {
    3726           0 :                         zend_error(E_COMPILE_WARNING, "Unsupported declare '%s'", name->val);
    3727             :                 }
    3728             :         }
    3729             : 
    3730          17 :         if (stmt_ast) {
    3731           3 :                 zend_compile_stmt(stmt_ast TSRMLS_CC);
    3732             : 
    3733           3 :                 CG(declarables) = orig_declarables;
    3734             :         }
    3735          17 : }
    3736             : /* }}} */
    3737             : 
    3738      133667 : void zend_compile_stmt_list(zend_ast *ast TSRMLS_DC) /* {{{ */
    3739             : {
    3740      133667 :         zend_ast_list *list = zend_ast_get_list(ast);
    3741             :         uint32_t i;
    3742      400446 :         for (i = 0; i < list->children; ++i) {
    3743      266834 :                 zend_compile_stmt(list->child[i] TSRMLS_CC);
    3744             :         }
    3745      133612 : }
    3746             : /* }}} */
    3747             : 
    3748       35188 : void zend_compile_params(zend_ast *ast TSRMLS_DC) /* {{{ */
    3749             : {
    3750       35188 :         zend_ast_list *list = zend_ast_get_list(ast);
    3751             :         uint32_t i;
    3752       35188 :         zend_op_array *op_array = CG(active_op_array);
    3753             :         zend_arg_info *arg_infos;
    3754             : 
    3755       35188 :         if (list->children == 0) {
    3756        8991 :                 return;
    3757             :         }
    3758             :         
    3759       26197 :         arg_infos = safe_emalloc(sizeof(zend_arg_info), list->children, 0);
    3760      108819 :         for (i = 0; i < list->children; ++i) {
    3761       82632 :                 zend_ast *param_ast = list->child[i];
    3762       82632 :                 zend_ast *type_ast = param_ast->child[0];
    3763       82632 :                 zend_ast *var_ast = param_ast->child[1];
    3764       82632 :                 zend_ast *default_ast = param_ast->child[2];
    3765       82632 :                 zend_string *name = zend_ast_get_str(var_ast);
    3766       82632 :                 zend_bool is_ref = (param_ast->attr & ZEND_PARAM_REF) != 0;
    3767       82632 :                 zend_bool is_variadic = (param_ast->attr & ZEND_PARAM_VARIADIC) != 0;
    3768             : 
    3769             :                 znode var_node, default_node;
    3770             :                 zend_uchar opcode;
    3771             :                 zend_op *opline;
    3772             :                 zend_arg_info *arg_info;
    3773             : 
    3774       82632 :                 if (zend_is_auto_global(name TSRMLS_CC)) {
    3775           0 :                         zend_error_noreturn(E_COMPILE_ERROR, "Cannot re-assign auto-global variable %s",
    3776             :                                 name->val);
    3777             :                 }
    3778             : 
    3779       82632 :                 var_node.op_type = IS_CV;
    3780       82632 :                 var_node.u.op.var = lookup_cv(CG(active_op_array), zend_string_copy(name) TSRMLS_CC);
    3781             : 
    3782       82632 :                 if (EX_VAR_TO_NUM(var_node.u.op.var) != i) {
    3783           2 :                         zend_error_noreturn(E_COMPILE_ERROR, "Redefinition of parameter $%s",
    3784             :                                 name->val);
    3785       82630 :                 } else if (zend_string_equals_literal(name, "this")) {
    3786           2 :                         if (op_array->scope && (op_array->fn_flags & ZEND_ACC_STATIC) == 0) {
    3787           1 :                                 zend_error_noreturn(E_COMPILE_ERROR, "Cannot re-assign $this");
    3788             :                         }
    3789           1 :                         op_array->this_var = var_node.u.op.var;
    3790             :                 }
    3791             : 
    3792       82629 :                 if (op_array->fn_flags & ZEND_ACC_VARIADIC) {
    3793           1 :                         zend_error_noreturn(E_COMPILE_ERROR, "Only the last parameter can be variadic");
    3794             :                 }
    3795             : 
    3796       82628 :                 if (is_variadic) {
    3797          38 :                         opcode = ZEND_RECV_VARIADIC;
    3798          38 :                         default_node.op_type = IS_UNUSED;
    3799          38 :                         op_array->fn_flags |= ZEND_ACC_VARIADIC;
    3800             : 
    3801          38 :                         if (default_ast) {
    3802           1 :                                 zend_error_noreturn(E_COMPILE_ERROR,
    3803             :                                         "Variadic parameter cannot have a default value");
    3804             :                         }
    3805       82590 :                 } else if (default_ast) {
    3806       14133 :                         opcode = ZEND_RECV_INIT;
    3807       14133 :                         default_node.op_type = IS_CONST;
    3808       14133 :                         zend_const_expr_to_zval(&default_node.u.constant, default_ast TSRMLS_CC);
    3809             :                 } else {
    3810       68457 :                         opcode = ZEND_RECV;
    3811       68457 :                         default_node.op_type = IS_UNUSED;
    3812       68457 :                         op_array->required_num_args = i + 1;
    3813             :                 }
    3814             : 
    3815       82625 :                 opline = zend_emit_op(NULL, opcode, NULL, &default_node TSRMLS_CC);
    3816       82625 :                 SET_NODE(opline->result, &var_node);
    3817       82625 :                 opline->op1.num = i + 1;
    3818             : 
    3819       82625 :                 arg_info = &arg_infos[i];
    3820       82625 :                 arg_info->name = estrndup(name->val, name->len);
    3821       82625 :                 arg_info->name_len = (uint32_t)name->len;
    3822       82625 :                 arg_info->pass_by_reference = is_ref;
    3823       82625 :                 arg_info->is_variadic = is_variadic;
    3824       82625 :                 arg_info->type_hint = 0;
    3825       82625 :                 arg_info->allow_null = 1;
    3826       82625 :                 arg_info->class_name = NULL;
    3827       82625 :                 arg_info->class_name_len = 0;
    3828             : 
    3829       82625 :                 if (type_ast) {
    3830         453 :                         zend_bool has_null_default = default_ast
    3831             :                                 && (Z_TYPE(default_node.u.constant) == IS_NULL
    3832             :                                         || (Z_TYPE(default_node.u.constant) == IS_CONSTANT
    3833           0 :                                                 && strcasecmp(Z_STRVAL(default_node.u.constant), "NULL") == 0)
    3834         402 :                                         || Z_TYPE(default_node.u.constant) == IS_CONSTANT_AST); // ???
    3835             : 
    3836         402 :                         op_array->fn_flags |= ZEND_ACC_HAS_TYPE_HINTS;
    3837         402 :                         arg_info->allow_null = has_null_default;
    3838             : 
    3839         402 :                         if (type_ast->kind == ZEND_AST_TYPE) {
    3840         228 :                                 arg_info->type_hint = type_ast->attr;
    3841         228 :                                 if (arg_info->type_hint == IS_ARRAY) {
    3842         227 :                                         if (default_ast && !has_null_default
    3843             :                                                 && Z_TYPE(default_node.u.constant) != IS_ARRAY
    3844             :                                         ) {
    3845           1 :                                                 zend_error_noreturn(E_COMPILE_ERROR, "Default value for parameters "
    3846             :                                                         "with array type hint can only be an array or NULL");
    3847             :                                         }
    3848           8 :                                 } else if (arg_info->type_hint == IS_CALLABLE && default_ast) {
    3849           1 :                                         if (!has_null_default) {
    3850           0 :                                                 zend_error_noreturn(E_COMPILE_ERROR, "Default value for parameters "
    3851             :                                                         "with callable type hint can only be NULL");
    3852             :                                         }
    3853             :                                 }
    3854             :                         } else {
    3855         174 :                                 zend_string *class_name = zend_ast_get_str(type_ast);
    3856             : 
    3857         174 :                                 if (zend_is_const_default_class_ref(type_ast)) {
    3858         161 :                                         class_name = zend_resolve_class_name_ast(type_ast TSRMLS_CC);
    3859             :                                 } else {
    3860             :                                         zend_string_addref(class_name);
    3861             :                                 }
    3862             : 
    3863         173 :                                 arg_info->type_hint = IS_OBJECT;
    3864         173 :                                 arg_info->class_name = estrndup(class_name->val, class_name->len);
    3865         173 :                                 arg_info->class_name_len = (uint32_t)class_name->len;
    3866             : 
    3867             :                                 zend_string_release(class_name);
    3868             : 
    3869         173 :                                 if (default_ast && !has_null_default) {
    3870           1 :                                                 zend_error_noreturn(E_COMPILE_ERROR, "Default value for parameters "
    3871             :                                                         "with a class type hint can only be NULL");
    3872             :                                 }
    3873             :                         }
    3874             :                 }
    3875             :         }
    3876             : 
    3877             :         /* These are assigned at the end to avoid unitialized memory in case of an error */
    3878       26187 :         op_array->num_args = list->children;
    3879       26187 :         op_array->arg_info = arg_infos;
    3880             : }
    3881             : /* }}} */
    3882             : 
    3883         134 : void zend_compile_closure_uses(zend_ast *ast TSRMLS_DC) /* {{{ */
    3884             : {
    3885         134 :         zend_ast_list *list = zend_ast_get_list(ast);
    3886             :         uint32_t i;
    3887             : 
    3888         274 :         for (i = 0; i < list->children; ++i) {
    3889         141 :                 zend_ast *var_ast = list->child[i];
    3890         141 :                 zend_string *name = zend_ast_get_str(var_ast);
    3891         141 :                 zend_bool by_ref = var_ast->attr;
    3892             :                 zval zv;
    3893             : 
    3894         141 :                 if (zend_string_equals_literal(name, "this")) {
    3895           1 :                         zend_error_noreturn(E_COMPILE_ERROR, "Cannot use $this as lexical variable");
    3896             :                 }
    3897             : 
    3898         140 :                 ZVAL_NULL(&zv);
    3899         140 :                 Z_CONST_FLAGS(zv) = by_ref ? IS_LEXICAL_REF : IS_LEXICAL_VAR;
    3900             : 
    3901         140 :                 zend_compile_static_var_common(var_ast, &zv, by_ref TSRMLS_CC);
    3902             :         }
    3903         133 : }
    3904             : /* }}} */
    3905             : 
    3906       17112 : void zend_begin_method_decl(zend_op_array *op_array, zend_string *name, zend_bool has_body TSRMLS_DC) /* {{{ */
    3907             : {
    3908       17112 :         zend_class_entry *ce = CG(active_class_entry);
    3909       17112 :         zend_bool in_interface = (ce->ce_flags & ZEND_ACC_INTERFACE) != 0;
    3910       17112 :         zend_bool in_trait = ZEND_CE_IS_TRAIT(ce);
    3911       17112 :         zend_bool is_public = (op_array->fn_flags & ZEND_ACC_PUBLIC) != 0;
    3912       17112 :         zend_bool is_static = (op_array->fn_flags & ZEND_ACC_STATIC) != 0;
    3913             : 
    3914             :         zend_string *lcname;
    3915             : 
    3916       17112 :         if (in_interface) {
    3917         103 :                 if ((op_array->fn_flags & ZEND_ACC_PPP_MASK) != ZEND_ACC_PUBLIC) {
    3918           2 :                         zend_error_noreturn(E_COMPILE_ERROR, "Access type for interface method "
    3919           1 :                                 "%s::%s() must be omitted", ce->name->val, name->val);
    3920             :                 }
    3921         102 :                 op_array->fn_flags |= ZEND_ACC_ABSTRACT;
    3922       17009 :         } else if (is_static && (op_array->fn_flags & ZEND_ACC_ABSTRACT)) {
    3923           8 :                 zend_error(E_STRICT, "Static function %s::%s() should not be abstract",
    3924           4 :                         ce->name->val, name->val);
    3925             :         }
    3926             : 
    3927       17111 :         if (op_array->fn_flags & ZEND_ACC_ABSTRACT) {
    3928         168 :                 if (op_array->fn_flags & ZEND_ACC_PRIVATE) {
    3929           2 :                         zend_error_noreturn(E_COMPILE_ERROR, "%s function %s::%s() cannot be declared private",
    3930           1 :                                 in_interface ? "Interface" : "Abstract", ce->name->val, name->val);
    3931             :                 }
    3932             : 
    3933         167 :                 if (has_body) {
    3934           2 :                         zend_error_noreturn(E_COMPILE_ERROR, "%s function %s::%s() cannot contain body",
    3935           1 :                                 in_interface ? "Interface" : "Abstract", ce->name->val, name->val);
    3936             :                 }
    3937             : 
    3938         166 :                 ce->ce_flags |= ZEND_ACC_IMPLICIT_ABSTRACT_CLASS;
    3939       16943 :         } else if (!has_body) {
    3940           2 :                 zend_error_noreturn(E_COMPILE_ERROR, "Non-abstract method %s::%s() must contain body",
    3941           1 :                         ce->name->val, name->val);
    3942             :         }
    3943             : 
    3944       17108 :         op_array->scope = ce;
    3945       17108 :         op_array->function_name = zend_string_copy(name);
    3946             : 
    3947       34216 :         lcname = zend_string_alloc(name->len, 0);
    3948       17108 :         zend_str_tolower_copy(lcname->val, name->val, name->len);
    3949       17108 :         lcname = zend_new_interned_string(lcname TSRMLS_CC);
    3950             : 
    3951       34216 :         if (zend_hash_add_ptr(&ce->function_table, lcname, op_array) == NULL) {
    3952           2 :                 zend_error_noreturn(E_COMPILE_ERROR, "Cannot redeclare %s::%s()",
    3953           1 :                         ce->name->val, name->val);
    3954             :         }
    3955             : 
    3956       17107 :         if (in_interface) {
    3957         102 :                 if (zend_string_equals_literal(lcname, ZEND_CALL_FUNC_NAME)) {
    3958           1 :                         if (!is_public || is_static) {
    3959           1 :                                 zend_error(E_WARNING, "The magic method __call() must have "
    3960             :                                         "public visibility and cannot be static");
    3961             :                         }
    3962         101 :                 } else if (zend_string_equals_literal(lcname, ZEND_CALLSTATIC_FUNC_NAME)) {
    3963           1 :                         if (!is_public || !is_static) {
    3964           1 :                                 zend_error(E_WARNING, "The magic method __callStatic() must have "
    3965             :                                         "public visibility and be static");
    3966             :                         }
    3967          99 :                 } else if (zend_string_equals_literal(lcname, ZEND_GET_FUNC_NAME)) {
    3968           0 :                         if (!is_public || is_static) {
    3969           0 :                                 zend_error(E_WARNING, "The magic method __get() must have "
    3970             :                                         "public visibility and cannot be static");
    3971             :                         }
    3972          99 :                 } else if (zend_string_equals_literal(lcname, ZEND_SET_FUNC_NAME)) {
    3973           0 :                         if (!is_public || is_static) {
    3974           0 :                                 zend_error(E_WARNING, "The magic method __set() must have "
    3975             :                                         "public visibility and cannot be static");
    3976             :                         }
    3977          99 :                 } else if (zend_string_equals_literal(lcname, ZEND_UNSET_FUNC_NAME)) {
    3978           0 :                         if (!is_public || is_static) {
    3979           0 :                                 zend_error(E_WARNING, "The magic method __unset() must have "
    3980             :                                         "public visibility and cannot be static");
    3981             :                         }
    3982          99 :                 } else if (zend_string_equals_literal(lcname, ZEND_ISSET_FUNC_NAME)) {
    3983           0 :                         if (!is_public || is_static) {
    3984           0 :                                 zend_error(E_WARNING, "The magic method __isset() must have "
    3985             :                                         "public visibility and cannot be static");
    3986             :                         }
    3987          99 :                 } else if (zend_string_equals_literal(lcname, ZEND_TOSTRING_FUNC_NAME)) {
    3988           0 :                         if (!is_public || is_static) {
    3989           0 :                                 zend_error(E_WARNING, "The magic method __toString() must have "
    3990             :                                         "public visibility and cannot be static");
    3991             :                         }
    3992         100 :                 } else if (zend_string_equals_literal(lcname, ZEND_INVOKE_FUNC_NAME)) {
    3993           1 :                         if (!is_public || is_static) {
    3994           1 :                                 zend_error(E_WARNING, "The magic method __invoke() must have "
    3995             :                                         "public visibility and cannot be static");
    3996             :                         }
    3997          98 :                 } else if (zend_string_equals_literal(lcname, ZEND_DEBUGINFO_FUNC_NAME)) {
    3998           0 :                         if (!is_public || is_static) {
    3999           0 :                                 zend_error(E_WARNING, "The magic method __debugInfo() must have "
    4000             :                                         "public visibility and cannot be static");
    4001             :                         }
    4002             :                 }
    4003             :         } else {
    4004       17251 :                 if (!in_trait && zend_string_equals_str_ci(lcname, ce->name)) {
    4005         245 :                         if (!ce->constructor) {
    4006         235 :                                 ce->constructor = (zend_function *) op_array;
    4007             :                         }
    4008       18430 :                 } else if (zend_string_equals_literal(lcname, ZEND_CONSTRUCTOR_FUNC_NAME)) {
    4009        1669 :                         if (CG(active_class_entry)->constructor) {
    4010           8 :                                 zend_error(E_STRICT, "Redefining already defined constructor for class %s",
    4011           8 :                                         ce->name->val);
    4012             :                         }
    4013        1669 :                         ce->constructor = (zend_function *) op_array;
    4014       15236 :                 } else if (zend_string_equals_literal(lcname, ZEND_DESTRUCTOR_FUNC_NAME)) {
    4015         144 :                         ce->destructor = (zend_function *) op_array;
    4016       14974 :                 } else if (zend_string_equals_literal(lcname, ZEND_CLONE_FUNC_NAME)) {
    4017          26 :                         ce->clone = (zend_function *) op_array;
    4018       14985 :                 } else if (zend_string_equals_literal(lcname, ZEND_CALL_FUNC_NAME)) {
    4019          63 :                         if (!is_public || is_static) {
    4020           2 :                                 zend_error(E_WARNING, "The magic method __call() must have "
    4021             :                                         "public visibility and cannot be static");
    4022             :                         }
    4023          63 :                         ce->__call = (zend_function *) op_array;
    4024       14887 :                 } else if (zend_string_equals_literal(lcname, ZEND_CALLSTATIC_FUNC_NAME)) {
    4025          28 :                         if (!is_public || !is_static) {
    4026           1 :                                 zend_error(E_WARNING, "The magic method __callStatic() must have "
    4027             :                                         "public visibility and be static");
    4028             :                         }
    4029          28 :                         ce->__callstatic = (zend_function *) op_array;
    4030       14892 :                 } else if (zend_string_equals_literal(lcname, ZEND_GET_FUNC_NAME)) {
    4031          61 :                         if (!is_public || is_static) {
    4032           0 :                                 zend_error(E_WARNING, "The magic method __get() must have "
    4033             :                                         "public visibility and cannot be static");
    4034             :                         }
    4035          61 :                         ce->__get = (zend_function *) op_array;
    4036       14831 :                 } else if (zend_string_equals_literal(lcname, ZEND_SET_FUNC_NAME)) {
    4037          61 :                         if (!is_public || is_static) {
    4038           2 :                                 zend_error(E_WARNING, "The magic method __set() must have "
    4039             :                                         "public visibility and cannot be static");
    4040             :                         }
    4041          61 :                         ce->__set = (zend_function *) op_array;
    4042       14726 :                 } else if (zend_string_equals_literal(lcname, ZEND_UNSET_FUNC_NAME)) {
    4043          17 :                         if (!is_public || is_static) {
    4044           3 :                                 zend_error(E_WARNING, "The magic method __unset() must have "
    4045             :                                         "public visibility and cannot be static");
    4046             :                         }
    4047          17 :                         ce->__unset = (zend_function *) op_array;
    4048       14708 :                 } else if (zend_string_equals_literal(lcname, ZEND_ISSET_FUNC_NAME)) {
    4049          16 :                         if (!is_public || is_static) {
    4050           0 :                                 zend_error(E_WARNING, "The magic method __isset() must have "
    4051             :                                         "public visibility and cannot be static");
    4052             :                         }
    4053          16 :                         ce->__isset = (zend_function *) op_array;
    4054       15390 :                 } else if (zend_string_equals_literal(lcname, ZEND_TOSTRING_FUNC_NAME)) {
    4055         714 :                         if (!is_public || is_static) {
    4056           1 :                                 zend_error(E_WARNING, "The magic method __toString() must have "
    4057             :                                         "public visibility and cannot be static");
    4058             :                         }
    4059         714 :                         ce->__tostring = (zend_function *) op_array;
    4060       13975 :                 } else if (zend_string_equals_literal(lcname, ZEND_INVOKE_FUNC_NAME)) {
    4061          13 :                         if (!is_public || is_static) {
    4062           1 :                                 zend_error(E_WARNING, "The magic method __invoke() must have "
    4063             :                                         "public visibility and cannot be static");
    4064             :                         }
    4065       13961 :                 } else if (zend_string_equals_literal(lcname, ZEND_DEBUGINFO_FUNC_NAME)) {
    4066          12 :                         if (!is_public || is_static) {
    4067           0 :                                 zend_error(E_WARNING, "The magic method __debugInfo() must have "
    4068             :                                         "public visibility and cannot be static");
    4069             :                         }
    4070          12 :                         ce->__debugInfo = (zend_function *) op_array;
    4071       13937 :                 } else if (!is_static) {
    4072        7483 :                         op_array->fn_flags |= ZEND_ACC_ALLOW_STATIC;
    4073             :                 }
    4074             :         }
    4075             : 
    4076             :         zend_string_release(lcname);
    4077       17107 : }
    4078             : /* }}} */
    4079             : 
    4080       18083 : static void zend_begin_func_decl(znode *result, zend_op_array *op_array, zend_ast_decl *decl TSRMLS_DC) /* {{{ */
    4081             : {
    4082       18083 :         zend_ast *params_ast = decl->child[0];
    4083       18083 :         zend_string *name = decl->name, *lcname;
    4084             :         zend_op *opline;
    4085             : 
    4086       18083 :         op_array->function_name = name = zend_prefix_with_ns(name TSRMLS_CC);
    4087             : 
    4088       36166 :         lcname = zend_string_alloc(name->len, 0);
    4089       18083 :         zend_str_tolower_copy(lcname->val, name->val, name->len);
    4090             : 
    4091       18083 :         if (CG(current_import_function)) {
    4092           2 :                 zend_string *import_name = zend_hash_find_ptr(CG(current_import_function), lcname);
    4093           1 :                 if (import_name && !zend_string_equals_str_ci(lcname, import_name)) {
    4094           1 :                         zend_error(E_COMPILE_ERROR, "Cannot declare function %s "
    4095             :                                 "because the name is already in use", name->val);
    4096             :                 }
    4097             :         }
    4098             : 
    4099       18158 :         if (zend_string_equals_literal(lcname, ZEND_AUTOLOAD_FUNC_NAME)
    4100          76 :                 && zend_ast_get_list(params_ast)->children != 1
    4101             :         ) {
    4102           1 :                 zend_error_noreturn(E_COMPILE_ERROR, "%s() must take exactly 1 argument",
    4103             :                         ZEND_AUTOLOAD_FUNC_NAME);
    4104             :         }
    4105             : 
    4106       18081 :         if (op_array->fn_flags & ZEND_ACC_CLOSURE) {
    4107         362 :                 opline = zend_emit_op_tmp(result, ZEND_DECLARE_LAMBDA_FUNCTION, NULL, NULL TSRMLS_CC);
    4108             :         } else {
    4109       17719 :                 opline = get_next_op(CG(active_op_array) TSRMLS_CC);
    4110       17719 :                 opline->opcode = ZEND_DECLARE_FUNCTION;
    4111       17719 :                 opline->op2_type = IS_CONST;
    4112       35438 :                 LITERAL_STR(opline->op2, zend_string_copy(lcname));
    4113             :         }
    4114             : 
    4115             :         {
    4116       18081 :                 zend_string *key = zend_build_runtime_definition_key(lcname, decl->lex_pos TSRMLS_CC);
    4117             : 
    4118       18081 :                 opline->op1_type = IS_CONST;
    4119       18081 :                 LITERAL_STR(opline->op1, key);
    4120             : 
    4121       18081 :                 zend_hash_update_ptr(CG(function_table), key, op_array);
    4122             :         }
    4123             : 
    4124             :         zend_string_release(lcname);
    4125       18081 : }
    4126             : /* }}} */
    4127             : 
    4128       35195 : void zend_compile_func_decl(znode *result, zend_ast *ast TSRMLS_DC) /* {{{ */
    4129             : {
    4130       35195 :         zend_ast_decl *decl = (zend_ast_decl *) ast;
    4131       35195 :         zend_ast *params_ast = decl->child[0];
    4132       35195 :         zend_ast *uses_ast = decl->child[1];
    4133       35195 :         zend_ast *stmt_ast = decl->child[2];
    4134       35195 :         zend_bool is_method = decl->kind == ZEND_AST_METHOD;
    4135             : 
    4136       35195 :         zend_op_array *orig_op_array = CG(active_op_array);
    4137       35195 :         zend_op_array *op_array = zend_arena_alloc(&CG(arena), sizeof(zend_op_array));
    4138             : 
    4139             :         // TODO.AST interactive (not just here - also bpc etc!)
    4140             :         
    4141       35195 :         init_op_array(op_array, ZEND_USER_FUNCTION, INITIAL_OP_ARRAY_SIZE TSRMLS_CC);
    4142             : 
    4143       35195 :         op_array->fn_flags |= decl->flags;
    4144       35195 :         op_array->line_start = decl->start_lineno;
    4145       35195 :         op_array->line_end = decl->end_lineno;
    4146       35195 :         if (decl->doc_comment) {
    4147        4000 :                 op_array->doc_comment = zend_string_copy(decl->doc_comment);
    4148             :         }
    4149       35195 :         if (decl->kind == ZEND_AST_CLOSURE) {
    4150         362 :                 op_array->fn_flags |= ZEND_ACC_CLOSURE;
    4151             :         }
    4152             : 
    4153       35195 :         if (is_method) {
    4154       17112 :                 zend_bool has_body = stmt_ast != NULL;
    4155       17112 :                 zend_begin_method_decl(op_array, decl->name, has_body TSRMLS_CC);
    4156             :         } else {
    4157       18083 :                 zend_begin_func_decl(result, op_array, decl TSRMLS_CC);
    4158             :         }
    4159             : 
    4160       35188 :         CG(active_op_array) = op_array;
    4161       35188 :         zend_stack_push(&CG(context_stack), (void *) &CG(context));
    4162       35188 :         zend_init_compiler_context(TSRMLS_C);
    4163             : 
    4164       35188 :         if (CG(compiler_options) & ZEND_COMPILE_EXTENDED_INFO) {
    4165           0 :                 zend_op *opline_ext = zend_emit_op(NULL, ZEND_EXT_NOP, NULL, NULL TSRMLS_CC);
    4166           0 :                 opline_ext->lineno = decl->start_lineno;
    4167             :         }
    4168             : 
    4169             :         {
    4170             :                 /* Push a separator to the loop variable stack */
    4171             :                 znode dummy_var;
    4172       35188 :                 dummy_var.op_type = IS_UNUSED;
    4173             : 
    4174       35188 :                 zend_stack_push(&CG(loop_var_stack), (void *) &dummy_var);
    4175             :         }
    4176             : 
    4177       35188 :         zend_compile_params(params_ast TSRMLS_CC);
    4178       35178 :         if (uses_ast) {
    4179         134 :                 zend_compile_closure_uses(uses_ast TSRMLS_CC);
    4180             :         }
    4181       35177 :         zend_compile_stmt(stmt_ast TSRMLS_CC);
    4182             : 
    4183       35170 :         if (is_method) {
    4184       34188 :                 zend_check_magic_method_implementation(
    4185       17094 :                         CG(active_class_entry), (zend_function *) op_array, E_COMPILE_ERROR TSRMLS_CC);
    4186             :         }
    4187             : 
    4188       35154 :         zend_do_extended_info(TSRMLS_C);
    4189       35154 :         zend_emit_final_return(NULL TSRMLS_CC);
    4190             : 
    4191       35154 :         pass_two(CG(active_op_array) TSRMLS_CC);
    4192       35145 :         zend_release_labels(0 TSRMLS_CC);
    4193             : 
    4194             :         /* Pop the loop variable stack separator */
    4195       35145 :         zend_stack_del_top(&CG(loop_var_stack));
    4196             : 
    4197       35145 :         CG(active_op_array) = orig_op_array;
    4198       35145 : }
    4199             : /* }}} */
    4200             : 
    4201        2308 : void zend_compile_prop_decl(zend_ast *ast TSRMLS_DC) /* {{{ */
    4202             : {
    4203        2308 :         zend_ast_list *list = zend_ast_get_list(ast);
    4204        2308 :         uint32_t flags = list->attr;
    4205        2308 :         zend_class_entry *ce = CG(active_class_entry);
    4206        2308 :         uint32_t i, children = list->children;
    4207        2308 :         zend_string *doc_comment = NULL;
    4208             : 
    4209        2308 :         if (ce->ce_flags & ZEND_ACC_INTERFACE) {
    4210           1 :                 zend_error_noreturn(E_COMPILE_ERROR, "Interfaces may not include member variables");
    4211             :         }
    4212             : 
    4213        2307 :         if (flags & ZEND_ACC_ABSTRACT) {
    4214           1 :                 zend_error_noreturn(E_COMPILE_ERROR, "Properties cannot be declared abstract");
    4215             :         }
    4216             : 
    4217             :         /* Doc comment has been appended as last element in property list */
    4218        2306 :         if (list->child[children - 1]->kind == ZEND_AST_ZVAL) {
    4219         102 :                 doc_comment = zend_string_copy(zend_ast_get_str(list->child[children - 1]));
    4220          51 :                 children -= 1;
    4221             :         }
    4222             : 
    4223        4651 :         for (i = 0; i < children; ++i) {
    4224        2347 :                 zend_ast *prop_ast = list->child[i];
    4225        2347 :                 zend_ast *name_ast = prop_ast->child[0];
    4226        2347 :                 zend_ast *value_ast = prop_ast->child[1];
    4227        2347 :                 zend_string *name = zend_ast_get_str(name_ast);
    4228             :                 zval value_zv;
    4229             : 
    4230        2347 :                 if (flags & ZEND_ACC_FINAL) {
    4231           2 :                         zend_error_noreturn(E_COMPILE_ERROR, "Cannot declare property %s::$%s final, "
    4232             :                                 "the final modifier is allowed only for methods and classes",
    4233           1 :                                 ce->name->val, name->val);
    4234             :                 }
    4235             : 
    4236        2346 :                 if (zend_hash_exists(&ce->properties_info, name)) {
    4237           2 :                         zend_error_noreturn(E_COMPILE_ERROR, "Cannot redeclare %s::$%s",
    4238           1 :                                 ce->name->val, name->val);
    4239             :                 }
    4240             : 
    4241        2345 :                 if (value_ast) {
    4242        1223 :                         zend_const_expr_to_zval(&value_zv, value_ast TSRMLS_CC);
    4243             :                 } else {
    4244        1122 :                         ZVAL_NULL(&value_zv);
    4245             :                 }
    4246             : 
    4247        2345 :                 name = zend_new_interned_string_safe(name TSRMLS_CC);
    4248        2345 :                 zend_declare_property_ex(ce, name, &value_zv, flags, doc_comment TSRMLS_CC);
    4249             : 
    4250             :                 /* Doc comment is only assigned to first property */
    4251        2345 :                 doc_comment = NULL;
    4252             :         }
    4253        2304 : }
    4254             : /* }}} */
    4255             : 
    4256         239 : void zend_compile_class_const_decl(zend_ast *ast TSRMLS_DC) /* {{{ */
    4257             : {
    4258         239 :         zend_ast_list *list = zend_ast_get_list(ast);
    4259         239 :         zend_class_entry *ce = CG(active_class_entry);
    4260             :         uint32_t i;
    4261             : 
    4262         475 :         for (i = 0; i < list->children; ++i) {
    4263         242 :                 zend_ast *const_ast = list->child[i];
    4264         242 :                 zend_ast *name_ast = const_ast->child[0];
    4265         242 :                 zend_ast *value_ast = const_ast->child[1];
    4266         242 :                 zend_string *name = zend_ast_get_str(name_ast);
    4267             :                 zval value_zv;
    4268             : 
    4269         242 :                 if (ZEND_CE_IS_TRAIT(ce)) {
    4270           1 :                         zend_error_noreturn(E_COMPILE_ERROR, "Traits cannot have constants");
    4271             :                         return;
    4272             :                 }
    4273             : 
    4274         241 :                 zend_const_expr_to_zval(&value_zv, value_ast TSRMLS_CC);
    4275             : 
    4276         238 :                 name = zend_new_interned_string_safe(name TSRMLS_CC);
    4277         238 :                 if (zend_hash_add(&ce->constants_table, name, &value_zv) == NULL) {
    4278           4 :                         zend_error_noreturn(E_COMPILE_ERROR, "Cannot redefine class constant %s::%s",
    4279           2 :                                 ce->name->val, name->val);
    4280             :                 }
    4281             : 
    4282         236 :                 if (Z_CONSTANT(value_zv)) {
    4283          41 :                         ce->ce_flags &= ~ZEND_ACC_CONSTANTS_UPDATED;
    4284             :                 }
    4285             :         }
    4286             : }
    4287             : /* }}} */
    4288             : 
    4289          73 : static zend_trait_method_reference *zend_compile_method_ref(zend_ast *ast TSRMLS_DC) /* {{{ */
    4290             : {
    4291          73 :         zend_ast *class_ast = ast->child[0];
    4292          73 :         zend_ast *method_ast = ast->child[1];
    4293             : 
    4294          73 :         zend_trait_method_reference *method_ref = emalloc(sizeof(zend_trait_method_reference));
    4295          73 :         method_ref->ce = NULL;
    4296          73 :         method_ref->method_name = zend_string_copy(zend_ast_get_str(method_ast));
    4297             : 
    4298          73 :         if (class_ast) {
    4299          38 :                 method_ref->class_name = zend_resolve_class_name_ast(class_ast TSRMLS_CC);
    4300             :         } else {
    4301          35 :                 method_ref->class_name = NULL;
    4302             :         }
    4303             : 
    4304          73 :         return method_ref;
    4305             : }
    4306             : /* }}} */
    4307             : 
    4308          17 : static zend_string **zend_compile_name_list(zend_ast *ast TSRMLS_DC) /* {{{ */
    4309             : {
    4310          17 :         zend_ast_list *list = zend_ast_get_list(ast);
    4311          17 :         zend_string **names = safe_emalloc(sizeof(zend_string *), list->children + 1, 0);
    4312             :         uint32_t i;
    4313             : 
    4314          35 :         for (i = 0; i < list->children; ++i) {
    4315          18 :                 zend_ast *name_ast = list->child[i];
    4316          18 :                 names[i] = zend_resolve_class_name_ast(name_ast TSRMLS_CC);
    4317             :         }
    4318             : 
    4319          17 :         names[list->children] = NULL;
    4320             : 
    4321          17 :         return names;
    4322             : }
    4323             : /* }}} */
    4324             : 
    4325          17 : static void zend_compile_trait_precedence(zend_ast *ast TSRMLS_DC) /* {{{ */
    4326             : {
    4327          17 :         zend_ast *method_ref_ast = ast->child[0];
    4328          17 :         zend_ast *insteadof_ast = ast->child[1];
    4329             :         
    4330          17 :         zend_trait_precedence *precedence = emalloc(sizeof(zend_trait_precedence));
    4331          17 :         precedence->trait_method = zend_compile_method_ref(method_ref_ast TSRMLS_CC);
    4332          17 :         precedence->exclude_from_classes
    4333             :                 = (void *) zend_compile_name_list(insteadof_ast TSRMLS_CC);
    4334             : 
    4335          17 :         zend_add_to_list(&CG(active_class_entry)->trait_precedences, precedence TSRMLS_CC);
    4336          17 : }
    4337             : /* }}} */
    4338             : 
    4339          59 : static void zend_compile_trait_alias(zend_ast *ast TSRMLS_DC) /* {{{ */
    4340             : {
    4341          59 :         zend_ast *method_ref_ast = ast->child[0];
    4342          59 :         zend_ast *alias_ast = ast->child[1];
    4343          59 :         uint32_t modifiers = ast->attr;
    4344             : 
    4345             :         zend_trait_alias *alias;
    4346             : 
    4347          59 :         if (modifiers == ZEND_ACC_STATIC) {
    4348           1 :                 zend_error_noreturn(E_COMPILE_ERROR, "Cannot use 'static' as method modifier");
    4349          58 :         } else if (modifiers == ZEND_ACC_ABSTRACT) {
    4350           1 :                 zend_error_noreturn(E_COMPILE_ERROR, "Cannot use 'abstract' as method modifier");
    4351          57 :         } else if (modifiers == ZEND_ACC_FINAL) {
    4352           1 :                 zend_error_noreturn(E_COMPILE_ERROR, "Cannot use 'final' as method modifier");
    4353             :         }
    4354             : 
    4355          56 :         alias = emalloc(sizeof(zend_trait_alias));
    4356          56 :         alias->trait_method = zend_compile_method_ref(method_ref_ast TSRMLS_CC);
    4357          56 :         alias->modifiers = modifiers;
    4358             : 
    4359          56 :         if (alias_ast) {
    4360          48 :                 alias->alias = zend_string_copy(zend_ast_get_str(alias_ast));
    4361             :         } else {
    4362           8 :                 alias->alias = NULL;
    4363             :         }
    4364             : 
    4365          56 :         zend_add_to_list(&CG(active_class_entry)->trait_aliases, alias TSRMLS_CC);
    4366          56 : }
    4367             : /* }}} */
    4368             : 
    4369         198 : void zend_compile_use_trait(zend_ast *ast TSRMLS_DC) /* {{{ */
    4370             : {
    4371         396 :         zend_ast_list *traits = zend_ast_get_list(ast->child[0]);
    4372         255 :         zend_ast_list *adaptations = ast->child[1] ? zend_ast_get_list(ast->child[1]) : NULL;
    4373         198 :         zend_class_entry *ce = CG(active_class_entry);
    4374             :         zend_op *opline;
    4375             :         uint32_t i;
    4376             : 
    4377         435 :         for (i = 0; i < traits->children; ++i) {
    4378         238 :                 zend_ast *trait_ast = traits->child[i];
    4379         238 :                 zend_string *name = zend_ast_get_str(trait_ast);
    4380             : 
    4381         238 :                 if (ce->ce_flags & ZEND_ACC_INTERFACE) {
    4382           1 :                         zend_error_noreturn(E_COMPILE_ERROR, "Cannot use traits inside of interfaces. "
    4383           1 :                                 "%s is used in %s", name->val, ce->name->val);
    4384             :                 }
    4385             : 
    4386         237 :                 switch (zend_get_class_fetch_type(name)) {
    4387             :                         case ZEND_FETCH_CLASS_SELF:
    4388             :                         case ZEND_FETCH_CLASS_PARENT:
    4389             :                         case ZEND_FETCH_CLASS_STATIC:
    4390           0 :                                 zend_error_noreturn(E_COMPILE_ERROR, "Cannot use '%s' as trait name "
    4391             :                                         "as it is reserved", name->val);
    4392             :                                 break;
    4393             :                 }
    4394             : 
    4395         237 :                 opline = get_next_op(CG(active_op_array) TSRMLS_CC);
    4396         237 :                 opline->opcode = ZEND_ADD_TRAIT;
    4397         237 :                 SET_NODE(opline->op1, &CG(implementing_class));
    4398         237 :                 opline->op2_type = IS_CONST;
    4399         237 :                 opline->op2.constant = zend_add_class_name_literal(CG(active_op_array),
    4400             :                         zend_resolve_class_name_ast(trait_ast TSRMLS_CC) TSRMLS_CC);
    4401             : 
    4402         237 :                 ce->num_traits++;
    4403             :         }
    4404             : 
    4405         197 :         if (!adaptations) {
    4406         140 :                 return;
    4407             :         }
    4408             : 
    4409         130 :         for (i = 0; i < adaptations->children; ++i) {
    4410          76 :                 zend_ast *adaptation_ast = adaptations->child[i];
    4411          76 :                 switch (adaptation_ast->kind) {
    4412             :                         case ZEND_AST_TRAIT_PRECEDENCE:
    4413          17 :                                 zend_compile_trait_precedence(adaptation_ast TSRMLS_CC);
    4414          17 :                                 break;
    4415             :                         case ZEND_AST_TRAIT_ALIAS:
    4416          59 :                                 zend_compile_trait_alias(adaptation_ast TSRMLS_CC);
    4417             :                                 break;
    4418             :                         EMPTY_SWITCH_DEFAULT_CASE()
    4419             :                 }
    4420             :         }
    4421             : }
    4422             : /* }}} */
    4423             : 
    4424         328 : void zend_compile_implements(znode *class_node, zend_ast *ast TSRMLS_DC) /* {{{ */
    4425             : {
    4426         328 :         zend_ast_list *list = zend_ast_get_list(ast);
    4427             :         uint32_t i;
    4428         693 :         for (i = 0; i < list->children; ++i) {
    4429         368 :                 zend_ast *class_ast = list->child[i];
    4430         368 :                 zend_string *name = zend_ast_get_str(class_ast);
    4431             : 
    4432             :                 zend_op *opline;
    4433             : 
    4434             :                 /* Traits can not implement interfaces */
    4435         368 :                 if (ZEND_CE_IS_TRAIT(CG(active_class_entry))) {
    4436           1 :                         zend_error_noreturn(E_COMPILE_ERROR, "Cannot use '%s' as interface on '%s' "
    4437           1 :                                 "since it is a Trait", name->val, CG(active_class_entry)->name->val);
    4438             :                 }
    4439             : 
    4440         367 :                 if (!zend_is_const_default_class_ref(class_ast)) {
    4441           2 :                         zend_error_noreturn(E_COMPILE_ERROR,
    4442             :                                 "Cannot use '%s' as interface name as it is reserved", name->val);
    4443             :                 }
    4444             : 
    4445         365 :                 opline = zend_emit_op(NULL, ZEND_ADD_INTERFACE, class_node, NULL TSRMLS_CC);
    4446         365 :                 opline->op2_type = IS_CONST;
    4447         365 :                 opline->op2.constant = zend_add_class_name_literal(CG(active_op_array),
    4448             :                         zend_resolve_class_name_ast(class_ast TSRMLS_CC) TSRMLS_CC);
    4449             : 
    4450         365 :                 CG(active_class_entry)->num_interfaces++;
    4451             :         }
    4452         325 : }
    4453             : /* }}} */
    4454             : 
    4455        7265 : void zend_compile_class_decl(zend_ast *ast TSRMLS_DC) /* {{{ */
    4456             : {
    4457        7265 :         zend_ast_decl *decl = (zend_ast_decl *) ast;
    4458        7265 :         zend_ast *extends_ast = decl->child[0];
    4459        7265 :         zend_ast *implements_ast = decl->child[1];
    4460        7265 :         zend_ast *stmt_ast = decl->child[2];
    4461             : 
    4462        7265 :         zend_string *name = decl->name, *lcname, *import_name = NULL;
    4463        7265 :         zend_class_entry *ce = zend_arena_alloc(&CG(arena), sizeof(zend_class_entry));
    4464             :         zend_op *opline;
    4465             :         znode declare_node, extends_node;
    4466             : 
    4467        7265 :         if (CG(active_class_entry)) {
    4468           1 :                 zend_error_noreturn(E_COMPILE_ERROR, "Class declarations may not be nested");
    4469             :                 return;
    4470             :         }
    4471             : 
    4472        7264 :         if (ZEND_FETCH_CLASS_DEFAULT != zend_get_class_fetch_type(name)) {
    4473           3 :                 zend_error_noreturn(E_COMPILE_ERROR, "Cannot use '%s' as class name as it is reserved",
    4474             :                         name->val);
    4475             :         }
    4476             : 
    4477       14522 :         lcname = zend_string_alloc(name->len, 0);
    4478        7261 :         zend_str_tolower_copy(lcname->val, name->val, name->len);
    4479             : 
    4480        7261 :         if (CG(current_import)) {
    4481          46 :                 import_name = zend_hash_find_ptr(CG(current_import), lcname);
    4482             :         }
    4483             : 
    4484        7261 :         if (CG(current_namespace)) {
    4485         118 :                 name = zend_prefix_with_ns(name TSRMLS_CC);
    4486             : 
    4487             :                 zend_string_release(lcname);
    4488         236 :                 lcname = zend_string_alloc(name->len, 0);
    4489         118 :                 zend_str_tolower_copy(lcname->val, name->val, name->len);
    4490             :         } else {
    4491             :                 zend_string_addref(name);
    4492             :         }
    4493             : 
    4494        7261 :         if (import_name && !zend_string_equals_str_ci(lcname, import_name)) {
    4495           1 :                 zend_error_noreturn(E_COMPILE_ERROR, "Cannot declare class %s "
    4496             :                         "because the name is already in use", name->val);
    4497             :         }
    4498             : 
    4499        7260 :         name = zend_new_interned_string(name TSRMLS_CC);
    4500        7260 :         lcname = zend_new_interned_string(lcname TSRMLS_CC);
    4501             : 
    4502        7260 :         ce->type = ZEND_USER_CLASS;
    4503        7260 :         ce->name = name;
    4504        7260 :         zend_initialize_class_data(ce, 1 TSRMLS_CC);
    4505             : 
    4506        7260 :         ce->ce_flags |= decl->flags;
    4507        7260 :         ce->info.user.filename = zend_get_compiled_filename(TSRMLS_C);
    4508        7260 :         ce->info.user.line_start = decl->start_lineno;
    4509        7260 :         ce->info.user.line_end = decl->end_lineno;
    4510        7260 :         if (decl->doc_comment) {
    4511         126 :                 ce->info.user.doc_comment = zend_string_copy(decl->doc_comment);
    4512             :         }
    4513             : 
    4514        7260 :         if (extends_ast) {
    4515        2324 :                 if (ZEND_CE_IS_TRAIT(ce)) {
    4516           1 :                         zend_error_noreturn(E_COMPILE_ERROR, "A trait (%s) cannot extend a class. "
    4517             :                                 "Traits can only be composed from other traits with the 'use' keyword. Error",
    4518             :                                 name->val);
    4519             :                 }
    4520             : 
    4521        2323 :                 if (!zend_is_const_default_class_ref(extends_ast)) {
    4522           2 :                         zend_string *extends_name = zend_ast_get_str(extends_ast);
    4523           2 :                         zend_error_noreturn(E_COMPILE_ERROR,
    4524             :                                 "Cannot use '%s' as class name as it is reserved", extends_name->val);
    4525             :                 }
    4526             : 
    4527        2321 :                 zend_compile_class_ref(&extends_node, extends_ast TSRMLS_CC);
    4528             :         }
    4529             : 
    4530        7257 :         opline = get_next_op(CG(active_op_array) TSRMLS_CC);
    4531        7257 :         zend_make_var_result(&declare_node, opline TSRMLS_CC);
    4532             : 
    4533             :         // TODO.AST drop this
    4534        7257 :         GET_NODE(&CG(implementing_class), opline->result);
    4535             : 
    4536        7257 :         opline->op2_type = IS_CONST;
    4537        7257 :         LITERAL_STR(opline->op2, lcname);
    4538             : 
    4539        7257 :         if (extends_ast) {
    4540        2321 :                 opline->opcode = ZEND_DECLARE_INHERITED_CLASS;
    4541        2321 :                 opline->extended_value = extends_node.u.op.var;
    4542             :         } else {
    4543        4936 :                 opline->opcode = ZEND_DECLARE_CLASS;
    4544             :         }
    4545             : 
    4546             :         {
    4547        7257 :                 zend_string *key = zend_build_runtime_definition_key(lcname, decl->lex_pos TSRMLS_CC);
    4548             : 
    4549        7257 :                 opline->op1_type = IS_CONST;
    4550        7257 :                 LITERAL_STR(opline->op1, key);
    4551             : 
    4552        7257 :                 zend_hash_update_ptr(CG(class_table), key, ce);
    4553             :         }
    4554             : 
    4555        7257 :         CG(active_class_entry) = ce;
    4556             : 
    4557        7257 :         if (implements_ast) {
    4558         328 :                 zend_compile_implements(&declare_node, implements_ast TSRMLS_CC);
    4559             :         }
    4560             : 
    4561        7254 :         zend_compile_stmt(stmt_ast TSRMLS_CC);
    4562             : 
    4563        7206 :         if (ce->constructor) {
    4564        1895 :                 ce->constructor->common.fn_flags |= ZEND_ACC_CTOR;
    4565        1895 :                 if (ce->constructor->common.fn_flags & ZEND_ACC_STATIC) {
    4566           4 :                         zend_error_noreturn(E_COMPILE_ERROR, "Constructor %s::%s() cannot be static",
    4567           4 :                                 ce->name->val, ce->constructor->common.function_name->val);
    4568             :                 }
    4569             :         }
    4570        7204 :         if (ce->destructor) {
    4571         143 :                 ce->destructor->common.fn_flags |= ZEND_ACC_DTOR;
    4572         143 :                 if (ce->destructor->common.fn_flags & ZEND_ACC_STATIC) {
    4573           2 :                         zend_error_noreturn(E_COMPILE_ERROR, "Destructor %s::%s() cannot be static",
    4574           2 :                                 ce->name->val, ce->destructor->common.function_name->val);
    4575             :                 }
    4576             :         }
    4577        7203 :         if (ce->clone) {
    4578          25 :                 ce->clone->common.fn_flags |= ZEND_ACC_CLONE;
    4579          25 :                 if (ce->clone->common.fn_flags & ZEND_ACC_STATIC) {
    4580           2 :                         zend_error_noreturn(E_COMPILE_ERROR, "Clone method %s::%s() cannot be static",
    4581           2 :                                 ce->name->val, ce->clone->common.function_name->val);
    4582             :                 }
    4583             :         }
    4584             : 
    4585             :         /* Check for traits and proceed like with interfaces.
    4586             :          * The only difference will be a combined handling of them in the end.
    4587             :          * Thus, we need another opcode here. */
    4588        7202 :         if (ce->num_traits > 0) {
    4589         175 :                 ce->traits = NULL;
    4590         175 :                 ce->num_traits = 0;
    4591         175 :                 ce->ce_flags |= ZEND_ACC_IMPLEMENT_TRAITS;
    4592             : 
    4593         175 :                 zend_emit_op(NULL, ZEND_BIND_TRAITS, &declare_node, NULL TSRMLS_CC);
    4594             :         }
    4595             : 
    4596       11617 :         if (!(ce->ce_flags & (ZEND_ACC_INTERFACE|ZEND_ACC_EXPLICIT_ABSTRACT_CLASS))
    4597        4415 :                 && (extends_ast || ce->num_interfaces > 0)
    4598             :         ) {
    4599        2542 :                 zend_verify_abstract_class(ce TSRMLS_CC);
    4600        2540 :                 if (ce->num_interfaces && !(ce->ce_flags & ZEND_ACC_IMPLEMENT_TRAITS)) {
    4601         270 :                         zend_emit_op(NULL, ZEND_VERIFY_ABSTRACT_CLASS, &declare_node, NULL TSRMLS_CC);
    4602             :                 }
    4603             :         }
    4604             : 
    4605             :         /* Inherit interfaces; reset number to zero, we need it for above check and
    4606             :          * will restore it during actual implementation.
    4607             :          * The ZEND_ACC_IMPLEMENT_INTERFACES flag disables double call to
    4608             :          * zend_verify_abstract_class() */
    4609        7200 :         if (ce->num_interfaces > 0) {
    4610         325 :                 ce->interfaces = NULL;
    4611         325 :                 ce->num_interfaces = 0;
    4612         325 :                 ce->ce_flags |= ZEND_ACC_IMPLEMENT_INTERFACES;
    4613             :         }
    4614             : 
    4615        7200 :         CG(active_class_entry) = NULL;
    4616             : }
    4617             : /* }}} */
    4618             : 
    4619          82 : static HashTable *zend_get_import_ht(uint32_t type TSRMLS_DC) /* {{{ */
    4620             : {
    4621          82 :         switch (type) {
    4622             :                 case T_CLASS:
    4623          51 :                         if (!CG(current_import)) {
    4624          40 :                                 CG(current_import) = emalloc(sizeof(HashTable));
    4625          40 :                                 zend_hash_init(CG(current_import), 8, NULL, str_dtor, 0);
    4626             :                         }
    4627          51 :                         return CG(current_import);
    4628             :                 case T_FUNCTION:
    4629          17 :                         if (!CG(current_import_function)) {
    4630          15 :                                 CG(current_import_function) = emalloc(sizeof(HashTable));
    4631          15 :                                 zend_hash_init(CG(current_import_function), 8, NULL, str_dtor, 0);
    4632             :                         }
    4633          17 :                         return CG(current_import_function);
    4634             :                 case T_CONST:
    4635          14 :                         if (!CG(current_import_const)) {
    4636          12 :                                 CG(current_import_const) = emalloc(sizeof(HashTable));
    4637          12 :                                 zend_hash_init(CG(current_import_const), 8, NULL, str_dtor, 0);
    4638             :                         }
    4639          14 :                         return CG(current_import_const);
    4640             :                 EMPTY_SWITCH_DEFAULT_CASE()
    4641             :         }
    4642           0 : }
    4643             : /* }}} */
    4644             : 
    4645           7 : static char *zend_get_use_type_str(uint32_t type) /* {{{ */
    4646             : {
    4647           7 :         switch (type) {
    4648             :                 case T_CLASS:
    4649           2 :                         return "";
    4650             :                 case T_FUNCTION:
    4651           3 :                         return " function";
    4652             :                 case T_CONST:
    4653           2 :                         return " const";
    4654             :                 EMPTY_SWITCH_DEFAULT_CASE()
    4655             :         }
    4656           0 : }
    4657             : /* }}} */
    4658             : 
    4659           5 : static void zend_check_already_in_use(uint32_t type, zend_string *old_name, zend_string *new_name, zend_string *check_name) /* {{{ */
    4660             : {
    4661           5 :         if (zend_string_equals_str_ci(old_name, check_name)) {
    4662           1 :                 return;
    4663             :         }
    4664             : 
    4665           4 :         zend_error_noreturn(E_COMPILE_ERROR, "Cannot use%s %s as %s because the name "
    4666             :                 "is already in use", zend_get_use_type_str(type), old_name->val, new_name->val);
    4667             : }
    4668             : /* }}} */
    4669             : 
    4670          82 : void zend_compile_use(zend_ast *ast TSRMLS_DC) /* {{{ */
    4671             : {
    4672          82 :         zend_ast_list *list = zend_ast_get_list(ast);
    4673             :         uint32_t i;
    4674          82 :         zend_string *current_ns = CG(current_namespace);
    4675          82 :         uint32_t type = ast->attr;
    4676          82 :         HashTable *current_import = zend_get_import_ht(type TSRMLS_CC);
    4677          82 :         zend_bool case_sensitive = type == T_CONST;
    4678             : 
    4679         164 :         for (i = 0; i < list->children; ++i) {
    4680          90 :                 zend_ast *use_ast = list->child[i];
    4681          90 :                 zend_ast *old_name_ast = use_ast->child[0];
    4682          90 :                 zend_ast *new_name_ast = use_ast->child[1];
    4683          90 :                 zend_string *old_name = zend_ast_get_str(old_name_ast);
    4684             :                 zend_string *new_name, *lookup_name;
    4685             : 
    4686          90 :                 if (new_name_ast) {
    4687          45 :                         new_name = zend_string_copy(zend_ast_get_str(new_name_ast));
    4688             :                 } else {
    4689             :                         const char *unqualified_name;
    4690             :                         size_t unqualified_name_len;
    4691          45 :                         if (zend_get_unqualified_name(old_name, &unqualified_name, &unqualified_name_len)) {
    4692             :                                 /* The form "use A\B" is eqivalent to "use A\B as B" */
    4693          70 :                                 new_name = zend_string_init(unqualified_name, unqualified_name_len, 0);
    4694             :                         } else {
    4695          10 :                                 new_name = zend_string_copy(old_name);
    4696             : 
    4697          10 :                                 if (!current_ns) {
    4698           1 :                                         if (type == T_CLASS && zend_string_equals_literal(new_name, "strict")) {
    4699           0 :                                                 zend_error_noreturn(E_COMPILE_ERROR,
    4700             :                                                         "You seem to be trying to use a different language...");
    4701             :                                         }
    4702             : 
    4703           1 :                                         zend_error(E_WARNING, "The use statement with non-compound name '%s' "
    4704             :                                                 "has no effect", new_name->val);
    4705             :                                 }
    4706             :                         }
    4707             :                 }
    4708             : 
    4709          90 :                 if (case_sensitive) {
    4710          17 :                         lookup_name = zend_string_copy(new_name);
    4711             :                 } else {
    4712         146 :                         lookup_name = zend_string_alloc(new_name->len, 0);
    4713          73 :                         zend_str_tolower_copy(lookup_name->val, new_name->val, new_name->len);
    4714             :                 }
    4715             : 
    4716         142 :                 if (type == T_CLASS && (zend_string_equals_literal(lookup_name, "self")
    4717          52 :                         || zend_string_equals_literal(lookup_name, "parent"))
    4718             :                 ) {
    4719           1 :                         zend_error_noreturn(E_COMPILE_ERROR, "Cannot use %s as %s because '%s' "
    4720             :                                 "is a special class name", old_name->val, new_name->val, new_name->val);
    4721             :                 }
    4722             : 
    4723          89 :                 if (current_ns) {
    4724          90 :                         zend_string *ns_name = zend_string_alloc(current_ns->len + 1 + new_name->len, 0);
    4725          45 :                         zend_str_tolower_copy(ns_name->val, current_ns->val, current_ns->len);
    4726          45 :                         ns_name->val[current_ns->len] = '\\';
    4727          45 :                         memcpy(ns_name->val + current_ns->len + 1, lookup_name->val, lookup_name->len);
    4728             : 
    4729          45 :                         if (zend_hash_exists(CG(class_table), ns_name)) {
    4730           2 :                                 zend_check_already_in_use(type, old_name, new_name, ns_name);
    4731             :                         }
    4732             : 
    4733             :                         zend_string_free(ns_name);
    4734             :                 } else {
    4735          44 :                         switch (type) {
    4736             :                                 case T_CLASS:
    4737             :                                 {
    4738          24 :                                         zend_class_entry *ce = zend_hash_find_ptr(CG(class_table), lookup_name);
    4739          17 :                                         if (ce && ce->type == ZEND_USER_CLASS
    4740           5 :                                                 && ce->info.user.filename == CG(compiled_filename)
    4741             :                                         ) {
    4742           1 :                                                 zend_check_already_in_use(type, old_name, new_name, lookup_name);
    4743             :                                         }
    4744          11 :                                         break;
    4745             :                                 }
    4746             :                                 case T_FUNCTION:
    4747             :                                 {
    4748          34 :                                         zend_function *fn = zend_hash_find_ptr(CG(function_table), lookup_name);
    4749          20 :                                         if (fn && fn->type == ZEND_USER_FUNCTION
    4750           3 :                                                 && fn->op_array.filename == CG(compiled_filename)
    4751             :                                         ) {
    4752           1 :                                                 zend_check_already_in_use(type, old_name, new_name, lookup_name);
    4753             :                                         }
    4754          16 :                                         break;
    4755             :                                 }
    4756             :                                 case T_CONST:
    4757             :                                 {
    4758          15 :                                         zend_string *filename = zend_hash_find_ptr(&CG(const_filenames), lookup_name);
    4759          15 :                                         if (filename && filename == CG(compiled_filename)) {
    4760           1 :                                                 zend_check_already_in_use(type, old_name, new_name, lookup_name);
    4761             :                                         }
    4762             :                                         break;
    4763             :                                 }
    4764             :                                 EMPTY_SWITCH_DEFAULT_CASE()
    4765             :                         }
    4766             :                 }
    4767             : 
    4768             :                 zend_string_addref(old_name);
    4769          85 :                 if (!zend_hash_add_ptr(current_import, lookup_name, old_name)) {
    4770           3 :                         zend_error_noreturn(E_COMPILE_ERROR, "Cannot use%s %s as %s because the name "
    4771             :                                 "is already in use", zend_get_use_type_str(type), old_name->val, new_name->val);
    4772             :                 }
    4773             : 
    4774             :                 zend_string_release(lookup_name);
    4775             :                 zend_string_release(new_name);
    4776             :         }
    4777          74 : }
    4778             : /* }}} */
    4779             : 
    4780         161 : void zend_compile_const_decl(zend_ast *ast TSRMLS_DC) /* {{{ */
    4781             : {
    4782         161 :         zend_ast_list *list = zend_ast_get_list(ast);
    4783             :         uint32_t i;
    4784         319 :         for (i = 0; i < list->children; ++i) {
    4785         162 :                 zend_ast *const_ast = list->child[i];
    4786         162 :                 zend_ast *name_ast = const_ast->child[0];
    4787         162 :                 zend_ast *value_ast = const_ast->child[1];
    4788         162 :                 zend_string *name = zend_ast_get_str(name_ast);
    4789             : 
    4790             :                 zend_string *import_name;
    4791             :                 znode name_node, value_node;
    4792         162 :                 zval *value_zv = &value_node.u.constant;
    4793             : 
    4794         162 :                 value_node.op_type = IS_CONST;
    4795         162 :                 zend_const_expr_to_zval(value_zv, value_ast TSRMLS_CC);
    4796             : 
    4797         160 :                 if (zend_lookup_reserved_const(name->val, name->len TSRMLS_CC)) {
    4798           1 :                         zend_error_noreturn(E_COMPILE_ERROR, "Cannot redeclare constant '%s'", name->val);
    4799             :                 }
    4800             : 
    4801         159 :                 name = zend_prefix_with_ns(name TSRMLS_CC);
    4802         159 :                 name = zend_new_interned_string(name TSRMLS_CC);
    4803             : 
    4804         160 :                 if (CG(current_import_const)
    4805           1 :                         && (import_name = zend_hash_find_ptr(CG(current_import_const), name))
    4806             :                 ) {
    4807           1 :                         if (!zend_string_equals(import_name, name)) {
    4808           1 :                                 zend_error(E_COMPILE_ERROR, "Cannot declare const %s because "
    4809             :                                         "the name is already in use", name->val);
    4810             :                         }
    4811             :                 }
    4812             : 
    4813         158 :                 name_node.op_type = IS_CONST;
    4814         158 :                 ZVAL_STR(&name_node.u.constant, name);
    4815             : 
    4816         158 :                 zend_emit_op(NULL, ZEND_DECLARE_CONST, &name_node, &value_node TSRMLS_CC);
    4817             : 
    4818         158 :                 zend_hash_add_ptr(&CG(const_filenames), name, CG(compiled_filename));
    4819             :         }
    4820         157 : }
    4821             : /* }}}*/
    4822             : 
    4823         201 : void zend_compile_namespace(zend_ast *ast TSRMLS_DC) /* {{{ */
    4824             : {
    4825         201 :         zend_ast *name_ast = ast->child[0];
    4826         201 :         zend_ast *stmt_ast = ast->child[1];
    4827             :         zend_string *name;
    4828         201 :         zend_bool with_bracket = stmt_ast != NULL;
    4829             : 
    4830             :         /* handle mixed syntax declaration or nested namespaces */
    4831         201 :         if (!CG(has_bracketed_namespaces)) {
    4832         172 :                 if (CG(current_namespace)) {
    4833             :                         /* previous namespace declarations were unbracketed */
    4834           7 :                         if (with_bracket) {
    4835           1 :                                 zend_error_noreturn(E_COMPILE_ERROR, "Cannot mix bracketed namespace declarations "
    4836             :                                         "with unbracketed namespace declarations");
    4837             :                         }
    4838             :                 }
    4839             :         } else {
    4840             :                 /* previous namespace declarations were bracketed */
    4841          29 :                 if (!with_bracket) {
    4842           1 :                         zend_error_noreturn(E_COMPILE_ERROR, "Cannot mix bracketed namespace declarations "
    4843             :                                 "with unbracketed namespace declarations");
    4844          28 :                 } else if (CG(current_namespace) || CG(in_namespace)) {
    4845           1 :                         zend_error_noreturn(E_COMPILE_ERROR, "Namespace declarations cannot be nested");
    4846             :                 }
    4847             :         }
    4848             : 
    4849         432 :         if (((!with_bracket && !CG(current_namespace))
    4850         234 :                  || (with_bracket && !CG(has_bracketed_namespaces))) && CG(active_op_array)->last > 0
    4851             :         ) {
    4852             :                 /* ignore ZEND_EXT_STMT and ZEND_TICKS */
    4853           3 :                 uint32_t num = CG(active_op_array)->last;
    4854          13 :                 while (num > 0 &&
    4855           3 :                        (CG(active_op_array)->opcodes[num-1].opcode == ZEND_EXT_STMT ||
    4856           3 :                         CG(active_op_array)->opcodes[num-1].opcode == ZEND_TICKS)) {
    4857           1 :                         --num;
    4858             :                 }
    4859           3 :                 if (num > 0) {
    4860           2 :                         zend_error_noreturn(E_COMPILE_ERROR, "Namespace declaration statement has to be "
    4861             :                                 "the very first statement in the script");
    4862             :                 }
    4863             :         }
    4864             : 
    4865         196 :         if (CG(current_namespace)) {
    4866           6 :                 zend_string_release(CG(current_namespace));
    4867             :         }
    4868             : 
    4869         196 :         if (name_ast) {
    4870         166 :                 name = zend_ast_get_str(name_ast);
    4871             : 
    4872         166 :                 if (ZEND_FETCH_CLASS_DEFAULT != zend_get_class_fetch_type(name)) {
    4873           1 :                         zend_error_noreturn(E_COMPILE_ERROR, "Cannot use '%s' as namespace name", name->val);
    4874             :                 }
    4875             : 
    4876         165 :                 CG(current_namespace) = zend_string_copy(name);
    4877             :         } else {
    4878          30 :                 CG(current_namespace) = NULL;
    4879             :         }
    4880             : 
    4881         195 :         zend_reset_import_tables(TSRMLS_C);
    4882             : 
    4883         195 :         CG(in_namespace) = 1;
    4884         195 :         if (with_bracket) {
    4885          68 :                 CG(has_bracketed_namespaces) = 1;
    4886             :         }
    4887             : 
    4888         195 :         if (stmt_ast) {
    4889          68 :                 zend_compile_top_stmt(stmt_ast TSRMLS_CC);
    4890          55 :                 zend_end_namespace(TSRMLS_C);
    4891             :         }
    4892         182 : }
    4893             : /* }}} */
    4894             : 
    4895         274 : void zend_compile_halt_compiler(zend_ast *ast TSRMLS_DC) /* {{{ */
    4896             : {
    4897         274 :         zend_ast *offset_ast = ast->child[0];
    4898         274 :         zend_long offset = Z_LVAL_P(zend_ast_get_zval(offset_ast));
    4899             : 
    4900             :         zend_string *filename, *name;
    4901         274 :         const char const_name[] = "__COMPILER_HALT_OFFSET__";
    4902             : 
    4903         274 :         if (CG(has_bracketed_namespaces) && CG(in_namespace)) {
    4904           0 :                 zend_error_noreturn(E_COMPILE_ERROR,
    4905             :                         "__HALT_COMPILER() can only be used from the outermost scope");
    4906             :         }
    4907             : 
    4908         274 :         filename = zend_get_compiled_filename(TSRMLS_C);
    4909         274 :         name = zend_mangle_property_name(const_name, sizeof(const_name) - 1,
    4910             :                 filename->val, filename->len, 0);
    4911             : 
    4912         274 :         zend_register_long_constant(name->val, name->len, offset, CONST_CS, 0 TSRMLS_CC);
    4913             :         zend_string_release(name);
    4914         274 : }
    4915             : /* }}} */
    4916             : 
    4917        8611 : static zend_bool zend_try_ct_eval_magic_const(zval *zv, zend_ast *ast TSRMLS_DC) /* {{{ */
    4918             : {
    4919        8611 :         zend_op_array *op_array = CG(active_op_array);
    4920        8611 :         zend_class_entry *ce = CG(active_class_entry);
    4921             : 
    4922        8611 :         switch (ast->attr) {
    4923             :                 case T_LINE:
    4924          15 :                         ZVAL_LONG(zv, ast->lineno);
    4925          15 :                         break;
    4926             :                 case T_FILE:
    4927        7182 :                         ZVAL_STR_COPY(zv, CG(compiled_filename));
    4928        7182 :                         break;
    4929             :                 case T_DIR:
    4930             :                 {
    4931         441 :                         zend_string *filename = CG(compiled_filename);
    4932         882 :                         zend_string *dirname = zend_string_init(filename->val, filename->len, 0);
    4933         441 :                         zend_dirname(dirname->val, dirname->len);
    4934             : 
    4935         441 :                         if (strcmp(dirname->val, ".") == 0) {
    4936           0 :                                 dirname = zend_string_realloc(dirname, MAXPATHLEN, 0);
    4937             : #if HAVE_GETCWD
    4938           0 :                                 VCWD_GETCWD(dirname->val, MAXPATHLEN);
    4939             : #elif HAVE_GETWD
    4940             :                                 VCWD_GETWD(dirname->val);
    4941             : #endif
    4942             :                         }
    4943             : 
    4944         441 :                         dirname->len = strlen(dirname->val);
    4945         441 :                         ZVAL_STR(zv, dirname);
    4946         441 :                         break;
    4947             :                 }
    4948             :                 case T_FUNC_C:
    4949         208 :                         if (op_array && op_array->function_name) {
    4950         103 :                                 ZVAL_STR_COPY(zv, op_array->function_name);
    4951             :                         } else {
    4952           2 :                                 ZVAL_EMPTY_STRING(zv);
    4953             :                         }
    4954         105 :                         break;
    4955             :                 case T_METHOD_C:
    4956         747 :                         if (ce) {
    4957        1449 :                                 if (op_array && op_array->function_name) {
    4958         724 :                                         ZVAL_NEW_STR(zv, zend_concat3(ce->name->val, ce->name->len, "::", 2,
    4959             :                                                 op_array->function_name->val, op_array->function_name->len));
    4960             :                                 } else {
    4961           1 :                                         ZVAL_STR_COPY(zv, ce->name);
    4962             :                                 }
    4963          43 :                         } else if (op_array && op_array->function_name) {
    4964          21 :                                 ZVAL_STR_COPY(zv, op_array->function_name);
    4965             :                         } else {
    4966           1 :                                 ZVAL_EMPTY_STRING(zv);
    4967             :                         }
    4968         747 :                         break;
    4969             :                 case T_CLASS_C:
    4970          82 :                         if (ce) {
    4971          81 :                                 if (ZEND_CE_IS_TRAIT(ce)) {
    4972           5 :                                         return 0;
    4973             :                                 } else {
    4974          76 :                                         ZVAL_STR_COPY(zv, ce->name);
    4975             :                                 }
    4976             :                         } else {
    4977           1 :                                 ZVAL_EMPTY_STRING(zv);
    4978             :                         }
    4979          77 :                         break;
    4980             :                 case T_TRAIT_C:
    4981           6 :                         if (ce && ZEND_CE_IS_TRAIT(ce)) {
    4982           1 :                                 ZVAL_STR_COPY(zv, ce->name);
    4983             :                         } else {
    4984           4 :                                 ZVAL_EMPTY_STRING(zv);
    4985             :                         }
    4986           5 :                         break;
    4987             :                 case T_NS_C:
    4988          34 :                         if (CG(current_namespace)) {
    4989          25 :                                 ZVAL_STR_COPY(zv, CG(current_namespace));
    4990             :                         } else {
    4991           9 :                                 ZVAL_EMPTY_STRING(zv);
    4992             :                         }
    4993             :                         break;
    4994             :                 EMPTY_SWITCH_DEFAULT_CASE()
    4995             :         }
    4996             : 
    4997        8606 :         return 1;
    4998             : }
    4999             : /* }}} */
    5000             : 
    5001        3022 : static inline void zend_ct_eval_binary_op(zval *result, uint32_t opcode, zval *op1, zval *op2 TSRMLS_DC) /* {{{ */
    5002             : {
    5003        3022 :         binary_op_type fn = get_binary_op(opcode);
    5004        3022 :         fn(result, op1, op2 TSRMLS_CC);
    5005        3022 : }
    5006             : /* }}} */
    5007             : 
    5008        6545 : static inline void zend_ct_eval_unary_pm(zval *result, zend_ast_kind kind, zval *op TSRMLS_DC) /* {{{ */
    5009             : {
    5010             :         binary_op_type fn = kind == ZEND_AST_UNARY_PLUS
    5011        6545 :                 ? add_function : sub_function;
    5012             : 
    5013             :         zval left;
    5014        6545 :         ZVAL_LONG(&left, 0);
    5015        6545 :         fn(result, &left, op TSRMLS_CC);
    5016        6545 : }
    5017             : /* }}} */
    5018             : 
    5019          16 : static inline void zend_ct_eval_greater(zval *result, zend_ast_kind kind, zval *op1, zval *op2 TSRMLS_DC) /* {{{ */
    5020             : {
    5021             :         binary_op_type fn = kind == ZEND_AST_GREATER
    5022          16 :                 ? is_smaller_function : is_smaller_or_equal_function;
    5023          16 :         fn(result, op2, op1 TSRMLS_CC);
    5024          16 : }
    5025             : /* }}} */
    5026             : 
    5027       25631 : static zend_bool zend_try_ct_eval_array(zval *result, zend_ast *ast TSRMLS_DC) /* {{{ */
    5028             : {
    5029       25631 :         zend_ast_list *list = zend_ast_get_list(ast);
    5030             :         uint32_t i;
    5031             : 
    5032             :         /* First ensure that *all* child nodes are constant and by-val */
    5033      105473 :         for (i = 0; i < list->children; ++i) {
    5034       84923 :                 zend_ast *elem_ast = list->child[i];
    5035       84923 :                 zend_bool by_ref = elem_ast->attr;
    5036       84923 :                 zend_eval_const_expr(&elem_ast->child[0] TSRMLS_CC);
    5037       84923 :                 zend_eval_const_expr(&elem_ast->child[1] TSRMLS_CC);
    5038             : 
    5039      269492 :                 if (by_ref || elem_ast->child[0]->kind != ZEND_AST_ZVAL
    5040      184569 :                         || (elem_ast->child[1] && elem_ast->child[1]->kind != ZEND_AST_ZVAL)
    5041             :                 ) {
    5042        5081 :                         return 0;
    5043             :                 }
    5044             :         }
    5045             : 
    5046       20550 :         array_init_size(result, list->children);
    5047       85106 :         for (i = 0; i < list->children; ++i) {
    5048       64556 :                 zend_ast *elem_ast = list->child[i];
    5049       64556 :                 zend_ast *value_ast = elem_ast->child[0];
    5050       64556 :                 zend_ast *key_ast = elem_ast->child[1];
    5051             : 
    5052       64556 :                 zval *value = zend_ast_get_zval(value_ast);
    5053       64556 :                 if (Z_REFCOUNTED_P(value)) Z_ADDREF_P(value);
    5054             : 
    5055       64556 :                 if (key_ast) {
    5056       15900 :                         zval *key = zend_ast_get_zval(key_ast);
    5057       15900 :                         switch (Z_TYPE_P(key)) {
    5058             :                                 case IS_LONG:
    5059        2720 :                                         zend_hash_index_update(Z_ARRVAL_P(result), Z_LVAL_P(key), value);
    5060        2720 :                                         break;
    5061             :                                 case IS_STRING:
    5062       12655 :                                         zend_symtable_update(Z_ARRVAL_P(result), Z_STR_P(key), value);
    5063       12655 :                                         break;
    5064             :                                 case IS_DOUBLE:
    5065         524 :                                         zend_hash_index_update(Z_ARRVAL_P(result),
    5066             :                                                 zend_dval_to_lval(Z_DVAL_P(key)), value);
    5067         262 :                                         break;
    5068             :                                 case IS_FALSE:
    5069          72 :                                         zend_hash_index_update(Z_ARRVAL_P(result), 0, value);
    5070          72 :                                         break;
    5071             :                                 case IS_TRUE:
    5072          76 :                                         zend_hash_index_update(Z_ARRVAL_P(result), 1, value);
    5073          76 :                                         break;
    5074             :                                 case IS_NULL:
    5075         115 :                                         zend_hash_update(Z_ARRVAL_P(result), STR_EMPTY_ALLOC(), value);
    5076         115 :                                         break;
    5077             :                                 default:
    5078           0 :                                         zend_error(E_COMPILE_ERROR, "Illegal offset type");
    5079             :                                         break;
    5080             :                         }
    5081             :                 } else {
    5082       48656 :                         zend_hash_next_index_insert(Z_ARRVAL_P(result), value);
    5083             :                 }
    5084             :         }
    5085             : 
    5086       20550 :         return 1;
    5087             : }
    5088             : /* }}} */
    5089             : 
    5090       75948 : void zend_compile_binary_op(znode *result, zend_ast *ast TSRMLS_DC) /* {{{ */
    5091             : {
    5092       75948 :         zend_ast *left_ast = ast->child[0];
    5093       75948 :         zend_ast *right_ast = ast->child[1];
    5094       75948 :         uint32_t opcode = ast->attr;
    5095             : 
    5096             :         znode left_node, right_node;
    5097       75948 :         zend_compile_expr(&left_node, left_ast TSRMLS_CC);
    5098       75948 :         zend_compile_expr(&right_node, right_ast TSRMLS_CC);
    5099             : 
    5100       75948 :         if (left_node.op_type == IS_CONST && right_node.op_type == IS_CONST) {
    5101        2795 :                 result->op_type = IS_CONST;
    5102        2795 :                 zend_ct_eval_binary_op(&result->u.constant, opcode,
    5103             :                         &left_node.u.constant, &right_node.u.constant TSRMLS_CC);
    5104        2795 :                 zval_ptr_dtor(&left_node.u.constant);
    5105        2795 :                 zval_ptr_dtor(&right_node.u.constant);
    5106        2795 :                 return;
    5107             :         }
    5108             : 
    5109       73153 :         zend_emit_op_tmp(result, opcode, &left_node, &right_node TSRMLS_CC);
    5110             : }
    5111             : /* }}} */
    5112             : 
    5113             : /* We do not use zend_compile_binary_op for this because we want to retain the left-to-right
    5114             :  * evaluation order. */
    5115        1107 : void zend_compile_greater(znode *result, zend_ast *ast TSRMLS_DC) /* {{{ */
    5116             : {
    5117        1107 :         zend_ast *left_ast = ast->child[0];
    5118        1107 :         zend_ast *right_ast = ast->child[1];
    5119             :         znode left_node, right_node;
    5120             : 
    5121             :         ZEND_ASSERT(ast->kind == ZEND_AST_GREATER || ast->kind == ZEND_AST_GREATER_EQUAL);
    5122             : 
    5123        1107 :         zend_compile_expr(&left_node, left_ast TSRMLS_CC);
    5124        1107 :         zend_compile_expr(&right_node, right_ast TSRMLS_CC);
    5125             : 
    5126        1107 :         if (left_node.op_type == IS_CONST && right_node.op_type == IS_CONST) {
    5127          14 :                 result->op_type = IS_CONST;
    5128          14 :                 zend_ct_eval_greater(&result->u.constant, ast->kind,
    5129             :                         &left_node.u.constant, &right_node.u.constant TSRMLS_CC);
    5130          14 :                 zval_ptr_dtor(&left_node.u.constant);
    5131          14 :                 zval_ptr_dtor(&right_node.u.constant);
    5132          14 :                 return;
    5133             :         }
    5134             : 
    5135        1093 :         zend_emit_op_tmp(result,
    5136        1093 :                 ast->kind == ZEND_AST_GREATER ? ZEND_IS_SMALLER : ZEND_IS_SMALLER_OR_EQUAL,
    5137             :                 &right_node, &left_node TSRMLS_CC);
    5138             : }
    5139             : /* }}} */
    5140             : 
    5141       29204 : void zend_compile_unary_op(znode *result, zend_ast *ast TSRMLS_DC) /* {{{ */
    5142             : {
    5143       29204 :         zend_ast *expr_ast = ast->child[0];
    5144       29204 :         uint32_t opcode = ast->attr;
    5145             : 
    5146             :         znode expr_node;
    5147       29204 :         zend_compile_expr(&expr_node, expr_ast TSRMLS_CC);
    5148             : 
    5149       29204 :         zend_emit_op_tmp(result, opcode, &expr_node, NULL TSRMLS_CC);
    5150       29204 : }
    5151             : /* }}} */
    5152             : 
    5153        3175 : void zend_compile_unary_pm(znode *result, zend_ast *ast TSRMLS_DC) /* {{{ */
    5154             : {
    5155        3175 :         zend_ast *expr_ast = ast->child[0];
    5156             :         znode zero_node, expr_node;
    5157             : 
    5158             :         ZEND_ASSERT(ast->kind == ZEND_AST_UNARY_PLUS || ast->kind == ZEND_AST_UNARY_MINUS);
    5159             : 
    5160        3175 :         zend_compile_expr(&expr_node, expr_ast TSRMLS_CC);
    5161             : 
    5162        3175 :         if (expr_node.op_type == IS_CONST) {
    5163        3131 :                 result->op_type = IS_CONST;
    5164        3131 :                 zend_ct_eval_unary_pm(&result->u.constant, ast->kind, &expr_node.u.constant TSRMLS_CC);
    5165        3131 :                 zval_ptr_dtor(&expr_node.u.constant);
    5166        3131 :                 return;
    5167             :         }
    5168             : 
    5169          44 :         zero_node.op_type = IS_CONST;
    5170          44 :         ZVAL_LONG(&zero_node.u.constant, 0);
    5171             : 
    5172          44 :         zend_emit_op_tmp(result, ast->kind == ZEND_AST_UNARY_PLUS ? ZEND_ADD : ZEND_SUB,
    5173             :                 &zero_node, &expr_node TSRMLS_CC);
    5174             : }
    5175             : /* }}} */
    5176             : 
    5177       11713 : void zend_compile_short_circuiting(znode *result, zend_ast *ast TSRMLS_DC) /* {{{ */
    5178             : {
    5179       11713 :         zend_ast *left_ast = ast->child[0];
    5180       11713 :         zend_ast *right_ast = ast->child[1];
    5181             : 
    5182             :         znode left_node, right_node;
    5183             :         zend_op *opline_jmpz, *opline_bool;
    5184             :         uint32_t opnum_jmpz;
    5185             : 
    5186             :         ZEND_ASSERT(ast->kind == ZEND_AST_AND || ast->kind == ZEND_AST_OR);
    5187             : 
    5188       11713 :         zend_compile_expr(&left_node, left_ast TSRMLS_CC);
    5189             : 
    5190       11713 :         opnum_jmpz = get_next_op_number(CG(active_op_array));
    5191       11713 :         opline_jmpz = zend_emit_op(NULL, ast->kind == ZEND_AST_AND ? ZEND_JMPZ_EX : ZEND_JMPNZ_EX,
    5192             :                 &left_node, NULL TSRMLS_CC);
    5193             : 
    5194       11713 :         if (left_node.op_type == IS_TMP_VAR) {
    5195        9251 :                 SET_NODE(opline_jmpz->result, &left_node);
    5196             :         } else {
    5197        2462 :                 opline_jmpz->result.var = get_temporary_variable(CG(active_op_array));
    5198        2462 :                 opline_jmpz->result_type = IS_TMP_VAR;
    5199             :         }
    5200       11713 :         GET_NODE(result, opline_jmpz->result);
    5201             : 
    5202       11713 :         zend_compile_expr(&right_node, right_ast TSRMLS_CC);
    5203             : 
    5204       11713 :         opline_bool = zend_emit_op(NULL, ZEND_BOOL, &right_node, NULL TSRMLS_CC);
    5205       11713 :         SET_NODE(opline_bool->result, result);
    5206             : 
    5207       11713 :         zend_update_jump_target_to_next(opnum_jmpz TSRMLS_CC);
    5208       11713 : }
    5209             : /* }}} */
    5210             : 
    5211        5457 : void zend_compile_post_incdec(znode *result, zend_ast *ast TSRMLS_DC) /* {{{ */
    5212             : {
    5213        5457 :         zend_ast *var_ast = ast->child[0];
    5214             :         ZEND_ASSERT(ast->kind == ZEND_AST_POST_INC || ast->kind == ZEND_AST_POST_DEC);
    5215             : 
    5216        5457 :         if (var_ast->kind == ZEND_AST_PROP) {
    5217          51 :                 zend_op *opline = zend_compile_prop_common(NULL, var_ast, BP_VAR_RW TSRMLS_CC);
    5218          51 :                 opline->opcode = ast->kind == ZEND_AST_POST_INC ? ZEND_POST_INC_OBJ : ZEND_POST_DEC_OBJ;
    5219          51 :                 zend_make_tmp_result(result, opline TSRMLS_CC);
    5220             :         } else {
    5221             :                 znode var_node;
    5222        5406 :                 zend_compile_var(&var_node, var_ast, BP_VAR_RW TSRMLS_CC);
    5223        5406 :                 zend_emit_op_tmp(result, ast->kind == ZEND_AST_POST_INC ? ZEND_POST_INC : ZEND_POST_DEC,
    5224             :                         &var_node, NULL TSRMLS_CC);
    5225             :         }
    5226        5457 : }
    5227             : /* }}} */
    5228             : 
    5229         532 : void zend_compile_pre_incdec(znode *result, zend_ast *ast TSRMLS_DC) /* {{{ */
    5230             : {
    5231         532 :         zend_ast *var_ast = ast->child[0];
    5232             :         ZEND_ASSERT(ast->kind == ZEND_AST_PRE_INC || ast->kind == ZEND_AST_PRE_DEC);
    5233             : 
    5234         532 :         if (var_ast->kind == ZEND_AST_PROP) {
    5235          27 :                 zend_op *opline = zend_compile_prop_common(result, var_ast, BP_VAR_RW TSRMLS_CC);
    5236          27 :                 opline->opcode = ast->kind == ZEND_AST_PRE_INC ? ZEND_PRE_INC_OBJ : ZEND_PRE_DEC_OBJ;
    5237             :         } else {
    5238             :                 znode var_node;
    5239         505 :                 zend_compile_var(&var_node, var_ast, BP_VAR_RW TSRMLS_CC);
    5240         505 :                 zend_emit_op(result, ast->kind == ZEND_AST_PRE_INC ? ZEND_PRE_INC : ZEND_PRE_DEC,
    5241             :                         &var_node, NULL TSRMLS_CC);
    5242             :         }
    5243         532 : }
    5244             : /* }}} */
    5245             : 
    5246        6539 : void zend_compile_cast(znode *result, zend_ast *ast TSRMLS_DC) /* {{{ */
    5247             : {
    5248        6539 :         zend_ast *expr_ast = ast->child[0];
    5249             :         znode expr_node;
    5250             :         zend_op *opline;
    5251             : 
    5252        6539 :         zend_compile_expr(&expr_node, expr_ast TSRMLS_CC);
    5253             : 
    5254        6539 :         opline = zend_emit_op_tmp(result, ZEND_CAST, &expr_node, NULL TSRMLS_CC);
    5255        6539 :         opline->extended_value = ast->attr;
    5256        6539 : }
    5257             : /* }}} */
    5258             : 
    5259          37 : static void zend_compile_shorthand_conditional(znode *result, zend_ast *ast TSRMLS_DC) /* {{{ */
    5260             : {
    5261          37 :         zend_ast *cond_ast = ast->child[0];
    5262          37 :         zend_ast *false_ast = ast->child[2];
    5263             : 
    5264             :         znode cond_node, false_node;
    5265             :         zend_op *opline_jmp_set, *opline_qm_assign;
    5266             :         uint32_t opnum_jmp_set;
    5267             : 
    5268             :         ZEND_ASSERT(ast->child[1] == NULL);
    5269             : 
    5270          37 :         zend_compile_expr(&cond_node, cond_ast TSRMLS_CC);
    5271             : 
    5272          37 :         opnum_jmp_set = get_next_op_number(CG(active_op_array));
    5273          37 :         zend_emit_op_tmp(result, ZEND_JMP_SET, &cond_node, NULL TSRMLS_CC);
    5274             : 
    5275          37 :         zend_compile_expr(&false_node, false_ast TSRMLS_CC);
    5276             : 
    5277          37 :         opline_jmp_set = &CG(active_op_array)->opcodes[opnum_jmp_set];
    5278          37 :         opline_jmp_set->op2.opline_num = get_next_op_number(CG(active_op_array)) + 1;
    5279          37 :         opline_qm_assign = zend_emit_op_tmp(NULL, ZEND_QM_ASSIGN, &false_node, NULL TSRMLS_CC);
    5280          37 :         SET_NODE(opline_qm_assign->result, result);
    5281          37 : }
    5282             : /* }}} */
    5283             : 
    5284       27218 : void zend_compile_conditional(znode *result, zend_ast *ast TSRMLS_DC) /* {{{ */
    5285             : {
    5286       27218 :         zend_ast *cond_ast = ast->child[0];
    5287       27218 :         zend_ast *true_ast = ast->child[1];
    5288       27218 :         zend_ast *false_ast = ast->child[2];
    5289             : 
    5290             :         znode cond_node, true_node, false_node;
    5291             :         zend_op *opline_qm_assign1, *opline_qm_assign2;
    5292             :         uint32_t opnum_jmpz, opnum_jmp, opnum_qm_assign1;
    5293             : 
    5294       27218 :         if (!true_ast) {
    5295          37 :                 zend_compile_shorthand_conditional(result, ast TSRMLS_CC);
    5296          37 :                 return;
    5297             :         }
    5298             :         
    5299       27181 :         zend_compile_expr(&cond_node, cond_ast TSRMLS_CC);
    5300             : 
    5301       27181 :         opnum_jmpz = zend_emit_cond_jump(ZEND_JMPZ, &cond_node, 0 TSRMLS_CC);
    5302             : 
    5303       27181 :         zend_compile_expr(&true_node, true_ast TSRMLS_CC);
    5304             : 
    5305       27181 :         opnum_qm_assign1 = get_next_op_number(CG(active_op_array));
    5306       27181 :         zend_emit_op_tmp(result, ZEND_QM_ASSIGN, &true_node, NULL TSRMLS_CC);
    5307             : 
    5308       27181 :         opnum_jmp = zend_emit_jump(0 TSRMLS_CC);
    5309             : 
    5310       27181 :         zend_update_jump_target_to_next(opnum_jmpz TSRMLS_CC);
    5311             : 
    5312       27181 :         zend_compile_expr(&false_node, false_ast TSRMLS_CC);
    5313             : 
    5314       27181 :         opline_qm_assign1 = &CG(active_op_array)->opcodes[opnum_qm_assign1];
    5315       27181 :         opline_qm_assign2 = zend_emit_op(NULL, opline_qm_assign1->opcode, &false_node, NULL TSRMLS_CC);
    5316       27181 :         SET_NODE(opline_qm_assign2->result, result);
    5317             : 
    5318       27181 :         zend_update_jump_target_to_next(opnum_jmp TSRMLS_CC);
    5319             : }
    5320             : /* }}} */
    5321             : 
    5322          16 : void zend_compile_coalesce(znode *result, zend_ast *ast TSRMLS_DC) /* {{{ */
    5323             : {
    5324          16 :         zend_ast *expr_ast = ast->child[0];
    5325          16 :         zend_ast *default_ast = ast->child[1];
    5326             : 
    5327             :         znode expr_node, default_node;
    5328             :         zend_op *opline;
    5329             :         uint32_t opnum;
    5330             : 
    5331          16 :         zend_compile_var(&expr_node, expr_ast, BP_VAR_IS TSRMLS_CC);
    5332             : 
    5333          16 :         opnum = get_next_op_number(CG(active_op_array));
    5334          16 :         zend_emit_op_tmp(result, ZEND_COALESCE, &expr_node, NULL TSRMLS_CC);
    5335             : 
    5336          16 :         zend_compile_expr(&default_node, default_ast TSRMLS_CC);
    5337             : 
    5338          16 :         opline = zend_emit_op_tmp(NULL, ZEND_QM_ASSIGN, &default_node, NULL TSRMLS_CC);
    5339          16 :         SET_NODE(opline->result, result);
    5340             : 
    5341          16 :         opline = &CG(active_op_array)->opcodes[opnum];
    5342          16 :         opline->op2.opline_num = get_next_op_number(CG(active_op_array));
    5343          16 : }
    5344             : /* }}} */
    5345             : 
    5346        3382 : void zend_compile_print(znode *result, zend_ast *ast TSRMLS_DC) /* {{{ */
    5347             : {
    5348        3382 :         zend_ast *expr_ast = ast->child[0];
    5349             : 
    5350             :         znode expr_node;
    5351        3382 :         zend_compile_expr(&expr_node, expr_ast TSRMLS_CC);
    5352             : 
    5353        3382 :         zend_emit_op_tmp(result, ZEND_PRINT, &expr_node, NULL TSRMLS_CC);
    5354        3382 : }
    5355             : /* }}} */
    5356             : 
    5357       14351 : void zend_compile_exit(znode *result, zend_ast *ast TSRMLS_DC) /* {{{ */
    5358             : {
    5359       14351 :         zend_ast *expr_ast = ast->child[0];
    5360             : 
    5361       14351 :         if (expr_ast) {
    5362             :                 znode expr_node;
    5363       13817 :                 zend_compile_expr(&expr_node, expr_ast TSRMLS_CC);
    5364       13817 :                 zend_emit_op(NULL, ZEND_EXIT, &expr_node, NULL TSRMLS_CC);
    5365             :         } else {
    5366         534 :                 zend_emit_op(NULL, ZEND_EXIT, NULL, NULL TSRMLS_CC);
    5367             :         }
    5368             : 
    5369       14351 :         result->op_type = IS_CONST;
    5370       14351 :         ZVAL_BOOL(&result->u.constant, 1);
    5371       14351 : }
    5372             : /* }}} */
    5373             : 
    5374         121 : void zend_compile_yield(znode *result, zend_ast *ast TSRMLS_DC) /* {{{ */
    5375             : {
    5376         121 :         zend_ast *value_ast = ast->child[0];
    5377         121 :         zend_ast *key_ast = ast->child[1];
    5378             : 
    5379             :         znode value_node, key_node;
    5380         121 :         znode *value_node_ptr = NULL, *key_node_ptr = NULL;
    5381             :         zend_op *opline;
    5382         121 :         zend_bool returns_by_ref = (CG(active_op_array)->fn_flags & ZEND_ACC_RETURN_REFERENCE) != 0;
    5383             : 
    5384         121 :         if (!CG(active_op_array)->function_name) {
    5385           1 :                 zend_error_noreturn(E_COMPILE_ERROR,
    5386             :                         "The \"yield\" expression can only be used inside a function");
    5387             :         }
    5388             : 
    5389         120 :         CG(active_op_array)->fn_flags |= ZEND_ACC_GENERATOR;
    5390             : 
    5391         120 :         if (key_ast) {
    5392          17 :                 zend_compile_expr(&key_node, key_ast TSRMLS_CC);
    5393          17 :                 key_node_ptr = &key_node;
    5394             :         }
    5395             : 
    5396         120 :         if (value_ast) {
    5397          89 :                 if (returns_by_ref && zend_is_variable(value_ast) && !zend_is_call(value_ast)) {
    5398           5 :                         zend_compile_var(&value_node, value_ast, BP_VAR_REF TSRMLS_CC);
    5399             :                 } else {
    5400          79 :                         zend_compile_expr(&value_node, value_ast TSRMLS_CC);
    5401             :                 }
    5402          84 :                 value_node_ptr = &value_node;
    5403             :         }
    5404             : 
    5405         120 :         opline = zend_emit_op(result, ZEND_YIELD, value_node_ptr, key_node_ptr TSRMLS_CC);
    5406             : 
    5407         120 :         if (value_ast && returns_by_ref && zend_is_call(value_ast)) {
    5408           2 :                 opline->extended_value = ZEND_RETURNS_FUNCTION;
    5409             :         }
    5410         120 : }
    5411             : /* }}} */
    5412             : 
    5413          65 : void zend_compile_instanceof(znode *result, zend_ast *ast TSRMLS_DC) /* {{{ */
    5414             : {
    5415          65 :         zend_ast *obj_ast = ast->child[0];
    5416          65 :         zend_ast *class_ast = ast->child[1];
    5417             : 
    5418             :         znode obj_node, class_node;
    5419             :         zend_op *opline;
    5420             : 
    5421          65 :         zend_compile_expr(&obj_node, obj_ast TSRMLS_CC);
    5422          65 :         if (obj_node.op_type == IS_CONST) {
    5423           1 :                 zend_error_noreturn(E_COMPILE_ERROR,
    5424             :                         "instanceof expects an object instance, constant given");
    5425             :         }
    5426             : 
    5427          64 :         if (zend_is_const_default_class_ref(class_ast)) {
    5428          60 :                 class_node.op_type = IS_CONST;
    5429          60 :                 ZVAL_STR(&class_node.u.constant, zend_resolve_class_name_ast(class_ast TSRMLS_CC));
    5430             :         } else {
    5431           4 :                 opline = zend_compile_class_ref(&class_node, class_ast TSRMLS_CC);
    5432           4 :                 opline->extended_value |= ZEND_FETCH_CLASS_NO_AUTOLOAD;
    5433             :         }
    5434             : 
    5435          64 :         opline = zend_emit_op_tmp(result, ZEND_INSTANCEOF, &obj_node, NULL TSRMLS_CC);
    5436             : 
    5437          64 :         if (class_node.op_type == IS_CONST) {
    5438          60 :                 opline->op2_type = IS_CONST;
    5439          60 :                 opline->op2.constant = zend_add_class_name_literal(
    5440             :                         CG(active_op_array), Z_STR(class_node.u.constant) TSRMLS_CC);
    5441             :         } else {
    5442           4 :                 SET_NODE(opline->op2, &class_node);
    5443             :         }
    5444          64 : }
    5445             : /* }}} */
    5446             : 
    5447       10716 : void zend_compile_include_or_eval(znode *result, zend_ast *ast TSRMLS_DC) /* {{{ */
    5448             : {
    5449       10716 :         zend_ast *expr_ast = ast->child[0];
    5450             :         znode expr_node;
    5451             :         zend_op *opline;
    5452             : 
    5453       10716 :         zend_do_extended_fcall_begin(TSRMLS_C);
    5454       10716 :         zend_compile_expr(&expr_node, expr_ast TSRMLS_CC);
    5455             : 
    5456       10716 :         opline = zend_emit_op(result, ZEND_INCLUDE_OR_EVAL, &expr_node, NULL TSRMLS_CC);
    5457       10716 :         opline->extended_value = ast->attr;
    5458             : 
    5459       10716 :         zend_do_extended_fcall_end(TSRMLS_C);
    5460       10716 : }
    5461             : /* }}} */
    5462             : 
    5463       13249 : void zend_compile_isset_or_empty(znode *result, zend_ast *ast TSRMLS_DC) /* {{{ */
    5464             : {
    5465       13249 :         zend_ast *var_ast = ast->child[0];
    5466             : 
    5467             :         znode var_node;
    5468             :         zend_op *opline;
    5469             : 
    5470             :         ZEND_ASSERT(ast->kind == ZEND_AST_ISSET || ast->kind == ZEND_AST_EMPTY);
    5471             : 
    5472       13249 :         if (!zend_is_variable(var_ast) || zend_is_call(var_ast)) {
    5473          16 :                 if (ast->kind == ZEND_AST_EMPTY) {
    5474             :                         /* empty(expr) can be transformed to !expr */
    5475          14 :                         zend_ast *not_ast = zend_ast_create_ex(ZEND_AST_UNARY_OP, ZEND_BOOL_NOT, var_ast);
    5476          14 :                         zend_compile_expr(result, not_ast TSRMLS_CC);
    5477          14 :                         return;
    5478             :                 } else {
    5479           2 :                         zend_error_noreturn(E_COMPILE_ERROR,
    5480             :                                 "Cannot use isset() on the result of an expression "
    5481             :                                 "(you can use \"null !== expression\" instead)");
    5482             :                 }
    5483             :         }
    5484             : 
    5485       13233 :         switch (var_ast->kind) {
    5486             :                 case ZEND_AST_VAR:
    5487        3737 :                         if (zend_try_compile_cv(&var_node, var_ast TSRMLS_CC) == SUCCESS) {
    5488        3717 :                                 opline = zend_emit_op(result, ZEND_ISSET_ISEMPTY_VAR, &var_node, NULL TSRMLS_CC);
    5489        3717 :                                 opline->extended_value = ZEND_FETCH_LOCAL | ZEND_QUICK_SET;
    5490             :                         } else {
    5491          20 :                                 opline = zend_compile_simple_var_no_cv(result, var_ast, BP_VAR_IS TSRMLS_CC);
    5492          20 :                                 opline->opcode = ZEND_ISSET_ISEMPTY_VAR;
    5493             :                         }
    5494        3737 :                         break;
    5495             :                 case ZEND_AST_DIM:
    5496        8652 :                         opline = zend_compile_dim_common(result, var_ast, BP_VAR_IS TSRMLS_CC);
    5497        8651 :                         opline->opcode = ZEND_ISSET_ISEMPTY_DIM_OBJ;
    5498        8651 :                         break;
    5499             :                 case ZEND_AST_PROP:
    5500         734 :                         opline = zend_compile_prop_common(result, var_ast, BP_VAR_IS TSRMLS_CC);
    5501         734 :                         opline->opcode = ZEND_ISSET_ISEMPTY_PROP_OBJ;
    5502         734 :                         break;
    5503             :                 case ZEND_AST_STATIC_PROP:
    5504         110 :                         opline = zend_compile_static_prop_common(result, var_ast, BP_VAR_IS TSRMLS_CC);
    5505         110 :                         opline->opcode = ZEND_ISSET_ISEMPTY_VAR;
    5506             :                         break;
    5507             :                 EMPTY_SWITCH_DEFAULT_CASE()
    5508             :         }
    5509             : 
    5510       13232 :         result->op_type = opline->result_type = IS_TMP_VAR;
    5511       13232 :         opline->extended_value |= ast->kind == ZEND_AST_ISSET ? ZEND_ISSET : ZEND_ISEMPTY;
    5512             : }
    5513             : /* }}} */
    5514             : 
    5515        5519 : void zend_compile_silence(znode *result, zend_ast *ast TSRMLS_DC) /* {{{ */
    5516             : {
    5517        5519 :         zend_ast *expr_ast = ast->child[0];
    5518             :         znode silence_node;
    5519             :         uint32_t opline_num;
    5520             :         zend_op *begin_silence, *end_silence;
    5521             : 
    5522        5519 :         opline_num = get_next_op_number(CG(active_op_array));
    5523        5519 :         begin_silence = zend_emit_op_tmp(&silence_node, ZEND_BEGIN_SILENCE, NULL, NULL TSRMLS_CC);
    5524             :         /* pair BEGIN_SILENCE and END_SILENCE opcodes */
    5525        5519 :         begin_silence->op2.num = opline_num;
    5526             : 
    5527        5519 :         if (expr_ast->kind == ZEND_AST_VAR) {
    5528             :                 /* For @$var we need to force a FETCH instruction, otherwise the CV access will
    5529             :                  * happen outside the silenced section. */
    5530        1510 :                 zend_compile_simple_var_no_cv(result, expr_ast, BP_VAR_R TSRMLS_CC);
    5531             :         } else {
    5532        4009 :                 zend_compile_expr(result, expr_ast TSRMLS_CC);
    5533             :         }
    5534             : 
    5535        5519 :         end_silence = zend_emit_op(NULL, ZEND_END_SILENCE, &silence_node, NULL TSRMLS_CC);
    5536             :         /* pair BEGIN_SILENCE and END_SILENCE opcodes */
    5537        5519 :         end_silence->op2.num = opline_num;
    5538        5519 : }
    5539             : /* }}} */
    5540             : 
    5541         113 : void zend_compile_shell_exec(znode *result, zend_ast *ast TSRMLS_DC) /* {{{ */
    5542             : {
    5543         113 :         zend_ast *expr_ast = ast->child[0];
    5544             : 
    5545             :         zval fn_name;
    5546             :         zend_ast *name_ast, *args_ast, *call_ast;
    5547             : 
    5548         226 :         ZVAL_STRING(&fn_name, "shell_exec");
    5549         113 :         name_ast = zend_ast_create_zval(&fn_name);
    5550         113 :         args_ast = zend_ast_create_list(1, ZEND_AST_ARG_LIST, expr_ast);
    5551         113 :         call_ast = zend_ast_create(ZEND_AST_CALL, name_ast, args_ast);
    5552             : 
    5553         113 :         zend_compile_expr(result, call_ast TSRMLS_CC);
    5554             : 
    5555         113 :         zval_ptr_dtor(&fn_name);
    5556         113 : }
    5557             : /* }}} */
    5558             : 
    5559       15555 : void zend_compile_array(znode *result, zend_ast *ast TSRMLS_DC) /* {{{ */
    5560             : {
    5561       15555 :         zend_ast_list *list = zend_ast_get_list(ast);
    5562             :         zend_op *opline;
    5563       15555 :         uint32_t i, opnum_init = -1;
    5564       15555 :         zend_bool packed = 1;
    5565             : 
    5566       15555 :         if (zend_try_ct_eval_array(&result->u.constant, ast TSRMLS_CC)) {
    5567       10799 :                 result->op_type = IS_CONST;
    5568       10799 :                 return;
    5569             :         }
    5570             : 
    5571       36273 :         for (i = 0; i < list->children; ++i) {
    5572       31517 :                 zend_ast *elem_ast = list->child[i];
    5573       31517 :                 zend_ast *value_ast = elem_ast->child[0];
    5574       31517 :                 zend_ast *key_ast = elem_ast->child[1];
    5575       31517 :                 zend_bool by_ref = elem_ast->attr;
    5576             : 
    5577       31517 :                 znode value_node, key_node, *key_node_ptr = NULL;
    5578             : 
    5579       31517 :                 if (key_ast) {
    5580       10955 :                         zend_compile_expr(&key_node, key_ast TSRMLS_CC);
    5581       10955 :                         zend_handle_numeric_op(&key_node TSRMLS_CC);
    5582       10955 :                         key_node_ptr = &key_node;
    5583             :                 }
    5584             : 
    5585       31517 :                 if (by_ref) {
    5586         151 :                         zend_ensure_writable_variable(value_ast);
    5587         151 :                         zend_compile_var(&value_node, value_ast, BP_VAR_W TSRMLS_CC);
    5588             :                 } else {
    5589       31366 :                         zend_compile_expr(&value_node, value_ast TSRMLS_CC);
    5590             :                 }
    5591             : 
    5592       31517 :                 if (i == 0) {
    5593        4756 :                         opnum_init = get_next_op_number(CG(active_op_array));
    5594        4756 :                         opline = zend_emit_op_tmp(result, ZEND_INIT_ARRAY, &value_node, key_node_ptr TSRMLS_CC);
    5595        4756 :                         opline->extended_value = list->children << ZEND_ARRAY_SIZE_SHIFT;
    5596             :                 } else {
    5597       26761 :                         opline = zend_emit_op(NULL, ZEND_ADD_ARRAY_ELEMENT,
    5598             :                                 &value_node, key_node_ptr TSRMLS_CC);
    5599       26761 :                         SET_NODE(opline->result, result);
    5600             :                 }
    5601       31517 :                 opline->extended_value |= by_ref;
    5602             : 
    5603       42103 :                 if (key_ast && key_node.op_type == IS_CONST && Z_TYPE(key_node.u.constant) == IS_STRING) {
    5604        9891 :                         packed = 0;
    5605             :                 }
    5606             :         }
    5607             : 
    5608             :         /* Handle empty array */
    5609        4756 :         if (!list->children) {
    5610           0 :                 zend_emit_op_tmp(result, ZEND_INIT_ARRAY, NULL, NULL TSRMLS_CC);
    5611             :         }
    5612             : 
    5613             :         /* Add a flag to INIT_ARRAY if we know this array cannot be packed */
    5614        4756 :         if (!packed) {
    5615             :                 ZEND_ASSERT(opnum_init != -1);
    5616        1971 :                 opline = &CG(active_op_array)->opcodes[opnum_init];
    5617        1971 :                 opline->extended_value |= ZEND_ARRAY_NOT_PACKED;
    5618             :         }
    5619             : }
    5620             : /* }}} */
    5621             : 
    5622       64369 : void zend_compile_const(znode *result, zend_ast *ast TSRMLS_DC) /* {{{ */
    5623             : {
    5624       64369 :         zend_ast *name_ast = ast->child[0];
    5625             : 
    5626             :         zend_op *opline;
    5627             : 
    5628             :         zend_bool is_fully_qualified;
    5629       64369 :         zend_string *orig_name = zend_ast_get_str(name_ast);
    5630       64369 :         zend_string *resolved_name = zend_resolve_const_name(
    5631      128738 :                 orig_name, name_ast->attr, &is_fully_qualified TSRMLS_CC);
    5632             : 
    5633       64369 :         if (zend_try_ct_eval_const(&result->u.constant, resolved_name, is_fully_qualified TSRMLS_CC)) {
    5634       58870 :                 result->op_type = IS_CONST;
    5635             :                 zend_string_release(resolved_name);
    5636       58870 :                 return;
    5637             :         }
    5638             : 
    5639        5499 :         opline = zend_emit_op_tmp(result, ZEND_FETCH_CONSTANT, NULL, NULL TSRMLS_CC);
    5640        5499 :         opline->op2_type = IS_CONST;
    5641             : 
    5642        5499 :         if (is_fully_qualified) {
    5643          60 :                 opline->op2.constant = zend_add_const_name_literal(
    5644             :                         CG(active_op_array), resolved_name, 0 TSRMLS_CC);
    5645             :         } else {
    5646        5439 :                 opline->extended_value = IS_CONSTANT_UNQUALIFIED;
    5647        5439 :                 if (CG(current_namespace)) {
    5648          21 :                         opline->extended_value |= IS_CONSTANT_IN_NAMESPACE;
    5649          21 :                         opline->op2.constant = zend_add_const_name_literal(
    5650             :                                 CG(active_op_array), resolved_name, 1 TSRMLS_CC);
    5651             :                 } else {
    5652        5418 :                         opline->op2.constant = zend_add_const_name_literal(
    5653             :                                 CG(active_op_array), resolved_name, 0 TSRMLS_CC);
    5654             :                 }
    5655             :         }
    5656        5499 :         zend_alloc_cache_slot(opline->op2.constant TSRMLS_CC);
    5657             : }
    5658             : /* }}} */
    5659             : 
    5660        8673 : void zend_compile_class_const(znode *result, zend_ast *ast TSRMLS_DC) /* {{{ */
    5661             : {
    5662        8673 :         zend_ast *class_ast = ast->child[0];
    5663        8673 :         zend_ast *const_ast = ast->child[1];
    5664             : 
    5665             :         znode class_node, const_node;
    5666             :         zend_op *opline;
    5667             : 
    5668        8673 :         if (zend_is_const_default_class_ref(class_ast)) {
    5669        8616 :                 class_node.op_type = IS_CONST;
    5670        8616 :                 ZVAL_STR(&class_node.u.constant, zend_resolve_class_name_ast(class_ast TSRMLS_CC));
    5671             :         } else {
    5672          57 :                 zend_compile_class_ref(&class_node, class_ast TSRMLS_CC);
    5673             :         }
    5674             : 
    5675        8673 :         zend_compile_expr(&const_node, const_ast TSRMLS_CC);
    5676             : 
    5677        8673 :         opline = zend_emit_op_tmp(result, ZEND_FETCH_CONSTANT, NULL, &const_node TSRMLS_CC);
    5678             : 
    5679        8673 :         zend_set_class_name_op1(opline, &class_node TSRMLS_CC);
    5680             : 
    5681        8673 :         if (opline->op1_type == IS_CONST) {
    5682        8616 :                 zend_alloc_cache_slot(opline->op2.constant TSRMLS_CC);
    5683             :         } else {
    5684          57 :                 zend_alloc_polymorphic_cache_slot(opline->op2.constant TSRMLS_CC);
    5685             :         }
    5686        8673 : }
    5687             : /* }}} */
    5688             : 
    5689          21 : void zend_compile_resolve_class_name(znode *result, zend_ast *ast TSRMLS_DC) /* {{{ */
    5690             : {
    5691          21 :         zend_ast *name_ast = ast->child[0];
    5692          21 :         uint32_t fetch_type = zend_get_class_fetch_type(zend_ast_get_str(name_ast));
    5693             : 
    5694          21 :         switch (fetch_type) {
    5695             :                 case ZEND_FETCH_CLASS_SELF:
    5696           6 :                         if (!CG(active_class_entry)) {
    5697           1 :                                 zend_error_noreturn(E_COMPILE_ERROR,
    5698             :                                         "Cannot access self::class when no class scope is active");
    5699             :                         }
    5700           5 :                         result->op_type = IS_CONST;
    5701           5 :                         ZVAL_STR_COPY(&result->u.constant, CG(active_class_entry)->name);
    5702           5 :                         break;
    5703             :         case ZEND_FETCH_CLASS_STATIC:
    5704             :         case ZEND_FETCH_CLASS_PARENT:
    5705           8 :                         if (!CG(active_class_entry)) {
    5706           2 :                                 zend_error_noreturn(E_COMPILE_ERROR,
    5707             :                                         "Cannot access %s::class when no class scope is active",
    5708             :                                         fetch_type == ZEND_FETCH_CLASS_STATIC ? "static" : "parent");
    5709             :                         } else {
    5710             :                                 zval class_str_zv;
    5711             :                                 zend_ast *class_str_ast, *class_const_ast;
    5712             : 
    5713          12 :                                 ZVAL_STRING(&class_str_zv, "class");
    5714           6 :                                 class_str_ast = zend_ast_create_zval(&class_str_zv);
    5715           6 :                                 class_const_ast = zend_ast_create(
    5716             :                                         ZEND_AST_CLASS_CONST, name_ast, class_str_ast);
    5717             : 
    5718           6 :                                 zend_compile_expr(result, class_const_ast TSRMLS_CC);
    5719             : 
    5720           6 :                                 zval_ptr_dtor(&class_str_zv);
    5721             :                         }
    5722           6 :                         break;
    5723             :                 case ZEND_FETCH_CLASS_DEFAULT:
    5724           7 :                         result->op_type = IS_CONST;
    5725           7 :                         ZVAL_STR(&result->u.constant, zend_resolve_class_name_ast(name_ast TSRMLS_CC));
    5726             :                         break;
    5727             :                 EMPTY_SWITCH_DEFAULT_CASE()
    5728             :         }
    5729          18 : }
    5730             : /* }}} */
    5731             : 
    5732       12388 : void zend_compile_encaps_list(znode *result, zend_ast *ast TSRMLS_DC) /* {{{ */
    5733             : {
    5734       12388 :         zend_ast_list *list = zend_ast_get_list(ast);
    5735             :         uint32_t i;
    5736             : 
    5737             :         ZEND_ASSERT(list->children > 0);
    5738             : 
    5739       12388 :         result->op_type = IS_TMP_VAR;
    5740       12388 :         result->u.op.var = get_temporary_variable(CG(active_op_array));
    5741             : 
    5742       53220 :         for (i = 0; i < list->children; ++i) {
    5743       40832 :                 zend_ast *elem_ast = list->child[i];
    5744             :                 znode elem_node;
    5745             :                 zend_op *opline;
    5746             : 
    5747       40832 :                 zend_compile_expr(&elem_node, elem_ast TSRMLS_CC);
    5748             : 
    5749       40832 :                 if (elem_ast->kind == ZEND_AST_ZVAL) {
    5750       22486 :                         zval *zv = &elem_node.u.constant;
    5751             :                         ZEND_ASSERT(Z_TYPE_P(zv) == IS_STRING);
    5752             : 
    5753       22486 :                         if (Z_STRLEN_P(zv) > 1) {
    5754       17553 :                                 opline = get_next_op(CG(active_op_array) TSRMLS_CC);
    5755       17553 :                                 opline->opcode = ZEND_ADD_STRING;
    5756        4933 :                         } else if (Z_STRLEN_P(zv) == 1) {
    5757        4925 :                                 char ch = *Z_STRVAL_P(zv);
    5758        4925 :                                 zend_string_release(Z_STR_P(zv));
    5759        4925 :                                 ZVAL_LONG(zv, ch);
    5760             : 
    5761        4925 :                                 opline = get_next_op(CG(active_op_array) TSRMLS_CC);
    5762        4925 :                                 opline->opcode = ZEND_ADD_CHAR;
    5763             :                         } else {
    5764             :                                 /* String can be empty after a variable at the end of a heredoc */
    5765           8 :                                 zend_string_release(Z_STR_P(zv));
    5766           8 :                                 continue;
    5767             :                         }
    5768             :                 } else {
    5769       18346 :                         opline = get_next_op(CG(active_op_array) TSRMLS_CC);
    5770       18346 :                         opline->opcode = ZEND_ADD_VAR;
    5771             :                         ZEND_ASSERT(elem_node.op_type != IS_CONST);
    5772             :                 }
    5773             : 
    5774       40824 :                 if (i == 0) {
    5775       12388 :                         SET_UNUSED(opline->op1);
    5776             :                 } else {
    5777       28436 :                         SET_NODE(opline->op1, result);
    5778             :                 }
    5779       40824 :                 SET_NODE(opline->op2, &elem_node);
    5780       40824 :                 SET_NODE(opline->result, result);
    5781             :         }
    5782       12388 : }
    5783             : /* }}} */
    5784             : 
    5785        8508 : void zend_compile_magic_const(znode *result, zend_ast *ast TSRMLS_DC) /* {{{ */
    5786             : {
    5787        8508 :         zend_class_entry *ce = CG(active_class_entry);
    5788             : 
    5789        8508 :         if (zend_try_ct_eval_magic_const(&result->u.constant, ast TSRMLS_CC)) {
    5790        8505 :                 result->op_type = IS_CONST;
    5791        8505 :                 return;
    5792             :         }
    5793             : 
    5794             :         ZEND_ASSERT(ast->attr == T_CLASS_C && ce && ZEND_CE_IS_TRAIT(ce));
    5795             : 
    5796             :         {
    5797           3 :                 zend_ast *const_ast = zend_ast_create(ZEND_AST_CONST,
    5798           3 :                         zend_ast_create_zval_from_str(zend_string_init("__CLASS__", sizeof("__CLASS__") - 1, 0)));
    5799           3 :                 zend_compile_const(result, const_ast TSRMLS_CC);
    5800           3 :                 zend_ast_destroy(const_ast);
    5801             :         }
    5802             : }
    5803             : /* }}} */
    5804             : 
    5805         797 : zend_bool zend_is_allowed_in_const_expr(zend_ast_kind kind) /* {{{ */
    5806             : {
    5807         797 :         return kind == ZEND_AST_ZVAL || kind == ZEND_AST_BINARY_OP
    5808             :                 || kind == ZEND_AST_GREATER || kind == ZEND_AST_GREATER_EQUAL
    5809             :                 || kind == ZEND_AST_AND || kind == ZEND_AST_OR
    5810             :                 || kind == ZEND_AST_UNARY_OP
    5811             :                 || kind == ZEND_AST_UNARY_PLUS || kind == ZEND_AST_UNARY_MINUS
    5812             :                 || kind == ZEND_AST_CONDITIONAL || kind == ZEND_AST_DIM
    5813             :                 || kind == ZEND_AST_ARRAY || kind == ZEND_AST_ARRAY_ELEM
    5814             :                 || kind == ZEND_AST_CONST || kind == ZEND_AST_CLASS_CONST
    5815             :                 || kind == ZEND_AST_RESOLVE_CLASS_NAME || kind == ZEND_AST_MAGIC_CONST;
    5816             : }
    5817             : /* }}} */
    5818             : 
    5819         362 : void zend_compile_const_expr_class_const(zend_ast **ast_ptr TSRMLS_DC) /* {{{ */
    5820             : {
    5821         362 :         zend_ast *ast = *ast_ptr;
    5822         362 :         zend_ast *class_ast = ast->child[0];
    5823         362 :         zend_ast *const_ast = ast->child[1];
    5824             :         zend_string *class_name;
    5825         362 :         zend_string *const_name = zend_ast_get_str(const_ast);
    5826             :         zval result;
    5827             :         int fetch_type;
    5828             : 
    5829         362 :         if (class_ast->kind != ZEND_AST_ZVAL) {
    5830           1 :                 zend_error_noreturn(E_COMPILE_ERROR,
    5831             :                         "Dynamic class names are not allowed in compile-time class constant references");
    5832             :         }
    5833             : 
    5834         361 :         class_name = zend_ast_get_str(class_ast);
    5835         361 :         fetch_type = zend_get_class_fetch_type(class_name);
    5836             : 
    5837         361 :         if (ZEND_FETCH_CLASS_STATIC == fetch_type) {
    5838           1 :                 zend_error_noreturn(E_COMPILE_ERROR,
    5839             :                         "\"static::\" is not allowed in compile-time constants");
    5840             :         }
    5841             :         
    5842         360 :         if (ZEND_FETCH_CLASS_DEFAULT == fetch_type) {
    5843         297 :                 class_name = zend_resolve_class_name_ast(class_ast TSRMLS_CC);
    5844             :         } else {
    5845             :                 zend_string_addref(class_name);
    5846             :         }
    5847             : 
    5848         360 :         Z_STR(result) = zend_concat3(
    5849             :                 class_name->val, class_name->len, "::", 2, const_name->val, const_name->len);
    5850             : 
    5851         360 :         Z_TYPE_INFO(result) = IS_CONSTANT_EX;
    5852         360 :         Z_CONST_FLAGS(result) = fetch_type;
    5853             : 
    5854         360 :         zend_ast_destroy(ast);
    5855             :         zend_string_release(class_name);
    5856             : 
    5857         360 :         *ast_ptr = zend_ast_create_zval(&result);
    5858         360 : }
    5859             : /* }}} */
    5860             : 
    5861         149 : void zend_compile_const_expr_const(zend_ast **ast_ptr TSRMLS_DC) /* {{{ */
    5862             : {
    5863         149 :         zend_ast *ast = *ast_ptr;
    5864         149 :         zend_ast *name_ast = ast->child[0];
    5865         149 :         zend_string *orig_name = zend_ast_get_str(name_ast);
    5866             :         zend_bool is_fully_qualified;
    5867             : 
    5868             :         zval result, resolved_name;
    5869         149 :         ZVAL_STR(&resolved_name, zend_resolve_const_name(
    5870             :                 orig_name, name_ast->attr, &is_fully_qualified TSRMLS_CC));
    5871             : 
    5872         149 :         if (zend_try_ct_eval_const(&result, Z_STR(resolved_name), is_fully_qualified TSRMLS_CC)) {
    5873           6 :                 zend_string_release(Z_STR(resolved_name));
    5874           6 :                 zend_ast_destroy(ast);
    5875           6 :                 *ast_ptr = zend_ast_create_zval(&result);
    5876           6 :                 return;
    5877             :         }
    5878             : 
    5879         143 :         Z_TYPE_INFO(resolved_name) = IS_CONSTANT_EX;
    5880         143 :         if (!is_fully_qualified) {
    5881         101 :                 Z_CONST_FLAGS(resolved_name) = IS_CONSTANT_UNQUALIFIED;
    5882             :         }
    5883             : 
    5884         143 :         zend_ast_destroy(ast);
    5885         143 :         *ast_ptr = zend_ast_create_zval(&resolved_name);
    5886             : }
    5887             : /* }}} */
    5888             : 
    5889           8 : void zend_compile_const_expr_resolve_class_name(zend_ast **ast_ptr TSRMLS_DC) /* {{{ */
    5890             : {
    5891           8 :         zend_ast *ast = *ast_ptr;
    5892           8 :         zend_ast *name_ast = ast->child[0];
    5893           8 :         uint32_t fetch_type = zend_get_class_fetch_type(zend_ast_get_str(name_ast));
    5894             :         zval result;
    5895             : 
    5896           8 :         switch (fetch_type) {
    5897             :                 case ZEND_FETCH_CLASS_SELF:
    5898           2 :                         if (!CG(active_class_entry)) {
    5899           0 :                                 zend_error_noreturn(E_COMPILE_ERROR,
    5900             :                                         "Cannot access self::class when no class scope is active");
    5901             :                         }
    5902           2 :                         ZVAL_STR_COPY(&result, CG(active_class_entry)->name);
    5903           2 :                         break;
    5904             :         case ZEND_FETCH_CLASS_STATIC:
    5905             :         case ZEND_FETCH_CLASS_PARENT:
    5906           4 :                         zend_error_noreturn(E_COMPILE_ERROR,
    5907             :                                 "%s::class cannot be used for compile-time class name resolution",
    5908             :                                 fetch_type == ZEND_FETCH_CLASS_STATIC ? "static" : "parent"
    5909             :                         );
    5910             :                         break;
    5911             :                 case ZEND_FETCH_CLASS_DEFAULT:
    5912           2 :                         ZVAL_STR(&result, zend_resolve_class_name_ast(name_ast TSRMLS_CC));
    5913             :                         break;
    5914             :                 EMPTY_SWITCH_DEFAULT_CASE()
    5915             :         }
    5916             : 
    5917           4 :         zend_ast_destroy(ast);
    5918           4 :         *ast_ptr = zend_ast_create_zval(&result);
    5919           4 : }
    5920             : /* }}} */
    5921             : 
    5922           2 : void zend_compile_const_expr_magic_const(zend_ast **ast_ptr TSRMLS_DC) /* {{{ */
    5923             : {
    5924           2 :         zend_ast *ast = *ast_ptr;
    5925           2 :         zend_class_entry *ce = CG(active_class_entry);
    5926             : 
    5927             :         /* Other cases already resolved by constant folding */
    5928             :         ZEND_ASSERT(ast->attr == T_CLASS_C && ce && ZEND_CE_IS_TRAIT(ce));
    5929             : 
    5930             :         {
    5931             :                 zval const_zv;
    5932           4 :                 ZVAL_STRING(&const_zv, "__CLASS__");
    5933           2 :                 Z_TYPE_INFO(const_zv) = IS_CONSTANT_EX;
    5934             : 
    5935           2 :                 zend_ast_destroy(ast);
    5936           2 :                 *ast_ptr = zend_ast_create_zval(&const_zv);
    5937             :         }
    5938           2 : }
    5939             : /* }}} */
    5940             : 
    5941       18113 : void zend_compile_const_expr(zend_ast **ast_ptr TSRMLS_DC) /* {{{ */
    5942             : {
    5943       18113 :         zend_ast *ast = *ast_ptr;
    5944       18113 :         if (ast == NULL || ast->kind == ZEND_AST_ZVAL) {
    5945       17316 :                 return;
    5946             :         }
    5947             : 
    5948         797 :         if (!zend_is_allowed_in_const_expr(ast->kind)) {
    5949           1 :                 zend_error_noreturn(E_COMPILE_ERROR, "Constant expression contains invalid operations");
    5950             :         }
    5951             : 
    5952         796 :         switch (ast->kind) {
    5953             :                 case ZEND_AST_CLASS_CONST:
    5954         362 :                         zend_compile_const_expr_class_const(ast_ptr TSRMLS_CC);
    5955         360 :                         break;
    5956             :                 case ZEND_AST_CONST:
    5957         149 :                         zend_compile_const_expr_const(ast_ptr TSRMLS_CC);
    5958         149 :                         break;
    5959             :                 case ZEND_AST_RESOLVE_CLASS_NAME:
    5960           8 :                         zend_compile_const_expr_resolve_class_name(ast_ptr TSRMLS_CC);
    5961           4 :                         break;
    5962             :                 case ZEND_AST_MAGIC_CONST:
    5963           2 :                         zend_compile_const_expr_magic_const(ast_ptr TSRMLS_CC);
    5964           2 :                         break;
    5965             :                 default:
    5966         275 :                         zend_ast_apply(ast, zend_compile_const_expr TSRMLS_CC);
    5967             :                         break;
    5968             :         }
    5969             : }
    5970             : /* }}} */
    5971             : 
    5972       17628 : void zend_const_expr_to_zval(zval *result, zend_ast *ast TSRMLS_DC) /* {{{ */
    5973             : {
    5974       17628 :         zend_ast *orig_ast = ast;
    5975       17628 :         zend_eval_const_expr(&ast TSRMLS_CC);
    5976       17628 :         zend_compile_const_expr(&ast TSRMLS_CC);
    5977       17621 :         if (ast->kind == ZEND_AST_ZVAL) {
    5978       34980 :                 ZVAL_COPY_VALUE(result, zend_ast_get_zval(ast));
    5979             : 
    5980             :                 /* Kill this branch of the original AST, as it was already destroyed.
    5981             :                  * It would be nice to find a better solution to this problem in the
    5982             :                  * future. */
    5983       17490 :                 orig_ast->kind = 0;
    5984             :         } else {
    5985         131 :                 ZVAL_NEW_AST(result, zend_ast_copy(ast));
    5986             :         }
    5987       17621 : }
    5988             : /* }}} */
    5989             : 
    5990             : /* Same as compile_stmt, but with early binding */
    5991      263924 : void zend_compile_top_stmt(zend_ast *ast TSRMLS_DC) /* {{{ */
    5992             : {
    5993      263924 :         if (!ast) {
    5994       27105 :                 return;
    5995             :         }
    5996             : 
    5997      236819 :         if (ast->kind == ZEND_AST_STMT_LIST) {
    5998       49137 :                 zend_ast_list *list = zend_ast_get_list(ast);
    5999             :                 uint32_t i;
    6000      283349 :                 for (i = 0; i < list->children; ++i) {
    6001      234406 :                         zend_compile_top_stmt(list->child[i] TSRMLS_CC);
    6002             :                 }
    6003       48943 :                 return;
    6004             :         }
    6005             : 
    6006      187682 :         zend_compile_stmt(ast TSRMLS_CC);
    6007             : 
    6008      187534 :         if (ast->kind != ZEND_AST_NAMESPACE && ast->kind != ZEND_AST_HALT_COMPILER) {
    6009      187078 :                 zend_verify_namespace(TSRMLS_C);
    6010             :         }
    6011      187533 :         if (ast->kind == ZEND_AST_FUNC_DECL || ast->kind == ZEND_AST_CLASS) {
    6012       19583 :                 CG(zend_lineno) = ((zend_ast_decl *) ast)->end_lineno;
    6013       19583 :                 zend_do_early_binding(TSRMLS_C);
    6014             :         }
    6015             : }
    6016             : /* }}} */
    6017             : 
    6018      603470 : void zend_compile_stmt(zend_ast *ast TSRMLS_DC) /* {{{ */
    6019             : {
    6020      603470 :         if (!ast) {
    6021         303 :                 return;
    6022             :         }
    6023             : 
    6024      603167 :         CG(zend_lineno) = ast->lineno;
    6025             : 
    6026      603167 :         switch (ast->kind) {
    6027             :                 case ZEND_AST_STMT_LIST:
    6028      133667 :                         zend_compile_stmt_list(ast TSRMLS_CC);
    6029      133612 :                         break;
    6030             :                 case ZEND_AST_GLOBAL:
    6031        4580 :                         zend_compile_global_var(ast TSRMLS_CC);
    6032        4580 :                         break;
    6033             :                 case ZEND_AST_STATIC:
    6034        1883 :                         zend_compile_static_var(ast TSRMLS_CC);
    6035        1883 :                         break;
    6036             :                 case ZEND_AST_UNSET:
    6037        1581 :                         zend_compile_unset(ast TSRMLS_CC);
    6038        1580 :                         break;
    6039             :                 case ZEND_AST_RETURN:
    6040       43567 :                         zend_compile_return(ast TSRMLS_CC);
    6041       43566 :                         break;
    6042             :                 case ZEND_AST_ECHO:
    6043       33840 :                         zend_compile_echo(ast TSRMLS_CC);
    6044       33840 :                         break;
    6045             :                 case ZEND_AST_THROW:
    6046         317 :                         zend_compile_throw(ast TSRMLS_CC);
    6047         317 :                         break;
    6048             :                 case ZEND_AST_BREAK:
    6049             :                 case ZEND_AST_CONTINUE:
    6050        2088 :                         zend_compile_break_continue(ast TSRMLS_CC);
    6051        2088 :                         break;
    6052             :                 case ZEND_AST_GOTO:
    6053          35 :                         zend_compile_goto(ast TSRMLS_CC);
    6054          33 :                         break;
    6055             :                 case ZEND_AST_LABEL:
    6056          37 :                         zend_compile_label(ast TSRMLS_CC);
    6057          36 :                         break;
    6058             :                 case ZEND_AST_WHILE:
    6059        1870 :                         zend_compile_while(ast TSRMLS_CC);
    6060        1870 :                         break;
    6061             :                 case ZEND_AST_DO_WHILE:
    6062         289 :                         zend_compile_do_while(ast TSRMLS_CC);
    6063         289 :                         break;
    6064             :                 case ZEND_AST_FOR:
    6065        1869 :                         zend_compile_for(ast TSRMLS_CC);
    6066        1869 :                         break;
    6067             :                 case ZEND_AST_FOREACH:
    6068        9738 :                         zend_compile_foreach(ast TSRMLS_CC);
    6069        9731 :                         break;
    6070             :                 case ZEND_AST_IF:
    6071       68256 :                         zend_compile_if(ast TSRMLS_CC);
    6072       68256 :                         break;
    6073             :                 case ZEND_AST_SWITCH:
    6074         449 :                         zend_compile_switch(ast TSRMLS_CC);
    6075         448 :                         break;
    6076             :                 case ZEND_AST_TRY:
    6077        1990 :                         zend_compile_try(ast TSRMLS_CC);
    6078        1989 :                         break;
    6079             :                 case ZEND_AST_DECLARE:
    6080          18 :                         zend_compile_declare(ast TSRMLS_CC);
    6081          17 :                         break;
    6082             :                 case ZEND_AST_FUNC_DECL:
    6083             :                 case ZEND_AST_METHOD:
    6084       34833 :                         zend_compile_func_decl(NULL, ast TSRMLS_CC);
    6085       34784 :                         break;
    6086             :                 case ZEND_AST_PROP_DECL:
    6087        2308 :                         zend_compile_prop_decl(ast TSRMLS_CC);
    6088        2304 :                         break;
    6089             :                 case ZEND_AST_CLASS_CONST_DECL:
    6090         239 :                         zend_compile_class_const_decl(ast TSRMLS_CC);
    6091         233 :                         break;
    6092             :                 case ZEND_AST_USE_TRAIT:
    6093         198 :                         zend_compile_use_trait(ast TSRMLS_CC);
    6094         194 :                         break;
    6095             :                 case ZEND_AST_CLASS:
    6096        7265 :                         zend_compile_class_decl(ast TSRMLS_CC);
    6097        7200 :                         break;
    6098             :                 case ZEND_AST_USE:
    6099          82 :                         zend_compile_use(ast TSRMLS_CC);
    6100          74 :                         break;
    6101             :                 case ZEND_AST_CONST_DECL:
    6102         161 :                         zend_compile_const_decl(ast TSRMLS_CC);
    6103         157 :                         break;
    6104             :                 case ZEND_AST_NAMESPACE:
    6105         201 :                         zend_compile_namespace(ast TSRMLS_CC);
    6106         182 :                         break;
    6107             :                 case ZEND_AST_HALT_COMPILER:
    6108         274 :                         zend_compile_halt_compiler(ast TSRMLS_CC);
    6109         274 :                         break;
    6110             :                 default:
    6111             :                 {
    6112             :                         znode result;
    6113      251532 :                         zend_compile_expr(&result, ast TSRMLS_CC);
    6114      251503 :                         zend_do_free(&result TSRMLS_CC);
    6115             :                 }
    6116             :         }
    6117             : 
    6118      602909 :         if (Z_LVAL(CG(declarables).ticks) && !zend_is_unticked_stmt(ast)) {
    6119          29 :                 zend_emit_tick(TSRMLS_C);
    6120             :         }
    6121             : }
    6122             : /* }}} */
    6123             : 
    6124     1472028 : void zend_compile_expr(znode *result, zend_ast *ast TSRMLS_DC) /* {{{ */
    6125             : {
    6126             :         /* CG(zend_lineno) = ast->lineno; */
    6127     1472028 :         CG(zend_lineno) = zend_ast_get_lineno(ast);
    6128             : 
    6129     1472028 :         switch (ast->kind) {
    6130             :                 case ZEND_AST_ZVAL:
    6131     1122198 :                         ZVAL_COPY(&result->u.constant, zend_ast_get_zval(ast));
    6132      561099 :                         result->op_type = IS_CONST;
    6133      561099 :                         return;
    6134             :                 case ZEND_AST_ZNODE:
    6135       14748 :                         *result = *zend_ast_get_znode(ast);
    6136       14748 :                         return;
    6137             :                 case ZEND_AST_VAR:
    6138             :                 case ZEND_AST_DIM:
    6139             :                 case ZEND_AST_PROP:
    6140             :                 case ZEND_AST_STATIC_PROP:
    6141             :                 case ZEND_AST_CALL:
    6142             :                 case ZEND_AST_METHOD_CALL:
    6143             :                 case ZEND_AST_STATIC_CALL:
    6144      430066 :                         zend_compile_var(result, ast, BP_VAR_R TSRMLS_CC);
    6145      430048 :                         return;
    6146             :                 case ZEND_AST_ASSIGN:
    6147      129422 :                         zend_compile_assign(result, ast TSRMLS_CC);
    6148      129413 :                         return;
    6149             :                 case ZEND_AST_ASSIGN_REF:
    6150         414 :                         zend_compile_assign_ref(result, ast TSRMLS_CC);
    6151         412 :                         return;
    6152             :                 case ZEND_AST_NEW:
    6153       14116 :                         zend_compile_new(result, ast TSRMLS_CC);
    6154       14116 :                         return;
    6155             :                 case ZEND_AST_CLONE:
    6156         115 :                         zend_compile_clone(result, ast TSRMLS_CC);
    6157         115 :                         return;
    6158             :                 case ZEND_AST_ASSIGN_OP:
    6159        3750 :                         zend_compile_compound_assign(result, ast TSRMLS_CC);
    6160        3750 :                         return;
    6161             :                 case ZEND_AST_BINARY_OP:
    6162       75948 :                         zend_compile_binary_op(result, ast TSRMLS_CC);
    6163       75948 :                         return;
    6164             :                 case ZEND_AST_GREATER:
    6165             :                 case ZEND_AST_GREATER_EQUAL:
    6166        1107 :                         zend_compile_greater(result, ast TSRMLS_CC);
    6167        1107 :                         return;
    6168             :                 case ZEND_AST_UNARY_OP:
    6169       29204 :                         zend_compile_unary_op(result, ast TSRMLS_CC);
    6170       29204 :                         return;
    6171             :                 case ZEND_AST_UNARY_PLUS:
    6172             :                 case ZEND_AST_UNARY_MINUS:
    6173        3175 :                         zend_compile_unary_pm(result, ast TSRMLS_CC);
    6174        3175 :                         return;
    6175             :                 case ZEND_AST_AND:
    6176             :                 case ZEND_AST_OR:
    6177       11713 :                         zend_compile_short_circuiting(result, ast TSRMLS_CC);
    6178       11713 :                         return;
    6179             :                 case ZEND_AST_POST_INC:
    6180             :                 case ZEND_AST_POST_DEC:
    6181        5457 :                         zend_compile_post_incdec(result, ast TSRMLS_CC);
    6182        5457 :                         return;
    6183             :                 case ZEND_AST_PRE_INC:
    6184             :                 case ZEND_AST_PRE_DEC:
    6185         532 :                         zend_compile_pre_incdec(result, ast TSRMLS_CC);
    6186         532 :                         return;
    6187             :                 case ZEND_AST_CAST:
    6188        6539 :                         zend_compile_cast(result, ast TSRMLS_CC);
    6189        6539 :                         return;
    6190             :                 case ZEND_AST_CONDITIONAL:
    6191       27218 :                         zend_compile_conditional(result, ast TSRMLS_CC);
    6192       27218 :                         return;
    6193             :                 case ZEND_AST_COALESCE:
    6194          16 :                         zend_compile_coalesce(result, ast TSRMLS_CC);
    6195          16 :                         return;
    6196             :                 case ZEND_AST_PRINT:
    6197        3382 :                         zend_compile_print(result, ast TSRMLS_CC);
    6198        3382 :                         return;
    6199             :                 case ZEND_AST_EXIT:
    6200       14351 :                         zend_compile_exit(result, ast TSRMLS_CC);
    6201       14351 :                         return;
    6202             :                 case ZEND_AST_YIELD:
    6203         121 :                         zend_compile_yield(result, ast TSRMLS_CC);
    6204         120 :                         return;
    6205             :                 case ZEND_AST_INSTANCEOF:
    6206          65 :                         zend_compile_instanceof(result, ast TSRMLS_CC);
    6207          64 :                         return;
    6208             :                 case ZEND_AST_INCLUDE_OR_EVAL:
    6209       10716 :                         zend_compile_include_or_eval(result, ast TSRMLS_CC);
    6210       10716 :                         return;
    6211             :                 case ZEND_AST_ISSET:
    6212             :                 case ZEND_AST_EMPTY:
    6213       13249 :                         zend_compile_isset_or_empty(result, ast TSRMLS_CC);
    6214       13246 :                         return;
    6215             :                 case ZEND_AST_SILENCE:
    6216        5519 :                         zend_compile_silence(result, ast TSRMLS_CC);
    6217        5519 :                         return;
    6218             :                 case ZEND_AST_SHELL_EXEC:
    6219         113 :                         zend_compile_shell_exec(result, ast TSRMLS_CC);
    6220         113 :                         return;
    6221             :                 case ZEND_AST_ARRAY:
    6222       15555 :                         zend_compile_array(result, ast TSRMLS_CC);
    6223       15555 :                         return;
    6224             :                 case ZEND_AST_CONST:
    6225       64366 :                         zend_compile_const(result, ast TSRMLS_CC);
    6226       64366 :                         return;
    6227             :                 case ZEND_AST_CLASS_CONST:
    6228        8673 :                         zend_compile_class_const(result, ast TSRMLS_CC);
    6229        8673 :                         return;
    6230             :                 case ZEND_AST_RESOLVE_CLASS_NAME:
    6231          21 :                         zend_compile_resolve_class_name(result, ast TSRMLS_CC);
    6232          18 :                         return;
    6233             :                 case ZEND_AST_ENCAPS_LIST:
    6234       12388 :                         zend_compile_encaps_list(result, ast TSRMLS_CC);
    6235       12388 :                         return;
    6236             :                 case ZEND_AST_MAGIC_CONST:
    6237        8508 :                         zend_compile_magic_const(result, ast TSRMLS_CC);
    6238        8508 :                         return;
    6239             :                 case ZEND_AST_CLOSURE:
    6240         362 :                         zend_compile_func_decl(result, ast TSRMLS_CC);
    6241         361 :                         return;
    6242             :                 default:
    6243             :                         ZEND_ASSERT(0 /* not supported */);
    6244             :         }
    6245             : }
    6246             : /* }}} */
    6247             : 
    6248     1010634 : void zend_compile_var(znode *result, zend_ast *ast, uint32_t type TSRMLS_DC) /* {{{ */
    6249             : {
    6250     1010634 :         switch (ast->kind) {
    6251             :                 case ZEND_AST_VAR:
    6252      598248 :                         zend_compile_simple_var(result, ast, type TSRMLS_CC);
    6253      598248 :                         return;
    6254             :                 case ZEND_AST_DIM:
    6255      103224 :                         zend_compile_dim(result, ast, type TSRMLS_CC);
    6256      103218 :                         return;
    6257             :                 case ZEND_AST_PROP:
    6258        5932 :                         zend_compile_prop(result, ast, type TSRMLS_CC);
    6259        5932 :                         return;
    6260             :                 case ZEND_AST_STATIC_PROP:
    6261         517 :                         zend_compile_static_prop(result, ast, type TSRMLS_CC);
    6262         517 :                         return;
    6263             :                 case ZEND_AST_CALL:
    6264      256067 :                         zend_compile_call(result, ast, type TSRMLS_CC);
    6265      256053 :                         return;
    6266             :                 case ZEND_AST_METHOD_CALL:
    6267       34411 :                         zend_compile_method_call(result, ast, type TSRMLS_CC);
    6268       34409 :                         return;
    6269             :                 case ZEND_AST_STATIC_CALL:
    6270       10199 :                         zend_compile_static_call(result, ast, type TSRMLS_CC);
    6271       10199 :                         return;
    6272             :                 case ZEND_AST_ZNODE:
    6273        1989 :                         *result = *zend_ast_get_znode(ast);
    6274        1989 :                         return;
    6275             :                 default:
    6276          47 :                         if (type == BP_VAR_W || type == BP_VAR_REF
    6277             :                                 || type == BP_VAR_RW || type == BP_VAR_UNSET
    6278             :                         ) {
    6279             :                                 /* For BC reasons =& new Foo is allowed */
    6280          11 :                                 if (type != BP_VAR_REF || ast->kind != ZEND_AST_NEW) {
    6281           1 :                                         zend_error_noreturn(E_COMPILE_ERROR,
    6282             :                                                 "Cannot use temporary expression in write context");
    6283             :                                 }
    6284             :                         }
    6285             : 
    6286          46 :                         zend_compile_expr(result, ast TSRMLS_CC);
    6287          46 :                         return;
    6288             :         }
    6289             : }
    6290             : /* }}} */
    6291             : 
    6292      129266 : void zend_delayed_compile_var(znode *result, zend_ast *ast, uint32_t type TSRMLS_DC) /* {{{ */
    6293             : {
    6294             :         zend_op *opline;
    6295      129266 :         switch (ast->kind) {
    6296             :                 case ZEND_AST_DIM:
    6297        3762 :                         opline = zend_delayed_compile_dim(result, ast, type TSRMLS_CC);
    6298        3761 :                         zend_adjust_for_fetch_type(opline, type);
    6299        3761 :                         return;
    6300             :                 case ZEND_AST_PROP:
    6301        1195 :                         opline = zend_delayed_compile_prop(result, ast, type TSRMLS_CC);
    6302        1195 :                         zend_adjust_for_fetch_type(opline, type);
    6303        1195 :                         return;
    6304             :                 default:
    6305      124309 :                         zend_compile_var(result, ast, type TSRMLS_CC);
    6306      124308 :                         return;
    6307             :         }
    6308             : }
    6309             : /* }}} */
    6310             : 
    6311      193287 : void zend_eval_const_expr(zend_ast **ast_ptr TSRMLS_DC) /* {{{ */
    6312             : {
    6313      193287 :         zend_ast *ast = *ast_ptr;
    6314             :         zval result;
    6315             : 
    6316      193287 :         if (!ast) {
    6317       63001 :                 return;
    6318             :         }
    6319             : 
    6320      130286 :         switch (ast->kind) {
    6321             :                 case ZEND_AST_BINARY_OP:
    6322        1194 :                         zend_eval_const_expr(&ast->child[0] TSRMLS_CC);
    6323        1194 :                         zend_eval_const_expr(&ast->child[1] TSRMLS_CC);
    6324        1194 :                         if (ast->child[0]->kind != ZEND_AST_ZVAL || ast->child[1]->kind != ZEND_AST_ZVAL) {
    6325         967 :                                 return;
    6326             :                         }
    6327             : 
    6328         681 :                         zend_ct_eval_binary_op(&result, ast->attr,
    6329             :                                 zend_ast_get_zval(ast->child[0]), zend_ast_get_zval(ast->child[1]) TSRMLS_CC);
    6330         227 :                         break;
    6331             :                 case ZEND_AST_GREATER:
    6332             :                 case ZEND_AST_GREATER_EQUAL:
    6333           4 :                         zend_eval_const_expr(&ast->child[0] TSRMLS_CC);
    6334           4 :                         zend_eval_const_expr(&ast->child[1] TSRMLS_CC);
    6335           4 :                         if (ast->child[0]->kind != ZEND_AST_ZVAL || ast->child[1]->kind != ZEND_AST_ZVAL) {
    6336           2 :                                 return;
    6337             :                         }
    6338             : 
    6339           6 :                         zend_ct_eval_greater(&result, ast->kind,
    6340             :                                 zend_ast_get_zval(ast->child[0]), zend_ast_get_zval(ast->child[1]) TSRMLS_CC);
    6341           2 :                         break;
    6342             :                 case ZEND_AST_UNARY_PLUS:
    6343             :                 case ZEND_AST_UNARY_MINUS:
    6344        3417 :                         zend_eval_const_expr(&ast->child[0] TSRMLS_CC);
    6345        3417 :                         if (ast->child[0]->kind != ZEND_AST_ZVAL) {
    6346           3 :                                 return;
    6347             :                         }
    6348             : 
    6349        6828 :                         zend_ct_eval_unary_pm(&result, ast->kind,
    6350             :                                 zend_ast_get_zval(ast->child[0]) TSRMLS_CC);
    6351        3414 :                         break;
    6352             :                 case ZEND_AST_ARRAY:
    6353       10076 :                         if (!zend_try_ct_eval_array(&result, ast TSRMLS_CC)) {
    6354         325 :                                 return;
    6355             :                         }
    6356        9751 :                         break;
    6357             :                 case ZEND_AST_MAGIC_CONST:
    6358         103 :                         if (!zend_try_ct_eval_magic_const(&result, ast TSRMLS_CC)) {
    6359           2 :                                 return;
    6360             :                         }
    6361         101 :                         break;
    6362             :                 case ZEND_AST_CONST:
    6363             :                 {
    6364       12944 :                         zend_ast *name_ast = ast->child[0];
    6365             :                         zend_bool is_fully_qualified;
    6366       25888 :                         zend_string *resolved_name = zend_resolve_const_name(
    6367       25888 :                                 zend_ast_get_str(name_ast), name_ast->attr, &is_fully_qualified TSRMLS_CC);
    6368             : 
    6369       12944 :                         if (!zend_try_ct_eval_const(&result, resolved_name, is_fully_qualified TSRMLS_CC)) {
    6370             :                                 zend_string_release(resolved_name);
    6371         388 :                                 return;
    6372             :                         }
    6373             : 
    6374             :                         zend_string_release(resolved_name);
    6375       12556 :                         break;
    6376             :                 }
    6377             :                 default:
    6378      102548 :                         return;
    6379             :         }
    6380             : 
    6381       26051 :         zend_ast_destroy(ast);
    6382       26051 :         *ast_ptr = zend_ast_create_zval(&result);
    6383             : }
    6384             : /* }}} */
    6385             : 
    6386             : /*
    6387             :  * Local variables:
    6388             :  * tab-width: 4
    6389             :  * c-basic-offset: 4
    6390             :  * indent-tabs-mode: t
    6391             :  * End:
    6392             :  */

Generated by: LCOV version 1.10

Generated at Thu, 30 Oct 2014 07:41:27 +0000 (36 hours ago)

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