Beispiel #1
0
        public override 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);
                    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);
                }
            }
        }
Beispiel #2
0
        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);
                }
            }
        }
Beispiel #3
0
        public override void LeaveGeneratorExpression(GeneratorExpression node)
        {
            var collector = new ForeignReferenceCollector();
            collector.CurrentType = (IType) AstUtil.GetParentClass(node).Entity;
            collector.Visit(node);

            var processor = new GeneratorExpressionProcessor(Context, collector, node);
            processor.Run();
            ReplaceCurrentNode(processor.CreateEnumerableConstructorInvocation());
        }
Beispiel #4
0
        override public void LeaveGeneratorExpression(GeneratorExpression node)
        {
            using (ForeignReferenceCollector collector = new ForeignReferenceCollector())
            {
                collector.CurrentType = (IType)AstUtil.GetParentClass(node).Entity;
                collector.Initialize(_context);
                collector.Visit(node);

                GeneratorExpressionProcessor processor = new GeneratorExpressionProcessor(_context, collector, node);
                processor.Run();
                ReplaceCurrentNode(processor.CreateEnumerableConstructorInvocation());
            }
        }