aboutsummaryrefslogtreecommitdiff
path: root/src/cmd/compile/internal/syntax/nodes.go
diff options
context:
space:
mode:
authorMatthew Dempsky <mdempsky@google.com>2016-08-16 13:33:29 -0700
committerMatthew Dempsky <mdempsky@google.com>2016-08-19 01:09:52 +0000
commit117793624b630b0ee63abb16dcb019301adc6472 (patch)
treede7abfdde47e7fe0307b26d5ad6164ad5136a52e /src/cmd/compile/internal/syntax/nodes.go
parent4e8c11379345f08ccf47239f7e0ea192917f602a (diff)
downloadgo-117793624b630b0ee63abb16dcb019301adc6472.tar.gz
go-117793624b630b0ee63abb16dcb019301adc6472.zip
cmd/compile/internal/syntax: expose additional information for gc
gc needs access to line offsets for Nodes. It also needs access to the end line offset for function bodies so it knows what line number to use for things like implicit returns and defer executions. Lastly, include an extra bool to distinguish between simple and full slice expressions. This is redundant in valid parse trees, but needed by gc for producing complete warnings in invalid inputs. Change-Id: I64baf334a35c72336d26fa6755c67eb9d6f4e93c Reviewed-on: https://go-review.googlesource.com/27196 Reviewed-by: Robert Griesemer <gri@golang.org> Run-TryBot: Matthew Dempsky <mdempsky@google.com> TryBot-Result: Gobot Gobot <gobot@golang.org>
Diffstat (limited to 'src/cmd/compile/internal/syntax/nodes.go')
-rw-r--r--src/cmd/compile/internal/syntax/nodes.go26
1 files changed, 19 insertions, 7 deletions
diff --git a/src/cmd/compile/internal/syntax/nodes.go b/src/cmd/compile/internal/syntax/nodes.go
index 4e264c1e82..e56b1235fe 100644
--- a/src/cmd/compile/internal/syntax/nodes.go
+++ b/src/cmd/compile/internal/syntax/nodes.go
@@ -8,6 +8,7 @@ package syntax
// Nodes
type Node interface {
+ Line() uint32
aNode()
}
@@ -19,6 +20,10 @@ type node struct {
func (*node) aNode() {}
+func (n *node) Line() uint32 {
+ return n.line
+}
+
func (n *node) init(p *parser) {
n.pos = uint32(p.pos)
n.line = uint32(p.line)
@@ -80,11 +85,12 @@ type (
}
FuncDecl struct {
- Attr map[string]bool // go:attr map
- Recv *Field // nil means regular function
- Name *Name
- Type *FuncType
- Body []Stmt // nil means no body (forward declaration)
+ Attr map[string]bool // go:attr map
+ Recv *Field // nil means regular function
+ Name *Name
+ Type *FuncType
+ Body []Stmt // nil means no body (forward declaration)
+ EndLine uint32 // TODO(mdempsky): Cleaner solution.
decl
}
)
@@ -136,8 +142,9 @@ type (
// func Type { Body }
FuncLit struct {
- Type *FuncType
- Body []Stmt
+ Type *FuncType
+ Body []Stmt
+ EndLine uint32 // TODO(mdempsky): Cleaner solution.
expr
}
@@ -165,6 +172,11 @@ type (
SliceExpr struct {
X Expr
Index [3]Expr
+ // Full indicates whether this is a simple or full slice expression.
+ // In a valid AST, this is equivalent to Index[2] != nil.
+ // TODO(mdempsky): This is only needed to report the "3-index
+ // slice of string" error when Index[2] is missing.
+ Full bool
expr
}