Mailing List Archive

[master] 7bb73c586 Slight polish while looking at #3360
commit 7bb73c586323fe6511ce04e6558fb2eca7073cef
Author: Poul-Henning Kamp <phk@FreeBSD.org>
Date: Mon Jul 13 09:40:56 2020 +0000

Slight polish while looking at #3360

diff --git a/lib/libvcc/vcc_compile.c b/lib/libvcc/vcc_compile.c
index d24ebf5e1..6bf82bfa0 100644
--- a/lib/libvcc/vcc_compile.c
+++ b/lib/libvcc/vcc_compile.c
@@ -251,7 +251,7 @@ EmitCoordinates(const struct vcc *tl, struct vsb *vsb)
{
struct token *t;
unsigned lin, pos;
- struct source *sp;
+ const struct source *sp;
const char *p;

VSB_cat(vsb, "/* ---===### Source Code ###===---*/\n");
@@ -610,7 +610,7 @@ vcc_resolve_includes(struct vcc *tl)
VTAILQ_INSERT_TAIL(&tl->sources, sp, list);
sp->idx = tl->nsources++;
tl->t = t2;
- vcc_Lexer(tl, sp);
+ vcc_Lexer(tl, sp, 0);

VTAILQ_REMOVE(&tl->tokens, t, list);
VTAILQ_REMOVE(&tl->tokens, t1, list);
@@ -654,7 +654,7 @@ vcc_CompileSource(struct vcc *tl, struct source *sp, const char *jfile)
/* Register and lex the main source */
VTAILQ_INSERT_TAIL(&tl->sources, sp, list);
sp->idx = tl->nsources++;
- vcc_Lexer(tl, sp);
+ vcc_Lexer(tl, sp, 0);
if (tl->err)
return (NULL);

@@ -663,12 +663,7 @@ vcc_CompileSource(struct vcc *tl, struct source *sp, const char *jfile)
assert(sp != NULL);
VTAILQ_INSERT_TAIL(&tl->sources, sp, list);
sp->idx = tl->nsources++;
- vcc_Lexer(tl, sp);
- if (tl->err)
- return (NULL);
-
- /* Add "END OF INPUT" token */
- vcc_AddToken(tl, EOI, sp->e, sp->e);
+ vcc_Lexer(tl, sp, 1);
if (tl->err)
return (NULL);

diff --git a/lib/libvcc/vcc_compile.h b/lib/libvcc/vcc_compile.h
index 47f3e51d0..1c9053b24 100644
--- a/lib/libvcc/vcc_compile.h
+++ b/lib/libvcc/vcc_compile.h
@@ -91,7 +91,7 @@ struct token {
unsigned tok;
const char *b;
const char *e;
- struct source *src;
+ const struct source *src;
VTAILQ_ENTRY(token) list;
unsigned cnt;
char *dec;
@@ -249,7 +249,6 @@ struct vcc {
struct tokenhead tokens;
VTAILQ_HEAD(, source) sources;
unsigned nsources;
- struct source *src;
struct token *t;
int indent;
int hindent;
@@ -404,12 +403,10 @@ void vcc_Warn(struct vcc *);
void vcc__Expect(struct vcc *tl, unsigned tok, unsigned line);
int vcc_IdIs(const struct token *t, const char *p);
void vcc_ExpectVid(struct vcc *tl, const char *what);
-void vcc_Lexer(struct vcc *tl, struct source *sp);
+void vcc_Lexer(struct vcc *tl, const struct source *sp, int eoi);
void vcc_NextToken(struct vcc *tl);
void vcc__ErrInternal(struct vcc *tl, const char *func,
unsigned line);
-void vcc_AddToken(struct vcc *tl, unsigned tok, const char *b,
- const char *e);

/* vcc_types.c */
vcc_type_t VCC_Type(const char *p);
diff --git a/lib/libvcc/vcc_token.c b/lib/libvcc/vcc_token.c
index 0e3b4569d..176b74eab 100644
--- a/lib/libvcc/vcc_token.c
+++ b/lib/libvcc/vcc_token.c
@@ -362,8 +362,9 @@ vcc_decstr(struct vcc *tl)
* Add a token to the token list.
*/

-void
-vcc_AddToken(struct vcc *tl, unsigned tok, const char *b, const char *e)
+static void
+vcc_addtoken(struct vcc *tl, unsigned tok,
+ const struct source *sp, const char *b, const char *e)
{
struct token *t;

@@ -372,7 +373,7 @@ vcc_AddToken(struct vcc *tl, unsigned tok, const char *b, const char *e)
t->tok = tok;
t->b = b;
t->e = e;
- t->src = tl->src;
+ t->src = sp;
if (tl->t != NULL)
VTAILQ_INSERT_AFTER(&tl->tokens, tl->t, t, list);
else
@@ -385,12 +386,11 @@ vcc_AddToken(struct vcc *tl, unsigned tok, const char *b, const char *e)
*/

void
-vcc_Lexer(struct vcc *tl, struct source *sp)
+vcc_Lexer(struct vcc *tl, const struct source *sp, int eoi)
{
const char *p, *q;
unsigned u;

- tl->src = sp;
for (p = sp->b; p < sp->e; ) {

/* Skip any whitespace */
@@ -412,9 +412,9 @@ vcc_Lexer(struct vcc *tl, struct source *sp)
if (*q == '/' && q[1] == '*') {
VSB_cat(tl->sb,
"/* ... */ comment contains /*\n");
- vcc_AddToken(tl, EOI, p, p + 2);
+ vcc_addtoken(tl, EOI, sp, p, p + 2);
vcc_ErrWhere(tl, tl->t);
- vcc_AddToken(tl, EOI, q, q + 2);
+ vcc_addtoken(tl, EOI, sp, q, q + 2);
vcc_ErrWhere(tl, tl->t);
return;
}
@@ -425,7 +425,7 @@ vcc_Lexer(struct vcc *tl, struct source *sp)
}
if (q < sp->e)
continue;
- vcc_AddToken(tl, EOI, p, p + 2);
+ vcc_addtoken(tl, EOI, sp, p, p + 2);
VSB_cat(tl->sb,
"Unterminated /* ... */ comment, starting at\n");
vcc_ErrWhere(tl, tl->t);
@@ -443,7 +443,7 @@ vcc_Lexer(struct vcc *tl, struct source *sp)
if (*p == 'C' && p[1] == '{') {
for (q = p + 2; q < sp->e; q++) {
if (*q == '}' && q[1] == 'C') {
- vcc_AddToken(tl, CSRC, p, q + 2);
+ vcc_addtoken(tl, CSRC, sp, p, q + 2);
break;
}
}
@@ -451,7 +451,7 @@ vcc_Lexer(struct vcc *tl, struct source *sp)
p = q + 2;
continue;
}
- vcc_AddToken(tl, EOI, p, p + 2);
+ vcc_addtoken(tl, EOI, sp, p, p + 2);
VSB_cat(tl->sb,
"Unterminated inline C source, starting at\n");
vcc_ErrWhere(tl, tl->t);
@@ -462,7 +462,7 @@ vcc_Lexer(struct vcc *tl, struct source *sp)
if (*p == '{' && p[1] == '"') {
for (q = p + 2; q < sp->e; q++) {
if (*q == '"' && q[1] == '}') {
- vcc_AddToken(tl, CSTR, p, q + 2);
+ vcc_addtoken(tl, CSTR, sp, p, q + 2);
break;
}
}
@@ -476,7 +476,7 @@ vcc_Lexer(struct vcc *tl, struct source *sp)
tl->t->dec[u] = '\0';
continue;
}
- vcc_AddToken(tl, EOI, p, p + 2);
+ vcc_addtoken(tl, EOI, sp, p, p + 2);
VSB_cat(tl->sb,
"Unterminated long-string, starting at\n");
vcc_ErrWhere(tl, tl->t);
@@ -486,7 +486,7 @@ vcc_Lexer(struct vcc *tl, struct source *sp)
/* Match for the fixed tokens (see generate.py) */
u = vcl_fixed_token(p, &q);
if (u != 0) {
- vcc_AddToken(tl, u, p, q);
+ vcc_addtoken(tl, u, sp, p, q);
p = q;
continue;
}
@@ -499,14 +499,14 @@ vcc_Lexer(struct vcc *tl, struct source *sp)
break;
}
if (*q == '\r' || *q == '\n') {
- vcc_AddToken(tl, EOI, p, q);
+ vcc_addtoken(tl, EOI, sp, p, q);
VSB_cat(tl->sb,
"Unterminated string at\n");
vcc_ErrWhere(tl, tl->t);
return;
}
}
- vcc_AddToken(tl, CSTR, p, q);
+ vcc_addtoken(tl, CSTR, sp, p, q);
if (vcc_decstr(tl))
return;
p = q;
@@ -518,7 +518,7 @@ vcc_Lexer(struct vcc *tl, struct source *sp)
for (q = p; q < sp->e; q++)
if (!vct_isident(*q))
break;
- vcc_AddToken(tl, ID, p, q);
+ vcc_addtoken(tl, ID, sp, p, q);
p = q;
continue;
}
@@ -529,20 +529,22 @@ vcc_Lexer(struct vcc *tl, struct source *sp)
if (!vct_isdigit(*q))
break;
if (*q != '.') {
- vcc_AddToken(tl, CNUM, p, q);
+ vcc_addtoken(tl, CNUM, sp, p, q);
p = q;
continue;
}
for (++q; q < sp->e; q++)
if (!vct_isdigit(*q))
break;
- vcc_AddToken(tl, FNUM, p, q);
+ vcc_addtoken(tl, FNUM, sp, p, q);
p = q;
continue;
}
- vcc_AddToken(tl, EOI, p, p + 1);
+ vcc_addtoken(tl, EOI, sp, p, p + 1);
VSB_cat(tl->sb, "Syntax error at\n");
vcc_ErrWhere(tl, tl->t);
return;
}
+ if (eoi)
+ vcc_addtoken(tl, EOI, sp, sp->e, sp->e);
}
_______________________________________________
varnish-commit mailing list
varnish-commit@varnish-cache.org
https://www.varnish-cache.org/lists/mailman/listinfo/varnish-commit