From: ian Date: Wed, 9 Feb 2011 22:28:42 +0000 (+0000) Subject: The "main" package is not special if -fgo-prefix is used. X-Git-Tag: upstream/4.9.2~22900 X-Git-Url: http://review.tizen.org/git/?a=commitdiff_plain;h=2b0adbff36b720ae3b0faa9ac42f7895ecf601e1;p=platform%2Fupstream%2Flinaro-gcc.git The "main" package is not special if -fgo-prefix is used. git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@169986 138bc75d-0d04-0410-961f-82ee72b054a4 --- 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 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_types_; };