Handling blocks and inner blocks

This commit is contained in:
Wolfgang (Blub) Bumiller 2012-08-11 10:35:10 +02:00
parent d3d2e00b64
commit 3e4f490a59

View file

@ -741,6 +741,7 @@ onerr:
}
static bool parser_variable(parser_t *parser, ast_block *localblock);
static ast_block* parser_parse_block(parser_t *parser);
static bool parser_parse_statement(parser_t *parser, ast_block *block, ast_expression **out)
{
if (parser->tok == TOKEN_TYPENAME)
@ -797,9 +798,12 @@ static bool parser_parse_statement(parser_t *parser, ast_block *block, ast_expre
}
else if (parser->tok == '{')
{
/* a block */
parseerror(parser, "TODO: inner blocks: %s", parser_tokval(parser));
return false;
ast_block *inner;
inner = parser_parse_block(parser);
if (!inner)
return false;
*out = (ast_expression*)inner;
return true;
}
else
{
@ -811,6 +815,12 @@ static bool parser_parse_statement(parser_t *parser, ast_block *block, ast_expre
}
}
static void parser_pop_local(parser_t *parser)
{
parser->locals_count--;
mem_d(parser->locals[parser->locals_count].name);
}
static ast_block* parser_parse_block(parser_t *parser)
{
size_t oldblocklocal;
@ -856,6 +866,9 @@ static ast_block* parser_parse_block(parser_t *parser)
cleanup:
parser->blocklocal = oldblocklocal;
/* unroll the local vector */
while (parser->locals_count > parser->blocklocal)
parser_pop_local(parser);
return block;
}
@ -869,12 +882,6 @@ static ast_expression* parser_parse_statement_or_block(parser_t *parser)
return expr;
}
static void parser_pop_local(parser_t *parser)
{
parser->locals_count--;
mem_d(parser->locals[parser->locals_count].name);
}
static bool parser_variable(parser_t *parser, ast_block *localblock)
{
bool isfunc = false;