changeset 7877:59031cfe331b

lasterror fixes
author John W. Eaton <jwe@octave.org>
date Mon, 09 Jun 2008 14:47:25 -0400
parents 8447a5024650
children b4ac6bb4114b
files src/ChangeLog src/error.cc src/toplev.cc src/toplev.h
diffstat 4 files changed, 107 insertions(+), 28 deletions(-) [+]
line wrap: on
line diff
--- a/src/ChangeLog	Fri Jun 06 15:04:12 2008 -0400
+++ b/src/ChangeLog	Mon Jun 09 14:47:25 2008 -0400
@@ -1,3 +1,15 @@
+2008-06-09  John W. Eaton  <jwe@octave.org>
+
+	* 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  <jwe@octave.org>
 
 	* ov.h (octave_value::erase_subfunctions):
--- a/src/error.cc	Fri Jun 06 15:04:12 2008 -0400
+++ b/src/error.cc	Mon Jun 09 14:47:25 2008 -0400
@@ -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 ();
 	}
     }
 
--- a/src/toplev.cc	Fri Jun 06 15:04:12 2008 -0400
+++ b/src/toplev.cc	Mon Jun 09 14:47:25 2008 -0400
@@ -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
 {
--- a/src/toplev.h	Fri Jun 06 15:04:12 2008 -0400
+++ b/src/toplev.h	Mon Jun 09 14:47:25 2008 -0400
@@ -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)