comparison src/vim9compile.c @ 21717:ef3b31d510d2 v8.2.1408

patch 8.2.1408: Vim9: type casting not supported Commit: https://github.com/vim/vim/commit/64d662d5fc2ff8af4dbf399ff02aa9d711cc9312 Author: Bram Moolenaar <Bram@vim.org> Date: Sun Aug 9 19:02:50 2020 +0200 patch 8.2.1408: Vim9: type casting not supported Problem: Vim9: type casting not supported. Solution: Introduce type casting.
author Bram Moolenaar <Bram@vim.org>
date Sun, 09 Aug 2020 19:15:03 +0200
parents 571832713efa
children caf0286cf02b
comparison
equal deleted inserted replaced
21716:ba99b55d3fb7 21717:ef3b31d510d2
3400 vim_strncpy(buf, op, len); 3400 vim_strncpy(buf, op, len);
3401 semsg(_(e_white_both), buf); 3401 semsg(_(e_white_both), buf);
3402 } 3402 }
3403 3403
3404 /* 3404 /*
3405 * <type>expr7: runtime type check / conversion
3406 */
3407 static int
3408 compile_expr7t(char_u **arg, cctx_T *cctx, ppconst_T *ppconst)
3409 {
3410 type_T *want_type = NULL;
3411
3412 // Recognize <type>
3413 if (**arg == '<' && eval_isnamec1((*arg)[1]))
3414 {
3415 int called_emsg_before = called_emsg;
3416
3417 ++*arg;
3418 want_type = parse_type(arg, cctx->ctx_type_list);
3419 if (called_emsg != called_emsg_before)
3420 return FAIL;
3421
3422 if (**arg != '>')
3423 {
3424 if (*skipwhite(*arg) == '>')
3425 semsg(_(e_no_white_before), ">");
3426 else
3427 emsg(_("E1104: Missing >"));
3428 return FAIL;
3429 }
3430 ++*arg;
3431 if (may_get_next_line_error(*arg - 1, arg, cctx) == FAIL)
3432 return FAIL;
3433 }
3434
3435 if (compile_expr7(arg, cctx, ppconst) == FAIL)
3436 return FAIL;
3437
3438 if (want_type != NULL)
3439 {
3440 garray_T *stack = &cctx->ctx_type_stack;
3441 type_T *actual = ((type_T **)stack->ga_data)[stack->ga_len - 1];
3442
3443 if (check_type(want_type, actual, FALSE) == FAIL)
3444 {
3445 generate_ppconst(cctx, ppconst);
3446 if (need_type(actual, want_type, -1, cctx, FALSE) == FAIL)
3447 return FAIL;
3448 }
3449 }
3450
3451 return OK;
3452 }
3453
3454 /*
3405 * * number multiplication 3455 * * number multiplication
3406 * / number division 3456 * / number division
3407 * % number modulo 3457 * % number modulo
3408 */ 3458 */
3409 static int 3459 static int
3412 char_u *op; 3462 char_u *op;
3413 char_u *next; 3463 char_u *next;
3414 int ppconst_used = ppconst->pp_used; 3464 int ppconst_used = ppconst->pp_used;
3415 3465
3416 // get the first expression 3466 // get the first expression
3417 if (compile_expr7(arg, cctx, ppconst) == FAIL) 3467 if (compile_expr7t(arg, cctx, ppconst) == FAIL)
3418 return FAIL; 3468 return FAIL;
3419 3469
3420 /* 3470 /*
3421 * Repeat computing, until no "*", "/" or "%" is following. 3471 * Repeat computing, until no "*", "/" or "%" is following.
3422 */ 3472 */
3439 *arg = skipwhite(op + 1); 3489 *arg = skipwhite(op + 1);
3440 if (may_get_next_line(op + 1, arg, cctx) == FAIL) 3490 if (may_get_next_line(op + 1, arg, cctx) == FAIL)
3441 return FAIL; 3491 return FAIL;
3442 3492
3443 // get the second expression 3493 // get the second expression
3444 if (compile_expr7(arg, cctx, ppconst) == FAIL) 3494 if (compile_expr7t(arg, cctx, ppconst) == FAIL)
3445 return FAIL; 3495 return FAIL;
3446 3496
3447 if (ppconst->pp_used == ppconst_used + 2 3497 if (ppconst->pp_used == ppconst_used + 2
3448 && ppconst->pp_tv[ppconst_used].v_type == VAR_NUMBER 3498 && ppconst->pp_tv[ppconst_used].v_type == VAR_NUMBER
3449 && ppconst->pp_tv[ppconst_used + 1].v_type == VAR_NUMBER) 3499 && ppconst->pp_tv[ppconst_used + 1].v_type == VAR_NUMBER)