source: lib/libvcl/vcc_compile.h @ 261945

Revision 261945, 5.8 KB checked in by Poul-Henning Kamp <phk@…>, 7 years ago (diff)

Have the VCL compiler provide a hint about the worst case number of
operations on the req.hash variable.

It is only a hint, because it merely counts how many times the parser
saw something being added to the req.hash variable. If the operation
was in a subroutine which was called multiple times, the hint will not
reflect the number of actual operations.

For now we will deal with that at runtime, at the expense of a
failed transaction every time we run short. If this becomes an issue,
an extensive topological analysis of the VCL program can give us
a definitive count.

git-svn-id:  http://www.varnish-cache.org/svn/trunk/varnish-cache@1803 d4fa192b-c00b-0410-8231-f00ffab90ce4

  • Property mode set to 100644
Line 
1/*-
2 * Copyright (c) 2006 Verdens Gang AS
3 * Copyright (c) 2006-2007 Linpro AS
4 * All rights reserved.
5 *
6 * Author: Poul-Henning Kamp <phk@phk.freebsd.dk>
7 *
8 * Redistribution and use in source and binary forms, with or without
9 * modification, are permitted provided that the following conditions
10 * are met:
11 * 1. Redistributions of source code must retain the above copyright
12 *    notice, this list of conditions and the following disclaimer.
13 * 2. Redistributions in binary form must reproduce the above copyright
14 *    notice, this list of conditions and the following disclaimer in the
15 *    documentation and/or other materials provided with the distribution.
16 *
17 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR AND CONTRIBUTORS ``AS IS'' AND
18 * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
19 * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
20 * ARE DISCLAIMED.  IN NO EVENT SHALL AUTHOR OR CONTRIBUTORS BE LIABLE
21 * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
22 * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
23 * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
24 * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
25 * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
26 * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
27 * SUCH DAMAGE.
28 *
29 * $Id$
30 */
31
32#include "queue.h"
33#include "vcl_returns.h"
34
35#define INDENT          2
36
37struct membit {
38        TAILQ_ENTRY(membit)     list;
39        void                    *ptr;
40};
41
42struct source {
43        TAILQ_ENTRY(source)     list;
44        char                    *name;
45        const char              *b;
46        const char              *e;
47        unsigned                idx;
48        char                    *freeit;
49};
50
51struct token {
52        unsigned                tok;
53        const char              *b;
54        const char              *e;
55        struct source           *src;
56        TAILQ_ENTRY(token)      list;
57        unsigned                cnt;
58        char                    *dec;
59};
60
61TAILQ_HEAD(tokenhead, token);
62
63struct tokenlist {
64        struct tokenhead        tokens;
65        TAILQ_HEAD(, source)    sources;
66        TAILQ_HEAD(, membit)    membits;
67        unsigned                nsources;
68        struct source           *src;
69        struct token            *t;
70        int                     indent;
71        int                     hindent;
72        int                     iindent;
73        int                     findent;
74        unsigned                cnt;
75        struct vsb              *fc, *fh, *fi, *ff, *fb;
76        struct vsb              *fm[N_METHODS];
77        TAILQ_HEAD(, ref)       refs;
78        struct vsb              *sb;
79        int                     err;
80        int                     nbackend;
81        TAILQ_HEAD(, proc)      procs;
82        struct proc             *curproc;
83        struct proc             *mprocs[N_METHODS];
84
85        unsigned                recnt;
86        unsigned                nhashcount;
87};
88
89enum var_type {
90        BACKEND,
91        BOOL,
92        INT,
93        FLOAT,
94        SIZE,
95        RATE,
96        TIME,
97        STRING,
98        IP,
99        HOSTNAME,
100        PORTNAME,
101        HASH,
102        HEADER
103};
104
105enum ref_type {
106        R_FUNC,
107        R_ACL,
108        R_BACKEND
109};
110
111struct ref {
112        enum ref_type           type;
113        struct token            *name;
114        unsigned                defcnt;
115        unsigned                refcnt;
116        TAILQ_ENTRY(ref)        list;
117};
118
119struct var {
120        const char              *name;
121        enum var_type           fmt;
122        unsigned                len;
123        const char              *rname;
124        const char              *lname;
125        enum {V_RO, V_RW, V_WO} access;
126        const char              *hdr;
127        unsigned                methods;
128};
129
130struct method {
131        const char              *name;
132        unsigned                returns;
133        unsigned                bitval;
134};
135
136/*--------------------------------------------------------------------*/
137
138/* vcc_acl.c */
139
140void vcc_Acl(struct tokenlist *tl);
141void vcc_Cond_Ip(const struct var *vp, struct tokenlist *tl);
142
143/* vcc_action.c */
144void vcc_ParseAction(struct tokenlist *tl);
145
146/* vcc_backend.c */
147void vcc_ParseBackend(struct tokenlist *tl);
148
149/* vcc_compile.c */
150extern struct method method_tab[];
151void Fh(const struct tokenlist *tl, int indent, const char *fmt, ...);
152void Fc(const struct tokenlist *tl, int indent, const char *fmt, ...);
153void Fb(const struct tokenlist *tl, int indent, const char *fmt, ...);
154void Fi(const struct tokenlist *tl, int indent, const char *fmt, ...);
155void Ff(const struct tokenlist *tl, int indent, const char *fmt, ...);
156void EncToken(struct vsb *sb, const struct token *t);
157int IsMethod(const struct token *t);
158void TlFree(struct tokenlist *tl, void *p);
159void *TlAlloc(struct tokenlist *tl, unsigned len);
160
161/* vcc_obj.c */
162extern struct var vcc_be_vars[];
163extern struct var vcc_vars[];
164
165/* vcc_parse.c */
166void vcc_Parse(struct tokenlist *tl);
167void vcc_RateVal(struct tokenlist *tl);
168void vcc_TimeVal(struct tokenlist *tl);
169void vcc_SizeVal(struct tokenlist *tl);
170unsigned vcc_UintVal(struct tokenlist *tl);
171double vcc_DoubleVal(struct tokenlist *tl);
172
173/* vcc_string.c */
174char *vcc_regexp(struct tokenlist *tl, int sub);
175int vcc_StringVal(struct tokenlist *tl);
176void vcc_ExpectedStringval(struct tokenlist *tl);
177
178/* vcc_token.c */
179void vcc_ErrToken(const struct tokenlist *tl, const struct token *t);
180void vcc_ErrWhere(struct tokenlist *tl, const struct token *t);
181void vcc__Expect(struct tokenlist *tl, unsigned tok, int line);
182int vcc_Teq(const struct token *t1, const struct token *t2);
183int vcc_IdIs(const struct token *t, const char *p);
184void vcc_Lexer(struct tokenlist *tl, struct source *sp);
185void vcc_NextToken(struct tokenlist *tl);
186void vcc__ErrInternal(struct tokenlist *tl, const char *func, unsigned line);
187void vcc_AddToken(struct tokenlist *tl, unsigned tok, const char *b, const char *e);
188void vcc_FreeToken(struct token *t);
189
190/* vcc_var.c */
191struct var *vcc_FindVar(struct tokenlist *tl, const struct token *t, struct var *vl);
192
193/* vcc_xref.c */
194void vcc_AddDef(struct tokenlist *tl, struct token *t, enum ref_type type);
195void vcc_AddRef(struct tokenlist *tl, struct token *t, enum ref_type type);
196int vcc_CheckReferences(struct tokenlist *tl);
197
198void vcc_AddCall(struct tokenlist *tl, struct token *t);
199struct proc *vcc_AddProc(struct tokenlist *tl, struct token *t);
200void vcc_ProcAction(struct proc *p, unsigned action, struct token *t);
201int vcc_CheckAction(struct tokenlist *tl);
202void vcc_AddUses(struct tokenlist *tl, struct var *v);
203int vcc_CheckUses(struct tokenlist *tl);
204
205#define ERRCHK(tl)      do { if ((tl)->err) return; } while (0)
206#define ErrInternal(tl) vcc__ErrInternal(tl, __func__, __LINE__)
207#define Expect(a, b) vcc__Expect(a, b, __LINE__)
208#define ExpectErr(a, b) do { vcc__Expect(a, b, __LINE__); ERRCHK(a);} while (0)
209
Note: See TracBrowser for help on using the repository browser.