void srl_iterator_step_out(pTHX_ srl_iterator_t *iter, UV n) { UV offset; srl_stack_t *stack = iter->stack; DEBUG_ASSERT_RDR_SANE(iter->pbuf); SRL_ITER_TRACE("n=%"UVuf, n); SRL_ITER_ASSERT_STACK(iter); // SRL_ITER_ASSERT_EOF(iter, "serialized object"); XXX need ability to go back on last element // if (expect_false(n == 0)) return; XXX keep it as a feature? while (n--) { srl_stack_pop_nocheck(stack); if (expect_false(srl_stack_empty(stack))) { SRL_ITER_ERROR("It was last object on stack, no more parents"); } } offset = stack->ptr->offset; iter->buf.pos = iter->buf.body_pos + offset; stack->ptr->idx = stack->ptr->count; DEBUG_ASSERT_RDR_SANE(iter->pbuf); }
void srl_iterator_unite(pTHX_ srl_iterator_t *iter) { UV offset; srl_stack_t *stack = iter->pstack; SRL_ITER_TRACE("--------------------------"); if (expect_false(SRL_STACK_DEPTH(stack) <= 0)) SRL_ITER_ERROR("There is nothing to unite. Please call disjoin first."); while (!SRL_ITER_STACK_ON_ROOT(stack)) { srl_stack_pop(stack); } offset = stack->ptr->offset; srl_stack_pop(stack); // remove SRL_ITER_STACK_ROOT_TAG SRL_ITER_ASSERT_STACK(iter); iter->buf.pos = iter->buf.body_pos + offset; SRL_ITER_REPORT_STACK_STATE(iter); SRL_ITER_TRACE("ofs %"UVuf" body_ofs %"UVuf, (UV) SRL_RDR_POS_OFS((iter)->pbuf), (UV) SRL_RDR_BODY_POS_OFS((iter)->pbuf)); DEBUG_ASSERT_RDR_SANE(iter->pbuf); }
void srl_iterator_step_out(pTHX_ srl_iterator_t *iter, UV n) { srl_stack_t *stack = iter->pstack; DEBUG_ASSERT_RDR_SANE(iter->pbuf); SRL_ITER_ASSERT_STACK(iter); SRL_ITER_TRACE("n=%"UVuf, n); SRL_ITER_REPORT_STACK_STATE(iter); // SRL_ITER_ASSERT_EOF(iter, "serialized object"); XXX need ability to go back on last element // if (expect_false(n == 0)) return; XXX keep it as a feature? while (n--) { if (expect_false(SRL_ITER_STACK_ON_ROOT(stack))) { SRL_ITER_ERROR("It was last object on stack, no more parents"); } srl_stack_pop_nocheck(stack); } srl_iterator_restore_stack_position(aTHX_ iter); }
void srl_iterator_next(pTHX_ srl_iterator_t *iter, UV n) { srl_stack_t *stack = iter->stack; IV expected_depth = SRL_STACK_DEPTH(stack); DEBUG_ASSERT_RDR_SANE(iter->pbuf); SRL_ITER_TRACE("n=%"UVuf, n); SRL_ITER_ASSERT_STACK(iter); if (expect_false(n == 0)) return; if (expect_false(stack->ptr->idx == 0)) SRL_ITER_ERROR("Nothing to parse at this depth"); while (expect_true(!srl_stack_empty(stack))) { if (SRL_STACK_DEPTH(stack) == expected_depth) { if (n == 0) break; else n--; } srl_iterator_step_internal(aTHX_ iter); srl_iterator_wrap_stack(aTHX_ iter, expected_depth); } if (expect_false(n != 0)) { SRL_ITER_ERRORf1("Failed to do %"UVuf" next steps. Likely EOF was reached", n); } if (expect_false(SRL_STACK_DEPTH(stack) != expected_depth)) { SRL_ITER_ERRORf2("next() led to wrong stack depth, expected=%"IVdf", actual=%"IVdf, expected_depth, SRL_STACK_DEPTH(stack)); } SRL_ITER_TRACE("Did expected number of steps at depth %"IVdf, expected_depth); DEBUG_ASSERT_RDR_SANE(iter->pbuf); }