if (this->init_fn_name_.empty())
{
gcc_assert(this->package_ != NULL);
- if (this->package_name() == "main")
+ if (this->is_main_package())
{
// Use a name which the runtime knows.
this->init_fn_name_ = "__go_init_main";
void
Gogo::init_imports(tree* init_stmt_list)
{
- gcc_assert(this->package_name() == "main");
+ gcc_assert(this->is_main_package());
if (this->imported_init_fns_.empty())
return;
{
// Make sure that we thought we needed an initialization function,
// as otherwise we will not have reported it in the export data.
- gcc_assert(this->package_name() == "main" || this->need_init_fn_);
+ gcc_assert(this->is_main_package() || this->need_init_fn_);
if (fndecl == NULL_TREE)
fndecl = this->initialization_function_decl();
tree init_fndecl = NULL_TREE;
tree init_stmt_list = NULL_TREE;
- if (this->package_name() == "main")
+ if (this->is_main_package())
this->init_imports(&init_stmt_list);
// A list of variable initializations.
// This will be called if this package is imported.
if (init_stmt_list != NULL_TREE
|| this->need_init_fn_
- || this->package_name() == "main")
+ || this->is_main_package())
this->write_initialization_function(init_fndecl, init_stmt_list);
// Pass everything back to the middle-end.
&& !this->type_->is_method())
;
else if (Gogo::unpack_hidden_name(no->name()) == "main"
- && gogo->package_name() == "main")
+ && gogo->is_main_package())
TREE_PUBLIC(decl) = 1;
// Methods have to be public even if they are hidden because
// they can be pulled into type descriptors when using
init_fn_name_(),
imported_init_fns_(),
unique_prefix_(),
+ unique_prefix_specified_(false),
interface_types_()
{
const source_location loc = BUILTINS_LOCATION;
// package name (e.g., P.x), but we no longer do.
// this->globals_->add_package(package_name, this->package_);
- if (package_name == "main")
+ if (this->is_main_package())
{
// Declare "main" as a function which takes no parameters and
// returns no value.
}
}
+// Return whether this is the "main" package. This is not true if
+// -fgo-prefix was used.
+
+bool
+Gogo::is_main_package() const
+{
+ return this->package_name() == "main" && !this->unique_prefix_specified_;
+}
+
// Import a package.
void
{
gcc_assert(this->unique_prefix_.empty());
this->unique_prefix_ = arg;
+ this->unique_prefix_specified_ = true;
}
// Work out the package priority. It is one more than the maximum
exp.export_globals(this->package_name(),
this->unique_prefix(),
this->package_priority(),
- (this->need_init_fn_ && this->package_name() != "main"
+ (this->need_init_fn_ && !this->is_main_package()
? this->get_init_fn_name()
: ""),
this->imported_init_fns_,
void
set_package_name(const std::string&, source_location);
+ // Return whether this is the "main" package.
+ bool
+ is_main_package() const;
+
// If necessary, adjust the name to use for a hidden symbol. We add
// a prefix of the package name, so that hidden symbols in different
// packages do not collide.
std::set<Import_init> imported_init_fns_;
// The unique prefix used for all global symbols.
std::string unique_prefix_;
+ // Whether an explicit unique prefix was set by -fgo-prefix.
+ bool unique_prefix_specified_;
// A list of interface types defined while parsing.
std::vector<Interface_type*> interface_types_;
};