int lv_arg; // when TRUE this is an argument
} lvar_T;
+// values for ctx_skip
+typedef enum {
+ SKIP_NOT, // condition is a constant, produce code
+ SKIP_YES, // condition is a constant, do NOT produce code
+ SKIP_UNKNONW // condition is not a constant, produce code
+} skip_T;
+
/*
* Context for compiling lines of Vim script.
* Stores info about the local variables and condition stack.
garray_T ctx_imports; // imported items
- int ctx_skip; // when TRUE skip commands, when FALSE skip
- // commands after "else"
+ skip_T ctx_skip;
scope_T *ctx_scope; // current scope, NULL at toplevel
cctx_T *ctx_outer; // outer scope for lambda or nested
/////////////////////////////////////////////////////////////////////
// Following generate_ functions expect the caller to call ga_grow().
-#define RETURN_NULL_IF_SKIP(cctx) if (cctx->ctx_skip == TRUE) return NULL
-#define RETURN_OK_IF_SKIP(cctx) if (cctx->ctx_skip == TRUE) return OK
+#define RETURN_NULL_IF_SKIP(cctx) if (cctx->ctx_skip == SKIP_YES) return NULL
+#define RETURN_OK_IF_SKIP(cctx) if (cctx->ctx_skip == SKIP_YES) return OK
/*
* Generate an instruction without arguments.
int ret = OK;
int save_skip = cctx->ctx_skip;
- cctx->ctx_skip = FALSE;
+ cctx->ctx_skip = SKIP_NOT;
for (i = 0; i < ppconst->pp_used; ++i)
if (generate_tv_PUSH(cctx, &ppconst->pp_tv[i]) == FAIL)
ret = FAIL;
}
start_leader = end_leader; // don't apply again below
- if (cctx->ctx_skip == TRUE)
+ if (cctx->ctx_skip == SKIP_YES)
clear_tv(rettv);
else
// A constant expression can possibly be handled compile time,
const_value = tv2bool(&ppconst->pp_tv[ppconst_used]);
clear_tv(&ppconst->pp_tv[ppconst_used]);
--ppconst->pp_used;
- cctx->ctx_skip = save_skip == TRUE || !const_value;
+ cctx->ctx_skip = save_skip == SKIP_YES || !const_value
+ ? SKIP_YES : SKIP_NOT;
}
else
{
// evaluate the third expression
if (has_const_expr)
- cctx->ctx_skip = save_skip == TRUE || const_value;
+ cctx->ctx_skip = save_skip == SKIP_YES || const_value
+ ? SKIP_YES : SKIP_NOT;
*arg = skipwhite(p + 1);
if (may_get_next_line(p + 1, arg, cctx) == FAIL)
return FAIL;
eap->arg = name_end;
eap->getline = exarg_getline;
eap->cookie = cctx;
- eap->skip = cctx->ctx_skip == TRUE;
+ eap->skip = cctx->ctx_skip == SKIP_YES;
eap->forceit = FALSE;
ufunc = def_function(eap, name);
return NULL;
end = p;
- if (cctx->ctx_skip != TRUE)
+ if (cctx->ctx_skip != SKIP_YES)
{
type_T *stacktype;
if (!heredoc)
type = &t_any;
- if (cctx->ctx_skip != TRUE)
+ if (cctx->ctx_skip != SKIP_YES)
{
if (*var_start == '&')
{
goto theend;
}
- if (lvar == NULL && dest == dest_local && cctx->ctx_skip != TRUE)
+ if (lvar == NULL && dest == dest_local && cctx->ctx_skip != SKIP_YES)
{
if (oplen > 1 && !heredoc)
{
if (!heredoc)
{
- if (cctx->ctx_skip == TRUE)
+ if (cctx->ctx_skip == SKIP_YES)
{
if (oplen > 0 && var_count == 0)
{
}
// no need to parse more when skipping
- if (cctx->ctx_skip == TRUE)
+ if (cctx->ctx_skip == SKIP_YES)
break;
if (oplen > 0 && *op != '=')
{
// The expression results in a constant.
// TODO: how about nesting?
- cctx->ctx_skip = tv2bool(&ppconst.pp_tv[0]) ? FALSE : TRUE;
+ cctx->ctx_skip = tv2bool(&ppconst.pp_tv[0]) ? SKIP_NOT : SKIP_YES;
clear_ppconst(&ppconst);
}
else
{
// Not a constant, generate instructions for the expression.
- cctx->ctx_skip = MAYBE;
+ cctx->ctx_skip = SKIP_UNKNONW;
if (generate_ppconst(cctx, &ppconst) == FAIL)
return NULL;
}
if (scope == NULL)
return NULL;
- if (cctx->ctx_skip == MAYBE)
+ if (cctx->ctx_skip == SKIP_UNKNONW)
{
// "where" is set when ":elseif", "else" or ":endif" is found
scope->se_u.se_if.is_if_label = instr->ga_len;
}
unwind_locals(cctx, scope->se_local_count);
- if (cctx->ctx_skip == MAYBE)
+ if (cctx->ctx_skip == SKIP_UNKNONW)
{
if (compile_jump_to_end(&scope->se_u.se_if.is_end_label,
JUMP_ALWAYS, cctx) == FAIL)
{
// The expression results in a constant.
// TODO: how about nesting?
- cctx->ctx_skip = tv2bool(&ppconst.pp_tv[0]) ? FALSE : TRUE;
+ cctx->ctx_skip = tv2bool(&ppconst.pp_tv[0]) ? SKIP_NOT : SKIP_YES;
clear_ppconst(&ppconst);
scope->se_u.se_if.is_if_label = -1;
}
else
{
// Not a constant, generate instructions for the expression.
- cctx->ctx_skip = MAYBE;
+ cctx->ctx_skip = SKIP_UNKNONW;
if (generate_ppconst(cctx, &ppconst) == FAIL)
return NULL;
unwind_locals(cctx, scope->se_local_count);
// jump from previous block to the end, unless the else block is empty
- if (cctx->ctx_skip == MAYBE)
+ if (cctx->ctx_skip == SKIP_UNKNONW)
{
if (compile_jump_to_end(&scope->se_u.se_if.is_end_label,
JUMP_ALWAYS, cctx) == FAIL)
return NULL;
}
- if (cctx->ctx_skip == MAYBE)
+ if (cctx->ctx_skip == SKIP_UNKNONW)
{
if (scope->se_u.se_if.is_if_label >= 0)
{
}
}
- if (cctx->ctx_skip != MAYBE)
- cctx->ctx_skip = !cctx->ctx_skip;
+ if (cctx->ctx_skip != SKIP_UNKNONW)
+ cctx->ctx_skip = cctx->ctx_skip == SKIP_YES ? SKIP_NOT : SKIP_YES;
return p;
}
// Fill in the "end" label in jumps at the end of the blocks.
compile_fill_jump_to_end(&ifscope->is_end_label, cctx);
// TODO: this should restore the value from before the :if
- cctx->ctx_skip = MAYBE;
+ cctx->ctx_skip = SKIP_UNKNONW;
drop_scope(cctx);
return arg;
char_u *p;
int has_expr = FALSE;
- if (cctx->ctx_skip == TRUE)
+ if (cctx->ctx_skip == SKIP_YES)
goto theend;
if (eap->cmdidx >= 0 && eap->cmdidx < CMD_SIZE)
if (p == ea.cmd && ea.cmdidx != CMD_SIZE)
{
- if (cctx.ctx_skip == TRUE)
+ if (cctx.ctx_skip == SKIP_YES)
{
line += STRLEN(line);
continue;
p = skipwhite(p);
- if (cctx.ctx_skip == TRUE
+ if (cctx.ctx_skip == SKIP_YES
&& ea.cmdidx != CMD_elseif
&& ea.cmdidx != CMD_else
&& ea.cmdidx != CMD_endif)