comparison src/vim9compile.c @ 24262:d0e86f1b34e7 v8.2.2672

patch 8.2.2672: Vim9: cannot use :lockvar and :unlockvar in compiled script Commit: https://github.com/vim/vim/commit/b2cb6c8bbd215177ed05c1d952e7ef2ad8f7ef4b Author: Bram Moolenaar <Bram@vim.org> Date: Sun Mar 28 20:38:34 2021 +0200 patch 8.2.2672: Vim9: cannot use :lockvar and :unlockvar in compiled script Problem: Vim9: cannot use :lockvar and :unlockvar in compiled script. Solution: Implement locking support.
author Bram Moolenaar <Bram@vim.org>
date Sun, 28 Mar 2021 20:45:06 +0200
parents 7ffc795288dd
children cabed216cc2f
comparison
equal deleted inserted replaced
24261:f5ada7905e93 24262:d0e86f1b34e7
6706 *name_end = cc; 6706 *name_end = cc;
6707 return ret; 6707 return ret;
6708 } 6708 }
6709 6709
6710 /* 6710 /*
6711 * Callback passed to ex_unletlock().
6712 */
6713 static int
6714 compile_lock_unlock(
6715 lval_T *lvp,
6716 char_u *name_end,
6717 exarg_T *eap,
6718 int deep UNUSED,
6719 void *coookie)
6720 {
6721 cctx_T *cctx = coookie;
6722 int cc = *name_end;
6723 char_u *p = lvp->ll_name;
6724 int ret = OK;
6725 size_t len;
6726 char_u *buf;
6727
6728 if (cctx->ctx_skip == SKIP_YES)
6729 return OK;
6730
6731 // Cannot use :lockvar and :unlockvar on local variables.
6732 if (p[1] != ':')
6733 {
6734 char_u *end = skip_var_one(p, FALSE);
6735
6736 if (lookup_local(p, end - p, NULL, cctx) == OK)
6737 {
6738 emsg(_(e_cannot_lock_unlock_local_variable));
6739 return FAIL;
6740 }
6741 }
6742
6743 // Checking is done at runtime.
6744 *name_end = NUL;
6745 len = name_end - p + 20;
6746 buf = alloc(len);
6747 if (buf == NULL)
6748 ret = FAIL;
6749 else
6750 {
6751 vim_snprintf((char *)buf, len, "%s %s",
6752 eap->cmdidx == CMD_lockvar ? "lockvar" : "unlockvar",
6753 p);
6754 ret = generate_EXEC(cctx, buf);
6755
6756 vim_free(buf);
6757 *name_end = cc;
6758 }
6759 return ret;
6760 }
6761
6762 /*
6711 * compile "unlet var", "lock var" and "unlock var" 6763 * compile "unlet var", "lock var" and "unlock var"
6712 * "arg" points to "var". 6764 * "arg" points to "var".
6713 */ 6765 */
6714 static char_u * 6766 static char_u *
6715 compile_unletlock(char_u *arg, exarg_T *eap, cctx_T *cctx) 6767 compile_unletlock(char_u *arg, exarg_T *eap, cctx_T *cctx)
6716 { 6768 {
6717 char_u *p = arg; 6769 ex_unletlock(eap, arg, 0, GLV_NO_AUTOLOAD | GLV_COMPILING,
6718 6770 eap->cmdidx == CMD_unlet ? compile_unlet : compile_lock_unlock,
6719 if (eap->cmdidx != CMD_unlet) 6771 cctx);
6720 {
6721 emsg("Sorry, :lock and unlock not implemented yet");
6722 return NULL;
6723 }
6724
6725 ex_unletlock(eap, p, 0, GLV_NO_AUTOLOAD | GLV_COMPILING,
6726 compile_unlet, cctx);
6727 return eap->nextcmd == NULL ? (char_u *)"" : eap->nextcmd; 6772 return eap->nextcmd == NULL ? (char_u *)"" : eap->nextcmd;
6728 } 6773 }
6729 6774
6730 /* 6775 /*
6731 * Compile an :import command. 6776 * Compile an :import command.