aboutsummaryrefslogtreecommitdiff
path: root/src/cmd/compile/internal/syntax/nodes.go
diff options
context:
space:
mode:
authorRobert Griesemer <gri@golang.org>2017-03-21 15:22:13 -0700
committerRobert Griesemer <gri@golang.org>2017-03-22 22:36:37 +0000
commite0329248d5cda9a6a6c1492a2fdeeacd982afc9c (patch)
tree9907015e04ff016f1d78588ce2521b1ac925b710 /src/cmd/compile/internal/syntax/nodes.go
parentec512340148f80aa0be3da90f86043ff535c4081 (diff)
downloadgo-e0329248d5cda9a6a6c1492a2fdeeacd982afc9c.tar.gz
go-e0329248d5cda9a6a6c1492a2fdeeacd982afc9c.zip
cmd/compile/internal/syntax: add position info for { and } braces
This change adds position information for { and } braces in the source. There's a 1.9% increase in memory use for syntax.Nodes, which is negligible relative to overall compiler memory consumption. Parsing the std library (using syntax package only) and memory consumption before this change (fastest of 5 runs): $ go test -run StdLib -fast parsed 1516827 lines (3392 files) in 780.612335ms (1943124 lines/s) allocated 379.903Mb (486.673Mb/s) After this change (fastest of 5 runs): $ go test -run StdLib -fast parsed 1517022 lines (3394 files) in 793.487886ms (1911840 lines/s) allocated 387.086Mb (267B/line, 487.828Mb/s) While not an exact apples-to-apples comparison (the syntax package has changed and is also parsed), the overall impact is small. Also: Small improvements to nodes_test.go. Change-Id: Ib8a7f90bbe79de33d83684e33b1bf8dbc32e644a Reviewed-on: https://go-review.googlesource.com/38435 Reviewed-by: Matthew Dempsky <mdempsky@google.com>
Diffstat (limited to 'src/cmd/compile/internal/syntax/nodes.go')
-rw-r--r--src/cmd/compile/internal/syntax/nodes.go72
1 files changed, 38 insertions, 34 deletions
diff --git a/src/cmd/compile/internal/syntax/nodes.go b/src/cmd/compile/internal/syntax/nodes.go
index 0f7e8c2f17..a99cb008f2 100644
--- a/src/cmd/compile/internal/syntax/nodes.go
+++ b/src/cmd/compile/internal/syntax/nodes.go
@@ -28,11 +28,8 @@ type node struct {
pos src.Pos
}
-func (n *node) Pos() src.Pos {
- return n.pos
-}
-
-func (*node) aNode() {}
+func (n *node) Pos() src.Pos { return n.pos }
+func (*node) aNode() {}
// ----------------------------------------------------------------------------
// Files
@@ -100,13 +97,13 @@ type (
// func Receiver Name Type { Body }
// func Receiver Name 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)
- Pragma Pragma // TODO(mdempsky): Cleaner solution.
- Rbrace src.Pos // TODO(mdempsky): Cleaner solution.
+ 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)
+ Lbrace, Rbrace src.Pos
+ Pragma Pragma // TODO(mdempsky): Cleaner solution.
decl
}
)
@@ -144,10 +141,10 @@ type (
// Type { ElemList[0], ElemList[1], ... }
CompositeLit struct {
- Type Expr // nil means no literal type
- ElemList []Expr
- NKeys int // number of elements with keys
- Rbrace src.Pos // TODO(mdempsky): Cleaner solution.
+ Type Expr // nil means no literal type
+ ElemList []Expr
+ NKeys int // number of elements with keys
+ Lbrace, Rbrace src.Pos
expr
}
@@ -159,9 +156,9 @@ type (
// func Type { Body }
FuncLit struct {
- Type *FuncType
- Body []Stmt
- Rbrace src.Pos // TODO(mdempsky): Cleaner solution.
+ Type *FuncType
+ Body []Stmt
+ Lbrace, Rbrace src.Pos
expr
}
@@ -326,7 +323,8 @@ type (
}
BlockStmt struct {
- Body []Stmt
+ Body []Stmt
+ Rbrace src.Pos
stmt
}
@@ -369,30 +367,34 @@ type (
}
IfStmt struct {
- Init SimpleStmt
- Cond Expr
- Then []Stmt
- Else Stmt // either *IfStmt or *BlockStmt
+ Init SimpleStmt
+ Cond Expr
+ Then []Stmt
+ Lbrace, Rbrace src.Pos // of Then branch
+ Else Stmt // either *IfStmt or *BlockStmt
stmt
}
ForStmt struct {
- Init SimpleStmt // incl. *RangeClause
- Cond Expr
- Post SimpleStmt
- Body []Stmt
+ Init SimpleStmt // incl. *RangeClause
+ Cond Expr
+ Post SimpleStmt
+ Body []Stmt
+ Lbrace, Rbrace src.Pos
stmt
}
SwitchStmt struct {
- Init SimpleStmt
- Tag Expr
- Body []*CaseClause
+ Init SimpleStmt
+ Tag Expr
+ Body []*CaseClause
+ Rbrace src.Pos
stmt
}
SelectStmt struct {
- Body []*CommClause
+ Body []*CommClause
+ Rbrace src.Pos
stmt
}
)
@@ -415,12 +417,14 @@ type (
CaseClause struct {
Cases Expr // nil means default clause
Body []Stmt
+ Colon src.Pos
node
}
CommClause struct {
- Comm SimpleStmt // send or receive stmt; nil means default clause
- Body []Stmt
+ Comm SimpleStmt // send or receive stmt; nil means default clause
+ Body []Stmt
+ Colon src.Pos
node
}
)