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 |
|
19 Software Foundation, 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. |
|
20 |
|
21 */ |
|
22 |
|
23 #if !defined (octave_tree_stmt_h) |
|
24 #define octave_tree_stmt_h 1 |
|
25 |
|
26 #if defined (__GNUG__) |
|
27 #pragma interface |
|
28 #endif |
|
29 |
|
30 #include <SLList.h> |
|
31 |
|
32 class octave_value_list; |
|
33 |
|
34 class tree_command; |
|
35 class tree_expression; |
|
36 |
|
37 class tree_walker; |
|
38 |
|
39 // A statement is either a command to execute or an expression to |
|
40 // evaluate. |
|
41 |
|
42 class |
|
43 tree_statement |
|
44 { |
|
45 public: |
|
46 |
|
47 tree_statement (void) |
|
48 : cmd (0), expr (0), print_flag (true) { } |
|
49 |
|
50 tree_statement (tree_command *c) |
|
51 : cmd (c), expr (0), print_flag (true) { } |
|
52 |
|
53 tree_statement (tree_expression *e) |
|
54 : cmd (0), expr (e), print_flag (true) { } |
|
55 |
|
56 ~tree_statement (void); |
|
57 |
|
58 void set_print_flag (bool print) |
|
59 { print_flag = print; } |
|
60 |
|
61 bool is_command (void) |
|
62 { return cmd != 0; } |
|
63 |
|
64 bool is_expression (void) |
|
65 { return expr != 0; } |
|
66 |
|
67 int line (void); |
|
68 int column (void); |
|
69 |
|
70 void maybe_echo_code (bool in_function_body); |
|
71 |
|
72 bool print_result (void) { return print_flag; } |
|
73 |
|
74 tree_command *command (void) { return cmd; } |
|
75 |
|
76 octave_value_list eval (bool silent, int nargout, bool in_function_body); |
|
77 |
|
78 tree_expression *expression (void) { return expr; } |
|
79 |
|
80 void accept (tree_walker& tw); |
|
81 |
|
82 private: |
|
83 |
|
84 // Only one of cmd or expr can be valid at once. |
|
85 |
|
86 // Command to execute. |
|
87 tree_command *cmd; |
|
88 |
|
89 // Expression to evaluate. |
|
90 tree_expression *expr; |
|
91 |
|
92 // Print result of eval for this command? |
|
93 bool print_flag; |
2988
|
94 |
|
95 // No copying! |
|
96 |
|
97 tree_statement (const tree_statement&); |
|
98 |
|
99 tree_statement& operator = (const tree_statement&); |
2982
|
100 }; |
|
101 |
|
102 // A list of statements to evaluate. |
|
103 |
|
104 class |
|
105 tree_statement_list : public SLList<tree_statement *> |
|
106 { |
|
107 public: |
|
108 |
|
109 tree_statement_list (void) |
|
110 : SLList<tree_statement *> (), function_body (false) { } |
|
111 |
|
112 tree_statement_list (tree_statement *s) |
|
113 : SLList<tree_statement *> (), function_body (false) { append (s); } |
|
114 |
|
115 ~tree_statement_list (void) |
|
116 { |
|
117 while (! empty ()) |
|
118 { |
|
119 tree_statement *t = remove_front (); |
|
120 delete t; |
|
121 } |
|
122 } |
|
123 |
|
124 void mark_as_function_body (void) { function_body = true; } |
|
125 |
|
126 octave_value_list eval (bool silent = false, int nargout = 0); |
|
127 |
|
128 void accept (tree_walker& tw); |
|
129 |
|
130 private: |
|
131 |
|
132 // Does this list of statements make up the body of a function? |
|
133 bool function_body; |
2988
|
134 |
|
135 // No copying! |
|
136 |
|
137 tree_statement_list (const tree_statement_list&); |
|
138 |
|
139 tree_statement_list& operator = (const tree_statement_list&); |
2982
|
140 }; |
|
141 |
|
142 #endif |
|
143 |
|
144 /* |
|
145 ;;; Local Variables: *** |
|
146 ;;; mode: C++ *** |
|
147 ;;; End: *** |
|
148 */ |