Skip to content

Commit 429edcf

Browse files
committed
Revert "cmd/compile/internal/syntax: support for alias declarations"
This reverts commit 32db3f2. 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 <[email protected]>
1 parent a1a688f commit 429edcf

File tree

6 files changed

+38
-129
lines changed

6 files changed

+38
-129
lines changed

src/cmd/compile/internal/syntax/nodes.go

-31
Original file line numberDiff line numberDiff line change
@@ -25,21 +25,14 @@ func (n *node) Line() uint32 {
2525
return n.line
2626
}
2727

28-
// TODO(gri) clean up init/initFrom once we have a good file pos story
2928
func (n *node) init(p *parser) {
3029
n.pos = uint32(p.pos)
3130
n.line = uint32(p.line)
3231
}
3332

34-
func (n *node) initFrom(a *node) {
35-
n.pos = a.pos
36-
n.line = a.line
37-
}
38-
3933
// ----------------------------------------------------------------------------
4034
// Files
4135

42-
// package PkgName; DeclList[0], DeclList[1], ...
4336
type File struct {
4437
PkgName *Name
4538
DeclList []Decl
@@ -56,27 +49,13 @@ type (
5649
aDecl()
5750
}
5851

59-
// Path
60-
// LocalPkgName Path
6152
ImportDecl struct {
6253
LocalPkgName *Name // including "."; nil means no rename present
6354
Path *BasicLit
6455
Group *Group // nil means not part of a group
6556
decl
6657
}
6758

68-
// Name => Orig
69-
AliasDecl struct {
70-
Tok token // Const, Type, Var, or Func
71-
Name *Name
72-
Orig Expr
73-
Group *Group // nil means not part of a group
74-
decl
75-
}
76-
77-
// NameList
78-
// NameList = Values
79-
// NameList Type = Values
8059
ConstDecl struct {
8160
NameList []*Name
8261
Type Expr // nil means no type
@@ -85,7 +64,6 @@ type (
8564
decl
8665
}
8766

88-
// Name Type
8967
TypeDecl struct {
9068
Name *Name
9169
Type Expr
@@ -94,9 +72,6 @@ type (
9472
decl
9573
}
9674

97-
// NameList Type
98-
// NameList Type = Values
99-
// NameList = Values
10075
VarDecl struct {
10176
NameList []*Name
10277
Type Expr // nil means no type
@@ -105,10 +80,6 @@ type (
10580
decl
10681
}
10782

108-
// func Name Type { Body }
109-
// func Name Type
110-
// func Receiver Name Type { Body }
111-
// func Receiver Name Type
11283
FuncDecl struct {
11384
Attr map[string]bool // go:attr map
11485
Recv *Field // nil means regular function
@@ -448,8 +419,6 @@ func (simpleStmt) aSimpleStmt() {}
448419
// ----------------------------------------------------------------------------
449420
// Comments
450421

451-
// TODO(gri) Consider renaming to CommentPos, CommentPlacement, etc.
452-
// Kind = Above doesn't make much sense.
453422
type CommentKind uint
454423

455424
const (

src/cmd/compile/internal/syntax/parser.go

+30-68
Original file line numberDiff line numberDiff line change
@@ -317,38 +317,16 @@ func (p *parser) importDecl(group *Group) Decl {
317317
return d
318318
}
319319

320-
// AliasSpec = identifier "=>" [ PackageName "." ] identifier .
321-
func (p *parser) aliasDecl(tok token, name *Name, group *Group) Decl {
322-
// no tracing since this is already called from a const/type/var/funcDecl
323-
324-
d := new(AliasDecl)
325-
d.initFrom(&name.node)
326-
327-
// lhs identifier and "=>" have been consumed already
328-
329-
d.Tok = tok
330-
d.Name = name
331-
d.Orig = p.dotname(p.name())
332-
d.Group = group
333-
334-
return d
335-
}
336-
337-
// ConstSpec = IdentifierList [ [ Type ] "=" ExpressionList ] | AliasSpec .
320+
// ConstSpec = IdentifierList [ [ Type ] "=" ExpressionList ] .
338321
func (p *parser) constDecl(group *Group) Decl {
339322
if trace {
340323
defer p.trace("constDecl")()
341324
}
342325

343-
name := p.name()
344-
if p.got(_Rarrow) {
345-
return p.aliasDecl(Const, name, group)
346-
}
347-
348326
d := new(ConstDecl)
349-
d.initFrom(&name.node)
327+
d.init(p)
350328

351-
d.NameList = p.nameList(name)
329+
d.NameList = p.nameList(p.name())
352330
if p.tok != _EOF && p.tok != _Semi && p.tok != _Rparen {
353331
d.Type = p.tryType()
354332
if p.got(_Assign) {
@@ -360,21 +338,16 @@ func (p *parser) constDecl(group *Group) Decl {
360338
return d
361339
}
362340

363-
// TypeSpec = identifier Type | AliasSpec .
341+
// TypeSpec = identifier Type .
364342
func (p *parser) typeDecl(group *Group) Decl {
365343
if trace {
366344
defer p.trace("typeDecl")()
367345
}
368346

369-
name := p.name()
370-
if p.got(_Rarrow) {
371-
return p.aliasDecl(Type, name, group)
372-
}
373-
374347
d := new(TypeDecl)
375-
d.initFrom(&name.node)
348+
d.init(p)
376349

377-
d.Name = name
350+
d.Name = p.name()
378351
d.Type = p.tryType()
379352
if d.Type == nil {
380353
p.syntax_error("in type declaration")
@@ -386,21 +359,16 @@ func (p *parser) typeDecl(group *Group) Decl {
386359
return d
387360
}
388361

389-
// VarSpec = IdentifierList ( Type [ "=" ExpressionList ] | "=" ExpressionList ) | AliasSpec .
362+
// VarSpec = IdentifierList ( Type [ "=" ExpressionList ] | "=" ExpressionList ) .
390363
func (p *parser) varDecl(group *Group) Decl {
391364
if trace {
392365
defer p.trace("varDecl")()
393366
}
394367

395-
name := p.name()
396-
if p.got(_Rarrow) {
397-
return p.aliasDecl(Var, name, group)
398-
}
399-
400368
d := new(VarDecl)
401-
d.initFrom(&name.node)
369+
d.init(p)
402370

403-
d.NameList = p.nameList(name)
371+
d.NameList = p.nameList(p.name())
404372
if p.got(_Assign) {
405373
d.Values = p.exprList()
406374
} else {
@@ -417,28 +385,31 @@ func (p *parser) varDecl(group *Group) Decl {
417385
return d
418386
}
419387

420-
var badRecv = new(Field) // to signal invalid receiver in funcDecl
421-
422-
// FunctionDecl = "func" FunctionName ( Function | Signature ) | "func" AliasSpec .
388+
// FunctionDecl = "func" FunctionName ( Function | Signature ) .
423389
// FunctionName = identifier .
424390
// Function = Signature FunctionBody .
425391
// MethodDecl = "func" Receiver MethodName ( Function | Signature ) .
426392
// Receiver = Parameters .
427-
func (p *parser) funcDecl() Decl {
393+
func (p *parser) funcDecl() *FuncDecl {
428394
if trace {
429395
defer p.trace("funcDecl")()
430396
}
431397

432-
var recv *Field
398+
f := new(FuncDecl)
399+
f.init(p)
400+
401+
badRecv := false
433402
if p.tok == _Lparen {
434-
recv = badRecv
435-
switch list := p.paramList(); len(list) {
403+
rcvr := p.paramList()
404+
switch len(rcvr) {
436405
case 0:
437406
p.error("method has no receiver")
407+
badRecv = true
438408
case 1:
439-
recv = list[0]
409+
f.Recv = rcvr[0]
440410
default:
441411
p.error("method has multiple receivers")
412+
badRecv = true
442413
}
443414
}
444415

@@ -448,11 +419,6 @@ func (p *parser) funcDecl() Decl {
448419
return nil
449420
}
450421

451-
name := p.name()
452-
if recv == nil && p.got(_Rarrow) {
453-
return p.aliasDecl(Func, name, nil)
454-
}
455-
456422
// TODO(gri) check for regular functions only
457423
// if name.Sym.Name == "init" {
458424
// name = renameinit()
@@ -467,11 +433,7 @@ func (p *parser) funcDecl() Decl {
467433
// }
468434
// }
469435

470-
f := new(FuncDecl)
471-
f.initFrom(&name.node) // TODO(gri) is this the correct position for methods?
472-
473-
f.Recv = recv
474-
f.Name = name
436+
f.Name = p.name()
475437
f.Type = p.funcType()
476438
if gcCompat {
477439
f.node = f.Type.node
@@ -486,7 +448,7 @@ func (p *parser) funcDecl() Decl {
486448
// p.error("can only use //go:noescape with external func implementations")
487449
// }
488450

489-
if recv == badRecv {
451+
if badRecv {
490452
return nil // TODO(gri) better solution
491453
}
492454
return f
@@ -555,7 +517,7 @@ func (p *parser) unaryExpr() Expr {
555517
return x
556518
}
557519

558-
case _Larrow:
520+
case _Arrow:
559521
// receive op (<-x) or receive-only channel (<-chan E)
560522
p.next()
561523

@@ -969,7 +931,7 @@ func (p *parser) tryType() Expr {
969931
p.next()
970932
return indirect(p.type_())
971933

972-
case _Larrow:
934+
case _Arrow:
973935
// recvchantype
974936
p.next()
975937
p.want(_Chan)
@@ -1015,7 +977,7 @@ func (p *parser) tryType() Expr {
1015977
p.next()
1016978
t := new(ChanType)
1017979
t.init(p)
1018-
if p.got(_Larrow) {
980+
if p.got(_Arrow) {
1019981
t.Dir = SendOnly
1020982
}
1021983
t.Elem = p.chanElem()
@@ -1358,7 +1320,7 @@ func (p *parser) paramDecl() *Field {
13581320
case _Name:
13591321
f.Name = p.name()
13601322
switch p.tok {
1361-
case _Name, _Star, _Larrow, _Func, _Lbrack, _Chan, _Map, _Struct, _Interface, _Lparen:
1323+
case _Name, _Star, _Arrow, _Func, _Lbrack, _Chan, _Map, _Struct, _Interface, _Lparen:
13621324
// sym name_or_type
13631325
f.Type = p.type_()
13641326

@@ -1373,7 +1335,7 @@ func (p *parser) paramDecl() *Field {
13731335
f.Name = nil
13741336
}
13751337

1376-
case _Larrow, _Star, _Func, _Lbrack, _Chan, _Map, _Struct, _Interface, _Lparen:
1338+
case _Arrow, _Star, _Func, _Lbrack, _Chan, _Map, _Struct, _Interface, _Lparen:
13771339
// name_or_type
13781340
f.Type = p.type_()
13791341

@@ -1507,7 +1469,7 @@ func (p *parser) simpleStmt(lhs Expr, rangeOk bool) SimpleStmt {
15071469
p.next()
15081470
return p.newAssignStmt(op, lhs, ImplicitOne)
15091471

1510-
case _Larrow:
1472+
case _Arrow:
15111473
// lhs <- rhs
15121474
p.next()
15131475
s := new(SendStmt)
@@ -1860,7 +1822,7 @@ func (p *parser) commClause() *CommClause {
18601822
p.next()
18611823
lhs := p.exprList()
18621824

1863-
if _, ok := lhs.(*ListExpr); !ok && p.tok == _Larrow {
1825+
if _, ok := lhs.(*ListExpr); !ok && p.tok == _Arrow {
18641826
// lhs <- x
18651827
} else {
18661828
// lhs
@@ -1940,7 +1902,7 @@ func (p *parser) stmt() Stmt {
19401902

19411903
case _Literal, _Func, _Lparen, // operands
19421904
_Lbrack, _Struct, _Map, _Chan, _Interface, // composite types
1943-
_Larrow: // receive operator
1905+
_Arrow: // receive operator
19441906
return p.simpleStmt(nil, false)
19451907

19461908
case _For:

src/cmd/compile/internal/syntax/printer.go

+3-11
Original file line numberDiff line numberDiff line change
@@ -473,11 +473,11 @@ func (p *printer) printRawNode(n Node) {
473473

474474
case *ChanType:
475475
if n.Dir == RecvOnly {
476-
p.print(_Larrow)
476+
p.print(_Arrow)
477477
}
478478
p.print(_Chan)
479479
if n.Dir == SendOnly {
480-
p.print(_Larrow)
480+
p.print(_Arrow)
481481
}
482482
p.print(blank, n.Elem)
483483

@@ -495,7 +495,7 @@ func (p *printer) printRawNode(n Node) {
495495
p.print(n.X)
496496

497497
case *SendStmt:
498-
p.print(n.Chan, blank, _Larrow, blank, n.Value)
498+
p.print(n.Chan, blank, _Arrow, blank, n.Value)
499499

500500
case *AssignStmt:
501501
p.print(n.Lhs)
@@ -603,12 +603,6 @@ func (p *printer) printRawNode(n Node) {
603603
}
604604
p.print(n.Path)
605605

606-
case *AliasDecl:
607-
if n.Group == nil {
608-
p.print(n.Tok, blank)
609-
}
610-
p.print(n.Name, blank, _Rarrow, blank, n.Orig)
611-
612606
case *ConstDecl:
613607
if n.Group == nil {
614608
p.print(_Const, blank)
@@ -763,8 +757,6 @@ func groupFor(d Decl) (token, *Group) {
763757
switch d := d.(type) {
764758
case *ImportDecl:
765759
return _Import, d.Group
766-
case *AliasDecl:
767-
return d.Tok, d.Group
768760
case *ConstDecl:
769761
return _Const, d.Group
770762
case *TypeDecl:

src/cmd/compile/internal/syntax/scanner.go

+2-7
Original file line numberDiff line numberDiff line change
@@ -229,7 +229,7 @@ redo:
229229
goto assignop
230230
}
231231
if c == '-' {
232-
s.tok = _Larrow
232+
s.tok = _Arrow
233233
break
234234
}
235235
s.ungetr()
@@ -253,16 +253,11 @@ redo:
253253
s.tok = _Operator
254254

255255
case '=':
256-
c = s.getr()
257-
if c == '=' {
256+
if s.getr() == '=' {
258257
s.op, s.prec = Eql, precCmp
259258
s.tok = _Operator
260259
break
261260
}
262-
if c == '>' {
263-
s.tok = _Rarrow
264-
break
265-
}
266261
s.ungetr()
267262
s.tok = _Assign
268263

0 commit comments

Comments
 (0)