From: ian Date: Fri, 17 Feb 2012 23:21:08 +0000 (+0000) Subject: compiler: List imported packages in export information. X-Git-Url: http://git.ipfire.org/?a=commitdiff_plain;h=18d835b908fb5df56ebecc99038e2fa0e35cb03e;p=thirdparty%2Fgcc.git compiler: List imported packages in export information. git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@184355 138bc75d-0d04-0410-961f-82ee72b054a4 --- diff --git a/gcc/go/gofrontend/export.cc b/gcc/go/gofrontend/export.cc index 1fceb3b0fdc8..174596753ef8 100644 --- a/gcc/go/gofrontend/export.cc +++ b/gcc/go/gofrontend/export.cc @@ -93,6 +93,7 @@ void Export::export_globals(const std::string& package_name, const std::string& unique_prefix, int package_priority, + const std::map& imports, const std::string& import_init_fn, const std::set& imported_init_fns, const Bindings* bindings) @@ -149,6 +150,8 @@ Export::export_globals(const std::string& package_name, snprintf(buf, sizeof buf, "priority %d;\n", package_priority); this->write_c_string(buf); + this->write_imports(imports); + this->write_imported_init_fns(package_name, package_priority, import_init_fn, imported_init_fns); @@ -177,7 +180,46 @@ Export::export_globals(const std::string& package_name, this->stream_->write_checksum(s); } -// Write out the import control variables for this package. +// Sort imported packages. + +static bool +import_compare(const std::pair& a, + const std::pair& b) +{ + return a.first < b.first; +} + +// Write out the imported packages. + +void +Export::write_imports(const std::map& imports) +{ + // Sort the imports for more consistent output. + std::vector > imp; + for (std::map::const_iterator p = imports.begin(); + p != imports.end(); + ++p) + imp.push_back(std::make_pair(p->first, p->second)); + + std::sort(imp.begin(), imp.end(), import_compare); + + for (std::vector >::const_iterator p = + imp.begin(); + p != imp.end(); + ++p) + { + this->write_c_string("import "); + this->write_string(p->second->name()); + this->write_c_string(" "); + this->write_string(p->second->unique_prefix()); + this->write_c_string(" \""); + this->write_string(p->first); + this->write_c_string("\";\n"); + } +} + +// Write out the initialization functions which need to run for this +// package. void Export::write_imported_init_fns( @@ -189,7 +231,7 @@ Export::write_imported_init_fns( if (import_init_fn.empty() && imported_init_fns.empty()) return; - this->write_c_string("import"); + this->write_c_string("init"); if (!import_init_fn.empty()) { diff --git a/gcc/go/gofrontend/export.h b/gcc/go/gofrontend/export.h index a558510eab3d..0e03f4853d64 100644 --- a/gcc/go/gofrontend/export.h +++ b/gcc/go/gofrontend/export.h @@ -14,6 +14,7 @@ class Gogo; class Import_init; class Bindings; class Type; +class Package; // Codes used for the builtin types. These are all negative to make // them easily distinct from the codes assigned by Export::write_type. @@ -126,6 +127,7 @@ class Export : public String_dump export_globals(const std::string& package_name, const std::string& unique_prefix, int package_priority, + const std::map& imports, const std::string& import_init_fn, const std::set& imported_init_fns, const Bindings* bindings); @@ -158,6 +160,10 @@ class Export : public String_dump Export(const Export&); Export& operator=(const Export&); + // Write out the imported packages. + void + write_imports(const std::map& imports); + // Write out the imported initialization functions. void write_imported_init_fns(const std::string& package_name, int priority, diff --git a/gcc/go/gofrontend/gogo.cc b/gcc/go/gofrontend/gogo.cc index b4c522ef51ba..acc92317dcc5 100644 --- a/gcc/go/gofrontend/gogo.cc +++ b/gcc/go/gofrontend/gogo.cc @@ -2859,6 +2859,7 @@ Gogo::do_exports() exp.export_globals(this->package_name(), this->unique_prefix(), this->package_priority(), + this->imports_, (this->need_init_fn_ && !this->is_main_package() ? this->get_init_fn_name() : ""), diff --git a/gcc/go/gofrontend/import.cc b/gcc/go/gofrontend/import.cc index 6cecf19f70b3..58b0355c6c6f 100644 --- a/gcc/go/gofrontend/import.cc +++ b/gcc/go/gofrontend/import.cc @@ -304,7 +304,10 @@ Import::import(Gogo* gogo, const std::string& local_name, this->package_->set_priority(prio); this->require_c_string(";\n"); - if (stream->match_c_string("import ")) + while (stream->match_c_string("import")) + this->read_one_import(); + + if (stream->match_c_string("init")) this->read_import_init_fns(gogo); // Loop over all the input data for this package. @@ -344,12 +347,24 @@ Import::import(Gogo* gogo, const std::string& local_name, return this->package_; } +// Read an import line. We don't actually care about these. + +void +Import::read_one_import() +{ + this->require_c_string("import "); + Stream* stream = this->stream_; + while (stream->peek_char() != ';') + stream->advance(1); + this->require_c_string(";\n"); +} + // Read the list of import control functions. void Import::read_import_init_fns(Gogo* gogo) { - this->require_c_string("import"); + this->require_c_string("init"); while (!this->match_c_string(";")) { this->require_c_string(" "); diff --git a/gcc/go/gofrontend/import.h b/gcc/go/gofrontend/import.h index b4d203527f7d..67bdcb02d57d 100644 --- a/gcc/go/gofrontend/import.h +++ b/gcc/go/gofrontend/import.h @@ -213,6 +213,10 @@ class Import find_archive_export_data(const std::string& filename, int fd, Location); + // Read an import line. + void + read_one_import(); + // Read the import control functions. void read_import_init_fns(Gogo*); diff --git a/gcc/go/gofrontend/unsafe.cc b/gcc/go/gofrontend/unsafe.cc index 6e8a4042e725..9508feaaf972 100644 --- a/gcc/go/gofrontend/unsafe.cc +++ b/gcc/go/gofrontend/unsafe.cc @@ -34,6 +34,8 @@ Gogo::import_unsafe(const std::string& local_name, bool is_local_name_exported, package->set_location(location); package->set_is_imported(); + this->imports_.insert(std::make_pair("unsafe", package)); + Bindings* bindings = package->bindings(); // The type may have already been created by an import.