[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 <gri@golang.org>
This commit is contained in:
Robert Griesemer 2020-07-31 11:38:49 -07:00
parent 569c893c93
commit c77c3236b1
4 changed files with 5 additions and 70 deletions

View File

@ -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": "",

View File

@ -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

View File

@ -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 {

View File

@ -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)
}
}
}