Ejemplo n.º 1
0
        protected StateMachineRewriter(
            BoundStatement body,
            MethodSymbol method,
            SynthesizedContainer stateMachineType,
            VariableSlotAllocator slotAllocatorOpt,
            TypeCompilationState compilationState,
            DiagnosticBag diagnostics)
        {
            Debug.Assert(body != null);
            Debug.Assert(method != null);
            Debug.Assert(stateMachineType != null);
            Debug.Assert(compilationState != null);
            Debug.Assert(diagnostics != null);

            this.body             = body;
            this.method           = method;
            this.stateMachineType = stateMachineType;
            this.slotAllocatorOpt = slotAllocatorOpt;
            this.compilationState = compilationState;
            this.diagnostics      = diagnostics;

            this.F = new SyntheticBoundNodeFactory(method, body.Syntax, compilationState, diagnostics);
            Debug.Assert(F.CurrentClass == method.ContainingType);
            Debug.Assert(F.Syntax == body.Syntax);
        }
Ejemplo n.º 2
0
        protected StateMachineRewriter(
            BoundStatement body,
            MethodSymbol method,
            SynthesizedContainer stateMachineType,
            VariableSlotAllocator slotAllocatorOpt,
            TypeCompilationState compilationState,
            BindingDiagnosticBag diagnostics)
        {
            Debug.Assert(body != null);
            Debug.Assert(method != null);
            Debug.Assert((object)stateMachineType != null);
            Debug.Assert(compilationState != null);
            Debug.Assert(diagnostics != null);
            Debug.Assert(diagnostics.DiagnosticBag != null);

            this.body                     = body;
            this.method                   = method;
            this.stateMachineType         = stateMachineType;
            this.slotAllocatorOpt         = slotAllocatorOpt;
            this.synthesizedLocalOrdinals = new SynthesizedLocalOrdinalsDispenser();
            this.diagnostics              = diagnostics;

            this.F = new SyntheticBoundNodeFactory(method, body.Syntax, compilationState, diagnostics);
            Debug.Assert(TypeSymbol.Equals(F.CurrentType, method.ContainingType, TypeCompareKind.ConsiderEverything2));
            Debug.Assert(F.Syntax == body.Syntax);
        }
Ejemplo n.º 3
0
        private static TypeSymbol GetCapturedVariableFieldType(
            SynthesizedContainer frame,
            Symbol variable
            )
        {
            var local = variable as LocalSymbol;

            if ((object)local != null)
            {
                // if we're capturing a generic frame pointer, construct it with the new frame's type parameters
                var lambdaFrame = local.Type.OriginalDefinition as SynthesizedClosureEnvironment;
                if ((object)lambdaFrame != null)
                {
                    // lambdaFrame may have less generic type parameters than frame, so trim them down (the first N will always match)
                    var typeArguments = frame.TypeArgumentsWithAnnotationsNoUseSiteDiagnostics;
                    if (typeArguments.Length > lambdaFrame.Arity)
                    {
                        typeArguments = ImmutableArray.Create(typeArguments, 0, lambdaFrame.Arity);
                    }

                    return(lambdaFrame.ConstructIfGeneric(typeArguments));
                }
            }

            return(frame.TypeMap.SubstituteType(
                       (
                           (object)local != null
                        ? local.TypeWithAnnotations
                        : ((ParameterSymbol)variable).TypeWithAnnotations
                       ).Type
                       ).Type);
        }
Ejemplo n.º 4
0
        private LambdaCapturedVariable(SynthesizedContainer frame, TypeSymbol type, string fieldName, bool isThisParameter)
            : base(frame,
                   fieldName,
                   isPublic: true,
                   isReadOnly: false,
                   isStatic: false)
        {
            Debug.Assert((object)type != null);

            // lifted fields do not need to have the CompilerGeneratedAttribute attached to it, the closure is already
            // marked as being compiler generated.
            _type   = type;
            _isThis = isThisParameter;
        }
Ejemplo n.º 5
0
        private static TypeSymbol GetType(SynthesizedContainer frame, Symbol captured)
        {
            var local = captured as LocalSymbol;

            if ((object)local != null)
            {
                // if we're capturing a generic frame pointer, construct it with the new frame's type parameters
                var lambdaFrame = local.Type.OriginalDefinition as LambdaFrame;
                if ((object)lambdaFrame != null)
                {
                    return(lambdaFrame.ConstructIfGeneric(frame.TypeArgumentsNoUseSiteDiagnostics));
                }
            }
            return(frame.TypeMap.SubstituteType((object)local != null ? local.Type : ((ParameterSymbol)captured).Type));
        }
Ejemplo n.º 6
0
        private static TypeSymbol GetCapturedVariableFieldType(SynthesizedContainer frame, Symbol variable)
        {
            var local = variable as LocalSymbol;

            if ((object)local != null)
            {
                // if we're capturing a generic frame pointer, construct it with the new frame's type parameters
                var lambdaFrame = local.Type.OriginalDefinition as LambdaFrame;
                if ((object)lambdaFrame != null)
                {
                    return(lambdaFrame.ConstructIfGeneric(frame.TypeArgumentsNoUseSiteDiagnostics.SelectAsArray(TypeMap.TypeSymbolAsTypeWithModifiers)));
                }
            }

            return(frame.TypeMap.SubstituteType((object)local != null ? local.Type : ((ParameterSymbol)variable).Type).Type);
        }
Ejemplo n.º 7
0
 protected StateMachineRewriter(
     BoundStatement body,
     MethodSymbol method,
     SynthesizedContainer stateMachineClass,
     TypeCompilationState compilationState,
     DiagnosticBag diagnostics,
     bool generateDebugInfo)
 {
     this.body              = body;
     this.method            = method;
     this.stateMachineClass = stateMachineClass;
     this.compilationState  = compilationState;
     this.diagnostics       = diagnostics;
     this.generateDebugInfo = generateDebugInfo;
     this.F = new SyntheticBoundNodeFactory(method, body.Syntax, compilationState, diagnostics);
     Debug.Assert(F.CurrentClass == method.ContainingType);
     Debug.Assert(F.Syntax == body.Syntax);
 }
        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);
        }
Ejemplo n.º 9
0
 internal LambdaCapturedVariable(SynthesizedContainer frame, Symbol captured)
     : base(frame, captured, GetType(frame, captured))
 {
 }