Exemple #1
0
 private static void AddTopLevelType(HashSet <string> names, Cci.INamespaceTypeDefinition type)
 {
     if (names != null)
     {
         names.Add(MetadataHelpers.BuildQualifiedName(type.NamespaceName, Cci.PeWriter.GetMangledName(type)));
     }
 }
Exemple #2
0
 private static void VisitTopLevelType(
     Cci.TypeReferenceIndexer noPiaIndexer,
     Cci.INamespaceTypeDefinition type
     )
 {
     noPiaIndexer?.Visit((Cci.ITypeDefinition)type);
 }
            private Cci.INamespaceTypeDefinition VisitNamespaceType(Cci.INamespaceTypeDefinition def)
            {
                // All generated top-level types are assumed to be in the global namespace.
                // However, this may be an embedded NoPIA type within a namespace.
                // Since we do not support edits that include references to NoPIA types
                // (see #855640), it's reasonable to simply drop such cases.
                if (!string.IsNullOrEmpty(def.NamespaceName))
                {
                    return(null);
                }

                var topLevelTypes = this.GetTopLevelTypesByName();

                Cci.INamespaceTypeDefinition otherDef;
                topLevelTypes.TryGetValue(def.Name, out otherDef);
                return(otherDef);
            }
Exemple #4
0
 private static void VisitTopLevelType(Cci.NoPiaReferenceIndexer noPiaIndexer, Cci.INamespaceTypeDefinition type)
 {
     if (noPiaIndexer != null)
     {
         noPiaIndexer.Visit((Cci.ITypeDefinition)type);
     }
 }
Exemple #5
0
 static void AddTopLevelType(HashSet <string> names, Cci.INamespaceTypeDefinition type)
 // _namesOfTopLevelTypes are only used to generated exported types, which are not emitted in EnC deltas (hence generation 0):
 => names?.Add(MetadataHelpers.BuildQualifiedName(type.NamespaceName, Cci.MetadataWriter.GetMangledName(type, generation: 0)));
Exemple #6
0
        /// <summary>
        /// Returns all top-level (not nested) types defined in the module.
        /// </summary>
        public override IEnumerable <Cci.INamespaceTypeDefinition> GetTopLevelTypes(EmitContext context)
        {
            Cci.NoPiaReferenceIndexer noPiaIndexer = null;
            HashSet <string>          names;

            // First time through, we need to collect emitted names of all top level types.
            if (_namesOfTopLevelTypes == null)
            {
                names = new HashSet <string>();
            }
            else
            {
                names = null;
            }

            // First time through, we need to push things through NoPiaReferenceIndexer
            // to make sure we collect all to be embedded NoPia types and members.
            if (EmbeddedTypesManagerOpt != null && !EmbeddedTypesManagerOpt.IsFrozen)
            {
                noPiaIndexer = new Cci.NoPiaReferenceIndexer(context);
                Debug.Assert(names != null);
                this.Dispatch(noPiaIndexer);
            }
#if XSHARP
            // Replace generation of the _rootModule with the generated
            // <Module> class when available
            Cci.INamespaceTypeDefinition topType = null;
            foreach (var type in this.GetTopLevelTypesCore(context))
            {
                if (String.Equals(type.Name, _rootModuleType.Name))
                {
                    topType = type;
                    AddTopLevelType(names, type);
                    VisitTopLevelType(noPiaIndexer, type);
                    yield return(type);
                }
            }
            if (topType == null)
            {
                AddTopLevelType(names, _rootModuleType);
                VisitTopLevelType(noPiaIndexer, _rootModuleType);
                yield return(_rootModuleType);
            }
#else
            AddTopLevelType(names, _rootModuleType);
            VisitTopLevelType(noPiaIndexer, _rootModuleType);
            yield return(_rootModuleType);
#endif

            foreach (var type in this.GetAnonymousTypes(context))
            {
                AddTopLevelType(names, type);
                VisitTopLevelType(noPiaIndexer, type);
                yield return(type);
            }

            foreach (var type in this.GetTopLevelTypesCore(context))
            {
#if XSHARP
                // Skip when class has been included as top level
                if (type != topType)
                {
                    AddTopLevelType(names, type);
                    VisitTopLevelType(noPiaIndexer, type);
                    yield return(type);
                }
#else
                AddTopLevelType(names, type);
                VisitTopLevelType(noPiaIndexer, type);
                yield return(type);
#endif
            }

            var privateImpl = this.PrivateImplClass;
            if (privateImpl != null)
            {
                AddTopLevelType(names, privateImpl);
                VisitTopLevelType(noPiaIndexer, privateImpl);
                yield return(privateImpl);
            }

            if (EmbeddedTypesManagerOpt != null)
            {
                foreach (var embedded in EmbeddedTypesManagerOpt.GetTypes(context.Diagnostics, names))
                {
                    AddTopLevelType(names, embedded);
                    yield return(embedded);
                }
            }

            if (names != null)
            {
                Debug.Assert(_namesOfTopLevelTypes == null);
                _namesOfTopLevelTypes = names;
            }
        }