Commit e09820fa authored by Poul-Henning Kamp's avatar Poul-Henning Kamp

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.



git-svn-id: http://www.varnish-cache.org/svn/trunk/varnish-cache@5148 d4fa192b-c00b-0410-8231-f00ffab90ce4
parent 4a31a5e1
...@@ -39,7 +39,7 @@ ...@@ -39,7 +39,7 @@
struct acl_e; struct acl_e;
enum var_type { enum var_type {
#define VCC_TYPE(foo) foo, #define VCC_TYPE(foo, bar) foo,
#include "vcc_types.h" #include "vcc_types.h"
#undef VCC_TYPE #undef VCC_TYPE
}; };
...@@ -75,6 +75,8 @@ struct symbol { ...@@ -75,6 +75,8 @@ struct symbol {
char *name; char *name;
unsigned nlen; unsigned nlen;
unsigned wildcard; unsigned wildcard;
const char *cfunc;
const char *args;
const struct var *var; const struct var *var;
enum var_type fmt; enum var_type fmt;
unsigned r_methods; unsigned r_methods;
......
...@@ -49,11 +49,25 @@ static const char * ...@@ -49,11 +49,25 @@ static const char *
vcc_Type(enum var_type fmt) vcc_Type(enum var_type fmt)
{ {
switch(fmt) { switch(fmt) {
#define VCC_TYPE(a) case a: return(#a); #define VCC_TYPE(a, b) case a: return(#a);
#include "vcc_types.h" #include "vcc_types.h"
#undef VCC_TYPE #undef VCC_TYPE
default: 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);
} }
} }
...@@ -397,6 +411,46 @@ hack_regsub(struct vcc *tl, struct expr **e, int all) ...@@ -397,6 +411,46 @@ hack_regsub(struct vcc *tl, struct expr **e, int all)
SkipToken(tl, ')'); SkipToken(tl, ')');
} }
/*--------------------------------------------------------------------
*/
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: * SYNTAX:
* Expr4: * Expr4:
...@@ -466,14 +520,20 @@ vcc_expr4(struct vcc *tl, struct expr **e, enum var_type fmt) ...@@ -466,14 +520,20 @@ vcc_expr4(struct vcc *tl, struct expr **e, enum var_type fmt)
} }
AN(sym); AN(sym);
vcc_AddUses(tl, tl->t, sym->r_methods, "Not available"); if (sym->var != NULL) {
AN(sym->var); vcc_AddUses(tl, tl->t, sym->r_methods, "Not available");
vp = vcc_FindVar(tl, tl->t, 0, "cannot be read"); vp = vcc_FindVar(tl, tl->t, 0, "cannot be read");
ERRCHK(tl); ERRCHK(tl);
assert(vp != NULL); assert(vp != NULL);
vsb_printf(e1->vsb, "%s", vp->rname); vsb_printf(e1->vsb, "%s", vp->rname);
e1->fmt = vp->fmt; e1->fmt = vp->fmt;
vcc_NextToken(tl); vcc_NextToken(tl);
} else if (sym->cfunc != NULL) {
vcc_expr_call(tl, &e1, sym);
ERRCHK(tl);
*e = e1;
return;
}
break; break;
case CSTR: case CSTR:
assert(fmt != VOID); assert(fmt != VOID);
......
...@@ -29,15 +29,15 @@ ...@@ -29,15 +29,15 @@
*/ */
/*lint -save -e525 -e539 */ /*lint -save -e525 -e539 */
VCC_TYPE(VOID) VCC_TYPE(VOID, 'V')
VCC_TYPE(BACKEND) VCC_TYPE(BACKEND, 'D')
VCC_TYPE(BOOL) VCC_TYPE(BOOL, 'B')
VCC_TYPE(INT) VCC_TYPE(INT, 'I')
VCC_TYPE(TIME) VCC_TYPE(TIME, 'T')
VCC_TYPE(DURATION) VCC_TYPE(DURATION, 'M')
VCC_TYPE(STRING) VCC_TYPE(STRING, 'S')
VCC_TYPE(STRING_LIST) VCC_TYPE(STRING_LIST, 'L')
VCC_TYPE(IP) VCC_TYPE(IP, 'A')
VCC_TYPE(HEADER) VCC_TYPE(HEADER, 'H')
VCC_TYPE(REAL) VCC_TYPE(REAL, 'R')
/*lint -restore */ /*lint -restore */
...@@ -33,6 +33,7 @@ SVNID("$Id$"); ...@@ -33,6 +33,7 @@ SVNID("$Id$");
#include <stdio.h> #include <stdio.h>
#include <dlfcn.h> #include <dlfcn.h>
#include <string.h>
#include "vsb.h" #include "vsb.h"
...@@ -48,6 +49,9 @@ vcc_ParseImport(struct vcc *tl) ...@@ -48,6 +49,9 @@ vcc_ParseImport(struct vcc *tl)
struct token *mod; struct token *mod;
const char *modname; const char *modname;
const char *proto; const char *proto;
const char **spec;
struct symbol *sym;
const char *p;
// int *modlen; // int *modlen;
SkipToken(tl, ID); SkipToken(tl, ID);
...@@ -115,5 +119,20 @@ vcc_ParseImport(struct vcc *tl) ...@@ -115,5 +119,20 @@ vcc_ParseImport(struct vcc *tl)
vcc_ErrWhere(tl, mod); vcc_ErrWhere(tl, mod);
return; 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); Fh(tl, 0, "\n%s\n", proto);
} }
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