Generate C code for "a or b or c".

This commit is contained in:
Nigel Tao committed 2017-06-16 14:35:43 +10:00
1 parent 540274b57d
commit ce2720fca1
5 files changed
+65 -3

No files matched your search

+18
View File
@@ -811,6 +811,24 @@ func (q *checker) bcheckExprBinaryOp(lhs *a.Expr, op t.Key, rhs *a.Expr, depth u
}
func (q *checker) bcheckExprAssociativeOp(n *a.Expr, depth uint32) (*big.Int, *big.Int, error) {
switch n.ID0().Key() {
// TODO.
case t.KeyXAssociativePlus:
case t.KeyXAssociativeStar:
case t.KeyXAssociativeAmp:
case t.KeyXAssociativePipe:
case t.KeyXAssociativeHat:
case t.KeyXAssociativeAnd, t.KeyXAssociativeOr:
for _, o := range n.Args() {
o := o.Expr()
if _, _, err := q.bcheckExpr(o, depth); err != nil {
return nil, nil, err
}
}
return zero, one, nil
}
return nil, nil, fmt.Errorf("check: unrecognized token.Key (0x%X) for bcheckExprAssociativeOp", n.ID0().Key())
}
+22
View File
@@ -657,7 +657,29 @@ func (q *checker) setConstValueBinaryOp(n *a.Expr, l *big.Int, r *big.Int) error
}
func (q *checker) tcheckExprAssociativeOp(n *a.Expr, depth uint32) error {
switch n.ID0().Key() {
// TODO.
case t.KeyXAssociativePlus:
case t.KeyXAssociativeStar:
case t.KeyXAssociativeAmp:
case t.KeyXAssociativePipe:
case t.KeyXAssociativeHat:
case t.KeyXAssociativeAnd, t.KeyXAssociativeOr:
for _, o := range n.Args() {
o := o.Expr()
if err := q.tcheckExpr(o, depth); err != nil {
return err
}
if !o.MType().IsBool() {
return fmt.Errorf("check: associative %q: %q, of type %q, does not have a boolean type",
n.ID0().AmbiguousForm().String(q.tm), o.String(q.tm), o.MType().String(q.tm))
}
}
n.SetMType(typeExprBool)
return nil
}
return fmt.Errorf("check: unrecognized token.Key (0x%X) for tcheckExprAssociativeOp", n.ID0().Key())
}