aboutsummaryrefslogtreecommitdiff
path: root/gcc/go/gofrontend/gogo.cc
diff options
context:
space:
mode:
Diffstat (limited to 'gcc/go/gofrontend/gogo.cc')
-rw-r--r--gcc/go/gofrontend/gogo.cc201
1 files changed, 26 insertions, 175 deletions
diff --git a/gcc/go/gofrontend/gogo.cc b/gcc/go/gofrontend/gogo.cc
index adc8e8a2363..da8f3c584eb 100644
--- a/gcc/go/gofrontend/gogo.cc
+++ b/gcc/go/gofrontend/gogo.cc
@@ -868,32 +868,6 @@ Gogo::register_gc_vars(const std::vector<Named_object*>& var_gc,
init_stmts.push_back(this->backend()->expression_statement(init_bfn, bcall));
}
-// Get the name to use for the import control function. If there is a
-// global function or variable, then we know that that name must be
-// unique in the link, and we use it as the basis for our name.
-
-const std::string&
-Gogo::get_init_fn_name()
-{
- if (this->init_fn_name_.empty())
- {
- go_assert(this->package_ != NULL);
- if (this->is_main_package())
- {
- // Use a name which the runtime knows.
- this->init_fn_name_ = "__go_init_main";
- }
- else
- {
- std::string s = this->pkgpath_symbol();
- s.append("..import");
- this->init_fn_name_ = s;
- }
- }
-
- return this->init_fn_name_;
-}
-
// Build the decl for the initialization function.
Named_object*
@@ -1774,11 +1748,7 @@ Gogo::start_function(const std::string& name, Function_type* type,
"func init must have no arguments and no return values");
// There can be multiple "init" functions, so give them each a
// different name.
- static int init_count;
- char buf[30];
- snprintf(buf, sizeof buf, ".$init%d", init_count);
- ++init_count;
- nested_name = buf;
+ nested_name = this->init_function_name();
pname = &nested_name;
is_init = true;
}
@@ -1787,22 +1757,15 @@ Gogo::start_function(const std::string& name, Function_type* type,
else
{
// Invent a name for a nested function.
- static int nested_count;
- char buf[30];
- snprintf(buf, sizeof buf, ".$nested%d", nested_count);
- ++nested_count;
- nested_name = buf;
+ nested_name = this->nested_function_name();
pname = &nested_name;
}
Named_object* ret;
if (Gogo::is_sink_name(*pname))
{
- static int sink_count;
- char buf[30];
- snprintf(buf, sizeof buf, ".$sink%d", sink_count);
- ++sink_count;
- ret = Named_object::make_function(buf, NULL, function);
+ std::string sname(this->sink_function_name());
+ ret = Named_object::make_function(sname, NULL, function);
ret->func_value()->set_is_sink();
if (!type->is_method())
@@ -1845,11 +1808,8 @@ Gogo::start_function(const std::string& name, Function_type* type,
{
// Redefinition error. Invent a name to avoid knockon
// errors.
- static int redefinition_count;
- char buf[30];
- snprintf(buf, sizeof buf, ".$redefined%d", redefinition_count);
- ++redefinition_count;
- ret = this->package_->bindings()->add_function(buf, NULL, function);
+ std::string rname(this->redefined_function_name());
+ ret = this->package_->bindings()->add_function(rname, NULL, function);
}
}
else
@@ -2274,47 +2234,6 @@ Gogo::record_interface_type(Interface_type* itype)
this->interface_types_.push_back(itype);
}
-// Return an erroneous name that indicates that an error has already
-// been reported.
-
-std::string
-Gogo::erroneous_name()
-{
- static int erroneous_count;
- char name[50];
- snprintf(name, sizeof name, "$erroneous%d", erroneous_count);
- ++erroneous_count;
- return name;
-}
-
-// Return whether a name is an erroneous name.
-
-bool
-Gogo::is_erroneous_name(const std::string& name)
-{
- return name.compare(0, 10, "$erroneous") == 0;
-}
-
-// Return a name for a thunk object.
-
-std::string
-Gogo::thunk_name()
-{
- static int thunk_count;
- char thunk_name[50];
- snprintf(thunk_name, sizeof thunk_name, "$thunk%d", thunk_count);
- ++thunk_count;
- return thunk_name;
-}
-
-// Return whether a function is a thunk.
-
-bool
-Gogo::is_thunk(const Named_object* no)
-{
- return no->name().compare(0, 6, "$thunk") == 0;
-}
-
// Define the global names. We do this only after parsing all the
// input files, because the program might define the global names
// itself.
@@ -4195,10 +4114,10 @@ Build_recover_thunks::function(Named_object* orig_no)
if (orig_fntype->is_varargs())
new_fntype->set_is_varargs();
- std::string name = orig_no->name();
+ Type* rtype = NULL;
if (orig_fntype->is_method())
- name += "$" + orig_fntype->receiver()->type()->mangled_name(gogo);
- name += "$recover";
+ rtype = orig_fntype->receiver()->type();
+ std::string name(gogo->recover_thunk_name(orig_no->name(), rtype));
Named_object *new_no = gogo->start_function(name, new_fntype, false,
location);
Function *new_func = new_no->func_value();
@@ -5449,29 +5368,10 @@ Function::get_or_make_decl(Gogo* gogo, Named_object* no)
{
if (!this->is_unnamed_type_stub_method_)
is_visible = true;
- std::string pkgpath = gogo->pkgpath_symbol();
- if (this->type_->is_method()
- && Gogo::is_hidden_name(no->name())
- && Gogo::hidden_name_pkgpath(no->name()) != gogo->pkgpath())
- {
- // This is a method we created for an unexported
- // method of an imported embedded type. We need to
- // use the pkgpath of the imported package to avoid
- // a possible name collision. See bug478 for a test
- // case.
- std::string p = Gogo::hidden_name_pkgpath(no->name());
- pkgpath = gogo->pkgpath_symbol_for_package(p);
- }
-
- asm_name = pkgpath;
- asm_name.append(1, '.');
- asm_name.append(Gogo::unpack_hidden_name(no->name()));
- if (this->type_->is_method())
- {
- asm_name.append(1, '.');
- Type* rtype = this->type_->receiver()->type();
- asm_name.append(rtype->mangled_name(gogo));
- }
+ Type* rtype = NULL;
+ if (this->type_->is_method())
+ rtype = this->type_->receiver()->type();
+ asm_name = gogo->function_asm_name(no->name(), NULL, rtype);
}
if (!this->asm_name_.empty())
@@ -5510,8 +5410,8 @@ Function::get_or_make_decl(Gogo* gogo, Named_object* no)
disable_split_stack = true;
// Encode name if asm_name not already set at this point
- if (asm_name.empty() && go_id_needs_encoding(no->get_id(gogo)))
- asm_name = go_encode_id(no->get_id(gogo));
+ if (asm_name.empty())
+ asm_name = gogo->unexported_function_asm_name(no->name());
// This should go into a unique section if that has been
// requested elsewhere, or if this is a nointerface function.
@@ -5553,30 +5453,12 @@ Function_declaration::get_or_make_decl(Gogo* gogo, Named_object* no)
std::string asm_name;
if (this->asm_name_.empty())
- {
- asm_name = (no->package() == NULL
- ? gogo->pkgpath_symbol()
- : no->package()->pkgpath_symbol());
- if (this->fntype_->is_method()
- && Gogo::is_hidden_name(no->name())
- && Gogo::hidden_name_pkgpath(no->name()) != gogo->pkgpath())
- {
- // This is a method created for an unexported method of
- // an imported embedded type. Use the pkgpath of the
- // imported package. This matches code in
- // Function::get_or_make_decl, above.
- std::string p = Gogo::hidden_name_pkgpath(no->name());
- asm_name = gogo->pkgpath_symbol_for_package(p);
- }
- asm_name.append(1, '.');
- asm_name.append(Gogo::unpack_hidden_name(no->name()));
- if (this->fntype_->is_method())
- {
- asm_name.append(1, '.');
- Type* rtype = this->fntype_->receiver()->type();
- asm_name.append(rtype->mangled_name(gogo));
- }
- }
+ {
+ Type* rtype = NULL;
+ if (this->fntype_->is_method())
+ rtype = this->fntype_->receiver()->type();
+ asm_name = gogo->function_asm_name(no->name(), no->package(), rtype);
+ }
else if (go_id_needs_encoding(no->get_id(gogo)))
asm_name = go_encode_id(no->get_id(gogo));
@@ -6815,18 +6697,8 @@ Variable::get_backend_variable(Gogo* gogo, Named_object* function,
: gogo->package_name());
var_name.push_back('.');
var_name.append(n);
- std::string asm_name;
- if (Gogo::is_hidden_name(name))
- asm_name = var_name;
- else
- {
- asm_name = package != NULL
- ? package->pkgpath_symbol()
- : gogo->pkgpath_symbol();
- asm_name.push_back('.');
- asm_name.append(n);
- }
- asm_name = go_encode_id(asm_name);
+
+ std::string asm_name(gogo->global_var_asm_name(name, package));
bool is_hidden = Gogo::is_hidden_name(name);
// Hack to export runtime.writeBarrier. FIXME.
@@ -7416,23 +7288,18 @@ Named_object::get_backend_variable(Gogo* gogo, Named_object* function)
go_unreachable();
}
-
// Return the external identifier for this object.
std::string
Named_object::get_id(Gogo* gogo)
{
- go_assert(!this->is_variable() && !this->is_result_variable());
+ go_assert(!this->is_variable()
+ && !this->is_result_variable()
+ && !this->is_type());
std::string decl_name;
if (this->is_function_declaration()
&& !this->func_declaration_value()->asm_name().empty())
decl_name = this->func_declaration_value()->asm_name();
- else if (this->is_type()
- && Linemap::is_predeclared_location(this->type_value()->location()))
- {
- // We don't need the package name for builtin types.
- decl_name = Gogo::unpack_hidden_name(this->name_);
- }
else
{
std::string package_name;
@@ -7466,22 +7333,6 @@ Named_object::get_id(Gogo* gogo)
decl_name.append(fntype->receiver()->type()->mangled_name(gogo));
}
}
- if (this->is_type())
- {
- unsigned int index;
- const Named_object* in_function = this->type_value()->in_function(&index);
- if (in_function != NULL)
- {
- decl_name += '$' + Gogo::unpack_hidden_name(in_function->name());
- if (index > 0)
- {
- char buf[30];
- snprintf(buf, sizeof buf, "%u", index);
- decl_name += '$';
- decl_name += buf;
- }
- }
- }
return decl_name;
}