Commit 429edcff authored by Robert Griesemer's avatar Robert Griesemer

Revert "cmd/compile/internal/syntax: support for alias declarations"

This reverts commit 32db3f27.

Reason: Decision to back out current alias implementation.

For #16339.

Change-Id: Ib05e3d96041d8347e49cae292f66bec791a1fdc8
Reviewed-on: https://go-review.googlesource.com/32825Reviewed-by: 's avatarMatthew Dempsky <mdempsky@google.com>
parent a1a688fa
...@@ -25,21 +25,14 @@ func (n *node) Line() uint32 { ...@@ -25,21 +25,14 @@ func (n *node) Line() uint32 {
return n.line return n.line
} }
// TODO(gri) clean up init/initFrom once we have a good file pos story
func (n *node) init(p *parser) { func (n *node) init(p *parser) {
n.pos = uint32(p.pos) n.pos = uint32(p.pos)
n.line = uint32(p.line) n.line = uint32(p.line)
} }
func (n *node) initFrom(a *node) {
n.pos = a.pos
n.line = a.line
}
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
// Files // Files
// package PkgName; DeclList[0], DeclList[1], ...
type File struct { type File struct {
PkgName *Name PkgName *Name
DeclList []Decl DeclList []Decl
...@@ -56,8 +49,6 @@ type ( ...@@ -56,8 +49,6 @@ type (
aDecl() aDecl()
} }
// Path
// LocalPkgName Path
ImportDecl struct { ImportDecl struct {
LocalPkgName *Name // including "."; nil means no rename present LocalPkgName *Name // including "."; nil means no rename present
Path *BasicLit Path *BasicLit
...@@ -65,18 +56,6 @@ type ( ...@@ -65,18 +56,6 @@ type (
decl decl
} }
// Name => Orig
AliasDecl struct {
Tok token // Const, Type, Var, or Func
Name *Name
Orig Expr
Group *Group // nil means not part of a group
decl
}
// NameList
// NameList = Values
// NameList Type = Values
ConstDecl struct { ConstDecl struct {
NameList []*Name NameList []*Name
Type Expr // nil means no type Type Expr // nil means no type
...@@ -85,7 +64,6 @@ type ( ...@@ -85,7 +64,6 @@ type (
decl decl
} }
// Name Type
TypeDecl struct { TypeDecl struct {
Name *Name Name *Name
Type Expr Type Expr
...@@ -94,9 +72,6 @@ type ( ...@@ -94,9 +72,6 @@ type (
decl decl
} }
// NameList Type
// NameList Type = Values
// NameList = Values
VarDecl struct { VarDecl struct {
NameList []*Name NameList []*Name
Type Expr // nil means no type Type Expr // nil means no type
...@@ -105,10 +80,6 @@ type ( ...@@ -105,10 +80,6 @@ type (
decl decl
} }
// func Name Type { Body }
// func Name Type
// func Receiver Name Type { Body }
// func Receiver Name Type
FuncDecl struct { FuncDecl struct {
Attr map[string]bool // go:attr map Attr map[string]bool // go:attr map
Recv *Field // nil means regular function Recv *Field // nil means regular function
...@@ -448,8 +419,6 @@ func (simpleStmt) aSimpleStmt() {} ...@@ -448,8 +419,6 @@ func (simpleStmt) aSimpleStmt() {}
// ---------------------------------------------------------------------------- // ----------------------------------------------------------------------------
// Comments // Comments
// TODO(gri) Consider renaming to CommentPos, CommentPlacement, etc.
// Kind = Above doesn't make much sense.
type CommentKind uint type CommentKind uint
const ( const (
......
...@@ -317,38 +317,16 @@ func (p *parser) importDecl(group *Group) Decl { ...@@ -317,38 +317,16 @@ func (p *parser) importDecl(group *Group) Decl {
return d return d
} }
// AliasSpec = identifier "=>" [ PackageName "." ] identifier . // ConstSpec = IdentifierList [ [ Type ] "=" ExpressionList ] .
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 .
func (p *parser) constDecl(group *Group) Decl { func (p *parser) constDecl(group *Group) Decl {
if trace { if trace {
defer p.trace("constDecl")() defer p.trace("constDecl")()
} }
name := p.name()
if p.got(_Rarrow) {
return p.aliasDecl(Const, name, group)
}
d := new(ConstDecl) 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 { if p.tok != _EOF && p.tok != _Semi && p.tok != _Rparen {
d.Type = p.tryType() d.Type = p.tryType()
if p.got(_Assign) { if p.got(_Assign) {
...@@ -360,21 +338,16 @@ func (p *parser) constDecl(group *Group) Decl { ...@@ -360,21 +338,16 @@ func (p *parser) constDecl(group *Group) Decl {
return d return d
} }
// TypeSpec = identifier Type | AliasSpec . // TypeSpec = identifier Type .
func (p *parser) typeDecl(group *Group) Decl { func (p *parser) typeDecl(group *Group) Decl {
if trace { if trace {
defer p.trace("typeDecl")() defer p.trace("typeDecl")()
} }
name := p.name()
if p.got(_Rarrow) {
return p.aliasDecl(Type, name, group)
}
d := new(TypeDecl) d := new(TypeDecl)
d.initFrom(&name.node) d.init(p)
d.Name = name d.Name = p.name()
d.Type = p.tryType() d.Type = p.tryType()
if d.Type == nil { if d.Type == nil {
p.syntax_error("in type declaration") p.syntax_error("in type declaration")
...@@ -386,21 +359,16 @@ func (p *parser) typeDecl(group *Group) Decl { ...@@ -386,21 +359,16 @@ func (p *parser) typeDecl(group *Group) Decl {
return d return d
} }
// VarSpec = IdentifierList ( Type [ "=" ExpressionList ] | "=" ExpressionList ) | AliasSpec . // VarSpec = IdentifierList ( Type [ "=" ExpressionList ] | "=" ExpressionList ) .
func (p *parser) varDecl(group *Group) Decl { func (p *parser) varDecl(group *Group) Decl {
if trace { if trace {
defer p.trace("varDecl")() defer p.trace("varDecl")()
} }
name := p.name()
if p.got(_Rarrow) {
return p.aliasDecl(Var, name, group)
}
d := new(VarDecl) 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) { if p.got(_Assign) {
d.Values = p.exprList() d.Values = p.exprList()
} else { } else {
...@@ -417,28 +385,31 @@ func (p *parser) varDecl(group *Group) Decl { ...@@ -417,28 +385,31 @@ func (p *parser) varDecl(group *Group) Decl {
return d return d
} }
var badRecv = new(Field) // to signal invalid receiver in funcDecl // FunctionDecl = "func" FunctionName ( Function | Signature ) .
// FunctionDecl = "func" FunctionName ( Function | Signature ) | "func" AliasSpec .
// FunctionName = identifier . // FunctionName = identifier .
// Function = Signature FunctionBody . // Function = Signature FunctionBody .
// MethodDecl = "func" Receiver MethodName ( Function | Signature ) . // MethodDecl = "func" Receiver MethodName ( Function | Signature ) .
// Receiver = Parameters . // Receiver = Parameters .
func (p *parser) funcDecl() Decl { func (p *parser) funcDecl() *FuncDecl {
if trace { if trace {
defer p.trace("funcDecl")() defer p.trace("funcDecl")()
} }
var recv *Field f := new(FuncDecl)
f.init(p)
badRecv := false
if p.tok == _Lparen { if p.tok == _Lparen {
recv = badRecv rcvr := p.paramList()
switch list := p.paramList(); len(list) { switch len(rcvr) {
case 0: case 0:
p.error("method has no receiver") p.error("method has no receiver")
badRecv = true
case 1: case 1:
recv = list[0] f.Recv = rcvr[0]
default: default:
p.error("method has multiple receivers") p.error("method has multiple receivers")
badRecv = true
} }
} }
...@@ -448,11 +419,6 @@ func (p *parser) funcDecl() Decl { ...@@ -448,11 +419,6 @@ func (p *parser) funcDecl() Decl {
return nil return nil
} }
name := p.name()
if recv == nil && p.got(_Rarrow) {
return p.aliasDecl(Func, name, nil)
}
// TODO(gri) check for regular functions only // TODO(gri) check for regular functions only
// if name.Sym.Name == "init" { // if name.Sym.Name == "init" {
// name = renameinit() // name = renameinit()
...@@ -467,11 +433,7 @@ func (p *parser) funcDecl() Decl { ...@@ -467,11 +433,7 @@ func (p *parser) funcDecl() Decl {
// } // }
// } // }
f := new(FuncDecl) f.Name = p.name()
f.initFrom(&name.node) // TODO(gri) is this the correct position for methods?
f.Recv = recv
f.Name = name
f.Type = p.funcType() f.Type = p.funcType()
if gcCompat { if gcCompat {
f.node = f.Type.node f.node = f.Type.node
...@@ -486,7 +448,7 @@ func (p *parser) funcDecl() Decl { ...@@ -486,7 +448,7 @@ func (p *parser) funcDecl() Decl {
// p.error("can only use //go:noescape with external func implementations") // p.error("can only use //go:noescape with external func implementations")
// } // }
if recv == badRecv { if badRecv {
return nil // TODO(gri) better solution return nil // TODO(gri) better solution
} }
return f return f
...@@ -555,7 +517,7 @@ func (p *parser) unaryExpr() Expr { ...@@ -555,7 +517,7 @@ func (p *parser) unaryExpr() Expr {
return x return x
} }
case _Larrow: case _Arrow:
// receive op (<-x) or receive-only channel (<-chan E) // receive op (<-x) or receive-only channel (<-chan E)
p.next() p.next()
...@@ -969,7 +931,7 @@ func (p *parser) tryType() Expr { ...@@ -969,7 +931,7 @@ func (p *parser) tryType() Expr {
p.next() p.next()
return indirect(p.type_()) return indirect(p.type_())
case _Larrow: case _Arrow:
// recvchantype // recvchantype
p.next() p.next()
p.want(_Chan) p.want(_Chan)
...@@ -1015,7 +977,7 @@ func (p *parser) tryType() Expr { ...@@ -1015,7 +977,7 @@ func (p *parser) tryType() Expr {
p.next() p.next()
t := new(ChanType) t := new(ChanType)
t.init(p) t.init(p)
if p.got(_Larrow) { if p.got(_Arrow) {
t.Dir = SendOnly t.Dir = SendOnly
} }
t.Elem = p.chanElem() t.Elem = p.chanElem()
...@@ -1358,7 +1320,7 @@ func (p *parser) paramDecl() *Field { ...@@ -1358,7 +1320,7 @@ func (p *parser) paramDecl() *Field {
case _Name: case _Name:
f.Name = p.name() f.Name = p.name()
switch p.tok { 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 // sym name_or_type
f.Type = p.type_() f.Type = p.type_()
...@@ -1373,7 +1335,7 @@ func (p *parser) paramDecl() *Field { ...@@ -1373,7 +1335,7 @@ func (p *parser) paramDecl() *Field {
f.Name = nil 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 // name_or_type
f.Type = p.type_() f.Type = p.type_()
...@@ -1507,7 +1469,7 @@ func (p *parser) simpleStmt(lhs Expr, rangeOk bool) SimpleStmt { ...@@ -1507,7 +1469,7 @@ func (p *parser) simpleStmt(lhs Expr, rangeOk bool) SimpleStmt {
p.next() p.next()
return p.newAssignStmt(op, lhs, ImplicitOne) return p.newAssignStmt(op, lhs, ImplicitOne)
case _Larrow: case _Arrow:
// lhs <- rhs // lhs <- rhs
p.next() p.next()
s := new(SendStmt) s := new(SendStmt)
...@@ -1860,7 +1822,7 @@ func (p *parser) commClause() *CommClause { ...@@ -1860,7 +1822,7 @@ func (p *parser) commClause() *CommClause {
p.next() p.next()
lhs := p.exprList() lhs := p.exprList()
if _, ok := lhs.(*ListExpr); !ok && p.tok == _Larrow { if _, ok := lhs.(*ListExpr); !ok && p.tok == _Arrow {
// lhs <- x // lhs <- x
} else { } else {
// lhs // lhs
...@@ -1940,7 +1902,7 @@ func (p *parser) stmt() Stmt { ...@@ -1940,7 +1902,7 @@ func (p *parser) stmt() Stmt {
case _Literal, _Func, _Lparen, // operands case _Literal, _Func, _Lparen, // operands
_Lbrack, _Struct, _Map, _Chan, _Interface, // composite types _Lbrack, _Struct, _Map, _Chan, _Interface, // composite types
_Larrow: // receive operator _Arrow: // receive operator
return p.simpleStmt(nil, false) return p.simpleStmt(nil, false)
case _For: case _For:
......
...@@ -473,11 +473,11 @@ func (p *printer) printRawNode(n Node) { ...@@ -473,11 +473,11 @@ func (p *printer) printRawNode(n Node) {
case *ChanType: case *ChanType:
if n.Dir == RecvOnly { if n.Dir == RecvOnly {
p.print(_Larrow) p.print(_Arrow)
} }
p.print(_Chan) p.print(_Chan)
if n.Dir == SendOnly { if n.Dir == SendOnly {
p.print(_Larrow) p.print(_Arrow)
} }
p.print(blank, n.Elem) p.print(blank, n.Elem)
...@@ -495,7 +495,7 @@ func (p *printer) printRawNode(n Node) { ...@@ -495,7 +495,7 @@ func (p *printer) printRawNode(n Node) {
p.print(n.X) p.print(n.X)
case *SendStmt: case *SendStmt:
p.print(n.Chan, blank, _Larrow, blank, n.Value) p.print(n.Chan, blank, _Arrow, blank, n.Value)
case *AssignStmt: case *AssignStmt:
p.print(n.Lhs) p.print(n.Lhs)
...@@ -603,12 +603,6 @@ func (p *printer) printRawNode(n Node) { ...@@ -603,12 +603,6 @@ func (p *printer) printRawNode(n Node) {
} }
p.print(n.Path) p.print(n.Path)
case *AliasDecl:
if n.Group == nil {
p.print(n.Tok, blank)
}
p.print(n.Name, blank, _Rarrow, blank, n.Orig)
case *ConstDecl: case *ConstDecl:
if n.Group == nil { if n.Group == nil {
p.print(_Const, blank) p.print(_Const, blank)
...@@ -763,8 +757,6 @@ func groupFor(d Decl) (token, *Group) { ...@@ -763,8 +757,6 @@ func groupFor(d Decl) (token, *Group) {
switch d := d.(type) { switch d := d.(type) {
case *ImportDecl: case *ImportDecl:
return _Import, d.Group return _Import, d.Group
case *AliasDecl:
return d.Tok, d.Group
case *ConstDecl: case *ConstDecl:
return _Const, d.Group return _Const, d.Group
case *TypeDecl: case *TypeDecl:
......
...@@ -229,7 +229,7 @@ redo: ...@@ -229,7 +229,7 @@ redo:
goto assignop goto assignop
} }
if c == '-' { if c == '-' {
s.tok = _Larrow s.tok = _Arrow
break break
} }
s.ungetr() s.ungetr()
...@@ -253,16 +253,11 @@ redo: ...@@ -253,16 +253,11 @@ redo:
s.tok = _Operator s.tok = _Operator
case '=': case '=':
c = s.getr() if s.getr() == '=' {
if c == '=' {
s.op, s.prec = Eql, precCmp s.op, s.prec = Eql, precCmp
s.tok = _Operator s.tok = _Operator
break break
} }
if c == '>' {
s.tok = _Rarrow
break
}
s.ungetr() s.ungetr()
s.tok = _Assign s.tok = _Assign
......
...@@ -210,8 +210,7 @@ var sampleTokens = [...]struct { ...@@ -210,8 +210,7 @@ var sampleTokens = [...]struct {
{_IncOp, "--", Sub, precAdd}, {_IncOp, "--", Sub, precAdd},
{_Assign, "=", 0, 0}, {_Assign, "=", 0, 0},
{_Define, ":=", 0, 0}, {_Define, ":=", 0, 0},
{_Larrow, "<-", 0, 0}, {_Arrow, "<-", 0, 0},
{_Rarrow, "=>", 0, 0},
// delimiters // delimiters
{_Lparen, "(", 0, 0}, {_Lparen, "(", 0, 0},
......
...@@ -22,8 +22,7 @@ const ( ...@@ -22,8 +22,7 @@ const (
_IncOp _IncOp
_Assign _Assign
_Define _Define
_Larrow _Arrow
_Rarrow
_Star _Star
// delimitors // delimitors
...@@ -70,12 +69,6 @@ const ( ...@@ -70,12 +69,6 @@ const (
) )
const ( const (
// for AliasDecl
Const = _Const
Type = _Type
Var = _Var
Func = _Func
// for BranchStmt // for BranchStmt
Break = _Break Break = _Break
Continue = _Continue Continue = _Continue
...@@ -101,8 +94,7 @@ var tokstrings = [...]string{ ...@@ -101,8 +94,7 @@ var tokstrings = [...]string{
_IncOp: "opop", _IncOp: "opop",
_Assign: "=", _Assign: "=",
_Define: ":=", _Define: ":=",
_Larrow: "<-", _Arrow: "<-",
_Rarrow: "=>",
_Star: "*", _Star: "*",
// delimitors // delimitors
......
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