diff options
author | Ian Lance Taylor <ian@gcc.gnu.org> | 2012-02-17 23:21:08 +0000 |
---|---|---|
committer | Ian Lance Taylor <ian@gcc.gnu.org> | 2012-02-17 23:21:08 +0000 |
commit | f21f4773f38db001b434d6e26daba5b9f7cf2e75 (patch) | |
tree | 8d741a435b92dd40a98b3a05ddacc3d2b3c78639 /gcc/go | |
parent | b2c4b7b9408b401e4ad668a3a005516d9af32c53 (diff) | |
download | gcc-f21f4773f38db001b434d6e26daba5b9f7cf2e75.zip gcc-f21f4773f38db001b434d6e26daba5b9f7cf2e75.tar.gz gcc-f21f4773f38db001b434d6e26daba5b9f7cf2e75.tar.bz2 |
compiler: List imported packages in export information.
From-SVN: r184355
Diffstat (limited to 'gcc/go')
-rw-r--r-- | gcc/go/gofrontend/export.cc | 46 | ||||
-rw-r--r-- | gcc/go/gofrontend/export.h | 6 | ||||
-rw-r--r-- | gcc/go/gofrontend/gogo.cc | 1 | ||||
-rw-r--r-- | gcc/go/gofrontend/import.cc | 19 | ||||
-rw-r--r-- | gcc/go/gofrontend/import.h | 4 | ||||
-rw-r--r-- | gcc/go/gofrontend/unsafe.cc | 2 |
6 files changed, 74 insertions, 4 deletions
diff --git a/gcc/go/gofrontend/export.cc b/gcc/go/gofrontend/export.cc index 1fceb3b..1745967 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<std::string, Package*>& imports, const std::string& import_init_fn, const std::set<Import_init>& 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<std::string, Package*>& a, + const std::pair<std::string, Package*>& b) +{ + return a.first < b.first; +} + +// Write out the imported packages. + +void +Export::write_imports(const std::map<std::string, Package*>& imports) +{ + // Sort the imports for more consistent output. + std::vector<std::pair<std::string, Package*> > imp; + for (std::map<std::string, Package*>::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<std::pair<std::string, Package*> >::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 a558510..0e03f48 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<std::string, Package*>& imports, const std::string& import_init_fn, const std::set<Import_init>& 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<std::string, Package*>& 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 b4c522e..acc9231 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 6cecf19..58b0355 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 b4d2035..67bdcb0 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 6e8a404..9508fea 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. |