Ejemplo n.º 1
0
        public void DoEmitBlock()
        {
            if (BlockStatement.Parent is MethodDeclaration)
            {
                var methodDeclaration = (MethodDeclaration)BlockStatement.Parent;
                if (!methodDeclaration.ReturnType.IsNull)
                {
                    var rr = Emitter.Resolver.ResolveNode(methodDeclaration.ReturnType);
                    ReturnType = rr.Type;
                }
                ConvertParamsToReferences(methodDeclaration.Parameters);
            }
            else if (BlockStatement.Parent is AnonymousMethodExpression)
            {
                var methodDeclaration = (AnonymousMethodExpression)BlockStatement.Parent;
                var rr = Emitter.Resolver.ResolveNode(methodDeclaration);
                ReturnType = rr.Type;
                ConvertParamsToReferences(methodDeclaration.Parameters);
            }
            else if (BlockStatement.Parent is LambdaExpression)
            {
                var methodDeclaration = (LambdaExpression)BlockStatement.Parent;
                var rr = Emitter.Resolver.ResolveNode(methodDeclaration);
                ReturnType = rr.Type;
                ConvertParamsToReferences(methodDeclaration.Parameters);
            }
            else if (BlockStatement.Parent is ConstructorDeclaration)
            {
                ConvertParamsToReferences(((ConstructorDeclaration)BlockStatement.Parent).Parameters);
            }
            else if (BlockStatement.Parent is OperatorDeclaration)
            {
                ConvertParamsToReferences(((OperatorDeclaration)BlockStatement.Parent).Parameters);
            }
            else if (BlockStatement.Parent is Accessor)
            {
                var role = BlockStatement.Parent.Role.ToString();

                if (role == "Setter")
                {
                    ConvertParamsToReferences(new ParameterDeclaration[] { new ParameterDeclaration {
                                                                               Name = "value"
                                                                           } });
                }
                else if (role == "Getter")
                {
                    var methodDeclaration = (Accessor)BlockStatement.Parent;
                    if (!methodDeclaration.ReturnType.IsNull)
                    {
                        var rr = Emitter.Resolver.ResolveNode(methodDeclaration.ReturnType);
                        ReturnType = rr.Type;
                    }
                }
            }

            if (IsMethodBlock && YieldBlock.HasYield(BlockStatement))
            {
                IsYield = true;
            }

            if (IsMethodBlock)
            {
                OldReturnType      = Emitter.ReturnType;
                Emitter.ReturnType = ReturnType;
            }

            if (Emitter.BeforeBlock != null)
            {
                Emitter.BeforeBlock();
                Emitter.BeforeBlock = null;
            }

            var ra = ReachabilityAnalysis.Create(BlockStatement, Emitter.Resolver.Resolver);

            BlockStatement.Children.ToList().ForEach(child =>
            {
                if (child is Statement statement && !ra.IsReachable(statement))
                {
                    return;
                }

                child.AcceptVisitor(Emitter);
            });
        }