diff options
author | Ian Lance Taylor <ian@gcc.gnu.org> | 2017-01-14 01:50:31 +0000 |
---|---|---|
committer | Ian Lance Taylor <ian@gcc.gnu.org> | 2017-01-14 01:50:31 +0000 |
commit | a2bd02aecff5ebb73ff3ab6db5a1db8b375205ac (patch) | |
tree | e0c6fe09604b8c1e8df1d97b108f37710551c3ee /gcc/go/gofrontend/parse.cc | |
parent | 3220ce78c95b6d2cf04851ea37c0f587f52e5fad (diff) | |
download | gcc-a2bd02aecff5ebb73ff3ab6db5a1db8b375205ac.zip gcc-a2bd02aecff5ebb73ff3ab6db5a1db8b375205ac.tar.gz gcc-a2bd02aecff5ebb73ff3ab6db5a1db8b375205ac.tar.bz2 |
compiler: implement type aliases
This is a start of implementing type aliases (`type T1 = T2`) in the
Go frontend. This is incomplete, in that the reflection information
is not updated for an embedded type alias. It is also not well
tested. Finally, the change to the language has not been approved.
This should be regarded as preliminary work for experimental use.
Update golang/go#18130.
Reviewed-on: https://go-review.googlesource.com/35120
From-SVN: r244460
Diffstat (limited to 'gcc/go/gofrontend/parse.cc')
-rw-r--r-- | gcc/go/gofrontend/parse.cc | 21 |
1 files changed, 15 insertions, 6 deletions
diff --git a/gcc/go/gofrontend/parse.cc b/gcc/go/gofrontend/parse.cc index 34a7765..84840fb 100644 --- a/gcc/go/gofrontend/parse.cc +++ b/gcc/go/gofrontend/parse.cc @@ -1515,7 +1515,7 @@ Parse::type_decl() this->decl(&Parse::type_spec, NULL); } -// TypeSpec = identifier Type . +// TypeSpec = identifier ["="] Type . void Parse::type_spec(void*) @@ -1531,6 +1531,13 @@ Parse::type_spec(void*) Location location = token->location(); token = this->advance_token(); + bool is_alias = false; + if (token->is_op(OPERATOR_EQ)) + { + is_alias = true; + token = this->advance_token(); + } + // The scope of the type name starts at the point where the // identifier appears in the source code. We implement this by // declaring the type before we read the type definition. @@ -1542,13 +1549,13 @@ Parse::type_spec(void*) } Type* type; - if (name == "_" && this->peek_token()->is_keyword(KEYWORD_INTERFACE)) + if (name == "_" && token->is_keyword(KEYWORD_INTERFACE)) { // We call Parse::interface_type explicity here because we do not want // to record an interface with a blank type name. type = this->interface_type(false); } - else if (!this->peek_token()->is_op(OPERATOR_SEMICOLON)) + else if (!token->is_op(OPERATOR_SEMICOLON)) type = this->type(); else { @@ -1579,9 +1586,11 @@ Parse::type_spec(void*) type = Type::make_error_type(); } - this->gogo_->define_type(named_type, - Type::make_named_type(named_type, type, - location)); + Named_type* nt = Type::make_named_type(named_type, type, location); + if (is_alias) + nt->set_is_alias(); + + this->gogo_->define_type(named_type, nt); go_assert(named_type->package() == NULL); } else |