Exemplo n.º 1
0
        public static ImmutableArray <T> SubstituteExplicitInterfaceImplementations <T>(ImmutableArray <T> unsubstitutedExplicitInterfaceImplementations, TypeMap map) where T : Symbol
        {
            var builder = ArrayBuilder <T> .GetInstance();

            foreach (var unsubstitutedPropertyImplemented in unsubstitutedExplicitInterfaceImplementations)
            {
                var unsubstitutedInterfaceType = unsubstitutedPropertyImplemented.ContainingType;
                Debug.Assert((object)unsubstitutedInterfaceType != null);
                var explicitInterfaceType = map.SubstituteNamedType(unsubstitutedInterfaceType);
                Debug.Assert((object)explicitInterfaceType != null);
                var name = unsubstitutedPropertyImplemented.Name; //should already be unqualified

                T substitutedMemberImplemented = null;
                foreach (var candidateMember in explicitInterfaceType.GetMembers(name))
                {
                    if (candidateMember.OriginalDefinition == unsubstitutedPropertyImplemented.OriginalDefinition)
                    {
                        substitutedMemberImplemented = (T)candidateMember;
                        break;
                    }
                }
                Debug.Assert((object)substitutedMemberImplemented != null); //if it was an explicit implementation before the substitution, it should still be after
                builder.Add(substitutedMemberImplemented);
            }

            return(builder.ToImmutableAndFree());
        }
Exemplo n.º 2
0
 internal override NamedTypeSymbol GetEffectiveBaseClass(
     ConsList <TypeParameterSymbol> inProgress
     )
 {
     return(_map.SubstituteNamedType(
                _underlyingTypeParameter.GetEffectiveBaseClass(inProgress)
                ));
 }
 internal FieldSymbol DefineCallSiteStorageSymbol(NamedTypeSymbol containerDefinition, NamedTypeSymbol delegateTypeOverMethodTypeParameters, TypeMap methodToContainerTypeParametersMap)
 {
     var fieldName = GeneratedNames.MakeDynamicCallSiteFieldName(_callSiteIdDispenser++);
     var delegateTypeOverContainerTypeParameters = methodToContainerTypeParametersMap.SubstituteNamedType(delegateTypeOverMethodTypeParameters);
     var callSiteType = _factory.Compilation.GetWellKnownType(WellKnownType.System_Runtime_CompilerServices_CallSite_T).Construct(new[] { delegateTypeOverContainerTypeParameters });
     var field = new SynthesizedFieldSymbol(containerDefinition, callSiteType, fieldName, isPublic: true, isStatic: true);
     _factory.AddField(containerDefinition, field);
     return _currentDynamicCallSiteContainer.IsGenericType ? field.AsMember(_currentDynamicCallSiteContainer) : field;
 }
Exemplo n.º 4
0
 private static FieldSymbol SubstituteField(FieldSymbol field, TypeMap typeMap)
 {
     Debug.Assert(!field.IsStatic);
     Debug.Assert(!field.IsReadOnly);
     Debug.Assert(field.CustomModifiers.Length == 0);
     // CONSIDER: Instead of digging fields out of the unsubstituted type and then performing substitution
     // on each one individually, we could dig fields out of the substituted type.
     return new EEDisplayClassFieldSymbol(typeMap.SubstituteNamedType(field.ContainingType), field.Name, typeMap.SubstituteType(field.Type));
 }
Exemplo n.º 5
0
        private NamedTypeSymbol GetFixedDelegate(NamedTypeSymbol delegateType)
        {
            Debug.Assert((object)delegateType != null);
            Debug.Assert(delegateType.IsDelegateType());

            // We have a delegate where the input types use no unfixed parameters.  Create
            // a substitution context; we can substitute unfixed parameters for themselves
            // since they don't actually occur in the inputs.  (They may occur in the outputs,
            // or there may be input parameters fixed to _unfixed_ method type variables.
            // Both of those scenarios are legal.)

            var fixedArguments = ArrayBuilder<TypeWithModifiers>.GetInstance(_methodTypeParameters.Length);
            for (int iParam = 0; iParam < _methodTypeParameters.Length; iParam++)
            {
                fixedArguments.Add(new TypeWithModifiers(IsUnfixed(iParam) ? _methodTypeParameters[iParam] : _fixedResults[iParam]));
            }

            TypeMap typeMap = new TypeMap(_constructedContainingTypeOfMethod, _methodTypeParameters, fixedArguments.ToImmutableAndFree());
            return typeMap.SubstituteNamedType(delegateType);
        }
Exemplo n.º 6
0
        internal EENamedTypeSymbol(
            NamespaceSymbol container,
            NamedTypeSymbol baseType,
            CSharpSyntaxNode syntax,
            MethodSymbol currentFrame,
            string typeName,
            Func<MethodSymbol, EENamedTypeSymbol, ImmutableArray<MethodSymbol>> getMethods)
        {
            _container = container;
            _baseType = baseType;
            _syntax = syntax;
            _name = typeName;

            // What we want is to map all original type parameters to the corresponding new type parameters
            // (since the old ones have the wrong owners).  Unfortunately, we have a circular dependency:
            //   1) Each new type parameter requires the entire map in order to be able to construct its constraint list.
            //   2) The map cannot be constructed until all new type parameters exist.
            // Our solution is to pass each new type parameter a lazy reference to the type map.  We then 
            // initialize the map as soon as the new type parameters are available - and before they are 
            // handed out - so that there is never a period where they can require the type map and find
            // it uninitialized.

            var sourceType = currentFrame.ContainingType;
            this.SourceTypeParameters = sourceType.GetAllTypeParameters();

            TypeMap typeMap = null;
            var getTypeMap = new Func<TypeMap>(() => typeMap);
            _typeParameters = this.SourceTypeParameters.SelectAsArray(
                (tp, i, arg) => (TypeParameterSymbol)new EETypeParameterSymbol(this, tp, i, getTypeMap),
                (object)null);

            typeMap = new TypeMap(this.SourceTypeParameters, _typeParameters);

            VerifyTypeParameters(this, _typeParameters);

            this.SubstitutedSourceType = typeMap.SubstituteNamedType(sourceType);
            TypeParameterChecker.Check(this.SubstitutedSourceType, _typeParameters);

            _methods = getMethods(currentFrame, this);
        }