File: ucstmt.h

package info (click to toggle)
exult 1.2-15.3
  • links: PTS, VCS
  • area: contrib
  • in suites: jessie, jessie-kfreebsd
  • size: 8,656 kB
  • ctags: 10,524
  • sloc: cpp: 99,373; sh: 7,324; ansic: 4,659; makefile: 991; yacc: 769; lex: 313; xml: 19
file content (286 lines) | stat: -rw-r--r-- 6,922 bytes parent folder | download | duplicates (8)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
/**
 **	Ucstmt.h - Usecode compiler statements.
 **
 **	Written: 1/2/01 - JSF
 **/

/*
Copyright (C) 2000 The Exult Team

This program is free software; you can redistribute it and/or
modify it under the terms of the GNU General Public License
as published by the Free Software Foundation; either version 2
of the License, or (at your option) any later version.

This program is distributed in the hope that it will be useful,
but WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
GNU General Public License for more details.

You should have received a copy of the GNU General Public License
along with this program; if not, write to the Free Software
Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
*/

#ifndef INCL_UCSTMT
#define INCL_UCSTMT

#include <vector>
#include "ucloc.h"
#include "uclabel.h"

class Uc_expression;
class Uc_call_expression;
class Uc_array_expression;
class Uc_function;
class Uc_var_symbol;

#ifndef ALPHA_LINUX_CXX
#  include <iosfwd>
#endif

/*
 *	A statement:
 */
class Uc_statement : public Uc_location
	{
public:
	Uc_statement() : Uc_location()
		{  }
	virtual ~Uc_statement() {  }
					// Generate code.
	virtual void gen(std::vector<char>& out, Uc_function *fun) = 0;
	};

/*
 *	A group of statements.
 */
class Uc_block_statement : public Uc_statement
	{
		std::vector<Uc_statement *> statements;
public:
	Uc_block_statement()
		{  }
	~Uc_block_statement();
	void add(Uc_statement *stmt)
		{ statements.push_back(stmt); }
					// Generate code.
	virtual void gen(std::vector<char>& out, Uc_function *fun);
	};

/*
 *	An assignment statement:
 */
class Uc_assignment_statement : public Uc_statement
	{
	Uc_expression *target, *value;
public:
	Uc_assignment_statement(Uc_expression *t, Uc_expression *v)
		: target(t), value(v)
		{  }
	~Uc_assignment_statement();
					// Generate code.
	virtual void gen(std::vector<char>& out, Uc_function *fun);
	};

/*
 *	An IF statement:
 */
class Uc_if_statement : public Uc_statement
	{
	Uc_expression *expr;		// What to test.
					// What to execute:
	Uc_statement *if_stmt, *else_stmt;
public:
	Uc_if_statement(Uc_expression *e, Uc_statement *t, Uc_statement *f)
		: expr(e), if_stmt(t), else_stmt(f)
		{  }
	~Uc_if_statement();
					// Generate code.
	virtual void gen(std::vector<char>& out, Uc_function *fun);
	};

/*
 *	An WHILE statement:
 */
class Uc_while_statement : public Uc_statement
	{
	Uc_expression *expr;		// What to test.
	Uc_statement *stmt;		// What to execute.
public:
	Uc_while_statement(Uc_expression *e, Uc_statement *s)
		: expr(e), stmt(s)
		{  }
	~Uc_while_statement();
					// Generate code.
	virtual void gen(std::vector<char>& out, Uc_function *fun);
	};

/*
 *	An array loop statement:
 */
class Uc_arrayloop_statement : public Uc_statement
	{
	Uc_var_symbol *var;		// Loop variable.
	Uc_var_symbol *array;		// Array to loop over.
	Uc_var_symbol *index;		// Counter.
	Uc_var_symbol *array_size;	// Symbol holding array size.
	Uc_statement *stmt;		// What to execute.
public:
	Uc_arrayloop_statement(Uc_var_symbol *v, Uc_var_symbol *a)
		: var(v), array(a), index(0), array_size(0), stmt(0)
		{  }
	~Uc_arrayloop_statement();
	void set_statement(Uc_statement *s)
		{ stmt = s; }
	void set_index(Uc_var_symbol *i)
		{ index = i; }
	void set_array_size(Uc_var_symbol *as)
		{ array_size = as; }
	void finish(Uc_function *fun);	// Create tmps. if necessary.
					// Generate code.
	virtual void gen(std::vector<char>& out, Uc_function *fun);
	};

