Allow fieldpointer parameters in functions, allow function fields again

This commit is contained in:
Wolfgang (Blub) Bumiller 2012-08-16 15:27:06 +02:00
parent 1c81c27cee
commit ec439d7880
2 changed files with 28 additions and 1 deletions

View file

@ -635,7 +635,6 @@ int lex_do(lex_file *lex)
!strcmp(v, "do") ||
!strcmp(v, "if") ||
!strcmp(v, "else") ||
!strcmp(v, "var") ||
!strcmp(v, "local") ||
!strcmp(v, "return") ||
!strcmp(v, "const"))

View file

@ -292,6 +292,8 @@ static ast_value *parser_parse_type(parser_t *parser, int basetype, bool *isfunc
*isfunc = true;
while (true) {
ast_value *param;
ast_value *fld;
bool isfield = false;
bool dummy;
if (!parser_next(parser))
@ -300,6 +302,14 @@ static ast_value *parser_parse_type(parser_t *parser, int basetype, bool *isfunc
if (parser->tok == ')')
break;
if (parser->tok == '.') {
isfield = true;
if (!parser_next(parser)) {
parseerror(parser, "expected field parameter type");
goto on_error;
}
}
temptype = parser_token(parser)->constval.t;
if (!parser_next(parser))
goto on_error;
@ -318,6 +328,12 @@ static ast_value *parser_parse_type(parser_t *parser, int basetype, bool *isfunc
goto on_error;
}
if (isfield) {
fld = ast_value_new(ctx, param->name, TYPE_FIELD);
fld->expression.next = (ast_expression*)param;
param = fld;
}
if (!paramlist_t_p_add(&params, param)) {
parseerror(parser, "Out of memory while parsing typename");
goto on_error;
@ -2007,6 +2023,18 @@ static bool parser_do(parser_t *parser)
}
}
if (isfunc) {
ast_value *fval;
fval = ast_value_new(ctx, var->name, TYPE_FUNCTION);
if (!fval) {
ast_value_delete(var);
return false;
}
fval->expression.next = (ast_expression*)var;
MEM_VECTOR_MOVE(&var->expression, params, &fval->expression, params);
var = fval;
}
/* turn it into a field */
fld = ast_value_new(ctx, parser_tokval(parser), TYPE_FIELD);
fld->expression.next = (ast_expression*)var;