internal CommonPEModuleBuilder CreateModuleBuilder(
            string outputName,
            IEnumerable<ResourceDescription> manifestResources,
            Func<IAssemblySymbol, AssemblyIdentity> assemblySymbolMapper,
            CancellationToken cancellationToken,
            CompilationTestData testData,
            DiagnosticBag diagnostics,
            bool metadataOnly,
            ImmutableArray<NamedTypeSymbol> additionalTypes)
        {
            // Do not waste a slot in the submission chain for submissions that contain no executable code
            // (they may only contain #r directives, usings, etc.)
            if (IsSubmission && !HasCodeToEmit())
            {
                return null;
            }

            string runtimeMDVersion = GetRuntimeMetadataVersion(diagnostics);
            if (runtimeMDVersion == null)
            {
                return null;
            }

            var moduleProps = ConstructModuleSerializationProperties(runtimeMDVersion);

            if (manifestResources == null)
            {
                manifestResources = SpecializedCollections.EmptyEnumerable<ResourceDescription>();
            }

            PEModuleBuilder moduleBeingBuilt;
            if (options.OutputKind.IsNetModule())
            {
                Debug.Assert(additionalTypes.IsEmpty);

                moduleBeingBuilt = new PENetModuleBuilder(
                    (SourceModuleSymbol)SourceModule,
                    outputName,
                    moduleProps,
                    manifestResources,
                    metadataOnly);
            }
            else
            {
                var kind = options.OutputKind.IsValid() ? options.OutputKind : OutputKind.DynamicallyLinkedLibrary;
                moduleBeingBuilt = new PEAssemblyBuilder(
                    SourceAssembly,
                    outputName,
                    kind,
                    moduleProps,
                    manifestResources,
                    assemblySymbolMapper,
                    additionalTypes,
                    metadataOnly);
            }

            // testData is only passed when running tests.
            if (testData != null)
            {
                moduleBeingBuilt.SetMethodTestData(testData.Methods);
                testData.Module = moduleBeingBuilt;
            }

            return moduleBeingBuilt;
        }
Exemple #2
0
        internal CommonPEModuleBuilder CreateModuleBuilder(
            string outputName,
            IEnumerable<ResourceDescription> manifestResources,
            Func<IAssemblySymbol, AssemblyIdentity> assemblySymbolMapper,
            ImmutableArray<NamedTypeSymbol> additionalTypes,
            CancellationToken cancellationToken,
            CompilationTestData testData,
            DiagnosticBag diagnostics,
            ref bool hasDeclarationErrors,
            bool metadataOnly)
        {
            // The diagnostics should include syntax and declaration errors also. We insert these before calling Emitter.Emit, so that the emitter
            // does not attempt to emit if there are declaration errors (but we do insert all errors from method body binding...)
            if (!FilterAndAppendDiagnostics(
                diagnostics,
                GetDiagnostics(CompilationStage.Declare, true, cancellationToken),
                this.options))
            {
                hasDeclarationErrors = true;
            }

            // Do not waste a slot in the submission chain for submissions that contain no executable code
            // (they may only contain #r directives, usings, etc.)
            if (IsSubmission && !HasCodeToEmit())
            {
                return null;
            }

            string runtimeMDVersion = GetRuntimeMetadataVersion(diagnostics);
            if (runtimeMDVersion == null)
            {
                return null;
            }

            var moduleProps = ConstructModuleSerializationProperties(runtimeMDVersion);

            if (manifestResources == null)
            {
                manifestResources = SpecializedCollections.EmptyEnumerable<ResourceDescription>();
            }

            PEModuleBuilder moduleBeingBuilt;
            if (options.OutputKind.IsNetModule())
            {
                Debug.Assert(additionalTypes.IsEmpty);

                moduleBeingBuilt = new PENetModuleBuilder(
                    (SourceModuleSymbol)SourceModule,
                    outputName,
                    moduleProps,
                    manifestResources,
                    metadataOnly);
            }
            else
            {
                var kind = options.OutputKind.IsValid() ? options.OutputKind : OutputKind.DynamicallyLinkedLibrary;
                moduleBeingBuilt = new PEAssemblyBuilder(
                    SourceAssembly,
                    outputName,
                    kind,
                    moduleProps,
                    manifestResources,
                    assemblySymbolMapper,
                    additionalTypes,
                    metadataOnly);
            }

            // testData is only passed when running tests.
            if (testData != null)
            {
                moduleBeingBuilt.SetMethodTestData(testData.Methods);
                testData.Module = moduleBeingBuilt;
            }

            return moduleBeingBuilt;
        }