aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRobert Griesemer <gri@golang.org>2016-06-08 17:45:16 -0700
committerMatthew Dempsky <mdempsky@google.com>2016-08-16 14:32:08 -0700
commit573afbcdb6bf11e1fc7ed176b07a04719c1e9a26 (patch)
tree0c910252b28e929ac9a16f85e595ab396961cb8f
parenta6a470105382b7d9082615ad94857647a5023166 (diff)
downloadgo-573afbcdb6bf11e1fc7ed176b07a04719c1e9a26.tar.gz
go-573afbcdb6bf11e1fc7ed176b07a04719c1e9a26.zip
cmd/compile/internal/syntax: export ImplicitOne and use to identify x++/x--
+ minor documentation improvements
-rw-r--r--src/cmd/compile/internal/syntax/nodes.go8
-rw-r--r--src/cmd/compile/internal/syntax/parser.go7
-rw-r--r--src/cmd/compile/internal/syntax/printer.go2
-rw-r--r--src/cmd/compile/internal/syntax/tokens.go8
4 files changed, 14 insertions, 11 deletions
diff --git a/src/cmd/compile/internal/syntax/nodes.go b/src/cmd/compile/internal/syntax/nodes.go
index f426a5ef47..de677a847a 100644
--- a/src/cmd/compile/internal/syntax/nodes.go
+++ b/src/cmd/compile/internal/syntax/nodes.go
@@ -317,24 +317,24 @@ type (
AssignStmt struct {
Op Operator // 0 means no operation
- Lhs, Rhs Expr
+ Lhs, Rhs Expr // Rhs == ImplicitOne means Lhs++ (Op == Add) or Lhs-- (Op == Sub)
simpleStmt
}
BranchStmt struct {
- Tok token // TODO(gri) token values are not yet exported
+ Tok token // Break, Continue, Fallthrough, or Goto
Label *Name
stmt
}
CallStmt struct {
- Tok token // _Go, or _Defer -- TODO(gri) token values are not yet exported
+ Tok token // Go or Defer
Call *CallExpr
stmt
}
ReturnStmt struct {
- Results Expr // nil means no (explicit) results
+ Results Expr // nil means no explicit return values
stmt
}
diff --git a/src/cmd/compile/internal/syntax/parser.go b/src/cmd/compile/internal/syntax/parser.go
index 6419998ff1..903a89c2ff 100644
--- a/src/cmd/compile/internal/syntax/parser.go
+++ b/src/cmd/compile/internal/syntax/parser.go
@@ -1367,8 +1367,9 @@ func (p *parser) paramList() (list []*Field) {
// ----------------------------------------------------------------------------
// Statements
-// We represent x++, x-- as assignments x += one, x -= one.
-var one = &BasicLit{Value: "1"}
+// 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 .
//
@@ -1403,7 +1404,7 @@ func (p *parser) simpleStmt(lhs Expr, rangeOk bool) SimpleStmt {
// lhs++ or lhs--
op := p.op
p.next()
- return p.newAssignStmt(op, lhs, one)
+ return p.newAssignStmt(op, lhs, ImplicitOne)
case _Arrow:
// lhs <- rhs
diff --git a/src/cmd/compile/internal/syntax/printer.go b/src/cmd/compile/internal/syntax/printer.go
index ce3377afc1..0cacf1e5d4 100644
--- a/src/cmd/compile/internal/syntax/printer.go
+++ b/src/cmd/compile/internal/syntax/printer.go
@@ -499,7 +499,7 @@ func (p *printer) printRawNode(n Node) {
case *AssignStmt:
p.print(n.Lhs)
- if n.Rhs == one {
+ if n.Rhs == ImplicitOne {
// 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/tokens.go b/src/cmd/compile/internal/syntax/tokens.go
index ed7a643a97..91a217655f 100644
--- a/src/cmd/compile/internal/syntax/tokens.go
+++ b/src/cmd/compile/internal/syntax/tokens.go
@@ -69,13 +69,15 @@ const (
)
const (
- Go = _Go
- Defer = _Defer
-
+ // for BranchStmt
Break = _Break
Continue = _Continue
Fallthrough = _Fallthrough
Goto = _Goto
+
+ // for CallStmt
+ Go = _Go
+ Defer = _Defer
)
var tokstrings = [...]string{