Add an io_writer var to gif's decoder.decode_id

This commit is contained in:
Nigel Tao committed 2018-05-13 10:40:44 +10:00
1 parent 0f32650064
commit 2d3b3b1dae
7 files changed
+47 -15

No files matched your search

+6
View File
@@ -495,6 +495,8 @@ func NewField(name t.ID, xType *TypeExpr, defaultValue *Expr) *Field {
// IOBind is "io_bind (in_fields) { List2 }":
// - List0: <Expr> in.something fields
// - List2: <Statement> body
//
// TODO: in_fields and "in.something" isn't right.
type IOBind Node
func (n *IOBind) Node() *Node { return (*Node)(n) }
@@ -705,6 +707,10 @@ func (n *TypeExpr) IsIdeal() bool {
return n.id0 == 0 && n.id1 == t.IDBase && n.id2 == t.IDDoubleZ
}
func (n *TypeExpr) IsIOType() bool {
return n.id0 == 0 && n.id1 == t.IDBase && (n.id2 == t.IDIOReader || n.id2 == t.IDIOWriter)
}
func (n *TypeExpr) IsNumType() bool {
return n.id0 == 0 && n.id1 == t.IDBase && n.id2.IsNumType()
}
+2 -8
View File
@@ -123,15 +123,9 @@ func (q *checker) tcheckStatement(n *a.Node) error {
if err := q.tcheckExpr(o.Expr(), 0); err != nil {
return err
}
isIOType := false
if typ := o.Expr().MType(); typ.Decorator() == 0 {
if qid := typ.QID(); qid[0] == t.IDBase && (qid[1] == t.IDIOReader || qid[1] == t.IDIOWriter) {
isIOType = true
}
}
if !isIOType {
if typ := o.Expr().MType(); !typ.IsIOType() {
return fmt.Errorf("check: io_bind expression %q, of type %q, does not have an I/O type",
o.Expr().Str(q.tm), o.Expr().MType().Str(q.tm))
o.Expr().Str(q.tm), typ.Str(q.tm))
}
}
for _, o := range n.Body() {
+4 -1
View File
@@ -845,7 +845,10 @@ func (p *parser) parseIOBindExprNode() (*a.Node, error) {
if err != nil {
return nil, err
}
if e.Operator() == t.IDDot {
switch e.Operator() {
case 0:
return e.Node(), nil
case t.IDDot:
if lhs := e.LHS().Expr(); lhs.Operator() == 0 && lhs.Ident() == t.IDIn {
return e.Node(), nil
}