Пример #1
0
        IUnboundExpr IPatternVisitor <IUnboundExpr> .Visit(TuplePattern expr)
        {
            var tupleDecl = (BoundTupleType)mDecl;

            // match each field
            var match = (IUnboundExpr)null;

            for (int i = 0; i < tupleDecl.Fields.Count; i++)
            {
                mC.SetPosition(expr.Fields[i].Position);

                // create an expression to pull out the tuple field
                var fieldValue = mC.Call(mC.Int(i), mValue);

                // match it
                var matchField = Match(mContext, tupleDecl.Fields[i], expr.Fields[i],
                                       fieldValue, mVariables);

                if (match == null)
                {
                    match = matchField;
                }
                else
                {
                    // combine with the previous matches
                    match = mC.Op(match, "&", matchField);
                }
            }

            return(match);
        }
Пример #2
0
        bool IPatternVisitor <bool> .Visit(TuplePattern expr)
        {
            var tuple = mType as BoundTupleType;

            // it must be a tuple
            if (tuple == null)
            {
                throw new CompileException(expr.Position,
                                           String.Format("A tuple pattern cannot be used to match against a value of type {0}.", mType));
            }

            // if must be the right length
            if (tuple.Fields.Count != expr.Fields.Count)
            {
                throw new CompileException(expr.Position,
                                           String.Format("The tuple pattern has {0} fields when {1} are expected.", expr.Fields.Count, tuple.Fields.Count));
            }

            // the fields must match for
            for (int i = 0; i < expr.Fields.Count; i++)
            {
                expr.Fields[i].Accept(new ShapeChecker(tuple.Fields[i], mUsedVariables));
            }

            return(true);
        }
Пример #3
0
 bool IPatternVisitor <bool> .Visit(TuplePattern expr)
 {
     //### bob: coverage for tuples is not supported yet
     // so this just does nothing
     return(false);
 }