public virtual Differences VisitApplyToAll(ApplyToAll/*!*/ applyToAll1, ApplyToAll applyToAll2) { Differences differences = new Differences(applyToAll1, applyToAll2); if (applyToAll1 == null || applyToAll2 == null){ if (applyToAll1 != applyToAll2) differences.NumberOfDifferences++; else differences.NumberOfSimilarities++; return differences; } ApplyToAll changes = (ApplyToAll)applyToAll2.Clone(); ApplyToAll deletions = (ApplyToAll)applyToAll2.Clone(); ApplyToAll insertions = (ApplyToAll)applyToAll2.Clone(); Differences diff = this.VisitExpression(applyToAll1.Operand1, applyToAll2.Operand1); if (diff == null){Debug.Assert(false); return differences;} changes.Operand1 = diff.Changes as Expression; deletions.Operand1 = diff.Deletions as Expression; insertions.Operand1 = diff.Insertions as Expression; Debug.Assert(diff.Changes == changes.Operand1 && diff.Deletions == deletions.Operand1 && diff.Insertions == insertions.Operand1); differences.NumberOfDifferences += diff.NumberOfDifferences; differences.NumberOfSimilarities += diff.NumberOfSimilarities; diff = this.VisitExpression(applyToAll1.Operand2, applyToAll2.Operand2); if (diff == null){Debug.Assert(false); return differences;} changes.Operand2 = diff.Changes as Expression; deletions.Operand2 = diff.Deletions as Expression; insertions.Operand2 = diff.Insertions as Expression; Debug.Assert(diff.Changes == changes.Operand2 && diff.Deletions == deletions.Operand2 && diff.Insertions == insertions.Operand2); differences.NumberOfDifferences += diff.NumberOfDifferences; differences.NumberOfSimilarities += diff.NumberOfSimilarities; if (differences.NumberOfDifferences == 0){ differences.Changes = null; differences.Deletions = null; differences.Insertions = null; }else{ differences.Changes = changes; differences.Deletions = deletions; differences.Insertions = insertions; } return differences; }
public virtual Expression VisitApplyToAll(ApplyToAll applyToAll, ApplyToAll changes, ApplyToAll deletions, ApplyToAll insertions){ this.UpdateSourceContext(applyToAll, changes); if (applyToAll == null) return changes; if (changes != null){ if (deletions == null || insertions == null) Debug.Assert(false); else{ applyToAll.Operand1 = this.VisitExpression(applyToAll.Operand1, changes.Operand1, deletions.Operand1, insertions.Operand1); applyToAll.Operand2 = this.VisitExpression(applyToAll.Operand2, changes.Operand2, deletions.Operand2, insertions.Operand2); } }else if (deletions != null) return null; return applyToAll; }
public override Expression VisitApplyToAll(ApplyToAll applyToAll) { if (applyToAll == null) return null; Expression collection = applyToAll.Operand1; if (collection == null) { Debug.Assert(false); return null; } TypeNode elemType = this.typeSystem.GetStreamElementType(collection.Type, this.TypeViewer); bool singleTon = elemType == collection.Type; Local loc = applyToAll.ElementLocal; if (loc == null) loc = new Local(elemType); if (singleTon) applyToAll.Operand1 = this.VisitExpression(collection); else applyToAll.Operand1 = this.VisitEnumerableCollection(collection, loc.Type); if (applyToAll.Operand1 == null) return null; AnonymousNestedFunction func = applyToAll.Operand2 as AnonymousNestedFunction; Expression expr = applyToAll.Operand2 as BlockExpression; if (func != null || expr != null) { this.VisitAnonymousNestedFunction(func); if (singleTon || applyToAll.Type == SystemTypes.Void) return applyToAll; //Create an iterator to compute stream that results from ApplyToAll Class closureClass = this.currentMethod.Scope.ClosureClass; Method method = new Method(); method.Name = Identifier.For("Function:"+method.UniqueKey); method.SourceContext = collection.SourceContext; method.Flags = MethodFlags.CompilerControlled; method.CallingConvention = CallingConventionFlags.HasThis; method.InitLocals = true; method.DeclaringType = closureClass; closureClass.Members.Add(method); method.Scope = new MethodScope(new TypeScope(null, closureClass), null); Parameter coll = new Parameter(StandardIds.Collection, collection.Type); ParameterField fcoll = new ParameterField(method.Scope, null, FieldFlags.CompilerControlled, StandardIds.Collection, collection.Type, null); fcoll.Parameter = coll; method.Scope.Members.Add(fcoll); Parameter closure = new Parameter(StandardIds.Closure, closureClass); ParameterField fclosure = new ParameterField(method.Scope, null, FieldFlags.CompilerControlled, StandardIds.Closure, closureClass, null); fclosure.Parameter = closure; if (func != null) { method.Scope.Members.Add(fclosure); method.Parameters = new ParameterList(coll, closure); } else method.Parameters = new ParameterList(coll); method.ReturnType = applyToAll.Type; ForEach forEach = new ForEach(); forEach.TargetVariable = loc; forEach.TargetVariableType = loc.Type; forEach.SourceEnumerable = new MemberBinding(new ImplicitThis(), fcoll); if (func != null) { MemberBinding mb = new MemberBinding(new MemberBinding(new ImplicitThis(), fclosure), func.Method); expr = new MethodCall(mb, new ExpressionList(loc), NodeType.Call, func.Method.ReturnType, func.SourceContext); } else expr = this.VisitExpression(expr); expr = this.typeSystem.ImplicitCoercion(expr, this.typeSystem.GetStreamElementType(applyToAll.Type, this.TypeViewer), this.TypeViewer); if (expr == null) return null; BlockExpression bExpr = expr as BlockExpression; if (bExpr != null && bExpr.Type == SystemTypes.Void) forEach.Body = bExpr.Block; else forEach.Body = new Block(new StatementList(new Yield(expr))); forEach.ScopeForTemporaryVariables = new BlockScope(method.Scope, forEach.Body); method.Body = new Block(new StatementList(forEach)); applyToAll.ResultIterator = this.VisitMethod(method); return applyToAll; } Debug.Assert(false); return null; }
public virtual Expression VisitApplyToAll(ApplyToAll applyToAll){ if (applyToAll == null) return null; applyToAll.Operand1 = this.VisitExpression(applyToAll.Operand1); applyToAll.Operand2 = this.VisitExpression(applyToAll.Operand2); return applyToAll; }
public override Expression VisitApplyToAll(ApplyToAll applyToAll){ if (applyToAll == null) return null; Expression opnd1 = applyToAll.Operand1 = this.VisitExpression(applyToAll.Operand1); if (opnd1 == null) return null; TypeNode t1 = opnd1.Type; TypeNode elemType = this.typeSystem.GetStreamElementType(t1, this.TypeViewer); AnonymousNestedFunction func = applyToAll.Operand2 as AnonymousNestedFunction; if (func != null && func.Method != null && func.Method.Parameters != null && func.Method.Parameters.Count == 1){ if (func.Method.Parameters[0].Type != null) return applyToAll; //Already visited func.Method.Parameters[0].Type = elemType; applyToAll.Operand2 = this.VisitAnonymousNestedFunction(func); if (func.Method != null && func.Method.ReturnType != null){ if (this.typeSystem.IsVoid(func.Method.ReturnType)) applyToAll.Type = SystemTypes.Void; else{ elemType = this.typeSystem.GetRootType(func.Method.ReturnType, this.TypeViewer); if (elemType != func.Method.ReturnType){ this.HandleError(func, Error.NotYetImplemented, "applying an iterator to each element of stream"); return null; }else applyToAll.Type = SystemTypes.GenericIEnumerable.GetTemplateInstance(this.currentType, func.Method.ReturnType); } return applyToAll; } } Debug.Assert(false); return null; }
public virtual void VisitApplyToAll(ApplyToAll applyToAll) { if (applyToAll == null) return; this.VisitExpression(applyToAll.Operand1); this.VisitExpression(applyToAll.Operand2); }
public override Expression VisitApplyToAll(ApplyToAll applyToAll) { if (applyToAll == null) return null; return base.VisitApplyToAll((ApplyToAll)applyToAll.Clone()); }
public virtual Expression VisitApplyToAll(ApplyToAll applyToAll1, ApplyToAll applyToAll2) { if (applyToAll1 == null) return null; if (applyToAll2 == null) { applyToAll1.Operand1 = this.VisitExpression(applyToAll1.Operand1, null); applyToAll1.Operand2 = this.VisitExpression(applyToAll1.Operand2, null); } else { applyToAll1.Operand1 = this.VisitExpression(applyToAll1.Operand1, applyToAll2.Operand1); applyToAll1.Operand2 = this.VisitExpression(applyToAll1.Operand2, applyToAll2.Operand2); } return applyToAll1; }
public override Expression VisitApplyToAll(ApplyToAll applyToAll){ if (applyToAll == null) return null; CollectionEnumerator cEnumerator = applyToAll.Operand1 as CollectionEnumerator; AnonymousNestedFunction func = applyToAll.Operand2 as AnonymousNestedFunction; if (func != null) this.VisitAnonymousNestedFunction(func); Expression cc = this.currentClosureLocal; if (cEnumerator == null) { Debug.Assert(cc != null, "VisitApplyToAll: no closure"); Debug.Assert(func != null, "VisitApplyToAll: no function"); if (cc == null || func == null) return null; cc = this.GetBindingPath(cc, func.Method.DeclaringType); return new MethodCall(new MemberBinding(cc, func.Method), new ExpressionList(this.VisitExpression(applyToAll.Operand1)), NodeType.Call, func.Method.ReturnType, cc.SourceContext); } Debug.Assert(cEnumerator.Collection != null, "VisitApplyToAll: no collection"); if (cEnumerator.Collection == null) return null; Method method = applyToAll.ResultIterator; if (method != null) { Debug.Assert(cc != null, "VisitApplyToAll: no closure"); if (cc == null) return null; cc = this.GetBindingPath(cc, method.DeclaringType); this.VisitMethod(method); Expression coll = this.VisitExpression(cEnumerator.Collection); if (coll == null) return null; if (func != null) return new MethodCall(new MemberBinding(cc, method), new ExpressionList(coll, cc), NodeType.Call, applyToAll.Type); else return new MethodCall(new MemberBinding(cc, method), new ExpressionList(coll), NodeType.Call, applyToAll.Type); } ForEach forEach = new ForEach(); forEach.SourceContext = applyToAll.SourceContext; forEach.SourceEnumerable = cEnumerator; if (func != null) { MemberBinding mb = new MemberBinding(cc, func.Method); MethodCall call = new MethodCall(mb, new ExpressionList(cEnumerator.ElementLocal), NodeType.Call, func.Method.ReturnType, cc.SourceContext); forEach.Body = new Block(new StatementList(new ExpressionStatement(call))); } else { BlockExpression be = applyToAll.Operand2 as BlockExpression; Debug.Assert(be != null, "VisitApplyToAll: Bad operand type"); if (be == null) return null; Block b = new Block(new StatementList(2)); b.Statements.Add(new AssignmentStatement(applyToAll.ElementLocal, cEnumerator.ElementLocal)); b.Statements.Add(be.Block); forEach.Body = b; } forEach.ScopeForTemporaryVariables = new BlockScope(this.currentMethod.Scope, forEach.Body); return this.VisitBlockExpression(new BlockExpression(new Block(new StatementList(forEach)), SystemTypes.Void)); }