Commit 05a95072 authored by Poul-Henning Kamp's avatar Poul-Henning Kamp

Call types types instead of formats

parent 0d0bac74
......@@ -1272,7 +1272,7 @@ def one_var(nm, spec):
else:
fo.write(" SYM_VAR);\n")
fo.write("\tAN(sym);\n")
fo.write("\tsym->fmt = %s;\n" % spec.typ)
fo.write("\tsym->type = %s;\n" % spec.typ)
fo.write("\tsym->eval = vcc_Eval_Var;\n")
if len(spec.rd) == 0:
......
......@@ -88,7 +88,7 @@ static void v_matchproto_(sym_act_f)
vcc_act_set(struct vcc *tl, struct token *t, struct symbol *sym)
{
const struct arith *ap;
vcc_type_t fmt;
vcc_type_t type;
(void)t;
ExpectErr(tl, ID);
......@@ -107,28 +107,28 @@ vcc_act_set(struct vcc *tl, struct token *t, struct symbol *sym)
vcc_AddUses(tl, t, tl->t, sym->w_methods, "Cannot be set");
Fb(tl, 1, "%s\n", sym->lname);
tl->indent += INDENT;
fmt = sym->fmt;
type = sym->type;
for (ap = arith; ap->type != VOID; ap++) {
if (ap->type != fmt)
if (ap->type != type)
continue;
if (ap->oper != tl->t->tok)
continue;
if (ap->oper != '=')
Fb(tl, 1, "%s %c ", sym->rname, *tl->t->b);
vcc_NextToken(tl);
fmt = ap->want;
type = ap->want;
break;
}
if (ap->type == VOID)
SkipToken(tl, ap->oper);
if (fmt == HEADER) {
if (type == HEADER) {
vcc_Expr(tl, STRING_LIST);
} else if (fmt == STRING) {
} else if (type == STRING) {
vcc_Expr(tl, STRING_LIST);
} else if (fmt == BODY) {
} else if (type == BODY) {
vcc_Expr(tl, STRING_LIST);
} else {
vcc_Expr(tl, fmt);
vcc_Expr(tl, type);
}
ERRCHK(tl);
tl->indent -= INDENT;
......
......@@ -811,7 +811,7 @@ vcc_predef_vcl(struct vcc *vcc, const char *name)
sym = VCC_MkSym(vcc, name, SYM_VCL);
AN(sym);
sym->fmt = VCL;
sym->type = VCL;
sym->r_methods = VCL_MET_RECV;
}
......
......@@ -129,7 +129,7 @@ struct symbol {
const struct token *def_b, *def_e, *ref_b;
vcc_type_t fmt;
vcc_type_t type;
sym_expr_t *eval;
const void *eval_priv;
......
......@@ -328,19 +328,19 @@ vcc_Eval_BoolConst(struct vcc *tl, struct expr **e, struct token *t,
void v_matchproto_(sym_expr_t)
vcc_Eval_Handle(struct vcc *tl, struct expr **e, struct token *t,
struct symbol *sym, vcc_type_t fmt)
struct symbol *sym, vcc_type_t type)
{
(void)t;
(void)tl;
AN(sym->rname);
if (sym->fmt != STRING && fmt == STRINGS) {
if (sym->type != STRING && type == STRINGS) {
*e = vcc_mk_expr(STRINGS, "\"%s\"", sym->name);
(*e)->nstr = 1;
(*e)->constant |= EXPR_CONST | EXPR_STR_CONST;
} else {
*e = vcc_mk_expr(sym->fmt, "%s", sym->rname);
*e = vcc_mk_expr(sym->type, "%s", sym->rname);
(*e)->constant = EXPR_VAR;
(*e)->nstr = 1;
if ((*e)->fmt == STRING)
......@@ -353,14 +353,14 @@ vcc_Eval_Handle(struct vcc *tl, struct expr **e, struct token *t,
void v_matchproto_(sym_expr_t)
vcc_Eval_Var(struct vcc *tl, struct expr **e, struct token *t,
struct symbol *sym, vcc_type_t fmt)
struct symbol *sym, vcc_type_t type)
{
(void)fmt;
(void)type;
assert(sym->kind == SYM_VAR);
vcc_AddUses(tl, t, NULL, sym->r_methods, "Not available");
ERRCHK(tl);
*e = vcc_mk_expr(sym->fmt, "%s", sym->rname);
*e = vcc_mk_expr(sym->type, "%s", sym->rname);
(*e)->constant = EXPR_VAR;
(*e)->nstr = 1;
if ((*e)->fmt == STRING)
......@@ -664,18 +664,12 @@ vcc_expr4(struct vcc *tl, struct expr **e, vcc_type_t fmt)
XREF_REF);
ERRCHK(tl);
AN(sym);
if (sym->kind == SYM_FUNC && sym->fmt == VOID) {
if (sym->kind == SYM_FUNC && sym->type == VOID) {
VSB_printf(tl->sb, "Function returns VOID:\n");
vcc_ErrWhere(tl, tl->t);
return;
}
switch (sym->kind) {
case SYM_VAR:
case SYM_FUNC:
case SYM_ACL:
case SYM_BACKEND:
case SYM_STEVEDORE:
case SYM_PROBE:
if (sym->eval != NULL) {
AN(sym->eval);
AZ(*e);
sym->eval(tl, e, t, sym, fmt);
......@@ -686,9 +680,6 @@ vcc_expr4(struct vcc *tl, struct expr **e, vcc_type_t fmt)
ERRCHK(tl);
}
return;
default:
AZ(sym->eval);
break;
}
VSB_printf(tl->sb,
"Symbol type (%s) can not be used in expression.\n",
......@@ -1291,21 +1282,25 @@ vcc_Expr_Init(struct vcc *tl)
sym = VCC_MkSym(tl, "regsub", SYM_FUNC);
AN(sym);
sym->type = STRING;
sym->eval = vcc_Eval_Regsub;
sym->eval_priv = NULL;
sym = VCC_MkSym(tl, "regsuball", SYM_FUNC);
AN(sym);
sym->type = STRING;
sym->eval = vcc_Eval_Regsub;
sym->eval_priv = sym;
sym = VCC_MkSym(tl, "true", SYM_FUNC);
AN(sym);
sym->type = BOOL;
sym->eval = vcc_Eval_BoolConst;
sym->eval_priv = sym;
sym = VCC_MkSym(tl, "false", SYM_FUNC);
AN(sym);
sym->type = BOOL;
sym->eval = vcc_Eval_BoolConst;
sym->eval_priv = NULL;
}
......@@ -67,7 +67,7 @@
static struct stvars {
const char *name;
vcc_type_t fmt;
vcc_type_t type;
} stvars[] = {
#define VRTSTVVAR(nm, vtype, ctype, dval) { #nm, vtype },
#include "tbl/vrt_stv_var.h"
......@@ -86,7 +86,7 @@ vcc_stevedore(struct vcc *vcc, const char *stv_name)
bprintf(buf, "storage.%s", stv_name);
sym = VCC_MkSym(vcc, buf, SYM_VAR);
AN(sym);
sym->fmt = STEVEDORE;
sym->type = STEVEDORE;
sym->eval = vcc_Eval_Var;
bprintf(buf, "VRT_stevedore(\"%s\")", stv_name);
sym->rname = TlDup(vcc, buf);
......@@ -96,7 +96,7 @@ vcc_stevedore(struct vcc *vcc, const char *stv_name)
bprintf(buf, "storage.%s.%s", stv_name, sv->name);
sym = VCC_MkSym(vcc, buf, SYM_VAR);
AN(sym);
sym->fmt = sv->fmt;
sym->type = sv->type;
sym->eval = vcc_Eval_Var;
bprintf(buf, "VRT_Stv_%s(\"%s\")", sv->name, stv_name);
sym->rname = TlDup(vcc, buf);
......
......@@ -101,6 +101,7 @@ vcc_new_symbol(struct vcc *tl, const char *b, const char *e)
sym->name[e - b] = '\0';
sym->nlen = e - b;
VTAILQ_INIT(&sym->children);
sym->type = VOID;
return (sym);
}
......@@ -290,7 +291,7 @@ VCC_WalkSymbols(struct vcc *tl, symwalk_f *func, enum symkind kind)
}
void
VCC_GlobalSymbol(struct symbol *sym, vcc_type_t fmt, const char *pfx)
VCC_GlobalSymbol(struct symbol *sym, vcc_type_t type, const char *pfx)
{
struct vsb *vsb;
......@@ -306,8 +307,8 @@ VCC_GlobalSymbol(struct symbol *sym, vcc_type_t fmt, const char *pfx)
AN(sym->rname);
VSB_destroy(&vsb);
sym->fmt = fmt;
sym->kind = VCC_HandleKind(sym->fmt);
sym->type = type;
sym->kind = VCC_HandleKind(sym->type);
if (sym->kind != SYM_NONE) {
AZ(VCT_invalid_name(sym->rname, NULL));
sym->eval = vcc_Eval_Handle;
......
......@@ -41,7 +41,7 @@ vcc_Var_Wildcard(struct vcc *tl, struct symbol *parent, struct symbol *sym)
{
struct vsb *vsb;
assert(parent->fmt == HEADER);
assert(parent->type == HEADER);
if (sym->nlen >= 127) {
VSB_printf(tl->sb, "HTTP header (%.20s..) is too long.\n",
......@@ -53,7 +53,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->type = parent->type;
sym->eval = vcc_Eval_Var;
sym->r_methods = parent->r_methods;
sym->w_methods = parent->w_methods;
......
......@@ -250,8 +250,8 @@ vcc_ParseImport(struct vcc *tl)
sym->eval = vcc_Eval_SymFunc;
p += strlen(p) + 1;
sym->eval_priv = p;
sym->fmt = VCC_Type(p);
AN(sym->fmt);
sym->type = VCC_Type(p);
AN(sym->type);
} else {
VSB_printf(tl->sb, "Internal spec error (%s)\n", p);
vcc_ErrWhere(tl, mod);
......@@ -337,7 +337,7 @@ vcc_Act_New(struct vcc *tl, struct token *t, struct symbol *sym)
sy3->eval = vcc_Eval_SymFunc;
p += strlen(p) + 1;
sy3->eval_priv = p;
sy3->fmt = VCC_Type(p);
sy3->type = VCC_Type(p);
sy3->extra = TlDup(tl, buf1);
sy3->vmod = sy2->vmod;
while (p[0] != '\0' || p[1] != '\0' || p[2] != '\0')
......
......@@ -336,7 +336,7 @@ vcc_xreftable(struct vcc *tl, const struct symbol *sym)
{
Fc(tl, 0, " * %-7s ", VCC_SymKind(tl, sym));
Fc(tl, 0, " %-9s ", sym->fmt != NULL ? sym->fmt->name : "");
Fc(tl, 0, " %-9s ", sym->type->name);
vcc_pnam(tl, sym);
if (sym->wildcard != NULL)
Fc(tl, 0, "*");
......
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