#ifndef GO_TYPES_H
#define GO_TYPES_H
+#include "go-linemap.h"
+
class Gogo;
class Package;
class Traverse;
class Translate_context;
class Export;
class Import;
+class Btype;
+class Bexpression;
+class Bvariable;
// Type codes used in type descriptors. These must match the values
// in libgo/runtime/go-type.h. They also match the values in the gc
static const int RUNTIME_TYPE_KIND_STRUCT = 25;
static const int RUNTIME_TYPE_KIND_UNSAFE_POINTER = 26;
+static const int RUNTIME_TYPE_KIND_NO_POINTERS = (1 << 7);
+
// To build the complete list of methods for a named type we need to
// gather all methods from anonymous fields. Those methods may
// require an arbitrary set of indirections and field offsets. There
{ return this->do_type(); }
// Return the location of the method receiver.
- source_location
+ Location
receiver_location() const
{ return this->do_receiver_location(); }
// Return an expression which binds this method to EXPR. This is
// something which can be used with a function call.
Expression*
- bind_method(Expression* expr, source_location location) const;
+ bind_method(Expression* expr, Location location) const;
// Return the named object for this method. This may only be called
// after methods are finalized.
do_type() const = 0;
// Return the location of the method receiver.
- virtual source_location
+ virtual Location
do_receiver_location() const = 0;
// Bind a method to an object.
virtual Expression*
- do_bind_method(Expression* expr, source_location location) const = 0;
+ do_bind_method(Expression* expr, Location location) const = 0;
private:
// The sequence of field indexes used for this method. If this is
do_type() const;
// Return the location of the method receiver.
- source_location
+ Location
do_receiver_location() const;
// Bind a method to an object.
Expression*
- do_bind_method(Expression* expr, source_location location) const;
+ do_bind_method(Expression* expr, Location location) const;
private:
// The method itself. For a method which needs a stub, this starts
class Interface_method : public Method
{
public:
- Interface_method(const std::string& name, source_location location,
+ Interface_method(const std::string& name, Location location,
Function_type* fntype, const Field_indexes* field_indexes,
unsigned int depth)
: Method(field_indexes, depth, true, true),
{ return this->fntype_; }
// Return the location of the method receiver.
- source_location
+ Location
do_receiver_location() const
{ return this->location_; }
// Bind a method to an object.
Expression*
- do_bind_method(Expression* expr, source_location location) const;
+ do_bind_method(Expression* expr, Location location) const;
private:
// The name of the interface method to call.
std::string name_;
// The location of the definition of the interface method.
- source_location location_;
+ Location location_;
// The type of the interface method.
Function_type* fntype_;
};
make_function_type(Typed_identifier* receiver,
Typed_identifier_list* parameters,
Typed_identifier_list* results,
- source_location);
+ Location);
static Pointer_type*
make_pointer_type(Type*);
make_call_multiple_result_type(Call_expression*);
static Struct_type*
- make_struct_type(Struct_field_list* fields, source_location);
+ make_struct_type(Struct_field_list* fields, Location);
static Array_type*
make_array_type(Type* element_type, Expression* length);
static Map_type*
- make_map_type(Type* key_type, Type* value_type, source_location);
+ make_map_type(Type* key_type, Type* value_type, Location);
static Channel_type*
make_channel_type(bool send, bool receive, Type*);
static Interface_type*
- make_interface_type(Typed_identifier_list* methods, source_location);
+ make_interface_type(Typed_identifier_list* methods, Location);
static Type*
make_type_descriptor_type();
make_type_descriptor_ptr_type();
static Named_type*
- make_named_type(Named_object*, Type*, source_location);
+ make_named_type(Named_object*, Type*, Location);
static Type*
make_forward_declaration(Named_object*);
static bool
are_compatible_for_binop(const Type* t1, const Type* t2);
+ // Return true if two types are compatible for use with the
+ // comparison operator. IS_EQUALITY_OP is true if this is an
+ // equality comparison, false if it is an ordered comparison. This
+ // is an equivalence relation. If this returns false, and REASON is
+ // not NULL, it sets *REASON.
+ static bool
+ are_compatible_for_comparison(bool is_equality_op, const Type *t1,
+ const Type *t2, std::string* reason);
+
+ // Return true if a type is comparable with itself. This is true of
+ // most types, but false for, e.g., function types.
+ bool
+ is_comparable() const
+ { return Type::are_compatible_for_comparison(true, this, this, NULL); }
+
// Return true if a value with type RHS is assignable to a variable
// with type LHS. This is not an equivalence relation. If this
// returns false, and REASON is not NULL, it sets *REASON.
bool
has_hidden_fields(const Named_type* within, std::string* reason) const;
+ // Return true if values of this type can be compared using an
+ // identity function which gets nothing but a pointer to the value
+ // and a size.
+ bool
+ compare_is_identity() const
+ { return this->do_compare_is_identity(); }
+
// Return a hash code for this type for the method hash table.
// Types which are equivalent according to are_identical will have
// the same hash code.
array_type() const
{ return this->convert<const Array_type, TYPE_ARRAY>(); }
- // Return whether if this is an open array type.
+ // Return whether if this is a slice type.
bool
- is_open_array_type() const;
+ is_slice_type() const;
// If this is a map type, return it. Otherwise, return NULL.
Map_type*
// it, bound to EXPR.
static Expression*
bind_field_or_method(Gogo*, const Type* type, Expression* expr,
- const std::string& name, source_location);
+ const std::string& name, Location);
// Return true if NAME is an unexported field or method of TYPE.
static bool
is_unexported_field_or_method(Gogo*, const Type*, const std::string&,
std::vector<const Named_type*>*);
- // This type was passed to the builtin function make. ARGS are the
- // arguments passed to make after the type; this may be NULL if
- // there were none. Issue any required errors.
- bool
- check_make_expression(Expression_list* args, source_location location)
- { return this->do_check_make_expression(args, location); }
-
// Convert the builtin named types.
static void
convert_builtin_named_types(Gogo*);
- // Return a tree representing this type.
- tree
- get_tree(Gogo*);
-
- // Return a tree representing a zero initialization for this type.
- // This will be something like an INTEGER_CST or a CONSTRUCTOR. If
- // IS_CLEAR is true, then the memory is known to be zeroed; in that
- // case, this will return NULL if there is nothing to be done.
- tree
- get_init_tree(Gogo*, bool is_clear);
-
- // Like get_init_tree, but passing in the type to use for the
- // initializer.
- tree
- get_typed_init_tree(Gogo* gogo, tree type_tree, bool is_clear)
- { return this->do_get_init_tree(gogo, type_tree, is_clear); }
-
- // Return a tree for a make expression applied to this type.
- tree
- make_expression_tree(Translate_context* context, Expression_list* args,
- source_location location)
- { return this->do_make_expression_tree(context, args, location); }
+ // Return the backend representation of this type.
+ Btype*
+ get_backend(Gogo*);
// Build a type descriptor entry for this type. Return a pointer to
- // it.
+ // it. The location is the location which causes us to need the
+ // entry.
tree
- type_descriptor_pointer(Gogo* gogo);
+ type_descriptor_pointer(Gogo* gogo, Location);
// Return the type reflection string for this type.
std::string
std::string
mangled_name(Gogo*) const;
+ // If the size of the type can be determined, set *PSIZE to the size
+ // in bytes and return true. Otherwise, return false. This queries
+ // the backend.
+ bool
+ backend_type_size(Gogo*, unsigned int* psize);
+
+ // If the alignment of the type can be determined, set *PALIGN to
+ // the alignment in bytes and return true. Otherwise, return false.
+ bool
+ backend_type_align(Gogo*, unsigned int* palign);
+
+ // If the alignment of a struct field of this type can be
+ // determined, set *PALIGN to the alignment in bytes and return
+ // true. Otherwise, return false.
+ bool
+ backend_type_field_align(Gogo*, unsigned int* palign);
+
+ // Whether the backend size is known.
+ bool
+ is_backend_type_size_known(Gogo*) const;
+
+ // Get the hash and equality functions for a type.
+ void
+ type_functions(Gogo*, Named_type* name, Function_type* hash_fntype,
+ Function_type* equal_fntype, Named_object** hash_fn,
+ Named_object** equal_fn);
+
+ // Write the hash and equality type functions.
+ void
+ write_specific_type_functions(Gogo*, Named_type*,
+ const std::string& hash_name,
+ Function_type* hash_fntype,
+ const std::string& equal_name,
+ Function_type* equal_fntype);
+
// Export the type.
void
export_type(Export* exp) const
do_has_pointer() const
{ return false; }
- virtual unsigned int
- do_hash_for_method(Gogo*) const;
-
virtual bool
- do_check_make_expression(Expression_list* args, source_location);
+ do_compare_is_identity() const = 0;
+ virtual unsigned int
+ do_hash_for_method(Gogo*) const;
- virtual tree
- do_get_tree(Gogo*) = 0;
-
- virtual tree
- do_get_init_tree(Gogo*, tree, bool) = 0;
-
- virtual tree
- do_make_expression_tree(Translate_context*, Expression_list*,
- source_location);
+ virtual Btype*
+ do_get_backend(Gogo*) = 0;
virtual Expression*
do_type_descriptor(Gogo*, Named_type* name) = 0;
virtual void
do_reflection(Gogo*, std::string*) const = 0;
-
virtual void
do_mangled_name(Gogo*, std::string*) const = 0;
virtual void
do_export(Export*) const;
- // Return whether an expression is an integer.
- static bool
- check_int_value(Expression*, const char*, source_location);
-
// Return whether a method expects a pointer as the receiver.
static bool
method_expects_pointer(const Named_object*);
// Finalize the methods for a type.
static void
- finalize_methods(Gogo*, const Type*, source_location, Methods**);
+ finalize_methods(Gogo*, const Type*, Location, Methods**);
// Return a method from a set of methods.
static Method*
static unsigned int
hash_string(const std::string&, unsigned int);
- // Return a tree for the underlying type of a named type.
- static tree
- get_named_type_tree(Gogo* gogo, Type* base_type)
- { return base_type->get_tree_without_hash(gogo); }
+ // Return the backend representation for the underlying type of a
+ // named type.
+ static Btype*
+ get_named_base_btype(Gogo* gogo, Type* base_type)
+ { return base_type->get_btype_without_hash(gogo); }
private:
// Convert to the desired type classification, or return NULL. This
are_assignable_check_hidden(const Type* lhs, const Type* rhs,
bool check_hidden_fields, std::string* reason);
- // Get the hash and equality functions for a type.
+ // Map unnamed types to type descriptor decls.
+ typedef Unordered_map_hash(const Type*, Bvariable*, Type_hash_identical,
+ Type_identical) Type_descriptor_vars;
+
+ static Type_descriptor_vars type_descriptor_vars;
+
+ // Build the type descriptor variable for this type.
void
- type_functions(const char** hash_fn, const char** equal_fn) const;
+ make_type_descriptor_var(Gogo*);
+
+ // Return the name of the type descriptor variable. If NAME is not
+ // NULL, it is the name to use.
+ std::string
+ type_descriptor_var_name(Gogo*, Named_type* name);
+
+ // Return true if the type descriptor for this type should be
+ // defined in some other package. If NAME is not NULL, it is the
+ // name of this type. If this returns true it sets *PACKAGE to the
+ // package where the type descriptor is defined.
+ bool
+ type_descriptor_defined_elsewhere(Named_type* name, const Package** package);
+
+ // Build the hash and equality type functions for a type which needs
+ // specific functions.
+ void
+ specific_type_functions(Gogo*, Named_type*, Function_type* hash_fntype,
+ Function_type* equal_fntype, Named_object** hash_fn,
+ Named_object** equal_fn);
// Build a composite literal for the uncommon type information.
Expression*
// Build a composite literal for one method.
Expression*
method_constructor(Gogo*, Type* method_type, const std::string& name,
- const Method*) const;
+ const Method*, bool only_value_methods) const;
static tree
build_receive_return_type(tree type);
// Build stub methods for a type.
static void
build_stub_methods(Gogo*, const Type* type, const Methods* methods,
- source_location);
+ Location);
static void
build_one_stub_method(Gogo*, Method*, const char* receiver_name,
const Typed_identifier_list*, bool is_varargs,
- source_location);
+ Location);
static Expression*
apply_field_indexes(Expression*, const Method::Field_indexes*,
- source_location);
+ Location);
// Look for a field or method named NAME in TYPE.
static bool
bool* is_method, bool* found_pointer_method,
std::string* ambig1, std::string* ambig2);
- // Get a tree for a type without looking in the hash table for
- // identical types.
- tree
- get_tree_without_hash(Gogo*);
+ // Get the backend representation for a type without looking in the
+ // hash table for identical types.
+ Btype*
+ get_btype_without_hash(Gogo*);
- // A mapping from Type to tree, used to ensure that the GIMPLE
+ // A mapping from Type to Btype*, used to ensure that the backend
// representation of identical types is identical.
- typedef Unordered_map_hash(const Type*, tree, Type_hash_identical,
- Type_identical) Type_trees;
+ typedef Unordered_map_hash(const Type*, Btype*, Type_hash_identical,
+ Type_identical) Type_btypes;
- static Type_trees type_trees;
+ static Type_btypes type_btypes;
// A list of builtin named types.
static std::vector<Named_type*> named_builtin_types;
+ // A map from types which need specific type functions to the type
+ // functions themselves.
+ typedef std::pair<Named_object*, Named_object*> Hash_equal_fn;
+ typedef Unordered_map_hash(const Type*, Hash_equal_fn, Type_hash_identical,
+ Type_identical) Type_functions;
+
+ static Type_functions type_functions_table;
+
// The type classification.
Type_classification classification_;
- // The tree representation of the type, once it has been determined.
- tree tree_;
- // The decl for the type descriptor for this type. This starts out
- // as NULL and is filled in as needed.
- tree type_descriptor_decl_;
+ // The backend representation of the type, once it has been
+ // determined.
+ Btype* btype_;
+ // The type descriptor for this type. This starts out as NULL and
+ // is filled in as needed.
+ Bvariable* type_descriptor_var_;
};
// Type hash table operations.
{
public:
Typed_identifier(const std::string& name, Type* type,
- source_location location)
+ Location location)
: name_(name), type_(type), location_(location)
{ }
// Return the location where the name was seen. This is not always
// meaningful.
- source_location
+ Location
location() const
{ return this->location_; }
// Type.
Type* type_;
// The location where the name was seen.
- source_location location_;
+ Location location_;
};
// A list of Typed_identifiers.
resize(size_t c)
{
go_assert(c <= this->entries_.size());
- this->entries_.resize(c, Typed_identifier("", NULL, UNKNOWN_LOCATION));
+ this->entries_.resize(c, Typed_identifier("", NULL,
+ Linemap::unknown_location()));
}
// Iterators.
is_identical(const Integer_type* t) const;
protected:
+ bool
+ do_compare_is_identity() const
+ { return true; }
+
unsigned int
do_hash_for_method(Gogo*) const;
- tree
- do_get_tree(Gogo*);
-
- tree
- do_get_init_tree(Gogo*, tree, bool);
+ Btype*
+ do_get_backend(Gogo*);
Expression*
do_type_descriptor(Gogo*, Named_type*);
bool
is_identical(const Float_type* t) const;
- // Return a tree for this type without using a Gogo*.
- tree
- type_tree() const;
-
protected:
+ bool
+ do_compare_is_identity() const
+ { return false; }
+
unsigned int
do_hash_for_method(Gogo*) const;
- tree
- do_get_tree(Gogo*);
-
- tree
- do_get_init_tree(Gogo*, tree, bool);
+ Btype*
+ do_get_backend(Gogo*);
Expression*
do_type_descriptor(Gogo*, Named_type*);
bool
is_identical(const Complex_type* t) const;
- // Return a tree for this type without using a Gogo*.
- tree
- type_tree() const;
-
protected:
+ bool
+ do_compare_is_identity() const
+ { return false; }
+
unsigned int
do_hash_for_method(Gogo*) const;
- tree
- do_get_tree(Gogo*);
-
- tree
- do_get_init_tree(Gogo*, tree, bool);
+ Btype*
+ do_get_backend(Gogo*);
Expression*
do_type_descriptor(Gogo*, Named_type*);
do_has_pointer() const
{ return true; }
- tree
- do_get_tree(Gogo*);
+ bool
+ do_compare_is_identity() const
+ { return false; }
- tree
- do_get_init_tree(Gogo* gogo, tree, bool);
+ Btype*
+ do_get_backend(Gogo*);
Expression*
do_type_descriptor(Gogo*, Named_type*);
{
public:
Function_type(Typed_identifier* receiver, Typed_identifier_list* parameters,
- Typed_identifier_list* results, source_location location)
+ Typed_identifier_list* results, Location location)
: Type(TYPE_FUNCTION),
receiver_(receiver), parameters_(parameters), results_(results),
location_(location), is_varargs_(false), is_builtin_(false)
{ return this->is_builtin_; }
// The location where this type was defined.
- source_location
+ Location
location() const
{ return this->location_; }
Function_type*
copy_with_receiver(Type*) const;
+ // Finishing converting function types.
+ static void
+ convert_types(Gogo*);
+
static Type*
make_function_type_descriptor_type();
do_has_pointer() const
{ return true; }
+ bool
+ do_compare_is_identity() const
+ { return false; }
+
unsigned int
do_hash_for_method(Gogo*) const;
- tree
- do_get_tree(Gogo*);
-
- tree
- do_get_init_tree(Gogo*, tree, bool);
+ Btype*
+ do_get_backend(Gogo*);
Expression*
do_type_descriptor(Gogo*, Named_type*);
type_descriptor_params(Type*, const Typed_identifier*,
const Typed_identifier_list*);
+ Btype*
+ get_function_backend(Gogo*);
+
+ // A list of function types with multiple results and their
+ // placeholder backend representations, used to postpone building
+ // the structs we use for multiple results until all types are
+ // converted.
+ typedef std::vector<std::pair<Function_type*, Btype*> > Placeholders;
+ static Placeholders placeholders;
+
// The receiver name and type. This will be NULL for a normal
// function, non-NULL for a method.
Typed_identifier* receiver_;
// The location where this type was defined. This exists solely to
// give a location for the fields of the struct if this function
// returns multiple values.
- source_location location_;
+ Location location_;
// Whether this function takes a variable number of arguments.
bool is_varargs_;
// Whether this is a special builtin function which can not simply
do_has_pointer() const
{ return true; }
+ bool
+ do_compare_is_identity() const
+ { return true; }
+
unsigned int
do_hash_for_method(Gogo*) const;
- tree
- do_get_tree(Gogo*);
-
- tree
- do_get_init_tree(Gogo*, tree, bool);
+ Btype*
+ do_get_backend(Gogo*);
Expression*
do_type_descriptor(Gogo*, Named_type*);
const std::string&
field_name() const;
+ // Return whether this struct field is named NAME.
+ bool
+ is_field_name(const std::string& name) const;
+
// The field type.
Type*
type() const
{ return this->typed_identifier_.type(); }
// The field location.
- source_location
+ Location
location() const
{ return this->typed_identifier_.location(); }
class Struct_type : public Type
{
public:
- Struct_type(Struct_field_list* fields, source_location location)
+ Struct_type(Struct_field_list* fields, Location location)
: Type(TYPE_STRUCT),
fields_(fields), location_(location), all_methods_(NULL)
{ }
// NULL if there is no field with that name.
Field_reference_expression*
field_reference(Expression* struct_expr, const std::string& name,
- source_location) const;
+ Location) const;
// Return the total number of fields, including embedded fields.
// This is the number of values which can appear in a conversion to
traverse_field_types(Traverse* traverse)
{ return this->do_traverse(traverse); }
+ // If the offset of field INDEX in the backend implementation can be
+ // determined, set *POFFSET to the offset in bytes and return true.
+ // Otherwise, return false.
+ bool
+ backend_field_offset(Gogo*, unsigned int index, unsigned int* poffset);
+
// Import a struct type.
static Struct_type*
do_import(Import*);
- // Fill in the fields for a named struct type.
- tree
- fill_in_tree(Gogo*, tree);
-
static Type*
make_struct_type_descriptor_type();
+ // Write the hash function for this type.
+ void
+ write_hash_function(Gogo*, Named_type*, Function_type*, Function_type*);
+
+ // Write the equality function for this type.
+ void
+ write_equal_function(Gogo*, Named_type*);
+
protected:
int
do_traverse(Traverse*);
bool
do_has_pointer() const;
+ bool
+ do_compare_is_identity() const;
+
unsigned int
do_hash_for_method(Gogo*) const;
- tree
- do_get_tree(Gogo*);
-
- tree
- do_get_init_tree(Gogo*, tree, bool);
+ Btype*
+ do_get_backend(Gogo*);
Expression*
do_type_descriptor(Gogo*, Named_type*);
Field_reference_expression*
field_reference_depth(Expression* struct_expr, const std::string& name,
- source_location, Saw_named_type*,
+ Location, Saw_named_type*,
unsigned int* depth) const;
// The fields of the struct.
Struct_field_list* fields_;
// The place where the struct was declared.
- source_location location_;
+ Location location_;
// If this struct is unnamed, a list of methods.
Methods* all_methods_;
};
array_has_hidden_fields(const Named_type* within, std::string* reason) const
{ return this->element_type_->has_hidden_fields(within, reason); }
+ // Build the hash and equality functions if necessary.
+ void
+ finalize_methods(Gogo*);
+
// Return a tree for the pointer to the values in an array.
tree
value_pointer_tree(Gogo*, tree array) const;
static Array_type*
do_import(Import*);
- // Fill in the fields for a named array type.
- tree
- fill_in_array_tree(Gogo*, tree);
+ // Return the backend representation of the element type.
+ Btype*
+ get_backend_element(Gogo*);
- // Fill in the fields for a named slice type.
- tree
- fill_in_slice_tree(Gogo*, tree);
+ // Return the backend representation of the length.
+ Bexpression*
+ get_backend_length(Gogo*);
static Type*
make_array_type_descriptor_type();
static Type*
make_slice_type_descriptor_type();
+ // Write the hash function for this type.
+ void
+ write_hash_function(Gogo*, Named_type*, Function_type*, Function_type*);
+
+ // Write the equality function for this type.
+ void
+ write_equal_function(Gogo*, Named_type*);
+
protected:
int
do_traverse(Traverse* traverse);
return this->length_ == NULL || this->element_type_->has_pointer();
}
- unsigned int
- do_hash_for_method(Gogo*) const;
-
bool
- do_check_make_expression(Expression_list*, source_location);
-
- tree
- do_get_tree(Gogo*);
+ do_compare_is_identity() const
+ {
+ return (this->length_ != NULL
+ && this->element_type_->compare_is_identity());
+ }
- tree
- do_get_init_tree(Gogo*, tree, bool);
+ unsigned int
+ do_hash_for_method(Gogo*) const;
- tree
- do_make_expression_tree(Translate_context*, Expression_list*,
- source_location);
+ Btype*
+ do_get_backend(Gogo*);
Expression*
do_type_descriptor(Gogo*, Named_type*);
class Map_type : public Type
{
public:
- Map_type(Type* key_type, Type* val_type, source_location location)
+ Map_type(Type* key_type, Type* val_type, Location location)
: Type(TYPE_MAP),
key_type_(key_type), val_type_(val_type), location_(location)
{ }
static Type*
make_map_type_descriptor_type();
+ static Type*
+ make_map_descriptor_type();
+
+ // Build a map descriptor for this type. Return a pointer to it.
+ // The location is the location which causes us to need the
+ // descriptor.
+ tree
+ map_descriptor_pointer(Gogo* gogo, Location);
+
protected:
int
do_traverse(Traverse*);
do_has_pointer() const
{ return true; }
- unsigned int
- do_hash_for_method(Gogo*) const;
-
bool
- do_check_make_expression(Expression_list*, source_location);
-
- tree
- do_get_tree(Gogo*);
+ do_compare_is_identity() const
+ { return false; }
- tree
- do_get_init_tree(Gogo*, tree, bool);
+ unsigned int
+ do_hash_for_method(Gogo*) const;
- tree
- do_make_expression_tree(Translate_context*, Expression_list*,
- source_location);
+ Btype*
+ do_get_backend(Gogo*);
Expression*
do_type_descriptor(Gogo*, Named_type*);
do_export(Export*) const;
private:
+ // Mapping from map types to map descriptors.
+ typedef Unordered_map_hash(const Map_type*, Bvariable*, Type_hash_identical,
+ Type_identical) Map_descriptors;
+ static Map_descriptors map_descriptors;
+
+ Bvariable*
+ map_descriptor(Gogo*);
+
// The key type.
Type* key_type_;
// The value type.
Type* val_type_;
// Where the type was defined.
- source_location location_;
+ Location location_;
};
// The type of a channel.
do_has_pointer() const
{ return true; }
- unsigned int
- do_hash_for_method(Gogo*) const;
-
bool
- do_check_make_expression(Expression_list*, source_location);
-
- tree
- do_get_tree(Gogo*);
+ do_compare_is_identity() const
+ { return true; }
- tree
- do_get_init_tree(Gogo*, tree, bool);
+ unsigned int
+ do_hash_for_method(Gogo*) const;
- tree
- do_make_expression_tree(Translate_context*, Expression_list*,
- source_location);
+ Btype*
+ do_get_backend(Gogo*);
Expression*
do_type_descriptor(Gogo*, Named_type*);
class Interface_type : public Type
{
public:
- Interface_type(Typed_identifier_list* methods, source_location location)
+ Interface_type(Typed_identifier_list* methods, Location location)
: Type(TYPE_INTERFACE),
methods_(methods), location_(location)
{ go_assert(methods == NULL || !methods->empty()); }
// The location where the interface type was defined.
- source_location
+ Location
location() const
{ return this->location_; }
do_import(Import*);
// Make a struct for an empty interface type.
- static tree
- empty_type_tree(Gogo*);
-
- // Make a struct for non-empty interface type.
- static tree
- non_empty_type_tree(source_location);
-
- // Fill in the fields for a named interface type.
- tree
- fill_in_tree(Gogo*, tree);
+ static Btype*
+ get_backend_empty_interface_type(Gogo*);
static Type*
make_interface_type_descriptor_type();
do_has_pointer() const
{ return true; }
+ bool
+ do_compare_is_identity() const
+ { return false; }
+
unsigned int
do_hash_for_method(Gogo*) const;
- tree
- do_get_tree(Gogo*);
-
- tree
- do_get_init_tree(Gogo* gogo, tree, bool);
+ Btype*
+ do_get_backend(Gogo*);
Expression*
do_type_descriptor(Gogo*, Named_type*);
// NULL for the empty interface.
Typed_identifier_list* methods_;
// The location where the interface was defined.
- source_location location_;
+ Location location_;
};
// The value we keep for a named type. This lets us get the right
class Named_type : public Type
{
public:
- Named_type(Named_object* named_object, Type* type, source_location location)
+ Named_type(Named_object* named_object, Type* type, Location location)
: Type(TYPE_NAMED),
named_object_(named_object), in_function_(NULL), type_(type),
local_methods_(NULL), all_methods_(NULL),
interface_method_tables_(NULL), pointer_interface_method_tables_(NULL),
- location_(location), named_tree_(NULL), dependencies_(),
- is_visible_(true), is_error_(false), is_converted_(false),
- is_circular_(false), seen_(0)
+ location_(location), named_btype_(NULL), dependencies_(),
+ is_visible_(true), is_error_(false), is_placeholder_(false),
+ is_converted_(false), is_circular_(false), seen_(false),
+ seen_in_get_backend_(false)
{ }
// Return the associated Named_object. This holds the actual name.
{ return this->type_; }
// Return the location.
- source_location
+ Location
location() const
{ return this->location_; }
// Whether this is a builtin type.
bool
is_builtin() const
- { return this->location_ == BUILTINS_LOCATION; }
+ { return Linemap::is_predeclared_location(this->location_); }
// Whether this is a circular type: a pointer or function type that
// refers to itself, which is not possible in C.
bool
is_named_error_type() const;
+ // Return whether this type is comparable. If REASON is not NULL,
+ // set *REASON when returning false.
+ bool
+ named_type_is_comparable(std::string* reason) const;
+
// Add a method to this type.
Named_object*
add_method(const std::string& name, Function*);
// Add a method declaration to this type.
Named_object*
add_method_declaration(const std::string& name, Package* package,
- Function_type* type, source_location location);
+ Function_type* type, Location location);
// Add an existing method--one defined before the type itself was
// defined--to a type.
add_dependency(Named_type* nt)
{ this->dependencies_.push_back(nt); }
+ // Return true if the size and alignment of the backend
+ // representation of this type is known. This is always true after
+ // types have been converted, but may be false beforehand.
+ bool
+ is_named_backend_type_size_known() const
+ { return this->named_btype_ != NULL && !this->is_placeholder_; }
+
// Export the type.
void
export_named_type(Export*, const std::string& name) const;
bool
do_has_pointer() const;
- unsigned int
- do_hash_for_method(Gogo*) const;
-
bool
- do_check_make_expression(Expression_list* args, source_location location)
- { return this->type_->check_make_expression(args, location); }
-
- tree
- do_get_tree(Gogo*);
+ do_compare_is_identity() const;
- tree
- do_get_init_tree(Gogo* gogo, tree type_tree, bool is_clear)
- { return this->type_->get_typed_init_tree(gogo, type_tree, is_clear); }
+ unsigned int
+ do_hash_for_method(Gogo*) const;
- tree
- do_make_expression_tree(Translate_context* context, Expression_list* args,
- source_location location)
- { return this->type_->make_expression_tree(context, args, location); }
+ Btype*
+ do_get_backend(Gogo*);
Expression*
do_type_descriptor(Gogo*, Named_type*);
// tables for pointers to this type.
Interface_method_tables* pointer_interface_method_tables_;
// The location where this type was defined.
- source_location location_;
- // The tree for this type while converting to GENERIC. This is used
- // to avoid endless recursion when a named type refers to itself.
- tree named_tree_;
+ Location location_;
+ // The backend representation of this type during backend
+ // conversion. This is used to avoid endless recursion when a named
+ // type refers to itself.
+ Btype* named_btype_;
// A list of types which must be converted to the backend
// representation before this type can be converted. This is for
// cases like
bool is_visible_;
// Whether this type is erroneous.
bool is_error_;
+ // Whether the current value of named_btype_ is a placeholder for
+ // which the final size of the type is not known.
+ bool is_placeholder_;
// Whether this type has been converted to the backend
- // representation.
+ // representation. Implies that is_placeholder_ is false.
bool is_converted_;
// Whether this is a pointer or function type which refers to the
// type itself.
// used to prevent infinite recursion when a type refers to itself.
// This is mutable because it is always reset to false when the
// function exits.
- mutable int seen_;
+ mutable bool seen_;
+ // Like seen_, but used only by do_get_backend.
+ bool seen_in_get_backend_;
};
// A forward declaration. This handles a type which has been declared
// Add a method declaration to this type.
Named_object*
add_method_declaration(const std::string& name, Function_type*,
- source_location);
+ Location);
protected:
int
do_has_pointer() const
{ return this->real_type()->has_pointer(); }
+ bool
+ do_compare_is_identity() const
+ { return this->real_type()->compare_is_identity(); }
+
unsigned int
do_hash_for_method(Gogo* gogo) const
{ return this->real_type()->hash_for_method(gogo); }
- bool
- do_check_make_expression(Expression_list* args, source_location location)
- { return this->base()->check_make_expression(args, location); }
-
- tree
- do_get_tree(Gogo* gogo);
-
- tree
- do_get_init_tree(Gogo* gogo, tree type_tree, bool is_clear)
- { return this->base()->get_typed_init_tree(gogo, type_tree, is_clear); }
-
- tree
- do_make_expression_tree(Translate_context* context, Expression_list* args,
- source_location location)
- { return this->base()->make_expression_tree(context, args, location); }
+ Btype*
+ do_get_backend(Gogo* gogo);
Expression*
do_type_descriptor(Gogo*, Named_type*);