예제 #1
0
        private IEnumerable <object> ResolveExpression(Expression expr, IVariable declaration)
        {
            Contract.Requires(expr != null);

            if (expr is BinaryExpr)
            {
                BinaryExpr bexp = expr as BinaryExpr;
                switch (bexp.Op)
                {
                case BinaryExpr.Opcode.In:
                    NameSegment var = bexp.E0 as NameSegment;
                    Contract.Assert(var != null, Error.MkErr(bexp, 6, declaration.Name));
                    Contract.Assert(var.Name == declaration.Name, Error.MkErr(bexp, 6, var.Name));
                    foreach (var result in ResolveExpression(bexp.E1))
                    {
                        if (result is IEnumerable)
                        {
                            dynamic resultList = result;
                            foreach (var item in resultList)
                            {
                                yield return(item);
                            }
                        }
                    }
                    yield break;

                case BinaryExpr.Opcode.And:
                    // for each item in the resolved lhs of the expression
                    foreach (var item in ResolveExpression(bexp.E0, declaration))
                    {
                        Atomic copy = Copy();
                        copy.AddLocal(declaration, item);
                        // resolve the rhs expression
                        foreach (var res in copy.ResolveExpression(bexp.E1))
                        {
                            LiteralExpr lit = res as LiteralExpr;
                            // sanity check
                            Contract.Assert(lit != null, Error.MkErr(expr, 17));
                            if (lit.Value is bool)
                            {
                                // if resolved to true
                                if ((bool)lit.Value)
                                {
                                    yield return(item);
                                }
                            }
                        }
                    }
                    yield break;
                }
            }
        }