protected SynthesizedContainer(string name, int parameterCount, bool returnsVoid) { Debug.Assert(name != null); _name = name; _typeMap = TypeMap.Empty; _typeParameters = CreateTypeParameters(parameterCount, returnsVoid); }
private SubstitutedParameterSymbol(Symbol containingSymbol, TypeMap map, ParameterSymbol originalParameter) : base(originalParameter) { Debug.Assert(originalParameter.IsDefinition); _containingSymbol = containingSymbol; _mapOrType = map; }
protected SynthesizedContainer(string name, MethodSymbol topLevelMethod) { Debug.Assert(name != null); Debug.Assert(topLevelMethod != null); _name = name; _typeMap = TypeMap.Empty.WithAlphaRename(topLevelMethod, this, out _typeParameters); }
protected SynthesizedContainer(string name, ImmutableArray<TypeParameterSymbol> typeParameters, TypeMap typeMap) { Debug.Assert(name != null); Debug.Assert(!typeParameters.IsDefault); Debug.Assert(typeMap != null); _name = name; _typeParameters = typeParameters; _typeMap = typeMap; }
internal SubstitutedTypeParameterSymbol(Symbol newContainer, TypeMap map, TypeParameterSymbol substitutedFrom) { _container = newContainer; // it is important that we don't use the map here in the constructor, as the map is still being filled // in by TypeMap.WithAlphaRename. Instead, we can use the map lazily when yielding the constraints. _map = map; _substitutedFrom = substitutedFrom; #if DEBUG_ALPHA _mySequence = _nextSequence++; #endif }
protected SubstitutedNamedTypeSymbol(Symbol newContainer, TypeMap map, NamedTypeSymbol originalDefinition, NamedTypeSymbol constructedFrom = null, bool unbound = false) { Debug.Assert(originalDefinition.IsDefinition); _originalDefinition = originalDefinition; _newContainer = newContainer; _inputMap = map; _unbound = unbound; // if we're substituting to create a new unconstructed type as a member of a constructed type, // then we must alpha rename the type parameters. if ((object)constructedFrom != null) { Debug.Assert(ReferenceEquals(constructedFrom.ConstructedFrom, constructedFrom)); _lazyTypeParameters = constructedFrom.TypeParameters; _lazyMap = map; } }
protected SubstitutedMethodSymbol(NamedTypeSymbol containingSymbol, TypeMap map, MethodSymbol originalDefinition, MethodSymbol constructedFrom) { Debug.Assert(originalDefinition.IsDefinition); _containingType = containingSymbol; this.originalDefinition = originalDefinition; _inputMap = map; if ((object)constructedFrom != null) { _constructedFrom = constructedFrom; Debug.Assert(ReferenceEquals(constructedFrom.ConstructedFrom, constructedFrom)); _lazyTypeParameters = constructedFrom.TypeParameters; _lazyMap = map; } else { _constructedFrom = this; } }
private TypeMap WithAlphaRename(ImmutableArray<TypeParameterSymbol> oldTypeParameters, Symbol newOwner, out ImmutableArray<TypeParameterSymbol> newTypeParameters) { if (oldTypeParameters.Length == 0) { newTypeParameters = ImmutableArray<TypeParameterSymbol>.Empty; return this; } // Note: the below assertion doesn't hold while rewriting async lambdas defined inside generic methods. // The async rewriter adds a synthesized struct inside the lambda frame and construct a typemap from // the lambda frame's substituted type parameters. // Debug.Assert(!oldTypeParameters.Any(tp => tp is SubstitutedTypeParameterSymbol)); // warning: we expose result to the SubstitutedTypeParameterSymbol constructor, below, even before it's all filled in. TypeMap result = new TypeMap(this.Mapping); ArrayBuilder<TypeParameterSymbol> newTypeParametersBuilder = ArrayBuilder<TypeParameterSymbol>.GetInstance(); // The case where it is "synthesized" is when we're creating type parameters for a synthesized (generic) // class or method for a lambda appearing in a generic method. bool synthesized = !ReferenceEquals(oldTypeParameters[0].ContainingSymbol.OriginalDefinition, newOwner.OriginalDefinition); foreach (var tp in oldTypeParameters) { var newTp = synthesized ? new SynthesizedSubstitutedTypeParameterSymbol(newOwner, result, tp) : new SubstitutedTypeParameterSymbol(newOwner, result, tp); result.Mapping.Add(tp, new TypeWithModifiers(newTp)); newTypeParametersBuilder.Add(newTp); } newTypeParameters = newTypeParametersBuilder.ToImmutableAndFree(); return result; }
internal SubstitutedParameterSymbol(PropertySymbol containingSymbol, TypeMap map, ParameterSymbol originalParameter) : this((Symbol)containingSymbol, map, originalParameter) { }
internal override TypeSymbol SubstituteTypeParameters( PEModuleSymbol moduleSymbol, TypeSymbol genericTypeDef, ImmutableArray <KeyValuePair <TypeSymbol, ImmutableArray <ModifierInfo <TypeSymbol> > > > arguments, ImmutableArray <bool> refersToNoPiaLocalType) { if (genericTypeDef is UnsupportedMetadataTypeSymbol) { return(genericTypeDef); } // Let's return unsupported metadata type if any argument is unsupported metadata type foreach (var arg in arguments) { if (arg.Key.Kind == SymbolKind.ErrorType && arg.Key is UnsupportedMetadataTypeSymbol) { return(new UnsupportedMetadataTypeSymbol()); } } NamedTypeSymbol genericType = (NamedTypeSymbol)genericTypeDef; //// See if it is or its enclosing type is a non-interface closed over NoPia local types. //ImmutableArray<AssemblySymbol> linkedAssemblies = moduleSymbol.ContainingAssembly.GetLinkedReferencedAssemblies(); //bool noPiaIllegalGenericInstantiation = false; //if (!linkedAssemblies.IsDefaultOrEmpty || moduleSymbol.Module.ContainsNoPiaLocalTypes()) //{ // NamedTypeSymbol typeToCheck = genericType; // int argumentIndex = refersToNoPiaLocalType.Length - 1; // do // { // if (!typeToCheck.IsInterface) // { // break; // } // else // { // argumentIndex -= typeToCheck.Arity; // } // typeToCheck = typeToCheck.ContainingType; // } // while ((object)typeToCheck != null); // for (int i = argumentIndex; i >= 0; i--) // { // if (refersToNoPiaLocalType[i] || // (!linkedAssemblies.IsDefaultOrEmpty && // MetadataDecoder.IsOrClosedOverATypeFromAssemblies(arguments[i].Key, linkedAssemblies))) // { // noPiaIllegalGenericInstantiation = true; // break; // } // } //} // Collect generic parameters for the type and its containers in the order // that matches passed in arguments, i.e. sorted by the nesting. ImmutableArray <TypeParameterSymbol> typeParameters = genericType.GetAllTypeParameters(); Debug.Assert(typeParameters.Length > 0); if (typeParameters.Length != arguments.Length) { return(new UnsupportedMetadataTypeSymbol()); } TypeMap substitution = new TypeMap(typeParameters, arguments.SelectAsArray(arg => new TypeWithModifiers(arg.Key, CSharpCustomModifier.Convert(arg.Value)))); NamedTypeSymbol constructedType = substitution.SubstituteNamedType(genericType); //if (noPiaIllegalGenericInstantiation) //{ // constructedType = new NoPiaIllegalGenericInstantiationSymbol(moduleSymbol, constructedType); //} return(constructedType); }
protected SynthesizedContainer(string name, ImmutableArray <TypeParameterSymbol> typeParameters, TypeMap typeMap) { Debug.Assert(name != null); Debug.Assert(!typeParameters.IsDefault); Debug.Assert(typeMap != null); _name = name; _typeParameters = typeParameters; _typeMap = typeMap; }