Commit f21f4773 by Ian Lance Taylor

compiler: List imported packages in export information.

From-SVN: r184355
parent b2c4b7b9
......@@ -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())
{
......
......@@ -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,
......
......@@ -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()
: ""),
......
......@@ -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(" ");
......
......@@ -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*);
......
......@@ -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.
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment