示例#1
0
        private CodeExpression TranslateToLinq(CodeExpression projection, CompFor compFor)
        {
            var e            = compFor.collection.Accept(this);
            var queryClauses = new List <CodeQueryClause>();

            From(compFor.variable, e, queryClauses);
            var iter = compFor.next;

            while (iter != null)
            {
                if (iter is CompIf filter)
                {
                    e = filter.test.Accept(this);
                    queryClauses.Add(m.Where(e));
                }
                else if (iter is CompFor join)
                {
                    e = join.collection.Accept(this);
                    From(join.variable, e, queryClauses);
                }
                iter = iter.next;
            }
            queryClauses.Add(m.Select(projection));
            return(m.Query(queryClauses.ToArray()));
        }
示例#2
0
        private bool IsIdentityProjection(CompFor compFor, Exp projection)
        {
            var idV = compFor.variable as Identifier;
            var idP = projection as Identifier;

            return(idV != null && idP != null && idV.Name == idP.Name);
        }
示例#3
0
        private CodeExpression Translate(CodeExpression v, CompFor compFor)
        {
            var c = compFor.collection.Accept(this);

            if (compFor.next != null)
            {
                if (compFor.next is CompIf filter)
                {
                    return(Where(c, v, filter.test.Accept(this)));
                }
                if (compFor.next is CompFor join)
                {
                    //var pySrc = "((a, s) for a in stackframe.alocs.values() for s in a._segment_list)";
                    //string sExp = "stackframe.alocs.SelectMany(aa => aa._segment_list, (a, s) => Tuple.Create( a, s ))";
                    return(m.Appl(
                               m.MethodRef(c, "SelectMany"),
                               m.Lambda(
                                   new CodeExpression[] { ((Identifier)compFor.variable).Accept(this) },
                                   join.collection.Accept(this)),
                               m.Lambda(
                                   new CodeExpression[] {
                        ((Identifier)compFor.variable).Accept(this),
                        ((Identifier)join.variable).Accept(this)
                    },
                                   m.Appl(
                                       m.MethodRef(
                                           m.TypeRefExpr("Tuple"),
                                           "Create"),
                                       ((Identifier)compFor.variable).Accept(this),
                                       ((Identifier)join.variable).Accept(this)))));
                }
            }
            return(c);
        }
示例#4
0
        public DataType VisitCompFor(CompFor f)
        {
            var it = f.variable.Accept(this);

            scope.BindIterator(analyzer, f.variable, f.collection, it, BindingKind.SCOPE);
            //f.visit(node.ifs, s);
            return(f.variable.Accept(this));
        }
示例#5
0
 public CodeExpression VisitCompFor(CompFor f)
 {
     throw new NotImplementedException();
     //var v = compFor.variable.Accept(this);
     //var c = Translate(v, compFor);
     //var mr = new CodeMethodReferenceExpression(c, "Select");
     //var s = m.Appl(mr, new CodeExpression[] {
     //            m.Lambda(
     //                new CodeExpression[] { v },
     //                a.name.Accept(this))
     //        });
     //return s;
 }
示例#6
0
 public void VisitCompFor(CompFor f)
 {
     throw new NotImplementedException();
 }
示例#7
0
 public void VisitCompFor(CompFor f)
 {
     throw new NotImplementedException();
 }