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 |
|
9 Free Software Foundation; either version 2, or (at your option) any |
|
10 later version. |
|
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 |
|
18 along with Octave; see the file COPYING. If not, write to the Free |
5307
|
19 Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA |
|
20 02110-1301, USA. |
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 |
2982
|
85 void accept (tree_walker& tw); |
|
86 |
|
87 private: |
|
88 |
|
89 // Only one of cmd or expr can be valid at once. |
|
90 |
|
91 // Command to execute. |
|
92 tree_command *cmd; |
|
93 |
|
94 // Expression to evaluate. |
|
95 tree_expression *expr; |
|
96 |
3665
|
97 // Comment associated with this statement. |
|
98 octave_comment_list *comm; |
|
99 |
2982
|
100 // Print result of eval for this command? |
|
101 bool print_flag; |
2988
|
102 |
|
103 // No copying! |
|
104 tree_statement (const tree_statement&); |
|
105 |
|
106 tree_statement& operator = (const tree_statement&); |
2982
|
107 }; |
|
108 |
|
109 // A list of statements to evaluate. |
|
110 |
|
111 class |
4219
|
112 tree_statement_list : public octave_base_list<tree_statement *> |
2982
|
113 { |
|
114 public: |
|
115 |
|
116 tree_statement_list (void) |
4219
|
117 : function_body (false) { } |
2982
|
118 |
|
119 tree_statement_list (tree_statement *s) |
4219
|
120 : function_body (false) { append (s); } |
2982
|
121 |
|
122 ~tree_statement_list (void) |
|
123 { |
4219
|
124 while (! empty ()) |
2982
|
125 { |
4219
|
126 iterator p = begin (); |
|
127 delete *p; |
|
128 erase (p); |
2982
|
129 } |
|
130 } |
|
131 |
|
132 void mark_as_function_body (void) { function_body = true; } |
|
133 |
|
134 octave_value_list eval (bool silent = false, int nargout = 0); |
|
135 |
3770
|
136 int set_breakpoint (int line); |
|
137 |
|
138 void delete_breakpoint (int line); |
|
139 |
|
140 octave_value_list list_breakpoints (void); |
|
141 |
2982
|
142 void accept (tree_walker& tw); |
|
143 |
|
144 private: |
|
145 |
|
146 // Does this list of statements make up the body of a function? |
|
147 bool function_body; |
2988
|
148 |
|
149 // No copying! |
|
150 |
|
151 tree_statement_list (const tree_statement_list&); |
|
152 |
|
153 tree_statement_list& operator = (const tree_statement_list&); |
2982
|
154 }; |
|
155 |
3707
|
156 // Pointer to the current statement being executed. |
|
157 extern tree_statement *curr_statement; |
|
158 |
4975
|
159 // Pointer to the current statement being executed in the calling function. |
|
160 extern tree_statement *curr_caller_statement; |
|
161 |
2982
|
162 #endif |
|
163 |
|
164 /* |
|
165 ;;; Local Variables: *** |
|
166 ;;; mode: C++ *** |
|
167 ;;; End: *** |
|
168 */ |