Default parser_t::eval()'s block type to top

This is the parameter value at every call site except one. Just make it the
default.
This commit is contained in:
ridiculousfish
2019-12-22 16:27:03 -08:00
parent 0c49dce75d
commit c19407ab0f
10 changed files with 29 additions and 30 deletions

View File

@@ -165,7 +165,7 @@ void builtin_print_help(parser_t &parser, io_streams_t &streams, const wchar_t *
// If it's an error, redirect the output of __fish_print_help to stderr
ios.push_back(std::make_shared<io_fd_t>(STDOUT_FILENO, STDERR_FILENO));
}
parser.eval(cmd, ios, block_type_t::top);
parser.eval(cmd, ios);
// ignore the exit status of __fish_print_help
}

View File

@@ -27,8 +27,7 @@ int builtin_eval(parser_t &parser, io_streams_t &streams, wchar_t **argv) {
const auto cached_exec_count = parser.libdata().exec_count;
int status = STATUS_CMD_OK;
if (argc > 1) {
if (parser.eval(std::move(new_cmd), *streams.io_chain, block_type_t::top) !=
eval_result_t::ok) {
if (parser.eval(std::move(new_cmd), *streams.io_chain) != eval_result_t::ok) {
status = STATUS_CMD_ERROR;
} else if (cached_exec_count == parser.libdata().exec_count) {
// Issue #5692, in particular, to catch `eval ""`, `eval "begin; end;"`, etc.

View File

@@ -286,7 +286,7 @@ static void event_fire_internal(parser_t &parser, const event_t &event) {
auto prev_statuses = parser.get_last_statuses();
block_t *b = parser.push_block(block_t::event_block(event));
parser.eval(buffer, io_chain_t(), block_type_t::top);
parser.eval(buffer, io_chain_t());
parser.pop_block(b);
parser.set_last_statuses(std::move(prev_statuses));
}

View File

@@ -733,7 +733,7 @@ static proc_performer_t get_performer_for_process(process_t *p, const job_t *job
tnode_t<grammar::statement> node = p->internal_block_node;
assert(source && node && "Process is missing node info");
return [=](parser_t &parser) {
eval_result_t res = parser.eval_node(source, node, block_type_t::top, lineage);
eval_result_t res = parser.eval_node(source, node, lineage);
switch (res) {
case eval_result_t::ok:
case eval_result_t::error:
@@ -758,8 +758,7 @@ static proc_performer_t get_performer_for_process(process_t *p, const job_t *job
const auto &ld = parser.libdata();
auto saved_exec_count = ld.exec_count;
const block_t *fb = function_prepare_environment(parser, *argv, *props);
auto res = parser.eval_node(props->parsed_source, props->body_node, block_type_t::top,
lineage);
auto res = parser.eval_node(props->parsed_source, props->body_node, lineage);
function_restore_environment(parser, fb);
switch (res) {

View File

@@ -228,7 +228,7 @@ static void source_config_in_directory(const wcstring &dir) {
const wcstring cmd = L"builtin source " + escaped_pathname;
parser_t &parser = parser_t::principal_parser();
set_is_within_fish_initialization(true);
parser.eval(cmd, io_chain_t(), block_type_t::top);
parser.eval(cmd, io_chain_t());
set_is_within_fish_initialization(false);
}
@@ -254,7 +254,7 @@ int run_command_list(std::vector<std::string> *cmds, const io_chain_t &io) {
for (const auto &cmd : *cmds) {
const wcstring cmd_wcs = str2wcstring(cmd);
eval_result_t eval_res = parser.eval(cmd_wcs, io, block_type_t::top);
eval_result_t eval_res = parser.eval(cmd_wcs, io);
res = (eval_res == eval_result_t::ok ? 0 : 1);
}

View File

@@ -1003,17 +1003,16 @@ static void test_parser() {
// Ensure that we don't crash on infinite self recursion and mutual recursion. These must use
// the principal parser because we cannot yet execute jobs on other parsers.
say(L"Testing recursion detection");
parser->eval(L"function recursive ; recursive ; end ; recursive; ", io_chain_t(),
block_type_t::top);
parser->eval(L"function recursive ; recursive ; end ; recursive; ", io_chain_t());
#if 0
// This is disabled since it produces a long backtrace. We should find a way to either visually
// compress the backtrace, or disable error spewing.
parser->.eval(L"function recursive1 ; recursive2 ; end ; "
L"function recursive2 ; recursive1 ; end ; recursive1; ", io_chain_t(), block_type_t::top);
L"function recursive2 ; recursive1 ; end ; recursive1; ", io_chain_t());
#endif
say(L"Testing empty function name");
parser->eval(L"function '' ; echo fail; exit 42 ; end ; ''", io_chain_t(), block_type_t::top);
parser->eval(L"function '' ; echo fail; exit 42 ; end ; ''", io_chain_t());
say(L"Testing eval_args");
completion_list_t comps = parser_t::expand_argument_list(
@@ -1033,8 +1032,7 @@ static void test_1_cancellation(const wchar_t *src) {
usleep(delay * 1E6);
pthread_kill(thread, SIGINT);
});
eval_result_t ret =
parser_t::principal_parser().eval(src, io_chain_t{filler}, block_type_t::top);
eval_result_t ret = parser_t::principal_parser().eval(src, io_chain_t{filler});
auto buffer = io_bufferfill_t::finish(std::move(filler));
if (buffer->buffer().size() != 0) {
err(L"Expected 0 bytes in out_buff, but instead found %lu bytes, for command %ls\n",
@@ -1076,7 +1074,7 @@ static void test_cancellation() {
bool iis = is_interactive_session();
set_interactive_session(true);
const wchar_t *child_self_destructor = L"while true ; sh -c 'sleep .25; kill -s INT $$' ; end";
parser_t::principal_parser().eval(child_self_destructor, io_chain_t(), block_type_t::top);
parser_t::principal_parser().eval(child_self_destructor, io_chain_t());
set_interactive_session(iis);
// Restore signal handling.
@@ -5200,7 +5198,7 @@ static void test_illegal_command_exit_code() {
parser_t &parser = parser_t::principal_parser();
for (const auto &test : tests) {
parser.eval(test.txt, empty_ios, block_type_t::top);
parser.eval(test.txt, empty_ios);
int exit_status = parser.get_last_status();
if (exit_status != test.result) {

View File

@@ -389,7 +389,7 @@ void inputter_t::mapping_execute(const input_mapping_t &m, bool allow_commands)
// see that until all other commands have also been run.
auto last_statuses = parser_->get_last_statuses();
for (const wcstring &cmd : m.commands) {
parser_->eval(cmd, io_chain_t(), block_type_t::top);
parser_->eval(cmd, io_chain_t{});
}
parser_->set_last_statuses(std::move(last_statuses));
event_queue_.push_front(char_event_type_t::check_exit);

View File

@@ -634,14 +634,14 @@ eval_result_t parser_t::eval(parsed_source_ref_t ps, const io_chain_t &io,
lineage.block_io = io;
// Execute the first node.
tnode_t<grammar::job_list> start{&ps->tree, &ps->tree.front()};
return this->eval_node(ps, start, block_type, std::move(lineage));
return this->eval_node(ps, start, std::move(lineage), block_type);
}
return eval_result_t::ok;
}
template <typename T>
eval_result_t parser_t::eval_node(parsed_source_ref_t ps, tnode_t<T> node, block_type_t block_type,
job_lineage_t lineage) {
eval_result_t parser_t::eval_node(parsed_source_ref_t ps, tnode_t<T> node, job_lineage_t lineage,
block_type_t block_type) {
static_assert(
std::is_same<T, grammar::statement>::value || std::is_same<T, grammar::job_list>::value,
"Unexpected node type");
@@ -684,9 +684,9 @@ eval_result_t parser_t::eval_node(parsed_source_ref_t ps, tnode_t<T> node, block
// Explicit instantiations. TODO: use overloads instead?
template eval_result_t parser_t::eval_node(parsed_source_ref_t, tnode_t<grammar::statement>,
enum block_type_t, job_lineage_t lineage);
job_lineage_t, block_type_t);
template eval_result_t parser_t::eval_node(parsed_source_ref_t, tnode_t<grammar::job_list>,
enum block_type_t, job_lineage_t lineage);
job_lineage_t, block_type_t);
void parser_t::get_backtrace(const wcstring &src, const parse_error_list_t &errors,
wcstring &output) const {

View File

@@ -259,20 +259,23 @@ class parser_t : public std::enable_shared_from_this<parser_t> {
///
/// \param cmd the string to evaluate
/// \param io io redirections to perform on all started jobs
/// \param block_type The type of block to push on the block stack
/// \param block_type The type of block to push on the block stack, which must be either 'top'
/// or 'subst'.
///
/// \return the eval result,
eval_result_t eval(const wcstring &cmd, const io_chain_t &io, enum block_type_t block_type);
eval_result_t eval(const wcstring &cmd, const io_chain_t &io,
block_type_t block_type = block_type_t::top);
/// Evaluate the parsed source ps.
/// Because the source has been parsed, a syntax error is impossible.
eval_result_t eval(parsed_source_ref_t ps, const io_chain_t &io, enum block_type_t block_type);
eval_result_t eval(parsed_source_ref_t ps, const io_chain_t &io,
block_type_t block_type = block_type_t::top);
/// Evaluates a node.
/// The node type must be grammar::statement or grammar::job_list.
template <typename T>
eval_result_t eval_node(parsed_source_ref_t ps, tnode_t<T> node, block_type_t block_type,
job_lineage_t lineage);
eval_result_t eval_node(parsed_source_ref_t ps, tnode_t<T> node, job_lineage_t lineage,
block_type_t block_type = block_type_t::top);
/// Evaluate line as a list of parameters, i.e. tokenize it and perform parameter expansion and
/// cmdsubst execution on the tokens. Errors are ignored. If a parser is provided, it is used

View File

@@ -1952,7 +1952,7 @@ void reader_run_command(parser_t &parser, const wcstring &cmd) {
gettimeofday(&time_before, nullptr);
parser.eval(cmd, io_chain_t(), block_type_t::top);
parser.eval(cmd, io_chain_t{});
job_reap(parser, true);
gettimeofday(&time_after, nullptr);
@@ -3551,7 +3551,7 @@ static int read_ni(parser_t &parser, int fd, const io_chain_t &io) {
parsed_source_ref_t pstree;
if (!parse_util_detect_errors(str, &errors, false /* do not accept incomplete */,
&pstree)) {
parser.eval(pstree, io, block_type_t::top);
parser.eval(pstree, io);
} else {
wcstring sb;
parser.get_backtrace(str, errors, sb);