From: phk Date: Sat, 5 Aug 2006 18:11:31 +0000 (+0000) Subject: Make vcl methods call their defaults as a last resort. X-Git-Url: https://err.no/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=8ad66f1b9b7583603ed277454c63287bb0fab5ca;p=varnish Make vcl methods call their defaults as a last resort. Fix the location table so it knows about the default code too. git-svn-id: svn+ssh://projects.linpro.no/svn/varnish/trunk@682 d4fa192b-c00b-0410-8231-f00ffab90ce4 --- diff --git a/varnish-cache/include/vcl.h b/varnish-cache/include/vcl.h index 67a53dc4..fa281c26 100644 --- a/varnish-cache/include/vcl.h +++ b/varnish-cache/include/vcl.h @@ -22,7 +22,7 @@ struct VCL_conf { unsigned nref; unsigned busy; - void *priv; + void *priv; vcl_init_f *init_func; vcl_fini_f *fini_func; diff --git a/varnish-cache/include/vcl_returns.h b/varnish-cache/include/vcl_returns.h index ef965c1b..b1814abe 100644 --- a/varnish-cache/include/vcl_returns.h +++ b/varnish-cache/include/vcl_returns.h @@ -1,5 +1,5 @@ /* - * $Id: vcc_gen_fixed_token.tcl 556 2006-07-22 09:38:09Z phk $ + * $Id: vcc_gen_fixed_token.tcl 638 2006-08-04 10:54:30Z phk $ * * NB: This file is machine generated, DO NOT EDIT! * diff --git a/varnish-cache/include/vrt.h b/varnish-cache/include/vrt.h index 7b507703..71a32838 100644 --- a/varnish-cache/include/vrt.h +++ b/varnish-cache/include/vrt.h @@ -3,7 +3,7 @@ * * Runtime support for compiled VCL programs. * - * XXX: When this file is changed, lib/libvcl/vcl_gen_fixed_token.tcl + * XXX: When this file is changed, lib/libvcl/vcc_gen_fixed_token.tcl * XXX: *MUST* be rerun. */ @@ -13,6 +13,7 @@ struct backend; struct VCL_conf; struct vrt_ref { + unsigned file; unsigned line; unsigned pos; unsigned count; diff --git a/varnish-cache/lib/libvcl/vcc_compile.c b/varnish-cache/lib/libvcl/vcc_compile.c index 66898cb9..2fca8e96 100644 --- a/varnish-cache/lib/libvcl/vcc_compile.c +++ b/varnish-cache/lib/libvcl/vcc_compile.c @@ -190,6 +190,21 @@ EncString(struct token *t) return (p); } +/*--------------------------------------------------------------------*/ + +static int +IsMethod(struct token *t) +{ + struct method *m; + + for(m = method_tab; m->name != NULL; m++) { + if (vcc_IdIs(t, m->defname)) + return (2); + if (vcc_IdIs(t, m->name)) + return (1); + } + return (0); +} /*-------------------------------------------------------------------- * Keep track of definitions and references @@ -997,17 +1012,26 @@ Backend(struct tokenlist *tl) static void Function(struct tokenlist *tl) { + struct token *tn; vcc_NextToken(tl); ExpectErr(tl, ID); tl->curproc = AddProc(tl, tl->t, 1); tl->curproc->exists++; + tn = tl->t; AddDef(tl, tl->t, R_FUNC); Fh(tl, 0, "static int VGC_function_%T (struct sess *sp);\n", tl->t); Fc(tl, 1, "static int\n"); Fc(tl, 1, "VGC_function_%T (struct sess *sp)\n", tl->t); vcc_NextToken(tl); + tl->indent += INDENT; + Fc(tl, 1, "{\n"); L(tl, Compound(tl)); + if (IsMethod(tn) == 1) { + Fc(tl, 1, "VGC_function_default_%T(sp);\n", tn); + } + Fc(tl, 1, "}\n"); + tl->indent -= INDENT; Fc(tl, 0, "\n"); } @@ -1221,19 +1245,26 @@ static void LocTable(struct tokenlist *tl) { struct token *t; - unsigned lin, pos; + unsigned fil, lin, pos; const char *p; Fh(tl, 0, "#define VGC_NREFS %u\n", tl->cnt + 1); Fh(tl, 0, "static struct vrt_ref VGC_ref[VGC_NREFS];\n"); Fc(tl, 0, "static struct vrt_ref VGC_ref[VGC_NREFS] = {\n"); + fil = 0; lin = 1; pos = 0; - p = tl->b; + p = vcc_default_vcl_b; TAILQ_FOREACH(t, &tl->tokens, list) { if (t->cnt == 0) continue; for (;p < t->b; p++) { + if (p == vcc_default_vcl_e) { + p = tl->b; + fil = 1; + lin = 1; + pos = 0; + } if (*p == '\n') { lin++; pos = 0; @@ -1244,8 +1275,8 @@ LocTable(struct tokenlist *tl) pos++; } - Fc(tl, 0, " [%3u] = { %4u, %3u, 0, \"%T\" },\n", - t->cnt, lin, pos + 1, t); + Fc(tl, 0, " [%3u] = { %d, %4u, %3u, 0, \"%T\" },\n", + t->cnt, fil, lin, pos + 1, t); } Fc(tl, 0, "};\n"); } @@ -1341,8 +1372,8 @@ VCC_Compile(struct sbuf *sb, const char *b, const char *e) e = strchr(b, '\0'); assert(e != NULL); tokens.e = e; - vcc_Lexer(&tokens, b, e); vcc_Lexer(&tokens, vcc_default_vcl_b, vcc_default_vcl_e); + vcc_Lexer(&tokens, b, e); vcc_AddToken(&tokens, EOI, e, e); if (tokens.err) goto done; diff --git a/varnish-cache/lib/libvcl/vcc_fixed_token.c b/varnish-cache/lib/libvcl/vcc_fixed_token.c index fb254bca..1777c6e8 100644 --- a/varnish-cache/lib/libvcl/vcc_fixed_token.c +++ b/varnish-cache/lib/libvcl/vcc_fixed_token.c @@ -455,7 +455,7 @@ vcl_output_lang_h(FILE *f) fputs(" unsigned nref;\n", f); fputs(" unsigned busy;\n", f); fputs("\n", f); - fputs(" void *priv;\n", f); + fputs(" void *priv;\n", f); fputs("\n", f); fputs(" vcl_init_f *init_func;\n", f); fputs(" vcl_fini_f *fini_func;\n", f); @@ -471,7 +471,7 @@ vcl_output_lang_h(FILE *f) fputs(" *\n", f); fputs(" * Runtime support for compiled VCL programs.\n", f); fputs(" *\n", f); - fputs(" * XXX: When this file is changed, lib/libvcl/vcl_gen_fixed_token.tcl\n", f); + fputs(" * XXX: When this file is changed, lib/libvcl/vcc_gen_fixed_token.tcl\n", f); fputs(" * XXX: *MUST* be rerun.\n", f); fputs(" */\n", f); fputs("\n", f); @@ -481,6 +481,7 @@ vcl_output_lang_h(FILE *f) fputs("struct VCL_conf;\n", f); fputs("\n", f); fputs("struct vrt_ref {\n", f); + fputs(" unsigned file;\n", f); fputs(" unsigned line;\n", f); fputs(" unsigned pos;\n", f); fputs(" unsigned count;\n", f);