[master] adb65db Dont assume that symbols are a single token (1/many)

Poul-Henning Kamp phk at FreeBSD.org
Wed Jan 31 10:50:10 UTC 2018


commit adb65db53cba2ec2282d49d8f9442507e71e8e36
Author: Poul-Henning Kamp <phk at FreeBSD.org>
Date:   Wed Jan 31 09:20:13 2018 +0000

    Dont assume that symbols are a single token (1/many)

diff --git a/lib/libvcc/vcc_compile.h b/lib/libvcc/vcc_compile.h
index 0067365..a572847 100644
--- a/lib/libvcc/vcc_compile.h
+++ b/lib/libvcc/vcc_compile.h
@@ -105,7 +105,7 @@ enum symkind {
 };
 
 typedef void sym_expr_t(struct vcc *tl, struct expr **,
-    struct symbol *sym, vcc_type_t);
+    struct token *, struct symbol *sym, vcc_type_t);
 typedef void sym_wildcard_t(struct vcc *, struct symbol *, struct symbol *);
 
 typedef void sym_act_f(struct vcc *, struct symbol *);
diff --git a/lib/libvcc/vcc_expr.c b/lib/libvcc/vcc_expr.c
index d43f5e8..5cfc76c 100644
--- a/lib/libvcc/vcc_expr.c
+++ b/lib/libvcc/vcc_expr.c
@@ -282,16 +282,16 @@ vcc_expr_tostring(struct vcc *tl, struct expr **e, vcc_type_t fmt)
  */
 
 static void v_matchproto_(sym_expr_t)
