To: vim_dev@googlegroups.com Subject: Patch 9.0.1058 Fcc: outbox From: Bram Moolenaar Mime-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit ------------ Patch 9.0.1058 Problem: String value of class and object do not have useful information. Solution: Add the class name and for the object the member values. Files: src/eval.c, src/testdir/test_vim9_class.vim *** ../vim-9.0.1057/src/eval.c 2022-12-10 18:42:09.094378801 +0000 --- src/eval.c 2022-12-14 17:21:38.170624143 +0000 *************** *** 5604,5610 **** } case VAR_CLASS: ! // TODO: mark methods in class_obj_methods ? break; case VAR_OBJECT: --- 5604,5611 ---- } case VAR_CLASS: ! // TODO: Mark methods in class_obj_methods ? ! // Mark initializer expressions? break; case VAR_OBJECT: *************** *** 5863,5875 **** break; case VAR_CLASS: ! *tofree = NULL; ! r = (char_u *)"class"; break; case VAR_OBJECT: ! *tofree = NULL; ! r = (char_u *)"object"; break; case VAR_FLOAT: --- 5864,5905 ---- break; case VAR_CLASS: ! { ! class_T *cl = tv->vval.v_class; ! size_t len = 6 + (cl == NULL ? 9 : STRLEN(cl->class_name)) + 1; ! r = *tofree = alloc(len); ! vim_snprintf((char *)r, len, "class %s", ! cl == NULL ? "[unknown]" : (char *)cl->class_name); ! } break; case VAR_OBJECT: ! garray_T ga; ! ga_init2(&ga, 1, 50); ! ga_concat(&ga, (char_u *)"object of "); ! object_T *obj = tv->vval.v_object; ! class_T *cl = obj == NULL ? NULL : obj->obj_class; ! ga_concat(&ga, cl == NULL ? (char_u *)"[unknown]" : cl->class_name); ! if (cl != NULL) ! { ! ga_concat(&ga, (char_u *)" {"); ! for (int i = 0; i < cl->class_obj_member_count; ++i) ! { ! if (i > 0) ! ga_concat(&ga, (char_u *)", "); ! objmember_T *m = &cl->class_obj_members[i]; ! ga_concat(&ga, m->om_name); ! ga_concat(&ga, (char_u *)": "); ! char_u *tf = NULL; ! ga_concat(&ga, echo_string_core((typval_T *)(obj + 1) + i, ! &tf, numbuf, copyID, echo_style, ! restore_copyID, composite_val)); ! vim_free(tf); ! } ! ga_concat(&ga, (char_u *)"}"); ! } ! ! *tofree = r = ga.ga_data; break; case VAR_FLOAT: *** ../vim-9.0.1057/src/testdir/test_vim9_class.vim 2022-12-13 21:14:19.219930894 +0000 --- src/testdir/test_vim9_class.vim 2022-12-14 17:20:09.422603391 +0000 *************** *** 283,288 **** --- 283,303 ---- v9.CheckScriptFailure(lines, 'E1330:') enddef + def Test_class_object_to_string() + var lines =<< trim END + vim9script + class TextPosition + this.lnum = 1 + this.col = 22 + endclass + + assert_equal("class TextPosition", string(TextPosition)) + + var pos = TextPosition.new() + assert_equal("object of TextPosition {lnum: 1, col: 22}", string(pos)) + END + v9.CheckScriptSuccess(lines) + enddef " vim: ts=8 sw=2 sts=2 expandtab tw=80 fdm=marker *** ../vim-9.0.1057/src/version.c 2022-12-14 16:42:11.286755477 +0000 --- src/version.c 2022-12-14 17:13:47.054526492 +0000 *************** *** 697,698 **** --- 697,700 ---- { /* Add new patch number below this line */ + /**/ + 1058, /**/ -- FATHER: Make sure the Prince doesn't leave this room until I come and get him. FIRST GUARD: Not ... to leave the room ... even if you come and get him. FATHER: No. Until I come and get him. SECOND GUARD: Hic. "Monty Python and the Holy Grail" PYTHON (MONTY) PICTURES LTD /// Bram Moolenaar -- Bram@Moolenaar.net -- http://www.Moolenaar.net \\\ /// \\\ \\\ sponsor Vim, vote for features -- http://www.Vim.org/sponsor/ /// \\\ help me help AIDS victims -- http://ICCF-Holland.org ///