static void vcc_Compound(struct vcc *tl) { int i; SkipToken(tl, '{'); Fb(tl, 1, "{\n"); tl->indent += INDENT; C(tl, ";"); while (1) { ERRCHK(tl); switch (tl->t->tok) { case '{': vcc_Compound(tl); break; case '}': vcc_NextToken(tl); tl->indent -= INDENT; Fb(tl, 1, "}\n"); return; case CSRC: if (tl->allow_inline_c) { Fb(tl, 1, "%.*s\n", (int) (tl->t->e - (tl->t->b + 2)), tl->t->b + 1); vcc_NextToken(tl); } else { VSB_printf(tl->sb, "Inline-C not allowed\n"); vcc_ErrWhere(tl, tl->t); } break; case EOI: VSB_printf(tl->sb, "End of input while in compound statement\n"); tl->err = 1; return; case ID: if (vcc_IdIs(tl->t, "if")) { vcc_IfStmt(tl); break; } else { i = vcc_ParseAction(tl); ERRCHK(tl); if (i) { SkipToken(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; } } }
static void vcc_IfStmt(struct vcc *tl) { SkipToken(tl, ID); Fb(tl, 1, "if "); vcc_Conditional(tl); ERRCHK(tl); L(tl, vcc_Compound(tl)); ERRCHK(tl); while (tl->t->tok == ID) { if (vcc_IdIs(tl->t, "else")) { vcc_NextToken(tl); if (tl->t->tok == '{') { Fb(tl, 1, "else\n"); L(tl, vcc_Compound(tl)); ERRCHK(tl); return; } if (tl->t->tok != ID || !vcc_IdIs(tl->t, "if")) { VSB_printf(tl->sb, "'else' must be followed by 'if' or '{'\n"); vcc_ErrWhere(tl, tl->t); return; } Fb(tl, 1, "else if "); vcc_NextToken(tl); vcc_Conditional(tl); ERRCHK(tl); L(tl, vcc_Compound(tl)); ERRCHK(tl); } else if (vcc_IdIs(tl->t, "elseif") || vcc_IdIs(tl->t, "elsif") || vcc_IdIs(tl->t, "elif")) { Fb(tl, 1, "else if "); vcc_NextToken(tl); vcc_Conditional(tl); ERRCHK(tl); L(tl, vcc_Compound(tl)); ERRCHK(tl); } else { break; } } C(tl, ";"); }
static void vcc_Function(struct vcc *tl) { int m, i; vcc_NextToken(tl); ExpectErr(tl, ID); m = IsMethod(tl->t); if (m != -1) { assert(m < VCL_MET_MAX); tl->fb = tl->fm[m]; if (tl->mprocs[m] == NULL) { (void)vcc_AddDef(tl, tl->t, SYM_SUB); vcc_AddRef(tl, tl->t, SYM_SUB); tl->mprocs[m] = vcc_AddProc(tl, tl->t); } tl->curproc = tl->mprocs[m]; Fb(tl, 1, " /* ... from "); vcc_Coord(tl, tl->fb, NULL); Fb(tl, 0, " */\n"); } else { tl->fb = tl->fc; i = vcc_AddDef(tl, tl->t, SYM_SUB); if (i > 1) { VSB_printf(tl->sb, "Function %.*s redefined\n", PF(tl->t)); vcc_ErrWhere(tl, tl->t); return; } tl->curproc = vcc_AddProc(tl, tl->t); Fh(tl, 0, "static int VGC_function_%.*s (struct sess *sp);\n", PF(tl->t)); Fc(tl, 1, "\nstatic int\n"); Fc(tl, 1, "VGC_function_%.*s (struct sess *sp)\n", PF(tl->t)); } vcc_NextToken(tl); tl->indent += INDENT; Fb(tl, 1, "{\n"); L(tl, vcc_Compound(tl)); if (m == -1) { /* * non-method subroutines must have an explicit non-action * return in case they just fall through the bottom. */ Fb(tl, 1, " return(0);\n"); } Fb(tl, 1, "}\n"); tl->indent -= INDENT; tl->fb = NULL; tl->curproc = NULL; }
static void vcc_IfStmt(struct vcc *tl) { SkipToken(tl, T_IF); Fb(tl, 1, "if "); vcc_Conditional(tl); ERRCHK(tl); L(tl, vcc_Compound(tl)); ERRCHK(tl); while (1) { switch (tl->t->tok) { case T_ELSE: vcc_NextToken(tl); if (tl->t->tok != T_IF) { Fb(tl, 1, "else\n"); L(tl, vcc_Compound(tl)); ERRCHK(tl); return; } /* FALLTHROUGH */ case T_ELSEIF: case T_ELSIF: Fb(tl, 1, "else if "); vcc_NextToken(tl); vcc_Conditional(tl); ERRCHK(tl); L(tl, vcc_Compound(tl)); ERRCHK(tl); break; default: C(tl, ";"); return; } } }
static void vcc_ParseFunction(struct vcc *tl) { int m, i; vcc_NextToken(tl); vcc_ExpectCid(tl, "function"); ERRCHK(tl); m = IsMethod(tl->t); if (m == -2) { VSB_printf(tl->sb, "VCL sub's named 'vcl*' are reserved names.\n"); vcc_ErrWhere(tl, tl->t); VSB_printf(tl->sb, "Valid vcl_* methods are:\n"); for (i = 1; method_tab[i].name != NULL; i++) VSB_printf(tl->sb, "\t%s\n", method_tab[i].name); return; } else if (m != -1) { assert(m < VCL_MET_MAX); tl->fb = tl->fm[m]; if (tl->mprocs[m] == NULL) { (void)vcc_AddDef(tl, tl->t, SYM_SUB); vcc_AddRef(tl, tl->t, SYM_SUB); tl->mprocs[m] = vcc_AddProc(tl, tl->t); } tl->curproc = tl->mprocs[m]; Fb(tl, 1, " /* ... from "); vcc_Coord(tl, tl->fb, NULL); Fb(tl, 0, " */\n"); } else { tl->fb = tl->fc; i = vcc_AddDef(tl, tl->t, SYM_SUB); if (i > 1) { VSB_printf(tl->sb, "Function '%.*s' redefined\n", PF(tl->t)); vcc_ErrWhere(tl, tl->t); return; } tl->curproc = vcc_AddProc(tl, tl->t); Fh(tl, 0, "int VGC_function_%.*s " "(VRT_CTX);\n", PF(tl->t)); Fc(tl, 1, "\nint __match_proto__(vcl_func_t)\n"); Fc(tl, 1, "VGC_function_%.*s(VRT_CTX)\n", PF(tl->t)); } vcc_NextToken(tl); tl->indent += INDENT; Fb(tl, 1, "{\n"); L(tl, vcc_Compound(tl)); if (m == -1) { /* * non-method subroutines must have an explicit non-action * return in case they just fall through the bottom. */ Fb(tl, 1, " return(0);\n"); } Fb(tl, 1, "}\n"); tl->indent -= INDENT; tl->fb = NULL; tl->curproc = NULL; }