Esempio n. 1
0
static void
parse_return(struct vcc *tl)
{
	unsigned hand;
	const char *h;

	vcc_NextToken(tl);
	ExpectErr(tl, '(');
	vcc_NextToken(tl);
	ExpectErr(tl, ID);

	hand = VCL_RET_MAX;
	h = NULL;
#define VCL_RET_MAC(l, U, B)				\
		if (vcc_IdIs(tl->t, #l)) {		\
			hand = VCL_RET_ ## U;		\
			h = #U;				\
		}
#include "tbl/vcl_returns.h"
#undef VCL_RET_MAC
	if (h == NULL) {
		VSB_printf(tl->sb, "Expected return action name.\n");
		vcc_ErrWhere(tl, tl->t);
		ERRCHK(tl);
	}
	assert(hand < VCL_RET_MAX);

	vcc_ProcAction(tl->curproc, hand, tl->t);
	vcc_NextToken(tl);
	if (tl->t->tok == '(') {
		if (hand == VCL_RET_SYNTH)
			parse_return_synth(tl);
		else if (hand == VCL_RET_VCL)
			parse_return_vcl(tl);
		else if (hand == VCL_RET_PASS)
			parse_return_pass(tl);
		else {
			VSB_printf(tl->sb, "Arguments not allowed.\n");
			vcc_ErrWhere(tl, tl->t);
		}
	} else {
		if (hand == VCL_RET_SYNTH || hand == VCL_RET_VCL) {
			VSB_printf(tl->sb, "Missing argument.\n");
			vcc_ErrWhere(tl, tl->t);
		}
	}
	ERRCHK(tl);
	Fb(tl, 1, "VRT_handling(ctx, VCL_RET_%s);\n", h);
	Fb(tl, 1, "return (1);\n");
	ExpectErr(tl, ')');
	vcc_NextToken(tl);
}
Esempio n. 2
0
static void
parse_restart(struct tokenlist *tl)
{
	struct token *t1;

	t1 = VTAILQ_NEXT(tl->t, list);
	if (t1->tok == ID && vcc_IdIs(t1, "rollback")) {
		Fb(tl, 1, "VRT_Rollback(sp);\n");
		vcc_NextToken(tl);
	} else if (t1->tok != ';') {
		vsb_printf(tl->sb, "Expected \"rollback\" or semicolon.\n");
		vcc_ErrWhere(tl, t1);
		ERRCHK(tl);
	}
	Fb(tl, 1, "VRT_done(sp, VCL_RET_RESTART);\n");
	vcc_ProcAction(tl->curproc, VCL_RET_RESTART, tl->t);
	vcc_NextToken(tl);
}
Esempio n. 3
0
static void
parse_return(struct vcc *tl)
{
	int retval = 0;

	vcc_NextToken(tl);
	ExpectErr(tl, '(');
	vcc_NextToken(tl);
	ExpectErr(tl, ID);

	/* 'error' gets special handling, to allow optional status/response */
	if (vcc_IdIs(tl->t, "synth")) {
		vcc_NextToken(tl);
		if (tl->t->tok == ')') {
			VSB_printf(tl->sb,
			    "Syntax has changed, use:\n"
			    "\treturn(synth(999));\n"
			    "or\n"
			    "\treturn(synth(999, \"Response text\"));\n");
			vcc_ErrWhere(tl, tl->t);
			return;
		}
		ExpectErr(tl, '(');
		vcc_NextToken(tl);
		Fb(tl, 1, "VRT_error(ctx,\n");
		tl->indent += INDENT;
		vcc_Expr(tl, INT);
		ERRCHK(tl);
		Fb(tl, 1, ",\n");
		if (tl->t->tok == ',') {
			vcc_NextToken(tl);
			vcc_Expr(tl, STRING);
			ERRCHK(tl);
		} else {
			Fb(tl, 1, "(const char*)0\n");
		}
		tl->indent -= INDENT;
		ExpectErr(tl, ')');
		vcc_NextToken(tl);
		Fb(tl, 1, ");\n");
		Fb(tl, 1, "VRT_handling(ctx, VCL_RET_SYNTH);\n");
		Fb(tl, 1, "return (1);\n");
		vcc_ProcAction(tl->curproc, VCL_RET_SYNTH, tl->t);
		ExpectErr(tl, ')');
		vcc_NextToken(tl);
		return;
	}

#define VCL_RET_MAC(l, U, B)						\
	do {								\
		if (vcc_IdIs(tl->t, #l)) {				\
			Fb(tl, 1, "VRT_handling(ctx, VCL_RET_" #U ");\n"); \
			Fb(tl, 1, "return (1);\n");			\
			vcc_ProcAction(tl->curproc, VCL_RET_##U, tl->t);\
			retval = 1;					\
		}							\
	} while (0);
#include "tbl/vcl_returns.h"
#undef VCL_RET_MAC
	if (!retval) {
		VSB_printf(tl->sb, "Expected return action name.\n");
		vcc_ErrWhere(tl, tl->t);
		ERRCHK(tl);
	}
	vcc_NextToken(tl);
	ExpectErr(tl, ')');
	vcc_NextToken(tl);
}