]> Cypherpunks repositories - gostls13.git/commitdiff
[dev.typeparams] cmd/compile/internal/syntax: prepare syntax nodes for type parameters
authorRobert Griesemer <gri@golang.org>
Mon, 12 Oct 2020 20:11:03 +0000 (13:11 -0700)
committerRobert Griesemer <gri@golang.org>
Tue, 13 Oct 2020 00:22:03 +0000 (00:22 +0000)
- 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>
src/cmd/compile/internal/gc/noder.go
src/cmd/compile/internal/syntax/nodes.go
src/cmd/compile/internal/syntax/parser.go
src/cmd/compile/internal/syntax/parser_test.go

index 5dce533e4b7e791d08f0632c11d76113cbc9c33b..8b1105598364fc5d429fd5e8f4a4d6206631e73b 100644 (file)
@@ -60,7 +60,7 @@ func parseFiles(filenames []string) uint {
                }
 
                p.node()
-               lines += p.file.Lines
+               lines += p.file.EOF.Line()
                p.file = nil // release memory
 
                if nsyntaxerrors != 0 {
index 815630fcd412edbc2344c4ef468a188a851bb816..f2dbdcda29769f1f92587686d8a77dfb30031146 100644 (file)
@@ -37,7 +37,7 @@ type File struct {
        Pragma   Pragma
        PkgName  *Name
        DeclList []Decl
-       Lines    uint
+       EOF      Pos
        node
 }
 
@@ -74,11 +74,12 @@ type (
 
        // Name Type
        TypeDecl struct {
-               Group  *Group // nil means not part of a group
-               Pragma Pragma
-               Name   *Name
-               Alias  bool
-               Type   Expr
+               Group      *Group // nil means not part of a group
+               Pragma     Pragma
+               Name       *Name
+               TParamList []*Field // nil means no type parameters
+               Alias      bool
+               Type       Expr
                decl
        }
 
@@ -99,11 +100,12 @@ type (
        // func Receiver Name Type { Body }
        // func Receiver Name Type
        FuncDecl struct {
-               Pragma Pragma
-               Recv   *Field // nil means regular function
-               Name   *Name
-               Type   *FuncType
-               Body   *BlockStmt // nil means no body (forward declaration)
+               Pragma     Pragma
+               Recv       *Field // nil means regular function
+               Name       *Name
+               TParamList []*Field // nil means no type parameters
+               Type       *FuncType
+               Body       *BlockStmt // nil means no body (forward declaration)
                decl
        }
 )
@@ -223,9 +225,10 @@ type (
 
        // Fun(ArgList[0], ArgList[1], ...)
        CallExpr struct {
-               Fun     Expr
-               ArgList []Expr // nil means no arguments
-               HasDots bool   // last argument is followed by ...
+               Fun      Expr
+               ArgList  []Expr // nil means no arguments
+               HasDots  bool   // last argument is followed by ...
+               Brackets bool   // []'s instead of ()'s
                expr
        }
 
@@ -272,7 +275,7 @@ type (
 
        // interface { MethodList[0]; MethodList[1]; ... }
        InterfaceType struct {
-               MethodList []*Field
+               MethodList []*Field // a field named "type" means a type constraint
                expr
        }
 
index 1485b700596aa47617dd92453ba23881d7855ce3..146f83ed017698b0864ec22b84078a3c3f6db382 100644 (file)
@@ -445,7 +445,7 @@ func (p *parser) fileOrNil() *File {
        // p.tok == _EOF
 
        p.clearPragma()
-       f.Lines = p.line
+       f.EOF = p.pos()
 
        return f
 }
index 81945faee95e2d55ac2dfca3f7ffdd2e5901d552..f1c5433b400e4c50a6f61ece0e3aba1873db8270 100644 (file)
@@ -76,7 +76,7 @@ func TestStdLib(t *testing.T) {
                                if *verify {
                                        verifyPrint(filename, ast)
                                }
-                               results <- parseResult{filename, ast.Lines}
+                               results <- parseResult{filename, ast.EOF.Line()}
                        })
                }
        }()