Mercurial > octave
annotate src/pt-stmt.h @ 8471:02de6775f1fe
parse.y: always append statements to list, but remove null statements after seeing separator
author | John W. Eaton <jwe@octave.org> |
---|---|
date | Mon, 12 Jan 2009 19:03:33 -0500 |
parents | 71f068b22fcc |
children | 73c4516fae10 |
rev | line source |
---|---|
2982 | 1 /* |
2 | |
7017 | 3 Copyright (C) 1996, 1997, 2000, 2001, 2002, 2004, 2005, 2006, 2007 |
4 John W. Eaton | |
2982 | 5 |
6 This file is part of Octave. | |
7 | |
8 Octave is free software; you can redistribute it and/or modify it | |
9 under the terms of the GNU General Public License as published by the | |
7016 | 10 Free Software Foundation; either version 3 of the License, or (at your |
11 option) any later version. | |
2982 | 12 |
13 Octave is distributed in the hope that it will be useful, but WITHOUT | |
14 ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or | |
15 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License | |
16 for more details. | |
17 | |
18 You should have received a copy of the GNU General Public License | |
7016 | 19 along with Octave; see the file COPYING. If not, see |
20 <http://www.gnu.org/licenses/>. | |
2982 | 21 |
22 */ | |
23 | |
24 #if !defined (octave_tree_stmt_h) | |
25 #define octave_tree_stmt_h 1 | |
26 | |
27 class octave_value_list; | |
28 | |
29 class tree_command; | |
30 class tree_expression; | |
31 | |
32 class tree_walker; | |
33 | |
7552
6070c3bd69c4
Arbitrary call stack access for external debuggers changeset
ryanru@PrinceHumperdinck
parents:
7336
diff
changeset
|
34 #include <deque> |
6070c3bd69c4
Arbitrary call stack access for external debuggers changeset
ryanru@PrinceHumperdinck
parents:
7336
diff
changeset
|
35 |
4219 | 36 #include "base-list.h" |
3665 | 37 #include "comment-list.h" |
7336 | 38 #include "symtab.h" |
3665 | 39 |
2982 | 40 // A statement is either a command to execute or an expression to |
41 // evaluate. | |
42 | |
43 class | |
44 tree_statement | |
45 { | |
46 public: | |
47 | |
48 tree_statement (void) | |
3665 | 49 : cmd (0), expr (0), comm (0), print_flag (true) { } |
2982 | 50 |
3665 | 51 tree_statement (tree_command *c, octave_comment_list *cl) |
52 : cmd (c), expr (0), comm (cl), print_flag (true) { } | |
2982 | 53 |
3665 | 54 tree_statement (tree_expression *e, octave_comment_list *cl) |
55 : cmd (0), expr (e), comm (cl), print_flag (true) { } | |
2982 | 56 |
57 ~tree_statement (void); | |
58 | |
3933 | 59 void set_print_flag (bool print) { print_flag = print; } |
2982 | 60 |
3933 | 61 bool is_command (void) { return cmd != 0; } |
2982 | 62 |
3933 | 63 bool is_expression (void) { return expr != 0; } |
2982 | 64 |
65 int line (void); | |
66 int column (void); | |
67 | |
68 void maybe_echo_code (bool in_function_body); | |
69 | |
70 bool print_result (void) { return print_flag; } | |
71 | |
72 tree_command *command (void) { return cmd; } | |
73 | |
7736 | 74 octave_value_list eval (bool silent, int nargout, |
75 bool in_function_or_script_body); | |
2982 | 76 |
77 tree_expression *expression (void) { return expr; } | |
78 | |
3665 | 79 octave_comment_list *comment_text (void) { return comm; } |
80 | |
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
|
81 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
|
82 |
4935 | 83 // Allow modification of this statement. Note that there is no |
84 // checking. If you use these, are you sure you knwo what you are | |
85 // doing? | |
86 | |
87 void set_command (tree_command *c) { cmd = c; } | |
88 | |
89 void set_expression (tree_expression *e) { expr = e; } | |
90 | |
7767
71f068b22fcc
scope and context fixes for function handles
John W. Eaton <jwe@octave.org>
parents:
7736
diff
changeset
|
91 tree_statement *dup (symbol_table::scope_id scope, |
71f068b22fcc
scope and context fixes for function handles
John W. Eaton <jwe@octave.org>
parents:
7736
diff
changeset
|
92 symbol_table::context_id context); |
5861 | 93 |
2982 | 94 void accept (tree_walker& tw); |
95 | |
96 private: | |
97 | |
98 // Only one of cmd or expr can be valid at once. | |
99 | |
100 // Command to execute. | |
101 tree_command *cmd; | |
102 | |
103 // Expression to evaluate. | |
104 tree_expression *expr; | |
105 | |
3665 | 106 // Comment associated with this statement. |
107 octave_comment_list *comm; | |
108 | |
2982 | 109 // Print result of eval for this command? |
110 bool print_flag; | |
2988 | 111 |
112 // No copying! | |
113 tree_statement (const tree_statement&); | |
114 | |
115 tree_statement& operator = (const tree_statement&); | |
2982 | 116 }; |
117 | |
118 // A list of statements to evaluate. | |
119 | |
120 class | |
4219 | 121 tree_statement_list : public octave_base_list<tree_statement *> |
2982 | 122 { |
123 public: | |
124 | |
125 tree_statement_list (void) | |
7736 | 126 : function_body (false), script_body (false) { } |
2982 | 127 |
128 tree_statement_list (tree_statement *s) | |
7736 | 129 : function_body (false), script_body (false) { append (s); } |
2982 | 130 |
131 ~tree_statement_list (void) | |
132 { | |
4219 | 133 while (! empty ()) |
2982 | 134 { |
4219 | 135 iterator p = begin (); |
136 delete *p; | |
137 erase (p); | |
2982 | 138 } |
139 } | |
140 | |
141 void mark_as_function_body (void) { function_body = true; } | |
142 | |
7736 | 143 void mark_as_script_body (void) { script_body = true; } |
144 | |
2982 | 145 octave_value_list eval (bool silent = false, int nargout = 0); |
146 | |
3770 | 147 int set_breakpoint (int line); |
148 | |
149 void delete_breakpoint (int line); | |
150 | |
151 octave_value_list list_breakpoints (void); | |
152 | |
7767
71f068b22fcc
scope and context fixes for function handles
John W. Eaton <jwe@octave.org>
parents:
7736
diff
changeset
|
153 tree_statement_list *dup (symbol_table::scope_id scope, |
71f068b22fcc
scope and context fixes for function handles
John W. Eaton <jwe@octave.org>
parents:
7736
diff
changeset
|
154 symbol_table::context_id context); |
5861 | 155 |
2982 | 156 void accept (tree_walker& tw); |
157 | |
158 private: | |
159 | |
160 // Does this list of statements make up the body of a function? | |
161 bool function_body; | |
2988 | 162 |
7736 | 163 // Does this list of statements make up the body of a script? |
164 bool script_body; | |
165 | |
2988 | 166 // No copying! |
167 | |
168 tree_statement_list (const tree_statement_list&); | |
169 | |
170 tree_statement_list& operator = (const tree_statement_list&); | |
2982 | 171 }; |
172 | |
173 #endif | |
174 | |
175 /* | |
176 ;;; Local Variables: *** | |
177 ;;; mode: C++ *** | |
178 ;;; End: *** | |
179 */ |