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 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) static bool parser_parse_statement(parser_t *parser, ast_block *block, ast_expression **out)
{ {
if (parser->tok == TOKEN_TYPENAME) 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 == '{') else if (parser->tok == '{')
{ {
/* a block */ ast_block *inner;
parseerror(parser, "TODO: inner blocks: %s", parser_tokval(parser)); inner = parser_parse_block(parser);
if (!inner)
return false; return false;
*out = (ast_expression*)inner;
return true;
} }
else 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) static ast_block* parser_parse_block(parser_t *parser)
{ {
size_t oldblocklocal; size_t oldblocklocal;
@ -856,6 +866,9 @@ static ast_block* parser_parse_block(parser_t *parser)
cleanup: cleanup:
parser->blocklocal = oldblocklocal; parser->blocklocal = oldblocklocal;
/* unroll the local vector */
while (parser->locals_count > parser->blocklocal)
parser_pop_local(parser);
return block; return block;
} }
@ -869,12 +882,6 @@ static ast_expression* parser_parse_statement_or_block(parser_t *parser)
return expr; 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) static bool parser_variable(parser_t *parser, ast_block *localblock)
{ {
bool isfunc = false; bool isfunc = false;