eval: Extract find_var_ht_dict from find_var_ht

This commit is contained in:
Thiago de Arruda
2015-11-05 11:37:31 -03:00
parent 80a44c0525
commit ba1f327200

View File

@@ -18109,53 +18109,67 @@ static dictitem_T *find_var_in_ht(hashtab_T *ht, int htname, char_u *varname, in
return HI2DI(hi); return HI2DI(hi);
} }
/* // Find the dict and hashtable used for a variable name. Set "varname" to the
* Find the hashtab used for a variable name. // start of name without ':'.
* Set "varname" to the start of name without ':'. static hashtab_T *find_var_ht_dict(char_u *name, uint8_t **varname, dict_T **d)
*/
static hashtab_T *find_var_ht(char_u *name, char_u **varname)
{ {
hashitem_T *hi; hashitem_T *hi;
*d = NULL;
if (name[1] != ':') { if (name[1] != ':') {
/* The name must not start with a colon or #. */ // name has implicit scope
if (name[0] == ':' || name[0] == AUTOLOAD_CHAR) if (name[0] == ':' || name[0] == AUTOLOAD_CHAR) {
// The name must not start with a colon or #.
return NULL; return NULL;
}
*varname = name; *varname = name;
/* "version" is "v:version" in all scopes */ // "version" is "v:version" in all scopes
hi = hash_find(&compat_hashtab, name); hi = hash_find(&compat_hashtab, name);
if (!HASHITEM_EMPTY(hi)) if (!HASHITEM_EMPTY(hi)) {
return &compat_hashtab; return &compat_hashtab;
}
if (current_funccal == NULL) *d = current_funccal ? &current_funccal->l_vars : &globvardict;
return &globvarht; /* global variable */ goto end;
return &current_funccal->l_vars.dv_hashtab; /* l: variable */
} }
*varname = name + 2; *varname = name + 2;
if (*name == 'g') /* global variable */ if (*name == 'g') { // global variable
return &globvarht; *d = &globvardict;
/* There must be no ':' or '#' in the rest of the name, unless g: is used } else if (vim_strchr(name + 2, ':') != NULL
*/ || vim_strchr(name + 2, AUTOLOAD_CHAR) != NULL) {
if (vim_strchr(name + 2, ':') != NULL // There must be no ':' or '#' in the rest of the name if g: was not used
|| vim_strchr(name + 2, AUTOLOAD_CHAR) != NULL)
return NULL; return NULL;
if (*name == 'b') /* buffer variable */ }
return &curbuf->b_vars->dv_hashtab;
if (*name == 'w') /* window variable */ if (*name == 'b') { // buffer variable
return &curwin->w_vars->dv_hashtab; *d = curbuf->b_vars;
if (*name == 't') /* tab page variable */ } else if (*name == 'w') { // window variable
return &curtab->tp_vars->dv_hashtab; *d = curwin->w_vars;
if (*name == 'v') /* v: variable */ } else if (*name == 't') { // tab page variable
return &vimvarht; *d = curtab->tp_vars;
if (*name == 'a' && current_funccal != NULL) /* function argument */ } else if (*name == 'v') { // v: variable
return &current_funccal->l_avars.dv_hashtab; *d = &vimvardict;
if (*name == 'l' && current_funccal != NULL) /* local function variable */ } else if (*name == 'a' && current_funccal != NULL) { // function argument
return &current_funccal->l_vars.dv_hashtab; *d = &current_funccal->l_avars;
if (*name == 's' /* script variable */ } else if (*name == 'l' && current_funccal != NULL) { // local variable
&& current_SID > 0 && current_SID <= ga_scripts.ga_len) *d = &current_funccal->l_vars;
return &SCRIPT_VARS(current_SID); } else if (*name == 's' // script variable
return NULL; && current_SID > 0 && current_SID <= ga_scripts.ga_len) {
*d = &SCRIPT_SV(current_SID)->sv_dict;
}
end:
return *d ? &(*d)->dv_hashtab : NULL;
}
// Find the hashtab used for a variable name.
// Set "varname" to the start of name without ':'.
static hashtab_T *find_var_ht(uint8_t *name, uint8_t **varname)
{
dict_T *d;
return find_var_ht_dict(name, varname, &d);
} }
/* /*