aboutsummaryrefslogtreecommitdiff
path: root/src/cmd/compile/internal/syntax
diff options
context:
space:
mode:
authorRobert Griesemer <gri@golang.org>2021-01-20 17:03:36 -0800
committerRobert Griesemer <gri@golang.org>2021-01-21 06:55:47 +0000
commit18bd7aa62581f313c86164d763b1e246307888a9 (patch)
tree635a5e70ed41388129ac991812c06985e032fa00 /src/cmd/compile/internal/syntax
parent2427f6e6c07de20a00dd8b9ab464f0abe5ccd13a (diff)
downloadgo-18bd7aa62581f313c86164d763b1e246307888a9.tar.gz
go-18bd7aa62581f313c86164d763b1e246307888a9.zip
[dev.typeparams] cmd/compile: use nil instead of syntax.ImplicitOne
Represent x++/-- as x +=/-= with the RHS of the assignment being nil rather than syntax.ImplicitOne. Dependent code already had to check for syntax.ImplicitOne, but then shared some existing code for regular assignment operations. Now always handle this case fully explicit, which simplifies the code. Change-Id: I28c7918153c27cbbf97b041d0c85ff027c58687c Reviewed-on: https://go-review.googlesource.com/c/go/+/285172 Trust: Robert Griesemer <gri@golang.org> Reviewed-by: Matthew Dempsky <mdempsky@google.com>
Diffstat (limited to 'src/cmd/compile/internal/syntax')
-rw-r--r--src/cmd/compile/internal/syntax/nodes.go2
-rw-r--r--src/cmd/compile/internal/syntax/parser.go6
-rw-r--r--src/cmd/compile/internal/syntax/printer.go2
-rw-r--r--src/cmd/compile/internal/syntax/walk.go4
4 files changed, 6 insertions, 8 deletions
diff --git a/src/cmd/compile/internal/syntax/nodes.go b/src/cmd/compile/internal/syntax/nodes.go
index a06d6e85b1..fb9786daa3 100644
--- a/src/cmd/compile/internal/syntax/nodes.go
+++ b/src/cmd/compile/internal/syntax/nodes.go
@@ -367,7 +367,7 @@ type (
AssignStmt struct {
Op Operator // 0 means no operation
- Lhs, Rhs Expr // Rhs == ImplicitOne means Lhs++ (Op == Add) or Lhs-- (Op == Sub)
+ Lhs, Rhs Expr // Rhs == nil means Lhs++ (Op == Add) or Lhs-- (Op == Sub)
simpleStmt
}
diff --git a/src/cmd/compile/internal/syntax/parser.go b/src/cmd/compile/internal/syntax/parser.go
index e3fb1003a2..c4ccbb82cb 100644
--- a/src/cmd/compile/internal/syntax/parser.go
+++ b/src/cmd/compile/internal/syntax/parser.go
@@ -1874,10 +1874,6 @@ func (p *parser) badExpr() *BadExpr {
// ----------------------------------------------------------------------------
// Statements
-// We represent x++, x-- as assignments x += ImplicitOne, x -= ImplicitOne.
-// ImplicitOne should not be used elsewhere.
-var ImplicitOne = &BasicLit{Value: "1"}
-
// SimpleStmt = EmptyStmt | ExpressionStmt | SendStmt | IncDecStmt | Assignment | ShortVarDecl .
func (p *parser) simpleStmt(lhs Expr, keyword token) SimpleStmt {
if trace {
@@ -1910,7 +1906,7 @@ func (p *parser) simpleStmt(lhs Expr, keyword token) SimpleStmt {
// lhs++ or lhs--
op := p.op
p.next()
- return p.newAssignStmt(pos, op, lhs, ImplicitOne)
+ return p.newAssignStmt(pos, op, lhs, nil)
case _Arrow:
// lhs <- rhs
diff --git a/src/cmd/compile/internal/syntax/printer.go b/src/cmd/compile/internal/syntax/printer.go
index 161eb0d092..9109ce2363 100644
--- a/src/cmd/compile/internal/syntax/printer.go
+++ b/src/cmd/compile/internal/syntax/printer.go
@@ -549,7 +549,7 @@ func (p *printer) printRawNode(n Node) {
case *AssignStmt:
p.print(n.Lhs)
- if n.Rhs == ImplicitOne {
+ if n.Rhs == nil {
// TODO(gri) This is going to break the mayCombine
// check once we enable that again.
p.print(n.Op, n.Op) // ++ or --
diff --git a/src/cmd/compile/internal/syntax/walk.go b/src/cmd/compile/internal/syntax/walk.go
index 418b26d674..c26e97a0d8 100644
--- a/src/cmd/compile/internal/syntax/walk.go
+++ b/src/cmd/compile/internal/syntax/walk.go
@@ -207,7 +207,9 @@ func (w *walker) node(n Node) {
case *AssignStmt:
w.node(n.Lhs)
- w.node(n.Rhs)
+ if n.Rhs != nil {
+ w.node(n.Rhs)
+ }
case *BranchStmt:
if n.Label != nil {