From c77c3236b1d64e99db05059c2a7eed8a8623e3fd Mon Sep 17 00:00:00 2001 From: Robert Griesemer Date: Fri, 31 Jul 2020 11:38:49 -0700 Subject: [PATCH] [dev.go2go] cmd/compile/internal/types2: remove most token.Token dependencies The remaining uses of token.Token are needed for the go/constant API. Change-Id: I5dc8be1fae16217433da1acb5606fd1d7b8eea54 Reviewed-on: https://go-review.googlesource.com/c/go/+/246257 Reviewed-by: Robert Griesemer --- src/cmd/compile/fmtmap_test.go | 2 - src/cmd/compile/internal/types2/expr.go | 4 +- src/cmd/compile/internal/types2/stmt.go | 22 ++------- src/cmd/compile/internal/types2/token_test.go | 47 ------------------- 4 files changed, 5 insertions(+), 70 deletions(-) delete mode 100644 src/cmd/compile/internal/types2/token_test.go diff --git a/src/cmd/compile/fmtmap_test.go b/src/cmd/compile/fmtmap_test.go index 366cb5a7bc..3885f4ce17 100644 --- a/src/cmd/compile/fmtmap_test.go +++ b/src/cmd/compile/fmtmap_test.go @@ -181,8 +181,6 @@ var knownFormats = map[string]string{ "float64 %.6g": "", "float64 %g": "", "go/constant.Value %s": "", - "go/token.Token %d": "", - "go/token.Token %s": "", "int %#x": "", "int %-12d": "", "int %-6d": "", diff --git a/src/cmd/compile/internal/types2/expr.go b/src/cmd/compile/internal/types2/expr.go index c150cfb190..a6e46b9910 100644 --- a/src/cmd/compile/internal/types2/expr.go +++ b/src/cmd/compile/internal/types2/expr.go @@ -81,11 +81,11 @@ func (check *Checker) op(m opPredicates, x *operand, op syntax.Operator) bool { func op2token(op syntax.Operator) token.Token { switch op { case syntax.Def: // : - unimplemented() + unreachable() case syntax.Not: // ! return token.NOT case syntax.Recv: // <- - unimplemented() + unreachable() case syntax.OrOr: // || return token.LOR diff --git a/src/cmd/compile/internal/types2/stmt.go b/src/cmd/compile/internal/types2/stmt.go index 04145aae69..6f3a2a9216 100644 --- a/src/cmd/compile/internal/types2/stmt.go +++ b/src/cmd/compile/internal/types2/stmt.go @@ -9,7 +9,6 @@ package types2 import ( "cmd/compile/internal/syntax" "go/constant" - "go/token" "sort" ) @@ -164,14 +163,6 @@ func (check *Checker) closeScope() { check.scope = check.scope.Parent() } -func assignOp(op token.Token) token.Token { - // token_test.go verifies the token ordering this function relies on - if token.ADD_ASSIGN <= op && op <= token.AND_NOT_ASSIGN { - return op + (token.ADD - token.ADD_ASSIGN) - } - return token.ILLEGAL -} - func (check *Checker) suspendedCall(keyword string, call *syntax.CallExpr) { var x operand var msg string @@ -368,9 +359,8 @@ func (check *Checker) stmt(ctxt stmtContext, s syntax.Stmt) { case *syntax.AssignStmt: lhs := unpackExpr(s.Lhs) rhs := unpackExpr(s.Rhs) - switch s.Op { - // case token.ASSIGN, token.DEFINE: - case 0, syntax.Def: + if s.Op == 0 || s.Op == syntax.Def { + // regular assignment or short variable declaration if len(lhs) == 0 { check.invalidAST(s.Pos(), "missing lhs in assignment") return @@ -381,18 +371,12 @@ func (check *Checker) stmt(ctxt stmtContext, s syntax.Stmt) { // regular assignment check.assignVars(lhs, rhs) } - - default: + } else { // assignment operations if len(lhs) != 1 || len(rhs) != 1 { check.errorf(s.Pos(), "assignment operation %s requires single-valued expressions", s.Op) return } - // op := assignOp(s.Tok) - // if op == token.ILLEGAL { - // check.invalidAST(s.Pos(), "unknown assignment operation %s", s.Op) - // return - // } var x operand check.binary(&x, nil, lhs[0], rhs[0], s.Op) if x.mode == invalid { diff --git a/src/cmd/compile/internal/types2/token_test.go b/src/cmd/compile/internal/types2/token_test.go deleted file mode 100644 index 63afa6c6ff..0000000000 --- a/src/cmd/compile/internal/types2/token_test.go +++ /dev/null @@ -1,47 +0,0 @@ -// Copyright 2013 The Go Authors. All rights reserved. -// Use of this source code is governed by a BSD-style -// license that can be found in the LICENSE file. - -// This file checks invariants of token.Token ordering that we rely on -// since package go/token doesn't provide any guarantees at the moment. - -package types2 - -import ( - "go/token" - "testing" -) - -var assignOps = map[token.Token]token.Token{ - token.ADD_ASSIGN: token.ADD, - token.SUB_ASSIGN: token.SUB, - token.MUL_ASSIGN: token.MUL, - token.QUO_ASSIGN: token.QUO, - token.REM_ASSIGN: token.REM, - token.AND_ASSIGN: token.AND, - token.OR_ASSIGN: token.OR, - token.XOR_ASSIGN: token.XOR, - token.SHL_ASSIGN: token.SHL, - token.SHR_ASSIGN: token.SHR, - token.AND_NOT_ASSIGN: token.AND_NOT, -} - -func TestZeroTok(t *testing.T) { - // zero value for token.Token must be token.ILLEGAL - var zero token.Token - if token.ILLEGAL != zero { - t.Errorf("%s == %d; want 0", token.ILLEGAL, zero) - } -} - -func TestAssignOp(t *testing.T) { - // there are fewer than 256 tokens - for i := 0; i < 256; i++ { - tok := token.Token(i) - got := assignOp(tok) - want := assignOps[tok] - if got != want { - t.Errorf("for assignOp(%s): got %s; want %s", tok, got, want) - } - } -}