Mercurial > vim
comparison src/vim9compile.c @ 34676:5b25ec43f208 v9.1.0219
patch 9.1.0219: Vim9: No enum support
Commit: https://github.com/vim/vim/commit/3164cf8f12f14b725b918e3170bb0a9085af8298
Author: Yegappan Lakshmanan <yegappan@yahoo.com>
Date: Thu Mar 28 10:36:42 2024 +0100
patch 9.1.0219: Vim9: No enum support
Problem: No enum support
Solution: Implement enums for Vim9 script
(Yegappan Lakshmanan)
closes: #14224
Signed-off-by: Yegappan Lakshmanan <yegappan@yahoo.com>
Signed-off-by: Christian Brabandt <cb@256bit.org>
author | Christian Brabandt <cb@256bit.org> |
---|---|
date | Thu, 28 Mar 2024 10:45:06 +0100 |
parents | 7ff3c277377f |
children | 529709e74c11 |
comparison
equal
deleted
inserted
replaced
34675:42bca55140ec | 34676:5b25ec43f208 |
---|---|
1612 { | 1612 { |
1613 member_not_found_msg(cl, lhs->lhs_type->tt_type, name, namelen); | 1613 member_not_found_msg(cl, lhs->lhs_type->tt_type, name, namelen); |
1614 return FALSE; | 1614 return FALSE; |
1615 } | 1615 } |
1616 | 1616 |
1617 if (IS_ENUM(cl)) | |
1618 { | |
1619 semsg(_(e_enumvalue_str_cannot_be_modified), cl->class_name, | |
1620 m->ocm_name); | |
1621 return FALSE; | |
1622 } | |
1623 | |
1617 // If it is private member variable, then accessing it outside the | 1624 // If it is private member variable, then accessing it outside the |
1618 // class is not allowed. | 1625 // class is not allowed. |
1619 // If it is a read only class variable, then it can be modified | 1626 // If it is a read only class variable, then it can be modified |
1620 // only inside the class where it is defined. | 1627 // only inside the class where it is defined. |
1621 if ((m->ocm_access != VIM_ACCESS_ALL) && | 1628 if ((m->ocm_access != VIM_ACCESS_ALL) && |
2035 { | 2042 { |
2036 member_not_found_msg(cl, lhs->lhs_type->tt_type, name, namelen); | 2043 member_not_found_msg(cl, lhs->lhs_type->tt_type, name, namelen); |
2037 return FAIL; | 2044 return FAIL; |
2038 } | 2045 } |
2039 | 2046 |
2047 if (IS_ENUM(cl)) | |
2048 { | |
2049 if (!inside_class(cctx, cl)) | |
2050 { | |
2051 semsg(_(e_enumvalue_str_cannot_be_modified), | |
2052 cl->class_name, m->ocm_name); | |
2053 return FALSE; | |
2054 } | |
2055 if (lhs->lhs_type->tt_type == VAR_OBJECT && | |
2056 lhs->lhs_member_idx < 2) | |
2057 { | |
2058 char *msg = lhs->lhs_member_idx == 0 ? | |
2059 e_enum_str_name_cannot_be_modified : | |
2060 e_enum_str_ordinal_cannot_be_modified; | |
2061 semsg(_(msg), cl->class_name); | |
2062 return FALSE; | |
2063 } | |
2064 } | |
2065 | |
2040 // If it is private member variable, then accessing it outside the | 2066 // If it is private member variable, then accessing it outside the |
2041 // class is not allowed. | 2067 // class is not allowed. |
2042 // If it is a read only class variable, then it can be modified | 2068 // If it is a read only class variable, then it can be modified |
2043 // only inside the class where it is defined. | 2069 // only inside the class where it is defined. |
2044 if ((m->ocm_access != VIM_ACCESS_ALL) && | 2070 if ((m->ocm_access != VIM_ACCESS_ALL) && |
2302 { | 2328 { |
2303 // load object variable or argument | 2329 // load object variable or argument |
2304 if (compile_load_lhs(lhs, var_start, lhs->lhs_type, cctx) == FAIL) | 2330 if (compile_load_lhs(lhs, var_start, lhs->lhs_type, cctx) == FAIL) |
2305 return FAIL; | 2331 return FAIL; |
2306 } | 2332 } |
2307 if (cl->class_flags & CLASS_INTERFACE) | 2333 if (IS_INTERFACE(cl)) |
2308 return generate_GET_ITF_MEMBER(cctx, cl, lhs->lhs_member_idx, type); | 2334 return generate_GET_ITF_MEMBER(cctx, cl, lhs->lhs_member_idx, type); |
2309 return generate_GET_OBJ_MEMBER(cctx, lhs->lhs_member_idx, type); | 2335 return generate_GET_OBJ_MEMBER(cctx, lhs->lhs_member_idx, type); |
2310 } | 2336 } |
2311 else if (lhs->lhs_type->tt_type == VAR_CLASS) | 2337 else if (lhs->lhs_type->tt_type == VAR_CLASS) |
2312 { | 2338 { |
2451 | 2477 |
2452 if (dest_type == VAR_OBJECT) | 2478 if (dest_type == VAR_OBJECT) |
2453 { | 2479 { |
2454 class_T *cl = lhs->lhs_type->tt_class; | 2480 class_T *cl = lhs->lhs_type->tt_class; |
2455 | 2481 |
2456 if (cl->class_flags & CLASS_INTERFACE) | 2482 if (IS_INTERFACE(cl)) |
2457 { | 2483 { |
2458 // "this.value": load "this" object and get the value | 2484 // "this.value": load "this" object and get the value |
2459 // at index for an object or class member get the type | 2485 // at index for an object or class member get the type |
2460 // of the member | 2486 // of the member |
2461 isn->isn_arg.storeindex.si_class = cl; | 2487 isn->isn_arg.storeindex.si_class = cl; |
3373 generate_CONSTRUCT(&cctx, ufunc->uf_class); | 3399 generate_CONSTRUCT(&cctx, ufunc->uf_class); |
3374 | 3400 |
3375 for (int i = 0; i < ufunc->uf_class->class_obj_member_count; ++i) | 3401 for (int i = 0; i < ufunc->uf_class->class_obj_member_count; ++i) |
3376 { | 3402 { |
3377 ocmember_T *m = &ufunc->uf_class->class_obj_members[i]; | 3403 ocmember_T *m = &ufunc->uf_class->class_obj_members[i]; |
3404 | |
3405 if (i < 2 && IS_ENUM(ufunc->uf_class)) | |
3406 // The first two object variables in an enum are the name | |
3407 // and the ordinal. These are set by the ISN_CONSTRUCT | |
3408 // instruction. So don't generate instructions to set | |
3409 // these variables. | |
3410 continue; | |
3411 | |
3378 if (m->ocm_init != NULL) | 3412 if (m->ocm_init != NULL) |
3379 { | 3413 { |
3380 char_u *expr = m->ocm_init; | 3414 char_u *expr = m->ocm_init; |
3381 if (compile_expr0(&expr, &cctx) == FAIL) | 3415 if (compile_expr0(&expr, &cctx) == FAIL) |
3382 goto erret; | 3416 goto erret; |
3479 } | 3513 } |
3480 ufunc->uf_args_visible = ufunc->uf_args.ga_len; | 3514 ufunc->uf_args_visible = ufunc->uf_args.ga_len; |
3481 | 3515 |
3482 // Compiling a function in an interface is done to get the function type. | 3516 // Compiling a function in an interface is done to get the function type. |
3483 // No code is actually compiled. | 3517 // No code is actually compiled. |
3484 if (ufunc->uf_class != NULL | 3518 if (ufunc->uf_class != NULL && IS_INTERFACE(ufunc->uf_class)) |
3485 && (ufunc->uf_class->class_flags & CLASS_INTERFACE)) | |
3486 { | 3519 { |
3487 ufunc->uf_def_status = UF_NOT_COMPILED; | 3520 ufunc->uf_def_status = UF_NOT_COMPILED; |
3488 ret = OK; | 3521 ret = OK; |
3489 goto erret; | 3522 goto erret; |
3490 } | 3523 } |