diff options
author | Ian Lance Taylor <ian@gcc.gnu.org> | 2011-02-09 22:28:42 +0000 |
---|---|---|
committer | Ian Lance Taylor <ian@gcc.gnu.org> | 2011-02-09 22:28:42 +0000 |
commit | 2181e7141cf1f517868e4aa657ad04f95f37c258 (patch) | |
tree | 39400fa4c4e13e03ea013d1191c98c37bf44b3a5 /gcc/go | |
parent | 15167bbaa59ef9668501a4a224484efa2ff502c9 (diff) | |
download | gcc-2181e7141cf1f517868e4aa657ad04f95f37c258.zip gcc-2181e7141cf1f517868e4aa657ad04f95f37c258.tar.gz gcc-2181e7141cf1f517868e4aa657ad04f95f37c258.tar.bz2 |
The "main" package is not special if -fgo-prefix is used.
From-SVN: r169986
Diffstat (limited to 'gcc/go')
-rw-r--r-- | gcc/go/gofrontend/gogo-tree.cc | 12 | ||||
-rw-r--r-- | gcc/go/gofrontend/gogo.cc | 15 | ||||
-rw-r--r-- | gcc/go/gofrontend/gogo.h | 6 |
3 files changed, 25 insertions, 8 deletions
diff --git a/gcc/go/gofrontend/gogo-tree.cc b/gcc/go/gofrontend/gogo-tree.cc index ec5f65a..73f2503 100644 --- a/gcc/go/gofrontend/gogo-tree.cc +++ b/gcc/go/gofrontend/gogo-tree.cc @@ -161,7 +161,7 @@ Gogo::get_init_fn_name() 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"; @@ -186,7 +186,7 @@ Gogo::get_init_fn_name() 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; @@ -384,7 +384,7 @@ Gogo::write_initialization_function(tree fndecl, tree init_stmt_list) { // 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(); @@ -648,7 +648,7 @@ Gogo::write_globals() 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. @@ -804,7 +804,7 @@ Gogo::write_globals() // 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. @@ -1259,7 +1259,7 @@ Function::get_or_make_decl(Gogo* gogo, Named_object* no, tree id) && !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 diff --git a/gcc/go/gofrontend/gogo.cc b/gcc/go/gofrontend/gogo.cc index 794dd74..aa66cf4 100644 --- a/gcc/go/gofrontend/gogo.cc +++ b/gcc/go/gofrontend/gogo.cc @@ -33,6 +33,7 @@ Gogo::Gogo(int int_type_size, int pointer_size) init_fn_name_(), imported_init_fns_(), unique_prefix_(), + unique_prefix_specified_(false), interface_types_() { const source_location loc = BUILTINS_LOCATION; @@ -259,7 +260,7 @@ Gogo::set_package_name(const std::string& package_name, // 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. @@ -270,6 +271,15 @@ Gogo::set_package_name(const std::string& package_name, } } +// 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 @@ -2446,6 +2456,7 @@ Gogo::set_unique_prefix(const std::string& arg) { 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 @@ -2477,7 +2488,7 @@ Gogo::do_exports() 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_, diff --git a/gcc/go/gofrontend/gogo.h b/gcc/go/gofrontend/gogo.h index cb3fe67..57928d6 100644 --- a/gcc/go/gofrontend/gogo.h +++ b/gcc/go/gofrontend/gogo.h @@ -112,6 +112,10 @@ class Gogo 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. @@ -653,6 +657,8 @@ class Gogo 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_; }; |