Commit b2c4b7b9 by Ian Lance Taylor Committed by Ian Lance Taylor

compiler: Add parameter names to export information.

	* Make-lang.in (go/import.o): Add dependency on $(GO_LEX_H).

From-SVN: r184353
parent 0a911509
2012-02-17 Ian Lance Taylor <iant@google.com> 2012-02-17 Ian Lance Taylor <iant@google.com>
* Make-lang.in (go/import.o): Add dependency on $(GO_LEX_H).
2012-02-17 Ian Lance Taylor <iant@google.com>
* gospec.c (lang_specific_driver): If linking, and no -o option * gospec.c (lang_specific_driver): If linking, and no -o option
was used, add one. was used, add one.
......
...@@ -295,7 +295,8 @@ go/gogo.o: go/gofrontend/gogo.cc $(GO_SYSTEM_H) $(GO_C_H) \ ...@@ -295,7 +295,8 @@ go/gogo.o: go/gofrontend/gogo.cc $(GO_SYSTEM_H) $(GO_C_H) \
$(GO_IMPORT_H) $(GO_EXPORT_H) go/gofrontend/backend.h $(GO_GOGO_H) $(GO_IMPORT_H) $(GO_EXPORT_H) go/gofrontend/backend.h $(GO_GOGO_H)
go/import.o: go/gofrontend/import.cc $(GO_SYSTEM_H) \ go/import.o: go/gofrontend/import.cc $(GO_SYSTEM_H) \
$(srcdir)/../include/filenames.h $(srcdir)/../include/simple-object.h \ $(srcdir)/../include/filenames.h $(srcdir)/../include/simple-object.h \
$(GO_C_H) $(GO_GOGO_H) $(GO_TYPES_H) $(GO_EXPORT_H) $(GO_IMPORT_H) $(GO_C_H) $(GO_GOGO_H) $(GO_LEX_H) $(GO_TYPES_H) $(GO_EXPORT_H) \
$(GO_IMPORT_H)
go/import-archive.o: go/gofrontend/import-archive.cc $(GO_SYSTEM_H) \ go/import-archive.o: go/gofrontend/import-archive.cc $(GO_SYSTEM_H) \
$(GO_IMPORT_H) $(GO_IMPORT_H)
go/lex.o: go/gofrontend/lex.cc $(GO_LEX_H) $(GO_SYSTEM_H) go/lex.o: go/gofrontend/lex.cc $(GO_LEX_H) $(GO_SYSTEM_H)
......
...@@ -229,6 +229,17 @@ Export::write_imported_init_fns( ...@@ -229,6 +229,17 @@ Export::write_imported_init_fns(
this->write_c_string(";\n"); this->write_c_string(";\n");
} }
// Write a name to the export stream.
void
Export::write_name(const std::string& name)
{
if (name.empty())
this->write_c_string("?");
else
this->write_string(Gogo::message_name(name));
}
// Export a type. We have to ensure that on import we create a single // Export a type. We have to ensure that on import we create a single
// Named_type node for each named type. We do this by keeping a hash // Named_type node for each named type. We do this by keeping a hash
// table mapping named types to reference numbers. The first time we // table mapping named types to reference numbers. The first time we
......
...@@ -145,6 +145,10 @@ class Export : public String_dump ...@@ -145,6 +145,10 @@ class Export : public String_dump
write_bytes(const char* bytes, size_t length) write_bytes(const char* bytes, size_t length)
{ this->stream_->write_bytes(bytes, length); } { this->stream_->write_bytes(bytes, length); }
// Write a name to the export stream. If NAME is empty, write "?".
void
write_name(const std::string& name);
// Write out a type. This handles references back to previous // Write out a type. This handles references back to previous
// definitions. // definitions.
void void
......
...@@ -11783,7 +11783,7 @@ Selector_expression::lower_method_expression(Gogo* gogo) ...@@ -11783,7 +11783,7 @@ Selector_expression::lower_method_expression(Gogo* gogo)
p != method_parameters->end(); p != method_parameters->end();
++p, ++i) ++p, ++i)
{ {
if (!p->name().empty() && p->name() != Import::import_marker) if (!p->name().empty())
parameters->push_back(*p); parameters->push_back(*p);
else else
{ {
......
...@@ -3274,7 +3274,10 @@ Function::export_func_with_type(Export* exp, const std::string& name, ...@@ -3274,7 +3274,10 @@ Function::export_func_with_type(Export* exp, const std::string& name,
if (fntype->is_method()) if (fntype->is_method())
{ {
exp->write_c_string("("); exp->write_c_string("(");
exp->write_type(fntype->receiver()->type()); const Typed_identifier* receiver = fntype->receiver();
exp->write_name(receiver->name());
exp->write_c_string(" ");
exp->write_type(receiver->type());
exp->write_c_string(") "); exp->write_c_string(") ");
} }
...@@ -3294,6 +3297,8 @@ Function::export_func_with_type(Export* exp, const std::string& name, ...@@ -3294,6 +3297,8 @@ Function::export_func_with_type(Export* exp, const std::string& name,
first = false; first = false;
else else
exp->write_c_string(", "); exp->write_c_string(", ");
exp->write_name(p->name());
exp->write_c_string(" ");
if (!is_varargs || p + 1 != parameters->end()) if (!is_varargs || p + 1 != parameters->end())
exp->write_type(p->type()); exp->write_type(p->type());
else else
...@@ -3308,7 +3313,7 @@ Function::export_func_with_type(Export* exp, const std::string& name, ...@@ -3308,7 +3313,7 @@ Function::export_func_with_type(Export* exp, const std::string& name,
const Typed_identifier_list* results = fntype->results(); const Typed_identifier_list* results = fntype->results();
if (results != NULL) if (results != NULL)
{ {
if (results->size() == 1) if (results->size() == 1 && results->begin()->name().empty())
{ {
exp->write_c_string(" "); exp->write_c_string(" ");
exp->write_type(results->begin()->type()); exp->write_type(results->begin()->type());
...@@ -3325,6 +3330,8 @@ Function::export_func_with_type(Export* exp, const std::string& name, ...@@ -3325,6 +3330,8 @@ Function::export_func_with_type(Export* exp, const std::string& name,
first = false; first = false;
else else
exp->write_c_string(", "); exp->write_c_string(", ");
exp->write_name(p->name());
exp->write_c_string(" ");
exp->write_type(p->type()); exp->write_type(p->type());
} }
exp->write_c_string(")"); exp->write_c_string(")");
...@@ -3348,9 +3355,10 @@ Function::import_func(Import* imp, std::string* pname, ...@@ -3348,9 +3355,10 @@ Function::import_func(Import* imp, std::string* pname,
if (imp->peek_char() == '(') if (imp->peek_char() == '(')
{ {
imp->require_c_string("("); imp->require_c_string("(");
std::string name = imp->read_name();
imp->require_c_string(" ");
Type* rtype = imp->read_type(); Type* rtype = imp->read_type();
*preceiver = new Typed_identifier(Import::import_marker, rtype, *preceiver = new Typed_identifier(name, rtype, imp->location());
imp->location());
imp->require_c_string(") "); imp->require_c_string(") ");
} }
...@@ -3366,6 +3374,9 @@ Function::import_func(Import* imp, std::string* pname, ...@@ -3366,6 +3374,9 @@ Function::import_func(Import* imp, std::string* pname,
parameters = new Typed_identifier_list(); parameters = new Typed_identifier_list();
while (true) while (true)
{ {
std::string name = imp->read_name();
imp->require_c_string(" ");
if (imp->match_c_string("...")) if (imp->match_c_string("..."))
{ {
imp->advance(3); imp->advance(3);
...@@ -3375,8 +3386,8 @@ Function::import_func(Import* imp, std::string* pname, ...@@ -3375,8 +3386,8 @@ Function::import_func(Import* imp, std::string* pname,
Type* ptype = imp->read_type(); Type* ptype = imp->read_type();
if (*is_varargs) if (*is_varargs)
ptype = Type::make_array_type(ptype, NULL); ptype = Type::make_array_type(ptype, NULL);
parameters->push_back(Typed_identifier(Import::import_marker, parameters->push_back(Typed_identifier(name, ptype,
ptype, imp->location())); imp->location()));
if (imp->peek_char() != ',') if (imp->peek_char() != ',')
break; break;
go_assert(!*is_varargs); go_assert(!*is_varargs);
...@@ -3396,17 +3407,18 @@ Function::import_func(Import* imp, std::string* pname, ...@@ -3396,17 +3407,18 @@ Function::import_func(Import* imp, std::string* pname,
if (imp->peek_char() != '(') if (imp->peek_char() != '(')
{ {
Type* rtype = imp->read_type(); Type* rtype = imp->read_type();
results->push_back(Typed_identifier(Import::import_marker, rtype, results->push_back(Typed_identifier("", rtype, imp->location()));
imp->location()));
} }
else else
{ {
imp->require_c_string("("); imp->require_c_string("(");
while (true) while (true)
{ {
std::string name = imp->read_name();
imp->require_c_string(" ");
Type* rtype = imp->read_type(); Type* rtype = imp->read_type();
results->push_back(Typed_identifier(Import::import_marker, results->push_back(Typed_identifier(name, rtype,
rtype, imp->location())); imp->location()));
if (imp->peek_char() != ',') if (imp->peek_char() != ',')
break; break;
imp->require_c_string(", "); imp->require_c_string(", ");
......
...@@ -11,6 +11,7 @@ ...@@ -11,6 +11,7 @@
#include "go-c.h" #include "go-c.h"
#include "gogo.h" #include "gogo.h"
#include "lex.h"
#include "types.h" #include "types.h"
#include "export.h" #include "export.h"
#include "import.h" #include "import.h"
...@@ -33,11 +34,6 @@ go_add_search_path(const char* path) ...@@ -33,11 +34,6 @@ go_add_search_path(const char* path)
search_path.push_back(std::string(path)); search_path.push_back(std::string(path));
} }
// The name used for parameters, receivers, and results in imported
// function types.
const char* const Import::import_marker = "*imported*";
// Find import data. This searches the file system for FILENAME and // Find import data. This searches the file system for FILENAME and
// returns a pointer to a Stream object to read the data that it // returns a pointer to a Stream object to read the data that it
// exports. If the file is not found, it returns NULL. // exports. If the file is not found, it returns NULL.
...@@ -749,6 +745,21 @@ Import::read_identifier() ...@@ -749,6 +745,21 @@ Import::read_identifier()
return ret; return ret;
} }
// Read a name from the stream.
std::string
Import::read_name()
{
std::string ret = this->read_identifier();
if (ret == "?")
ret.clear();
else if (!Lex::is_exported_name(ret))
ret = ('.' + this->package_->unique_prefix()
+ '.' + this->package_->name()
+ '.' + ret);
return ret;
}
// Turn a string into a integer with appropriate error handling. // Turn a string into a integer with appropriate error handling.
bool bool
......
...@@ -181,14 +181,15 @@ class Import ...@@ -181,14 +181,15 @@ class Import
std::string std::string
read_identifier(); read_identifier();
// Read a name. This is like read_identifier, except that a "?" is
// returned as an empty string. This matches Export::write_name.
std::string
read_name();
// Read a type. // Read a type.
Type* Type*
read_type(); read_type();
// The name used for parameters, receivers, and results in imported
// function types.
static const char* const import_marker;
private: private:
static Stream* static Stream*
try_package_in_directory(const std::string&, Location); try_package_in_directory(const std::string&, Location);
......
...@@ -3111,9 +3111,7 @@ Function_type::is_valid_redeclaration(const Function_type* t, ...@@ -3111,9 +3111,7 @@ Function_type::is_valid_redeclaration(const Function_type* t,
// A redeclaration of a function is required to use the same names // A redeclaration of a function is required to use the same names
// for the receiver and parameters. // for the receiver and parameters.
if (this->receiver() != NULL if (this->receiver() != NULL
&& this->receiver()->name() != t->receiver()->name() && this->receiver()->name() != t->receiver()->name())
&& this->receiver()->name() != Import::import_marker
&& t->receiver()->name() != Import::import_marker)
{ {
if (reason != NULL) if (reason != NULL)
*reason = "receiver name changed"; *reason = "receiver name changed";
...@@ -3129,9 +3127,7 @@ Function_type::is_valid_redeclaration(const Function_type* t, ...@@ -3129,9 +3127,7 @@ Function_type::is_valid_redeclaration(const Function_type* t,
p2 != parms2->end(); p2 != parms2->end();
++p2, ++p1) ++p2, ++p1)
{ {
if (p1->name() != p2->name() if (p1->name() != p2->name())
&& p1->name() != Import::import_marker
&& p2->name() != Import::import_marker)
{ {
if (reason != NULL) if (reason != NULL)
*reason = "parameter name changed"; *reason = "parameter name changed";
...@@ -3160,9 +3156,7 @@ Function_type::is_valid_redeclaration(const Function_type* t, ...@@ -3160,9 +3156,7 @@ Function_type::is_valid_redeclaration(const Function_type* t,
res2 != results2->end(); res2 != results2->end();
++res2, ++res1) ++res2, ++res1)
{ {
if (res1->name() != res2->name() if (res1->name() != res2->name())
&& res1->name() != Import::import_marker
&& res2->name() != Import::import_marker)
{ {
if (reason != NULL) if (reason != NULL)
*reason = "result name changed"; *reason = "result name changed";
...@@ -3609,6 +3603,8 @@ Function_type::do_export(Export* exp) const ...@@ -3609,6 +3603,8 @@ Function_type::do_export(Export* exp) const
first = false; first = false;
else else
exp->write_c_string(", "); exp->write_c_string(", ");
exp->write_name(p->name());
exp->write_c_string(" ");
if (!is_varargs || p + 1 != this->parameters_->end()) if (!is_varargs || p + 1 != this->parameters_->end())
exp->write_type(p->type()); exp->write_type(p->type());
else else
...@@ -3624,7 +3620,7 @@ Function_type::do_export(Export* exp) const ...@@ -3624,7 +3620,7 @@ Function_type::do_export(Export* exp) const
if (results != NULL) if (results != NULL)
{ {
exp->write_c_string(" "); exp->write_c_string(" ");
if (results->size() == 1) if (results->size() == 1 && results->begin()->name().empty())
exp->write_type(results->begin()->type()); exp->write_type(results->begin()->type());
else else
{ {
...@@ -3638,6 +3634,8 @@ Function_type::do_export(Export* exp) const ...@@ -3638,6 +3634,8 @@ Function_type::do_export(Export* exp) const
first = false; first = false;
else else
exp->write_c_string(", "); exp->write_c_string(", ");
exp->write_name(p->name());
exp->write_c_string(" ");
exp->write_type(p->type()); exp->write_type(p->type());
} }
exp->write_c_string(")"); exp->write_c_string(")");
...@@ -3660,6 +3658,9 @@ Function_type::do_import(Import* imp) ...@@ -3660,6 +3658,9 @@ Function_type::do_import(Import* imp)
parameters = new Typed_identifier_list(); parameters = new Typed_identifier_list();
while (true) while (true)
{ {
std::string name = imp->read_name();
imp->require_c_string(" ");
if (imp->match_c_string("...")) if (imp->match_c_string("..."))
{ {
imp->advance(3); imp->advance(3);
...@@ -3669,8 +3670,8 @@ Function_type::do_import(Import* imp) ...@@ -3669,8 +3670,8 @@ Function_type::do_import(Import* imp)
Type* ptype = imp->read_type(); Type* ptype = imp->read_type();
if (is_varargs) if (is_varargs)
ptype = Type::make_array_type(ptype, NULL); ptype = Type::make_array_type(ptype, NULL);
parameters->push_back(Typed_identifier(Import::import_marker, parameters->push_back(Typed_identifier(name, ptype,
ptype, imp->location())); imp->location()));
if (imp->peek_char() != ',') if (imp->peek_char() != ',')
break; break;
go_assert(!is_varargs); go_assert(!is_varargs);
...@@ -3689,17 +3690,18 @@ Function_type::do_import(Import* imp) ...@@ -3689,17 +3690,18 @@ Function_type::do_import(Import* imp)
if (imp->peek_char() != '(') if (imp->peek_char() != '(')
{ {
Type* rtype = imp->read_type(); Type* rtype = imp->read_type();
results->push_back(Typed_identifier(Import::import_marker, rtype, results->push_back(Typed_identifier("", rtype, imp->location()));
imp->location()));
} }
else else
{ {
imp->advance(1); imp->advance(1);
while (true) while (true)
{ {
std::string name = imp->read_name();
imp->require_c_string(" ");
Type* rtype = imp->read_type(); Type* rtype = imp->read_type();
results->push_back(Typed_identifier(Import::import_marker, results->push_back(Typed_identifier(name, rtype,
rtype, imp->location())); imp->location()));
if (imp->peek_char() != ',') if (imp->peek_char() != ',')
break; break;
imp->require_c_string(", "); imp->require_c_string(", ");
...@@ -7185,7 +7187,7 @@ Interface_type::do_export(Export* exp) const ...@@ -7185,7 +7187,7 @@ Interface_type::do_export(Export* exp) const
{ {
if (pm->name().empty()) if (pm->name().empty())
{ {
exp->write_c_string("$ "); exp->write_c_string("? ");
exp->write_type(pm->type()); exp->write_type(pm->type());
} }
else else
...@@ -7209,6 +7211,8 @@ Interface_type::do_export(Export* exp) const ...@@ -7209,6 +7211,8 @@ Interface_type::do_export(Export* exp) const
first = false; first = false;
else else
exp->write_c_string(", "); exp->write_c_string(", ");
exp->write_name(pp->name());
exp->write_c_string(" ");
if (!is_varargs || pp + 1 != parameters->end()) if (!is_varargs || pp + 1 != parameters->end())
exp->write_type(pp->type()); exp->write_type(pp->type());
else else
...@@ -7226,7 +7230,7 @@ Interface_type::do_export(Export* exp) const ...@@ -7226,7 +7230,7 @@ Interface_type::do_export(Export* exp) const
if (results != NULL) if (results != NULL)
{ {
exp->write_c_string(" "); exp->write_c_string(" ");
if (results->size() == 1) if (results->size() == 1 && results->begin()->name().empty())
exp->write_type(results->begin()->type()); exp->write_type(results->begin()->type());
else else
{ {
...@@ -7241,6 +7245,8 @@ Interface_type::do_export(Export* exp) const ...@@ -7241,6 +7245,8 @@ Interface_type::do_export(Export* exp) const
first = false; first = false;
else else
exp->write_c_string(", "); exp->write_c_string(", ");
exp->write_name(p->name());
exp->write_c_string(" ");
exp->write_type(p->type()); exp->write_type(p->type());
} }
exp->write_c_string(")"); exp->write_c_string(")");
...@@ -7267,7 +7273,7 @@ Interface_type::do_import(Import* imp) ...@@ -7267,7 +7273,7 @@ Interface_type::do_import(Import* imp)
{ {
std::string name = imp->read_identifier(); std::string name = imp->read_identifier();
if (name == "$") if (name == "?")
{ {
imp->require_c_string(" "); imp->require_c_string(" ");
Type* t = imp->read_type(); Type* t = imp->read_type();
...@@ -7287,6 +7293,9 @@ Interface_type::do_import(Import* imp) ...@@ -7287,6 +7293,9 @@ Interface_type::do_import(Import* imp)
parameters = new Typed_identifier_list; parameters = new Typed_identifier_list;
while (true) while (true)
{ {
std::string name = imp->read_name();
imp->require_c_string(" ");
if (imp->match_c_string("...")) if (imp->match_c_string("..."))
{ {
imp->advance(3); imp->advance(3);
...@@ -7296,8 +7305,8 @@ Interface_type::do_import(Import* imp) ...@@ -7296,8 +7305,8 @@ Interface_type::do_import(Import* imp)
Type* ptype = imp->read_type(); Type* ptype = imp->read_type();
if (is_varargs) if (is_varargs)
ptype = Type::make_array_type(ptype, NULL); ptype = Type::make_array_type(ptype, NULL);
parameters->push_back(Typed_identifier(Import::import_marker, parameters->push_back(Typed_identifier(name, ptype,
ptype, imp->location())); imp->location()));
if (imp->peek_char() != ',') if (imp->peek_char() != ',')
break; break;
go_assert(!is_varargs); go_assert(!is_varargs);
...@@ -7316,17 +7325,18 @@ Interface_type::do_import(Import* imp) ...@@ -7316,17 +7325,18 @@ Interface_type::do_import(Import* imp)
if (imp->peek_char() != '(') if (imp->peek_char() != '(')
{ {
Type* rtype = imp->read_type(); Type* rtype = imp->read_type();
results->push_back(Typed_identifier(Import::import_marker, results->push_back(Typed_identifier("", rtype, imp->location()));
rtype, imp->location()));
} }
else else
{ {
imp->advance(1); imp->advance(1);
while (true) while (true)
{ {
std::string name = imp->read_name();
imp->require_c_string(" ");
Type* rtype = imp->read_type(); Type* rtype = imp->read_type();
results->push_back(Typed_identifier(Import::import_marker, results->push_back(Typed_identifier(name, rtype,
rtype, imp->location())); imp->location()));
if (imp->peek_char() != ',') if (imp->peek_char() != ',')
break; break;
imp->require_c_string(", "); imp->require_c_string(", ");
......
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