aboutsummaryrefslogtreecommitdiff
path: root/src/cmd/compile/internal/noder/noder.go
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/noder/noder.go
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/noder/noder.go')
-rw-r--r--src/cmd/compile/internal/noder/noder.go16
1 files changed, 9 insertions, 7 deletions
diff --git a/src/cmd/compile/internal/noder/noder.go b/src/cmd/compile/internal/noder/noder.go
index 0c7d015977..e1ae2569e0 100644
--- a/src/cmd/compile/internal/noder/noder.go
+++ b/src/cmd/compile/internal/noder/noder.go
@@ -677,11 +677,7 @@ func (p *noder) expr(expr syntax.Expr) ir.Node {
case *syntax.Name:
return p.mkname(expr)
case *syntax.BasicLit:
- pos := base.Pos
- if expr != syntax.ImplicitOne { // ImplicitOne doesn't have a unique position
- pos = p.pos(expr)
- }
- n := ir.NewBasicLit(pos, p.basicLit(expr))
+ n := ir.NewBasicLit(p.pos(expr), p.basicLit(expr))
if expr.Kind == syntax.RuneLit {
n.SetType(types.UntypedRune)
}
@@ -1039,9 +1035,15 @@ func (p *noder) stmtFall(stmt syntax.Stmt, fallOK bool) ir.Node {
case *syntax.DeclStmt:
return ir.NewBlockStmt(src.NoXPos, p.decls(stmt.DeclList))
case *syntax.AssignStmt:
+ if stmt.Rhs == nil {
+ pos := p.pos(stmt)
+ n := ir.NewAssignOpStmt(pos, p.binOp(stmt.Op), p.expr(stmt.Lhs), ir.NewBasicLit(pos, one))
+ n.IncDec = true
+ return n
+ }
+
if stmt.Op != 0 && stmt.Op != syntax.Def {
n := ir.NewAssignOpStmt(p.pos(stmt), p.binOp(stmt.Op), p.expr(stmt.Lhs), p.expr(stmt.Rhs))
- n.IncDec = stmt.Rhs == syntax.ImplicitOne
return n
}
@@ -1502,7 +1504,7 @@ func (p *noder) wrapname(n syntax.Node, x ir.Node) ir.Node {
}
func (p *noder) setlineno(n syntax.Node) {
- if n != nil && n != syntax.ImplicitOne {
+ if n != nil {
base.Pos = p.pos(n)
}
}