From bc1fc62bc638d8b564c9e038ee7d9f31b3071ec0 Mon Sep 17 00:00:00 2001 From: phk Date: Sun, 1 Apr 2007 15:33:56 +0000 Subject: [PATCH] Remove unused METHOD token. Improve error handling for unterminated /* ... */ comments. Add undocumented and unsupported facility for inline C source code in VCL programs. The syntax is "C{ getpid(); }C" and you are on your own if you use this. git-svn-id: svn+ssh://projects.linpro.no/svn/varnish/trunk@1301 d4fa192b-c00b-0410-8231-f00ffab90ce4 --- varnish-cache/lib/libvcl/vcc_fixed_token.c | 2 +- .../lib/libvcl/vcc_gen_fixed_token.tcl | 2 +- varnish-cache/lib/libvcl/vcc_parse.c | 6 +++ varnish-cache/lib/libvcl/vcc_token.c | 37 +++++++++++++++---- varnish-cache/lib/libvcl/vcc_token_defs.h | 2 +- varnish-cache/lib/libvcl/vcc_xref.c | 5 --- 6 files changed, 39 insertions(+), 15 deletions(-) diff --git a/varnish-cache/lib/libvcl/vcc_fixed_token.c b/varnish-cache/lib/libvcl/vcc_fixed_token.c index 864ddc9e..69e8a778 100644 --- a/varnish-cache/lib/libvcl/vcc_fixed_token.c +++ b/varnish-cache/lib/libvcl/vcc_fixed_token.c @@ -268,10 +268,10 @@ vcl_init_tnames(void) vcl_tnames['~'] = "'~'"; vcl_tnames[';'] = "';'"; vcl_tnames[CNUM] = "CNUM"; + vcl_tnames[CSRC] = "CSRC"; vcl_tnames[CSTR] = "CSTR"; vcl_tnames[EOI] = "EOI"; vcl_tnames[ID] = "ID"; - vcl_tnames[METHOD] = "METHOD"; vcl_tnames[T_ACL] = "acl"; vcl_tnames[T_BACKEND] = "backend"; vcl_tnames[T_CAND] = "&&"; diff --git a/varnish-cache/lib/libvcl/vcc_gen_fixed_token.tcl b/varnish-cache/lib/libvcl/vcc_gen_fixed_token.tcl index c4d32c74..4a8ba4df 100755 --- a/varnish-cache/lib/libvcl/vcc_gen_fixed_token.tcl +++ b/varnish-cache/lib/libvcl/vcc_gen_fixed_token.tcl @@ -97,7 +97,7 @@ set char {{}()*+-/%><=;!&.|~,} # Other token identifiers # -set extras {ID VAR CNUM CSTR EOI METHOD} +set extras {ID VAR CNUM CSTR EOI CSRC} #---------------------------------------------------------------------- # Boilerplate warning for all generated files. diff --git a/varnish-cache/lib/libvcl/vcc_parse.c b/varnish-cache/lib/libvcl/vcc_parse.c index 6b485b8e..a6c46458 100644 --- a/varnish-cache/lib/libvcl/vcc_parse.c +++ b/varnish-cache/lib/libvcl/vcc_parse.c @@ -487,6 +487,12 @@ Compound(struct tokenlist *tl) tl->indent -= INDENT; Fb(tl, 1, "}\n"); return; + case CSRC: + Fb(tl, 1, "%.*s\n", + tl->t->e - (tl->t->b + 2), + tl->t->b + 1); + vcc_NextToken(tl); + break; case EOI: vsb_printf(tl->sb, "End of input while in compound statement\n"); diff --git a/varnish-cache/lib/libvcl/vcc_token.c b/varnish-cache/lib/libvcl/vcc_token.c index 00ff0429..9e496724 100644 --- a/varnish-cache/lib/libvcl/vcc_token.c +++ b/varnish-cache/lib/libvcl/vcc_token.c @@ -49,6 +49,8 @@ vcc_ErrToken(struct tokenlist *tl, struct token *t) if (t->tok == EOI) vsb_printf(tl->sb, "end of input"); + else if (t->tok == CSRC) + vsb_printf(tl->sb, "C{ ... }C"); else vsb_printf(tl->sb, "'%.*s'", PF(t)); } @@ -71,8 +73,6 @@ vcc_ErrWhere(struct tokenlist *tl, struct token *t) lin = 1; pos = 0; - if (t->tok == METHOD) - return; sp = t->src; f = sp->name; b = sp->b; @@ -315,14 +315,18 @@ vcc_Lexer(struct tokenlist *tl, struct source *sp) /* Skip C-style comments */ if (*p == '/' && p[1] == '*') { - p += 2; - for (p += 2; p < sp->e; p++) { - if (*p == '*' && p[1] == '/') { - p += 2; + for (q += 2; q < sp->e; q++) { + if (*q == '*' && q[1] == '/') { + p = q + 2; break; } } - continue; + if (q < sp->e) + continue; + vcc_AddToken(tl, EOI, p, p + 2); + vsb_printf(tl->sb, "Unterminated /* ... */ comment, starting at\n"); + vcc_ErrWhere(tl, tl->t); + return; } /* Skip C++-style comments */ @@ -332,6 +336,25 @@ vcc_Lexer(struct tokenlist *tl, struct source *sp) continue; } + /* Recognize inline C-code */ + if (*p == 'C' && p[1] == '{') { + for (q = p + 2; q < sp->e; q++) { + if (*q == '}' && q[1] == 'C') { + vcc_AddToken(tl, CSRC, p, q + 2); + p = q + 2; + break; + } + } + if (q < sp->e) + continue; + vcc_AddToken(tl, EOI, p, p + 2); + vsb_printf(tl->sb, + "Unterminated inline C source, starting at\n"); + vcc_ErrWhere(tl, tl->t); + return; + } + + /* Match for the fixed tokens (see token.tcl) */ u = vcl_fixed_token(p, &q); if (u != 0) { diff --git a/varnish-cache/lib/libvcl/vcc_token_defs.h b/varnish-cache/lib/libvcl/vcc_token_defs.h index d5ebec7d..9a5d81ee 100644 --- a/varnish-cache/lib/libvcl/vcc_token_defs.h +++ b/varnish-cache/lib/libvcl/vcc_token_defs.h @@ -34,4 +34,4 @@ #define CNUM 152 #define CSTR 153 #define EOI 154 -#define METHOD 155 +#define CSRC 155 diff --git a/varnish-cache/lib/libvcl/vcc_xref.c b/varnish-cache/lib/libvcl/vcc_xref.c index b45d884d..68c8ec54 100644 --- a/varnish-cache/lib/libvcl/vcc_xref.c +++ b/varnish-cache/lib/libvcl/vcc_xref.c @@ -149,11 +149,6 @@ vcc_CheckReferences(struct tokenlist *tl) nerr++; type = vcc_typename(tl, r); - if (r->defcnt == 0 && r->name->tok == METHOD) { - vsb_printf(tl->sb, - "No definition for method %.*s\n", PF(r->name)); - continue; - } if (r->defcnt == 0) { vsb_printf(tl->sb, -- 2.39.5