[master] df4804b92 Manage symbol references with higher-level types

Dridi Boukelmoune dridi.boukelmoune at gmail.com
Wed Apr 1 07:49:08 UTC 2020


commit df4804b923eb2f47741dee300f05d2a1bf281488
Author: Dridi Boukelmoune <dridi.boukelmoune at gmail.com>
Date:   Wed Dec 18 16:57:38 2019 +0100

    Manage symbol references with higher-level types
    
    That would be the symbol itself instead of only the relevant mask, and a
    XREF constants wrapping the error message as well. The `struct xrefuse`
    pun was definitely intended.

diff --git a/lib/libvcc/vcc_action.c b/lib/libvcc/vcc_action.c
index 542e1289f..bcbeea9ba 100644
--- a/lib/libvcc/vcc_action.c
+++ b/lib/libvcc/vcc_action.c
@@ -135,7 +135,7 @@ vcc_act_set(struct vcc *tl, struct token *t, struct symbol *sym)
 			VSB_printf(tl->sb, "Variable cannot be set.\n");
 		return;
 	}
-	vcc_AddUses(tl, t, tl->t, sym->w_methods, "Cannot be set");
+	vcc_AddUses(tl, t, tl->t, sym, XREF_WRITE);
 	type = sym->type;
 	for (ap = assign; ap->type != VOID; ap++) {
 		if (ap->type != type)
@@ -177,7 +177,7 @@ vcc_act_unset(struct vcc *tl, struct token *t, struct symbol *sym)
 		VSB_printf(tl->sb, "Variable cannot be unset.\n");
 		return;
 	}
-	vcc_AddUses(tl, t, tl->t, sym->u_methods, "Cannot be unset");
+	vcc_AddUses(tl, t, tl->t, sym, XREF_UNSET);
 	Fb(tl, 1, "%s;\n", sym->uname);
 	SkipToken(tl, ';');
 }
diff --git a/lib/libvcc/vcc_compile.h b/lib/libvcc/vcc_compile.h
index ad1af617a..6a291c50b 100644
--- a/lib/libvcc/vcc_compile.h
+++ b/lib/libvcc/vcc_compile.h
@@ -406,8 +406,16 @@ void VCC_XrefTable(struct vcc *);
 void vcc_AddCall(struct vcc *, struct token *, struct symbol *);
 void vcc_ProcAction(struct proc *p, unsigned action, struct token *t);
 int vcc_CheckAction(struct vcc *tl);
+
+
+struct xrefuse { const char *name, *err; };
+extern const struct xrefuse XREF_READ[1];
+extern const struct xrefuse XREF_WRITE[1];
+extern const struct xrefuse XREF_UNSET[1];
+extern const struct xrefuse XREF_ACTION[1];
+
 void vcc_AddUses(struct vcc *, const struct token *, const struct token *,
-     unsigned mask, const char *use);
+    const struct symbol *sym, const struct xrefuse *use);
 int vcc_CheckUses(struct vcc *tl);
 const char *vcc_MarkPriv(struct vcc *, struct procprivhead *,
     const char *);
diff --git a/lib/libvcc/vcc_expr.c b/lib/libvcc/vcc_expr.c
index dc36effeb..dd62b279d 100644
--- a/lib/libvcc/vcc_expr.c
+++ b/lib/libvcc/vcc_expr.c
@@ -341,7 +341,7 @@ vcc_Eval_Var(struct vcc *tl, struct expr **e, struct token *t,
 
 	(void)type;
 	assert(sym->kind == SYM_VAR);
-	vcc_AddUses(tl, t, NULL, sym->r_methods, "Not available");
+	vcc_AddUses(tl, t, NULL, sym, XREF_READ);
 	ERRCHK(tl);
 	*e = vcc_mk_expr(sym->type, "%s", sym->rname);
 	(*e)->constant = EXPR_VAR;
diff --git a/lib/libvcc/vcc_parse.c b/lib/libvcc/vcc_parse.c
index 2bfeb86fb..f5dc8c364 100644
--- a/lib/libvcc/vcc_parse.c
+++ b/lib/libvcc/vcc_parse.c
@@ -196,9 +196,7 @@ vcc_Compound(struct vcc *tl)
 				return;
 			}
 			if (sym->action_mask != 0)