-vcc_Eval_Regsub(struct vcc *tl, struct expr **e, struct symbol *sym,
-    vcc_type_t fmt)
+vcc_Eval_Regsub(struct vcc *tl, struct expr **e, struct token *t,
+    struct symbol *sym, vcc_type_t fmt)
 {
 	struct expr *e2;
 	int all = sym->eval_priv == NULL ? 0 : 1;
 	const char *p;
 	char buf[128];
 
+	(void)t;
 	(void)fmt;
-	SkipToken(tl, ID);
 	SkipToken(tl, '(');
 	vcc_expr0(tl, &e2, STRING);
 	ERRCHK(tl);
@@ -312,12 +312,13 @@ vcc_Eval_Regsub(struct vcc *tl, struct expr **e, struct symbol *sym,
  */
 
 static void v_matchproto_(sym_expr_t)
-vcc_Eval_BoolConst(struct vcc *tl, struct expr **e, struct symbol *sym,
-    vcc_type_t fmt)
+vcc_Eval_BoolConst(struct vcc *tl, struct expr **e, struct token *t,
+    struct symbol *sym, vcc_type_t fmt)
 {
 
+	(void)t;
+	(void)tl;
 	(void)fmt;
-	vcc_NextToken(tl);
 	*e = vcc_mk_expr(BOOL, "(0==%d)", sym->eval_priv == NULL ? 1 : 0);
 	(*e)->constant = EXPR_CONST;
 }
@@ -326,10 +327,11 @@ vcc_Eval_BoolConst(struct vcc *tl, struct expr **e, struct symbol *sym,
  */
 
 void v_matchproto_(sym_expr_t)
-vcc_Eval_Handle(struct vcc *tl, struct expr **e, struct symbol *sym,
-    vcc_type_t fmt)
+vcc_Eval_Handle(struct vcc *tl, struct expr **e, struct token *t,
+    struct symbol *sym, vcc_type_t fmt)
 {
 
+	(void)t;
 	AN(sym->rname);
 
 	vcc_AddRef(tl, sym);
@@ -338,34 +340,31 @@ vcc_Eval_Handle(struct vcc *tl, struct expr **e, struct symbol *sym,
 		(*e)->nstr = 1;
 		(*e)->constant |= EXPR_CONST | EXPR_STR_CONST;
 	} else {
-		vcc_ExpectVid(tl, "handle");
 		*e = vcc_mk_expr(sym->fmt, "%s", sym->rname);
 		(*e)->constant = EXPR_VAR;
 		(*e)->nstr = 1;
 		if ((*e)->fmt == STRING)
 			(*e)->fmt = STRINGS;
 	}
-	vcc_NextToken(tl);
 }
 
 /*--------------------------------------------------------------------
  */
 
 void v_matchproto_(sym_expr_t)
-vcc_Eval_Var(struct vcc *tl, struct expr **e, struct symbol *sym,
-    vcc_type_t fmt)
+vcc_Eval_Var(struct vcc *tl, struct expr **e, struct token *t,
+    struct symbol *sym, vcc_type_t fmt)
 {
 
 	(void)fmt;
 	assert(sym->kind == SYM_VAR);
-	vcc_AddUses(tl, tl->t, NULL, sym->r_methods, "Not available");
+	vcc_AddUses(tl, t, NULL, sym->r_methods, "Not available");
 	ERRCHK(tl);
 	*e = vcc_mk_expr(sym->fmt, "%s", sym->rname);
 	(*e)->constant = EXPR_VAR;
 	(*e)->nstr = 1;
 	if ((*e)->fmt == STRING)
 		(*e)->fmt = STRINGS;
-	vcc_NextToken(tl);
 }
 
 /*--------------------------------------------------------------------
@@ -597,16 +596,16 @@ vcc_Eval_Func(struct vcc *tl, const char *spec,
  */
 
 void v_matchproto_(sym_expr_t)
-vcc_Eval_SymFunc(struct vcc *tl, struct expr **e, struct symbol *sym,
-    vcc_type_t fmt)
+vcc_Eval_SymFunc(struct vcc *tl, struct expr **e, struct token *t,
+    struct symbol *sym, vcc_type_t fmt)
 {
 
+	(void)t;
 	(void)fmt;
 	assert(sym->kind == SYM_FUNC);
 	AN(sym->eval_priv);
 
-	SkipToken(tl, ID);
-	assert(sym->fmt == VCC_Type(sym->eval_priv));
+	// assert(sym->fmt == VCC_Type(sym->eval_priv));
 	vcc_func(tl, e, sym->eval_priv, sym->extra, sym);
 	ERRCHK(tl);
 	if ((*e)->fmt == STRING) {
@@ -629,6 +628,7 @@ vcc_expr4(struct vcc *tl, struct expr **e, vcc_type_t fmt)
 {
 	struct expr *e1, *e2;
 	const char *ip, *sign;
+	struct token *t;
 	struct symbol *sym;
 	double d;
 	int i;
@@ -677,7 +677,9 @@ vcc_expr4(struct vcc *tl, struct expr **e, vcc_type_t fmt)
 		case SYM_PROBE:
 			AN(sym->eval);
 			AZ(*e);
-			sym->eval(tl, e, sym, fmt);
+			t = tl->t;
+			vcc_NextToken(tl);
+			sym->eval(tl, e, t, sym, fmt);
 			ERRCHK(tl);
 			/* Unless asked for a HEADER, fold to string here */
 			if (*e && fmt != HEADER && (*e)->fmt == HEADER) {
@@ -1270,7 +1272,8 @@ vcc_ParseCall(struct vcc *tl, struct symbol *sym)
 
 	t1 = tl->t;
 	e = NULL;
-	vcc_Eval_SymFunc(tl, &e, sym, VOID);
+	vcc_NextToken(tl);
+	vcc_Eval_SymFunc(tl, &e, t1, sym, VOID);
 	if (!tl->err) {
 		vcc_expr_fmt(tl->fb, tl->indent, e);
 		SkipToken(tl, ';');
@@ -1291,13 +1294,11 @@ vcc_Expr_Init(struct vcc *tl)
 
 	sym = VCC_MkSym(tl, "regsub", SYM_FUNC);
 	AN(sym);
-	sym->action = vcc_ParseCall;
 	sym->eval = vcc_Eval_Regsub;
 	sym->eval_priv = NULL;
 
 	sym = VCC_MkSym(tl, "regsuball", SYM_FUNC);
 	AN(sym);
-	sym->action = vcc_ParseCall;
 	sym->eval = vcc_Eval_Regsub;
 	sym->eval_priv = sym;
 
diff --git a/lib/libvcc/vcc_symb.c b/lib/libvcc/vcc_symb.c
index 0e58c4c..f79068e 100644
--- a/lib/libvcc/vcc_symb.c
+++ b/lib/libvcc/vcc_symb.c
@@ -271,10 +271,12 @@ VCC_GlobalSymbol(struct symbol *sym, vcc_type_t fmt, const char *pfx)
 
 	sym->fmt = fmt;
 	sym->kind = VCC_HandleKind(sym->fmt);
-	if (sym->kind != SYM_NONE)
+	if (sym->kind != SYM_NONE) {
+		AZ(VCT_invalid_name(sym->rname, NULL));
 		sym->eval = vcc_Eval_Handle;
-	else
+	} else {
 		WRONG("Wrong kind of global symbol");
+	}
 
 #define VCL_MET_MAC(l,u,t,b)   sym->r_methods |= VCL_MET_##u;
 #include "tbl/vcl_returns.h"


More information about the varnish-commit mailing list