Пример #1
0
        public void AssignmentAnalyzer_Quote()
        {
            var x = Expression.Parameter(typeof(int));

            var b =
                Expression.Block(
                    new[] { x },
                    Expression.Quote(Expression.Lambda <Func <int> >(x))
                    );

            var analyze = new AssignmentAnalyzer(b.Variables);

            var res = analyze.Visit(b.Expressions);

            Assert.AreSame(b.Expressions, res);

            Assert.AreEqual(0, analyze.Unassigned.Count);
        }
Пример #2
0
        public void AssignmentAnalyzer_RuntimeVariables()
        {
            var x = Expression.Parameter(typeof(int));

            var b =
                Expression.Block(
                    new[] { x },
                    Expression.RuntimeVariables(x)
                    );

            var analyze = new AssignmentAnalyzer(b.Variables);

            var res = analyze.Visit(b.Expressions);

            Assert.AreSame(b.Expressions, res);

            Assert.AreEqual(0, analyze.Unassigned.Count);
        }
Пример #3
0
        public void AssignmentAnalyzer_Unassigned()
        {
            var x = Expression.Parameter(typeof(int));

            var b =
                Expression.Block(
                    new[] { x },
                    x
                    );

            var analyze = new AssignmentAnalyzer(b.Variables);

            var res = analyze.Visit(b.Expressions);

            Assert.AreSame(b.Expressions, res);

            Assert.IsTrue(new[] { x }.SequenceEqual(analyze.Unassigned));
        }
Пример #4
0
        public void AssignmentAnalyzer_Assign()
        {
            var x = Expression.Parameter(typeof(int));

            var b =
                Expression.Block(
                    new[] { x },
                    Expression.Constant(0),
                    Expression.Assign(x, Expression.Constant(1)),
                    Expression.Constant(2)
                    );

            var analyze = new AssignmentAnalyzer(b.Variables);

            var res = analyze.Visit(b.Expressions);

            Assert.AreSame(b.Expressions, res);

            Assert.AreEqual(0, analyze.Unassigned.Count);
        }
Пример #5
0
        public void AssignmentAnalyzer_ByRef()
        {
            var read = typeof(Volatile).GetMethod(nameof(Volatile.Read), new[] { typeof(int).MakeByRefType() });

            var x = Expression.Parameter(typeof(int));

            var b =
                Expression.Block(
                    new[] { x },
                    Expression.Constant(0),
                    Expression.Call(read, x),
                    Expression.Constant(2)
                    );

            var analyze = new AssignmentAnalyzer(b.Variables);

            var res = analyze.Visit(b.Expressions);

            Assert.AreSame(b.Expressions, res);

            Assert.AreEqual(0, analyze.Unassigned.Count);
        }