Exemplo n.º 1
0
static int xdiff_outf(void *priv_, mmbuffer_t *mb, int nbuf)
{
	struct xdiff_emit_state *priv = priv_;
	int i;

	for (i = 0; i < nbuf; i++) {
		if (mb[i].ptr[mb[i].size-1] != '\n') {
			/* Incomplete line */
			strbuf_add(&priv->remainder, mb[i].ptr, mb[i].size);
			continue;
		}

		/* we have a complete line */
		if (!priv->remainder.len) {
			consume_one(priv, mb[i].ptr, mb[i].size);
			continue;
		}
		strbuf_add(&priv->remainder, mb[i].ptr, mb[i].size);
		consume_one(priv, priv->remainder.buf, priv->remainder.len);
		strbuf_reset(&priv->remainder);
	}
	if (priv->remainder.len) {
		consume_one(priv, priv->remainder.buf, priv->remainder.len);
		strbuf_reset(&priv->remainder);
	}
	return 0;
}
Exemplo n.º 2
0
    bool pop(U & ret)
    {
        BOOST_STATIC_ASSERT((lslboost::is_convertible<T, U>::value));
        detail::consume_via_copy<U> consumer(ret);

        return consume_one(consumer);
    }
Exemplo n.º 3
0
    size_t consume_all(Functor const & f)
    {
        size_t element_count = 0;
        while (consume_one(f))
            element_count += 1;

        return element_count;
    }
Exemplo n.º 4
0
const out_val *out_op(
		out_ctx *octx, enum op_type binop,
		const out_val *lhs, const out_val *rhs)
{
	const out_val *div = NULL;
	const out_val *vconst = NULL, *vregp_or_lbl = NULL;
	const out_val *result;
	const out_val *decay_except[] = { lhs, rhs, NULL };

	v_decay_flags_except(octx, decay_except); /* an op instruction may change cpu flags */

	fill_if_type(lhs, &vconst, &vregp_or_lbl);
	fill_if_type(rhs, &vconst, &vregp_or_lbl);

	/* check for adding or subtracting to stack */
	if(vconst && vregp_or_lbl){
		result = try_mem_offset(octx, binop, vconst, vregp_or_lbl, rhs);
		if(result)
			return result;
	}

	if(vconst && const_is_noop(binop, vconst, vconst == lhs))
		return consume_one(octx, vconst == lhs ? rhs : lhs, lhs, rhs);

	/* constant folding */
	if(vconst && (fopt_mode & FOPT_CONST_FOLD)){
		const out_val *oconst = (vconst == lhs ? rhs : lhs);

		if(oconst->type == V_CONST_I){
			int step_l = calc_ptr_step(lhs->t);
			int step_r = calc_ptr_step(rhs->t);
			out_val *consted;

			/* currently we bail if something like (short *)0 + 2
			 * is attempted */
			if(step_l == 1 && step_r == 1){
				consted = try_const_fold(octx, binop, lhs, rhs);
				if(consted)
					return consted;
			}
		}
	}

	switch(binop){
		case op_plus:
		case op_minus:
			apply_ptr_step(octx, &lhs, &rhs, &div);
			break;
		case op_multiply:
		case op_divide:
			if(vconst && (fopt_mode & FOPT_TRAPV) == 0)
				try_shift_conv(octx, &binop, &lhs, &rhs);
			break;
		default:
			break;
	}

	result = impl_op(octx, binop, lhs, rhs);

	if(div)
		result = out_op(octx, op_divide, result, div);

	return result;
}