Polish vcc_act_call()

Diff best viewed with -b option

- avoid the second call to VCC_SymbolGet(), unless necessary
- reorder from simple to complex

Ref 7ec28f1a
parent 95dfe7f0
......@@ -37,6 +37,11 @@ varnish v1 -errvcl {Symbol 'vcl_recv' type (sub) can not be used in expression.}
}
}
varnish v1 -errvcl {Symbol 'acl' type (reserved) can not be used in expression.} {
import std;
sub vcl_recv { call acl; }
}
varnish v1 -errvcl {Operator * not possible on type STRING.} {
sub vcl_recv {
set req.http.foo = "bla" * "foo";
......@@ -378,9 +383,9 @@ varnish v1 -errvcl {'||' must be preceeded by BOOL, found REAL.} {
sub vcl_recv { if (std.random(0,1) || 0) { } }
}
varnish v1 -errvcl {Symbol 'acl' has wrong type (reserved), expected sub:} {
varnish v1 -errvcl {Symbol 'acl' has wrong type (reserved), expected acl:} {
import std;
sub vcl_recv { call acl; }
sub vcl_recv { if (client.ip ~ acl) {} }
}
server s1 {
......
......@@ -50,41 +50,45 @@ vcc_act_call(struct vcc *tl, struct token *t, struct symbol *sym)
(void)t;
ExpectErr(tl, ID);
t0 = tl->t;
sym = VCC_SymbolGet(tl, SYM_MAIN, SYM_NONE, SYMTAB_NOERR, XREF_NONE);
tl->t = t0;
// only functions/methods may evaluate to SUB
if (sym != NULL && (sym->kind == SYM_FUNC || sym->kind == SYM_METHOD)) {
u = tl->unique++;
Fb(tl, 1, "{\n");
tl->indent += INDENT;
Fb(tl, 2, "VCL_SUB call_%u =\n", u);
tl->indent += INDENT;
vcc_Expr(tl, SUB);
Fb(tl, 2, ";\n\n");
SkipToken(tl, ';');
tl->indent -= INDENT;
Fb(tl, 2, "if (call_%u == NULL) {\n", u);
Fb(tl, 2, " VRT_fail(ctx, \"Tried to call NULL SUB near"
" source %%u line %%u\",\n");
Fb(tl, 2, " VGC_ref[%u].source,\n", tl->cnt);
Fb(tl, 2, " VGC_ref[%u].line);\n", tl->cnt);
Fb(tl, 2, " END_;\n");
Fb(tl, 2, "}\n");
Fb(tl, 2, "call_%u->func(ctx, VSUB_STATIC, NULL);\n", u);
tl->indent -= INDENT;
Fb(tl, 1, "}\n");
sym = VCC_SymbolGet(tl, SYM_MAIN, SYM_NONE, SYMTAB_NOERR, XREF_REF);
if (sym == NULL)
sym = VCC_SymbolGet(tl, SYM_MAIN, SYM_SUB, SYMTAB_CREATE,
XREF_REF);
if (sym == NULL)
return;
}
sym = VCC_SymbolGet(tl, SYM_MAIN, SYM_SUB, SYMTAB_CREATE, XREF_REF);
if (sym != NULL) {
if (sym->kind == SYM_SUB) {
vcc_AddCall(tl, t0, sym);
VCC_GlobalSymbol(sym, SUB, "VGC_function");
Fb(tl, 1, "%s(ctx, VSUB_STATIC, NULL);\n", sym->lname);
SkipToken(tl, ';');
return;
}
tl->t = t0;
u = tl->unique++;
Fb(tl, 1, "{\n");
tl->indent += INDENT;
Fb(tl, 2, "VCL_SUB call_%u =\n", u);
tl->indent += INDENT;
vcc_Expr(tl, SUB);
Fb(tl, 2, ";\n\n");
SkipToken(tl, ';');
tl->indent -= INDENT;
Fb(tl, 2, "if (call_%u == NULL) {\n", u);
Fb(tl, 2, " VRT_fail(ctx, \"Tried to call NULL SUB near"
" source %%u line %%u\",\n");
Fb(tl, 2, " VGC_ref[%u].source,\n", tl->cnt);
Fb(tl, 2, " VGC_ref[%u].line);\n", tl->cnt);
Fb(tl, 2, " END_;\n");
Fb(tl, 2, "}\n");
Fb(tl, 2, "call_%u->func(ctx, VSUB_STATIC, NULL);\n", u);
tl->indent -= INDENT;
Fb(tl, 1, "}\n");
}
/*--------------------------------------------------------------------*/
......
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