comparison src/eval.c @ 163:06bc859d1a32 v7.0049

updated for version 7.0049
author vimboss
date Mon, 07 Feb 2005 22:05:52 +0000
parents 389c8abd5925
children e943e5502fc9
comparison
equal deleted inserted replaced
162:7e6c3b196717 163:06bc859d1a32
569 static int eval_fname_sid __ARGS((char_u *p)); 569 static int eval_fname_sid __ARGS((char_u *p));
570 static void list_func_head __ARGS((ufunc_T *fp, int indent)); 570 static void list_func_head __ARGS((ufunc_T *fp, int indent));
571 static void cat_func_name __ARGS((char_u *buf, ufunc_T *fp)); 571 static void cat_func_name __ARGS((char_u *buf, ufunc_T *fp));
572 static ufunc_T *find_func __ARGS((char_u *name)); 572 static ufunc_T *find_func __ARGS((char_u *name));
573 static int function_exists __ARGS((char_u *name)); 573 static int function_exists __ARGS((char_u *name));
574 static int builtin_function __ARGS((char_u *name));
575 static int func_autoload __ARGS((char_u *name));
574 static void func_free __ARGS((ufunc_T *fp)); 576 static void func_free __ARGS((ufunc_T *fp));
575 static void func_unref __ARGS((char_u *name)); 577 static void func_unref __ARGS((char_u *name));
576 static void func_ref __ARGS((char_u *name)); 578 static void func_ref __ARGS((char_u *name));
577 static void call_user_func __ARGS((ufunc_T *fp, int argcount, typval_T *argvars, typval_T *rettv, linenr_T firstline, linenr_T lastline, dict_T *selfdict)); 579 static void call_user_func __ARGS((ufunc_T *fp, int argcount, typval_T *argvars, typval_T *rettv, linenr_T firstline, linenr_T lastline, dict_T *selfdict));
578 static void add_nr_var __ARGS((dict_T *dp, dictitem_T *v, char *name, varnumber_T nr)); 580 static void add_nr_var __ARGS((dict_T *dp, dictitem_T *v, char *name, varnumber_T nr));
2493 startarg = skipwhite(arg); 2495 startarg = skipwhite(arg);
2494 rettv.v_type = VAR_UNKNOWN; /* clear_tv() uses this */ 2496 rettv.v_type = VAR_UNKNOWN; /* clear_tv() uses this */
2495 2497
2496 if (*startarg != '(') 2498 if (*startarg != '(')
2497 { 2499 {
2498 EMSG2(_("E107: Missing braces: %s"), name); 2500 if (*name == K_SPECIAL)
2501 EMSG2(_("E107: Missing braces: <SNR>%s"), name + 3);
2502 else
2503 EMSG2(_("E107: Missing braces: %s"), name);
2499 goto end; 2504 goto end;
2500 } 2505 }
2501 2506
2502 /* 2507 /*
2503 * When skipping, evaluate the function once, to find the end of the 2508 * When skipping, evaluate the function once, to find the end of the
2982 2987
2983 /* w: variables */ 2988 /* w: variables */
2984 ht = &curwin->w_vars.dv_hashtab; 2989 ht = &curwin->w_vars.dv_hashtab;
2985 if (wdone < ht->ht_used) 2990 if (wdone < ht->ht_used)
2986 { 2991 {
2987 if (bdone++ == 0) 2992 if (wdone++ == 0)
2988 hi = ht->ht_array; 2993 hi = ht->ht_array;
2989 else 2994 else
2990 ++hi; 2995 ++hi;
2991 while (HASHITEM_EMPTY(hi)) 2996 while (HASHITEM_EMPTY(hi))
2992 ++hi; 2997 ++hi;
6137 if (evaluate && error == ERROR_NONE) 6142 if (evaluate && error == ERROR_NONE)
6138 { 6143 {
6139 rettv->v_type = VAR_NUMBER; /* default is number rettv */ 6144 rettv->v_type = VAR_NUMBER; /* default is number rettv */
6140 error = ERROR_UNKNOWN; 6145 error = ERROR_UNKNOWN;
6141 6146
6142 if (!ASCII_ISLOWER(fname[0])) 6147 if (!builtin_function(fname))
6143 { 6148 {
6144 /* 6149 /*
6145 * User defined function. 6150 * User defined function.
6146 */ 6151 */
6147 fp = find_func(fname); 6152 fp = find_func(fname);
6153
6148 #ifdef FEAT_AUTOCMD 6154 #ifdef FEAT_AUTOCMD
6149 if (fp == NULL && apply_autocmds(EVENT_FUNCUNDEFINED, 6155 /* Trigger FuncUndefined event, may load the function. */
6150 fname, fname, TRUE, NULL) 6156 if (fp == NULL
6151 #ifdef FEAT_EVAL 6157 && apply_autocmds(EVENT_FUNCUNDEFINED,
6152 && !aborting() 6158 fname, fname, TRUE, NULL)
6153 #endif 6159 && !aborting())
6154 )
6155 { 6160 {
6156 /* executed an autocommand, search for function again */ 6161 /* executed an autocommand, search for the function again */
6157 fp = find_func(fname); 6162 fp = find_func(fname);
6158 } 6163 }
6159 #endif 6164 #endif
6165 /* Try loading a package. */
6166 if (fp == NULL && func_autoload(fname) && !aborting())
6167 {
6168 /* loaded a package, search for the function again */
6169 fp = find_func(fname);
6170 }
6171
6160 if (fp != NULL) 6172 if (fp != NULL)
6161 { 6173 {
6162 if (fp->flags & FC_RANGE) 6174 if (fp->flags & FC_RANGE)
6163 *doesrange = TRUE; 6175 *doesrange = TRUE;
6164 if (argcount < fp->args.ga_len) 6176 if (argcount < fp->args.ga_len)
15373 } 15385 }
15374 sprintf((char *)sid_buf, "%ld_", (long)current_SID); 15386 sprintf((char *)sid_buf, "%ld_", (long)current_SID);
15375 lead += (int)STRLEN(sid_buf); 15387 lead += (int)STRLEN(sid_buf);
15376 } 15388 }
15377 } 15389 }
15378 else if (!(flags & TFN_INT) && !ASCII_ISUPPER(*lv.ll_name)) 15390 else if (!(flags & TFN_INT) && builtin_function(lv.ll_name))
15379 { 15391 {
15380 EMSG2(_("E128: Function name must start with a capital: %s"), 15392 EMSG2(_("E128: Function name must start with a capital or contain a colon: %s"), lv.ll_name);
15381 lv.ll_name);
15382 goto theend; 15393 goto theend;
15383 } 15394 }
15384 name = alloc((unsigned)(len + lead + 1)); 15395 name = alloc((unsigned)(len + lead + 1));
15385 if (name != NULL) 15396 if (name != NULL)
15386 { 15397 {
15494 int n = FALSE; 15505 int n = FALSE;
15495 15506
15496 p = trans_function_name(&p, FALSE, TFN_INT|TFN_QUIET, NULL); 15507 p = trans_function_name(&p, FALSE, TFN_INT|TFN_QUIET, NULL);
15497 if (p != NULL) 15508 if (p != NULL)
15498 { 15509 {
15499 if (ASCII_ISUPPER(*p) || p[0] == K_SPECIAL) 15510 if (builtin_function(p))
15511 n = (find_internal_func(p) >= 0);
15512 else
15500 n = (find_func(p) != NULL); 15513 n = (find_func(p) != NULL);
15501 else if (ASCII_ISLOWER(*p))
15502 n = (find_internal_func(p) >= 0);
15503 vim_free(p); 15514 vim_free(p);
15504 } 15515 }
15505 return n; 15516 return n;
15517 }
15518
15519 /*
15520 * Return TRUE if "name" looks like a builtin function name: starts with a
15521 * lower case letter and doesn't contain a ':'.
15522 */
15523 static int
15524 builtin_function(name)
15525 char_u *name;
15526 {
15527 return ASCII_ISLOWER(name[0]) && vim_strchr(name, ':') == NULL;
15528 }
15529
15530 /*
15531 * If "name" has a package name try autoloading the script.
15532 * Return TRUE if a package was loaded.
15533 */
15534 static int
15535 func_autoload(name)
15536 char_u *name;
15537 {
15538 char_u *p;
15539 char_u *scriptname;
15540 int ret = FALSE;
15541
15542 /* If there is no colon after name[1] there is no package name. */
15543 p = vim_strchr(name, ':');
15544 if (p == NULL || p <= name + 2)
15545 return FALSE;
15546
15547 /* Get the script file name: replace ':' with '/', append ".vim". */
15548 scriptname = alloc((unsigned)(STRLEN(name) + 14));
15549 if (scriptname == NULL)
15550 return FALSE;
15551 STRCPY(scriptname, "autoload/");
15552 STRCAT(scriptname, name);
15553 *vim_strrchr(scriptname, ':') = NUL;
15554 STRCAT(scriptname, ".vim");
15555 while ((p = vim_strchr(scriptname, ':')) != NULL)
15556 *p = '/';
15557
15558 /* Try loading the package from $VIMRUNTIME/autoload/<name>.vim */
15559 if (cmd_runtime(scriptname, FALSE) == OK)
15560 ret = TRUE;
15561
15562 vim_free(scriptname);
15563 return ret;
15506 } 15564 }
15507 15565
15508 #if defined(FEAT_CMDL_COMPL) || defined(PROTO) 15566 #if defined(FEAT_CMDL_COMPL) || defined(PROTO)
15509 15567
15510 /* 15568 /*