pt-stmt.cc

Go to the documentation of this file.
00001 /*
00002 
00003 Copyright (C) 1996-2012 John W. Eaton
00004 
00005 This file is part of Octave.
00006 
00007 Octave is free software; you can redistribute it and/or modify it
00008 under the terms of the GNU General Public License as published by the
00009 Free Software Foundation; either version 3 of the License, or (at your
00010 option) any later version.
00011 
00012 Octave is distributed in the hope that it will be useful, but WITHOUT
00013 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
00014 FITNESS FOR A PARTICULAR PURPOSE.  See the GNU General Public License
00015 for more details.
00016 
00017 You should have received a copy of the GNU General Public License
00018 along with Octave; see the file COPYING.  If not, see
00019 <http://www.gnu.org/licenses/>.
00020 
00021 */
00022 
00023 #ifdef HAVE_CONFIG_H
00024 #include <config.h>
00025 #endif
00026 
00027 #include <typeinfo>
00028 
00029 #include "quit.h"
00030 
00031 #include "defun.h"
00032 #include "error.h"
00033 #include "gripes.h"
00034 #include "ov.h"
00035 #include "oct-lvalue.h"
00036 #include "input.h"
00037 #include "pager.h"
00038 #include "pt-bp.h"
00039 #include "pt-cmd.h"
00040 #include "pt-id.h"
00041 #include "pt-idx.h"
00042 #include "pt-jump.h"
00043 #include "pt-pr-code.h"
00044 #include "pt-stmt.h"
00045 #include "pt-walk.h"
00046 #include "unwind-prot.h"
00047 #include "utils.h"
00048 #include "variables.h"
00049 
00050 // A list of commands to be executed.
00051 
00052 tree_statement::~tree_statement (void)
00053 {
00054   delete cmd;
00055   delete expr;
00056   delete comm;
00057 }
00058 
00059 void
00060 tree_statement::set_print_flag (bool print_flag)
00061 {
00062   if (expr)
00063     expr->set_print_flag (print_flag);
00064 }
00065 
00066 bool
00067 tree_statement::print_result (void)
00068 {
00069   return expr && expr->print_result ();
00070 }
00071 
00072 void
00073 tree_statement::set_breakpoint (void)
00074 {
00075   if (cmd)
00076     cmd->set_breakpoint ();
00077   else if (expr)
00078     expr->set_breakpoint ();
00079 }
00080 
00081 void
00082 tree_statement::delete_breakpoint (void)
00083 {
00084   if (cmd)
00085     cmd->delete_breakpoint ();
00086   else if (expr)
00087     expr->delete_breakpoint ();
00088 }
00089 
00090 bool
00091 tree_statement::is_breakpoint (void) const
00092 {
00093   return cmd ? cmd->is_breakpoint () : (expr ? expr->is_breakpoint () : false);
00094 }
00095 
00096 int
00097 tree_statement::line (void) const
00098 {
00099   return cmd ? cmd->line () : (expr ? expr->line () : -1);
00100 }
00101 
00102 int
00103 tree_statement::column (void) const
00104 {
00105   return cmd ? cmd->column () : (expr ? expr->column () : -1);
00106 }
00107 
00108 void
00109 tree_statement::echo_code (void)
00110 {
00111   tree_print_code tpc (octave_stdout, VPS4);
00112 
00113   accept (tpc);
00114 }
00115 
00116 bool
00117 tree_statement::is_end_of_fcn_or_script (void) const
00118 {
00119   bool retval = false;
00120 
00121   if (cmd)
00122     {
00123       tree_no_op_command *no_op_cmd
00124         = dynamic_cast<tree_no_op_command *> (cmd);
00125 
00126       if (no_op_cmd)
00127         retval = no_op_cmd->is_end_of_fcn_or_script ();
00128     }
00129 
00130   return retval;
00131 }
00132 
00133 tree_statement *
00134 tree_statement::dup (symbol_table::scope_id scope,
00135                      symbol_table::context_id context) const
00136 {
00137   tree_statement *new_stmt = new tree_statement ();
00138 
00139   new_stmt->cmd = cmd ? cmd->dup (scope, context) : 0;
00140 
00141   new_stmt->expr = expr ? expr->dup (scope, context) : 0;
00142 
00143   new_stmt->comm = comm ? comm->dup () : 0;
00144 
00145   return new_stmt;
00146 }
00147 
00148 void
00149 tree_statement::accept (tree_walker& tw)
00150 {
00151   tw.visit_statement (*this);
00152 }
00153 
00154 int
00155 tree_statement_list::set_breakpoint (int line)
00156 {
00157   tree_breakpoint tbp (line, tree_breakpoint::set);
00158   accept (tbp);
00159 
00160   return tbp.get_line ();
00161 }
00162 
00163 void
00164 tree_statement_list::delete_breakpoint (int line)
00165 {
00166   if (line < 0)
00167     {
00168       octave_value_list bp_lst = list_breakpoints ();
00169 
00170       int len = bp_lst.length ();
00171 
00172       for (int i = 0; i < len; i++)
00173         {
00174           tree_breakpoint tbp (i, tree_breakpoint::clear);
00175           accept (tbp);
00176         }
00177     }
00178   else
00179     {
00180       tree_breakpoint tbp (line, tree_breakpoint::clear);
00181       accept (tbp);
00182     }
00183 }
00184 
00185 octave_value_list
00186 tree_statement_list::list_breakpoints (void)
00187 {
00188   tree_breakpoint tbp (0, tree_breakpoint::list);
00189   accept (tbp);
00190 
00191   return tbp.get_list ();
00192 }
00193 
00194 tree_statement_list *
00195 tree_statement_list::dup (symbol_table::scope_id scope,
00196                           symbol_table::context_id context) const
00197 {
00198   tree_statement_list *new_list = new tree_statement_list ();
00199 
00200   new_list->function_body = function_body;
00201 
00202   for (const_iterator p = begin (); p != end (); p++)
00203     {
00204       const tree_statement *elt = *p;
00205 
00206       new_list->append (elt ? elt->dup (scope, context) : 0);
00207     }
00208 
00209   return new_list;
00210 }
00211 
00212 void
00213 tree_statement_list::accept (tree_walker& tw)
00214 {
00215   tw.visit_statement_list (*this);
00216 }
 All Classes Files Functions Variables Typedefs Enumerations Enumerator Friends Defines