Lines Matching refs:generator
35 ZEND_API void zend_generator_restore_call_stack(zend_generator *generator) /* {{{ */ in zend_generator_restore_call_stack() argument
39 call = generator->frozen_call_stack; in zend_generator_restore_call_stack()
53 generator->execute_data->call = prev_call; in zend_generator_restore_call_stack()
54 efree(generator->frozen_call_stack); in zend_generator_restore_call_stack()
55 generator->frozen_call_stack = NULL; in zend_generator_restore_call_stack()
113 zend_generator *generator, zend_execute_data *execute_data, uint32_t catch_op_num) /* {{{ */ in zend_generator_cleanup_unfinished_execution() argument
120 if (UNEXPECTED(generator->frozen_call_stack)) { in zend_generator_cleanup_unfinished_execution()
122 zend_execute_data *save_ex = generator->execute_data; in zend_generator_cleanup_unfinished_execution()
123 generator->execute_data = execute_data; in zend_generator_cleanup_unfinished_execution()
124 zend_generator_restore_call_stack(generator); in zend_generator_cleanup_unfinished_execution()
125 generator->execute_data = save_ex; in zend_generator_cleanup_unfinished_execution()
133 ZEND_API void zend_generator_close(zend_generator *generator, bool finished_execution) /* {{{ */ in zend_generator_close() argument
135 if (EXPECTED(generator->execute_data)) { in zend_generator_close()
136 zend_execute_data *execute_data = generator->execute_data; in zend_generator_close()
139 generator->execute_data = NULL; in zend_generator_close()
157 generator->execute_data = NULL; in zend_generator_close()
166 zend_generator_cleanup_unfinished_execution(generator, execute_data, 0); in zend_generator_close()
200 static zend_always_inline zend_generator *clear_link_to_leaf(zend_generator *generator) { in clear_link_to_leaf() argument
201 ZEND_ASSERT(!generator->node.parent); in clear_link_to_leaf()
202 zend_generator *leaf = generator->node.ptr.leaf; in clear_link_to_leaf()
205 generator->node.ptr.leaf = NULL; in clear_link_to_leaf()
211 static zend_always_inline void clear_link_to_root(zend_generator *generator) { in clear_link_to_root() argument
212 ZEND_ASSERT(generator->node.parent); in clear_link_to_root()
213 if (generator->node.ptr.root) { in clear_link_to_root()
214 generator->node.ptr.root->node.ptr.leaf = NULL; in clear_link_to_root()
215 generator->node.ptr.root = NULL; in clear_link_to_root()
221 zend_generator *generator = (zend_generator*) object; in zend_generator_dtor_storage() local
222 zend_execute_data *ex = generator->execute_data; in zend_generator_dtor_storage()
228 if (zend_generator_get_current(generator)->flags & ZEND_GENERATOR_IN_FIBER) { in zend_generator_dtor_storage()
230 generator->flags |= ZEND_GENERATOR_FORCED_CLOSE; in zend_generator_dtor_storage()
235 if (UNEXPECTED(Z_TYPE(generator->values) != IS_UNDEF)) { in zend_generator_dtor_storage()
236 zval_ptr_dtor(&generator->values); in zend_generator_dtor_storage()
237 ZVAL_UNDEF(&generator->values); in zend_generator_dtor_storage()
240 zend_generator *parent = generator->node.parent; in zend_generator_dtor_storage()
242 zend_generator_remove_child(&parent->node, generator); in zend_generator_dtor_storage()
243 clear_link_to_root(generator); in zend_generator_dtor_storage()
244 generator->node.parent = NULL; in zend_generator_dtor_storage()
247 clear_link_to_leaf(generator); in zend_generator_dtor_storage()
252 zend_generator_close(generator, 0); in zend_generator_dtor_storage()
281 zend_generator_cleanup_unfinished_execution(generator, ex, try_catch->finally_op); in zend_generator_dtor_storage()
289 generator->flags |= ZEND_GENERATOR_FORCED_CLOSE; in zend_generator_dtor_storage()
290 zend_generator_resume(generator); in zend_generator_dtor_storage()
323 zend_generator_close(generator, 0); in zend_generator_dtor_storage()
329 zend_generator *generator = (zend_generator*) object; in zend_generator_free_storage() local
331 zend_generator_close(generator, 0); in zend_generator_free_storage()
334 zval_ptr_dtor(&generator->value); in zend_generator_free_storage()
335 zval_ptr_dtor(&generator->key); in zend_generator_free_storage()
337 if (EXPECTED(!Z_ISUNDEF(generator->retval))) { in zend_generator_free_storage()
338 zval_ptr_dtor(&generator->retval); in zend_generator_free_storage()
341 if (UNEXPECTED(generator->node.children > 1)) { in zend_generator_free_storage()
342 zend_hash_destroy(generator->node.child.ht); in zend_generator_free_storage()
343 efree(generator->node.child.ht); in zend_generator_free_storage()
346 zend_object_std_dtor(&generator->std); in zend_generator_free_storage()
352 zend_generator *generator = (zend_generator*)object; in zend_generator_get_gc() local
353 zend_execute_data *execute_data = generator->execute_data; in zend_generator_get_gc()
359 *table = &generator->value; in zend_generator_get_gc()
364 if (generator->flags & ZEND_GENERATOR_CURRENTLY_RUNNING) { in zend_generator_get_gc()
376 zend_get_gc_buffer_add_zval(gc_buffer, &generator->value); in zend_generator_get_gc()
377 zend_get_gc_buffer_add_zval(gc_buffer, &generator->key); in zend_generator_get_gc()
378 zend_get_gc_buffer_add_zval(gc_buffer, &generator->retval); in zend_generator_get_gc()
379 zend_get_gc_buffer_add_zval(gc_buffer, &generator->values); in zend_generator_get_gc()
381 if (UNEXPECTED(generator->frozen_call_stack)) { in zend_generator_get_gc()
383 call = zend_generator_revert_call_stack(generator->frozen_call_stack); in zend_generator_get_gc()
388 if (UNEXPECTED(generator->frozen_call_stack)) { in zend_generator_get_gc()
392 if (generator->node.parent) { in zend_generator_get_gc()
393 zend_get_gc_buffer_add_obj(gc_buffer, &generator->node.parent->std); in zend_generator_get_gc()
407 zend_generator *generator; in zend_generator_create() local
409 generator = emalloc(sizeof(zend_generator)); in zend_generator_create()
410 memset(generator, 0, sizeof(zend_generator)); in zend_generator_create()
413 generator->largest_used_integer_key = -1; in zend_generator_create()
415 ZVAL_UNDEF(&generator->retval); in zend_generator_create()
416 ZVAL_UNDEF(&generator->values); in zend_generator_create()
419 generator->node.parent = NULL; in zend_generator_create()
420 generator->node.children = 0; in zend_generator_create()
421 generator->node.ptr.root = NULL; in zend_generator_create()
423 zend_object_std_init(&generator->std, class_type); in zend_generator_create()
424 generator->std.handlers = &zend_generator_handlers; in zend_generator_create()
426 return (zend_object*)generator; in zend_generator_create()
442 zend_generator *generator = (zend_generator *) Z_OBJ(ptr->This); in zend_generator_check_placeholder_frame() local
444 ZEND_ASSERT(generator->node.parent && "Placeholder only used with delegation"); in zend_generator_check_placeholder_frame()
445 while (generator->node.parent->node.parent) { in zend_generator_check_placeholder_frame()
446 generator->execute_data->prev_execute_data = prev; in zend_generator_check_placeholder_frame()
447 prev = generator->execute_data; in zend_generator_check_placeholder_frame()
448 generator = generator->node.parent; in zend_generator_check_placeholder_frame()
450 generator->execute_data->prev_execute_data = prev; in zend_generator_check_placeholder_frame()
451 ptr = generator->execute_data; in zend_generator_check_placeholder_frame()
457 static void zend_generator_throw_exception(zend_generator *generator, zval *exception) in zend_generator_throw_exception() argument
463 EG(current_execute_data) = generator->execute_data; in zend_generator_throw_exception()
464 generator->execute_data->opline--; in zend_generator_throw_exception()
473 if (UNEXPECTED(Z_TYPE(generator->values) != IS_UNDEF)) { in zend_generator_throw_exception()
474 zval_ptr_dtor(&generator->values); in zend_generator_throw_exception()
475 ZVAL_UNDEF(&generator->values); in zend_generator_throw_exception()
478 generator->execute_data->opline++; in zend_generator_throw_exception()
482 static void zend_generator_add_child(zend_generator *generator, zend_generator *child) in zend_generator_add_child() argument
484 zend_generator_node *node = &generator->node; in zend_generator_add_child()
503 void zend_generator_yield_from(zend_generator *generator, zend_generator *from) in zend_generator_yield_from() argument
505 ZEND_ASSERT(!generator->node.parent && "Already has parent?"); in zend_generator_yield_from()
506 zend_generator *leaf = clear_link_to_leaf(generator); in zend_generator_yield_from()
511 generator->node.parent = from; in zend_generator_yield_from()
512 zend_generator_add_child(from, generator); in zend_generator_yield_from()
513 generator->flags |= ZEND_GENERATOR_DO_INIT; in zend_generator_yield_from()
516 ZEND_API zend_generator *zend_generator_update_root(zend_generator *generator) in zend_generator_update_root() argument
518 zend_generator *root = generator->node.parent; in zend_generator_update_root()
524 root->node.ptr.leaf = generator; in zend_generator_update_root()
525 generator->node.ptr.root = root; in zend_generator_update_root()
529 static zend_generator *get_new_root(zend_generator *generator, zend_generator *root) in get_new_root() argument
541 while (generator->node.parent->execute_data) { in get_new_root()
542 generator = generator->node.parent; in get_new_root()
545 return generator; in get_new_root()
548 ZEND_API zend_generator *zend_generator_update_current(zend_generator *generator) in zend_generator_update_current() argument
550 zend_generator *old_root = generator->node.ptr.root; in zend_generator_update_current()
553 zend_generator *new_root = get_new_root(generator, old_root); in zend_generator_update_current()
555 ZEND_ASSERT(old_root->node.ptr.leaf == generator); in zend_generator_update_current()
556 generator->node.ptr.root = new_root; in zend_generator_update_current()
557 new_root->node.ptr.leaf = generator; in zend_generator_update_current()
564 …if (EXPECTED(EG(exception) == NULL) && EXPECTED((OBJ_FLAGS(&generator->std) & IS_OBJ_DESTRUCTOR_CA… in zend_generator_update_current()
573 if (new_root == generator) { in zend_generator_update_current()
576 new_root->execute_data->prev_execute_data = &generator->execute_fake; in zend_generator_update_current()
577 generator->execute_fake.prev_execute_data = original_execute_data; in zend_generator_update_current()
586 if (!((old_root ? old_root : generator)->flags & ZEND_GENERATOR_CURRENTLY_RUNNING)) { in zend_generator_update_current()
589 zend_generator_resume(generator); in zend_generator_update_current()
590 return zend_generator_get_current(generator); in zend_generator_update_current()
606 static zend_result zend_generator_get_next_delegated_value(zend_generator *generator) /* {{{ */ in zend_generator_get_next_delegated_value() argument
608 --generator->execute_data->opline; in zend_generator_get_next_delegated_value()
611 if (Z_TYPE(generator->values) == IS_ARRAY) { in zend_generator_get_next_delegated_value()
612 HashTable *ht = Z_ARR(generator->values); in zend_generator_get_next_delegated_value()
613 HashPosition pos = Z_FE_POS(generator->values); in zend_generator_get_next_delegated_value()
627 zval_ptr_dtor(&generator->value); in zend_generator_get_next_delegated_value()
628 ZVAL_COPY(&generator->value, value); in zend_generator_get_next_delegated_value()
630 zval_ptr_dtor(&generator->key); in zend_generator_get_next_delegated_value()
632 ZVAL_STR_COPY(&generator->key, p->key); in zend_generator_get_next_delegated_value()
634 ZVAL_LONG(&generator->key, p->h); in zend_generator_get_next_delegated_value()
637 Z_FE_POS(generator->values) = pos; in zend_generator_get_next_delegated_value()
639 zend_object_iterator *iter = (zend_object_iterator *) Z_OBJ(generator->values); in zend_generator_get_next_delegated_value()
658 zval_ptr_dtor(&generator->value); in zend_generator_get_next_delegated_value()
659 ZVAL_COPY(&generator->value, value); in zend_generator_get_next_delegated_value()
661 zval_ptr_dtor(&generator->key); in zend_generator_get_next_delegated_value()
663 iter->funcs->get_current_key(iter, &generator->key); in zend_generator_get_next_delegated_value()
665 ZVAL_UNDEF(&generator->key); in zend_generator_get_next_delegated_value()
669 ZVAL_LONG(&generator->key, iter->index); in zend_generator_get_next_delegated_value()
673 ++generator->execute_data->opline; in zend_generator_get_next_delegated_value()
677 zval_ptr_dtor(&generator->values); in zend_generator_get_next_delegated_value()
678 ZVAL_UNDEF(&generator->values); in zend_generator_get_next_delegated_value()
680 ++generator->execute_data->opline; in zend_generator_get_next_delegated_value()
687 zend_generator *generator = zend_generator_get_current(orig_generator); in zend_generator_resume() local
690 if (UNEXPECTED(!generator->execute_data)) { in zend_generator_resume()
695 if (generator->flags & ZEND_GENERATOR_CURRENTLY_RUNNING) { in zend_generator_resume()
700 …if (UNEXPECTED((orig_generator->flags & ZEND_GENERATOR_DO_INIT) != 0 && !Z_ISUNDEF(generator->valu… in zend_generator_resume()
714 EG(current_execute_data) = generator->execute_data; in zend_generator_resume()
720 if (generator == orig_generator) { in zend_generator_resume()
721 generator->execute_data->prev_execute_data = original_execute_data; in zend_generator_resume()
725 generator->execute_data->prev_execute_data = &orig_generator->execute_fake; in zend_generator_resume()
730 if (UNEXPECTED(!Z_ISUNDEF(generator->values))) { in zend_generator_resume()
731 if (EXPECTED(zend_generator_get_next_delegated_value(generator) == SUCCESS)) { in zend_generator_resume()
743 if (UNEXPECTED(generator->frozen_call_stack)) { in zend_generator_resume()
745 zend_generator_restore_call_stack(generator); in zend_generator_resume()
749 generator->flags |= ZEND_GENERATOR_CURRENTLY_RUNNING in zend_generator_resume()
752 zend_execute_ex(generator->execute_data); in zend_generator_resume()
754 zend_observer_generator_resume(generator->execute_data); in zend_generator_resume()
755 zend_execute_ex(generator->execute_data); in zend_generator_resume()
756 if (generator->execute_data) { in zend_generator_resume()
758 zend_observer_fcall_end(generator->execute_data, &generator->value); in zend_generator_resume()
761 generator->flags &= ~(ZEND_GENERATOR_CURRENTLY_RUNNING | ZEND_GENERATOR_IN_FIBER); in zend_generator_resume()
763 generator->frozen_call_stack = NULL; in zend_generator_resume()
764 if (EXPECTED(generator->execute_data) && in zend_generator_resume()
765 UNEXPECTED(generator->execute_data->call)) { in zend_generator_resume()
767 generator->frozen_call_stack = zend_generator_freeze_call_stack(generator->execute_data); in zend_generator_resume()
779 if (generator == orig_generator) { in zend_generator_resume()
780 zend_generator_close(generator, 0); in zend_generator_resume()
788 generator = zend_generator_get_current(orig_generator); in zend_generator_resume()
789 zend_generator_throw_exception(generator, NULL); in zend_generator_resume()
796 …if (UNEXPECTED((generator != orig_generator && !Z_ISUNDEF(generator->retval)) || (generator->execu… in zend_generator_resume()
797 generator = zend_generator_get_current(orig_generator); in zend_generator_resume()
805 static inline void zend_generator_ensure_initialized(zend_generator *generator) /* {{{ */ in zend_generator_ensure_initialized() argument
807 …if (UNEXPECTED(Z_TYPE(generator->value) == IS_UNDEF) && EXPECTED(generator->execute_data) && EXPEC… in zend_generator_ensure_initialized()
808 zend_generator_resume(generator); in zend_generator_ensure_initialized()
809 generator->flags |= ZEND_GENERATOR_AT_FIRST_YIELD; in zend_generator_ensure_initialized()
814 static inline void zend_generator_rewind(zend_generator *generator) /* {{{ */ in zend_generator_rewind() argument
816 zend_generator_ensure_initialized(generator); in zend_generator_rewind()
818 if (!(generator->flags & ZEND_GENERATOR_AT_FIRST_YIELD)) { in zend_generator_rewind()
827 zend_generator *generator; in ZEND_METHOD() local
831 generator = (zend_generator *) Z_OBJ_P(ZEND_THIS); in ZEND_METHOD()
833 zend_generator_rewind(generator); in ZEND_METHOD()
840 zend_generator *generator; in ZEND_METHOD() local
844 generator = (zend_generator *) Z_OBJ_P(ZEND_THIS); in ZEND_METHOD()
846 zend_generator_ensure_initialized(generator); in ZEND_METHOD()
848 zend_generator_get_current(generator); in ZEND_METHOD()
850 RETURN_BOOL(EXPECTED(generator->execute_data != NULL)); in ZEND_METHOD()
857 zend_generator *generator, *root; in ZEND_METHOD() local
861 generator = (zend_generator *) Z_OBJ_P(ZEND_THIS); in ZEND_METHOD()
863 zend_generator_ensure_initialized(generator); in ZEND_METHOD()
865 root = zend_generator_get_current(generator); in ZEND_METHOD()
866 if (EXPECTED(generator->execute_data != NULL && Z_TYPE(root->value) != IS_UNDEF)) { in ZEND_METHOD()
875 zend_generator *generator, *root; in ZEND_METHOD() local
879 generator = (zend_generator *) Z_OBJ_P(ZEND_THIS); in ZEND_METHOD()
881 zend_generator_ensure_initialized(generator); in ZEND_METHOD()
883 root = zend_generator_get_current(generator); in ZEND_METHOD()
884 if (EXPECTED(generator->execute_data != NULL && Z_TYPE(root->key) != IS_UNDEF)) { in ZEND_METHOD()
893 zend_generator *generator; in ZEND_METHOD() local
897 generator = (zend_generator *) Z_OBJ_P(ZEND_THIS); in ZEND_METHOD()
899 zend_generator_ensure_initialized(generator); in ZEND_METHOD()
901 zend_generator_resume(generator); in ZEND_METHOD()
909 zend_generator *generator, *root; in ZEND_METHOD() local
915 generator = (zend_generator *) Z_OBJ_P(ZEND_THIS); in ZEND_METHOD()
917 zend_generator_ensure_initialized(generator); in ZEND_METHOD()
920 if (UNEXPECTED(!generator->execute_data)) { in ZEND_METHOD()
924 root = zend_generator_get_current(generator); in ZEND_METHOD()
930 zend_generator_resume(generator); in ZEND_METHOD()
932 root = zend_generator_get_current(generator); in ZEND_METHOD()
933 if (EXPECTED(generator->execute_data)) { in ZEND_METHOD()
943 zend_generator *generator; in ZEND_METHOD() local
951 generator = (zend_generator *) Z_OBJ_P(ZEND_THIS); in ZEND_METHOD()
953 zend_generator_ensure_initialized(generator); in ZEND_METHOD()
955 if (generator->execute_data) { in ZEND_METHOD()
956 zend_generator *root = zend_generator_get_current(generator); in ZEND_METHOD()
960 zend_generator_resume(generator); in ZEND_METHOD()
962 root = zend_generator_get_current(generator); in ZEND_METHOD()
963 if (generator->execute_data) { in ZEND_METHOD()
977 zend_generator *generator; in ZEND_METHOD() local
981 generator = (zend_generator *) Z_OBJ_P(ZEND_THIS); in ZEND_METHOD()
983 zend_generator_ensure_initialized(generator); in ZEND_METHOD()
988 if (Z_ISUNDEF(generator->retval)) { in ZEND_METHOD()
995 ZVAL_COPY(return_value, &generator->retval); in ZEND_METHOD()
1009 zend_generator *generator = (zend_generator*)Z_OBJ(iterator->data); in zend_generator_iterator_valid() local
1011 zend_generator_ensure_initialized(generator); in zend_generator_iterator_valid()
1013 zend_generator_get_current(generator); in zend_generator_iterator_valid()
1015 return generator->execute_data ? SUCCESS : FAILURE; in zend_generator_iterator_valid()
1021 zend_generator *generator = (zend_generator*)Z_OBJ(iterator->data), *root; in zend_generator_iterator_get_data() local
1023 zend_generator_ensure_initialized(generator); in zend_generator_iterator_get_data()
1025 root = zend_generator_get_current(generator); in zend_generator_iterator_get_data()
1033 zend_generator *generator = (zend_generator*)Z_OBJ(iterator->data), *root; in zend_generator_iterator_get_key() local
1035 zend_generator_ensure_initialized(generator); in zend_generator_iterator_get_key()
1037 root = zend_generator_get_current(generator); in zend_generator_iterator_get_key()
1051 zend_generator *generator = (zend_generator*)Z_OBJ(iterator->data); in zend_generator_iterator_move_forward() local
1053 zend_generator_ensure_initialized(generator); in zend_generator_iterator_move_forward()
1055 zend_generator_resume(generator); in zend_generator_iterator_move_forward()
1061 zend_generator *generator = (zend_generator*)Z_OBJ(iterator->data); in zend_generator_iterator_rewind() local
1063 zend_generator_rewind(generator); in zend_generator_iterator_rewind()
1090 zend_generator *generator = (zend_generator*)Z_OBJ_P(object); in zend_generator_get_iterator() local
1092 if (!generator->execute_data) { in zend_generator_get_iterator()
1097 …if (UNEXPECTED(by_ref) && !(generator->execute_data->func->op_array.fn_flags & ZEND_ACC_RETURN_REF… in zend_generator_get_iterator()