/* vi:set ts=8 sts=4 sw=4 noet:
*
* VIM - Vi IMproved by Bram Moolenaar
*
* Do ":help uganda" in Vim to read copying and usage conditions.
* Do ":help credits" in Vim to see a list of people who contributed.
* See README.txt for an overview of the Vim source code.
*/
/*
* vim9class.c: Vim9 script class support
*/
#define USING_FLOAT_STUFF
#include "vim.h"
#if defined(FEAT_EVAL) || defined(PROTO)
// When not generating protos this is included in proto.h
#ifdef PROTO
# include "vim9.h"
#endif
/*
* Parse a member declaration, both object and class member.
* Returns OK or FAIL. When OK then "varname_end" is set to just after the
* variable name and "type_ret" is set to the decleared or detected type.
* "init_expr" is set to the initialisation expression (allocated), if there is
* one. For an interface "init_expr" is NULL.
*/
static int
parse_member(
exarg_T *eap,
char_u *line,
char_u *varname,
int has_public, // TRUE if "public" seen before "varname"
char_u **varname_end,
garray_T *type_list,
type_T **type_ret,
char_u **init_expr)
{
*varname_end = to_name_end(varname, FALSE);
if (*varname == '_' && has_public)
{
semsg(_(e_public_member_name_cannot_start_with_underscore_str), line);
return FAIL;
}
char_u *colon = skipwhite(*varname_end);
char_u *type_arg = colon;
type_T *type = NULL;
if (*colon == ':')
{
if (VIM_ISWHITE(**varname_end))
{
semsg(_(e_no_white_space_allowed_before_colon_str), varname);
return FAIL;
}
if (!VIM_ISWHITE(colon[1]))
{
semsg(_(e_white_space_required_after_str_str), ":", varname);
return FAIL;
}
type_arg = skipwhite(colon + 1);
type = parse_type(&type_arg, type_list, TRUE);
if (type == NULL)
return FAIL;
}
char_u *expr_start = skipwhite(type_arg);
char_u *expr_end = expr_start;
if (type == NULL && *expr_start != '=')
{
emsg(_(e_type_or_initialization_required));
return FAIL;
}
if (*expr_start == '=')
{
if (!VIM_ISWHITE(expr_start[-1]) || !VIM_ISWHITE(expr_start[1]))
{
semsg(_(e_white_space_required_before_and_after_str_at_str),
"=", type_arg);
return FAIL;
}
expr_start = skipwhite(expr_start + 1);
expr_end = expr_start;
evalarg_T evalarg;
fill_evalarg_from_eap(&evalarg, eap, FALSE);
skip_expr(&expr_end, NULL);
if (type == NULL)
{
// No