mirror of
https://github.com/fish-shell/fish-shell.git
synced 2024-11-22 13:18:59 +08:00
Additional changes related to https://github.com/fish-shell/fish-shell/pull/592
This commit is contained in:
parent
c55cbd3f2f
commit
94b1d58cc2
18
common.h
18
common.h
|
@ -455,35 +455,33 @@ public:
|
|||
template <typename T>
|
||||
class scoped_push
|
||||
{
|
||||
T &ref;
|
||||
T * const ref;
|
||||
T saved_value;
|
||||
bool restored;
|
||||
|
||||
public:
|
||||
scoped_push(T &r):
|
||||
ref(r), restored(false)
|
||||
scoped_push(T *r): ref(r), saved_value(*r), restored(false)
|
||||
{
|
||||
saved_value = ref;
|
||||
}
|
||||
|
||||
scoped_push(T &r, T new_value):
|
||||
ref(r), restored(false)
|
||||
scoped_push(T *r, const T &new_value) : ref(r), saved_value(*r), restored(false)
|
||||
{
|
||||
saved_value = ref;
|
||||
ref = new_value;
|
||||
*r = new_value;
|
||||
}
|
||||
|
||||
~scoped_push()
|
||||
{
|
||||
if (!restored)
|
||||
restore();
|
||||
}
|
||||
|
||||
void restore()
|
||||
{
|
||||
ref = saved_value;
|
||||
if (!restored)
|
||||
{
|
||||
std::swap(*ref, saved_value);
|
||||
restored = true;
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
|
|
28
parser.cpp
28
parser.cpp
|
@ -746,8 +746,8 @@ int parser_t::eval_args(const wchar_t *line, std::vector<completion_t> &args)
|
|||
eval_args may be called while evaulating another command, so we
|
||||
save the previous tokenizer and restore it on exit
|
||||
*/
|
||||
scoped_push<tokenizer_t*> tokenizer_push(current_tokenizer, &tok);
|
||||
scoped_push<int> tokenizer_pos_push(current_tokenizer_pos, 0);
|
||||
scoped_push<tokenizer_t*> tokenizer_push(¤t_tokenizer, &tok);
|
||||
scoped_push<int> tokenizer_pos_push(¤t_tokenizer_pos, 0);
|
||||
|
||||
error_code=0;
|
||||
|
||||
|
@ -1557,7 +1557,8 @@ void parser_t::parse_job_argument_list(process_t *p,
|
|||
}
|
||||
}
|
||||
|
||||
if (new_io.get() != NULL) {
|
||||
if (new_io.get() != NULL)
|
||||
{
|
||||
j->io.push_back(new_io);
|
||||
}
|
||||
|
||||
|
@ -1648,7 +1649,7 @@ int parser_t::parse_job(process_t *p,
|
|||
bool allow_bogus_command = false; // If we are an elseif that will not be executed, or an AND or OR that will have been short circuited, don't complain about non-existent commands
|
||||
|
||||
block_t *prev_block = current_block;
|
||||
scoped_push<int> tokenizer_pos_push(current_tokenizer_pos, tok_get_pos(tok));
|
||||
scoped_push<int> tokenizer_pos_push(¤t_tokenizer_pos, tok_get_pos(tok));
|
||||
|
||||
while (args.empty())
|
||||
{
|
||||
|
@ -2410,7 +2411,7 @@ void parser_t::eval_job(tokenizer_t *tok)
|
|||
int was_builtin = 0;
|
||||
if (j->first_process->type==INTERNAL_BUILTIN && !j->first_process->next)
|
||||
was_builtin = 1;
|
||||
scoped_push<int> tokenizer_pos_push(current_tokenizer_pos, job_begin_pos);
|
||||
scoped_push<int> tokenizer_pos_push(¤t_tokenizer_pos, job_begin_pos);
|
||||
exec(*this, j);
|
||||
|
||||
/* Only external commands require a new fishd barrier */
|
||||
|
@ -2552,9 +2553,9 @@ int parser_t::eval(const wcstring &cmdStr, const io_chain_t &io, enum block_type
|
|||
block_t *start_current_block = current_block;
|
||||
|
||||
/* Record the current chain so we can put it back later */
|
||||
scoped_push<io_chain_t> block_io_push(block_io, io);
|
||||
scoped_push<io_chain_t> block_io_push(&block_io, io);
|
||||
|
||||
scoped_push<std::vector<wcstring> > forbidden_function_push(forbidden_function);
|
||||
scoped_push<wcstring_list_t> forbidden_function_push(&forbidden_function);
|
||||
|
||||
if (block_type == SUBST)
|
||||
{
|
||||
|
@ -2591,7 +2592,8 @@ int parser_t::eval(const wcstring &cmdStr, const io_chain_t &io, enum block_type
|
|||
|
||||
this->push_block(new scope_block_t(block_type));
|
||||
|
||||
scoped_push<tokenizer_t*> tokenizer_push(current_tokenizer, new tokenizer_t(cmd, 0));
|
||||
tokenizer_t local_tokenizer(cmd, 0);
|
||||
scoped_push<tokenizer_t *> tokenizer_push(¤t_tokenizer, &local_tokenizer);
|
||||
|
||||
error_code = 0;
|
||||
|
||||
|
@ -2641,7 +2643,7 @@ int parser_t::eval(const wcstring &cmdStr, const io_chain_t &io, enum block_type
|
|||
|
||||
this->print_errors_stderr();
|
||||
|
||||
delete current_tokenizer;
|
||||
tokenizer_push.restore();
|
||||
|
||||
while (forbidden_function.size() > forbid_count)
|
||||
parser_t::allow_function();
|
||||
|
@ -2819,8 +2821,8 @@ int parser_t::test_args(const wchar_t * buff, wcstring *out, const wchar_t *pre
|
|||
CHECK(buff, 1);
|
||||
|
||||
tokenizer_t tok(buff, 0);
|
||||
scoped_push<tokenizer_t*> tokenizer_push(current_tokenizer, &tok);
|
||||
scoped_push<int> tokenizer_pos_push(current_tokenizer_pos);
|
||||
scoped_push<tokenizer_t*> tokenizer_push(¤t_tokenizer, &tok);
|
||||
scoped_push<int> tokenizer_pos_push(¤t_tokenizer_pos);
|
||||
|
||||
for (; do_loop && tok_has_next(&tok); tok_next(&tok))
|
||||
{
|
||||
|
@ -2946,8 +2948,8 @@ int parser_t::test(const wchar_t *buff, int *block_level, wcstring *out, const w
|
|||
|
||||
tokenizer_t tok(buff, 0);
|
||||
|
||||
scoped_push<tokenizer_t*> tokenizer_push(current_tokenizer, &tok);
|
||||
scoped_push<int> tokenizer_pos_push(current_tokenizer_pos);
|
||||
scoped_push<tokenizer_t*> tokenizer_push(¤t_tokenizer, &tok);
|
||||
scoped_push<int> tokenizer_pos_push(¤t_tokenizer_pos);
|
||||
|
||||
for (;; tok_next(&tok))
|
||||
{
|
||||
|
|
Loading…
Reference in New Issue
Block a user