Ejemplo n.º 1
0
        public Element Element(ElementExpression node, List <object> parameters)
        {
            var ids = new List <int>();

            foreach (var n in node.Children)
            {
                ids.Add(_interpreter.DispatchInt(n, parameters));
            }
            return(new Element(ids));
        }
Ejemplo n.º 2
0
            public override void VisitElementExpression(ElementExpression node)
            {
                base.VisitElementExpression(node);

                // expressions within the element selector have path scope?
                if (_position >= node.Selector.TriviaStart)
                {
                    _binder._pathScope = node.Expression.ResultType;
                }
            }
Ejemplo n.º 3
0
        public ElementExpression(BinaryExpressionKind kind,
                                 ElementExpression expr1, ElementExpression expr2)
        {
            ArityKind  = ArityKind.Binary;
            UnaryKind  = UnaryExpressionKind.None;
            BinaryKind = kind;

            Expr1 = expr1;
            Expr2 = expr2;
        }
Ejemplo n.º 4
0
        public ElementExpression(ElementExpression test,
                                 ElementExpression ifTrue, ElementExpression ifFalse)
        {
            ArityKind  = ArityKind.Ternary;
            UnaryKind  = UnaryExpressionKind.None;
            BinaryKind = BinaryExpressionKind.None;

            Expr1 = test;
            Expr2 = ifTrue;
            Expr3 = ifFalse;
        }
 public TypeNode VisitElement(ElementExpression n, List <TypeNode> parameterTypes)
 {
     foreach (var c in n.Children)
     {
         var type = _getType(c, parameterTypes).Type;
         if (type != TypeEnum.Integer)
         {
             throw new UnmatchableTypesException(n, TypeEnum.Integer, type);
         }
     }
     return(new TypeNode(TypeEnum.Element, 0, 0));
 }
        internal static void GetGraphExpression(int vertexCount, int edgeCount, int indexCount, out GraphExpression graphExpr, out FunctionNode src, out FunctionNode dst)
        {
            SetExpression        vertexSetExpr = GetSet(indexCount, GetBoundList(indexCount, 1, vertexCount));
            SetExpression        edgeSetExpr   = GetSet(indexCount, GetBoundList(indexCount, 1, edgeCount));
            IdentifierExpression srcId         = GetIdExpression(0, false);
            IdentifierExpression dstId         = GetIdExpression(1, false);

            graphExpr = new GraphExpression(vertexSetExpr, edgeSetExpr, srcId, dstId, 0, 0);
            ElementExpression srcElementExpr = GetElementExpression(GetIntList(1, indexCount));
            ConditionNode     srcCondNode    = GetConditionNode(srcElementExpr, indexCount, 0);

            src = GetElementFunctionNode(srcCondNode);
            ElementExpression dstElementExpr = GetElementExpression(GetIntList(1, indexCount), GetIntListWithValue(indexCount, 1));
            ConditionNode     dstCondNode    = GetConditionNode(dstElementExpr, indexCount, 0);

            dst = GetElementFunctionNode(dstCondNode);
        }
        public void InBoolean_GivenElementAndSet_CorrectValueReturned(int[] a, int[] b, bool expected)
        {
            Element           lhsValue   = new Element(a.ToList());
            Set               rhsValue   = GetSetWith1DElements(b);
            ElementExpression lhs        = new ElementExpression(null, 0, 0);
            SetExpression     rhs        = GetSetInit();
            InExpression      expression = new InExpression(lhs, rhs, 0, 0);

            IInterpreterBoolean parent = Substitute.For <IInterpreterBoolean>();

            DispatchElementForParent(lhsValue, lhs, parent);
            DispatchSetForParent(rhsValue, rhs, parent);
            BooleanHelper booleanHelper = Utilities.GetBooleanHelper(parent);

            bool res = booleanHelper.InBoolean(expression, new List <object>());

            Assert.AreEqual(expected, res);
        }
Ejemplo n.º 8
0
        public static bool StructuralEquals(this ElementExpression expr, ElementExpression other)
        {
            if (expr == null && other == null)
            {
                return(true);
            }

            if (expr.ArityKind != other.ArityKind)
            {
                return(false);
            }

            if (expr.UnaryKind != other.UnaryKind)
            {
                return(false);
            }

            if (expr.BinaryKind != other.BinaryKind)
            {
                return(false);
            }

            if (!expr.Element.StructuralEquals(other.Element))
            {
                return(false);
            }

            if (!expr.Expr1.StructuralEquals(other.Expr1))
            {
                return(false);
            }

            if (!expr.Expr2.StructuralEquals(other.Expr2))
            {
                return(false);
            }

            if (!expr.Expr3.StructuralEquals(other.Expr3))
            {
                return(false);
            }

            return(true);
        }
            public override void VisitElementExpression(ElementExpression node)
            {
                node.Expression.Accept(this);

                // result type of left-side expression is in scope for the element expression inside the brackets.
                var oldPathScope = _binder._pathScope;

                _binder._pathScope = _binder.GetResultTypeOrError(node.Expression);
                try
                {
                    node.Selector.Accept(this);
                }
                finally
                {
                    _binder._pathScope = oldPathScope;
                }

                BindNode(node);
            }
Ejemplo n.º 10
0
        private static ElementExpression Project(ElementExpression expr)
        {
            switch (expr.ArityKind)
            {
            case ArityKind.Element:
                return(new ElementExpression(Project(expr.Element)));

            case ArityKind.Unary:
                return(new ElementExpression(expr.UnaryKind, Project(expr.Expr1)));

            case ArityKind.Binary:
                return(new ElementExpression(expr.BinaryKind, Project(expr.Expr1), Project(expr.Expr2)));

            case ArityKind.Ternary:
                return(new ElementExpression(Project(expr.Expr1), Project(expr.Expr2), Project(expr.Expr3)));

            default:
                throw new NotSupportedException();
            }
        }
        internal static void GetGraphExpression(int vertexCount, int edgeCount, out GraphExpression graphExpr, out FunctionNode src, out FunctionNode dst)
        {
            SetExpression vertexSetExpr = GetSet(1, new List <Tuple <int, int> >()
            {
                new Tuple <int, int>(1, vertexCount)
            });
            SetExpression edgeSetExpr = GetSet(1, new List <Tuple <int, int> >()
            {
                new Tuple <int, int>(1, edgeCount)
            });
            IdentifierExpression srcId = GetIdExpression(0, false);
            IdentifierExpression dstId = GetIdExpression(1, false);

            graphExpr = new GraphExpression(vertexSetExpr, edgeSetExpr, srcId, dstId, 0, 0);
            ElementExpression srcElementExpr = GetElementExpression(1);
            ConditionNode     srcCondNode    = GetConditionNode(srcElementExpr, 1, 0);

            src = GetElementFunctionNode(srcCondNode);
            ElementExpression dstElementExpr = GetElementExpression(1, 1);
            ConditionNode     dstCondNode    = GetConditionNode(dstElementExpr, 1, 0);

            dst = GetElementFunctionNode(dstCondNode);
        }
 private static void DispatchElementForParent(Element elementValue, ElementExpression elementExpression, IInterpreterBoolean parent)
 {
     parent.DispatchElement(elementExpression, Arg.Any <List <object> >()).Returns(elementValue);
 }
Ejemplo n.º 13
0
 public override T VisitElementExpression(ElementExpression node)
 {
     throw new NotImplementedException();
 }