[master] b2a86df62 Introduce a "reserved" symboltype and wrangle an error message or two.

Poul-Henning Kamp phk at FreeBSD.org
Thu May 16 08:12:10 UTC 2019


commit b2a86df62afc206ec03dc034aada220bc659db1e
Author: Poul-Henning Kamp <phk at FreeBSD.org>
Date:   Thu May 16 08:11:13 2019 +0000

    Introduce a "reserved" symboltype and wrangle an error message or two.

diff --git a/bin/varnishtest/tests/m00001.vtc b/bin/varnishtest/tests/m00001.vtc
index 6e0781262..1a676c673 100644
--- a/bin/varnishtest/tests/m00001.vtc
+++ b/bin/varnishtest/tests/m00001.vtc
@@ -66,7 +66,7 @@ varnish v1 -cliok "vcl.discard vcl2"
 varnish v1 -cliok "vcl.list"
 varnish v1 -cliok "debug.vmod"
 
-varnish v1 -errvcl {Symbol type (vmod) can not be used in expression.} {
+varnish v1 -errvcl {Symbol 'std' type (vmod) can not be used in expression.} {
 	import std;
 
 	sub vcl_recv {
diff --git a/bin/varnishtest/tests/v00020.vtc b/bin/varnishtest/tests/v00020.vtc
index 1c61f02e5..919624a41 100644
--- a/bin/varnishtest/tests/v00020.vtc
+++ b/bin/varnishtest/tests/v00020.vtc
@@ -20,7 +20,7 @@ varnish v1 -errvcl {Found: '0' at} { 0; }
 # VCLs tokenstream.
 # XXX: A better error message would be desirable
 
-varnish v1 -errvcl {Symbol not found} " sub vcl_recv { { } { "
+varnish v1 -errvcl {Symbol cannot be used here} " sub vcl_recv { { } { "
 
 varnish v1 -errvcl {Comparison of different types: INT '!=' STRING} {
 	sub vcl_recv {
@@ -31,7 +31,7 @@ varnish v1 -errvcl {Comparison of different types: INT '!=' STRING} {
 	}
 }
 
-varnish v1 -errvcl {Symbol type (sub) can not be used in expression.} {
+varnish v1 -errvcl {Symbol 'vcl_recv' type (sub) can not be used in expression.} {
 	sub vcl_recv {
 		set req.http.foo = vcl_recv;
 	}
@@ -307,6 +307,11 @@ 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):} {
+	import std;
+	sub vcl_recv { call acl; }
+}
+
 server s1 {
 	rxreq
 	txresp -hdr "bar: X"
diff --git a/include/tbl/symbol_kind.h b/include/tbl/symbol_kind.h
index bfae2c1e2..8c0294373 100644
--- a/include/tbl/symbol_kind.h
+++ b/include/tbl/symbol_kind.h
@@ -30,6 +30,7 @@
 /*lint -save -e525 -e539 */
 
 VCC_KIND(NONE,		none)
+VCC_KIND(RESERVED,	reserved)
 VCC_KIND(ACL,		acl)
 VCC_KIND(ACTION,	action)
 VCC_KIND(BACKEND,	backend)
diff --git a/lib/libvcc/vcc_action.c b/lib/libvcc/vcc_action.c
index af1d7fee6..8126f9924 100644
--- a/lib/libvcc/vcc_action.c
+++ b/lib/libvcc/vcc_action.c
@@ -46,11 +46,12 @@ vcc_act_call(struct vcc *tl, struct token *t, struct symbol *sym)
 	(void)t;
 	ExpectErr(tl, ID);
 	sym = VCC_SymbolGet(tl, SYM_SUB, SYMTAB_CREATE, XREF_REF);
-	AN(sym);
-	vcc_AddCall(tl, sym);
-	VCC_GlobalSymbol(sym, SUB, "VGC_function");
-	Fb(tl, 1, "%s(ctx);\n", sym->rname);
-	SkipToken(tl, ';');
+	if (sym != NULL) {
+		vcc_AddCall(tl, sym);
+		VCC_GlobalSymbol(sym, SUB, "VGC_function");
+		Fb(tl, 1, "%s(ctx);\n", sym->rname);
+		SkipToken(tl, ';');
+	}
 }
 
 /*--------------------------------------------------------------------*/
diff --git a/lib/libvcc/vcc_expr.c b/lib/libvcc/vcc_expr.c
index e8fd18a28..d04444dae 100644
--- a/lib/libvcc/vcc_expr.c
+++ b/lib/libvcc/vcc_expr.c
@@ -713,9 +713,9 @@ vcc_expr4(struct vcc *tl, struct expr **e, vcc_type_t fmt)
 			return;
 		}
 		VSB_printf(tl->sb,
-		    "Symbol type (%s) can not be used in expression.\n",
-		    sym->kind->name);
-		vcc_ErrWhere(tl, tl->t);
+		    "Symbol '%.*s' type (%s) can not be used in expression.\n",
+		    PF(t), sym->kind->name);
+		vcc_ErrWhere(tl, t);
 		if (sym->def_b != NULL) {
 			VSB_printf(tl->sb, "That symbol was defined here:\n");
 			vcc_ErrWhere(tl, sym->def_b);
diff --git a/lib/libvcc/vcc_parse.c b/lib/libvcc/vcc_parse.c
index ce0deb08c..bb695ba92 100644
--- a/lib/libvcc/vcc_parse.c
+++ b/lib/libvcc/vcc_parse.c
@@ -434,5 +434,5 @@ vcc_Parse_Init(struct vcc *tl)
 	struct toplev *tp;
 
 	for (tp = toplev; tp->name != NULL; tp++)
-		AN(VCC_MkSym(tl, tp->name, SYM_NONE, tp->vcllo, tp->vclhi));
+		AN(VCC_MkSym(tl, tp->name, SYM_RESERVED, tp->vcllo, tp->vclhi));
 }


More information about the varnish-commit mailing list