[master] 530f0b2 Rename tag -> lhs and val -> rhs in the parser.
Martin Blix Grydeland
martin at varnish-cache.org
Tue Oct 1 14:48:18 CEST 2013
commit 530f0b20612886ee17903d30837c8719438176d7
Author: Martin Blix Grydeland <martin at varnish-software.com>
Date: Fri Sep 20 13:58:46 2013 +0200
Rename tag -> lhs and val -> rhs in the parser.
diff --git a/lib/libvarnishapi/vsl_query.c b/lib/libvarnishapi/vsl_query.c
index 12fcd28..3659a72 100644
--- a/lib/libvarnishapi/vsl_query.c
+++ b/lib/libvarnishapi/vsl_query.c
@@ -56,7 +56,7 @@ struct vslq_query {
static int
vslq_test_rec(const struct vex *vex, const struct VSLC_ptr *rec)
{
- const struct vex_val *val;
+ const struct vex_rhs *rhs;
int reclen;
const char *recdata;
long long recint;
@@ -65,8 +65,8 @@ vslq_test_rec(const struct vex *vex, const struct VSLC_ptr *rec)
AN(vex);
AN(rec);
- val = vex->val;
- AN(val);
+ rhs = vex->rhs;
+ AN(rhs);
reclen = VSL_LEN(rec->ptr);
recdata = VSL_CDATA(rec->ptr);
@@ -80,7 +80,7 @@ vslq_test_rec(const struct vex *vex, const struct VSLC_ptr *rec)
case T_LEQ: /* <= */
case T_GEQ: /* >= */
/* Numerical comparison */
- switch (val->type) {
+ switch (rhs->type) {
case VEX_INT:
recint = strtoll(recdata, &endptr, 0);
if (*endptr == '\0' || isspace(*endptr))
@@ -102,93 +102,93 @@ vslq_test_rec(const struct vex *vex, const struct VSLC_ptr *rec)
/* Compare */
switch (vex->tok) {
case T_EQ: /* == */
- switch (val->type) {
+ switch (rhs->type) {
case VEX_INT:
- if (recint == val->val_int)
+ if (recint == rhs->val_int)
return (1);
return (0);
case VEX_FLOAT:
- if (recfloat == val->val_float)
+ if (recfloat == rhs->val_float)
return (1);
return (0);
default:
- WRONG("Wrong value type");
+ WRONG("Wrong RHS type");
}
case T_NEQ: /* != */
- switch (val->type) {
+ switch (rhs->type) {
case VEX_INT:
- if (recint != val->val_int)
+ if (recint != rhs->val_int)
return (1);
return (0);
case VEX_FLOAT:
- if (recfloat != val->val_float)
+ if (recfloat != rhs->val_float)
return (1);
return (0);
default:
- WRONG("Wrong value type");
+ WRONG("Wrong RHS type");
}
case '<': /* < */
- switch (val->type) {
+ switch (rhs->type) {
case VEX_INT:
- if (recint < val->val_int)
+ if (recint < rhs->val_int)
return (1);
return (0);
case VEX_FLOAT:
- if (recfloat < val->val_float)
+ if (recfloat < rhs->val_float)
return (1);
return (0);
default:
- WRONG("Wrong value type");
+ WRONG("Wrong RHS type");
}
case '>':
- switch (val->type) {
+ switch (rhs->type) {
case VEX_INT:
- if (recint > val->val_int)
+ if (recint > rhs->val_int)
return (1);
return (0);
case VEX_FLOAT:
- if (recfloat > val->val_float)
+ if (recfloat > rhs->val_float)
return (1);
return (0);
default:
- WRONG("Wrong value type");
+ WRONG("Wrong RHS type");
}
case T_LEQ: /* <= */
- switch (val->type) {
+ switch (rhs->type) {
case VEX_INT:
- if (recint <= val->val_int)
+ if (recint <= rhs->val_int)
return (1);
return (0);
case VEX_FLOAT:
- if (recfloat <= val->val_float)
+ if (recfloat <= rhs->val_float)
return (1);
return (0);
default:
- WRONG("Wrong value type");
+ WRONG("Wrong RHS type");
}
case T_GEQ: /* >= */
- switch (val->type) {
+ switch (rhs->type) {
case VEX_INT:
- if (recint >= val->val_int)
+ if (recint >= rhs->val_int)
return (1);
return (0);
case VEX_FLOAT:
- if (recfloat >= val->val_float)
+ if (recfloat >= rhs->val_float)
return (1);
return (0);
default:
- WRONG("Wrong value type");
+ WRONG("Wrong RHS type");
}
case T_SEQ: /* eq */
- assert(val->type == VEX_STRING);
- if (reclen == val->val_stringlen + 1 &&
- !strncmp(recdata, val->val_string, reclen))
+ assert(rhs->type == VEX_STRING);
+ if (reclen == rhs->val_stringlen + 1 &&
+ !strncmp(recdata, rhs->val_string, reclen))
return (1);
return (0);
case T_SNEQ: /* ne */
- assert(val->type == VEX_STRING);
- if (reclen != val->val_stringlen + 1 ||
- strncmp(recdata, val->val_string, reclen))
+ assert(rhs->type == VEX_STRING);
+ if (reclen != rhs->val_stringlen + 1 ||
+ strncmp(recdata, rhs->val_string, reclen))
return (1);
return (0);
default:
@@ -205,8 +205,8 @@ vslq_test(const struct vex *vex, struct VSL_transaction * const ptrans[])
int i;
CHECK_OBJ_NOTNULL(vex, VEX_MAGIC);
- CHECK_OBJ_NOTNULL(vex->tag, VEX_TAG_MAGIC);
- CHECK_OBJ_NOTNULL(vex->val, VEX_VAL_MAGIC);
+ CHECK_OBJ_NOTNULL(vex->lhs, VEX_LHS_MAGIC);
+ CHECK_OBJ_NOTNULL(vex->rhs, VEX_RHS_MAGIC);
for (t = ptrans[0]; t != NULL; t = *++ptrans) {
AZ(VSL_ResetCursor(t->c));
@@ -219,7 +219,7 @@ vslq_test(const struct vex *vex, struct VSL_transaction * const ptrans[])
assert(i == 1);
AN(t->c->rec.ptr);
- if (vex->tag->tag != VSL_TAG(t->c->rec.ptr))
+ if (vex->lhs->tag != VSL_TAG(t->c->rec.ptr))
continue;
i = vslq_test_rec(vex, &t->c->rec);
diff --git a/lib/libvarnishapi/vxp.h b/lib/libvarnishapi/vxp.h
index 35d1d33..73b3bc0 100644
--- a/lib/libvarnishapi/vxp.h
+++ b/lib/libvarnishapi/vxp.h
@@ -76,16 +76,19 @@ struct vxp {
struct vex;
-struct vex_tag {
+struct vex_lhs {
+ /* Left-hand-side of a vex expression. Stores the information
+ about which records and what parts of those records the
+ expression should be applied to */
unsigned magic;
-#define VEX_TAG_MAGIC 0x1AD3D78D
+#define VEX_LHS_MAGIC 0x1AD3D78D
int tag;
int field;
int level_min;
int level_max;
};
-enum vex_val_e {
+enum vex_rhs_e {
VEX__UNSET,
VEX_INT,
VEX_FLOAT,
@@ -93,10 +96,12 @@ enum vex_val_e {
VEX_REGEX,
};
-struct vex_val {
+struct vex_rhs {
+ /* Right-hand-side of a vex expression. Stores the value that the
+ records from LHS should be matched against */
unsigned magic;
-#define VEX_VAL_MAGIC 0x3F109965
- enum vex_val_e type;
+#define VEX_RHS_MAGIC 0x3F109965
+ enum vex_rhs_e type;
long long val_int;
double val_float;
char *val_string;
@@ -109,8 +114,8 @@ struct vex {
#define VEX_MAGIC 0xC7DB792D
unsigned tok;
struct vex *a, *b;
- struct vex_tag *tag;
- struct vex_val *val;
+ struct vex_lhs *lhs;
+ struct vex_rhs *rhs;
};
/* VXP internals */
diff --git a/lib/libvarnishapi/vxp_parse.c b/lib/libvarnishapi/vxp_parse.c
index 7e3ed5a..2cc1288 100644
--- a/lib/libvarnishapi/vxp_parse.c
+++ b/lib/libvarnishapi/vxp_parse.c
@@ -48,26 +48,26 @@
static void vxp_expr_or(struct vxp *vxp, struct vex **pvex);
static void
-vxp_expr_tag(struct vxp *vxp, struct vex_tag **ptag)
+vxp_expr_lhs(struct vxp *vxp, struct vex_lhs **plhs)
{
/* XXX: Tag wildcards */
- AN(ptag);
- AZ(*ptag);
+ AN(plhs);
+ AZ(*plhs);
if (vxp->t->tok != VAL) {
VSB_printf(vxp->sb, "Expected VSL tag got '%.*s' ", PF(vxp->t));
vxp_ErrWhere(vxp, vxp->t, -1);
return;
}
- ALLOC_OBJ(*ptag, VEX_TAG_MAGIC);
- AN(*ptag);
- (*ptag)->tag = VSL_Name2Tag(vxp->t->dec, -1);
- if ((*ptag)->tag == -1) {
+ ALLOC_OBJ(*plhs, VEX_LHS_MAGIC);
+ AN(*plhs);
+ (*plhs)->tag = VSL_Name2Tag(vxp->t->dec, -1);
+ if ((*plhs)->tag == -1) {
VSB_printf(vxp->sb, "Could not match '%.*s' to any tag ",
PF(vxp->t));
vxp_ErrWhere(vxp, vxp->t, -1);
return;
- } else if ((*ptag)->tag == -2) {
+ } else if ((*plhs)->tag == -2) {
VSB_printf(vxp->sb, "'%.*s' matches multiple tags ",
PF(vxp->t));
vxp_ErrWhere(vxp, vxp->t, -1);
@@ -75,27 +75,27 @@ vxp_expr_tag(struct vxp *vxp, struct vex_tag **ptag)
}
vxp_NextToken(vxp);
- /* XXX: Tag limiting operators ([], {}) */
+ /* XXX: Lhs limiting operators ([], {}) */
}
static void
-vxp_expr_num(struct vxp *vxp, struct vex_val **pval)
+vxp_expr_num(struct vxp *vxp, struct vex_rhs **prhs)
{
char *endptr;
- AN(pval);
- AZ(*pval);
+ AN(prhs);
+ AZ(*prhs);
if (vxp->t->tok != VAL) {
VSB_printf(vxp->sb, "Expected number got '%.*s' ", PF(vxp->t));
vxp_ErrWhere(vxp, vxp->t, -1);
return;
}
AN(vxp->t->dec);
- ALLOC_OBJ(*pval, VEX_VAL_MAGIC);
- AN(*pval);
+ ALLOC_OBJ(*prhs, VEX_RHS_MAGIC);
+ AN(*prhs);
if (strchr(vxp->t->dec, '.')) {
- (*pval)->type = VEX_FLOAT;
- (*pval)->val_float = strtod(vxp->t->dec, &endptr);
+ (*prhs)->type = VEX_FLOAT;
+ (*prhs)->val_float = strtod(vxp->t->dec, &endptr);
while (isspace(*endptr))
endptr++;
if (*endptr != '\0') {
@@ -104,8 +104,8 @@ vxp_expr_num(struct vxp *vxp, struct vex_val **pval)
return;
}
} else {
- (*pval)->type = VEX_INT;
- (*pval)->val_int = strtoll(vxp->t->dec, &endptr, 0);
+ (*prhs)->type = VEX_INT;
+ (*prhs)->val_int = strtoll(vxp->t->dec, &endptr, 0);
while (isspace(*endptr))
endptr++;
if (*endptr != '\0') {
@@ -118,36 +118,36 @@ vxp_expr_num(struct vxp *vxp, struct vex_val **pval)
}
static void
-vxp_expr_str(struct vxp *vxp, struct vex_val **pval)
+vxp_expr_str(struct vxp *vxp, struct vex_rhs **prhs)
{
- AN(pval);
- AZ(*pval);
+ AN(prhs);
+ AZ(*prhs);
if (vxp->t->tok != VAL) {
VSB_printf(vxp->sb, "Expected string got '%.*s' ", PF(vxp->t));
vxp_ErrWhere(vxp, vxp->t, -1);
return;
}
AN(vxp->t->dec);
- ALLOC_OBJ(*pval, VEX_VAL_MAGIC);
- AN(*pval);
- (*pval)->type = VEX_STRING;
- (*pval)->val_string = strdup(vxp->t->dec);
- AN((*pval)->val_string);
- (*pval)->val_stringlen = strlen((*pval)->val_string);
+ ALLOC_OBJ(*prhs, VEX_RHS_MAGIC);
+ AN(*prhs);
+ (*prhs)->type = VEX_STRING;
+ (*prhs)->val_string = strdup(vxp->t->dec);
+ AN((*prhs)->val_string);
+ (*prhs)->val_stringlen = strlen((*prhs)->val_string);
vxp_NextToken(vxp);
}
static void
-vxp_expr_regex(struct vxp *vxp, struct vex_val **pval)
+vxp_expr_regex(struct vxp *vxp, struct vex_rhs **prhs)
{
const char *errptr;
int erroff;
/* XXX: Caseless option */
- AN(pval);
- AZ(*pval);
+ AN(prhs);
+ AZ(*prhs);
if (vxp->t->tok != VAL) {
VSB_printf(vxp->sb, "Expected regular expression got '%.*s' ",
PF(vxp->t));
@@ -155,12 +155,12 @@ vxp_expr_regex(struct vxp *vxp, struct vex_val **pval)
return;
}
AN(vxp->t->dec);
- ALLOC_OBJ(*pval, VEX_VAL_MAGIC);
- AN(*pval);
- (*pval)->type = VEX_REGEX;
- (*pval)->val_string = strdup(vxp->t->dec);
- (*pval)->val_regex = VRE_compile(vxp->t->dec, 0, &errptr, &erroff);
- if ((*pval)->val_regex == NULL) {
+ ALLOC_OBJ(*prhs, VEX_RHS_MAGIC);
+ AN(*prhs);
+ (*prhs)->type = VEX_REGEX;
+ (*prhs)->val_string = strdup(vxp->t->dec);
+ (*prhs)->val_regex = VRE_compile(vxp->t->dec, 0, &errptr, &erroff);
+ if ((*prhs)->val_regex == NULL) {
AN(errptr);
VSB_printf(vxp->sb, "Regular expression error: %s ", errptr);
vxp_ErrWhere(vxp, vxp->t, erroff);
@@ -172,8 +172,8 @@ vxp_expr_regex(struct vxp *vxp, struct vex_val **pval)
/*
* SYNTAX:
* expr_cmp:
- * tag
- * tag <operator> num|str|regex
+ * lhs
+ * lhs <operator> num|str|regex
*/
static void
@@ -184,13 +184,13 @@ vxp_expr_cmp(struct vxp *vxp, struct vex **pvex)
AZ(*pvex);
ALLOC_OBJ(*pvex, VEX_MAGIC);
AN(*pvex);
- vxp_expr_tag(vxp, &(*pvex)->tag);
+ vxp_expr_lhs(vxp, &(*pvex)->lhs);
ERRCHK(vxp);
/* Test operator */
switch (vxp->t->tok) {
- /* Single tag expressions don't take any more tokens */
+ /* Single lhs expressions don't take any more tokens */
case EOI:
case T_AND:
case T_OR:
@@ -231,15 +231,15 @@ vxp_expr_cmp(struct vxp *vxp, struct vex **pvex)
case T_GEQ: /* >= */
case T_LEQ: /* <= */
case T_NEQ: /* != */
- vxp_expr_num(vxp, &(*pvex)->val);
+ vxp_expr_num(vxp, &(*pvex)->rhs);
break;
case T_SEQ: /* eq */
case T_SNEQ: /* ne */
- vxp_expr_str(vxp, &(*pvex)->val);
+ vxp_expr_str(vxp, &(*pvex)->rhs);
break;
case '~': /* ~ */
case T_NOMATCH: /* !~ */
- vxp_expr_regex(vxp, &(*pvex)->val);
+ vxp_expr_regex(vxp, &(*pvex)->rhs);
break;
default:
INCOMPL();
@@ -401,14 +401,14 @@ void
vex_Free(struct vex **pvex)
{
- if ((*pvex)->tag != NULL)
- FREE_OBJ((*pvex)->tag);
- if ((*pvex)->val != NULL) {
- if ((*pvex)->val->val_string)
- free((*pvex)->val->val_string);
- if ((*pvex)->val->val_regex)
- VRE_free(&(*pvex)->val->val_regex);
- FREE_OBJ((*pvex)->val);
+ if ((*pvex)->lhs != NULL)
+ FREE_OBJ((*pvex)->lhs);
+ if ((*pvex)->rhs != NULL) {
+ if ((*pvex)->rhs->val_string)
+ free((*pvex)->rhs->val_string);
+ if ((*pvex)->rhs->val_regex)
+ VRE_free(&(*pvex)->rhs->val_regex);
+ FREE_OBJ((*pvex)->rhs);
}
if ((*pvex)->a != NULL) {
vex_Free(&(*pvex)->a);
@@ -425,28 +425,28 @@ vex_Free(struct vex **pvex)
#ifdef VXP_DEBUG
static void
-vex_print_val(const struct vex_val *val)
+vex_print_rhs(const struct vex_rhs *rhs)
{
- CHECK_OBJ_NOTNULL(val, VEX_VAL_MAGIC);
- switch (val->type) {
+ CHECK_OBJ_NOTNULL(rhs, VEX_RHS_MAGIC);
+ switch (rhs->type) {
case VEX_INT:
- fprintf(stderr, "INT=%jd", (intmax_t)val->val_int);
+ fprintf(stderr, "INT=%jd", (intmax_t)rhs->val_int);
break;
case VEX_FLOAT:
- fprintf(stderr, "FLOAT=%f", val->val_float);
+ fprintf(stderr, "FLOAT=%f", rhs->val_float);
break;
case VEX_STRING:
- AN(val->val_string);
- fprintf(stderr, "STRING='%s'", val->val_string);
+ AN(rhs->val_string);
+ fprintf(stderr, "STRING='%s'", rhs->val_string);
break;
case VEX_REGEX:
- AN(val->val_string);
- AN(val->val_regex);
- fprintf(stderr, "REGEX='%s'", val->val_string);
+ AN(rhs->val_string);
+ AN(rhs->val_regex);
+ fprintf(stderr, "REGEX='%s'", rhs->val_string);
break;
default:
- WRONG("value type");
+ WRONG("rhs type");
break;
}
}
@@ -457,13 +457,13 @@ vex_print(const struct vex *vex, int indent)
CHECK_OBJ_NOTNULL(vex, VEX_MAGIC);
fprintf(stderr, "%*s%s", indent, "", vxp_tnames[vex->tok]);
- if (vex->tag != NULL) {
- CHECK_OBJ_NOTNULL(vex->tag, VEX_TAG_MAGIC);
- fprintf(stderr, " tag=%s", VSL_tags[vex->tag->tag]);
+ if (vex->lhs != NULL) {
+ CHECK_OBJ_NOTNULL(vex->lhs, VEX_LHS_MAGIC);
+ fprintf(stderr, " tag=%s", VSL_tags[vex->lhs->tag]);
}
- if (vex->val != NULL) {
+ if (vex->rhs != NULL) {
fprintf(stderr, " ");
- vex_print_val(vex->val);
+ vex_print_rhs(vex->rhs);
}
fprintf(stderr, "\n");
if (vex->a != NULL)
More information about the varnish-commit
mailing list