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 |
4219
|
34 #include "base-list.h" |
3665
|
35 #include "comment-list.h" |
|
36 |
2982
|
37 // A statement is either a command to execute or an expression to |
|
38 // evaluate. |
|
39 |
|
40 class |
|
41 tree_statement |
|
42 { |
|
43 public: |
|
44 |
|
45 tree_statement (void) |
3665
|
46 : cmd (0), expr (0), comm (0), print_flag (true) { } |
2982
|
47 |
3665
|
48 tree_statement (tree_command *c, octave_comment_list *cl) |
|
49 : cmd (c), expr (0), comm (cl), print_flag (true) { } |
2982
|
50 |
3665
|
51 tree_statement (tree_expression *e, octave_comment_list *cl) |
|
52 : cmd (0), expr (e), comm (cl), print_flag (true) { } |
2982
|
53 |
|
54 ~tree_statement (void); |
|
55 |
3933
|
56 void set_print_flag (bool print) { print_flag = print; } |
2982
|
57 |
3933
|
58 bool is_command (void) { return cmd != 0; } |
2982
|
59 |
3933
|
60 bool is_expression (void) { return expr != 0; } |
2982
|
61 |
|
62 int line (void); |
|
63 int column (void); |
|
64 |
|
65 void maybe_echo_code (bool in_function_body); |
|
66 |
|
67 bool print_result (void) { return print_flag; } |
|
68 |
|
69 tree_command *command (void) { return cmd; } |
|
70 |
|
71 octave_value_list eval (bool silent, int nargout, bool in_function_body); |
|
72 |
|
73 tree_expression *expression (void) { return expr; } |
|
74 |
3665
|
75 octave_comment_list *comment_text (void) { return comm; } |
|
76 |
4935
|
77 // Allow modification of this statement. Note that there is no |
|
78 // checking. If you use these, are you sure you knwo what you are |
|
79 // doing? |
|
80 |
|
81 void set_command (tree_command *c) { cmd = c; } |
|
82 |
|
83 void set_expression (tree_expression *e) { expr = e; } |
|
84 |
5861
|
85 tree_statement *dup (symbol_table *sym_tab); |
|
86 |
2982
|
87 void accept (tree_walker& tw); |
|
88 |
|
89 private: |
|
90 |
|
91 // Only one of cmd or expr can be valid at once. |
|
92 |
|
93 // Command to execute. |
|
94 tree_command *cmd; |
|
95 |
|
96 // Expression to evaluate. |
|
97 tree_expression *expr; |
|
98 |
3665
|
99 // Comment associated with this statement. |
|
100 octave_comment_list *comm; |
|
101 |
2982
|
102 // Print result of eval for this command? |
|
103 bool print_flag; |
2988
|
104 |
|
105 // No copying! |
|
106 tree_statement (const tree_statement&); |
|
107 |
|
108 tree_statement& operator = (const tree_statement&); |
2982
|
109 }; |
|
110 |
|
111 // A list of statements to evaluate. |
|
112 |
|
113 class |
4219
|
114 tree_statement_list : public octave_base_list<tree_statement *> |
2982
|
115 { |
|
116 public: |
|
117 |
|
118 tree_statement_list (void) |
4219
|
119 : function_body (false) { } |
2982
|
120 |
|
121 tree_statement_list (tree_statement *s) |
4219
|
122 : function_body (false) { append (s); } |
2982
|
123 |
|
124 ~tree_statement_list (void) |
|
125 { |
4219
|
126 while (! empty ()) |
2982
|
127 { |
4219
|
128 iterator p = begin (); |
|
129 delete *p; |
|
130 erase (p); |
2982
|
131 } |
|
132 } |
|
133 |
|
134 void mark_as_function_body (void) { function_body = true; } |
|
135 |
|
136 octave_value_list eval (bool silent = false, int nargout = 0); |
|
137 |
3770
|
138 int set_breakpoint (int line); |
|
139 |
|
140 void delete_breakpoint (int line); |
|
141 |
|
142 octave_value_list list_breakpoints (void); |
|
143 |
5861
|
144 tree_statement_list *dup (symbol_table *sym_tab); |
|
145 |
2982
|
146 void accept (tree_walker& tw); |
|
147 |
|
148 private: |
|
149 |
|
150 // Does this list of statements make up the body of a function? |
|
151 bool function_body; |
2988
|
152 |
|
153 // No copying! |
|
154 |
|
155 tree_statement_list (const tree_statement_list&); |
|
156 |
|
157 tree_statement_list& operator = (const tree_statement_list&); |
2982
|
158 }; |
|
159 |
3707
|
160 // Pointer to the current statement being executed. |
|
161 extern tree_statement *curr_statement; |
|
162 |
4975
|
163 // Pointer to the current statement being executed in the calling function. |
|
164 extern tree_statement *curr_caller_statement; |
|
165 |
2982
|
166 #endif |
|
167 |
|
168 /* |
|
169 ;;; Local Variables: *** |
|
170 ;;; mode: C++ *** |
|
171 ;;; End: *** |
|
172 */ |