@@ -374,6 +374,13 @@ type (
374
374
Rparen token.Pos // position of ")"
375
375
}
376
376
377
+ // A ListExpr node represents a list of expressions separated by commas.
378
+ // ListExpr nodes are used as index in IndexExpr nodes representing type
379
+ // or function instantiations with more than one type argument.
380
+ ListExpr struct {
381
+ ElemList []Expr
382
+ }
383
+
377
384
// A StarExpr node represents an expression of the form "*" Expression.
378
385
// Semantically it could be a unary "*" expression, or a pointer type.
379
386
//
@@ -440,6 +447,14 @@ type (
440
447
441
448
// Pointer types are represented via StarExpr nodes.
442
449
450
+ // A FuncType node represents a function type.
451
+ FuncType struct {
452
+ Func token.Pos // position of "func" keyword (token.NoPos if there is no "func")
453
+ TParams * FieldList // type parameters; or nil
454
+ Params * FieldList // (incoming) parameters; non-nil
455
+ Results * FieldList // (outgoing) results; or nil
456
+ }
457
+
443
458
// An InterfaceType node represents an interface type.
444
459
InterfaceType struct {
445
460
Interface token.Pos // position of "interface" keyword
@@ -482,12 +497,18 @@ func (x *IndexExpr) Pos() token.Pos { return x.X.Pos() }
482
497
func (x * SliceExpr ) Pos () token.Pos { return x .X .Pos () }
483
498
func (x * TypeAssertExpr ) Pos () token.Pos { return x .X .Pos () }
484
499
func (x * CallExpr ) Pos () token.Pos { return x .Fun .Pos () }
485
- func (x * StarExpr ) Pos () token.Pos { return x .Star }
486
- func (x * UnaryExpr ) Pos () token.Pos { return x .OpPos }
487
- func (x * BinaryExpr ) Pos () token.Pos { return x .X .Pos () }
488
- func (x * KeyValueExpr ) Pos () token.Pos { return x .Key .Pos () }
489
- func (x * ArrayType ) Pos () token.Pos { return x .Lbrack }
490
- func (x * StructType ) Pos () token.Pos { return x .Struct }
500
+ func (x * ListExpr ) Pos () token.Pos {
501
+ if len (x .ElemList ) > 0 {
502
+ return x .ElemList [0 ].Pos ()
503
+ }
504
+ return token .NoPos
505
+ }
506
+ func (x * StarExpr ) Pos () token.Pos { return x .Star }
507
+ func (x * UnaryExpr ) Pos () token.Pos { return x .OpPos }
508
+ func (x * BinaryExpr ) Pos () token.Pos { return x .X .Pos () }
509
+ func (x * KeyValueExpr ) Pos () token.Pos { return x .Key .Pos () }
510
+ func (x * ArrayType ) Pos () token.Pos { return x .Lbrack }
511
+ func (x * StructType ) Pos () token.Pos { return x .Struct }
491
512
func (x * FuncType ) Pos () token.Pos {
492
513
if x .Func .IsValid () || x .Params == nil { // see issue 3870
493
514
return x .Func
@@ -515,12 +536,18 @@ func (x *IndexExpr) End() token.Pos { return x.Rbrack + 1 }
515
536
func (x * SliceExpr ) End () token.Pos { return x .Rbrack + 1 }
516
537
func (x * TypeAssertExpr ) End () token.Pos { return x .Rparen + 1 }
517
538
func (x * CallExpr ) End () token.Pos { return x .Rparen + 1 }
518
- func (x * StarExpr ) End () token.Pos { return x .X .End () }
519
- func (x * UnaryExpr ) End () token.Pos { return x .X .End () }
520
- func (x * BinaryExpr ) End () token.Pos { return x .Y .End () }
521
- func (x * KeyValueExpr ) End () token.Pos { return x .Value .End () }
522
- func (x * ArrayType ) End () token.Pos { return x .Elt .End () }
523
- func (x * StructType ) End () token.Pos { return x .Fields .End () }
539
+ func (x * ListExpr ) End () token.Pos {
540
+ if len (x .ElemList ) > 0 {
541
+ return x .ElemList [len (x .ElemList )- 1 ].End ()
542
+ }
543
+ return token .NoPos
544
+ }
545
+ func (x * StarExpr ) End () token.Pos { return x .X .End () }
546
+ func (x * UnaryExpr ) End () token.Pos { return x .X .End () }
547
+ func (x * BinaryExpr ) End () token.Pos { return x .Y .End () }
548
+ func (x * KeyValueExpr ) End () token.Pos { return x .Value .End () }
549
+ func (x * ArrayType ) End () token.Pos { return x .Elt .End () }
550
+ func (x * StructType ) End () token.Pos { return x .Fields .End () }
524
551
func (x * FuncType ) End () token.Pos {
525
552
if x .Results != nil {
526
553
return x .Results .End ()
@@ -546,6 +573,7 @@ func (*IndexExpr) exprNode() {}
546
573
func (* SliceExpr ) exprNode () {}
547
574
func (* TypeAssertExpr ) exprNode () {}
548
575
func (* CallExpr ) exprNode () {}
576
+ func (* ListExpr ) exprNode () {}
549
577
func (* StarExpr ) exprNode () {}
550
578
func (* UnaryExpr ) exprNode () {}
551
579
func (* BinaryExpr ) exprNode () {}
@@ -892,6 +920,16 @@ type (
892
920
Values []Expr // initial values; or nil
893
921
Comment * CommentGroup // line comments; or nil
894
922
}
923
+
924
+ // A TypeSpec node represents a type declaration (TypeSpec production).
925
+ TypeSpec struct {
926
+ Doc * CommentGroup // associated documentation; or nil
927
+ Name * Ident // type name
928
+ TParams * FieldList // type parameters; or nil
929
+ Assign token.Pos // position of '=', if any
930
+ Type Expr // *Ident, *ParenExpr, *SelectorExpr, *StarExpr, or any of the *XxxTypes
931
+ Comment * CommentGroup // line comments; or nil
932
+ }
895
933
)
896
934
897
935
// Pos and End implementations for spec nodes.
0 commit comments