From ac363c5b6f50aeff2ddc404cfb98959bc812ad18 Mon Sep 17 00:00:00 2001 From: phk Date: Sun, 1 Apr 2007 09:07:44 +0000 Subject: [PATCH] Implement the returns with the new ID based table and eliminate their corresponding dedicated tokens. git-svn-id: svn+ssh://projects.linpro.no/svn/varnish/trunk@1298 d4fa192b-c00b-0410-8231-f00ffab90ce4 --- varnish-cache/lib/libvcl/vcc_action.c | 95 ++++++++++++------- varnish-cache/lib/libvcl/vcc_fixed_token.c | 72 -------------- .../lib/libvcl/vcc_gen_fixed_token.tcl | 2 - varnish-cache/lib/libvcl/vcc_token_defs.h | 58 +++++------ 4 files changed, 87 insertions(+), 140 deletions(-) diff --git a/varnish-cache/lib/libvcl/vcc_action.c b/varnish-cache/lib/libvcl/vcc_action.c index 822795df..4e0a78a7 100644 --- a/varnish-cache/lib/libvcl/vcc_action.c +++ b/varnish-cache/lib/libvcl/vcc_action.c @@ -69,12 +69,67 @@ /*--------------------------------------------------------------------*/ +#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); @@ -166,12 +221,18 @@ parse_set(struct tokenlist *tl) /*--------------------------------------------------------------------*/ -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 } }; @@ -180,12 +241,10 @@ static struct action_table { 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)) { @@ -194,6 +253,7 @@ vcc_ParseAction(struct tokenlist *tl) } } } + vcc_NextToken(tl); switch (at->tok) { case T_NO_NEW_CACHE: Fb(tl, 1, "VCL_no_new_cache(sp);\n"); @@ -201,40 +261,11 @@ vcc_ParseAction(struct tokenlist *tl) 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)); diff --git a/varnish-cache/lib/libvcl/vcc_fixed_token.c b/varnish-cache/lib/libvcl/vcc_fixed_token.c index 70031da6..bc2b5036 100644 --- a/varnish-cache/lib/libvcl/vcc_fixed_token.c +++ b/varnish-cache/lib/libvcl/vcc_fixed_token.c @@ -173,33 +173,7 @@ vcl_fixed_token(const char *p, const char **q) 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; @@ -223,26 +197,8 @@ vcl_fixed_token(const char *p, const char **q) *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])) { @@ -254,14 +210,6 @@ vcl_fixed_token(const char *p, const char **q) 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' && @@ -284,16 +232,6 @@ vcl_fixed_token(const char *p, const char **q) *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' && @@ -382,36 +320,26 @@ vcl_init_tnames(void) 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] = "<<"; diff --git a/varnish-cache/lib/libvcl/vcc_gen_fixed_token.tcl b/varnish-cache/lib/libvcl/vcc_gen_fixed_token.tcl index a01bae8a..ce94a454 100755 --- a/varnish-cache/lib/libvcl/vcc_gen_fixed_token.tcl +++ b/varnish-cache/lib/libvcl/vcc_gen_fixed_token.tcl @@ -71,7 +71,6 @@ set keywords { backend - call no_cache no_new_cache rewrite @@ -234,7 +233,6 @@ proc mk_token {tok str alpha} { } foreach k $keywords { mk_token $k $k 1 } -foreach k $returns { mk_token $k $k 1 } foreach k $magic { mk_token [lindex $k 1] [lindex $k 0] 0 } foreach k $extras { set t [string toupper $k] diff --git a/varnish-cache/lib/libvcl/vcc_token_defs.h b/varnish-cache/lib/libvcl/vcc_token_defs.h index 8d91ba28..74526f23 100644 --- a/varnish-cache/lib/libvcl/vcc_token_defs.h +++ b/varnish-cache/lib/libvcl/vcc_token_defs.h @@ -17,37 +17,27 @@ #define T_SUB 135 #define T_ACL 136 #define T_BACKEND 137 -#define T_CALL 138 -#define T_NO_CACHE 139 -#define T_NO_NEW_CACHE 140 -#define T_REWRITE 141 -#define T_SWITCH_CONFIG 142 -#define T_ERROR 143 -#define T_LOOKUP 144 -#define T_HASH 145 -#define T_PIPE 146 -#define T_PASS 147 -#define T_FETCH 148 -#define T_INSERT 149 -#define T_DELIVER 150 -#define T_DISCARD 151 -#define T_INC 152 -#define T_DEC 153 -#define T_CAND 154 -#define T_COR 155 -#define T_LEQ 156 -#define T_EQ 157 -#define T_NEQ 158 -#define T_GEQ 159 -#define T_SHR 160 -#define T_SHL 161 -#define T_INCR 162 -#define T_DECR 163 -#define T_MUL 164 -#define T_DIV 165 -#define ID 166 -#define VAR 167 -#define CNUM 168 -#define CSTR 169 -#define EOI 170 -#define METHOD 171 +#define T_NO_CACHE 138 +#define T_NO_NEW_CACHE 139 +#define T_REWRITE 140 +#define T_SWITCH_CONFIG 141 +#define T_INC 142 +#define T_DEC 143 +#define T_CAND 144 +#define T_COR 145 +#define T_LEQ 146 +#define T_EQ 147 +#define T_NEQ 148 +#define T_GEQ 149 +#define T_SHR 150 +#define T_SHL 151 +#define T_INCR 152 +#define T_DECR 153 +#define T_MUL 154 +#define T_DIV 155 +#define ID 156 +#define VAR 157 +#define CNUM 158 +#define CSTR 159 +#define EOI 160 +#define METHOD 161 -- 2.39.5