Mercurial > octave
annotate libinterp/parse-tree/pt-stmt.h @ 23083:e9a0469dedd9 stable
maint: strip extra trailing newlines from files.
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Fri, 20 Jan 2017 12:19:08 -0500 |
parents | 34ce5be04942 |
children | ef4d915df748 3ac9f9ecfae5 |
rev | line source |
---|---|
2982 | 1 /* |
2 | |
22323
bac0d6f07a3e
maint: Update copyright notices for 2016.
John W. Eaton <jwe@octave.org>
parents:
21244
diff
changeset
|
3 Copyright (C) 1996-2016 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 | |
20791
f7084eae3318
maint: Use Octave coding conventions for #if statements.
Rik <rik@octave.org>
parents:
19697
diff
changeset
|
23 #if ! defined (octave_pt_stmt_h) |
17822
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 |
21244
1473547f50f5
include octave-config.h in public header files
John W. Eaton <jwe@octave.org>
parents:
21157
diff
changeset
|
26 #include "octave-config.h" |
1473547f50f5
include octave-config.h in public header files
John W. Eaton <jwe@octave.org>
parents:
21157
diff
changeset
|
27 |
2982 | 28 class octave_value_list; |
29 | |
30 class tree_command; | |
31 class tree_expression; | |
32 | |
33 class tree_walker; | |
34 | |
7552
6070c3bd69c4
Arbitrary call stack access for external debuggers changeset
ryanru@PrinceHumperdinck
parents:
7336
diff
changeset
|
35 #include <deque> |
6070c3bd69c4
Arbitrary call stack access for external debuggers changeset
ryanru@PrinceHumperdinck
parents:
7336
diff
changeset
|
36 |
4219 | 37 #include "base-list.h" |
3665 | 38 #include "comment-list.h" |
16530
7ca7e7d5eb91
remove breakpoints when clearing function
John W. Eaton <jwe@octave.org>
parents:
15195
diff
changeset
|
39 #include "debug.h" |
7336 | 40 #include "symtab.h" |
14899 | 41 #include "pt.h" |
3665 | 42 |
2982 | 43 // A statement is either a command to execute or an expression to |
44 // evaluate. | |
45 | |
46 class | |
14899 | 47 tree_statement : public tree |
2982 | 48 { |
49 public: | |
50 | |
51 tree_statement (void) | |
8843
b9ce57a309a3
don't store breakpoint info in tree_statement object
John W. Eaton <jwe@octave.org>
parents:
8669
diff
changeset
|
52 : cmd (0), expr (0), comm (0) { } |
2982 | 53 |
3665 | 54 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
|
55 : cmd (c), expr (0), comm (cl) { } |
2982 | 56 |
3665 | 57 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
|
58 : cmd (0), expr (e), comm (cl) { } |
2982 | 59 |
60 ~tree_statement (void); | |
61 | |
8658
73c4516fae10
New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents:
8471
diff
changeset
|
62 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
|
63 |
73c4516fae10
New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents:
8471
diff
changeset
|
64 bool print_result (void); |
2982 | 65 |
8658
73c4516fae10
New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents:
8471
diff
changeset
|
66 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
|
67 |
73c4516fae10
New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents:
8471
diff
changeset
|
68 bool is_expression (void) const { return expr != 0; } |
2982 | 69 |
21157
94fc5f13d51b
dbstop: conditional breakpoint, dbstop if caught error etc. (bug #46795)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
20791
diff
changeset
|
70 void set_breakpoint (const std::string& condition); |
8658
73c4516fae10
New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents:
8471
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 delete_breakpoint (void); |
2982 | 73 |
21157
94fc5f13d51b
dbstop: conditional breakpoint, dbstop if caught error etc. (bug #46795)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
20791
diff
changeset
|
74 bool is_breakpoint (bool check_valid = false) const; |
94fc5f13d51b
dbstop: conditional breakpoint, dbstop if caught error etc. (bug #46795)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
20791
diff
changeset
|
75 std::string bp_cond () const; |
8658
73c4516fae10
New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents:
8471
diff
changeset
|
76 |
73c4516fae10
New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents:
8471
diff
changeset
|
77 int line (void) const; |
73c4516fae10
New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents:
8471
diff
changeset
|
78 int column (void) const; |
2982 | 79 |
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
|
80 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
|
81 |
8669
33783e94fb16
line number fixes and other evaluator tweaks
John W. Eaton <jwe@octave.org>
parents:
8658
diff
changeset
|
82 void echo_code (void); |
2982 | 83 |
84 tree_command *command (void) { return cmd; } | |
85 | |
86 tree_expression *expression (void) { return expr; } | |
87 | |
3665 | 88 octave_comment_list *comment_text (void) { return comm; } |
89 | |
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
|
90 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
|
91 |
8658
73c4516fae10
New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents:
8471
diff
changeset
|
92 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
|
93 |
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
|
94 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
|
95 |
4935 | 96 // Allow modification of this statement. Note that there is no |
97 // checking. If you use these, are you sure you knwo what you are | |
98 // doing? | |
99 | |
100 void set_command (tree_command *c) { cmd = c; } | |
101 | |
102 void set_expression (tree_expression *e) { expr = e; } | |
103 | |
7767
71f068b22fcc
scope and context fixes for function handles
John W. Eaton <jwe@octave.org>
parents:
7736
diff
changeset
|
104 tree_statement *dup (symbol_table::scope_id scope, |
10313 | 105 symbol_table::context_id context) const; |
5861 | 106 |
2982 | 107 void accept (tree_walker& tw); |
108 | |
109 private: | |
110 | |
111 // Only one of cmd or expr can be valid at once. | |
112 | |
113 // Command to execute. | |
114 tree_command *cmd; | |
115 | |
116 // Expression to evaluate. | |
117 tree_expression *expr; | |
118 | |
3665 | 119 // Comment associated with this statement. |
120 octave_comment_list *comm; | |
121 | |
2988 | 122 // No copying! |
123 tree_statement (const tree_statement&); | |
124 | |
125 tree_statement& operator = (const tree_statement&); | |
2982 | 126 }; |
127 | |
128 // A list of statements to evaluate. | |
129 | |
130 class | |
22333
2758af148ced
move base_list and regexp classes to octave namespace
John W. Eaton <jwe@octave.org>
parents:
22323
diff
changeset
|
131 tree_statement_list : public octave::base_list<tree_statement *> |
2982 | 132 { |
133 public: | |
134 | |
135 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
|
136 : 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
|
137 script_body (false) { } |
2982 | 138 |
139 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
|
140 : 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
|
141 script_body (false) { append (s); } |
2982 | 142 |
143 ~tree_statement_list (void) | |
17787
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
144 { |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
145 while (! empty ()) |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
146 { |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
147 iterator p = begin (); |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
148 delete *p; |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
149 erase (p); |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
150 } |
175b392e91fe
Use GNU style coding conventions for code in libinterp/
Rik <rik@octave.org>
parents:
17744
diff
changeset
|
151 } |
2982 | 152 |
153 void mark_as_function_body (void) { function_body = true; } | |
154 | |
8658
73c4516fae10
New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents:
8471
diff
changeset
|
155 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
|
156 |
7736 | 157 void mark_as_script_body (void) { script_body = true; } |
158 | |
8658
73c4516fae10
New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents:
8471
diff
changeset
|
159 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
|
160 |
73c4516fae10
New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents:
8471
diff
changeset
|
161 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
|
162 |
73c4516fae10
New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents:
8471
diff
changeset
|
163 bool is_script_body (void) const { return script_body; } |
2982 | 164 |
21157
94fc5f13d51b
dbstop: conditional breakpoint, dbstop if caught error etc. (bug #46795)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
20791
diff
changeset
|
165 int set_breakpoint (int line, const std::string& condition); |
3770 | 166 |
167 void delete_breakpoint (int line); | |
168 | |
169 octave_value_list list_breakpoints (void); | |
170 | |
21157
94fc5f13d51b
dbstop: conditional breakpoint, dbstop if caught error etc. (bug #46795)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
20791
diff
changeset
|
171 std::list<bp_type> breakpoints_and_conds (void); |
94fc5f13d51b
dbstop: conditional breakpoint, dbstop if caught error etc. (bug #46795)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
20791
diff
changeset
|
172 |
16530
7ca7e7d5eb91
remove breakpoints when clearing function
John W. Eaton <jwe@octave.org>
parents:
15195
diff
changeset
|
173 bp_table::intmap add_breakpoint (const std::string& file, |
21157
94fc5f13d51b
dbstop: conditional breakpoint, dbstop if caught error etc. (bug #46795)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
20791
diff
changeset
|
174 const bp_table::intmap& line, |
94fc5f13d51b
dbstop: conditional breakpoint, dbstop if caught error etc. (bug #46795)
Lachlan Andrew <lachlanbis@gmail.com>
parents:
20791
diff
changeset
|
175 const std::string& condition); |
16530
7ca7e7d5eb91
remove breakpoints when clearing function
John W. Eaton <jwe@octave.org>
parents:
15195
diff
changeset
|
176 |
7ca7e7d5eb91
remove breakpoints when clearing function
John W. Eaton <jwe@octave.org>
parents:
15195
diff
changeset
|
177 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
|
178 |
7767
71f068b22fcc
scope and context fixes for function handles
John W. Eaton <jwe@octave.org>
parents:
7736
diff
changeset
|
179 tree_statement_list *dup (symbol_table::scope_id scope, |
10313 | 180 symbol_table::context_id context) const; |
5861 | 181 |
2982 | 182 void accept (tree_walker& tw); |
183 | |
184 private: | |
185 | |
186 // Does this list of statements make up the body of a function? | |
187 bool function_body; | |
2988 | 188 |
8658
73c4516fae10
New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents:
8471
diff
changeset
|
189 // 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
|
190 bool anon_function_body; |
73c4516fae10
New evaluator and debugger derived from tree-walker class
John W. Eaton <jwe@octave.org>
parents:
8471
diff
changeset
|
191 |
7736 | 192 // Does this list of statements make up the body of a script? |
193 bool script_body; | |
194 | |
2988 | 195 // No copying! |
196 | |
197 tree_statement_list (const tree_statement_list&); | |
198 | |
199 tree_statement_list& operator = (const tree_statement_list&); | |
2982 | 200 }; |
201 | |
202 #endif |