-				vcc_AddUses(tl, t, NULL,
-				    sym->action_mask,
-				    "Not a valid action");
+				vcc_AddUses(tl, t, NULL, sym, XREF_ACTION);
 			sym->action(tl, t, sym);
 			break;
 		default:
diff --git a/lib/libvcc/vcc_xref.c b/lib/libvcc/vcc_xref.c
index 9e66bdd8a..d2e933db3 100644
--- a/lib/libvcc/vcc_xref.c
+++ b/lib/libvcc/vcc_xref.c
@@ -57,8 +57,9 @@ struct procuse {
 	VTAILQ_ENTRY(procuse)	list;
 	const struct token	*t1;
 	const struct token	*t2;
+	const struct symbol	*sym;
+	const struct xrefuse	*use;
 	unsigned		mask;
-	const char		*use;
 	struct proc		*fm;
 };
 
@@ -102,22 +103,41 @@ vcc_CheckReferences(struct vcc *tl)
  * Returns checks
  */
 
+const struct xrefuse XREF_READ[1] = {{"xref_read", "Not available"}};
+const struct xrefuse XREF_WRITE[1] = {{"xref_write", "Cannot be set"}};
+const struct xrefuse XREF_UNSET[1] = {{"xref_unset", "Cannot be unset"}};
+const struct xrefuse XREF_ACTION[1] = {{"xref_action", "Not a valid action"}};
+
 void
 vcc_AddUses(struct vcc *tl, const struct token *t1, const struct token *t2,
-    unsigned mask, const char *use)
+    const struct symbol *sym, const struct xrefuse *use)
 {
 	struct procuse *pu;
 
 	AN(tl->curproc);
 	pu = TlAlloc(tl, sizeof *pu);
 	AN(pu);
+	AN(sym);
+	AN(use);
 	pu->t1 = t1;
 	pu->t2 = t2;
 	if (pu->t2 == NULL)
 		pu->t2 = VTAILQ_NEXT(t1, list);
-	pu->mask = mask;
+	pu->sym = sym;
 	pu->use = use;
 	pu->fm = tl->curproc;
+
+	if (pu->use == XREF_READ)
+		pu->mask = sym->r_methods;
+	else if (pu->use == XREF_WRITE)
+		pu->mask = sym->w_methods;
+	else if (pu->use == XREF_UNSET)
+		pu->mask = sym->u_methods;
+	else if (pu->use == XREF_ACTION)
+		pu->mask = sym->action_mask;
+	else
+		WRONG("wrong xref use");
+
 	VTAILQ_INSERT_TAIL(&tl->curproc->uses, pu, list);
 }
 
@@ -252,7 +272,7 @@ vcc_CheckUseRecurse(struct vcc *tl, const struct proc *p,
 	if (pu != NULL) {
 		vcc_ErrWhere2(tl, pu->t1, pu->t2);
 		VSB_printf(tl->sb, "%s from subroutine '%s'.\n",
-		    pu->use, m->name);
+		    pu->use->err, m->name);
 		VSB_printf(tl->sb, "\n...in subroutine \"%.*s\"\n",
 		    PF(pu->fm->name));
 		vcc_ErrWhere(tl, p->name);
@@ -283,7 +303,7 @@ vcc_checkuses(struct vcc *tl, const struct symbol *sym)
 	if (pu != NULL) {
 		vcc_ErrWhere2(tl, pu->t1, pu->t2);
 		VSB_printf(tl->sb, "%s in subroutine '%.*s'.",
-		    pu->use, PF(p->name));
+		    pu->use->err, PF(p->name));
 		VSB_cat(tl->sb, "\nAt: ");
 		return;
 	}


More information about the varnish-commit mailing list