Mercurial > vim
comparison src/vim9compile.c @ 23553:5c094273c015 v8.2.2319
patch 8.2.2319: "exptype_T" can be read as "expected type"
Commit: https://github.com/vim/vim/commit/657137ca487c60d63989236115115161def270a5
Author: Bram Moolenaar <Bram@vim.org>
Date: Sat Jan 9 15:45:23 2021 +0100
patch 8.2.2319: "exptype_T" can be read as "expected type"
Problem: "exptype_T" can be read as "expected type".
Solution: Rename to "exprtype_T", expression type.
author | Bram Moolenaar <Bram@vim.org> |
---|---|
date | Sat, 09 Jan 2021 16:00:04 +0100 |
parents | f90e429453fd |
children | f50ee1ae4d9b |
comparison
equal
deleted
inserted
replaced
23552:4c3639333c84 | 23553:5c094273c015 |
---|---|
667 /* | 667 /* |
668 * Get the instruction to use for comparing "type1" with "type2" | 668 * Get the instruction to use for comparing "type1" with "type2" |
669 * Return ISN_DROP when failed. | 669 * Return ISN_DROP when failed. |
670 */ | 670 */ |
671 static isntype_T | 671 static isntype_T |
672 get_compare_isn(exptype_T exptype, vartype_T type1, vartype_T type2) | 672 get_compare_isn(exprtype_T exprtype, vartype_T type1, vartype_T type2) |
673 { | 673 { |
674 isntype_T isntype = ISN_DROP; | 674 isntype_T isntype = ISN_DROP; |
675 | 675 |
676 if (type1 == VAR_UNKNOWN) | 676 if (type1 == VAR_UNKNOWN) |
677 type1 = VAR_ANY; | 677 type1 = VAR_ANY; |
697 else if (type1 == VAR_ANY || type2 == VAR_ANY | 697 else if (type1 == VAR_ANY || type2 == VAR_ANY |
698 || ((type1 == VAR_NUMBER || type1 == VAR_FLOAT) | 698 || ((type1 == VAR_NUMBER || type1 == VAR_FLOAT) |
699 && (type2 == VAR_NUMBER || type2 ==VAR_FLOAT))) | 699 && (type2 == VAR_NUMBER || type2 ==VAR_FLOAT))) |
700 isntype = ISN_COMPAREANY; | 700 isntype = ISN_COMPAREANY; |
701 | 701 |
702 if ((exptype == EXPR_IS || exptype == EXPR_ISNOT) | 702 if ((exprtype == EXPR_IS || exprtype == EXPR_ISNOT) |
703 && (isntype == ISN_COMPAREBOOL | 703 && (isntype == ISN_COMPAREBOOL |
704 || isntype == ISN_COMPARESPECIAL | 704 || isntype == ISN_COMPARESPECIAL |
705 || isntype == ISN_COMPARENR | 705 || isntype == ISN_COMPARENR |
706 || isntype == ISN_COMPAREFLOAT)) | 706 || isntype == ISN_COMPAREFLOAT)) |
707 { | 707 { |
708 semsg(_(e_cannot_use_str_with_str), | 708 semsg(_(e_cannot_use_str_with_str), |
709 exptype == EXPR_IS ? "is" : "isnot" , vartype_name(type1)); | 709 exprtype == EXPR_IS ? "is" : "isnot" , vartype_name(type1)); |
710 return ISN_DROP; | 710 return ISN_DROP; |
711 } | 711 } |
712 if (isntype == ISN_DROP | 712 if (isntype == ISN_DROP |
713 || ((exptype != EXPR_EQUAL && exptype != EXPR_NEQUAL | 713 || ((exprtype != EXPR_EQUAL && exprtype != EXPR_NEQUAL |
714 && (type1 == VAR_BOOL || type1 == VAR_SPECIAL | 714 && (type1 == VAR_BOOL || type1 == VAR_SPECIAL |
715 || type2 == VAR_BOOL || type2 == VAR_SPECIAL))) | 715 || type2 == VAR_BOOL || type2 == VAR_SPECIAL))) |
716 || ((exptype != EXPR_EQUAL && exptype != EXPR_NEQUAL | 716 || ((exprtype != EXPR_EQUAL && exprtype != EXPR_NEQUAL |
717 && exptype != EXPR_IS && exptype != EXPR_ISNOT | 717 && exprtype != EXPR_IS && exprtype != EXPR_ISNOT |
718 && (type1 == VAR_BLOB || type2 == VAR_BLOB | 718 && (type1 == VAR_BLOB || type2 == VAR_BLOB |
719 || type1 == VAR_LIST || type2 == VAR_LIST)))) | 719 || type1 == VAR_LIST || type2 == VAR_LIST)))) |
720 { | 720 { |
721 semsg(_(e_cannot_compare_str_with_str), | 721 semsg(_(e_cannot_compare_str_with_str), |
722 vartype_name(type1), vartype_name(type2)); | 722 vartype_name(type1), vartype_name(type2)); |
724 } | 724 } |
725 return isntype; | 725 return isntype; |
726 } | 726 } |
727 | 727 |
728 int | 728 int |
729 check_compare_types(exptype_T type, typval_T *tv1, typval_T *tv2) | 729 check_compare_types(exprtype_T type, typval_T *tv1, typval_T *tv2) |
730 { | 730 { |
731 if (get_compare_isn(type, tv1->v_type, tv2->v_type) == ISN_DROP) | 731 if (get_compare_isn(type, tv1->v_type, tv2->v_type) == ISN_DROP) |
732 return FAIL; | 732 return FAIL; |
733 return OK; | 733 return OK; |
734 } | 734 } |
735 | 735 |
736 /* | 736 /* |
737 * Generate an ISN_COMPARE* instruction with a boolean result. | 737 * Generate an ISN_COMPARE* instruction with a boolean result. |
738 */ | 738 */ |
739 static int | 739 static int |
740 generate_COMPARE(cctx_T *cctx, exptype_T exptype, int ic) | 740 generate_COMPARE(cctx_T *cctx, exprtype_T exprtype, int ic) |
741 { | 741 { |
742 isntype_T isntype; | 742 isntype_T isntype; |
743 isn_T *isn; | 743 isn_T *isn; |
744 garray_T *stack = &cctx->ctx_type_stack; | 744 garray_T *stack = &cctx->ctx_type_stack; |
745 vartype_T type1; | 745 vartype_T type1; |
750 // Get the known type of the two items on the stack. If they are matching | 750 // Get the known type of the two items on the stack. If they are matching |
751 // use a type-specific instruction. Otherwise fall back to runtime type | 751 // use a type-specific instruction. Otherwise fall back to runtime type |
752 // checking. | 752 // checking. |
753 type1 = ((type_T **)stack->ga_data)[stack->ga_len - 2]->tt_type; | 753 type1 = ((type_T **)stack->ga_data)[stack->ga_len - 2]->tt_type; |
754 type2 = ((type_T **)stack->ga_data)[stack->ga_len - 1]->tt_type; | 754 type2 = ((type_T **)stack->ga_data)[stack->ga_len - 1]->tt_type; |
755 isntype = get_compare_isn(exptype, type1, type2); | 755 isntype = get_compare_isn(exprtype, type1, type2); |
756 if (isntype == ISN_DROP) | 756 if (isntype == ISN_DROP) |
757 return FAIL; | 757 return FAIL; |
758 | 758 |
759 if ((isn = generate_instr(cctx, isntype)) == NULL) | 759 if ((isn = generate_instr(cctx, isntype)) == NULL) |
760 return FAIL; | 760 return FAIL; |
761 isn->isn_arg.op.op_type = exptype; | 761 isn->isn_arg.op.op_type = exprtype; |
762 isn->isn_arg.op.op_ic = ic; | 762 isn->isn_arg.op.op_ic = ic; |
763 | 763 |
764 // takes two arguments, puts one bool back | 764 // takes two arguments, puts one bool back |
765 if (stack->ga_len >= 2) | 765 if (stack->ga_len >= 2) |
766 { | 766 { |
3346 rettv->vval.v_number = VVAL_NONE; | 3346 rettv->vval.v_number = VVAL_NONE; |
3347 *arg += 6; | 3347 *arg += 6; |
3348 } | 3348 } |
3349 } | 3349 } |
3350 | 3350 |
3351 exptype_T | 3351 exprtype_T |
3352 get_compare_type(char_u *p, int *len, int *type_is) | 3352 get_compare_type(char_u *p, int *len, int *type_is) |
3353 { | 3353 { |
3354 exptype_T type = EXPR_UNKNOWN; | 3354 exprtype_T type = EXPR_UNKNOWN; |
3355 int i; | 3355 int i; |
3356 | 3356 |
3357 switch (p[0]) | 3357 switch (p[0]) |
3358 { | 3358 { |
3359 case '=': if (p[1] == '=') | 3359 case '=': if (p[1] == '=') |
4344 * COMPARE one of the compare instructions | 4344 * COMPARE one of the compare instructions |
4345 */ | 4345 */ |
4346 static int | 4346 static int |
4347 compile_expr4(char_u **arg, cctx_T *cctx, ppconst_T *ppconst) | 4347 compile_expr4(char_u **arg, cctx_T *cctx, ppconst_T *ppconst) |
4348 { | 4348 { |
4349 exptype_T type = EXPR_UNKNOWN; | 4349 exprtype_T type = EXPR_UNKNOWN; |
4350 char_u *p; | 4350 char_u *p; |
4351 char_u *next; | 4351 char_u *next; |
4352 int len = 2; | 4352 int len = 2; |
4353 int type_is = FALSE; | 4353 int type_is = FALSE; |
4354 int ppconst_used = ppconst->pp_used; | 4354 int ppconst_used = ppconst->pp_used; |