aboutsummaryrefslogtreecommitdiff
path: root/gcc/go
diff options
context:
space:
mode:
authorIan Lance Taylor <ian@gcc.gnu.org>2019-09-27 17:51:43 +0000
committerIan Lance Taylor <ian@gcc.gnu.org>2019-09-27 17:51:43 +0000
commit37ed4c3269f940a3a064e320331aed38890fb8c0 (patch)
treedebbcd2618d12faca1022453affd57f60e070665 /gcc/go
parent51c3b7c6ec20262f2a4698f42e533c28d2c38a87 (diff)
downloadgcc-37ed4c3269f940a3a064e320331aed38890fb8c0.zip
gcc-37ed4c3269f940a3a064e320331aed38890fb8c0.tar.gz
gcc-37ed4c3269f940a3a064e320331aed38890fb8c0.tar.bz2
compiler: don't read known type, simplify Import::finalize_methods
With the current export format, if we already know the type, we don't have to read and parse the definition. We only use the finalizer in Import::finalize_methods, so make it a local variable. To match Finalize_methods::type, only put struct types into real_for_named. Reviewed-on: https://go-review.googlesource.com/c/gofrontend/+/197700 From-SVN: r276188
Diffstat (limited to 'gcc/go')
-rw-r--r--gcc/go/gofrontend/MERGE2
-rw-r--r--gcc/go/gofrontend/import.cc40
-rw-r--r--gcc/go/gofrontend/import.h4
3 files changed, 23 insertions, 23 deletions
diff --git a/gcc/go/gofrontend/MERGE b/gcc/go/gofrontend/MERGE
index 871a3ee..1e6ca6f 100644
--- a/gcc/go/gofrontend/MERGE
+++ b/gcc/go/gofrontend/MERGE
@@ -1,4 +1,4 @@
-27d1f3031197428b5745d09c167f982d638b8776
+9112ea664ed9ee5f108158a913812adaf03edf6e
The first line of this file holds the git revision number of the last
merge done from the gofrontend repository.
diff --git a/gcc/go/gofrontend/import.cc b/gcc/go/gofrontend/import.cc
index bbc8d7d..c63ae24 100644
--- a/gcc/go/gofrontend/import.cc
+++ b/gcc/go/gofrontend/import.cc
@@ -290,16 +290,10 @@ Import::Import(Stream* stream, Location location)
: gogo_(NULL), stream_(stream), location_(location), package_(NULL),
add_to_globals_(false), packages_(), type_data_(), type_pos_(0),
type_offsets_(), builtin_types_((- SMALLEST_BUILTIN_CODE) + 1),
- types_(), finalizer_(NULL), version_(EXPORT_FORMAT_UNKNOWN)
+ types_(), version_(EXPORT_FORMAT_UNKNOWN)
{
}
-Import::~Import()
-{
- if (this->finalizer_ != NULL)
- delete this->finalizer_;
-}
-
// Import the data in the associated stream.
Package*
@@ -692,16 +686,22 @@ Import::read_types()
void
Import::finalize_methods()
{
- if (this->finalizer_ == NULL)
- this->finalizer_ = new Finalize_methods(gogo_);
+ Finalize_methods finalizer(this->gogo_);
Unordered_set(Type*) real_for_named;
for (size_t i = 1; i < this->types_.size(); i++)
{
Type* type = this->types_[i];
if (type != NULL && type->named_type() != NULL)
{
- this->finalizer_->type(type);
- real_for_named.insert(type->named_type()->real_type());
+ finalizer.type(type);
+
+ // If the real type is a struct type, we don't want to
+ // finalize its methods. For a named type defined as a
+ // struct type, we only want to finalize the methods of the
+ // named type. This is like Finalize_methods::type.
+ Type* real_type = type->named_type()->real_type();
+ if (real_type->struct_type() != NULL)
+ real_for_named.insert(real_type);
}
}
for (size_t i = 1; i < this->types_.size(); i++)
@@ -710,7 +710,7 @@ Import::finalize_methods()
if (type != NULL
&& type->named_type() == NULL
&& real_for_named.find(type) == real_for_named.end())
- this->finalizer_->type(type);
+ finalizer.type(type);
}
}
@@ -1105,12 +1105,12 @@ Import::read_named_type(int index)
type = this->types_[index];
else
{
- type = this->read_type();
-
if (no->is_type_declaration())
{
// We can define the type now.
+ type = this->read_type();
+
no = package->add_type(type_name, type, this->location_);
Named_type* ntype = no->type_value();
@@ -1127,14 +1127,18 @@ Import::read_named_type(int index)
}
else if (no->is_type())
{
- // We have seen this type before. FIXME: it would be a good
- // idea to check that the two imported types are identical,
- // but we have not finalized the methods yet, which means
- // that we can not reliably compare interface types.
+ // We have seen this type before.
type = no->type_value();
// Don't change the visibility of the existing type.
+
+ // For older export versions, we need to skip the type
+ // definition in the stream.
+ if (this->version_ < EXPORT_FORMAT_V3)
+ this->read_type();
}
+ else
+ go_unreachable();
this->types_[index] = type;
diff --git a/gcc/go/gofrontend/import.h b/gcc/go/gofrontend/import.h
index a78e48b..b12b3b8 100644
--- a/gcc/go/gofrontend/import.h
+++ b/gcc/go/gofrontend/import.h
@@ -208,8 +208,6 @@ class Import : public Import_expression
// Constructor.
Import(Stream*, Location);
- virtual ~Import();
-
// Register the builtin types.
void
register_builtin_types(Gogo*);
@@ -450,8 +448,6 @@ class Import : public Import_expression
std::vector<Named_type*> builtin_types_;
// Mapping from exported type codes to Type structures.
std::vector<Type*> types_;
- // Helper for finalizing methods.
- Finalize_methods* finalizer_;
// Version of export data we're reading.
Export_data_version version_;
};