mirror of
https://github.com/ddidderr/wuffs.git
synced 2026-11-18 00:32:11 +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
@@ -508,7 +508,7 @@ func (g *gen) writeConst(b *buffer, n *a.Const) error {
|
||||
}
|
||||
|
||||
func (g *gen) writeConstList(b *buffer, n *a.Expr) error {
|
||||
switch n.ID0().Key() {
|
||||
switch n.Operator().Key() {
|
||||
case 0:
|
||||
b.writes(n.ConstValue().String())
|
||||
case t.KeyDollar:
|
||||
|
||||
@@ -57,7 +57,7 @@ func (g *gen) writeExpr(b *buffer, n *a.Expr, rp replacementPolicy, pp parenthes
|
||||
return nil
|
||||
}
|
||||
|
||||
switch n.ID0().Flags() & (t.FlagsUnaryOp | t.FlagsBinaryOp | t.FlagsAssociativeOp) {
|
||||
switch n.Operator().Flags() & (t.FlagsUnaryOp | t.FlagsBinaryOp | t.FlagsAssociativeOp) {
|
||||
case 0:
|
||||
if err := g.writeExprOther(b, n, rp, pp, depth); err != nil {
|
||||
return err
|
||||
@@ -75,16 +75,16 @@ func (g *gen) writeExpr(b *buffer, n *a.Expr, rp replacementPolicy, pp parenthes
|
||||
return err
|
||||
}
|
||||
default:
|
||||
return fmt.Errorf("unrecognized token.Key (0x%X) for writeExpr", n.ID0().Key())
|
||||
return fmt.Errorf("unrecognized token.Key (0x%X) for writeExpr", n.Operator().Key())
|
||||
}
|
||||
|
||||
return nil
|
||||
}
|
||||
|
||||
func (g *gen) writeExprOther(b *buffer, n *a.Expr, rp replacementPolicy, pp parenthesesPolicy, depth uint32) error {
|
||||
switch n.ID0().Key() {
|
||||
switch n.Operator().Key() {
|
||||
case 0:
|
||||
if id1 := n.ID1(); id1.Key() == t.KeyThis {
|
||||
if id1 := n.Ident(); id1.Key() == t.KeyThis {
|
||||
b.writes("self")
|
||||
} else {
|
||||
if n.GlobalIdent() {
|
||||
@@ -142,7 +142,7 @@ func (g *gen) writeExprOther(b *buffer, n *a.Expr, rp replacementPolicy, pp pare
|
||||
if err := g.writeExpr(b, x, rp, parenthesesMandatory, depth); err != nil {
|
||||
return err
|
||||
}
|
||||
switch key := n.LHS().Expr().ID1().Key(); key {
|
||||
switch key := n.LHS().Expr().Ident().Key(); key {
|
||||
case t.KeyIsError:
|
||||
b.writes(" < 0")
|
||||
case t.KeyIsOK:
|
||||
@@ -421,9 +421,9 @@ func (g *gen) writeExprOther(b *buffer, n *a.Expr, rp replacementPolicy, pp pare
|
||||
|
||||
case t.KeyDot:
|
||||
lhs := n.LHS().Expr()
|
||||
if lhs.ID1().Key() == t.KeyIn {
|
||||
if lhs.Ident().Key() == t.KeyIn {
|
||||
b.writes(aPrefix)
|
||||
b.writes(n.ID1().Str(g.tm))
|
||||
b.writes(n.Ident().Str(g.tm))
|
||||
return nil
|
||||
}
|
||||
|
||||
@@ -436,13 +436,13 @@ func (g *gen) writeExprOther(b *buffer, n *a.Expr, rp replacementPolicy, pp pare
|
||||
b.writes(".")
|
||||
}
|
||||
b.writes("private_impl." + fPrefix)
|
||||
b.writes(n.ID1().Str(g.tm))
|
||||
b.writes(n.Ident().Str(g.tm))
|
||||
return nil
|
||||
|
||||
case t.KeyError, t.KeyStatus, t.KeySuspension:
|
||||
status := g.statusMap[t.QID{0, n.ID1()}]
|
||||
status := g.statusMap[t.QID{0, n.Ident()}]
|
||||
if status.name == "" {
|
||||
msg, _ := t.Unescape(n.ID1().Str(g.tm))
|
||||
msg, _ := t.Unescape(n.Ident().Str(g.tm))
|
||||
z := builtin.StatusMap[msg]
|
||||
if z.Message == "" {
|
||||
return fmt.Errorf("no status code for %q", msg)
|
||||
@@ -452,16 +452,16 @@ func (g *gen) writeExprOther(b *buffer, n *a.Expr, rp replacementPolicy, pp pare
|
||||
b.writes(status.name)
|
||||
return nil
|
||||
}
|
||||
return fmt.Errorf("unrecognized token.Key (0x%X) for writeExprOther", n.ID0().Key())
|
||||
return fmt.Errorf("unrecognized token.Key (0x%X) for writeExprOther", n.Operator().Key())
|
||||
}
|
||||
|
||||
func (g *gen) writeExprUnaryOp(b *buffer, n *a.Expr, rp replacementPolicy, pp parenthesesPolicy, depth uint32) error {
|
||||
b.writes(cOpNames[0xFF&n.ID0().Key()])
|
||||
b.writes(cOpNames[0xFF&n.Operator().Key()])
|
||||
return g.writeExpr(b, n.RHS().Expr(), rp, parenthesesMandatory, depth)
|
||||
}
|
||||
|
||||
func (g *gen) writeExprBinaryOp(b *buffer, n *a.Expr, rp replacementPolicy, pp parenthesesPolicy, depth uint32) error {
|
||||
op := n.ID0()
|
||||
op := n.Operator()
|
||||
if op.Key() == t.KeyXBinaryAs {
|
||||
return g.writeExprAs(b, n.LHS().Expr(), n.RHS().TypeExpr(), rp, depth)
|
||||
}
|
||||
@@ -501,7 +501,7 @@ func (g *gen) writeExprAssociativeOp(b *buffer, n *a.Expr, rp replacementPolicy,
|
||||
if pp == parenthesesMandatory {
|
||||
b.writeb('(')
|
||||
}
|
||||
opName := cOpNames[0xFF&n.ID0().Key()]
|
||||
opName := cOpNames[0xFF&n.Operator().Key()]
|
||||
for i, o := range n.Args() {
|
||||
if i != 0 {
|
||||
b.writes(opName)
|
||||
|
||||
@@ -229,7 +229,7 @@ func (g *gen) writeStatement(b *buffer, n *a.Node, depth uint32) error {
|
||||
if retExpr == nil {
|
||||
b.printf("%s%s", g.PKGPREFIX, "STATUS_OK")
|
||||
} else {
|
||||
retKeyword = retExpr.ID0().Key()
|
||||
retKeyword = retExpr.Operator().Key()
|
||||
// TODO: check that retExpr has no call-suspendibles.
|
||||
if err := g.writeExpr(
|
||||
b, retExpr, replaceCallSuspendibles, parenthesesMandatory, depth); err != nil {
|
||||
@@ -772,19 +772,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 {
|
||||
@@ -797,45 +797,45 @@ 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
|
||||
}
|
||||
|
||||
func isThisMethod(tm *t.Map, n *a.Expr, methodName string, nArgs int) bool {
|
||||
// TODO: check that n.Args() is "(src:in.src)".
|
||||
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() != tm.ByName(methodName) {
|
||||
if n.Operator().Key() != t.KeyDot || n.Ident() != tm.ByName(methodName) {
|
||||
return false
|
||||
}
|
||||
n = n.LHS().Expr()
|
||||
return n.ID0() == 0 && n.ID1().Key() == t.KeyThis
|
||||
return n.Operator() == 0 && n.Ident().Key() == t.KeyThis
|
||||
}
|
||||
|
||||
// isThatMethod is like isThisMethod but for foo.bar(etc), not this.bar(etc).
|
||||
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()
|
||||
return n.ID0().Key() == t.KeyDot && n.ID1().Key() == methodName
|
||||
return n.Operator().Key() == t.KeyDot && n.Ident().Key() == methodName
|
||||
}
|
||||
@@ -32,19 +32,19 @@ func (g *gen) needDerivedVar(name t.ID) bool {
|
||||
return nil
|
||||
}
|
||||
q := p.Expr()
|
||||
if q.ID0().Key() != t.KeyOpenParen {
|
||||
if q.Operator().Key() != t.KeyOpenParen {
|
||||
return nil
|
||||
}
|
||||
q = q.LHS().Expr()
|
||||
if q.ID0().Key() != t.KeyDot {
|
||||
if q.Operator().Key() != t.KeyDot {
|
||||
return nil
|
||||
}
|
||||
q = q.LHS().Expr()
|
||||
if q.ID0().Key() != t.KeyDot || q.ID1() != name {
|
||||
if q.Operator().Key() != t.KeyDot || q.Ident() != name {
|
||||
return nil
|
||||
}
|
||||
q = q.LHS().Expr()
|
||||
if q.ID0() != 0 || q.ID1().Key() != t.KeyIn {
|
||||
if q.Operator() != 0 || q.Ident().Key() != t.KeyIn {
|
||||
return nil
|
||||
}
|
||||
return errNeedDerivedVar
|
||||
@@ -220,7 +220,7 @@ func (g *gen) writeLoadExprDerivedVars(b *buffer, n *a.Expr) error {
|
||||
if g.currFunk.derivedVars == nil {
|
||||
return nil
|
||||
}
|
||||
if k := n.ID0().Key(); k != t.KeyOpenParen && k != t.KeyTry {
|
||||
if k := n.Operator().Key(); k != t.KeyOpenParen && k != t.KeyTry {
|
||||
return nil
|
||||
}
|
||||
for _, o := range n.Args() {
|
||||
@@ -240,7 +240,7 @@ func (g *gen) writeSaveExprDerivedVars(b *buffer, n *a.Expr) error {
|
||||
if g.currFunk.derivedVars == nil {
|
||||
return nil
|
||||
}
|
||||
if k := n.ID0().Key(); k != t.KeyOpenParen && k != t.KeyTry {
|
||||
if k := n.Operator().Key(); k != t.KeyOpenParen && k != t.KeyTry {
|
||||
return nil
|
||||
}
|
||||
for _, o := range n.Args() {
|
||||
|
||||
+8
-8
@@ -140,7 +140,7 @@ type Node struct {
|
||||
// Assert keyword reason . Assert
|
||||
// Assign operator . . Assign
|
||||
// Const . pkg name Const
|
||||
// Expr operator literal/ident . Expr
|
||||
// Expr operator . literal/ident Expr
|
||||
// Field . . name Field
|
||||
// File . . . File
|
||||
// Func funcName receiverPkg receiverName Func
|
||||
@@ -268,13 +268,13 @@ const MaxExprDepth = 255
|
||||
// - FlagsCallImpure is "f(x)" vs "f!(x)"
|
||||
// - FlagsCallSuspendible is "f(x)" vs "f?(x)", it implies FlagsCallImpure
|
||||
// - ID0: <0|operator|IDOpenParen|IDOpenBracket|IDColon|IDDot>
|
||||
// - ID1: <0|ident|literal>
|
||||
// - ID2: <0|literal|ident>
|
||||
// - LHS: <nil|Expr>
|
||||
// - MHS: <nil|Expr>
|
||||
// - RHS: <nil|Expr|TypeExpr>
|
||||
// - List0: <Arg|Expr> function call args, assoc. op args or list members.
|
||||
//
|
||||
// A zero ID0 means an identifier or literal in ID1, like "foo" or "42".
|
||||
// A zero ID0 means an identifier or literal in ID2, like "foo" or "42".
|
||||
//
|
||||
// For unary operators, ID0 is the operator and RHS is the operand.
|
||||
//
|
||||
@@ -293,7 +293,7 @@ const MaxExprDepth = 255
|
||||
//
|
||||
// For slices, like "LHS[MHS:RHS]", ID0 is IDColon.
|
||||
//
|
||||
// For selectors, like "LHS.ID1", ID0 is IDDot.
|
||||
// For selectors, like "LHS.ID2", ID0 is IDDot.
|
||||
//
|
||||
// For lists, like "$(0, 1, 2)", ID0 is IDDollar.
|
||||
//
|
||||
@@ -312,8 +312,8 @@ func (n *Expr) ProvenNotToSuspend() bool { return n.flags&FlagsProvenNotToSusp
|
||||
func (n *Expr) BoundsCheckOptimized() bool { return n.flags&FlagsBoundsCheckOptimized != 0 }
|
||||
func (n *Expr) ConstValue() *big.Int { return n.constValue }
|
||||
func (n *Expr) MType() *TypeExpr { return n.mType }
|
||||
func (n *Expr) ID0() t.ID { return n.id0 }
|
||||
func (n *Expr) ID1() t.ID { return n.id1 }
|
||||
func (n *Expr) Operator() t.ID { return n.id0 }
|
||||
func (n *Expr) Ident() t.ID { return n.id2 }
|
||||
func (n *Expr) LHS() *Node { return n.lhs }
|
||||
func (n *Expr) MHS() *Node { return n.mhs }
|
||||
func (n *Expr) RHS() *Node { return n.rhs }
|
||||
@@ -325,7 +325,7 @@ func (n *Expr) SetGlobalIdent() { n.flags |= FlagsGlobalIdent }
|
||||
func (n *Expr) SetMType(x *TypeExpr) { n.mType = x }
|
||||
func (n *Expr) SetProvenNotToSuspend() { n.flags |= FlagsProvenNotToSuspend }
|
||||
|
||||
func NewExpr(flags Flags, operator t.ID, nameLiteralSelector t.ID, lhs *Node, mhs *Node, rhs *Node, args []*Node) *Expr {
|
||||
func NewExpr(flags Flags, operator t.ID, ident t.ID, lhs *Node, mhs *Node, rhs *Node, args []*Node) *Expr {
|
||||
if lhs != nil {
|
||||
flags |= lhs.flags & (FlagsImpure | FlagsSuspendible)
|
||||
}
|
||||
@@ -343,7 +343,7 @@ func NewExpr(flags Flags, operator t.ID, nameLiteralSelector t.ID, lhs *Node, mh
|
||||
kind: KExpr,
|
||||
flags: flags,
|
||||
id0: operator,
|
||||
id1: nameLiteralSelector,
|
||||
id2: ident,
|
||||
lhs: lhs,
|
||||
mhs: mhs,
|
||||
rhs: rhs,
|
||||
|
||||
+3
-3
@@ -24,7 +24,7 @@ func (n *Expr) Str(tm *t.Map) string {
|
||||
return ""
|
||||
}
|
||||
if n.id0 == 0 {
|
||||
return tm.ByID(n.id1)
|
||||
return tm.ByID(n.id2)
|
||||
}
|
||||
return string(n.appendStr(nil, tm, false, 0))
|
||||
}
|
||||
@@ -40,7 +40,7 @@ func (n *Expr) appendStr(buf []byte, tm *t.Map, parenthesize bool, depth uint32)
|
||||
case 0:
|
||||
switch n.id0.Key() {
|
||||
case 0:
|
||||
buf = append(buf, tm.ByID(n.id1)...)
|
||||
buf = append(buf, tm.ByID(n.id2)...)
|
||||
|
||||
case t.KeyTry:
|
||||
buf = append(buf, "try "...)
|
||||
@@ -81,7 +81,7 @@ func (n *Expr) appendStr(buf []byte, tm *t.Map, parenthesize bool, depth uint32)
|
||||
case t.KeyDot:
|
||||
buf = n.lhs.Expr().appendStr(buf, tm, true, depth)
|
||||
buf = append(buf, '.')
|
||||
buf = append(buf, tm.ByID(n.id1)...)
|
||||
buf = append(buf, tm.ByID(n.id2)...)
|
||||
|
||||
case t.KeyDollar:
|
||||
buf = append(buf, "$("...)
|
||||
|
||||
@@ -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 {
|
||||
|
||||
+2
-2
@@ -831,11 +831,11 @@ func (p *parser) parseTryExpr() (*a.Expr, error) {
|
||||
if err != nil {
|
||||
return nil, err
|
||||
}
|
||||
if call.ID0() != t.IDOpenParen {
|
||||
if call.Operator() != t.IDOpenParen {
|
||||
return nil, fmt.Errorf(`parse: expected function call after "try", got %q at %s:%d`,
|
||||
call.Str(p.tm), p.filename, p.line())
|
||||
}
|
||||
return a.NewExpr(call.Node().Raw().Flags(), t.IDTry, call.ID1(),
|
||||
return a.NewExpr(call.Node().Raw().Flags(), t.IDTry, call.Ident(),
|
||||
call.LHS(), call.MHS(), call.RHS(), call.Args()), nil
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user