[dev.typeparams] cmd/compile/internal/syntax: prepare syntax nodes for type parameters

- add TParamList fields to TypeDecl, FuncDecl
- also: change File.Lines to File.EOF so we have the actual file end position

Change-Id: Ia345f888080a884f7ac5cefd8bff3d80e4a59cdc
Reviewed-on: https://go-review.googlesource.com/c/go/+/261657
Trust: Robert Griesemer <gri@golang.org>
Run-TryBot: Robert Griesemer <gri@golang.org>
TryBot-Result: Go Bot <gobot@golang.org>
Reviewed-by: Matthew Dempsky <mdempsky@google.com>
This commit is contained in:
Robert Griesemer 2020-10-12 13:11:03 -07:00
parent 986cad14e2
commit 617b633917
4 changed files with 21 additions and 18 deletions

View file

@ -60,7 +60,7 @@ func parseFiles(filenames []string) uint {
} }
p.node() p.node()
lines += p.file.Lines lines += p.file.EOF.Line()
p.file = nil // release memory p.file = nil // release memory
if nsyntaxerrors != 0 { if nsyntaxerrors != 0 {

View file

@ -37,7 +37,7 @@ type File struct {
Pragma Pragma Pragma Pragma
PkgName *Name PkgName *Name
DeclList []Decl DeclList []Decl
Lines uint EOF Pos
node node
} }
@ -77,6 +77,7 @@ type (
Group *Group // nil means not part of a group Group *Group // nil means not part of a group
Pragma Pragma Pragma Pragma
Name *Name Name *Name
TParamList []*Field // nil means no type parameters
Alias bool Alias bool
Type Expr Type Expr
decl decl
@ -102,6 +103,7 @@ type (
Pragma Pragma Pragma Pragma
Recv *Field // nil means regular function Recv *Field // nil means regular function
Name *Name Name *Name
TParamList []*Field // nil means no type parameters
Type *FuncType Type *FuncType
Body *BlockStmt // nil means no body (forward declaration) Body *BlockStmt // nil means no body (forward declaration)
decl decl
@ -226,6 +228,7 @@ type (
Fun Expr Fun Expr
ArgList []Expr // nil means no arguments ArgList []Expr // nil means no arguments
HasDots bool // last argument is followed by ... HasDots bool // last argument is followed by ...
Brackets bool // []'s instead of ()'s
expr expr
} }
@ -272,7 +275,7 @@ type (
// interface { MethodList[0]; MethodList[1]; ... } // interface { MethodList[0]; MethodList[1]; ... }
InterfaceType struct { InterfaceType struct {
MethodList []*Field MethodList []*Field // a field named "type" means a type constraint
expr expr
} }

View file

@ -445,7 +445,7 @@ func (p *parser) fileOrNil() *File {
// p.tok == _EOF // p.tok == _EOF
p.clearPragma() p.clearPragma()
f.Lines = p.line f.EOF = p.pos()
return f return f
} }

View file

@ -76,7 +76,7 @@ func TestStdLib(t *testing.T) {
if *verify { if *verify {
verifyPrint(filename, ast) verifyPrint(filename, ast)
} }
results <- parseResult{filename, ast.Lines} results <- parseResult{filename, ast.EOF.Line()}
}) })
} }
}() }()