Exemple #1
0
        public PEDeltaAssemblyBuilder(
            SourceAssemblySymbol sourceAssembly,
            string outputName,
            OutputKind outputKind,
            ModulePropertiesForSerialization serializationProperties,
            IEnumerable <ResourceDescription> manifestResources,
            Func <AssemblySymbol, AssemblyIdentity> assemblySymbolMapper,
            EmitBaseline previousGeneration,
            IEnumerable <SemanticEdit> edits)
            : base(sourceAssembly, outputName, outputKind, serializationProperties, manifestResources, assemblySymbolMapper, additionalTypes: ImmutableArray <NamedTypeSymbol> .Empty)
        {
            var context          = new Context(this, null, new DiagnosticBag());
            var module           = previousGeneration.OriginalMetadata;
            var compilation      = sourceAssembly.DeclaringCompilation;
            var metadataAssembly = compilation.GetBoundReferenceManager().CreatePEAssemblyForAssemblyMetadata(AssemblyMetadata.Create(module), MetadataImportOptions.All);
            var metadataDecoder  = new Microsoft.CodeAnalysis.CSharp.Symbols.Metadata.PE.MetadataDecoder(metadataAssembly.PrimaryModule);

            previousGeneration = EnsureInitialized(previousGeneration, metadataDecoder);

            var matchToMetadata = new SymbolMatcher(previousGeneration.AnonymousTypeMap, sourceAssembly, context, metadataAssembly);

            SymbolMatcher matchToPrevious = null;

            if (previousGeneration.Ordinal > 0)
            {
                var previousAssembly = ((CSharpCompilation)previousGeneration.Compilation).SourceAssembly;
                var previousContext  = new Context((PEModuleBuilder)previousGeneration.PEModuleBuilder, null, new DiagnosticBag());
                matchToPrevious = new SymbolMatcher(previousGeneration.AnonymousTypeMap, sourceAssembly, context, previousAssembly, previousContext);
            }

            this.previousDefinitions = new DefinitionMap(previousGeneration.OriginalMetadata.Module, metadataDecoder, matchToMetadata, matchToPrevious, GenerateMethodMap(edits));
            this.previousGeneration  = previousGeneration;
            this.changes             = new SymbolChanges(this.previousDefinitions, edits);
        }
Exemple #2
0
        private static EncLocalInfo MapLocalInfo(
            SymbolMatcher map,
            EncLocalInfo localInfo)
        {
            Debug.Assert(!localInfo.IsDefault);
            var type = map.MapReference(localInfo.Type);

            Debug.Assert(type != null);
            return(new EncLocalInfo(localInfo.Offset, type, localInfo.Constraints, localInfo.TempKind));
        }
        public CSharpDefinitionMap(
            PEModule module,
            IEnumerable <SemanticEdit> edits,
            MetadataDecoder metadataDecoder,
            SymbolMatcher mapToMetadata,
            SymbolMatcher mapToPrevious)
            : base(module, edits)
        {
            Debug.Assert(mapToMetadata != null);
            Debug.Assert(metadataDecoder != null);

            this.mapToMetadata   = mapToMetadata;
            this.mapToPrevious   = mapToPrevious ?? mapToMetadata;
            this.metadataDecoder = metadataDecoder;
        }
        public DefinitionMap(
            PEModule module,
            MetadataDecoder metadataDecoder,
            SymbolMatcher mapToMetadata,
            SymbolMatcher mapToPrevious,
            IReadOnlyDictionary <MethodSymbol, MethodDefinitionEntry> methodMap)
        {
            Debug.Assert(module != null);
            Debug.Assert(metadataDecoder != null);
            Debug.Assert(mapToMetadata != null);
            Debug.Assert(methodMap != null);

            this.module          = module;
            this.metadataDecoder = metadataDecoder;
            this.mapToMetadata   = mapToMetadata;
            this.mapToPrevious   = mapToPrevious ?? mapToMetadata;
            this.methodMap       = methodMap;
        }
