Mercurial > hg > octave-nkf
changeset 16126:5c885c13bfa3
localize use of yylval.tok_val in lexical_feedback member functions
* lex.h, lex.ll (lexical_feedback::push_token): New function.
(lexical_feedback::current_token): New function.
(lexical_feedback::token_stack): Now private.
* lex.ll (TOK_PUSH_AND_RETURN, BIN_OP_RETURN_INTERNAL,
lexical_feedback::is_keyword_token, lexical_feedback::handle_number,
lexical_feedback::handle_string,
lexical_feedback::handle_superclass_identifier,
lexical_feedback::handle_meta_identifier,
lexical_feedback::handle_identifier, lexical_feedback::display_token):
Use push_token and current_token instead of accessing yylval.tok_val
directly.
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Tue, 26 Feb 2013 15:13:43 -0500 |
parents | 96a58f197f93 |
children | f7eb13f14320 |
files | libinterp/parse-tree/lex.h libinterp/parse-tree/lex.ll |
diffstat | 2 files changed, 86 insertions(+), 72 deletions(-) [+] |
line wrap: on
line diff
--- a/libinterp/parse-tree/lex.h +++ b/libinterp/parse-tree/lex.h @@ -283,6 +283,10 @@ void gripe_matlab_incompatible_operator (const std::string& op); + void push_token (token *); + + token *current_token (void); + void display_token (int tok); void lexer_debug (const char *pattern, const char *text); @@ -383,16 +387,16 @@ // a paren? bbp_nesting_level nesting_level; + // For unwind protect. + static void cleanup (lexical_feedback *lexer) { delete lexer; } + +private: + // Stack to hold tokens so that we can delete them when the parser is // reset and avoid growing forever just because we are stashing some // information. std::stack <token*> token_stack; - // For unwind protect. - static void cleanup (lexical_feedback *lexer) { delete lexer; } - -private: - // No copying! lexical_feedback (const lexical_feedback&);
--- a/libinterp/parse-tree/lex.ll +++ b/libinterp/parse-tree/lex.ll @@ -158,9 +158,9 @@ #define TOK_PUSH_AND_RETURN(name, tok) \ do \ { \ - yylval.tok_val = new token (name, curr_lexer->input_line_number, \ - curr_lexer->current_input_column); \ - curr_lexer->token_stack.push (yylval.tok_val); \ + curr_lexer->push_token \ + (new token (name, curr_lexer->input_line_number, \ + curr_lexer->current_input_column)); \ TOK_RETURN (tok); \ } \ while (0) @@ -168,9 +168,9 @@ #define BIN_OP_RETURN_INTERNAL(tok, convert, bos, qit) \ do \ { \ - yylval.tok_val = new token (curr_lexer->input_line_number, \ - curr_lexer->current_input_column); \ - curr_lexer->token_stack.push (yylval.tok_val); \ + curr_lexer->push_token \ + (new token (curr_lexer->input_line_number, \ + curr_lexer->current_input_column)); \ curr_lexer->current_input_column += yyleng; \ curr_lexer->quote_is_transpose = qit; \ curr_lexer->convert_spaces_to_comma = convert; \ @@ -1617,7 +1617,7 @@ if (kw) { - yylval.tok_val = 0; + token *tok_val = 0; switch (kw->kw_id) { @@ -1662,72 +1662,72 @@ || parsed_function_name.top ())))) return 0; - yylval.tok_val = new token (token::simple_end, l, c); + tok_val = new token (token::simple_end, l, c); at_beginning_of_statement = true; break; case end_try_catch_kw: - yylval.tok_val = new token (token::try_catch_end, l, c); + tok_val = new token (token::try_catch_end, l, c); at_beginning_of_statement = true; break; case end_unwind_protect_kw: - yylval.tok_val = new token (token::unwind_protect_end, l, c); + tok_val = new token (token::unwind_protect_end, l, c); at_beginning_of_statement = true; break; case endfor_kw: - yylval.tok_val = new token (token::for_end, l, c); + tok_val = new token (token::for_end, l, c); at_beginning_of_statement = true; break; case endfunction_kw: - yylval.tok_val = new token (token::function_end, l, c); + tok_val = new token (token::function_end, l, c); at_beginning_of_statement = true; break; case endif_kw: - yylval.tok_val = new token (token::if_end, l, c); + tok_val = new token (token::if_end, l, c); at_beginning_of_statement = true; break; case endparfor_kw: - yylval.tok_val = new token (token::parfor_end, l, c); + tok_val = new token (token::parfor_end, l, c); at_beginning_of_statement = true; break; case endswitch_kw: - yylval.tok_val = new token (token::switch_end, l, c); + tok_val = new token (token::switch_end, l, c); at_beginning_of_statement = true; break; case endwhile_kw: - yylval.tok_val = new token (token::while_end, l, c); + tok_val = new token (token::while_end, l, c); at_beginning_of_statement = true; break; case endclassdef_kw: - yylval.tok_val = new token (token::classdef_end, l, c); + tok_val = new token (token::classdef_end, l, c); at_beginning_of_statement = true; break; case endenumeration_kw: - yylval.tok_val = new token (token::enumeration_end, l, c); + tok_val = new token (token::enumeration_end, l, c); at_beginning_of_statement = true; break; case endevents_kw: - yylval.tok_val = new token (token::events_end, l, c); + tok_val = new token (token::events_end, l, c); at_beginning_of_statement = true; break; case endmethods_kw: - yylval.tok_val = new token (token::methods_end, l, c); + tok_val = new token (token::methods_end, l, c); at_beginning_of_statement = true; break; case endproperties_kw: - yylval.tok_val = new token (token::properties_end, l, c); + tok_val = new token (token::properties_end, l, c); at_beginning_of_statement = true; break; @@ -1795,24 +1795,24 @@ if ((reading_fcn_file || reading_script_file || reading_classdef_file) && ! curr_fcn_file_full_name.empty ()) - yylval.tok_val = new token (curr_fcn_file_full_name, l, c); + tok_val = new token (curr_fcn_file_full_name, l, c); else - yylval.tok_val = new token ("stdin", l, c); + tok_val = new token ("stdin", l, c); } break; case magic_line_kw: - yylval.tok_val = new token (static_cast<double> (l), "", l, c); + tok_val = new token (static_cast<double> (l), "", l, c); break; default: panic_impossible (); } - if (! yylval.tok_val) - yylval.tok_val = new token (l, c); - - token_stack.push (yylval.tok_val); + if (! tok_val) + tok_val = new token (l, c); + + curr_lexer->push_token (tok_val); return kw->tok; } @@ -2501,10 +2501,8 @@ looking_for_object_index = false; at_beginning_of_statement = false; - yylval.tok_val = new token (value, yytext, input_line_number, - current_input_column); - - token_stack.push (yylval.tok_val); + curr_lexer->push_token (new token (value, yytext, input_line_number, + current_input_column)); current_input_column += yyleng; @@ -2718,8 +2716,7 @@ quote_is_transpose = true; convert_spaces_to_comma = true; - yylval.tok_val = new token (s, bos_line, bos_col); - token_stack.push (yylval.tok_val); + curr_lexer->push_token (new token (s, bos_line, bos_col)); if (delim == '"') gripe_matlab_incompatible ("\" used as string delimiter"); @@ -3231,13 +3228,11 @@ return LEXICAL_ERROR; } - yylval.tok_val - = new token (meth.empty () ? 0 : &(symbol_table::insert (meth)), - cls.empty () ? 0 : &(symbol_table::insert (cls)), - pkg.empty () ? 0 : &(symbol_table::insert (pkg)), - input_line_number, - current_input_column); - token_stack.push (yylval.tok_val); + curr_lexer->push_token + (new token (meth.empty () ? 0 : &(symbol_table::insert (meth)), + cls.empty () ? 0 : &(symbol_table::insert (cls)), + pkg.empty () ? 0 : &(symbol_table::insert (pkg)), + input_line_number, current_input_column)); convert_spaces_to_comma = true; current_input_column += yyleng; @@ -3267,13 +3262,10 @@ return LEXICAL_ERROR; } - yylval.tok_val - = new token (cls.empty () ? 0 : &(symbol_table::insert (cls)), - pkg.empty () ? 0 : &(symbol_table::insert (pkg)), - input_line_number, - current_input_column); - - token_stack.push (yylval.tok_val); + curr_lexer->push_token + (new token (cls.empty () ? 0 : &(symbol_table::insert (cls)), + pkg.empty () ? 0 : &(symbol_table::insert (pkg)), + input_line_number, current_input_column)); convert_spaces_to_comma = true; current_input_column += yyleng; @@ -3309,10 +3301,8 @@ maybe_unput_comma (spc_gobbled); - yylval.tok_val = new token (tok, input_line_number, - current_input_column); - - token_stack.push (yylval.tok_val); + curr_lexer->push_token (new token (tok, input_line_number, + current_input_column)); quote_is_transpose = true; convert_spaces_to_comma = true; @@ -3346,10 +3336,8 @@ } else { - yylval.tok_val = new token (tok, input_line_number, - current_input_column); - - token_stack.push (yylval.tok_val); + curr_lexer->push_token (new token (tok, input_line_number, + current_input_column)); current_input_column += yyleng; quote_is_transpose = false; @@ -3429,11 +3417,8 @@ if (tok == "end") tok = "__end__"; - yylval.tok_val = new token (&(symbol_table::insert (tok)), - input_line_number, - current_input_column); - - token_stack.push (yylval.tok_val); + curr_lexer->push_token (new token (&(symbol_table::insert (tok)), + input_line_number, current_input_column)); // After seeing an identifer, it is ok to convert spaces to a comma // (if needed). @@ -3526,6 +3511,19 @@ } void +lexical_feedback::push_token (token *tok) +{ + yylval.tok_val = tok; + token_stack.push (tok); +} + +token * +lexical_feedback::current_token (void) +{ + return yylval.tok_val; +} + +void lexical_feedback::display_token (int tok) { switch (tok) @@ -3578,16 +3576,24 @@ case NUM: case IMAG_NUM: - std::cerr << (tok == NUM ? "NUM" : "IMAG_NUM") - << " [" << yylval.tok_val->number () << "]\n"; + { + token *tok_val = curr_lexer->current_token (); + std::cerr << (tok == NUM ? "NUM" : "IMAG_NUM") + << " [" << tok_val->number () << "]\n"; + } break; case STRUCT_ELT: - std::cerr << "STRUCT_ELT [" << yylval.tok_val->text () << "]\n"; break; + { + token *tok_val = curr_lexer->current_token (); + std::cerr << "STRUCT_ELT [" << tok_val->text () << "]\n"; + } + break; case NAME: { - symbol_table::symbol_record *sr = yylval.tok_val->sym_rec (); + token *tok_val = curr_lexer->current_token (); + symbol_table::symbol_record *sr = tok_val->sym_rec (); std::cerr << "NAME"; if (sr) std::cerr << " [" << sr->name () << "]"; @@ -3599,8 +3605,12 @@ case DQ_STRING: case SQ_STRING: - std::cerr << (tok == DQ_STRING ? "DQ_STRING" : "SQ_STRING") - << " [" << yylval.tok_val->text () << "]\n"; + { + token *tok_val = curr_lexer->current_token (); + + std::cerr << (tok == DQ_STRING ? "DQ_STRING" : "SQ_STRING") + << " [" << tok_val->text () << "]\n"; + } break; case FOR: std::cerr << "FOR\n"; break;