Commit df4804b9 authored by Dridi Boukelmoune's avatar Dridi Boukelmoune

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.
parent 3399615a
......@@ -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, ';');
}
......
......@@ -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 *);
......
......@@ -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;
......
......@@ -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:
......
......@@ -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;
}
......
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