Exemple #5
0
        private static IReadOnlyDictionary <K, V> MapDefinitions <K, V>(
            SymbolMatcher map,
            IReadOnlyDictionary <K, V> items)
            where K : Cci.IDefinition
        {
            var result = new Dictionary <K, V>();

            foreach (var pair in items)
            {
                var key = (K)map.MapDefinition(pair.Key);
                // Result may be null if the definition was deleted, or if the definition
                // was synthesized (e.g.: an iterator type) and the method that generated
                // the synthesized definition was unchanged and not recompiled.
                if (key != null)
                {
                    result.Add(key, pair.Value);
                }
            }
            return(result);
        }
Exemple #6
0
        /// <summary>
        /// Return a version of the baseline with all definitions mapped to this compilation.
        /// Definitions from the initial generation, from metadata, are not mapped since
        /// the initial generation is always included as metadata. That is, the symbols from
        /// types, methods, ... in the TypesAdded, MethodsAdded, ... collections are replaced
        /// by the corresponding symbols from the current compilation.
        /// </summary>
        private static EmitBaseline MapToCompilation(
            CSharpCompilation compilation,
            PEDeltaAssemblyBuilder moduleBeingBuilt)
        {
            var previousGeneration = moduleBeingBuilt.PreviousGeneration;

            Debug.Assert(previousGeneration.Compilation != compilation);

            if (previousGeneration.Ordinal == 0)
            {
                // Initial generation, nothing to map. (Since the initial generation
                // is always loaded from metadata in the context of the current
                // compilation, there's no separate mapping step.)
                return(previousGeneration);
            }

            var map = new SymbolMatcher(
                moduleBeingBuilt.GetAnonymousTypeMap(),
                ((CSharpCompilation)previousGeneration.Compilation).SourceAssembly,
                new EmitContext((PEModuleBuilder)previousGeneration.PEModuleBuilder, null, new DiagnosticBag()),
                compilation.SourceAssembly,
                new EmitContext((Cci.IModule)moduleBeingBuilt, null, new DiagnosticBag()));

            // Map all definitions to this compilation.
            var typesAdded      = MapDefinitions(map, previousGeneration.TypesAdded);
            var eventsAdded     = MapDefinitions(map, previousGeneration.EventsAdded);
            var fieldsAdded     = MapDefinitions(map, previousGeneration.FieldsAdded);
            var methodsAdded    = MapDefinitions(map, previousGeneration.MethodsAdded);
            var propertiesAdded = MapDefinitions(map, previousGeneration.PropertiesAdded);

            // Map anonymous types to this compilation.
            var anonymousTypeMap = new Dictionary <AnonymousTypeKey, AnonymousTypeValue>();

            foreach (var pair in previousGeneration.AnonymousTypeMap)
            {
                var key   = pair.Key;
                var value = pair.Value;
                var type  = (Cci.ITypeDefinition)map.MapDefinition(value.Type);
                Debug.Assert(type != null);
                anonymousTypeMap.Add(key, new AnonymousTypeValue(value.Name, value.UniqueIndex, type));
            }

            // Map locals (specifically, local types) to this compilation.
            var locals = new Dictionary <uint, ImmutableArray <EncLocalInfo> >();

            foreach (var pair in previousGeneration.LocalsForMethodsAddedOrChanged)
            {
                locals.Add(pair.Key, pair.Value.SelectAsArray((l, m) => MapLocalInfo(m, l), map));
            }

            return(previousGeneration.With(
                       compilation,
                       moduleBeingBuilt,
                       previousGeneration.Ordinal,
                       previousGeneration.EncId,
                       typesAdded,
                       eventsAdded,
                       fieldsAdded,
                       methodsAdded,
                       propertiesAdded,
                       eventMapAdded: previousGeneration.EventMapAdded,
                       propertyMapAdded: previousGeneration.PropertyMapAdded,
                       methodImplsAdded: previousGeneration.MethodImplsAdded,
                       tableEntriesAdded: previousGeneration.TableEntriesAdded,
                       blobStreamLengthAdded: previousGeneration.BlobStreamLengthAdded,
                       stringStreamLengthAdded: previousGeneration.StringStreamLengthAdded,
                       userStringStreamLengthAdded: previousGeneration.UserStringStreamLengthAdded,
                       guidStreamLengthAdded: previousGeneration.GuidStreamLengthAdded,
                       anonymousTypeMap: anonymousTypeMap,
                       localsForMethodsAddedOrChanged: locals,
                       localNames: previousGeneration.LocalNames));
        }