Mercurial > vim
comparison src/eval.c @ 33233:108d890d887f v9.0.1890
patch 9.0.1890: Vim9: lookup code for class/object repaeated
Commit: https://github.com/vim/vim/commit/f36bbcd402c6ee5a27bcab3b20b6362ab93b8898
Author: Yegappan Lakshmanan <yegappan@yahoo.com>
Date: Sun Sep 10 18:19:06 2023 +0200
patch 9.0.1890: Vim9: lookup code for class/object repaeated
Problem: Vim9: lookup code for class/object repaeated
Solution: Refactor and make use of lookup functions
closes: #13067
Signed-off-by: Christian Brabandt <cb@256bit.org>
Co-authored-by: Yegappan Lakshmanan <yegappan@yahoo.com>
author | Christian Brabandt <cb@256bit.org> |
---|---|
date | Sun, 10 Sep 2023 18:30:04 +0200 |
parents | 1e649fd371cd |
children | aba1fa2b7d1e |
comparison
equal
deleted
inserted
replaced
33232:d72f150af9f1 | 33233:108d890d887f |
---|---|
1538 { | 1538 { |
1539 // First look for a function with this name. | 1539 // First look for a function with this name. |
1540 // round 1: class functions (skipped for an object) | 1540 // round 1: class functions (skipped for an object) |
1541 // round 2: object methods | 1541 // round 2: object methods |
1542 for (int round = v_type == VAR_OBJECT ? 2 : 1; | 1542 for (int round = v_type == VAR_OBJECT ? 2 : 1; |
1543 round <= 2; ++round) | 1543 round <= 2; ++round) |
1544 { | 1544 { |
1545 int count = round == 1 | 1545 int m_idx; |
1546 ? cl->class_class_function_count | 1546 ufunc_T *fp; |
1547 : cl->class_obj_method_count; | 1547 |
1548 ufunc_T **funcs = round == 1 | 1548 fp = method_lookup(cl, |
1549 ? cl->class_class_functions | 1549 round == 1 ? VAR_CLASS : VAR_OBJECT, |
1550 : cl->class_obj_methods; | 1550 key, p - key, &m_idx); |
1551 for (int i = 0; i < count; ++i) | 1551 if (fp != NULL) |
1552 { | 1552 { |
1553 ufunc_T *fp = funcs[i]; | 1553 lp->ll_ufunc = fp; |
1554 char_u *ufname = (char_u *)fp->uf_name; | 1554 lp->ll_valtype = fp->uf_func_type; |
1555 if (STRNCMP(ufname, key, p - key) == 0 | 1555 break; |
1556 && ufname[p - key] == NUL) | |
1557 { | |
1558 lp->ll_ufunc = fp; | |
1559 lp->ll_valtype = fp->uf_func_type; | |
1560 round = 3; | |
1561 break; | |
1562 } | |
1563 } | 1556 } |
1564 } | 1557 } |
1565 } | 1558 } |
1566 | 1559 |
1567 if (lp->ll_valtype == NULL) | 1560 if (lp->ll_valtype == NULL) |
1568 { | 1561 { |
1569 int count = v_type == VAR_OBJECT | 1562 int m_idx; |
1570 ? cl->class_obj_member_count | 1563 ocmember_T *om; |
1571 : cl->class_class_member_count; | 1564 |
1572 ocmember_T *members = v_type == VAR_OBJECT | 1565 om = member_lookup(cl, v_type, key, p - key, &m_idx); |
1573 ? cl->class_obj_members | 1566 if (om != NULL) |
1574 : cl->class_class_members; | |
1575 for (int i = 0; i < count; ++i) | |
1576 { | 1567 { |
1577 ocmember_T *om = members + i; | 1568 switch (om->ocm_access) |
1578 if (STRNCMP(om->ocm_name, key, p - key) == 0 | |
1579 && om->ocm_name[p - key] == NUL) | |
1580 { | 1569 { |
1581 switch (om->ocm_access) | 1570 case VIM_ACCESS_PRIVATE: |
1582 { | 1571 semsg(_(e_cannot_access_private_member_str), |
1583 case VIM_ACCESS_PRIVATE: | 1572 om->ocm_name); |
1584 semsg(_(e_cannot_access_private_member_str), | 1573 return NULL; |
1585 om->ocm_name); | 1574 case VIM_ACCESS_READ: |
1586 return NULL; | 1575 if ((flags & GLV_READ_ONLY) == 0) |
1587 case VIM_ACCESS_READ: | 1576 { |
1588 if ((flags & GLV_READ_ONLY) == 0) | 1577 semsg(_(e_member_is_not_writable_str), |
1589 { | 1578 om->ocm_name); |
1590 semsg(_(e_member_is_not_writable_str), | 1579 return NULL; |
1591 om->ocm_name); | 1580 } |
1592 return NULL; | 1581 break; |
1593 } | 1582 case VIM_ACCESS_ALL: |
1594 break; | 1583 break; |
1595 case VIM_ACCESS_ALL: | |
1596 break; | |
1597 } | |
1598 | |
1599 lp->ll_valtype = om->ocm_type; | |
1600 | |
1601 if (v_type == VAR_OBJECT) | |
1602 lp->ll_tv = ((typval_T *)( | |
1603 lp->ll_tv->vval.v_object + 1)) + i; | |
1604 else | |
1605 lp->ll_tv = &cl->class_members_tv[i]; | |
1606 break; | |
1607 } | 1584 } |
1585 | |
1586 lp->ll_valtype = om->ocm_type; | |
1587 | |
1588 if (v_type == VAR_OBJECT) | |
1589 lp->ll_tv = ((typval_T *)( | |
1590 lp->ll_tv->vval.v_object + 1)) + m_idx; | |
1591 else | |
1592 lp->ll_tv = &cl->class_members_tv[m_idx]; | |
1593 break; | |
1608 } | 1594 } |
1609 } | 1595 } |
1610 | 1596 |
1611 if (lp->ll_valtype == NULL) | 1597 if (lp->ll_valtype == NULL) |
1612 { | 1598 { |