Commit 90005c6b authored by Poul-Henning Kamp's avatar Poul-Henning Kamp

Move things over to the correct "VCC" prefix.

Split some stuff into separate files while we're at it.



git-svn-id: http://www.varnish-cache.org/svn/trunk/varnish-cache@544 d4fa192b-c00b-0410-8231-f00ffab90ce4
parent e915ed28
......@@ -5,8 +5,11 @@ INCLUDES = -I$(top_srcdir)/include
lib_LTLIBRARIES = libvcl.la
libvcl_la_SOURCES = \
vcl_priv.h \
vcl_token_defs.h \
vcc_priv.h \
vcc_compile.h \
vcc_token_defs.h \
\
vcl_compile.c \
vcl_fixed_token.c
vcc_compile.c \
vcc_fixed_token.c \
vcc_obj.c \
vcc_token.c
This diff is collapsed.
/*
* $Id$
*/
#include "queue.h"
#include "vcl_returns.h"
#define INDENT 2
struct token {
unsigned tok;
const char *b;
const char *e;
TAILQ_ENTRY(token) list;
unsigned cnt;
};
struct tokenlist {
TAILQ_HEAD(, token) tokens;
const char *b;
const char *e;
struct token *t;
int indent;
unsigned cnt;
struct sbuf *fc, *fh;
TAILQ_HEAD(, ref) refs;
struct sbuf *sb;
int err;
int nbackend;
TAILQ_HEAD(, proc) procs;
struct proc *curproc;
};
enum var_type {
BACKEND,
BOOL,
INT,
FLOAT,
SIZE,
RATE,
TIME,
STRING,
IP,
HOSTNAME,
PORTNAME,
HEADER
};
enum ref_type {
R_FUNC,
R_ACL,
R_BACKEND
};
struct ref {
enum ref_type type;
struct token *name;
unsigned defcnt;
unsigned refcnt;
TAILQ_ENTRY(ref) list;
};
struct var {
const char *name;
enum var_type fmt;
int len;
const char *rname;
const char *lname;
};
static struct method {
const char *name;
const char *defname;
unsigned returns;
} method_tab[] = {
#define VCL_RET_MAC(a,b,c)
#define VCL_MET_MAC(a,b,c) { "vcl_"#a, "default_vcl_"#a, c },
#include "vcl_returns.h"
#undef VCL_MET_MAC
#undef VCL_RET_MAC
{ NULL, 0U }
};
struct proccall {
TAILQ_ENTRY(proccall) list;
struct proc *p;
struct token *t;
};
struct proc {
TAILQ_ENTRY(proc) list;
TAILQ_HEAD(,proccall) calls;
struct token *name;
unsigned returns;
unsigned exists;
unsigned called;
unsigned active;
struct token *returnt[VCL_RET_MAX];
};
/*--------------------------------------------------------------------*/
/* vcc_compile.c */
extern const char *vcc_default_vcl_b, *vcc_default_vcl_e;
/* vcc_obj.c */
extern struct var vcc_be_vars[];
extern struct var vcc_vars[];
/* vcc_token.c */
void vcc_ErrToken(struct tokenlist *tl, struct token *t);
void vcc_ErrWhere(struct tokenlist *tl, struct token *t);
void vcc__Expect(struct tokenlist *tl, unsigned tok, int line);
int vcc_Teq(struct token *t1, struct token *t2);
int vcc_IdIs(struct token *t, const char *p);
void vcc_Lexer(struct tokenlist *tl, const char *b, const char *e);
void vcc_NextToken(struct tokenlist *tl);
void vcc__ErrInternal(struct tokenlist *tl, const char *func, unsigned line);
void vcc_AddToken(struct tokenlist *tl, unsigned tok, const char *b, const char *e);
......@@ -3,12 +3,12 @@
*
* NB: This file is machine generated, DO NOT EDIT!
*
* Edit vcl_gen_fixed_token.tcl instead
* Edit vcc_gen_fixed_token.tcl instead
*/
#include <stdio.h>
#include <ctype.h>
#include "vcl_priv.h"
#include "vcc_priv.h"
unsigned
vcl_fixed_token(const char *p, const char **q)
......@@ -436,7 +436,7 @@ vcl_output_lang_h(FILE *f)
fputs(" *\n", f);
fputs(" * NB: This file is machine generated, DO NOT EDIT!\n", f);
fputs(" *\n", f);
fputs(" * Edit vcl_gen_fixed_token.tcl instead\n", f);
fputs(" * Edit vcc_gen_fixed_token.tcl instead\n", f);
fputs(" */\n", f);
fputs("\n", f);
fputs("struct sess;\n", f);
......
......@@ -84,7 +84,7 @@ proc warns {fd} {
puts $fd " *"
puts $fd " * NB: This file is machine generated, DO NOT EDIT!"
puts $fd " *"
puts $fd " * Edit vcl_gen_fixed_token.tcl instead"
puts $fd " * Edit vcc_gen_fixed_token.tcl instead"
puts $fd " */"
puts $fd ""
}
......@@ -162,15 +162,15 @@ close $for
#----------------------------------------------------------------------
# Build the compiler token table and recognizers
set fo [open "vcl_fixed_token.c" w]
set fo [open "vcc_fixed_token.c" w]
warns $fo
set foh [open "vcl_token_defs.h" w]
set foh [open "vcc_token_defs.h" w]
warns $foh
puts $fo "#include <stdio.h>"
puts $fo "#include <ctype.h>"
puts $fo "#include \"vcl_priv.h\""
puts $fo "#include \"vcc_priv.h\""
set tn 128
puts $foh "#define LOW_TOKEN $tn"
......
This diff is collapsed.
......@@ -2,7 +2,7 @@
* Stuff shared between main.c and fixed_token.c
*/
#include "vcl_token_defs.h"
#include "vcc_token_defs.h"
#define isident1(c) (isalpha(c))
#define isident(c) (isalpha(c) || isdigit(c) || (c) == '_')
......
/*
* $Id$
*/
#include <sys/types.h>
#include <sys/socket.h>
#include <sys/stat.h>
#include <assert.h>
#include <ctype.h>
#include <errno.h>
#include <fcntl.h>
#include <netdb.h>
#include <stdio.h>
#include <printf.h>
#include <stdarg.h>
#include <sbuf.h>
#include <stdlib.h>
#include <string.h>
#include <queue.h>
#include <unistd.h>
#include "vcc_priv.h"
#include "vcl_returns.h"
#include "vcc_compile.h"
#include "libvcl.h"
#define ERRCHK(tl) do { if ((tl)->err) return; } while (0)
#define INDENT 2
/*--------------------------------------------------------------------*/
void
vcc_ErrToken(struct tokenlist *tl, struct token *t)
{
if (t->tok == EOI)
sbuf_printf(tl->sb, "end of input");
else
sbuf_printf(tl->sb, "'%T'", t);
}
void
vcc__ErrInternal(struct tokenlist *tl, const char *func, unsigned line)
{
sbuf_printf(tl->sb, "VCL compiler internal error at %s():%u\n",
func, line);
tl->err = 1;
}
void
vcc_ErrWhere(struct tokenlist *tl, struct token *t)
{
unsigned lin, pos, x, y;
const char *p, *l, *f, *b, *e;
lin = 1;
pos = 0;
if (t->tok == METHOD)
return;
if (t->b >= vcc_default_vcl_b && t->b < vcc_default_vcl_e) {
f = "Default VCL code (compiled in)";
b = vcc_default_vcl_b;
e = vcc_default_vcl_e;
} else {
f = "VCL code";
b = tl->b;
e = tl->e;
}
for (l = p = b; p < t->b; p++) {
if (*p == '\n') {
lin++;
pos = 0;
l = p + 1;
} else if (*p == '\t') {
pos &= ~7;
pos += 8;
} else
pos++;
}
sbuf_printf(tl->sb, "In %s Line %d Pos %d\n", f, lin, pos);
x = y = 0;
for (p = l; p < e && *p != '\n'; p++) {
if (*p == '\t') {
y &= ~7;
y += 8;
while (x < y) {
sbuf_bcat(tl->sb, " ", 1);
x++;
}
} else {
x++;
y++;
sbuf_bcat(tl->sb, p, 1);
}
}
sbuf_cat(tl->sb, "\n");
x = y = 0;
for (p = l; p < e && *p != '\n'; p++) {
if (p >= t->b && p < t->e) {
sbuf_bcat(tl->sb, "#", 1);
x++;
y++;
continue;
}
if (*p == '\t') {
y &= ~7;
y += 8;
} else
y++;
while (x < y) {
sbuf_bcat(tl->sb, "-", 1);
x++;
}
}
sbuf_cat(tl->sb, "\n");
tl->err = 1;
}
/*--------------------------------------------------------------------*/
void
vcc_NextToken(struct tokenlist *tl)
{
tl->t = TAILQ_NEXT(tl->t, list);
if (tl->t == NULL) {
sbuf_printf(tl->sb,
"Ran out of input, something is missing or"
" maybe unbalanced (...) or {...}\n");
tl->err = 1;
return;
}
}
void
vcc__Expect(struct tokenlist *tl, unsigned tok, int line)
{
if (tl->t->tok == tok)
return;
sbuf_printf(tl->sb, "Expected %s got ", vcl_tnames[tok]);
vcc_ErrToken(tl, tl->t);
sbuf_printf(tl->sb, "\n(program line %u), at\n", line);
vcc_ErrWhere(tl, tl->t);
}
#define Expect(a, b) _Expect(a, b, __LINE__)
#define ExpectErr(a, b) do { _Expect(a, b, __LINE__); ERRCHK(a);} while (0)
#define L(tl, foo) do { \
tl->indent += INDENT; \
foo; \
tl->indent -= INDENT; \
} while (0)
#define C(tl, sep) do { \
Fc(tl, 1, "VRT_count(sp, %u)%s\n", ++tl->cnt, sep); \
tl->t->cnt = tl->cnt; \
} while (0)
/*--------------------------------------------------------------------
* Compare token to token
*/
int
vcc_Teq(struct token *t1, struct token *t2)
{
if (t1->e - t1->b != t2->e - t2->b)
return (0);
return (!memcmp(t1->b, t2->b, t1->e - t1->b));
}
/*--------------------------------------------------------------------
* Compare ID token to string, return true of match
*/
int
vcc_IdIs(struct token *t, const char *p)
{
const char *q;
assert(t->tok == ID);
for (q = t->b; q < t->e && *p != '\0'; p++, q++)
if (*q != *p)
return (0);
if (q != t->e || *p != '\0')
return (0);
return (1);
}
/*--------------------------------------------------------------------
* Add a token to the token list.
*/
void
vcc_AddToken(struct tokenlist *tl, unsigned tok, const char *b, const char *e)
{
struct token *t;
t = calloc(sizeof *t, 1);
assert(t != NULL);
t->tok = tok;
t->b = b;
t->e = e;
TAILQ_INSERT_TAIL(&tl->tokens, t, list);
tl->t = t;
if (0) {
fprintf(stderr, "[%s %*.*s] ",
vcl_tnames[tok],
e - b, e - b, b);
if (tok == EOI)
fprintf(stderr, "\n");
}
}
/*--------------------------------------------------------------------
* Lexical analysis and token generation
*/
void
vcc_Lexer(struct tokenlist *tl, const char *b, const char *e)
{
const char *p, *q;
unsigned u;
for (p = b; p < e; ) {
/* Skip any whitespace */
if (isspace(*p)) {
p++;
continue;
}
/* Skip '#.*\n' comments */
if (*p == '#') {
while (p < e && *p != '\n')
p++;
continue;
}
/* Skip C-style comments */
if (*p == '/' && p[1] == '*') {
p += 2;
for (p += 2; p < e; p++) {
if (*p == '*' && p[1] == '/') {
p += 2;
break;
}
}
continue;
}
/* Match for the fixed tokens (see token.tcl) */
u = vcl_fixed_token(p, &q);
if (u != 0) {
vcc_AddToken(tl, u, p, q);
p = q;
continue;
}
/* Match strings, with \\ and \" escapes */
if (*p == '"') {
for (q = p + 1; q < e; q++) {
if (*q == '\\' && q[1] == '\\')
q++;
else if (*q == '\\' && q[1] == '"')
q++;
else if (*q == '"') {
q++;
break;
}
}
vcc_AddToken(tl, CSTR, p, q);
p = q;
continue;
}
/* Match Identifiers */
if (isident1(*p)) {
for (q = p; q < e; q++)
if (!isident(*q))
break;
if (isvar(*q)) {
for (; q < e; q++)
if (!isvar(*q))
break;
vcc_AddToken(tl, VAR, p, q);
} else {
vcc_AddToken(tl, ID, p, q);
}
p = q;
continue;
}
/* Match numbers { [0-9]+ } */
if (isdigit(*p)) {
for (q = p; q < e; q++)
if (!isdigit(*q))
break;
vcc_AddToken(tl, CNUM, p, q);
p = q;
continue;
}
vcc_AddToken(tl, EOI, p, p + 1);
sbuf_printf(tl->sb, "Syntax error at\n");
vcc_ErrWhere(tl, tl->t);
return;
}
}
......@@ -3,7 +3,7 @@
*
* NB: This file is machine generated, DO NOT EDIT!
*
* Edit vcl_gen_fixed_token.tcl instead
* Edit vcc_gen_fixed_token.tcl instead
*/
#define LOW_TOKEN 128
......
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