Mercurial > hg > octave-nkf
annotate libinterp/parse-tree/pt-stmt.h @ 19840:c5270263d466 gui-release
close gui-release branch
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Fri, 30 Jan 2015 17:41:50 -0500 |
parents | ebb3ef964372 |
children | 4197fc428c7d |
rev | line source |
---|---|
2982 | 1 /* |
2 | |
17744
d63878346099
maint: Update copyright notices for release.
John W. Eaton <jwe@octave.org>
parents:
16627
diff
changeset
|
3 Copyright (C) 1996-2013 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 | |
17822
ebb3ef964372
maint: Use common #define syntax "octave_filename_h" in h_files.
Rik <rik@octave.org>
parents:
17787
diff
changeset
|
23 #if !defined (octave_pt_stmt_h) |
ebb3ef964372
maint: Use common #define syntax "octave_filename_h" in h_files.
Rik <rik@octave.org>
parents:
17787
diff
changeset
|
24 #define octave_pt_stmt_h 1 |
2982 | 25 |
26 class octave_value_list; | |
27 | |
28 class tree_command; | |
29 class tree_expression; | |
30 | |
31 class tree_walker; | |
32 | |
7552
6070c3bd69c4
Arbitrary call stack access for external debuggers changeset
ryanru@PrinceHumperdinck
parents:
7336
diff
changeset
|
33 #include <deque> |
6070c3bd69c4
Arbitrary call stack access for external debuggers changeset
ryanru@PrinceHumperdinck
parents:
7336
diff
changeset
|
34 |
4219 | 35 #include "base-list.h" |
3665 | 36 #include "comment-list.h" |
16530
7ca7e7d5eb91
remove breakpoints when clearing function
John W. Eaton <jwe@octave.org>
parents:
15195
diff
changeset
|
37 #include "debug.h" |
7336 | 38 #include "symtab.h" |
14899 | 39 #include "pt.h" |
3665 | 40 |
2982 | 41 // A statement is either a command to execute or an expression to |
42 // evaluate. | |
43 | |
44 class | |
14899 | 45 tree_statement : public tree |
2982 | 46 { |
47 public: | |
48 | |
49 tree_statement (void) | |
8843
b9ce57a309a3
don't store breakpoint info in tree_statement object
John W. Eaton <jwe@octave.org>
parents:
8669
diff
changeset
|
50 : cmd (0), expr (0), comm (0) { } |
2982 | 51 |
3665 | 52 tree_statement (tree_command *c, octave_comment_list *cl) |
8843
b9ce57a309a3
don't store breakpoint info in tree_statement object
John W. Eaton <jwe@octave.org>
parents:
8669
diff
changeset
|
53 : cmd (c), expr (0), comm (cl) { } |
2982 | 54 |
3665 | 55 tree_statement (tree_expression *e, octave_comment_list *cl) |
8843
b9ce57a309a3
don't store breakpoint info in tree_statement object
John W. Eaton <jwe@octave.org>
parents:
8669
diff
changeset
|
56 : cmd (0), expr (e), comm (cl) { } |
2982 | 57 |
58 ~tree_statement (void); | |
59 | |
8658
73c4516fae10
New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents:
8471
diff
changeset
|
60 void set_print_flag (bool print_flag); |
73c4516fae10
New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents:
8471
diff
changeset
|
61 |
73c4516fae10
New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents:
8471
diff
changeset
|
62 bool print_result (void); |
2982 | 63 |
8658
73c4516fae10
New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents:
8471
diff
changeset
|
64 bool is_command (void) const { return cmd != 0; } |
73c4516fae10
New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents:
8471
diff
changeset
|
65 |
73c4516fae10
New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents:
8471
diff
changeset
|
66 bool is_expression (void) const { return expr != 0; } |
2982 | 67 |
8843
b9ce57a309a3
don't store breakpoint info in tree_statement object
John W. Eaton <jwe@octave.org>
parents:
8669
diff
changeset
|
68 void set_breakpoint (void); |
8658
73c4516fae10
New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents:
8471
diff
changeset
|
69 |
8843
b9ce57a309a3
don't store breakpoint info in tree_statement object
John W. Eaton <jwe@octave.org>
parents:
8669
diff
changeset
|
70 void delete_breakpoint (void); |
2982 | 71 |
8843
b9ce57a309a3
don't store breakpoint info in tree_statement object
John W. Eaton <jwe@octave.org>
parents:
8669
diff
changeset
|
72 bool is_breakpoint (void) const; |
8658
73c4516fae10
New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents:
8471
diff
changeset
|
73 |
73c4516fae10
New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents:
8471
diff
changeset
|
74 int line (void) const; |
73c4516fae10
New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents:
8471
diff
changeset
|
75 int column (void) const; |
2982 | 76 |
16627
de91b1621260
adjust location of eof marker for files with subfunctions but no explicit end statements
John W. Eaton <jwe@octave.org>
parents:
16530
diff
changeset
|
77 void set_location (int l, int c); |
de91b1621260
adjust location of eof marker for files with subfunctions but no explicit end statements
John W. Eaton <jwe@octave.org>
parents:
16530
diff
changeset
|
78 |
8669
33783e94fb16
line number fixes and other evaluator tweaks
John W. Eaton <jwe@octave.org>
parents:
8658
diff
changeset
|
79 void echo_code (void); |
2982 | 80 |
81 tree_command *command (void) { return cmd; } | |
82 | |
83 tree_expression *expression (void) { return expr; } | |
84 | |
3665 | 85 octave_comment_list *comment_text (void) { return comm; } |
86 | |
8471
02de6775f1fe
parse.y: always append statements to list, but remove null statements after seeing separator
John W. Eaton <jwe@octave.org>
parents:
7767
diff
changeset
|
87 bool is_null_statement (void) const { return ! (cmd || expr || comm); } |
02de6775f1fe
parse.y: always append statements to list, but remove null statements after seeing separator
John W. Eaton <jwe@octave.org>
parents:
7767
diff
changeset
|
88 |
8658
73c4516fae10
New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents:
8471
diff
changeset
|
89 bool is_end_of_fcn_or_script (void) const; |
73c4516fae10
New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents:
8471
diff
changeset
|
90 |
16627
de91b1621260
adjust location of eof marker for files with subfunctions but no explicit end statements
John W. Eaton <jwe@octave.org>
parents:
16530
diff
changeset
|
91 bool is_end_of_file (void) const; |
de91b1621260
adjust location of eof marker for files with subfunctions but no explicit end statements
John W. Eaton <jwe@octave.org>
parents:
16530
diff
changeset
|
92 |
4935 | 93 // Allow modification of this statement. Note that there is no |
94 // checking. If you use these, are you sure you knwo what you are | |
95 // doing? | |
96 | |
97 void set_command (tree_command *c) { cmd = c; } | |
98 | |
99 void set_expression (tree_expression *e) { expr = e; } | |
100 | |
7767
71f068b22fcc
scope and context fixes for function handles
John W. Eaton <jwe@octave.org>
parents:
7736
diff
changeset
|
101 tree_statement *dup (symbol_table::scope_id scope, |
10313 | 102 symbol_table::context_id context) const; |
5861 | 103 |
2982 | 104 void accept (tree_walker& tw); |
105 | |
106 private: | |
107 | |
108 // Only one of cmd or expr can be valid at once. | |
109 | |
110 // Command to execute. | |
111 tree_command *cmd; | |
112 | |
113 // Expression to evaluate. | |
114 tree_expression *expr; | |
115 | |
3665 | 116 // Comment associated with this statement. |
117 octave_comment_list *comm; | |
118 | |
2988 | 119 // No copying! |
120 tree_statement (const tree_statement&); | |
121 | |
122 tree_statement& operator = (const tree_statement&); | |
2982 | 123 }; |
124 | |
125 // A list of statements to evaluate. | |
126 | |
127 class | |
4219 | 128 tree_statement_list : public octave_base_list<tree_statement *> |
2982 | 129 { |
130 public: | |
131 | |
132 tree_statement_list (void) | |
8658
73c4516fae10
New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents:
8471
diff
changeset
|
133 : function_body (false), anon_function_body (false), |
73c4516fae10
New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents:
8471
diff
changeset
|
134 script_body (false) { } |
2982 | 135 |
136 tree_statement_list (tree_statement *s) | |
8658
73c4516fae10
New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents:
8471
diff
changeset
|
137 : function_body (false), anon_function_body (false), |
73c4516fae10
New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents:
8471
diff
changeset
|
138 script_body (false) { append (s); } |
2982 | 139 |
140 ~tree_statement_list (void) | |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
141 { |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
142 while (! empty ()) |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
143 { |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
144 iterator p = begin (); |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
145 delete *p; |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
146 erase (p); |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
147 } |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
148 } |
2982 | 149 |
150 void mark_as_function_body (void) { function_body = true; } | |
151 | |
8658
73c4516fae10
New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents:
8471
diff
changeset
|
152 void mark_as_anon_function_body (void) { anon_function_body = true; } |
73c4516fae10
New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents:
8471
diff
changeset
|
153 |
7736 | 154 void mark_as_script_body (void) { script_body = true; } |
155 | |
8658
73c4516fae10
New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents:
8471
diff
changeset
|
156 bool is_function_body (void) const { return function_body; } |
73c4516fae10
New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents:
8471
diff
changeset
|
157 |
73c4516fae10
New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents:
8471
diff
changeset
|
158 bool is_anon_function_body (void) const { return anon_function_body; } |
73c4516fae10
New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents:
8471
diff
changeset
|
159 |
73c4516fae10
New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents:
8471
diff
changeset
|
160 bool is_script_body (void) const { return script_body; } |
2982 | 161 |
3770 | 162 int set_breakpoint (int line); |
163 | |
164 void delete_breakpoint (int line); | |
165 | |
166 octave_value_list list_breakpoints (void); | |
167 | |
16530
7ca7e7d5eb91
remove breakpoints when clearing function
John W. Eaton <jwe@octave.org>
parents:
15195
diff
changeset
|
168 bp_table::intmap add_breakpoint (const std::string& file, |
7ca7e7d5eb91
remove breakpoints when clearing function
John W. Eaton <jwe@octave.org>
parents:
15195
diff
changeset
|
169 const bp_table::intmap& line); |
7ca7e7d5eb91
remove breakpoints when clearing function
John W. Eaton <jwe@octave.org>
parents:
15195
diff
changeset
|
170 |
7ca7e7d5eb91
remove breakpoints when clearing function
John W. Eaton <jwe@octave.org>
parents:
15195
diff
changeset
|
171 bp_table::intmap remove_all_breakpoints (const std::string& file); |
7ca7e7d5eb91
remove breakpoints when clearing function
John W. Eaton <jwe@octave.org>
parents:
15195
diff
changeset
|
172 |
7767
71f068b22fcc
scope and context fixes for function handles
John W. Eaton <jwe@octave.org>
parents:
7736
diff
changeset
|
173 tree_statement_list *dup (symbol_table::scope_id scope, |
10313 | 174 symbol_table::context_id context) const; |
5861 | 175 |
2982 | 176 void accept (tree_walker& tw); |
177 | |
178 private: | |
179 | |
180 // Does this list of statements make up the body of a function? | |
181 bool function_body; | |
2988 | 182 |
8658
73c4516fae10
New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents:
8471
diff
changeset
|
183 // Does this list of statements make up the body of a function? |
73c4516fae10
New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents:
8471
diff
changeset
|
184 bool anon_function_body; |
73c4516fae10
New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents:
8471
diff
changeset
|
185 |
7736 | 186 // Does this list of statements make up the body of a script? |
187 bool script_body; | |
188 | |
2988 | 189 // No copying! |
190 | |
191 tree_statement_list (const tree_statement_list&); | |
192 | |
193 tree_statement_list& operator = (const tree_statement_list&); | |
2982 | 194 }; |
195 | |
196 #endif |