annotate gcc/go/gofrontend/statements.h @ 158:494b0b89df80 default tip

...
author Shinji KONO <kono@ie.u-ryukyu.ac.jp>
date Mon, 25 May 2020 18:13:55 +0900
parents 1830386684a0
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
111
kono
parents:
diff changeset
1 // statements.h -- Go frontend statements. -*- C++ -*-
kono
parents:
diff changeset
2
kono
parents:
diff changeset
3 // Copyright 2009 The Go Authors. All rights reserved.
kono
parents:
diff changeset
4 // Use of this source code is governed by a BSD-style
kono
parents:
diff changeset
5 // license that can be found in the LICENSE file.
kono
parents:
diff changeset
6
kono
parents:
diff changeset
7 #ifndef GO_STATEMENTS_H
kono
parents:
diff changeset
8 #define GO_STATEMENTS_H
kono
parents:
diff changeset
9
kono
parents:
diff changeset
10 #include "operator.h"
kono
parents:
diff changeset
11
kono
parents:
diff changeset
12 class Gogo;
kono
parents:
diff changeset
13 class Traverse;
kono
parents:
diff changeset
14 class Statement_inserter;
kono
parents:
diff changeset
15 class Block;
kono
parents:
diff changeset
16 class Function;
kono
parents:
diff changeset
17 class Unnamed_label;
145
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
18 class Export_function_body;
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
19 class Import_function_body;
111
kono
parents:
diff changeset
20 class Assignment_statement;
kono
parents:
diff changeset
21 class Temporary_statement;
kono
parents:
diff changeset
22 class Variable_declaration_statement;
kono
parents:
diff changeset
23 class Expression_statement;
kono
parents:
diff changeset
24 class Block_statement;
kono
parents:
diff changeset
25 class Return_statement;
kono
parents:
diff changeset
26 class Thunk_statement;
145
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
27 class Defer_statement;
111
kono
parents:
diff changeset
28 class Goto_statement;
kono
parents:
diff changeset
29 class Goto_unnamed_statement;
kono
parents:
diff changeset
30 class Label_statement;
kono
parents:
diff changeset
31 class Unnamed_label_statement;
kono
parents:
diff changeset
32 class If_statement;
kono
parents:
diff changeset
33 class For_statement;
kono
parents:
diff changeset
34 class For_range_statement;
kono
parents:
diff changeset
35 class Switch_statement;
kono
parents:
diff changeset
36 class Type_switch_statement;
kono
parents:
diff changeset
37 class Send_statement;
kono
parents:
diff changeset
38 class Select_statement;
kono
parents:
diff changeset
39 class Variable;
kono
parents:
diff changeset
40 class Named_object;
kono
parents:
diff changeset
41 class Label;
kono
parents:
diff changeset
42 class Translate_context;
kono
parents:
diff changeset
43 class Expression;
kono
parents:
diff changeset
44 class Expression_list;
kono
parents:
diff changeset
45 class Struct_type;
kono
parents:
diff changeset
46 class Call_expression;
kono
parents:
diff changeset
47 class Map_index_expression;
kono
parents:
diff changeset
48 class Receive_expression;
kono
parents:
diff changeset
49 class Case_clauses;
kono
parents:
diff changeset
50 class Type_case_clauses;
kono
parents:
diff changeset
51 class Select_clauses;
kono
parents:
diff changeset
52 class Typed_identifier_list;
kono
parents:
diff changeset
53 class Bexpression;
kono
parents:
diff changeset
54 class Bstatement;
kono
parents:
diff changeset
55 class Bvariable;
kono
parents:
diff changeset
56 class Ast_dump_context;
kono
parents:
diff changeset
57
kono
parents:
diff changeset
58 // This class is used to traverse assignments made by a statement
kono
parents:
diff changeset
59 // which makes assignments.
kono
parents:
diff changeset
60
kono
parents:
diff changeset
61 class Traverse_assignments
kono
parents:
diff changeset
62 {
kono
parents:
diff changeset
63 public:
kono
parents:
diff changeset
64 Traverse_assignments()
kono
parents:
diff changeset
65 { }
kono
parents:
diff changeset
66
kono
parents:
diff changeset
67 virtual ~Traverse_assignments()
kono
parents:
diff changeset
68 { }
kono
parents:
diff changeset
69
kono
parents:
diff changeset
70 // This is called for a variable initialization.
kono
parents:
diff changeset
71 virtual void
kono
parents:
diff changeset
72 initialize_variable(Named_object*) = 0;
kono
parents:
diff changeset
73
kono
parents:
diff changeset
74 // This is called for each assignment made by the statement. PLHS
kono
parents:
diff changeset
75 // points to the left hand side, and PRHS points to the right hand
kono
parents:
diff changeset
76 // side. PRHS may be NULL if there is no associated expression, as
kono
parents:
diff changeset
77 // in the bool set by a non-blocking receive.
kono
parents:
diff changeset
78 virtual void
kono
parents:
diff changeset
79 assignment(Expression** plhs, Expression** prhs) = 0;
kono
parents:
diff changeset
80
kono
parents:
diff changeset
81 // This is called for each expression which is not passed to the
kono
parents:
diff changeset
82 // assignment function. This is used for some of the statements
kono
parents:
diff changeset
83 // which assign two values, for which there is no expression which
kono
parents:
diff changeset
84 // describes the value. For ++ and -- the value is passed to both
kono
parents:
diff changeset
85 // the assignment method and the rhs method. IS_STORED is true if
kono
parents:
diff changeset
86 // this value is being stored directly. It is false if the value is
kono
parents:
diff changeset
87 // computed but not stored. IS_LOCAL is true if the value is being
kono
parents:
diff changeset
88 // stored in a local variable or this is being called by a return
kono
parents:
diff changeset
89 // statement.
kono
parents:
diff changeset
90 virtual void
kono
parents:
diff changeset
91 value(Expression**, bool is_stored, bool is_local) = 0;
kono
parents:
diff changeset
92 };
kono
parents:
diff changeset
93
kono
parents:
diff changeset
94 // A single statement.
kono
parents:
diff changeset
95
kono
parents:
diff changeset
96 class Statement
kono
parents:
diff changeset
97 {
kono
parents:
diff changeset
98 public:
kono
parents:
diff changeset
99 // The types of statements.
kono
parents:
diff changeset
100 enum Statement_classification
kono
parents:
diff changeset
101 {
kono
parents:
diff changeset
102 STATEMENT_ERROR,
kono
parents:
diff changeset
103 STATEMENT_VARIABLE_DECLARATION,
kono
parents:
diff changeset
104 STATEMENT_TEMPORARY,
kono
parents:
diff changeset
105 STATEMENT_ASSIGNMENT,
kono
parents:
diff changeset
106 STATEMENT_EXPRESSION,
kono
parents:
diff changeset
107 STATEMENT_BLOCK,
kono
parents:
diff changeset
108 STATEMENT_GO,
kono
parents:
diff changeset
109 STATEMENT_DEFER,
kono
parents:
diff changeset
110 STATEMENT_RETURN,
kono
parents:
diff changeset
111 STATEMENT_BREAK_OR_CONTINUE,
kono
parents:
diff changeset
112 STATEMENT_GOTO,
kono
parents:
diff changeset
113 STATEMENT_GOTO_UNNAMED,
kono
parents:
diff changeset
114 STATEMENT_LABEL,
kono
parents:
diff changeset
115 STATEMENT_UNNAMED_LABEL,
kono
parents:
diff changeset
116 STATEMENT_IF,
kono
parents:
diff changeset
117 STATEMENT_CONSTANT_SWITCH,
kono
parents:
diff changeset
118 STATEMENT_SEND,
kono
parents:
diff changeset
119 STATEMENT_SELECT,
kono
parents:
diff changeset
120
kono
parents:
diff changeset
121 // These statements types are created by the parser, but they
kono
parents:
diff changeset
122 // disappear during the lowering pass.
kono
parents:
diff changeset
123 STATEMENT_ASSIGNMENT_OPERATION,
kono
parents:
diff changeset
124 STATEMENT_TUPLE_ASSIGNMENT,
kono
parents:
diff changeset
125 STATEMENT_TUPLE_MAP_ASSIGNMENT,
kono
parents:
diff changeset
126 STATEMENT_TUPLE_RECEIVE_ASSIGNMENT,
kono
parents:
diff changeset
127 STATEMENT_TUPLE_TYPE_GUARD_ASSIGNMENT,
kono
parents:
diff changeset
128 STATEMENT_INCDEC,
kono
parents:
diff changeset
129 STATEMENT_FOR,
kono
parents:
diff changeset
130 STATEMENT_FOR_RANGE,
kono
parents:
diff changeset
131 STATEMENT_SWITCH,
kono
parents:
diff changeset
132 STATEMENT_TYPE_SWITCH
kono
parents:
diff changeset
133 };
kono
parents:
diff changeset
134
kono
parents:
diff changeset
135 Statement(Statement_classification, Location);
kono
parents:
diff changeset
136
kono
parents:
diff changeset
137 virtual ~Statement();
kono
parents:
diff changeset
138
kono
parents:
diff changeset
139 // Make a variable declaration.
kono
parents:
diff changeset
140 static Statement*
kono
parents:
diff changeset
141 make_variable_declaration(Named_object*);
kono
parents:
diff changeset
142
kono
parents:
diff changeset
143 // Make a statement which creates a temporary variable and
kono
parents:
diff changeset
144 // initializes it to an expression. The block is used if the
kono
parents:
diff changeset
145 // temporary variable has to be explicitly destroyed; the variable
kono
parents:
diff changeset
146 // must still be added to the block. References to the temporary
kono
parents:
diff changeset
147 // variable may be constructed using make_temporary_reference.
kono
parents:
diff changeset
148 // Either the type or the initialization expression may be NULL, but
kono
parents:
diff changeset
149 // not both.
kono
parents:
diff changeset
150 static Temporary_statement*
kono
parents:
diff changeset
151 make_temporary(Type*, Expression*, Location);
kono
parents:
diff changeset
152
kono
parents:
diff changeset
153 // Make an assignment statement.
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
154 static Assignment_statement*
111
kono
parents:
diff changeset
155 make_assignment(Expression*, Expression*, Location);
kono
parents:
diff changeset
156
kono
parents:
diff changeset
157 // Make an assignment operation (+=, etc.).
kono
parents:
diff changeset
158 static Statement*
kono
parents:
diff changeset
159 make_assignment_operation(Operator, Expression*, Expression*,
kono
parents:
diff changeset
160 Location);
kono
parents:
diff changeset
161
kono
parents:
diff changeset
162 // Make a tuple assignment statement.
kono
parents:
diff changeset
163 static Statement*
kono
parents:
diff changeset
164 make_tuple_assignment(Expression_list*, Expression_list*, Location);
kono
parents:
diff changeset
165
kono
parents:
diff changeset
166 // Make an assignment from a map index to a pair of variables.
kono
parents:
diff changeset
167 static Statement*
kono
parents:
diff changeset
168 make_tuple_map_assignment(Expression* val, Expression* present,
kono
parents:
diff changeset
169 Expression*, Location);
kono
parents:
diff changeset
170
kono
parents:
diff changeset
171 // Make an assignment from a nonblocking receive to a pair of
kono
parents:
diff changeset
172 // variables.
kono
parents:
diff changeset
173 static Statement*
kono
parents:
diff changeset
174 make_tuple_receive_assignment(Expression* val, Expression* closed,
kono
parents:
diff changeset
175 Expression* channel, Location);
kono
parents:
diff changeset
176
kono
parents:
diff changeset
177 // Make an assignment from a type guard to a pair of variables.
kono
parents:
diff changeset
178 static Statement*
kono
parents:
diff changeset
179 make_tuple_type_guard_assignment(Expression* val, Expression* ok,
kono
parents:
diff changeset
180 Expression* expr, Type* type,
kono
parents:
diff changeset
181 Location);
kono
parents:
diff changeset
182
kono
parents:
diff changeset
183 // Make an expression statement from an Expression. IS_IGNORED is
kono
parents:
diff changeset
184 // true if the value is being explicitly ignored, as in an
kono
parents:
diff changeset
185 // assignment to _.
kono
parents:
diff changeset
186 static Statement*
kono
parents:
diff changeset
187 make_statement(Expression*, bool is_ignored);
kono
parents:
diff changeset
188
kono
parents:
diff changeset
189 // Make a block statement from a Block. This is an embedded list of
kono
parents:
diff changeset
190 // statements which may also include variable definitions.
145
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
191 static Block_statement*
111
kono
parents:
diff changeset
192 make_block_statement(Block*, Location);
kono
parents:
diff changeset
193
kono
parents:
diff changeset
194 // Make an increment statement.
kono
parents:
diff changeset
195 static Statement*
kono
parents:
diff changeset
196 make_inc_statement(Expression*);
kono
parents:
diff changeset
197
kono
parents:
diff changeset
198 // Make a decrement statement.
kono
parents:
diff changeset
199 static Statement*
kono
parents:
diff changeset
200 make_dec_statement(Expression*);
kono
parents:
diff changeset
201
kono
parents:
diff changeset
202 // Make a go statement.
kono
parents:
diff changeset
203 static Statement*
kono
parents:
diff changeset
204 make_go_statement(Call_expression* call, Location);
kono
parents:
diff changeset
205
kono
parents:
diff changeset
206 // Make a defer statement.
kono
parents:
diff changeset
207 static Statement*
kono
parents:
diff changeset
208 make_defer_statement(Call_expression* call, Location);
kono
parents:
diff changeset
209
kono
parents:
diff changeset
210 // Make a return statement.
kono
parents:
diff changeset
211 static Return_statement*
kono
parents:
diff changeset
212 make_return_statement(Expression_list*, Location);
kono
parents:
diff changeset
213
kono
parents:
diff changeset
214 // Make a statement that returns the result of a call expression.
kono
parents:
diff changeset
215 // If the call does not return any results, this just returns the
kono
parents:
diff changeset
216 // call expression as a statement, assuming that the function will
kono
parents:
diff changeset
217 // end immediately afterward.
kono
parents:
diff changeset
218 static Statement*
kono
parents:
diff changeset
219 make_return_from_call(Call_expression*, Location);
kono
parents:
diff changeset
220
kono
parents:
diff changeset
221 // Make a break statement.
kono
parents:
diff changeset
222 static Statement*
kono
parents:
diff changeset
223 make_break_statement(Unnamed_label* label, Location);
kono
parents:
diff changeset
224
kono
parents:
diff changeset
225 // Make a continue statement.
kono
parents:
diff changeset
226 static Statement*
kono
parents:
diff changeset
227 make_continue_statement(Unnamed_label* label, Location);
kono
parents:
diff changeset
228
kono
parents:
diff changeset
229 // Make a goto statement.
kono
parents:
diff changeset
230 static Statement*
kono
parents:
diff changeset
231 make_goto_statement(Label* label, Location);
kono
parents:
diff changeset
232
kono
parents:
diff changeset
233 // Make a goto statement to an unnamed label.
kono
parents:
diff changeset
234 static Statement*
kono
parents:
diff changeset
235 make_goto_unnamed_statement(Unnamed_label* label, Location);
kono
parents:
diff changeset
236
kono
parents:
diff changeset
237 // Make a label statement--where the label is defined.
kono
parents:
diff changeset
238 static Statement*
kono
parents:
diff changeset
239 make_label_statement(Label* label, Location);
kono
parents:
diff changeset
240
kono
parents:
diff changeset
241 // Make an unnamed label statement--where the label is defined.
kono
parents:
diff changeset
242 static Statement*
kono
parents:
diff changeset
243 make_unnamed_label_statement(Unnamed_label* label);
kono
parents:
diff changeset
244
kono
parents:
diff changeset
245 // Make an if statement.
kono
parents:
diff changeset
246 static Statement*
kono
parents:
diff changeset
247 make_if_statement(Expression* cond, Block* then_block, Block* else_block,
kono
parents:
diff changeset
248 Location);
kono
parents:
diff changeset
249
kono
parents:
diff changeset
250 // Make a switch statement.
kono
parents:
diff changeset
251 static Switch_statement*
kono
parents:
diff changeset
252 make_switch_statement(Expression* switch_val, Location);
kono
parents:
diff changeset
253
kono
parents:
diff changeset
254 // Make a type switch statement.
kono
parents:
diff changeset
255 static Type_switch_statement*
kono
parents:
diff changeset
256 make_type_switch_statement(const std::string&, Expression*, Location);
kono
parents:
diff changeset
257
kono
parents:
diff changeset
258 // Make a send statement.
kono
parents:
diff changeset
259 static Send_statement*
kono
parents:
diff changeset
260 make_send_statement(Expression* channel, Expression* val, Location);
kono
parents:
diff changeset
261
kono
parents:
diff changeset
262 // Make a select statement.
kono
parents:
diff changeset
263 static Select_statement*
kono
parents:
diff changeset
264 make_select_statement(Location);
kono
parents:
diff changeset
265
kono
parents:
diff changeset
266 // Make a for statement.
kono
parents:
diff changeset
267 static For_statement*
kono
parents:
diff changeset
268 make_for_statement(Block* init, Expression* cond, Block* post,
kono
parents:
diff changeset
269 Location location);
kono
parents:
diff changeset
270
kono
parents:
diff changeset
271 // Make a for statement with a range clause.
kono
parents:
diff changeset
272 static For_range_statement*
kono
parents:
diff changeset
273 make_for_range_statement(Expression* index_var, Expression* value_var,
kono
parents:
diff changeset
274 Expression* range, Location);
kono
parents:
diff changeset
275
kono
parents:
diff changeset
276 // Return the statement classification.
kono
parents:
diff changeset
277 Statement_classification
kono
parents:
diff changeset
278 classification() const
kono
parents:
diff changeset
279 { return this->classification_; }
kono
parents:
diff changeset
280
kono
parents:
diff changeset
281 // Get the statement location.
kono
parents:
diff changeset
282 Location
kono
parents:
diff changeset
283 location() const
kono
parents:
diff changeset
284 { return this->location_; }
kono
parents:
diff changeset
285
kono
parents:
diff changeset
286 // Traverse the tree.
kono
parents:
diff changeset
287 int
kono
parents:
diff changeset
288 traverse(Block*, size_t* index, Traverse*);
kono
parents:
diff changeset
289
kono
parents:
diff changeset
290 // Traverse the contents of this statement--the expressions and
kono
parents:
diff changeset
291 // statements which it contains.
kono
parents:
diff changeset
292 int
kono
parents:
diff changeset
293 traverse_contents(Traverse*);
kono
parents:
diff changeset
294
kono
parents:
diff changeset
295 // If this statement assigns some values, it calls a function for
kono
parents:
diff changeset
296 // each value to which this statement assigns a value, and returns
kono
parents:
diff changeset
297 // true. If this statement does not assign any values, it returns
kono
parents:
diff changeset
298 // false.
kono
parents:
diff changeset
299 bool
kono
parents:
diff changeset
300 traverse_assignments(Traverse_assignments* tassign);
kono
parents:
diff changeset
301
kono
parents:
diff changeset
302 // Lower a statement. This is called immediately after parsing to
kono
parents:
diff changeset
303 // simplify statements for further processing. It returns the same
kono
parents:
diff changeset
304 // Statement or a new one. FUNCTION is the function containing this
kono
parents:
diff changeset
305 // statement. BLOCK is the block containing this statement.
kono
parents:
diff changeset
306 // INSERTER can be used to insert new statements before this one.
kono
parents:
diff changeset
307 Statement*
kono
parents:
diff changeset
308 lower(Gogo* gogo, Named_object* function, Block* block,
kono
parents:
diff changeset
309 Statement_inserter* inserter)
kono
parents:
diff changeset
310 { return this->do_lower(gogo, function, block, inserter); }
kono
parents:
diff changeset
311
kono
parents:
diff changeset
312 // Flatten a statement. This is called immediately after the order of
kono
parents:
diff changeset
313 // evaluation rules are applied to statements. It returns the same
kono
parents:
diff changeset
314 // Statement or a new one. FUNCTION is the function containing this
kono
parents:
diff changeset
315 // statement. BLOCK is the block containing this statement.
kono
parents:
diff changeset
316 // INSERTER can be used to insert new statements before this one.
kono
parents:
diff changeset
317 Statement*
kono
parents:
diff changeset
318 flatten(Gogo* gogo, Named_object* function, Block* block,
kono
parents:
diff changeset
319 Statement_inserter* inserter)
kono
parents:
diff changeset
320 { return this->do_flatten(gogo, function, block, inserter); }
kono
parents:
diff changeset
321
kono
parents:
diff changeset
322 // Set type information for unnamed constants.
kono
parents:
diff changeset
323 void
kono
parents:
diff changeset
324 determine_types();
kono
parents:
diff changeset
325
kono
parents:
diff changeset
326 // Check types in a statement. This simply checks that any
kono
parents:
diff changeset
327 // expressions used by the statement have the right type.
kono
parents:
diff changeset
328 void
kono
parents:
diff changeset
329 check_types(Gogo* gogo)
kono
parents:
diff changeset
330 { this->do_check_types(gogo); }
kono
parents:
diff changeset
331
145
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
332 // Return the cost of this statement for inlining purposes.
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
333 int
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
334 inlining_cost()
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
335 { return this->do_inlining_cost(); }
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
336
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
337 // Export data for this statement to BODY.
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
338 void
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
339 export_statement(Export_function_body* efb)
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
340 { this->do_export_statement(efb); }
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
341
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
342 // Make implicit type conversions explicit.
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
343 void
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
344 add_conversions()
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
345 { this->do_add_conversions(); }
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
346
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
347 // Read a statement from export data. The location should be used
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
348 // for the returned statement. Errors should be reported using the
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
349 // Import_function_body's location method.
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
350 static Statement*
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
351 import_statement(Import_function_body*, Location);
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
352
111
kono
parents:
diff changeset
353 // Return whether this is a block statement.
kono
parents:
diff changeset
354 bool
kono
parents:
diff changeset
355 is_block_statement() const
kono
parents:
diff changeset
356 { return this->classification_ == STATEMENT_BLOCK; }
kono
parents:
diff changeset
357
kono
parents:
diff changeset
358 // If this is an assignment statement, return it. Otherwise return
kono
parents:
diff changeset
359 // NULL.
kono
parents:
diff changeset
360 Assignment_statement*
kono
parents:
diff changeset
361 assignment_statement()
kono
parents:
diff changeset
362 {
kono
parents:
diff changeset
363 return this->convert<Assignment_statement, STATEMENT_ASSIGNMENT>();
kono
parents:
diff changeset
364 }
kono
parents:
diff changeset
365
kono
parents:
diff changeset
366 // If this is an temporary statement, return it. Otherwise return
kono
parents:
diff changeset
367 // NULL.
kono
parents:
diff changeset
368 Temporary_statement*
kono
parents:
diff changeset
369 temporary_statement()
kono
parents:
diff changeset
370 {
kono
parents:
diff changeset
371 return this->convert<Temporary_statement, STATEMENT_TEMPORARY>();
kono
parents:
diff changeset
372 }
kono
parents:
diff changeset
373
kono
parents:
diff changeset
374 // If this is a variable declaration statement, return it.
kono
parents:
diff changeset
375 // Otherwise return NULL.
kono
parents:
diff changeset
376 Variable_declaration_statement*
kono
parents:
diff changeset
377 variable_declaration_statement()
kono
parents:
diff changeset
378 {
kono
parents:
diff changeset
379 return this->convert<Variable_declaration_statement,
kono
parents:
diff changeset
380 STATEMENT_VARIABLE_DECLARATION>();
kono
parents:
diff changeset
381 }
kono
parents:
diff changeset
382
kono
parents:
diff changeset
383 // If this is an expression statement, return it. Otherwise return
kono
parents:
diff changeset
384 // NULL.
kono
parents:
diff changeset
385 Expression_statement*
kono
parents:
diff changeset
386 expression_statement()
kono
parents:
diff changeset
387 {
kono
parents:
diff changeset
388 return this->convert<Expression_statement, STATEMENT_EXPRESSION>();
kono
parents:
diff changeset
389 }
kono
parents:
diff changeset
390
kono
parents:
diff changeset
391 // If this is an block statement, return it. Otherwise return
kono
parents:
diff changeset
392 // NULL.
kono
parents:
diff changeset
393 Block_statement*
kono
parents:
diff changeset
394 block_statement()
kono
parents:
diff changeset
395 { return this->convert<Block_statement, STATEMENT_BLOCK>(); }
kono
parents:
diff changeset
396
kono
parents:
diff changeset
397 // If this is a return statement, return it. Otherwise return NULL.
kono
parents:
diff changeset
398 Return_statement*
kono
parents:
diff changeset
399 return_statement()
kono
parents:
diff changeset
400 { return this->convert<Return_statement, STATEMENT_RETURN>(); }
kono
parents:
diff changeset
401
kono
parents:
diff changeset
402 // If this is a thunk statement (a go or defer statement), return
kono
parents:
diff changeset
403 // it. Otherwise return NULL.
kono
parents:
diff changeset
404 Thunk_statement*
kono
parents:
diff changeset
405 thunk_statement();
kono
parents:
diff changeset
406
145
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
407 // If this is a defer statement, return it. Otherwise return NULL.
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
408 Defer_statement*
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
409 defer_statement()
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
410 { return this->convert<Defer_statement, STATEMENT_DEFER>(); }
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
411
111
kono
parents:
diff changeset
412 // If this is a goto statement, return it. Otherwise return NULL.
kono
parents:
diff changeset
413 Goto_statement*
kono
parents:
diff changeset
414 goto_statement()
kono
parents:
diff changeset
415 { return this->convert<Goto_statement, STATEMENT_GOTO>(); }
kono
parents:
diff changeset
416
kono
parents:
diff changeset
417 // If this is a goto_unnamed statement, return it. Otherwise return NULL.
kono
parents:
diff changeset
418 Goto_unnamed_statement*
kono
parents:
diff changeset
419 goto_unnamed_statement()
kono
parents:
diff changeset
420 { return this->convert<Goto_unnamed_statement, STATEMENT_GOTO_UNNAMED>(); }
kono
parents:
diff changeset
421
kono
parents:
diff changeset
422 // If this is a label statement, return it. Otherwise return NULL.
kono
parents:
diff changeset
423 Label_statement*
kono
parents:
diff changeset
424 label_statement()
kono
parents:
diff changeset
425 { return this->convert<Label_statement, STATEMENT_LABEL>(); }
kono
parents:
diff changeset
426
kono
parents:
diff changeset
427 // If this is an unnamed_label statement, return it. Otherwise return NULL.
kono
parents:
diff changeset
428 Unnamed_label_statement*
kono
parents:
diff changeset
429 unnamed_label_statement()
kono
parents:
diff changeset
430 { return this->convert<Unnamed_label_statement, STATEMENT_UNNAMED_LABEL>(); }
kono
parents:
diff changeset
431
kono
parents:
diff changeset
432 // If this is an if statement, return it. Otherwise return NULL.
kono
parents:
diff changeset
433 If_statement*
kono
parents:
diff changeset
434 if_statement()
kono
parents:
diff changeset
435 { return this->convert<If_statement, STATEMENT_IF>(); }
kono
parents:
diff changeset
436
kono
parents:
diff changeset
437 // If this is a for statement, return it. Otherwise return NULL.
kono
parents:
diff changeset
438 For_statement*
kono
parents:
diff changeset
439 for_statement()
kono
parents:
diff changeset
440 { return this->convert<For_statement, STATEMENT_FOR>(); }
kono
parents:
diff changeset
441
kono
parents:
diff changeset
442 // If this is a for statement over a range clause, return it.
kono
parents:
diff changeset
443 // Otherwise return NULL.
kono
parents:
diff changeset
444 For_range_statement*
kono
parents:
diff changeset
445 for_range_statement()
kono
parents:
diff changeset
446 { return this->convert<For_range_statement, STATEMENT_FOR_RANGE>(); }
kono
parents:
diff changeset
447
kono
parents:
diff changeset
448 // If this is a switch statement, return it. Otherwise return NULL.
kono
parents:
diff changeset
449 Switch_statement*
kono
parents:
diff changeset
450 switch_statement()
kono
parents:
diff changeset
451 { return this->convert<Switch_statement, STATEMENT_SWITCH>(); }
kono
parents:
diff changeset
452
kono
parents:
diff changeset
453 // If this is a type switch statement, return it. Otherwise return
kono
parents:
diff changeset
454 // NULL.
kono
parents:
diff changeset
455 Type_switch_statement*
kono
parents:
diff changeset
456 type_switch_statement()
kono
parents:
diff changeset
457 { return this->convert<Type_switch_statement, STATEMENT_TYPE_SWITCH>(); }
kono
parents:
diff changeset
458
kono
parents:
diff changeset
459 // If this is a send statement, return it. Otherwise return NULL.
kono
parents:
diff changeset
460 Send_statement*
kono
parents:
diff changeset
461 send_statement()
kono
parents:
diff changeset
462 { return this->convert<Send_statement, STATEMENT_SEND>(); }
kono
parents:
diff changeset
463
kono
parents:
diff changeset
464 // If this is a select statement, return it. Otherwise return NULL.
kono
parents:
diff changeset
465 Select_statement*
kono
parents:
diff changeset
466 select_statement()
kono
parents:
diff changeset
467 { return this->convert<Select_statement, STATEMENT_SELECT>(); }
kono
parents:
diff changeset
468
kono
parents:
diff changeset
469 // Return true if this statement may fall through--if after
kono
parents:
diff changeset
470 // executing this statement we may go on to execute the following
kono
parents:
diff changeset
471 // statement, if any.
kono
parents:
diff changeset
472 bool
kono
parents:
diff changeset
473 may_fall_through() const
kono
parents:
diff changeset
474 { return this->do_may_fall_through(); }
kono
parents:
diff changeset
475
kono
parents:
diff changeset
476 // Convert the statement to the backend representation.
kono
parents:
diff changeset
477 Bstatement*
kono
parents:
diff changeset
478 get_backend(Translate_context*);
kono
parents:
diff changeset
479
kono
parents:
diff changeset
480 // Dump AST representation of a statement to a dump context.
kono
parents:
diff changeset
481 void
kono
parents:
diff changeset
482 dump_statement(Ast_dump_context*) const;
kono
parents:
diff changeset
483
kono
parents:
diff changeset
484 protected:
kono
parents:
diff changeset
485 // Implemented by child class: traverse the tree.
kono
parents:
diff changeset
486 virtual int
kono
parents:
diff changeset
487 do_traverse(Traverse*) = 0;
kono
parents:
diff changeset
488
kono
parents:
diff changeset
489 // Implemented by child class: traverse assignments. Any statement
kono
parents:
diff changeset
490 // which includes an assignment should implement this.
kono
parents:
diff changeset
491 virtual bool
kono
parents:
diff changeset
492 do_traverse_assignments(Traverse_assignments*)
kono
parents:
diff changeset
493 { return false; }
kono
parents:
diff changeset
494
kono
parents:
diff changeset
495 // Implemented by the child class: lower this statement to a simpler
kono
parents:
diff changeset
496 // one.
kono
parents:
diff changeset
497 virtual Statement*
kono
parents:
diff changeset
498 do_lower(Gogo*, Named_object*, Block*, Statement_inserter*)
kono
parents:
diff changeset
499 { return this; }
kono
parents:
diff changeset
500
kono
parents:
diff changeset
501 // Implemented by the child class: lower this statement to a simpler
kono
parents:
diff changeset
502 // one.
kono
parents:
diff changeset
503 virtual Statement*
kono
parents:
diff changeset
504 do_flatten(Gogo*, Named_object*, Block*, Statement_inserter*)
kono
parents:
diff changeset
505 { return this; }
kono
parents:
diff changeset
506
kono
parents:
diff changeset
507 // Implemented by child class: set type information for unnamed
kono
parents:
diff changeset
508 // constants. Any statement which includes an expression needs to
kono
parents:
diff changeset
509 // implement this.
kono
parents:
diff changeset
510 virtual void
kono
parents:
diff changeset
511 do_determine_types()
kono
parents:
diff changeset
512 { }
kono
parents:
diff changeset
513
kono
parents:
diff changeset
514 // Implemented by child class: check types of expressions used in a
kono
parents:
diff changeset
515 // statement.
kono
parents:
diff changeset
516 virtual void
kono
parents:
diff changeset
517 do_check_types(Gogo*)
kono
parents:
diff changeset
518 { }
kono
parents:
diff changeset
519
145
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
520 // Implemented by child class: return the cost of this statement for
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
521 // inlining. The default cost is high, so we only need to define
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
522 // this method for statements that can be inlined.
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
523 virtual int
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
524 do_inlining_cost()
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
525 { return 0x100000; }
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
526
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
527 // Implemented by child class: write export data for this statement
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
528 // to the string. This need only be implemented by classes that
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
529 // implement do_inlining_cost with a reasonable value.
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
530 virtual void
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
531 do_export_statement(Export_function_body*)
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
532 { go_unreachable(); }
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
533
111
kono
parents:
diff changeset
534 // Implemented by child class: return true if this statement may
kono
parents:
diff changeset
535 // fall through.
kono
parents:
diff changeset
536 virtual bool
kono
parents:
diff changeset
537 do_may_fall_through() const
kono
parents:
diff changeset
538 { return true; }
kono
parents:
diff changeset
539
kono
parents:
diff changeset
540 // Implemented by child class: convert to backend representation.
kono
parents:
diff changeset
541 virtual Bstatement*
kono
parents:
diff changeset
542 do_get_backend(Translate_context*) = 0;
kono
parents:
diff changeset
543
kono
parents:
diff changeset
544 // Implemented by child class: dump ast representation.
kono
parents:
diff changeset
545 virtual void
kono
parents:
diff changeset
546 do_dump_statement(Ast_dump_context*) const = 0;
kono
parents:
diff changeset
547
145
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
548 // Implemented by child class: make implicit conversions explicit.
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
549 virtual void
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
550 do_add_conversions()
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
551 { }
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
552
111
kono
parents:
diff changeset
553 // Traverse an expression in a statement.
kono
parents:
diff changeset
554 int
kono
parents:
diff changeset
555 traverse_expression(Traverse*, Expression**);
kono
parents:
diff changeset
556
kono
parents:
diff changeset
557 // Traverse an expression list in a statement. The Expression_list
kono
parents:
diff changeset
558 // may be NULL.
kono
parents:
diff changeset
559 int
kono
parents:
diff changeset
560 traverse_expression_list(Traverse*, Expression_list*);
kono
parents:
diff changeset
561
kono
parents:
diff changeset
562 // Traverse a type in a statement.
kono
parents:
diff changeset
563 int
kono
parents:
diff changeset
564 traverse_type(Traverse*, Type*);
kono
parents:
diff changeset
565
kono
parents:
diff changeset
566 // For children to call when they detect that they are in error.
kono
parents:
diff changeset
567 void
kono
parents:
diff changeset
568 set_is_error();
kono
parents:
diff changeset
569
kono
parents:
diff changeset
570 // For children to call to report an error conveniently.
kono
parents:
diff changeset
571 void
kono
parents:
diff changeset
572 report_error(const char*);
kono
parents:
diff changeset
573
kono
parents:
diff changeset
574 // For children to return an error statement from lower().
kono
parents:
diff changeset
575 static Statement*
kono
parents:
diff changeset
576 make_error_statement(Location);
kono
parents:
diff changeset
577
kono
parents:
diff changeset
578 private:
kono
parents:
diff changeset
579 // Convert to the desired statement classification, or return NULL.
kono
parents:
diff changeset
580 // This is a controlled dynamic cast.
kono
parents:
diff changeset
581 template<typename Statement_class, Statement_classification sc>
kono
parents:
diff changeset
582 Statement_class*
kono
parents:
diff changeset
583 convert()
kono
parents:
diff changeset
584 {
kono
parents:
diff changeset
585 return (this->classification_ == sc
kono
parents:
diff changeset
586 ? static_cast<Statement_class*>(this)
kono
parents:
diff changeset
587 : NULL);
kono
parents:
diff changeset
588 }
kono
parents:
diff changeset
589
kono
parents:
diff changeset
590 template<typename Statement_class, Statement_classification sc>
kono
parents:
diff changeset
591 const Statement_class*
kono
parents:
diff changeset
592 convert() const
kono
parents:
diff changeset
593 {
kono
parents:
diff changeset
594 return (this->classification_ == sc
kono
parents:
diff changeset
595 ? static_cast<const Statement_class*>(this)
kono
parents:
diff changeset
596 : NULL);
kono
parents:
diff changeset
597 }
kono
parents:
diff changeset
598
kono
parents:
diff changeset
599 // The statement classification.
kono
parents:
diff changeset
600 Statement_classification classification_;
kono
parents:
diff changeset
601 // The location in the input file of the start of this statement.
kono
parents:
diff changeset
602 Location location_;
kono
parents:
diff changeset
603 };
kono
parents:
diff changeset
604
kono
parents:
diff changeset
605 // An assignment statement.
kono
parents:
diff changeset
606
kono
parents:
diff changeset
607 class Assignment_statement : public Statement
kono
parents:
diff changeset
608 {
kono
parents:
diff changeset
609 public:
kono
parents:
diff changeset
610 Assignment_statement(Expression* lhs, Expression* rhs,
kono
parents:
diff changeset
611 Location location)
kono
parents:
diff changeset
612 : Statement(STATEMENT_ASSIGNMENT, location),
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
613 lhs_(lhs), rhs_(rhs), omit_write_barrier_(false)
111
kono
parents:
diff changeset
614 { }
kono
parents:
diff changeset
615
kono
parents:
diff changeset
616 Expression*
kono
parents:
diff changeset
617 lhs() const
kono
parents:
diff changeset
618 { return this->lhs_; }
kono
parents:
diff changeset
619
kono
parents:
diff changeset
620 Expression*
kono
parents:
diff changeset
621 rhs() const
kono
parents:
diff changeset
622 { return this->rhs_; }
kono
parents:
diff changeset
623
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
624 bool
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
625 omit_write_barrier() const
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
626 { return this->omit_write_barrier_; }
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
627
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
628 void
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
629 set_omit_write_barrier()
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
630 { this->omit_write_barrier_ = true; }
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
631
111
kono
parents:
diff changeset
632 protected:
kono
parents:
diff changeset
633 int
kono
parents:
diff changeset
634 do_traverse(Traverse* traverse);
kono
parents:
diff changeset
635
kono
parents:
diff changeset
636 bool
kono
parents:
diff changeset
637 do_traverse_assignments(Traverse_assignments*);
kono
parents:
diff changeset
638
kono
parents:
diff changeset
639 virtual Statement*
kono
parents:
diff changeset
640 do_lower(Gogo*, Named_object*, Block*, Statement_inserter*);
kono
parents:
diff changeset
641
kono
parents:
diff changeset
642 void
kono
parents:
diff changeset
643 do_determine_types();
kono
parents:
diff changeset
644
kono
parents:
diff changeset
645 void
kono
parents:
diff changeset
646 do_check_types(Gogo*);
kono
parents:
diff changeset
647
145
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
648 int
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
649 do_inlining_cost()
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
650 { return 1; }
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
651
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
652 void
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
653 do_export_statement(Export_function_body*);
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
654
111
kono
parents:
diff changeset
655 Statement*
kono
parents:
diff changeset
656 do_flatten(Gogo*, Named_object*, Block*, Statement_inserter*);
kono
parents:
diff changeset
657
kono
parents:
diff changeset
658 Bstatement*
kono
parents:
diff changeset
659 do_get_backend(Translate_context*);
kono
parents:
diff changeset
660
kono
parents:
diff changeset
661 void
kono
parents:
diff changeset
662 do_dump_statement(Ast_dump_context*) const;
kono
parents:
diff changeset
663
145
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
664 void
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
665 do_add_conversions();
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
666
111
kono
parents:
diff changeset
667 private:
kono
parents:
diff changeset
668 // Left hand side--the lvalue.
kono
parents:
diff changeset
669 Expression* lhs_;
kono
parents:
diff changeset
670 // Right hand side--the rvalue.
kono
parents:
diff changeset
671 Expression* rhs_;
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
672 // True if we can omit a write barrier from this assignment.
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
673 bool omit_write_barrier_;
111
kono
parents:
diff changeset
674 };
kono
parents:
diff changeset
675
kono
parents:
diff changeset
676 // A statement which creates and initializes a temporary variable.
kono
parents:
diff changeset
677
kono
parents:
diff changeset
678 class Temporary_statement : public Statement
kono
parents:
diff changeset
679 {
kono
parents:
diff changeset
680 public:
kono
parents:
diff changeset
681 Temporary_statement(Type* type, Expression* init, Location location)
kono
parents:
diff changeset
682 : Statement(STATEMENT_TEMPORARY, location),
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
683 type_(type), init_(init), bvariable_(NULL), is_address_taken_(false),
145
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
684 value_escapes_(false), assigned_(false), uses_(0)
111
kono
parents:
diff changeset
685 { }
kono
parents:
diff changeset
686
kono
parents:
diff changeset
687 // Return the type of the temporary variable.
kono
parents:
diff changeset
688 Type*
kono
parents:
diff changeset
689 type() const;
kono
parents:
diff changeset
690
kono
parents:
diff changeset
691 // Return the initializer if there is one.
kono
parents:
diff changeset
692 Expression*
kono
parents:
diff changeset
693 init() const
kono
parents:
diff changeset
694 { return this->init_; }
kono
parents:
diff changeset
695
145
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
696 // Set the initializer.
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
697 void
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
698 set_init(Expression* expr)
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
699 { this->init_ = expr; }
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
700
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
701 // Whether something takes the address of this temporary
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
702 // variable.
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
703 bool
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
704 is_address_taken()
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
705 { return this->is_address_taken_; }
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
706
111
kono
parents:
diff changeset
707 // Record that something takes the address of this temporary
kono
parents:
diff changeset
708 // variable.
kono
parents:
diff changeset
709 void
kono
parents:
diff changeset
710 set_is_address_taken()
kono
parents:
diff changeset
711 { this->is_address_taken_ = true; }
kono
parents:
diff changeset
712
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
713 // Whether the value escapes.
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
714 bool
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
715 value_escapes() const
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
716 { return this->value_escapes_; }
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
717
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
718 // Record that the value escapes.
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
719 void
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
720 set_value_escapes()
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
721 { this->value_escapes_ = true; }
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
722
145
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
723 // Whether this temporary variable is assigned (after initialization).
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
724 bool
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
725 assigned()
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
726 { return this->assigned_; }
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
727
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
728 // Record that this temporary variable is assigned.
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
729 void
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
730 set_assigned()
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
731 { this->assigned_ = true; }
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
732
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
733 // Number of uses of this temporary variable.
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
734 int
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
735 uses()
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
736 { return this->uses_; }
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
737
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
738 // Add one use of this temporary variable.
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
739 void
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
740 add_use()
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
741 { this->uses_++; }
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
742
111
kono
parents:
diff changeset
743 // Return the temporary variable. This should not be called until
kono
parents:
diff changeset
744 // after the statement itself has been converted.
kono
parents:
diff changeset
745 Bvariable*
kono
parents:
diff changeset
746 get_backend_variable(Translate_context*) const;
kono
parents:
diff changeset
747
145
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
748 // Import the declaration of a temporary.
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
749 static Statement*
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
750 do_import(Import_function_body*, Location);
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
751
111
kono
parents:
diff changeset
752 protected:
kono
parents:
diff changeset
753 int
kono
parents:
diff changeset
754 do_traverse(Traverse*);
kono
parents:
diff changeset
755
kono
parents:
diff changeset
756 bool
kono
parents:
diff changeset
757 do_traverse_assignments(Traverse_assignments*);
kono
parents:
diff changeset
758
kono
parents:
diff changeset
759 void
kono
parents:
diff changeset
760 do_determine_types();
kono
parents:
diff changeset
761
kono
parents:
diff changeset
762 void
kono
parents:
diff changeset
763 do_check_types(Gogo*);
kono
parents:
diff changeset
764
145
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
765 int
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
766 do_inlining_cost()
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
767 { return 1; }
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
768
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
769 void
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
770 do_export_statement(Export_function_body*);
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
771
111
kono
parents:
diff changeset
772 Statement*
kono
parents:
diff changeset
773 do_flatten(Gogo*, Named_object*, Block*, Statement_inserter*);
kono
parents:
diff changeset
774
kono
parents:
diff changeset
775 Bstatement*
kono
parents:
diff changeset
776 do_get_backend(Translate_context*);
kono
parents:
diff changeset
777
kono
parents:
diff changeset
778 void
kono
parents:
diff changeset
779 do_dump_statement(Ast_dump_context*) const;
kono
parents:
diff changeset
780
145
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
781 void
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
782 do_add_conversions();
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
783
111
kono
parents:
diff changeset
784 private:
kono
parents:
diff changeset
785 // The type of the temporary variable.
kono
parents:
diff changeset
786 Type* type_;
kono
parents:
diff changeset
787 // The initial value of the temporary variable. This may be NULL.
kono
parents:
diff changeset
788 Expression* init_;
kono
parents:
diff changeset
789 // The backend representation of the temporary variable.
kono
parents:
diff changeset
790 Bvariable* bvariable_;
kono
parents:
diff changeset
791 // True if something takes the address of this temporary variable.
kono
parents:
diff changeset
792 bool is_address_taken_;
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
793 // True if the value assigned to this temporary variable escapes.
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
794 // This is used for select statements.
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
795 bool value_escapes_;
145
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
796 // True if this temporary variable is assigned (after initialization).
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
797 bool assigned_;
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
798 // Number of uses of this temporary variable.
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
799 int uses_;
111
kono
parents:
diff changeset
800 };
kono
parents:
diff changeset
801
kono
parents:
diff changeset
802 // A variable declaration. This marks the point in the code where a
kono
parents:
diff changeset
803 // variable is declared. The Variable is also attached to a Block.
kono
parents:
diff changeset
804
kono
parents:
diff changeset
805 class Variable_declaration_statement : public Statement
kono
parents:
diff changeset
806 {
kono
parents:
diff changeset
807 public:
kono
parents:
diff changeset
808 Variable_declaration_statement(Named_object* var);
kono
parents:
diff changeset
809
kono
parents:
diff changeset
810 // The variable being declared.
kono
parents:
diff changeset
811 Named_object*
kono
parents:
diff changeset
812 var()
kono
parents:
diff changeset
813 { return this->var_; }
kono
parents:
diff changeset
814
145
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
815 // Import a variable declaration.
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
816 static Statement*
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
817 do_import(Import_function_body*, Location);
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
818
111
kono
parents:
diff changeset
819 protected:
kono
parents:
diff changeset
820 int
kono
parents:
diff changeset
821 do_traverse(Traverse*);
kono
parents:
diff changeset
822
kono
parents:
diff changeset
823 bool
kono
parents:
diff changeset
824 do_traverse_assignments(Traverse_assignments*);
kono
parents:
diff changeset
825
kono
parents:
diff changeset
826 Statement*
kono
parents:
diff changeset
827 do_lower(Gogo*, Named_object*, Block*, Statement_inserter*);
kono
parents:
diff changeset
828
145
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
829 int
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
830 do_inlining_cost()
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
831 { return 1; }
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
832
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
833 void
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
834 do_export_statement(Export_function_body*);
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
835
111
kono
parents:
diff changeset
836 Statement*
kono
parents:
diff changeset
837 do_flatten(Gogo*, Named_object*, Block*, Statement_inserter*);
kono
parents:
diff changeset
838
kono
parents:
diff changeset
839 Bstatement*
kono
parents:
diff changeset
840 do_get_backend(Translate_context*);
kono
parents:
diff changeset
841
kono
parents:
diff changeset
842 void
kono
parents:
diff changeset
843 do_dump_statement(Ast_dump_context*) const;
kono
parents:
diff changeset
844
145
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
845 void
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
846 do_add_conversions();
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
847
111
kono
parents:
diff changeset
848 private:
kono
parents:
diff changeset
849 Named_object* var_;
kono
parents:
diff changeset
850 };
kono
parents:
diff changeset
851
kono
parents:
diff changeset
852 // A return statement.
kono
parents:
diff changeset
853
kono
parents:
diff changeset
854 class Return_statement : public Statement
kono
parents:
diff changeset
855 {
kono
parents:
diff changeset
856 public:
kono
parents:
diff changeset
857 Return_statement(Expression_list* vals, Location location)
kono
parents:
diff changeset
858 : Statement(STATEMENT_RETURN, location),
kono
parents:
diff changeset
859 vals_(vals), is_lowered_(false)
kono
parents:
diff changeset
860 { }
kono
parents:
diff changeset
861
kono
parents:
diff changeset
862 // The list of values being returned. This may be NULL.
kono
parents:
diff changeset
863 const Expression_list*
kono
parents:
diff changeset
864 vals() const
kono
parents:
diff changeset
865 { return this->vals_; }
kono
parents:
diff changeset
866
kono
parents:
diff changeset
867 protected:
kono
parents:
diff changeset
868 int
kono
parents:
diff changeset
869 do_traverse(Traverse* traverse)
kono
parents:
diff changeset
870 { return this->traverse_expression_list(traverse, this->vals_); }
kono
parents:
diff changeset
871
kono
parents:
diff changeset
872 bool
kono
parents:
diff changeset
873 do_traverse_assignments(Traverse_assignments*);
kono
parents:
diff changeset
874
kono
parents:
diff changeset
875 Statement*
kono
parents:
diff changeset
876 do_lower(Gogo*, Named_object*, Block*, Statement_inserter*);
kono
parents:
diff changeset
877
kono
parents:
diff changeset
878 bool
kono
parents:
diff changeset
879 do_may_fall_through() const
kono
parents:
diff changeset
880 { return false; }
kono
parents:
diff changeset
881
145
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
882 int
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
883 do_inlining_cost()
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
884 { return 1; }
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
885
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
886 void
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
887 do_export_statement(Export_function_body*);
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
888
111
kono
parents:
diff changeset
889 Bstatement*
kono
parents:
diff changeset
890 do_get_backend(Translate_context*);
kono
parents:
diff changeset
891
kono
parents:
diff changeset
892 void
kono
parents:
diff changeset
893 do_dump_statement(Ast_dump_context*) const;
kono
parents:
diff changeset
894
kono
parents:
diff changeset
895 private:
kono
parents:
diff changeset
896 // Return values. This may be NULL.
kono
parents:
diff changeset
897 Expression_list* vals_;
kono
parents:
diff changeset
898 // True if this statement has been lowered.
kono
parents:
diff changeset
899 bool is_lowered_;
kono
parents:
diff changeset
900 };
kono
parents:
diff changeset
901
kono
parents:
diff changeset
902 // An expression statement.
kono
parents:
diff changeset
903
kono
parents:
diff changeset
904 class Expression_statement : public Statement
kono
parents:
diff changeset
905 {
kono
parents:
diff changeset
906 public:
kono
parents:
diff changeset
907 Expression_statement(Expression* expr, bool is_ignored);
kono
parents:
diff changeset
908
kono
parents:
diff changeset
909 Expression*
kono
parents:
diff changeset
910 expr()
kono
parents:
diff changeset
911 { return this->expr_; }
kono
parents:
diff changeset
912
kono
parents:
diff changeset
913 protected:
kono
parents:
diff changeset
914 int
kono
parents:
diff changeset
915 do_traverse(Traverse* traverse)
kono
parents:
diff changeset
916 { return this->traverse_expression(traverse, &this->expr_); }
kono
parents:
diff changeset
917
kono
parents:
diff changeset
918 void
kono
parents:
diff changeset
919 do_determine_types();
kono
parents:
diff changeset
920
kono
parents:
diff changeset
921 void
kono
parents:
diff changeset
922 do_check_types(Gogo*);
kono
parents:
diff changeset
923
kono
parents:
diff changeset
924 bool
kono
parents:
diff changeset
925 do_may_fall_through() const;
kono
parents:
diff changeset
926
145
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
927 int
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
928 do_inlining_cost()
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
929 { return 0; }
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
930
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
931 void
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
932 do_export_statement(Export_function_body*);
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
933
111
kono
parents:
diff changeset
934 Bstatement*
kono
parents:
diff changeset
935 do_get_backend(Translate_context* context);
kono
parents:
diff changeset
936
kono
parents:
diff changeset
937 void
kono
parents:
diff changeset
938 do_dump_statement(Ast_dump_context*) const;
kono
parents:
diff changeset
939
kono
parents:
diff changeset
940 private:
kono
parents:
diff changeset
941 Expression* expr_;
kono
parents:
diff changeset
942 // Whether the value of this expression is being explicitly ignored.
kono
parents:
diff changeset
943 bool is_ignored_;
kono
parents:
diff changeset
944 };
kono
parents:
diff changeset
945
kono
parents:
diff changeset
946 // A block statement--a list of statements which may include variable
kono
parents:
diff changeset
947 // definitions.
kono
parents:
diff changeset
948
kono
parents:
diff changeset
949 class Block_statement : public Statement
kono
parents:
diff changeset
950 {
kono
parents:
diff changeset
951 public:
kono
parents:
diff changeset
952 Block_statement(Block* block, Location location)
kono
parents:
diff changeset
953 : Statement(STATEMENT_BLOCK, location),
kono
parents:
diff changeset
954 block_(block), is_lowered_for_statement_(false)
kono
parents:
diff changeset
955 { }
kono
parents:
diff changeset
956
145
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
957 // Return the actual block.
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
958 Block*
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
959 block() const
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
960 { return this->block_; }
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
961
111
kono
parents:
diff changeset
962 void
kono
parents:
diff changeset
963 set_is_lowered_for_statement()
kono
parents:
diff changeset
964 { this->is_lowered_for_statement_ = true; }
kono
parents:
diff changeset
965
kono
parents:
diff changeset
966 bool
kono
parents:
diff changeset
967 is_lowered_for_statement()
kono
parents:
diff changeset
968 { return this->is_lowered_for_statement_; }
kono
parents:
diff changeset
969
145
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
970 // Export a block for a block statement.
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
971 static void
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
972 export_block(Export_function_body*, Block*, bool is_lowered_for_statement);
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
973
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
974 // Import a block statement, returning the block.
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
975 // *IS_LOWERED_FOR_STATEMENT reports whether this block statement
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
976 // was lowered from a for statement.
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
977 static Block*
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
978 do_import(Import_function_body*, Location, bool* is_lowered_for_statement);
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
979
111
kono
parents:
diff changeset
980 protected:
kono
parents:
diff changeset
981 int
kono
parents:
diff changeset
982 do_traverse(Traverse* traverse)
kono
parents:
diff changeset
983 { return this->block_->traverse(traverse); }
kono
parents:
diff changeset
984
kono
parents:
diff changeset
985 void
kono
parents:
diff changeset
986 do_determine_types()
kono
parents:
diff changeset
987 { this->block_->determine_types(); }
kono
parents:
diff changeset
988
145
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
989 int
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
990 do_inlining_cost()
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
991 { return 0; }
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
992
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
993 void
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
994 do_export_statement(Export_function_body*);
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
995
111
kono
parents:
diff changeset
996 bool
kono
parents:
diff changeset
997 do_may_fall_through() const
kono
parents:
diff changeset
998 { return this->block_->may_fall_through(); }
kono
parents:
diff changeset
999
kono
parents:
diff changeset
1000 Bstatement*
kono
parents:
diff changeset
1001 do_get_backend(Translate_context* context);
kono
parents:
diff changeset
1002
kono
parents:
diff changeset
1003 void
kono
parents:
diff changeset
1004 do_dump_statement(Ast_dump_context*) const;
kono
parents:
diff changeset
1005
kono
parents:
diff changeset
1006 private:
kono
parents:
diff changeset
1007 Block* block_;
kono
parents:
diff changeset
1008 // True if this block statement represents a lowered for statement.
kono
parents:
diff changeset
1009 bool is_lowered_for_statement_;
kono
parents:
diff changeset
1010 };
kono
parents:
diff changeset
1011
kono
parents:
diff changeset
1012 // A send statement.
kono
parents:
diff changeset
1013
kono
parents:
diff changeset
1014 class Send_statement : public Statement
kono
parents:
diff changeset
1015 {
kono
parents:
diff changeset
1016 public:
kono
parents:
diff changeset
1017 Send_statement(Expression* channel, Expression* val,
kono
parents:
diff changeset
1018 Location location)
kono
parents:
diff changeset
1019 : Statement(STATEMENT_SEND, location),
kono
parents:
diff changeset
1020 channel_(channel), val_(val)
kono
parents:
diff changeset
1021 { }
kono
parents:
diff changeset
1022
kono
parents:
diff changeset
1023 Expression*
kono
parents:
diff changeset
1024 channel()
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1025 { return this->channel_; }
111
kono
parents:
diff changeset
1026
kono
parents:
diff changeset
1027 Expression*
kono
parents:
diff changeset
1028 val()
kono
parents:
diff changeset
1029 { return this->val_; }
kono
parents:
diff changeset
1030
kono
parents:
diff changeset
1031 protected:
kono
parents:
diff changeset
1032 int
kono
parents:
diff changeset
1033 do_traverse(Traverse* traverse);
kono
parents:
diff changeset
1034
kono
parents:
diff changeset
1035 void
kono
parents:
diff changeset
1036 do_determine_types();
kono
parents:
diff changeset
1037
kono
parents:
diff changeset
1038 void
kono
parents:
diff changeset
1039 do_check_types(Gogo*);
kono
parents:
diff changeset
1040
kono
parents:
diff changeset
1041 Statement*
kono
parents:
diff changeset
1042 do_flatten(Gogo*, Named_object*, Block*, Statement_inserter*);
kono
parents:
diff changeset
1043
kono
parents:
diff changeset
1044 Bstatement*
kono
parents:
diff changeset
1045 do_get_backend(Translate_context*);
kono
parents:
diff changeset
1046
kono
parents:
diff changeset
1047 void
kono
parents:
diff changeset
1048 do_dump_statement(Ast_dump_context*) const;
kono
parents:
diff changeset
1049
145
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1050 void
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1051 do_add_conversions();
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1052
111
kono
parents:
diff changeset
1053 private:
kono
parents:
diff changeset
1054 // The channel on which to send the value.
kono
parents:
diff changeset
1055 Expression* channel_;
kono
parents:
diff changeset
1056 // The value to send.
kono
parents:
diff changeset
1057 Expression* val_;
kono
parents:
diff changeset
1058 };
kono
parents:
diff changeset
1059
kono
parents:
diff changeset
1060 // Select_clauses holds the clauses of a select statement. This is
kono
parents:
diff changeset
1061 // built by the parser.
kono
parents:
diff changeset
1062
kono
parents:
diff changeset
1063 class Select_clauses
kono
parents:
diff changeset
1064 {
kono
parents:
diff changeset
1065 public:
kono
parents:
diff changeset
1066 Select_clauses()
kono
parents:
diff changeset
1067 : clauses_()
kono
parents:
diff changeset
1068 { }
kono
parents:
diff changeset
1069
kono
parents:
diff changeset
1070 // Add a new clause. IS_SEND is true if this is a send clause,
kono
parents:
diff changeset
1071 // false for a receive clause. For a send clause CHANNEL is the
kono
parents:
diff changeset
1072 // channel and VAL is the value to send. For a receive clause
kono
parents:
diff changeset
1073 // CHANNEL is the channel, VAL is either NULL or a Var_expression
kono
parents:
diff changeset
1074 // for the variable to set, and CLOSED is either NULL or a
kono
parents:
diff changeset
1075 // Var_expression to set to whether the channel is closed. If VAL
kono
parents:
diff changeset
1076 // is NULL, VAR may be a variable to be initialized with the
145
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1077 // received value, and CLOSEDVAR may be a variable to be initialized
111
kono
parents:
diff changeset
1078 // with whether the channel is closed. IS_DEFAULT is true if this
kono
parents:
diff changeset
1079 // is the default clause. STATEMENTS is the list of statements to
kono
parents:
diff changeset
1080 // execute.
kono
parents:
diff changeset
1081 void
kono
parents:
diff changeset
1082 add(bool is_send, Expression* channel, Expression* val, Expression* closed,
kono
parents:
diff changeset
1083 Named_object* var, Named_object* closedvar, bool is_default,
kono
parents:
diff changeset
1084 Block* statements, Location location)
kono
parents:
diff changeset
1085 {
kono
parents:
diff changeset
1086 this->clauses_.push_back(Select_clause(is_send, channel, val, closed, var,
kono
parents:
diff changeset
1087 closedvar, is_default, statements,
kono
parents:
diff changeset
1088 location));
kono
parents:
diff changeset
1089 }
kono
parents:
diff changeset
1090
kono
parents:
diff changeset
1091 size_t
kono
parents:
diff changeset
1092 size() const
kono
parents:
diff changeset
1093 { return this->clauses_.size(); }
kono
parents:
diff changeset
1094
kono
parents:
diff changeset
1095 // Traverse the select clauses.
kono
parents:
diff changeset
1096 int
kono
parents:
diff changeset
1097 traverse(Traverse*);
kono
parents:
diff changeset
1098
kono
parents:
diff changeset
1099 // Lower statements.
kono
parents:
diff changeset
1100 void
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1101 lower(Gogo*, Named_object*, Block*, Temporary_statement*,
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1102 Temporary_statement*);
111
kono
parents:
diff changeset
1103
kono
parents:
diff changeset
1104 // Determine types.
kono
parents:
diff changeset
1105 void
kono
parents:
diff changeset
1106 determine_types();
kono
parents:
diff changeset
1107
kono
parents:
diff changeset
1108 // Check types.
kono
parents:
diff changeset
1109 void
kono
parents:
diff changeset
1110 check_types();
kono
parents:
diff changeset
1111
kono
parents:
diff changeset
1112 // Whether the select clauses may fall through to the statement
kono
parents:
diff changeset
1113 // which follows the overall select statement.
kono
parents:
diff changeset
1114 bool
kono
parents:
diff changeset
1115 may_fall_through() const;
kono
parents:
diff changeset
1116
kono
parents:
diff changeset
1117 // Convert to the backend representation.
kono
parents:
diff changeset
1118 Bstatement*
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1119 get_backend(Translate_context*, Temporary_statement* index,
111
kono
parents:
diff changeset
1120 Unnamed_label* break_label, Location);
kono
parents:
diff changeset
1121
kono
parents:
diff changeset
1122 // Dump AST representation.
kono
parents:
diff changeset
1123 void
kono
parents:
diff changeset
1124 dump_clauses(Ast_dump_context*) const;
kono
parents:
diff changeset
1125
kono
parents:
diff changeset
1126 // A single clause.
kono
parents:
diff changeset
1127 class Select_clause
kono
parents:
diff changeset
1128 {
kono
parents:
diff changeset
1129 public:
kono
parents:
diff changeset
1130 Select_clause()
kono
parents:
diff changeset
1131 : channel_(NULL), val_(NULL), closed_(NULL), var_(NULL),
kono
parents:
diff changeset
1132 closedvar_(NULL), statements_(NULL), is_send_(false),
kono
parents:
diff changeset
1133 is_default_(false)
kono
parents:
diff changeset
1134 { }
kono
parents:
diff changeset
1135
kono
parents:
diff changeset
1136 Select_clause(bool is_send, Expression* channel, Expression* val,
kono
parents:
diff changeset
1137 Expression* closed, Named_object* var,
kono
parents:
diff changeset
1138 Named_object* closedvar, bool is_default, Block* statements,
kono
parents:
diff changeset
1139 Location location)
kono
parents:
diff changeset
1140 : channel_(channel), val_(val), closed_(closed), var_(var),
kono
parents:
diff changeset
1141 closedvar_(closedvar), statements_(statements), location_(location),
kono
parents:
diff changeset
1142 is_send_(is_send), is_default_(is_default), is_lowered_(false)
kono
parents:
diff changeset
1143 { go_assert(is_default ? channel == NULL : channel != NULL); }
kono
parents:
diff changeset
1144
kono
parents:
diff changeset
1145 // Traverse the select clause.
kono
parents:
diff changeset
1146 int
kono
parents:
diff changeset
1147 traverse(Traverse*);
kono
parents:
diff changeset
1148
kono
parents:
diff changeset
1149 // Lower statements.
kono
parents:
diff changeset
1150 void
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1151 lower(Gogo*, Named_object*, Block*, Temporary_statement*, size_t,
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1152 Temporary_statement*);
111
kono
parents:
diff changeset
1153
kono
parents:
diff changeset
1154 // Determine types.
kono
parents:
diff changeset
1155 void
kono
parents:
diff changeset
1156 determine_types();
kono
parents:
diff changeset
1157
kono
parents:
diff changeset
1158 // Check types.
kono
parents:
diff changeset
1159 void
kono
parents:
diff changeset
1160 check_types();
kono
parents:
diff changeset
1161
kono
parents:
diff changeset
1162 // Return true if this is the default clause.
kono
parents:
diff changeset
1163 bool
kono
parents:
diff changeset
1164 is_default() const
kono
parents:
diff changeset
1165 { return this->is_default_; }
kono
parents:
diff changeset
1166
kono
parents:
diff changeset
1167 // Return the channel. This will return NULL for the default
kono
parents:
diff changeset
1168 // clause.
kono
parents:
diff changeset
1169 Expression*
kono
parents:
diff changeset
1170 channel() const
kono
parents:
diff changeset
1171 { return this->channel_; }
kono
parents:
diff changeset
1172
kono
parents:
diff changeset
1173 // Return true for a send, false for a receive.
kono
parents:
diff changeset
1174 bool
kono
parents:
diff changeset
1175 is_send() const
kono
parents:
diff changeset
1176 {
kono
parents:
diff changeset
1177 go_assert(!this->is_default_);
kono
parents:
diff changeset
1178 return this->is_send_;
kono
parents:
diff changeset
1179 }
kono
parents:
diff changeset
1180
145
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1181 // Return the value to send or the lvalue to receive into.
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1182 Expression*
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1183 val() const
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1184 { return this->val_; }
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1185
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1186 // Return the lvalue to set to whether the channel is closed
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1187 // on a receive.
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1188 Expression*
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1189 closed() const
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1190 { return this->closed_; }
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1191
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1192 // Return the variable to initialize, for "case a := <-ch".
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1193 Named_object*
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1194 var() const
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1195 { return this->var_; }
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1196
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1197 // Return the variable to initialize to whether the channel
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1198 // is closed, for "case a, c := <-ch".
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1199 Named_object*
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1200 closedvar() const
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1201 { return this->closedvar_; }
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1202
111
kono
parents:
diff changeset
1203 // Return the statements.
145
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1204 Block*
111
kono
parents:
diff changeset
1205 statements() const
kono
parents:
diff changeset
1206 { return this->statements_; }
kono
parents:
diff changeset
1207
kono
parents:
diff changeset
1208 // Return the location.
kono
parents:
diff changeset
1209 Location
kono
parents:
diff changeset
1210 location() const
kono
parents:
diff changeset
1211 { return this->location_; }
kono
parents:
diff changeset
1212
kono
parents:
diff changeset
1213 // Whether this clause may fall through to the statement which
kono
parents:
diff changeset
1214 // follows the overall select statement.
kono
parents:
diff changeset
1215 bool
kono
parents:
diff changeset
1216 may_fall_through() const;
kono
parents:
diff changeset
1217
kono
parents:
diff changeset
1218 // Convert the statements to the backend representation.
kono
parents:
diff changeset
1219 Bstatement*
kono
parents:
diff changeset
1220 get_statements_backend(Translate_context*);
kono
parents:
diff changeset
1221
kono
parents:
diff changeset
1222 // Dump AST representation.
kono
parents:
diff changeset
1223 void
kono
parents:
diff changeset
1224 dump_clause(Ast_dump_context*) const;
kono
parents:
diff changeset
1225
kono
parents:
diff changeset
1226 private:
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1227 // These values must match the values in libgo/go/runtime/select.go.
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1228 enum
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1229 {
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1230 caseRecv = 1,
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1231 caseSend = 2,
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1232 caseDefault = 3,
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1233 };
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1234
111
kono
parents:
diff changeset
1235 void
kono
parents:
diff changeset
1236 lower_default(Block*, Expression*);
kono
parents:
diff changeset
1237
kono
parents:
diff changeset
1238 void
kono
parents:
diff changeset
1239 lower_send(Block*, Expression*, Expression*);
kono
parents:
diff changeset
1240
kono
parents:
diff changeset
1241 void
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1242 lower_recv(Gogo*, Named_object*, Block*, Expression*, Expression*,
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1243 Temporary_statement*);
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1244
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1245 void
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1246 set_case(Block*, Expression*, Expression*, Expression*, int);
111
kono
parents:
diff changeset
1247
kono
parents:
diff changeset
1248 // The channel.
kono
parents:
diff changeset
1249 Expression* channel_;
kono
parents:
diff changeset
1250 // The value to send or the lvalue to receive into.
kono
parents:
diff changeset
1251 Expression* val_;
kono
parents:
diff changeset
1252 // The lvalue to set to whether the channel is closed on a
kono
parents:
diff changeset
1253 // receive.
kono
parents:
diff changeset
1254 Expression* closed_;
kono
parents:
diff changeset
1255 // The variable to initialize, for "case a := <-ch".
kono
parents:
diff changeset
1256 Named_object* var_;
kono
parents:
diff changeset
1257 // The variable to initialize to whether the channel is closed,
kono
parents:
diff changeset
1258 // for "case a, c := <-ch".
kono
parents:
diff changeset
1259 Named_object* closedvar_;
kono
parents:
diff changeset
1260 // The statements to execute.
kono
parents:
diff changeset
1261 Block* statements_;
kono
parents:
diff changeset
1262 // The location of this clause.
kono
parents:
diff changeset
1263 Location location_;
kono
parents:
diff changeset
1264 // Whether this is a send or a receive.
kono
parents:
diff changeset
1265 bool is_send_;
kono
parents:
diff changeset
1266 // Whether this is the default.
kono
parents:
diff changeset
1267 bool is_default_;
kono
parents:
diff changeset
1268 // Whether this has been lowered.
kono
parents:
diff changeset
1269 bool is_lowered_;
kono
parents:
diff changeset
1270 };
kono
parents:
diff changeset
1271
145
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1272 Select_clause&
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1273 at(size_t i)
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1274 { return this->clauses_.at(i); }
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1275
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1276 private:
111
kono
parents:
diff changeset
1277 typedef std::vector<Select_clause> Clauses;
kono
parents:
diff changeset
1278
kono
parents:
diff changeset
1279 Clauses clauses_;
kono
parents:
diff changeset
1280 };
kono
parents:
diff changeset
1281
kono
parents:
diff changeset
1282 // A select statement.
kono
parents:
diff changeset
1283
kono
parents:
diff changeset
1284 class Select_statement : public Statement
kono
parents:
diff changeset
1285 {
kono
parents:
diff changeset
1286 public:
kono
parents:
diff changeset
1287 Select_statement(Location location)
kono
parents:
diff changeset
1288 : Statement(STATEMENT_SELECT, location),
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1289 clauses_(NULL), index_(NULL), break_label_(NULL), is_lowered_(false)
111
kono
parents:
diff changeset
1290 { }
kono
parents:
diff changeset
1291
kono
parents:
diff changeset
1292 // Add the clauses.
kono
parents:
diff changeset
1293 void
kono
parents:
diff changeset
1294 add_clauses(Select_clauses* clauses)
kono
parents:
diff changeset
1295 {
kono
parents:
diff changeset
1296 go_assert(this->clauses_ == NULL);
kono
parents:
diff changeset
1297 this->clauses_ = clauses;
kono
parents:
diff changeset
1298 }
kono
parents:
diff changeset
1299
kono
parents:
diff changeset
1300 // Return the break label for this select statement.
kono
parents:
diff changeset
1301 Unnamed_label*
kono
parents:
diff changeset
1302 break_label();
kono
parents:
diff changeset
1303
kono
parents:
diff changeset
1304 protected:
kono
parents:
diff changeset
1305 int
kono
parents:
diff changeset
1306 do_traverse(Traverse* traverse)
kono
parents:
diff changeset
1307 { return this->clauses_->traverse(traverse); }
kono
parents:
diff changeset
1308
kono
parents:
diff changeset
1309 Statement*
kono
parents:
diff changeset
1310 do_lower(Gogo*, Named_object*, Block*, Statement_inserter*);
kono
parents:
diff changeset
1311
kono
parents:
diff changeset
1312 void
kono
parents:
diff changeset
1313 do_determine_types()
kono
parents:
diff changeset
1314 { this->clauses_->determine_types(); }
kono
parents:
diff changeset
1315
kono
parents:
diff changeset
1316 void
kono
parents:
diff changeset
1317 do_check_types(Gogo*)
kono
parents:
diff changeset
1318 { this->clauses_->check_types(); }
kono
parents:
diff changeset
1319
kono
parents:
diff changeset
1320 bool
kono
parents:
diff changeset
1321 do_may_fall_through() const;
kono
parents:
diff changeset
1322
kono
parents:
diff changeset
1323 Bstatement*
kono
parents:
diff changeset
1324 do_get_backend(Translate_context*);
kono
parents:
diff changeset
1325
kono
parents:
diff changeset
1326 void
kono
parents:
diff changeset
1327 do_dump_statement(Ast_dump_context*) const;
kono
parents:
diff changeset
1328
kono
parents:
diff changeset
1329 private:
145
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1330 // Lower a one-case select statement.
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1331 Statement*
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1332 lower_one_case(Block*);
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1333
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1334 // Lower a two-case select statement with one defualt case.
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1335 Statement*
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1336 lower_two_case(Block*);
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1337
111
kono
parents:
diff changeset
1338 // The select clauses.
kono
parents:
diff changeset
1339 Select_clauses* clauses_;
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1340 // A temporary that holds the index value returned by selectgo.
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1341 Temporary_statement* index_;
111
kono
parents:
diff changeset
1342 // The break label.
kono
parents:
diff changeset
1343 Unnamed_label* break_label_;
kono
parents:
diff changeset
1344 // Whether this statement has been lowered.
kono
parents:
diff changeset
1345 bool is_lowered_;
kono
parents:
diff changeset
1346 };
kono
parents:
diff changeset
1347
kono
parents:
diff changeset
1348 // A statement which requires a thunk: go or defer.
kono
parents:
diff changeset
1349
kono
parents:
diff changeset
1350 class Thunk_statement : public Statement
kono
parents:
diff changeset
1351 {
kono
parents:
diff changeset
1352 public:
kono
parents:
diff changeset
1353 Thunk_statement(Statement_classification, Call_expression*,
kono
parents:
diff changeset
1354 Location);
kono
parents:
diff changeset
1355
kono
parents:
diff changeset
1356 // Return the call expression.
kono
parents:
diff changeset
1357 Expression*
kono
parents:
diff changeset
1358 call() const
kono
parents:
diff changeset
1359 { return this->call_; }
kono
parents:
diff changeset
1360
kono
parents:
diff changeset
1361 // Simplify a go or defer statement so that it only uses a single
kono
parents:
diff changeset
1362 // parameter.
kono
parents:
diff changeset
1363 bool
kono
parents:
diff changeset
1364 simplify_statement(Gogo*, Named_object*, Block*);
kono
parents:
diff changeset
1365
kono
parents:
diff changeset
1366 protected:
kono
parents:
diff changeset
1367 int
kono
parents:
diff changeset
1368 do_traverse(Traverse* traverse);
kono
parents:
diff changeset
1369
kono
parents:
diff changeset
1370 bool
kono
parents:
diff changeset
1371 do_traverse_assignments(Traverse_assignments*);
kono
parents:
diff changeset
1372
kono
parents:
diff changeset
1373 void
kono
parents:
diff changeset
1374 do_determine_types();
kono
parents:
diff changeset
1375
kono
parents:
diff changeset
1376 void
kono
parents:
diff changeset
1377 do_check_types(Gogo*);
kono
parents:
diff changeset
1378
kono
parents:
diff changeset
1379 // Return the function and argument for the call.
kono
parents:
diff changeset
1380 bool
kono
parents:
diff changeset
1381 get_fn_and_arg(Expression** pfn, Expression** parg);
kono
parents:
diff changeset
1382
kono
parents:
diff changeset
1383 private:
kono
parents:
diff changeset
1384 // Return whether this is a simple go statement.
kono
parents:
diff changeset
1385 bool
kono
parents:
diff changeset
1386 is_simple(Function_type*) const;
kono
parents:
diff changeset
1387
kono
parents:
diff changeset
1388 // Return whether the thunk function is a constant.
kono
parents:
diff changeset
1389 bool
kono
parents:
diff changeset
1390 is_constant_function() const;
kono
parents:
diff changeset
1391
kono
parents:
diff changeset
1392 // Build the struct to use for a complex case.
kono
parents:
diff changeset
1393 Struct_type*
kono
parents:
diff changeset
1394 build_struct(Function_type* fntype);
kono
parents:
diff changeset
1395
kono
parents:
diff changeset
1396 // Build the thunk.
kono
parents:
diff changeset
1397 void
kono
parents:
diff changeset
1398 build_thunk(Gogo*, const std::string&);
kono
parents:
diff changeset
1399
kono
parents:
diff changeset
1400 // Set the name to use for thunk field N.
kono
parents:
diff changeset
1401 void
kono
parents:
diff changeset
1402 thunk_field_param(int n, char* buf, size_t buflen);
kono
parents:
diff changeset
1403
kono
parents:
diff changeset
1404 // The function call to be executed in a separate thread (go) or
kono
parents:
diff changeset
1405 // later (defer).
kono
parents:
diff changeset
1406 Expression* call_;
kono
parents:
diff changeset
1407 // The type used for a struct to pass to a thunk, if this is not a
kono
parents:
diff changeset
1408 // simple call.
kono
parents:
diff changeset
1409 Struct_type* struct_type_;
kono
parents:
diff changeset
1410 };
kono
parents:
diff changeset
1411
kono
parents:
diff changeset
1412 // A go statement.
kono
parents:
diff changeset
1413
kono
parents:
diff changeset
1414 class Go_statement : public Thunk_statement
kono
parents:
diff changeset
1415 {
kono
parents:
diff changeset
1416 public:
kono
parents:
diff changeset
1417 Go_statement(Call_expression* call, Location location)
kono
parents:
diff changeset
1418 : Thunk_statement(STATEMENT_GO, call, location)
kono
parents:
diff changeset
1419 { }
kono
parents:
diff changeset
1420
kono
parents:
diff changeset
1421 protected:
kono
parents:
diff changeset
1422 Bstatement*
kono
parents:
diff changeset
1423 do_get_backend(Translate_context*);
kono
parents:
diff changeset
1424
kono
parents:
diff changeset
1425 void
kono
parents:
diff changeset
1426 do_dump_statement(Ast_dump_context*) const;
kono
parents:
diff changeset
1427 };
kono
parents:
diff changeset
1428
kono
parents:
diff changeset
1429 // A defer statement.
kono
parents:
diff changeset
1430
kono
parents:
diff changeset
1431 class Defer_statement : public Thunk_statement
kono
parents:
diff changeset
1432 {
kono
parents:
diff changeset
1433 public:
kono
parents:
diff changeset
1434 Defer_statement(Call_expression* call, Location location)
145
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1435 : Thunk_statement(STATEMENT_DEFER, call, location),
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1436 on_stack_(false)
111
kono
parents:
diff changeset
1437 { }
kono
parents:
diff changeset
1438
145
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1439 void
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1440 set_on_stack()
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1441 { this->on_stack_ = true; }
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1442
111
kono
parents:
diff changeset
1443 protected:
kono
parents:
diff changeset
1444 Bstatement*
kono
parents:
diff changeset
1445 do_get_backend(Translate_context*);
kono
parents:
diff changeset
1446
kono
parents:
diff changeset
1447 void
kono
parents:
diff changeset
1448 do_dump_statement(Ast_dump_context*) const;
145
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1449
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1450 private:
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1451 static Type*
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1452 defer_struct_type();
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1453
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1454 bool on_stack_;
111
kono
parents:
diff changeset
1455 };
kono
parents:
diff changeset
1456
kono
parents:
diff changeset
1457 // A goto statement.
kono
parents:
diff changeset
1458
kono
parents:
diff changeset
1459 class Goto_statement : public Statement
kono
parents:
diff changeset
1460 {
kono
parents:
diff changeset
1461 public:
kono
parents:
diff changeset
1462 Goto_statement(Label* label, Location location)
kono
parents:
diff changeset
1463 : Statement(STATEMENT_GOTO, location),
kono
parents:
diff changeset
1464 label_(label)
kono
parents:
diff changeset
1465 { }
kono
parents:
diff changeset
1466
kono
parents:
diff changeset
1467 // Return the label being jumped to.
kono
parents:
diff changeset
1468 Label*
kono
parents:
diff changeset
1469 label() const
kono
parents:
diff changeset
1470 { return this->label_; }
kono
parents:
diff changeset
1471
145
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1472 // Import a goto statement.
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1473 static Statement*
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1474 do_import(Import_function_body*, Location);
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1475
111
kono
parents:
diff changeset
1476 protected:
kono
parents:
diff changeset
1477 int
kono
parents:
diff changeset
1478 do_traverse(Traverse*);
kono
parents:
diff changeset
1479
kono
parents:
diff changeset
1480 void
kono
parents:
diff changeset
1481 do_check_types(Gogo*);
kono
parents:
diff changeset
1482
kono
parents:
diff changeset
1483 bool
kono
parents:
diff changeset
1484 do_may_fall_through() const
kono
parents:
diff changeset
1485 { return false; }
kono
parents:
diff changeset
1486
kono
parents:
diff changeset
1487 Bstatement*
kono
parents:
diff changeset
1488 do_get_backend(Translate_context*);
kono
parents:
diff changeset
1489
145
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1490 int
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1491 do_inlining_cost()
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1492 { return 5; }
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1493
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1494 void
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1495 do_export_statement(Export_function_body*);
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1496
111
kono
parents:
diff changeset
1497 void
kono
parents:
diff changeset
1498 do_dump_statement(Ast_dump_context*) const;
kono
parents:
diff changeset
1499
kono
parents:
diff changeset
1500 private:
kono
parents:
diff changeset
1501 Label* label_;
kono
parents:
diff changeset
1502 };
kono
parents:
diff changeset
1503
kono
parents:
diff changeset
1504 // A goto statement to an unnamed label.
kono
parents:
diff changeset
1505
kono
parents:
diff changeset
1506 class Goto_unnamed_statement : public Statement
kono
parents:
diff changeset
1507 {
kono
parents:
diff changeset
1508 public:
kono
parents:
diff changeset
1509 Goto_unnamed_statement(Unnamed_label* label, Location location)
kono
parents:
diff changeset
1510 : Statement(STATEMENT_GOTO_UNNAMED, location),
kono
parents:
diff changeset
1511 label_(label)
kono
parents:
diff changeset
1512 { }
kono
parents:
diff changeset
1513
kono
parents:
diff changeset
1514 Unnamed_label*
kono
parents:
diff changeset
1515 unnamed_label() const
kono
parents:
diff changeset
1516 { return this->label_; }
kono
parents:
diff changeset
1517
kono
parents:
diff changeset
1518 protected:
kono
parents:
diff changeset
1519 int
kono
parents:
diff changeset
1520 do_traverse(Traverse*);
kono
parents:
diff changeset
1521
kono
parents:
diff changeset
1522 bool
kono
parents:
diff changeset
1523 do_may_fall_through() const
kono
parents:
diff changeset
1524 { return false; }
kono
parents:
diff changeset
1525
kono
parents:
diff changeset
1526 Bstatement*
kono
parents:
diff changeset
1527 do_get_backend(Translate_context* context);
kono
parents:
diff changeset
1528
145
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1529 int
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1530 do_inlining_cost()
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1531 { return 5; }
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1532
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1533 void
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1534 do_export_statement(Export_function_body*);
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1535
111
kono
parents:
diff changeset
1536 void
kono
parents:
diff changeset
1537 do_dump_statement(Ast_dump_context*) const;
kono
parents:
diff changeset
1538
kono
parents:
diff changeset
1539 private:
kono
parents:
diff changeset
1540 Unnamed_label* label_;
kono
parents:
diff changeset
1541 };
kono
parents:
diff changeset
1542
kono
parents:
diff changeset
1543 // A label statement.
kono
parents:
diff changeset
1544
kono
parents:
diff changeset
1545 class Label_statement : public Statement
kono
parents:
diff changeset
1546 {
kono
parents:
diff changeset
1547 public:
kono
parents:
diff changeset
1548 Label_statement(Label* label, Location location)
kono
parents:
diff changeset
1549 : Statement(STATEMENT_LABEL, location),
kono
parents:
diff changeset
1550 label_(label)
kono
parents:
diff changeset
1551 { }
kono
parents:
diff changeset
1552
kono
parents:
diff changeset
1553 // Return the label itself.
kono
parents:
diff changeset
1554 Label*
kono
parents:
diff changeset
1555 label() const
kono
parents:
diff changeset
1556 { return this->label_; }
kono
parents:
diff changeset
1557
145
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1558 // Import a label or unnamed label.
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1559 static Statement*
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1560 do_import(Import_function_body*, Location);
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1561
111
kono
parents:
diff changeset
1562 protected:
kono
parents:
diff changeset
1563 int
kono
parents:
diff changeset
1564 do_traverse(Traverse*);
kono
parents:
diff changeset
1565
kono
parents:
diff changeset
1566 Bstatement*
kono
parents:
diff changeset
1567 do_get_backend(Translate_context*);
kono
parents:
diff changeset
1568
145
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1569 int
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1570 do_inlining_cost()
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1571 { return 1; }
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1572
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1573 void
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1574 do_export_statement(Export_function_body*);
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1575
111
kono
parents:
diff changeset
1576 void
kono
parents:
diff changeset
1577 do_dump_statement(Ast_dump_context*) const;
kono
parents:
diff changeset
1578
kono
parents:
diff changeset
1579 private:
kono
parents:
diff changeset
1580 // The label.
kono
parents:
diff changeset
1581 Label* label_;
kono
parents:
diff changeset
1582 };
kono
parents:
diff changeset
1583
kono
parents:
diff changeset
1584 // An unnamed label statement.
kono
parents:
diff changeset
1585
kono
parents:
diff changeset
1586 class Unnamed_label_statement : public Statement
kono
parents:
diff changeset
1587 {
kono
parents:
diff changeset
1588 public:
kono
parents:
diff changeset
1589 Unnamed_label_statement(Unnamed_label* label);
kono
parents:
diff changeset
1590
kono
parents:
diff changeset
1591 protected:
kono
parents:
diff changeset
1592 int
kono
parents:
diff changeset
1593 do_traverse(Traverse*);
kono
parents:
diff changeset
1594
kono
parents:
diff changeset
1595 Bstatement*
kono
parents:
diff changeset
1596 do_get_backend(Translate_context* context);
kono
parents:
diff changeset
1597
145
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1598 int
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1599 do_inlining_cost()
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1600 { return 1; }
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1601
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1602 void
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1603 do_export_statement(Export_function_body*);
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1604
111
kono
parents:
diff changeset
1605 void
kono
parents:
diff changeset
1606 do_dump_statement(Ast_dump_context*) const;
kono
parents:
diff changeset
1607
kono
parents:
diff changeset
1608 private:
kono
parents:
diff changeset
1609 // The label.
kono
parents:
diff changeset
1610 Unnamed_label* label_;
kono
parents:
diff changeset
1611 };
kono
parents:
diff changeset
1612
kono
parents:
diff changeset
1613 // An if statement.
kono
parents:
diff changeset
1614
kono
parents:
diff changeset
1615 class If_statement : public Statement
kono
parents:
diff changeset
1616 {
kono
parents:
diff changeset
1617 public:
kono
parents:
diff changeset
1618 If_statement(Expression* cond, Block* then_block, Block* else_block,
kono
parents:
diff changeset
1619 Location location)
kono
parents:
diff changeset
1620 : Statement(STATEMENT_IF, location),
kono
parents:
diff changeset
1621 cond_(cond), then_block_(then_block), else_block_(else_block)
kono
parents:
diff changeset
1622 { }
kono
parents:
diff changeset
1623
kono
parents:
diff changeset
1624 Expression*
kono
parents:
diff changeset
1625 condition() const
kono
parents:
diff changeset
1626 { return this->cond_; }
kono
parents:
diff changeset
1627
145
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1628 Block*
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1629 then_block() const
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1630 { return this->then_block_; }
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1631
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1632 Block*
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1633 else_block() const
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1634 { return this->else_block_; }
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1635
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1636 // Import an if statement.
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1637 static Statement*
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1638 do_import(Import_function_body*, Location);
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1639
111
kono
parents:
diff changeset
1640 protected:
kono
parents:
diff changeset
1641 int
kono
parents:
diff changeset
1642 do_traverse(Traverse*);
kono
parents:
diff changeset
1643
kono
parents:
diff changeset
1644 void
kono
parents:
diff changeset
1645 do_determine_types();
kono
parents:
diff changeset
1646
kono
parents:
diff changeset
1647 void
kono
parents:
diff changeset
1648 do_check_types(Gogo*);
kono
parents:
diff changeset
1649
145
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1650 int
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1651 do_inlining_cost()
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1652 { return 5; }
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1653
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1654 void
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1655 do_export_statement(Export_function_body*);
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1656
111
kono
parents:
diff changeset
1657 bool
kono
parents:
diff changeset
1658 do_may_fall_through() const;
kono
parents:
diff changeset
1659
kono
parents:
diff changeset
1660 Bstatement*
kono
parents:
diff changeset
1661 do_get_backend(Translate_context*);
kono
parents:
diff changeset
1662
kono
parents:
diff changeset
1663 void
kono
parents:
diff changeset
1664 do_dump_statement(Ast_dump_context*) const;
kono
parents:
diff changeset
1665
kono
parents:
diff changeset
1666 private:
kono
parents:
diff changeset
1667 Expression* cond_;
kono
parents:
diff changeset
1668 Block* then_block_;
kono
parents:
diff changeset
1669 Block* else_block_;
kono
parents:
diff changeset
1670 };
kono
parents:
diff changeset
1671
kono
parents:
diff changeset
1672 // A for statement.
kono
parents:
diff changeset
1673
kono
parents:
diff changeset
1674 class For_statement : public Statement
kono
parents:
diff changeset
1675 {
kono
parents:
diff changeset
1676 public:
kono
parents:
diff changeset
1677 For_statement(Block* init, Expression* cond, Block* post,
kono
parents:
diff changeset
1678 Location location)
kono
parents:
diff changeset
1679 : Statement(STATEMENT_FOR, location),
kono
parents:
diff changeset
1680 init_(init), cond_(cond), post_(post), statements_(NULL),
kono
parents:
diff changeset
1681 break_label_(NULL), continue_label_(NULL)
kono
parents:
diff changeset
1682 { }
kono
parents:
diff changeset
1683
kono
parents:
diff changeset
1684 // Add the statements.
kono
parents:
diff changeset
1685 void
kono
parents:
diff changeset
1686 add_statements(Block* statements)
kono
parents:
diff changeset
1687 {
kono
parents:
diff changeset
1688 go_assert(this->statements_ == NULL);
kono
parents:
diff changeset
1689 this->statements_ = statements;
kono
parents:
diff changeset
1690 }
kono
parents:
diff changeset
1691
kono
parents:
diff changeset
1692 // Return the break label for this for statement.
kono
parents:
diff changeset
1693 Unnamed_label*
kono
parents:
diff changeset
1694 break_label();
kono
parents:
diff changeset
1695
kono
parents:
diff changeset
1696 // Return the continue label for this for statement.
kono
parents:
diff changeset
1697 Unnamed_label*
kono
parents:
diff changeset
1698 continue_label();
kono
parents:
diff changeset
1699
kono
parents:
diff changeset
1700 // Set the break and continue labels for this statement.
kono
parents:
diff changeset
1701 void
kono
parents:
diff changeset
1702 set_break_continue_labels(Unnamed_label* break_label,
kono
parents:
diff changeset
1703 Unnamed_label* continue_label);
kono
parents:
diff changeset
1704
kono
parents:
diff changeset
1705 protected:
kono
parents:
diff changeset
1706 int
kono
parents:
diff changeset
1707 do_traverse(Traverse*);
kono
parents:
diff changeset
1708
kono
parents:
diff changeset
1709 bool
kono
parents:
diff changeset
1710 do_traverse_assignments(Traverse_assignments*)
kono
parents:
diff changeset
1711 { go_unreachable(); }
kono
parents:
diff changeset
1712
kono
parents:
diff changeset
1713 Statement*
kono
parents:
diff changeset
1714 do_lower(Gogo*, Named_object*, Block*, Statement_inserter*);
kono
parents:
diff changeset
1715
kono
parents:
diff changeset
1716 bool
kono
parents:
diff changeset
1717 do_may_fall_through() const;
kono
parents:
diff changeset
1718
kono
parents:
diff changeset
1719 Bstatement*
kono
parents:
diff changeset
1720 do_get_backend(Translate_context*)
kono
parents:
diff changeset
1721 { go_unreachable(); }
kono
parents:
diff changeset
1722
kono
parents:
diff changeset
1723 void
kono
parents:
diff changeset
1724 do_dump_statement(Ast_dump_context*) const;
kono
parents:
diff changeset
1725
kono
parents:
diff changeset
1726 private:
kono
parents:
diff changeset
1727 // The initialization statements. This may be NULL.
kono
parents:
diff changeset
1728 Block* init_;
kono
parents:
diff changeset
1729 // The condition. This may be NULL.
kono
parents:
diff changeset
1730 Expression* cond_;
kono
parents:
diff changeset
1731 // The statements to run after each iteration. This may be NULL.
kono
parents:
diff changeset
1732 Block* post_;
kono
parents:
diff changeset
1733 // The statements in the loop itself.
kono
parents:
diff changeset
1734 Block* statements_;
kono
parents:
diff changeset
1735 // The break label, if needed.
kono
parents:
diff changeset
1736 Unnamed_label* break_label_;
kono
parents:
diff changeset
1737 // The continue label, if needed.
kono
parents:
diff changeset
1738 Unnamed_label* continue_label_;
kono
parents:
diff changeset
1739 };
kono
parents:
diff changeset
1740
kono
parents:
diff changeset
1741 // A for statement over a range clause.
kono
parents:
diff changeset
1742
kono
parents:
diff changeset
1743 class For_range_statement : public Statement
kono
parents:
diff changeset
1744 {
kono
parents:
diff changeset
1745 public:
kono
parents:
diff changeset
1746 For_range_statement(Expression* index_var, Expression* value_var,
kono
parents:
diff changeset
1747 Expression* range, Location location)
kono
parents:
diff changeset
1748 : Statement(STATEMENT_FOR_RANGE, location),
kono
parents:
diff changeset
1749 index_var_(index_var), value_var_(value_var), range_(range),
kono
parents:
diff changeset
1750 statements_(NULL), break_label_(NULL), continue_label_(NULL)
kono
parents:
diff changeset
1751 { }
kono
parents:
diff changeset
1752
kono
parents:
diff changeset
1753 // Add the statements.
kono
parents:
diff changeset
1754 void
kono
parents:
diff changeset
1755 add_statements(Block* statements)
kono
parents:
diff changeset
1756 {
kono
parents:
diff changeset
1757 go_assert(this->statements_ == NULL);
kono
parents:
diff changeset
1758 this->statements_ = statements;
kono
parents:
diff changeset
1759 }
kono
parents:
diff changeset
1760
kono
parents:
diff changeset
1761 // Return the break label for this for statement.
kono
parents:
diff changeset
1762 Unnamed_label*
kono
parents:
diff changeset
1763 break_label();
kono
parents:
diff changeset
1764
kono
parents:
diff changeset
1765 // Return the continue label for this for statement.
kono
parents:
diff changeset
1766 Unnamed_label*
kono
parents:
diff changeset
1767 continue_label();
kono
parents:
diff changeset
1768
kono
parents:
diff changeset
1769 protected:
kono
parents:
diff changeset
1770 int
kono
parents:
diff changeset
1771 do_traverse(Traverse*);
kono
parents:
diff changeset
1772
kono
parents:
diff changeset
1773 bool
kono
parents:
diff changeset
1774 do_traverse_assignments(Traverse_assignments*)
kono
parents:
diff changeset
1775 { go_unreachable(); }
kono
parents:
diff changeset
1776
kono
parents:
diff changeset
1777 Statement*
kono
parents:
diff changeset
1778 do_lower(Gogo*, Named_object*, Block*, Statement_inserter*);
kono
parents:
diff changeset
1779
kono
parents:
diff changeset
1780 Bstatement*
kono
parents:
diff changeset
1781 do_get_backend(Translate_context*)
kono
parents:
diff changeset
1782 { go_unreachable(); }
kono
parents:
diff changeset
1783
kono
parents:
diff changeset
1784 void
kono
parents:
diff changeset
1785 do_dump_statement(Ast_dump_context*) const;
kono
parents:
diff changeset
1786
kono
parents:
diff changeset
1787 private:
kono
parents:
diff changeset
1788 Expression*
kono
parents:
diff changeset
1789 make_range_ref(Named_object*, Temporary_statement*, Location);
kono
parents:
diff changeset
1790
kono
parents:
diff changeset
1791 Call_expression*
kono
parents:
diff changeset
1792 call_builtin(Gogo*, const char* funcname, Expression* arg, Location);
kono
parents:
diff changeset
1793
kono
parents:
diff changeset
1794 void
kono
parents:
diff changeset
1795 lower_range_array(Gogo*, Block*, Block*, Named_object*, Temporary_statement*,
kono
parents:
diff changeset
1796 Temporary_statement*, Temporary_statement*,
kono
parents:
diff changeset
1797 Block**, Expression**, Block**, Block**);
kono
parents:
diff changeset
1798
kono
parents:
diff changeset
1799 void
kono
parents:
diff changeset
1800 lower_range_slice(Gogo*, Block*, Block*, Named_object*, Temporary_statement*,
kono
parents:
diff changeset
1801 Temporary_statement*, Temporary_statement*,
kono
parents:
diff changeset
1802 Block**, Expression**, Block**, Block**);
kono
parents:
diff changeset
1803
kono
parents:
diff changeset
1804 void
kono
parents:
diff changeset
1805 lower_range_string(Gogo*, Block*, Block*, Named_object*, Temporary_statement*,
kono
parents:
diff changeset
1806 Temporary_statement*, Temporary_statement*,
kono
parents:
diff changeset
1807 Block**, Expression**, Block**, Block**);
kono
parents:
diff changeset
1808
kono
parents:
diff changeset
1809 void
kono
parents:
diff changeset
1810 lower_range_map(Gogo*, Map_type*, Block*, Block*, Named_object*,
kono
parents:
diff changeset
1811 Temporary_statement*, Temporary_statement*,
kono
parents:
diff changeset
1812 Temporary_statement*, Block**, Expression**, Block**,
kono
parents:
diff changeset
1813 Block**);
kono
parents:
diff changeset
1814
kono
parents:
diff changeset
1815 void
kono
parents:
diff changeset
1816 lower_range_channel(Gogo*, Block*, Block*, Named_object*,
kono
parents:
diff changeset
1817 Temporary_statement*, Temporary_statement*,
kono
parents:
diff changeset
1818 Temporary_statement*, Block**, Expression**, Block**,
kono
parents:
diff changeset
1819 Block**);
kono
parents:
diff changeset
1820
145
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1821 Statement*
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1822 lower_map_range_clear(Type*, Block*, Expression*, Named_object*,
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1823 Temporary_statement*, Location);
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1824
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1825 Statement*
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1826 lower_array_range_clear(Gogo*, Type*, Expression*, Block*,
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1827 Named_object*, Temporary_statement*,
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1828 Location);
1830386684a0 gcc-9.2.0
anatofuz
parents: 131
diff changeset
1829
111
kono
parents:
diff changeset
1830 // The variable which is set to the index value.
kono
parents:
diff changeset
1831 Expression* index_var_;
kono
parents:
diff changeset
1832 // The variable which is set to the element value. This may be
kono
parents:
diff changeset
1833 // NULL.
kono
parents:
diff changeset
1834 Expression* value_var_;
kono
parents:
diff changeset
1835 // The expression we are ranging over.
kono
parents:
diff changeset
1836 Expression* range_;
kono
parents:
diff changeset
1837 // The statements in the block.
kono
parents:
diff changeset
1838 Block* statements_;
kono
parents:
diff changeset
1839 // The break label, if needed.
kono
parents:
diff changeset
1840 Unnamed_label* break_label_;
kono
parents:
diff changeset
1841 // The continue label, if needed.
kono
parents:
diff changeset
1842 Unnamed_label* continue_label_;
kono
parents:
diff changeset
1843 };
kono
parents:
diff changeset
1844
kono
parents:
diff changeset
1845 // Class Case_clauses holds the clauses of a switch statement. This
kono
parents:
diff changeset
1846 // is built by the parser.
kono
parents:
diff changeset
1847
kono
parents:
diff changeset
1848 class Case_clauses
kono
parents:
diff changeset
1849 {
kono
parents:
diff changeset
1850 public:
kono
parents:
diff changeset
1851 Case_clauses()
kono
parents:
diff changeset
1852 : clauses_()
kono
parents:
diff changeset
1853 { }
kono
parents:
diff changeset
1854
kono
parents:
diff changeset
1855 // Add a new clause. CASES is a list of case expressions; it may be
kono
parents:
diff changeset
1856 // NULL. IS_DEFAULT is true if this is the default case.
kono
parents:
diff changeset
1857 // STATEMENTS is a block of statements. IS_FALLTHROUGH is true if
kono
parents:
diff changeset
1858 // after the statements the case clause should fall through to the
kono
parents:
diff changeset
1859 // next clause.
kono
parents:
diff changeset
1860 void
kono
parents:
diff changeset
1861 add(Expression_list* cases, bool is_default, Block* statements,
kono
parents:
diff changeset
1862 bool is_fallthrough, Location location)
kono
parents:
diff changeset
1863 {
kono
parents:
diff changeset
1864 this->clauses_.push_back(Case_clause(cases, is_default, statements,
kono
parents:
diff changeset
1865 is_fallthrough, location));
kono
parents:
diff changeset
1866 }
kono
parents:
diff changeset
1867
kono
parents:
diff changeset
1868 // Return whether there are no clauses.
kono
parents:
diff changeset
1869 bool
kono
parents:
diff changeset
1870 empty() const
kono
parents:
diff changeset
1871 { return this->clauses_.empty(); }
kono
parents:
diff changeset
1872
kono
parents:
diff changeset
1873 // Traverse the case clauses.
kono
parents:
diff changeset
1874 int
kono
parents:
diff changeset
1875 traverse(Traverse*);
kono
parents:
diff changeset
1876
kono
parents:
diff changeset
1877 // Lower for a nonconstant switch.
kono
parents:
diff changeset
1878 void
kono
parents:
diff changeset
1879 lower(Block*, Temporary_statement*, Unnamed_label*) const;
kono
parents:
diff changeset
1880
kono
parents:
diff changeset
1881 // Determine types of expressions. The Type parameter is the type
kono
parents:
diff changeset
1882 // of the switch value.
kono
parents:
diff changeset
1883 void
kono
parents:
diff changeset
1884 determine_types(Type*);
kono
parents:
diff changeset
1885
kono
parents:
diff changeset
1886 // Check types. The Type parameter is the type of the switch value.
kono
parents:
diff changeset
1887 bool
kono
parents:
diff changeset
1888 check_types(Type*);
kono
parents:
diff changeset
1889
kono
parents:
diff changeset
1890 // Return true if all the clauses are constant values.
kono
parents:
diff changeset
1891 bool
kono
parents:
diff changeset
1892 is_constant() const;
kono
parents:
diff changeset
1893
kono
parents:
diff changeset
1894 // Return true if these clauses may fall through to the statements
kono
parents:
diff changeset
1895 // following the switch statement.
kono
parents:
diff changeset
1896 bool
kono
parents:
diff changeset
1897 may_fall_through() const;
kono
parents:
diff changeset
1898
kono
parents:
diff changeset
1899 // Return the body of a SWITCH_EXPR when all the clauses are
kono
parents:
diff changeset
1900 // constants.
kono
parents:
diff changeset
1901 void
kono
parents:
diff changeset
1902 get_backend(Translate_context*, Unnamed_label* break_label,
kono
parents:
diff changeset
1903 std::vector<std::vector<Bexpression*> >* all_cases,
kono
parents:
diff changeset
1904 std::vector<Bstatement*>* all_statements) const;
kono
parents:
diff changeset
1905
kono
parents:
diff changeset
1906 // Dump the AST representation to a dump context.
kono
parents:
diff changeset
1907 void
kono
parents:
diff changeset
1908 dump_clauses(Ast_dump_context*) const;
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1909
111
kono
parents:
diff changeset
1910 private:
kono
parents:
diff changeset
1911 // For a constant switch we need to keep a record of constants we
kono
parents:
diff changeset
1912 // have already seen.
kono
parents:
diff changeset
1913 class Hash_integer_value;
kono
parents:
diff changeset
1914 class Eq_integer_value;
kono
parents:
diff changeset
1915 typedef Unordered_set_hash(Expression*, Hash_integer_value,
kono
parents:
diff changeset
1916 Eq_integer_value) Case_constants;
kono
parents:
diff changeset
1917
kono
parents:
diff changeset
1918 // One case clause.
kono
parents:
diff changeset
1919 class Case_clause
kono
parents:
diff changeset
1920 {
kono
parents:
diff changeset
1921 public:
kono
parents:
diff changeset
1922 Case_clause()
kono
parents:
diff changeset
1923 : cases_(NULL), statements_(NULL), is_default_(false),
kono
parents:
diff changeset
1924 is_fallthrough_(false), location_(Linemap::unknown_location())
kono
parents:
diff changeset
1925 { }
kono
parents:
diff changeset
1926
kono
parents:
diff changeset
1927 Case_clause(Expression_list* cases, bool is_default, Block* statements,
kono
parents:
diff changeset
1928 bool is_fallthrough, Location location)
kono
parents:
diff changeset
1929 : cases_(cases), statements_(statements), is_default_(is_default),
kono
parents:
diff changeset
1930 is_fallthrough_(is_fallthrough), location_(location)
kono
parents:
diff changeset
1931 { }
kono
parents:
diff changeset
1932
kono
parents:
diff changeset
1933 // Whether this clause falls through to the next clause.
kono
parents:
diff changeset
1934 bool
kono
parents:
diff changeset
1935 is_fallthrough() const
kono
parents:
diff changeset
1936 { return this->is_fallthrough_; }
kono
parents:
diff changeset
1937
kono
parents:
diff changeset
1938 // Whether this is the default.
kono
parents:
diff changeset
1939 bool
kono
parents:
diff changeset
1940 is_default() const
kono
parents:
diff changeset
1941 { return this->is_default_; }
kono
parents:
diff changeset
1942
kono
parents:
diff changeset
1943 // The location of this clause.
kono
parents:
diff changeset
1944 Location
kono
parents:
diff changeset
1945 location() const
kono
parents:
diff changeset
1946 { return this->location_; }
kono
parents:
diff changeset
1947
kono
parents:
diff changeset
1948 // Traversal.
kono
parents:
diff changeset
1949 int
kono
parents:
diff changeset
1950 traverse(Traverse*);
kono
parents:
diff changeset
1951
kono
parents:
diff changeset
1952 // Lower for a nonconstant switch.
kono
parents:
diff changeset
1953 void
kono
parents:
diff changeset
1954 lower(Block*, Temporary_statement*, Unnamed_label*, Unnamed_label*) const;
kono
parents:
diff changeset
1955
kono
parents:
diff changeset
1956 // Determine types.
kono
parents:
diff changeset
1957 void
kono
parents:
diff changeset
1958 determine_types(Type*);
kono
parents:
diff changeset
1959
kono
parents:
diff changeset
1960 // Check types.
kono
parents:
diff changeset
1961 bool
kono
parents:
diff changeset
1962 check_types(Type*);
kono
parents:
diff changeset
1963
kono
parents:
diff changeset
1964 // Return true if all the case expressions are constant.
kono
parents:
diff changeset
1965 bool
kono
parents:
diff changeset
1966 is_constant() const;
kono
parents:
diff changeset
1967
kono
parents:
diff changeset
1968 // Return true if this clause may fall through to execute the
kono
parents:
diff changeset
1969 // statements following the switch statement. This is not the
kono
parents:
diff changeset
1970 // same as whether this clause falls through to the next clause.
kono
parents:
diff changeset
1971 bool
kono
parents:
diff changeset
1972 may_fall_through() const;
kono
parents:
diff changeset
1973
kono
parents:
diff changeset
1974 // Convert the case values and statements to the backend
kono
parents:
diff changeset
1975 // representation.
kono
parents:
diff changeset
1976 Bstatement*
kono
parents:
diff changeset
1977 get_backend(Translate_context*, Unnamed_label* break_label,
kono
parents:
diff changeset
1978 Case_constants*, std::vector<Bexpression*>* cases) const;
kono
parents:
diff changeset
1979
kono
parents:
diff changeset
1980 // Dump the AST representation to a dump context.
kono
parents:
diff changeset
1981 void
kono
parents:
diff changeset
1982 dump_clause(Ast_dump_context*) const;
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1983
111
kono
parents:
diff changeset
1984 private:
kono
parents:
diff changeset
1985 // The list of case expressions.
kono
parents:
diff changeset
1986 Expression_list* cases_;
kono
parents:
diff changeset
1987 // The statements to execute.
kono
parents:
diff changeset
1988 Block* statements_;
kono
parents:
diff changeset
1989 // Whether this is the default case.
kono
parents:
diff changeset
1990 bool is_default_;
kono
parents:
diff changeset
1991 // Whether this falls through after the statements.
kono
parents:
diff changeset
1992 bool is_fallthrough_;
kono
parents:
diff changeset
1993 // The location of this case clause.
kono
parents:
diff changeset
1994 Location location_;
kono
parents:
diff changeset
1995 };
kono
parents:
diff changeset
1996
kono
parents:
diff changeset
1997 friend class Case_clause;
kono
parents:
diff changeset
1998
kono
parents:
diff changeset
1999 // The type of the list of clauses.
kono
parents:
diff changeset
2000 typedef std::vector<Case_clause> Clauses;
kono
parents:
diff changeset
2001
kono
parents:
diff changeset
2002 // All the case clauses.
kono
parents:
diff changeset
2003 Clauses clauses_;
kono
parents:
diff changeset
2004 };
kono
parents:
diff changeset
2005
kono
parents:
diff changeset
2006 // A switch statement.
kono
parents:
diff changeset
2007
kono
parents:
diff changeset
2008 class Switch_statement : public Statement
kono
parents:
diff changeset
2009 {
kono
parents:
diff changeset
2010 public:
kono
parents:
diff changeset
2011 Switch_statement(Expression* val, Location location)
kono
parents:
diff changeset
2012 : Statement(STATEMENT_SWITCH, location),
kono
parents:
diff changeset
2013 val_(val), clauses_(NULL), break_label_(NULL)
kono
parents:
diff changeset
2014 { }
kono
parents:
diff changeset
2015
kono
parents:
diff changeset
2016 // Add the clauses.
kono
parents:
diff changeset
2017 void
kono
parents:
diff changeset
2018 add_clauses(Case_clauses* clauses)
kono
parents:
diff changeset
2019 {
kono
parents:
diff changeset
2020 go_assert(this->clauses_ == NULL);
kono
parents:
diff changeset
2021 this->clauses_ = clauses;
kono
parents:
diff changeset
2022 }
kono
parents:
diff changeset
2023
kono
parents:
diff changeset
2024 // Return the break label for this switch statement.
kono
parents:
diff changeset
2025 Unnamed_label*
kono
parents:
diff changeset
2026 break_label();
kono
parents:
diff changeset
2027
kono
parents:
diff changeset
2028 protected:
kono
parents:
diff changeset
2029 int
kono
parents:
diff changeset
2030 do_traverse(Traverse*);
kono
parents:
diff changeset
2031
kono
parents:
diff changeset
2032 Statement*
kono
parents:
diff changeset
2033 do_lower(Gogo*, Named_object*, Block*, Statement_inserter*);
kono
parents:
diff changeset
2034
kono
parents:
diff changeset
2035 Bstatement*
kono
parents:
diff changeset
2036 do_get_backend(Translate_context*)
kono
parents:
diff changeset
2037 { go_unreachable(); }
kono
parents:
diff changeset
2038
kono
parents:
diff changeset
2039 void
kono
parents:
diff changeset
2040 do_dump_statement(Ast_dump_context*) const;
kono
parents:
diff changeset
2041
kono
parents:
diff changeset
2042 bool
kono
parents:
diff changeset
2043 do_may_fall_through() const;
kono
parents:
diff changeset
2044
kono
parents:
diff changeset
2045 private:
kono
parents:
diff changeset
2046 // The value to switch on. This may be NULL.
kono
parents:
diff changeset
2047 Expression* val_;
kono
parents:
diff changeset
2048 // The case clauses.
kono
parents:
diff changeset
2049 Case_clauses* clauses_;
kono
parents:
diff changeset
2050 // The break label, if needed.
kono
parents:
diff changeset
2051 Unnamed_label* break_label_;
kono
parents:
diff changeset
2052 };
kono
parents:
diff changeset
2053
kono
parents:
diff changeset
2054 // Class Type_case_clauses holds the clauses of a type switch
kono
parents:
diff changeset
2055 // statement. This is built by the parser.
kono
parents:
diff changeset
2056
kono
parents:
diff changeset
2057 class Type_case_clauses
kono
parents:
diff changeset
2058 {
kono
parents:
diff changeset
2059 public:
kono
parents:
diff changeset
2060 Type_case_clauses()
kono
parents:
diff changeset
2061 : clauses_()
kono
parents:
diff changeset
2062 { }
kono
parents:
diff changeset
2063
kono
parents:
diff changeset
2064 // Add a new clause. TYPE is the type for this clause; it may be
kono
parents:
diff changeset
2065 // NULL. IS_FALLTHROUGH is true if this falls through to the next
kono
parents:
diff changeset
2066 // clause; in this case STATEMENTS will be NULL. IS_DEFAULT is true
kono
parents:
diff changeset
2067 // if this is the default case. STATEMENTS is a block of
kono
parents:
diff changeset
2068 // statements; it may be NULL.
kono
parents:
diff changeset
2069 void
kono
parents:
diff changeset
2070 add(Type* type, bool is_fallthrough, bool is_default, Block* statements,
kono
parents:
diff changeset
2071 Location location)
kono
parents:
diff changeset
2072 {
kono
parents:
diff changeset
2073 this->clauses_.push_back(Type_case_clause(type, is_fallthrough, is_default,
kono
parents:
diff changeset
2074 statements, location));
kono
parents:
diff changeset
2075 }
kono
parents:
diff changeset
2076
kono
parents:
diff changeset
2077 // Return whether there are no clauses.
kono
parents:
diff changeset
2078 bool
kono
parents:
diff changeset
2079 empty() const
kono
parents:
diff changeset
2080 { return this->clauses_.empty(); }
kono
parents:
diff changeset
2081
kono
parents:
diff changeset
2082 // Traverse the type case clauses.
kono
parents:
diff changeset
2083 int
kono
parents:
diff changeset
2084 traverse(Traverse*);
kono
parents:
diff changeset
2085
kono
parents:
diff changeset
2086 // Check for duplicates.
kono
parents:
diff changeset
2087 void
kono
parents:
diff changeset
2088 check_duplicates() const;
kono
parents:
diff changeset
2089
kono
parents:
diff changeset
2090 // Lower to if and goto statements.
kono
parents:
diff changeset
2091 void
kono
parents:
diff changeset
2092 lower(Type*, Block*, Temporary_statement* descriptor_temp,
kono
parents:
diff changeset
2093 Unnamed_label* break_label) const;
kono
parents:
diff changeset
2094
kono
parents:
diff changeset
2095 // Return true if these clauses may fall through to the statements
kono
parents:
diff changeset
2096 // following the switch statement.
kono
parents:
diff changeset
2097 bool
kono
parents:
diff changeset
2098 may_fall_through() const;
kono
parents:
diff changeset
2099
kono
parents:
diff changeset
2100 // Dump the AST representation to a dump context.
kono
parents:
diff changeset
2101 void
kono
parents:
diff changeset
2102 dump_clauses(Ast_dump_context*) const;
kono
parents:
diff changeset
2103
kono
parents:
diff changeset
2104 private:
kono
parents:
diff changeset
2105 // One type case clause.
kono
parents:
diff changeset
2106 class Type_case_clause
kono
parents:
diff changeset
2107 {
kono
parents:
diff changeset
2108 public:
kono
parents:
diff changeset
2109 Type_case_clause()
kono
parents:
diff changeset
2110 : type_(NULL), statements_(NULL), is_default_(false),
kono
parents:
diff changeset
2111 location_(Linemap::unknown_location())
kono
parents:
diff changeset
2112 { }
kono
parents:
diff changeset
2113
kono
parents:
diff changeset
2114 Type_case_clause(Type* type, bool is_fallthrough, bool is_default,
kono
parents:
diff changeset
2115 Block* statements, Location location)
kono
parents:
diff changeset
2116 : type_(type), statements_(statements), is_fallthrough_(is_fallthrough),
kono
parents:
diff changeset
2117 is_default_(is_default), location_(location)
kono
parents:
diff changeset
2118 { }
kono
parents:
diff changeset
2119
kono
parents:
diff changeset
2120 // The type.
kono
parents:
diff changeset
2121 Type*
kono
parents:
diff changeset
2122 type() const
kono
parents:
diff changeset
2123 { return this->type_; }
kono
parents:
diff changeset
2124
kono
parents:
diff changeset
2125 // Whether this is the default.
kono
parents:
diff changeset
2126 bool
kono
parents:
diff changeset
2127 is_default() const
kono
parents:
diff changeset
2128 { return this->is_default_; }
kono
parents:
diff changeset
2129
kono
parents:
diff changeset
2130 // The location of this type clause.
kono
parents:
diff changeset
2131 Location
kono
parents:
diff changeset
2132 location() const
kono
parents:
diff changeset
2133 { return this->location_; }
kono
parents:
diff changeset
2134
kono
parents:
diff changeset
2135 // Traversal.
kono
parents:
diff changeset
2136 int
kono
parents:
diff changeset
2137 traverse(Traverse*);
kono
parents:
diff changeset
2138
kono
parents:
diff changeset
2139 // Lower to if and goto statements.
kono
parents:
diff changeset
2140 void
kono
parents:
diff changeset
2141 lower(Type*, Block*, Temporary_statement* descriptor_temp,
kono
parents:
diff changeset
2142 Unnamed_label* break_label, Unnamed_label** stmts_label) const;
kono
parents:
diff changeset
2143
kono
parents:
diff changeset
2144 // Return true if this clause may fall through to execute the
kono
parents:
diff changeset
2145 // statements following the switch statement. This is not the
kono
parents:
diff changeset
2146 // same as whether this clause falls through to the next clause.
kono
parents:
diff changeset
2147 bool
kono
parents:
diff changeset
2148 may_fall_through() const;
kono
parents:
diff changeset
2149
kono
parents:
diff changeset
2150 // Dump the AST representation to a dump context.
kono
parents:
diff changeset
2151 void
kono
parents:
diff changeset
2152 dump_clause(Ast_dump_context*) const;
kono
parents:
diff changeset
2153
kono
parents:
diff changeset
2154 private:
kono
parents:
diff changeset
2155 // The type for this type clause.
kono
parents:
diff changeset
2156 Type* type_;
kono
parents:
diff changeset
2157 // The statements to execute.
kono
parents:
diff changeset
2158 Block* statements_;
kono
parents:
diff changeset
2159 // Whether this falls through--this is true for "case T1, T2".
kono
parents:
diff changeset
2160 bool is_fallthrough_;
kono
parents:
diff changeset
2161 // Whether this is the default case.
kono
parents:
diff changeset
2162 bool is_default_;
kono
parents:
diff changeset
2163 // The location of this type case clause.
kono
parents:
diff changeset
2164 Location location_;
kono
parents:
diff changeset
2165 };
kono
parents:
diff changeset
2166
kono
parents:
diff changeset
2167 friend class Type_case_clause;
kono
parents:
diff changeset
2168
kono
parents:
diff changeset
2169 // The type of the list of type clauses.
kono
parents:
diff changeset
2170 typedef std::vector<Type_case_clause> Type_clauses;
kono
parents:
diff changeset
2171
kono
parents:
diff changeset
2172 // All the type case clauses.
kono
parents:
diff changeset
2173 Type_clauses clauses_;
kono
parents:
diff changeset
2174 };
kono
parents:
diff changeset
2175
kono
parents:
diff changeset
2176 // A type switch statement.
kono
parents:
diff changeset
2177
kono
parents:
diff changeset
2178 class Type_switch_statement : public Statement
kono
parents:
diff changeset
2179 {
kono
parents:
diff changeset
2180 public:
kono
parents:
diff changeset
2181 Type_switch_statement(const std::string& name, Expression* expr,
kono
parents:
diff changeset
2182 Location location)
kono
parents:
diff changeset
2183 : Statement(STATEMENT_TYPE_SWITCH, location),
kono
parents:
diff changeset
2184 name_(name), expr_(expr), clauses_(NULL), break_label_(NULL)
kono
parents:
diff changeset
2185 { }
kono
parents:
diff changeset
2186
kono
parents:
diff changeset
2187 // Add the clauses.
kono
parents:
diff changeset
2188 void
kono
parents:
diff changeset
2189 add_clauses(Type_case_clauses* clauses)
kono
parents:
diff changeset
2190 {
kono
parents:
diff changeset
2191 go_assert(this->clauses_ == NULL);
kono
parents:
diff changeset
2192 this->clauses_ = clauses;
kono
parents:
diff changeset
2193 }
kono
parents:
diff changeset
2194
kono
parents:
diff changeset
2195 // Return the break label for this type switch statement.
kono
parents:
diff changeset
2196 Unnamed_label*
kono
parents:
diff changeset
2197 break_label();
kono
parents:
diff changeset
2198
kono
parents:
diff changeset
2199 protected:
kono
parents:
diff changeset
2200 int
kono
parents:
diff changeset
2201 do_traverse(Traverse*);
kono
parents:
diff changeset
2202
kono
parents:
diff changeset
2203 Statement*
kono
parents:
diff changeset
2204 do_lower(Gogo*, Named_object*, Block*, Statement_inserter*);
kono
parents:
diff changeset
2205
kono
parents:
diff changeset
2206 Bstatement*
kono
parents:
diff changeset
2207 do_get_backend(Translate_context*)
kono
parents:
diff changeset
2208 { go_unreachable(); }
kono
parents:
diff changeset
2209
kono
parents:
diff changeset
2210 void
kono
parents:
diff changeset
2211 do_dump_statement(Ast_dump_context*) const;
kono
parents:
diff changeset
2212
kono
parents:
diff changeset
2213 bool
kono
parents:
diff changeset
2214 do_may_fall_through() const;
kono
parents:
diff changeset
2215
kono
parents:
diff changeset
2216 private:
kono
parents:
diff changeset
2217 // The name of the variable declared in the type switch guard. Empty if there
kono
parents:
diff changeset
2218 // is no variable declared.
kono
parents:
diff changeset
2219 std::string name_;
kono
parents:
diff changeset
2220 // The expression we are switching on if there is no variable.
kono
parents:
diff changeset
2221 Expression* expr_;
kono
parents:
diff changeset
2222 // The type case clauses.
kono
parents:
diff changeset
2223 Type_case_clauses* clauses_;
kono
parents:
diff changeset
2224 // The break label, if needed.
kono
parents:
diff changeset
2225 Unnamed_label* break_label_;
kono
parents:
diff changeset
2226 };
kono
parents:
diff changeset
2227
kono
parents:
diff changeset
2228 #endif // !defined(GO_STATEMENTS_H)