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.} ...@@ -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.} { varnish v1 -errvcl {Operator * not possible on type STRING.} {
sub vcl_recv { sub vcl_recv {
set req.http.foo = "bla" * "foo"; set req.http.foo = "bla" * "foo";
...@@ -378,9 +383,9 @@ varnish v1 -errvcl {'||' must be preceeded by BOOL, found REAL.} { ...@@ -378,9 +383,9 @@ varnish v1 -errvcl {'||' must be preceeded by BOOL, found REAL.} {
sub vcl_recv { if (std.random(0,1) || 0) { } } 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; import std;
sub vcl_recv { call acl; } sub vcl_recv { if (client.ip ~ acl) {} }
} }
server s1 { server s1 {
......
...@@ -50,41 +50,45 @@ vcc_act_call(struct vcc *tl, struct token *t, struct symbol *sym) ...@@ -50,41 +50,45 @@ vcc_act_call(struct vcc *tl, struct token *t, struct symbol *sym)
(void)t; (void)t;
ExpectErr(tl, ID); ExpectErr(tl, ID);
t0 = tl->t; t0 = tl->t;
sym = VCC_SymbolGet(tl, SYM_MAIN, SYM_NONE, SYMTAB_NOERR, XREF_NONE); sym = VCC_SymbolGet(tl, SYM_MAIN, SYM_NONE, SYMTAB_NOERR, XREF_REF);
tl->t = t0;
// only functions/methods may evaluate to SUB if (sym == NULL)
if (sym != NULL && (sym->kind == SYM_FUNC || sym->kind == SYM_METHOD)) { sym = VCC_SymbolGet(tl, SYM_MAIN, SYM_SUB, SYMTAB_CREATE,
u = tl->unique++; XREF_REF);
Fb(tl, 1, "{\n"); if (sym == NULL)
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");
return; return;
}
sym = VCC_SymbolGet(tl, SYM_MAIN, SYM_SUB, SYMTAB_CREATE, XREF_REF); if (sym->kind == SYM_SUB) {
if (sym != NULL) {
vcc_AddCall(tl, t0, sym); vcc_AddCall(tl, t0, sym);
VCC_GlobalSymbol(sym, SUB, "VGC_function"); VCC_GlobalSymbol(sym, SUB, "VGC_function");
Fb(tl, 1, "%s(ctx, VSUB_STATIC, NULL);\n", sym->lname); Fb(tl, 1, "%s(ctx, VSUB_STATIC, NULL);\n", sym->lname);
SkipToken(tl, ';'); 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