Navigation Menu

Skip to content
This repository has been archived by the owner on Apr 28, 2022. It is now read-only.

Commit

Permalink
More polishing and comment cleanup
Browse files Browse the repository at this point in the history
git-svn-id: http://www.varnish-cache.org/svn/trunk/varnish-cache@4617 d4fa192b-c00b-0410-8231-f00ffab90ce4
  • Loading branch information
bsdphk committed Mar 16, 2010
1 parent 1387718 commit e9a8dfd
Show file tree
Hide file tree
Showing 3 changed files with 48 additions and 45 deletions.
66 changes: 28 additions & 38 deletions lib/libvcl/vcc_action.c
Expand Up @@ -25,6 +25,9 @@
* 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
* SUCH DAMAGE.
*
* This file parses the real action of the VCL code, the procedure
* statements which do the actual work.
*/

#include "config.h"
Expand All @@ -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
parse_restart(struct tokenlist *tl)
{
Expand Down Expand Up @@ -488,13 +464,29 @@ parse_panic(struct tokenlist *tl)
static void
parse_return(struct tokenlist *tl)
{
int retval = 0;

vcc_NextToken(tl);
Expect(tl, '(');
vcc_NextToken(tl);
Expect(tl, ID);

parse_action(tl);
ERRCHK(tl);
#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 return action name.\n");
vcc_ErrWhere(tl, tl->t);
ERRCHK(tl);
}
vcc_NextToken(tl);
Expect(tl, ')');
vcc_NextToken(tl);
}
Expand Down Expand Up @@ -542,21 +534,19 @@ static struct action_table {
{ NULL, NULL }
};

void
int
vcc_ParseAction(struct tokenlist *tl)
{
struct token *at;
struct action_table *atp;

at = tl->t;
if (at->tok == ID) {
for(atp = action_table; atp->name != NULL; atp++) {
if (vcc_IdIs(at, atp->name)) {
atp->func(tl);
return;
}
assert (at->tok == ID);
for(atp = action_table; atp->name != NULL; atp++) {
if (vcc_IdIs(at, atp->name)) {
atp->func(tl);
return(1);
}
}
vsb_printf(tl->sb, "Expected action, 'if' or '}'\n");
vcc_ErrWhere(tl, at);
return (0);
}
2 changes: 1 addition & 1 deletion lib/libvcl/vcc_compile.h
Expand Up @@ -154,7 +154,7 @@ void vcc_Acl(struct tokenlist *tl);
void vcc_Cond_Ip(const struct var *vp, struct tokenlist *tl);

/* vcc_action.c */
void vcc_ParseAction(struct tokenlist *tl);
int vcc_ParseAction(struct tokenlist *tl);

/* vcc_backend.c */
struct fld_spec;
Expand Down
25 changes: 19 additions & 6 deletions lib/libvcl/vcc_parse.c
Expand Up @@ -467,6 +467,7 @@ IfStmt(struct tokenlist *tl)
static void
Compound(struct tokenlist *tl)
{
int i;

ExpectErr(tl, '{');
Fb(tl, 1, "{\n");
Expand Down Expand Up @@ -498,12 +499,21 @@ Compound(struct tokenlist *tl)
"End of input while in compound statement\n");
tl->err = 1;
return;
default:
vcc_ParseAction(tl);
case ID:
i = vcc_ParseAction(tl);
ERRCHK(tl);
ExpectErr(tl, ';');
vcc_NextToken(tl);
break;
if (i) {
ExpectErr(tl, ';');
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;
}
}
}
Expand Down Expand Up @@ -559,8 +569,10 @@ Function(struct tokenlist *tl)

/*--------------------------------------------------------------------
* Top level of parser, recognize:
* Inline C-code
* ACL definitions
* Function definitions
* Backend definitions
* Backend & Director definitions
* End of input
*/

Expand Down Expand Up @@ -603,6 +615,7 @@ vcc_Parse(struct tokenlist *tl)
break;
/* FALLTHROUGH */
default:
/* We deliberately do not mention inline-C */
vsb_printf(tl->sb, "Expected one of\n\t");
for (tp = toplev; tp->name != NULL; tp++) {
if (tp[1].name == NULL)
Expand Down

0 comments on commit e9a8dfd

Please sign in to comment.