comparison src/vim9compile.c @ 27714:072c7ae27b06 v8.2.4383

patch 8.2.4383: Vim9: unused code lines Commit: https://github.com/vim/vim/commit/7a3b802bab5add34baae37ec2c1ae7ad2f1693bd Author: Bram Moolenaar <Bram@vim.org> Date: Mon Feb 14 19:53:03 2022 +0000 patch 8.2.4383: Vim9: unused code lines Problem: Vim9: unused code lines. Solution: Rely on either "cctx" or "cstack" to not be NULL.
author Bram Moolenaar <Bram@vim.org>
date Mon, 14 Feb 2022 21:00:03 +0100
parents 3813036f19cb
children 4097434c7c67
comparison
equal deleted inserted replaced
27713:40bf82852134 27714:072c7ae27b06
149 } 149 }
150 150
151 /* 151 /*
152 * Lookup a script-local variable in the current script, possibly defined in a 152 * Lookup a script-local variable in the current script, possibly defined in a
153 * block that contains the function "cctx->ctx_ufunc". 153 * block that contains the function "cctx->ctx_ufunc".
154 * "cctx" is NULL at the script level. 154 * "cctx" is NULL at the script level, "cstack" is NULL in a function.
155 * "cstack_T" is NULL in a function.
156 * If "len" is <= 0 "name" must be NUL terminated. 155 * If "len" is <= 0 "name" must be NUL terminated.
157 * Return NULL when not found. 156 * Return NULL when not found.
158 */ 157 */
159 static sallvar_T * 158 static sallvar_T *
160 find_script_var(char_u *name, size_t len, cctx_T *cctx, cstack_T *cstack) 159 find_script_var(char_u *name, size_t len, cctx_T *cctx, cstack_T *cstack)
183 return sav; 182 return sav;
184 183
185 if (cctx == NULL) 184 if (cctx == NULL)
186 { 185 {
187 // Not in a function scope, find variable with block ID equal to or 186 // Not in a function scope, find variable with block ID equal to or
188 // smaller than the current block id. If "cstack" is not NULL go up 187 // smaller than the current block id. Use "cstack" to go up the block
189 // the block scopes (more accurate). 188 // scopes.
190 while (sav != NULL) 189 while (sav != NULL)
191 { 190 {
192 if (cstack != NULL) 191 int idx;
193 { 192
194 int idx; 193 for (idx = cstack->cs_idx; idx >= 0; --idx)
195 194 if (cstack->cs_block_id[idx] == sav->sav_block_id)
196 for (idx = cstack->cs_idx; idx >= 0; --idx)
197 if (cstack->cs_block_id[idx] == sav->sav_block_id)
198 break;
199 if (idx >= 0)
200 break; 195 break;
201 } 196 if (idx >= 0)
202 else if (sav->sav_block_id <= si->sn_current_block_id)
203 break; 197 break;
204 sav = sav->sav_next; 198 sav = sav->sav_next;
205 } 199 }
206 return sav; 200 return sav;
207 } 201 }
234 return SCRIPT_ITEM(current_sctx.sc_sid)->sn_version == SCRIPT_VERSION_VIM9; 228 return SCRIPT_ITEM(current_sctx.sc_sid)->sn_version == SCRIPT_VERSION_VIM9;
235 } 229 }
236 230
237 /* 231 /*
238 * Lookup a variable (without s: prefix) in the current script. 232 * Lookup a variable (without s: prefix) in the current script.
239 * "cctx" is NULL at the script level. 233 * "cctx" is NULL at the script level, "cstack" is NULL in a function.
240 * "cstack" is NULL in a function.
241 * Returns OK or FAIL. 234 * Returns OK or FAIL.
242 */ 235 */
243 int 236 int
244 script_var_exists(char_u *name, size_t len, cctx_T *cctx, cstack_T *cstack) 237 script_var_exists(char_u *name, size_t len, cctx_T *cctx, cstack_T *cstack)
245 { 238 {
294 return variable_exists(name, len, cctx); 287 return variable_exists(name, len, cctx);
295 } 288 }
296 289
297 /* 290 /*
298 * Check if "p[len]" is already defined, either in script "import_sid" or in 291 * Check if "p[len]" is already defined, either in script "import_sid" or in
299 * compilation context "cctx". "cctx" is NULL at the script level. 292 * compilation context "cctx".
293 * "cctx" is NULL at the script level, "cstack" is NULL in a function.
300 * Does not check the global namespace. 294 * Does not check the global namespace.
301 * If "is_arg" is TRUE the error message is for an argument name. 295 * If "is_arg" is TRUE the error message is for an argument name.
302 * Return FAIL and give an error if it defined. 296 * Return FAIL and give an error if it defined.
303 */ 297 */
304 int 298 int
505 } 499 }
506 500
507 /* 501 /*
508 * Find "name" in script-local items of script "sid". 502 * Find "name" in script-local items of script "sid".
509 * Pass "check_writable" to check_item_writable(). 503 * Pass "check_writable" to check_item_writable().
504 * "cctx" is NULL at the script level, "cstack" is NULL in a function.
510 * Returns the index in "sn_var_vals" if found. 505 * Returns the index in "sn_var_vals" if found.
511 * If found but not in "sn_var_vals" returns -1. 506 * If found but not in "sn_var_vals" returns -1.
512 * If not found or the variable is not writable returns -2. 507 * If not found or the variable is not writable returns -2.
513 */ 508 */
514 int 509 int