コード例 #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.synthesizedLocalOrdinals = new SynthesizedLocalOrdinalsDispenser();
            this.diagnostics = diagnostics;

            this.F = new SyntheticBoundNodeFactory(method, body.Syntax, compilationState, diagnostics);
            Debug.Assert(F.CurrentType == method.ContainingType);
            Debug.Assert(F.Syntax == body.Syntax);
        }
コード例 #2
0
 internal SynthesizedCapturedVariable(SynthesizedContainer container, Symbol captured, TypeSymbol type)
     : base(container,
            name: IsThis(captured) ? GeneratedNames.IteratorThisProxyName() : captured.Name,
            isPublic: true,
            isReadOnly: false,
            isStatic: false)
 {
     // lifted fields do not need to have the CompilerGeneratedAttribute attached to it, the closure is already
     // marked as being compiler generated.
     this.type   = type;
     this.isThis = IsThis(captured);
 }
コード例 #3
0
 internal SynthesizedCapturedVariable(SynthesizedContainer container, Symbol captured, TypeSymbol type)
     : base(container,
            name: IsThis(captured) ? GeneratedNames.IteratorThisProxyName() : captured.Name,
            isPublic: true,
            isReadOnly: false,
            isStatic: false)
 {
     // lifted fields do not need to have the CompilerGeneratedAttribute attached to it, the closure is already 
     // marked as being compiler generated.
     this.type = type;
     this.isThis = IsThis(captured);
 }
コード例 #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;
        }
コード例 #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);
 }
コード例 #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;
        }
コード例 #7
0
 protected StateMachineRewriter(
     BoundStatement body,
     MethodSymbol method,
     SynthesizedContainer stateMachineClass,
     TypeCompilationState compilationState,
     DiagnosticBag diagnostics)
 {
     this.body = body;
     this.method = method;
     this.stateMachineClass = stateMachineClass;
     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);
 }
コード例 #8
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)
                {
                    // lambdaFrame may have less generic type parameters than frame, so trim them down (the first N will always match)
                    var typeArguments = frame.TypeArgumentsNoUseSiteDiagnostics;
                    if (typeArguments.Length > lambdaFrame.Arity)
                    {
                        typeArguments = ImmutableArray.Create(typeArguments, 0, lambdaFrame.Arity);
                    }
                    return lambdaFrame.ConstructIfGeneric(typeArguments.SelectAsArray(TypeMap.TypeSymbolAsTypeWithModifiers));
                }
            }

            return frame.TypeMap.SubstituteType((object)local != null ? local.Type : ((ParameterSymbol)variable).Type).Type;
        }
コード例 #9
0
 internal LambdaCapturedVariable(SynthesizedContainer frame, Symbol captured)
     : base(frame, captured, GetType(frame, captured))
 {
 }
コード例 #10
0
        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;
        }