summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorian <ian@138bc75d-0d04-0410-961f-82ee72b054a4>2012-02-17 22:36:10 +0000
committerian <ian@138bc75d-0d04-0410-961f-82ee72b054a4>2012-02-17 22:36:10 +0000
commit688835310af1344ab6590e18cac8c09ac2e54093 (patch)
tree0ee6ebaf6cb2e24a987c173ccd14c68971ead20d
parentca33b5eb6cfba99a644d01532021023e64a6a4ea (diff)
downloadppe42-gcc-688835310af1344ab6590e18cac8c09ac2e54093.tar.gz
ppe42-gcc-688835310af1344ab6590e18cac8c09ac2e54093.zip
compiler: Add parameter names to export information.
* Make-lang.in (go/import.o): Add dependency on $(GO_LEX_H). git-svn-id: svn+ssh://gcc.gnu.org/svn/gcc/trunk@184353 138bc75d-0d04-0410-961f-82ee72b054a4
-rw-r--r--gcc/go/ChangeLog4
-rw-r--r--gcc/go/Make-lang.in3
-rw-r--r--gcc/go/gofrontend/export.cc11
-rw-r--r--gcc/go/gofrontend/export.h4
-rw-r--r--gcc/go/gofrontend/expressions.cc2
-rw-r--r--gcc/go/gofrontend/gogo.cc32
-rw-r--r--gcc/go/gofrontend/import.cc21
-rw-r--r--gcc/go/gofrontend/import.h9
-rw-r--r--gcc/go/gofrontend/types.cc60
9 files changed, 100 insertions, 46 deletions
diff --git a/gcc/go/ChangeLog b/gcc/go/ChangeLog
index fe896ab2bca..eb2638fd54d 100644
--- a/gcc/go/ChangeLog
+++ b/gcc/go/ChangeLog
@@ -1,5 +1,9 @@
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
was used, add one.
diff --git a/gcc/go/Make-lang.in b/gcc/go/Make-lang.in
index 2994fe185ae..34e5584cc09 100644
--- a/gcc/go/Make-lang.in
+++ b/gcc/go/Make-lang.in
@@ -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.o: go/gofrontend/import.cc $(GO_SYSTEM_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_H)
go/lex.o: go/gofrontend/lex.cc $(GO_LEX_H) $(GO_SYSTEM_H)
diff --git a/gcc/go/gofrontend/export.cc b/gcc/go/gofrontend/export.cc
index b6c0740cade..1fceb3b0fdc 100644
--- a/gcc/go/gofrontend/export.cc
+++ b/gcc/go/gofrontend/export.cc
@@ -229,6 +229,17 @@ Export::write_imported_init_fns(
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
// 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
diff --git a/gcc/go/gofrontend/export.h b/gcc/go/gofrontend/export.h
index 087f477e482..a558510eab3 100644
--- a/gcc/go/gofrontend/export.h
+++ b/gcc/go/gofrontend/export.h
@@ -145,6 +145,10 @@ class Export : public String_dump
write_bytes(const char* bytes, size_t 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
// definitions.
void
diff --git a/gcc/go/gofrontend/expressions.cc b/gcc/go/gofrontend/expressions.cc
index 0c78ccf7fbd..638cacbe2c9 100644
--- a/gcc/go/gofrontend/expressions.cc
+++ b/gcc/go/gofrontend/expressions.cc
@@ -11783,7 +11783,7 @@ Selector_expression::lower_method_expression(Gogo* gogo)
p != method_parameters->end();
++p, ++i)
{
- if (!p->name().empty() && p->name() != Import::import_marker)
+ if (!p->name().empty())
parameters->push_back(*p);
else
{
diff --git a/gcc/go/gofrontend/gogo.cc b/gcc/go/gofrontend/gogo.cc
index a90ce1df384..b4c522ef51b 100644
--- a/gcc/go/gofrontend/gogo.cc
+++ b/gcc/go/gofrontend/gogo.cc
@@ -3274,7 +3274,10 @@ Function::export_func_with_type(Export* exp, const std::string& name,
if (fntype->is_method())
{
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(") ");
}
@@ -3294,6 +3297,8 @@ Function::export_func_with_type(Export* exp, const std::string& name,
first = false;
else
exp->write_c_string(", ");
+ exp->write_name(p->name());
+ exp->write_c_string(" ");
if (!is_varargs || p + 1 != parameters->end())
exp->write_type(p->type());
else
@@ -3308,7 +3313,7 @@ Function::export_func_with_type(Export* exp, const std::string& name,
const Typed_identifier_list* results = fntype->results();
if (results != NULL)
{
- if (results->size() == 1)
+ if (results->size() == 1 && results->begin()->name().empty())
{
exp->write_c_string(" ");
exp->write_type(results->begin()->type());
@@ -3325,6 +3330,8 @@ Function::export_func_with_type(Export* exp, const std::string& name,
first = false;
else
exp->write_c_string(", ");
+ exp->write_name(p->name());
+ exp->write_c_string(" ");
exp->write_type(p->type());
}
exp->write_c_string(")");
@@ -3348,9 +3355,10 @@ Function::import_func(Import* imp, std::string* pname,
if (imp->peek_char() == '(')
{
imp->require_c_string("(");
+ std::string name = imp->read_name();
+ imp->require_c_string(" ");
Type* rtype = imp->read_type();
- *preceiver = new Typed_identifier(Import::import_marker, rtype,
- imp->location());
+ *preceiver = new Typed_identifier(name, rtype, imp->location());
imp->require_c_string(") ");
}
@@ -3366,6 +3374,9 @@ Function::import_func(Import* imp, std::string* pname,
parameters = new Typed_identifier_list();
while (true)
{
+ std::string name = imp->read_name();
+ imp->require_c_string(" ");
+
if (imp->match_c_string("..."))
{
imp->advance(3);
@@ -3375,8 +3386,8 @@ Function::import_func(Import* imp, std::string* pname,
Type* ptype = imp->read_type();
if (*is_varargs)
ptype = Type::make_array_type(ptype, NULL);
- parameters->push_back(Typed_identifier(Import::import_marker,
- ptype, imp->location()));
+ parameters->push_back(Typed_identifier(name, ptype,
+ imp->location()));
if (imp->peek_char() != ',')
break;
go_assert(!*is_varargs);
@@ -3396,17 +3407,18 @@ Function::import_func(Import* imp, std::string* pname,
if (imp->peek_char() != '(')
{
Type* rtype = imp->read_type();
- results->push_back(Typed_identifier(Import::import_marker, rtype,
- imp->location()));
+ results->push_back(Typed_identifier("", rtype, imp->location()));
}
else
{
imp->require_c_string("(");
while (true)
{
+ std::string name = imp->read_name();
+ imp->require_c_string(" ");
Type* rtype = imp->read_type();
- results->push_back(Typed_identifier(Import::import_marker,
- rtype, imp->location()));
+ results->push_back(Typed_identifier(name, rtype,
+ imp->location()));
if (imp->peek_char() != ',')
break;
imp->require_c_string(", ");
diff --git a/gcc/go/gofrontend/import.cc b/gcc/go/gofrontend/import.cc
index 44ffda61fba..6cecf19f70b 100644
--- a/gcc/go/gofrontend/import.cc
+++ b/gcc/go/gofrontend/import.cc
@@ -11,6 +11,7 @@
#include "go-c.h"
#include "gogo.h"
+#include "lex.h"
#include "types.h"
#include "export.h"
#include "import.h"
@@ -33,11 +34,6 @@ go_add_search_path(const char* 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
// returns a pointer to a Stream object to read the data that it
// exports. If the file is not found, it returns NULL.
@@ -749,6 +745,21 @@ Import::read_identifier()
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.
bool
diff --git a/gcc/go/gofrontend/import.h b/gcc/go/gofrontend/import.h
index bdff0c2a9e1..b4d203527f7 100644
--- a/gcc/go/gofrontend/import.h
+++ b/gcc/go/gofrontend/import.h
@@ -181,14 +181,15 @@ class Import
std::string
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.
Type*
read_type();
- // The name used for parameters, receivers, and results in imported
- // function types.
- static const char* const import_marker;
-
private:
static Stream*
try_package_in_directory(const std::string&, Location);
diff --git a/gcc/go/gofrontend/types.cc b/gcc/go/gofrontend/types.cc
index 4ed54bb5358..f8b6f1a3113 100644
--- a/gcc/go/gofrontend/types.cc
+++ b/gcc/go/gofrontend/types.cc
@@ -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
// for the receiver and parameters.
if (this->receiver() != NULL
- && this->receiver()->name() != t->receiver()->name()
- && this->receiver()->name() != Import::import_marker
- && t->receiver()->name() != Import::import_marker)
+ && this->receiver()->name() != t->receiver()->name())
{
if (reason != NULL)
*reason = "receiver name changed";
@@ -3129,9 +3127,7 @@ Function_type::is_valid_redeclaration(const Function_type* t,
p2 != parms2->end();
++p2, ++p1)
{
- if (p1->name() != p2->name()
- && p1->name() != Import::import_marker
- && p2->name() != Import::import_marker)
+ if (p1->name() != p2->name())
{
if (reason != NULL)
*reason = "parameter name changed";
@@ -3160,9 +3156,7 @@ Function_type::is_valid_redeclaration(const Function_type* t,
res2 != results2->end();
++res2, ++res1)
{
- if (res1->name() != res2->name()
- && res1->name() != Import::import_marker
- && res2->name() != Import::import_marker)
+ if (res1->name() != res2->name())
{
if (reason != NULL)
*reason = "result name changed";
@@ -3609,6 +3603,8 @@ Function_type::do_export(Export* exp) const
first = false;
else
exp->write_c_string(", ");
+ exp->write_name(p->name());
+ exp->write_c_string(" ");
if (!is_varargs || p + 1 != this->parameters_->end())
exp->write_type(p->type());
else
@@ -3624,7 +3620,7 @@ Function_type::do_export(Export* exp) const
if (results != NULL)
{
exp->write_c_string(" ");
- if (results->size() == 1)
+ if (results->size() == 1 && results->begin()->name().empty())
exp->write_type(results->begin()->type());
else
{
@@ -3638,6 +3634,8 @@ Function_type::do_export(Export* exp) const
first = false;
else
exp->write_c_string(", ");
+ exp->write_name(p->name());
+ exp->write_c_string(" ");
exp->write_type(p->type());
}
exp->write_c_string(")");
@@ -3660,6 +3658,9 @@ Function_type::do_import(Import* imp)
parameters = new Typed_identifier_list();
while (true)
{
+ std::string name = imp->read_name();
+ imp->require_c_string(" ");
+
if (imp->match_c_string("..."))
{
imp->advance(3);
@@ -3669,8 +3670,8 @@ Function_type::do_import(Import* imp)
Type* ptype = imp->read_type();
if (is_varargs)
ptype = Type::make_array_type(ptype, NULL);
- parameters->push_back(Typed_identifier(Import::import_marker,
- ptype, imp->location()));
+ parameters->push_back(Typed_identifier(name, ptype,
+ imp->location()));
if (imp->peek_char() != ',')
break;
go_assert(!is_varargs);
@@ -3689,17 +3690,18 @@ Function_type::do_import(Import* imp)
if (imp->peek_char() != '(')
{
Type* rtype = imp->read_type();
- results->push_back(Typed_identifier(Import::import_marker, rtype,
- imp->location()));
+ results->push_back(Typed_identifier("", rtype, imp->location()));
}
else
{
imp->advance(1);
while (true)
{
+ std::string name = imp->read_name();
+ imp->require_c_string(" ");
Type* rtype = imp->read_type();
- results->push_back(Typed_identifier(Import::import_marker,
- rtype, imp->location()));
+ results->push_back(Typed_identifier(name, rtype,
+ imp->location()));
if (imp->peek_char() != ',')
break;
imp->require_c_string(", ");
@@ -7185,7 +7187,7 @@ Interface_type::do_export(Export* exp) const
{
if (pm->name().empty())
{
- exp->write_c_string("$ ");
+ exp->write_c_string("? ");
exp->write_type(pm->type());
}
else
@@ -7209,6 +7211,8 @@ Interface_type::do_export(Export* exp) const
first = false;
else
exp->write_c_string(", ");
+ exp->write_name(pp->name());
+ exp->write_c_string(" ");
if (!is_varargs || pp + 1 != parameters->end())
exp->write_type(pp->type());
else
@@ -7226,7 +7230,7 @@ Interface_type::do_export(Export* exp) const
if (results != NULL)
{
exp->write_c_string(" ");
- if (results->size() == 1)
+ if (results->size() == 1 && results->begin()->name().empty())
exp->write_type(results->begin()->type());
else
{
@@ -7241,6 +7245,8 @@ Interface_type::do_export(Export* exp) const
first = false;
else
exp->write_c_string(", ");
+ exp->write_name(p->name());
+ exp->write_c_string(" ");
exp->write_type(p->type());
}
exp->write_c_string(")");
@@ -7267,7 +7273,7 @@ Interface_type::do_import(Import* imp)
{
std::string name = imp->read_identifier();
- if (name == "$")
+ if (name == "?")
{
imp->require_c_string(" ");
Type* t = imp->read_type();
@@ -7287,6 +7293,9 @@ Interface_type::do_import(Import* imp)
parameters = new Typed_identifier_list;
while (true)
{
+ std::string name = imp->read_name();
+ imp->require_c_string(" ");
+
if (imp->match_c_string("..."))
{
imp->advance(3);
@@ -7296,8 +7305,8 @@ Interface_type::do_import(Import* imp)
Type* ptype = imp->read_type();
if (is_varargs)
ptype = Type::make_array_type(ptype, NULL);
- parameters->push_back(Typed_identifier(Import::import_marker,
- ptype, imp->location()));
+ parameters->push_back(Typed_identifier(name, ptype,
+ imp->location()));
if (imp->peek_char() != ',')
break;
go_assert(!is_varargs);
@@ -7316,17 +7325,18 @@ Interface_type::do_import(Import* imp)
if (imp->peek_char() != '(')
{
Type* rtype = imp->read_type();
- results->push_back(Typed_identifier(Import::import_marker,
- rtype, imp->location()));
+ results->push_back(Typed_identifier("", rtype, imp->location()));
}
else
{
imp->advance(1);
while (true)
{
+ std::string name = imp->read_name();
+ imp->require_c_string(" ");
Type* rtype = imp->read_type();
- results->push_back(Typed_identifier(Import::import_marker,
- rtype, imp->location()));
+ results->push_back(Typed_identifier(name, rtype,
+ imp->location()));
if (imp->peek_char() != ',')
break;
imp->require_c_string(", ");
OpenPOWER on IntegriCloud