Mercurial > hg > octave-nkf
annotate libinterp/parse-tree/pt-stmt.cc @ 16267:15f55df088e7
6/10 commits reworking the lexer
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Mon, 11 Mar 2013 14:30:57 -0400 |
parents | 2fc554ffbc28 |
children | 7ca7e7d5eb91 |
rev | line source |
---|---|
2982 | 1 /* |
2 | |
14138
72c96de7a403
maint: update copyright notices for 2012
John W. Eaton <jwe@octave.org>
parents:
11586
diff
changeset
|
3 Copyright (C) 1996-2012 John W. Eaton |
2982 | 4 |
5 This file is part of Octave. | |
6 | |
7 Octave is free software; you can redistribute it and/or modify it | |
8 under the terms of the GNU General Public License as published by the | |
7016 | 9 Free Software Foundation; either version 3 of the License, or (at your |
10 option) any later version. | |
2982 | 11 |
12 Octave is distributed in the hope that it will be useful, but WITHOUT | |
13 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | |
14 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | |
15 for more details. | |
16 | |
17 You should have received a copy of the GNU General Public License | |
7016 | 18 along with Octave; see the file COPYING. If not, see |
19 <http://www.gnu.org/licenses/>. | |
2982 | 20 |
21 */ | |
22 | |
23 #ifdef HAVE_CONFIG_H | |
24 #include <config.h> | |
25 #endif | |
26 | |
8658
73c4516fae10
New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents:
8637
diff
changeset
|
27 #include <typeinfo> |
73c4516fae10
New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents:
8637
diff
changeset
|
28 |
4153 | 29 #include "quit.h" |
30 | |
2982 | 31 #include "defun.h" |
32 #include "error.h" | |
8011
3100283874d7
improve backtrace error messages
John W. Eaton <jwe@octave.org>
parents:
7890
diff
changeset
|
33 #include "gripes.h" |
2982 | 34 #include "ov.h" |
35 #include "oct-lvalue.h" | |
36 #include "input.h" | |
37 #include "pager.h" | |
3770 | 38 #include "pt-bp.h" |
2982 | 39 #include "pt-cmd.h" |
40 #include "pt-id.h" | |
41 #include "pt-idx.h" | |
2985 | 42 #include "pt-jump.h" |
2982 | 43 #include "pt-pr-code.h" |
44 #include "pt-stmt.h" | |
45 #include "pt-walk.h" | |
3707 | 46 #include "unwind-prot.h" |
2982 | 47 #include "utils.h" |
48 #include "variables.h" | |
49 | |
50 // A list of commands to be executed. | |
51 | |
52 tree_statement::~tree_statement (void) | |
53 { | |
54 delete cmd; | |
55 delete expr; | |
3665 | 56 delete comm; |
2982 | 57 } |
58 | |
8658
73c4516fae10
New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents:
8637
diff
changeset
|
59 void |
73c4516fae10
New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents:
8637
diff
changeset
|
60 tree_statement::set_print_flag (bool print_flag) |
73c4516fae10
New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents:
8637
diff
changeset
|
61 { |
73c4516fae10
New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents:
8637
diff
changeset
|
62 if (expr) |
73c4516fae10
New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents:
8637
diff
changeset
|
63 expr->set_print_flag (print_flag); |
73c4516fae10
New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents:
8637
diff
changeset
|
64 } |
73c4516fae10
New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents:
8637
diff
changeset
|
65 |
73c4516fae10
New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents:
8637
diff
changeset
|
66 bool |
73c4516fae10
New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents:
8637
diff
changeset
|
67 tree_statement::print_result (void) |
73c4516fae10
New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents:
8637
diff
changeset
|
68 { |
73c4516fae10
New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents:
8637
diff
changeset
|
69 return expr && expr->print_result (); |
73c4516fae10
New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents:
8637
diff
changeset
|
70 } |
73c4516fae10
New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents:
8637
diff
changeset
|
71 |
8843
b9ce57a309a3
don't store breakpoint info in tree_statement object
John W. Eaton <jwe@octave.org>
parents:
8669
diff
changeset
|
72 void |
b9ce57a309a3
don't store breakpoint info in tree_statement object
John W. Eaton <jwe@octave.org>
parents:
8669
diff
changeset
|
73 tree_statement::set_breakpoint (void) |
b9ce57a309a3
don't store breakpoint info in tree_statement object
John W. Eaton <jwe@octave.org>
parents:
8669
diff
changeset
|
74 { |
b9ce57a309a3
don't store breakpoint info in tree_statement object
John W. Eaton <jwe@octave.org>
parents:
8669
diff
changeset
|
75 if (cmd) |
b9ce57a309a3
don't store breakpoint info in tree_statement object
John W. Eaton <jwe@octave.org>
parents:
8669
diff
changeset
|
76 cmd->set_breakpoint (); |
b9ce57a309a3
don't store breakpoint info in tree_statement object
John W. Eaton <jwe@octave.org>
parents:
8669
diff
changeset
|
77 else if (expr) |
b9ce57a309a3
don't store breakpoint info in tree_statement object
John W. Eaton <jwe@octave.org>
parents:
8669
diff
changeset
|
78 expr->set_breakpoint (); |
b9ce57a309a3
don't store breakpoint info in tree_statement object
John W. Eaton <jwe@octave.org>
parents:
8669
diff
changeset
|
79 } |
b9ce57a309a3
don't store breakpoint info in tree_statement object
John W. Eaton <jwe@octave.org>
parents:
8669
diff
changeset
|
80 |
b9ce57a309a3
don't store breakpoint info in tree_statement object
John W. Eaton <jwe@octave.org>
parents:
8669
diff
changeset
|
81 void |
b9ce57a309a3
don't store breakpoint info in tree_statement object
John W. Eaton <jwe@octave.org>
parents:
8669
diff
changeset
|
82 tree_statement::delete_breakpoint (void) |
b9ce57a309a3
don't store breakpoint info in tree_statement object
John W. Eaton <jwe@octave.org>
parents:
8669
diff
changeset
|
83 { |
b9ce57a309a3
don't store breakpoint info in tree_statement object
John W. Eaton <jwe@octave.org>
parents:
8669
diff
changeset
|
84 if (cmd) |
b9ce57a309a3
don't store breakpoint info in tree_statement object
John W. Eaton <jwe@octave.org>
parents:
8669
diff
changeset
|
85 cmd->delete_breakpoint (); |
b9ce57a309a3
don't store breakpoint info in tree_statement object
John W. Eaton <jwe@octave.org>
parents:
8669
diff
changeset
|
86 else if (expr) |
b9ce57a309a3
don't store breakpoint info in tree_statement object
John W. Eaton <jwe@octave.org>
parents:
8669
diff
changeset
|
87 expr->delete_breakpoint (); |
b9ce57a309a3
don't store breakpoint info in tree_statement object
John W. Eaton <jwe@octave.org>
parents:
8669
diff
changeset
|
88 } |
b9ce57a309a3
don't store breakpoint info in tree_statement object
John W. Eaton <jwe@octave.org>
parents:
8669
diff
changeset
|
89 |
b9ce57a309a3
don't store breakpoint info in tree_statement object
John W. Eaton <jwe@octave.org>
parents:
8669
diff
changeset
|
90 bool |
b9ce57a309a3
don't store breakpoint info in tree_statement object
John W. Eaton <jwe@octave.org>
parents:
8669
diff
changeset
|
91 tree_statement::is_breakpoint (void) const |
b9ce57a309a3
don't store breakpoint info in tree_statement object
John W. Eaton <jwe@octave.org>
parents:
8669
diff
changeset
|
92 { |
b9ce57a309a3
don't store breakpoint info in tree_statement object
John W. Eaton <jwe@octave.org>
parents:
8669
diff
changeset
|
93 return cmd ? cmd->is_breakpoint () : (expr ? expr->is_breakpoint () : false); |
b9ce57a309a3
don't store breakpoint info in tree_statement object
John W. Eaton <jwe@octave.org>
parents:
8669
diff
changeset
|
94 } |
b9ce57a309a3
don't store breakpoint info in tree_statement object
John W. Eaton <jwe@octave.org>
parents:
8669
diff
changeset
|
95 |
2982 | 96 int |
8658
73c4516fae10
New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents:
8637
diff
changeset
|
97 tree_statement::line (void) const |
2982 | 98 { |
99 return cmd ? cmd->line () : (expr ? expr->line () : -1); | |
100 } | |
101 | |
102 int | |
8658
73c4516fae10
New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents:
8637
diff
changeset
|
103 tree_statement::column (void) const |
2982 | 104 { |
105 return cmd ? cmd->column () : (expr ? expr->column () : -1); | |
106 } | |
107 | |
108 void | |
8669
33783e94fb16
line number fixes and other evaluator tweaks
John W. Eaton <jwe@octave.org>
parents:
8658
diff
changeset
|
109 tree_statement::echo_code (void) |
2982 | 110 { |
8669
33783e94fb16
line number fixes and other evaluator tweaks
John W. Eaton <jwe@octave.org>
parents:
8658
diff
changeset
|
111 tree_print_code tpc (octave_stdout, VPS4); |
2982 | 112 |
8669
33783e94fb16
line number fixes and other evaluator tweaks
John W. Eaton <jwe@octave.org>
parents:
8658
diff
changeset
|
113 accept (tpc); |
2982 | 114 } |
115 | |
8658
73c4516fae10
New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents:
8637
diff
changeset
|
116 bool |
73c4516fae10
New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents:
8637
diff
changeset
|
117 tree_statement::is_end_of_fcn_or_script (void) const |
2982 | 118 { |
8658
73c4516fae10
New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents:
8637
diff
changeset
|
119 bool retval = false; |
2982 | 120 |
8658
73c4516fae10
New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents:
8637
diff
changeset
|
121 if (cmd) |
73c4516fae10
New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents:
8637
diff
changeset
|
122 { |
73c4516fae10
New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents:
8637
diff
changeset
|
123 tree_no_op_command *no_op_cmd |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
124 = dynamic_cast<tree_no_op_command *> (cmd); |
2982 | 125 |
8658
73c4516fae10
New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents:
8637
diff
changeset
|
126 if (no_op_cmd) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
127 retval = no_op_cmd->is_end_of_fcn_or_script (); |
2982 | 128 } |
129 | |
130 return retval; | |
131 } | |
132 | |
5861 | 133 tree_statement * |
7767
71f068b22fcc
scope and context fixes for function handles
John W. Eaton <jwe@octave.org>
parents:
7752
diff
changeset
|
134 tree_statement::dup (symbol_table::scope_id scope, |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
135 symbol_table::context_id context) const |
5861 | 136 { |
137 tree_statement *new_stmt = new tree_statement (); | |
138 | |
7767
71f068b22fcc
scope and context fixes for function handles
John W. Eaton <jwe@octave.org>
parents:
7752
diff
changeset
|
139 new_stmt->cmd = cmd ? cmd->dup (scope, context) : 0; |
5861 | 140 |
7767
71f068b22fcc
scope and context fixes for function handles
John W. Eaton <jwe@octave.org>
parents:
7752
diff
changeset
|
141 new_stmt->expr = expr ? expr->dup (scope, context) : 0; |
5861 | 142 |
8658
73c4516fae10
New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents:
8637
diff
changeset
|
143 new_stmt->comm = comm ? comm->dup () : 0; |
5861 | 144 |
145 return new_stmt; | |
146 } | |
147 | |
2982 | 148 void |
149 tree_statement::accept (tree_walker& tw) | |
150 { | |
151 tw.visit_statement (*this); | |
152 } | |
153 | |
3770 | 154 int |
155 tree_statement_list::set_breakpoint (int line) | |
156 { | |
157 tree_breakpoint tbp (line, tree_breakpoint::set); | |
158 accept (tbp); | |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
159 |
3770 | 160 return tbp.get_line (); |
161 } | |
162 | |
163 void | |
164 tree_statement_list::delete_breakpoint (int line) | |
165 { | |
3895 | 166 if (line < 0) |
167 { | |
4212 | 168 octave_value_list bp_lst = list_breakpoints (); |
3895 | 169 |
4212 | 170 int len = bp_lst.length (); |
3895 | 171 |
4587 | 172 for (int i = 0; i < len; i++) |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
173 { |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
174 tree_breakpoint tbp (i, tree_breakpoint::clear); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
175 accept (tbp); |
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
176 } |
3895 | 177 } |
178 else | |
179 { | |
11586
12df7854fa7c
strip trailing whitespace from source files
John W. Eaton <jwe@octave.org>
parents:
11523
diff
changeset
|
180 tree_breakpoint tbp (line, tree_breakpoint::clear); |
3895 | 181 accept (tbp); |
182 } | |
3770 | 183 } |
184 | |
185 octave_value_list | |
186 tree_statement_list::list_breakpoints (void) | |
187 { | |
188 tree_breakpoint tbp (0, tree_breakpoint::list); | |
189 accept (tbp); | |
190 | |
191 return tbp.get_list (); | |
192 } | |
193 | |
5861 | 194 tree_statement_list * |
7767
71f068b22fcc
scope and context fixes for function handles
John W. Eaton <jwe@octave.org>
parents:
7752
diff
changeset
|
195 tree_statement_list::dup (symbol_table::scope_id scope, |
10315
57a59eae83cc
untabify src C++ source files
John W. Eaton <jwe@octave.org>
parents:
10160
diff
changeset
|
196 symbol_table::context_id context) const |
5861 | 197 { |
198 tree_statement_list *new_list = new tree_statement_list (); | |
199 | |
200 new_list->function_body = function_body; | |
201 | |
8913
35cd375d4bb3
make tree::dup functions const
John W. Eaton <jwe@octave.org>
parents:
8844
diff
changeset
|
202 for (const_iterator p = begin (); p != end (); p++) |
5861 | 203 { |
8913
35cd375d4bb3
make tree::dup functions const
John W. Eaton <jwe@octave.org>
parents:
8844
diff
changeset
|
204 const tree_statement *elt = *p; |
5861 | 205 |
7767
71f068b22fcc
scope and context fixes for function handles
John W. Eaton <jwe@octave.org>
parents:
7752
diff
changeset
|
206 new_list->append (elt ? elt->dup (scope, context) : 0); |
5861 | 207 } |
208 | |
209 return new_list; | |
210 } | |
211 | |
2982 | 212 void |
213 tree_statement_list::accept (tree_walker& tw) | |
214 { | |
215 tw.visit_statement_list (*this); | |
216 } |