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

More polishing and comment cleanup



git-svn-id: http://www.varnish-cache.org/svn/trunk/varnish-cache@4617 d4fa192b-c00b-0410-8231-f00ffab90ce4
parent 13877181
...@@ -25,6 +25,9 @@ ...@@ -25,6 +25,9 @@
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
* SUCH DAMAGE. * SUCH DAMAGE.
*
* This file parses the real action of the VCL code, the procedure
* statements which do the actual work.
*/ */
#include "config.h" #include "config.h"
...@@ -43,33 +46,6 @@ SVNID("$Id$") ...@@ -43,33 +46,6 @@ SVNID("$Id$")
/*--------------------------------------------------------------------*/ /*--------------------------------------------------------------------*/
static void
parse_action(struct tokenlist *tl)
{
int retval = 0;
Expect(tl, ID);
#define VCL_RET_MAC(l, U) \
do { \
if (vcc_IdIs(tl->t, #l)) { \
Fb(tl, 1, "VRT_done(sp, VCL_RET_" #U ");\n"); \
vcc_ProcAction(tl->curproc, VCL_RET_##U, tl->t);\
retval = 1; \
} \
} while (0);
#include "vcl_returns.h"
#undef VCL_RET_MAC
if (!retval) {
vsb_printf(tl->sb, "Expected action name.\n");
vcc_ErrWhere(tl, tl->t);
ERRCHK(tl);
}
vcc_NextToken(tl);
}
/*--------------------------------------------------------------------*/
static void static void
parse_restart(struct tokenlist *tl) parse_restart(struct tokenlist *tl)
{ {
...@@ -488,13 +464,29 @@ parse_panic(struct tokenlist *tl) ...@@ -488,13 +464,29 @@ parse_panic(struct tokenlist *tl)
static void static void
parse_return(struct tokenlist *tl) parse_return(struct tokenlist *tl)
{ {
int retval = 0;
vcc_NextToken(tl); vcc_NextToken(tl);
Expect(tl, '('); Expect(tl, '(');
vcc_NextToken(tl); vcc_NextToken(tl);
Expect(tl, ID); Expect(tl, ID);
parse_action(tl); #define VCL_RET_MAC(l, U) \
ERRCHK(tl); do { \
if (vcc_IdIs(tl->t, #l)) { \
Fb(tl, 1, "VRT_done(sp, VCL_RET_" #U ");\n"); \
vcc_ProcAction(tl->curproc, VCL_RET_##U, tl->t);\
retval = 1; \
} \
} while (0);
#include "vcl_returns.h"
#undef VCL_RET_MAC
if (!retval) {
vsb_printf(tl->sb, "Expected return action name.\n");
vcc_ErrWhere(tl, tl->t);
ERRCHK(tl);
}
vcc_NextToken(tl);
Expect(tl, ')'); Expect(tl, ')');
vcc_NextToken(tl); vcc_NextToken(tl);
} }
...@@ -542,21 +534,19 @@ static struct action_table { ...@@ -542,21 +534,19 @@ static struct action_table {
{ NULL, NULL } { NULL, NULL }
}; };
void int
vcc_ParseAction(struct tokenlist *tl) vcc_ParseAction(struct tokenlist *tl)
{ {
struct token *at; struct token *at;
struct action_table *atp; struct action_table *atp;
at = tl->t; at = tl->t;
if (at->tok == ID) { assert (at->tok == ID);
for(atp = action_table; atp->name != NULL; atp++) { for(atp = action_table; atp->name != NULL; atp++) {
if (vcc_IdIs(at, atp->name)) { if (vcc_IdIs(at, atp->name)) {
atp->func(tl); atp->func(tl);
return; return(1);
}
} }
} }
vsb_printf(tl->sb, "Expected action, 'if' or '}'\n"); return (0);
vcc_ErrWhere(tl, at);
} }
...@@ -154,7 +154,7 @@ void vcc_Acl(struct tokenlist *tl); ...@@ -154,7 +154,7 @@ void vcc_Acl(struct tokenlist *tl);
void vcc_Cond_Ip(const struct var *vp, struct tokenlist *tl); void vcc_Cond_Ip(const struct var *vp, struct tokenlist *tl);
/* vcc_action.c */ /* vcc_action.c */
void vcc_ParseAction(struct tokenlist *tl); int vcc_ParseAction(struct tokenlist *tl);
/* vcc_backend.c */ /* vcc_backend.c */
struct fld_spec; struct fld_spec;
......
...@@ -467,6 +467,7 @@ IfStmt(struct tokenlist *tl) ...@@ -467,6 +467,7 @@ IfStmt(struct tokenlist *tl)
static void static void
Compound(struct tokenlist *tl) Compound(struct tokenlist *tl)
{ {
int i;
ExpectErr(tl, '{'); ExpectErr(tl, '{');
Fb(tl, 1, "{\n"); Fb(tl, 1, "{\n");
...@@ -498,12 +499,21 @@ Compound(struct tokenlist *tl) ...@@ -498,12 +499,21 @@ Compound(struct tokenlist *tl)
"End of input while in compound statement\n"); "End of input while in compound statement\n");
tl->err = 1; tl->err = 1;
return; return;
default: case ID:
vcc_ParseAction(tl); i = vcc_ParseAction(tl);
ERRCHK(tl); ERRCHK(tl);
ExpectErr(tl, ';'); if (i) {
vcc_NextToken(tl); ExpectErr(tl, ';');
break; vcc_NextToken(tl);
break;
}
/* FALLTHROUGH */
default:
/* We deliberately do not mention inline C */
vsb_printf(tl->sb,
"Expected an action, 'if', '{' or '}'\n");
vcc_ErrWhere(tl, tl->t);
return;
} }
} }
} }
...@@ -559,8 +569,10 @@ Function(struct tokenlist *tl) ...@@ -559,8 +569,10 @@ Function(struct tokenlist *tl)
/*-------------------------------------------------------------------- /*--------------------------------------------------------------------
* Top level of parser, recognize: * Top level of parser, recognize:
* Inline C-code
* ACL definitions
* Function definitions * Function definitions
* Backend definitions * Backend & Director definitions
* End of input * End of input
*/ */
...@@ -603,6 +615,7 @@ vcc_Parse(struct tokenlist *tl) ...@@ -603,6 +615,7 @@ vcc_Parse(struct tokenlist *tl)
break; break;
/* FALLTHROUGH */ /* FALLTHROUGH */
default: default:
/* We deliberately do not mention inline-C */
vsb_printf(tl->sb, "Expected one of\n\t"); vsb_printf(tl->sb, "Expected one of\n\t");
for (tp = toplev; tp->name != NULL; tp++) { for (tp = toplev; tp->name != NULL; tp++) {
if (tp[1].name == NULL) if (tp[1].name == NULL)
......
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