private static NamedTypeSymbol CreateCallSiteContainer(SyntheticBoundNodeFactory factory)
        {
            // TODO (tomat): consider - why do we need to include a method name at all? We could save some metadata bytes by not including it.
            // Dev11 uses an empty string for explicit interface method implementation:
            var containerName = GeneratedNames.MakeDynamicCallSiteContainerName(
                factory.TopLevelMethod.IsExplicitInterfaceImplementation ? "" : factory.TopLevelMethod.Name, factory.CompilationState.GenerateTempNumber());

            var synthesizedContainer = new SynthesizedContainer(factory.TopLevelMethod, containerName, TypeKind.Class);

            factory.AddNestedType(synthesizedContainer);

            if (factory.TopLevelMethod.IsGenericMethod)
            {
                return(synthesizedContainer.Construct(factory.TopLevelMethod.TypeParameters.Cast <TypeParameterSymbol, TypeSymbol>()));
            }

            return(synthesizedContainer);
        }
        private BoundStatement GenerateKickoffMethodBody()
        {
            F.CurrentFunction = method;
            var bodyBuilder = ArrayBuilder <BoundStatement> .GetInstance();

            var         frameType            = method.IsGenericMethod ? stateMachineType.Construct(method.TypeArgumentsWithAnnotations, unbound: false) : stateMachineType;
            LocalSymbol stateMachineVariable = F.SynthesizedLocal(frameType, null);

            InitializeStateMachine(bodyBuilder, frameType, stateMachineVariable);

            // plus code to initialize all of the parameter proxies result.proxy
            var proxies = PreserveInitialParameterValuesAndThreadId ? initialParameters : nonReusableLocalProxies;

            bodyBuilder.Add(GenerateStateMachineCreation(stateMachineVariable, frameType, proxies));

            return(F.Block(
                       ImmutableArray.Create(stateMachineVariable),
                       bodyBuilder.ToImmutableAndFree()));
        }
Exemplo n.º 3
0
        private BoundStatement GenerateKickoffMethodBody()
        {
            F.CurrentFunction = method;
            var bodyBuilder = ArrayBuilder <BoundStatement> .GetInstance();

            var         frameType            = method.IsGenericMethod ? stateMachineType.Construct(method.TypeArguments, unbound: false) : stateMachineType;
            LocalSymbol stateMachineVariable = F.SynthesizedLocal(frameType, null);

            InitializeStateMachine(bodyBuilder, frameType, stateMachineVariable);

            // plus code to initialize all of the parameter proxies result.proxy
            var proxies = PreserveInitialParameterValuesAndThreadId ? initialParameters : nonReusableLocalProxies;

            // starting with the "this" proxy
            if (!method.IsStatic)
            {
                Debug.Assert((object)method.ThisParameter != null);

                CapturedSymbolReplacement proxy;
                if (proxies.TryGetValue(method.ThisParameter, out proxy))
                {
                    bodyBuilder.Add(F.Assignment(proxy.Replacement(F.Syntax, frameType1 => F.Local(stateMachineVariable)), F.This()));
                }
            }

            foreach (var parameter in method.Parameters)
            {
                CapturedSymbolReplacement proxy;
                if (proxies.TryGetValue(parameter, out proxy))
                {
                    bodyBuilder.Add(F.Assignment(proxy.Replacement(F.Syntax, frameType1 => F.Local(stateMachineVariable)),
                                                 F.Parameter(parameter)));
                }
            }

            bodyBuilder.Add(GenerateStateMachineCreation(stateMachineVariable, frameType));
            return(F.Block(
                       ImmutableArray.Create(stateMachineVariable),
                       bodyBuilder.ToImmutableAndFree()));
        }
Exemplo n.º 4
0
        private BoundStatement ReplaceOriginalMethod()
        {
            F.CurrentMethod = method;
            var bodyBuilder = ArrayBuilder <BoundStatement> .GetInstance();

            var         frameType            = method.IsGenericMethod ? stateMachineClass.Construct(method.TypeArguments) : stateMachineClass;
            LocalSymbol stateMachineVariable = F.SynthesizedLocal(frameType, null);

            InitializeStateMachine(bodyBuilder, frameType, stateMachineVariable);

            // plus code to initialize all of the parameter proxies result.proxy
            Dictionary <Symbol, CapturedSymbolReplacement> copyDest = PreserveInitialLocals ? initialParameters : variableProxies;

            // starting with the "this" proxy
            if (!method.IsStatic)
            {
                Debug.Assert((object)method.ThisParameter != null);

                CapturedSymbolReplacement proxy;
                if (copyDest.TryGetValue(method.ThisParameter, out proxy))
                {
                    bodyBuilder.Add(F.Assignment(proxy.Replacement(F.Syntax, frameType1 => F.Local(stateMachineVariable)), F.This()));
                }
            }

            foreach (var parameter in method.Parameters)
            {
                CapturedSymbolReplacement proxy;
                if (copyDest.TryGetValue(parameter, out proxy))
                {
                    bodyBuilder.Add(F.Assignment(proxy.Replacement(F.Syntax, frameType1 => F.Local(stateMachineVariable)),
                                                 F.Parameter(parameter)));
                }
            }

            bodyBuilder.Add(GenerateReplacementBody(stateMachineVariable, frameType));
            return(F.Block(
                       ImmutableArray.Create <LocalSymbol>(stateMachineVariable),
                       bodyBuilder.ToImmutableAndFree()));
        }