Commit b63632da authored by Poul-Henning Kamp's avatar Poul-Henning Kamp

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: http://www.varnish-cache.org/svn/trunk/varnish-cache@1301 d4fa192b-c00b-0410-8231-f00ffab90ce4
parent 18fd375e
...@@ -268,10 +268,10 @@ vcl_init_tnames(void) ...@@ -268,10 +268,10 @@ vcl_init_tnames(void)
vcl_tnames['~'] = "'~'"; vcl_tnames['~'] = "'~'";
vcl_tnames[';'] = "';'"; vcl_tnames[';'] = "';'";
vcl_tnames[CNUM] = "CNUM"; vcl_tnames[CNUM] = "CNUM";
vcl_tnames[CSRC] = "CSRC";
vcl_tnames[CSTR] = "CSTR"; vcl_tnames[CSTR] = "CSTR";
vcl_tnames[EOI] = "EOI"; vcl_tnames[EOI] = "EOI";
vcl_tnames[ID] = "ID"; vcl_tnames[ID] = "ID";
vcl_tnames[METHOD] = "METHOD";
vcl_tnames[T_ACL] = "acl"; vcl_tnames[T_ACL] = "acl";
vcl_tnames[T_BACKEND] = "backend"; vcl_tnames[T_BACKEND] = "backend";
vcl_tnames[T_CAND] = "&&"; vcl_tnames[T_CAND] = "&&";
......
...@@ -97,7 +97,7 @@ set char {{}()*+-/%><=;!&.|~,} ...@@ -97,7 +97,7 @@ set char {{}()*+-/%><=;!&.|~,}
# Other token identifiers # 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. # Boilerplate warning for all generated files.
......
...@@ -487,6 +487,12 @@ Compound(struct tokenlist *tl) ...@@ -487,6 +487,12 @@ Compound(struct tokenlist *tl)
tl->indent -= INDENT; tl->indent -= INDENT;
Fb(tl, 1, "}\n"); Fb(tl, 1, "}\n");
return; 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: case EOI:
vsb_printf(tl->sb, vsb_printf(tl->sb,
"End of input while in compound statement\n"); "End of input while in compound statement\n");
......
...@@ -49,6 +49,8 @@ vcc_ErrToken(struct tokenlist *tl, struct token *t) ...@@ -49,6 +49,8 @@ vcc_ErrToken(struct tokenlist *tl, struct token *t)
if (t->tok == EOI) if (t->tok == EOI)
vsb_printf(tl->sb, "end of input"); vsb_printf(tl->sb, "end of input");
else if (t->tok == CSRC)
vsb_printf(tl->sb, "C{ ... }C");
else else
vsb_printf(tl->sb, "'%.*s'", PF(t)); vsb_printf(tl->sb, "'%.*s'", PF(t));
} }
...@@ -71,8 +73,6 @@ vcc_ErrWhere(struct tokenlist *tl, struct token *t) ...@@ -71,8 +73,6 @@ vcc_ErrWhere(struct tokenlist *tl, struct token *t)
lin = 1; lin = 1;
pos = 0; pos = 0;
if (t->tok == METHOD)
return;
sp = t->src; sp = t->src;
f = sp->name; f = sp->name;
b = sp->b; b = sp->b;
...@@ -315,14 +315,18 @@ vcc_Lexer(struct tokenlist *tl, struct source *sp) ...@@ -315,14 +315,18 @@ vcc_Lexer(struct tokenlist *tl, struct source *sp)
/* Skip C-style comments */ /* Skip C-style comments */
if (*p == '/' && p[1] == '*') { if (*p == '/' && p[1] == '*') {
p += 2; for (q += 2; q < sp->e; q++) {
for (p += 2; p < sp->e; p++) { if (*q == '*' && q[1] == '/') {
if (*p == '*' && p[1] == '/') { p = q + 2;
p += 2;
break; break;
} }
} }
if (q < sp->e)
continue; 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 */ /* Skip C++-style comments */
...@@ -332,6 +336,25 @@ vcc_Lexer(struct tokenlist *tl, struct source *sp) ...@@ -332,6 +336,25 @@ vcc_Lexer(struct tokenlist *tl, struct source *sp)
continue; 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) */ /* Match for the fixed tokens (see token.tcl) */
u = vcl_fixed_token(p, &q); u = vcl_fixed_token(p, &q);
if (u != 0) { if (u != 0) {
......
...@@ -34,4 +34,4 @@ ...@@ -34,4 +34,4 @@
#define CNUM 152 #define CNUM 152
#define CSTR 153 #define CSTR 153
#define EOI 154 #define EOI 154
#define METHOD 155 #define CSRC 155
...@@ -149,11 +149,6 @@ vcc_CheckReferences(struct tokenlist *tl) ...@@ -149,11 +149,6 @@ vcc_CheckReferences(struct tokenlist *tl)
nerr++; nerr++;
type = vcc_typename(tl, r); 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) { if (r->defcnt == 0) {
vsb_printf(tl->sb, vsb_printf(tl->sb,
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment