/*--------------------------------------------------------------------*/
+#define VCL_RET_MAC(l,u,b,i) \
+static void \
+parse_##l(struct tokenlist *tl) \
+{ \
+ \
+ Fb(tl, 1, "VRT_done(sp, VCL_RET_%s);\n", #u); \
+ vcc_ProcAction(tl->curproc, i, tl->t); \
+ vcc_NextToken(tl); \
+}
+
+#include "vcl_returns.h"
+#undef VCL_RET_MAC
+
+/*--------------------------------------------------------------------*/
+
+static void
+parse_call(struct tokenlist *tl)
+{
+
+ vcc_NextToken(tl);
+ ExpectErr(tl, ID);
+ vcc_AddCall(tl, tl->t);
+ vcc_AddRef(tl, tl->t, R_FUNC);
+ Fb(tl, 1, "if (VGC_function_%.*s(sp))\n", PF(tl->t));
+ Fb(tl, 1, "\treturn (1);\n");
+ vcc_NextToken(tl);
+ return;
+}
+
+/*--------------------------------------------------------------------*/
+
+static void
+parse_error(struct tokenlist *tl)
+{
+ unsigned a;
+
+ vcc_NextToken(tl);
+ if (tl->t->tok == CNUM)
+ a = vcc_UintVal(tl);
+ else
+ a = 0;
+ Fb(tl, 1, "VRT_error(sp, %u", a);
+ if (tl->t->tok == CSTR) {
+ Fb(tl, 0, ", %.*s", PF(tl->t));
+ vcc_NextToken(tl);
+ } else {
+ Fb(tl, 0, ", (const char *)0");
+ }
+ Fb(tl, 0, ");\n");
+ Fb(tl, 1, "VRT_done(sp, VCL_RET_ERROR);\n");
+}
+
+/*--------------------------------------------------------------------*/
+
static void
parse_set(struct tokenlist *tl)
{
struct var *vp;
struct token *at, *vt;
+ vcc_NextToken(tl);
ExpectErr(tl, VAR);
vt = tl->t;
vp = FindVar(tl, tl->t, vcc_vars);
/*--------------------------------------------------------------------*/
-typedef action_f(struct tokenlist *tl);
+typedef void action_f(struct tokenlist *tl);
static struct action_table {
const char *name;
action_f *func;
} action_table[] = {
+#define VCL_RET_MAC(l, u, b, i) { #l, parse_##l },
+#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
+ { "call", parse_call },
{ "set", parse_set },
{ NULL, NULL }
};
void
vcc_ParseAction(struct tokenlist *tl)
{
- unsigned a;
struct token *at;
struct action_table *atp;
at = tl->t;
- vcc_NextToken(tl);
if (at->tok == ID) {
for(atp = action_table; atp->name != NULL; atp++) {
if (vcc_IdIs(at, atp->name)) {
}
}
}
+ vcc_NextToken(tl);
switch (at->tok) {
case T_NO_NEW_CACHE:
Fb(tl, 1, "VCL_no_new_cache(sp);\n");
case T_NO_CACHE:
Fb(tl, 1, "VCL_no_cache(sp);\n");
return;
-#define VCL_RET_MAC(a,b,c,d) case T_##b: \
- Fb(tl, 1, "VRT_done(sp, VCL_RET_%s);\n", #b); \
- vcc_ProcAction(tl->curproc, d, at); \
- return;
-#include "vcl_returns.h"
-#undef VCL_RET_MAC
- case T_ERROR:
- if (tl->t->tok == CNUM)
- a = vcc_UintVal(tl);
- else
- a = 0;
- Fb(tl, 1, "VRT_error(sp, %u", a);
- if (tl->t->tok == CSTR) {
- Fb(tl, 0, ", %.*s", PF(tl->t));
- vcc_NextToken(tl);
- } else {
- Fb(tl, 0, ", (const char *)0");
- }
- Fb(tl, 0, ");\n");
- Fb(tl, 1, "VRT_done(sp, VCL_RET_ERROR);\n");
- return;
case T_SWITCH_CONFIG:
ExpectErr(tl, ID);
Fb(tl, 1, "VCL_switch_config(\"%.*s\");\n", PF(tl->t));
vcc_NextToken(tl);
return;
- case T_CALL:
- ExpectErr(tl, ID);
- vcc_AddCall(tl, tl->t);
- vcc_AddRef(tl, tl->t, R_FUNC);
- Fb(tl, 1, "if (VGC_function_%.*s(sp))\n", PF(tl->t));
- Fb(tl, 1, "\treturn (1);\n");
- vcc_NextToken(tl);
- return;
case T_REWRITE:
ExpectErr(tl, CSTR);
Fb(tl, 1, "VCL_rewrite(%.*s", PF(tl->t));
return (T_BACKEND);
}
return (0);
- case 'c':
- if (p[0] == 'c' && p[1] == 'a' && p[2] == 'l' &&
- p[3] == 'l' && !isvar(p[4])) {
- *q = p + 4;
- return (T_CALL);
- }
- return (0);
- case 'd':
- if (p[0] == 'd' && p[1] == 'i' && p[2] == 's' &&
- p[3] == 'c' && p[4] == 'a' && p[5] == 'r' &&
- p[6] == 'd' && !isvar(p[7])) {
- *q = p + 7;
- return (T_DISCARD);
- }
- if (p[0] == 'd' && p[1] == 'e' && p[2] == 'l' &&
- p[3] == 'i' && p[4] == 'v' && p[5] == 'e' &&
- p[6] == 'r' && !isvar(p[7])) {
- *q = p + 7;
- return (T_DELIVER);
- }
- return (0);
case 'e':
- if (p[0] == 'e' && p[1] == 'r' && p[2] == 'r' &&
- p[3] == 'o' && p[4] == 'r' && !isvar(p[5])) {
- *q = p + 5;
- return (T_ERROR);
- }
if (p[0] == 'e' && p[1] == 'l' && p[2] == 's' &&
p[3] == 'i' && p[4] == 'f' && !isvar(p[5])) {
*q = p + 5;
*q = p + 4;
return (T_FUNC);
}
- if (p[0] == 'f' && p[1] == 'e' && p[2] == 't' &&
- p[3] == 'c' && p[4] == 'h' && !isvar(p[5])) {
- *q = p + 5;
- return (T_FETCH);
- }
- return (0);
- case 'h':
- if (p[0] == 'h' && p[1] == 'a' && p[2] == 's' &&
- p[3] == 'h' && !isvar(p[4])) {
- *q = p + 4;
- return (T_HASH);
- }
return (0);
case 'i':
- if (p[0] == 'i' && p[1] == 'n' && p[2] == 's' &&
- p[3] == 'e' && p[4] == 'r' && p[5] == 't'
- && !isvar(p[6])) {
- *q = p + 6;
- return (T_INSERT);
- }
if (p[0] == 'i' && p[1] == 'n' && p[2] == 'c' &&
p[3] == 'l' && p[4] == 'u' && p[5] == 'd' &&
p[6] == 'e' && !isvar(p[7])) {
return (T_IF);
}
return (0);
- case 'l':
- if (p[0] == 'l' && p[1] == 'o' && p[2] == 'o' &&
- p[3] == 'k' && p[4] == 'u' && p[5] == 'p'
- && !isvar(p[6])) {
- *q = p + 6;
- return (T_LOOKUP);
- }
- return (0);
case 'n':
if (p[0] == 'n' && p[1] == 'o' && p[2] == '_' &&
p[3] == 'n' && p[4] == 'e' && p[5] == 'w' &&
*q = p + 4;
return (T_PROC);
}
- if (p[0] == 'p' && p[1] == 'i' && p[2] == 'p' &&
- p[3] == 'e' && !isvar(p[4])) {
- *q = p + 4;
- return (T_PIPE);
- }
- if (p[0] == 'p' && p[1] == 'a' && p[2] == 's' &&
- p[3] == 's' && !isvar(p[4])) {
- *q = p + 4;
- return (T_PASS);
- }
return (0);
case 'r':
if (p[0] == 'r' && p[1] == 'e' && p[2] == 'w' &&
vcl_tnames[METHOD] = "METHOD";
vcl_tnames[T_ACL] = "acl";
vcl_tnames[T_BACKEND] = "backend";
- vcl_tnames[T_CALL] = "call";
vcl_tnames[T_CAND] = "&&";
vcl_tnames[T_COR] = "||";
vcl_tnames[T_DEC] = "--";
vcl_tnames[T_DECR] = "-=";
- vcl_tnames[T_DELIVER] = "deliver";
- vcl_tnames[T_DISCARD] = "discard";
vcl_tnames[T_DIV] = "/=";
vcl_tnames[T_ELSE] = "else";
vcl_tnames[T_ELSEIF] = "elseif";
vcl_tnames[T_ELSIF] = "elsif";
vcl_tnames[T_EQ] = "==";
- vcl_tnames[T_ERROR] = "error";
- vcl_tnames[T_FETCH] = "fetch";
vcl_tnames[T_FUNC] = "func";
vcl_tnames[T_GEQ] = ">=";
- vcl_tnames[T_HASH] = "hash";
vcl_tnames[T_IF] = "if";
vcl_tnames[T_INC] = "++";
vcl_tnames[T_INCLUDE] = "include";
vcl_tnames[T_INCR] = "+=";
- vcl_tnames[T_INSERT] = "insert";
vcl_tnames[T_LEQ] = "<=";
- vcl_tnames[T_LOOKUP] = "lookup";
vcl_tnames[T_MUL] = "*=";
vcl_tnames[T_NEQ] = "!=";
vcl_tnames[T_NO_CACHE] = "no_cache";
vcl_tnames[T_NO_NEW_CACHE] = "no_new_cache";
- vcl_tnames[T_PASS] = "pass";
- vcl_tnames[T_PIPE] = "pipe";
vcl_tnames[T_PROC] = "proc";
vcl_tnames[T_REWRITE] = "rewrite";
vcl_tnames[T_SHL] = "<<";