summaryrefslogtreecommitdiffstats
path: root/src/eval.c
diff options
context:
space:
mode:
authorBram Moolenaar <Bram@vim.org>2022-12-14 20:59:32 +0000
committerBram Moolenaar <Bram@vim.org>2022-12-14 20:59:32 +0000
commit3d473ee1a6aed7cb9eae458bbd8d42dffdc754f9 (patch)
tree787ae08f91baa1ef09a13c88adf209b7486e892b /src/eval.c
parentf94178db8d7324099b1bf916a0dff022c08abdff (diff)
patch 9.0.1060: private and public object members are not implemented yetv9.0.1060
problem: Private and public object members are not implemented yet. Solution: Implement private and public object members.
Diffstat (limited to 'src/eval.c')
-rw-r--r--src/eval.c55
1 files changed, 51 insertions, 4 deletions
diff --git a/src/eval.c b/src/eval.c
index 286e5af273..5baaa99062 100644
--- a/src/eval.c
+++ b/src/eval.c
@@ -1194,6 +1194,7 @@ get_lval(
while (*p == '[' || (*p == '.' && p[1] != '=' && p[1] != '.'))
{
if (*p == '.' && lp->ll_tv->v_type != VAR_DICT
+ && lp->ll_tv->v_type != VAR_OBJECT
&& lp->ll_tv->v_type != VAR_CLASS)
{
if (!quiet)
@@ -1203,6 +1204,7 @@ get_lval(
if (lp->ll_tv->v_type != VAR_LIST
&& lp->ll_tv->v_type != VAR_DICT
&& lp->ll_tv->v_type != VAR_BLOB
+ && lp->ll_tv->v_type != VAR_OBJECT
&& lp->ll_tv->v_type != VAR_CLASS)
{
if (!quiet)
@@ -1509,10 +1511,55 @@ get_lval(
lp->ll_tv = &lp->ll_li->li_tv;
}
- else // v_type == VAR_CLASS
+ else // v_type == VAR_CLASS || v_type == VAR_OBJECT
{
- // TODO: check object members and methods if
- // "key" points name start, "p" to the end
+ class_T *cl = (lp->ll_tv->v_type == VAR_OBJECT
+ && lp->ll_tv->vval.v_object != NULL)
+ ? lp->ll_tv->vval.v_object->obj_class
+ : lp->ll_tv->vval.v_class;
+ // TODO: what if class is NULL?
+ if (cl != NULL)
+ {
+ lp->ll_valtype = NULL;
+ for (int i = 0; i < cl->class_obj_member_count; ++i)
+ {
+ objmember_T *om = cl->class_obj_members + i;
+ if (STRNCMP(om->om_name, key, p - key) == 0
+ && om->om_name[p - key] == NUL)
+ {
+ switch (om->om_access)
+ {
+ case ACCESS_PRIVATE:
+ semsg(_(e_cannot_access_private_object_member_str),
+ om->om_name);
+ return NULL;
+ case ACCESS_READ:
+ if (!(flags & GLV_READ_ONLY))
+ {
+ semsg(_(e_object_member_is_not_writable_str),
+ om->om_name);
+ return NULL;
+ }
+ break;
+ case ACCESS_ALL:
+ break;
+ }
+
+ lp->ll_valtype = om->om_type;
+
+ if (lp->ll_tv->v_type == VAR_OBJECT)
+ lp->ll_tv = ((typval_T *)(
+ lp->ll_tv->vval.v_object + 1)) + i;
+ // TODO: what about a class?
+ break;
+ }
+ }
+ if (lp->ll_valtype == NULL)
+ {
+ semsg(_(e_object_member_not_found_str), key);
+ return NULL;
+ }
+ }
}
}
@@ -1640,7 +1687,7 @@ set_var_lval(
else
{
/*
- * Assign to a List or Dictionary item.
+ * Assign to a List, Dictionary or Object item.
*/
if ((flags & (ASSIGN_CONST | ASSIGN_FINAL))
&& (flags & ASSIGN_FOR_LOOP) == 0)