Mercurial > vim
comparison src/vim9compile.c @ 19259:77cce0439714 v8.2.0188
patch 8.2.0188: Check commands don't work well with Vim9 script
Commit: https://github.com/vim/vim/commit/7f829cab356d63b8e59559285593777a66bcc02b
Author: Bram Moolenaar <Bram@vim.org>
Date: Fri Jan 31 22:12:41 2020 +0100
patch 8.2.0188: Check commands don't work well with Vim9 script
Problem: Check commands don't work well with Vim9 script.
Solution: Improve constant expression handling.
author | Bram Moolenaar <Bram@vim.org> |
---|---|
date | Fri, 31 Jan 2020 22:15:03 +0100 |
parents | 5aab9c306181 |
children | 9dc843109c97 |
comparison
equal
deleted
inserted
replaced
19258:952650587332 | 19259:77cce0439714 |
---|---|
3458 scope->se_local_count = cctx->ctx_locals.ga_len; | 3458 scope->se_local_count = cctx->ctx_locals.ga_len; |
3459 return scope; | 3459 return scope; |
3460 } | 3460 } |
3461 | 3461 |
3462 /* | 3462 /* |
3463 * Evaluate an expression that is a constant: has(arg) | 3463 * Evaluate an expression that is a constant: |
3464 * has(arg) | |
3465 * | |
3466 * Also handle: | |
3467 * ! in front logical NOT | |
3468 * | |
3464 * Return FAIL if the expression is not a constant. | 3469 * Return FAIL if the expression is not a constant. |
3465 */ | 3470 */ |
3466 static int | 3471 static int |
3467 evaluate_const_expr4(char_u **arg, cctx_T *cctx UNUSED, typval_T *tv) | 3472 evaluate_const_expr7(char_u **arg, cctx_T *cctx UNUSED, typval_T *tv) |
3468 { | 3473 { |
3469 typval_T argvars[2]; | 3474 typval_T argvars[2]; |
3470 | 3475 char_u *start_leader, *end_leader; |
3476 | |
3477 /* | |
3478 * Skip '!' characters. They are handled later. | |
3479 */ | |
3480 start_leader = *arg; | |
3481 while (**arg == '!') | |
3482 *arg = skipwhite(*arg + 1); | |
3483 end_leader = *arg; | |
3484 | |
3485 /* | |
3486 * Recognize only has() for now. | |
3487 */ | |
3471 if (STRNCMP("has(", *arg, 4) != 0) | 3488 if (STRNCMP("has(", *arg, 4) != 0) |
3472 return FAIL; | 3489 return FAIL; |
3473 *arg = skipwhite(*arg + 4); | 3490 *arg = skipwhite(*arg + 4); |
3474 | 3491 |
3475 if (**arg == '"') | 3492 if (**arg == '"') |
3495 tv->v_type = VAR_NUMBER; | 3512 tv->v_type = VAR_NUMBER; |
3496 tv->vval.v_number = 0; | 3513 tv->vval.v_number = 0; |
3497 f_has(argvars, tv); | 3514 f_has(argvars, tv); |
3498 clear_tv(&argvars[0]); | 3515 clear_tv(&argvars[0]); |
3499 | 3516 |
3517 while (start_leader < end_leader) | |
3518 { | |
3519 if (*start_leader == '!') | |
3520 tv->vval.v_number = !tv->vval.v_number; | |
3521 ++start_leader; | |
3522 } | |
3523 | |
3500 return OK; | 3524 return OK; |
3501 } | 3525 } |
3502 | 3526 |
3503 static int evaluate_const_expr3(char_u **arg, cctx_T *cctx, typval_T *tv); | 3527 static int evaluate_const_expr3(char_u **arg, cctx_T *cctx, typval_T *tv); |
3504 | 3528 |
3527 | 3551 |
3528 // eval the next expression | 3552 // eval the next expression |
3529 *arg = skipwhite(p + 2); | 3553 *arg = skipwhite(p + 2); |
3530 tv2.v_type = VAR_UNKNOWN; | 3554 tv2.v_type = VAR_UNKNOWN; |
3531 if ((opchar == '|' ? evaluate_const_expr3(arg, cctx, &tv2) | 3555 if ((opchar == '|' ? evaluate_const_expr3(arg, cctx, &tv2) |
3532 : evaluate_const_expr4(arg, cctx, &tv2)) == FAIL) | 3556 : evaluate_const_expr7(arg, cctx, &tv2)) == FAIL) |
3533 { | 3557 { |
3534 clear_tv(&tv2); | 3558 clear_tv(&tv2); |
3535 return FAIL; | 3559 return FAIL; |
3536 } | 3560 } |
3537 if ((opchar == '&') == val) | 3561 if ((opchar == '&') == val) |
3556 */ | 3580 */ |
3557 static int | 3581 static int |
3558 evaluate_const_expr3(char_u **arg, cctx_T *cctx, typval_T *tv) | 3582 evaluate_const_expr3(char_u **arg, cctx_T *cctx, typval_T *tv) |
3559 { | 3583 { |
3560 // evaluate the first expression | 3584 // evaluate the first expression |
3561 if (evaluate_const_expr4(arg, cctx, tv) == FAIL) | 3585 if (evaluate_const_expr7(arg, cctx, tv) == FAIL) |
3562 return FAIL; | 3586 return FAIL; |
3563 | 3587 |
3564 // || and && work almost the same | 3588 // || and && work almost the same |
3565 return evaluate_const_and_or(arg, cctx, "&&", tv); | 3589 return evaluate_const_and_or(arg, cctx, "&&", tv); |
3566 } | 3590 } |