示例#1
0
        public void Equality_Default()
        {
            var a = new IndexAccessExpression();
            var b = new IndexAccessExpression();

            Assert.AreEqual(a, b);
            Assert.AreEqual(a.GetHashCode(), b.GetHashCode());
        }
示例#2
0
        public void DefaultValues()
        {
            var sut = new IndexAccessExpression();

            Assert.AreEqual(new VariableReference(), sut.Reference);
            Assert.AreEqual(Lists.NewList <ISimpleExpression>(), sut.Indices);
            Assert.AreNotEqual(0, sut.GetHashCode());
            Assert.AreNotEqual(1, sut.GetHashCode());
        }
        public void IndexAccessExpression()
        {
            var sst = new IndexAccessExpression
            {
                Reference = VarRef("arr"),
                Indices   = { new ConstantValueExpression {
                                  Value = "1"
                              } }
            };

            AssertPrint(sst, "arr[1]");
        }
示例#4
0
        public void SettingValues()
        {
            var sut = new IndexAccessExpression
            {
                Reference = SomeVarRef(),
                Indices   = { new ConstantValueExpression() }
            };

            Assert.AreEqual(SomeVarRef(), sut.Reference);
            Assert.AreEqual(new KaVEList <ISimpleExpression> {
                new ConstantValueExpression()
            }, sut.Indices);
        }
示例#5
0
        public void Equality_ReallyTheSame()
        {
            var a = new IndexAccessExpression
            {
                Reference = SomeVarRef(),
                Indices   = { new ConstantValueExpression() }
            };

            var b = new IndexAccessExpression
            {
                Reference = SomeVarRef(),
                Indices   = { new ConstantValueExpression() }
            };

            Assert.AreEqual(a, b);
            Assert.AreEqual(a.GetHashCode(), b.GetHashCode());
        }
示例#6
0
        public void Equality_DifferentIndex()
        {
            var a = new IndexAccessExpression
            {
                Reference = SomeVarRef(),
                Indices   = { new ConstantValueExpression {
                                  Value = "1"
                              } }
            };

            var b = new IndexAccessExpression
            {
                Reference = SomeVarRef(),
                Indices   = { new ConstantValueExpression {
                                  Value = "2"
                              } }
            };

            Assert.AreNotEqual(a, b);
            Assert.AreNotEqual(a.GetHashCode(), b.GetHashCode());
        }
示例#7
0
        public void VisitorWithReturnIsImplemented()
        {
            var sut = new IndexAccessExpression();

            sut.Accept(23).VerifyWithReturn(v => v.Visit(sut, 23));
        }
示例#8
0
        IProperty ResolveIndexAccessExpression(IStackFrame frame, IndexAccessExpression exp, uint dwTimeout)
        {
            IProperty body = Resolve(frame, exp.Body, dwTimeout);
            IProperty prop = null;

            if (body != null)
            {
                VariableReference reference = body.GetVariableReference();
                if (reference != null)
                {
                    uint threadHash;

                    if (reference.Type < VariableTypes.Error)
                    {
                        var idxExp            = exp.Index;
                        VariableReference idx = null;
                        if (idxExp is NameExpression)
                        {
                            int idxInt;
                            var content = ((NameExpression)idxExp).Content;
                            if (content == "true")
                            {
                                idx = VariableReference.True;
                            }
                            else if (content == "false")
                            {
                                idx = VariableReference.False;
                            }
                            else if (content == "null")
                            {
                                idx = VariableReference.Null;
                            }
                            else if (int.TryParse(content, out idxInt))
                            {
                                idx = VariableReference.GetInteger(idxInt);
                            }
                            else
                            {
                                var info = ResolveNameExpression(frame, (NameExpression)idxExp, dwTimeout);
                                idx = info.GetVariableReference();
                            }
                        }
                        else if (idxExp is StringLiteralExpression)
                        {
                            idx = VariableReference.GetString(((StringLiteralExpression)idxExp).Content);
                        }
                        else
                        {
                            var info = Resolve(frame, idxExp, dwTimeout);
                            idx = info.GetVariableReference();
                        }
                        if (idx != null && idx.Type < VariableTypes.Error)
                        {
                            if (exp.IsRoot)
                            {
                                var info = ResolveIndexAccess(reference, idx, frame.ThreadID, frame.Index, dwTimeout);
                                prop            = CreateProperty(frame, info);
                                prop.Parent     = body;
                                prop.Parameters = new VariableReference[] { idx };
                            }
                            else
                            {
                                var info = VariableInfo.FromObject(null);
                                info.Type       = VariableTypes.IndexAccess;
                                prop            = CreateProperty(frame, info);
                                prop.Parent     = body;
                                prop.Parameters = new VariableReference[] { idx };
                            }
                        }
                    }
                }
            }
            else
            {
                prop = CreateProperty(frame, VariableInfo.NullReferenceExeption);
            }
            return(prop);
        }