Clean up parser_t's block stack

Currently the block stack is just a vector of pointers.
Clients must manually use new() to allocate a block, and then
transfer ownership to the stack (so must NOT delete it).

Give the parser itself responsibility for allocating blocks too,
so that it takes over both allocation and deletion. Use unique_ptr
to make deletion less error-prone.
This commit is contained in:
ridiculousfish
2017-01-21 15:35:35 -08:00
parent ac8b27fcb1
commit 0991e398bb
6 changed files with 47 additions and 55 deletions

View File

@@ -629,8 +629,8 @@ void exec_job(parser_t &parser, job_t *j) {
debug(0, _(L"Unknown function '%ls'"), p->argv0());
break;
}
function_block_t *newv = new function_block_t(p, func_name, shadow_scope);
parser.push_block(newv);
function_block_t *fb = parser.push_block<function_block_t>(p, func_name, shadow_scope);
// Setting variables might trigger an event handler, hence we need to unblock
// signals.
@@ -661,7 +661,7 @@ void exec_job(parser_t &parser, job_t *j) {
}
parser.allow_function();
parser.pop_block();
parser.pop_block(fb);
break;
}