提交 83b213bf 编写于 作者: T Tomas Matousek

Unnest CompilationVerifier

上级 d483954d
......@@ -9,7 +9,7 @@ namespace Microsoft.CodeAnalysis.CSharp.UnitTests.CodeGen
{
public static class LocalFunctionTestsUtil
{
public static IMethodSymbol FindLocalFunction(this CommonTestBase.CompilationVerifier verifier, string localFunctionName)
public static IMethodSymbol FindLocalFunction(this CompilationVerifier verifier, string localFunctionName)
{
localFunctionName = (char)GeneratedNameKind.LocalFunction + "__" + localFunctionName;
var methods = verifier.TestData.GetMethodsByName();
......
......@@ -2,6 +2,7 @@
using Microsoft.CodeAnalysis.CSharp.Syntax;
using Microsoft.CodeAnalysis.CSharp.Test.Utilities;
using Microsoft.CodeAnalysis.Test.Utilities;
using Roslyn.Test.Utilities;
using Roslyn.Utilities;
using Xunit;
......@@ -703,14 +704,6 @@ public static IEnumerable Power(int number, int exponent)
CompileAndVerify(text, expectedOutput: expectedOutput);
}
// When ReflectionEmit supports writing exception handler info, this method
// can be removed and CompileAndVerify references above will resolve to
// the overload that emits with both CCI and ReflectionEmit. (Bug #7012)
private CompilationVerifier CompileAndVerify(string source, string expectedOutput = null)
{
return base.CompileAndVerify(source: source, expectedOutput: expectedOutput);
}
[WorkItem(540719, "http://vstfdevdiv:8080/DevDiv2/DevDiv/_workitems/edit/540719")]
[Fact]
public void LabelBetweenLocalAndInitialize()
......
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
// Copyright (c) Microsoft. All Rights Reserved. Licensed under the Apache License, Version 2.0. See License.txt in the project root for license information.
using Microsoft.CodeAnalysis.CSharp.Test.Utilities;
using Microsoft.CodeAnalysis.Test.Utilities;
using Roslyn.Test.Utilities;
using static Microsoft.CodeAnalysis.Test.Utilities.CommonTestBase;
namespace Microsoft.CodeAnalysis.CSharp.UnitTests
{
......
......@@ -3,11 +3,8 @@
using System;
using System.Collections.Generic;
using System.Collections.Immutable;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Reflection.Metadata;
using System.Reflection.Metadata.Ecma335;
using System.Runtime.CompilerServices;
using System.Xml.Linq;
using Microsoft.CodeAnalysis;
......@@ -21,335 +18,330 @@
namespace Microsoft.CodeAnalysis.Test.Utilities
{
public partial class CommonTestBase
public sealed class CompilationVerifier
{
public class CompilationVerifier
private readonly Compilation _compilation;
private CompilationTestData _testData;
private readonly IEnumerable<ModuleData> _dependencies;
private ImmutableArray<Diagnostic> _diagnostics;
private IModuleSymbol _lazyModuleSymbol;
private IList<ModuleData> _allModuleData;
internal ImmutableArray<byte> EmittedAssemblyData;
internal ImmutableArray<byte> EmittedAssemblyPdb;
private readonly Func<IModuleSymbol, CompilationTestData.MethodData, IReadOnlyDictionary<int, string>, string> _visualizeRealIL;
internal CompilationVerifier(
Compilation compilation,
Func<IModuleSymbol, CompilationTestData.MethodData, IReadOnlyDictionary<int, string>, string> visualizeRealIL = null,
IEnumerable<ModuleData> dependencies = null)
{
private readonly Compilation _compilation;
private CompilationTestData _testData;
private readonly IEnumerable<ModuleData> _dependencies;
private ImmutableArray<Diagnostic> _diagnostics;
private IModuleSymbol _lazyModuleSymbol;
private IList<ModuleData> _allModuleData;
internal ImmutableArray<byte> EmittedAssemblyData;
internal ImmutableArray<byte> EmittedAssemblyPdb;
private readonly Func<IModuleSymbol, CompilationTestData.MethodData, IReadOnlyDictionary<int, string>, string> _visualizeRealIL;
internal CompilationVerifier(
Compilation compilation,
Func<IModuleSymbol, CompilationTestData.MethodData, IReadOnlyDictionary<int, string>, string> visualizeRealIL = null,
IEnumerable<ModuleData> dependencies = null)
_compilation = compilation;
_dependencies = dependencies;
_visualizeRealIL = visualizeRealIL;
}
internal CompilationTestData TestData => _testData;
public Compilation Compilation => _compilation;
internal ImmutableArray<Diagnostic> Diagnostics => _diagnostics;
internal ImmutableArray<ModuleMetadata> GetAllModuleMetadata()
{
if (EmittedAssemblyData == null)
{
_compilation = compilation;
_dependencies = dependencies;
_visualizeRealIL = visualizeRealIL;
throw new InvalidOperationException("You must call Emit before calling GetAllModuleMetadata.");
}
internal CompilationTestData TestData => _testData;
public Compilation Compilation => _compilation;
internal ImmutableArray<Diagnostic> Diagnostics => _diagnostics;
ImmutableArray<ModuleMetadata> modules = ImmutableArray.Create(ModuleMetadata.CreateFromImage(EmittedAssemblyData));
internal ImmutableArray<ModuleMetadata> GetAllModuleMetadata()
if (_allModuleData != null)
{
if (EmittedAssemblyData == null)
var netModules = _allModuleData.Where(m => m.Kind == OutputKind.NetModule);
if (netModules.Any())
{
throw new InvalidOperationException("You must call Emit before calling GetAllModuleMetadata.");
modules = modules.Concat(
ImmutableArray.CreateRange(netModules.Select(m => ModuleMetadata.CreateFromImage(m.Image))));
}
}
ImmutableArray<ModuleMetadata> modules = ImmutableArray.Create(ModuleMetadata.CreateFromImage(EmittedAssemblyData));
return modules;
}
if (_allModuleData != null)
public void Emit(string expectedOutput, int? expectedReturnCode, string[] args, IEnumerable<ResourceDescription> manifestResources, EmitOptions emitOptions, bool peVerify, SignatureDescription[] expectedSignatures)
{
using (var testEnvironment = RuntimeEnvironmentFactory.Create(_dependencies))
{
string mainModuleName = Emit(testEnvironment, manifestResources, emitOptions);
_allModuleData = testEnvironment.GetAllModuleData();
if (peVerify)
{
var netModules = _allModuleData.Where(m => m.Kind == OutputKind.NetModule);
if (netModules.Any())
{
modules = modules.Concat(
ImmutableArray.CreateRange(netModules.Select(m => ModuleMetadata.CreateFromImage(m.Image))));
}
testEnvironment.PeVerify();
}
return modules;
}
public void Emit(string expectedOutput, int? expectedReturnCode, string[] args, IEnumerable<ResourceDescription> manifestResources, EmitOptions emitOptions, bool peVerify, SignatureDescription[] expectedSignatures)
{
using (var testEnvironment = RuntimeEnvironmentFactory.Create(_dependencies))
if (expectedSignatures != null)
{
string mainModuleName = Emit(testEnvironment, manifestResources, emitOptions);
_allModuleData = testEnvironment.GetAllModuleData();
if (peVerify)
{
testEnvironment.PeVerify();
}
MetadataSignatureUnitTestHelper.VerifyMemberSignatures(testEnvironment, expectedSignatures);
}
if (expectedSignatures != null)
{
MetadataSignatureUnitTestHelper.VerifyMemberSignatures(testEnvironment, expectedSignatures);
}
if (expectedOutput != null || expectedReturnCode != null)
{
var returnCode = testEnvironment.Execute(mainModuleName, args, expectedOutput);
if (expectedOutput != null || expectedReturnCode != null)
if (expectedReturnCode is int exCode)
{
var returnCode = testEnvironment.Execute(mainModuleName, args, expectedOutput);
if (expectedReturnCode is int exCode)
{
Assert.Equal(exCode, returnCode);
}
Assert.Equal(exCode, returnCode);
}
}
}
}
// TODO(tomat): Fold into CompileAndVerify.
// Replace bool verify parameter with string[] expectedPeVerifyOutput. If null, no verification. If empty verify have to succeed. Otherwise compare errors.
public void EmitAndVerify(params string[] expectedPeVerifyOutput)
{
using (var testEnvironment = RuntimeEnvironmentFactory.Create(_dependencies))
{
string mainModuleName = Emit(testEnvironment, null, null);
string[] actualOutput = testEnvironment.PeVerifyModules(new[] { mainModuleName }, throwOnError: false);
Assert.Equal(expectedPeVerifyOutput, actualOutput);
}
}
private string Emit(IRuntimeEnvironment testEnvironment, IEnumerable<ResourceDescription> manifestResources, EmitOptions emitOptions)
{
testEnvironment.Emit(_compilation, manifestResources, emitOptions);
_diagnostics = testEnvironment.GetDiagnostics();
EmittedAssemblyData = testEnvironment.GetMainImage();
EmittedAssemblyPdb = testEnvironment.GetMainPdb();
_testData = ((IInternalRuntimeEnvironment)testEnvironment).GetCompilationTestData();
return _compilation.Assembly.Identity.GetDisplayName();
}
public CompilationVerifier VerifyIL(
string qualifiedMethodName,
XCData expectedIL,
bool realIL = false,
string sequencePoints = null,
[CallerFilePath]string callerPath = null,
[CallerLineNumber]int callerLine = 0)
// TODO(tomat): Fold into CompileAndVerify.
// Replace bool verify parameter with string[] expectedPeVerifyOutput. If null, no verification. If empty verify have to succeed. Otherwise compare errors.
public void EmitAndVerify(params string[] expectedPeVerifyOutput)
{
using (var testEnvironment = RuntimeEnvironmentFactory.Create(_dependencies))
{
return VerifyILImpl(qualifiedMethodName, expectedIL.Value, realIL, sequencePoints, callerPath, callerLine, escapeQuotes: false);
string mainModuleName = Emit(testEnvironment, null, null);
string[] actualOutput = testEnvironment.PeVerifyModules(new[] { mainModuleName }, throwOnError: false);
Assert.Equal(expectedPeVerifyOutput, actualOutput);
}
}
public CompilationVerifier VerifyIL(
string qualifiedMethodName,
string expectedIL,
bool realIL = false,
string sequencePoints = null,
[CallerFilePath]string callerPath = null,
[CallerLineNumber]int callerLine = 0,
string source = null)
{
return VerifyILImpl(qualifiedMethodName, expectedIL, realIL, sequencePoints, callerPath, callerLine, escapeQuotes: true, source: source);
}
private string Emit(IRuntimeEnvironment testEnvironment, IEnumerable<ResourceDescription> manifestResources, EmitOptions emitOptions)
{
testEnvironment.Emit(_compilation, manifestResources, emitOptions);
public void VerifyLocalSignature(
string qualifiedMethodName,
string expectedSignature,
[CallerLineNumber]int callerLine = 0,
[CallerFilePath]string callerPath = null)
{
var ilBuilder = _testData.GetMethodData(qualifiedMethodName).ILBuilder;
string actualSignature = ILBuilderVisualizer.LocalSignatureToString(ilBuilder);
AssertEx.AssertEqualToleratingWhitespaceDifferences(expectedSignature, actualSignature, escapeQuotes: true, expectedValueSourcePath: callerPath, expectedValueSourceLine: callerLine);
}
_diagnostics = testEnvironment.GetDiagnostics();
EmittedAssemblyData = testEnvironment.GetMainImage();
EmittedAssemblyPdb = testEnvironment.GetMainPdb();
_testData = ((IInternalRuntimeEnvironment)testEnvironment).GetCompilationTestData();
private CompilationVerifier VerifyILImpl(
string qualifiedMethodName,
string expectedIL,
bool realIL,
string sequencePoints,
string callerPath,
int callerLine,
bool escapeQuotes,
string source = null)
{
string actualIL = VisualizeIL(qualifiedMethodName, realIL, sequencePoints, source);
AssertEx.AssertEqualToleratingWhitespaceDifferences(expectedIL, actualIL, escapeQuotes, callerPath, callerLine);
return this;
}
return _compilation.Assembly.Identity.GetDisplayName();
}
public CompilationVerifier VerifyPdb(
XElement expectedPdb,
IMethodSymbol debugEntryPoint = null,
DebugInformationFormat format = 0,
PdbToXmlOptions options = 0,
[CallerLineNumber]int expectedValueSourceLine = 0,
[CallerFilePath]string expectedValueSourcePath = null)
{
_compilation.VerifyPdb(expectedPdb, debugEntryPoint, format, options, expectedValueSourceLine, expectedValueSourcePath);
return this;
}
public CompilationVerifier VerifyIL(
string qualifiedMethodName,
XCData expectedIL,
bool realIL = false,
string sequencePoints = null,
[CallerFilePath]string callerPath = null,
[CallerLineNumber]int callerLine = 0)
{
return VerifyILImpl(qualifiedMethodName, expectedIL.Value, realIL, sequencePoints, callerPath, callerLine, escapeQuotes: false);
}
public CompilationVerifier VerifyPdb(
string expectedPdb,
IMethodSymbol debugEntryPoint = null,
DebugInformationFormat format = 0,
PdbToXmlOptions options = 0,
[CallerLineNumber]int expectedValueSourceLine = 0,
[CallerFilePath]string expectedValueSourcePath = null)
{
_compilation.VerifyPdb(expectedPdb, debugEntryPoint, format, options, expectedValueSourceLine, expectedValueSourcePath);
return this;
}
public CompilationVerifier VerifyIL(
string qualifiedMethodName,
string expectedIL,
bool realIL = false,
string sequencePoints = null,
[CallerFilePath]string callerPath = null,
[CallerLineNumber]int callerLine = 0,
string source = null)
{
return VerifyILImpl(qualifiedMethodName, expectedIL, realIL, sequencePoints, callerPath, callerLine, escapeQuotes: true, source: source);
}
public CompilationVerifier VerifyPdb(
string qualifiedMethodName,
string expectedPdb,
IMethodSymbol debugEntryPoint = null,
DebugInformationFormat format = 0,
PdbToXmlOptions options = 0,
[CallerLineNumber]int expectedValueSourceLine = 0,
[CallerFilePath]string expectedValueSourcePath = null)
{
_compilation.VerifyPdb(qualifiedMethodName, expectedPdb, debugEntryPoint, format, options, expectedValueSourceLine, expectedValueSourcePath);
return this;
}
public void VerifyLocalSignature(
string qualifiedMethodName,
string expectedSignature,
[CallerLineNumber]int callerLine = 0,
[CallerFilePath]string callerPath = null)
{
var ilBuilder = _testData.GetMethodData(qualifiedMethodName).ILBuilder;
string actualSignature = ILBuilderVisualizer.LocalSignatureToString(ilBuilder);
AssertEx.AssertEqualToleratingWhitespaceDifferences(expectedSignature, actualSignature, escapeQuotes: true, expectedValueSourcePath: callerPath, expectedValueSourceLine: callerLine);
}
public CompilationVerifier VerifyPdb(
string qualifiedMethodName,
XElement expectedPdb,
IMethodSymbol debugEntryPoint = null,
DebugInformationFormat format = 0,
PdbToXmlOptions options = 0,
[CallerLineNumber]int expectedValueSourceLine = 0,
[CallerFilePath]string expectedValueSourcePath = null)
{
_compilation.VerifyPdb(qualifiedMethodName, expectedPdb, debugEntryPoint, format, options, expectedValueSourceLine, expectedValueSourcePath);
return this;
}
private CompilationVerifier VerifyILImpl(
string qualifiedMethodName,
string expectedIL,
bool realIL,
string sequencePoints,
string callerPath,
int callerLine,
bool escapeQuotes,
string source = null)
{
string actualIL = VisualizeIL(qualifiedMethodName, realIL, sequencePoints, source);
AssertEx.AssertEqualToleratingWhitespaceDifferences(expectedIL, actualIL, escapeQuotes, callerPath, callerLine);
return this;
}
public ISymUnmanagedReader3 CreateSymReader()
{
var pdbStream = new MemoryStream(EmittedAssemblyPdb.ToArray());
return SymReaderFactory.CreateReader(pdbStream, metadataReaderOpt: null, metadataMemoryOwnerOpt: null);
}
public CompilationVerifier VerifyPdb(
XElement expectedPdb,
IMethodSymbol debugEntryPoint = null,
DebugInformationFormat format = 0,
PdbToXmlOptions options = 0,
[CallerLineNumber]int expectedValueSourceLine = 0,
[CallerFilePath]string expectedValueSourcePath = null)
{
_compilation.VerifyPdb(expectedPdb, debugEntryPoint, format, options, expectedValueSourceLine, expectedValueSourcePath);
return this;
}
public string VisualizeIL(string qualifiedMethodName, bool realIL = false, string sequencePoints = null, string source = null)
{
// TODO: Currently the qualifiedMethodName is a symbol display name while PDB need metadata name.
// So we need to pass the PDB metadata name of the method to sequencePoints (instead of just bool).
public CompilationVerifier VerifyPdb(
string expectedPdb,
IMethodSymbol debugEntryPoint = null,
DebugInformationFormat format = 0,
PdbToXmlOptions options = 0,
[CallerLineNumber]int expectedValueSourceLine = 0,
[CallerFilePath]string expectedValueSourcePath = null)
{
_compilation.VerifyPdb(expectedPdb, debugEntryPoint, format, options, expectedValueSourceLine, expectedValueSourcePath);
return this;
}
return VisualizeIL(_testData.GetMethodData(qualifiedMethodName), realIL, sequencePoints, source);
}
public CompilationVerifier VerifyPdb(
string qualifiedMethodName,
string expectedPdb,
IMethodSymbol debugEntryPoint = null,
DebugInformationFormat format = 0,
PdbToXmlOptions options = 0,
[CallerLineNumber]int expectedValueSourceLine = 0,
[CallerFilePath]string expectedValueSourcePath = null)
{
_compilation.VerifyPdb(qualifiedMethodName, expectedPdb, debugEntryPoint, format, options, expectedValueSourceLine, expectedValueSourcePath);
return this;
}
internal string VisualizeIL(CompilationTestData.MethodData methodData, bool realIL, string sequencePoints = null, string source = null)
{
Dictionary<int, string> markers = null;
public CompilationVerifier VerifyPdb(
string qualifiedMethodName,
XElement expectedPdb,
IMethodSymbol debugEntryPoint = null,
DebugInformationFormat format = 0,
PdbToXmlOptions options = 0,
[CallerLineNumber]int expectedValueSourceLine = 0,
[CallerFilePath]string expectedValueSourcePath = null)
{
_compilation.VerifyPdb(qualifiedMethodName, expectedPdb, debugEntryPoint, format, options, expectedValueSourceLine, expectedValueSourcePath);
return this;
}
if (sequencePoints != null)
{
var actualPdbXml = PdbToXmlConverter.ToXml(
pdbStream: new MemoryStream(EmittedAssemblyPdb.ToArray()),
peStream: new MemoryStream(EmittedAssemblyData.ToArray()),
options: PdbToXmlOptions.ResolveTokens |
PdbToXmlOptions.ThrowOnError |
PdbToXmlOptions.ExcludeDocuments |
PdbToXmlOptions.ExcludeCustomDebugInformation |
PdbToXmlOptions.ExcludeScopes,
methodName: sequencePoints);
markers = PdbValidation.GetMarkers(actualPdbXml, source);
}
public ISymUnmanagedReader3 CreateSymReader()
{
var pdbStream = new MemoryStream(EmittedAssemblyPdb.ToArray());
return SymReaderFactory.CreateReader(pdbStream, metadataReaderOpt: null, metadataMemoryOwnerOpt: null);
}
if (!realIL)
{
return ILBuilderVisualizer.ILBuilderToString(methodData.ILBuilder, markers: markers);
}
public string VisualizeIL(string qualifiedMethodName, bool realIL = false, string sequencePoints = null, string source = null)
{
// TODO: Currently the qualifiedMethodName is a symbol display name while PDB need metadata name.
// So we need to pass the PDB metadata name of the method to sequencePoints (instead of just bool).
if (_lazyModuleSymbol == null)
{
_lazyModuleSymbol = GetModuleSymbolForEmittedImage(EmittedAssemblyData, MetadataImportOptions.All);
}
return VisualizeIL(_testData.GetMethodData(qualifiedMethodName), realIL, sequencePoints, source);
}
return _lazyModuleSymbol != null ? _visualizeRealIL(_lazyModuleSymbol, methodData, markers) : null;
}
internal string VisualizeIL(CompilationTestData.MethodData methodData, bool realIL, string sequencePoints = null, string source = null)
{
Dictionary<int, string> markers = null;
public CompilationVerifier VerifyMemberInIL(string methodName, bool expected)
if (sequencePoints != null)
{
Assert.Equal(expected, _testData.GetMethodsByName().ContainsKey(methodName));
return this;
var actualPdbXml = PdbToXmlConverter.ToXml(
pdbStream: new MemoryStream(EmittedAssemblyPdb.ToArray()),
peStream: new MemoryStream(EmittedAssemblyData.ToArray()),
options: PdbToXmlOptions.ResolveTokens |
PdbToXmlOptions.ThrowOnError |
PdbToXmlOptions.ExcludeDocuments |
PdbToXmlOptions.ExcludeCustomDebugInformation |
PdbToXmlOptions.ExcludeScopes,
methodName: sequencePoints);
markers = PdbValidation.GetMarkers(actualPdbXml, source);
}
public CompilationVerifier VerifyDiagnostics(params DiagnosticDescription[] expected)
if (!realIL)
{
_diagnostics.Verify(expected);
return this;
return ILBuilderVisualizer.ILBuilderToString(methodData.ILBuilder, markers: markers);
}
public IModuleSymbol GetModuleSymbolForEmittedImage()
if (_lazyModuleSymbol == null)
{
return GetModuleSymbolForEmittedImage(EmittedAssemblyData, _compilation.Options.MetadataImportOptions);
_lazyModuleSymbol = GetModuleSymbolForEmittedImage(EmittedAssemblyData, MetadataImportOptions.All);
}
private IModuleSymbol GetModuleSymbolForEmittedImage(ImmutableArray<byte> peImage, MetadataImportOptions importOptions)
{
if (peImage.IsDefault)
{
return null;
}
return _lazyModuleSymbol != null ? _visualizeRealIL(_lazyModuleSymbol, methodData, markers) : null;
}
var targetReference = LoadTestEmittedExecutableForSymbolValidation(peImage, _compilation.Options.OutputKind, display: _compilation.AssemblyName);
var references = _compilation.References.Concat(new[] { targetReference });
var assemblies = GetReferencesToModuleSymbols(references, importOptions);
return assemblies.Last();
}
public CompilationVerifier VerifyMemberInIL(string methodName, bool expected)
{
Assert.Equal(expected, _testData.GetMethodsByName().ContainsKey(methodName));
return this;
}
public CompilationVerifier VerifyDiagnostics(params DiagnosticDescription[] expected)
{
_diagnostics.Verify(expected);
return this;
}
public IModuleSymbol GetModuleSymbolForEmittedImage()
{
return GetModuleSymbolForEmittedImage(EmittedAssemblyData, _compilation.Options.MetadataImportOptions);
}
private IEnumerable<IModuleSymbol> GetReferencesToModuleSymbols(IEnumerable<MetadataReference> references, MetadataImportOptions importOptions)
private IModuleSymbol GetModuleSymbolForEmittedImage(ImmutableArray<byte> peImage, MetadataImportOptions importOptions)
{
if (peImage.IsDefault)
{
var dummy = _compilation
.RemoveAllReferences()
.RemoveAllSyntaxTrees()
.WithReferences(references)
.WithAssemblyName("Dummy")
.WithOptions(_compilation.Options.WithMetadataImportOptions(importOptions));
return references.Select(reference =>
{
if (reference.Properties.Kind == MetadataImageKind.Assembly)
{
return ((IAssemblySymbol)dummy.GetAssemblyOrModuleSymbol(reference))?.Modules.First();
}
else
{
return (IModuleSymbol)dummy.GetAssemblyOrModuleSymbol(reference);
}
});
return null;
}
var targetReference = LoadTestEmittedExecutableForSymbolValidation(peImage, _compilation.Options.OutputKind, display: _compilation.AssemblyName);
var references = _compilation.References.Concat(new[] { targetReference });
var assemblies = GetReferencesToModuleSymbols(references, importOptions);
return assemblies.Last();
}
internal static MetadataReference LoadTestEmittedExecutableForSymbolValidation(
ImmutableArray<byte> image,
OutputKind outputKind,
string display = null)
{
var moduleMetadata = ModuleMetadata.CreateFromImage(image);
moduleMetadata.Module.PretendThereArentNoPiaLocalTypes();
private IEnumerable<IModuleSymbol> GetReferencesToModuleSymbols(IEnumerable<MetadataReference> references, MetadataImportOptions importOptions)
{
var dummy = _compilation
.RemoveAllSyntaxTrees()
.WithReferences(references)
.WithAssemblyName("Dummy")
.WithOptions(_compilation.Options.WithMetadataImportOptions(importOptions));
if (outputKind == OutputKind.NetModule)
return references.Select(reference =>
{
if (reference.Properties.Kind == MetadataImageKind.Assembly)
{
return moduleMetadata.GetReference(display: display);
return ((IAssemblySymbol)dummy.GetAssemblyOrModuleSymbol(reference))?.Modules.First();
}
else
{
return AssemblyMetadata.Create(moduleMetadata).GetReference(display: display);
return (IModuleSymbol)dummy.GetAssemblyOrModuleSymbol(reference);
}
}
});
}
internal static MetadataReference LoadTestEmittedExecutableForSymbolValidation(
ImmutableArray<byte> image,
OutputKind outputKind,
string display = null)
{
var moduleMetadata = ModuleMetadata.CreateFromImage(image);
moduleMetadata.Module.PretendThereArentNoPiaLocalTypes();
public void VerifyOperationTree(string expectedOperationTree, bool skipImplicitlyDeclaredSymbols = false)
if (outputKind == OutputKind.NetModule)
{
_compilation.VerifyOperationTree(expectedOperationTree, skipImplicitlyDeclaredSymbols);
return moduleMetadata.GetReference(display: display);
}
public void VerifyOperationTree(string symbolToVerify, string expectedOperationTree, bool skipImplicitlyDeclaredSymbols = false)
else
{
_compilation.VerifyOperationTree(symbolToVerify, expectedOperationTree, skipImplicitlyDeclaredSymbols);
return AssemblyMetadata.Create(moduleMetadata).GetReference(display: display);
}
}
public void VerifyOperationTree(string expectedOperationTree, bool skipImplicitlyDeclaredSymbols = false)
{
_compilation.VerifyOperationTree(expectedOperationTree, skipImplicitlyDeclaredSymbols);
}
public void VerifyOperationTree(string symbolToVerify, string expectedOperationTree, bool skipImplicitlyDeclaredSymbols = false)
{
_compilation.VerifyOperationTree(symbolToVerify, expectedOperationTree, skipImplicitlyDeclaredSymbols);
}
}
}
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册