aboutsummaryrefslogtreecommitdiff
path: root/src/cmd/compile/internal/syntax/parser.go
diff options
context:
space:
mode:
authorRobert Griesemer <gri@golang.org>2016-11-04 16:27:31 -0700
committerRobert Griesemer <gri@golang.org>2016-11-05 00:46:39 +0000
commit429edcff1049899cef4e3c5cb4b473e13a31d85c (patch)
treeeff2794211af0f7ad00182030f3d5edf8e9acfbf /src/cmd/compile/internal/syntax/parser.go
parenta1a688fa0012f7ce3a37e9ac0070461fe8e3f28e (diff)
downloadgo-429edcff1049899cef4e3c5cb4b473e13a31d85c.tar.xz
Revert "cmd/compile/internal/syntax: support for alias declarations"
This reverts commit 32db3f2756324616b7c856ac9501deccc2491239. Reason: Decision to back out current alias implementation. For #16339. Change-Id: Ib05e3d96041d8347e49cae292f66bec791a1fdc8 Reviewed-on: https://go-review.googlesource.com/32825 Reviewed-by: Matthew Dempsky <mdempsky@google.com>
Diffstat (limited to 'src/cmd/compile/internal/syntax/parser.go')
-rw-r--r--src/cmd/compile/internal/syntax/parser.go98
1 files changed, 30 insertions, 68 deletions
diff --git a/src/cmd/compile/internal/syntax/parser.go b/src/cmd/compile/internal/syntax/parser.go
index 1ed20651b1..a959c6cd25 100644
--- a/src/cmd/compile/internal/syntax/parser.go
+++ b/src/cmd/compile/internal/syntax/parser.go
@@ -317,38 +317,16 @@ func (p *parser) importDecl(group *Group) Decl {
return d
}
-// AliasSpec = identifier "=>" [ PackageName "." ] identifier .
-func (p *parser) aliasDecl(tok token, name *Name, group *Group) Decl {
- // no tracing since this is already called from a const/type/var/funcDecl
-
- d := new(AliasDecl)
- d.initFrom(&name.node)
-
- // lhs identifier and "=>" have been consumed already
-
- d.Tok = tok
- d.Name = name
- d.Orig = p.dotname(p.name())
- d.Group = group
-
- return d
-}
-
-// ConstSpec = IdentifierList [ [ Type ] "=" ExpressionList ] | AliasSpec .
+// ConstSpec = IdentifierList [ [ Type ] "=" ExpressionList ] .
func (p *parser) constDecl(group *Group) Decl {
if trace {
defer p.trace("constDecl")()
}
- name := p.name()
- if p.got(_Rarrow) {
- return p.aliasDecl(Const, name, group)
- }
-
d := new(ConstDecl)
- d.initFrom(&name.node)
+ d.init(p)
- d.NameList = p.nameList(name)
+ d.NameList = p.nameList(p.name())
if p.tok != _EOF && p.tok != _Semi && p.tok != _Rparen {
d.Type = p.tryType()
if p.got(_Assign) {
@@ -360,21 +338,16 @@ func (p *parser) constDecl(group *Group) Decl {
return d
}
-// TypeSpec = identifier Type | AliasSpec .
+// TypeSpec = identifier Type .
func (p *parser) typeDecl(group *Group) Decl {
if trace {
defer p.trace("typeDecl")()
}
- name := p.name()
- if p.got(_Rarrow) {
- return p.aliasDecl(Type, name, group)
- }
-
d := new(TypeDecl)
- d.initFrom(&name.node)
+ d.init(p)
- d.Name = name
+ d.Name = p.name()
d.Type = p.tryType()
if d.Type == nil {
p.syntax_error("in type declaration")
@@ -386,21 +359,16 @@ func (p *parser) typeDecl(group *Group) Decl {
return d
}
-// VarSpec = IdentifierList ( Type [ "=" ExpressionList ] | "=" ExpressionList ) | AliasSpec .
+// VarSpec = IdentifierList ( Type [ "=" ExpressionList ] | "=" ExpressionList ) .
func (p *parser) varDecl(group *Group) Decl {
if trace {
defer p.trace("varDecl")()
}
- name := p.name()
- if p.got(_Rarrow) {
- return p.aliasDecl(Var, name, group)
- }
-
d := new(VarDecl)
- d.initFrom(&name.node)
+ d.init(p)
- d.NameList = p.nameList(name)
+ d.NameList = p.nameList(p.name())
if p.got(_Assign) {
d.Values = p.exprList()
} else {
@@ -417,28 +385,31 @@ func (p *parser) varDecl(group *Group) Decl {
return d
}
-var badRecv = new(Field) // to signal invalid receiver in funcDecl
-
-// FunctionDecl = "func" FunctionName ( Function | Signature ) | "func" AliasSpec .
+// FunctionDecl = "func" FunctionName ( Function | Signature ) .
// FunctionName = identifier .
// Function = Signature FunctionBody .
// MethodDecl = "func" Receiver MethodName ( Function | Signature ) .
// Receiver = Parameters .
-func (p *parser) funcDecl() Decl {
+func (p *parser) funcDecl() *FuncDecl {
if trace {
defer p.trace("funcDecl")()
}
- var recv *Field
+ f := new(FuncDecl)
+ f.init(p)
+
+ badRecv := false
if p.tok == _Lparen {
- recv = badRecv
- switch list := p.paramList(); len(list) {
+ rcvr := p.paramList()
+ switch len(rcvr) {
case 0:
p.error("method has no receiver")
+ badRecv = true
case 1:
- recv = list[0]
+ f.Recv = rcvr[0]
default:
p.error("method has multiple receivers")
+ badRecv = true
}
}
@@ -448,11 +419,6 @@ func (p *parser) funcDecl() Decl {
return nil
}
- name := p.name()
- if recv == nil && p.got(_Rarrow) {
- return p.aliasDecl(Func, name, nil)
- }
-
// TODO(gri) check for regular functions only
// if name.Sym.Name == "init" {
// name = renameinit()
@@ -467,11 +433,7 @@ func (p *parser) funcDecl() Decl {
// }
// }
- f := new(FuncDecl)
- f.initFrom(&name.node) // TODO(gri) is this the correct position for methods?
-
- f.Recv = recv
- f.Name = name
+ f.Name = p.name()
f.Type = p.funcType()
if gcCompat {
f.node = f.Type.node
@@ -486,7 +448,7 @@ func (p *parser) funcDecl() Decl {
// p.error("can only use //go:noescape with external func implementations")
// }
- if recv == badRecv {
+ if badRecv {
return nil // TODO(gri) better solution
}
return f
@@ -555,7 +517,7 @@ func (p *parser) unaryExpr() Expr {
return x
}
- case _Larrow:
+ case _Arrow:
// receive op (<-x) or receive-only channel (<-chan E)
p.next()
@@ -969,7 +931,7 @@ func (p *parser) tryType() Expr {
p.next()
return indirect(p.type_())
- case _Larrow:
+ case _Arrow:
// recvchantype
p.next()
p.want(_Chan)
@@ -1015,7 +977,7 @@ func (p *parser) tryType() Expr {
p.next()
t := new(ChanType)
t.init(p)
- if p.got(_Larrow) {
+ if p.got(_Arrow) {
t.Dir = SendOnly
}
t.Elem = p.chanElem()
@@ -1358,7 +1320,7 @@ func (p *parser) paramDecl() *Field {
case _Name:
f.Name = p.name()
switch p.tok {
- case _Name, _Star, _Larrow, _Func, _Lbrack, _Chan, _Map, _Struct, _Interface, _Lparen:
+ case _Name, _Star, _Arrow, _Func, _Lbrack, _Chan, _Map, _Struct, _Interface, _Lparen:
// sym name_or_type
f.Type = p.type_()
@@ -1373,7 +1335,7 @@ func (p *parser) paramDecl() *Field {
f.Name = nil
}
- case _Larrow, _Star, _Func, _Lbrack, _Chan, _Map, _Struct, _Interface, _Lparen:
+ case _Arrow, _Star, _Func, _Lbrack, _Chan, _Map, _Struct, _Interface, _Lparen:
// name_or_type
f.Type = p.type_()
@@ -1507,7 +1469,7 @@ func (p *parser) simpleStmt(lhs Expr, rangeOk bool) SimpleStmt {
p.next()
return p.newAssignStmt(op, lhs, ImplicitOne)
- case _Larrow:
+ case _Arrow:
// lhs <- rhs
p.next()
s := new(SendStmt)
@@ -1860,7 +1822,7 @@ func (p *parser) commClause() *CommClause {
p.next()
lhs := p.exprList()
- if _, ok := lhs.(*ListExpr); !ok && p.tok == _Larrow {
+ if _, ok := lhs.(*ListExpr); !ok && p.tok == _Arrow {
// lhs <- x
} else {
// lhs
@@ -1940,7 +1902,7 @@ func (p *parser) stmt() Stmt {
case _Literal, _Func, _Lparen, // operands
_Lbrack, _Struct, _Map, _Chan, _Interface, // composite types
- _Larrow: // receive operator
+ _Arrow: // receive operator
return p.simpleStmt(nil, false)
case _For: