Commit 618908db authored by Martin Blix Grydeland's avatar Martin Blix Grydeland

Enable taglists in VSL query expressions

parent 24ad8224
...@@ -172,3 +172,10 @@ logexpect l1 -d 1 -g vxid -q "RespHeader[2] == 123" { ...@@ -172,3 +172,10 @@ logexpect l1 -d 1 -g vxid -q "RespHeader[2] == 123" {
expect * = ReqEnd expect * = ReqEnd
expect * = End expect * = End
} -run } -run
# Test taglists
logexpect l1 -d 1 -g vxid -q "Debug,Resp* == 200" {
expect 0 * Begin req
expect * = ReqEnd
expect * = End
} -run
...@@ -40,6 +40,8 @@ ...@@ -40,6 +40,8 @@
int vsl_diag(struct VSL_data *vsl, const char *fmt, ...) int vsl_diag(struct VSL_data *vsl, const char *fmt, ...)
__printflike(2, 3); __printflike(2, 3);
int vsl_skip(struct VSL_cursor *c, ssize_t words); int vsl_skip(struct VSL_cursor *c, ssize_t words);
void vsl_vbm_bitset(int bit, void *priv);
void vsl_vbm_bitclr(int bit, void *priv);
typedef void vslc_delete_f(struct VSL_cursor *); typedef void vslc_delete_f(struct VSL_cursor *);
typedef int vslc_next_f(struct VSL_cursor *); typedef int vslc_next_f(struct VSL_cursor *);
......
...@@ -212,14 +212,14 @@ VSLQ_Name2Grouping(const char *name, int l) ...@@ -212,14 +212,14 @@ VSLQ_Name2Grouping(const char *name, int l)
return (n); return (n);
} }
static void void __match_proto__(VSL_tagfind_f)
vsl_vbm_bitset(int bit, void *priv) vsl_vbm_bitset(int bit, void *priv)
{ {
vbit_set((struct vbitmap *)priv, bit); vbit_set((struct vbitmap *)priv, bit);
} }
static void void __match_proto__(VSL_tagfind_f)
vsl_vbm_bitclr(int bit, void *priv) vsl_vbm_bitclr(int bit, void *priv)
{ {
......
...@@ -39,6 +39,7 @@ ...@@ -39,6 +39,7 @@
#include "miniobj.h" #include "miniobj.h"
#include "vre.h" #include "vre.h"
#include "vsb.h" #include "vsb.h"
#include "vbm.h"
#include "vapi/vsl.h" #include "vapi/vsl.h"
#include "vsl_api.h" #include "vsl_api.h"
...@@ -187,6 +188,7 @@ vslq_test(const struct vex *vex, struct VSL_transaction * const ptrans[]) ...@@ -187,6 +188,7 @@ vslq_test(const struct vex *vex, struct VSL_transaction * const ptrans[])
CHECK_OBJ_NOTNULL(vex, VEX_MAGIC); CHECK_OBJ_NOTNULL(vex, VEX_MAGIC);
CHECK_OBJ_NOTNULL(vex->lhs, VEX_LHS_MAGIC); CHECK_OBJ_NOTNULL(vex->lhs, VEX_LHS_MAGIC);
AN(vex->lhs->tags);
CHECK_OBJ_NOTNULL(vex->rhs, VEX_RHS_MAGIC); CHECK_OBJ_NOTNULL(vex->rhs, VEX_RHS_MAGIC);
for (t = ptrans[0]; t != NULL; t = *++ptrans) { for (t = ptrans[0]; t != NULL; t = *++ptrans) {
...@@ -200,14 +202,12 @@ vslq_test(const struct vex *vex, struct VSL_transaction * const ptrans[]) ...@@ -200,14 +202,12 @@ vslq_test(const struct vex *vex, struct VSL_transaction * const ptrans[])
assert(i == 1); assert(i == 1);
AN(t->c->rec.ptr); AN(t->c->rec.ptr);
if (vex->lhs->tag != VSL_TAG(t->c->rec.ptr)) if (!vbit_test(vex->lhs->tags, VSL_TAG(t->c->rec.ptr)))
continue; continue;
i = vslq_test_rec(vex, &t->c->rec); i = vslq_test_rec(vex, &t->c->rec);
if (i) if (i)
return (i); return (i);
} }
} }
......
...@@ -35,8 +35,8 @@ ...@@ -35,8 +35,8 @@
#include "vxp_tokens.h" #include "vxp_tokens.h"
#define isword(c) \ #define isword(c) (isalpha(c) || isdigit(c) || (c) == '_' || (c) == '-' || \
(isalpha(c) || isdigit(c) || (c) == '_' || (c) == '-' || (c) == '.') (c) == '.' || (c) == '*' || (c) == ',')
#define PF(t) (int)((t)->e - (t)->b), (t)->b #define PF(t) (int)((t)->e - (t)->b), (t)->b
...@@ -82,7 +82,7 @@ struct vex_lhs { ...@@ -82,7 +82,7 @@ struct vex_lhs {
expression should be applied to */ expression should be applied to */
unsigned magic; unsigned magic;
#define VEX_LHS_MAGIC 0x1AD3D78D #define VEX_LHS_MAGIC 0x1AD3D78D
int tag; struct vbitmap *tags;
int field; int field;
int level_min; int level_min;
int level_max; int level_max;
......
...@@ -40,8 +40,10 @@ ...@@ -40,8 +40,10 @@
#include "vas.h" #include "vas.h"
#include "vsb.h" #include "vsb.h"
#include "vbm.h"
#include "miniobj.h" #include "miniobj.h"
#include "vapi/vsl.h" #include "vapi/vsl.h"
#include "vsl_api.h"
#include "vxp.h" #include "vxp.h"
...@@ -51,29 +53,36 @@ static void ...@@ -51,29 +53,36 @@ static void
vxp_expr_lhs(struct vxp *vxp, struct vex_lhs **plhs) vxp_expr_lhs(struct vxp *vxp, struct vex_lhs **plhs)
{ {
char *p; char *p;
int i;
/* XXX: Tag wildcards */
AN(plhs); AN(plhs);
AZ(*plhs); AZ(*plhs);
if (vxp->t->tok != VAL) { if (vxp->t->tok != VAL) {
VSB_printf(vxp->sb, "Expected VSL tag got '%.*s' ", PF(vxp->t)); VSB_printf(vxp->sb, "Expected VSL taglist got '%.*s' ",
PF(vxp->t));
vxp_ErrWhere(vxp, vxp->t, -1); vxp_ErrWhere(vxp, vxp->t, -1);
return; return;
} }
ALLOC_OBJ(*plhs, VEX_LHS_MAGIC); ALLOC_OBJ(*plhs, VEX_LHS_MAGIC);
AN(*plhs); AN(*plhs);
(*plhs)->tag = VSL_Name2Tag(vxp->t->dec, -1); (*plhs)->tags = vbit_init(SLT__MAX);
if ((*plhs)->tag == -1) { i = VSL_List2Tags(vxp->t->dec, -1, vsl_vbm_bitset, (*plhs)->tags);
VSB_printf(vxp->sb, "Could not match '%.*s' to any tag ", if (i == -1) {
PF(vxp->t)); VSB_printf(vxp->sb, "Taglist matches zero tags");
vxp_ErrWhere(vxp, vxp->t, -1); vxp_ErrWhere(vxp, vxp->t, -1);
return; return;
} else if ((*plhs)->tag == -2) { }
VSB_printf(vxp->sb, "'%.*s' matches multiple tags ", if (i == -2) {
PF(vxp->t)); VSB_printf(vxp->sb, "Taglist is ambiguous");
vxp_ErrWhere(vxp, vxp->t, -1);
return;
}
if (i == -3) {
VSB_printf(vxp->sb, "Syntax error in taglist");
vxp_ErrWhere(vxp, vxp->t, -1); vxp_ErrWhere(vxp, vxp->t, -1);
return; return;
} }
assert(i > 0);
vxp_NextToken(vxp); vxp_NextToken(vxp);
if (vxp->t->tok == '[') { if (vxp->t->tok == '[') {
...@@ -422,8 +431,11 @@ void ...@@ -422,8 +431,11 @@ void
vex_Free(struct vex **pvex) vex_Free(struct vex **pvex)
{ {
if ((*pvex)->lhs != NULL) if ((*pvex)->lhs != NULL) {
if ((*pvex)->lhs->tags != NULL)
vbit_destroy((*pvex)->lhs->tags);
FREE_OBJ((*pvex)->lhs); FREE_OBJ((*pvex)->lhs);
}
if ((*pvex)->rhs != NULL) { if ((*pvex)->rhs != NULL) {
if ((*pvex)->rhs->val_string) if ((*pvex)->rhs->val_string)
free((*pvex)->rhs->val_string); free((*pvex)->rhs->val_string);
...@@ -472,6 +484,25 @@ vex_print_rhs(const struct vex_rhs *rhs) ...@@ -472,6 +484,25 @@ vex_print_rhs(const struct vex_rhs *rhs)
} }
} }
static void
vex_print_tags(const struct vbitmap *vbm)
{
int i;
int first = 1;
for (i = 0; i < SLT__MAX; i++) {
if (VSL_tags[i] == NULL)
continue;
if (!vbit_test(vbm, i))
continue;
if (first)
first = 0;
else
fprintf(stderr, ",");
fprintf(stderr, "%s", VSL_tags[i]);
}
}
static void static void
vex_print(const struct vex *vex, int indent) vex_print(const struct vex *vex, int indent)
{ {
...@@ -480,7 +511,10 @@ vex_print(const struct vex *vex, int indent) ...@@ -480,7 +511,10 @@ vex_print(const struct vex *vex, int indent)
fprintf(stderr, "%*s%s", indent, "", vxp_tnames[vex->tok]); fprintf(stderr, "%*s%s", indent, "", vxp_tnames[vex->tok]);
if (vex->lhs != NULL) { if (vex->lhs != NULL) {
CHECK_OBJ_NOTNULL(vex->lhs, VEX_LHS_MAGIC); CHECK_OBJ_NOTNULL(vex->lhs, VEX_LHS_MAGIC);
fprintf(stderr, " tag=%s", VSL_tags[vex->lhs->tag]); AN(vex->lhs->tags);
fprintf(stderr, " lhs=(");
vex_print_tags(vex->lhs->tags);
fprintf(stderr, ")");
if (vex->lhs->field >= 0) if (vex->lhs->field >= 0)
fprintf(stderr, "[%d]", vex->lhs->field); fprintf(stderr, "[%d]", vex->lhs->field);
} }
......
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