mirror of
https://github.com/ddidderr/wuffs.git
synced 2026-11-24 08:52:18 +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 {
|
func (g *gen) writeConstList(b *buffer, n *a.Expr) error {
|
||||||
switch n.ID0().Key() {
|
switch n.Operator().Key() {
|
||||||
case 0:
|
case 0:
|
||||||
b.writes(n.ConstValue().String())
|
b.writes(n.ConstValue().String())
|
||||||
case t.KeyDollar:
|
case t.KeyDollar:
|
||||||
|
|||||||
@@ -57,7 +57,7 @@ func (g *gen) writeExpr(b *buffer, n *a.Expr, rp replacementPolicy, pp parenthes
|
|||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
switch n.ID0().Flags() & (t.FlagsUnaryOp | t.FlagsBinaryOp | t.FlagsAssociativeOp) {
|
switch n.Operator().Flags() & (t.FlagsUnaryOp | t.FlagsBinaryOp | t.FlagsAssociativeOp) {
|
||||||
case 0:
|
case 0:
|
||||||
if err := g.writeExprOther(b, n, rp, pp, depth); err != nil {
|
if err := g.writeExprOther(b, n, rp, pp, depth); err != nil {
|
||||||
return err
|
return err
|
||||||
@@ -75,16 +75,16 @@ func (g *gen) writeExpr(b *buffer, n *a.Expr, rp replacementPolicy, pp parenthes
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
default:
|
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
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (g *gen) writeExprOther(b *buffer, n *a.Expr, rp replacementPolicy, pp parenthesesPolicy, depth uint32) error {
|
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:
|
case 0:
|
||||||
if id1 := n.ID1(); id1.Key() == t.KeyThis {
|
if id1 := n.Ident(); id1.Key() == t.KeyThis {
|
||||||
b.writes("self")
|
b.writes("self")
|
||||||
} else {
|
} else {
|
||||||
if n.GlobalIdent() {
|
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 {
|
if err := g.writeExpr(b, x, rp, parenthesesMandatory, depth); err != nil {
|
||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
switch key := n.LHS().Expr().ID1().Key(); key {
|
switch key := n.LHS().Expr().Ident().Key(); key {
|
||||||
case t.KeyIsError:
|
case t.KeyIsError:
|
||||||
b.writes(" < 0")
|
b.writes(" < 0")
|
||||||
case t.KeyIsOK:
|
case t.KeyIsOK:
|
||||||
@@ -421,9 +421,9 @@ func (g *gen) writeExprOther(b *buffer, n *a.Expr, rp replacementPolicy, pp pare
|
|||||||
|
|
||||||
case t.KeyDot:
|
case t.KeyDot:
|
||||||
lhs := n.LHS().Expr()
|
lhs := n.LHS().Expr()
|
||||||
if lhs.ID1().Key() == t.KeyIn {
|
if lhs.Ident().Key() == t.KeyIn {
|
||||||
b.writes(aPrefix)
|
b.writes(aPrefix)
|
||||||
b.writes(n.ID1().Str(g.tm))
|
b.writes(n.Ident().Str(g.tm))
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -436,13 +436,13 @@ func (g *gen) writeExprOther(b *buffer, n *a.Expr, rp replacementPolicy, pp pare
|
|||||||
b.writes(".")
|
b.writes(".")
|
||||||
}
|
}
|
||||||
b.writes("private_impl." + fPrefix)
|
b.writes("private_impl." + fPrefix)
|
||||||
b.writes(n.ID1().Str(g.tm))
|
b.writes(n.Ident().Str(g.tm))
|
||||||
return nil
|
return nil
|
||||||
|
|
||||||
case t.KeyError, t.KeyStatus, t.KeySuspension:
|
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 == "" {
|
if status.name == "" {
|
||||||
msg, _ := t.Unescape(n.ID1().Str(g.tm))
|
msg, _ := t.Unescape(n.Ident().Str(g.tm))
|
||||||
z := builtin.StatusMap[msg]
|
z := builtin.StatusMap[msg]
|
||||||
if z.Message == "" {
|
if z.Message == "" {
|
||||||
return fmt.Errorf("no status code for %q", msg)
|
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)
|
b.writes(status.name)
|
||||||
return nil
|
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 {
|
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)
|
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 {
|
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 {
|
if op.Key() == t.KeyXBinaryAs {
|
||||||
return g.writeExprAs(b, n.LHS().Expr(), n.RHS().TypeExpr(), rp, depth)
|
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 {
|
if pp == parenthesesMandatory {
|
||||||
b.writeb('(')
|
b.writeb('(')
|
||||||
}
|
}
|
||||||
opName := cOpNames[0xFF&n.ID0().Key()]
|
opName := cOpNames[0xFF&n.Operator().Key()]
|
||||||
for i, o := range n.Args() {
|
for i, o := range n.Args() {
|
||||||
if i != 0 {
|
if i != 0 {
|
||||||
b.writes(opName)
|
b.writes(opName)
|
||||||
|
|||||||
@@ -229,7 +229,7 @@ func (g *gen) writeStatement(b *buffer, n *a.Node, depth uint32) error {
|
|||||||
if retExpr == nil {
|
if retExpr == nil {
|
||||||
b.printf("%s%s", g.PKGPREFIX, "STATUS_OK")
|
b.printf("%s%s", g.PKGPREFIX, "STATUS_OK")
|
||||||
} else {
|
} else {
|
||||||
retKeyword = retExpr.ID0().Key()
|
retKeyword = retExpr.Operator().Key()
|
||||||
// TODO: check that retExpr has no call-suspendibles.
|
// TODO: check that retExpr has no call-suspendibles.
|
||||||
if err := g.writeExpr(
|
if err := g.writeExpr(
|
||||||
b, retExpr, replaceCallSuspendibles, parenthesesMandatory, depth); err != nil {
|
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 &&
|
callSuspendible := methodName != t.KeySinceMark &&
|
||||||
methodName != t.KeyMark &&
|
methodName != t.KeyMark &&
|
||||||
methodName != t.KeyLimit
|
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
|
return false
|
||||||
}
|
}
|
||||||
n = n.LHS().Expr()
|
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
|
return false
|
||||||
}
|
}
|
||||||
n = n.LHS().Expr()
|
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
|
return false
|
||||||
}
|
}
|
||||||
n = n.LHS().Expr()
|
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 {
|
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.KeyMark &&
|
||||||
methodName != t.KeyLimit
|
methodName != t.KeyLimit
|
||||||
// TODO: check that n.Args() is "(x:bar)".
|
// 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
|
return false
|
||||||
}
|
}
|
||||||
n = n.LHS().Expr()
|
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
|
return false
|
||||||
}
|
}
|
||||||
n = n.LHS().Expr()
|
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
|
return false
|
||||||
}
|
}
|
||||||
n = n.LHS().Expr()
|
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 {
|
func isThisMethod(tm *t.Map, n *a.Expr, methodName string, nArgs int) bool {
|
||||||
// TODO: check that n.Args() is "(src:in.src)".
|
// 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
|
return false
|
||||||
}
|
}
|
||||||
if len(n.Args()) != nArgs {
|
if len(n.Args()) != nArgs {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
n = n.LHS().Expr()
|
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
|
return false
|
||||||
}
|
}
|
||||||
n = n.LHS().Expr()
|
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).
|
// 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 {
|
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
|
return false
|
||||||
}
|
}
|
||||||
if len(n.Args()) != nArgs {
|
if len(n.Args()) != nArgs {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
n = n.LHS().Expr()
|
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
|
return nil
|
||||||
}
|
}
|
||||||
q := p.Expr()
|
q := p.Expr()
|
||||||
if q.ID0().Key() != t.KeyOpenParen {
|
if q.Operator().Key() != t.KeyOpenParen {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
q = q.LHS().Expr()
|
q = q.LHS().Expr()
|
||||||
if q.ID0().Key() != t.KeyDot {
|
if q.Operator().Key() != t.KeyDot {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
q = q.LHS().Expr()
|
q = q.LHS().Expr()
|
||||||
if q.ID0().Key() != t.KeyDot || q.ID1() != name {
|
if q.Operator().Key() != t.KeyDot || q.Ident() != name {
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
q = q.LHS().Expr()
|
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 nil
|
||||||
}
|
}
|
||||||
return errNeedDerivedVar
|
return errNeedDerivedVar
|
||||||
@@ -220,7 +220,7 @@ func (g *gen) writeLoadExprDerivedVars(b *buffer, n *a.Expr) error {
|
|||||||
if g.currFunk.derivedVars == nil {
|
if g.currFunk.derivedVars == nil {
|
||||||
return 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
|
return nil
|
||||||
}
|
}
|
||||||
for _, o := range n.Args() {
|
for _, o := range n.Args() {
|
||||||
@@ -240,7 +240,7 @@ func (g *gen) writeSaveExprDerivedVars(b *buffer, n *a.Expr) error {
|
|||||||
if g.currFunk.derivedVars == nil {
|
if g.currFunk.derivedVars == nil {
|
||||||
return 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
|
return nil
|
||||||
}
|
}
|
||||||
for _, o := range n.Args() {
|
for _, o := range n.Args() {
|
||||||
|
|||||||
+8
-8
@@ -140,7 +140,7 @@ type Node struct {
|
|||||||
// Assert keyword reason . Assert
|
// Assert keyword reason . Assert
|
||||||
// Assign operator . . Assign
|
// Assign operator . . Assign
|
||||||
// Const . pkg name Const
|
// Const . pkg name Const
|
||||||
// Expr operator literal/ident . Expr
|
// Expr operator . literal/ident Expr
|
||||||
// Field . . name Field
|
// Field . . name Field
|
||||||
// File . . . File
|
// File . . . File
|
||||||
// Func funcName receiverPkg receiverName Func
|
// Func funcName receiverPkg receiverName Func
|
||||||
@@ -268,13 +268,13 @@ const MaxExprDepth = 255
|
|||||||
// - FlagsCallImpure is "f(x)" vs "f!(x)"
|
// - FlagsCallImpure is "f(x)" vs "f!(x)"
|
||||||
// - FlagsCallSuspendible is "f(x)" vs "f?(x)", it implies FlagsCallImpure
|
// - FlagsCallSuspendible is "f(x)" vs "f?(x)", it implies FlagsCallImpure
|
||||||
// - ID0: <0|operator|IDOpenParen|IDOpenBracket|IDColon|IDDot>
|
// - ID0: <0|operator|IDOpenParen|IDOpenBracket|IDColon|IDDot>
|
||||||
// - ID1: <0|ident|literal>
|
// - ID2: <0|literal|ident>
|
||||||
// - LHS: <nil|Expr>
|
// - LHS: <nil|Expr>
|
||||||
// - MHS: <nil|Expr>
|
// - MHS: <nil|Expr>
|
||||||
// - RHS: <nil|Expr|TypeExpr>
|
// - RHS: <nil|Expr|TypeExpr>
|
||||||
// - List0: <Arg|Expr> function call args, assoc. op args or list members.
|
// - 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.
|
// 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 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.
|
// 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) BoundsCheckOptimized() bool { return n.flags&FlagsBoundsCheckOptimized != 0 }
|
||||||
func (n *Expr) ConstValue() *big.Int { return n.constValue }
|
func (n *Expr) ConstValue() *big.Int { return n.constValue }
|
||||||
func (n *Expr) MType() *TypeExpr { return n.mType }
|
func (n *Expr) MType() *TypeExpr { return n.mType }
|
||||||
func (n *Expr) ID0() t.ID { return n.id0 }
|
func (n *Expr) Operator() t.ID { return n.id0 }
|
||||||
func (n *Expr) ID1() t.ID { return n.id1 }
|
func (n *Expr) Ident() t.ID { return n.id2 }
|
||||||
func (n *Expr) LHS() *Node { return n.lhs }
|
func (n *Expr) LHS() *Node { return n.lhs }
|
||||||
func (n *Expr) MHS() *Node { return n.mhs }
|
func (n *Expr) MHS() *Node { return n.mhs }
|
||||||
func (n *Expr) RHS() *Node { return n.rhs }
|
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) SetMType(x *TypeExpr) { n.mType = x }
|
||||||
func (n *Expr) SetProvenNotToSuspend() { n.flags |= FlagsProvenNotToSuspend }
|
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 {
|
if lhs != nil {
|
||||||
flags |= lhs.flags & (FlagsImpure | FlagsSuspendible)
|
flags |= lhs.flags & (FlagsImpure | FlagsSuspendible)
|
||||||
}
|
}
|
||||||
@@ -343,7 +343,7 @@ func NewExpr(flags Flags, operator t.ID, nameLiteralSelector t.ID, lhs *Node, mh
|
|||||||
kind: KExpr,
|
kind: KExpr,
|
||||||
flags: flags,
|
flags: flags,
|
||||||
id0: operator,
|
id0: operator,
|
||||||
id1: nameLiteralSelector,
|
id2: ident,
|
||||||
lhs: lhs,
|
lhs: lhs,
|
||||||
mhs: mhs,
|
mhs: mhs,
|
||||||
rhs: rhs,
|
rhs: rhs,
|
||||||
|
|||||||
+3
-3
@@ -24,7 +24,7 @@ func (n *Expr) Str(tm *t.Map) string {
|
|||||||
return ""
|
return ""
|
||||||
}
|
}
|
||||||
if n.id0 == 0 {
|
if n.id0 == 0 {
|
||||||
return tm.ByID(n.id1)
|
return tm.ByID(n.id2)
|
||||||
}
|
}
|
||||||
return string(n.appendStr(nil, tm, false, 0))
|
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:
|
case 0:
|
||||||
switch n.id0.Key() {
|
switch n.id0.Key() {
|
||||||
case 0:
|
case 0:
|
||||||
buf = append(buf, tm.ByID(n.id1)...)
|
buf = append(buf, tm.ByID(n.id2)...)
|
||||||
|
|
||||||
case t.KeyTry:
|
case t.KeyTry:
|
||||||
buf = append(buf, "try "...)
|
buf = append(buf, "try "...)
|
||||||
@@ -81,7 +81,7 @@ func (n *Expr) appendStr(buf []byte, tm *t.Map, parenthesize bool, depth uint32)
|
|||||||
case t.KeyDot:
|
case t.KeyDot:
|
||||||
buf = n.lhs.Expr().appendStr(buf, tm, true, depth)
|
buf = n.lhs.Expr().appendStr(buf, tm, true, depth)
|
||||||
buf = append(buf, '.')
|
buf = append(buf, '.')
|
||||||
buf = append(buf, tm.ByID(n.id1)...)
|
buf = append(buf, tm.ByID(n.id2)...)
|
||||||
|
|
||||||
case t.KeyDollar:
|
case t.KeyDollar:
|
||||||
buf = append(buf, "$("...)
|
buf = append(buf, "$("...)
|
||||||
|
|||||||
@@ -27,7 +27,7 @@ import (
|
|||||||
// binary-op expression like "thisHS == thatHS" or "thatHS < thisHS" (which is
|
// binary-op expression like "thisHS == thatHS" or "thatHS < thisHS" (which is
|
||||||
// equivalent to "thisHS > thatHS"). If not, it returns (0, nil).
|
// equivalent to "thisHS > thatHS"). If not, it returns (0, nil).
|
||||||
func otherHandSide(n *a.Expr, thisHS *a.Expr) (op t.ID, thatHS *a.Expr) {
|
func otherHandSide(n *a.Expr, thisHS *a.Expr) (op t.ID, thatHS *a.Expr) {
|
||||||
op = n.ID0()
|
op = n.Operator()
|
||||||
|
|
||||||
reverseOp := t.ID(0)
|
reverseOp := t.ID(0)
|
||||||
switch op.Key() {
|
switch op.Key() {
|
||||||
@@ -66,7 +66,7 @@ func (z *facts) appendFact(fact *a.Expr) {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
switch fact.ID0().Key() {
|
switch fact.Operator().Key() {
|
||||||
case 0:
|
case 0:
|
||||||
for _, x := range *z {
|
for _, x := range *z {
|
||||||
if op, other := otherHandSide(x, fact); op.Key() == t.KeyXBinaryEqEq {
|
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".
|
// parseBinaryOp parses n as "lhs op rhs".
|
||||||
func parseBinaryOp(n *a.Expr) (op t.ID, lhs *a.Expr, rhs *a.Expr) {
|
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
|
return 0, nil, nil
|
||||||
}
|
}
|
||||||
op = n.ID0()
|
op = n.Operator()
|
||||||
if op.Key() == t.KeyAs {
|
if op.Key() == t.KeyAs {
|
||||||
return 0, nil, nil
|
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) {
|
if !x.LHS().Expr().Eq(lhs) {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
factOp := x.ID0().Key()
|
factOp := x.Operator().Key()
|
||||||
if opImpliesOp(factOp, op) && x.RHS().Expr().Eq(rhs) {
|
if opImpliesOp(factOp, op) && x.RHS().Expr().Eq(rhs) {
|
||||||
return nil
|
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 {
|
if cv := n.ConstValue(); cv != nil {
|
||||||
return nil, fmt.Errorf("check: invert(%q) called on constant expression", n.Str(tm))
|
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)
|
op, lhs, rhs, args := n.Operator(), n.LHS().Expr(), n.RHS().Expr(), []*a.Node(nil)
|
||||||
switch id0.Key() {
|
switch op.Key() {
|
||||||
case t.KeyXUnaryNot:
|
case t.KeyXUnaryNot:
|
||||||
return rhs, nil
|
return rhs, nil
|
||||||
case t.KeyXBinaryNotEq:
|
case t.KeyXBinaryNotEq:
|
||||||
id0 = t.IDXBinaryEqEq
|
op = t.IDXBinaryEqEq
|
||||||
case t.KeyXBinaryLessThan:
|
case t.KeyXBinaryLessThan:
|
||||||
id0 = t.IDXBinaryGreaterEq
|
op = t.IDXBinaryGreaterEq
|
||||||
case t.KeyXBinaryLessEq:
|
case t.KeyXBinaryLessEq:
|
||||||
id0 = t.IDXBinaryGreaterThan
|
op = t.IDXBinaryGreaterThan
|
||||||
case t.KeyXBinaryEqEq:
|
case t.KeyXBinaryEqEq:
|
||||||
id0 = t.IDXBinaryNotEq
|
op = t.IDXBinaryNotEq
|
||||||
case t.KeyXBinaryGreaterEq:
|
case t.KeyXBinaryGreaterEq:
|
||||||
id0 = t.IDXBinaryLessThan
|
op = t.IDXBinaryLessThan
|
||||||
case t.KeyXBinaryGreaterThan:
|
case t.KeyXBinaryGreaterThan:
|
||||||
id0 = t.IDXBinaryLessEq
|
op = t.IDXBinaryLessEq
|
||||||
case t.KeyXBinaryAnd, t.KeyXBinaryOr:
|
case t.KeyXBinaryAnd, t.KeyXBinaryOr:
|
||||||
var err error
|
var err error
|
||||||
lhs, err = invert(tm, lhs)
|
lhs, err = invert(tm, lhs)
|
||||||
@@ -141,10 +141,10 @@ func invert(tm *t.Map, n *a.Expr) (*a.Expr, error) {
|
|||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
if id0.Key() == t.KeyXBinaryAnd {
|
if op.Key() == t.KeyXBinaryAnd {
|
||||||
id0 = t.IDXBinaryOr
|
op = t.IDXBinaryOr
|
||||||
} else {
|
} else {
|
||||||
id0 = t.IDXBinaryAnd
|
op = t.IDXBinaryAnd
|
||||||
}
|
}
|
||||||
case t.KeyXAssociativeAnd, t.KeyXAssociativeOr:
|
case t.KeyXAssociativeAnd, t.KeyXAssociativeOr:
|
||||||
args = make([]*a.Node, 0, len(n.Args()))
|
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())
|
args = append(args, v.Node())
|
||||||
}
|
}
|
||||||
if id0.Key() == t.KeyXAssociativeAnd {
|
if op.Key() == t.KeyXAssociativeAnd {
|
||||||
id0 = t.IDXAssociativeOr
|
op = t.IDXAssociativeOr
|
||||||
} else {
|
} else {
|
||||||
id0 = t.IDXAssociativeAnd
|
op = t.IDXAssociativeAnd
|
||||||
}
|
}
|
||||||
default:
|
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())
|
o.SetMType(n.MType())
|
||||||
return o, nil
|
return o, nil
|
||||||
}
|
}
|
||||||
@@ -349,8 +349,8 @@ func (q *checker) bcheckAssert(n *a.Assert) error {
|
|||||||
} else {
|
} else {
|
||||||
err = fmt.Errorf("no such reason %s", reasonID.Str(q.tm))
|
err = fmt.Errorf("no such reason %s", reasonID.Str(q.tm))
|
||||||
}
|
}
|
||||||
} else if condition.ID0().IsBinaryOp() && condition.ID0().Key() != t.KeyAs {
|
} else if condition.Operator().IsBinaryOp() && condition.Operator().Key() != t.KeyAs {
|
||||||
err = q.proveBinaryOp(condition.ID0().Key(), condition.LHS().Expr(), condition.RHS().Expr())
|
err = q.proveBinaryOp(condition.Operator().Key(), condition.LHS().Expr(), condition.RHS().Expr())
|
||||||
}
|
}
|
||||||
|
|
||||||
if err != nil {
|
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 {
|
if cv := n.ConstValue(); cv != nil {
|
||||||
return cv, 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:
|
case 0:
|
||||||
return q.bcheckExprOther(n, depth)
|
return q.bcheckExprOther(n, depth)
|
||||||
case t.FlagsUnaryOp:
|
case t.FlagsUnaryOp:
|
||||||
return q.bcheckExprUnaryOp(n, depth)
|
return q.bcheckExprUnaryOp(n, depth)
|
||||||
case t.FlagsBinaryOp:
|
case t.FlagsBinaryOp:
|
||||||
if n.ID0().Key() == t.KeyXBinaryAs {
|
if n.Operator().Key() == t.KeyXBinaryAs {
|
||||||
return q.bcheckExpr(n.LHS().Expr(), depth)
|
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:
|
case t.FlagsAssociativeOp:
|
||||||
return q.bcheckExprAssociativeOp(n, depth)
|
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) {
|
func (q *checker) bcheckExprOther(n *a.Expr, depth uint32) (*big.Int, *big.Int, error) {
|
||||||
switch n.ID0().Key() {
|
switch n.Operator().Key() {
|
||||||
case 0:
|
case 0:
|
||||||
// No-op.
|
// No-op.
|
||||||
|
|
||||||
@@ -933,16 +933,16 @@ func (q *checker) bcheckExprOther(n *a.Expr, depth uint32) (*big.Int, *big.Int,
|
|||||||
|
|
||||||
case t.KeyDot:
|
case t.KeyDot:
|
||||||
// TODO: delete this hack that only matches "in".
|
// 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() {
|
for _, o := range q.f.Func.In().Fields() {
|
||||||
o := o.Field()
|
o := o.Field()
|
||||||
if o.Name() == n.ID1() {
|
if o.Name() == n.Ident() {
|
||||||
return q.bcheckTypeExpr(o.XType())
|
return q.bcheckTypeExpr(o.XType())
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
lTyp := n.LHS().Expr().MType()
|
lTyp := n.LHS().Expr().MType()
|
||||||
return nil, nil, fmt.Errorf("check: no field named %q found in struct type %q for expression %q",
|
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 {
|
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.
|
// No-op.
|
||||||
|
|
||||||
default:
|
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())
|
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
|
return nil, nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
switch n.ID0().Key() {
|
switch n.Operator().Key() {
|
||||||
case t.KeyXUnaryPlus:
|
case t.KeyXUnaryPlus:
|
||||||
return rMin, rMax, nil
|
return rMin, rMax, nil
|
||||||
case t.KeyXUnaryMinus:
|
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 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) {
|
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) {
|
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 {
|
if op == 0 {
|
||||||
return nil, nil, fmt.Errorf(
|
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()
|
args := n.Args()
|
||||||
if len(args) < 1 {
|
if len(args) < 1 {
|
||||||
@@ -1163,7 +1163,7 @@ func (q *checker) bcheckExprAssociativeOp(n *a.Expr, depth uint32) (*big.Int, *b
|
|||||||
if i == 0 {
|
if i == 0 {
|
||||||
continue
|
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)
|
lMin, lMax, err = q.bcheckExprBinaryOp1(op, lhs, lMin, lMax, o.Expr(), depth)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, nil, err
|
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 {
|
func (c *Checker) checkConstElement(n *a.Expr, nMin *big.Int, nMax *big.Int, nLists int) error {
|
||||||
if nLists > 0 {
|
if nLists > 0 {
|
||||||
nLists--
|
nLists--
|
||||||
if n.ID0().Key() != t.KeyDollar {
|
if n.Operator().Key() != t.KeyDollar {
|
||||||
return fmt.Errorf("invalid const value %q", n.Str(c.tm))
|
return fmt.Errorf("invalid const value %q", n.Str(c.tm))
|
||||||
}
|
}
|
||||||
for _, o := range n.Args() {
|
for _, o := range n.Args() {
|
||||||
|
|||||||
+11
-11
@@ -34,15 +34,15 @@ import (
|
|||||||
// splitReceiverMethodArgs returns the "receiver", "method" and "args" in the
|
// splitReceiverMethodArgs returns the "receiver", "method" and "args" in the
|
||||||
// expression "receiver.method(args)".
|
// expression "receiver.method(args)".
|
||||||
func splitReceiverMethodArgs(n *a.Expr) (receiver *a.Expr, method t.Key, args []*a.Node) {
|
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
|
return nil, 0, nil
|
||||||
}
|
}
|
||||||
args = n.Args()
|
args = n.Args()
|
||||||
n = n.LHS().Expr()
|
n = n.LHS().Expr()
|
||||||
if n.ID0().Key() != t.KeyDot {
|
if n.Operator().Key() != t.KeyDot {
|
||||||
return nil, 0, nil
|
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
|
// TODO: should optimizeNonSuspendible be optimizeExpr and check both
|
||||||
@@ -113,7 +113,7 @@ check0:
|
|||||||
check1:
|
check1:
|
||||||
for {
|
for {
|
||||||
for _, x := range q.facts {
|
for _, x := range q.facts {
|
||||||
if x.ID0().Key() != t.KeyXBinaryGreaterThan {
|
if x.Operator().Key() != t.KeyXBinaryGreaterThan {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
if lhs := x.LHS().Expr(); !lhs.Eq(d) {
|
if lhs := x.LHS().Expr(); !lhs.Eq(d) {
|
||||||
@@ -131,13 +131,13 @@ check1:
|
|||||||
check2:
|
check2:
|
||||||
for {
|
for {
|
||||||
for _, x := range q.facts {
|
for _, x := range q.facts {
|
||||||
if x.ID0().Key() != t.KeyXBinaryLessEq {
|
if x.Operator().Key() != t.KeyXBinaryLessEq {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check that the LHS is "d as u64".
|
// Check that the LHS is "d as u64".
|
||||||
lhs := x.LHS().Expr()
|
lhs := x.LHS().Expr()
|
||||||
if lhs.ID0().Key() != t.KeyXBinaryAs {
|
if lhs.Operator().Key() != t.KeyXBinaryAs {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
llhs, lrhs := lhs.LHS().Expr(), lhs.RHS().TypeExpr()
|
llhs, lrhs := lhs.LHS().Expr(), lhs.RHS().TypeExpr()
|
||||||
@@ -167,13 +167,13 @@ check2:
|
|||||||
check3:
|
check3:
|
||||||
for {
|
for {
|
||||||
for _, x := range q.facts {
|
for _, x := range q.facts {
|
||||||
if x.ID0().Key() != t.KeyXBinaryLessEq {
|
if x.Operator().Key() != t.KeyXBinaryLessEq {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
|
|
||||||
// Check that the LHS is "l as u64".
|
// Check that the LHS is "l as u64".
|
||||||
lhs := x.LHS().Expr()
|
lhs := x.LHS().Expr()
|
||||||
if lhs.ID0().Key() != t.KeyXBinaryAs {
|
if lhs.Operator().Key() != t.KeyXBinaryAs {
|
||||||
continue
|
continue
|
||||||
}
|
}
|
||||||
llhs, lrhs := lhs.LHS().Expr(), lhs.RHS().TypeExpr()
|
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 {
|
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) {
|
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 {
|
if op != t.KeyXBinaryGreaterEq && op != t.KeyXBinaryGreaterThan {
|
||||||
return x, nil
|
return x, nil
|
||||||
}
|
}
|
||||||
@@ -259,11 +259,11 @@ func (q *checker) optimizeIOMethodAdvance(n *a.Expr, receiver *a.Expr, advance *
|
|||||||
|
|
||||||
// Check that lhs is "receiver.available()".
|
// Check that lhs is "receiver.available()".
|
||||||
lhs := x.LHS().Expr()
|
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
|
return x, nil
|
||||||
}
|
}
|
||||||
lhs = lhs.LHS().Expr()
|
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
|
return x, nil
|
||||||
}
|
}
|
||||||
lhs = lhs.LHS().Expr()
|
lhs = lhs.LHS().Expr()
|
||||||
|
|||||||
+43
-43
@@ -349,7 +349,7 @@ func (q *checker) tcheckExpr(n *a.Expr, depth uint32) error {
|
|||||||
}
|
}
|
||||||
depth++
|
depth++
|
||||||
|
|
||||||
switch n.ID0().Flags() & (t.FlagsUnaryOp | t.FlagsBinaryOp | t.FlagsAssociativeOp) {
|
switch n.Operator().Flags() & (t.FlagsUnaryOp | t.FlagsBinaryOp | t.FlagsAssociativeOp) {
|
||||||
case 0:
|
case 0:
|
||||||
if err := q.tcheckExprOther(n, depth); err != nil {
|
if err := q.tcheckExprOther(n, depth); err != nil {
|
||||||
return err
|
return err
|
||||||
@@ -367,16 +367,16 @@ func (q *checker) tcheckExpr(n *a.Expr, depth uint32) error {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
default:
|
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()
|
n.Node().SetTypeChecked()
|
||||||
return nil
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func (q *checker) tcheckExprOther(n *a.Expr, depth uint32) error {
|
func (q *checker) tcheckExprOther(n *a.Expr, depth uint32) error {
|
||||||
switch n.ID0().Key() {
|
switch n.Operator().Key() {
|
||||||
case 0:
|
case 0:
|
||||||
id1 := n.ID1()
|
id1 := n.Ident()
|
||||||
if id1.IsNumLiteral() {
|
if id1.IsNumLiteral() {
|
||||||
z := big.NewInt(0)
|
z := big.NewInt(0)
|
||||||
s := id1.Str(q.tm)
|
s := id1.Str(q.tm)
|
||||||
@@ -443,7 +443,7 @@ func (q *checker) tcheckExprOther(n *a.Expr, depth uint32) error {
|
|||||||
return err
|
return err
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
if n.ID0().Key() == t.KeyTry {
|
if n.Operator().Key() == t.KeyTry {
|
||||||
// TODO: be more principled about inferring "try etc"'s type.
|
// TODO: be more principled about inferring "try etc"'s type.
|
||||||
n.SetMType(typeExprStatus)
|
n.SetMType(typeExprStatus)
|
||||||
} else {
|
} else {
|
||||||
@@ -521,12 +521,12 @@ func (q *checker) tcheckExprOther(n *a.Expr, depth uint32) error {
|
|||||||
return q.tcheckDot(n, depth)
|
return q.tcheckDot(n, depth)
|
||||||
|
|
||||||
case t.KeyError, t.KeyStatus, t.KeySuspension:
|
case t.KeyError, t.KeyStatus, t.KeySuspension:
|
||||||
nominalKeyword := n.ID0()
|
nominalKeyword := n.Operator()
|
||||||
declaredKeyword := t.ID(0)
|
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()
|
declaredKeyword = s.Status.Keyword()
|
||||||
} else {
|
} else {
|
||||||
msg, _ := t.Unescape(n.ID1().Str(q.tm))
|
msg, _ := t.Unescape(n.Ident().Str(q.tm))
|
||||||
z, ok := builtin.StatusMap[msg]
|
z, ok := builtin.StatusMap[msg]
|
||||||
if !ok {
|
if !ok {
|
||||||
return fmt.Errorf("check: no error or status with message %q", msg)
|
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",
|
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 {
|
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
|
// TODO: figure out calls with and without "?" should interact with the out
|
||||||
// type.
|
// type.
|
||||||
if n.ID0().Key() == t.KeyTry {
|
if n.Operator().Key() == t.KeyTry {
|
||||||
n.SetMType(typeExprStatus)
|
n.SetMType(typeExprStatus)
|
||||||
} else {
|
} else {
|
||||||
outFields := f.Out().Fields()
|
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 &&
|
callSuspendible := methodName != t.KeySinceMark &&
|
||||||
methodName != t.KeyMark &&
|
methodName != t.KeyMark &&
|
||||||
methodName != t.KeyLimit
|
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
|
return false
|
||||||
}
|
}
|
||||||
n = n.LHS().Expr()
|
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
|
return false
|
||||||
}
|
}
|
||||||
n = n.LHS().Expr()
|
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
|
return false
|
||||||
}
|
}
|
||||||
n = n.LHS().Expr()
|
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 {
|
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.KeyMark &&
|
||||||
methodName != t.KeyLimit
|
methodName != t.KeyLimit
|
||||||
// TODO: check that n.Args() is "(x:bar)".
|
// 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
|
return false
|
||||||
}
|
}
|
||||||
n = n.LHS().Expr()
|
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
|
return false
|
||||||
}
|
}
|
||||||
n = n.LHS().Expr()
|
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
|
return false
|
||||||
}
|
}
|
||||||
n = n.LHS().Expr()
|
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.
|
// isThatMethod matches foo.methodName(etc) where etc has nArgs elements.
|
||||||
func isThatMethod(tm *t.Map, n *a.Expr, methodName t.Key, nArgs int) bool {
|
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
|
return false
|
||||||
}
|
}
|
||||||
if len(n.Args()) != nArgs {
|
if len(n.Args()) != nArgs {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
n = n.LHS().Expr()
|
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
|
return false
|
||||||
}
|
}
|
||||||
n = n.LHS().Expr()
|
n = n.LHS().Expr()
|
||||||
if n.ID0().Key() == t.KeyDot &&
|
if n.Operator().Key() == t.KeyDot &&
|
||||||
(n.ID1() == tm.ByName("src") || n.ID1() == tm.ByName("dst")) {
|
(n.Ident() == tm.ByName("src") || n.Ident() == tm.ByName("dst")) {
|
||||||
return false
|
return false
|
||||||
}
|
}
|
||||||
return true
|
return true
|
||||||
@@ -683,7 +683,7 @@ func (q *checker) tcheckDot(n *a.Expr, depth uint32) error {
|
|||||||
}
|
}
|
||||||
lTyp := lhs.MType().Pointee()
|
lTyp := lhs.MType().Pointee()
|
||||||
lQID := lTyp.QID()
|
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 {
|
if key := lTyp.Decorator().Key(); key == t.KeyColon {
|
||||||
// lTyp is a slice.
|
// 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 {
|
if f, err := q.c.builtInSliceFunc(qqid); err != nil {
|
||||||
return err
|
return err
|
||||||
} else if f == nil {
|
} 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
|
return nil
|
||||||
} else if key != 0 {
|
} else if key != 0 {
|
||||||
return fmt.Errorf("check: invalid type %q for dot-expression LHS %q", lTyp.Str(q.tm), lhs.Str(q.tm))
|
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))
|
qqid[0].Str(q.tm), lTyp.Str(q.tm), lhs.Str(q.tm))
|
||||||
} else if u.funcs[qqid] == nil {
|
} else if u.funcs[qqid] == nil {
|
||||||
return fmt.Errorf("check: no method named %q found in type %q for expression %q",
|
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
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -720,7 +720,7 @@ func (q *checker) tcheckDot(n *a.Expr, depth uint32) error {
|
|||||||
f = q.c.funcs[qqid].Func
|
f = q.c.funcs[qqid].Func
|
||||||
}
|
}
|
||||||
if f != nil {
|
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
|
return nil
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -743,7 +743,7 @@ func (q *checker) tcheckDot(n *a.Expr, depth uint32) error {
|
|||||||
if s != nil {
|
if s != nil {
|
||||||
for _, field := range s.Fields() {
|
for _, field := range s.Fields() {
|
||||||
f := field.Field()
|
f := field.Field()
|
||||||
if f.Name() == n.ID1() {
|
if f.Name() == n.Ident() {
|
||||||
n.SetMType(f.XType())
|
n.SetMType(f.XType())
|
||||||
return nil
|
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",
|
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 {
|
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()
|
rTyp := rhs.MType()
|
||||||
|
|
||||||
switch n.ID0().Key() {
|
switch n.Operator().Key() {
|
||||||
case t.KeyXUnaryPlus, t.KeyXUnaryMinus:
|
case t.KeyXUnaryPlus, t.KeyXUnaryMinus:
|
||||||
if !rTyp.IsNumTypeOrIdeal() {
|
if !rTyp.IsNumTypeOrIdeal() {
|
||||||
return fmt.Errorf("check: unary %q: %q, of type %q, does not have a numeric type",
|
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 cv := rhs.ConstValue(); cv != nil {
|
||||||
if n.ID0().Key() == t.KeyXUnaryMinus {
|
if n.Operator().Key() == t.KeyXUnaryMinus {
|
||||||
cv = neg(cv)
|
cv = neg(cv)
|
||||||
}
|
}
|
||||||
n.SetConstValue(cv)
|
n.SetConstValue(cv)
|
||||||
@@ -779,7 +779,7 @@ func (q *checker) tcheckExprUnaryOp(n *a.Expr, depth uint32) error {
|
|||||||
case t.KeyXUnaryNot:
|
case t.KeyXUnaryNot:
|
||||||
if !rTyp.IsBool() {
|
if !rTyp.IsBool() {
|
||||||
return fmt.Errorf("check: unary %q: %q, of type %q, does not have a boolean type",
|
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 {
|
if cv := rhs.ConstValue(); cv != nil {
|
||||||
n.SetConstValue(btoi(cv.Cmp(zero) == 0))
|
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())
|
n.SetMType(rTyp.Inner())
|
||||||
return nil
|
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 {
|
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
|
return err
|
||||||
}
|
}
|
||||||
lTyp := lhs.MType()
|
lTyp := lhs.MType()
|
||||||
op := n.ID0()
|
op := n.Operator()
|
||||||
if op.Key() == t.KeyXBinaryAs {
|
if op.Key() == t.KeyXBinaryAs {
|
||||||
rhs := n.RHS().TypeExpr()
|
rhs := n.RHS().TypeExpr()
|
||||||
if err := q.tcheckTypeExpr(rhs, 0); err != nil {
|
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) {
|
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:
|
case t.KeyXBinaryPlus:
|
||||||
return big.NewInt(0).Add(l, r), nil
|
return big.NewInt(0).Add(l, r), nil
|
||||||
case t.KeyXBinaryMinus:
|
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:
|
case t.KeyXBinaryTildePlus:
|
||||||
return nil, fmt.Errorf("check: cannot apply ~+ operator to ideal numbers")
|
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 {
|
func (q *checker) tcheckExprAssociativeOp(n *a.Expr, depth uint32) error {
|
||||||
switch n.ID0().Key() {
|
switch n.Operator().Key() {
|
||||||
case t.KeyXAssociativePlus, t.KeyXAssociativeStar,
|
case t.KeyXAssociativePlus, t.KeyXAssociativeStar,
|
||||||
t.KeyXAssociativeAmp, t.KeyXAssociativePipe, t.KeyXAssociativeHat:
|
t.KeyXAssociativeAmp, t.KeyXAssociativePipe, t.KeyXAssociativeHat:
|
||||||
|
|
||||||
@@ -989,7 +989,7 @@ func (q *checker) tcheckExprAssociativeOp(n *a.Expr, depth uint32) error {
|
|||||||
}
|
}
|
||||||
if !oTyp.IsNumType() {
|
if !oTyp.IsNumType() {
|
||||||
return fmt.Errorf("check: associative %q: %q, of type %q, does not have a numeric type",
|
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 {
|
if typ == nil {
|
||||||
expr, typ = o, oTyp.Unrefined()
|
expr, typ = o, oTyp.Unrefined()
|
||||||
@@ -998,7 +998,7 @@ func (q *checker) tcheckExprAssociativeOp(n *a.Expr, depth uint32) error {
|
|||||||
if !typ.EqIgnoringRefinements(oTyp) {
|
if !typ.EqIgnoringRefinements(oTyp) {
|
||||||
return fmt.Errorf("check: associative %q: %q and %q, of types %q and %q, "+
|
return fmt.Errorf("check: associative %q: %q and %q, of types %q and %q, "+
|
||||||
"do not have compatible types",
|
"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.Str(q.tm), o.Str(q.tm),
|
||||||
expr.MType().Str(q.tm), o.MType().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() {
|
if !o.MType().IsBool() {
|
||||||
return fmt.Errorf("check: associative %q: %q, of type %q, does not have a boolean type",
|
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)
|
n.SetMType(typeExprBool)
|
||||||
return nil
|
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 {
|
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 {
|
if err != nil {
|
||||||
return nil, err
|
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`,
|
return nil, fmt.Errorf(`parse: expected function call after "try", got %q at %s:%d`,
|
||||||
call.Str(p.tm), p.filename, p.line())
|
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
|
call.LHS(), call.MHS(), call.RHS(), call.Args()), nil
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in new issue
Block a user