# HG changeset patch # User John W. Eaton # Date 1213037245 14400 # Node ID 59031cfe331bd5ae4b81516c3b14023cfc1eb4e9 # Parent 8447a5024650ca44c7b28feae41a1ebbccdb9244 lasterror fixes diff --git a/src/ChangeLog b/src/ChangeLog --- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,3 +1,15 @@ +2008-06-09 John W. Eaton + + * error.cc (verror): Omit "name: " and "\a" from Vlast_error_msg. + Save line and column information from user code. + * toplev.cc (octave_call_stack::do_caller_user_code_line, + octave_call_stack::do_caller_user_code_column): New functions. + * toplev.h: Provide decls. + (octave_call_stack::caller_user_code_line, + octave_call_stack::caller_user_code_column): New functions. + (octave_call_stack::current_line, octave_call_stack::current_column): + Default return value is -1, not 0. + 2008-06-06 John W. Eaton * ov.h (octave_value::erase_subfunctions): diff --git a/src/error.cc b/src/error.cc --- a/src/error.cc +++ b/src/error.cc @@ -200,49 +200,48 @@ if (! buffer_error_messages) flush_octave_stdout (); - bool to_beep_or_not_to_beep_p = Vbeep_on_error && ! error_state; - - std::ostringstream output_buf; - - if (to_beep_or_not_to_beep_p) - output_buf << "\a"; - - if (name) - output_buf << name << ": "; - - octave_vformat (output_buf, fmt, args); - - output_buf << std::endl; - // FIXME -- we really want to capture the message before it // has all the formatting goop attached to it. We probably also // want just the message, not the traceback information. - std::string msg_string = output_buf.str (); + std::ostringstream output_buf; + + octave_vformat (output_buf, fmt, args); + + std::string base_msg = output_buf.str (); + + bool to_beep_or_not_to_beep_p = Vbeep_on_error && ! error_state; + + std::string msg_string; + + if (to_beep_or_not_to_beep_p) + msg_string = "\a"; + + if (name) + msg_string += std::string (name) + ": "; + + msg_string += base_msg; if (! error_state && save_last_error) { // This is the first error in a possible series. Vlast_error_id = id; - Vlast_error_message = msg_string; + Vlast_error_message = base_msg; Vlast_error_line = -1; Vlast_error_column = -1; Vlast_error_name = std::string (); Vlast_error_file = std::string (); - if (octave_call_stack::current_statement ()) - { - octave_user_code *fcn = octave_call_stack::caller_user_code (); + octave_user_code *fcn = octave_call_stack::caller_user_code (); - if (fcn) - { - Vlast_error_file = fcn->fcn_file_name (); - Vlast_error_name = fcn->name(); - Vlast_error_line = octave_call_stack::current_line (); - Vlast_error_column = octave_call_stack::current_column (); - } + if (fcn) + { + Vlast_error_file = fcn->fcn_file_name (); + Vlast_error_name = fcn->name (); + Vlast_error_line = octave_call_stack::caller_user_code_line (); + Vlast_error_column = octave_call_stack::caller_user_code_column (); } } diff --git a/src/toplev.cc b/src/toplev.cc --- a/src/toplev.cc +++ b/src/toplev.cc @@ -111,6 +111,58 @@ return stmt ? stmt->column () : -1; } +int +octave_call_stack::do_caller_user_code_line (difference_type q) const +{ + int retval = -1; + + for (const_iterator p = cs.begin () + q; p != cs.end (); p++) + { + const call_stack_elt& elt = *p; + + octave_function *f = elt.fcn; + + if (f && f->is_user_code ()) + { + tree_statement *stmt = elt.stmt; + + if (stmt) + { + retval = stmt->line (); + break; + } + } + } + + return retval; +} + +int +octave_call_stack::do_caller_user_code_column (difference_type q) const +{ + int retval = -1; + + for (const_iterator p = cs.begin () + q; p != cs.end (); p++) + { + const call_stack_elt& elt = *p; + + octave_function *f = elt.fcn; + + if (f && f->is_user_code ()) + { + tree_statement *stmt = elt.stmt; + + if (stmt) + { + retval = stmt->column (); + break; + } + } + } + + return retval; +} + octave_user_script * octave_call_stack::do_caller_user_script (difference_type q) const { diff --git a/src/toplev.h b/src/toplev.h --- a/src/toplev.h +++ b/src/toplev.h @@ -122,13 +122,25 @@ // Current line in current function. static int current_line (void) { - return instance_ok () ? instance->do_current_line () : 0; + return instance_ok () ? instance->do_current_line () : -1; } // Current column in current function. static int current_column (void) { - return instance_ok () ? instance->do_current_column () : 0; + return instance_ok () ? instance->do_current_column () : -1; + } + + // Line in user code caller. + static int caller_user_code_line (difference_type q = 0) + { + return instance_ok () ? instance->do_caller_user_code_line (q) : -1; + } + + // Column in user code caller. + static int caller_user_code_column (difference_type q = 0) + { + return instance_ok () ? instance->do_caller_user_code_column (q) : -1; } // Caller function, may be built-in. @@ -237,6 +249,10 @@ int do_current_column (void) const; + int do_caller_user_code_line (difference_type q = 0) const; + + int do_caller_user_code_column (difference_type q = 0) const; + size_t do_current_frame (void) { return curr_frame; } octave_function *do_element (size_t n)