comparison src/eval.c @ 31455:5ef28f5ff357 v9.0.1060

patch 9.0.1060: private and public object members are not implemented yet Commit: https://github.com/vim/vim/commit/3d473ee1a6aed7cb9eae458bbd8d42dffdc754f9 Author: Bram Moolenaar <Bram@vim.org> Date: Wed Dec 14 20:59:32 2022 +0000 patch 9.0.1060: private and public object members are not implemented yet problem: Private and public object members are not implemented yet. Solution: Implement private and public object members.
author Bram Moolenaar <Bram@vim.org>
date Wed, 14 Dec 2022 22:00:04 +0100
parents 06a1c71c58ad
children 1bebc2093e6b
comparison
equal deleted inserted replaced
31454:d03a62e7fe0e 31455:5ef28f5ff357
1192 var1.v_type = VAR_UNKNOWN; 1192 var1.v_type = VAR_UNKNOWN;
1193 var2.v_type = VAR_UNKNOWN; 1193 var2.v_type = VAR_UNKNOWN;
1194 while (*p == '[' || (*p == '.' && p[1] != '=' && p[1] != '.')) 1194 while (*p == '[' || (*p == '.' && p[1] != '=' && p[1] != '.'))
1195 { 1195 {
1196 if (*p == '.' && lp->ll_tv->v_type != VAR_DICT 1196 if (*p == '.' && lp->ll_tv->v_type != VAR_DICT
1197 && lp->ll_tv->v_type != VAR_OBJECT
1197 && lp->ll_tv->v_type != VAR_CLASS) 1198 && lp->ll_tv->v_type != VAR_CLASS)
1198 { 1199 {
1199 if (!quiet) 1200 if (!quiet)
1200 semsg(_(e_dot_can_only_be_used_on_dictionary_str), name); 1201 semsg(_(e_dot_can_only_be_used_on_dictionary_str), name);
1201 return NULL; 1202 return NULL;
1202 } 1203 }
1203 if (lp->ll_tv->v_type != VAR_LIST 1204 if (lp->ll_tv->v_type != VAR_LIST
1204 && lp->ll_tv->v_type != VAR_DICT 1205 && lp->ll_tv->v_type != VAR_DICT
1205 && lp->ll_tv->v_type != VAR_BLOB 1206 && lp->ll_tv->v_type != VAR_BLOB
1207 && lp->ll_tv->v_type != VAR_OBJECT
1206 && lp->ll_tv->v_type != VAR_CLASS) 1208 && lp->ll_tv->v_type != VAR_CLASS)
1207 { 1209 {
1208 if (!quiet) 1210 if (!quiet)
1209 emsg(_(e_can_only_index_list_dictionary_or_blob)); 1211 emsg(_(e_can_only_index_list_dictionary_or_blob));
1210 return NULL; 1212 return NULL;
1507 return NULL; 1509 return NULL;
1508 } 1510 }
1509 1511
1510 lp->ll_tv = &lp->ll_li->li_tv; 1512 lp->ll_tv = &lp->ll_li->li_tv;
1511 } 1513 }
1512 else // v_type == VAR_CLASS 1514 else // v_type == VAR_CLASS || v_type == VAR_OBJECT
1513 { 1515 {
1514 // TODO: check object members and methods if 1516 class_T *cl = (lp->ll_tv->v_type == VAR_OBJECT
1515 // "key" points name start, "p" to the end 1517 && lp->ll_tv->vval.v_object != NULL)
1518 ? lp->ll_tv->vval.v_object->obj_class
1519 : lp->ll_tv->vval.v_class;
1520 // TODO: what if class is NULL?
1521 if (cl != NULL)
1522 {
1523 lp->ll_valtype = NULL;
1524 for (int i = 0; i < cl->class_obj_member_count; ++i)
1525 {
1526 objmember_T *om = cl->class_obj_members + i;
1527 if (STRNCMP(om->om_name, key, p - key) == 0
1528 && om->om_name[p - key] == NUL)
1529 {
1530 switch (om->om_access)
1531 {
1532 case ACCESS_PRIVATE:
1533 semsg(_(e_cannot_access_private_object_member_str),
1534 om->om_name);
1535 return NULL;
1536 case ACCESS_READ:
1537 if (!(flags & GLV_READ_ONLY))
1538 {
1539 semsg(_(e_object_member_is_not_writable_str),
1540 om->om_name);
1541 return NULL;
1542 }
1543 break;
1544 case ACCESS_ALL:
1545 break;
1546 }
1547
1548 lp->ll_valtype = om->om_type;
1549
1550 if (lp->ll_tv->v_type == VAR_OBJECT)
1551 lp->ll_tv = ((typval_T *)(
1552 lp->ll_tv->vval.v_object + 1)) + i;
1553 // TODO: what about a class?
1554 break;
1555 }
1556 }
1557 if (lp->ll_valtype == NULL)
1558 {
1559 semsg(_(e_object_member_not_found_str), key);
1560 return NULL;
1561 }
1562 }
1516 } 1563 }
1517 } 1564 }
1518 1565
1519 clear_tv(&var1); 1566 clear_tv(&var1);
1520 lp->ll_name_end = p; 1567 lp->ll_name_end = p;
1638 lp->ll_n1, lp->ll_n2, lp->ll_empty2, op, lp->ll_name); 1685 lp->ll_n1, lp->ll_n2, lp->ll_empty2, op, lp->ll_name);
1639 } 1686 }
1640 else 1687 else
1641 { 1688 {
1642 /* 1689 /*
1643 * Assign to a List or Dictionary item. 1690 * Assign to a List, Dictionary or Object item.
1644 */ 1691 */
1645 if ((flags & (ASSIGN_CONST | ASSIGN_FINAL)) 1692 if ((flags & (ASSIGN_CONST | ASSIGN_FINAL))
1646 && (flags & ASSIGN_FOR_LOOP) == 0) 1693 && (flags & ASSIGN_FOR_LOOP) == 0)
1647 { 1694 {
1648 emsg(_(e_cannot_lock_list_or_dict)); 1695 emsg(_(e_cannot_lock_list_or_dict));