From 8ec73b2dd40bf95d2b665cfb4cc22c26a2717cae Mon Sep 17 00:00:00 2001 From: ridiculousfish Date: Sun, 16 Mar 2014 14:49:51 -0700 Subject: [PATCH] Removing some variables from parser_t that are no longer used in the new execution model --- parser.cpp | 40 ++++++++++++---------------------------- parser.h | 24 +----------------------- 2 files changed, 13 insertions(+), 51 deletions(-) diff --git a/parser.cpp b/parser.cpp index 8513d5300..9db079032 100644 --- a/parser.cpp +++ b/parser.cpp @@ -199,10 +199,7 @@ parser_t::parser_t(enum parser_type_t type, bool errors) : cancellation_requested(false), is_within_fish_initialization(false), current_tokenizer(NULL), - current_tokenizer_pos(0), - job_start_pos(0), - eval_level(-1), - block_io(shared_ptr()) + current_tokenizer_pos(0) { } @@ -497,7 +494,7 @@ void parser_t::print_errors(wcstring &target, const wchar_t *prefix) tmp = current_tokenizer_pos; current_tokenizer_pos = err_pos; - append_format(target, L"%ls", this->current_line()); + target.append(this->current_line()); current_tokenizer_pos=tmp; } @@ -516,11 +513,11 @@ void parser_t::print_errors_stderr() tmp = current_tokenizer_pos; current_tokenizer_pos = err_pos; - fwprintf(stderr, L"%ls", this->current_line()); + wcstring current_line = this->current_line(); + fwprintf(stderr, L"%ls", current_line.c_str()); current_tokenizer_pos=tmp; } - } void parser_t::eval_args(const wchar_t *line, std::vector &args) @@ -635,7 +632,7 @@ void parser_t::stack_trace(size_t block_idx, wcstring &buff) const return; } - if (b->type() == FUNCTION_CALL || b->type()==SOURCE || b->type()==SUBST) + if (b->type() == FUNCTION_CALL || b->type() == FUNCTION_CALL_NO_SHADOW || b->type()==SOURCE || b->type()==SUBST) { /* These types of blocks should be printed @@ -653,6 +650,7 @@ void parser_t::stack_trace(size_t block_idx, wcstring &buff) const break; } case FUNCTION_CALL: + case FUNCTION_CALL_NO_SHADOW: { const function_block_t *fb = static_cast(b); append_format(buff, _(L"in function '%ls'\n"), fb->name.c_str()); @@ -728,7 +726,7 @@ const wchar_t *parser_t::is_function() const for (size_t block_idx = 0; block_idx < this->block_count(); block_idx++) { const block_t *b = this->block_at_index(block_idx); - if (b->type() == FUNCTION_CALL) + if (b->type() == FUNCTION_CALL || b->type() == FUNCTION_CALL_NO_SHADOW) { const function_block_t *fb = static_cast(b); result = fb->name.c_str(); @@ -766,6 +764,7 @@ const wchar_t *parser_t::current_filename() const for (size_t i=0; i < this->block_count(); i++) { const block_t *b = this->block_at_index(i); + /* Note that we deliberately skip FUNCTION_CALL_NO_SHADOW here, because the only such functions in wide use are '.' and eval, and we don't want to report those */ if (b->type() == FUNCTION_CALL) { const function_block_t *fb = static_cast(b); @@ -809,8 +808,10 @@ static int printed_width(const wchar_t *str, int len) } -const wchar_t *parser_t::current_line() +wcstring parser_t::current_line() { + wcstring lineinfo; + int lineno=1; const wchar_t *file; @@ -836,8 +837,6 @@ const wchar_t *parser_t::current_line() return L""; - lineinfo.clear(); - /* Calculate line number, line offset, etc. */ @@ -923,24 +922,9 @@ const wchar_t *parser_t::current_line() free((void *)line); parser_t::stack_trace(0, lineinfo); - return lineinfo.c_str(); + return lineinfo; } -int parser_t::get_pos() const -{ - return tok_get_pos(current_tokenizer); -} - -int parser_t::get_job_pos() const -{ - return job_start_pos; -} - - -void parser_t::set_pos(int p) -{ - tok_set_pos(current_tokenizer, p); -} const wchar_t *parser_t::get_buffer() const { diff --git a/parser.h b/parser.h index 446c84ee8..4011b95da 100644 --- a/parser.h +++ b/parser.h @@ -260,31 +260,18 @@ private: /** Pointer to the current tokenizer */ tokenizer_t *current_tokenizer; - /** String for representing the current line */ - wcstring lineinfo; - /** This is the position of the beginning of the currently parsed command */ int current_tokenizer_pos; /** List of called functions, used to help prevent infinite recursion */ wcstring_list_t forbidden_function; - /** String index where the current job started. */ - int job_start_pos; - /** The jobs associated with this parser */ job_list_t my_job_list; /** The list of blocks, allocated with new. It's our responsibility to delete these */ std::vector block_stack; - /** - Keeps track of how many recursive eval calls have been made. Eval - doesn't call itself directly, recursion happens on blocks and on - command substitutions. - */ - int eval_level; - /* No copying allowed */ parser_t(const parser_t&); parser_t& operator=(const parser_t&); @@ -371,7 +358,7 @@ public: init.fish (line 127): ls|grep pancake */ - const wchar_t *current_line(); + wcstring current_line(); /** Returns the current line number */ int get_lineno() const; @@ -379,15 +366,6 @@ public: /** Returns the line number for the character at the given index */ int line_number_of_character_at_offset(size_t idx) const; - /** Returns the current position in the latest string of the tokenizer. */ - int get_pos() const; - - /** Returns the position where the current job started in the latest string of the tokenizer. */ - int get_job_pos() const; - - /** Set the current position in the latest string of the tokenizer. */ - void set_pos(int p); - /** Returns the block at the given index. 0 corresponds to the innermost block. Returns NULL when idx is at or equal to the number of blocks. */ const block_t *block_at_index(size_t idx) const; block_t *block_at_index(size_t idx);