# HG changeset patch # User John W. Eaton # Date 1709238748 18000 # Node ID 9acadc2d83369d67e3d36591cf8ab87aeaee2853 # Parent 4cae6d1e51225c9472a2186ab1cef4206742f5d7# Parent 985d25d4eafdcf99101d40d08fa9c3ead96b23a8 maint: merge default to bytecode-interpreter diff -r 4cae6d1e5122 -r 9acadc2d8336 libinterp/parse-tree/lex.ll --- a/libinterp/parse-tree/lex.ll Thu Feb 29 13:55:38 2024 -0500 +++ b/libinterp/parse-tree/lex.ll Thu Feb 29 15:32:28 2024 -0500 @@ -991,10 +991,8 @@ curr_lexer->m_looking_for_object_index = true; curr_lexer->m_at_beginning_of_statement = false; - curr_lexer->push_token (new octave::token (DQ_STRING, - curr_lexer->m_string_text, - curr_lexer->m_tok_beg, - curr_lexer->m_tok_end)); + octave::token *tok = new octave::token (DQ_STRING, curr_lexer->m_string_text, curr_lexer->m_tok_beg, curr_lexer->m_tok_end); + curr_lexer->push_token (tok); curr_lexer->m_string_text = ""; @@ -1013,10 +1011,8 @@ if (result > 0xff) { // Use location of octal digits for error token. - octave::token *tok - = new octave::token (LEXICAL_ERROR, - "invalid octal escape sequence in character string", - curr_lexer->m_tok_beg, curr_lexer->m_tok_end); + std::string msg {"invalid octal escape sequence in character string"}; + octave::token *tok = new octave::token (LEXICAL_ERROR, msg, curr_lexer->m_tok_beg, curr_lexer->m_tok_end); curr_lexer->push_token (tok); @@ -1121,10 +1117,8 @@ curr_lexer->lexer_debug ("{NL}"); // Use current file position for error token. - octave::token *tok - = new octave::token (LEXICAL_ERROR, - "unterminated character string constant", - curr_lexer->m_filepos, curr_lexer->m_filepos); + std::string msg {"unterminated character string constant"}; + octave::token *tok = new octave::token (LEXICAL_ERROR, msg, curr_lexer->m_filepos, curr_lexer->m_filepos); curr_lexer->push_token (tok); @@ -1158,10 +1152,9 @@ curr_lexer->m_looking_for_object_index = true; curr_lexer->m_at_beginning_of_statement = false; - curr_lexer->push_token (new octave::token (SQ_STRING, - curr_lexer->m_string_text, - curr_lexer->m_tok_beg, - curr_lexer->m_tok_end)); + octave::token *tok = new octave::token (SQ_STRING, curr_lexer->m_string_text, curr_lexer->m_tok_beg, curr_lexer->m_tok_end); + + curr_lexer->push_token (tok); curr_lexer->m_string_text = ""; @@ -1180,10 +1173,8 @@ curr_lexer->lexer_debug ("{NL}"); // Use current file position for error token. - octave::token *tok - = new octave::token (LEXICAL_ERROR, - "unterminated character string constant", - curr_lexer->m_filepos, curr_lexer->m_filepos); + std::string msg {"unterminated character string constant"}; + octave::token *tok = new octave::token (LEXICAL_ERROR, msg, curr_lexer->m_filepos, curr_lexer->m_filepos); curr_lexer->push_token (tok); @@ -1421,17 +1412,15 @@ octave::token *tok; if (octave::iskeyword (ident)) - tok = new octave::token (LEXICAL_ERROR, - "function handles may not refer to keywords", - curr_lexer->m_tok_beg, - curr_lexer->m_tok_end); + { + std::string msg {"function handles may not refer to keywords"}; + tok = new octave::token (LEXICAL_ERROR, msg, curr_lexer->m_tok_beg, curr_lexer->m_tok_end); + } else { curr_lexer->m_looking_for_object_index = true; - tok = new octave::token (FCN_HANDLE, ident, - curr_lexer->m_tok_beg, - curr_lexer->m_tok_end); + tok = new octave::token (FCN_HANDLE, ident, curr_lexer->m_tok_beg, curr_lexer->m_tok_end); } curr_lexer->push_token (tok); @@ -1475,10 +1464,8 @@ curr_lexer->m_filepos.next_line (); // Use current file position for error token. - octave::token *tok - = new octave::token (LEXICAL_ERROR, - "unexpected internal lexer error", - curr_lexer->m_filepos, curr_lexer->m_filepos); + std::string msg {"unexpected internal lexer error"}; + octave::token *tok = new octave::token (LEXICAL_ERROR, msg, curr_lexer->m_filepos, curr_lexer->m_filepos); curr_lexer->push_token (tok); @@ -1881,9 +1868,8 @@ << "' (ASCII " << c << ")"; // Use current file position for error token. - octave::token *tok - = new octave::token (LEXICAL_ERROR, buf.str (), - curr_lexer->m_filepos, curr_lexer->m_filepos); + std::string msg {"unexpected internal lexer error"}; + octave::token *tok = new octave::token (LEXICAL_ERROR, buf.str (), msg, curr_lexer->m_filepos, curr_lexer->m_filepos); curr_lexer->push_token (tok); @@ -2673,14 +2659,12 @@ break; case end_try_catch_kw: - tok_val = new token (kw->tok, token::try_catch_end, m_tok_beg, - m_tok_end); + tok_val = new token (kw->tok, token::try_catch_end, m_tok_beg, m_tok_end); m_at_beginning_of_statement = true; break; case end_unwind_protect_kw: - tok_val = new token (kw->tok, token::unwind_protect_end, m_tok_beg, - m_tok_end); + tok_val = new token (kw->tok, token::unwind_protect_end, m_tok_beg, m_tok_end); m_at_beginning_of_statement = true; break; @@ -2690,8 +2674,7 @@ break; case endfunction_kw: - tok_val = new token (kw->tok, token::function_end, m_tok_beg, - m_tok_end); + tok_val = new token (kw->tok, token::function_end, m_tok_beg, m_tok_end); m_at_beginning_of_statement = true; break; @@ -2719,39 +2702,33 @@ #if defined (DISABLE_ARGUMENTS_VALIDATION_BLOCK) return 0; #else - tok_val = new token (kw->tok, token::arguments_end, m_tok_beg, - m_tok_end); + tok_val = new token (kw->tok, token::arguments_end, m_tok_beg, m_tok_end); m_at_beginning_of_statement = true; break; #endif case endclassdef_kw: - tok_val = new token (kw->tok, token::classdef_end, m_tok_beg, - m_tok_end); + tok_val = new token (kw->tok, token::classdef_end, m_tok_beg, m_tok_end); m_at_beginning_of_statement = true; break; case endenumeration_kw: - tok_val = new token (kw->tok, token::enumeration_end, m_tok_beg, - m_tok_end); + tok_val = new token (kw->tok, token::enumeration_end, m_tok_beg, m_tok_end); m_at_beginning_of_statement = true; break; case endevents_kw: - tok_val = new token (kw->tok, token::events_end, m_tok_beg, - m_tok_end); + tok_val = new token (kw->tok, token::events_end, m_tok_beg, m_tok_end); m_at_beginning_of_statement = true; break; case endmethods_kw: - tok_val = new token (kw->tok, token::methods_end, m_tok_beg, - m_tok_end); + tok_val = new token (kw->tok, token::methods_end, m_tok_beg, m_tok_end); m_at_beginning_of_statement = true; break; case endproperties_kw: - tok_val = new token (kw->tok, token::properties_end, m_tok_beg, - m_tok_end); + tok_val = new token (kw->tok, token::properties_end, m_tok_beg, m_tok_end); m_at_beginning_of_statement = true; break; @@ -2863,8 +2840,7 @@ if ((m_reading_fcn_file || m_reading_script_file || m_reading_classdef_file) && ! m_fcn_file_full_name.empty ()) - tok_val = new token (kw->tok, m_fcn_file_full_name, - m_tok_beg, m_tok_end); + tok_val = new token (kw->tok, m_fcn_file_full_name, m_tok_beg, m_tok_end); else tok_val = new token (kw->tok, "stdin", m_tok_beg, m_tok_end); } @@ -3043,10 +3019,8 @@ if (bytes < 0) { - token *tok - = new token (LEXICAL_ERROR, - "too many digits for binary constant", - m_tok_beg, m_tok_end); + std::string msg {"too many digits for binary constant"}; + token *tok = new token (LEXICAL_ERROR, msg, m_tok_beg, m_tok_end); push_token (tok); @@ -3251,10 +3225,8 @@ if (bytes < 0) { - token *tok - = new token (LEXICAL_ERROR, - "too many digits for hexadecimal constant", - m_tok_beg, m_tok_end); + std::string msg {"too many digits for hexadecimal constant"}; + token *tok = new token (LEXICAL_ERROR, msg, m_tok_beg, m_tok_end); push_token (tok); @@ -3416,10 +3388,8 @@ if (iskeyword (meth) || fq_identifier_contains_keyword (cls)) { - token *tok - = new token (LEXICAL_ERROR, - "method, class, and package names may not be keywords", - m_tok_beg, m_tok_end); + std::string msg {"method, class, and package names may not be keywords"}; + token *tok = new token (LEXICAL_ERROR, msg, m_tok_beg, m_tok_end); push_token (tok); @@ -3449,9 +3419,9 @@ if (fq_identifier_contains_keyword (cls)) { - token *tok = new token (LEXICAL_ERROR, - "class and package names may not be keywords", - m_tok_beg, m_tok_end); + std::string msg {"class and package names may not be keywords"}; + token *tok = new token (LEXICAL_ERROR, msg, m_tok_beg, m_tok_end); + push_token (tok); return count_token_internal (LEXICAL_ERROR); @@ -3477,10 +3447,8 @@ if (fq_identifier_contains_keyword (txt)) { - token *tok - = new token (LEXICAL_ERROR, - "function, method, class, and package names may not be keywords", - m_tok_beg, m_tok_end); + std::string msg {"function, method, class, and package names may not be keywords"}; + token *tok = new token (LEXICAL_ERROR, msg, m_tok_beg, m_tok_end); push_token (tok); diff -r 4cae6d1e5122 -r 9acadc2d8336 libinterp/parse-tree/token.h --- a/libinterp/parse-tree/token.h Thu Feb 29 13:55:38 2024 -0500 +++ b/libinterp/parse-tree/token.h Thu Feb 29 15:32:28 2024 -0500 @@ -71,52 +71,34 @@ while_end, }; +public: + token (int tv, const filepos& beg_pos, const filepos& end_pos) - : m_maybe_cmd (false), m_tspc (false), m_beg_pos (beg_pos), - m_end_pos (end_pos), m_tok_val (tv), m_type_tag (generic_token), - m_tok_info (), m_orig_text () + : m_beg_pos (beg_pos), m_end_pos (end_pos), m_tok_val (tv) { } - token (int tv, bool is_kw, const filepos& beg_pos, - const filepos& end_pos) - : m_maybe_cmd (false), m_tspc (false), m_beg_pos (beg_pos), - m_end_pos (end_pos), m_tok_val (tv), - m_type_tag (is_kw ? keyword_token : generic_token), m_tok_info (), - m_orig_text () + token (int tv, bool is_kw, const filepos& beg_pos, const filepos& end_pos) + : m_beg_pos (beg_pos), m_end_pos (end_pos), m_tok_val (tv), m_type_tag (is_kw ? keyword_token : generic_token) { } - token (int tv, const char *s, const filepos& beg_pos, - const filepos& end_pos) - : m_maybe_cmd (false), m_tspc (false), m_beg_pos (beg_pos), - m_end_pos (end_pos), m_tok_val (tv), m_type_tag (string_token), - m_tok_info (s), m_orig_text () + token (int tv, const char *s, const filepos& beg_pos, const filepos& end_pos) + : m_beg_pos (beg_pos), m_end_pos (end_pos), m_tok_val (tv), m_type_tag (string_token), m_tok_info (s) { } - token (int tv, const std::string& s, const filepos& beg_pos, - const filepos& end_pos) - : m_maybe_cmd (false), m_tspc (false), m_beg_pos (beg_pos), - m_end_pos (end_pos), m_tok_val (tv), m_type_tag (string_token), - m_tok_info (s), m_orig_text () + token (int tv, const std::string& s, const filepos& beg_pos, const filepos& end_pos) + : m_beg_pos (beg_pos), m_end_pos (end_pos), m_tok_val (tv), m_type_tag (string_token), m_tok_info (s) { } - token (int tv, const octave_value& val, const std::string& s, - const filepos& beg_pos, const filepos& end_pos) - : m_maybe_cmd (false), m_tspc (false), m_beg_pos (beg_pos), - m_end_pos (end_pos), m_tok_val (tv), m_type_tag (numeric_token), - m_tok_info (val), m_orig_text (s) + token (int tv, const octave_value& val, const std::string& s, const filepos& beg_pos, const filepos& end_pos) + : m_beg_pos (beg_pos), m_end_pos (end_pos), m_tok_val (tv), m_type_tag (numeric_token), m_tok_info (val), m_orig_text (s) { } token (int tv, end_tok_type t, const filepos& beg_pos, const filepos& end_pos) - : m_maybe_cmd (false), m_tspc (false), m_beg_pos (beg_pos), - m_end_pos (end_pos), m_tok_val (tv), m_type_tag (ettype_token), - m_tok_info (t), m_orig_text () + : m_beg_pos (beg_pos), m_end_pos (end_pos), m_tok_val (tv), m_type_tag (ettype_token), m_tok_info (t) { } - token (int tv, const std::string& meth, const std::string& cls, - const filepos& beg_pos, const filepos& end_pos) - : m_maybe_cmd (false), m_tspc (false), m_beg_pos (beg_pos), - m_end_pos (end_pos), m_tok_val (tv), m_type_tag (scls_name_token), - m_tok_info (meth, cls), m_orig_text () + token (int tv, const std::string& meth, const std::string& cls, const filepos& beg_pos, const filepos& end_pos) + : m_beg_pos (beg_pos), m_end_pos (end_pos), m_tok_val (tv), m_type_tag (scls_name_token), m_tok_info (meth, cls) { } OCTAVE_DEFAULT_COPY_MOVE_DELETE (token) @@ -159,16 +141,16 @@ private: - bool m_maybe_cmd; + bool m_maybe_cmd {false}; - bool m_tspc; + bool m_tspc {false}; filepos m_beg_pos; filepos m_end_pos; int m_tok_val; - token_type m_type_tag; + token_type m_type_tag {generic_token}; class superclass_info { @@ -197,55 +179,57 @@ std::string m_class_name; }; - typedef std::variant tok_info_variant; - - class tok_info : public tok_info_variant + class tok_info { public: - tok_info (const char *s) : tok_info_variant (std::string (s)) { } + tok_info (const char *s) : m_value (std::string (s)) { } - tok_info (const std::string& str) : tok_info_variant (str) { } + tok_info (const std::string& str) : m_value (str) { } - tok_info (const octave_value& num) : tok_info_variant (octave_value (num)) { } + tok_info (const octave_value& num) : m_value (octave_value (num)) { } - tok_info (end_tok_type et) : tok_info_variant (et) { } + tok_info (end_tok_type et) : m_value (et) { } - tok_info (const std::string& meth, const std::string& cls) : tok_info_variant (superclass_info (meth, cls)) { } + tok_info (const std::string& meth, const std::string& cls) : m_value (superclass_info (meth, cls)) { } OCTAVE_DEFAULT_CONSTRUCT_COPY_MOVE_DELETE (tok_info) std::string text () const { - panic_unless (std::holds_alternative (*this)); - return std::get (*this); + panic_unless (std::holds_alternative (m_value)); + return std::get (m_value); } octave_value number () const { - panic_unless (std::holds_alternative (*this)); - return std::get (*this); + panic_unless (std::holds_alternative (m_value)); + return std::get (m_value); } token::end_tok_type ettype () const { - panic_unless (std::holds_alternative (*this)); - return std::get (*this); + panic_unless (std::holds_alternative (m_value)); + return std::get (m_value); } std::string superclass_method_name () const { - panic_unless (std::holds_alternative (*this)); - return std::get (*this).method_name (); + panic_unless (std::holds_alternative (m_value)); + return std::get (m_value).method_name (); } std::string superclass_class_name () const { - panic_unless (std::holds_alternative (*this)); - return std::get (*this).class_name (); + panic_unless (std::holds_alternative (m_value)); + return std::get (m_value).class_name (); } + + private: + + std::variant m_value; }; tok_info m_tok_info;