Commit 96edbd29 authored by Dridi Boukelmoune's avatar Dridi Boukelmoune

Remove type method and property definitions from vcc_expr

This is a first step towards making expression parsing more agnostic and
type methods more prevalent.
parent a971e6c3
...@@ -100,6 +100,15 @@ struct token { ...@@ -100,6 +100,15 @@ struct token {
typedef const struct type *vcc_type_t; typedef const struct type *vcc_type_t;
/*
* A type attribute is information already existing, requiring no processing
* or resource usage.
*
* A type method is a call and may do significant processing, change things,
* eat workspace etc.
*
* XXX: type methods might move in a more comprehensive direction.
*/
struct vcc_method { struct vcc_method {
vcc_type_t type; vcc_type_t type;
const char *name; const char *name;
......
...@@ -816,38 +816,12 @@ vcc_expr5(struct vcc *tl, struct expr **e, vcc_type_t fmt) ...@@ -816,38 +816,12 @@ vcc_expr5(struct vcc *tl, struct expr **e, vcc_type_t fmt)
* SYNTAX: * SYNTAX:
* Expr4: * Expr4:
* Expr5 [ '.' (type_attribute | type_method()) ]* * Expr5 [ '.' (type_attribute | type_method()) ]*
*
* type_attributes is information already existing, requiring no
* processing or resource usage.
*
* type_methods are calls and may do (significant processing, change things,
* eat workspace etc.
*/ */
static const struct vcc_methods {
vcc_type_t type_from;
vcc_type_t type_to;
const char *method;
const char *impl;
int func;
} vcc_methods[] = {
//{ BACKEND, BOOL, "healthy", "VRT_Healthy(ctx, \v1, 0)" },
#define VRTSTVVAR(nm, vtype, ctype, dval) \
{ STEVEDORE, vtype, #nm, "VRT_stevedore_" #nm "(\v1)", 0},
#include "tbl/vrt_stv_var.h"
{ STRINGS, STRING, "upper", "VRT_UpperLowerStrands(ctx, \vT, 1)", 1 },
{ STRINGS, STRING, "lower", "VRT_UpperLowerStrands(ctx, \vT, 0)", 1 },
{ BACKEND, BACKEND, "resolve", "VRT_DirectorResolve(ctx, \v1)", 1 },
{ NULL, NULL, NULL, NULL},
};
static void static void
vcc_expr4(struct vcc *tl, struct expr **e, vcc_type_t fmt) vcc_expr4(struct vcc *tl, struct expr **e, vcc_type_t fmt)
{ {
const struct vcc_methods *vm; const struct vcc_method *vm;
*e = NULL; *e = NULL;
vcc_expr5(tl, e, fmt); vcc_expr5(tl, e, fmt);
...@@ -857,14 +831,14 @@ vcc_expr4(struct vcc *tl, struct expr **e, vcc_type_t fmt) ...@@ -857,14 +831,14 @@ vcc_expr4(struct vcc *tl, struct expr **e, vcc_type_t fmt)
vcc_NextToken(tl); vcc_NextToken(tl);
ExpectErr(tl, ID); ExpectErr(tl, ID);
for(vm = vcc_methods; vm->type_from != NULL; vm++) { vm = (*e)->fmt->methods;
while (vm != NULL && vm->type != NULL) {
if (vm->type_from == (*e)->fmt && if (vcc_IdIs(tl->t, vm->name))
vcc_IdIs(tl->t, vm->method))
break; break;
vm++;
} }
if (vm->type_from == NULL) { if (vm == NULL || vm->type == NULL) {
VSB_cat(tl->sb, "Unknown property "); VSB_cat(tl->sb, "Unknown property ");
vcc_ErrToken(tl, tl->t); vcc_ErrToken(tl, tl->t);
VSB_printf(tl->sb, VSB_printf(tl->sb,
...@@ -873,7 +847,7 @@ vcc_expr4(struct vcc *tl, struct expr **e, vcc_type_t fmt) ...@@ -873,7 +847,7 @@ vcc_expr4(struct vcc *tl, struct expr **e, vcc_type_t fmt)
return; return;
} }
vcc_NextToken(tl); vcc_NextToken(tl);
*e = vcc_expr_edit(tl, vm->type_to, vm->impl, *e, NULL); *e = vcc_expr_edit(tl, vm->type, vm->impl, *e, NULL);
ERRCHK(tl); ERRCHK(tl);
if ((*e)->fmt == STRING) { if ((*e)->fmt == STRING) {
(*e)->fmt = STRINGS; (*e)->fmt = STRINGS;
......
...@@ -43,7 +43,7 @@ const struct type ACL[1] = {{ ...@@ -43,7 +43,7 @@ const struct type ACL[1] = {{
}}; }};
static const struct vcc_method backend_methods[] = { static const struct vcc_method backend_methods[] = {
{ BACKEND, "resolve", "VRT_VDI_Resolve(ctx, \v1)", 1 }, { BACKEND, "resolve", "VRT_DirectorResolve(ctx, \v1)", 1 },
{ NULL }, { NULL },
}; };
......
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