Mercurial > octave
changeset 33319:302c3a1d12d7 bytecode-interpreter
maint: merge default to bytecode-interpreter
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Thu, 04 Apr 2024 14:23:30 -0400 |
parents | 3e3a10b70fcd (current diff) b794f004bff7 (diff) |
children | ba0ba1b58e5e |
files | |
diffstat | 5 files changed, 144 insertions(+), 327 deletions(-) [+] |
line wrap: on
line diff
--- a/libinterp/corefcn/input.h Thu Apr 04 03:27:57 2024 -0400 +++ b/libinterp/corefcn/input.h Thu Apr 04 14:23:30 2024 -0400 @@ -42,7 +42,7 @@ #include "pager.h" // TRUE after a call to completion_matches. -extern bool octave_completion_matches_called; +extern OCTINTERP_API bool octave_completion_matches_called; // TRUE if the plotting system has requested a call to drawnow at // the next user prompt.
--- a/libinterp/parse-tree/anon-fcn-validator.cc Thu Apr 04 03:27:57 2024 -0400 +++ b/libinterp/parse-tree/anon-fcn-validator.cc Thu Apr 04 14:23:30 2024 -0400 @@ -35,9 +35,7 @@ OCTAVE_BEGIN_NAMESPACE(octave) -anon_fcn_validator::anon_fcn_validator (tree_parameter_list *, - tree_expression *expr) - : m_ok (true), m_line (-1), m_column (-1), m_message () +anon_fcn_validator::anon_fcn_validator (tree_parameter_list *, tree_expression *expr) { expr->accept (*this); } @@ -80,10 +78,9 @@ anon_fcn_validator::error (tree_expression& expr) { m_ok = false; - m_line = expr.line (); - m_column = expr.column (); - m_message - = "invalid use of operator " + expr.oper () + " in anonymous function"; + m_beg_pos = expr.beg_pos (); + m_end_pos = expr.end_pos (); + m_message = "invalid use of operator " + expr.oper () + " in anonymous function"; } OCTAVE_END_NAMESPACE(octave)
--- a/libinterp/parse-tree/anon-fcn-validator.h Thu Apr 04 03:27:57 2024 -0400 +++ b/libinterp/parse-tree/anon-fcn-validator.h Thu Apr 04 14:23:30 2024 -0400 @@ -30,6 +30,7 @@ #include <string> +#include "filepos.h" #include "pt-walk.h" OCTAVE_BEGIN_NAMESPACE(octave) @@ -59,16 +60,16 @@ bool ok () const { return m_ok; } - int line () const { return m_line; } - int column () const { return m_column; } + filepos beg_pos () const { return m_beg_pos; } + filepos end_pos () const { return m_end_pos; } std::string message () const { return m_message; } private: - bool m_ok; - int m_line; - int m_column; + bool m_ok {true}; + filepos m_beg_pos; + filepos m_end_pos; std::string m_message; void error (tree_expression& expr);
--- a/libinterp/parse-tree/oct-parse.yy Thu Apr 04 03:27:57 2024 -0400 +++ b/libinterp/parse-tree/oct-parse.yy Thu Apr 04 14:23:30 2024 -0400 @@ -197,7 +197,7 @@ octave::tree_classdef_enum_block* tree_classdef_enum_block_type; } -// Tokens with line and column information. +// Tokens with position information. %token <tok> '=' ':' '-' '+' '*' '/' '~' '!' %token <tok> '(' ')' '[' ']' '{' '}' '.' '@' %token <tok> ',' ';' '\n' @@ -393,9 +393,7 @@ // already explicitly declared for all types. // // %destructor { -// warning_with_id -// ("Octave:parser-destructor", -// "possible memory leak in cleanup following parse error"); +// warning_with_id ("Octave:parser-destructor", "possible memory leak in cleanup following parse error"); // } <*> // Where to start. @@ -2222,13 +2220,8 @@ parse_exception () = delete; - parse_exception (const std::string& message, - const std::string& fcn_name = "", - const std::string& file_name = "", - int line = -1, int column = -1) - : runtime_error (message), m_message (message), - m_fcn_name (fcn_name), m_file_name (file_name), - m_line (line), m_column (column) + parse_exception (const std::string& message, const std::string& fcn_name = "", const std::string& file_name = "", const filepos& pos = filepos ()) + : runtime_error (message), m_message (message), m_fcn_name (fcn_name), m_file_name (file_name), m_pos (pos) { } OCTAVE_DEFAULT_COPY_MOVE_DELETE (parse_exception) @@ -2241,8 +2234,7 @@ std::string fcn_name () const { return m_fcn_name; } std::string file_name () const { return m_file_name; } - int line () const { return m_line; } - int column () const { return m_column; } + filepos pos () const { return m_pos; } // virtual void display (std::ostream& os) const; @@ -2252,8 +2244,7 @@ std::string m_fcn_name; std::string m_file_name; - int m_line; - int m_column; + filepos m_pos; }; class parse_tree_validator : public tree_walker @@ -2302,8 +2293,7 @@ { for (auto& nm_val : subfcns) { - octave_user_function *subfcn - = nm_val.second.user_function_value (); + octave_user_function *subfcn = nm_val.second.user_function_value (); if (subfcn) subfcn->accept (*this); @@ -2319,11 +2309,8 @@ if (m_scope.is_variable (sym_nm)) { - std::string message - = sym_nm + ": invalid use of symbol as both variable and command"; - parse_exception pe (message, m_scope.fcn_name (), - m_scope.fcn_file_name (), - idx_expr.line (), idx_expr.column ()); + std::string message = sym_nm + ": invalid use of symbol as both variable and command"; + parse_exception pe (message, m_scope.fcn_name (), m_scope.fcn_file_name (), idx_expr.beg_pos ()); m_error_list.push_back (pe); } @@ -2406,9 +2393,7 @@ // function, or nested function. Otherwise, it is OK to have a // duplicate name. - return ! (m_parser.parsing_subfunctions () - || m_parser.parsing_local_functions () - || m_parser.curr_fcn_depth () > 0); + return ! (m_parser.parsing_subfunctions () || m_parser.parsing_local_functions () || m_parser.curr_fcn_depth () > 0); } m_all_names.insert (full_name); @@ -2597,9 +2582,7 @@ void base_parser::end_token_error (token *tok, token::end_tok_type expected) { - std::string msg = ("'" + end_token_as_string (expected) - + "' command matched by '" - + end_token_as_string (tok->ettype ()) + "'"); + std::string msg = ("'" + end_token_as_string (expected) + "' command matched by '" + end_token_as_string (tok->ettype ()) + "'"); bison_error (msg, tok->beg_pos ()); } @@ -2626,12 +2609,11 @@ m_lexer.m_symtab_context.push (symbol_scope ("parser:push_fcn_symtab")); m_function_scopes.push (m_lexer.m_symtab_context.curr_scope ()); - if (! m_lexer.m_reading_script_file && m_curr_fcn_depth == 0 - && ! m_parsing_subfunctions) - { - m_primary_fcn_scope = m_lexer.m_symtab_context.curr_scope (); - m_primary_fcn_scope.mark_primary_fcn_scope (); - } + if (! m_lexer.m_reading_script_file && m_curr_fcn_depth == 0 && ! m_parsing_subfunctions) + { + m_primary_fcn_scope = m_lexer.m_symtab_context.curr_scope (); + m_primary_fcn_scope.mark_primary_fcn_scope (); + } if (m_lexer.m_reading_script_file && m_curr_fcn_depth > 0) { @@ -2728,7 +2710,7 @@ delete param_list; delete expr; - bison_error (validator.message (), validator.line (), validator.column ()); + bison_error (validator.message (), validator.beg_pos ()); return nullptr; } @@ -2742,8 +2724,7 @@ fcn_scope.mark_static (); - tree_anon_fcn_handle *retval - = new tree_anon_fcn_handle (*at_tok, param_list, expr, fcn_scope, parent_scope); + tree_anon_fcn_handle *retval = new tree_anon_fcn_handle (*at_tok, param_list, expr, fcn_scope, parent_scope); std::ostringstream buf; @@ -2797,13 +2778,11 @@ token tmp_colon_2_tok = colon_2_tok ? *colon_2_tok : token (); - tree_colon_expression *expr - = new tree_colon_expression (base, *colon_1_tok, incr, tmp_colon_2_tok, limit); + tree_colon_expression *expr = new tree_colon_expression (base, *colon_1_tok, incr, tmp_colon_2_tok, limit); retval = expr; - if (base->is_constant () && limit->is_constant () - && (! incr || incr->is_constant ())) + if (base->is_constant () && limit->is_constant () && (! incr || incr->is_constant ())) { interpreter& interp = m_lexer.m_interpreter; @@ -2815,13 +2794,9 @@ error_system& es = interp.get_error_system (); - unwind_action restore_last_warning_message - (&error_system::set_last_warning_message, &es, - es.last_warning_message ("")); - - unwind_action restore_discard_warning_messages - (&error_system::set_discard_warning_messages, &es, - es.discard_warning_messages (true)); + unwind_action restore_last_warning_message (&error_system::set_last_warning_message, &es, es.last_warning_message ("")); + + unwind_action restore_discard_warning_messages (&error_system::set_discard_warning_messages, &es, es.discard_warning_messages (true)); tree_evaluator& tw = interp.get_evaluator (); @@ -2966,8 +2941,7 @@ binexp->rhs (rhs); octave_value::binary_op op_type = binexp->op_type (); - if (op_type == octave_value::op_el_and - || op_type == octave_value::op_el_or) + if (op_type == octave_value::op_el_and || op_type == octave_value::op_el_or) { binexp->preserve_operands (); @@ -3395,8 +3369,7 @@ } tree_switch_case_list * - base_parser::append_switch_case (tree_switch_case_list *list, - tree_switch_case *elt) + base_parser::append_switch_case (tree_switch_case_list *list, tree_switch_case *elt) { return list_append (list, elt); } @@ -3475,8 +3448,7 @@ delete lhs; delete rhs; - bison_error ("computed multiple assignment not allowed", - eq_tok->beg_pos ()); + bison_error ("computed multiple assignment not allowed", eq_tok->beg_pos ()); return nullptr; } @@ -3487,8 +3459,7 @@ tree_expression *tmp = lhs->remove_front (); - if ((tmp->is_identifier () || tmp->is_index_expression ()) - && iskeyword (tmp->name ())) + if ((tmp->is_identifier () || tmp->is_index_expression ()) && iskeyword (tmp->name ())) { std::string kw = tmp->name (); @@ -3496,8 +3467,7 @@ delete lhs; delete rhs; - bison_error ("invalid assignment to keyword \"" + kw + "\"", - eq_tok->beg_pos ()); + bison_error ("invalid assignment to keyword \"" + kw + "\"", eq_tok->beg_pos ()); return nullptr; } @@ -3519,8 +3489,7 @@ delete lhs; delete rhs; - bison_error ("invalid assignment to keyword \"" + kw + "\"", - eq_tok->beg_pos ()); + bison_error ("invalid assignment to keyword \"" + kw + "\"", eq_tok->beg_pos ()); return nullptr; } @@ -3533,8 +3502,7 @@ } void - base_parser::make_script (tree_statement_list *cmds, - tree_statement *end_script) + base_parser::make_script (tree_statement_list *cmds, tree_statement *end_script) { // Any comments at the beginning of a script file should be // attached to the first statement in the file or the END_SCRIPT @@ -3558,10 +3526,7 @@ std::string doc_string = leading_comments.find_doc_string (); - octave_user_script *script - = new octave_user_script (m_lexer.m_fcn_file_full_name, - m_lexer.m_fcn_file_name, script_scope, - cmds, doc_string); + octave_user_script *script = new octave_user_script (m_lexer.m_fcn_file_full_name, m_lexer.m_fcn_file_name, script_scope, cmds, doc_string); m_lexer.m_symtab_context.pop (); @@ -3585,8 +3550,13 @@ if (! m_function_scopes.name_current_scope (id_name)) { - bison_error ("duplicate subfunction or nested function name", - id->line (), id->column () + 1); + // FIXME: is this correct? Before using position, the column + // was incremented. Hmm. + + filepos id_pos = id->beg_pos (); + id_pos.increment_column (); + + bison_error ("duplicate subfunction or nested function name", id_pos); delete id; return nullptr; @@ -3675,11 +3645,7 @@ // Begin defining a function. octave_user_function * - base_parser::start_function (tree_identifier *id, - tree_parameter_list *param_list, - tree_statement_list *body, - tree_statement *end_fcn_stmt, - const std::string& doc_string) + base_parser::start_function (tree_identifier *id, tree_parameter_list *param_list, tree_statement_list *body, tree_statement *end_fcn_stmt, const std::string& doc_string) { // We'll fill in the return list later. @@ -3698,15 +3664,13 @@ body->push_back (end_fcn_stmt); - octave_user_function *fcn - = new octave_user_function (m_lexer.m_symtab_context.curr_scope (), id, param_list, nullptr, body); + octave_user_function *fcn = new octave_user_function (m_lexer.m_symtab_context.curr_scope (), id, param_list, nullptr, body); // If input is coming from a file, issue a warning if the name of // the file does not match the name of the function stated in the // file. Matlab doesn't provide a diagnostic (it ignores the stated // name). - if (! m_autoloading && m_lexer.m_reading_fcn_file - && m_curr_fcn_depth == 0 && ! m_parsing_subfunctions) + if (! m_autoloading && m_lexer.m_reading_fcn_file && m_curr_fcn_depth == 0 && ! m_parsing_subfunctions) { // FIXME: should m_lexer.m_fcn_file_name already be // preprocessed when we get here? It seems to only be a @@ -3721,10 +3685,7 @@ if (nm != id_name) { - warning_with_id - ("Octave:function-name-clash", - "function name '%s' does not agree with function filename '%s'", - id_name.c_str (), m_lexer.m_fcn_file_full_name.c_str ()); + warning_with_id ("Octave:function-name-clash", "function name '%s' does not agree with function filename '%s'", id_name.c_str (), m_lexer.m_fcn_file_full_name.c_str ()); id_name = nm; } @@ -3769,17 +3730,10 @@ sys::file_stat fs (nm); if (fs && fs.is_newer (now)) - warning_with_id ("Octave:future-time-stamp", - "time stamp for '%s' is in the future", nm.c_str ()); + warning_with_id ("Octave:future-time-stamp", "time stamp for '%s' is in the future", nm.c_str ()); } - else if (! m_lexer.input_from_tmp_history_file () - && ! m_lexer.m_force_script - && m_lexer.m_reading_script_file - && m_lexer.m_fcn_file_name == id_name) - { - warning ("function '%s' defined within script file '%s'", - id_name.c_str (), m_lexer.m_fcn_file_full_name.c_str ()); - } + else if (! m_lexer.input_from_tmp_history_file () && ! m_lexer.m_force_script && m_lexer.m_reading_script_file && m_lexer.m_fcn_file_name == id_name) + warning ("function '%s' defined within script file '%s'", id_name.c_str (), m_lexer.m_fcn_file_full_name.c_str ()); // Record doc string for functions other than nested functions. // We cannot currently record help for nested functions (bug #46008) @@ -3790,8 +3744,7 @@ fcn->document (doc_string); - if (m_lexer.m_reading_fcn_file && m_curr_fcn_depth == 0 - && ! m_parsing_subfunctions) + if (m_lexer.m_reading_fcn_file && m_curr_fcn_depth == 0 && ! m_parsing_subfunctions) m_primary_fcn = octave_value (fcn); return fcn; @@ -3896,8 +3849,7 @@ } tree_statement_list * - base_parser::append_function_body (tree_statement_list *body, - tree_statement_list *list) + base_parser::append_function_body (tree_statement_list *body, tree_statement_list *list) { if (list) { @@ -3928,11 +3880,7 @@ } tree_arg_validation * - base_parser::make_arg_validation (tree_arg_size_spec *size_spec, - tree_identifier *class_name, - tree_arg_validation_fcns *validation_fcns, - token *eq_tok, - tree_expression *default_value) + base_parser::make_arg_validation (tree_arg_size_spec *size_spec, tree_identifier *class_name, tree_arg_validation_fcns *validation_fcns, token *eq_tok, tree_expression *default_value) { // FIXME: Validate arguments and convert to more specific types // (std::string for arg_name and class_name, etc). @@ -3958,8 +3906,7 @@ } tree_args_block_validation_list * - base_parser::append_args_validation_list (tree_args_block_validation_list *list, - tree_arg_validation *arg_validation) + base_parser::append_args_validation_list (tree_args_block_validation_list *list, tree_arg_validation *arg_validation) { return list_append (list, arg_validation); } @@ -3985,8 +3932,7 @@ { m_lexer.m_symtab_context.pop (); - if (m_lexer.m_reading_fcn_file && m_curr_fcn_depth == 0 - && ! m_parsing_subfunctions) + if (m_lexer.m_reading_fcn_file && m_curr_fcn_depth == 0 && ! m_parsing_subfunctions) m_parsing_subfunctions = true; m_curr_fcn_depth--; @@ -4016,23 +3962,19 @@ std::string full_name = m_lexer.m_fcn_file_full_name; std::string short_name = m_lexer.m_fcn_file_name; - std::size_t pos - = short_name.find_last_of (sys::file_ops::dir_sep_chars ()); + std::size_t pos = short_name.find_last_of (sys::file_ops::dir_sep_chars ()); if (pos != std::string::npos) short_name = short_name.substr (pos+1); if (short_name != cls_name) { - int l = id->line (); - int c = id->column (); - delete a; delete id; delete sc; delete body; - bison_error ("invalid classdef definition, the class name must match the filename", l, c); + bison_error ("invalid classdef definition, the class name must match the filename", id->beg_pos ()); } else @@ -4271,9 +4213,7 @@ tree_classdef_attribute * base_parser::make_classdef_attribute (tree_identifier *id, token *eq_tok, tree_expression *expr) { - return (expr - ? new tree_classdef_attribute (id, *eq_tok, expr) - : new tree_classdef_attribute (id)); + return (expr ? new tree_classdef_attribute (id, *eq_tok, expr) : new tree_classdef_attribute (id)); } tree_classdef_attribute * @@ -4313,29 +4253,25 @@ } tree_classdef_body * - base_parser::append_classdef_properties_block (tree_classdef_body *body, - tree_classdef_properties_block *block) + base_parser::append_classdef_properties_block (tree_classdef_body *body, tree_classdef_properties_block *block) { return body->append (block); } tree_classdef_body * - base_parser::append_classdef_methods_block (tree_classdef_body *body, - tree_classdef_methods_block *block) + base_parser::append_classdef_methods_block (tree_classdef_body *body, tree_classdef_methods_block *block) { return body->append (block); } tree_classdef_body * - base_parser::append_classdef_events_block (tree_classdef_body *body, - tree_classdef_events_block *block) + base_parser::append_classdef_events_block (tree_classdef_body *body, tree_classdef_events_block *block) { return body->append (block); } tree_classdef_body * - base_parser::append_classdef_enum_block (tree_classdef_body *body, - tree_classdef_enum_block *block) + base_parser::append_classdef_enum_block (tree_classdef_body *body, tree_classdef_enum_block *block) { return body->append (block); } @@ -4357,9 +4293,7 @@ // - class constructor // - 'delete' - if (mname.find_first_of (".") == std::string::npos - && mname != "delete" - && mname != m_curr_class_name) + if (mname.find_first_of (".") == std::string::npos && mname != "delete" && mname != m_curr_class_name) { // Create a dummy function that is used until the real method // is loaded. @@ -4369,9 +4303,7 @@ retval->stash_function_name (mname); } else - bison_error ("invalid external method declaration, an external " - "method cannot be the class constructor, 'delete' " - "or have a dot (.) character in its name"); + bison_error ("invalid external method declaration, an external method cannot be the class constructor, 'delete' or have a dot (.) character in its name"); } else bison_error ("external methods are only allowed in @-folders"); @@ -4407,8 +4339,7 @@ } tree_classdef_method_list * - base_parser::append_classdef_method (tree_classdef_method_list *list, - tree_function_def *fcn_def) + base_parser::append_classdef_method (tree_classdef_method_list *list, tree_function_def *fcn_def) { octave_value fcn; @@ -4435,8 +4366,7 @@ { tree_command *cmd = elt->command (); - tree_function_def *fcn_def - = dynamic_cast<tree_function_def *> (cmd); + tree_function_def *fcn_def = dynamic_cast<tree_function_def *> (cmd); fcn_def->accept (validator); } @@ -4465,8 +4395,7 @@ { tree_command *cmd = elt->command (); - tree_function_def *fcn_def - = dynamic_cast<tree_function_def *> (cmd); + tree_function_def *fcn_def = dynamic_cast<tree_function_def *> (cmd); octave_value ov_fcn = fcn_def->function (); octave_user_function *fcn = ov_fcn.user_function_value (); @@ -4628,22 +4557,20 @@ } tree_decl_init_list * - base_parser::append_decl_init_list (tree_decl_init_list *list, - tree_decl_elt *elt) + base_parser::append_decl_init_list (tree_decl_init_list *list, tree_decl_elt *elt) { return list_append (list, elt); } tree_decl_elt * - base_parser::make_decl_elt (tree_identifier *id, token */*eq_op*/, - tree_expression *expr) + base_parser::make_decl_elt (tree_identifier *id, token */*eq_op*/, tree_expression *expr) { + // FIXME XXX! need to capture EQ_OP here. return expr ? new tree_decl_elt (id, expr) : new tree_decl_elt (id); } bool - base_parser::validate_param_list (tree_parameter_list *lst, - tree_parameter_list::in_or_out type) + base_parser::validate_param_list (tree_parameter_list *lst, tree_parameter_list::in_or_out type) { std::set<std::string> dict; @@ -4665,14 +4592,12 @@ } else if (iskeyword (name)) { - bison_error ("invalid use of keyword '" + name - + "' in parameter list"); + bison_error ("invalid use of keyword '" + name + "' in parameter list"); return false; } else if (dict.find (name) != dict.end ()) { - bison_error ("'" + name - + "' appears more than once in parameter list"); + bison_error ("'" + name + "' appears more than once in parameter list"); return false; } else @@ -4680,8 +4605,7 @@ } } - std::string va_type = (type == tree_parameter_list::in - ? "varargin" : "varargout"); + std::string va_type = (type == tree_parameter_list::in ? "varargin" : "varargout"); std::size_t len = lst->size (); @@ -4814,13 +4738,9 @@ error_system& es = interp.get_error_system (); - unwind_action restore_last_warning_message - (&error_system::set_last_warning_message, &es, - es.last_warning_message ("")); - - unwind_action restore_discard_warning_messages - (&error_system::set_discard_warning_messages, &es, - es.discard_warning_messages (true)); + unwind_action restore_last_warning_message (&error_system::set_last_warning_message, &es, es.last_warning_message ("")); + + unwind_action restore_discard_warning_messages (&error_system::set_discard_warning_messages, &es, es.discard_warning_messages (true)); tree_evaluator& tw = interp.get_evaluator (); @@ -4944,8 +4864,7 @@ } tree_statement_list * - base_parser::set_stmt_print_flag (tree_statement_list *list, - char sep, bool warn_missing_semi) + base_parser::set_stmt_print_flag (tree_statement_list *list, char sep, bool warn_missing_semi) { tree_statement *tmp = list->back (); @@ -4995,9 +4914,7 @@ } tree_statement_list * - base_parser::append_statement_list (tree_statement_list *list, - char sep, tree_statement *stmt, - bool warn_missing_semi) + base_parser::append_statement_list (tree_statement_list *list, char sep, tree_statement *stmt, bool warn_missing_semi) { set_stmt_print_flag (list, sep, warn_missing_semi); @@ -5077,27 +4994,19 @@ void base_parser::bison_error (const std::string& str, const filepos& pos) { - bison_error (str, pos.line (), pos.column ()); - } - - void - base_parser::bison_error (const std::string& str, int err_line, int err_col) - { std::ostringstream output_buf; - bool in_file = (m_lexer.m_reading_fcn_file || m_lexer.m_reading_script_file - || m_lexer.m_reading_classdef_file); + int err_line = pos.line (); + int err_col = pos.column (); + + bool in_file = (m_lexer.m_reading_fcn_file || m_lexer.m_reading_script_file || m_lexer.m_reading_classdef_file); // Adjust the error column for display because it is 1-based in the // lexer for easier reporting. err_col--; if (in_file) - { - output_buf << str - << " near line " << err_line << ", column " << err_col - << " in file " << m_lexer.m_fcn_file_full_name << "\n"; - } + output_buf << str << " near line " << err_line << ", column " << err_col << " in file " << m_lexer.m_fcn_file_full_name << "\n"; else { // On command line, point directly to error @@ -5134,7 +5043,7 @@ void base_parser::bison_error (const parse_exception& pe) { - bison_error (pe.message (), pe.line (), pe.column ()); + bison_error (pe.message (), pe.pos ()); } void @@ -5145,7 +5054,7 @@ parse_exception pe = pe_list.front (); - bison_error (pe.message (), pe.line (), pe.column ()); + bison_error (pe.message (), pe.pos ()); } int @@ -5273,8 +5182,7 @@ int exit_status = 0; - std::string prompt - = command_editor::decode_prompt_string (m_interpreter.PS1 ()); + std::string prompt = command_editor::decode_prompt_string (m_interpreter.PS1 ()); do { @@ -5304,11 +5212,7 @@ } octave_value - parse_fcn_file (interpreter& interp, const std::string& full_file, - const std::string& file, const std::string& dir_name, - const std::string& dispatch_type, - const std::string& package_name, bool require_file, - bool force_script, bool autoload, bool relative_lookup) + parse_fcn_file (interpreter& interp, const std::string& full_file, const std::string& file, const std::string& dir_name, const std::string& dispatch_type, const std::string& package_name, bool require_file, bool force_script, bool autoload, bool relative_lookup) { octave_value retval; @@ -5365,8 +5269,7 @@ octave_value ov_fcn = parser.m_primary_fcn; - if (parser.m_lexer.m_reading_classdef_file - && parser.classdef_object ()) + if (parser.m_lexer.m_reading_classdef_file && parser.classdef_object ()) { // Convert parse tree for classdef object to // meta.class info (and stash it in the symbol @@ -5377,8 +5280,7 @@ bool is_at_folder = ! dispatch_type.empty (); - std::shared_ptr<tree_classdef> cdef_obj - = parser.classdef_object(); + std::shared_ptr<tree_classdef> cdef_obj = parser.classdef_object(); return cdef_obj->make_meta_class (interp, is_at_folder); } @@ -5462,14 +5364,9 @@ if (expr->is_assignment_expression () && expr->delim_count () < 2) { if (m_lexer.m_fcn_file_full_name.empty ()) - warning_with_id - ("Octave:assign-as-truth-value", - "suggest parenthesis around assignment used as truth value"); + warning_with_id ("Octave:assign-as-truth-value", "suggest parenthesis around assignment used as truth value"); else - warning_with_id - ("Octave:assign-as-truth-value", - "suggest parenthesis around assignment used as truth value near line %d, column %d in file '%s'", - expr->line (), expr->column (), m_lexer.m_fcn_file_full_name.c_str ()); + warning_with_id ("Octave:assign-as-truth-value", "suggest parenthesis around assignment used as truth value near line %d, column %d in file '%s'", expr->line (), expr->column (), m_lexer.m_fcn_file_full_name.c_str ()); } } @@ -5481,13 +5378,9 @@ if (! expr->is_constant ()) { if (m_lexer.m_fcn_file_full_name.empty ()) - warning_with_id ("Octave:variable-switch-label", - "variable switch label"); + warning_with_id ("Octave:variable-switch-label", "variable switch label"); else - warning_with_id - ("Octave:variable-switch-label", - "variable switch label near line %d, column %d in file '%s'", - expr->line (), expr->column (), m_lexer.m_fcn_file_full_name.c_str ()); + warning_with_id ("Octave:variable-switch-label", "variable switch label near line %d, column %d in file '%s'", expr->line (), expr->column (), m_lexer.m_fcn_file_full_name.c_str ()); } } @@ -5499,10 +5392,7 @@ tree_statement *tmp = t->back (); if (tmp->is_expression ()) - warning_with_id - ("Octave:missing-semicolon", - "missing semicolon near line %d, column %d in file '%s'", - tmp->line (), tmp->column (), m_lexer.m_fcn_file_full_name.c_str ()); + warning_with_id ("Octave:missing-semicolon", "missing semicolon near line %d, column %d in file '%s'", tmp->line (), tmp->column (), m_lexer.m_fcn_file_full_name.c_str ()); } } @@ -5536,9 +5426,7 @@ symbol_found = true; - octave_value ov_fcn - = parse_fcn_file (interp, full_file, file, "", "", "", true, - false, false, false); + octave_value ov_fcn = parse_fcn_file (interp, full_file, file, "", "", "", true, false, false, false); if (ov_fcn.is_defined ()) { @@ -5560,11 +5448,7 @@ } octave_value - load_fcn_from_file (const std::string& file_name, - const std::string& dir_name, - const std::string& dispatch_type, - const std::string& package_name, - const std::string& fcn_name, bool autoload) + load_fcn_from_file (const std::string& file_name, const std::string& dir_name, const std::string& dispatch_type, const std::string& package_name, const std::string& fcn_name, bool autoload) { octave_value retval; @@ -5607,8 +5491,7 @@ if (autoload && ! fcn_name.empty ()) nm = fcn_name; - octave_function *tmpfcn - = dyn_loader.load_oct (nm, file, relative_lookup); + octave_function *tmpfcn = dyn_loader.load_oct (nm, file, relative_lookup); if (tmpfcn) { @@ -5623,10 +5506,7 @@ std::string doc_string; - octave_value ov_fcn - = parse_fcn_file (interp, file.substr (0, len - 2), nm, dir_name, - dispatch_type, package_name, false, - autoload, autoload, relative_lookup); + octave_value ov_fcn = parse_fcn_file (interp, file.substr (0, len - 2), nm, dir_name, dispatch_type, package_name, false, autoload, autoload, relative_lookup); if (ov_fcn.is_defined ()) { @@ -5636,8 +5516,7 @@ doc_string = tmpfcn->doc_string (); } - octave_function *tmpfcn - = dyn_loader.load_mex (nm, file, relative_lookup); + octave_function *tmpfcn = dyn_loader.load_mex (nm, file, relative_lookup); if (tmpfcn) { @@ -5648,11 +5527,7 @@ } } else if (len > 2) - { - retval = parse_fcn_file (interp, file, nm, dir_name, - dispatch_type, package_name, true, - autoload, autoload, relative_lookup); - } + retval = parse_fcn_file (interp, file, nm, dir_name, dispatch_type, package_name, true, autoload, autoload, relative_lookup); return retval; } @@ -5715,8 +5590,7 @@ else if (nargin == 3) { if (argv[3] != "remove") - error_with_id ("Octave:invalid-input-arg", - "autoload: third argument can only be 'remove'"); + error_with_id ("Octave:invalid-input-arg", "autoload: third argument can only be 'remove'"); tw.remove_autoload (argv[1], argv[2]); } @@ -5791,8 +5665,7 @@ if (nargin < 1 || nargin > 2) print_usage (); - std::string file_name - = args(0).xstring_value ("source: FILE must be a string"); + std::string file_name = args(0).xstring_value ("source: FILE must be a string"); std::string context; if (nargin == 2) @@ -5997,8 +5870,7 @@ return interp.eval (try_code, nargout); else { - if (! args(1).is_string () || args(1).rows () > 1 - || args(1).ndims () != 2) + if (! args(1).is_string () || args(1).rows () > 1 || args(1).ndims () != 2) error ("eval: CATCH must be a string"); std::string catch_code = args(1).string_value (); @@ -6070,11 +5942,9 @@ if (args.length () != 3) print_usage (); - std::string context - = args(0).xstring_value ("assignin: CONTEXT must be a string"); - - std::string varname - = args(1).xstring_value ("assignin: VARNAME must be a string"); + std::string context = args(0).xstring_value ("assignin: CONTEXT must be a string"); + + std::string varname = args(1).xstring_value ("assignin: VARNAME must be a string"); interp.assignin (context, varname, args(2)); @@ -6101,16 +5971,13 @@ if (nargin < 2 || nargin > 3) print_usage (); - std::string context - = args(0).xstring_value ("evalin: CONTEXT must be a string"); - - std::string try_code - = args(1).xstring_value ("evalin: TRY must be a string"); + std::string context = args(0).xstring_value ("evalin: CONTEXT must be a string"); + + std::string try_code = args(1).xstring_value ("evalin: TRY must be a string"); if (nargin == 3) { - std::string catch_code - = args(2).xstring_value ("evalin: CATCH must be a string"); + std::string catch_code = args(2).xstring_value ("evalin: CATCH must be a string"); return interp.evalin (context, try_code, catch_code, nargout); } @@ -6309,8 +6176,7 @@ if (nargin < 1 || nargin > 2) print_usage (); - std::string file - = args(0).xstring_value ("__parse_file__: expecting filename as argument"); + std::string file = args(0).xstring_value ("__parse_file__: expecting filename as argument"); std::string full_file = sys::file_ops::tilde_expand (file); @@ -6338,9 +6204,7 @@ if (nargin == 2) octave_stdout << "parsing " << full_file << std::endl; - octave_value ov_fcn - = parse_fcn_file (interp, full_file, file, dir_name, "", "", true, - false, false, false); + octave_value ov_fcn = parse_fcn_file (interp, full_file, file, dir_name, "", "", true, false, false, false); return retval; }
--- a/libinterp/parse-tree/parse.h Thu Apr 04 03:27:57 2024 -0400 +++ b/libinterp/parse-tree/parse.h Thu Apr 04 14:23:30 2024 -0400 @@ -366,9 +366,7 @@ // Begin defining a function. OCTINTERP_API octave_user_function * - start_function (tree_identifier *id, tree_parameter_list *param_list, - tree_statement_list *body, tree_statement *end_function, - const std::string& doc_string); + start_function (tree_identifier *id, tree_parameter_list *param_list, tree_statement_list *body, tree_statement *end_function, const std::string& doc_string); // Create a no-op statement for end_function. OCTINTERP_API tree_statement * @@ -394,11 +392,7 @@ // Make an argument validation. OCTINTERP_API tree_arg_validation * - make_arg_validation (tree_arg_size_spec *size_spec, - tree_identifier *class_name, - tree_arg_validation_fcns *validation_fcns, - token *eq_tok = nullptr, - tree_expression *default_value = nullptr); + make_arg_validation (tree_arg_size_spec *size_spec, tree_identifier *class_name, tree_arg_validation_fcns *validation_fcns, token *eq_tok = nullptr, tree_expression *default_value = nullptr); // Make an argument validation list. OCTINTERP_API tree_args_block_validation_list * @@ -406,8 +400,7 @@ // Append an argument validation to an existing list. OCTINTERP_API tree_args_block_validation_list * - append_args_validation_list (tree_args_block_validation_list *list, - tree_arg_validation *arg_validation); + append_args_validation_list (tree_args_block_validation_list *list, tree_arg_validation *arg_validation); // Make an argument size specification object. OCTINTERP_API tree_arg_size_spec * @@ -434,8 +427,7 @@ make_classdef_property (tree_identifier *id, tree_arg_validation *av); OCTINTERP_API tree_classdef_property_list * - append_classdef_property (tree_classdef_property_list *list, - tree_classdef_property *elt); + append_classdef_property (tree_classdef_property_list *list, tree_classdef_property *elt); OCTINTERP_API tree_classdef_methods_block * make_classdef_methods_block (token *tok, tree_classdef_attribute_list *a, tree_classdef_method_list *mlist, token *end_tok); @@ -450,8 +442,7 @@ make_classdef_event (tree_identifier *id); OCTINTERP_API tree_classdef_event_list * - append_classdef_event (tree_classdef_event_list *list, - tree_classdef_event *elt); + append_classdef_event (tree_classdef_event_list *list, tree_classdef_event *elt); OCTINTERP_API tree_classdef_enum_block * make_classdef_enum_block (token *tok, tree_classdef_attribute_list *a, tree_classdef_enum_list *elist, token *end_tok); @@ -463,8 +454,7 @@ make_classdef_enum (tree_identifier *id, token *open_paren, tree_expression *expr, token *close_paren); OCTINTERP_API tree_classdef_enum_list * - append_classdef_enum (tree_classdef_enum_list *list, - tree_classdef_enum *elt); + append_classdef_enum (tree_classdef_enum_list *list, tree_classdef_enum *elt); OCTINTERP_API tree_classdef_superclass_list * make_classdef_superclass_list (token *lt_tok, tree_classdef_superclass *sc); @@ -503,20 +493,16 @@ make_classdef_body (tree_classdef_enum_block *enb); OCTINTERP_API tree_classdef_body * - append_classdef_properties_block (tree_classdef_body *body, - tree_classdef_properties_block *block); + append_classdef_properties_block (tree_classdef_body *body, tree_classdef_properties_block *block); OCTINTERP_API tree_classdef_body * - append_classdef_methods_block (tree_classdef_body *body, - tree_classdef_methods_block *block); + append_classdef_methods_block (tree_classdef_body *body, tree_classdef_methods_block *block); OCTINTERP_API tree_classdef_body * - append_classdef_events_block (tree_classdef_body *body, - tree_classdef_events_block *block); + append_classdef_events_block (tree_classdef_body *body, tree_classdef_events_block *block); OCTINTERP_API tree_classdef_body * - append_classdef_enum_block (tree_classdef_body *body, - tree_classdef_enum_block *block); + append_classdef_enum_block (tree_classdef_body *body, tree_classdef_enum_block *block); OCTINTERP_API octave_user_function * start_classdef_external_method (tree_identifier *id, tree_parameter_list *pl = nullptr); @@ -528,8 +514,7 @@ make_classdef_method_list (tree_function_def *fcn_def); OCTINTERP_API tree_classdef_method_list * - append_classdef_method (tree_classdef_method_list *list, - tree_function_def *fcn_def); + append_classdef_method (tree_classdef_method_list *list, tree_function_def *fcn_def); OCTINTERP_API bool finish_classdef_file (tree_classdef *cls, tree_statement_list *local_fcns, token *eof_tok); @@ -554,16 +539,14 @@ make_decl_init_list (tree_decl_elt *elt); OCTINTERP_API tree_decl_elt * - make_decl_elt (tree_identifier *id, token *eq_op = nullptr, - tree_expression *expr = nullptr); + make_decl_elt (tree_identifier *id, token *eq_op = nullptr, tree_expression *expr = nullptr); OCTINTERP_API tree_decl_init_list * append_decl_init_list (tree_decl_init_list *list, tree_decl_elt *elt); // Validate an function parameter list. OCTINTERP_API bool - validate_param_list (tree_parameter_list *lst, - tree_parameter_list::in_or_out type); + validate_param_list (tree_parameter_list *lst, tree_parameter_list::in_or_out type); // Validate matrix or cell OCTINTERP_API bool validate_array_list (tree_expression *e); @@ -647,16 +630,11 @@ // Generic error messages. OCTINTERP_API void bison_error (const std::string& s); OCTINTERP_API void bison_error (const std::string& s, const filepos& pos); - OCTINTERP_API void bison_error (const std::string& s, int line, int column); OCTINTERP_API void bison_error (const std::list<parse_exception>& pe); OCTINTERP_API void bison_error (const parse_exception& pe); friend OCTINTERP_API octave_value - parse_fcn_file (interpreter& interp, const std::string& full_file, - const std::string& file, const std::string& dir_name, - const std::string& dispatch_type, - const std::string& package_name, bool require_file, - bool force_script, bool autoload, bool relative_lookup); + parse_fcn_file (interpreter& interp, const std::string& full_file, const std::string& file, const std::string& dir_name, const std::string& dispatch_type, const std::string& package_name, bool require_file, bool force_script, bool autoload, bool relative_lookup); // Thih interface allows push or pull parsers to be used // equivalently, provided that the push parser also owns its input @@ -670,8 +648,7 @@ // semantic errors. OCTINTERP_API bool validate_primary_fcn (); - OCTINTERP_API bool finish_input (tree_statement_list *lst, - bool at_eof = false); + OCTINTERP_API bool finish_input (tree_statement_list *lst, bool at_eof = false); protected: @@ -760,11 +737,7 @@ // Publish externally used friend functions. extern OCTINTERP_API octave_value -parse_fcn_file (interpreter& interp, const std::string& full_file, - const std::string& file, const std::string& dir_name, - const std::string& dispatch_type, - const std::string& package_name, bool require_file, - bool force_script, bool autoload, bool relative_lookup); +parse_fcn_file (interpreter& interp, const std::string& full_file, const std::string& file, const std::string& dir_name, const std::string& dispatch_type, const std::string& package_name, bool require_file, bool force_script, bool autoload, bool relative_lookup); class parser : public base_parser { @@ -806,16 +779,14 @@ public: push_parser (interpreter& interp) - : base_parser (*(new push_lexer (interp))), - m_interpreter (interp), m_reader () + : base_parser (*(new push_lexer (interp))), m_interpreter (interp), m_reader () { } // The parser assumes ownership of READER, which must be created // with new. push_parser (interpreter& interp, input_reader *reader) - : base_parser (*(new push_lexer (interp))), - m_interpreter (interp), m_reader (reader) + : base_parser (*(new push_lexer (interp))), m_interpreter (interp), m_reader (reader) { } OCTAVE_DISABLE_CONSTRUCT_COPY_MOVE (push_parser) @@ -841,44 +812,28 @@ }; extern OCTINTERP_API std::string -get_help_from_file (const std::string& nm, bool& symbol_found, - std::string& file); +get_help_from_file (const std::string& nm, bool& symbol_found, std::string& file); extern OCTINTERP_API std::string get_help_from_file (const std::string& nm, bool& symbol_found); extern OCTINTERP_API octave_value -load_fcn_from_file (const std::string& file_name, - const std::string& dir_name = "", - const std::string& dispatch_type = "", - const std::string& package_name = "", - const std::string& fcn_name = "", - bool autoload = false); +load_fcn_from_file (const std::string& file_name, const std::string& dir_name = "", const std::string& dispatch_type = "", const std::string& package_name = "", const std::string& fcn_name = "", bool autoload = false); extern OCTINTERP_API void -source_file (const std::string& file_name, - const std::string& context = "", - bool verbose = false, bool require_file = true); +source_file (const std::string& file_name, const std::string& context = "", bool verbose = false, bool require_file = true); extern OCTINTERP_API octave_value_list -feval (const char *name, - const octave_value_list& args = octave_value_list (), - int nargout = 0); +feval (const char *name, const octave_value_list& args = octave_value_list (), int nargout = 0); extern OCTINTERP_API octave_value_list -feval (const std::string& name, - const octave_value_list& args = octave_value_list (), - int nargout = 0); +feval (const std::string& name, const octave_value_list& args = octave_value_list (), int nargout = 0); extern OCTINTERP_API octave_value_list -feval (octave_function *fcn, - const octave_value_list& args = octave_value_list (), - int nargout = 0); +feval (octave_function *fcn, const octave_value_list& args = octave_value_list (), int nargout = 0); extern OCTINTERP_API octave_value_list -feval (const octave_value& val, - const octave_value_list& args = octave_value_list (), - int nargout = 0); +feval (const octave_value& val, const octave_value_list& args = octave_value_list (), int nargout = 0); extern OCTINTERP_API octave_value_list feval (const octave_value_list& args, int nargout = 0);