diff options
author | Ian Lance Taylor <ian@gcc.gnu.org> | 2014-07-20 15:13:50 +0000 |
---|---|---|
committer | Ian Lance Taylor <ian@gcc.gnu.org> | 2014-07-20 15:13:50 +0000 |
commit | 16c6dcc57b81334bdfc99b994686f42369e33094 (patch) | |
tree | 03a02caa9871571c9a9490ee4eba3abf17caf9fe /gcc/go | |
parent | aefa5ff4cf0a058ff76dbd0bea246b690e9dcac0 (diff) | |
download | gcc-16c6dcc57b81334bdfc99b994686f42369e33094.zip gcc-16c6dcc57b81334bdfc99b994686f42369e33094.tar.gz gcc-16c6dcc57b81334bdfc99b994686f42369e33094.tar.bz2 |
compiler: Don't let dot-import names match names from previous files.
The test case for this will be bug488.go in the main
repository: https://codereview.appspot.com/118000043 .
From-SVN: r212871
Diffstat (limited to 'gcc/go')
-rw-r--r-- | gcc/go/gofrontend/gogo.cc | 29 | ||||
-rw-r--r-- | gcc/go/gofrontend/gogo.h | 2 | ||||
-rw-r--r-- | gcc/go/gofrontend/import.cc | 6 | ||||
-rw-r--r-- | gcc/go/gofrontend/unsafe.cc | 6 |
4 files changed, 32 insertions, 11 deletions
diff --git a/gcc/go/gofrontend/gogo.cc b/gcc/go/gofrontend/gogo.cc index b9c8fa9..623befd 100644 --- a/gcc/go/gofrontend/gogo.cc +++ b/gcc/go/gofrontend/gogo.cc @@ -473,7 +473,7 @@ Gogo::import_package(const std::string& filename, bindings->begin_declarations(); p != bindings->end_declarations(); ++p) - this->add_named_object(p->second); + this->add_dot_import_object(p->second); } else if (ln == "_") package->set_uses_sink_alias(); @@ -1968,11 +1968,32 @@ Gogo::add_sink() return Named_object::make_sink(); } -// Add a named object. +// Add a named object for a dot import. void -Gogo::add_named_object(Named_object* no) -{ +Gogo::add_dot_import_object(Named_object* no) +{ + // If the name already exists, then it was defined in some file seen + // earlier. If the earlier name is just a declaration, don't add + // this name, because that will cause the previous declaration to + // merge to this imported name, which should not happen. Just add + // this name to the list of file block names to get appropriate + // errors if we see a later definition. + Named_object* e = this->package_->bindings()->lookup(no->name()); + if (e != NULL && e->package() == NULL) + { + if (e->is_unknown()) + e = e->resolve(); + if (e->package() == NULL + && (e->is_type_declaration() + || e->is_function_declaration() + || e->is_unknown())) + { + this->add_file_block_name(no->name(), no->location()); + return; + } + } + this->current_bindings()->add_named_object(no); } diff --git a/gcc/go/gofrontend/gogo.h b/gcc/go/gofrontend/gogo.h index 700b092..01390ac 100644 --- a/gcc/go/gofrontend/gogo.h +++ b/gcc/go/gofrontend/gogo.h @@ -397,7 +397,7 @@ class Gogo // Add a named object to the current namespace. This is used for // import . "package". void - add_named_object(Named_object*); + add_dot_import_object(Named_object*); // Add an identifier to the list of names seen in the file block. void diff --git a/gcc/go/gofrontend/import.cc b/gcc/go/gofrontend/import.cc index 4913100..c83ebe2 100644 --- a/gcc/go/gofrontend/import.cc +++ b/gcc/go/gofrontend/import.cc @@ -431,7 +431,7 @@ Import::import_const() Typed_identifier tid(name, type, this->location_); Named_object* no = this->package_->add_constant(tid, expr); if (this->add_to_globals_) - this->gogo_->add_named_object(no); + this->gogo_->add_dot_import_object(no); } // Import a type. @@ -464,7 +464,7 @@ Import::import_var() Named_object* no; no = this->package_->add_variable(name, var); if (this->add_to_globals_) - this->gogo_->add_named_object(no); + this->gogo_->add_dot_import_object(no); } // Import a function into PACKAGE. PACKAGE is normally @@ -518,7 +518,7 @@ Import::import_func(Package* package) { no = package->add_function_declaration(name, fntype, loc); if (this->add_to_globals_) - this->gogo_->add_named_object(no); + this->gogo_->add_dot_import_object(no); } return no; } diff --git a/gcc/go/gofrontend/unsafe.cc b/gcc/go/gofrontend/unsafe.cc index e7c61f0..9b5ec44 100644 --- a/gcc/go/gofrontend/unsafe.cc +++ b/gcc/go/gofrontend/unsafe.cc @@ -66,7 +66,7 @@ Gogo::import_unsafe(const std::string& local_name, bool is_local_name_exported, fntype->set_is_builtin(); no = bindings->add_function_declaration("Sizeof", package, fntype, bloc); if (add_to_globals) - this->add_named_object(no); + this->add_dot_import_object(no); // Offsetof. results = new Typed_identifier_list; @@ -76,7 +76,7 @@ Gogo::import_unsafe(const std::string& local_name, bool is_local_name_exported, fntype->set_is_builtin(); no = bindings->add_function_declaration("Offsetof", package, fntype, bloc); if (add_to_globals) - this->add_named_object(no); + this->add_dot_import_object(no); // Alignof. results = new Typed_identifier_list; @@ -86,7 +86,7 @@ Gogo::import_unsafe(const std::string& local_name, bool is_local_name_exported, fntype->set_is_builtin(); no = bindings->add_function_declaration("Alignof", package, fntype, bloc); if (add_to_globals) - this->add_named_object(no); + this->add_dot_import_object(no); if (!this->imported_unsafe_) { |