override public void LeaveBlockExpression(BlockExpression node) { InternalMethod closureEntity = (InternalMethod)GetEntity(node); using (ForeignReferenceCollector collector = new ForeignReferenceCollector()) { collector.CurrentMethod = closureEntity.Method; collector.CurrentType = (IType)closureEntity.DeclaringType; collector.Initialize(_context); collector.Visit(closureEntity.Method.Body); if (collector.ContainsForeignLocalReferences) { BooClassBuilder closureClass = CreateClosureClass(collector, closureEntity); collector.AdjustReferences(); ReplaceCurrentNode( CodeBuilder.CreateMemberReference( collector.CreateConstructorInvocationWithReferencedEntities( closureClass.Entity), closureEntity)); } else { Expression expression = CodeBuilder.CreateMemberReference(closureEntity); TypeSystemServices.GetConcreteExpressionType(expression); ReplaceCurrentNode(expression); } } }
public override void LeaveBlockExpression(BlockExpression node) { var closureEntity = GetEntity(node) as InternalMethod; if (closureEntity == null) { return; } var collector = new ForeignReferenceCollector(); { collector.CurrentMethod = closureEntity.Method; collector.CurrentType = closureEntity.DeclaringType; closureEntity.Method.Body.Accept(collector); if (collector.ContainsForeignLocalReferences) { BooClassBuilder closureClass = CreateClosureClass(collector, closureEntity); if (closureEntity is InternalGenericMethod) { closureEntity = GetEntity(closureEntity.Method) as InternalMethod; } closureClass.ClassDefinition.LexicalInfo = node.LexicalInfo; collector.AdjustReferences(); if (_mapper != null) { closureClass.ClassDefinition.Accept(new GenericTypeMapper(_mapper)); } ReplaceCurrentNode( CodeBuilder.CreateMemberReference( collector.CreateConstructorInvocationWithReferencedEntities( closureClass.Entity, node.GetAncestor <Method>()), closureEntity)); } else { _mapper = closureEntity.Method["GenericMapper"] as GeneratorTypeReplacer; if (_mapper != null) { closureEntity.Method.Accept(new GenericTypeMapper(_mapper)); } IMethod entity = closureEntity; if (entity.GenericInfo != null) { entity = MapGenericMethod(entity, node.GetAncestor <Method>().GenericParameters); } Expression expression = CodeBuilder.CreateMemberReference(entity); expression.LexicalInfo = node.LexicalInfo; TypeSystemServices.GetConcreteExpressionType(expression); ReplaceCurrentNode(expression); } } }
override public void LeaveBlockExpression(BlockExpression node) { var closureEntity = GetEntity(node) as InternalMethod; if (closureEntity == null) { return; } var collector = new ForeignReferenceCollector(); { collector.CurrentMethod = closureEntity.Method; collector.CurrentType = (IType)closureEntity.DeclaringType; closureEntity.Method.Body.Accept(collector); if (collector.ContainsForeignLocalReferences) { BooClassBuilder closureClass = CreateClosureClass(collector, closureEntity); closureClass.ClassDefinition.LexicalInfo = node.LexicalInfo; collector.AdjustReferences(); ReplaceCurrentNode( CodeBuilder.CreateMemberReference( collector.CreateConstructorInvocationWithReferencedEntities( closureClass.Entity), closureEntity)); } else { Expression expression = CodeBuilder.CreateMemberReference(closureEntity); expression.LexicalInfo = node.LexicalInfo; TypeSystemServices.GetConcreteExpressionType(expression); ReplaceCurrentNode(expression); } } }
public GeneratorSkeleton SkeletonFor(GeneratorExpression generator, Method enclosingMethod) { return(CreateGeneratorSkeleton(generator, enclosingMethod, TypeSystemServices.GetConcreteExpressionType(generator.Expression))); }