本文整理汇总了C#中Microsoft.CodeAnalysis.CSharp.TypeCompilationState.GetIteratorOrAsyncImplementationClass方法的典型用法代码示例。如果您正苦于以下问题:C# TypeCompilationState.GetIteratorOrAsyncImplementationClass方法的具体用法?C# TypeCompilationState.GetIteratorOrAsyncImplementationClass怎么用?C# TypeCompilationState.GetIteratorOrAsyncImplementationClass使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Microsoft.CodeAnalysis.CSharp.TypeCompilationState
的用法示例。
在下文中一共展示了TypeCompilationState.GetIteratorOrAsyncImplementationClass方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: GenerateMethodBody
internal static MethodBody GenerateMethodBody(TypeCompilationState compilationState, MethodSymbol method, BoundStatement block, DiagnosticBag diagnostics,
bool optimize, DebugDocumentProvider debugDocumentProvider, ImmutableArray<NamespaceScope> namespaceScopes)
{
// Note: don't call diagnostics.HasAnyErrors() in release; could be expensive if compilation has many warnings.
Debug.Assert(!diagnostics.HasAnyErrors(), "Running code generator when errors exist might be dangerous; code generator not well hardened");
bool emitSequencePoints = !namespaceScopes.IsDefault && !method.IsAsync;
var module = compilationState.ModuleBuilder;
var compilation = module.Compilation;
var localSlotManager = module.CreateLocalSlotManager(method);
ILBuilder builder = new ILBuilder(module, localSlotManager, optimize);
DiagnosticBag diagnosticsForThisMethod = DiagnosticBag.GetInstance();
try
{
AsyncMethodBodyDebugInfo asyncDebugInfo = null;
if ((object)method.AsyncKickoffMethod == null) // is this the MoveNext of an async method?
{
CodeGen.CodeGenerator.Run(
method, block, builder, module, diagnosticsForThisMethod, optimize, emitSequencePoints);
}
else
{
int asyncCatchHandlerOffset;
ImmutableArray<int> asyncYieldPoints;
ImmutableArray<int> asyncResumePoints;
CodeGen.CodeGenerator.Run(
method, block, builder, module, diagnosticsForThisMethod, optimize, emitSequencePoints,
out asyncCatchHandlerOffset, out asyncYieldPoints, out asyncResumePoints);
asyncDebugInfo = new AsyncMethodBodyDebugInfo(method.AsyncKickoffMethod, asyncCatchHandlerOffset, asyncYieldPoints, asyncResumePoints);
}
var localVariables = builder.LocalSlotManager.LocalsInOrder();
if (localVariables.Length > 0xFFFE)
{
diagnosticsForThisMethod.Add(ErrorCode.ERR_TooManyLocals, method.Locations.First());
}
if (diagnosticsForThisMethod.HasAnyErrors())
{
// we are done here. Since there were errors we should not emit anything.
return null;
}
// We will only save the IL builders when running tests.
if (module.SaveTestData)
{
module.SetMethodTestData(method, builder.GetSnapshot());
}
// Only compiler-generated MoveNext methods have iterator scopes. See if this is one.
bool hasIteratorScopes =
method.Locations.IsEmpty && method.Name == "MoveNext" &&
(method.ExplicitInterfaceImplementations.Contains(compilation.GetSpecialTypeMember(SpecialMember.System_Collections_IEnumerator__MoveNext) as MethodSymbol) ||
method.ExplicitInterfaceImplementations.Contains(compilation.GetWellKnownTypeMember(WellKnownMember.System_Runtime_CompilerServices_IAsyncStateMachine_MoveNext) as MethodSymbol));
var iteratorScopes = hasIteratorScopes ? builder.GetIteratorScopes() : ImmutableArray<LocalScope>.Empty;
var iteratorOrAsyncImplementation = compilationState.GetIteratorOrAsyncImplementationClass(method);
return new MethodBody(
builder.RealizedIL,
builder.MaxStack,
method,
localVariables,
builder.RealizedSequencePoints,
debugDocumentProvider,
builder.RealizedExceptionHandlers,
builder.GetAllScopes(),
Microsoft.Cci.CustomDebugInfoKind.CSharpStyle,
builder.HasDynamicLocal,
namespaceScopes,
(object)iteratorOrAsyncImplementation == null ? null : iteratorOrAsyncImplementation.MetadataName,
iteratorScopes,
asyncMethodDebugInfo: asyncDebugInfo
);
}
finally
{
// Basic blocks contain poolable builders for IL and sequence points. Free those back
// to their pools.
builder.FreeBasicBlocks();
// Remember diagnostics.
diagnostics.AddRange(diagnosticsForThisMethod);
diagnosticsForThisMethod.Free();
}
}