comparison src/eval.c @ 12477:68d7bc045dbe v8.0.1118

patch 8.0.1118: FEAT_WINDOWS adds a lot of #ifdefs commit https://github.com/vim/vim/commit/4033c55eca575777718c0701e26635a0cc47d907 Author: Bram Moolenaar <Bram@vim.org> Date: Sat Sep 16 20:54:51 2017 +0200 patch 8.0.1118: FEAT_WINDOWS adds a lot of #ifdefs Problem: FEAT_WINDOWS adds a lot of #ifdefs while it is nearly always enabled and only adds 7% to the binary size of the tiny build. Solution: Graduate FEAT_WINDOWS.
author Christian Brabandt <cb@256bit.org>
date Sat, 16 Sep 2017 21:00:06 +0200
parents c952a6af25e0
children 3f16cf18386c
comparison
equal deleted inserted replaced
12476:2516383741e6 12477:68d7bc045dbe
209 static char_u *skip_var_list(char_u *arg, int *var_count, int *semicolon); 209 static char_u *skip_var_list(char_u *arg, int *var_count, int *semicolon);
210 static char_u *skip_var_one(char_u *arg); 210 static char_u *skip_var_one(char_u *arg);
211 static void list_glob_vars(int *first); 211 static void list_glob_vars(int *first);
212 static void list_buf_vars(int *first); 212 static void list_buf_vars(int *first);
213 static void list_win_vars(int *first); 213 static void list_win_vars(int *first);
214 #ifdef FEAT_WINDOWS
215 static void list_tab_vars(int *first); 214 static void list_tab_vars(int *first);
216 #endif
217 static void list_vim_vars(int *first); 215 static void list_vim_vars(int *first);
218 static void list_script_vars(int *first); 216 static void list_script_vars(int *first);
219 static char_u *list_arg_vars(exarg_T *eap, char_u *arg, int *first); 217 static char_u *list_arg_vars(exarg_T *eap, char_u *arg, int *first);
220 static char_u *ex_let_one(char_u *arg, typval_T *tv, int copy, char_u *endchars, char_u *op); 218 static char_u *ex_let_one(char_u *arg, typval_T *tv, int copy, char_u *endchars, char_u *op);
221 static void set_var_lval(lval_T *lp, char_u *endp, typval_T *rettv, int copy, char_u *op); 219 static void set_var_lval(lval_T *lp, char_u *endp, typval_T *rettv, int copy, char_u *op);
1203 { 1201 {
1204 /* ":let" */ 1202 /* ":let" */
1205 list_glob_vars(&first); 1203 list_glob_vars(&first);
1206 list_buf_vars(&first); 1204 list_buf_vars(&first);
1207 list_win_vars(&first); 1205 list_win_vars(&first);
1208 #ifdef FEAT_WINDOWS
1209 list_tab_vars(&first); 1206 list_tab_vars(&first);
1210 #endif
1211 list_script_vars(&first); 1207 list_script_vars(&first);
1212 list_func_vars(&first); 1208 list_func_vars(&first);
1213 list_vim_vars(&first); 1209 list_vim_vars(&first);
1214 } 1210 }
1215 eap->nextcmd = check_nextcmd(arg); 1211 eap->nextcmd = check_nextcmd(arg);
1467 { 1463 {
1468 list_hashtable_vars(&curwin->w_vars->dv_hashtab, 1464 list_hashtable_vars(&curwin->w_vars->dv_hashtab,
1469 (char_u *)"w:", TRUE, first); 1465 (char_u *)"w:", TRUE, first);
1470 } 1466 }
1471 1467
1472 #ifdef FEAT_WINDOWS
1473 /* 1468 /*
1474 * List tab page variables. 1469 * List tab page variables.
1475 */ 1470 */
1476 static void 1471 static void
1477 list_tab_vars(int *first) 1472 list_tab_vars(int *first)
1478 { 1473 {
1479 list_hashtable_vars(&curtab->tp_vars->dv_hashtab, 1474 list_hashtable_vars(&curtab->tp_vars->dv_hashtab,
1480 (char_u *)"t:", TRUE, first); 1475 (char_u *)"t:", TRUE, first);
1481 } 1476 }
1482 #endif
1483 1477
1484 /* 1478 /*
1485 * List Vim variables. 1479 * List Vim variables.
1486 */ 1480 */
1487 static void 1481 static void
1563 switch (*name) 1557 switch (*name)
1564 { 1558 {
1565 case 'g': list_glob_vars(first); break; 1559 case 'g': list_glob_vars(first); break;
1566 case 'b': list_buf_vars(first); break; 1560 case 'b': list_buf_vars(first); break;
1567 case 'w': list_win_vars(first); break; 1561 case 'w': list_win_vars(first); break;
1568 #ifdef FEAT_WINDOWS
1569 case 't': list_tab_vars(first); break; 1562 case 't': list_tab_vars(first); break;
1570 #endif
1571 case 'v': list_vim_vars(first); break; 1563 case 'v': list_vim_vars(first); break;
1572 case 's': list_script_vars(first); break; 1564 case 's': list_script_vars(first); break;
1573 case 'l': list_func_vars(first); break; 1565 case 'l': list_func_vars(first); break;
1574 default: 1566 default:
1575 EMSG2(_("E738: Can't list variables for %s"), name); 1567 EMSG2(_("E738: Can't list variables for %s"), name);
3073 get_user_var_name(expand_T *xp, int idx) 3065 get_user_var_name(expand_T *xp, int idx)
3074 { 3066 {
3075 static long_u gdone; 3067 static long_u gdone;
3076 static long_u bdone; 3068 static long_u bdone;
3077 static long_u wdone; 3069 static long_u wdone;
3078 #ifdef FEAT_WINDOWS
3079 static long_u tdone; 3070 static long_u tdone;
3080 #endif
3081 static int vidx; 3071 static int vidx;
3082 static hashitem_T *hi; 3072 static hashitem_T *hi;
3083 hashtab_T *ht; 3073 hashtab_T *ht;
3084 3074
3085 if (idx == 0) 3075 if (idx == 0)
3086 { 3076 {
3087 gdone = bdone = wdone = vidx = 0; 3077 gdone = bdone = wdone = vidx = 0;
3088 #ifdef FEAT_WINDOWS
3089 tdone = 0; 3078 tdone = 0;
3090 #endif
3091 } 3079 }
3092 3080
3093 /* Global variables */ 3081 /* Global variables */
3094 if (gdone < globvarht.ht_used) 3082 if (gdone < globvarht.ht_used)
3095 { 3083 {
3128 while (HASHITEM_EMPTY(hi)) 3116 while (HASHITEM_EMPTY(hi))
3129 ++hi; 3117 ++hi;
3130 return cat_prefix_varname('w', hi->hi_key); 3118 return cat_prefix_varname('w', hi->hi_key);
3131 } 3119 }
3132 3120
3133 #ifdef FEAT_WINDOWS
3134 /* t: variables */ 3121 /* t: variables */
3135 ht = &curtab->tp_vars->dv_hashtab; 3122 ht = &curtab->tp_vars->dv_hashtab;
3136 if (tdone < ht->ht_used) 3123 if (tdone < ht->ht_used)
3137 { 3124 {
3138 if (tdone++ == 0) 3125 if (tdone++ == 0)
3141 ++hi; 3128 ++hi;
3142 while (HASHITEM_EMPTY(hi)) 3129 while (HASHITEM_EMPTY(hi))
3143 ++hi; 3130 ++hi;
3144 return cat_prefix_varname('t', hi->hi_key); 3131 return cat_prefix_varname('t', hi->hi_key);
3145 } 3132 }
3146 #endif
3147 3133
3148 /* v: variables */ 3134 /* v: variables */
3149 if (vidx < VV_LEN) 3135 if (vidx < VV_LEN)
3150 return cat_prefix_varname('v', (char_u *)vimvars[vidx++].vv_name); 3136 return cat_prefix_varname('v', (char_u *)vimvars[vidx++].vv_name);
3151 3137
5236 int abort = FALSE; 5222 int abort = FALSE;
5237 buf_T *buf; 5223 buf_T *buf;
5238 win_T *wp; 5224 win_T *wp;
5239 int i; 5225 int i;
5240 int did_free = FALSE; 5226 int did_free = FALSE;
5241 #ifdef FEAT_WINDOWS
5242 tabpage_T *tp; 5227 tabpage_T *tp;
5243 #endif
5244 5228
5245 if (!testing) 5229 if (!testing)
5246 { 5230 {
5247 /* Only do this once. */ 5231 /* Only do this once. */
5248 want_garbage_collect = FALSE; 5232 want_garbage_collect = FALSE;
5281 if (aucmd_win != NULL) 5265 if (aucmd_win != NULL)
5282 abort = abort || set_ref_in_item(&aucmd_win->w_winvar.di_tv, copyID, 5266 abort = abort || set_ref_in_item(&aucmd_win->w_winvar.di_tv, copyID,
5283 NULL, NULL); 5267 NULL, NULL);
5284 #endif 5268 #endif
5285 5269
5286 #ifdef FEAT_WINDOWS
5287 /* tabpage-local variables */ 5270 /* tabpage-local variables */
5288 FOR_ALL_TABPAGES(tp) 5271 FOR_ALL_TABPAGES(tp)
5289 abort = abort || set_ref_in_item(&tp->tp_winvar.di_tv, copyID, 5272 abort = abort || set_ref_in_item(&tp->tp_winvar.di_tv, copyID,
5290 NULL, NULL); 5273 NULL, NULL);
5291 #endif
5292
5293 /* global variables */ 5274 /* global variables */
5294 abort = abort || set_ref_in_ht(&globvarht, copyID, NULL); 5275 abort = abort || set_ref_in_ht(&globvarht, copyID, NULL);
5295 5276
5296 /* function-local variables */ 5277 /* function-local variables */
5297 abort = abort || set_ref_in_call_stack(copyID); 5278 abort = abort || set_ref_in_call_stack(copyID);
7387 case 's': return &SCRIPT_SV(current_SID)->sv_var; 7368 case 's': return &SCRIPT_SV(current_SID)->sv_var;
7388 case 'g': return &globvars_var; 7369 case 'g': return &globvars_var;
7389 case 'v': return &vimvars_var; 7370 case 'v': return &vimvars_var;
7390 case 'b': return &curbuf->b_bufvar; 7371 case 'b': return &curbuf->b_bufvar;
7391 case 'w': return &curwin->w_winvar; 7372 case 'w': return &curwin->w_winvar;
7392 #ifdef FEAT_WINDOWS
7393 case 't': return &curtab->tp_winvar; 7373 case 't': return &curtab->tp_winvar;
7394 #endif
7395 case 'l': return get_funccal_local_var(); 7374 case 'l': return get_funccal_local_var();
7396 case 'a': return get_funccal_args_var(); 7375 case 'a': return get_funccal_args_var();
7397 } 7376 }
7398 return NULL; 7377 return NULL;
7399 } 7378 }
7459 return NULL; 7438 return NULL;
7460 if (*name == 'b') /* buffer variable */ 7439 if (*name == 'b') /* buffer variable */
7461 return &curbuf->b_vars->dv_hashtab; 7440 return &curbuf->b_vars->dv_hashtab;
7462 if (*name == 'w') /* window variable */ 7441 if (*name == 'w') /* window variable */
7463 return &curwin->w_vars->dv_hashtab; 7442 return &curwin->w_vars->dv_hashtab;
7464 #ifdef FEAT_WINDOWS
7465 if (*name == 't') /* tab page variable */ 7443 if (*name == 't') /* tab page variable */
7466 return &curtab->tp_vars->dv_hashtab; 7444 return &curtab->tp_vars->dv_hashtab;
7467 #endif
7468 if (*name == 'v') /* v: variable */ 7445 if (*name == 'v') /* v: variable */
7469 return &vimvarht; 7446 return &vimvarht;
7470 if (*name == 'a') /* a: function argument */ 7447 if (*name == 'a') /* a: function argument */
7471 return get_funccal_args_ht(); 7448 return get_funccal_args_ht();
7472 if (*name == 'l') /* l: local function variable */ 7449 if (*name == 'l') /* l: local function variable */
8384 win_T * 8361 win_T *
8385 find_win_by_nr( 8362 find_win_by_nr(
8386 typval_T *vp, 8363 typval_T *vp,
8387 tabpage_T *tp UNUSED) /* NULL for current tab page */ 8364 tabpage_T *tp UNUSED) /* NULL for current tab page */
8388 { 8365 {
8389 #ifdef FEAT_WINDOWS
8390 win_T *wp; 8366 win_T *wp;
8391 #endif
8392 int nr; 8367 int nr;
8393 8368
8394 nr = (int)get_tv_number_chk(vp, NULL); 8369 nr = (int)get_tv_number_chk(vp, NULL);
8395 8370
8396 #ifdef FEAT_WINDOWS
8397 if (nr < 0) 8371 if (nr < 0)
8398 return NULL; 8372 return NULL;
8399 if (nr == 0) 8373 if (nr == 0)
8400 return curwin; 8374 return curwin;
8401 8375
8410 break; 8384 break;
8411 } 8385 }
8412 if (nr >= LOWEST_WIN_ID) 8386 if (nr >= LOWEST_WIN_ID)
8413 return NULL; 8387 return NULL;
8414 return wp; 8388 return wp;
8415 #else
8416 if (nr == 0 || nr == 1 || nr == curwin->w_id)
8417 return curwin;
8418 return NULL;
8419 #endif
8420 } 8389 }
8421 8390
8422 /* 8391 /*
8423 * Find window specified by "wvp" in tabpage "tvp". 8392 * Find window specified by "wvp" in tabpage "tvp".
8424 */ 8393 */
8463 win_T *win; 8432 win_T *win;
8464 char_u *varname; 8433 char_u *varname;
8465 dictitem_T *v; 8434 dictitem_T *v;
8466 tabpage_T *tp = NULL; 8435 tabpage_T *tp = NULL;
8467 int done = FALSE; 8436 int done = FALSE;
8468 #ifdef FEAT_WINDOWS
8469 win_T *oldcurwin; 8437 win_T *oldcurwin;
8470 tabpage_T *oldtabpage; 8438 tabpage_T *oldtabpage;
8471 int need_switch_win; 8439 int need_switch_win;
8472 #endif 8440
8473
8474 #ifdef FEAT_WINDOWS
8475 if (off == 1) 8441 if (off == 1)
8476 tp = find_tabpage((int)get_tv_number_chk(&argvars[0], NULL)); 8442 tp = find_tabpage((int)get_tv_number_chk(&argvars[0], NULL));
8477 else 8443 else
8478 tp = curtab; 8444 tp = curtab;
8479 #endif
8480 win = find_win_by_nr(&argvars[off], tp); 8445 win = find_win_by_nr(&argvars[off], tp);
8481 varname = get_tv_string_chk(&argvars[off + 1]); 8446 varname = get_tv_string_chk(&argvars[off + 1]);
8482 ++emsg_off; 8447 ++emsg_off;
8483 8448
8484 rettv->v_type = VAR_STRING; 8449 rettv->v_type = VAR_STRING;
8485 rettv->vval.v_string = NULL; 8450 rettv->vval.v_string = NULL;
8486 8451
8487 if (win != NULL && varname != NULL) 8452 if (win != NULL && varname != NULL)
8488 { 8453 {
8489 #ifdef FEAT_WINDOWS
8490 /* Set curwin to be our win, temporarily. Also set the tabpage, 8454 /* Set curwin to be our win, temporarily. Also set the tabpage,
8491 * otherwise the window is not valid. Only do this when needed, 8455 * otherwise the window is not valid. Only do this when needed,
8492 * autocommands get blocked. */ 8456 * autocommands get blocked. */
8493 need_switch_win = !(tp == curtab && win == curwin); 8457 need_switch_win = !(tp == curtab && win == curwin);
8494 if (!need_switch_win 8458 if (!need_switch_win
8495 || switch_win(&oldcurwin, &oldtabpage, win, tp, TRUE) == OK) 8459 || switch_win(&oldcurwin, &oldtabpage, win, tp, TRUE) == OK)
8496 #endif
8497 { 8460 {
8498 if (*varname == '&') 8461 if (*varname == '&')
8499 { 8462 {
8500 if (varname[1] == NUL) 8463 if (varname[1] == NUL)
8501 { 8464 {
8524 done = TRUE; 8487 done = TRUE;
8525 } 8488 }
8526 } 8489 }
8527 } 8490 }
8528 8491
8529 #ifdef FEAT_WINDOWS
8530 if (need_switch_win) 8492 if (need_switch_win)
8531 /* restore previous notion of curwin */ 8493 /* restore previous notion of curwin */
8532 restore_win(oldcurwin, oldtabpage, TRUE); 8494 restore_win(oldcurwin, oldtabpage, TRUE);
8533 #endif
8534 } 8495 }
8535 8496
8536 if (!done && argvars[off + 2].v_type != VAR_UNKNOWN) 8497 if (!done && argvars[off + 2].v_type != VAR_UNKNOWN)
8537 /* use the default return value */ 8498 /* use the default return value */
8538 copy_tv(&argvars[off + 2], rettv); 8499 copy_tv(&argvars[off + 2], rettv);
8545 */ 8506 */
8546 void 8507 void
8547 setwinvar(typval_T *argvars, typval_T *rettv UNUSED, int off) 8508 setwinvar(typval_T *argvars, typval_T *rettv UNUSED, int off)
8548 { 8509 {
8549 win_T *win; 8510 win_T *win;
8550 #ifdef FEAT_WINDOWS
8551 win_T *save_curwin; 8511 win_T *save_curwin;
8552 tabpage_T *save_curtab; 8512 tabpage_T *save_curtab;
8553 int need_switch_win; 8513 int need_switch_win;
8554 #endif
8555 char_u *varname, *winvarname; 8514 char_u *varname, *winvarname;
8556 typval_T *varp; 8515 typval_T *varp;
8557 char_u nbuf[NUMBUFLEN]; 8516 char_u nbuf[NUMBUFLEN];
8558 tabpage_T *tp = NULL; 8517 tabpage_T *tp = NULL;
8559 8518
8560 if (check_restricted() || check_secure()) 8519 if (check_restricted() || check_secure())
8561 return; 8520 return;
8562 8521
8563 #ifdef FEAT_WINDOWS
8564 if (off == 1) 8522 if (off == 1)
8565 tp = find_tabpage((int)get_tv_number_chk(&argvars[0], NULL)); 8523 tp = find_tabpage((int)get_tv_number_chk(&argvars[0], NULL));
8566 else 8524 else
8567 tp = curtab; 8525 tp = curtab;
8568 #endif
8569 win = find_win_by_nr(&argvars[off], tp); 8526 win = find_win_by_nr(&argvars[off], tp);
8570 varname = get_tv_string_chk(&argvars[off + 1]); 8527 varname = get_tv_string_chk(&argvars[off + 1]);
8571 varp = &argvars[off + 2]; 8528 varp = &argvars[off + 2];
8572 8529
8573 if (win != NULL && varname != NULL && varp != NULL) 8530 if (win != NULL && varname != NULL && varp != NULL)
8574 { 8531 {
8575 #ifdef FEAT_WINDOWS
8576 need_switch_win = !(tp == curtab && win == curwin); 8532 need_switch_win = !(tp == curtab && win == curwin);
8577 if (!need_switch_win 8533 if (!need_switch_win
8578 || switch_win(&save_curwin, &save_curtab, win, tp, TRUE) == OK) 8534 || switch_win(&save_curwin, &save_curtab, win, tp, TRUE) == OK)
8579 #endif
8580 { 8535 {
8581 if (*varname == '&') 8536 if (*varname == '&')
8582 { 8537 {
8583 long numval; 8538 long numval;
8584 char_u *strval; 8539 char_u *strval;
8600 set_var(winvarname, varp, TRUE); 8555 set_var(winvarname, varp, TRUE);
8601 vim_free(winvarname); 8556 vim_free(winvarname);
8602 } 8557 }
8603 } 8558 }
8604 } 8559 }
8605 #ifdef FEAT_WINDOWS
8606 if (need_switch_win) 8560 if (need_switch_win)
8607 restore_win(save_curwin, save_curtab, TRUE); 8561 restore_win(save_curwin, save_curtab, TRUE);
8608 #endif
8609 } 8562 }
8610 } 8563 }
8611 8564
8612 /* 8565 /*
8613 * Skip over the name of an option: "&option", "&g:option" or "&l:option". 8566 * Skip over the name of an option: "&option", "&g:option" or "&l:option".