Пример #1
0
        internal override MSA.Expression /*!*/ TransformRead(AstGenerator /*!*/ gen)
        {
            // variable assigned to the transformed block in MakeCallWithBlockRetryable:
            MSA.Expression blockArgVariable = gen.CurrentScope.DefineHiddenVariable("#super-call-block", typeof(Proc));

            // invoke super member action:
            var siteBuilder = new CallSiteBuilder(gen, gen.CurrentSelfVariable, blockArgVariable);

            // arguments:
            if (HasImplicitArguments)
            {
                // MRI 1.8: If a block is called via define_method stub its parameters are used here.
                // MRI 1.9: This scenario is not supported.
                // We don't support this either. Otherwise we would need to emit super call with dynamic parameters if gen.CurrentBlock != null.

                if (gen.CurrentMethod.Parameters != null)
                {
                    gen.CurrentMethod.Parameters.TransformForSuperCall(gen, siteBuilder);
                }
                else if (gen.CompilerOptions.TopLevelParameterNames != null)
                {
                    bool     hasUnsplat = gen.CompilerOptions.TopLevelHasUnsplatParameter;
                    string[] names      = gen.CompilerOptions.TopLevelParameterNames;

                    // dynamic lookup:
                    for (int i = 0; i < names.Length - (hasUnsplat ? 1 : 0); i++)
                    {
                        siteBuilder.Add(Methods.GetLocalVariable.OpCall(gen.CurrentScopeVariable, AstUtils.Constant(names[i])));
                    }
                    if (hasUnsplat)
                    {
                        siteBuilder.SplattedArgument =
                            Methods.GetLocalVariable.OpCall(gen.CurrentScopeVariable, AstUtils.Constant(names[names.Length - 1]));
                    }
                }
                else
                {
                    // this means we are not inside any method scope -> an exception will be thrown at the call site
                }
            }
            else
            {
                Arguments.TransformToCall(gen, siteBuilder);
            }

            // block:
            MSA.Expression transformedBlock;
            if (Block != null)
            {
                transformedBlock = Block.Transform(gen);
            }
            else
            {
                transformedBlock = gen.MakeMethodBlockParameterRead();
            }

            return(gen.DebugMark(
                       MethodCall.MakeCallWithBlockRetryable(gen,
                                                             siteBuilder.MakeSuperCallAction(gen.CurrentFrame.UniqueId, HasImplicitArguments),
                                                             blockArgVariable,
                                                             transformedBlock,
                                                             Block != null && Block.IsDefinition
                                                             ),
                       "#RB: super call ('" + gen.CurrentMethod.MethodName + "')"
                       ));
        }