Mercurial > vim
comparison src/vim9compile.c @ 21959:67d4be2757b0 v8.2.1529
patch 8.2.1529: Vim9: :elseif may be compiled when not needed
Commit: https://github.com/vim/vim/commit/749639ec7248740cd271f34ec5f7bb70891b459c
Author: Bram Moolenaar <Bram@vim.org>
Date: Thu Aug 27 23:08:47 2020 +0200
patch 8.2.1529: Vim9: :elseif may be compiled when not needed
Problem: Vim9: :elseif may be compiled when not needed.
Solution: Do evaluate the :elseif expression.
author | Bram Moolenaar <Bram@vim.org> |
---|---|
date | Thu, 27 Aug 2020 23:15:04 +0200 |
parents | 4343657b49fa |
children | 0ce86b015058 |
comparison
equal
deleted
inserted
replaced
21958:d6f29ea3c947 | 21959:67d4be2757b0 |
---|---|
5517 garray_T *instr = &cctx->ctx_instr; | 5517 garray_T *instr = &cctx->ctx_instr; |
5518 int instr_count = instr->ga_len; | 5518 int instr_count = instr->ga_len; |
5519 isn_T *isn; | 5519 isn_T *isn; |
5520 scope_T *scope = cctx->ctx_scope; | 5520 scope_T *scope = cctx->ctx_scope; |
5521 ppconst_T ppconst; | 5521 ppconst_T ppconst; |
5522 skip_T save_skip = cctx->ctx_skip; | |
5522 | 5523 |
5523 if (scope == NULL || scope->se_type != IF_SCOPE) | 5524 if (scope == NULL || scope->se_type != IF_SCOPE) |
5524 { | 5525 { |
5525 emsg(_(e_elseif_without_if)); | 5526 emsg(_(e_elseif_without_if)); |
5526 return NULL; | 5527 return NULL; |
5539 isn->isn_arg.jump.jump_where = instr->ga_len; | 5540 isn->isn_arg.jump.jump_where = instr->ga_len; |
5540 } | 5541 } |
5541 | 5542 |
5542 // compile "expr"; if we know it evaluates to FALSE skip the block | 5543 // compile "expr"; if we know it evaluates to FALSE skip the block |
5543 CLEAR_FIELD(ppconst); | 5544 CLEAR_FIELD(ppconst); |
5545 if (cctx->ctx_skip == SKIP_YES) | |
5546 cctx->ctx_skip = SKIP_UNKNOWN; | |
5544 if (compile_expr1(&p, cctx, &ppconst) == FAIL) | 5547 if (compile_expr1(&p, cctx, &ppconst) == FAIL) |
5545 { | 5548 { |
5546 clear_ppconst(&ppconst); | 5549 clear_ppconst(&ppconst); |
5547 return NULL; | 5550 return NULL; |
5548 } | 5551 } |
5552 cctx->ctx_skip = save_skip; | |
5549 if (scope->se_skip_save == SKIP_YES) | 5553 if (scope->se_skip_save == SKIP_YES) |
5550 clear_ppconst(&ppconst); | 5554 clear_ppconst(&ppconst); |
5551 else if (instr->ga_len == instr_count && ppconst.pp_used == 1) | 5555 else if (instr->ga_len == instr_count && ppconst.pp_used == 1) |
5552 { | 5556 { |
5553 // The expression results in a constant. | 5557 // The expression results in a constant. |