void VCL_Get(struct VCL_conf **vcc);
void VCL_Poll(void);
-#define VCL_RET_MAC(l,u,b,n)
#define VCL_MET_MAC(l,u,b) void VCL_##l##_method(struct sess *);
#include "vcl_returns.h"
#undef VCL_MET_MAC
-#undef VCL_RET_MAC
/* cache_vrt_esi.c */
/*--------------------------------------------------------------------*/
-#define VCL_RET_MAC(l,u,b,n)
-
#define VCL_MET_MAC(func, upper, bitmap) \
void \
VCL_##func##_method(struct sess *sp) \
sp->vcl->func##_func(sp); \
WSP(sp, SLT_VCL_return, "%s", VCC_Return_Name(sp->handling)); \
sp->cur_method = 0; \
- assert(sp->handling & bitmap); \
- assert(!(sp->handling & ~bitmap)); \
+ assert((1 << sp->handling) & bitmap); \
+ assert(!((1 << sp->handling) & ~bitmap)); \
}
#include "vcl_returns.h"
#undef VCL_MET_MAC
-#undef VCL_RET_MAC
/*--------------------------------------------------------------------*/
{
CHECK_OBJ_NOTNULL(sp, SESS_MAGIC);
- assert(!(hand & (hand -1))); /* must be power of two */
+ assert(hand < VCL_RET_MAX);
sp->handling = hand;
}
#define VCL_MET_MAX 12
/* VCL Returns */
-#define VCL_RET_ERROR (1 << 0)
-#define VCL_RET_LOOKUP (1 << 1)
-#define VCL_RET_HASH (1 << 2)
-#define VCL_RET_PIPE (1 << 3)
-#define VCL_RET_PASS (1 << 4)
-#define VCL_RET_FETCH (1 << 5)
-#define VCL_RET_DELIVER (1 << 6)
-#define VCL_RET_DISCARD (1 << 7)
-#define VCL_RET_KEEP (1 << 8)
-#define VCL_RET_RESTART (1 << 9)
+#define VCL_RET_ERROR 0
+#define VCL_RET_LOOKUP 1
+#define VCL_RET_HASH 2
+#define VCL_RET_PIPE 3
+#define VCL_RET_PASS 4
+#define VCL_RET_FETCH 5
+#define VCL_RET_DELIVER 6
+#define VCL_RET_DISCARD 7
+#define VCL_RET_KEEP 8
+#define VCL_RET_RESTART 9
#define VCL_RET_MAX 10
*/
#ifdef VCL_RET_MAC
-#ifdef VCL_RET_MAC_E
-VCL_RET_MAC_E(error, ERROR, (1 << 0), 0)
-#endif
-VCL_RET_MAC(lookup, LOOKUP, (1 << 1), 1)
-VCL_RET_MAC(hash, HASH, (1 << 2), 2)
-VCL_RET_MAC(pipe, PIPE, (1 << 3), 3)
-VCL_RET_MAC(pass, PASS, (1 << 4), 4)
-VCL_RET_MAC(fetch, FETCH, (1 << 5), 5)
-VCL_RET_MAC(deliver, DELIVER, (1 << 6), 6)
-VCL_RET_MAC(discard, DISCARD, (1 << 7), 7)
-VCL_RET_MAC(keep, KEEP, (1 << 8), 8)
-VCL_RET_MAC(restart, RESTART, (1 << 9), 9)
+VCL_RET_MAC(error, ERROR)
+VCL_RET_MAC(lookup, LOOKUP)
+VCL_RET_MAC(hash, HASH)
+VCL_RET_MAC(pipe, PIPE)
+VCL_RET_MAC(pass, PASS)
+VCL_RET_MAC(fetch, FETCH)
+VCL_RET_MAC(deliver, DELIVER)
+VCL_RET_MAC(discard, DISCARD)
+VCL_RET_MAC(keep, KEEP)
+VCL_RET_MAC(restart, RESTART)
#endif
#ifdef VCL_MET_MAC
VCL_MET_MAC(recv,RECV,
- (VCL_RET_ERROR|VCL_RET_PASS|VCL_RET_PIPE|VCL_RET_LOOKUP))
+ ((1 << VCL_RET_ERROR)
+ | (1 << VCL_RET_PASS)
+ | (1 << VCL_RET_PIPE)
+ | (1 << VCL_RET_LOOKUP)
+))
VCL_MET_MAC(pipe,PIPE,
- (VCL_RET_ERROR|VCL_RET_PIPE))
+ ((1 << VCL_RET_ERROR)
+ | (1 << VCL_RET_PIPE)
+))
VCL_MET_MAC(pass,PASS,
- (VCL_RET_ERROR|VCL_RET_RESTART|VCL_RET_PASS))
+ ((1 << VCL_RET_ERROR)
+ | (1 << VCL_RET_RESTART)
+ | (1 << VCL_RET_PASS)
+))
VCL_MET_MAC(hash,HASH,
- (VCL_RET_HASH))
+ ((1 << VCL_RET_HASH)
+))
VCL_MET_MAC(miss,MISS,
- (VCL_RET_ERROR|VCL_RET_RESTART|VCL_RET_PASS|VCL_RET_FETCH))
+ ((1 << VCL_RET_ERROR)
+ | (1 << VCL_RET_RESTART)
+ | (1 << VCL_RET_PASS)
+ | (1 << VCL_RET_FETCH)
+))
VCL_MET_MAC(hit,HIT,
- (VCL_RET_ERROR|VCL_RET_RESTART|VCL_RET_PASS|VCL_RET_DELIVER))
+ ((1 << VCL_RET_ERROR)
+ | (1 << VCL_RET_RESTART)
+ | (1 << VCL_RET_PASS)
+ | (1 << VCL_RET_DELIVER)
+))
VCL_MET_MAC(fetch,FETCH,
- (VCL_RET_ERROR|VCL_RET_RESTART|VCL_RET_PASS|VCL_RET_DELIVER))
+ ((1 << VCL_RET_ERROR)
+ | (1 << VCL_RET_RESTART)
+ | (1 << VCL_RET_PASS)
+ | (1 << VCL_RET_DELIVER)
+))
VCL_MET_MAC(deliver,DELIVER,
- (VCL_RET_RESTART|VCL_RET_DELIVER))
+ ((1 << VCL_RET_RESTART)
+ | (1 << VCL_RET_DELIVER)
+))
VCL_MET_MAC(prefetch,PREFETCH,
- (VCL_RET_FETCH|VCL_RET_PASS))
+ ((1 << VCL_RET_FETCH)
+ | (1 << VCL_RET_PASS)
+))
VCL_MET_MAC(timeout,TIMEOUT,
- (VCL_RET_FETCH|VCL_RET_DISCARD))
+ ((1 << VCL_RET_FETCH)
+ | (1 << VCL_RET_DISCARD)
+))
VCL_MET_MAC(discard,DISCARD,
- (VCL_RET_DISCARD|VCL_RET_KEEP))
+ ((1 << VCL_RET_DISCARD)
+ | (1 << VCL_RET_KEEP)
+))
VCL_MET_MAC(error,ERROR,
- (VCL_RET_DELIVER))
+ ((1 << VCL_RET_DELIVER)
+))
#endif
Expect(tl, ID);
-#define VCL_RET_MAC(l, u, b, i) \
+#define VCL_RET_MAC(l, U) \
do { \
if (vcc_IdIs(tl->t, #l)) { \
- Fb(tl, 1, "VRT_done(sp, VCL_RET_%s);\n", #u); \
- vcc_ProcAction(tl->curproc, i, tl->t); \
+ Fb(tl, 1, "VRT_done(sp, VCL_RET_" #U ");\n"); \
+ vcc_ProcAction(tl->curproc, VCL_RET_##U, tl->t);\
retval = 1; \
} \
} while (0);
-#define VCL_RET_MAC_E(l, u, b, i) VCL_RET_MAC(l, u, b, i)
#include "vcl_returns.h"
#undef VCL_RET_MAC
-#undef VCL_RET_MAC_E
if (!retval) {
vsb_printf(tl->sb, "Expected action name.\n");
vcc_ErrWhere(tl, tl->t);
ERRCHK(tl);
}
Fb(tl, 1, "VRT_done(sp, VCL_RET_RESTART);\n");
- assert(VCL_RET_RESTART == (1 << 9)); /* XXX: BANDAID FIXME! */
- vcc_ProcAction(tl->curproc, 9, tl->t);
+ vcc_ProcAction(tl->curproc, VCL_RET_RESTART, tl->t);
vcc_NextToken(tl);
}
} action_table[] = {
{ "restart", parse_restart },
{ "error", parse_error },
-#define VCL_RET_MAC(l, u, b, i) { #l, parse_action },
+#define VCL_RET_MAC(l, U) { #l, parse_action },
#include "vcl_returns.h"
#undef VCL_RET_MAC
#include "libvarnish.h"
struct method method_tab[] = {
-#define VCL_RET_MAC(l,U,b,n)
#define VCL_MET_MAC(l,U,m) { "vcl_"#l, m, VCL_MET_##U },
#include "vcl_returns.h"
#undef VCL_MET_MAC
-#undef VCL_RET_MAC
{ NULL, 0U, 0}
};
Fc(tl, 0, "\t.srcname = srcname,\n");
Fc(tl, 0, "\t.srcbody = srcbody,\n");
Fc(tl, 0, "\t.nhashcount = %u,\n", tl->nhashcount);
-#define VCL_RET_MAC(l,u,b,n)
#define VCL_MET_MAC(l,u,b) \
Fc(tl, 0, "\t." #l "_func = VGC_function_vcl_" #l ",\n");
#include "vcl_returns.h"
#undef VCL_MET_MAC
-#undef VCL_RET_MAC
Fc(tl, 0, "};\n");
}
{
switch (method) {
- case 0: return ("<none>");
-#define VCL_RET_MAC(l, u, b, i) case b: return(#l);
-#define VCL_RET_MAC_E(l, u, b, i) case b: return(#l);
+#define VCL_RET_MAC(l, U) case VCL_RET_##U: return(#l);
#include "vcl_returns.h"
-#undef VCL_RET_MAC_E
#undef VCL_RET_MAC
}
return (NULL);
struct method {
const char *name;
- unsigned returns;
+ unsigned ret_bitmap;
unsigned bitval;
};
void
vcl_output_lang_h(struct vsb *sb)
{
- vsb_cat(sb, "#define VCL_RET_ERROR (1 << 0)\n");
- vsb_cat(sb, "#define VCL_RET_LOOKUP (1 << 1)\n");
- vsb_cat(sb, "#define VCL_RET_HASH (1 << 2)\n");
- vsb_cat(sb, "#define VCL_RET_PIPE (1 << 3)\n");
- vsb_cat(sb, "#define VCL_RET_PASS (1 << 4)\n");
- vsb_cat(sb, "#define VCL_RET_FETCH (1 << 5)\n");
- vsb_cat(sb, "#define VCL_RET_DELIVER (1 << 6)\n");
- vsb_cat(sb, "#define VCL_RET_DISCARD (1 << 7)\n");
- vsb_cat(sb, "#define VCL_RET_KEEP (1 << 8)\n");
- vsb_cat(sb, "#define VCL_RET_RESTART (1 << 9)\n");
/* ../../include/vcl.h */
- vsb_cat(sb, "/*\n * $Id: vcc_gen_fixed_token.tcl 3482 2008-12-21 16");
- vsb_cat(sb, ":18:39Z phk $\n *\n * NB: This file is machine genera");
+ vsb_cat(sb, "/*\n * $Id: vcc_gen_fixed_token.tcl 3484 2008-12-21 17");
+ vsb_cat(sb, ":01:58Z phk $\n *\n * NB: This file is machine genera");
vsb_cat(sb, "ted, DO NOT EDIT!\n *\n * Edit and run vcc_gen_fixed_t");
vsb_cat(sb, "oken.tcl instead\n */\n\nstruct sess;\n");
vsb_cat(sb, "struct cli;\n\ntypedef void vcl_init_f(struct cli *);\n");
vsb_cat(sb, "#define VCL_MET_DISCARD\t\t(1 << 10)\n");
vsb_cat(sb, "#define VCL_MET_ERROR\t\t(1 << 11)\n");
vsb_cat(sb, "\n#define VCL_MET_MAX\t\t12\n\n");
- vsb_cat(sb, "/* VCL Returns */\n#define VCL_RET_ERROR\t\t(1 << 0)\n");
- vsb_cat(sb, "#define VCL_RET_LOOKUP\t\t(1 << 1)\n");
- vsb_cat(sb, "#define VCL_RET_HASH\t\t(1 << 2)\n");
- vsb_cat(sb, "#define VCL_RET_PIPE\t\t(1 << 3)\n");
- vsb_cat(sb, "#define VCL_RET_PASS\t\t(1 << 4)\n");
- vsb_cat(sb, "#define VCL_RET_FETCH\t\t(1 << 5)\n");
- vsb_cat(sb, "#define VCL_RET_DELIVER\t\t(1 << 6)\n");
- vsb_cat(sb, "#define VCL_RET_DISCARD\t\t(1 << 7)\n");
- vsb_cat(sb, "#define VCL_RET_KEEP\t\t(1 << 8)\n");
- vsb_cat(sb, "#define VCL_RET_RESTART\t\t(1 << 9)\n");
- vsb_cat(sb, "\n#define VCL_RET_MAX\t\t10\n\n");
- vsb_cat(sb, "struct VCL_conf {\n\tunsigned\tmagic;\n");
+ vsb_cat(sb, "/* VCL Returns */\n#define VCL_RET_ERROR\t\t0\n");
+ vsb_cat(sb, "#define VCL_RET_LOOKUP\t\t1\n#define VCL_RET_HASH\t\t2");
+ vsb_cat(sb, "\n#define VCL_RET_PIPE\t\t3\n#define VCL_RET_PASS\t\t4");
+ vsb_cat(sb, "\n#define VCL_RET_FETCH\t\t5\n#define VCL_RET_DELIVER\t");
+ vsb_cat(sb, "\t6\n#define VCL_RET_DISCARD\t\t7\n");
+ vsb_cat(sb, "#define VCL_RET_KEEP\t\t8\n#define VCL_RET_RESTART\t\t");
+ vsb_cat(sb, "9\n\n#define VCL_RET_MAX\t\t10\n");
+ vsb_cat(sb, "\nstruct VCL_conf {\n\tunsigned\tmagic;\n");
vsb_cat(sb, "#define VCL_CONF_MAGIC\t0x7406c509\t/* from /dev/rando");
vsb_cat(sb, "m */\n\n\tstruct director\t**director;\n");
vsb_cat(sb, "\tunsigned\tndirector;\n\tstruct vrt_ref\t*ref;\n");
VTAILQ_HEAD(,proccall) calls;
VTAILQ_HEAD(,procuse) uses;
struct token *name;
- unsigned returns;
+ unsigned ret_bitmap;
unsigned exists;
unsigned called;
unsigned active;
vcc_ProcAction(struct proc *p, unsigned returns, struct token *t)
{
- p->returns |= (1U << returns);
+ assert(returns < VCL_RET_MAX);
+ p->ret_bitmap |= (1U << returns);
/* Record the first instance of this return */
if (p->return_tok[returns] == NULL)
p->return_tok[returns] = t;
}
static int
-vcc_CheckActionRecurse(struct tokenlist *tl, struct proc *p, unsigned returns)
+vcc_CheckActionRecurse(struct tokenlist *tl, struct proc *p, unsigned bitmap)
{
unsigned u;
struct proccall *pc;
vcc_ErrWhere(tl, p->name);
return (1);
}
- u = p->returns & ~returns;
+ u = p->ret_bitmap & ~bitmap;
if (u) {
/*lint -save -e525 -e539 */
-#define VCL_RET_MAC(a, b, c, d) \
- if (u & VCL_RET_##b) { \
- vsb_printf(tl->sb, "Invalid return \"%s\"\n", #a); \
- vcc_ErrWhere(tl, p->return_tok[d]); \
+#define VCL_RET_MAC(l, U) \
+ if (u & (1 << (VCL_RET_##U))) { \
+ vsb_printf(tl->sb, "Invalid return \"" #l "\"\n");\
+ vcc_ErrWhere(tl, p->return_tok[VCL_RET_##U]); \
}
#include "vcl_returns.h"
#undef VCL_RET_MAC
}
p->active = 1;
VTAILQ_FOREACH(pc, &p->calls, list) {
- if (vcc_CheckActionRecurse(tl, pc->p, returns)) {
+ if (vcc_CheckActionRecurse(tl, pc->p, bitmap)) {
vsb_printf(tl->sb, "\n...called from \"%.*s\"\n",
PF(p->name));
vcc_ErrWhere(tl, pc->t);
if (i < 0)
continue;
m = method_tab + i;
- if (vcc_CheckActionRecurse(tl, p, m->returns)) {
+ if (vcc_CheckActionRecurse(tl, p, m->ret_bitmap)) {
vsb_printf(tl->sb,
"\n...which is the \"%s\" method\n", m->name);
vsb_printf(tl->sb, "Legal returns are:");
-#define VCL_RET_MAC(a, b, c, d) \
- if (m->returns & c) \
- vsb_printf(tl->sb, " \"%s\"", #a);
-#define VCL_RET_MAC_E(a, b, c, d) VCL_RET_MAC(a, b, c, d)
+#define VCL_RET_MAC(l, U) \
+ if (m->ret_bitmap & ((1 << VCL_RET_##U))) \
+ vsb_printf(tl->sb, " \"%s\"", #l);
/*lint -save -e525 -e539 */
#include "vcl_returns.h"
/*lint +e525 */
#undef VCL_RET_MAC
-#undef VCL_RET_MAC_E
/*lint -restore */
vsb_printf(tl->sb, "\n");
return (1);