mirror of
https://github.com/ddidderr/wuffs.git
synced 2026-11-22 16:47:28 +01:00
Rename some ast.Expr methods
This commit is contained in:
1 parent
ed03c5943a
commit
8b4ba30a36
12 files changed
+140
-140
No files matched your search
@@ -27,7 +27,7 @@ import (
|
||||
// binary-op expression like "thisHS == thatHS" or "thatHS < thisHS" (which is
|
||||
// equivalent to "thisHS > thatHS"). If not, it returns (0, nil).
|
||||
func otherHandSide(n *a.Expr, thisHS *a.Expr) (op t.ID, thatHS *a.Expr) {
|
||||
op = n.ID0()
|
||||
op = n.Operator()
|
||||
|
||||
reverseOp := t.ID(0)
|
||||
switch op.Key() {
|
||||
@@ -66,7 +66,7 @@ func (z *facts) appendFact(fact *a.Expr) {
|
||||
}
|
||||
}
|
||||
|
||||
switch fact.ID0().Key() {
|
||||
switch fact.Operator().Key() {
|
||||
case 0:
|
||||
for _, x := range *z {
|
||||
if op, other := otherHandSide(x, fact); op.Key() == t.KeyXBinaryEqEq {
|
||||
@@ -239,10 +239,10 @@ func argValue(tm *t.Map, args []*a.Node, name string) *a.Expr {
|
||||
|
||||
// parseBinaryOp parses n as "lhs op rhs".
|
||||
func parseBinaryOp(n *a.Expr) (op t.ID, lhs *a.Expr, rhs *a.Expr) {
|
||||
if !n.ID0().IsBinaryOp() {
|
||||
if !n.Operator().IsBinaryOp() {
|
||||
return 0, nil, nil
|
||||
}
|
||||
op = n.ID0()
|
||||
op = n.Operator()
|
||||
if op.Key() == t.KeyAs {
|
||||
return 0, nil, nil
|
||||
}
|
||||
@@ -293,7 +293,7 @@ func (q *checker) proveBinaryOp(op t.Key, lhs *a.Expr, rhs *a.Expr) error {
|
||||
if !x.LHS().Expr().Eq(lhs) {
|
||||
continue
|
||||
}
|
||||
factOp := x.ID0().Key()
|
||||
factOp := x.Operator().Key()
|
||||
if opImpliesOp(factOp, op) && x.RHS().Expr().Eq(rhs) {
|
||||
return nil
|
||||
}
|
||||
|
||||
+32
-32
@@ -115,22 +115,22 @@ func invert(tm *t.Map, n *a.Expr) (*a.Expr, error) {
|
||||
if cv := n.ConstValue(); cv != nil {
|
||||
return nil, fmt.Errorf("check: invert(%q) called on constant expression", n.Str(tm))
|
||||
}
|
||||
id0, lhs, rhs, args := n.ID0(), n.LHS().Expr(), n.RHS().Expr(), []*a.Node(nil)
|
||||
switch id0.Key() {
|
||||
op, lhs, rhs, args := n.Operator(), n.LHS().Expr(), n.RHS().Expr(), []*a.Node(nil)
|
||||
switch op.Key() {
|
||||
case t.KeyXUnaryNot:
|
||||
return rhs, nil
|
||||
case t.KeyXBinaryNotEq:
|
||||
id0 = t.IDXBinaryEqEq
|
||||
op = t.IDXBinaryEqEq
|
||||
case t.KeyXBinaryLessThan:
|
||||
id0 = t.IDXBinaryGreaterEq
|
||||
op = t.IDXBinaryGreaterEq
|
||||
case t.KeyXBinaryLessEq:
|
||||
id0 = t.IDXBinaryGreaterThan
|
||||
op = t.IDXBinaryGreaterThan
|
||||
case t.KeyXBinaryEqEq:
|
||||
id0 = t.IDXBinaryNotEq
|
||||
op = t.IDXBinaryNotEq
|
||||
case t.KeyXBinaryGreaterEq:
|
||||
id0 = t.IDXBinaryLessThan
|
||||
op = t.IDXBinaryLessThan
|
||||
case t.KeyXBinaryGreaterThan:
|
||||
id0 = t.IDXBinaryLessEq
|
||||
op = t.IDXBinaryLessEq
|
||||
case t.KeyXBinaryAnd, t.KeyXBinaryOr:
|
||||
var err error
|
||||
lhs, err = invert(tm, lhs)
|
||||
@@ -141,10 +141,10 @@ func invert(tm *t.Map, n *a.Expr) (*a.Expr, error) {
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if id0.Key() == t.KeyXBinaryAnd {
|
||||
id0 = t.IDXBinaryOr
|
||||
if op.Key() == t.KeyXBinaryAnd {
|
||||
op = t.IDXBinaryOr
|
||||
} else {
|
||||
id0 = t.IDXBinaryAnd
|
||||
op = t.IDXBinaryAnd
|
||||
}
|
||||
case t.KeyXAssociativeAnd, t.KeyXAssociativeOr:
|
||||
args = make([]*a.Node, 0, len(n.Args()))
|
||||
@@ -155,15 +155,15 @@ func invert(tm *t.Map, n *a.Expr) (*a.Expr, error) {
|
||||
}
|
||||
args = append(args, v.Node())
|
||||
}
|
||||
if id0.Key() == t.KeyXAssociativeAnd {
|
||||
id0 = t.IDXAssociativeOr
|
||||
if op.Key() == t.KeyXAssociativeAnd {
|
||||
op = t.IDXAssociativeOr
|
||||
} else {
|
||||
id0 = t.IDXAssociativeAnd
|
||||
op = t.IDXAssociativeAnd
|
||||
}
|
||||
default:
|
||||
id0, lhs, rhs = t.IDXUnaryNot, nil, n
|
||||
op, lhs, rhs = t.IDXUnaryNot, nil, n
|
||||
}
|
||||
o := a.NewExpr(n.Node().Raw().Flags(), id0, 0, lhs.Node(), nil, rhs.Node(), args)
|
||||
o := a.NewExpr(n.Node().Raw().Flags(), op, 0, lhs.Node(), nil, rhs.Node(), args)
|
||||
o.SetMType(n.MType())
|
||||
return o, nil
|
||||
}
|
||||
@@ -349,8 +349,8 @@ func (q *checker) bcheckAssert(n *a.Assert) error {
|
||||
} else {
|
||||
err = fmt.Errorf("no such reason %s", reasonID.Str(q.tm))
|
||||
}
|
||||
} else if condition.ID0().IsBinaryOp() && condition.ID0().Key() != t.KeyAs {
|
||||
err = q.proveBinaryOp(condition.ID0().Key(), condition.LHS().Expr(), condition.RHS().Expr())
|
||||
} else if condition.Operator().IsBinaryOp() && condition.Operator().Key() != t.KeyAs {
|
||||
err = q.proveBinaryOp(condition.Operator().Key(), condition.LHS().Expr(), condition.RHS().Expr())
|
||||
}
|
||||
|
||||
if err != nil {
|
||||
@@ -755,24 +755,24 @@ func (q *checker) bcheckExpr1(n *a.Expr, depth uint32) (*big.Int, *big.Int, erro
|
||||
if cv := n.ConstValue(); cv != nil {
|
||||
return cv, cv, nil
|
||||
}
|
||||
switch n.ID0().Flags() & (t.FlagsUnaryOp | t.FlagsBinaryOp | t.FlagsAssociativeOp) {
|
||||
switch n.Operator().Flags() & (t.FlagsUnaryOp | t.FlagsBinaryOp | t.FlagsAssociativeOp) {
|
||||
case 0:
|
||||
return q.bcheckExprOther(n, depth)
|
||||
case t.FlagsUnaryOp:
|
||||
return q.bcheckExprUnaryOp(n, depth)
|
||||
case t.FlagsBinaryOp:
|
||||
if n.ID0().Key() == t.KeyXBinaryAs {
|
||||
if n.Operator().Key() == t.KeyXBinaryAs {
|
||||
return q.bcheckExpr(n.LHS().Expr(), depth)
|
||||
}
|
||||
return q.bcheckExprBinaryOp(n.ID0().Key(), n.LHS().Expr(), n.RHS().Expr(), depth)
|
||||
return q.bcheckExprBinaryOp(n.Operator().Key(), n.LHS().Expr(), n.RHS().Expr(), depth)
|
||||
case t.FlagsAssociativeOp:
|
||||
return q.bcheckExprAssociativeOp(n, depth)
|
||||
}
|
||||
return nil, nil, fmt.Errorf("check: unrecognized token.Key (0x%X) for bcheckExpr", n.ID0().Key())
|
||||
return nil, nil, fmt.Errorf("check: unrecognized token.Key (0x%X) for bcheckExpr", n.Operator().Key())
|
||||
}
|
||||
|
||||
func (q *checker) bcheckExprOther(n *a.Expr, depth uint32) (*big.Int, *big.Int, error) {
|
||||
switch n.ID0().Key() {
|
||||
switch n.Operator().Key() {
|
||||
case 0:
|
||||
// No-op.
|
||||
|
||||
@@ -933,16 +933,16 @@ func (q *checker) bcheckExprOther(n *a.Expr, depth uint32) (*big.Int, *big.Int,
|
||||
|
||||
case t.KeyDot:
|
||||
// TODO: delete this hack that only matches "in".
|
||||
if n.LHS().Expr().ID1().Key() == t.KeyIn {
|
||||
if n.LHS().Expr().Ident().Key() == t.KeyIn {
|
||||
for _, o := range q.f.Func.In().Fields() {
|
||||
o := o.Field()
|
||||
if o.Name() == n.ID1() {
|
||||
if o.Name() == n.Ident() {
|
||||
return q.bcheckTypeExpr(o.XType())
|
||||
}
|
||||
}
|
||||
lTyp := n.LHS().Expr().MType()
|
||||
return nil, nil, fmt.Errorf("check: no field named %q found in struct type %q for expression %q",
|
||||
n.ID1().Str(q.tm), lTyp.QID().Str(q.tm), n.Str(q.tm))
|
||||
n.Ident().Str(q.tm), lTyp.QID().Str(q.tm), n.Str(q.tm))
|
||||
}
|
||||
|
||||
if _, _, err := q.bcheckExpr(n.LHS().Expr(), depth); err != nil {
|
||||
@@ -953,7 +953,7 @@ func (q *checker) bcheckExprOther(n *a.Expr, depth uint32) (*big.Int, *big.Int,
|
||||
// No-op.
|
||||
|
||||
default:
|
||||
return nil, nil, fmt.Errorf("check: unrecognized token.Key (0x%X) for bcheckExprOther", n.ID0().Key())
|
||||
return nil, nil, fmt.Errorf("check: unrecognized token.Key (0x%X) for bcheckExprOther", n.Operator().Key())
|
||||
}
|
||||
return q.bcheckTypeExpr(n.MType())
|
||||
}
|
||||
@@ -990,7 +990,7 @@ func (q *checker) bcheckExprUnaryOp(n *a.Expr, depth uint32) (*big.Int, *big.Int
|
||||
return nil, nil, err
|
||||
}
|
||||
|
||||
switch n.ID0().Key() {
|
||||
switch n.Operator().Key() {
|
||||
case t.KeyXUnaryPlus:
|
||||
return rMin, rMax, nil
|
||||
case t.KeyXUnaryMinus:
|
||||
@@ -1001,7 +1001,7 @@ func (q *checker) bcheckExprUnaryOp(n *a.Expr, depth uint32) (*big.Int, *big.Int
|
||||
return q.bcheckTypeExpr(n.MType())
|
||||
}
|
||||
|
||||
return nil, nil, fmt.Errorf("check: unrecognized token.Key (0x%X) for bcheckExprUnaryOp", n.ID0().Key())
|
||||
return nil, nil, fmt.Errorf("check: unrecognized token.Key (0x%X) for bcheckExprUnaryOp", n.Operator().Key())
|
||||
}
|
||||
|
||||
func (q *checker) bcheckExprBinaryOp(op t.Key, lhs *a.Expr, rhs *a.Expr, depth uint32) (*big.Int, *big.Int, error) {
|
||||
@@ -1146,10 +1146,10 @@ func (q *checker) bcheckExprBinaryOp1(op t.Key, lhs *a.Expr, lMin *big.Int, lMax
|
||||
}
|
||||
|
||||
func (q *checker) bcheckExprAssociativeOp(n *a.Expr, depth uint32) (*big.Int, *big.Int, error) {
|
||||
op := n.ID0().AmbiguousForm().BinaryForm().Key()
|
||||
op := n.Operator().AmbiguousForm().BinaryForm().Key()
|
||||
if op == 0 {
|
||||
return nil, nil, fmt.Errorf(
|
||||
"check: unrecognized token.Key (0x%X) for bcheckExprAssociativeOp", n.ID0().Key())
|
||||
"check: unrecognized token.Key (0x%X) for bcheckExprAssociativeOp", n.Operator().Key())
|
||||
}
|
||||
args := n.Args()
|
||||
if len(args) < 1 {
|
||||
@@ -1163,7 +1163,7 @@ func (q *checker) bcheckExprAssociativeOp(n *a.Expr, depth uint32) (*big.Int, *b
|
||||
if i == 0 {
|
||||
continue
|
||||
}
|
||||
lhs := a.NewExpr(n.Node().Raw().Flags(), n.ID0(), n.ID1(), n.LHS(), n.MHS(), n.RHS(), args[:i])
|
||||
lhs := a.NewExpr(n.Node().Raw().Flags(), n.Operator(), n.Ident(), n.LHS(), n.MHS(), n.RHS(), args[:i])
|
||||
lMin, lMax, err = q.bcheckExprBinaryOp1(op, lhs, lMin, lMax, o.Expr(), depth)
|
||||
if err != nil {
|
||||
return nil, nil, err
|
||||
|
||||
+1
-1
@@ -375,7 +375,7 @@ func (c *Checker) checkConst(node *a.Node) error {
|
||||
func (c *Checker) checkConstElement(n *a.Expr, nMin *big.Int, nMax *big.Int, nLists int) error {
|
||||
if nLists > 0 {
|
||||
nLists--
|
||||
if n.ID0().Key() != t.KeyDollar {
|
||||
if n.Operator().Key() != t.KeyDollar {
|
||||
return fmt.Errorf("invalid const value %q", n.Str(c.tm))
|
||||
}
|
||||
for _, o := range n.Args() {
|
||||
|
||||
+11
-11
@@ -34,15 +34,15 @@ import (
|
||||
// splitReceiverMethodArgs returns the "receiver", "method" and "args" in the
|
||||
// expression "receiver.method(args)".
|
||||
func splitReceiverMethodArgs(n *a.Expr) (receiver *a.Expr, method t.Key, args []*a.Node) {
|
||||
if n.ID0().Key() != t.KeyOpenParen {
|
||||
if n.Operator().Key() != t.KeyOpenParen {
|
||||
return nil, 0, nil
|
||||
}
|
||||
args = n.Args()
|
||||
n = n.LHS().Expr()
|
||||
if n.ID0().Key() != t.KeyDot {
|
||||
if n.Operator().Key() != t.KeyDot {
|
||||
return nil, 0, nil
|
||||
}
|
||||
return n.LHS().Expr(), n.ID1().Key(), args
|
||||
return n.LHS().Expr(), n.Ident().Key(), args
|
||||
}
|
||||
|
||||
// TODO: should optimizeNonSuspendible be optimizeExpr and check both
|
||||
@@ -113,7 +113,7 @@ check0:
|
||||
check1:
|
||||
for {
|
||||
for _, x := range q.facts {
|
||||
if x.ID0().Key() != t.KeyXBinaryGreaterThan {
|
||||
if x.Operator().Key() != t.KeyXBinaryGreaterThan {
|
||||
continue
|
||||
}
|
||||
if lhs := x.LHS().Expr(); !lhs.Eq(d) {
|
||||
@@ -131,13 +131,13 @@ check1:
|
||||
check2:
|
||||
for {
|
||||
for _, x := range q.facts {
|
||||
if x.ID0().Key() != t.KeyXBinaryLessEq {
|
||||
if x.Operator().Key() != t.KeyXBinaryLessEq {
|
||||
continue
|
||||
}
|
||||
|
||||
// Check that the LHS is "d as u64".
|
||||
lhs := x.LHS().Expr()
|
||||
if lhs.ID0().Key() != t.KeyXBinaryAs {
|
||||
if lhs.Operator().Key() != t.KeyXBinaryAs {
|
||||
continue
|
||||
}
|
||||
llhs, lrhs := lhs.LHS().Expr(), lhs.RHS().TypeExpr()
|
||||
@@ -167,13 +167,13 @@ check2:
|
||||
check3:
|
||||
for {
|
||||
for _, x := range q.facts {
|
||||
if x.ID0().Key() != t.KeyXBinaryLessEq {
|
||||
if x.Operator().Key() != t.KeyXBinaryLessEq {
|
||||
continue
|
||||
}
|
||||
|
||||
// Check that the LHS is "l as u64".
|
||||
lhs := x.LHS().Expr()
|
||||
if lhs.ID0().Key() != t.KeyXBinaryAs {
|
||||
if lhs.Operator().Key() != t.KeyXBinaryAs {
|
||||
continue
|
||||
}
|
||||
llhs, lrhs := lhs.LHS().Expr(), lhs.RHS().TypeExpr()
|
||||
@@ -247,7 +247,7 @@ func (q *checker) optimizeSuspendible(n *a.Expr, depth uint32) error {
|
||||
|
||||
func (q *checker) optimizeIOMethodAdvance(n *a.Expr, receiver *a.Expr, advance *big.Int) error {
|
||||
return q.facts.update(func(x *a.Expr) (*a.Expr, error) {
|
||||
op := x.ID0().Key()
|
||||
op := x.Operator().Key()
|
||||
if op != t.KeyXBinaryGreaterEq && op != t.KeyXBinaryGreaterThan {
|
||||
return x, nil
|
||||
}
|
||||
@@ -259,11 +259,11 @@ func (q *checker) optimizeIOMethodAdvance(n *a.Expr, receiver *a.Expr, advance *
|
||||
|
||||
// Check that lhs is "receiver.available()".
|
||||
lhs := x.LHS().Expr()
|
||||
if lhs.ID0().Key() != t.KeyOpenParen || len(lhs.Args()) != 0 {
|
||||
if lhs.Operator().Key() != t.KeyOpenParen || len(lhs.Args()) != 0 {
|
||||
return x, nil
|
||||
}
|
||||
lhs = lhs.LHS().Expr()
|
||||
if lhs.ID0().Key() != t.KeyDot || lhs.ID1().Key() != t.KeyAvailable {
|
||||
if lhs.Operator().Key() != t.KeyDot || lhs.Ident().Key() != t.KeyAvailable {
|
||||
return x, nil
|
||||
}
|
||||
lhs = lhs.LHS().Expr()
|
||||
|
||||
+43
-43
@@ -349,7 +349,7 @@ func (q *checker) tcheckExpr(n *a.Expr, depth uint32) error {
|
||||
}
|
||||
depth++
|
||||
|
||||
switch n.ID0().Flags() & (t.FlagsUnaryOp | t.FlagsBinaryOp | t.FlagsAssociativeOp) {
|
||||
switch n.Operator().Flags() & (t.FlagsUnaryOp | t.FlagsBinaryOp | t.FlagsAssociativeOp) {
|
||||
case 0:
|
||||
if err := q.tcheckExprOther(n, depth); err != nil {
|
||||
return err
|
||||
@@ -367,16 +367,16 @@ func (q *checker) tcheckExpr(n *a.Expr, depth uint32) error {
|
||||
return err
|
||||
}
|
||||
default:
|
||||
return fmt.Errorf("check: unrecognized token.Key (0x%X) for tcheckExpr", n.ID0().Key())
|
||||
return fmt.Errorf("check: unrecognized token.Key (0x%X) for tcheckExpr", n.Operator().Key())
|
||||
}
|
||||
n.Node().SetTypeChecked()
|
||||
return nil
|
||||
}
|
||||
|
||||
func (q *checker) tcheckExprOther(n *a.Expr, depth uint32) error {
|
||||
switch n.ID0().Key() {
|
||||
switch n.Operator().Key() {
|
||||
case 0:
|
||||
id1 := n.ID1()
|
||||
id1 := n.Ident()
|
||||
if id1.IsNumLiteral() {
|
||||
z := big.NewInt(0)
|
||||
s := id1.Str(q.tm)
|
||||
@@ -443,7 +443,7 @@ func (q *checker) tcheckExprOther(n *a.Expr, depth uint32) error {
|
||||
return err
|
||||
}
|
||||
}
|
||||
if n.ID0().Key() == t.KeyTry {
|
||||
if n.Operator().Key() == t.KeyTry {
|
||||
// TODO: be more principled about inferring "try etc"'s type.
|
||||
n.SetMType(typeExprStatus)
|
||||
} else {
|
||||
@@ -521,12 +521,12 @@ func (q *checker) tcheckExprOther(n *a.Expr, depth uint32) error {
|
||||
return q.tcheckDot(n, depth)
|
||||
|
||||
case t.KeyError, t.KeyStatus, t.KeySuspension:
|
||||
nominalKeyword := n.ID0()
|
||||
nominalKeyword := n.Operator()
|
||||
declaredKeyword := t.ID(0)
|
||||
if s, ok := q.c.statuses[t.QID{0, n.ID1()}]; ok {
|
||||
if s, ok := q.c.statuses[t.QID{0, n.Ident()}]; ok {
|
||||
declaredKeyword = s.Status.Keyword()
|
||||
} else {
|
||||
msg, _ := t.Unescape(n.ID1().Str(q.tm))
|
||||
msg, _ := t.Unescape(n.Ident().Str(q.tm))
|
||||
z, ok := builtin.StatusMap[msg]
|
||||
if !ok {
|
||||
return fmt.Errorf("check: no error or status with message %q", msg)
|
||||
@@ -552,7 +552,7 @@ func (q *checker) tcheckExprOther(n *a.Expr, depth uint32) error {
|
||||
}
|
||||
|
||||
return fmt.Errorf("check: unrecognized token.Key (0x%X) in expression %q for tcheckExprOther",
|
||||
n.ID0().Key(), n.Str(q.tm))
|
||||
n.Operator().Key(), n.Str(q.tm))
|
||||
}
|
||||
|
||||
func (q *checker) tcheckExprCall(n *a.Expr, depth uint32) error {
|
||||
@@ -588,7 +588,7 @@ func (q *checker) tcheckExprCall(n *a.Expr, depth uint32) error {
|
||||
//
|
||||
// TODO: figure out calls with and without "?" should interact with the out
|
||||
// type.
|
||||
if n.ID0().Key() == t.KeyTry {
|
||||
if n.Operator().Key() == t.KeyTry {
|
||||
n.SetMType(typeExprStatus)
|
||||
} else {
|
||||
outFields := f.Out().Fields()
|
||||
@@ -616,19 +616,19 @@ func isInSrc(tm *t.Map, n *a.Expr, methodName t.Key, nArgs int) bool {
|
||||
callSuspendible := methodName != t.KeySinceMark &&
|
||||
methodName != t.KeyMark &&
|
||||
methodName != t.KeyLimit
|
||||
if n.ID0().Key() != t.KeyOpenParen || n.CallSuspendible() != callSuspendible || len(n.Args()) != nArgs {
|
||||
if n.Operator().Key() != t.KeyOpenParen || n.CallSuspendible() != callSuspendible || len(n.Args()) != nArgs {
|
||||
return false
|
||||
}
|
||||
n = n.LHS().Expr()
|
||||
if n.ID0().Key() != t.KeyDot || n.ID1().Key() != methodName {
|
||||
if n.Operator().Key() != t.KeyDot || n.Ident().Key() != methodName {
|
||||
return false
|
||||
}
|
||||
n = n.LHS().Expr()
|
||||
if n.ID0().Key() != t.KeyDot || n.ID1() != tm.ByName("src") {
|
||||
if n.Operator().Key() != t.KeyDot || n.Ident() != tm.ByName("src") {
|
||||
return false
|
||||
}
|
||||
n = n.LHS().Expr()
|
||||
return n.ID0() == 0 && n.ID1().Key() == t.KeyIn
|
||||
return n.Operator() == 0 && n.Ident().Key() == t.KeyIn
|
||||
}
|
||||
|
||||
func isInDst(tm *t.Map, n *a.Expr, methodName t.Key, nArgs int) bool {
|
||||
@@ -641,36 +641,36 @@ func isInDst(tm *t.Map, n *a.Expr, methodName t.Key, nArgs int) bool {
|
||||
methodName != t.KeyMark &&
|
||||
methodName != t.KeyLimit
|
||||
// TODO: check that n.Args() is "(x:bar)".
|
||||
if n.ID0().Key() != t.KeyOpenParen || n.CallSuspendible() != callSuspendible || len(n.Args()) != nArgs {
|
||||
if n.Operator().Key() != t.KeyOpenParen || n.CallSuspendible() != callSuspendible || len(n.Args()) != nArgs {
|
||||
return false
|
||||
}
|
||||
n = n.LHS().Expr()
|
||||
if n.ID0().Key() != t.KeyDot || n.ID1().Key() != methodName {
|
||||
if n.Operator().Key() != t.KeyDot || n.Ident().Key() != methodName {
|
||||
return false
|
||||
}
|
||||
n = n.LHS().Expr()
|
||||
if n.ID0().Key() != t.KeyDot || n.ID1() != tm.ByName("dst") {
|
||||
if n.Operator().Key() != t.KeyDot || n.Ident() != tm.ByName("dst") {
|
||||
return false
|
||||
}
|
||||
n = n.LHS().Expr()
|
||||
return n.ID0() == 0 && n.ID1().Key() == t.KeyIn
|
||||
return n.Operator() == 0 && n.Ident().Key() == t.KeyIn
|
||||
}
|
||||
|
||||
// isThatMethod matches foo.methodName(etc) where etc has nArgs elements.
|
||||
func isThatMethod(tm *t.Map, n *a.Expr, methodName t.Key, nArgs int) bool {
|
||||
if k := n.ID0().Key(); k != t.KeyOpenParen && k != t.KeyTry {
|
||||
if k := n.Operator().Key(); k != t.KeyOpenParen && k != t.KeyTry {
|
||||
return false
|
||||
}
|
||||
if len(n.Args()) != nArgs {
|
||||
return false
|
||||
}
|
||||
n = n.LHS().Expr()
|
||||
if n.ID0().Key() != t.KeyDot || n.ID1().Key() != methodName {
|
||||
if n.Operator().Key() != t.KeyDot || n.Ident().Key() != methodName {
|
||||
return false
|
||||
}
|
||||
n = n.LHS().Expr()
|
||||
if n.ID0().Key() == t.KeyDot &&
|
||||
(n.ID1() == tm.ByName("src") || n.ID1() == tm.ByName("dst")) {
|
||||
if n.Operator().Key() == t.KeyDot &&
|
||||
(n.Ident() == tm.ByName("src") || n.Ident() == tm.ByName("dst")) {
|
||||
return false
|
||||
}
|
||||
return true
|
||||
@@ -683,7 +683,7 @@ func (q *checker) tcheckDot(n *a.Expr, depth uint32) error {
|
||||
}
|
||||
lTyp := lhs.MType().Pointee()
|
||||
lQID := lTyp.QID()
|
||||
qqid := t.QQID{lQID[0], lQID[1], n.ID1()}
|
||||
qqid := t.QQID{lQID[0], lQID[1], n.Ident()}
|
||||
|
||||
if key := lTyp.Decorator().Key(); key == t.KeyColon {
|
||||
// lTyp is a slice.
|
||||
@@ -692,9 +692,9 @@ func (q *checker) tcheckDot(n *a.Expr, depth uint32) error {
|
||||
if f, err := q.c.builtInSliceFunc(qqid); err != nil {
|
||||
return err
|
||||
} else if f == nil {
|
||||
return fmt.Errorf("check: no slice method %q", n.ID1().Str(q.tm))
|
||||
return fmt.Errorf("check: no slice method %q", n.Ident().Str(q.tm))
|
||||
}
|
||||
n.SetMType(a.NewTypeExpr(t.IDOpenParen, 0, n.ID1(), lTyp.Node(), nil, nil))
|
||||
n.SetMType(a.NewTypeExpr(t.IDOpenParen, 0, n.Ident(), lTyp.Node(), nil, nil))
|
||||
return nil
|
||||
} else if key != 0 {
|
||||
return fmt.Errorf("check: invalid type %q for dot-expression LHS %q", lTyp.Str(q.tm), lhs.Str(q.tm))
|
||||
@@ -707,9 +707,9 @@ func (q *checker) tcheckDot(n *a.Expr, depth uint32) error {
|
||||
qqid[0].Str(q.tm), lTyp.Str(q.tm), lhs.Str(q.tm))
|
||||
} else if u.funcs[qqid] == nil {
|
||||
return fmt.Errorf("check: no method named %q found in type %q for expression %q",
|
||||
n.ID1().Str(q.tm), lTyp.Str(q.tm), n.Str(q.tm))
|
||||
n.Ident().Str(q.tm), lTyp.Str(q.tm), n.Str(q.tm))
|
||||
}
|
||||
n.SetMType(a.NewTypeExpr(t.IDOpenParen, 0, n.ID1(), lTyp.Node(), nil, nil))
|
||||
n.SetMType(a.NewTypeExpr(t.IDOpenParen, 0, n.Ident(), lTyp.Node(), nil, nil))
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -720,7 +720,7 @@ func (q *checker) tcheckDot(n *a.Expr, depth uint32) error {
|
||||
f = q.c.funcs[qqid].Func
|
||||
}
|
||||
if f != nil {
|
||||
n.SetMType(a.NewTypeExpr(t.IDOpenParen, 0, n.ID1(), lTyp.Node(), nil, nil))
|
||||
n.SetMType(a.NewTypeExpr(t.IDOpenParen, 0, n.Ident(), lTyp.Node(), nil, nil))
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -743,7 +743,7 @@ func (q *checker) tcheckDot(n *a.Expr, depth uint32) error {
|
||||
if s != nil {
|
||||
for _, field := range s.Fields() {
|
||||
f := field.Field()
|
||||
if f.Name() == n.ID1() {
|
||||
if f.Name() == n.Ident() {
|
||||
n.SetMType(f.XType())
|
||||
return nil
|
||||
}
|
||||
@@ -751,7 +751,7 @@ func (q *checker) tcheckDot(n *a.Expr, depth uint32) error {
|
||||
}
|
||||
|
||||
return fmt.Errorf("check: no field or method named %q found in type %q for expression %q",
|
||||
n.ID1().Str(q.tm), lTyp.Str(q.tm), n.Str(q.tm))
|
||||
n.Ident().Str(q.tm), lTyp.Str(q.tm), n.Str(q.tm))
|
||||
}
|
||||
|
||||
func (q *checker) tcheckExprUnaryOp(n *a.Expr, depth uint32) error {
|
||||
@@ -761,14 +761,14 @@ func (q *checker) tcheckExprUnaryOp(n *a.Expr, depth uint32) error {
|
||||
}
|
||||
rTyp := rhs.MType()
|
||||
|
||||
switch n.ID0().Key() {
|
||||
switch n.Operator().Key() {
|
||||
case t.KeyXUnaryPlus, t.KeyXUnaryMinus:
|
||||
if !rTyp.IsNumTypeOrIdeal() {
|
||||
return fmt.Errorf("check: unary %q: %q, of type %q, does not have a numeric type",
|
||||
n.ID0().AmbiguousForm().Str(q.tm), rhs.Str(q.tm), rTyp.Str(q.tm))
|
||||
n.Operator().AmbiguousForm().Str(q.tm), rhs.Str(q.tm), rTyp.Str(q.tm))
|
||||
}
|
||||
if cv := rhs.ConstValue(); cv != nil {
|
||||
if n.ID0().Key() == t.KeyXUnaryMinus {
|
||||
if n.Operator().Key() == t.KeyXUnaryMinus {
|
||||
cv = neg(cv)
|
||||
}
|
||||
n.SetConstValue(cv)
|
||||
@@ -779,7 +779,7 @@ func (q *checker) tcheckExprUnaryOp(n *a.Expr, depth uint32) error {
|
||||
case t.KeyXUnaryNot:
|
||||
if !rTyp.IsBool() {
|
||||
return fmt.Errorf("check: unary %q: %q, of type %q, does not have a boolean type",
|
||||
n.ID0().AmbiguousForm().Str(q.tm), rhs.Str(q.tm), rTyp.Str(q.tm))
|
||||
n.Operator().AmbiguousForm().Str(q.tm), rhs.Str(q.tm), rTyp.Str(q.tm))
|
||||
}
|
||||
if cv := rhs.ConstValue(); cv != nil {
|
||||
n.SetConstValue(btoi(cv.Cmp(zero) == 0))
|
||||
@@ -798,7 +798,7 @@ func (q *checker) tcheckExprUnaryOp(n *a.Expr, depth uint32) error {
|
||||
n.SetMType(rTyp.Inner())
|
||||
return nil
|
||||
}
|
||||
return fmt.Errorf("check: unrecognized token.Key (0x%X) for tcheckExprUnaryOp", n.ID0().Key())
|
||||
return fmt.Errorf("check: unrecognized token.Key (0x%X) for tcheckExprUnaryOp", n.Operator().Key())
|
||||
}
|
||||
|
||||
func (q *checker) tcheckExprBinaryOp(n *a.Expr, depth uint32) error {
|
||||
@@ -807,7 +807,7 @@ func (q *checker) tcheckExprBinaryOp(n *a.Expr, depth uint32) error {
|
||||
return err
|
||||
}
|
||||
lTyp := lhs.MType()
|
||||
op := n.ID0()
|
||||
op := n.Operator()
|
||||
if op.Key() == t.KeyXBinaryAs {
|
||||
rhs := n.RHS().TypeExpr()
|
||||
if err := q.tcheckTypeExpr(rhs, 0); err != nil {
|
||||
@@ -911,7 +911,7 @@ func (q *checker) tcheckExprBinaryOp(n *a.Expr, depth uint32) error {
|
||||
}
|
||||
|
||||
func evalConstValueBinaryOp(tm *t.Map, n *a.Expr, l *big.Int, r *big.Int) (*big.Int, error) {
|
||||
switch n.ID0().Key() {
|
||||
switch n.Operator().Key() {
|
||||
case t.KeyXBinaryPlus:
|
||||
return big.NewInt(0).Add(l, r), nil
|
||||
case t.KeyXBinaryMinus:
|
||||
@@ -969,11 +969,11 @@ func evalConstValueBinaryOp(tm *t.Map, n *a.Expr, l *big.Int, r *big.Int) (*big.
|
||||
case t.KeyXBinaryTildePlus:
|
||||
return nil, fmt.Errorf("check: cannot apply ~+ operator to ideal numbers")
|
||||
}
|
||||
return nil, fmt.Errorf("check: unrecognized token.Key (0x%02X) for evalConstValueBinaryOp", n.ID0().Key())
|
||||
return nil, fmt.Errorf("check: unrecognized token.Key (0x%02X) for evalConstValueBinaryOp", n.Operator().Key())
|
||||
}
|
||||
|
||||
func (q *checker) tcheckExprAssociativeOp(n *a.Expr, depth uint32) error {
|
||||
switch n.ID0().Key() {
|
||||
switch n.Operator().Key() {
|
||||
case t.KeyXAssociativePlus, t.KeyXAssociativeStar,
|
||||
t.KeyXAssociativeAmp, t.KeyXAssociativePipe, t.KeyXAssociativeHat:
|
||||
|
||||
@@ -989,7 +989,7 @@ func (q *checker) tcheckExprAssociativeOp(n *a.Expr, depth uint32) error {
|
||||
}
|
||||
if !oTyp.IsNumType() {
|
||||
return fmt.Errorf("check: associative %q: %q, of type %q, does not have a numeric type",
|
||||
n.ID0().AmbiguousForm().Str(q.tm), o.Str(q.tm), oTyp.Str(q.tm))
|
||||
n.Operator().AmbiguousForm().Str(q.tm), o.Str(q.tm), oTyp.Str(q.tm))
|
||||
}
|
||||
if typ == nil {
|
||||
expr, typ = o, oTyp.Unrefined()
|
||||
@@ -998,7 +998,7 @@ func (q *checker) tcheckExprAssociativeOp(n *a.Expr, depth uint32) error {
|
||||
if !typ.EqIgnoringRefinements(oTyp) {
|
||||
return fmt.Errorf("check: associative %q: %q and %q, of types %q and %q, "+
|
||||
"do not have compatible types",
|
||||
n.ID0().AmbiguousForm().Str(q.tm),
|
||||
n.Operator().AmbiguousForm().Str(q.tm),
|
||||
expr.Str(q.tm), o.Str(q.tm),
|
||||
expr.MType().Str(q.tm), o.MType().Str(q.tm))
|
||||
}
|
||||
@@ -1017,14 +1017,14 @@ func (q *checker) tcheckExprAssociativeOp(n *a.Expr, depth uint32) error {
|
||||
}
|
||||
if !o.MType().IsBool() {
|
||||
return fmt.Errorf("check: associative %q: %q, of type %q, does not have a boolean type",
|
||||
n.ID0().AmbiguousForm().Str(q.tm), o.Str(q.tm), o.MType().Str(q.tm))
|
||||
n.Operator().AmbiguousForm().Str(q.tm), o.Str(q.tm), o.MType().Str(q.tm))
|
||||
}
|
||||
}
|
||||
n.SetMType(typeExprBool)
|
||||
return nil
|
||||
}
|
||||
|
||||
return fmt.Errorf("check: unrecognized token.Key (0x%X) for tcheckExprAssociativeOp", n.ID0().Key())
|
||||
return fmt.Errorf("check: unrecognized token.Key (0x%X) for tcheckExprAssociativeOp", n.Operator().Key())
|
||||
}
|
||||
|
||||
func (q *checker) tcheckTypeExpr(typ *a.TypeExpr, depth uint32) error {
|
||||
|
||||
Reference in new issue
Block a user