// Return whether this is an open array type.
bool
-Type::is_open_array_type() const
+Type::is_slice_type() const
{
return this->array_type() != NULL && this->array_type()->length() == NULL;
}
if (lhs->is_nil_type()
&& (rhs->points_to() != NULL
|| rhs->interface_type() != NULL
- || rhs->is_open_array_type()
+ || rhs->is_slice_type()
|| rhs->map_type() != NULL
|| rhs->channel_type() != NULL
|| rhs->function_type() != NULL))
if (rhs->is_nil_type()
&& (lhs->points_to() != NULL
|| lhs->interface_type() != NULL
- || lhs->is_open_array_type()
+ || lhs->is_slice_type()
|| lhs->map_type() != NULL
|| lhs->channel_type() != NULL
|| lhs->function_type() != NULL))
if (rhs->is_nil_type()
&& (lhs->points_to() != NULL
|| lhs->function_type() != NULL
- || lhs->is_open_array_type()
+ || lhs->is_slice_type()
|| lhs->map_type() != NULL
|| lhs->channel_type() != NULL
|| lhs->interface_type() != NULL))
bool
Type::are_assignable(const Type* lhs, const Type* rhs, std::string* reason)
{
- return Type::are_assignable_check_hidden(lhs, rhs, true, reason);
+ return Type::are_assignable_check_hidden(lhs, rhs, false, reason);
}
// Like are_assignable but don't check for hidden fields.
{
if (rhs->integer_type() != NULL)
return true;
- if (rhs->is_open_array_type() && rhs->named_type() == NULL)
+ if (rhs->is_slice_type() && rhs->named_type() == NULL)
{
const Type* e = rhs->array_type()->element_type()->forwarded();
if (e->integer_type() != NULL
// A string may be converted to []byte or []int.
if (rhs->is_string_type()
- && lhs->is_open_array_type()
+ && lhs->is_slice_type()
&& lhs->named_type() == NULL)
{
const Type* e = lhs->array_type()->element_type()->forwarded();
// Return a pointer to the type descriptor for this type.
tree
-Type::type_descriptor_pointer(Gogo* gogo, source_location location)
+Type::type_descriptor_pointer(Gogo* gogo, Location location)
{
Type* t = this->forwarded();
if (t->type_descriptor_var_ == NULL)
tree var_tree = var_to_tree(t->type_descriptor_var_);
if (var_tree == error_mark_node)
return error_mark_node;
- return build_fold_addr_expr_loc(location, var_tree);
+ return build_fold_addr_expr_loc(location.gcc_location(), var_tree);
}
// A mapping from unnamed types to type descriptor variables.
}
}
- source_location loc = nt == NULL ? BUILTINS_LOCATION : nt->location();
+ Location loc = nt == NULL ? Linemap::predeclared_location() : nt->location();
if (is_defined_elsewhere)
{
va_list ap;
va_start(ap, nfields);
- source_location bloc = BUILTINS_LOCATION;
+ Location bloc = Linemap::predeclared_location();
Struct_field_list* sfl = new Struct_field_list();
for (int i = 0; i < nfields; i++)
{
Named_type*
Type::make_builtin_named_type(const char* name, Type* type)
{
- source_location bloc = BUILTINS_LOCATION;
+ Location bloc = Linemap::predeclared_location();
Named_object* no = Named_object::make_type(name, NULL, type, bloc);
Named_type* ret = no->type_value();
Type::named_builtin_types.push_back(ret);
static Type* ret;
if (ret == NULL)
{
- source_location bloc = BUILTINS_LOCATION;
+ Location bloc = Linemap::predeclared_location();
Type* uint8_type = Type::lookup_integer_type("uint8");
Type* uint32_type = Type::lookup_integer_type("uint32");
Named_type* name, const Methods* methods,
bool only_value_methods)
{
- source_location bloc = BUILTINS_LOCATION;
+ Location bloc = Linemap::predeclared_location();
Type* td_type = Type::make_type_descriptor_type();
const Struct_field_list* fields = td_type->struct_type()->fields();
Named_type* name, const Methods* methods,
bool only_value_methods) const
{
- source_location bloc = BUILTINS_LOCATION;
+ Location bloc = Linemap::predeclared_location();
const Struct_field_list* fields = uncommon_type->struct_type()->fields();
const Methods* methods,
bool only_value_methods) const
{
- source_location bloc = BUILTINS_LOCATION;
+ Location bloc = Linemap::predeclared_location();
std::vector<std::pair<std::string, const Method*> > smethods;
if (methods != NULL)
const Method* m,
bool only_value_methods) const
{
- source_location bloc = BUILTINS_LOCATION;
+ Location bloc = Linemap::predeclared_location();
const Struct_field_list* fields = method_type->struct_type()->fields();
Expression*
do_type_descriptor(Gogo*, Named_type*)
- { return Expression::make_error(BUILTINS_LOCATION); }
+ { return Expression::make_error(Linemap::predeclared_location()); }
void
do_reflection(Gogo*, std::string*) const
Type::make_named_bool_type()
{
Type* bool_type = Type::make_boolean_type();
- Named_object* named_object = Named_object::make_type("bool", NULL,
- bool_type,
- BUILTINS_LOCATION);
+ Named_object* named_object =
+ Named_object::make_type("bool", NULL, bool_type,
+ Linemap::predeclared_location());
Named_type* named_type = named_object->type_value();
named_bool_type = named_type;
return named_type;
Integer_type* integer_type = new Integer_type(false, is_unsigned, bits,
runtime_type_kind);
std::string sname(name);
- Named_object* named_object = Named_object::make_type(sname, NULL,
- integer_type,
- BUILTINS_LOCATION);
+ Named_object* named_object =
+ Named_object::make_type(sname, NULL, integer_type,
+ Linemap::predeclared_location());
Named_type* named_type = named_object->type_value();
std::pair<Named_integer_types::iterator, bool> ins =
Integer_type::named_integer_types.insert(std::make_pair(sname, named_type));
{
Float_type* float_type = new Float_type(false, bits, runtime_type_kind);
std::string sname(name);
- Named_object* named_object = Named_object::make_type(sname, NULL, float_type,
- BUILTINS_LOCATION);
+ Named_object* named_object =
+ Named_object::make_type(sname, NULL, float_type,
+ Linemap::predeclared_location());
Named_type* named_type = named_object->type_value();
std::pair<Named_float_types::iterator, bool> ins =
Float_type::named_float_types.insert(std::make_pair(sname, named_type));
Complex_type* complex_type = new Complex_type(false, bits,
runtime_type_kind);
std::string sname(name);
- Named_object* named_object = Named_object::make_type(sname, NULL,
- complex_type,
- BUILTINS_LOCATION);
+ Named_object* named_object =
+ Named_object::make_type(sname, NULL, complex_type,
+ Linemap::predeclared_location());
Named_type* named_type = named_object->type_value();
std::pair<Named_complex_types::iterator, bool> ins =
Complex_type::named_complex_types.insert(std::make_pair(sname,
Type* pb = Type::make_pointer_type(b);
fields[0].name = "__data";
fields[0].btype = pb->get_backend(gogo);
- fields[0].location = UNKNOWN_LOCATION;
+ fields[0].location = Linemap::predeclared_location();
Type* int_type = Type::lookup_integer_type("int");
fields[1].name = "__length";
fields[1].btype = int_type->get_backend(gogo);
- fields[1].location = UNKNOWN_LOCATION;
+ fields[1].location = fields[0].location;
backend_string_type = gogo->backend()->struct_type(fields);
}
Type::make_named_string_type()
{
Type* string_type = Type::make_string_type();
- Named_object* named_object = Named_object::make_type("string", NULL,
- string_type,
- BUILTINS_LOCATION);
+ Named_object* named_object =
+ Named_object::make_type("string", NULL, string_type,
+ Linemap::predeclared_location());
Named_type* named_type = named_object->type_value();
named_string_type = named_type;
return named_type;
Expression*
Function_type::do_type_descriptor(Gogo* gogo, Named_type* name)
{
- source_location bloc = BUILTINS_LOCATION;
+ Location bloc = Linemap::predeclared_location();
Type* ftdt = Function_type::make_function_type_descriptor_type();
const Typed_identifier* receiver,
const Typed_identifier_list* params)
{
- source_location bloc = BUILTINS_LOCATION;
+ Location bloc = Linemap::predeclared_location();
if (receiver == NULL && params == NULL)
return Expression::make_slice_composite_literal(params_type, NULL, bloc);
Type::make_function_type(Typed_identifier* receiver,
Typed_identifier_list* parameters,
Typed_identifier_list* results,
- source_location location)
+ Location location)
{
return new Function_type(receiver, parameters, results, location);
}
}
else
{
- source_location bloc = BUILTINS_LOCATION;
+ Location bloc = Linemap::predeclared_location();
const Methods* methods;
Type* deref = this->points_to();
do_type_descriptor(Gogo*, Named_type*)
{
go_assert(saw_errors());
- return Expression::make_error(UNKNOWN_LOCATION);
+ return Expression::make_error(Linemap::unknown_location());
}
void
Field_reference_expression*
Struct_type::field_reference(Expression* struct_expr, const std::string& name,
- source_location location) const
+ Location location) const
{
unsigned int depth;
return this->field_reference_depth(struct_expr, name, location, NULL,
Field_reference_expression*
Struct_type::field_reference_depth(Expression* struct_expr,
const std::string& name,
- source_location location,
+ Location location,
Saw_named_type* saw,
unsigned int* depth) const
{
Expression*
Struct_type::do_type_descriptor(Gogo* gogo, Named_type* name)
{
- source_location bloc = BUILTINS_LOCATION;
+ Location bloc = Linemap::predeclared_location();
Type* stdt = Struct_type::make_struct_type_descriptor_type();
if (p->has_tag())
{
exp->write_c_string(" ");
- Expression* expr = Expression::make_string(p->tag(),
- BUILTINS_LOCATION);
+ Expression* expr =
+ Expression::make_string(p->tag(), Linemap::predeclared_location());
expr->export_expression(exp);
delete expr;
}
Struct_type*
Type::make_struct_type(Struct_field_list* fields,
- source_location location)
+ Location location)
{
return new Struct_type(fields, location);
}
Type* pet = Type::make_pointer_type(type->element_type());
Btype* pbet = pet->get_backend(gogo);
+ Location ploc = Linemap::predeclared_location();
Backend::Btyped_identifier* p = &(*bfields)[0];
p->name = "__values";
p->btype = pbet;
- p->location = UNKNOWN_LOCATION;
+ p->location = ploc;
Type* int_type = Type::lookup_integer_type("int");
p = &(*bfields)[1];
p->name = "__count";
p->btype = int_type->get_backend(gogo);
- p->location = UNKNOWN_LOCATION;
+ p->location = ploc;
p = &(*bfields)[2];
p->name = "__capacity";
p->btype = int_type->get_backend(gogo);
- p->location = UNKNOWN_LOCATION;
+ p->location = ploc;
}
// Get a tree for the type of this array. A fixed array is simply
Expression*
Array_type::array_type_descriptor(Gogo* gogo, Named_type* name)
{
- source_location bloc = BUILTINS_LOCATION;
+ Location bloc = Linemap::predeclared_location();
Type* atdt = Array_type::make_array_type_descriptor_type();
Expression*
Array_type::slice_type_descriptor(Gogo* gogo, Named_type* name)
{
- source_location bloc = BUILTINS_LOCATION;
+ Location bloc = Linemap::predeclared_location();
Type* stdt = Array_type::make_slice_type_descriptor_type();
{
std::vector<Backend::Btyped_identifier> bfields(4);
+ Location bloc = Linemap::predeclared_location();
+
Type* pdt = Type::make_type_descriptor_ptr_type();
bfields[0].name = "__descriptor";
bfields[0].btype = pdt->get_backend(gogo);
- bfields[0].location = BUILTINS_LOCATION;
+ bfields[0].location = bloc;
Type* uintptr_type = Type::lookup_integer_type("uintptr");
bfields[1].name = "__element_count";
bfields[1].btype = uintptr_type->get_backend(gogo);
- bfields[1].location = BUILTINS_LOCATION;
+ bfields[1].location = bloc;
bfields[2].name = "__bucket_count";
bfields[2].btype = bfields[1].btype;
- bfields[2].location = BUILTINS_LOCATION;
+ bfields[2].location = bloc;
Btype* bvt = gogo->backend()->void_type();
Btype* bpvt = gogo->backend()->pointer_type(bvt);
Btype* bppvt = gogo->backend()->pointer_type(bpvt);
bfields[3].name = "__buckets";
bfields[3].btype = bppvt;
- bfields[3].location = BUILTINS_LOCATION;
+ bfields[3].location = bloc;
Btype *bt = gogo->backend()->struct_type(bfields);
- bt = gogo->backend()->named_type("__go_map", bt, BUILTINS_LOCATION);
+ bt = gogo->backend()->named_type("__go_map", bt, bloc);
backend_map_type = gogo->backend()->pointer_type(bt);
}
return backend_map_type;
Expression*
Map_type::do_type_descriptor(Gogo* gogo, Named_type* name)
{
- source_location bloc = BUILTINS_LOCATION;
+ Location bloc = Linemap::predeclared_location();
Type* mtdt = Map_type::make_map_type_descriptor_type();
// Build a map descriptor for this type. Return a pointer to it.
tree
-Map_type::map_descriptor_pointer(Gogo* gogo, source_location location)
+Map_type::map_descriptor_pointer(Gogo* gogo, Location location)
{
Bvariable* bvar = this->map_descriptor(gogo);
tree var_tree = var_to_tree(bvar);
if (var_tree == error_mark_node)
return error_mark_node;
- return build_fold_addr_expr_loc(location, var_tree);
+ return build_fold_addr_expr_loc(location.gcc_location(), var_tree);
}
// Build a map descriptor for this type.
Expression_list* vals = new Expression_list();
vals->reserve(4);
- source_location bloc = BUILTINS_LOCATION;
+ Location bloc = Linemap::predeclared_location();
Struct_field_list::const_iterator p = fields->begin();
// Make a map type.
Map_type*
-Type::make_map_type(Type* key_type, Type* val_type, source_location location)
+Type::make_map_type(Type* key_type, Type* val_type, Location location)
{
return new Map_type(key_type, val_type, location);
}
{
std::vector<Backend::Btyped_identifier> bfields;
Btype* bt = gogo->backend()->struct_type(bfields);
- bt = gogo->backend()->named_type("__go_channel", bt, BUILTINS_LOCATION);
+ bt = gogo->backend()->named_type("__go_channel", bt,
+ Linemap::predeclared_location());
backend_channel_type = gogo->backend()->pointer_type(bt);
}
return backend_channel_type;
Expression*
Channel_type::do_type_descriptor(Gogo* gogo, Named_type* name)
{
- source_location bloc = BUILTINS_LOCATION;
+ Location bloc = Linemap::predeclared_location();
Type* ctdt = Channel_type::make_chan_type_descriptor_type();
{
std::vector<Backend::Btyped_identifier> bfields(2);
+ Location bloc = Linemap::predeclared_location();
+
Type* pdt = Type::make_type_descriptor_ptr_type();
bfields[0].name = "__type_descriptor";
bfields[0].btype = pdt->get_backend(gogo);
- bfields[0].location = UNKNOWN_LOCATION;
+ bfields[0].location = bloc;
Type* vt = Type::make_pointer_type(Type::make_void_type());
bfields[1].name = "__object";
bfields[1].btype = vt->get_backend(gogo);
- bfields[1].location = UNKNOWN_LOCATION;
+ bfields[1].location = bloc;
empty_interface_type = gogo->backend()->struct_type(bfields);
}
get_backend_interface_fields(Gogo* gogo, Interface_type* type,
std::vector<Backend::Btyped_identifier>* bfields)
{
- source_location loc = type->location();
+ Location loc = type->location();
std::vector<Backend::Btyped_identifier> mfields(type->methods()->size() + 1);
Type* vt = Type::make_pointer_type(Type::make_void_type());
(*bfields)[1].name = "__object";
(*bfields)[1].btype = vt->get_backend(gogo);
- (*bfields)[1].location = UNKNOWN_LOCATION;
+ (*bfields)[1].location = Linemap::predeclared_location();
}
// Return a tree for an interface type. An interface is a pointer to
Expression*
Interface_type::do_type_descriptor(Gogo* gogo, Named_type* name)
{
- source_location bloc = BUILTINS_LOCATION;
+ Location bloc = Linemap::predeclared_location();
Type* itdt = Interface_type::make_interface_type_descriptor_type();
Struct_field_list::const_iterator pif = ifields->begin();
go_assert(pif->is_field_name("commonType"));
- ivals->push_back(this->type_descriptor_constructor(gogo,
- RUNTIME_TYPE_KIND_INTERFACE,
- name, NULL, true));
+ const int rt = RUNTIME_TYPE_KIND_INTERFACE;
+ ivals->push_back(this->type_descriptor_constructor(gogo, rt, name, NULL,
+ true));
++pif;
go_assert(pif->is_field_name("methods"));
ret->append("interface {");
if (this->methods_ != NULL)
{
+ ret->push_back(' ');
for (Typed_identifier_list::const_iterator p = this->methods_->begin();
p != this->methods_->end();
++p)
{
if (p != this->methods_->begin())
- ret->append(";");
- ret->push_back(' ');
+ ret->append("; ");
if (!Gogo::is_hidden_name(p->name()))
ret->append(p->name());
else
sub = sub.substr(4);
ret->append(sub);
}
+ ret->push_back(' ');
}
- ret->append(" }");
+ ret->append("}");
}
// Mangled name.
Interface_type*
Type::make_interface_type(Typed_identifier_list* methods,
- source_location location)
+ Location location)
{
return new Interface_type(methods, location);
}
// Bind a method to an object.
Expression*
-Method::bind_method(Expression* expr, source_location location) const
+Method::bind_method(Expression* expr, Location location) const
{
if (this->stub_ == NULL)
{
// Return the location of the method receiver.
-source_location
+Location
Named_method::do_receiver_location() const
{
return this->do_type()->receiver()->location();
// Bind a method to an object.
Expression*
-Named_method::do_bind_method(Expression* expr, source_location location) const
+Named_method::do_bind_method(Expression* expr, Location location) const
{
Named_object* no = this->named_object_;
Bound_method_expression* bme = Expression::make_bound_method(expr, no,
Expression*
Interface_method::do_bind_method(Expression* expr,
- source_location location) const
+ Location location) const
{
return Expression::make_interface_field_reference(expr, this->name_,
location);
Named_object*
Named_type::add_method_declaration(const std::string& name, Package* package,
Function_type* type,
- source_location location)
+ Location location)
{
if (this->local_methods_ == NULL)
this->local_methods_ = new Bindings(NULL);
// essentially a pointer: a pointer, a slice, a function, a map, or
// a channel.
if (type->points_to() != NULL
- || type->is_open_array_type()
+ || type->is_slice_type()
|| type->function_type() != NULL
|| type->map_type() != NULL
|| type->channel_type() != NULL)
case TYPE_ARRAY:
// Slice types were completed in create_placeholder.
- if (!base->is_open_array_type())
+ if (!base->is_slice_type())
{
Btype* bet = base->array_type()->get_backend_element(gogo);
Bexpression* blen = base->array_type()->get_backend_length(gogo);
break;
case TYPE_ARRAY:
- if (base->is_open_array_type())
+ if (base->is_slice_type())
bt = gogo->backend()->placeholder_struct_type(this->name(),
this->location_);
else
this->named_btype_ = bt;
- if (base->is_open_array_type())
+ if (base->is_slice_type())
{
// We do not record slices as dependencies of other types,
// because we can fill them in completely here with the final
void
Named_type::do_reflection(Gogo* gogo, std::string* ret) const
{
- if (this->location() != BUILTINS_LOCATION)
+ if (!Linemap::is_predeclared_location(this->location()))
{
const Package* package = this->named_object_->package();
if (package != NULL)
{
Named_object* no = this->named_object_;
std::string name;
- if (this->location() == BUILTINS_LOCATION)
+ if (Linemap::is_predeclared_location(this->location()))
go_assert(this->in_function_ == NULL);
else
{
Named_type*
Type::make_named_type(Named_object* named_object, Type* type,
- source_location location)
+ Location location)
{
return new Named_type(named_object, type, location);
}
// all required stubs.
void
-Type::finalize_methods(Gogo* gogo, const Type* type, source_location location,
+Type::finalize_methods(Gogo* gogo, const Type* type, Location location,
Methods** all_methods)
{
*all_methods = NULL;
void
Type::build_stub_methods(Gogo* gogo, const Type* type, const Methods* methods,
- source_location location)
+ Location location)
{
if (methods == NULL)
return;
Type* receiver_type = const_cast<Type*>(type);
if (!m->is_value_method())
receiver_type = Type::make_pointer_type(receiver_type);
- source_location receiver_location = m->receiver_location();
+ Location receiver_location = m->receiver_location();
Typed_identifier* receiver = new Typed_identifier(buf, receiver_type,
receiver_location);
const char* receiver_name,
const Typed_identifier_list* params,
bool is_varargs,
- source_location location)
+ Location location)
{
Named_object* receiver_object = gogo->lookup(receiver_name, NULL);
go_assert(receiver_object != NULL);
Expression*
Type::apply_field_indexes(Expression* expr,
const Method::Field_indexes* field_indexes,
- source_location location)
+ Location location)
{
if (field_indexes == NULL)
return expr;
Expression*
Type::bind_field_or_method(Gogo* gogo, const Type* type, Expression* expr,
const std::string& name,
- source_location location)
+ Location location)
{
if (type->deref()->is_error_type())
return Expression::make_error(location);
Named_object*
Forward_declaration_type::add_method_declaration(const std::string& name,
Function_type* type,
- source_location location)
+ Location location)
{
Named_object* no = this->named_object();
if (no->is_unknown())
Expression*
Forward_declaration_type::do_type_descriptor(Gogo* gogo, Named_type* name)
{
+ Location ploc = Linemap::predeclared_location();
if (!this->is_defined())
- return Expression::make_nil(BUILTINS_LOCATION);
+ return Expression::make_nil(ploc);
else
{
Type* t = this->real_type();
if (name != NULL)
return this->named_type_descriptor(gogo, t, name);
else
- return Expression::make_type_descriptor(t, BUILTINS_LOCATION);
+ return Expression::make_type_descriptor(t, ploc);
}
}