Mercurial > vim
comparison src/evalvars.c @ 20091:a64c16ff98b8 v8.2.0601
patch 8.2.0601: Vim9: :unlet is not compiled
Commit: https://github.com/vim/vim/commit/d72c1bf0a6784afdc8d8ceab4a007cd76d5b81e1
Author: Bram Moolenaar <Bram@vim.org>
Date: Sun Apr 19 16:28:59 2020 +0200
patch 8.2.0601: Vim9: :unlet is not compiled
Problem: Vim9: :unlet is not compiled.
Solution: Implement :unlet instruction and check for errors.
author | Bram Moolenaar <Bram@vim.org> |
---|---|
date | Sun, 19 Apr 2020 16:30:04 +0200 |
parents | 04ef2ccf2519 |
children | 646c53fa5781 |
comparison
equal
deleted
inserted
replaced
20090:b2225a10b777 | 20091:a64c16ff98b8 |
---|---|
170 static void list_buf_vars(int *first); | 170 static void list_buf_vars(int *first); |
171 static void list_win_vars(int *first); | 171 static void list_win_vars(int *first); |
172 static void list_tab_vars(int *first); | 172 static void list_tab_vars(int *first); |
173 static char_u *list_arg_vars(exarg_T *eap, char_u *arg, int *first); | 173 static char_u *list_arg_vars(exarg_T *eap, char_u *arg, int *first); |
174 static char_u *ex_let_one(char_u *arg, typval_T *tv, int copy, int flags, char_u *endchars, char_u *op); | 174 static char_u *ex_let_one(char_u *arg, typval_T *tv, int copy, int flags, char_u *endchars, char_u *op); |
175 static void ex_unletlock(exarg_T *eap, char_u *argstart, int deep); | 175 static int do_unlet_var(lval_T *lp, char_u *name_end, exarg_T *eap, int deep, void *cookie); |
176 static int do_unlet_var(lval_T *lp, char_u *name_end, int forceit); | 176 static int do_lock_var(lval_T *lp, char_u *name_end, exarg_T *eap, int deep, void *cookie); |
177 static int do_lock_var(lval_T *lp, char_u *name_end, int deep, int lock); | |
178 static void item_lock(typval_T *tv, int deep, int lock); | 177 static void item_lock(typval_T *tv, int deep, int lock); |
179 static void delete_var(hashtab_T *ht, hashitem_T *hi); | 178 static void delete_var(hashtab_T *ht, hashitem_T *hi); |
180 static void list_one_var(dictitem_T *v, char *prefix, int *first); | 179 static void list_one_var(dictitem_T *v, char *prefix, int *first); |
181 static void list_one_var_a(char *prefix, char_u *name, int type, char_u *string, int *first); | 180 static void list_one_var_a(char *prefix, char_u *name, int type, char_u *string, int *first); |
182 | 181 |
1370 * ":unlet[!] var1 ... " command. | 1369 * ":unlet[!] var1 ... " command. |
1371 */ | 1370 */ |
1372 void | 1371 void |
1373 ex_unlet(exarg_T *eap) | 1372 ex_unlet(exarg_T *eap) |
1374 { | 1373 { |
1375 ex_unletlock(eap, eap->arg, 0); | 1374 ex_unletlock(eap, eap->arg, 0, 0, do_unlet_var, NULL); |
1376 } | 1375 } |
1377 | 1376 |
1378 /* | 1377 /* |
1379 * ":lockvar" and ":unlockvar" commands | 1378 * ":lockvar" and ":unlockvar" commands |
1380 */ | 1379 */ |
1390 { | 1389 { |
1391 deep = getdigits(&arg); | 1390 deep = getdigits(&arg); |
1392 arg = skipwhite(arg); | 1391 arg = skipwhite(arg); |
1393 } | 1392 } |
1394 | 1393 |
1395 ex_unletlock(eap, arg, deep); | 1394 ex_unletlock(eap, arg, deep, 0, do_lock_var, NULL); |
1396 } | 1395 } |
1397 | 1396 |
1398 /* | 1397 /* |
1399 * ":unlet", ":lockvar" and ":unlockvar" are quite similar. | 1398 * ":unlet", ":lockvar" and ":unlockvar" are quite similar. |
1400 */ | 1399 * Also used for Vim9 script. "callback" is invoked as: |
1401 static void | 1400 * callback(&lv, name_end, eap, deep, cookie) |
1401 */ | |
1402 void | |
1402 ex_unletlock( | 1403 ex_unletlock( |
1403 exarg_T *eap, | 1404 exarg_T *eap, |
1404 char_u *argstart, | 1405 char_u *argstart, |
1405 int deep) | 1406 int deep, |
1407 int glv_flags, | |
1408 int (*callback)(lval_T *, char_u *, exarg_T *, int, void *), | |
1409 void *cookie) | |
1406 { | 1410 { |
1407 char_u *arg = argstart; | 1411 char_u *arg = argstart; |
1408 char_u *name_end; | 1412 char_u *name_end; |
1409 int error = FALSE; | 1413 int error = FALSE; |
1410 lval_T lv; | 1414 lval_T lv; |
1424 arg = skipwhite(arg); | 1428 arg = skipwhite(arg); |
1425 continue; | 1429 continue; |
1426 } | 1430 } |
1427 | 1431 |
1428 // Parse the name and find the end. | 1432 // Parse the name and find the end. |
1429 name_end = get_lval(arg, NULL, &lv, TRUE, eap->skip || error, 0, | 1433 name_end = get_lval(arg, NULL, &lv, TRUE, eap->skip || error, |
1430 FNE_CHECK_START); | 1434 glv_flags, FNE_CHECK_START); |
1431 if (lv.ll_name == NULL) | 1435 if (lv.ll_name == NULL) |
1432 error = TRUE; // error but continue parsing | 1436 error = TRUE; // error but continue parsing |
1433 if (name_end == NULL || (!VIM_ISWHITE(*name_end) | 1437 if (name_end == NULL || (!VIM_ISWHITE(*name_end) |
1434 && !ends_excmd(*name_end))) | 1438 && !ends_excmd(*name_end))) |
1435 { | 1439 { |
1441 if (!(eap->skip || error)) | 1445 if (!(eap->skip || error)) |
1442 clear_lval(&lv); | 1446 clear_lval(&lv); |
1443 break; | 1447 break; |
1444 } | 1448 } |
1445 | 1449 |
1446 if (!error && !eap->skip) | 1450 if (!error && !eap->skip |
1447 { | 1451 && callback(&lv, name_end, eap, deep, cookie) == FAIL) |
1448 if (eap->cmdidx == CMD_unlet) | 1452 error = TRUE; |
1449 { | |
1450 if (do_unlet_var(&lv, name_end, eap->forceit) == FAIL) | |
1451 error = TRUE; | |
1452 } | |
1453 else | |
1454 { | |
1455 if (do_lock_var(&lv, name_end, deep, | |
1456 eap->cmdidx == CMD_lockvar) == FAIL) | |
1457 error = TRUE; | |
1458 } | |
1459 } | |
1460 | 1453 |
1461 if (!eap->skip) | 1454 if (!eap->skip) |
1462 clear_lval(&lv); | 1455 clear_lval(&lv); |
1463 | 1456 |
1464 arg = skipwhite(name_end); | 1457 arg = skipwhite(name_end); |
1465 } while (!ends_excmd(*arg)); | 1458 } while (!ends_excmd2(name_end, arg)); |
1466 | 1459 |
1467 eap->nextcmd = check_nextcmd(arg); | 1460 eap->nextcmd = check_nextcmd(arg); |
1468 } | 1461 } |
1469 | 1462 |
1470 static int | 1463 static int |
1471 do_unlet_var( | 1464 do_unlet_var( |
1472 lval_T *lp, | 1465 lval_T *lp, |
1473 char_u *name_end, | 1466 char_u *name_end, |
1474 int forceit) | 1467 exarg_T *eap, |
1475 { | 1468 int deep UNUSED, |
1469 void *cookie UNUSED) | |
1470 { | |
1471 int forceit = eap->forceit; | |
1476 int ret = OK; | 1472 int ret = OK; |
1477 int cc; | 1473 int cc; |
1478 | 1474 |
1479 if (lp->ll_tv == NULL) | 1475 if (lp->ll_tv == NULL) |
1480 { | 1476 { |
1538 hashtab_T *ht; | 1534 hashtab_T *ht; |
1539 hashitem_T *hi; | 1535 hashitem_T *hi; |
1540 char_u *varname; | 1536 char_u *varname; |
1541 dict_T *d; | 1537 dict_T *d; |
1542 dictitem_T *di; | 1538 dictitem_T *di; |
1539 | |
1540 if (current_sctx.sc_version == SCRIPT_VERSION_VIM9 | |
1541 && check_vim9_unlet(name) == FAIL) | |
1542 return FAIL; | |
1543 | 1543 |
1544 ht = find_var_ht(name, &varname); | 1544 ht = find_var_ht(name, &varname); |
1545 if (ht != NULL && *varname != NUL) | 1545 if (ht != NULL && *varname != NUL) |
1546 { | 1546 { |
1547 d = get_current_funccal_dict(ht); | 1547 d = get_current_funccal_dict(ht); |
1590 */ | 1590 */ |
1591 static int | 1591 static int |
1592 do_lock_var( | 1592 do_lock_var( |
1593 lval_T *lp, | 1593 lval_T *lp, |
1594 char_u *name_end, | 1594 char_u *name_end, |
1595 exarg_T *eap, | |
1595 int deep, | 1596 int deep, |
1596 int lock) | 1597 void *cookie UNUSED) |
1597 { | 1598 { |
1599 int lock = eap->cmdidx == CMD_lockvar; | |
1598 int ret = OK; | 1600 int ret = OK; |
1599 int cc; | 1601 int cc; |
1600 dictitem_T *di; | 1602 dictitem_T *di; |
1601 | 1603 |
1602 if (deep == 0) // nothing to do | 1604 if (deep == 0) // nothing to do |