/*
 *	An RETURN statement:
 */
class Uc_return_statement : public Uc_statement
	{
	Uc_expression *expr;		// What to return.  May be 0.
public:
	Uc_return_statement(Uc_expression *e = 0) : expr(e)
		{  }
	~Uc_return_statement();
					// Generate code.
	virtual void gen(std::vector<char>& out, Uc_function *fun);
	};

/*
 *	BREAK statement:
 */
class Uc_break_statement : public Uc_statement
	{
public:
	Uc_break_statement() {  }
					// Generate code.
	virtual void gen(std::vector<char>& out, Uc_function *fun);
	};

/*
 *  a LABEL statement:
 */
class Uc_label_statement : public Uc_statement
{
	Uc_label *label;
 public:
	Uc_label_statement(Uc_label *l) : label(l)
		{ }
	virtual void gen(std::vector<char>& out, Uc_function *fun);
};

/*
 *  a GOTO statement:
 */
class Uc_goto_statement : public Uc_statement
{
	char *label;
 public:
	Uc_goto_statement(char *l) : label(l)
		{ }
	virtual void gen(std::vector<char>& out, Uc_function *fun);
};



/*
 *	A CONVERSE statement is a loop that prompts for a user response at
 *	the top, or exits the loop if there are no possible answers.
 */
class Uc_converse_statement : public Uc_statement
	{
	Uc_statement *stmt;		// What to execute.
public:
	Uc_converse_statement(Uc_statement *s)
		: stmt(s)
		{  }
	~Uc_converse_statement();
					// Generate code.
	virtual void gen(std::vector<char>& out, Uc_function *fun);
	};

/*
 *	Conversation CASE statement:
 */
class Uc_converse_case_statement : public Uc_statement
	{
	int string_offset;		// Offset of string to compare.
	bool remove;			// True to remove answer.
	Uc_statement *statements;	// Execute these.
public:
	Uc_converse_case_statement(int soff, bool rem, Uc_statement *stmts)
		: string_offset(soff), remove(rem), statements(stmts)
		{  }
	~Uc_converse_case_statement()
		{ delete statements; }
					// Generate code.
	virtual void gen(std::vector<char>& out, Uc_function *fun);
	};

/*
 *	A CONVERSE2 statement provides a less wordy way to implement a
 *	conversation.  It provides for CASE entries for the comparisons, and
 *	also generates push/pop-answers so these can be nested.
 */
class Uc_converse2_statement : public Uc_statement
	{
	static int nest;		// Keeps track of nesting.
	Uc_expression *answers;		// Answers to add.
	Uc_statement *cases;		// What to execute.
public:
	Uc_converse2_statement(Uc_expression *a, Uc_statement *cs)
		: answers(a), cases(cs)
		{  }
	~Uc_converse2_statement();
					// Generate code.
	virtual void gen(std::vector<char>& out, Uc_function *fun);
	};

/*
 *	Add string to current message (for conversations).
 */
class Uc_message_statement : public Uc_statement
	{
	Uc_array_expression *msgs;
public:
	Uc_message_statement(Uc_array_expression *m) : msgs(m) {  }
					// Generate code.
	virtual void gen(std::vector<char>& out, Uc_function *fun);
	};

/*
 *	Print message on screen (in conversation).
 */
class Uc_say_statement : public Uc_message_statement
	{
public:
	Uc_say_statement(Uc_array_expression *m) : Uc_message_statement(m) 
		{  }
					// Generate code.
	virtual void gen(std::vector<char>& out, Uc_function *fun);
	};

/*
 *	Call a function/intrinsic.
 */
class Uc_call_statement : public Uc_statement
	{
	Uc_call_expression *function_call;
public:
	Uc_call_statement(Uc_call_expression *f);
	~Uc_call_statement();
					// Generate code.
	virtual void gen(std::vector<char>& out, Uc_function *fun);
	};

#endif