[master] ad3455c Don't assume symbols are a single token (xref-edition) (3/many)
Poul-Henning Kamp
phk at FreeBSD.org
Wed Jan 31 10:50:10 UTC 2018
commit ad3455c7b815419b19896d43c98c052b5e65426a
Author: Poul-Henning Kamp <phk at FreeBSD.org>
Date: Wed Jan 31 10:11:42 2018 +0000
Don't assume symbols are a single token (xref-edition) (3/many)
diff --git a/bin/varnishtest/tests/v00038.vtc b/bin/varnishtest/tests/v00038.vtc
index 9b8cfb0..f4a8c88 100644
--- a/bin/varnishtest/tests/v00038.vtc
+++ b/bin/varnishtest/tests/v00038.vtc
@@ -92,8 +92,20 @@ varnish v1 -errvcl "Mandatory field 'host' missing." {
.port = "NONE";
}
}
+
varnish v1 -errvcl "No default probe defined" {
backend b1 {
.probe = default;
}
}
+
+varnish v1 -errvcl "Only one default director possible." {
+ backend b1 { .host = "127.0.0.1"; }
+ backend default { .host = "127.0.0.1"; }
+ backend default { .host = "127.0.0.1"; }
+}
+
+varnish v1 -errvcl "Unused backend b1, defined:" {
+ backend b1 { .host = "127.0.0.1"; }
+ backend default { .host = "127.0.0.1"; }
+}
diff --git a/lib/libvcc/vcc_backend.c b/lib/libvcc/vcc_backend.c
index 64f73ac..28d05c9 100644
--- a/lib/libvcc/vcc_backend.c
+++ b/lib/libvcc/vcc_backend.c
@@ -485,6 +485,17 @@ vcc_ParseBackend(struct vcc *tl)
t_be = tl->t;
if (vcc_IdIs(tl->t, "default")) {
+ if (tl->first_director != NULL) {
+ tl->first_director->noref = 0;
+ tl->first_director = NULL;
+ tl->default_director = NULL;
+ }
+ if (tl->default_director != NULL) {
+ VSB_printf(tl->sb,
+ "Only one default director possible.\n");
+ vcc_ErrWhere(tl, t_first);
+ return;
+ }
vcc_NextToken(tl);
dn = "vgc_backend_default";
tl->default_director = dn;
@@ -493,8 +504,9 @@ vcc_ParseBackend(struct vcc *tl)
ERRCHK(tl);
dn = sym->rname;
if (tl->default_director == NULL) {
+ tl->first_director = sym;
tl->default_director = dn;
- sym->nref++;
+ sym->noref = 1;
}
}
Fh(tl, 0, "\nstatic struct director *%s;\n", dn);
diff --git a/lib/libvcc/vcc_compile.h b/lib/libvcc/vcc_compile.h
index 0bfed2a..699b9ff 100644
--- a/lib/libvcc/vcc_compile.h
+++ b/lib/libvcc/vcc_compile.h
@@ -136,7 +136,7 @@ struct symbol {
/* xref.c */
struct proc *proc;
- unsigned nref, ndef;
+ unsigned noref, nref, ndef;
const char *extra;
@@ -223,6 +223,7 @@ struct vcc {
int nprobe;
int ndirector;
+ struct symbol *first_director;
const char *default_director;
const char *default_probe;
@@ -279,7 +280,7 @@ char *TlDup(struct vcc *tl, const char *s);
/* vcc_expr.c */
void vcc_Expr(struct vcc *tl, vcc_type_t typ);
-sym_act_f vcc_ParseCall;
+sym_act_f vcc_Act_Call;
void vcc_Expr_Init(struct vcc *tl);
sym_expr_t vcc_Eval_Var;
sym_expr_t vcc_Eval_Handle;
@@ -353,7 +354,6 @@ void vcc_ParseImport(struct vcc *tl);
sym_act_f vcc_Act_New;
/* vcc_xref.c */
-void vcc_AddRef(struct vcc *, struct symbol *);
int vcc_CheckReferences(struct vcc *tl);
void VCC_XrefTable(struct vcc *);
diff --git a/lib/libvcc/vcc_expr.c b/lib/libvcc/vcc_expr.c
index f874d58..cdbfa61 100644
--- a/lib/libvcc/vcc_expr.c
+++ b/lib/libvcc/vcc_expr.c
@@ -332,9 +332,9 @@ vcc_Eval_Handle(struct vcc *tl, struct expr **e, struct token *t,
{
(void)t;
+ (void)tl;
AN(sym->rname);
- vcc_AddRef(tl, sym);
if (sym->fmt != STRING && fmt == STRINGS) {
*e = vcc_mk_expr(STRINGS, "\"%s\"", sym->name);
(*e)->nstr = 1;
@@ -660,7 +660,7 @@ vcc_expr4(struct vcc *tl, struct expr **e, vcc_type_t fmt)
return;
}
sym = VCC_SymbolGet(tl, SYM_NONE, "Symbol not found",
- XREF_NONE);
+ XREF_REF);
ERRCHK(tl);
AN(sym);
if (sym->kind == SYM_FUNC && sym->fmt == VOID) {
@@ -688,6 +688,7 @@ vcc_expr4(struct vcc *tl, struct expr **e, vcc_type_t fmt)
}
return;
default:
+ AZ(sym->eval);
break;
}
VSB_printf(tl->sb,
@@ -1264,7 +1265,7 @@ vcc_Expr(struct vcc *tl, vcc_type_t fmt)
*/
void v_matchproto_(sym_act_f)
-vcc_ParseCall(struct vcc *tl, struct token *t, struct symbol *sym)
+vcc_Act_Call(struct vcc *tl, struct token *t, struct symbol *sym)
{
struct expr *e;
diff --git a/lib/libvcc/vcc_parse.c b/lib/libvcc/vcc_parse.c
index a64e143..b94e0a0 100644
--- a/lib/libvcc/vcc_parse.c
+++ b/lib/libvcc/vcc_parse.c
@@ -212,12 +212,14 @@ static void
vcc_ParseFunction(struct vcc *tl)
{
struct symbol *sym;
+ struct token *t;
struct proc *p;
vcc_NextToken(tl);
vcc_ExpectVid(tl, "function");
ERRCHK(tl);
+ t = tl->t;
sym = VCC_SymbolGet(tl, SYM_SUB, SYMTAB_CREATE, XREF_DEF);
AN(sym);
p = sym->proc;
@@ -249,10 +251,8 @@ vcc_ParseFunction(struct vcc *tl)
} else {
/* Add to VCL sub */
AN(p->method);
- if (p->name == NULL) {
- vcc_AddRef(tl, sym);
- p->name = tl->t;
- }
+ if (p->name == NULL)
+ p->name = t;
}
CHECK_OBJ_NOTNULL(p, PROC_MAGIC);
tl->fb = p->body;
diff --git a/lib/libvcc/vcc_symb.c b/lib/libvcc/vcc_symb.c
index f79068e..51354eb 100644
--- a/lib/libvcc/vcc_symb.c
+++ b/lib/libvcc/vcc_symb.c
@@ -227,7 +227,11 @@ VCC_SymbolGet(struct vcc *tl, enum symkind kind, const char *e, const char *x)
struct symbol *
VCC_MkSym(struct vcc *tl, const char *b, enum symkind kind)
{
- return (VCC_Symbol(tl, NULL, b, NULL, kind, 1));
+ struct symbol *sym;
+
+ sym = VCC_Symbol(tl, NULL, b, NULL, kind, 1);
+ sym->noref = 1;
+ return (sym);
}
diff --git a/lib/libvcc/vcc_var.c b/lib/libvcc/vcc_var.c
index ce09c4b..5c8eadf 100644
--- a/lib/libvcc/vcc_var.c
+++ b/lib/libvcc/vcc_var.c
@@ -51,6 +51,7 @@ vcc_Var_Wildcard(struct vcc *tl, struct symbol *parent, struct symbol *sym)
}
AN(sym);
+ sym->noref = 1;
sym->kind = SYM_VAR;
sym->fmt = parent->fmt;
sym->eval = vcc_Eval_Var;
diff --git a/lib/libvcc/vcc_vmod.c b/lib/libvcc/vcc_vmod.c
index e0c0fdd..168ca04 100644
--- a/lib/libvcc/vcc_vmod.c
+++ b/lib/libvcc/vcc_vmod.c
@@ -245,7 +245,7 @@ vcc_ParseImport(struct vcc *tl)
sym = VCC_MkSym(tl, p, SYM_FUNC);
ERRCHK(tl);
AN(sym);
- sym->action = vcc_ParseCall;
+ sym->action = vcc_Act_Call;
sym->vmod = msym->name;
sym->eval = vcc_Eval_SymFunc;
p += strlen(p) + 1;
@@ -281,9 +281,7 @@ vcc_Act_New(struct vcc *tl, struct token *t, struct symbol *sym)
ERRCHK(tl);
sy1 = VCC_HandleSymbol(tl, INSTANCE, "vo");
ERRCHK(tl);
-
- /* We allow implicit use of VMOD objects: Pretend it's ref'ed */
- sy1->nref++;
+ sy1->noref = 1;
ExpectErr(tl, '=');
vcc_NextToken(tl);
@@ -335,7 +333,7 @@ vcc_Act_New(struct vcc *tl, struct token *t, struct symbol *sym)
bprintf(buf2, "%s%s", sy1->name, p);
sy3 = VCC_MkSym(tl, buf2, SYM_FUNC);
AN(sy3);
- sy3->action = vcc_ParseCall;
+ sy3->action = vcc_Act_Call;
sy3->eval = vcc_Eval_SymFunc;
p += strlen(p) + 1;
sy3->eval_priv = p;
diff --git a/lib/libvcc/vcc_xref.c b/lib/libvcc/vcc_xref.c
index 31655dc..a419f8b 100644
--- a/lib/libvcc/vcc_xref.c
+++ b/lib/libvcc/vcc_xref.c
@@ -59,26 +59,14 @@ struct procuse {
struct proc *fm;
};
-/*--------------------------------------------------------------------
- * Keep track of definitions and references
- */
-
-void
-vcc_AddRef(struct vcc *tl, struct symbol *sym)
-{
-
- (void)tl;
- if (sym->ref_b == NULL)
- sym->ref_b = tl->t;
- sym->nref++;
-}
-
/*--------------------------------------------------------------------*/
static void
vcc_checkref(struct vcc *tl, const struct symbol *sym)
{
+ if (sym->noref)
+ return;
if (sym->ndef == 0 && sym->nref != 0) {
AN(sym->ref_b);
VSB_printf(tl->sb, "Undefined %s %.*s, first reference:\n",
More information about the varnish-commit
mailing list