示例#1
0
        public void CombineOneTwoLevelAndOneOneLevelFunctions2()
        {
            var q1 = new GeneratedCode();
            var q2 = new GeneratedCode();

            var f1 = QMFuncUtils.GenerateFunction();
            var r1 = DeclarableParameter.CreateDeclarableParameterExpression(typeof(int));
            var s1 = new Statements.StatementAssign(r1, new Variables.ValSimple(f1.Name + "()", typeof(int)));
            var f2 = GenerateFunction2();
            var r2 = DeclarableParameter.CreateDeclarableParameterExpression(typeof(int));
            var s2 = new Statements.StatementAssign(r2, new Variables.ValSimple(f2[1].Name + "()", typeof(int)));

            q1.Add(f1);
            q1.Add(s1);
            q1.SetResult(r1);

            q2.Add(f2[0]);
            q2.Add(f2[1]);
            q2.Add(s2);
            q2.SetResult(r2);

            var target = new CombinedGeneratedCode();

            target.AddGeneratedCode(q1);
            target.AddGeneratedCode(q2);

            target.DumpCodeToConsole();

            Assert.AreEqual(2, target.Functions.Count(), "# of functions should be combined to 2");
            Assert.AreEqual(1, target.QueryCode().Count(), "# of query code blocks");
            Assert.AreEqual(2, target.QueryCode().First().Statements.Count(), "# of statements in the combined block.");
            Assert.IsFalse(target.DumpCode().Where(l => l.Contains(f2[0].Name)).Any(), "The new function was still in there");
        }
示例#2
0
        private QMFuncSource[] GenerateFunction2()
        {
            var fsub = QMFuncUtils.GenerateFunction();

            int[] ints = new int[10];
            var   h    = new QMFuncHeader()
            {
                Arguments = new object[] { }, QM = new QueryModel(new MainFromClause("i", typeof(int), Expression.Constant(ints)), new SelectClause(Expression.Constant(10)))
            };

            h.QMText = h.QM.ToString();
            var f = new QMFuncSource(h);

            var p           = DeclarableParameter.CreateDeclarableParameterExpression(typeof(int));
            var st          = new StatementAssign(p, new ValSimple(fsub.Name + "()", typeof(int)));
            var inlineblock = new StatementInlineBlock();

            inlineblock.Add(st);
            inlineblock.Add(new StatementReturn(p));
            f.SetCodeBody(inlineblock);

            return(new QMFuncSource[] { fsub, f });
        }