Пример #1
0
 internal override IEnumerable <FieldSymbol> GetFieldsToEmit()
 {
     foreach (FieldSymbol f in _underlyingType.GetFieldsToEmit())
     {
         yield return(this.RetargetingTranslator.Retarget(f));
     }
 }
Пример #2
0
 private static IReadOnlyDictionary<string, ImmutableArray<Symbol>> GetTypeMembers(NamedTypeSymbol type)
 {
     var members = ArrayBuilder<Symbol>.GetInstance();
     members.AddRange(type.GetEventsToEmit());
     members.AddRange(type.GetFieldsToEmit());
     members.AddRange(type.GetMethodsToEmit());
     members.AddRange(type.GetTypeMembers());
     members.AddRange(type.GetPropertiesToEmit());
     var result = members.ToDictionary(s => s.Name, NameComparer);
     members.Free();
     return result;
 }
Пример #3
0
            private IReadOnlyDictionary <string, ImmutableArray <Cci.ITypeDefinitionMember> > GetOtherTypeMembers(NamedTypeSymbol otherType)
            {
                var members = ArrayBuilder <Cci.ITypeDefinitionMember> .GetInstance();

                members.AddRange(otherType.GetEventsToEmit());
                members.AddRange(otherType.GetFieldsToEmit());
                members.AddRange(otherType.GetMethodsToEmit());
                members.AddRange(otherType.GetTypeMembers());
                members.AddRange(otherType.GetPropertiesToEmit());

                ImmutableArray <Cci.ITypeDefinitionMember> synthesizedMembers;

                if (_otherSynthesizedMembersOpt != null && _otherSynthesizedMembersOpt.TryGetValue(otherType, out synthesizedMembers))
                {
                    members.AddRange(synthesizedMembers);
                }

                var result = members.ToDictionary(s => ((Symbol)s).Name, StringOrdinalComparer.Instance);

                members.Free();
                return(result);
            }
Пример #4
0
        private EmbeddedType EmbedType(
            NamedTypeSymbol namedType,
            bool fromImplements,
            SyntaxNode syntaxNodeOpt,
            DiagnosticBag diagnostics)
        {
            Debug.Assert(namedType.IsDefinition);

            var          adapter  = namedType.GetCciAdapter();
            EmbeddedType embedded = new EmbeddedType(this, adapter);
            EmbeddedType cached   = EmbeddedTypesMap.GetOrAdd(adapter, embedded);

            bool isInterface = (namedType.IsInterface);

            if (isInterface && fromImplements)
            {
                // Note, we must use 'cached' here because we might drop 'embedded' below.
                cached.EmbedAllMembersOfImplementedInterface(syntaxNodeOpt, diagnostics);
            }

            if (embedded != cached)
            {
                return(cached);
            }

            // We do not expect this method to be called on a different thread once GetTypes is called.
            // Therefore, the following check can be as simple as:
            Debug.Assert(!IsFrozen, "Set of embedded types is frozen.");

            var noPiaIndexer = new Cci.TypeReferenceIndexer(new EmitContext(ModuleBeingBuilt, syntaxNodeOpt, diagnostics, metadataOnly: false, includePrivateMembers: true));

            // Make sure we embed all types referenced by the type declaration: implemented interfaces, etc.
            noPiaIndexer.VisitTypeDefinitionNoMembers(embedded);

            if (!isInterface)
            {
                Debug.Assert(namedType.TypeKind == TypeKind.Struct || namedType.TypeKind == TypeKind.Enum || namedType.TypeKind == TypeKind.Delegate);
                // For structures, enums and delegates we embed all members.

                if (namedType.TypeKind == TypeKind.Struct || namedType.TypeKind == TypeKind.Enum)
                {
                    // TODO: When building debug versions in the IDE, the compiler will insert some extra members
                    // that support ENC. These make no sense in local types, so we will skip them. We have to
                    // check for them explicitly or they will trip the member-validity check that follows.
                }

                foreach (FieldSymbol f in namedType.GetFieldsToEmit())
                {
                    EmbedField(embedded, f.GetCciAdapter(), syntaxNodeOpt, diagnostics);
                }

                foreach (MethodSymbol m in namedType.GetMethodsToEmit())
                {
                    if ((object)m != null)
                    {
                        EmbedMethod(embedded, m.GetCciAdapter(), syntaxNodeOpt, diagnostics);
                    }
                }

                // We also should embed properties and events, but we don't need to do this explicitly here
                // because accessors embed them automatically.
            }

            return(embedded);
        }