mirror of
https://github.com/ddidderr/wuffs.git
synced 2026-11-22 16:47:28 +01:00
Add some ast.Expr.IsEtc methods
This commit is contained in:
1 parent
b645180357
commit
41e407a774
7 files changed
+58
-48
No files matched your search
+7
-21
@@ -356,15 +356,8 @@ func (q *checker) bcheckStatement(n *a.Node) error {
|
||||
|
||||
func (q *checker) hasIsErrorFact(id t.ID) bool {
|
||||
for _, x := range q.facts {
|
||||
if (x.Operator() != t.IDOpenParen) || (len(x.Args()) != 0) {
|
||||
continue
|
||||
}
|
||||
x = x.LHS().AsExpr()
|
||||
if (x.Operator() != t.IDDot) || (x.Ident() != t.IDIsError) {
|
||||
continue
|
||||
}
|
||||
x = x.LHS().AsExpr()
|
||||
if (x.Operator() != 0) || (x.Ident() != id) {
|
||||
if lhs, meth, args, _ := x.IsMethodCall(); (meth != t.IDIsError) || (len(args) != 0) ||
|
||||
(lhs.Operator() != 0) || (lhs.Ident() != id) {
|
||||
continue
|
||||
}
|
||||
return true
|
||||
@@ -525,16 +518,16 @@ func (q *checker) bcheckAssignment(lhs *a.Expr, op t.ID, rhs *a.Expr) error {
|
||||
}
|
||||
|
||||
// Look for "lhs = x[i .. j]" where i and j are constants.
|
||||
if rhs.Operator() == t.IDDotDot {
|
||||
if _, i, j, ok := rhs.IsSlice(); ok {
|
||||
icv := (*big.Int)(nil)
|
||||
if i := rhs.MHS().AsExpr(); i == nil {
|
||||
if i == nil {
|
||||
icv = zero
|
||||
} else if i.ConstValue() != nil {
|
||||
icv = i.ConstValue()
|
||||
}
|
||||
|
||||
jcv := (*big.Int)(nil)
|
||||
if j := rhs.RHS().AsExpr(); (j != nil) && (j.ConstValue() != nil) {
|
||||
if (j != nil) && (j.ConstValue() != nil) {
|
||||
jcv = j.ConstValue()
|
||||
}
|
||||
|
||||
@@ -1265,15 +1258,8 @@ func (q *checker) bcheckExprCallSpecialCases(n *a.Expr, depth uint32) (bounds, e
|
||||
|
||||
func (q *checker) canUndoByte(recv *a.Expr) error {
|
||||
for _, x := range q.facts {
|
||||
if x.Operator() != t.IDOpenParen || len(x.Args()) != 0 {
|
||||
continue
|
||||
}
|
||||
x = x.LHS().AsExpr()
|
||||
if x.Operator() != t.IDDot || x.Ident() != t.IDCanUndoByte {
|
||||
continue
|
||||
}
|
||||
x = x.LHS().AsExpr()
|
||||
if !x.Eq(recv) {
|
||||
if lhs, meth, args, _ := x.IsMethodCall(); (meth != t.IDCanUndoByte) || (len(args) != 0) ||
|
||||
!lhs.Eq(recv) {
|
||||
continue
|
||||
}
|
||||
return q.facts.update(func(o *a.Expr) (*a.Expr, error) {
|
||||
|
||||
+6
-5
@@ -391,12 +391,13 @@ func (c *Checker) checkConst(node *a.Node) error {
|
||||
func (c *Checker) checkConstElement(n *a.Expr, nb bounds, nLists int) error {
|
||||
if nLists > 0 {
|
||||
nLists--
|
||||
if n.Operator() != t.IDComma {
|
||||
if args, ok := n.IsList(); !ok {
|
||||
return fmt.Errorf("invalid const value %q", n.Str(c.tm))
|
||||
}
|
||||
for _, o := range n.Args() {
|
||||
if err := c.checkConstElement(o.AsExpr(), nb, nLists); err != nil {
|
||||
return err
|
||||
} else {
|
||||
for _, o := range args {
|
||||
if err := c.checkConstElement(o.AsExpr(), nb, nLists); err != nil {
|
||||
return err
|
||||
}
|
||||
}
|
||||
}
|
||||
return nil
|
||||
|
||||
@@ -55,16 +55,16 @@ func (q *checker) optimizeIOMethodAdvance(receiver *a.Expr, advance *big.Int, ad
|
||||
|
||||
// Check if receiver looks like "a[i .. j]" where i and j are constants and
|
||||
// ((j - i) >= advance).
|
||||
if receiver.Operator() == t.IDDotDot {
|
||||
if _, i, j, ok := receiver.IsSlice(); ok {
|
||||
icv := (*big.Int)(nil)
|
||||
if i := receiver.MHS().AsExpr(); i == nil {
|
||||
if i == nil {
|
||||
icv = zero
|
||||
} else if i.ConstValue() != nil {
|
||||
icv = i.ConstValue()
|
||||
}
|
||||
|
||||
jcv := (*big.Int)(nil)
|
||||
if j := receiver.RHS().AsExpr(); (j != nil) && (j.ConstValue() != nil) {
|
||||
if (j != nil) && (j.ConstValue() != nil) {
|
||||
jcv = j.ConstValue()
|
||||
}
|
||||
|
||||
|
||||
Reference in new issue
Block a user