r5148 - trunk/varnish-cache/lib/libvcl
phk at varnish-cache.org
phk at varnish-cache.org
Mon Aug 30 13:06:05 CEST 2010
Author: phk
Date: 2010-08-30 13:06:05 +0200 (Mon, 30 Aug 2010)
New Revision: 5148
Modified:
trunk/varnish-cache/lib/libvcl/vcc_compile.h
trunk/varnish-cache/lib/libvcl/vcc_expr.c
trunk/varnish-cache/lib/libvcl/vcc_types.h
trunk/varnish-cache/lib/libvcl/vcc_vmod.c
Log:
Pick up the specification strings, and build symbols from them.
Add code to implement function calls, based on symbols.
Add type-single-char values to definitions in vcc_types.h.
Modified: trunk/varnish-cache/lib/libvcl/vcc_compile.h
===================================================================
--- trunk/varnish-cache/lib/libvcl/vcc_compile.h 2010-08-30 11:04:38 UTC (rev 5147)
+++ trunk/varnish-cache/lib/libvcl/vcc_compile.h 2010-08-30 11:06:05 UTC (rev 5148)
@@ -39,7 +39,7 @@
struct acl_e;
enum var_type {
-#define VCC_TYPE(foo) foo,
+#define VCC_TYPE(foo, bar) foo,
#include "vcc_types.h"
#undef VCC_TYPE
};
@@ -75,6 +75,8 @@
char *name;
unsigned nlen;
unsigned wildcard;
+ const char *cfunc;
+ const char *args;
const struct var *var;
enum var_type fmt;
unsigned r_methods;
Modified: trunk/varnish-cache/lib/libvcl/vcc_expr.c
===================================================================
--- trunk/varnish-cache/lib/libvcl/vcc_expr.c 2010-08-30 11:04:38 UTC (rev 5147)
+++ trunk/varnish-cache/lib/libvcl/vcc_expr.c 2010-08-30 11:06:05 UTC (rev 5148)
@@ -49,14 +49,28 @@
vcc_Type(enum var_type fmt)
{
switch(fmt) {
-#define VCC_TYPE(a) case a: return(#a);
+#define VCC_TYPE(a, b) case a: return(#a);
#include "vcc_types.h"
#undef VCC_TYPE
default:
- return("Unknown Type");
+ assert("Unknwon Type");
+ return(NULL);
}
}
+static enum var_type
+vcc_Ltype(char c)
+{
+ switch (c) {
+#define VCC_TYPE(a, b) case b: return(a);
+#include "vcc_types.h"
+#undef VCC_TYPE
+ default:
+ assert("Unknwon Type");
+ return(0);
+ }
+}
+
/*--------------------------------------------------------------------
* Recognize and convert units of time, return seconds.
*/
@@ -398,6 +412,46 @@
}
/*--------------------------------------------------------------------
+ */
+
+static void
+vcc_expr_call(struct vcc *tl, struct expr **e, const struct symbol *sym)
+{
+ const char *p, *q;
+ struct expr *e1;
+
+ (void)tl;
+ (void)e;
+ AN(sym->cfunc);
+ AN(sym->args);
+ SkipToken(tl, ID);
+ SkipToken(tl, '(');
+ p = sym->args;
+ (*e)->fmt = vcc_Ltype(*p++);
+ vsb_printf((*e)->vsb, "%s(sp, \v+", sym->cfunc);
+ vsb_finish((*e)->vsb);
+ AZ(vsb_overflowed((*e)->vsb));
+ q = "\v1\n\v2";
+ while (*p != '\0') {
+ e1 = NULL;
+ vcc_expr0(tl, &e1, vcc_Ltype(*p));
+ ERRCHK(tl);
+ assert(e1->fmt == vcc_Ltype(*p));
+ if (e1->fmt == STRING_LIST) {
+ e1 = vcc_expr_edit(STRING_LIST,
+ "\v+\n\v1,\nvrt_magic_string_end\v-", e1, NULL);
+ }
+ *e = vcc_expr_edit((*e)->fmt, q, *e, e1);
+ q = "\v1,\n\v2";
+ p++;
+ if (*p != '\0')
+ SkipToken(tl, ',');
+ }
+ SkipToken(tl, ')');
+ *e = vcc_expr_edit((*e)->fmt, "\v1\n)\v-", *e, NULL);
+}
+
+/*--------------------------------------------------------------------
* SYNTAX:
* Expr4:
* '(' Expr0 ')'
@@ -466,14 +520,20 @@
}
AN(sym);
- vcc_AddUses(tl, tl->t, sym->r_methods, "Not available");
- AN(sym->var);
- vp = vcc_FindVar(tl, tl->t, 0, "cannot be read");
- ERRCHK(tl);
- assert(vp != NULL);
- vsb_printf(e1->vsb, "%s", vp->rname);
- e1->fmt = vp->fmt;
- vcc_NextToken(tl);
+ if (sym->var != NULL) {
+ vcc_AddUses(tl, tl->t, sym->r_methods, "Not available");
+ vp = vcc_FindVar(tl, tl->t, 0, "cannot be read");
+ ERRCHK(tl);
+ assert(vp != NULL);
+ vsb_printf(e1->vsb, "%s", vp->rname);
+ e1->fmt = vp->fmt;
+ vcc_NextToken(tl);
+ } else if (sym->cfunc != NULL) {
+ vcc_expr_call(tl, &e1, sym);
+ ERRCHK(tl);
+ *e = e1;
+ return;
+ }
break;
case CSTR:
assert(fmt != VOID);
Modified: trunk/varnish-cache/lib/libvcl/vcc_types.h
===================================================================
--- trunk/varnish-cache/lib/libvcl/vcc_types.h 2010-08-30 11:04:38 UTC (rev 5147)
+++ trunk/varnish-cache/lib/libvcl/vcc_types.h 2010-08-30 11:06:05 UTC (rev 5148)
@@ -29,15 +29,15 @@
*/
/*lint -save -e525 -e539 */
-VCC_TYPE(VOID)
-VCC_TYPE(BACKEND)
-VCC_TYPE(BOOL)
-VCC_TYPE(INT)
-VCC_TYPE(TIME)
-VCC_TYPE(DURATION)
-VCC_TYPE(STRING)
-VCC_TYPE(STRING_LIST)
-VCC_TYPE(IP)
-VCC_TYPE(HEADER)
-VCC_TYPE(REAL)
+VCC_TYPE(VOID, 'V')
+VCC_TYPE(BACKEND, 'D')
+VCC_TYPE(BOOL, 'B')
+VCC_TYPE(INT, 'I')
+VCC_TYPE(TIME, 'T')
+VCC_TYPE(DURATION, 'M')
+VCC_TYPE(STRING, 'S')
+VCC_TYPE(STRING_LIST, 'L')
+VCC_TYPE(IP, 'A')
+VCC_TYPE(HEADER, 'H')
+VCC_TYPE(REAL, 'R')
/*lint -restore */
Modified: trunk/varnish-cache/lib/libvcl/vcc_vmod.c
===================================================================
--- trunk/varnish-cache/lib/libvcl/vcc_vmod.c 2010-08-30 11:04:38 UTC (rev 5147)
+++ trunk/varnish-cache/lib/libvcl/vcc_vmod.c 2010-08-30 11:06:05 UTC (rev 5148)
@@ -33,6 +33,7 @@
#include <stdio.h>
#include <dlfcn.h>
+#include <string.h>
#include "vsb.h"
@@ -48,6 +49,9 @@
struct token *mod;
const char *modname;
const char *proto;
+ const char **spec;
+ struct symbol *sym;
+ const char *p;
// int *modlen;
SkipToken(tl, ID);
@@ -115,5 +119,20 @@
vcc_ErrWhere(tl, mod);
return;
}
+ spec = dlsym(hdl, "Vmod_Spec");
+ if (modname == NULL) {
+ vsb_printf(tl->sb, "Could not load module %.*s\n\t%s\n\t%s\n",
+ PF(mod), fn, "Symbol Vmod_Spec not found");
+ vcc_ErrWhere(tl, mod);
+ return;
+ }
+ for (; *spec != NULL; spec++) {
+ p = *spec;
+ sym = VCC_AddSymbol(tl, p);
+ p += strlen(p) + 1;
+ sym->cfunc = p;
+ p += strlen(p) + 1;
+ sym->args = p;
+ }
Fh(tl, 0, "\n%s\n", proto);
}
More information about the varnish-commit
mailing list