diff src/toplev.cc @ 7734:2dee19385d32

eliminate tree_statement_stack; handle current statement info in octave_call_stack
author John W. Eaton <jwe@octave.org>
date Fri, 25 Apr 2008 12:16:42 -0400
parents bb614b3883a9
children a059b5679fbb
line wrap: on
line diff
--- a/src/toplev.cc	Thu Apr 24 16:18:44 2008 -0400
+++ b/src/toplev.cc	Fri Apr 25 12:16:42 2008 -0400
@@ -95,14 +95,32 @@
 
 octave_call_stack *octave_call_stack::instance = 0;
 
+int
+octave_call_stack::do_current_line (void) const
+{
+  tree_statement *stmt = do_top_statement ();
+
+  return stmt ? stmt->line () : -1;
+}
+
+int
+octave_call_stack::do_current_column (void) const
+{
+  tree_statement *stmt = do_top_statement ();
+
+  return stmt ? stmt->column () : -1;
+}
+
 octave_user_script *
-octave_call_stack::do_caller_user_script (void)
+octave_call_stack::do_caller_user_script (void) const
 {
   octave_user_script *retval = 0;
 
-  for (iterator p = cs.begin (); p != cs.end (); p++)
+  for (const_iterator p = cs.begin (); p != cs.end (); p++)
     {
-      octave_function *f = *p;
+      const call_stack_elt& elt = *p;
+
+      octave_function *f = elt.fcn;
 
       if (f && f->is_user_script ())
 	{
@@ -115,13 +133,15 @@
 }
 
 octave_user_function *
-octave_call_stack::do_caller_user_function (void)
+octave_call_stack::do_caller_user_function (void) const
 {
   octave_user_function *retval = 0;
 
-  for (iterator p = cs.begin (); p != cs.end (); p++)
+  for (const_iterator p = cs.begin (); p != cs.end (); p++)
     {
-      octave_function *f = *p;
+      const call_stack_elt& elt = *p;
+
+      octave_function *f = elt.fcn;
 
       if (f && f->is_user_function ())
 	{
@@ -134,13 +154,15 @@
 }
 
 octave_user_code *
-octave_call_stack::do_caller_user_code (void)
+octave_call_stack::do_caller_user_code (void) const
 {
   octave_user_code *retval = 0;
 
-  for (iterator p = cs.begin (); p != cs.end (); p++)
+  for (const_iterator p = cs.begin (); p != cs.end (); p++)
     {
-      octave_function *f = *p;
+      const call_stack_elt& elt = *p;
+
+      octave_function *f = elt.fcn;
 
       if (f && f->is_user_code ())
 	{
@@ -152,6 +174,77 @@
   return retval;
 }
 
+Octave_map
+octave_call_stack::do_backtrace (void) const
+{
+  Octave_map retval;
+
+  size_t nframes = cs.size () - 1;
+
+  Cell keys (4, 1);
+
+  keys(0) = "file";
+  keys(1) = "name";
+  keys(2) = "line";
+  keys(3) = "column";
+
+  Cell file (nframes, 1);
+  Cell name (nframes, 1);
+  Cell line (nframes, 1);
+  Cell column (nframes, 1);
+
+  const_iterator p = cs.begin ();
+  
+  // Skip innermost function as it will be the dbstatus function
+  // itself.  FIXME -- Is it best to do this here?
+  p++;
+
+  octave_idx_type k = 0;
+
+  while (p != cs.end ())
+    {
+      const call_stack_elt& elt = *p;
+
+      octave_function *f = elt.fcn;
+
+      if (f)
+	{
+	  file(k) = f->fcn_file_name ();
+	  name(k) = f->name ();
+
+	  tree_statement *stmt = elt.stmt;
+
+	  if (stmt)
+	    {
+	      line(k) = stmt->line ();
+	      column(k) = stmt->column ();
+	    }
+	  else
+	    {
+	      line(k) = -1;
+	      column(k) = -1;
+	    }
+	}
+      else
+	{
+	  file(k) = "<unknown>";
+	  name(k) = "<unknown>";
+	  line(k) = -1;
+	  column(k) = -1;
+	}
+
+      k++;
+      p++;
+    }
+
+  retval.assign ("file", file);
+  retval.assign ("name", name);
+  retval.assign ("line", line);
+  retval.assign ("column", column);
+
+  return retval;
+}
+
 void
 recover_from_exception (void)
 {