aboutsummaryrefslogtreecommitdiff
path: root/src/go/ast/ast_typeparams.go
blob: 24fdc5f1317e5f2cd1a6c27be8aac26bc8873273 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
// Copyright 2021 The Go Authors. All rights reserved.
// Use of this source code is governed by a BSD-style
// license that can be found in the LICENSE file.

//go:build typeparams
// +build typeparams

package ast

import "go/token"

type (
	// A FuncType node represents a function type.
	FuncType struct {
		Func    token.Pos  // position of "func" keyword (token.NoPos if there is no "func")
		TParams *FieldList // type parameters; or nil
		Params  *FieldList // (incoming) parameters; non-nil
		Results *FieldList // (outgoing) results; or nil
	}

	// A TypeSpec node represents a type declaration (TypeSpec production).
	TypeSpec struct {
		Doc     *CommentGroup // associated documentation; or nil
		Name    *Ident        // type name
		TParams *FieldList    // type parameters; or nil
		Assign  token.Pos     // position of '=', if any
		Type    Expr          // *Ident, *ParenExpr, *SelectorExpr, *StarExpr, or any of the *XxxTypes
		Comment *CommentGroup // line comments; or nil
	}

	// A ListExpr node represents a list of expressions separated by commas.
	// ListExpr nodes are used as index in IndexExpr nodes representing type
	// or function instantiations with more than one type argument.
	ListExpr struct {
		ElemList []Expr
	}
)

func (*ListExpr) exprNode() {}
func (x *ListExpr) Pos() token.Pos {
	if len(x.ElemList) > 0 {
		return x.ElemList[0].Pos()
	}
	return token.NoPos
}
func (x *ListExpr) End() token.Pos {
	if len(x.ElemList) > 0 {
		return x.ElemList[len(x.ElemList)-1].End()
	}
	return token.NoPos
}