本文整理汇总了C#中Microsoft.CodeAnalysis.CSharp.TypeCompilationState类的典型用法代码示例。如果您正苦于以下问题:C# TypeCompilationState类的具体用法?C# TypeCompilationState怎么用?C# TypeCompilationState使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
TypeCompilationState类属于Microsoft.CodeAnalysis.CSharp命名空间,在下文中一共展示了TypeCompilationState类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: Rewrite
/// <summary>
/// Rewrite an iterator method into a state machine class.
/// </summary>
/// <param name="body">The original body of the method</param>
/// <param name="method">The method's identity</param>
/// <param name="compilationState">The collection of generated methods that result from this transformation and which must be emitted</param>
/// <param name="diagnostics">Diagnostic bag for diagnostics.</param>
/// <param name="generateDebugInfo"></param>
internal static BoundStatement Rewrite(
BoundStatement body,
MethodSymbol method,
TypeCompilationState compilationState,
DiagnosticBag diagnostics,
bool generateDebugInfo)
{
TypeSymbol elementType = method.IteratorElementType;
if ((object)elementType == null)
{
return body;
}
// Figure out what kind of iterator we are generating.
bool isEnumerable;
switch (method.ReturnType.OriginalDefinition.SpecialType)
{
case SpecialType.System_Collections_IEnumerable:
case SpecialType.System_Collections_Generic_IEnumerable_T:
isEnumerable = true;
break;
case SpecialType.System_Collections_IEnumerator:
case SpecialType.System_Collections_Generic_IEnumerator_T:
isEnumerable = false;
break;
default:
throw ExceptionUtilities.UnexpectedValue(method.ReturnType.OriginalDefinition.SpecialType);
}
var iteratorClass = new IteratorStateMachine(method, isEnumerable, elementType, compilationState);
return new IteratorRewriter(body, method, isEnumerable, iteratorClass, compilationState, diagnostics, generateDebugInfo).Rewrite();
}
示例2: Rewrite
/// <summary>
/// Rewrite an async method into a state machine class.
/// </summary>
/// <param name="body">The original body of the method</param>
/// <param name="method">The method's identity</param>
/// <param name="compilationState">The collection of generated methods that result from this transformation and which must be emitted</param>
/// <param name="diagnostics">Diagnostic bag for diagnostics.</param>
/// <param name="generateDebugInfo"></param>
/// <param name="stateMachineType"></param>
internal static BoundStatement Rewrite(
BoundStatement body,
MethodSymbol method,
TypeCompilationState compilationState,
DiagnosticBag diagnostics,
bool generateDebugInfo,
out AsyncStateMachine stateMachineType)
{
if (!method.IsAsync)
{
stateMachineType = null;
return body;
}
// The CLR doesn't support adding fields to structs, so in order to enable EnC in an async method we need to generate a class.
var typeKind = compilationState.Compilation.Options.EnableEditAndContinue ? TypeKind.Class : TypeKind.Struct;
var bodyWithAwaitLifted = AwaitLiftingRewriter.Rewrite(body, method, compilationState, diagnostics);
stateMachineType = new AsyncStateMachine(method, typeKind);
compilationState.ModuleBuilderOpt.CompilationState.SetStateMachineType(method, stateMachineType);
var rewriter = new AsyncRewriter(bodyWithAwaitLifted, method, stateMachineType, compilationState, diagnostics, generateDebugInfo);
if (!rewriter.constructedSuccessfully)
{
return body;
}
return rewriter.Rewrite();
}
示例3: SynthesizedLambdaMethod
internal SynthesizedLambdaMethod(NamedTypeSymbol containingType, MethodSymbol topLevelMethod, BoundLambda node, bool isStatic, TypeCompilationState compilationState)
: base(containingType,
node.Symbol,
null,
node.SyntaxTree.GetReference(node.Body.Syntax),
node.Syntax.GetLocation(),
GeneratedNames.MakeLambdaMethodName(topLevelMethod.Name, compilationState.GenerateTempNumber()),
(containingType is LambdaFrame ? DeclarationModifiers.Internal : DeclarationModifiers.Private)
| (isStatic ? DeclarationModifiers.Static : 0)
| (node.Symbol.IsAsync ? DeclarationModifiers.Async : 0))
{
TypeMap typeMap;
ImmutableArray<TypeParameterSymbol> typeParameters;
LambdaFrame lambdaFrame;
if (!topLevelMethod.IsGenericMethod)
{
typeMap = TypeMap.Empty;
typeParameters = ImmutableArray<TypeParameterSymbol>.Empty;
}
else if ((object)(lambdaFrame = this.ContainingType as LambdaFrame) != null)
{
typeMap = lambdaFrame.TypeMap;
typeParameters = ImmutableArray<TypeParameterSymbol>.Empty;
}
else
{
typeMap = TypeMap.Empty.WithAlphaRename(topLevelMethod, this, out typeParameters);
}
AssignTypeMapAndTypeParameters(typeMap, typeParameters);
}
示例4: StateMachineRewriter
protected StateMachineRewriter(
BoundStatement body,
MethodSymbol method,
SynthesizedContainer stateMachineType,
VariableSlotAllocator slotAllocatorOpt,
TypeCompilationState compilationState,
DiagnosticBag diagnostics)
{
Debug.Assert(body != null);
Debug.Assert(method != null);
Debug.Assert(stateMachineType != null);
Debug.Assert(compilationState != null);
Debug.Assert(diagnostics != null);
this.body = body;
this.method = method;
this.stateMachineType = stateMachineType;
this.slotAllocatorOpt = slotAllocatorOpt;
this.synthesizedLocalOrdinals = new SynthesizedLocalOrdinalsDispenser();
this.diagnostics = diagnostics;
this.F = new SyntheticBoundNodeFactory(method, body.Syntax, compilationState, diagnostics);
Debug.Assert(F.CurrentType == method.ContainingType);
Debug.Assert(F.Syntax == body.Syntax);
}
示例5: Rewrite
/// <summary>
/// Rewrite an async method into a state machine type.
/// </summary>
internal static BoundStatement Rewrite(
BoundStatement body,
MethodSymbol method,
int methodOrdinal,
VariableSlotAllocator slotAllocatorOpt,
TypeCompilationState compilationState,
DiagnosticBag diagnostics,
out AsyncStateMachine stateMachineType)
{
if (!method.IsAsync)
{
stateMachineType = null;
return body;
}
// The CLR doesn't support adding fields to structs, so in order to enable EnC in an async method we need to generate a class.
var typeKind = compilationState.Compilation.Options.EnableEditAndContinue ? TypeKind.Class : TypeKind.Struct;
var bodyWithAwaitLifted = AwaitExpressionSpiller.Rewrite(body, method, compilationState, diagnostics);
stateMachineType = new AsyncStateMachine(slotAllocatorOpt, compilationState, method, methodOrdinal, typeKind);
compilationState.ModuleBuilderOpt.CompilationState.SetStateMachineType(method, stateMachineType);
var rewriter = new AsyncRewriter(bodyWithAwaitLifted, method, methodOrdinal, stateMachineType, slotAllocatorOpt, compilationState, diagnostics);
if (!rewriter.VerifyPresenceOfRequiredAPIs())
{
return body;
}
return rewriter.Rewrite();
}
示例6: Rewrite
internal static BoundBlock Rewrite(SourceMethodSymbol sourceMethodSymbol, MethodContractSyntax contract, BoundBlock body, TypeCompilationState compilationState, DiagnosticBag diagsForCurrentMethod)
{
var binder = compilationState.Compilation.GetBinderFactory(sourceMethodSymbol.SyntaxTree)
.GetBinder(body.Syntax);
SyntheticBoundNodeFactory factory = new SyntheticBoundNodeFactory(sourceMethodSymbol, sourceMethodSymbol.SyntaxNode, compilationState, diagsForCurrentMethod);
var contractType = compilationState.Compilation.GetTypeByReflectionType(typeof(System.Diagnostics.Contracts.Contract), diagsForCurrentMethod);
var contractStatements = ArrayBuilder<BoundStatement>.GetInstance(contract.Requires.Count);
foreach (var requires in contract.Requires)
{
var condition = binder.BindExpression(requires.Condition, diagsForCurrentMethod);
var methodCall = factory.StaticCall(contractType, "Requires", condition);
var statement = factory.ExpressionStatement(methodCall);
contractStatements.Add(statement);
}
foreach (var requires in contract.Ensures)
{
var condition = binder.BindExpression(requires.Condition, diagsForCurrentMethod);
var methodCall = factory.StaticCall(contractType, "Ensures", condition);
var statement = factory.ExpressionStatement(methodCall);
contractStatements.Add(statement);
}
return body.Update(body.Locals, body.Statements.InsertRange(0, contractStatements.ToImmutableAndFree()));
}
示例7: SpillFieldAllocator
internal SpillFieldAllocator(SyntheticBoundNodeFactory F, TypeCompilationState CompilationState)
{
allocatedFields = new KeyedStack<TypeSymbol, FieldSymbol>();
realizedSpills = new Dictionary<BoundSpillTemp, FieldSymbol>();
this.F = F;
this.CompilationState = CompilationState;
}
开发者ID:modulexcite,项目名称:pattern-matching-csharp,代码行数:7,代码来源:AwaitLoweringRewriterPass2_SpillFieldAllocator.cs
示例8: AsyncStruct
public AsyncStruct(MethodSymbol method, TypeCompilationState compilationState)
: base(method, GeneratedNames.MakeIteratorOrAsyncDisplayClassName(method.Name, compilationState.GenerateTempNumber()), TypeKind.Struct)
{
this.interfaces = ReadOnlyArray<NamedTypeSymbol>.CreateFrom(
compilationState.EmitModule.Compilation.GetWellKnownType(WellKnownType.System_Runtime_CompilerServices_IAsyncStateMachine));
this.constructor = new SynthesizedInstanceConstructor(this);
}
示例9: AsyncStateMachine
public AsyncStateMachine(VariableSlotAllocator variableAllocatorOpt, TypeCompilationState compilationState, MethodSymbol asyncMethod, int asyncMethodOrdinal, TypeKind typeKind)
: base(variableAllocatorOpt, compilationState, asyncMethod, asyncMethodOrdinal)
{
// TODO: report use-site errors on these types
_typeKind = typeKind;
_interfaces = ImmutableArray.Create(asyncMethod.DeclaringCompilation.GetWellKnownType(WellKnownType.System_Runtime_CompilerServices_IAsyncStateMachine));
_constructor = new AsyncConstructor(this);
}
示例10: ExpressionLambdaRewriter
private ExpressionLambdaRewriter(TypeCompilationState compilationState, CSharpSyntaxNode node, DiagnosticBag diagnostics)
{
Bound = new SyntheticBoundNodeFactory((NamedTypeSymbol)null, node, compilationState, diagnostics);
Int32Type = Bound.SpecialType(SpecialType.System_Int32);
ObjectType = Bound.SpecialType(SpecialType.System_Object);
NullableType = Bound.SpecialType(SpecialType.System_Nullable_T);
IEnumerableType = Bound.SpecialType(SpecialType.System_Collections_Generic_IEnumerable_T);
}
示例11: IteratorRewriter
private IteratorRewriter(
BoundStatement body,
MethodSymbol method,
bool isEnumerable,
IteratorStateMachine iteratorClass,
TypeCompilationState compilationState,
DiagnosticBag diagnostics)
: base(body, method, iteratorClass, compilationState, diagnostics)
{
// the element type may contain method type parameters, which are now alpha-renamed into type parameters of the generated class
this.elementType = iteratorClass.ElementType;
this.isEnumerable = isEnumerable;
}
示例12: AsyncRewriter
private AsyncRewriter(
BoundStatement body,
MethodSymbol method,
int methodOrdinal,
AsyncStateMachine stateMachineType,
VariableSlotAllocator slotAllocatorOpt,
TypeCompilationState compilationState,
DiagnosticBag diagnostics)
: base(body, method, stateMachineType, slotAllocatorOpt, compilationState, diagnostics)
{
_constructedSuccessfully = AsyncMethodBuilderMemberCollection.TryCreate(F, method, this.stateMachineType.TypeMap, out _asyncMethodBuilderMemberCollection);
_methodOrdinal = methodOrdinal;
_ignoreAccessibility = compilationState.ModuleBuilderOpt.IgnoreAccessibility;
}
示例13: IteratorRewriter
private IteratorRewriter(
BoundStatement body,
MethodSymbol method,
bool isEnumerable,
IteratorStateMachine stateMachineType,
VariableSlotAllocator slotAllocatorOpt,
TypeCompilationState compilationState,
DiagnosticBag diagnostics)
: base(body, method, stateMachineType, slotAllocatorOpt, compilationState, diagnostics)
{
// the element type may contain method type parameters, which are now alpha-renamed into type parameters of the generated class
_elementType = stateMachineType.ElementType;
_isEnumerable = isEnumerable;
}
示例14: StateMachineRewriter
protected StateMachineRewriter(
BoundStatement body,
MethodSymbol method,
SynthesizedContainer stateMachineClass,
TypeCompilationState compilationState,
DiagnosticBag diagnostics)
{
this.body = body;
this.method = method;
this.stateMachineClass = stateMachineClass;
this.compilationState = compilationState;
this.diagnostics = diagnostics;
this.F = new SyntheticBoundNodeFactory(method, body.Syntax, compilationState, diagnostics);
Debug.Assert(F.CurrentClass == method.ContainingType);
Debug.Assert(F.Syntax == body.Syntax);
}
示例15: AsyncRewriter
private AsyncRewriter(
BoundStatement body,
MethodSymbol method,
AsyncStateMachine stateMachineClass,
TypeCompilationState compilationState,
DiagnosticBag diagnostics)
: base(body, method, stateMachineClass, compilationState, diagnostics)
{
try
{
constructedSuccessfully = AsyncMethodBuilderMemberCollection.TryCreate(F, method, this.stateMachineClass.TypeMap, out this.asyncMethodBuilderMemberCollection);
}
catch (SyntheticBoundNodeFactory.MissingPredefinedMember ex)
{
diagnostics.Add(ex.Diagnostic);
constructedSuccessfully = false;
}
}