annotate gcc/go/gofrontend/types.h @ 131:84e7813d76e9

gcc-8.2
author mir3636
date Thu, 25 Oct 2018 07:37:49 +0900
parents 04ced10e8804
children 1830386684a0
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
111
kono
parents:
diff changeset
1 // types.h -- Go frontend types. -*- 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_TYPES_H
kono
parents:
diff changeset
8 #define GO_TYPES_H
kono
parents:
diff changeset
9
kono
parents:
diff changeset
10 #include <ostream>
kono
parents:
diff changeset
11
kono
parents:
diff changeset
12 #include "go-linemap.h"
kono
parents:
diff changeset
13 #include "escape.h"
kono
parents:
diff changeset
14
kono
parents:
diff changeset
15 class Gogo;
kono
parents:
diff changeset
16 class Package;
kono
parents:
diff changeset
17 class Variable;
kono
parents:
diff changeset
18 class Traverse;
kono
parents:
diff changeset
19 class Typed_identifier;
kono
parents:
diff changeset
20 class Typed_identifier_list;
kono
parents:
diff changeset
21 class Integer_type;
kono
parents:
diff changeset
22 class Float_type;
kono
parents:
diff changeset
23 class Complex_type;
kono
parents:
diff changeset
24 class String_type;
kono
parents:
diff changeset
25 class Function_type;
kono
parents:
diff changeset
26 class Backend_function_type;
kono
parents:
diff changeset
27 class Struct_field;
kono
parents:
diff changeset
28 class Struct_field_list;
kono
parents:
diff changeset
29 class Struct_type;
kono
parents:
diff changeset
30 class Pointer_type;
kono
parents:
diff changeset
31 class Array_type;
kono
parents:
diff changeset
32 class Map_type;
kono
parents:
diff changeset
33 class Channel_type;
kono
parents:
diff changeset
34 class Interface_type;
kono
parents:
diff changeset
35 class Named_type;
kono
parents:
diff changeset
36 class Forward_declaration_type;
kono
parents:
diff changeset
37 class Method;
kono
parents:
diff changeset
38 class Methods;
kono
parents:
diff changeset
39 class Type_hash_identical;
kono
parents:
diff changeset
40 class Type_identical;
kono
parents:
diff changeset
41 class Expression;
kono
parents:
diff changeset
42 class Expression_list;
kono
parents:
diff changeset
43 class Call_expression;
kono
parents:
diff changeset
44 class Field_reference_expression;
kono
parents:
diff changeset
45 class Bound_method_expression;
kono
parents:
diff changeset
46 class Bindings;
kono
parents:
diff changeset
47 class Named_object;
kono
parents:
diff changeset
48 class Function;
kono
parents:
diff changeset
49 class Translate_context;
kono
parents:
diff changeset
50 class Export;
kono
parents:
diff changeset
51 class Import;
kono
parents:
diff changeset
52 class Btype;
kono
parents:
diff changeset
53 class Bexpression;
kono
parents:
diff changeset
54 class Bvariable;
kono
parents:
diff changeset
55
kono
parents:
diff changeset
56 // Type codes used in type descriptors. These must match the values
kono
parents:
diff changeset
57 // in libgo/runtime/go-type.h. They also match the values in the gc
kono
parents:
diff changeset
58 // compiler in src/cmd/gc/reflect.c and src/pkg/runtime/type.go,
kono
parents:
diff changeset
59 // although this is not required.
kono
parents:
diff changeset
60
kono
parents:
diff changeset
61 static const int RUNTIME_TYPE_KIND_BOOL = 1;
kono
parents:
diff changeset
62 static const int RUNTIME_TYPE_KIND_INT = 2;
kono
parents:
diff changeset
63 static const int RUNTIME_TYPE_KIND_INT8 = 3;
kono
parents:
diff changeset
64 static const int RUNTIME_TYPE_KIND_INT16 = 4;
kono
parents:
diff changeset
65 static const int RUNTIME_TYPE_KIND_INT32 = 5;
kono
parents:
diff changeset
66 static const int RUNTIME_TYPE_KIND_INT64 = 6;
kono
parents:
diff changeset
67 static const int RUNTIME_TYPE_KIND_UINT = 7;
kono
parents:
diff changeset
68 static const int RUNTIME_TYPE_KIND_UINT8 = 8;
kono
parents:
diff changeset
69 static const int RUNTIME_TYPE_KIND_UINT16 = 9;
kono
parents:
diff changeset
70 static const int RUNTIME_TYPE_KIND_UINT32 = 10;
kono
parents:
diff changeset
71 static const int RUNTIME_TYPE_KIND_UINT64 = 11;
kono
parents:
diff changeset
72 static const int RUNTIME_TYPE_KIND_UINTPTR = 12;
kono
parents:
diff changeset
73 static const int RUNTIME_TYPE_KIND_FLOAT32 = 13;
kono
parents:
diff changeset
74 static const int RUNTIME_TYPE_KIND_FLOAT64 = 14;
kono
parents:
diff changeset
75 static const int RUNTIME_TYPE_KIND_COMPLEX64 = 15;
kono
parents:
diff changeset
76 static const int RUNTIME_TYPE_KIND_COMPLEX128 = 16;
kono
parents:
diff changeset
77 static const int RUNTIME_TYPE_KIND_ARRAY = 17;
kono
parents:
diff changeset
78 static const int RUNTIME_TYPE_KIND_CHAN = 18;
kono
parents:
diff changeset
79 static const int RUNTIME_TYPE_KIND_FUNC = 19;
kono
parents:
diff changeset
80 static const int RUNTIME_TYPE_KIND_INTERFACE = 20;
kono
parents:
diff changeset
81 static const int RUNTIME_TYPE_KIND_MAP = 21;
kono
parents:
diff changeset
82 static const int RUNTIME_TYPE_KIND_PTR = 22;
kono
parents:
diff changeset
83 static const int RUNTIME_TYPE_KIND_SLICE = 23;
kono
parents:
diff changeset
84 static const int RUNTIME_TYPE_KIND_STRING = 24;
kono
parents:
diff changeset
85 static const int RUNTIME_TYPE_KIND_STRUCT = 25;
kono
parents:
diff changeset
86 static const int RUNTIME_TYPE_KIND_UNSAFE_POINTER = 26;
kono
parents:
diff changeset
87
kono
parents:
diff changeset
88 static const int RUNTIME_TYPE_KIND_DIRECT_IFACE = (1 << 5);
kono
parents:
diff changeset
89 static const int RUNTIME_TYPE_KIND_GC_PROG = (1 << 6);
kono
parents:
diff changeset
90 static const int RUNTIME_TYPE_KIND_NO_POINTERS = (1 << 7);
kono
parents:
diff changeset
91
kono
parents:
diff changeset
92 // To build the complete list of methods for a named type we need to
kono
parents:
diff changeset
93 // gather all methods from anonymous fields. Those methods may
kono
parents:
diff changeset
94 // require an arbitrary set of indirections and field offsets. There
kono
parents:
diff changeset
95 // is also the possibility of ambiguous methods, which we could ignore
kono
parents:
diff changeset
96 // except that we want to give a better error message for that case.
kono
parents:
diff changeset
97 // This is a base class. There are two types of methods: named
kono
parents:
diff changeset
98 // methods, and methods which are inherited from an anonymous field of
kono
parents:
diff changeset
99 // interface type.
kono
parents:
diff changeset
100
kono
parents:
diff changeset
101 class Method
kono
parents:
diff changeset
102 {
kono
parents:
diff changeset
103 public:
kono
parents:
diff changeset
104 // For methods in anonymous types we need to know the sequence of
kono
parents:
diff changeset
105 // field references used to extract the pointer to pass to the
kono
parents:
diff changeset
106 // method. Since each method for a particular anonymous field will
kono
parents:
diff changeset
107 // have the sequence of field indexes, and since the indexes can be
kono
parents:
diff changeset
108 // shared going down the chain, we use a manually managed linked
kono
parents:
diff changeset
109 // list. The first entry in the list is the field index for the
kono
parents:
diff changeset
110 // last field, the one passed to the method.
kono
parents:
diff changeset
111
kono
parents:
diff changeset
112 struct Field_indexes
kono
parents:
diff changeset
113 {
kono
parents:
diff changeset
114 const Field_indexes* next;
kono
parents:
diff changeset
115 unsigned int field_index;
kono
parents:
diff changeset
116 };
kono
parents:
diff changeset
117
kono
parents:
diff changeset
118 virtual ~Method()
kono
parents:
diff changeset
119 { }
kono
parents:
diff changeset
120
kono
parents:
diff changeset
121 // Get the list of field indexes.
kono
parents:
diff changeset
122 const Field_indexes*
kono
parents:
diff changeset
123 field_indexes() const
kono
parents:
diff changeset
124 { return this->field_indexes_; }
kono
parents:
diff changeset
125
kono
parents:
diff changeset
126 // Get the depth.
kono
parents:
diff changeset
127 unsigned int
kono
parents:
diff changeset
128 depth() const
kono
parents:
diff changeset
129 { return this->depth_; }
kono
parents:
diff changeset
130
kono
parents:
diff changeset
131 // Return whether this is a value method--a method which does not
kono
parents:
diff changeset
132 // require a pointer expression.
kono
parents:
diff changeset
133 bool
kono
parents:
diff changeset
134 is_value_method() const
kono
parents:
diff changeset
135 { return this->is_value_method_; }
kono
parents:
diff changeset
136
kono
parents:
diff changeset
137 // Return whether we need a stub method--this is true if we can't
kono
parents:
diff changeset
138 // just pass the main object to the method.
kono
parents:
diff changeset
139 bool
kono
parents:
diff changeset
140 needs_stub_method() const
kono
parents:
diff changeset
141 { return this->needs_stub_method_; }
kono
parents:
diff changeset
142
kono
parents:
diff changeset
143 // Return whether this is an ambiguous method name.
kono
parents:
diff changeset
144 bool
kono
parents:
diff changeset
145 is_ambiguous() const
kono
parents:
diff changeset
146 { return this->is_ambiguous_; }
kono
parents:
diff changeset
147
kono
parents:
diff changeset
148 // Note that this method is ambiguous.
kono
parents:
diff changeset
149 void
kono
parents:
diff changeset
150 set_is_ambiguous()
kono
parents:
diff changeset
151 { this->is_ambiguous_ = true; }
kono
parents:
diff changeset
152
kono
parents:
diff changeset
153 // Return the type of the method.
kono
parents:
diff changeset
154 Function_type*
kono
parents:
diff changeset
155 type() const
kono
parents:
diff changeset
156 { return this->do_type(); }
kono
parents:
diff changeset
157
kono
parents:
diff changeset
158 // Return the location of the method receiver.
kono
parents:
diff changeset
159 Location
kono
parents:
diff changeset
160 receiver_location() const
kono
parents:
diff changeset
161 { return this->do_receiver_location(); }
kono
parents:
diff changeset
162
kono
parents:
diff changeset
163 // Return an expression which binds this method to EXPR. This is
kono
parents:
diff changeset
164 // something which can be used with a function call.
kono
parents:
diff changeset
165 Expression*
kono
parents:
diff changeset
166 bind_method(Expression* expr, Location location) const;
kono
parents:
diff changeset
167
kono
parents:
diff changeset
168 // Return the named object for this method. This may only be called
kono
parents:
diff changeset
169 // after methods are finalized.
kono
parents:
diff changeset
170 Named_object*
kono
parents:
diff changeset
171 named_object() const;
kono
parents:
diff changeset
172
kono
parents:
diff changeset
173 // Get the stub object.
kono
parents:
diff changeset
174 Named_object*
kono
parents:
diff changeset
175 stub_object() const
kono
parents:
diff changeset
176 {
kono
parents:
diff changeset
177 go_assert(this->stub_ != NULL);
kono
parents:
diff changeset
178 return this->stub_;
kono
parents:
diff changeset
179 }
kono
parents:
diff changeset
180
kono
parents:
diff changeset
181 // Set the stub object.
kono
parents:
diff changeset
182 void
kono
parents:
diff changeset
183 set_stub_object(Named_object* no)
kono
parents:
diff changeset
184 {
kono
parents:
diff changeset
185 go_assert(this->stub_ == NULL);
kono
parents:
diff changeset
186 this->stub_ = no;
kono
parents:
diff changeset
187 }
kono
parents:
diff changeset
188
kono
parents:
diff changeset
189 // Return true if this method should not participate in any
kono
parents:
diff changeset
190 // interfaces.
kono
parents:
diff changeset
191 bool
kono
parents:
diff changeset
192 nointerface() const
kono
parents:
diff changeset
193 { return this->do_nointerface(); }
kono
parents:
diff changeset
194
kono
parents:
diff changeset
195 protected:
kono
parents:
diff changeset
196 // These objects are only built by the child classes.
kono
parents:
diff changeset
197 Method(const Field_indexes* field_indexes, unsigned int depth,
kono
parents:
diff changeset
198 bool is_value_method, bool needs_stub_method)
kono
parents:
diff changeset
199 : field_indexes_(field_indexes), depth_(depth), stub_(NULL),
kono
parents:
diff changeset
200 is_value_method_(is_value_method), needs_stub_method_(needs_stub_method),
kono
parents:
diff changeset
201 is_ambiguous_(false)
kono
parents:
diff changeset
202 { }
kono
parents:
diff changeset
203
kono
parents:
diff changeset
204 // The named object for this method.
kono
parents:
diff changeset
205 virtual Named_object*
kono
parents:
diff changeset
206 do_named_object() const = 0;
kono
parents:
diff changeset
207
kono
parents:
diff changeset
208 // The type of the method.
kono
parents:
diff changeset
209 virtual Function_type*
kono
parents:
diff changeset
210 do_type() const = 0;
kono
parents:
diff changeset
211
kono
parents:
diff changeset
212 // Return the location of the method receiver.
kono
parents:
diff changeset
213 virtual Location
kono
parents:
diff changeset
214 do_receiver_location() const = 0;
kono
parents:
diff changeset
215
kono
parents:
diff changeset
216 // Bind a method to an object.
kono
parents:
diff changeset
217 virtual Expression*
kono
parents:
diff changeset
218 do_bind_method(Expression* expr, Location location) const = 0;
kono
parents:
diff changeset
219
kono
parents:
diff changeset
220 // Return whether this method should not participate in interfaces.
kono
parents:
diff changeset
221 virtual bool
kono
parents:
diff changeset
222 do_nointerface() const = 0;
kono
parents:
diff changeset
223
kono
parents:
diff changeset
224 private:
kono
parents:
diff changeset
225 // The sequence of field indexes used for this method. If this is
kono
parents:
diff changeset
226 // NULL, then the method is defined for the current type.
kono
parents:
diff changeset
227 const Field_indexes* field_indexes_;
kono
parents:
diff changeset
228 // The depth at which this method was found.
kono
parents:
diff changeset
229 unsigned int depth_;
kono
parents:
diff changeset
230 // If a stub method is required, this is its object. This is only
kono
parents:
diff changeset
231 // set after stub methods are built in finalize_methods.
kono
parents:
diff changeset
232 Named_object* stub_;
kono
parents:
diff changeset
233 // Whether this is a value method--a method that does not require a
kono
parents:
diff changeset
234 // pointer.
kono
parents:
diff changeset
235 bool is_value_method_;
kono
parents:
diff changeset
236 // Whether a stub method is required.
kono
parents:
diff changeset
237 bool needs_stub_method_;
kono
parents:
diff changeset
238 // Whether this method is ambiguous.
kono
parents:
diff changeset
239 bool is_ambiguous_;
kono
parents:
diff changeset
240 };
kono
parents:
diff changeset
241
kono
parents:
diff changeset
242 // A named method. This is what you get with a method declaration,
kono
parents:
diff changeset
243 // either directly on the type, or inherited from some anonymous
kono
parents:
diff changeset
244 // embedded field.
kono
parents:
diff changeset
245
kono
parents:
diff changeset
246 class Named_method : public Method
kono
parents:
diff changeset
247 {
kono
parents:
diff changeset
248 public:
kono
parents:
diff changeset
249 Named_method(Named_object* named_object, const Field_indexes* field_indexes,
kono
parents:
diff changeset
250 unsigned int depth, bool is_value_method,
kono
parents:
diff changeset
251 bool needs_stub_method)
kono
parents:
diff changeset
252 : Method(field_indexes, depth, is_value_method, needs_stub_method),
kono
parents:
diff changeset
253 named_object_(named_object)
kono
parents:
diff changeset
254 { }
kono
parents:
diff changeset
255
kono
parents:
diff changeset
256 protected:
kono
parents:
diff changeset
257 // Get the Named_object for the method.
kono
parents:
diff changeset
258 Named_object*
kono
parents:
diff changeset
259 do_named_object() const
kono
parents:
diff changeset
260 { return this->named_object_; }
kono
parents:
diff changeset
261
kono
parents:
diff changeset
262 // The type of the method.
kono
parents:
diff changeset
263 Function_type*
kono
parents:
diff changeset
264 do_type() const;
kono
parents:
diff changeset
265
kono
parents:
diff changeset
266 // Return the location of the method receiver.
kono
parents:
diff changeset
267 Location
kono
parents:
diff changeset
268 do_receiver_location() const;
kono
parents:
diff changeset
269
kono
parents:
diff changeset
270 // Bind a method to an object.
kono
parents:
diff changeset
271 Expression*
kono
parents:
diff changeset
272 do_bind_method(Expression* expr, Location location) const;
kono
parents:
diff changeset
273
kono
parents:
diff changeset
274 // Return whether this method should not participate in interfaces.
kono
parents:
diff changeset
275 bool
kono
parents:
diff changeset
276 do_nointerface() const;
kono
parents:
diff changeset
277
kono
parents:
diff changeset
278 private:
kono
parents:
diff changeset
279 // The method itself. For a method which needs a stub, this starts
kono
parents:
diff changeset
280 // out as the underlying method, and is later replaced with the stub
kono
parents:
diff changeset
281 // method.
kono
parents:
diff changeset
282 Named_object* named_object_;
kono
parents:
diff changeset
283 };
kono
parents:
diff changeset
284
kono
parents:
diff changeset
285 // An interface method. This is used when an interface appears as an
kono
parents:
diff changeset
286 // anonymous field in a named struct.
kono
parents:
diff changeset
287
kono
parents:
diff changeset
288 class Interface_method : public Method
kono
parents:
diff changeset
289 {
kono
parents:
diff changeset
290 public:
kono
parents:
diff changeset
291 Interface_method(const std::string& name, Location location,
kono
parents:
diff changeset
292 Function_type* fntype, const Field_indexes* field_indexes,
kono
parents:
diff changeset
293 unsigned int depth)
kono
parents:
diff changeset
294 : Method(field_indexes, depth, true, true),
kono
parents:
diff changeset
295 name_(name), location_(location), fntype_(fntype)
kono
parents:
diff changeset
296 { }
kono
parents:
diff changeset
297
kono
parents:
diff changeset
298 protected:
kono
parents:
diff changeset
299 // Get the Named_object for the method. This should never be
kono
parents:
diff changeset
300 // called, as we always create a stub.
kono
parents:
diff changeset
301 Named_object*
kono
parents:
diff changeset
302 do_named_object() const
kono
parents:
diff changeset
303 { go_unreachable(); }
kono
parents:
diff changeset
304
kono
parents:
diff changeset
305 // The type of the method.
kono
parents:
diff changeset
306 Function_type*
kono
parents:
diff changeset
307 do_type() const
kono
parents:
diff changeset
308 { return this->fntype_; }
kono
parents:
diff changeset
309
kono
parents:
diff changeset
310 // Return the location of the method receiver.
kono
parents:
diff changeset
311 Location
kono
parents:
diff changeset
312 do_receiver_location() const
kono
parents:
diff changeset
313 { return this->location_; }
kono
parents:
diff changeset
314
kono
parents:
diff changeset
315 // Bind a method to an object.
kono
parents:
diff changeset
316 Expression*
kono
parents:
diff changeset
317 do_bind_method(Expression* expr, Location location) const;
kono
parents:
diff changeset
318
kono
parents:
diff changeset
319 // Return whether this method should not participate in interfaces.
kono
parents:
diff changeset
320 bool
kono
parents:
diff changeset
321 do_nointerface() const
kono
parents:
diff changeset
322 { return false; }
kono
parents:
diff changeset
323
kono
parents:
diff changeset
324 private:
kono
parents:
diff changeset
325 // The name of the interface method to call.
kono
parents:
diff changeset
326 std::string name_;
kono
parents:
diff changeset
327 // The location of the definition of the interface method.
kono
parents:
diff changeset
328 Location location_;
kono
parents:
diff changeset
329 // The type of the interface method.
kono
parents:
diff changeset
330 Function_type* fntype_;
kono
parents:
diff changeset
331 };
kono
parents:
diff changeset
332
kono
parents:
diff changeset
333 // A mapping from method name to Method. This is a wrapper around a
kono
parents:
diff changeset
334 // hash table.
kono
parents:
diff changeset
335
kono
parents:
diff changeset
336 class Methods
kono
parents:
diff changeset
337 {
kono
parents:
diff changeset
338 private:
kono
parents:
diff changeset
339 typedef Unordered_map(std::string, Method*) Method_map;
kono
parents:
diff changeset
340
kono
parents:
diff changeset
341 public:
kono
parents:
diff changeset
342 typedef Method_map::const_iterator const_iterator;
kono
parents:
diff changeset
343
kono
parents:
diff changeset
344 Methods()
kono
parents:
diff changeset
345 : methods_()
kono
parents:
diff changeset
346 { }
kono
parents:
diff changeset
347
kono
parents:
diff changeset
348 // Insert a new method. Returns true if it was inserted, false if
kono
parents:
diff changeset
349 // it was overidden or ambiguous.
kono
parents:
diff changeset
350 bool
kono
parents:
diff changeset
351 insert(const std::string& name, Method* m);
kono
parents:
diff changeset
352
kono
parents:
diff changeset
353 // The number of (unambiguous) methods.
kono
parents:
diff changeset
354 size_t
kono
parents:
diff changeset
355 count() const;
kono
parents:
diff changeset
356
kono
parents:
diff changeset
357 // Iterate.
kono
parents:
diff changeset
358 const_iterator
kono
parents:
diff changeset
359 begin() const
kono
parents:
diff changeset
360 { return this->methods_.begin(); }
kono
parents:
diff changeset
361
kono
parents:
diff changeset
362 const_iterator
kono
parents:
diff changeset
363 end() const
kono
parents:
diff changeset
364 { return this->methods_.end(); }
kono
parents:
diff changeset
365
kono
parents:
diff changeset
366 // Lookup.
kono
parents:
diff changeset
367 const_iterator
kono
parents:
diff changeset
368 find(const std::string& name) const
kono
parents:
diff changeset
369 { return this->methods_.find(name); }
kono
parents:
diff changeset
370
kono
parents:
diff changeset
371 bool
kono
parents:
diff changeset
372 empty() const
kono
parents:
diff changeset
373 { return this->methods_.empty(); }
kono
parents:
diff changeset
374
kono
parents:
diff changeset
375 private:
kono
parents:
diff changeset
376 Method_map methods_;
kono
parents:
diff changeset
377 };
kono
parents:
diff changeset
378
kono
parents:
diff changeset
379 // The base class for all types.
kono
parents:
diff changeset
380
kono
parents:
diff changeset
381 class Type
kono
parents:
diff changeset
382 {
kono
parents:
diff changeset
383 public:
kono
parents:
diff changeset
384 // The types of types.
kono
parents:
diff changeset
385 enum Type_classification
kono
parents:
diff changeset
386 {
kono
parents:
diff changeset
387 TYPE_ERROR,
kono
parents:
diff changeset
388 TYPE_VOID,
kono
parents:
diff changeset
389 TYPE_BOOLEAN,
kono
parents:
diff changeset
390 TYPE_INTEGER,
kono
parents:
diff changeset
391 TYPE_FLOAT,
kono
parents:
diff changeset
392 TYPE_COMPLEX,
kono
parents:
diff changeset
393 TYPE_STRING,
kono
parents:
diff changeset
394 TYPE_SINK,
kono
parents:
diff changeset
395 TYPE_FUNCTION,
kono
parents:
diff changeset
396 TYPE_POINTER,
kono
parents:
diff changeset
397 TYPE_NIL,
kono
parents:
diff changeset
398 TYPE_CALL_MULTIPLE_RESULT,
kono
parents:
diff changeset
399 TYPE_STRUCT,
kono
parents:
diff changeset
400 TYPE_ARRAY,
kono
parents:
diff changeset
401 TYPE_MAP,
kono
parents:
diff changeset
402 TYPE_CHANNEL,
kono
parents:
diff changeset
403 TYPE_INTERFACE,
kono
parents:
diff changeset
404 TYPE_NAMED,
kono
parents:
diff changeset
405 TYPE_FORWARD
kono
parents:
diff changeset
406 };
kono
parents:
diff changeset
407
kono
parents:
diff changeset
408 virtual ~Type();
kono
parents:
diff changeset
409
kono
parents:
diff changeset
410 // Creators.
kono
parents:
diff changeset
411
kono
parents:
diff changeset
412 static Type*
kono
parents:
diff changeset
413 make_error_type();
kono
parents:
diff changeset
414
kono
parents:
diff changeset
415 static Type*
kono
parents:
diff changeset
416 make_void_type();
kono
parents:
diff changeset
417
kono
parents:
diff changeset
418 // Get the unnamed bool type.
kono
parents:
diff changeset
419 static Type*
kono
parents:
diff changeset
420 make_boolean_type();
kono
parents:
diff changeset
421
kono
parents:
diff changeset
422 // Get the named type "bool".
kono
parents:
diff changeset
423 static Named_type*
kono
parents:
diff changeset
424 lookup_bool_type();
kono
parents:
diff changeset
425
kono
parents:
diff changeset
426 // Make the named type "bool".
kono
parents:
diff changeset
427 static Named_type*
kono
parents:
diff changeset
428 make_named_bool_type();
kono
parents:
diff changeset
429
kono
parents:
diff changeset
430 // Make an abstract integer type.
kono
parents:
diff changeset
431 static Integer_type*
kono
parents:
diff changeset
432 make_abstract_integer_type();
kono
parents:
diff changeset
433
kono
parents:
diff changeset
434 // Make an abstract type for a character constant.
kono
parents:
diff changeset
435 static Integer_type*
kono
parents:
diff changeset
436 make_abstract_character_type();
kono
parents:
diff changeset
437
kono
parents:
diff changeset
438 // Make a named integer type with a specified size.
kono
parents:
diff changeset
439 // RUNTIME_TYPE_KIND is the code to use in reflection information,
kono
parents:
diff changeset
440 // to distinguish int and int32.
kono
parents:
diff changeset
441 static Named_type*
kono
parents:
diff changeset
442 make_integer_type(const char* name, bool is_unsigned, int bits,
kono
parents:
diff changeset
443 int runtime_type_kind);
kono
parents:
diff changeset
444
kono
parents:
diff changeset
445 // Look up a named integer type.
kono
parents:
diff changeset
446 static Named_type*
kono
parents:
diff changeset
447 lookup_integer_type(const char* name);
kono
parents:
diff changeset
448
kono
parents:
diff changeset
449 // Make an abstract floating point type.
kono
parents:
diff changeset
450 static Float_type*
kono
parents:
diff changeset
451 make_abstract_float_type();
kono
parents:
diff changeset
452
kono
parents:
diff changeset
453 // Make a named floating point type with a specific size.
kono
parents:
diff changeset
454 // RUNTIME_TYPE_KIND is the code to use in reflection information,
kono
parents:
diff changeset
455 // to distinguish float and float32.
kono
parents:
diff changeset
456 static Named_type*
kono
parents:
diff changeset
457 make_float_type(const char* name, int bits, int runtime_type_kind);
kono
parents:
diff changeset
458
kono
parents:
diff changeset
459 // Look up a named float type.
kono
parents:
diff changeset
460 static Named_type*
kono
parents:
diff changeset
461 lookup_float_type(const char* name);
kono
parents:
diff changeset
462
kono
parents:
diff changeset
463 // Make an abstract complex type.
kono
parents:
diff changeset
464 static Complex_type*
kono
parents:
diff changeset
465 make_abstract_complex_type();
kono
parents:
diff changeset
466
kono
parents:
diff changeset
467 // Make a named complex type with a specific size.
kono
parents:
diff changeset
468 // RUNTIME_TYPE_KIND is the code to use in reflection information,
kono
parents:
diff changeset
469 // to distinguish complex and complex64.
kono
parents:
diff changeset
470 static Named_type*
kono
parents:
diff changeset
471 make_complex_type(const char* name, int bits, int runtime_type_kind);
kono
parents:
diff changeset
472
kono
parents:
diff changeset
473 // Look up a named complex type.
kono
parents:
diff changeset
474 static Named_type*
kono
parents:
diff changeset
475 lookup_complex_type(const char* name);
kono
parents:
diff changeset
476
kono
parents:
diff changeset
477 // Get the unnamed string type.
kono
parents:
diff changeset
478 static Type*
kono
parents:
diff changeset
479 make_string_type();
kono
parents:
diff changeset
480
kono
parents:
diff changeset
481 // Get the named type "string".
kono
parents:
diff changeset
482 static Named_type*
kono
parents:
diff changeset
483 lookup_string_type();
kono
parents:
diff changeset
484
kono
parents:
diff changeset
485 // Make the named type "string".
kono
parents:
diff changeset
486 static Named_type*
kono
parents:
diff changeset
487 make_named_string_type();
kono
parents:
diff changeset
488
kono
parents:
diff changeset
489 static Type*
kono
parents:
diff changeset
490 make_sink_type();
kono
parents:
diff changeset
491
kono
parents:
diff changeset
492 static Function_type*
kono
parents:
diff changeset
493 make_function_type(Typed_identifier* receiver,
kono
parents:
diff changeset
494 Typed_identifier_list* parameters,
kono
parents:
diff changeset
495 Typed_identifier_list* results,
kono
parents:
diff changeset
496 Location);
kono
parents:
diff changeset
497
kono
parents:
diff changeset
498 static Backend_function_type*
kono
parents:
diff changeset
499 make_backend_function_type(Typed_identifier* receiver,
kono
parents:
diff changeset
500 Typed_identifier_list* parameters,
kono
parents:
diff changeset
501 Typed_identifier_list* results,
kono
parents:
diff changeset
502 Location);
kono
parents:
diff changeset
503
kono
parents:
diff changeset
504 static Pointer_type*
kono
parents:
diff changeset
505 make_pointer_type(Type*);
kono
parents:
diff changeset
506
kono
parents:
diff changeset
507 static void
kono
parents:
diff changeset
508 finish_pointer_types(Gogo* gogo);
kono
parents:
diff changeset
509
kono
parents:
diff changeset
510 static Type*
kono
parents:
diff changeset
511 make_nil_type();
kono
parents:
diff changeset
512
kono
parents:
diff changeset
513 static Type*
kono
parents:
diff changeset
514 make_call_multiple_result_type(Call_expression*);
kono
parents:
diff changeset
515
kono
parents:
diff changeset
516 static Struct_type*
kono
parents:
diff changeset
517 make_struct_type(Struct_field_list* fields, Location);
kono
parents:
diff changeset
518
kono
parents:
diff changeset
519 static Array_type*
kono
parents:
diff changeset
520 make_array_type(Type* element_type, Expression* length);
kono
parents:
diff changeset
521
kono
parents:
diff changeset
522 static Map_type*
kono
parents:
diff changeset
523 make_map_type(Type* key_type, Type* value_type, Location);
kono
parents:
diff changeset
524
kono
parents:
diff changeset
525 static Channel_type*
kono
parents:
diff changeset
526 make_channel_type(bool send, bool receive, Type*);
kono
parents:
diff changeset
527
kono
parents:
diff changeset
528 static Interface_type*
kono
parents:
diff changeset
529 make_interface_type(Typed_identifier_list* methods, Location);
kono
parents:
diff changeset
530
kono
parents:
diff changeset
531 static Interface_type*
kono
parents:
diff changeset
532 make_empty_interface_type(Location);
kono
parents:
diff changeset
533
kono
parents:
diff changeset
534 static Type*
kono
parents:
diff changeset
535 make_type_descriptor_type();
kono
parents:
diff changeset
536
kono
parents:
diff changeset
537 static Type*
kono
parents:
diff changeset
538 make_type_descriptor_ptr_type();
kono
parents:
diff changeset
539
kono
parents:
diff changeset
540 static Named_type*
kono
parents:
diff changeset
541 make_named_type(Named_object*, Type*, Location);
kono
parents:
diff changeset
542
kono
parents:
diff changeset
543 static Type*
kono
parents:
diff changeset
544 make_forward_declaration(Named_object*);
kono
parents:
diff changeset
545
kono
parents:
diff changeset
546 // Make a builtin struct type from a list of fields.
kono
parents:
diff changeset
547 static Struct_type*
kono
parents:
diff changeset
548 make_builtin_struct_type(int nfields, ...);
kono
parents:
diff changeset
549
kono
parents:
diff changeset
550 // Make a builtin named type.
kono
parents:
diff changeset
551 static Named_type*
kono
parents:
diff changeset
552 make_builtin_named_type(const char* name, Type* type);
kono
parents:
diff changeset
553
kono
parents:
diff changeset
554 // Traverse a type.
kono
parents:
diff changeset
555 static int
kono
parents:
diff changeset
556 traverse(Type*, Traverse*);
kono
parents:
diff changeset
557
kono
parents:
diff changeset
558 // Verify the type. This is called after parsing, and verifies that
kono
parents:
diff changeset
559 // types are complete and meet the language requirements. This
kono
parents:
diff changeset
560 // returns false if the type is invalid and we should not continue
kono
parents:
diff changeset
561 // traversing it.
kono
parents:
diff changeset
562 bool
kono
parents:
diff changeset
563 verify()
kono
parents:
diff changeset
564 { return this->do_verify(); }
kono
parents:
diff changeset
565
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
566 // Bit flags to pass to are_identical and friends.
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
567
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
568 // Treat error types as their own distinct type. Sometimes we
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
569 // ignore error types--treat them as identical to every other
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
570 // type--to avoid cascading errors.
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
571 static const int COMPARE_ERRORS = 1;
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
572
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
573 // Compare struct field tags when comparing structs. We ignore
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
574 // struct field tags for purposes of type conversion.
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
575 static const int COMPARE_TAGS = 2;
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
576
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
577 // Compare aliases: treat an alias to T as distinct from T.
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
578 static const int COMPARE_ALIASES = 4;
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
579
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
580 // Return true if two types are identical. If this returns false,
111
kono
parents:
diff changeset
581 // and REASON is not NULL, it may set *REASON.
kono
parents:
diff changeset
582 static bool
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
583 are_identical(const Type* lhs, const Type* rhs, int flags,
111
kono
parents:
diff changeset
584 std::string* reason);
kono
parents:
diff changeset
585
kono
parents:
diff changeset
586 // Return true if two types are compatible for use in a binary
kono
parents:
diff changeset
587 // operation, other than a shift, comparison, or channel send. This
kono
parents:
diff changeset
588 // is an equivalence relation.
kono
parents:
diff changeset
589 static bool
kono
parents:
diff changeset
590 are_compatible_for_binop(const Type* t1, const Type* t2);
kono
parents:
diff changeset
591
kono
parents:
diff changeset
592 // Return true if two types are compatible for use with the
kono
parents:
diff changeset
593 // comparison operator. IS_EQUALITY_OP is true if this is an
kono
parents:
diff changeset
594 // equality comparison, false if it is an ordered comparison. This
kono
parents:
diff changeset
595 // is an equivalence relation. If this returns false, and REASON is
kono
parents:
diff changeset
596 // not NULL, it sets *REASON.
kono
parents:
diff changeset
597 static bool
kono
parents:
diff changeset
598 are_compatible_for_comparison(bool is_equality_op, const Type *t1,
kono
parents:
diff changeset
599 const Type *t2, std::string* reason);
kono
parents:
diff changeset
600
kono
parents:
diff changeset
601 // Return true if a type is comparable with itself. This is true of
kono
parents:
diff changeset
602 // most types, but false for, e.g., function types.
kono
parents:
diff changeset
603 bool
kono
parents:
diff changeset
604 is_comparable() const
kono
parents:
diff changeset
605 { return Type::are_compatible_for_comparison(true, this, this, NULL); }
kono
parents:
diff changeset
606
kono
parents:
diff changeset
607 // Return true if a value with type RHS is assignable to a variable
kono
parents:
diff changeset
608 // with type LHS. This is not an equivalence relation. If this
kono
parents:
diff changeset
609 // returns false, and REASON is not NULL, it sets *REASON.
kono
parents:
diff changeset
610 static bool
kono
parents:
diff changeset
611 are_assignable(const Type* lhs, const Type* rhs, std::string* reason);
kono
parents:
diff changeset
612
kono
parents:
diff changeset
613 // Return true if a value with type RHS may be converted to type
kono
parents:
diff changeset
614 // LHS. If this returns false, and REASON is not NULL, it sets
kono
parents:
diff changeset
615 // *REASON.
kono
parents:
diff changeset
616 static bool
kono
parents:
diff changeset
617 are_convertible(const Type* lhs, const Type* rhs, std::string* reason);
kono
parents:
diff changeset
618
kono
parents:
diff changeset
619 // Return true if values of this type can be compared using an
kono
parents:
diff changeset
620 // identity function which gets nothing but a pointer to the value
kono
parents:
diff changeset
621 // and a size.
kono
parents:
diff changeset
622 bool
kono
parents:
diff changeset
623 compare_is_identity(Gogo* gogo)
kono
parents:
diff changeset
624 { return this->do_compare_is_identity(gogo); }
kono
parents:
diff changeset
625
kono
parents:
diff changeset
626 // Return whether values of this type are reflexive: if a comparison
kono
parents:
diff changeset
627 // of a value with itself always returns true.
kono
parents:
diff changeset
628 bool
kono
parents:
diff changeset
629 is_reflexive()
kono
parents:
diff changeset
630 { return this->do_is_reflexive(); }
kono
parents:
diff changeset
631
kono
parents:
diff changeset
632 // Return whether values of this, when used as a key in map,
kono
parents:
diff changeset
633 // requires the key to be updated when an assignment is made.
kono
parents:
diff changeset
634 bool
kono
parents:
diff changeset
635 needs_key_update()
kono
parents:
diff changeset
636 { return this->do_needs_key_update(); }
kono
parents:
diff changeset
637
kono
parents:
diff changeset
638 // Whether the type is permitted in the heap.
kono
parents:
diff changeset
639 bool
kono
parents:
diff changeset
640 in_heap()
kono
parents:
diff changeset
641 { return this->do_in_heap(); }
kono
parents:
diff changeset
642
kono
parents:
diff changeset
643 // Return a hash code for this type for the method hash table.
kono
parents:
diff changeset
644 // Types which are equivalent according to are_identical will have
kono
parents:
diff changeset
645 // the same hash code.
kono
parents:
diff changeset
646 unsigned int
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
647 hash_for_method(Gogo*, int) const;
111
kono
parents:
diff changeset
648
kono
parents:
diff changeset
649 // Return the type classification.
kono
parents:
diff changeset
650 Type_classification
kono
parents:
diff changeset
651 classification() const
kono
parents:
diff changeset
652 { return this->classification_; }
kono
parents:
diff changeset
653
kono
parents:
diff changeset
654 // Return the base type for this type. This looks through forward
kono
parents:
diff changeset
655 // declarations and names. Using this with a forward declaration
kono
parents:
diff changeset
656 // which has not been defined will return an error type.
kono
parents:
diff changeset
657 Type*
kono
parents:
diff changeset
658 base();
kono
parents:
diff changeset
659
kono
parents:
diff changeset
660 const Type*
kono
parents:
diff changeset
661 base() const;
kono
parents:
diff changeset
662
kono
parents:
diff changeset
663 // Return the type skipping defined forward declarations. If this
kono
parents:
diff changeset
664 // type is a forward declaration which has not been defined, it will
kono
parents:
diff changeset
665 // return the Forward_declaration_type. This differs from base() in
kono
parents:
diff changeset
666 // that it will return a Named_type, and for a
kono
parents:
diff changeset
667 // Forward_declaration_type which is not defined it will return that
kono
parents:
diff changeset
668 // type rather than an error type.
kono
parents:
diff changeset
669 Type*
kono
parents:
diff changeset
670 forwarded();
kono
parents:
diff changeset
671
kono
parents:
diff changeset
672 const Type*
kono
parents:
diff changeset
673 forwarded() const;
kono
parents:
diff changeset
674
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
675 // Return the type skipping any alias definitions and any defined
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
676 // forward declarations. This is like forwarded, but also
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
677 // recursively expands alias definitions to the aliased type.
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
678 Type*
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
679 unalias();
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
680
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
681 const Type*
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
682 unalias() const;
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
683
111
kono
parents:
diff changeset
684 // Return true if this is a basic type: a type which is not composed
kono
parents:
diff changeset
685 // of other types, and is not void.
kono
parents:
diff changeset
686 bool
kono
parents:
diff changeset
687 is_basic_type() const;
kono
parents:
diff changeset
688
kono
parents:
diff changeset
689 // Return true if this is an abstract type--an integer, floating
kono
parents:
diff changeset
690 // point, or complex type whose size has not been determined.
kono
parents:
diff changeset
691 bool
kono
parents:
diff changeset
692 is_abstract() const;
kono
parents:
diff changeset
693
kono
parents:
diff changeset
694 // Return a non-abstract version of an abstract type.
kono
parents:
diff changeset
695 Type*
kono
parents:
diff changeset
696 make_non_abstract_type();
kono
parents:
diff changeset
697
kono
parents:
diff changeset
698 // Return true if this type is or contains a pointer. This
kono
parents:
diff changeset
699 // determines whether the garbage collector needs to look at a value
kono
parents:
diff changeset
700 // of this type.
kono
parents:
diff changeset
701 bool
kono
parents:
diff changeset
702 has_pointer() const
kono
parents:
diff changeset
703 { return this->do_has_pointer(); }
kono
parents:
diff changeset
704
kono
parents:
diff changeset
705 // Return true if this is the error type. This returns false for a
kono
parents:
diff changeset
706 // type which is not defined, as it is called by the parser before
kono
parents:
diff changeset
707 // all types are defined.
kono
parents:
diff changeset
708 bool
kono
parents:
diff changeset
709 is_error_type() const;
kono
parents:
diff changeset
710
kono
parents:
diff changeset
711 // Return true if this is the error type or if the type is
kono
parents:
diff changeset
712 // undefined. If the type is undefined, this will give an error.
kono
parents:
diff changeset
713 // This should only be called after parsing is complete.
kono
parents:
diff changeset
714 bool
kono
parents:
diff changeset
715 is_error() const
kono
parents:
diff changeset
716 { return this->base()->is_error_type(); }
kono
parents:
diff changeset
717
kono
parents:
diff changeset
718 // Return true if this is a void type.
kono
parents:
diff changeset
719 bool
kono
parents:
diff changeset
720 is_void_type() const
kono
parents:
diff changeset
721 { return this->classification_ == TYPE_VOID; }
kono
parents:
diff changeset
722
kono
parents:
diff changeset
723 // If this is an integer type, return the Integer_type. Otherwise,
kono
parents:
diff changeset
724 // return NULL. This is a controlled dynamic_cast.
kono
parents:
diff changeset
725 Integer_type*
kono
parents:
diff changeset
726 integer_type()
kono
parents:
diff changeset
727 { return this->convert<Integer_type, TYPE_INTEGER>(); }
kono
parents:
diff changeset
728
kono
parents:
diff changeset
729 const Integer_type*
kono
parents:
diff changeset
730 integer_type() const
kono
parents:
diff changeset
731 { return this->convert<const Integer_type, TYPE_INTEGER>(); }
kono
parents:
diff changeset
732
kono
parents:
diff changeset
733 // If this is a floating point type, return the Float_type.
kono
parents:
diff changeset
734 // Otherwise, return NULL. This is a controlled dynamic_cast.
kono
parents:
diff changeset
735 Float_type*
kono
parents:
diff changeset
736 float_type()
kono
parents:
diff changeset
737 { return this->convert<Float_type, TYPE_FLOAT>(); }
kono
parents:
diff changeset
738
kono
parents:
diff changeset
739 const Float_type*
kono
parents:
diff changeset
740 float_type() const
kono
parents:
diff changeset
741 { return this->convert<const Float_type, TYPE_FLOAT>(); }
kono
parents:
diff changeset
742
kono
parents:
diff changeset
743 // If this is a complex type, return the Complex_type. Otherwise,
kono
parents:
diff changeset
744 // return NULL.
kono
parents:
diff changeset
745 Complex_type*
kono
parents:
diff changeset
746 complex_type()
kono
parents:
diff changeset
747 { return this->convert<Complex_type, TYPE_COMPLEX>(); }
kono
parents:
diff changeset
748
kono
parents:
diff changeset
749 const Complex_type*
kono
parents:
diff changeset
750 complex_type() const
kono
parents:
diff changeset
751 { return this->convert<const Complex_type, TYPE_COMPLEX>(); }
kono
parents:
diff changeset
752
kono
parents:
diff changeset
753 // Return whether this is a numeric type.
kono
parents:
diff changeset
754 bool
kono
parents:
diff changeset
755 is_numeric_type() const
kono
parents:
diff changeset
756 {
kono
parents:
diff changeset
757 Type_classification tc = this->base()->classification_;
kono
parents:
diff changeset
758 return tc == TYPE_INTEGER || tc == TYPE_FLOAT || tc == TYPE_COMPLEX;
kono
parents:
diff changeset
759 }
kono
parents:
diff changeset
760
kono
parents:
diff changeset
761 // Return true if this is a boolean type.
kono
parents:
diff changeset
762 bool
kono
parents:
diff changeset
763 is_boolean_type() const
kono
parents:
diff changeset
764 { return this->base()->classification_ == TYPE_BOOLEAN; }
kono
parents:
diff changeset
765
kono
parents:
diff changeset
766 // Return true if this is an abstract boolean type.
kono
parents:
diff changeset
767 bool
kono
parents:
diff changeset
768 is_abstract_boolean_type() const
kono
parents:
diff changeset
769 { return this->classification_ == TYPE_BOOLEAN; }
kono
parents:
diff changeset
770
kono
parents:
diff changeset
771 // Return true if this is a string type.
kono
parents:
diff changeset
772 bool
kono
parents:
diff changeset
773 is_string_type() const
kono
parents:
diff changeset
774 { return this->base()->classification_ == TYPE_STRING; }
kono
parents:
diff changeset
775
kono
parents:
diff changeset
776 // Return true if this is an abstract string type.
kono
parents:
diff changeset
777 bool
kono
parents:
diff changeset
778 is_abstract_string_type() const
kono
parents:
diff changeset
779 { return this->classification_ == TYPE_STRING; }
kono
parents:
diff changeset
780
kono
parents:
diff changeset
781 // Return true if this is the sink type. This is the type of the
kono
parents:
diff changeset
782 // blank identifier _.
kono
parents:
diff changeset
783 bool
kono
parents:
diff changeset
784 is_sink_type() const
kono
parents:
diff changeset
785 { return this->base()->classification_ == TYPE_SINK; }
kono
parents:
diff changeset
786
kono
parents:
diff changeset
787 // If this is a function type, return it. Otherwise, return NULL.
kono
parents:
diff changeset
788 Function_type*
kono
parents:
diff changeset
789 function_type()
kono
parents:
diff changeset
790 { return this->convert<Function_type, TYPE_FUNCTION>(); }
kono
parents:
diff changeset
791
kono
parents:
diff changeset
792 const Function_type*
kono
parents:
diff changeset
793 function_type() const
kono
parents:
diff changeset
794 { return this->convert<const Function_type, TYPE_FUNCTION>(); }
kono
parents:
diff changeset
795
kono
parents:
diff changeset
796 // If this is a pointer type, return the type to which it points.
kono
parents:
diff changeset
797 // Otherwise, return NULL.
kono
parents:
diff changeset
798 Type*
kono
parents:
diff changeset
799 points_to() const;
kono
parents:
diff changeset
800
kono
parents:
diff changeset
801 // If this is a pointer type, return the type to which it points.
kono
parents:
diff changeset
802 // Otherwise, return the type itself.
kono
parents:
diff changeset
803 Type*
kono
parents:
diff changeset
804 deref()
kono
parents:
diff changeset
805 {
kono
parents:
diff changeset
806 Type* pt = this->points_to();
kono
parents:
diff changeset
807 return pt != NULL ? pt : this;
kono
parents:
diff changeset
808 }
kono
parents:
diff changeset
809
kono
parents:
diff changeset
810 const Type*
kono
parents:
diff changeset
811 deref() const
kono
parents:
diff changeset
812 {
kono
parents:
diff changeset
813 const Type* pt = this->points_to();
kono
parents:
diff changeset
814 return pt != NULL ? pt : this;
kono
parents:
diff changeset
815 }
kono
parents:
diff changeset
816
kono
parents:
diff changeset
817 // Return true if this is the nil type. We don't use base() here,
kono
parents:
diff changeset
818 // because this can be called during parse, and there is no way to
kono
parents:
diff changeset
819 // name the nil type anyhow.
kono
parents:
diff changeset
820 bool
kono
parents:
diff changeset
821 is_nil_type() const
kono
parents:
diff changeset
822 { return this->classification_ == TYPE_NIL; }
kono
parents:
diff changeset
823
kono
parents:
diff changeset
824 // Return true if this is the predeclared constant nil being used as
kono
parents:
diff changeset
825 // a type. This is what the parser produces for type switches which
kono
parents:
diff changeset
826 // use "case nil".
kono
parents:
diff changeset
827 bool
kono
parents:
diff changeset
828 is_nil_constant_as_type() const;
kono
parents:
diff changeset
829
kono
parents:
diff changeset
830 // Return true if this is the return type of a function which
kono
parents:
diff changeset
831 // returns multiple values.
kono
parents:
diff changeset
832 bool
kono
parents:
diff changeset
833 is_call_multiple_result_type() const
kono
parents:
diff changeset
834 { return this->base()->classification_ == TYPE_CALL_MULTIPLE_RESULT; }
kono
parents:
diff changeset
835
kono
parents:
diff changeset
836 // If this is a struct type, return it. Otherwise, return NULL.
kono
parents:
diff changeset
837 Struct_type*
kono
parents:
diff changeset
838 struct_type()
kono
parents:
diff changeset
839 { return this->convert<Struct_type, TYPE_STRUCT>(); }
kono
parents:
diff changeset
840
kono
parents:
diff changeset
841 const Struct_type*
kono
parents:
diff changeset
842 struct_type() const
kono
parents:
diff changeset
843 { return this->convert<const Struct_type, TYPE_STRUCT>(); }
kono
parents:
diff changeset
844
kono
parents:
diff changeset
845 // If this is an array type, return it. Otherwise, return NULL.
kono
parents:
diff changeset
846 Array_type*
kono
parents:
diff changeset
847 array_type()
kono
parents:
diff changeset
848 { return this->convert<Array_type, TYPE_ARRAY>(); }
kono
parents:
diff changeset
849
kono
parents:
diff changeset
850 const Array_type*
kono
parents:
diff changeset
851 array_type() const
kono
parents:
diff changeset
852 { return this->convert<const Array_type, TYPE_ARRAY>(); }
kono
parents:
diff changeset
853
kono
parents:
diff changeset
854 // Return whether if this is a slice type.
kono
parents:
diff changeset
855 bool
kono
parents:
diff changeset
856 is_slice_type() const;
kono
parents:
diff changeset
857
kono
parents:
diff changeset
858 // If this is a map type, return it. Otherwise, return NULL.
kono
parents:
diff changeset
859 Map_type*
kono
parents:
diff changeset
860 map_type()
kono
parents:
diff changeset
861 { return this->convert<Map_type, TYPE_MAP>(); }
kono
parents:
diff changeset
862
kono
parents:
diff changeset
863 const Map_type*
kono
parents:
diff changeset
864 map_type() const
kono
parents:
diff changeset
865 { return this->convert<const Map_type, TYPE_MAP>(); }
kono
parents:
diff changeset
866
kono
parents:
diff changeset
867 // If this is a channel type, return it. Otherwise, return NULL.
kono
parents:
diff changeset
868 Channel_type*
kono
parents:
diff changeset
869 channel_type()
kono
parents:
diff changeset
870 { return this->convert<Channel_type, TYPE_CHANNEL>(); }
kono
parents:
diff changeset
871
kono
parents:
diff changeset
872 const Channel_type*
kono
parents:
diff changeset
873 channel_type() const
kono
parents:
diff changeset
874 { return this->convert<const Channel_type, TYPE_CHANNEL>(); }
kono
parents:
diff changeset
875
kono
parents:
diff changeset
876 // If this is an interface type, return it. Otherwise, return NULL.
kono
parents:
diff changeset
877 Interface_type*
kono
parents:
diff changeset
878 interface_type()
kono
parents:
diff changeset
879 { return this->convert<Interface_type, TYPE_INTERFACE>(); }
kono
parents:
diff changeset
880
kono
parents:
diff changeset
881 const Interface_type*
kono
parents:
diff changeset
882 interface_type() const
kono
parents:
diff changeset
883 { return this->convert<const Interface_type, TYPE_INTERFACE>(); }
kono
parents:
diff changeset
884
kono
parents:
diff changeset
885 // If this is a named type, return it. Otherwise, return NULL.
kono
parents:
diff changeset
886 Named_type*
kono
parents:
diff changeset
887 named_type();
kono
parents:
diff changeset
888
kono
parents:
diff changeset
889 const Named_type*
kono
parents:
diff changeset
890 named_type() const;
kono
parents:
diff changeset
891
kono
parents:
diff changeset
892 // If this is a forward declaration, return it. Otherwise, return
kono
parents:
diff changeset
893 // NULL.
kono
parents:
diff changeset
894 Forward_declaration_type*
kono
parents:
diff changeset
895 forward_declaration_type()
kono
parents:
diff changeset
896 { return this->convert_no_base<Forward_declaration_type, TYPE_FORWARD>(); }
kono
parents:
diff changeset
897
kono
parents:
diff changeset
898 const Forward_declaration_type*
kono
parents:
diff changeset
899 forward_declaration_type() const
kono
parents:
diff changeset
900 {
kono
parents:
diff changeset
901 return this->convert_no_base<const Forward_declaration_type,
kono
parents:
diff changeset
902 TYPE_FORWARD>();
kono
parents:
diff changeset
903 }
kono
parents:
diff changeset
904
kono
parents:
diff changeset
905 // Return true if this type is not yet defined.
kono
parents:
diff changeset
906 bool
kono
parents:
diff changeset
907 is_undefined() const;
kono
parents:
diff changeset
908
kono
parents:
diff changeset
909 // Return true if this is the unsafe.pointer type. We currently
kono
parents:
diff changeset
910 // represent that as pointer-to-void.
kono
parents:
diff changeset
911 bool
kono
parents:
diff changeset
912 is_unsafe_pointer_type() const
kono
parents:
diff changeset
913 { return this->points_to() != NULL && this->points_to()->is_void_type(); }
kono
parents:
diff changeset
914
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
915 // Return a version of this type with any expressions copied, but
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
916 // only if copying the expressions will affect the size of the type.
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
917 // If there are no such expressions in the type (expressions can
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
918 // only occur in array types), just return the same type. If any
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
919 // expressions can not affect the size of the type, just return the
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
920 // same type.
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
921 Type*
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
922 copy_expressions();
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
923
111
kono
parents:
diff changeset
924 // Look for field or method NAME for TYPE. Return an expression for
kono
parents:
diff changeset
925 // it, bound to EXPR.
kono
parents:
diff changeset
926 static Expression*
kono
parents:
diff changeset
927 bind_field_or_method(Gogo*, const Type* type, Expression* expr,
kono
parents:
diff changeset
928 const std::string& name, Location);
kono
parents:
diff changeset
929
kono
parents:
diff changeset
930 // Return true if NAME is an unexported field or method of TYPE.
kono
parents:
diff changeset
931 static bool
kono
parents:
diff changeset
932 is_unexported_field_or_method(Gogo*, const Type*, const std::string&,
kono
parents:
diff changeset
933 std::vector<const Named_type*>*);
kono
parents:
diff changeset
934
kono
parents:
diff changeset
935 // Convert the builtin named types.
kono
parents:
diff changeset
936 static void
kono
parents:
diff changeset
937 convert_builtin_named_types(Gogo*);
kono
parents:
diff changeset
938
kono
parents:
diff changeset
939 // Return the backend representation of this type.
kono
parents:
diff changeset
940 Btype*
kono
parents:
diff changeset
941 get_backend(Gogo*);
kono
parents:
diff changeset
942
kono
parents:
diff changeset
943 // Return a placeholder for the backend representation of the type.
kono
parents:
diff changeset
944 // This will return a type of the correct size, but for which some
kono
parents:
diff changeset
945 // of the fields may still need to be completed.
kono
parents:
diff changeset
946 Btype*
kono
parents:
diff changeset
947 get_backend_placeholder(Gogo*);
kono
parents:
diff changeset
948
kono
parents:
diff changeset
949 // Finish the backend representation of a placeholder.
kono
parents:
diff changeset
950 void
kono
parents:
diff changeset
951 finish_backend(Gogo*, Btype*);
kono
parents:
diff changeset
952
kono
parents:
diff changeset
953 // Build a type descriptor entry for this type. Return a pointer to
kono
parents:
diff changeset
954 // it. The location is the location which causes us to need the
kono
parents:
diff changeset
955 // entry.
kono
parents:
diff changeset
956 Bexpression*
kono
parents:
diff changeset
957 type_descriptor_pointer(Gogo* gogo, Location);
kono
parents:
diff changeset
958
kono
parents:
diff changeset
959 // Build the Garbage Collection symbol for this type. Return a pointer to it.
kono
parents:
diff changeset
960 Bexpression*
kono
parents:
diff changeset
961 gc_symbol_pointer(Gogo* gogo);
kono
parents:
diff changeset
962
kono
parents:
diff changeset
963 // Return whether this type needs a garbage collection program.
kono
parents:
diff changeset
964 // Sets *PTRSIZE and *PTRDATA.
kono
parents:
diff changeset
965 bool
kono
parents:
diff changeset
966 needs_gcprog(Gogo*, int64_t* ptrsize, int64_t* ptrdata);
kono
parents:
diff changeset
967
kono
parents:
diff changeset
968 // Return a ptrmask variable for this type.
kono
parents:
diff changeset
969 Bvariable*
kono
parents:
diff changeset
970 gc_ptrmask_var(Gogo*, int64_t ptrsize, int64_t ptrdata);
kono
parents:
diff changeset
971
kono
parents:
diff changeset
972 // Return the type reflection string for this type.
kono
parents:
diff changeset
973 std::string
kono
parents:
diff changeset
974 reflection(Gogo*) const;
kono
parents:
diff changeset
975
kono
parents:
diff changeset
976 // Return a mangled name for the type. This is a name which can be
kono
parents:
diff changeset
977 // used in assembler code. Identical types should have the same
kono
parents:
diff changeset
978 // manged name.
kono
parents:
diff changeset
979 std::string
kono
parents:
diff changeset
980 mangled_name(Gogo*) const;
kono
parents:
diff changeset
981
kono
parents:
diff changeset
982 // If the size of the type can be determined, set *PSIZE to the size
kono
parents:
diff changeset
983 // in bytes and return true. Otherwise, return false. This queries
kono
parents:
diff changeset
984 // the backend.
kono
parents:
diff changeset
985 bool
kono
parents:
diff changeset
986 backend_type_size(Gogo*, int64_t* psize);
kono
parents:
diff changeset
987
kono
parents:
diff changeset
988 // If the alignment of the type can be determined, set *PALIGN to
kono
parents:
diff changeset
989 // the alignment in bytes and return true. Otherwise, return false.
kono
parents:
diff changeset
990 bool
kono
parents:
diff changeset
991 backend_type_align(Gogo*, int64_t* palign);
kono
parents:
diff changeset
992
kono
parents:
diff changeset
993 // If the alignment of a struct field of this type can be
kono
parents:
diff changeset
994 // determined, set *PALIGN to the alignment in bytes and return
kono
parents:
diff changeset
995 // true. Otherwise, return false.
kono
parents:
diff changeset
996 bool
kono
parents:
diff changeset
997 backend_type_field_align(Gogo*, int64_t* palign);
kono
parents:
diff changeset
998
kono
parents:
diff changeset
999 // Determine the ptrdata size for the backend version of this type:
kono
parents:
diff changeset
1000 // the length of the prefix of the type that can contain a pointer
kono
parents:
diff changeset
1001 // value. If it can be determined, set *PPTRDATA to the value in
kono
parents:
diff changeset
1002 // bytes and return true. Otherwise, return false.
kono
parents:
diff changeset
1003 bool
kono
parents:
diff changeset
1004 backend_type_ptrdata(Gogo*, int64_t* pptrdata);
kono
parents:
diff changeset
1005
kono
parents:
diff changeset
1006 // Determine the ptrdata size that we are going to set in the type
kono
parents:
diff changeset
1007 // descriptor. This is normally the same as backend_type_ptrdata,
kono
parents:
diff changeset
1008 // but differs if we use a gcprog for an array. The arguments and
kono
parents:
diff changeset
1009 // results are as for backend_type_ptrdata.
kono
parents:
diff changeset
1010 bool
kono
parents:
diff changeset
1011 descriptor_ptrdata(Gogo*, int64_t* pptrdata);
kono
parents:
diff changeset
1012
kono
parents:
diff changeset
1013 // Whether the backend size is known.
kono
parents:
diff changeset
1014 bool
kono
parents:
diff changeset
1015 is_backend_type_size_known(Gogo*);
kono
parents:
diff changeset
1016
kono
parents:
diff changeset
1017 // Return whether the type needs specially built type functions.
kono
parents:
diff changeset
1018 bool
kono
parents:
diff changeset
1019 needs_specific_type_functions(Gogo*);
kono
parents:
diff changeset
1020
kono
parents:
diff changeset
1021 // Get the hash and equality functions for a type.
kono
parents:
diff changeset
1022 void
kono
parents:
diff changeset
1023 type_functions(Gogo*, Named_type* name, Function_type* hash_fntype,
kono
parents:
diff changeset
1024 Function_type* equal_fntype, Named_object** hash_fn,
kono
parents:
diff changeset
1025 Named_object** equal_fn);
kono
parents:
diff changeset
1026
kono
parents:
diff changeset
1027 // Write the hash and equality type functions.
kono
parents:
diff changeset
1028 void
kono
parents:
diff changeset
1029 write_specific_type_functions(Gogo*, Named_type*, int64_t size,
kono
parents:
diff changeset
1030 const std::string& hash_name,
kono
parents:
diff changeset
1031 Function_type* hash_fntype,
kono
parents:
diff changeset
1032 const std::string& equal_name,
kono
parents:
diff changeset
1033 Function_type* equal_fntype);
kono
parents:
diff changeset
1034
kono
parents:
diff changeset
1035 // Return the alignment required by the memequalN function.
kono
parents:
diff changeset
1036 static int64_t memequal_align(Gogo*, int size);
kono
parents:
diff changeset
1037
kono
parents:
diff changeset
1038 // Export the type.
kono
parents:
diff changeset
1039 void
kono
parents:
diff changeset
1040 export_type(Export* exp) const
kono
parents:
diff changeset
1041 { this->do_export(exp); }
kono
parents:
diff changeset
1042
kono
parents:
diff changeset
1043 // Import a type.
kono
parents:
diff changeset
1044 static Type*
kono
parents:
diff changeset
1045 import_type(Import*);
kono
parents:
diff changeset
1046
kono
parents:
diff changeset
1047 protected:
kono
parents:
diff changeset
1048 Type(Type_classification);
kono
parents:
diff changeset
1049
kono
parents:
diff changeset
1050 // Functions implemented by the child class.
kono
parents:
diff changeset
1051
kono
parents:
diff changeset
1052 // Traverse the subtypes.
kono
parents:
diff changeset
1053 virtual int
kono
parents:
diff changeset
1054 do_traverse(Traverse*);
kono
parents:
diff changeset
1055
kono
parents:
diff changeset
1056 // Verify the type.
kono
parents:
diff changeset
1057 virtual bool
kono
parents:
diff changeset
1058 do_verify()
kono
parents:
diff changeset
1059 { return true; }
kono
parents:
diff changeset
1060
kono
parents:
diff changeset
1061 virtual bool
kono
parents:
diff changeset
1062 do_has_pointer() const
kono
parents:
diff changeset
1063 { return false; }
kono
parents:
diff changeset
1064
kono
parents:
diff changeset
1065 virtual bool
kono
parents:
diff changeset
1066 do_compare_is_identity(Gogo*) = 0;
kono
parents:
diff changeset
1067
kono
parents:
diff changeset
1068 virtual bool
kono
parents:
diff changeset
1069 do_is_reflexive()
kono
parents:
diff changeset
1070 { return true; }
kono
parents:
diff changeset
1071
kono
parents:
diff changeset
1072 virtual bool
kono
parents:
diff changeset
1073 do_needs_key_update()
kono
parents:
diff changeset
1074 { return false; }
kono
parents:
diff changeset
1075
kono
parents:
diff changeset
1076 virtual bool
kono
parents:
diff changeset
1077 do_in_heap()
kono
parents:
diff changeset
1078 { return true; }
kono
parents:
diff changeset
1079
kono
parents:
diff changeset
1080 virtual unsigned int
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1081 do_hash_for_method(Gogo*, int) const;
111
kono
parents:
diff changeset
1082
kono
parents:
diff changeset
1083 virtual Btype*
kono
parents:
diff changeset
1084 do_get_backend(Gogo*) = 0;
kono
parents:
diff changeset
1085
kono
parents:
diff changeset
1086 virtual Expression*
kono
parents:
diff changeset
1087 do_type_descriptor(Gogo*, Named_type* name) = 0;
kono
parents:
diff changeset
1088
kono
parents:
diff changeset
1089 virtual void
kono
parents:
diff changeset
1090 do_reflection(Gogo*, std::string*) const = 0;
kono
parents:
diff changeset
1091
kono
parents:
diff changeset
1092 virtual void
kono
parents:
diff changeset
1093 do_mangled_name(Gogo*, std::string*) const = 0;
kono
parents:
diff changeset
1094
kono
parents:
diff changeset
1095 virtual void
kono
parents:
diff changeset
1096 do_export(Export*) const;
kono
parents:
diff changeset
1097
kono
parents:
diff changeset
1098 // Return whether a method expects a pointer as the receiver.
kono
parents:
diff changeset
1099 static bool
kono
parents:
diff changeset
1100 method_expects_pointer(const Named_object*);
kono
parents:
diff changeset
1101
kono
parents:
diff changeset
1102 // Finalize the methods for a type.
kono
parents:
diff changeset
1103 static void
kono
parents:
diff changeset
1104 finalize_methods(Gogo*, const Type*, Location, Methods**);
kono
parents:
diff changeset
1105
kono
parents:
diff changeset
1106 // Return a method from a set of methods.
kono
parents:
diff changeset
1107 static Method*
kono
parents:
diff changeset
1108 method_function(const Methods*, const std::string& name,
kono
parents:
diff changeset
1109 bool* is_ambiguous);
kono
parents:
diff changeset
1110
kono
parents:
diff changeset
1111 // A mapping from interfaces to the associated interface method
kono
parents:
diff changeset
1112 // tables for this type. This maps to a decl.
kono
parents:
diff changeset
1113 typedef Unordered_map_hash(Interface_type*, Expression*, Type_hash_identical,
kono
parents:
diff changeset
1114 Type_identical) Interface_method_tables;
kono
parents:
diff changeset
1115
kono
parents:
diff changeset
1116 // Return a pointer to the interface method table for TYPE for the
kono
parents:
diff changeset
1117 // interface INTERFACE.
kono
parents:
diff changeset
1118 static Expression*
kono
parents:
diff changeset
1119 interface_method_table(Type* type,
kono
parents:
diff changeset
1120 Interface_type *interface, bool is_pointer,
kono
parents:
diff changeset
1121 Interface_method_tables** method_tables,
kono
parents:
diff changeset
1122 Interface_method_tables** pointer_tables);
kono
parents:
diff changeset
1123
kono
parents:
diff changeset
1124 // Return a composite literal for the type descriptor entry for a
kono
parents:
diff changeset
1125 // type.
kono
parents:
diff changeset
1126 static Expression*
kono
parents:
diff changeset
1127 type_descriptor(Gogo*, Type*);
kono
parents:
diff changeset
1128
kono
parents:
diff changeset
1129 // Return a composite literal for the type descriptor entry for
kono
parents:
diff changeset
1130 // TYPE, using NAME as the name of the type.
kono
parents:
diff changeset
1131 static Expression*
kono
parents:
diff changeset
1132 named_type_descriptor(Gogo*, Type* type, Named_type* name);
kono
parents:
diff changeset
1133
kono
parents:
diff changeset
1134 // Return a composite literal for a plain type descriptor for this
kono
parents:
diff changeset
1135 // type with the given kind and name.
kono
parents:
diff changeset
1136 Expression*
kono
parents:
diff changeset
1137 plain_type_descriptor(Gogo*, int runtime_type_kind, Named_type* name);
kono
parents:
diff changeset
1138
kono
parents:
diff changeset
1139 // Build a composite literal for the basic type descriptor.
kono
parents:
diff changeset
1140 Expression*
kono
parents:
diff changeset
1141 type_descriptor_constructor(Gogo*, int runtime_type_kind, Named_type*,
kono
parents:
diff changeset
1142 const Methods*, bool only_value_methods);
kono
parents:
diff changeset
1143
kono
parents:
diff changeset
1144 // For the benefit of child class reflection string generation.
kono
parents:
diff changeset
1145 void
kono
parents:
diff changeset
1146 append_reflection(const Type* type, Gogo* gogo, std::string* ret) const
kono
parents:
diff changeset
1147 { type->do_reflection(gogo, ret); }
kono
parents:
diff changeset
1148
kono
parents:
diff changeset
1149 // For the benefit of child class mangling.
kono
parents:
diff changeset
1150 void
kono
parents:
diff changeset
1151 append_mangled_name(const Type* type, Gogo* gogo, std::string* ret) const
kono
parents:
diff changeset
1152 { type->do_mangled_name(gogo, ret); }
kono
parents:
diff changeset
1153
kono
parents:
diff changeset
1154 // Incorporate a string into a hash code.
kono
parents:
diff changeset
1155 static unsigned int
kono
parents:
diff changeset
1156 hash_string(const std::string&, unsigned int);
kono
parents:
diff changeset
1157
kono
parents:
diff changeset
1158 // Return the backend representation for the underlying type of a
kono
parents:
diff changeset
1159 // named type.
kono
parents:
diff changeset
1160 static Btype*
kono
parents:
diff changeset
1161 get_named_base_btype(Gogo* gogo, Type* base_type)
kono
parents:
diff changeset
1162 { return base_type->get_btype_without_hash(gogo); }
kono
parents:
diff changeset
1163
kono
parents:
diff changeset
1164 private:
kono
parents:
diff changeset
1165 // Convert to the desired type classification, or return NULL. This
kono
parents:
diff changeset
1166 // is a controlled dynamic_cast.
kono
parents:
diff changeset
1167 template<typename Type_class, Type_classification type_classification>
kono
parents:
diff changeset
1168 Type_class*
kono
parents:
diff changeset
1169 convert()
kono
parents:
diff changeset
1170 {
kono
parents:
diff changeset
1171 Type* base = this->base();
kono
parents:
diff changeset
1172 return (base->classification_ == type_classification
kono
parents:
diff changeset
1173 ? static_cast<Type_class*>(base)
kono
parents:
diff changeset
1174 : NULL);
kono
parents:
diff changeset
1175 }
kono
parents:
diff changeset
1176
kono
parents:
diff changeset
1177 template<typename Type_class, Type_classification type_classification>
kono
parents:
diff changeset
1178 const Type_class*
kono
parents:
diff changeset
1179 convert() const
kono
parents:
diff changeset
1180 {
kono
parents:
diff changeset
1181 const Type* base = this->base();
kono
parents:
diff changeset
1182 return (base->classification_ == type_classification
kono
parents:
diff changeset
1183 ? static_cast<Type_class*>(base)
kono
parents:
diff changeset
1184 : NULL);
kono
parents:
diff changeset
1185 }
kono
parents:
diff changeset
1186
kono
parents:
diff changeset
1187 template<typename Type_class, Type_classification type_classification>
kono
parents:
diff changeset
1188 Type_class*
kono
parents:
diff changeset
1189 convert_no_base()
kono
parents:
diff changeset
1190 {
kono
parents:
diff changeset
1191 return (this->classification_ == type_classification
kono
parents:
diff changeset
1192 ? static_cast<Type_class*>(this)
kono
parents:
diff changeset
1193 : NULL);
kono
parents:
diff changeset
1194 }
kono
parents:
diff changeset
1195
kono
parents:
diff changeset
1196 template<typename Type_class, Type_classification type_classification>
kono
parents:
diff changeset
1197 const Type_class*
kono
parents:
diff changeset
1198 convert_no_base() const
kono
parents:
diff changeset
1199 {
kono
parents:
diff changeset
1200 return (this->classification_ == type_classification
kono
parents:
diff changeset
1201 ? static_cast<Type_class*>(this)
kono
parents:
diff changeset
1202 : NULL);
kono
parents:
diff changeset
1203 }
kono
parents:
diff changeset
1204
kono
parents:
diff changeset
1205 // Map unnamed types to type descriptor decls.
kono
parents:
diff changeset
1206 typedef Unordered_map_hash(const Type*, Bvariable*, Type_hash_identical,
kono
parents:
diff changeset
1207 Type_identical) Type_descriptor_vars;
kono
parents:
diff changeset
1208
kono
parents:
diff changeset
1209 static Type_descriptor_vars type_descriptor_vars;
kono
parents:
diff changeset
1210
kono
parents:
diff changeset
1211 // Build the type descriptor variable for this type.
kono
parents:
diff changeset
1212 void
kono
parents:
diff changeset
1213 make_type_descriptor_var(Gogo*);
kono
parents:
diff changeset
1214
kono
parents:
diff changeset
1215 // Map unnamed types to type descriptor decls.
kono
parents:
diff changeset
1216 typedef Unordered_map_hash(const Type*, Bvariable*, Type_hash_identical,
kono
parents:
diff changeset
1217 Type_identical) GC_symbol_vars;
kono
parents:
diff changeset
1218
kono
parents:
diff changeset
1219 static GC_symbol_vars gc_symbol_vars;
kono
parents:
diff changeset
1220
kono
parents:
diff changeset
1221 // Map ptrmask symbol names to the ptrmask variable.
kono
parents:
diff changeset
1222 typedef Unordered_map(std::string, Bvariable*) GC_gcbits_vars;
kono
parents:
diff changeset
1223
kono
parents:
diff changeset
1224 static GC_gcbits_vars gc_gcbits_vars;
kono
parents:
diff changeset
1225
kono
parents:
diff changeset
1226 // Build the GC symbol for this type.
kono
parents:
diff changeset
1227 void
kono
parents:
diff changeset
1228 make_gc_symbol_var(Gogo*);
kono
parents:
diff changeset
1229
kono
parents:
diff changeset
1230 // Return true if the type descriptor for this type should be
kono
parents:
diff changeset
1231 // defined in some other package. If NAME is not NULL, it is the
kono
parents:
diff changeset
1232 // name of this type. If this returns true it sets *PACKAGE to the
kono
parents:
diff changeset
1233 // package where the type descriptor is defined.
kono
parents:
diff changeset
1234 bool
kono
parents:
diff changeset
1235 type_descriptor_defined_elsewhere(Named_type* name, const Package** package);
kono
parents:
diff changeset
1236
kono
parents:
diff changeset
1237 // Make a composite literal for the garbage collection program for
kono
parents:
diff changeset
1238 // this type.
kono
parents:
diff changeset
1239 Expression*
kono
parents:
diff changeset
1240 gcprog_constructor(Gogo*, int64_t ptrsize, int64_t ptrdata);
kono
parents:
diff changeset
1241
kono
parents:
diff changeset
1242 // Build the hash and equality type functions for a type which needs
kono
parents:
diff changeset
1243 // specific functions.
kono
parents:
diff changeset
1244 void
kono
parents:
diff changeset
1245 specific_type_functions(Gogo*, Named_type*, int64_t size,
kono
parents:
diff changeset
1246 Function_type* hash_fntype,
kono
parents:
diff changeset
1247 Function_type* equal_fntype, Named_object** hash_fn,
kono
parents:
diff changeset
1248 Named_object** equal_fn);
kono
parents:
diff changeset
1249
kono
parents:
diff changeset
1250 void
kono
parents:
diff changeset
1251 write_identity_hash(Gogo*, int64_t size);
kono
parents:
diff changeset
1252
kono
parents:
diff changeset
1253 void
kono
parents:
diff changeset
1254 write_identity_equal(Gogo*, int64_t size);
kono
parents:
diff changeset
1255
kono
parents:
diff changeset
1256 void
kono
parents:
diff changeset
1257 write_named_hash(Gogo*, Named_type*, Function_type* hash_fntype,
kono
parents:
diff changeset
1258 Function_type* equal_fntype);
kono
parents:
diff changeset
1259
kono
parents:
diff changeset
1260 void
kono
parents:
diff changeset
1261 write_named_equal(Gogo*, Named_type*);
kono
parents:
diff changeset
1262
kono
parents:
diff changeset
1263 // Build a composite literal for the uncommon type information.
kono
parents:
diff changeset
1264 Expression*
kono
parents:
diff changeset
1265 uncommon_type_constructor(Gogo*, Type* uncommon_type,
kono
parents:
diff changeset
1266 Named_type*, const Methods*,
kono
parents:
diff changeset
1267 bool only_value_methods) const;
kono
parents:
diff changeset
1268
kono
parents:
diff changeset
1269 // Build a composite literal for the methods.
kono
parents:
diff changeset
1270 Expression*
kono
parents:
diff changeset
1271 methods_constructor(Gogo*, Type* methods_type, const Methods*,
kono
parents:
diff changeset
1272 bool only_value_methods) const;
kono
parents:
diff changeset
1273
kono
parents:
diff changeset
1274 // Build a composite literal for one method.
kono
parents:
diff changeset
1275 Expression*
kono
parents:
diff changeset
1276 method_constructor(Gogo*, Type* method_type, const std::string& name,
kono
parents:
diff changeset
1277 const Method*, bool only_value_methods) const;
kono
parents:
diff changeset
1278
kono
parents:
diff changeset
1279 // Add all methods for TYPE to the list of methods for THIS.
kono
parents:
diff changeset
1280 static void
kono
parents:
diff changeset
1281 add_methods_for_type(const Type* type, const Method::Field_indexes*,
kono
parents:
diff changeset
1282 unsigned int depth, bool, bool,
kono
parents:
diff changeset
1283 std::vector<const Named_type*>*,
kono
parents:
diff changeset
1284 Methods*);
kono
parents:
diff changeset
1285
kono
parents:
diff changeset
1286 static void
kono
parents:
diff changeset
1287 add_local_methods_for_type(const Named_type* type,
kono
parents:
diff changeset
1288 const Method::Field_indexes*,
kono
parents:
diff changeset
1289 unsigned int depth, bool, bool, Methods*);
kono
parents:
diff changeset
1290
kono
parents:
diff changeset
1291 static void
kono
parents:
diff changeset
1292 add_embedded_methods_for_type(const Type* type,
kono
parents:
diff changeset
1293 const Method::Field_indexes*,
kono
parents:
diff changeset
1294 unsigned int depth, bool, bool,
kono
parents:
diff changeset
1295 std::vector<const Named_type*>*,
kono
parents:
diff changeset
1296 Methods*);
kono
parents:
diff changeset
1297
kono
parents:
diff changeset
1298 static void
kono
parents:
diff changeset
1299 add_interface_methods_for_type(const Type* type,
kono
parents:
diff changeset
1300 const Method::Field_indexes*,
kono
parents:
diff changeset
1301 unsigned int depth, Methods*);
kono
parents:
diff changeset
1302
kono
parents:
diff changeset
1303 // Build stub methods for a type.
kono
parents:
diff changeset
1304 static void
kono
parents:
diff changeset
1305 build_stub_methods(Gogo*, const Type* type, const Methods* methods,
kono
parents:
diff changeset
1306 Location);
kono
parents:
diff changeset
1307
kono
parents:
diff changeset
1308 static void
kono
parents:
diff changeset
1309 build_one_stub_method(Gogo*, Method*, const char* receiver_name,
kono
parents:
diff changeset
1310 const Typed_identifier_list*, bool is_varargs,
kono
parents:
diff changeset
1311 Location);
kono
parents:
diff changeset
1312
kono
parents:
diff changeset
1313 static Expression*
kono
parents:
diff changeset
1314 apply_field_indexes(Expression*, const Method::Field_indexes*,
kono
parents:
diff changeset
1315 Location);
kono
parents:
diff changeset
1316
kono
parents:
diff changeset
1317 // Look for a field or method named NAME in TYPE.
kono
parents:
diff changeset
1318 static bool
kono
parents:
diff changeset
1319 find_field_or_method(const Type* type, const std::string& name,
kono
parents:
diff changeset
1320 bool receiver_can_be_pointer,
kono
parents:
diff changeset
1321 std::vector<const Named_type*>*, int* level,
kono
parents:
diff changeset
1322 bool* is_method, bool* found_pointer_method,
kono
parents:
diff changeset
1323 std::string* ambig1, std::string* ambig2);
kono
parents:
diff changeset
1324
kono
parents:
diff changeset
1325 // Get the backend representation for a type without looking in the
kono
parents:
diff changeset
1326 // hash table for identical types.
kono
parents:
diff changeset
1327 Btype*
kono
parents:
diff changeset
1328 get_btype_without_hash(Gogo*);
kono
parents:
diff changeset
1329
kono
parents:
diff changeset
1330 // A backend type that may be a placeholder.
kono
parents:
diff changeset
1331 struct Type_btype_entry
kono
parents:
diff changeset
1332 {
kono
parents:
diff changeset
1333 Btype *btype;
kono
parents:
diff changeset
1334 bool is_placeholder;
kono
parents:
diff changeset
1335 };
kono
parents:
diff changeset
1336
kono
parents:
diff changeset
1337 // A mapping from Type to Btype*, used to ensure that the backend
kono
parents:
diff changeset
1338 // representation of identical types is identical. This is only
kono
parents:
diff changeset
1339 // used for unnamed types.
kono
parents:
diff changeset
1340 typedef Unordered_map_hash(const Type*, Type_btype_entry,
kono
parents:
diff changeset
1341 Type_hash_identical, Type_identical) Type_btypes;
kono
parents:
diff changeset
1342
kono
parents:
diff changeset
1343 static Type_btypes type_btypes;
kono
parents:
diff changeset
1344
kono
parents:
diff changeset
1345 // A list of builtin named types.
kono
parents:
diff changeset
1346 static std::vector<Named_type*> named_builtin_types;
kono
parents:
diff changeset
1347
kono
parents:
diff changeset
1348 // A map from types which need specific type functions to the type
kono
parents:
diff changeset
1349 // functions themselves.
kono
parents:
diff changeset
1350 typedef std::pair<Named_object*, Named_object*> Hash_equal_fn;
kono
parents:
diff changeset
1351 typedef Unordered_map_hash(const Type*, Hash_equal_fn, Type_hash_identical,
kono
parents:
diff changeset
1352 Type_identical) Type_functions;
kono
parents:
diff changeset
1353
kono
parents:
diff changeset
1354 static Type_functions type_functions_table;
kono
parents:
diff changeset
1355
kono
parents:
diff changeset
1356 // Cache for reusing existing pointer types; maps from pointed-to-type
kono
parents:
diff changeset
1357 // to pointer type.
kono
parents:
diff changeset
1358 typedef Unordered_map(Type*, Pointer_type*) Pointer_type_table;
kono
parents:
diff changeset
1359
kono
parents:
diff changeset
1360 static Pointer_type_table pointer_types;
kono
parents:
diff changeset
1361
kono
parents:
diff changeset
1362 // List of placeholder pointer types.
kono
parents:
diff changeset
1363 static std::vector<Pointer_type*> placeholder_pointers;
kono
parents:
diff changeset
1364
kono
parents:
diff changeset
1365 // The type classification.
kono
parents:
diff changeset
1366 Type_classification classification_;
kono
parents:
diff changeset
1367 // The backend representation of the type, once it has been
kono
parents:
diff changeset
1368 // determined.
kono
parents:
diff changeset
1369 Btype* btype_;
kono
parents:
diff changeset
1370 // The type descriptor for this type. This starts out as NULL and
kono
parents:
diff changeset
1371 // is filled in as needed.
kono
parents:
diff changeset
1372 Bvariable* type_descriptor_var_;
kono
parents:
diff changeset
1373 // The GC symbol for this type. This starts out as NULL and
kono
parents:
diff changeset
1374 // is filled in as needed.
kono
parents:
diff changeset
1375 Bvariable* gc_symbol_var_;
kono
parents:
diff changeset
1376 // Whether this type can appear in the heap.
kono
parents:
diff changeset
1377 bool in_heap_;
kono
parents:
diff changeset
1378 };
kono
parents:
diff changeset
1379
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1380 // Type hash table operations, treating aliases as identical to the
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1381 // types that they alias.
111
kono
parents:
diff changeset
1382
kono
parents:
diff changeset
1383 class Type_hash_identical
kono
parents:
diff changeset
1384 {
kono
parents:
diff changeset
1385 public:
kono
parents:
diff changeset
1386 unsigned int
kono
parents:
diff changeset
1387 operator()(const Type* type) const
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1388 {
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1389 return type->hash_for_method(NULL,
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1390 Type::COMPARE_ERRORS | Type::COMPARE_TAGS);
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1391 }
111
kono
parents:
diff changeset
1392 };
kono
parents:
diff changeset
1393
kono
parents:
diff changeset
1394 class Type_identical
kono
parents:
diff changeset
1395 {
kono
parents:
diff changeset
1396 public:
kono
parents:
diff changeset
1397 bool
kono
parents:
diff changeset
1398 operator()(const Type* t1, const Type* t2) const
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1399 {
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1400 return Type::are_identical(t1, t2,
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1401 Type::COMPARE_ERRORS | Type::COMPARE_TAGS,
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1402 NULL);
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1403 }
111
kono
parents:
diff changeset
1404 };
kono
parents:
diff changeset
1405
kono
parents:
diff changeset
1406 // An identifier with a type.
kono
parents:
diff changeset
1407
kono
parents:
diff changeset
1408 class Typed_identifier
kono
parents:
diff changeset
1409 {
kono
parents:
diff changeset
1410 public:
kono
parents:
diff changeset
1411 Typed_identifier(const std::string& name, Type* type,
kono
parents:
diff changeset
1412 Location location)
kono
parents:
diff changeset
1413 : name_(name), type_(type), location_(location), note_(NULL)
kono
parents:
diff changeset
1414 { }
kono
parents:
diff changeset
1415
kono
parents:
diff changeset
1416 // Get the name.
kono
parents:
diff changeset
1417 const std::string&
kono
parents:
diff changeset
1418 name() const
kono
parents:
diff changeset
1419 { return this->name_; }
kono
parents:
diff changeset
1420
kono
parents:
diff changeset
1421 // Get the type.
kono
parents:
diff changeset
1422 Type*
kono
parents:
diff changeset
1423 type() const
kono
parents:
diff changeset
1424 { return this->type_; }
kono
parents:
diff changeset
1425
kono
parents:
diff changeset
1426 // Return the location where the name was seen. This is not always
kono
parents:
diff changeset
1427 // meaningful.
kono
parents:
diff changeset
1428 Location
kono
parents:
diff changeset
1429 location() const
kono
parents:
diff changeset
1430 { return this->location_; }
kono
parents:
diff changeset
1431
kono
parents:
diff changeset
1432 // Set the type--sometimes we see the identifier before the type.
kono
parents:
diff changeset
1433 void
kono
parents:
diff changeset
1434 set_type(Type* type)
kono
parents:
diff changeset
1435 {
kono
parents:
diff changeset
1436 go_assert(this->type_ == NULL || type->is_error_type());
kono
parents:
diff changeset
1437 this->type_ = type;
kono
parents:
diff changeset
1438 }
kono
parents:
diff changeset
1439
kono
parents:
diff changeset
1440 // Get the escape note.
kono
parents:
diff changeset
1441 std::string*
kono
parents:
diff changeset
1442 note() const
kono
parents:
diff changeset
1443 { return this->note_; }
kono
parents:
diff changeset
1444
kono
parents:
diff changeset
1445 // Set the escape note.
kono
parents:
diff changeset
1446 void
kono
parents:
diff changeset
1447 set_note(const std::string& note)
kono
parents:
diff changeset
1448 { this->note_ = new std::string(note); }
kono
parents:
diff changeset
1449
kono
parents:
diff changeset
1450 private:
kono
parents:
diff changeset
1451 // Identifier name.
kono
parents:
diff changeset
1452 std::string name_;
kono
parents:
diff changeset
1453 // Type.
kono
parents:
diff changeset
1454 Type* type_;
kono
parents:
diff changeset
1455 // The location where the name was seen.
kono
parents:
diff changeset
1456 Location location_;
kono
parents:
diff changeset
1457 // Escape note for this typed identifier. Used when importing and exporting
kono
parents:
diff changeset
1458 // functions.
kono
parents:
diff changeset
1459 std::string* note_;
kono
parents:
diff changeset
1460 };
kono
parents:
diff changeset
1461
kono
parents:
diff changeset
1462 // A list of Typed_identifiers.
kono
parents:
diff changeset
1463
kono
parents:
diff changeset
1464 class Typed_identifier_list
kono
parents:
diff changeset
1465 {
kono
parents:
diff changeset
1466 public:
kono
parents:
diff changeset
1467 Typed_identifier_list()
kono
parents:
diff changeset
1468 : entries_()
kono
parents:
diff changeset
1469 { }
kono
parents:
diff changeset
1470
kono
parents:
diff changeset
1471 // Whether the list is empty.
kono
parents:
diff changeset
1472 bool
kono
parents:
diff changeset
1473 empty() const
kono
parents:
diff changeset
1474 { return this->entries_.empty(); }
kono
parents:
diff changeset
1475
kono
parents:
diff changeset
1476 // Return the number of entries in the list.
kono
parents:
diff changeset
1477 size_t
kono
parents:
diff changeset
1478 size() const
kono
parents:
diff changeset
1479 { return this->entries_.size(); }
kono
parents:
diff changeset
1480
kono
parents:
diff changeset
1481 // Add an entry to the end of the list.
kono
parents:
diff changeset
1482 void
kono
parents:
diff changeset
1483 push_back(const Typed_identifier& td)
kono
parents:
diff changeset
1484 { this->entries_.push_back(td); }
kono
parents:
diff changeset
1485
kono
parents:
diff changeset
1486 // Remove an entry from the end of the list.
kono
parents:
diff changeset
1487 void
kono
parents:
diff changeset
1488 pop_back()
kono
parents:
diff changeset
1489 { this->entries_.pop_back(); }
kono
parents:
diff changeset
1490
kono
parents:
diff changeset
1491 // Set the type of entry I to TYPE.
kono
parents:
diff changeset
1492 void
kono
parents:
diff changeset
1493 set_type(size_t i, Type* type)
kono
parents:
diff changeset
1494 {
kono
parents:
diff changeset
1495 go_assert(i < this->entries_.size());
kono
parents:
diff changeset
1496 this->entries_[i].set_type(type);
kono
parents:
diff changeset
1497 }
kono
parents:
diff changeset
1498
kono
parents:
diff changeset
1499 // Sort the entries by name.
kono
parents:
diff changeset
1500 void
kono
parents:
diff changeset
1501 sort_by_name();
kono
parents:
diff changeset
1502
kono
parents:
diff changeset
1503 // Traverse types.
kono
parents:
diff changeset
1504 int
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1505 traverse(Traverse*) const;
111
kono
parents:
diff changeset
1506
kono
parents:
diff changeset
1507 // Return the first and last elements.
kono
parents:
diff changeset
1508 Typed_identifier&
kono
parents:
diff changeset
1509 front()
kono
parents:
diff changeset
1510 { return this->entries_.front(); }
kono
parents:
diff changeset
1511
kono
parents:
diff changeset
1512 const Typed_identifier&
kono
parents:
diff changeset
1513 front() const
kono
parents:
diff changeset
1514 { return this->entries_.front(); }
kono
parents:
diff changeset
1515
kono
parents:
diff changeset
1516 Typed_identifier&
kono
parents:
diff changeset
1517 back()
kono
parents:
diff changeset
1518 { return this->entries_.back(); }
kono
parents:
diff changeset
1519
kono
parents:
diff changeset
1520 const Typed_identifier&
kono
parents:
diff changeset
1521 back() const
kono
parents:
diff changeset
1522 { return this->entries_.back(); }
kono
parents:
diff changeset
1523
kono
parents:
diff changeset
1524 Typed_identifier&
kono
parents:
diff changeset
1525 at(size_t i)
kono
parents:
diff changeset
1526 { return this->entries_.at(i); }
kono
parents:
diff changeset
1527
kono
parents:
diff changeset
1528 const Typed_identifier&
kono
parents:
diff changeset
1529 at(size_t i) const
kono
parents:
diff changeset
1530 { return this->entries_.at(i); }
kono
parents:
diff changeset
1531
kono
parents:
diff changeset
1532 void
kono
parents:
diff changeset
1533 set(size_t i, const Typed_identifier& t)
kono
parents:
diff changeset
1534 { this->entries_.at(i) = t; }
kono
parents:
diff changeset
1535
kono
parents:
diff changeset
1536 void
kono
parents:
diff changeset
1537 resize(size_t c)
kono
parents:
diff changeset
1538 {
kono
parents:
diff changeset
1539 go_assert(c <= this->entries_.size());
kono
parents:
diff changeset
1540 this->entries_.resize(c, Typed_identifier("", NULL,
kono
parents:
diff changeset
1541 Linemap::unknown_location()));
kono
parents:
diff changeset
1542 }
kono
parents:
diff changeset
1543
kono
parents:
diff changeset
1544 void
kono
parents:
diff changeset
1545 reserve(size_t c)
kono
parents:
diff changeset
1546 { this->entries_.reserve(c); }
kono
parents:
diff changeset
1547
kono
parents:
diff changeset
1548 // Iterators.
kono
parents:
diff changeset
1549
kono
parents:
diff changeset
1550 typedef std::vector<Typed_identifier>::iterator iterator;
kono
parents:
diff changeset
1551 typedef std::vector<Typed_identifier>::const_iterator const_iterator;
kono
parents:
diff changeset
1552
kono
parents:
diff changeset
1553 iterator
kono
parents:
diff changeset
1554 begin()
kono
parents:
diff changeset
1555 { return this->entries_.begin(); }
kono
parents:
diff changeset
1556
kono
parents:
diff changeset
1557 const_iterator
kono
parents:
diff changeset
1558 begin() const
kono
parents:
diff changeset
1559 { return this->entries_.begin(); }
kono
parents:
diff changeset
1560
kono
parents:
diff changeset
1561 iterator
kono
parents:
diff changeset
1562 end()
kono
parents:
diff changeset
1563 { return this->entries_.end(); }
kono
parents:
diff changeset
1564
kono
parents:
diff changeset
1565 const_iterator
kono
parents:
diff changeset
1566 end() const
kono
parents:
diff changeset
1567 { return this->entries_.end(); }
kono
parents:
diff changeset
1568
kono
parents:
diff changeset
1569 // Return a copy of this list. This returns an independent copy of
kono
parents:
diff changeset
1570 // the vector, but does not copy the types.
kono
parents:
diff changeset
1571 Typed_identifier_list*
kono
parents:
diff changeset
1572 copy() const;
kono
parents:
diff changeset
1573
kono
parents:
diff changeset
1574 private:
kono
parents:
diff changeset
1575 std::vector<Typed_identifier> entries_;
kono
parents:
diff changeset
1576 };
kono
parents:
diff changeset
1577
kono
parents:
diff changeset
1578 // A type used to indicate a parsing error. This exists to simplify
kono
parents:
diff changeset
1579 // later error detection.
kono
parents:
diff changeset
1580
kono
parents:
diff changeset
1581 class Error_type : public Type
kono
parents:
diff changeset
1582 {
kono
parents:
diff changeset
1583 public:
kono
parents:
diff changeset
1584 Error_type()
kono
parents:
diff changeset
1585 : Type(TYPE_ERROR)
kono
parents:
diff changeset
1586 { }
kono
parents:
diff changeset
1587
kono
parents:
diff changeset
1588 protected:
kono
parents:
diff changeset
1589 bool
kono
parents:
diff changeset
1590 do_compare_is_identity(Gogo*)
kono
parents:
diff changeset
1591 { return false; }
kono
parents:
diff changeset
1592
kono
parents:
diff changeset
1593 Btype*
kono
parents:
diff changeset
1594 do_get_backend(Gogo* gogo);
kono
parents:
diff changeset
1595
kono
parents:
diff changeset
1596 Expression*
kono
parents:
diff changeset
1597 do_type_descriptor(Gogo*, Named_type*);
kono
parents:
diff changeset
1598
kono
parents:
diff changeset
1599 void
kono
parents:
diff changeset
1600 do_reflection(Gogo*, std::string*) const;
kono
parents:
diff changeset
1601
kono
parents:
diff changeset
1602 void
kono
parents:
diff changeset
1603 do_mangled_name(Gogo*, std::string* ret) const;
kono
parents:
diff changeset
1604 };
kono
parents:
diff changeset
1605
kono
parents:
diff changeset
1606 // The void type.
kono
parents:
diff changeset
1607
kono
parents:
diff changeset
1608 class Void_type : public Type
kono
parents:
diff changeset
1609 {
kono
parents:
diff changeset
1610 public:
kono
parents:
diff changeset
1611 Void_type()
kono
parents:
diff changeset
1612 : Type(TYPE_VOID)
kono
parents:
diff changeset
1613 { }
kono
parents:
diff changeset
1614
kono
parents:
diff changeset
1615 protected:
kono
parents:
diff changeset
1616 bool
kono
parents:
diff changeset
1617 do_compare_is_identity(Gogo*)
kono
parents:
diff changeset
1618 { return false; }
kono
parents:
diff changeset
1619
kono
parents:
diff changeset
1620 Btype*
kono
parents:
diff changeset
1621 do_get_backend(Gogo* gogo);
kono
parents:
diff changeset
1622
kono
parents:
diff changeset
1623 Expression*
kono
parents:
diff changeset
1624 do_type_descriptor(Gogo*, Named_type*)
kono
parents:
diff changeset
1625 { go_unreachable(); }
kono
parents:
diff changeset
1626
kono
parents:
diff changeset
1627 void
kono
parents:
diff changeset
1628 do_reflection(Gogo*, std::string*) const
kono
parents:
diff changeset
1629 { }
kono
parents:
diff changeset
1630
kono
parents:
diff changeset
1631 void
kono
parents:
diff changeset
1632 do_mangled_name(Gogo*, std::string* ret) const;
kono
parents:
diff changeset
1633 };
kono
parents:
diff changeset
1634
kono
parents:
diff changeset
1635 // The boolean type.
kono
parents:
diff changeset
1636
kono
parents:
diff changeset
1637 class Boolean_type : public Type
kono
parents:
diff changeset
1638 {
kono
parents:
diff changeset
1639 public:
kono
parents:
diff changeset
1640 Boolean_type()
kono
parents:
diff changeset
1641 : Type(TYPE_BOOLEAN)
kono
parents:
diff changeset
1642 { }
kono
parents:
diff changeset
1643
kono
parents:
diff changeset
1644 protected:
kono
parents:
diff changeset
1645 bool
kono
parents:
diff changeset
1646 do_compare_is_identity(Gogo*)
kono
parents:
diff changeset
1647 { return true; }
kono
parents:
diff changeset
1648
kono
parents:
diff changeset
1649 Btype*
kono
parents:
diff changeset
1650 do_get_backend(Gogo* gogo);
kono
parents:
diff changeset
1651
kono
parents:
diff changeset
1652 Expression*
kono
parents:
diff changeset
1653 do_type_descriptor(Gogo*, Named_type* name);
kono
parents:
diff changeset
1654
kono
parents:
diff changeset
1655 // We should not be asked for the reflection string of a basic type.
kono
parents:
diff changeset
1656 void
kono
parents:
diff changeset
1657 do_reflection(Gogo*, std::string* ret) const
kono
parents:
diff changeset
1658 { ret->append("bool"); }
kono
parents:
diff changeset
1659
kono
parents:
diff changeset
1660 void
kono
parents:
diff changeset
1661 do_mangled_name(Gogo*, std::string* ret) const;
kono
parents:
diff changeset
1662 };
kono
parents:
diff changeset
1663
kono
parents:
diff changeset
1664 // The type of an integer.
kono
parents:
diff changeset
1665
kono
parents:
diff changeset
1666 class Integer_type : public Type
kono
parents:
diff changeset
1667 {
kono
parents:
diff changeset
1668 public:
kono
parents:
diff changeset
1669 // Create a new integer type.
kono
parents:
diff changeset
1670 static Named_type*
kono
parents:
diff changeset
1671 create_integer_type(const char* name, bool is_unsigned, int bits,
kono
parents:
diff changeset
1672 int runtime_type_kind);
kono
parents:
diff changeset
1673
kono
parents:
diff changeset
1674 // Look up an existing integer type.
kono
parents:
diff changeset
1675 static Named_type*
kono
parents:
diff changeset
1676 lookup_integer_type(const char* name);
kono
parents:
diff changeset
1677
kono
parents:
diff changeset
1678 // Create an abstract integer type.
kono
parents:
diff changeset
1679 static Integer_type*
kono
parents:
diff changeset
1680 create_abstract_integer_type();
kono
parents:
diff changeset
1681
kono
parents:
diff changeset
1682 // Create an abstract character type.
kono
parents:
diff changeset
1683 static Integer_type*
kono
parents:
diff changeset
1684 create_abstract_character_type();
kono
parents:
diff changeset
1685
kono
parents:
diff changeset
1686 // Whether this is an abstract integer type.
kono
parents:
diff changeset
1687 bool
kono
parents:
diff changeset
1688 is_abstract() const
kono
parents:
diff changeset
1689 { return this->is_abstract_; }
kono
parents:
diff changeset
1690
kono
parents:
diff changeset
1691 // Whether this is an unsigned type.
kono
parents:
diff changeset
1692 bool
kono
parents:
diff changeset
1693 is_unsigned() const
kono
parents:
diff changeset
1694 { return this->is_unsigned_; }
kono
parents:
diff changeset
1695
kono
parents:
diff changeset
1696 // The number of bits.
kono
parents:
diff changeset
1697 int
kono
parents:
diff changeset
1698 bits() const
kono
parents:
diff changeset
1699 { return this->bits_; }
kono
parents:
diff changeset
1700
kono
parents:
diff changeset
1701 // Whether this type is the same as T.
kono
parents:
diff changeset
1702 bool
kono
parents:
diff changeset
1703 is_identical(const Integer_type* t) const;
kono
parents:
diff changeset
1704
kono
parents:
diff changeset
1705 // Whether this is the type "byte" or another name for "byte".
kono
parents:
diff changeset
1706 bool
kono
parents:
diff changeset
1707 is_byte() const
kono
parents:
diff changeset
1708 { return this->is_byte_; }
kono
parents:
diff changeset
1709
kono
parents:
diff changeset
1710 // Mark this as the "byte" type.
kono
parents:
diff changeset
1711 void
kono
parents:
diff changeset
1712 set_is_byte()
kono
parents:
diff changeset
1713 { this->is_byte_ = true; }
kono
parents:
diff changeset
1714
kono
parents:
diff changeset
1715 // Whether this is the type "rune" or another name for "rune".
kono
parents:
diff changeset
1716 bool
kono
parents:
diff changeset
1717 is_rune() const
kono
parents:
diff changeset
1718 { return this->is_rune_; }
kono
parents:
diff changeset
1719
kono
parents:
diff changeset
1720 // Mark this as the "rune" type.
kono
parents:
diff changeset
1721 void
kono
parents:
diff changeset
1722 set_is_rune()
kono
parents:
diff changeset
1723 { this->is_rune_ = true; }
kono
parents:
diff changeset
1724
kono
parents:
diff changeset
1725 protected:
kono
parents:
diff changeset
1726 bool
kono
parents:
diff changeset
1727 do_compare_is_identity(Gogo*)
kono
parents:
diff changeset
1728 { return true; }
kono
parents:
diff changeset
1729
kono
parents:
diff changeset
1730 unsigned int
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1731 do_hash_for_method(Gogo*, int) const;
111
kono
parents:
diff changeset
1732
kono
parents:
diff changeset
1733 Btype*
kono
parents:
diff changeset
1734 do_get_backend(Gogo*);
kono
parents:
diff changeset
1735
kono
parents:
diff changeset
1736 Expression*
kono
parents:
diff changeset
1737 do_type_descriptor(Gogo*, Named_type*);
kono
parents:
diff changeset
1738
kono
parents:
diff changeset
1739 void
kono
parents:
diff changeset
1740 do_reflection(Gogo*, std::string*) const;
kono
parents:
diff changeset
1741
kono
parents:
diff changeset
1742 void
kono
parents:
diff changeset
1743 do_mangled_name(Gogo*, std::string*) const;
kono
parents:
diff changeset
1744
kono
parents:
diff changeset
1745 private:
kono
parents:
diff changeset
1746 Integer_type(bool is_abstract, bool is_unsigned, int bits,
kono
parents:
diff changeset
1747 int runtime_type_kind)
kono
parents:
diff changeset
1748 : Type(TYPE_INTEGER),
kono
parents:
diff changeset
1749 is_abstract_(is_abstract), is_unsigned_(is_unsigned), is_byte_(false),
kono
parents:
diff changeset
1750 is_rune_(false), bits_(bits), runtime_type_kind_(runtime_type_kind)
kono
parents:
diff changeset
1751 { }
kono
parents:
diff changeset
1752
kono
parents:
diff changeset
1753 // Map names of integer types to the types themselves.
kono
parents:
diff changeset
1754 typedef std::map<std::string, Named_type*> Named_integer_types;
kono
parents:
diff changeset
1755 static Named_integer_types named_integer_types;
kono
parents:
diff changeset
1756
kono
parents:
diff changeset
1757 // True if this is an abstract type.
kono
parents:
diff changeset
1758 bool is_abstract_;
kono
parents:
diff changeset
1759 // True if this is an unsigned type.
kono
parents:
diff changeset
1760 bool is_unsigned_;
kono
parents:
diff changeset
1761 // True if this is the byte type.
kono
parents:
diff changeset
1762 bool is_byte_;
kono
parents:
diff changeset
1763 // True if this is the rune type.
kono
parents:
diff changeset
1764 bool is_rune_;
kono
parents:
diff changeset
1765 // The number of bits.
kono
parents:
diff changeset
1766 int bits_;
kono
parents:
diff changeset
1767 // The runtime type code used in the type descriptor for this type.
kono
parents:
diff changeset
1768 int runtime_type_kind_;
kono
parents:
diff changeset
1769 };
kono
parents:
diff changeset
1770
kono
parents:
diff changeset
1771 // The type of a floating point number.
kono
parents:
diff changeset
1772
kono
parents:
diff changeset
1773 class Float_type : public Type
kono
parents:
diff changeset
1774 {
kono
parents:
diff changeset
1775 public:
kono
parents:
diff changeset
1776 // Create a new float type.
kono
parents:
diff changeset
1777 static Named_type*
kono
parents:
diff changeset
1778 create_float_type(const char* name, int bits, int runtime_type_kind);
kono
parents:
diff changeset
1779
kono
parents:
diff changeset
1780 // Look up an existing float type.
kono
parents:
diff changeset
1781 static Named_type*
kono
parents:
diff changeset
1782 lookup_float_type(const char* name);
kono
parents:
diff changeset
1783
kono
parents:
diff changeset
1784 // Create an abstract float type.
kono
parents:
diff changeset
1785 static Float_type*
kono
parents:
diff changeset
1786 create_abstract_float_type();
kono
parents:
diff changeset
1787
kono
parents:
diff changeset
1788 // Whether this is an abstract float type.
kono
parents:
diff changeset
1789 bool
kono
parents:
diff changeset
1790 is_abstract() const
kono
parents:
diff changeset
1791 { return this->is_abstract_; }
kono
parents:
diff changeset
1792
kono
parents:
diff changeset
1793 // The number of bits.
kono
parents:
diff changeset
1794 int
kono
parents:
diff changeset
1795 bits() const
kono
parents:
diff changeset
1796 { return this->bits_; }
kono
parents:
diff changeset
1797
kono
parents:
diff changeset
1798 // Whether this type is the same as T.
kono
parents:
diff changeset
1799 bool
kono
parents:
diff changeset
1800 is_identical(const Float_type* t) const;
kono
parents:
diff changeset
1801
kono
parents:
diff changeset
1802 protected:
kono
parents:
diff changeset
1803 bool
kono
parents:
diff changeset
1804 do_compare_is_identity(Gogo*)
kono
parents:
diff changeset
1805 { return false; }
kono
parents:
diff changeset
1806
kono
parents:
diff changeset
1807 bool
kono
parents:
diff changeset
1808 do_is_reflexive()
kono
parents:
diff changeset
1809 { return false; }
kono
parents:
diff changeset
1810
kono
parents:
diff changeset
1811 // Distinction between +0 and -0 requires a key update.
kono
parents:
diff changeset
1812 bool
kono
parents:
diff changeset
1813 do_needs_key_update()
kono
parents:
diff changeset
1814 { return true; }
kono
parents:
diff changeset
1815
kono
parents:
diff changeset
1816 unsigned int
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1817 do_hash_for_method(Gogo*, int) const;
111
kono
parents:
diff changeset
1818
kono
parents:
diff changeset
1819 Btype*
kono
parents:
diff changeset
1820 do_get_backend(Gogo*);
kono
parents:
diff changeset
1821
kono
parents:
diff changeset
1822 Expression*
kono
parents:
diff changeset
1823 do_type_descriptor(Gogo*, Named_type*);
kono
parents:
diff changeset
1824
kono
parents:
diff changeset
1825 void
kono
parents:
diff changeset
1826 do_reflection(Gogo*, std::string*) const;
kono
parents:
diff changeset
1827
kono
parents:
diff changeset
1828 void
kono
parents:
diff changeset
1829 do_mangled_name(Gogo*, std::string*) const;
kono
parents:
diff changeset
1830
kono
parents:
diff changeset
1831 private:
kono
parents:
diff changeset
1832 Float_type(bool is_abstract, int bits, int runtime_type_kind)
kono
parents:
diff changeset
1833 : Type(TYPE_FLOAT),
kono
parents:
diff changeset
1834 is_abstract_(is_abstract), bits_(bits),
kono
parents:
diff changeset
1835 runtime_type_kind_(runtime_type_kind)
kono
parents:
diff changeset
1836 { }
kono
parents:
diff changeset
1837
kono
parents:
diff changeset
1838 // Map names of float types to the types themselves.
kono
parents:
diff changeset
1839 typedef std::map<std::string, Named_type*> Named_float_types;
kono
parents:
diff changeset
1840 static Named_float_types named_float_types;
kono
parents:
diff changeset
1841
kono
parents:
diff changeset
1842 // True if this is an abstract type.
kono
parents:
diff changeset
1843 bool is_abstract_;
kono
parents:
diff changeset
1844 // The number of bits in the floating point value.
kono
parents:
diff changeset
1845 int bits_;
kono
parents:
diff changeset
1846 // The runtime type code used in the type descriptor for this type.
kono
parents:
diff changeset
1847 int runtime_type_kind_;
kono
parents:
diff changeset
1848 };
kono
parents:
diff changeset
1849
kono
parents:
diff changeset
1850 // The type of a complex number.
kono
parents:
diff changeset
1851
kono
parents:
diff changeset
1852 class Complex_type : public Type
kono
parents:
diff changeset
1853 {
kono
parents:
diff changeset
1854 public:
kono
parents:
diff changeset
1855 // Create a new complex type.
kono
parents:
diff changeset
1856 static Named_type*
kono
parents:
diff changeset
1857 create_complex_type(const char* name, int bits, int runtime_type_kind);
kono
parents:
diff changeset
1858
kono
parents:
diff changeset
1859 // Look up an existing complex type.
kono
parents:
diff changeset
1860 static Named_type*
kono
parents:
diff changeset
1861 lookup_complex_type(const char* name);
kono
parents:
diff changeset
1862
kono
parents:
diff changeset
1863 // Create an abstract complex type.
kono
parents:
diff changeset
1864 static Complex_type*
kono
parents:
diff changeset
1865 create_abstract_complex_type();
kono
parents:
diff changeset
1866
kono
parents:
diff changeset
1867 // Whether this is an abstract complex type.
kono
parents:
diff changeset
1868 bool
kono
parents:
diff changeset
1869 is_abstract() const
kono
parents:
diff changeset
1870 { return this->is_abstract_; }
kono
parents:
diff changeset
1871
kono
parents:
diff changeset
1872 // The number of bits: 64 or 128.
kono
parents:
diff changeset
1873 int bits() const
kono
parents:
diff changeset
1874 { return this->bits_; }
kono
parents:
diff changeset
1875
kono
parents:
diff changeset
1876 // Whether this type is the same as T.
kono
parents:
diff changeset
1877 bool
kono
parents:
diff changeset
1878 is_identical(const Complex_type* t) const;
kono
parents:
diff changeset
1879
kono
parents:
diff changeset
1880 protected:
kono
parents:
diff changeset
1881 bool
kono
parents:
diff changeset
1882 do_compare_is_identity(Gogo*)
kono
parents:
diff changeset
1883 { return false; }
kono
parents:
diff changeset
1884
kono
parents:
diff changeset
1885 bool
kono
parents:
diff changeset
1886 do_is_reflexive()
kono
parents:
diff changeset
1887 { return false; }
kono
parents:
diff changeset
1888
kono
parents:
diff changeset
1889 // Distinction between +0 and -0 requires a key update.
kono
parents:
diff changeset
1890 bool
kono
parents:
diff changeset
1891 do_needs_key_update()
kono
parents:
diff changeset
1892 { return true; }
kono
parents:
diff changeset
1893
kono
parents:
diff changeset
1894 unsigned int
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
1895 do_hash_for_method(Gogo*, int) const;
111
kono
parents:
diff changeset
1896
kono
parents:
diff changeset
1897 Btype*
kono
parents:
diff changeset
1898 do_get_backend(Gogo*);
kono
parents:
diff changeset
1899
kono
parents:
diff changeset
1900 Expression*
kono
parents:
diff changeset
1901 do_type_descriptor(Gogo*, Named_type*);
kono
parents:
diff changeset
1902
kono
parents:
diff changeset
1903 void
kono
parents:
diff changeset
1904 do_reflection(Gogo*, std::string*) const;
kono
parents:
diff changeset
1905
kono
parents:
diff changeset
1906 void
kono
parents:
diff changeset
1907 do_mangled_name(Gogo*, std::string*) const;
kono
parents:
diff changeset
1908
kono
parents:
diff changeset
1909 private:
kono
parents:
diff changeset
1910 Complex_type(bool is_abstract, int bits, int runtime_type_kind)
kono
parents:
diff changeset
1911 : Type(TYPE_COMPLEX),
kono
parents:
diff changeset
1912 is_abstract_(is_abstract), bits_(bits),
kono
parents:
diff changeset
1913 runtime_type_kind_(runtime_type_kind)
kono
parents:
diff changeset
1914 { }
kono
parents:
diff changeset
1915
kono
parents:
diff changeset
1916 // Map names of complex types to the types themselves.
kono
parents:
diff changeset
1917 typedef std::map<std::string, Named_type*> Named_complex_types;
kono
parents:
diff changeset
1918 static Named_complex_types named_complex_types;
kono
parents:
diff changeset
1919
kono
parents:
diff changeset
1920 // True if this is an abstract type.
kono
parents:
diff changeset
1921 bool is_abstract_;
kono
parents:
diff changeset
1922 // The number of bits in the complex value--64 or 128.
kono
parents:
diff changeset
1923 int bits_;
kono
parents:
diff changeset
1924 // The runtime type code used in the type descriptor for this type.
kono
parents:
diff changeset
1925 int runtime_type_kind_;
kono
parents:
diff changeset
1926 };
kono
parents:
diff changeset
1927
kono
parents:
diff changeset
1928 // The type of a string.
kono
parents:
diff changeset
1929
kono
parents:
diff changeset
1930 class String_type : public Type
kono
parents:
diff changeset
1931 {
kono
parents:
diff changeset
1932 public:
kono
parents:
diff changeset
1933 String_type()
kono
parents:
diff changeset
1934 : Type(TYPE_STRING)
kono
parents:
diff changeset
1935 { }
kono
parents:
diff changeset
1936
kono
parents:
diff changeset
1937 protected:
kono
parents:
diff changeset
1938 bool
kono
parents:
diff changeset
1939 do_has_pointer() const
kono
parents:
diff changeset
1940 { return true; }
kono
parents:
diff changeset
1941
kono
parents:
diff changeset
1942 bool
kono
parents:
diff changeset
1943 do_compare_is_identity(Gogo*)
kono
parents:
diff changeset
1944 { return false; }
kono
parents:
diff changeset
1945
kono
parents:
diff changeset
1946 // New string might have a smaller backing store.
kono
parents:
diff changeset
1947 bool
kono
parents:
diff changeset
1948 do_needs_key_update()
kono
parents:
diff changeset
1949 { return true; }
kono
parents:
diff changeset
1950
kono
parents:
diff changeset
1951 Btype*
kono
parents:
diff changeset
1952 do_get_backend(Gogo*);
kono
parents:
diff changeset
1953
kono
parents:
diff changeset
1954 Expression*
kono
parents:
diff changeset
1955 do_type_descriptor(Gogo*, Named_type*);
kono
parents:
diff changeset
1956
kono
parents:
diff changeset
1957 void
kono
parents:
diff changeset
1958 do_reflection(Gogo*, std::string*) const;
kono
parents:
diff changeset
1959
kono
parents:
diff changeset
1960 void
kono
parents:
diff changeset
1961 do_mangled_name(Gogo*, std::string* ret) const;
kono
parents:
diff changeset
1962
kono
parents:
diff changeset
1963 private:
kono
parents:
diff changeset
1964 // The named string type.
kono
parents:
diff changeset
1965 static Named_type* string_type_;
kono
parents:
diff changeset
1966 };
kono
parents:
diff changeset
1967
kono
parents:
diff changeset
1968 // The type of a function.
kono
parents:
diff changeset
1969
kono
parents:
diff changeset
1970 class Function_type : public Type
kono
parents:
diff changeset
1971 {
kono
parents:
diff changeset
1972 public:
kono
parents:
diff changeset
1973 Function_type(Typed_identifier* receiver, Typed_identifier_list* parameters,
kono
parents:
diff changeset
1974 Typed_identifier_list* results, Location location)
kono
parents:
diff changeset
1975 : Type(TYPE_FUNCTION),
kono
parents:
diff changeset
1976 receiver_(receiver), parameters_(parameters), results_(results),
kono
parents:
diff changeset
1977 location_(location), is_varargs_(false), is_builtin_(false),
kono
parents:
diff changeset
1978 fnbtype_(NULL), is_tagged_(false)
kono
parents:
diff changeset
1979 { }
kono
parents:
diff changeset
1980
kono
parents:
diff changeset
1981 // Get the receiver.
kono
parents:
diff changeset
1982 const Typed_identifier*
kono
parents:
diff changeset
1983 receiver() const
kono
parents:
diff changeset
1984 { return this->receiver_; }
kono
parents:
diff changeset
1985
kono
parents:
diff changeset
1986 // Add an escape note for the receiver.
kono
parents:
diff changeset
1987 void
kono
parents:
diff changeset
1988 add_receiver_note(int encoding)
kono
parents:
diff changeset
1989 { this->receiver_->set_note(Escape_note::make_tag(encoding)); }
kono
parents:
diff changeset
1990
kono
parents:
diff changeset
1991 // Get the return names and types.
kono
parents:
diff changeset
1992 const Typed_identifier_list*
kono
parents:
diff changeset
1993 results() const
kono
parents:
diff changeset
1994 { return this->results_; }
kono
parents:
diff changeset
1995
kono
parents:
diff changeset
1996 // Get the parameter names and types.
kono
parents:
diff changeset
1997 const Typed_identifier_list*
kono
parents:
diff changeset
1998 parameters() const
kono
parents:
diff changeset
1999 { return this->parameters_; }
kono
parents:
diff changeset
2000
kono
parents:
diff changeset
2001 // Add an escape note for the ith parameter.
kono
parents:
diff changeset
2002 void
kono
parents:
diff changeset
2003 add_parameter_note(int index, int encoding)
kono
parents:
diff changeset
2004 { this->parameters_->at(index).set_note(Escape_note::make_tag(encoding)); }
kono
parents:
diff changeset
2005
kono
parents:
diff changeset
2006 // Whether this function has been tagged during escape analysis.
kono
parents:
diff changeset
2007 bool
kono
parents:
diff changeset
2008 is_tagged() const
kono
parents:
diff changeset
2009 { return this->is_tagged_; }
kono
parents:
diff changeset
2010
kono
parents:
diff changeset
2011 // Mark this function as tagged after analyzing its escape.
kono
parents:
diff changeset
2012 void
kono
parents:
diff changeset
2013 set_is_tagged()
kono
parents:
diff changeset
2014 { this->is_tagged_ = true; }
kono
parents:
diff changeset
2015
kono
parents:
diff changeset
2016 // Whether this is a varargs function.
kono
parents:
diff changeset
2017 bool
kono
parents:
diff changeset
2018 is_varargs() const
kono
parents:
diff changeset
2019 { return this->is_varargs_; }
kono
parents:
diff changeset
2020
kono
parents:
diff changeset
2021 // Whether this is a builtin function.
kono
parents:
diff changeset
2022 bool
kono
parents:
diff changeset
2023 is_builtin() const
kono
parents:
diff changeset
2024 { return this->is_builtin_; }
kono
parents:
diff changeset
2025
kono
parents:
diff changeset
2026 // The location where this type was defined.
kono
parents:
diff changeset
2027 Location
kono
parents:
diff changeset
2028 location() const
kono
parents:
diff changeset
2029 { return this->location_; }
kono
parents:
diff changeset
2030
kono
parents:
diff changeset
2031 // Return whether this is a method type.
kono
parents:
diff changeset
2032 bool
kono
parents:
diff changeset
2033 is_method() const
kono
parents:
diff changeset
2034 { return this->receiver_ != NULL; }
kono
parents:
diff changeset
2035
kono
parents:
diff changeset
2036 // Whether T is a valid redeclaration of this type. This is called
kono
parents:
diff changeset
2037 // when a function is declared more than once.
kono
parents:
diff changeset
2038 bool
kono
parents:
diff changeset
2039 is_valid_redeclaration(const Function_type* t, std::string*) const;
kono
parents:
diff changeset
2040
kono
parents:
diff changeset
2041 // Whether this type is the same as T.
kono
parents:
diff changeset
2042 bool
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
2043 is_identical(const Function_type* t, bool ignore_receiver, int flags,
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
2044 std::string*) const;
111
kono
parents:
diff changeset
2045
kono
parents:
diff changeset
2046 // Record that this is a varargs function.
kono
parents:
diff changeset
2047 void
kono
parents:
diff changeset
2048 set_is_varargs()
kono
parents:
diff changeset
2049 { this->is_varargs_ = true; }
kono
parents:
diff changeset
2050
kono
parents:
diff changeset
2051 // Record that this is a builtin function.
kono
parents:
diff changeset
2052 void
kono
parents:
diff changeset
2053 set_is_builtin()
kono
parents:
diff changeset
2054 { this->is_builtin_ = true; }
kono
parents:
diff changeset
2055
kono
parents:
diff changeset
2056 // Import a function type.
kono
parents:
diff changeset
2057 static Function_type*
kono
parents:
diff changeset
2058 do_import(Import*);
kono
parents:
diff changeset
2059
kono
parents:
diff changeset
2060 // Return a copy of this type without a receiver. This is only
kono
parents:
diff changeset
2061 // valid for a method type.
kono
parents:
diff changeset
2062 Function_type*
kono
parents:
diff changeset
2063 copy_without_receiver() const;
kono
parents:
diff changeset
2064
kono
parents:
diff changeset
2065 // Return a copy of this type with a receiver. This is used when an
kono
parents:
diff changeset
2066 // interface method is attached to a named or struct type.
kono
parents:
diff changeset
2067 Function_type*
kono
parents:
diff changeset
2068 copy_with_receiver(Type*) const;
kono
parents:
diff changeset
2069
kono
parents:
diff changeset
2070 // Return a copy of this type with the receiver treated as the first
kono
parents:
diff changeset
2071 // parameter. If WANT_POINTER_RECEIVER is true, the receiver is
kono
parents:
diff changeset
2072 // forced to be a pointer.
kono
parents:
diff changeset
2073 Function_type*
kono
parents:
diff changeset
2074 copy_with_receiver_as_param(bool want_pointer_receiver) const;
kono
parents:
diff changeset
2075
kono
parents:
diff changeset
2076 // Return a copy of this type ignoring any receiver and using dummy
kono
parents:
diff changeset
2077 // names for all parameters. This is used for thunks for method
kono
parents:
diff changeset
2078 // values.
kono
parents:
diff changeset
2079 Function_type*
kono
parents:
diff changeset
2080 copy_with_names() const;
kono
parents:
diff changeset
2081
kono
parents:
diff changeset
2082 static Type*
kono
parents:
diff changeset
2083 make_function_type_descriptor_type();
kono
parents:
diff changeset
2084
kono
parents:
diff changeset
2085 // Return the backend representation of this function type. This is used
kono
parents:
diff changeset
2086 // as the real type of a backend function declaration or defintion.
kono
parents:
diff changeset
2087 Btype*
kono
parents:
diff changeset
2088 get_backend_fntype(Gogo*);
kono
parents:
diff changeset
2089
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
2090 // Return whether this is a Backend_function_type.
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
2091 virtual bool
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
2092 is_backend_function_type() const
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
2093 { return false; }
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
2094
111
kono
parents:
diff changeset
2095 protected:
kono
parents:
diff changeset
2096 int
kono
parents:
diff changeset
2097 do_traverse(Traverse*);
kono
parents:
diff changeset
2098
kono
parents:
diff changeset
2099 // A function descriptor may be allocated on the heap.
kono
parents:
diff changeset
2100 bool
kono
parents:
diff changeset
2101 do_has_pointer() const
kono
parents:
diff changeset
2102 { return true; }
kono
parents:
diff changeset
2103
kono
parents:
diff changeset
2104 bool
kono
parents:
diff changeset
2105 do_compare_is_identity(Gogo*)
kono
parents:
diff changeset
2106 { return false; }
kono
parents:
diff changeset
2107
kono
parents:
diff changeset
2108 unsigned int
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
2109 do_hash_for_method(Gogo*, int) const;
111
kono
parents:
diff changeset
2110
kono
parents:
diff changeset
2111 Btype*
kono
parents:
diff changeset
2112 do_get_backend(Gogo*);
kono
parents:
diff changeset
2113
kono
parents:
diff changeset
2114 Expression*
kono
parents:
diff changeset
2115 do_type_descriptor(Gogo*, Named_type*);
kono
parents:
diff changeset
2116
kono
parents:
diff changeset
2117 void
kono
parents:
diff changeset
2118 do_reflection(Gogo*, std::string*) const;
kono
parents:
diff changeset
2119
kono
parents:
diff changeset
2120 void
kono
parents:
diff changeset
2121 do_mangled_name(Gogo*, std::string*) const;
kono
parents:
diff changeset
2122
kono
parents:
diff changeset
2123 void
kono
parents:
diff changeset
2124 do_export(Export*) const;
kono
parents:
diff changeset
2125
kono
parents:
diff changeset
2126 private:
kono
parents:
diff changeset
2127 Expression*
kono
parents:
diff changeset
2128 type_descriptor_params(Type*, const Typed_identifier*,
kono
parents:
diff changeset
2129 const Typed_identifier_list*);
kono
parents:
diff changeset
2130
kono
parents:
diff changeset
2131 // A mapping from a list of result types to a backend struct type.
kono
parents:
diff changeset
2132 class Results_hash
kono
parents:
diff changeset
2133 {
kono
parents:
diff changeset
2134 public:
kono
parents:
diff changeset
2135 unsigned int
kono
parents:
diff changeset
2136 operator()(const Typed_identifier_list*) const;
kono
parents:
diff changeset
2137 };
kono
parents:
diff changeset
2138
kono
parents:
diff changeset
2139 class Results_equal
kono
parents:
diff changeset
2140 {
kono
parents:
diff changeset
2141 public:
kono
parents:
diff changeset
2142 bool
kono
parents:
diff changeset
2143 operator()(const Typed_identifier_list*,
kono
parents:
diff changeset
2144 const Typed_identifier_list*) const;
kono
parents:
diff changeset
2145 };
kono
parents:
diff changeset
2146
kono
parents:
diff changeset
2147 typedef Unordered_map_hash(Typed_identifier_list*, Btype*,
kono
parents:
diff changeset
2148 Results_hash, Results_equal) Results_structs;
kono
parents:
diff changeset
2149
kono
parents:
diff changeset
2150 static Results_structs results_structs;
kono
parents:
diff changeset
2151
kono
parents:
diff changeset
2152 // The receiver name and type. This will be NULL for a normal
kono
parents:
diff changeset
2153 // function, non-NULL for a method.
kono
parents:
diff changeset
2154 Typed_identifier* receiver_;
kono
parents:
diff changeset
2155 // The parameter names and types.
kono
parents:
diff changeset
2156 Typed_identifier_list* parameters_;
kono
parents:
diff changeset
2157 // The result names and types. This will be NULL if no result was
kono
parents:
diff changeset
2158 // specified.
kono
parents:
diff changeset
2159 Typed_identifier_list* results_;
kono
parents:
diff changeset
2160 // The location where this type was defined. This exists solely to
kono
parents:
diff changeset
2161 // give a location for the fields of the struct if this function
kono
parents:
diff changeset
2162 // returns multiple values.
kono
parents:
diff changeset
2163 Location location_;
kono
parents:
diff changeset
2164 // Whether this function takes a variable number of arguments.
kono
parents:
diff changeset
2165 bool is_varargs_;
kono
parents:
diff changeset
2166 // Whether this is a special builtin function which can not simply
kono
parents:
diff changeset
2167 // be called. This is used for len, cap, etc.
kono
parents:
diff changeset
2168 bool is_builtin_;
kono
parents:
diff changeset
2169 // The backend representation of this type for backend function
kono
parents:
diff changeset
2170 // declarations and definitions.
kono
parents:
diff changeset
2171 Btype* fnbtype_;
kono
parents:
diff changeset
2172 // Whether this function has been analyzed by escape analysis. If this is
kono
parents:
diff changeset
2173 // TRUE, this function type's parameters contain a summary of the analysis.
kono
parents:
diff changeset
2174 bool is_tagged_;
kono
parents:
diff changeset
2175 };
kono
parents:
diff changeset
2176
kono
parents:
diff changeset
2177 // The type of a function's backend representation.
kono
parents:
diff changeset
2178
kono
parents:
diff changeset
2179 class Backend_function_type : public Function_type
kono
parents:
diff changeset
2180 {
kono
parents:
diff changeset
2181 public:
kono
parents:
diff changeset
2182 Backend_function_type(Typed_identifier* receiver,
kono
parents:
diff changeset
2183 Typed_identifier_list* parameters,
kono
parents:
diff changeset
2184 Typed_identifier_list* results, Location location)
kono
parents:
diff changeset
2185 : Function_type(receiver, parameters, results, location)
kono
parents:
diff changeset
2186 { }
kono
parents:
diff changeset
2187
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
2188 // Return whether this is a Backend_function_type. This overrides
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
2189 // Function_type::is_backend_function_type.
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
2190 bool
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
2191 is_backend_function_type() const
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
2192 { return true; }
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
2193
111
kono
parents:
diff changeset
2194 protected:
kono
parents:
diff changeset
2195 Btype*
kono
parents:
diff changeset
2196 do_get_backend(Gogo* gogo)
kono
parents:
diff changeset
2197 { return this->get_backend_fntype(gogo); }
kono
parents:
diff changeset
2198 };
kono
parents:
diff changeset
2199
kono
parents:
diff changeset
2200 // The type of a pointer.
kono
parents:
diff changeset
2201
kono
parents:
diff changeset
2202 class Pointer_type : public Type
kono
parents:
diff changeset
2203 {
kono
parents:
diff changeset
2204 public:
kono
parents:
diff changeset
2205 Pointer_type(Type* to_type)
kono
parents:
diff changeset
2206 : Type(TYPE_POINTER),
kono
parents:
diff changeset
2207 to_type_(to_type)
kono
parents:
diff changeset
2208 {}
kono
parents:
diff changeset
2209
kono
parents:
diff changeset
2210 Type*
kono
parents:
diff changeset
2211 points_to() const
kono
parents:
diff changeset
2212 { return this->to_type_; }
kono
parents:
diff changeset
2213
kono
parents:
diff changeset
2214 // Import a pointer type.
kono
parents:
diff changeset
2215 static Pointer_type*
kono
parents:
diff changeset
2216 do_import(Import*);
kono
parents:
diff changeset
2217
kono
parents:
diff changeset
2218 static Type*
kono
parents:
diff changeset
2219 make_pointer_type_descriptor_type();
kono
parents:
diff changeset
2220
kono
parents:
diff changeset
2221 protected:
kono
parents:
diff changeset
2222 int
kono
parents:
diff changeset
2223 do_traverse(Traverse*);
kono
parents:
diff changeset
2224
kono
parents:
diff changeset
2225 bool
kono
parents:
diff changeset
2226 do_verify()
kono
parents:
diff changeset
2227 { return this->to_type_->verify(); }
kono
parents:
diff changeset
2228
kono
parents:
diff changeset
2229 bool
kono
parents:
diff changeset
2230 do_has_pointer() const
kono
parents:
diff changeset
2231 { return true; }
kono
parents:
diff changeset
2232
kono
parents:
diff changeset
2233 bool
kono
parents:
diff changeset
2234 do_compare_is_identity(Gogo*)
kono
parents:
diff changeset
2235 { return true; }
kono
parents:
diff changeset
2236
kono
parents:
diff changeset
2237 unsigned int
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
2238 do_hash_for_method(Gogo*, int) const;
111
kono
parents:
diff changeset
2239
kono
parents:
diff changeset
2240 Btype*
kono
parents:
diff changeset
2241 do_get_backend(Gogo*);
kono
parents:
diff changeset
2242
kono
parents:
diff changeset
2243 Expression*
kono
parents:
diff changeset
2244 do_type_descriptor(Gogo*, Named_type*);
kono
parents:
diff changeset
2245
kono
parents:
diff changeset
2246 void
kono
parents:
diff changeset
2247 do_reflection(Gogo*, std::string*) const;
kono
parents:
diff changeset
2248
kono
parents:
diff changeset
2249 void
kono
parents:
diff changeset
2250 do_mangled_name(Gogo*, std::string*) const;
kono
parents:
diff changeset
2251
kono
parents:
diff changeset
2252 void
kono
parents:
diff changeset
2253 do_export(Export*) const;
kono
parents:
diff changeset
2254
kono
parents:
diff changeset
2255 private:
kono
parents:
diff changeset
2256 // The type to which this type points.
kono
parents:
diff changeset
2257 Type* to_type_;
kono
parents:
diff changeset
2258 };
kono
parents:
diff changeset
2259
kono
parents:
diff changeset
2260 // The nil type. We use a special type for nil because it is not the
kono
parents:
diff changeset
2261 // same as any other type. In C term nil has type void*, but there is
kono
parents:
diff changeset
2262 // no such type in Go.
kono
parents:
diff changeset
2263
kono
parents:
diff changeset
2264 class Nil_type : public Type
kono
parents:
diff changeset
2265 {
kono
parents:
diff changeset
2266 public:
kono
parents:
diff changeset
2267 Nil_type()
kono
parents:
diff changeset
2268 : Type(TYPE_NIL)
kono
parents:
diff changeset
2269 { }
kono
parents:
diff changeset
2270
kono
parents:
diff changeset
2271 protected:
kono
parents:
diff changeset
2272 bool
kono
parents:
diff changeset
2273 do_compare_is_identity(Gogo*)
kono
parents:
diff changeset
2274 { return false; }
kono
parents:
diff changeset
2275
kono
parents:
diff changeset
2276 Btype*
kono
parents:
diff changeset
2277 do_get_backend(Gogo* gogo);
kono
parents:
diff changeset
2278
kono
parents:
diff changeset
2279 Expression*
kono
parents:
diff changeset
2280 do_type_descriptor(Gogo*, Named_type*)
kono
parents:
diff changeset
2281 { go_unreachable(); }
kono
parents:
diff changeset
2282
kono
parents:
diff changeset
2283 void
kono
parents:
diff changeset
2284 do_reflection(Gogo*, std::string*) const
kono
parents:
diff changeset
2285 { go_unreachable(); }
kono
parents:
diff changeset
2286
kono
parents:
diff changeset
2287 void
kono
parents:
diff changeset
2288 do_mangled_name(Gogo*, std::string* ret) const;
kono
parents:
diff changeset
2289 };
kono
parents:
diff changeset
2290
kono
parents:
diff changeset
2291 // The type of a field in a struct.
kono
parents:
diff changeset
2292
kono
parents:
diff changeset
2293 class Struct_field
kono
parents:
diff changeset
2294 {
kono
parents:
diff changeset
2295 public:
kono
parents:
diff changeset
2296 explicit Struct_field(const Typed_identifier& typed_identifier)
kono
parents:
diff changeset
2297 : typed_identifier_(typed_identifier), tag_(NULL), is_imported_(false)
kono
parents:
diff changeset
2298 { }
kono
parents:
diff changeset
2299
kono
parents:
diff changeset
2300 // The field name.
kono
parents:
diff changeset
2301 const std::string&
kono
parents:
diff changeset
2302 field_name() const;
kono
parents:
diff changeset
2303
kono
parents:
diff changeset
2304 // Return whether this struct field is named NAME.
kono
parents:
diff changeset
2305 bool
kono
parents:
diff changeset
2306 is_field_name(const std::string& name) const;
kono
parents:
diff changeset
2307
kono
parents:
diff changeset
2308 // Return whether this struct field is an unexported field named NAME.
kono
parents:
diff changeset
2309 bool
kono
parents:
diff changeset
2310 is_unexported_field_name(Gogo*, const std::string& name) const;
kono
parents:
diff changeset
2311
kono
parents:
diff changeset
2312 // Return whether this struct field is an embedded built-in type.
kono
parents:
diff changeset
2313 bool
kono
parents:
diff changeset
2314 is_embedded_builtin(Gogo*) const;
kono
parents:
diff changeset
2315
kono
parents:
diff changeset
2316 // The field type.
kono
parents:
diff changeset
2317 Type*
kono
parents:
diff changeset
2318 type() const
kono
parents:
diff changeset
2319 { return this->typed_identifier_.type(); }
kono
parents:
diff changeset
2320
kono
parents:
diff changeset
2321 // The field location.
kono
parents:
diff changeset
2322 Location
kono
parents:
diff changeset
2323 location() const
kono
parents:
diff changeset
2324 { return this->typed_identifier_.location(); }
kono
parents:
diff changeset
2325
kono
parents:
diff changeset
2326 // Whether the field has a tag.
kono
parents:
diff changeset
2327 bool
kono
parents:
diff changeset
2328 has_tag() const
kono
parents:
diff changeset
2329 { return this->tag_ != NULL; }
kono
parents:
diff changeset
2330
kono
parents:
diff changeset
2331 // The tag.
kono
parents:
diff changeset
2332 const std::string&
kono
parents:
diff changeset
2333 tag() const
kono
parents:
diff changeset
2334 {
kono
parents:
diff changeset
2335 go_assert(this->tag_ != NULL);
kono
parents:
diff changeset
2336 return *this->tag_;
kono
parents:
diff changeset
2337 }
kono
parents:
diff changeset
2338
kono
parents:
diff changeset
2339 // Whether this is an anonymous field.
kono
parents:
diff changeset
2340 bool
kono
parents:
diff changeset
2341 is_anonymous() const
kono
parents:
diff changeset
2342 { return this->typed_identifier_.name().empty(); }
kono
parents:
diff changeset
2343
kono
parents:
diff changeset
2344 // Set the tag. FIXME: This is never freed.
kono
parents:
diff changeset
2345 void
kono
parents:
diff changeset
2346 set_tag(const std::string& tag)
kono
parents:
diff changeset
2347 { this->tag_ = new std::string(tag); }
kono
parents:
diff changeset
2348
kono
parents:
diff changeset
2349 // Record that this field is defined in an imported struct.
kono
parents:
diff changeset
2350 void
kono
parents:
diff changeset
2351 set_is_imported()
kono
parents:
diff changeset
2352 { this->is_imported_ = true; }
kono
parents:
diff changeset
2353
kono
parents:
diff changeset
2354 // Set the type. This is only used in error cases.
kono
parents:
diff changeset
2355 void
kono
parents:
diff changeset
2356 set_type(Type* type)
kono
parents:
diff changeset
2357 { this->typed_identifier_.set_type(type); }
kono
parents:
diff changeset
2358
kono
parents:
diff changeset
2359 private:
kono
parents:
diff changeset
2360 // The field name, type, and location.
kono
parents:
diff changeset
2361 Typed_identifier typed_identifier_;
kono
parents:
diff changeset
2362 // The field tag. This is NULL if the field has no tag.
kono
parents:
diff changeset
2363 std::string* tag_;
kono
parents:
diff changeset
2364 // Whether this field is defined in an imported struct.
kono
parents:
diff changeset
2365 bool is_imported_;
kono
parents:
diff changeset
2366 };
kono
parents:
diff changeset
2367
kono
parents:
diff changeset
2368 // A list of struct fields.
kono
parents:
diff changeset
2369
kono
parents:
diff changeset
2370 class Struct_field_list
kono
parents:
diff changeset
2371 {
kono
parents:
diff changeset
2372 public:
kono
parents:
diff changeset
2373 Struct_field_list()
kono
parents:
diff changeset
2374 : entries_()
kono
parents:
diff changeset
2375 { }
kono
parents:
diff changeset
2376
kono
parents:
diff changeset
2377 // Whether the list is empty.
kono
parents:
diff changeset
2378 bool
kono
parents:
diff changeset
2379 empty() const
kono
parents:
diff changeset
2380 { return this->entries_.empty(); }
kono
parents:
diff changeset
2381
kono
parents:
diff changeset
2382 // Return the number of entries.
kono
parents:
diff changeset
2383 size_t
kono
parents:
diff changeset
2384 size() const
kono
parents:
diff changeset
2385 { return this->entries_.size(); }
kono
parents:
diff changeset
2386
kono
parents:
diff changeset
2387 // Add an entry to the end of the list.
kono
parents:
diff changeset
2388 void
kono
parents:
diff changeset
2389 push_back(const Struct_field& sf)
kono
parents:
diff changeset
2390 { this->entries_.push_back(sf); }
kono
parents:
diff changeset
2391
kono
parents:
diff changeset
2392 // Index into the list.
kono
parents:
diff changeset
2393 const Struct_field&
kono
parents:
diff changeset
2394 at(size_t i) const
kono
parents:
diff changeset
2395 { return this->entries_.at(i); }
kono
parents:
diff changeset
2396
kono
parents:
diff changeset
2397 // Last entry in list.
kono
parents:
diff changeset
2398 Struct_field&
kono
parents:
diff changeset
2399 back()
kono
parents:
diff changeset
2400 { return this->entries_.back(); }
kono
parents:
diff changeset
2401
kono
parents:
diff changeset
2402 // Iterators.
kono
parents:
diff changeset
2403
kono
parents:
diff changeset
2404 typedef std::vector<Struct_field>::iterator iterator;
kono
parents:
diff changeset
2405 typedef std::vector<Struct_field>::const_iterator const_iterator;
kono
parents:
diff changeset
2406
kono
parents:
diff changeset
2407 iterator
kono
parents:
diff changeset
2408 begin()
kono
parents:
diff changeset
2409 { return this->entries_.begin(); }
kono
parents:
diff changeset
2410
kono
parents:
diff changeset
2411 const_iterator
kono
parents:
diff changeset
2412 begin() const
kono
parents:
diff changeset
2413 { return this->entries_.begin(); }
kono
parents:
diff changeset
2414
kono
parents:
diff changeset
2415 iterator
kono
parents:
diff changeset
2416 end()
kono
parents:
diff changeset
2417 { return this->entries_.end(); }
kono
parents:
diff changeset
2418
kono
parents:
diff changeset
2419 const_iterator
kono
parents:
diff changeset
2420 end() const
kono
parents:
diff changeset
2421 { return this->entries_.end(); }
kono
parents:
diff changeset
2422
kono
parents:
diff changeset
2423 private:
kono
parents:
diff changeset
2424 std::vector<Struct_field> entries_;
kono
parents:
diff changeset
2425 };
kono
parents:
diff changeset
2426
kono
parents:
diff changeset
2427 // The type of a struct.
kono
parents:
diff changeset
2428
kono
parents:
diff changeset
2429 class Struct_type : public Type
kono
parents:
diff changeset
2430 {
kono
parents:
diff changeset
2431 public:
kono
parents:
diff changeset
2432 Struct_type(Struct_field_list* fields, Location location)
kono
parents:
diff changeset
2433 : Type(TYPE_STRUCT),
kono
parents:
diff changeset
2434 fields_(fields), location_(location), all_methods_(NULL),
kono
parents:
diff changeset
2435 is_struct_incomparable_(false)
kono
parents:
diff changeset
2436 { }
kono
parents:
diff changeset
2437
kono
parents:
diff changeset
2438 // Return the field NAME. This only looks at local fields, not at
kono
parents:
diff changeset
2439 // embedded types. If the field is found, and PINDEX is not NULL,
kono
parents:
diff changeset
2440 // this sets *PINDEX to the field index. If the field is not found,
kono
parents:
diff changeset
2441 // this returns NULL.
kono
parents:
diff changeset
2442 const Struct_field*
kono
parents:
diff changeset
2443 find_local_field(const std::string& name, unsigned int *pindex) const;
kono
parents:
diff changeset
2444
kono
parents:
diff changeset
2445 // Return the field number INDEX.
kono
parents:
diff changeset
2446 const Struct_field*
kono
parents:
diff changeset
2447 field(unsigned int index) const
kono
parents:
diff changeset
2448 { return &this->fields_->at(index); }
kono
parents:
diff changeset
2449
kono
parents:
diff changeset
2450 // Get the struct fields.
kono
parents:
diff changeset
2451 const Struct_field_list*
kono
parents:
diff changeset
2452 fields() const
kono
parents:
diff changeset
2453 { return this->fields_; }
kono
parents:
diff changeset
2454
kono
parents:
diff changeset
2455 // Return the number of fields.
kono
parents:
diff changeset
2456 size_t
kono
parents:
diff changeset
2457 field_count() const
kono
parents:
diff changeset
2458 { return this->fields_->size(); }
kono
parents:
diff changeset
2459
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
2460 // Location of struct definition.
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
2461 Location
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
2462 location() const
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
2463 { return this->location_; }
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
2464
111
kono
parents:
diff changeset
2465 // Push a new field onto the end of the struct. This is used when
kono
parents:
diff changeset
2466 // building a closure variable.
kono
parents:
diff changeset
2467 void
kono
parents:
diff changeset
2468 push_field(const Struct_field& sf)
kono
parents:
diff changeset
2469 { this->fields_->push_back(sf); }
kono
parents:
diff changeset
2470
kono
parents:
diff changeset
2471 // Return an expression referring to field NAME in STRUCT_EXPR, or
kono
parents:
diff changeset
2472 // NULL if there is no field with that name.
kono
parents:
diff changeset
2473 Field_reference_expression*
kono
parents:
diff changeset
2474 field_reference(Expression* struct_expr, const std::string& name,
kono
parents:
diff changeset
2475 Location) const;
kono
parents:
diff changeset
2476
kono
parents:
diff changeset
2477 // Return the total number of fields, including embedded fields.
kono
parents:
diff changeset
2478 // This is the number of values that can appear in a conversion to
kono
parents:
diff changeset
2479 // this type.
kono
parents:
diff changeset
2480 unsigned int
kono
parents:
diff changeset
2481 total_field_count() const;
kono
parents:
diff changeset
2482
kono
parents:
diff changeset
2483 // Whether this type is identical with T.
kono
parents:
diff changeset
2484 bool
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
2485 is_identical(const Struct_type* t, int) const;
111
kono
parents:
diff changeset
2486
kono
parents:
diff changeset
2487 // Return whether NAME is a local field which is not exported. This
kono
parents:
diff changeset
2488 // is only used for better error reporting.
kono
parents:
diff changeset
2489 bool
kono
parents:
diff changeset
2490 is_unexported_local_field(Gogo*, const std::string& name) const;
kono
parents:
diff changeset
2491
kono
parents:
diff changeset
2492 // If this is an unnamed struct, build the complete list of methods,
kono
parents:
diff changeset
2493 // including those from anonymous fields, and build methods stubs if
kono
parents:
diff changeset
2494 // needed.
kono
parents:
diff changeset
2495 void
kono
parents:
diff changeset
2496 finalize_methods(Gogo*);
kono
parents:
diff changeset
2497
kono
parents:
diff changeset
2498 // Return whether this type has any methods. This should only be
kono
parents:
diff changeset
2499 // called after the finalize_methods pass.
kono
parents:
diff changeset
2500 bool
kono
parents:
diff changeset
2501 has_any_methods() const
kono
parents:
diff changeset
2502 { return this->all_methods_ != NULL; }
kono
parents:
diff changeset
2503
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
2504 // Return the methods for this type. This should only be called
111
kono
parents:
diff changeset
2505 // after the finalize_methods pass.
kono
parents:
diff changeset
2506 const Methods*
kono
parents:
diff changeset
2507 methods() const
kono
parents:
diff changeset
2508 { return this->all_methods_; }
kono
parents:
diff changeset
2509
kono
parents:
diff changeset
2510 // Return the method to use for NAME. This returns NULL if there is
kono
parents:
diff changeset
2511 // no such method or if the method is ambiguous. When it returns
kono
parents:
diff changeset
2512 // NULL, this sets *IS_AMBIGUOUS if the method name is ambiguous.
kono
parents:
diff changeset
2513 Method*
kono
parents:
diff changeset
2514 method_function(const std::string& name, bool* is_ambiguous) const;
kono
parents:
diff changeset
2515
kono
parents:
diff changeset
2516 // Return a pointer to the interface method table for this type for
kono
parents:
diff changeset
2517 // the interface INTERFACE. If IS_POINTER is true, set the type
kono
parents:
diff changeset
2518 // descriptor to a pointer to this type, otherwise set it to this
kono
parents:
diff changeset
2519 // type.
kono
parents:
diff changeset
2520 Expression*
kono
parents:
diff changeset
2521 interface_method_table(Interface_type* interface, bool is_pointer);
kono
parents:
diff changeset
2522
kono
parents:
diff changeset
2523 // Traverse just the field types of a struct type.
kono
parents:
diff changeset
2524 int
kono
parents:
diff changeset
2525 traverse_field_types(Traverse* traverse)
kono
parents:
diff changeset
2526 { return this->do_traverse(traverse); }
kono
parents:
diff changeset
2527
kono
parents:
diff changeset
2528 // If the offset of field INDEX in the backend implementation can be
kono
parents:
diff changeset
2529 // determined, set *POFFSET to the offset in bytes and return true.
kono
parents:
diff changeset
2530 // Otherwise, return false.
kono
parents:
diff changeset
2531 bool
kono
parents:
diff changeset
2532 backend_field_offset(Gogo*, unsigned int index, int64_t* poffset);
kono
parents:
diff changeset
2533
kono
parents:
diff changeset
2534 // Finish the backend representation of all the fields.
kono
parents:
diff changeset
2535 void
kono
parents:
diff changeset
2536 finish_backend_fields(Gogo*);
kono
parents:
diff changeset
2537
kono
parents:
diff changeset
2538 // Import a struct type.
kono
parents:
diff changeset
2539 static Struct_type*
kono
parents:
diff changeset
2540 do_import(Import*);
kono
parents:
diff changeset
2541
kono
parents:
diff changeset
2542 static Type*
kono
parents:
diff changeset
2543 make_struct_type_descriptor_type();
kono
parents:
diff changeset
2544
kono
parents:
diff changeset
2545 // Return whether this is a generated struct that is not comparable.
kono
parents:
diff changeset
2546 bool
kono
parents:
diff changeset
2547 is_struct_incomparable() const
kono
parents:
diff changeset
2548 { return this->is_struct_incomparable_; }
kono
parents:
diff changeset
2549
kono
parents:
diff changeset
2550 // Record that this is a generated struct that is not comparable.
kono
parents:
diff changeset
2551 void
kono
parents:
diff changeset
2552 set_is_struct_incomparable()
kono
parents:
diff changeset
2553 { this->is_struct_incomparable_ = true; }
kono
parents:
diff changeset
2554
kono
parents:
diff changeset
2555 // Write the hash function for this type.
kono
parents:
diff changeset
2556 void
kono
parents:
diff changeset
2557 write_hash_function(Gogo*, Named_type*, Function_type*, Function_type*);
kono
parents:
diff changeset
2558
kono
parents:
diff changeset
2559 // Write the equality function for this type.
kono
parents:
diff changeset
2560 void
kono
parents:
diff changeset
2561 write_equal_function(Gogo*, Named_type*);
kono
parents:
diff changeset
2562
kono
parents:
diff changeset
2563 // Whether we can write this type to a C header file, to implement
kono
parents:
diff changeset
2564 // -fgo-c-header.
kono
parents:
diff changeset
2565 bool
kono
parents:
diff changeset
2566 can_write_to_c_header(std::vector<const Named_object*>*,
kono
parents:
diff changeset
2567 std::vector<const Named_object*>*) const;
kono
parents:
diff changeset
2568
kono
parents:
diff changeset
2569 // Write this type to a C header file, to implement -fgo-c-header.
kono
parents:
diff changeset
2570 void
kono
parents:
diff changeset
2571 write_to_c_header(std::ostream&) const;
kono
parents:
diff changeset
2572
kono
parents:
diff changeset
2573 protected:
kono
parents:
diff changeset
2574 int
kono
parents:
diff changeset
2575 do_traverse(Traverse*);
kono
parents:
diff changeset
2576
kono
parents:
diff changeset
2577 bool
kono
parents:
diff changeset
2578 do_verify();
kono
parents:
diff changeset
2579
kono
parents:
diff changeset
2580 bool
kono
parents:
diff changeset
2581 do_has_pointer() const;
kono
parents:
diff changeset
2582
kono
parents:
diff changeset
2583 bool
kono
parents:
diff changeset
2584 do_compare_is_identity(Gogo*);
kono
parents:
diff changeset
2585
kono
parents:
diff changeset
2586 bool
kono
parents:
diff changeset
2587 do_is_reflexive();
kono
parents:
diff changeset
2588
kono
parents:
diff changeset
2589 bool
kono
parents:
diff changeset
2590 do_needs_key_update();
kono
parents:
diff changeset
2591
kono
parents:
diff changeset
2592 bool
kono
parents:
diff changeset
2593 do_in_heap();
kono
parents:
diff changeset
2594
kono
parents:
diff changeset
2595 unsigned int
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
2596 do_hash_for_method(Gogo*, int) const;
111
kono
parents:
diff changeset
2597
kono
parents:
diff changeset
2598 Btype*
kono
parents:
diff changeset
2599 do_get_backend(Gogo*);
kono
parents:
diff changeset
2600
kono
parents:
diff changeset
2601 Expression*
kono
parents:
diff changeset
2602 do_type_descriptor(Gogo*, Named_type*);
kono
parents:
diff changeset
2603
kono
parents:
diff changeset
2604 void
kono
parents:
diff changeset
2605 do_reflection(Gogo*, std::string*) const;
kono
parents:
diff changeset
2606
kono
parents:
diff changeset
2607 void
kono
parents:
diff changeset
2608 do_mangled_name(Gogo*, std::string*) const;
kono
parents:
diff changeset
2609
kono
parents:
diff changeset
2610 void
kono
parents:
diff changeset
2611 do_export(Export*) const;
kono
parents:
diff changeset
2612
kono
parents:
diff changeset
2613 private:
kono
parents:
diff changeset
2614 bool
kono
parents:
diff changeset
2615 can_write_type_to_c_header(const Type*,
kono
parents:
diff changeset
2616 std::vector<const Named_object*>*,
kono
parents:
diff changeset
2617 std::vector<const Named_object*>*) const;
kono
parents:
diff changeset
2618
kono
parents:
diff changeset
2619 void
kono
parents:
diff changeset
2620 write_field_to_c_header(std::ostream&, const std::string&, const Type*) const;
kono
parents:
diff changeset
2621
kono
parents:
diff changeset
2622 // Used to merge method sets of identical unnamed structs.
kono
parents:
diff changeset
2623 typedef Unordered_map_hash(Struct_type*, Struct_type*, Type_hash_identical,
kono
parents:
diff changeset
2624 Type_identical) Identical_structs;
kono
parents:
diff changeset
2625
kono
parents:
diff changeset
2626 static Identical_structs identical_structs;
kono
parents:
diff changeset
2627
kono
parents:
diff changeset
2628 // Used to manage method tables for identical unnamed structs.
kono
parents:
diff changeset
2629 typedef std::pair<Interface_method_tables*, Interface_method_tables*>
kono
parents:
diff changeset
2630 Struct_method_table_pair;
kono
parents:
diff changeset
2631
kono
parents:
diff changeset
2632 typedef Unordered_map_hash(Struct_type*, Struct_method_table_pair*,
kono
parents:
diff changeset
2633 Type_hash_identical, Type_identical)
kono
parents:
diff changeset
2634 Struct_method_tables;
kono
parents:
diff changeset
2635
kono
parents:
diff changeset
2636 static Struct_method_tables struct_method_tables;
kono
parents:
diff changeset
2637
kono
parents:
diff changeset
2638 // Used to avoid infinite loops in field_reference_depth.
kono
parents:
diff changeset
2639 struct Saw_named_type
kono
parents:
diff changeset
2640 {
kono
parents:
diff changeset
2641 Saw_named_type* next;
kono
parents:
diff changeset
2642 Named_type* nt;
kono
parents:
diff changeset
2643 };
kono
parents:
diff changeset
2644
kono
parents:
diff changeset
2645 Field_reference_expression*
kono
parents:
diff changeset
2646 field_reference_depth(Expression* struct_expr, const std::string& name,
kono
parents:
diff changeset
2647 Location, Saw_named_type*,
kono
parents:
diff changeset
2648 unsigned int* depth) const;
kono
parents:
diff changeset
2649
kono
parents:
diff changeset
2650 // The fields of the struct.
kono
parents:
diff changeset
2651 Struct_field_list* fields_;
kono
parents:
diff changeset
2652 // The place where the struct was declared.
kono
parents:
diff changeset
2653 Location location_;
kono
parents:
diff changeset
2654 // If this struct is unnamed, a list of methods.
kono
parents:
diff changeset
2655 Methods* all_methods_;
kono
parents:
diff changeset
2656 // True if this is a generated struct that is not considered to be
kono
parents:
diff changeset
2657 // comparable.
kono
parents:
diff changeset
2658 bool is_struct_incomparable_;
kono
parents:
diff changeset
2659 };
kono
parents:
diff changeset
2660
kono
parents:
diff changeset
2661 // The type of an array.
kono
parents:
diff changeset
2662
kono
parents:
diff changeset
2663 class Array_type : public Type
kono
parents:
diff changeset
2664 {
kono
parents:
diff changeset
2665 public:
kono
parents:
diff changeset
2666 Array_type(Type* element_type, Expression* length)
kono
parents:
diff changeset
2667 : Type(TYPE_ARRAY),
kono
parents:
diff changeset
2668 element_type_(element_type), length_(length), blength_(NULL),
kono
parents:
diff changeset
2669 issued_length_error_(false), is_array_incomparable_(false)
kono
parents:
diff changeset
2670 { }
kono
parents:
diff changeset
2671
kono
parents:
diff changeset
2672 // Return the element type.
kono
parents:
diff changeset
2673 Type*
kono
parents:
diff changeset
2674 element_type() const
kono
parents:
diff changeset
2675 { return this->element_type_; }
kono
parents:
diff changeset
2676
kono
parents:
diff changeset
2677 // Return the length. This will return NULL for a slice.
kono
parents:
diff changeset
2678 Expression*
kono
parents:
diff changeset
2679 length() const
kono
parents:
diff changeset
2680 { return this->length_; }
kono
parents:
diff changeset
2681
kono
parents:
diff changeset
2682 // Store the length as an int64_t into *PLEN. Return false if the
kono
parents:
diff changeset
2683 // length can not be determined. This will assert if called for a
kono
parents:
diff changeset
2684 // slice.
kono
parents:
diff changeset
2685 bool
kono
parents:
diff changeset
2686 int_length(int64_t* plen);
kono
parents:
diff changeset
2687
kono
parents:
diff changeset
2688 // Whether this type is identical with T.
kono
parents:
diff changeset
2689 bool
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
2690 is_identical(const Array_type* t, int) const;
111
kono
parents:
diff changeset
2691
kono
parents:
diff changeset
2692 // Return an expression for the pointer to the values in an array.
kono
parents:
diff changeset
2693 Expression*
kono
parents:
diff changeset
2694 get_value_pointer(Gogo*, Expression* array, bool is_lvalue) const;
kono
parents:
diff changeset
2695
kono
parents:
diff changeset
2696 // Return an expression for the length of an array with this type.
kono
parents:
diff changeset
2697 Expression*
kono
parents:
diff changeset
2698 get_length(Gogo*, Expression* array) const;
kono
parents:
diff changeset
2699
kono
parents:
diff changeset
2700 // Return an expression for the capacity of an array with this type.
kono
parents:
diff changeset
2701 Expression*
kono
parents:
diff changeset
2702 get_capacity(Gogo*, Expression* array) const;
kono
parents:
diff changeset
2703
kono
parents:
diff changeset
2704 // Import an array type.
kono
parents:
diff changeset
2705 static Array_type*
kono
parents:
diff changeset
2706 do_import(Import*);
kono
parents:
diff changeset
2707
kono
parents:
diff changeset
2708 // Return the backend representation of the element type.
kono
parents:
diff changeset
2709 Btype*
kono
parents:
diff changeset
2710 get_backend_element(Gogo*, bool use_placeholder);
kono
parents:
diff changeset
2711
kono
parents:
diff changeset
2712 // Return the backend representation of the length.
kono
parents:
diff changeset
2713 Bexpression*
kono
parents:
diff changeset
2714 get_backend_length(Gogo*);
kono
parents:
diff changeset
2715
kono
parents:
diff changeset
2716 // Finish the backend representation of the element type.
kono
parents:
diff changeset
2717 void
kono
parents:
diff changeset
2718 finish_backend_element(Gogo*);
kono
parents:
diff changeset
2719
kono
parents:
diff changeset
2720 static Type*
kono
parents:
diff changeset
2721 make_array_type_descriptor_type();
kono
parents:
diff changeset
2722
kono
parents:
diff changeset
2723 static Type*
kono
parents:
diff changeset
2724 make_slice_type_descriptor_type();
kono
parents:
diff changeset
2725
kono
parents:
diff changeset
2726 // Return whether this is a generated array that is not comparable.
kono
parents:
diff changeset
2727 bool
kono
parents:
diff changeset
2728 is_array_incomparable() const
kono
parents:
diff changeset
2729 { return this->is_array_incomparable_; }
kono
parents:
diff changeset
2730
kono
parents:
diff changeset
2731 // Record that this is a generated array that is not comparable.
kono
parents:
diff changeset
2732 void
kono
parents:
diff changeset
2733 set_is_array_incomparable()
kono
parents:
diff changeset
2734 { this->is_array_incomparable_ = true; }
kono
parents:
diff changeset
2735
kono
parents:
diff changeset
2736 // Write the hash function for this type.
kono
parents:
diff changeset
2737 void
kono
parents:
diff changeset
2738 write_hash_function(Gogo*, Named_type*, Function_type*, Function_type*);
kono
parents:
diff changeset
2739
kono
parents:
diff changeset
2740 // Write the equality function for this type.
kono
parents:
diff changeset
2741 void
kono
parents:
diff changeset
2742 write_equal_function(Gogo*, Named_type*);
kono
parents:
diff changeset
2743
kono
parents:
diff changeset
2744 protected:
kono
parents:
diff changeset
2745 int
kono
parents:
diff changeset
2746 do_traverse(Traverse* traverse);
kono
parents:
diff changeset
2747
kono
parents:
diff changeset
2748 bool
kono
parents:
diff changeset
2749 do_verify();
kono
parents:
diff changeset
2750
kono
parents:
diff changeset
2751 bool
kono
parents:
diff changeset
2752 do_has_pointer() const;
kono
parents:
diff changeset
2753
kono
parents:
diff changeset
2754 bool
kono
parents:
diff changeset
2755 do_compare_is_identity(Gogo*);
kono
parents:
diff changeset
2756
kono
parents:
diff changeset
2757 bool
kono
parents:
diff changeset
2758 do_is_reflexive()
kono
parents:
diff changeset
2759 {
kono
parents:
diff changeset
2760 return this->length_ != NULL && this->element_type_->is_reflexive();
kono
parents:
diff changeset
2761 }
kono
parents:
diff changeset
2762
kono
parents:
diff changeset
2763 bool
kono
parents:
diff changeset
2764 do_needs_key_update()
kono
parents:
diff changeset
2765 { return this->element_type_->needs_key_update(); }
kono
parents:
diff changeset
2766
kono
parents:
diff changeset
2767 bool
kono
parents:
diff changeset
2768 do_in_heap()
kono
parents:
diff changeset
2769 { return this->length_ == NULL || this->element_type_->in_heap(); }
kono
parents:
diff changeset
2770
kono
parents:
diff changeset
2771 unsigned int
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
2772 do_hash_for_method(Gogo*, int) const;
111
kono
parents:
diff changeset
2773
kono
parents:
diff changeset
2774 Btype*
kono
parents:
diff changeset
2775 do_get_backend(Gogo*);
kono
parents:
diff changeset
2776
kono
parents:
diff changeset
2777 Expression*
kono
parents:
diff changeset
2778 do_type_descriptor(Gogo*, Named_type*);
kono
parents:
diff changeset
2779
kono
parents:
diff changeset
2780 void
kono
parents:
diff changeset
2781 do_reflection(Gogo*, std::string*) const;
kono
parents:
diff changeset
2782
kono
parents:
diff changeset
2783 void
kono
parents:
diff changeset
2784 do_mangled_name(Gogo*, std::string*) const;
kono
parents:
diff changeset
2785
kono
parents:
diff changeset
2786 void
kono
parents:
diff changeset
2787 do_export(Export*) const;
kono
parents:
diff changeset
2788
kono
parents:
diff changeset
2789 private:
kono
parents:
diff changeset
2790 bool
kono
parents:
diff changeset
2791 verify_length();
kono
parents:
diff changeset
2792
kono
parents:
diff changeset
2793 Expression*
kono
parents:
diff changeset
2794 array_type_descriptor(Gogo*, Named_type*);
kono
parents:
diff changeset
2795
kono
parents:
diff changeset
2796 Expression*
kono
parents:
diff changeset
2797 slice_type_descriptor(Gogo*, Named_type*);
kono
parents:
diff changeset
2798
kono
parents:
diff changeset
2799 // The type of elements of the array.
kono
parents:
diff changeset
2800 Type* element_type_;
kono
parents:
diff changeset
2801 // The number of elements. This may be NULL.
kono
parents:
diff changeset
2802 Expression* length_;
kono
parents:
diff changeset
2803 // The backend representation of the length.
kono
parents:
diff changeset
2804 // We only want to compute this once.
kono
parents:
diff changeset
2805 Bexpression* blength_;
kono
parents:
diff changeset
2806 // Whether or not an invalid length error has been issued for this type,
kono
parents:
diff changeset
2807 // to avoid knock-on errors.
kono
parents:
diff changeset
2808 mutable bool issued_length_error_;
kono
parents:
diff changeset
2809 // True if this is a generated array that is not considered to be
kono
parents:
diff changeset
2810 // comparable.
kono
parents:
diff changeset
2811 bool is_array_incomparable_;
kono
parents:
diff changeset
2812 };
kono
parents:
diff changeset
2813
kono
parents:
diff changeset
2814 // The type of a map.
kono
parents:
diff changeset
2815
kono
parents:
diff changeset
2816 class Map_type : public Type
kono
parents:
diff changeset
2817 {
kono
parents:
diff changeset
2818 public:
kono
parents:
diff changeset
2819 Map_type(Type* key_type, Type* val_type, Location location)
kono
parents:
diff changeset
2820 : Type(TYPE_MAP),
kono
parents:
diff changeset
2821 key_type_(key_type), val_type_(val_type), hmap_type_(NULL),
kono
parents:
diff changeset
2822 bucket_type_(NULL), hiter_type_(NULL), location_(location)
kono
parents:
diff changeset
2823 { }
kono
parents:
diff changeset
2824
kono
parents:
diff changeset
2825 // Return the key type.
kono
parents:
diff changeset
2826 Type*
kono
parents:
diff changeset
2827 key_type() const
kono
parents:
diff changeset
2828 { return this->key_type_; }
kono
parents:
diff changeset
2829
kono
parents:
diff changeset
2830 // Return the value type.
kono
parents:
diff changeset
2831 Type*
kono
parents:
diff changeset
2832 val_type() const
kono
parents:
diff changeset
2833 { return this->val_type_; }
kono
parents:
diff changeset
2834
kono
parents:
diff changeset
2835 // Return the type used for an iteration over this map.
kono
parents:
diff changeset
2836 Type*
kono
parents:
diff changeset
2837 hiter_type(Gogo*);
kono
parents:
diff changeset
2838
kono
parents:
diff changeset
2839 // If this map requires the "fat" functions, returns the pointer to
kono
parents:
diff changeset
2840 // pass as the zero value to those functions. Otherwise, in the
kono
parents:
diff changeset
2841 // normal case, returns NULL.
kono
parents:
diff changeset
2842 Expression*
kono
parents:
diff changeset
2843 fat_zero_value(Gogo*);
kono
parents:
diff changeset
2844
kono
parents:
diff changeset
2845 // Return whether VAR is the map zero value.
kono
parents:
diff changeset
2846 static bool
kono
parents:
diff changeset
2847 is_zero_value(Variable* var);
kono
parents:
diff changeset
2848
kono
parents:
diff changeset
2849 // Return the backend representation of the map zero value.
kono
parents:
diff changeset
2850 static Bvariable*
kono
parents:
diff changeset
2851 backend_zero_value(Gogo*);
kono
parents:
diff changeset
2852
kono
parents:
diff changeset
2853 // Whether this type is identical with T.
kono
parents:
diff changeset
2854 bool
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
2855 is_identical(const Map_type* t, int) const;
111
kono
parents:
diff changeset
2856
kono
parents:
diff changeset
2857 // Import a map type.
kono
parents:
diff changeset
2858 static Map_type*
kono
parents:
diff changeset
2859 do_import(Import*);
kono
parents:
diff changeset
2860
kono
parents:
diff changeset
2861 static Type*
kono
parents:
diff changeset
2862 make_map_type_descriptor_type();
kono
parents:
diff changeset
2863
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
2864 // This must be in sync with libgo/go/runtime/hashmap.go.
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
2865 static const int bucket_size = 8;
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
2866
111
kono
parents:
diff changeset
2867 protected:
kono
parents:
diff changeset
2868 int
kono
parents:
diff changeset
2869 do_traverse(Traverse*);
kono
parents:
diff changeset
2870
kono
parents:
diff changeset
2871 bool
kono
parents:
diff changeset
2872 do_verify();
kono
parents:
diff changeset
2873
kono
parents:
diff changeset
2874 bool
kono
parents:
diff changeset
2875 do_has_pointer() const
kono
parents:
diff changeset
2876 { return true; }
kono
parents:
diff changeset
2877
kono
parents:
diff changeset
2878 bool
kono
parents:
diff changeset
2879 do_compare_is_identity(Gogo*)
kono
parents:
diff changeset
2880 { return false; }
kono
parents:
diff changeset
2881
kono
parents:
diff changeset
2882 bool
kono
parents:
diff changeset
2883 do_is_reflexive()
kono
parents:
diff changeset
2884 {
kono
parents:
diff changeset
2885 return this->key_type_->is_reflexive() && this->val_type_->is_reflexive();
kono
parents:
diff changeset
2886 }
kono
parents:
diff changeset
2887
kono
parents:
diff changeset
2888 unsigned int
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
2889 do_hash_for_method(Gogo*, int) const;
111
kono
parents:
diff changeset
2890
kono
parents:
diff changeset
2891 Btype*
kono
parents:
diff changeset
2892 do_get_backend(Gogo*);
kono
parents:
diff changeset
2893
kono
parents:
diff changeset
2894 Expression*
kono
parents:
diff changeset
2895 do_type_descriptor(Gogo*, Named_type*);
kono
parents:
diff changeset
2896
kono
parents:
diff changeset
2897 void
kono
parents:
diff changeset
2898 do_reflection(Gogo*, std::string*) const;
kono
parents:
diff changeset
2899
kono
parents:
diff changeset
2900 void
kono
parents:
diff changeset
2901 do_mangled_name(Gogo*, std::string*) const;
kono
parents:
diff changeset
2902
kono
parents:
diff changeset
2903 void
kono
parents:
diff changeset
2904 do_export(Export*) const;
kono
parents:
diff changeset
2905
kono
parents:
diff changeset
2906 private:
kono
parents:
diff changeset
2907 // These must be in sync with libgo/go/runtime/hashmap.go.
kono
parents:
diff changeset
2908 static const int max_key_size = 128;
kono
parents:
diff changeset
2909 static const int max_val_size = 128;
kono
parents:
diff changeset
2910 static const int max_zero_size = 1024;
kono
parents:
diff changeset
2911
kono
parents:
diff changeset
2912 // Maps with value types larger than max_zero_size require passing a
kono
parents:
diff changeset
2913 // zero value pointer to the map functions.
kono
parents:
diff changeset
2914
kono
parents:
diff changeset
2915 // The zero value variable.
kono
parents:
diff changeset
2916 static Named_object* zero_value;
kono
parents:
diff changeset
2917
kono
parents:
diff changeset
2918 // The current size of the zero value.
kono
parents:
diff changeset
2919 static int64_t zero_value_size;
kono
parents:
diff changeset
2920
kono
parents:
diff changeset
2921 // The current alignment of the zero value.
kono
parents:
diff changeset
2922 static int64_t zero_value_align;
kono
parents:
diff changeset
2923
kono
parents:
diff changeset
2924 Type*
kono
parents:
diff changeset
2925 bucket_type(Gogo*, int64_t, int64_t);
kono
parents:
diff changeset
2926
kono
parents:
diff changeset
2927 Type*
kono
parents:
diff changeset
2928 hmap_type(Type*);
kono
parents:
diff changeset
2929
kono
parents:
diff changeset
2930 // The key type.
kono
parents:
diff changeset
2931 Type* key_type_;
kono
parents:
diff changeset
2932 // The value type.
kono
parents:
diff changeset
2933 Type* val_type_;
kono
parents:
diff changeset
2934 // The hashmap type. At run time a map is represented as a pointer
kono
parents:
diff changeset
2935 // to this type.
kono
parents:
diff changeset
2936 Type* hmap_type_;
kono
parents:
diff changeset
2937 // The bucket type, the type used to hold keys and values at run time.
kono
parents:
diff changeset
2938 Type* bucket_type_;
kono
parents:
diff changeset
2939 // The iterator type.
kono
parents:
diff changeset
2940 Type* hiter_type_;
kono
parents:
diff changeset
2941 // Where the type was defined.
kono
parents:
diff changeset
2942 Location location_;
kono
parents:
diff changeset
2943 };
kono
parents:
diff changeset
2944
kono
parents:
diff changeset
2945 // The type of a channel.
kono
parents:
diff changeset
2946
kono
parents:
diff changeset
2947 class Channel_type : public Type
kono
parents:
diff changeset
2948 {
kono
parents:
diff changeset
2949 public:
kono
parents:
diff changeset
2950 Channel_type(bool may_send, bool may_receive, Type* element_type)
kono
parents:
diff changeset
2951 : Type(TYPE_CHANNEL),
kono
parents:
diff changeset
2952 may_send_(may_send), may_receive_(may_receive),
kono
parents:
diff changeset
2953 element_type_(element_type)
kono
parents:
diff changeset
2954 { go_assert(may_send || may_receive); }
kono
parents:
diff changeset
2955
kono
parents:
diff changeset
2956 // Whether this channel can send data.
kono
parents:
diff changeset
2957 bool
kono
parents:
diff changeset
2958 may_send() const
kono
parents:
diff changeset
2959 { return this->may_send_; }
kono
parents:
diff changeset
2960
kono
parents:
diff changeset
2961 // Whether this channel can receive data.
kono
parents:
diff changeset
2962 bool
kono
parents:
diff changeset
2963 may_receive() const
kono
parents:
diff changeset
2964 { return this->may_receive_; }
kono
parents:
diff changeset
2965
kono
parents:
diff changeset
2966 // The type of the values that may be sent on this channel. This is
kono
parents:
diff changeset
2967 // NULL if any type may be sent.
kono
parents:
diff changeset
2968 Type*
kono
parents:
diff changeset
2969 element_type() const
kono
parents:
diff changeset
2970 { return this->element_type_; }
kono
parents:
diff changeset
2971
kono
parents:
diff changeset
2972 // Whether this type is identical with T.
kono
parents:
diff changeset
2973 bool
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
2974 is_identical(const Channel_type* t, int) const;
111
kono
parents:
diff changeset
2975
kono
parents:
diff changeset
2976 // Import a channel type.
kono
parents:
diff changeset
2977 static Channel_type*
kono
parents:
diff changeset
2978 do_import(Import*);
kono
parents:
diff changeset
2979
kono
parents:
diff changeset
2980 static Type*
kono
parents:
diff changeset
2981 make_chan_type_descriptor_type();
kono
parents:
diff changeset
2982
kono
parents:
diff changeset
2983 static Type*
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
2984 select_case_type();
111
kono
parents:
diff changeset
2985
kono
parents:
diff changeset
2986 protected:
kono
parents:
diff changeset
2987 int
kono
parents:
diff changeset
2988 do_traverse(Traverse* traverse)
kono
parents:
diff changeset
2989 { return Type::traverse(this->element_type_, traverse); }
kono
parents:
diff changeset
2990
kono
parents:
diff changeset
2991 bool
kono
parents:
diff changeset
2992 do_verify();
kono
parents:
diff changeset
2993
kono
parents:
diff changeset
2994 bool
kono
parents:
diff changeset
2995 do_has_pointer() const
kono
parents:
diff changeset
2996 { return true; }
kono
parents:
diff changeset
2997
kono
parents:
diff changeset
2998 bool
kono
parents:
diff changeset
2999 do_compare_is_identity(Gogo*)
kono
parents:
diff changeset
3000 { return true; }
kono
parents:
diff changeset
3001
kono
parents:
diff changeset
3002 unsigned int
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
3003 do_hash_for_method(Gogo*, int) const;
111
kono
parents:
diff changeset
3004
kono
parents:
diff changeset
3005 Btype*
kono
parents:
diff changeset
3006 do_get_backend(Gogo*);
kono
parents:
diff changeset
3007
kono
parents:
diff changeset
3008 Expression*
kono
parents:
diff changeset
3009 do_type_descriptor(Gogo*, Named_type*);
kono
parents:
diff changeset
3010
kono
parents:
diff changeset
3011 void
kono
parents:
diff changeset
3012 do_reflection(Gogo*, std::string*) const;
kono
parents:
diff changeset
3013
kono
parents:
diff changeset
3014 void
kono
parents:
diff changeset
3015 do_mangled_name(Gogo*, std::string*) const;
kono
parents:
diff changeset
3016
kono
parents:
diff changeset
3017 void
kono
parents:
diff changeset
3018 do_export(Export*) const;
kono
parents:
diff changeset
3019
kono
parents:
diff changeset
3020 private:
kono
parents:
diff changeset
3021 // Whether this channel can send data.
kono
parents:
diff changeset
3022 bool may_send_;
kono
parents:
diff changeset
3023 // Whether this channel can receive data.
kono
parents:
diff changeset
3024 bool may_receive_;
kono
parents:
diff changeset
3025 // The types of elements which may be sent on this channel. If this
kono
parents:
diff changeset
3026 // is NULL, it means that any type may be sent.
kono
parents:
diff changeset
3027 Type* element_type_;
kono
parents:
diff changeset
3028 };
kono
parents:
diff changeset
3029
kono
parents:
diff changeset
3030 // An interface type.
kono
parents:
diff changeset
3031
kono
parents:
diff changeset
3032 class Interface_type : public Type
kono
parents:
diff changeset
3033 {
kono
parents:
diff changeset
3034 public:
kono
parents:
diff changeset
3035 Interface_type(Typed_identifier_list* methods, Location location)
kono
parents:
diff changeset
3036 : Type(TYPE_INTERFACE),
kono
parents:
diff changeset
3037 parse_methods_(methods), all_methods_(NULL), location_(location),
kono
parents:
diff changeset
3038 package_(NULL), interface_btype_(NULL), bmethods_(NULL),
kono
parents:
diff changeset
3039 assume_identical_(NULL), methods_are_finalized_(false),
kono
parents:
diff changeset
3040 bmethods_is_placeholder_(false), seen_(false)
kono
parents:
diff changeset
3041 { go_assert(methods == NULL || !methods->empty()); }
kono
parents:
diff changeset
3042
kono
parents:
diff changeset
3043 // The location where the interface type was defined.
kono
parents:
diff changeset
3044 Location
kono
parents:
diff changeset
3045 location() const
kono
parents:
diff changeset
3046 { return this->location_; }
kono
parents:
diff changeset
3047
kono
parents:
diff changeset
3048 // The package where the interface type was defined. Returns NULL
kono
parents:
diff changeset
3049 // for the package currently being compiled.
kono
parents:
diff changeset
3050 Package*
kono
parents:
diff changeset
3051 package() const
kono
parents:
diff changeset
3052 { return this->package_; }
kono
parents:
diff changeset
3053
kono
parents:
diff changeset
3054 // Return whether this is an empty interface.
kono
parents:
diff changeset
3055 bool
kono
parents:
diff changeset
3056 is_empty() const
kono
parents:
diff changeset
3057 {
kono
parents:
diff changeset
3058 go_assert(this->methods_are_finalized_);
kono
parents:
diff changeset
3059 return this->all_methods_ == NULL;
kono
parents:
diff changeset
3060 }
kono
parents:
diff changeset
3061
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
3062 // Return the list of locally defined methos. This will return NULL
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
3063 // for an empty interface. Embedded interfaces will appear in this
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
3064 // list as an entry with no name.
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
3065 const Typed_identifier_list*
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
3066 local_methods() const
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
3067 { return this->parse_methods_; }
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
3068
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
3069 // Return the list of all methods. This will return NULL for an
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
3070 // empty interface.
111
kono
parents:
diff changeset
3071 const Typed_identifier_list*
kono
parents:
diff changeset
3072 methods() const;
kono
parents:
diff changeset
3073
kono
parents:
diff changeset
3074 // Return the number of methods.
kono
parents:
diff changeset
3075 size_t
kono
parents:
diff changeset
3076 method_count() const;
kono
parents:
diff changeset
3077
kono
parents:
diff changeset
3078 // Return the method NAME, or NULL.
kono
parents:
diff changeset
3079 const Typed_identifier*
kono
parents:
diff changeset
3080 find_method(const std::string& name) const;
kono
parents:
diff changeset
3081
kono
parents:
diff changeset
3082 // Return the zero-based index of method NAME.
kono
parents:
diff changeset
3083 size_t
kono
parents:
diff changeset
3084 method_index(const std::string& name) const;
kono
parents:
diff changeset
3085
kono
parents:
diff changeset
3086 // Finalize the methods. This sets all_methods_. This handles
kono
parents:
diff changeset
3087 // interface inheritance.
kono
parents:
diff changeset
3088 void
kono
parents:
diff changeset
3089 finalize_methods();
kono
parents:
diff changeset
3090
kono
parents:
diff changeset
3091 // Return true if T implements this interface. If this returns
kono
parents:
diff changeset
3092 // false, and REASON is not NULL, it sets *REASON to the reason that
kono
parents:
diff changeset
3093 // it fails.
kono
parents:
diff changeset
3094 bool
kono
parents:
diff changeset
3095 implements_interface(const Type* t, std::string* reason) const;
kono
parents:
diff changeset
3096
kono
parents:
diff changeset
3097 // Whether this type is identical with T. REASON is as in
kono
parents:
diff changeset
3098 // implements_interface.
kono
parents:
diff changeset
3099 bool
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
3100 is_identical(const Interface_type* t, int) const;
111
kono
parents:
diff changeset
3101
kono
parents:
diff changeset
3102 // Whether we can assign T to this type. is_identical is known to
kono
parents:
diff changeset
3103 // be false.
kono
parents:
diff changeset
3104 bool
kono
parents:
diff changeset
3105 is_compatible_for_assign(const Interface_type*, std::string* reason) const;
kono
parents:
diff changeset
3106
kono
parents:
diff changeset
3107 // Return whether NAME is a method which is not exported. This is
kono
parents:
diff changeset
3108 // only used for better error reporting.
kono
parents:
diff changeset
3109 bool
kono
parents:
diff changeset
3110 is_unexported_method(Gogo*, const std::string& name) const;
kono
parents:
diff changeset
3111
kono
parents:
diff changeset
3112 // Import an interface type.
kono
parents:
diff changeset
3113 static Interface_type*
kono
parents:
diff changeset
3114 do_import(Import*);
kono
parents:
diff changeset
3115
kono
parents:
diff changeset
3116 // Make a struct for an empty interface type.
kono
parents:
diff changeset
3117 static Btype*
kono
parents:
diff changeset
3118 get_backend_empty_interface_type(Gogo*);
kono
parents:
diff changeset
3119
kono
parents:
diff changeset
3120 // Get a pointer to the backend representation of the method table.
kono
parents:
diff changeset
3121 Btype*
kono
parents:
diff changeset
3122 get_backend_methods(Gogo*);
kono
parents:
diff changeset
3123
kono
parents:
diff changeset
3124 // Return a placeholder for the backend representation of the
kono
parents:
diff changeset
3125 // pointer to the method table.
kono
parents:
diff changeset
3126 Btype*
kono
parents:
diff changeset
3127 get_backend_methods_placeholder(Gogo*);
kono
parents:
diff changeset
3128
kono
parents:
diff changeset
3129 // Finish the backend representation of the method types.
kono
parents:
diff changeset
3130 void
kono
parents:
diff changeset
3131 finish_backend_methods(Gogo*);
kono
parents:
diff changeset
3132
kono
parents:
diff changeset
3133 static Type*
kono
parents:
diff changeset
3134 make_interface_type_descriptor_type();
kono
parents:
diff changeset
3135
kono
parents:
diff changeset
3136 protected:
kono
parents:
diff changeset
3137 int
kono
parents:
diff changeset
3138 do_traverse(Traverse*);
kono
parents:
diff changeset
3139
kono
parents:
diff changeset
3140 bool
kono
parents:
diff changeset
3141 do_has_pointer() const
kono
parents:
diff changeset
3142 { return true; }
kono
parents:
diff changeset
3143
kono
parents:
diff changeset
3144 bool
kono
parents:
diff changeset
3145 do_compare_is_identity(Gogo*)
kono
parents:
diff changeset
3146 { return false; }
kono
parents:
diff changeset
3147
kono
parents:
diff changeset
3148 // Not reflexive if it contains a float.
kono
parents:
diff changeset
3149 bool
kono
parents:
diff changeset
3150 do_is_reflexive()
kono
parents:
diff changeset
3151 { return false; }
kono
parents:
diff changeset
3152
kono
parents:
diff changeset
3153 // Distinction between +0 and -0 requires a key update if it
kono
parents:
diff changeset
3154 // contains a float.
kono
parents:
diff changeset
3155 bool
kono
parents:
diff changeset
3156 do_needs_key_update()
kono
parents:
diff changeset
3157 { return true; }
kono
parents:
diff changeset
3158
kono
parents:
diff changeset
3159 unsigned int
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
3160 do_hash_for_method(Gogo*, int) const;
111
kono
parents:
diff changeset
3161
kono
parents:
diff changeset
3162 Btype*
kono
parents:
diff changeset
3163 do_get_backend(Gogo*);
kono
parents:
diff changeset
3164
kono
parents:
diff changeset
3165 Expression*
kono
parents:
diff changeset
3166 do_type_descriptor(Gogo*, Named_type*);
kono
parents:
diff changeset
3167
kono
parents:
diff changeset
3168 void
kono
parents:
diff changeset
3169 do_reflection(Gogo*, std::string*) const;
kono
parents:
diff changeset
3170
kono
parents:
diff changeset
3171 void
kono
parents:
diff changeset
3172 do_mangled_name(Gogo*, std::string*) const;
kono
parents:
diff changeset
3173
kono
parents:
diff changeset
3174 void
kono
parents:
diff changeset
3175 do_export(Export*) const;
kono
parents:
diff changeset
3176
kono
parents:
diff changeset
3177 private:
kono
parents:
diff changeset
3178 // This type guards against infinite recursion when comparing
kono
parents:
diff changeset
3179 // interface types. We keep a list of interface types assumed to be
kono
parents:
diff changeset
3180 // identical during comparison. We just keep the list on the stack.
kono
parents:
diff changeset
3181 // This permits us to compare cases like
kono
parents:
diff changeset
3182 // type I1 interface { F() interface{I1} }
kono
parents:
diff changeset
3183 // type I2 interface { F() interface{I2} }
kono
parents:
diff changeset
3184 struct Assume_identical
kono
parents:
diff changeset
3185 {
kono
parents:
diff changeset
3186 Assume_identical* next;
kono
parents:
diff changeset
3187 const Interface_type* t1;
kono
parents:
diff changeset
3188 const Interface_type* t2;
kono
parents:
diff changeset
3189 };
kono
parents:
diff changeset
3190
kono
parents:
diff changeset
3191 bool
kono
parents:
diff changeset
3192 assume_identical(const Interface_type*, const Interface_type*) const;
kono
parents:
diff changeset
3193
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
3194 struct Bmethods_map_entry
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
3195 {
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
3196 Btype *btype;
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
3197 bool is_placeholder;
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
3198 };
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
3199
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
3200 // A mapping from Interface_type to the backend type of its bmethods_,
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
3201 // used to ensure that the backend representation of identical types
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
3202 // is identical.
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
3203 typedef Unordered_map_hash(const Interface_type*, Bmethods_map_entry,
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
3204 Type_hash_identical, Type_identical) Bmethods_map;
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
3205
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
3206 static Bmethods_map bmethods_map;
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
3207
111
kono
parents:
diff changeset
3208 // The list of methods associated with the interface from the
kono
parents:
diff changeset
3209 // parser. This will be NULL for the empty interface. This may
kono
parents:
diff changeset
3210 // include unnamed interface types.
kono
parents:
diff changeset
3211 Typed_identifier_list* parse_methods_;
kono
parents:
diff changeset
3212 // The list of all methods associated with the interface. This
kono
parents:
diff changeset
3213 // expands any interface types listed in methods_. It is set by
kono
parents:
diff changeset
3214 // finalize_methods. This will be NULL for the empty interface.
kono
parents:
diff changeset
3215 Typed_identifier_list* all_methods_;
kono
parents:
diff changeset
3216 // The location where the interface was defined.
kono
parents:
diff changeset
3217 Location location_;
kono
parents:
diff changeset
3218 // The package where the interface was defined. This is NULL for
kono
parents:
diff changeset
3219 // the package being compiled.
kono
parents:
diff changeset
3220 Package* package_;
kono
parents:
diff changeset
3221 // The backend representation of this type during backend conversion.
kono
parents:
diff changeset
3222 Btype* interface_btype_;
kono
parents:
diff changeset
3223 // The backend representation of the pointer to the method table.
kono
parents:
diff changeset
3224 Btype* bmethods_;
kono
parents:
diff changeset
3225 // A list of interface types assumed to be identical during
kono
parents:
diff changeset
3226 // interface comparison.
kono
parents:
diff changeset
3227 mutable Assume_identical* assume_identical_;
kono
parents:
diff changeset
3228 // Whether the methods have been finalized.
kono
parents:
diff changeset
3229 bool methods_are_finalized_;
kono
parents:
diff changeset
3230 // Whether the bmethods_ field is a placeholder.
kono
parents:
diff changeset
3231 bool bmethods_is_placeholder_;
kono
parents:
diff changeset
3232 // Used to avoid endless recursion in do_mangled_name.
kono
parents:
diff changeset
3233 mutable bool seen_;
kono
parents:
diff changeset
3234 };
kono
parents:
diff changeset
3235
kono
parents:
diff changeset
3236 // The value we keep for a named type. This lets us get the right
kono
parents:
diff changeset
3237 // name when we convert to backend. Note that we don't actually keep
kono
parents:
diff changeset
3238 // the name here; the name is in the Named_object which points to
kono
parents:
diff changeset
3239 // this. This object exists to hold a unique backend representation for
kono
parents:
diff changeset
3240 // the type.
kono
parents:
diff changeset
3241
kono
parents:
diff changeset
3242 class Named_type : public Type
kono
parents:
diff changeset
3243 {
kono
parents:
diff changeset
3244 public:
kono
parents:
diff changeset
3245 Named_type(Named_object* named_object, Type* type, Location location)
kono
parents:
diff changeset
3246 : Type(TYPE_NAMED),
kono
parents:
diff changeset
3247 named_object_(named_object), in_function_(NULL), in_function_index_(0),
kono
parents:
diff changeset
3248 type_(type), local_methods_(NULL), all_methods_(NULL),
kono
parents:
diff changeset
3249 interface_method_tables_(NULL), pointer_interface_method_tables_(NULL),
kono
parents:
diff changeset
3250 location_(location), named_btype_(NULL), dependencies_(),
kono
parents:
diff changeset
3251 is_alias_(false), is_visible_(true), is_error_(false), in_heap_(true),
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
3252 is_placeholder_(false), is_converted_(false), is_verified_(false),
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
3253 seen_(false), seen_in_compare_is_identity_(false),
111
kono
parents:
diff changeset
3254 seen_in_get_backend_(false), seen_alias_(false)
kono
parents:
diff changeset
3255 { }
kono
parents:
diff changeset
3256
kono
parents:
diff changeset
3257 // Return the associated Named_object. This holds the actual name.
kono
parents:
diff changeset
3258 Named_object*
kono
parents:
diff changeset
3259 named_object()
kono
parents:
diff changeset
3260 { return this->named_object_; }
kono
parents:
diff changeset
3261
kono
parents:
diff changeset
3262 const Named_object*
kono
parents:
diff changeset
3263 named_object() const
kono
parents:
diff changeset
3264 { return this->named_object_; }
kono
parents:
diff changeset
3265
kono
parents:
diff changeset
3266 // Set the Named_object. This is used when we see a type
kono
parents:
diff changeset
3267 // declaration followed by a type.
kono
parents:
diff changeset
3268 void
kono
parents:
diff changeset
3269 set_named_object(Named_object* no)
kono
parents:
diff changeset
3270 { this->named_object_ = no; }
kono
parents:
diff changeset
3271
kono
parents:
diff changeset
3272 // Whether this is an alias (type T1 = T2) rather than an ordinary
kono
parents:
diff changeset
3273 // named type (type T1 T2).
kono
parents:
diff changeset
3274 bool
kono
parents:
diff changeset
3275 is_alias() const
kono
parents:
diff changeset
3276 { return this->is_alias_; }
kono
parents:
diff changeset
3277
kono
parents:
diff changeset
3278 // Record that this type is an alias.
kono
parents:
diff changeset
3279 void
kono
parents:
diff changeset
3280 set_is_alias()
kono
parents:
diff changeset
3281 { this->is_alias_ = true; }
kono
parents:
diff changeset
3282
kono
parents:
diff changeset
3283 // Mark this type as not permitted in the heap.
kono
parents:
diff changeset
3284 void
kono
parents:
diff changeset
3285 set_not_in_heap()
kono
parents:
diff changeset
3286 { this->in_heap_ = false; }
kono
parents:
diff changeset
3287
kono
parents:
diff changeset
3288 // Return the function in which this type is defined. This will
kono
parents:
diff changeset
3289 // return NULL for a type defined in global scope.
kono
parents:
diff changeset
3290 const Named_object*
kono
parents:
diff changeset
3291 in_function(unsigned int *pindex) const
kono
parents:
diff changeset
3292 {
kono
parents:
diff changeset
3293 *pindex = this->in_function_index_;
kono
parents:
diff changeset
3294 return this->in_function_;
kono
parents:
diff changeset
3295 }
kono
parents:
diff changeset
3296
kono
parents:
diff changeset
3297 // Set the function in which this type is defined.
kono
parents:
diff changeset
3298 void
kono
parents:
diff changeset
3299 set_in_function(Named_object* f, unsigned int index)
kono
parents:
diff changeset
3300 {
kono
parents:
diff changeset
3301 this->in_function_ = f;
kono
parents:
diff changeset
3302 this->in_function_index_ = index;
kono
parents:
diff changeset
3303 }
kono
parents:
diff changeset
3304
kono
parents:
diff changeset
3305 // Return the name of the type.
kono
parents:
diff changeset
3306 const std::string&
kono
parents:
diff changeset
3307 name() const;
kono
parents:
diff changeset
3308
kono
parents:
diff changeset
3309 // Return the name of the type for an error message. The difference
kono
parents:
diff changeset
3310 // is that if the type is defined in a different package, this will
kono
parents:
diff changeset
3311 // return PACKAGE.NAME.
kono
parents:
diff changeset
3312 std::string
kono
parents:
diff changeset
3313 message_name() const;
kono
parents:
diff changeset
3314
kono
parents:
diff changeset
3315 // Return the underlying type.
kono
parents:
diff changeset
3316 Type*
kono
parents:
diff changeset
3317 real_type()
kono
parents:
diff changeset
3318 { return this->type_; }
kono
parents:
diff changeset
3319
kono
parents:
diff changeset
3320 const Type*
kono
parents:
diff changeset
3321 real_type() const
kono
parents:
diff changeset
3322 { return this->type_; }
kono
parents:
diff changeset
3323
kono
parents:
diff changeset
3324 // Return the location.
kono
parents:
diff changeset
3325 Location
kono
parents:
diff changeset
3326 location() const
kono
parents:
diff changeset
3327 { return this->location_; }
kono
parents:
diff changeset
3328
kono
parents:
diff changeset
3329 // Whether this type is visible. This only matters when parsing.
kono
parents:
diff changeset
3330 bool
kono
parents:
diff changeset
3331 is_visible() const
kono
parents:
diff changeset
3332 { return this->is_visible_; }
kono
parents:
diff changeset
3333
kono
parents:
diff changeset
3334 // Mark this type as visible.
kono
parents:
diff changeset
3335 void
kono
parents:
diff changeset
3336 set_is_visible()
kono
parents:
diff changeset
3337 { this->is_visible_ = true; }
kono
parents:
diff changeset
3338
kono
parents:
diff changeset
3339 // Mark this type as invisible.
kono
parents:
diff changeset
3340 void
kono
parents:
diff changeset
3341 clear_is_visible()
kono
parents:
diff changeset
3342 { this->is_visible_ = false; }
kono
parents:
diff changeset
3343
kono
parents:
diff changeset
3344 // Whether this is a builtin type.
kono
parents:
diff changeset
3345 bool
kono
parents:
diff changeset
3346 is_builtin() const
kono
parents:
diff changeset
3347 { return Linemap::is_predeclared_location(this->location_); }
kono
parents:
diff changeset
3348
kono
parents:
diff changeset
3349 // Whether this named type is valid. A recursive named type is invalid.
kono
parents:
diff changeset
3350 bool
kono
parents:
diff changeset
3351 is_valid() const
kono
parents:
diff changeset
3352 { return !this->is_error_; }
kono
parents:
diff changeset
3353
kono
parents:
diff changeset
3354 // Return the base type for this type.
kono
parents:
diff changeset
3355 Type*
kono
parents:
diff changeset
3356 named_base();
kono
parents:
diff changeset
3357
kono
parents:
diff changeset
3358 const Type*
kono
parents:
diff changeset
3359 named_base() const;
kono
parents:
diff changeset
3360
kono
parents:
diff changeset
3361 // Return whether this is an error type.
kono
parents:
diff changeset
3362 bool
kono
parents:
diff changeset
3363 is_named_error_type() const;
kono
parents:
diff changeset
3364
kono
parents:
diff changeset
3365 // Return whether this type is comparable. If REASON is not NULL,
kono
parents:
diff changeset
3366 // set *REASON when returning false.
kono
parents:
diff changeset
3367 bool
kono
parents:
diff changeset
3368 named_type_is_comparable(std::string* reason) const;
kono
parents:
diff changeset
3369
kono
parents:
diff changeset
3370 // Add a method to this type.
kono
parents:
diff changeset
3371 Named_object*
kono
parents:
diff changeset
3372 add_method(const std::string& name, Function*);
kono
parents:
diff changeset
3373
kono
parents:
diff changeset
3374 // Add a method declaration to this type.
kono
parents:
diff changeset
3375 Named_object*
kono
parents:
diff changeset
3376 add_method_declaration(const std::string& name, Package* package,
kono
parents:
diff changeset
3377 Function_type* type, Location location);
kono
parents:
diff changeset
3378
kono
parents:
diff changeset
3379 // Add an existing method--one defined before the type itself was
kono
parents:
diff changeset
3380 // defined--to a type.
kono
parents:
diff changeset
3381 void
kono
parents:
diff changeset
3382 add_existing_method(Named_object*);
kono
parents:
diff changeset
3383
kono
parents:
diff changeset
3384 // Look up a local method.
kono
parents:
diff changeset
3385 Named_object*
kono
parents:
diff changeset
3386 find_local_method(const std::string& name) const;
kono
parents:
diff changeset
3387
kono
parents:
diff changeset
3388 // Return the list of local methods.
kono
parents:
diff changeset
3389 const Bindings*
kono
parents:
diff changeset
3390 local_methods() const;
kono
parents:
diff changeset
3391
kono
parents:
diff changeset
3392 // Build the complete list of methods, including those from
kono
parents:
diff changeset
3393 // anonymous fields, and build method stubs if needed.
kono
parents:
diff changeset
3394 void
kono
parents:
diff changeset
3395 finalize_methods(Gogo*);
kono
parents:
diff changeset
3396
kono
parents:
diff changeset
3397 // Return whether this type has any methods. This should only be
kono
parents:
diff changeset
3398 // called after the finalize_methods pass.
kono
parents:
diff changeset
3399 bool
kono
parents:
diff changeset
3400 has_any_methods() const;
kono
parents:
diff changeset
3401
kono
parents:
diff changeset
3402 // Return the methods for this type. This should only be called
kono
parents:
diff changeset
3403 // after the finalized_methods pass.
kono
parents:
diff changeset
3404 const Methods*
kono
parents:
diff changeset
3405 methods() const;
kono
parents:
diff changeset
3406
kono
parents:
diff changeset
3407 // Return the method to use for NAME. This returns NULL if there is
kono
parents:
diff changeset
3408 // no such method or if the method is ambiguous. When it returns
kono
parents:
diff changeset
3409 // NULL, this sets *IS_AMBIGUOUS if the method name is ambiguous.
kono
parents:
diff changeset
3410 Method*
kono
parents:
diff changeset
3411 method_function(const std::string& name, bool *is_ambiguous) const;
kono
parents:
diff changeset
3412
kono
parents:
diff changeset
3413 // Return whether NAME is a known field or method which is not
kono
parents:
diff changeset
3414 // exported. This is only used for better error reporting.
kono
parents:
diff changeset
3415 bool
kono
parents:
diff changeset
3416 is_unexported_local_method(Gogo*, const std::string& name) const;
kono
parents:
diff changeset
3417
kono
parents:
diff changeset
3418 // Return a pointer to the interface method table for this type for
kono
parents:
diff changeset
3419 // the interface INTERFACE. If IS_POINTER is true, set the type
kono
parents:
diff changeset
3420 // descriptor to a pointer to this type, otherwise set it to this
kono
parents:
diff changeset
3421 // type.
kono
parents:
diff changeset
3422 Expression*
kono
parents:
diff changeset
3423 interface_method_table(Interface_type* interface, bool is_pointer);
kono
parents:
diff changeset
3424
kono
parents:
diff changeset
3425 // Note that a type must be converted to the backend representation
kono
parents:
diff changeset
3426 // before we convert this type.
kono
parents:
diff changeset
3427 void
kono
parents:
diff changeset
3428 add_dependency(Named_type* nt)
kono
parents:
diff changeset
3429 { this->dependencies_.push_back(nt); }
kono
parents:
diff changeset
3430
kono
parents:
diff changeset
3431 // Return true if the size and alignment of the backend
kono
parents:
diff changeset
3432 // representation of this type is known. This is always true after
kono
parents:
diff changeset
3433 // types have been converted, but may be false beforehand.
kono
parents:
diff changeset
3434 bool
kono
parents:
diff changeset
3435 is_named_backend_type_size_known() const
kono
parents:
diff changeset
3436 { return this->named_btype_ != NULL && !this->is_placeholder_; }
kono
parents:
diff changeset
3437
kono
parents:
diff changeset
3438 // Add to the reflection string as for Type::append_reflection, but
kono
parents:
diff changeset
3439 // if USE_ALIAS use the alias name rather than the alias target.
kono
parents:
diff changeset
3440 void
kono
parents:
diff changeset
3441 append_reflection_type_name(Gogo*, bool use_alias, std::string*) const;
kono
parents:
diff changeset
3442
kono
parents:
diff changeset
3443 // Append the mangled type name as for Type::append_mangled_name,
kono
parents:
diff changeset
3444 // but if USE_ALIAS use the alias name rather than the alias target.
kono
parents:
diff changeset
3445 void
kono
parents:
diff changeset
3446 append_mangled_type_name(Gogo*, bool use_alias, std::string*) const;
kono
parents:
diff changeset
3447
kono
parents:
diff changeset
3448 // Import a named type.
kono
parents:
diff changeset
3449 static void
kono
parents:
diff changeset
3450 import_named_type(Import*, Named_type**);
kono
parents:
diff changeset
3451
kono
parents:
diff changeset
3452 // Initial conversion to backend representation.
kono
parents:
diff changeset
3453 void
kono
parents:
diff changeset
3454 convert(Gogo*);
kono
parents:
diff changeset
3455
kono
parents:
diff changeset
3456 protected:
kono
parents:
diff changeset
3457 int
kono
parents:
diff changeset
3458 do_traverse(Traverse* traverse)
kono
parents:
diff changeset
3459 { return Type::traverse(this->type_, traverse); }
kono
parents:
diff changeset
3460
kono
parents:
diff changeset
3461 bool
kono
parents:
diff changeset
3462 do_verify();
kono
parents:
diff changeset
3463
kono
parents:
diff changeset
3464 bool
kono
parents:
diff changeset
3465 do_has_pointer() const;
kono
parents:
diff changeset
3466
kono
parents:
diff changeset
3467 bool
kono
parents:
diff changeset
3468 do_compare_is_identity(Gogo*);
kono
parents:
diff changeset
3469
kono
parents:
diff changeset
3470 bool
kono
parents:
diff changeset
3471 do_is_reflexive();
kono
parents:
diff changeset
3472
kono
parents:
diff changeset
3473 bool
kono
parents:
diff changeset
3474 do_needs_key_update();
kono
parents:
diff changeset
3475
kono
parents:
diff changeset
3476 bool
kono
parents:
diff changeset
3477 do_in_heap()
kono
parents:
diff changeset
3478 { return this->in_heap_ && this->type_->in_heap(); }
kono
parents:
diff changeset
3479
kono
parents:
diff changeset
3480 unsigned int
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
3481 do_hash_for_method(Gogo*, int) const;
111
kono
parents:
diff changeset
3482
kono
parents:
diff changeset
3483 Btype*
kono
parents:
diff changeset
3484 do_get_backend(Gogo*);
kono
parents:
diff changeset
3485
kono
parents:
diff changeset
3486 Expression*
kono
parents:
diff changeset
3487 do_type_descriptor(Gogo*, Named_type*);
kono
parents:
diff changeset
3488
kono
parents:
diff changeset
3489 void
kono
parents:
diff changeset
3490 do_reflection(Gogo*, std::string*) const;
kono
parents:
diff changeset
3491
kono
parents:
diff changeset
3492 void
kono
parents:
diff changeset
3493 do_mangled_name(Gogo*, std::string* ret) const;
kono
parents:
diff changeset
3494
kono
parents:
diff changeset
3495 void
kono
parents:
diff changeset
3496 do_export(Export*) const;
kono
parents:
diff changeset
3497
kono
parents:
diff changeset
3498 private:
kono
parents:
diff changeset
3499 // Create the placeholder during conversion.
kono
parents:
diff changeset
3500 void
kono
parents:
diff changeset
3501 create_placeholder(Gogo*);
kono
parents:
diff changeset
3502
kono
parents:
diff changeset
3503 // A pointer back to the Named_object for this type.
kono
parents:
diff changeset
3504 Named_object* named_object_;
kono
parents:
diff changeset
3505 // If this type is defined in a function, a pointer back to the
kono
parents:
diff changeset
3506 // function in which it is defined.
kono
parents:
diff changeset
3507 Named_object* in_function_;
kono
parents:
diff changeset
3508 // The index of this type in IN_FUNCTION_.
kono
parents:
diff changeset
3509 unsigned int in_function_index_;
kono
parents:
diff changeset
3510 // The actual type.
kono
parents:
diff changeset
3511 Type* type_;
kono
parents:
diff changeset
3512 // The list of methods defined for this type. Any named type can
kono
parents:
diff changeset
3513 // have methods.
kono
parents:
diff changeset
3514 Bindings* local_methods_;
kono
parents:
diff changeset
3515 // The full list of methods for this type, including methods
kono
parents:
diff changeset
3516 // declared for anonymous fields.
kono
parents:
diff changeset
3517 Methods* all_methods_;
kono
parents:
diff changeset
3518 // A mapping from interfaces to the associated interface method
kono
parents:
diff changeset
3519 // tables for this type.
kono
parents:
diff changeset
3520 Interface_method_tables* interface_method_tables_;
kono
parents:
diff changeset
3521 // A mapping from interfaces to the associated interface method
kono
parents:
diff changeset
3522 // tables for pointers to this type.
kono
parents:
diff changeset
3523 Interface_method_tables* pointer_interface_method_tables_;
kono
parents:
diff changeset
3524 // The location where this type was defined.
kono
parents:
diff changeset
3525 Location location_;
kono
parents:
diff changeset
3526 // The backend representation of this type during backend
kono
parents:
diff changeset
3527 // conversion. This is used to avoid endless recursion when a named
kono
parents:
diff changeset
3528 // type refers to itself.
kono
parents:
diff changeset
3529 Btype* named_btype_;
kono
parents:
diff changeset
3530 // A list of types which must be converted to the backend
kono
parents:
diff changeset
3531 // representation before this type can be converted. This is for
kono
parents:
diff changeset
3532 // cases like
kono
parents:
diff changeset
3533 // type S1 { p *S2 }
kono
parents:
diff changeset
3534 // type S2 { s S1 }
kono
parents:
diff changeset
3535 // where we can't convert S2 to the backend representation unless we
kono
parents:
diff changeset
3536 // have converted S1.
kono
parents:
diff changeset
3537 std::vector<Named_type*> dependencies_;
kono
parents:
diff changeset
3538 // Whether this is an alias type.
kono
parents:
diff changeset
3539 bool is_alias_;
kono
parents:
diff changeset
3540 // Whether this type is visible. This is false if this type was
kono
parents:
diff changeset
3541 // created because it was referenced by an imported object, but the
kono
parents:
diff changeset
3542 // type itself was not exported. This will always be true for types
kono
parents:
diff changeset
3543 // created in the current package.
kono
parents:
diff changeset
3544 bool is_visible_;
kono
parents:
diff changeset
3545 // Whether this type is erroneous.
kono
parents:
diff changeset
3546 bool is_error_;
kono
parents:
diff changeset
3547 // Whether this type is permitted in the heap. This is true by
kono
parents:
diff changeset
3548 // default, false if there is a magic //go:notinheap comment.
kono
parents:
diff changeset
3549 bool in_heap_;
kono
parents:
diff changeset
3550 // Whether the current value of named_btype_ is a placeholder for
kono
parents:
diff changeset
3551 // which the final size of the type is not known.
kono
parents:
diff changeset
3552 bool is_placeholder_;
kono
parents:
diff changeset
3553 // Whether this type has been converted to the backend
kono
parents:
diff changeset
3554 // representation. Implies that is_placeholder_ is false.
kono
parents:
diff changeset
3555 bool is_converted_;
kono
parents:
diff changeset
3556 // Whether this type has been verified.
kono
parents:
diff changeset
3557 bool is_verified_;
kono
parents:
diff changeset
3558 // In a recursive operation such as has_pointer, this flag is used
kono
parents:
diff changeset
3559 // to prevent infinite recursion when a type refers to itself. This
kono
parents:
diff changeset
3560 // is mutable because it is always reset to false when the function
kono
parents:
diff changeset
3561 // exits.
kono
parents:
diff changeset
3562 mutable bool seen_;
kono
parents:
diff changeset
3563 // Like seen_, but used only by do_compare_is_identity.
kono
parents:
diff changeset
3564 bool seen_in_compare_is_identity_;
kono
parents:
diff changeset
3565 // Like seen_, but used only by do_get_backend.
kono
parents:
diff changeset
3566 bool seen_in_get_backend_;
kono
parents:
diff changeset
3567 // Like seen_, but used when resolving aliases.
kono
parents:
diff changeset
3568 mutable bool seen_alias_;
kono
parents:
diff changeset
3569 };
kono
parents:
diff changeset
3570
kono
parents:
diff changeset
3571 // A forward declaration. This handles a type which has been declared
kono
parents:
diff changeset
3572 // but not defined.
kono
parents:
diff changeset
3573
kono
parents:
diff changeset
3574 class Forward_declaration_type : public Type
kono
parents:
diff changeset
3575 {
kono
parents:
diff changeset
3576 public:
kono
parents:
diff changeset
3577 Forward_declaration_type(Named_object* named_object);
kono
parents:
diff changeset
3578
kono
parents:
diff changeset
3579 // The named object associated with this type declaration. This
kono
parents:
diff changeset
3580 // will be resolved.
kono
parents:
diff changeset
3581 Named_object*
kono
parents:
diff changeset
3582 named_object();
kono
parents:
diff changeset
3583
kono
parents:
diff changeset
3584 const Named_object*
kono
parents:
diff changeset
3585 named_object() const;
kono
parents:
diff changeset
3586
kono
parents:
diff changeset
3587 // Return the name of the type.
kono
parents:
diff changeset
3588 const std::string&
kono
parents:
diff changeset
3589 name() const;
kono
parents:
diff changeset
3590
kono
parents:
diff changeset
3591 // Return the type to which this points. Give an error if the type
kono
parents:
diff changeset
3592 // has not yet been defined.
kono
parents:
diff changeset
3593 Type*
kono
parents:
diff changeset
3594 real_type();
kono
parents:
diff changeset
3595
kono
parents:
diff changeset
3596 const Type*
kono
parents:
diff changeset
3597 real_type() const;
kono
parents:
diff changeset
3598
kono
parents:
diff changeset
3599 // Whether the base type has been defined.
kono
parents:
diff changeset
3600 bool
kono
parents:
diff changeset
3601 is_defined() const;
kono
parents:
diff changeset
3602
kono
parents:
diff changeset
3603 // Add a method to this type.
kono
parents:
diff changeset
3604 Named_object*
kono
parents:
diff changeset
3605 add_method(const std::string& name, Function*);
kono
parents:
diff changeset
3606
kono
parents:
diff changeset
3607 // Add a method declaration to this type.
kono
parents:
diff changeset
3608 Named_object*
kono
parents:
diff changeset
3609 add_method_declaration(const std::string& name, Package*, Function_type*,
kono
parents:
diff changeset
3610 Location);
kono
parents:
diff changeset
3611
kono
parents:
diff changeset
3612 // Add an already created object as a method to this type.
kono
parents:
diff changeset
3613 void
kono
parents:
diff changeset
3614 add_existing_method(Named_object*);
kono
parents:
diff changeset
3615
kono
parents:
diff changeset
3616 protected:
kono
parents:
diff changeset
3617 int
kono
parents:
diff changeset
3618 do_traverse(Traverse* traverse);
kono
parents:
diff changeset
3619
kono
parents:
diff changeset
3620 bool
kono
parents:
diff changeset
3621 do_verify();
kono
parents:
diff changeset
3622
kono
parents:
diff changeset
3623 bool
kono
parents:
diff changeset
3624 do_has_pointer() const
kono
parents:
diff changeset
3625 { return this->real_type()->has_pointer(); }
kono
parents:
diff changeset
3626
kono
parents:
diff changeset
3627 bool
kono
parents:
diff changeset
3628 do_compare_is_identity(Gogo* gogo)
kono
parents:
diff changeset
3629 { return this->real_type()->compare_is_identity(gogo); }
kono
parents:
diff changeset
3630
kono
parents:
diff changeset
3631 bool
kono
parents:
diff changeset
3632 do_is_reflexive()
kono
parents:
diff changeset
3633 { return this->real_type()->is_reflexive(); }
kono
parents:
diff changeset
3634
kono
parents:
diff changeset
3635 bool
kono
parents:
diff changeset
3636 do_needs_key_update()
kono
parents:
diff changeset
3637 { return this->real_type()->needs_key_update(); }
kono
parents:
diff changeset
3638
kono
parents:
diff changeset
3639 bool
kono
parents:
diff changeset
3640 do_in_heap()
kono
parents:
diff changeset
3641 { return this->real_type()->in_heap(); }
kono
parents:
diff changeset
3642
kono
parents:
diff changeset
3643 unsigned int
131
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
3644 do_hash_for_method(Gogo* gogo, int flags) const
84e7813d76e9 gcc-8.2
mir3636
parents: 111
diff changeset
3645 { return this->real_type()->hash_for_method(gogo, flags); }
111
kono
parents:
diff changeset
3646
kono
parents:
diff changeset
3647 Btype*
kono
parents:
diff changeset
3648 do_get_backend(Gogo* gogo);
kono
parents:
diff changeset
3649
kono
parents:
diff changeset
3650 Expression*
kono
parents:
diff changeset
3651 do_type_descriptor(Gogo*, Named_type*);
kono
parents:
diff changeset
3652
kono
parents:
diff changeset
3653 void
kono
parents:
diff changeset
3654 do_reflection(Gogo*, std::string*) const;
kono
parents:
diff changeset
3655
kono
parents:
diff changeset
3656 void
kono
parents:
diff changeset
3657 do_mangled_name(Gogo*, std::string* ret) const;
kono
parents:
diff changeset
3658
kono
parents:
diff changeset
3659 void
kono
parents:
diff changeset
3660 do_export(Export*) const;
kono
parents:
diff changeset
3661
kono
parents:
diff changeset
3662 private:
kono
parents:
diff changeset
3663 // Issue a warning about a use of an undefined type.
kono
parents:
diff changeset
3664 void
kono
parents:
diff changeset
3665 warn() const;
kono
parents:
diff changeset
3666
kono
parents:
diff changeset
3667 // The type declaration.
kono
parents:
diff changeset
3668 Named_object* named_object_;
kono
parents:
diff changeset
3669 // Whether we have issued a warning about this type.
kono
parents:
diff changeset
3670 mutable bool warned_;
kono
parents:
diff changeset
3671 };
kono
parents:
diff changeset
3672
kono
parents:
diff changeset
3673 // The Type_context struct describes what we expect for the type of an
kono
parents:
diff changeset
3674 // expression.
kono
parents:
diff changeset
3675
kono
parents:
diff changeset
3676 struct Type_context
kono
parents:
diff changeset
3677 {
kono
parents:
diff changeset
3678 // The exact type we expect, if known. This may be NULL.
kono
parents:
diff changeset
3679 Type* type;
kono
parents:
diff changeset
3680 // Whether an abstract type is permitted.
kono
parents:
diff changeset
3681 bool may_be_abstract;
kono
parents:
diff changeset
3682
kono
parents:
diff changeset
3683 // Constructors.
kono
parents:
diff changeset
3684 Type_context()
kono
parents:
diff changeset
3685 : type(NULL), may_be_abstract(false)
kono
parents:
diff changeset
3686 { }
kono
parents:
diff changeset
3687
kono
parents:
diff changeset
3688 Type_context(Type* a_type, bool a_may_be_abstract)
kono
parents:
diff changeset
3689 : type(a_type), may_be_abstract(a_may_be_abstract)
kono
parents:
diff changeset
3690 { }
kono
parents:
diff changeset
3691 };
kono
parents:
diff changeset
3692
kono
parents:
diff changeset
3693 #endif // !defined(GO_TYPES_H)