aboutsummaryrefslogtreecommitdiff
path: root/src/go/parser/parser.go
diff options
context:
space:
mode:
authorRob Findley <rfindley@google.com>2021-02-24 10:31:11 -0500
committerRobert Findley <rfindley@google.com>2021-03-02 01:50:12 +0000
commita6eeb4add46eddb19ceba36bdd448738808e5ce2 (patch)
tree06b2d25e5aef46c7ce3da6fae61e199025efdd88 /src/go/parser/parser.go
parentff5cf4ced3f1681ec972cd954d4b476f87616fe3 (diff)
downloadgo-a6eeb4add46eddb19ceba36bdd448738808e5ce2.tar.gz
go-a6eeb4add46eddb19ceba36bdd448738808e5ce2.zip
go/parser,go/types: hide API changes related to type parameters
While the dev.typeparams branch was merged, the type parameter API is slated for go1.18. Hide these changes to the go/parser and go/types API. This was done as follows: + For APIs that will probably not be needed for go1.18, simply unexport them. + For APIs that we expect to export in go1.18, prefix symbols with '_', so that the planned (upper-cased) symbol name is apparent. + For APIs that must be exported for testing, move both API and tests to files guarded by the go1.18 build constraint. + parser.ParseTypeParams is unexported and copied wherever it is needed. + The -G flag is removed from gofmt, replaced by enabling type parameters if built with the go1.18 build constraint. Notably, changes related to type parameters in go/ast are currently left exported. We're looking at the AST API separately. The new API diff from 1.16 is: +pkg go/ast, method (*FuncDecl) IsMethod() bool +pkg go/ast, method (*ListExpr) End() token.Pos +pkg go/ast, method (*ListExpr) Pos() token.Pos +pkg go/ast, type FuncType struct, TParams *FieldList +pkg go/ast, type ListExpr struct +pkg go/ast, type ListExpr struct, ElemList []Expr +pkg go/ast, type TypeSpec struct, TParams *FieldList +pkg go/types, type Config struct, GoVersion string Change-Id: I1baf67e26279b49092e774309a836c460979774a Reviewed-on: https://go-review.googlesource.com/c/go/+/295929 Trust: Robert Findley <rfindley@google.com> Trust: Robert Griesemer <gri@golang.org> Run-TryBot: Robert Findley <rfindley@google.com> TryBot-Result: Go Bot <gobot@golang.org> Reviewed-by: Robert Griesemer <gri@golang.org>
Diffstat (limited to 'src/go/parser/parser.go')
-rw-r--r--src/go/parser/parser.go22
1 files changed, 11 insertions, 11 deletions
diff --git a/src/go/parser/parser.go b/src/go/parser/parser.go
index 5c4cea8638..ed1867b3b3 100644
--- a/src/go/parser/parser.go
+++ b/src/go/parser/parser.go
@@ -651,7 +651,7 @@ func (p *parser) parseQualifiedIdent(ident *ast.Ident) ast.Expr {
}
typ := p.parseTypeName(ident)
- if p.tok == token.LBRACK && p.mode&ParseTypeParams != 0 {
+ if p.tok == token.LBRACK && p.mode&parseTypeParams != 0 {
typ = p.parseTypeInstance(typ)
}
@@ -712,7 +712,7 @@ func (p *parser) parseArrayFieldOrTypeInstance(x *ast.Ident) (*ast.Ident, ast.Ex
// TODO(rfindley): consider changing parseRhsOrType so that this function variable
// is not needed.
argparser := p.parseRhsOrType
- if p.mode&ParseTypeParams == 0 {
+ if p.mode&parseTypeParams == 0 {
argparser = p.parseRhs
}
if p.tok != token.RBRACK {
@@ -742,13 +742,13 @@ func (p *parser) parseArrayFieldOrTypeInstance(x *ast.Ident) (*ast.Ident, ast.Ex
// x [P]E
return x, &ast.ArrayType{Lbrack: lbrack, Len: args[0], Elt: elt}
}
- if p.mode&ParseTypeParams == 0 {
+ if p.mode&parseTypeParams == 0 {
p.error(rbrack, "missing element type in array type expression")
return nil, &ast.BadExpr{From: args[0].Pos(), To: args[0].End()}
}
}
- if p.mode&ParseTypeParams == 0 {
+ if p.mode&parseTypeParams == 0 {
p.error(firstComma, "expected ']', found ','")
return x, &ast.BadExpr{From: args[0].Pos(), To: args[len(args)-1].End()}
}
@@ -1045,7 +1045,7 @@ func (p *parser) parseParameters(scope *ast.Scope, acceptTParams bool) (tparams,
defer un(trace(p, "Parameters"))
}
- if p.mode&ParseTypeParams != 0 && acceptTParams && p.tok == token.LBRACK {
+ if p.mode&parseTypeParams != 0 && acceptTParams && p.tok == token.LBRACK {
opening := p.pos
p.next()
// [T any](params) syntax
@@ -1119,7 +1119,7 @@ func (p *parser) parseMethodSpec(scope *ast.Scope) *ast.Field {
x := p.parseTypeName(nil)
if ident, _ := x.(*ast.Ident); ident != nil {
switch {
- case p.tok == token.LBRACK && p.mode&ParseTypeParams != 0:
+ case p.tok == token.LBRACK && p.mode&parseTypeParams != 0:
// generic method or embedded instantiated type
lbrack := p.pos
p.next()
@@ -1171,7 +1171,7 @@ func (p *parser) parseMethodSpec(scope *ast.Scope) *ast.Field {
} else {
// embedded, possibly instantiated type
typ = x
- if p.tok == token.LBRACK && p.mode&ParseTypeParams != 0 {
+ if p.tok == token.LBRACK && p.mode&parseTypeParams != 0 {
// embedded instantiated interface
typ = p.parseTypeInstance(typ)
}
@@ -1193,7 +1193,7 @@ func (p *parser) parseInterfaceType() *ast.InterfaceType {
lbrace := p.expect(token.LBRACE)
scope := ast.NewScope(nil) // interface scope
var list []*ast.Field
- for p.tok == token.IDENT || p.mode&ParseTypeParams != 0 && p.tok == token.TYPE {
+ for p.tok == token.IDENT || p.mode&parseTypeParams != 0 && p.tok == token.TYPE {
if p.tok == token.IDENT {
list = append(list, p.parseMethodSpec(scope))
} else {
@@ -1289,7 +1289,7 @@ func (p *parser) tryIdentOrType() ast.Expr {
switch p.tok {
case token.IDENT:
typ := p.parseTypeName(nil)
- if p.tok == token.LBRACK && p.mode&ParseTypeParams != 0 {
+ if p.tok == token.LBRACK && p.mode&parseTypeParams != 0 {
typ = p.parseTypeInstance(typ)
}
return typ
@@ -1552,7 +1552,7 @@ func (p *parser) parseIndexOrSliceOrInstance(x ast.Expr) ast.Expr {
return &ast.IndexExpr{X: x, Lbrack: lbrack, Index: index[0], Rbrack: rbrack}
}
- if p.mode&ParseTypeParams == 0 {
+ if p.mode&parseTypeParams == 0 {
p.error(firstComma, "expected ']' or ':', found ','")
return &ast.BadExpr{From: args[0].Pos(), To: args[len(args)-1].End()}
}
@@ -2696,7 +2696,7 @@ func (p *parser) parseTypeSpec(doc *ast.CommentGroup, _ token.Pos, _ token.Token
p.exprLev++
x := p.parseExpr(true) // we don't know yet if we're a lhs or rhs expr
p.exprLev--
- if name0, _ := x.(*ast.Ident); p.mode&ParseTypeParams != 0 && name0 != nil && p.tok != token.RBRACK {
+ if name0, _ := x.(*ast.Ident); p.mode&parseTypeParams != 0 && name0 != nil && p.tok != token.RBRACK {
// generic type [T any];
p.parseGenericType(spec, lbrack, name0, token.RBRACK)
} else {