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