本文整理汇总了C#中Microsoft.CodeAnalysis.CSharp.SyntheticBoundNodeFactory.SynthesizedLocal方法的典型用法代码示例。如果您正苦于以下问题:C# SyntheticBoundNodeFactory.SynthesizedLocal方法的具体用法?C# SyntheticBoundNodeFactory.SynthesizedLocal怎么用?C# SyntheticBoundNodeFactory.SynthesizedLocal使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Microsoft.CodeAnalysis.CSharp.SyntheticBoundNodeFactory
的用法示例。
在下文中一共展示了SyntheticBoundNodeFactory.SynthesizedLocal方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: AsyncMethodToStateMachineRewriter
internal AsyncMethodToStateMachineRewriter(
MethodSymbol method,
int methodOrdinal,
AsyncMethodBuilderMemberCollection asyncMethodBuilderMemberCollection,
SyntheticBoundNodeFactory F,
FieldSymbol state,
FieldSymbol builder,
IReadOnlySet<Symbol> hoistedVariables,
IReadOnlyDictionary<Symbol, CapturedSymbolReplacement> nonReusableLocalProxies,
SynthesizedLocalOrdinalsDispenser synthesizedLocalOrdinals,
VariableSlotAllocator slotAllocatorOpt,
int nextFreeHoistedLocalSlot,
DiagnosticBag diagnostics)
: base(F, method, state, hoistedVariables, nonReusableLocalProxies, synthesizedLocalOrdinals, slotAllocatorOpt, nextFreeHoistedLocalSlot, diagnostics, useFinalizerBookkeeping: false)
{
_method = method;
_asyncMethodBuilderMemberCollection = asyncMethodBuilderMemberCollection;
_asyncMethodBuilderField = builder;
_exprReturnLabel = F.GenerateLabel("exprReturn");
_exitLabel = F.GenerateLabel("exitLabel");
_exprRetValue = method.IsGenericTaskReturningAsync(F.Compilation)
? F.SynthesizedLocal(asyncMethodBuilderMemberCollection.ResultType, syntax: F.Syntax, kind: SynthesizedLocalKind.AsyncMethodReturnValue)
: null;
_dynamicFactory = new LoweredDynamicOperationFactory(F, methodOrdinal);
_awaiterFields = new Dictionary<TypeSymbol, FieldSymbol>(TypeSymbol.EqualsIgnoringDynamicComparer);
_nextAwaiterId = slotAllocatorOpt?.PreviousAwaiterSlotCount ?? 0;
}
示例2: MethodToStateMachineRewriter
public MethodToStateMachineRewriter(
SyntheticBoundNodeFactory F,
MethodSymbol originalMethod,
FieldSymbol state,
IReadOnlySet<Symbol> variablesCaptured,
IReadOnlyDictionary<Symbol, CapturedSymbolReplacement> nonReusableLocalProxies,
DiagnosticBag diagnostics,
bool useFinalizerBookkeeping)
: base(F.CompilationState, diagnostics)
{
Debug.Assert(F != null);
Debug.Assert(originalMethod != null);
Debug.Assert(state != null);
Debug.Assert(nonReusableLocalProxies != null);
Debug.Assert(diagnostics != null);
Debug.Assert(variablesCaptured != null);
this.F = F;
this.stateField = state;
this.cachedState = F.SynthesizedLocal(F.SpecialType(SpecialType.System_Int32), kind: SynthesizedLocalKind.StateMachineCachedState);
this.useFinalizerBookkeeping = useFinalizerBookkeeping;
this.hasFinalizerState = useFinalizerBookkeeping;
this.originalMethod = originalMethod;
this.variablesCaptured = variablesCaptured;
foreach (var proxy in nonReusableLocalProxies)
{
this.proxies.Add(proxy.Key, proxy.Value);
}
}
示例3: AsyncMethodToClassRewriter
internal AsyncMethodToClassRewriter(
MethodSymbol method,
AsyncMethodBuilderMemberCollection asyncMethodBuilderMemberCollection,
SyntheticBoundNodeFactory F,
FieldSymbol state,
FieldSymbol builder,
HashSet<Symbol> variablesCaptured,
Dictionary<Symbol, CapturedSymbolReplacement> initialProxies,
DiagnosticBag diagnostics,
bool generateDebugInfo)
: base(F, method, state, variablesCaptured, initialProxies, diagnostics,
useFinalizerBookkeeping: false,
generateDebugInfo: generateDebugInfo)
{
this.method = method;
this.asyncMethodBuilderMemberCollection = asyncMethodBuilderMemberCollection;
this.asyncMethodBuilderField = builder;
this.exprReturnLabel = F.GenerateLabel("exprReturn");
this.exitLabel = F.GenerateLabel("exitLabel");
this.exprRetValue = method.IsGenericTaskReturningAsync(F.Compilation)
? F.SynthesizedLocal(asyncMethodBuilderMemberCollection.ResultType, GeneratedNames.AsyncExprRetValueFieldName())
: null;
this.dynamicFactory = new LoweredDynamicOperationFactory(F);
}
示例4: DynamicAnalysisInjector
private DynamicAnalysisInjector(MethodSymbol method, BoundStatement methodBody, SyntheticBoundNodeFactory methodBodyFactory, MethodSymbol createPayload, DiagnosticBag diagnostics, DebugDocumentProvider debugDocumentProvider, Instrumenter previous)
: base(previous)
{
_createPayload = createPayload;
_method = method;
_methodBody = methodBody;
_spansBuilder = ArrayBuilder<SourceSpan>.GetInstance();
TypeSymbol payloadElementType = methodBodyFactory.SpecialType(SpecialType.System_Boolean);
_payloadType = ArrayTypeSymbol.CreateCSharpArray(methodBodyFactory.Compilation.Assembly, payloadElementType);
_methodPayload = methodBodyFactory.SynthesizedLocal(_payloadType, kind: SynthesizedLocalKind.InstrumentationPayload, syntax: methodBody.Syntax);
_diagnostics = diagnostics;
_debugDocumentProvider = debugDocumentProvider;
_methodHasExplicitBlock = MethodHasExplicitBlock(method);
_methodBodyFactory = methodBodyFactory;
// The first point indicates entry into the method and has the span of the method definition.
_methodEntryInstrumentation = AddAnalysisPoint(MethodDeclarationIfAvailable(methodBody.Syntax), methodBodyFactory);
}
示例5: StateMachineMethodToClassRewriter
public StateMachineMethodToClassRewriter(
SyntheticBoundNodeFactory F,
MethodSymbol originalMethod,
FieldSymbol state,
HashSet<Symbol> variablesCaptured,
Dictionary<Symbol, CapturedSymbolReplacement> initialProxies,
DiagnosticBag diagnostics,
bool useFinalizerBookkeeping,
bool generateDebugInfo)
: base(F.CompilationState, diagnostics, generateDebugInfo)
{
this.F = F;
this.stateField = state;
this.cachedState = F.SynthesizedLocal(F.SpecialType(SpecialType.System_Int32), "cachedState");
this.variablesCaptured = variablesCaptured;
this.useFinalizerBookkeeping = useFinalizerBookkeeping;
this.hasFinalizerState = useFinalizerBookkeeping;
this.originalMethod = originalMethod;
foreach (var p in initialProxies) this.proxies.Add(p.Key, p.Value);
}
示例6: AsyncMethodToClassRewriter
internal AsyncMethodToClassRewriter(
MethodSymbol method,
AsyncMethodBuilderMemberCollection asyncMethodBuilderMemberCollection,
SyntheticBoundNodeFactory factory,
FieldSymbol state,
FieldSymbol builder,
Dictionary<Symbol, CapturedSymbol> localProxies,
DiagnosticBag diagnostics)
: base(factory, state, localProxies, diagnostics)
{
this.method = method;
this.asyncMethodBuilderMemberCollection = asyncMethodBuilderMemberCollection;
this.asyncMethodBuilderField = builder;
this.exprReturnLabel = factory.GenerateLabel("exprReturn");
this.exprRetValue = method.IsGenericTaskReturningAsync()
? factory.SynthesizedLocal(asyncMethodBuilderMemberCollection.ResultType, GeneratedNames.AsyncExprRetValueFieldName())
: null;
this.dynamicFactory = new LoweredDynamicOperationFactory(factory);
}
示例7: AsyncMethodToStateMachineRewriter
internal AsyncMethodToStateMachineRewriter(
MethodSymbol method,
AsyncMethodBuilderMemberCollection asyncMethodBuilderMemberCollection,
SyntheticBoundNodeFactory F,
FieldSymbol state,
FieldSymbol builder,
IReadOnlySet<Symbol> variablesCaptured,
IReadOnlyDictionary<Symbol, CapturedSymbolReplacement> nonReusableLocalProxies,
DiagnosticBag diagnostics)
: base(F, method, state, variablesCaptured, nonReusableLocalProxies, diagnostics, useFinalizerBookkeeping: false)
{
this.method = method;
this.asyncMethodBuilderMemberCollection = asyncMethodBuilderMemberCollection;
this.asyncMethodBuilderField = builder;
this.exprReturnLabel = F.GenerateLabel("exprReturn");
this.exitLabel = F.GenerateLabel("exitLabel");
this.exprRetValue = method.IsGenericTaskReturningAsync(F.Compilation)
? F.SynthesizedLocal(asyncMethodBuilderMemberCollection.ResultType, kind: SynthesizedLocalKind.AsyncMethodReturnValue)
: null;
this.dynamicFactory = new LoweredDynamicOperationFactory(F);
}
示例8: InitializeFixedStatementArrayLocal
private BoundStatement InitializeFixedStatementArrayLocal(
LocalSymbol localSymbol,
BoundFixedLocalCollectionInitializer fixedInitializer,
SyntheticBoundNodeFactory factory,
out LocalSymbol arrayTemp)
{
// From ExpressionBinder::BindPtrToArray:
// (((temp = array) != null && temp.Length > 0) ? loc = &temp[0] : loc = null)
// NOTE: The assignment needs to be inside the EK_QUESTIONMARK. See Whidbey bug #397859.
// We can't do loc = (... ? ... : ...) since the CLR type of &temp[0] is a managed
// pointer and null is a UIntPtr - which confuses the JIT. We can't just convert
// &temp[0] to UIntPtr with a conv.u instruction because then if a GC occurs between
// the time of the cast and the assignment to the local, we're toast.
TypeSymbol localType = localSymbol.Type;
BoundExpression initializerExpr = VisitExpression(fixedInitializer.Expression);
TypeSymbol initializerType = initializerExpr.Type;
arrayTemp = factory.SynthesizedLocal(initializerType);
ArrayTypeSymbol arrayType = (ArrayTypeSymbol)arrayTemp.Type;
TypeSymbol arrayElementType = arrayType.ElementType;
int arrayRank = arrayType.Rank;
// NOTE: we pin the pointer, not the array.
Debug.Assert(!arrayTemp.IsPinned);
Debug.Assert(localSymbol.IsPinned);
//(temp = array)
BoundExpression arrayTempInit = factory.AssignmentExpression(factory.Local(arrayTemp), initializerExpr);
//(temp = array) != null
BoundExpression notNullCheck = MakeNullCheck(factory.Syntax, arrayTempInit, BinaryOperatorKind.NotEqual);
BoundExpression lengthCall;
if (arrayRank == 1)
{
lengthCall = factory.ArrayLength(factory.Local(arrayTemp));
}
else
{
MethodSymbol lengthMethod;
if (TryGetWellKnownTypeMember(fixedInitializer.Syntax, WellKnownMember.System_Array__get_Length, out lengthMethod))
{
lengthCall = factory.Call(factory.Local(arrayTemp), lengthMethod);
}
else
{
lengthCall = new BoundBadExpression(fixedInitializer.Syntax, LookupResultKind.NotInvocable, ImmutableArray<Symbol>.Empty, ImmutableArray.Create<BoundNode>(factory.Local(arrayTemp)), ErrorTypeSymbol.UnknownResultType);
}
}
// NOTE: dev10 comment says ">", but code actually checks "!="
//temp.Length != 0
BoundExpression lengthCheck = factory.Binary(BinaryOperatorKind.IntNotEqual, factory.SpecialType(SpecialType.System_Boolean), lengthCall, factory.Literal(0));
//((temp = array) != null && temp.Length != 0)
BoundExpression condition = factory.Binary(BinaryOperatorKind.LogicalBoolAnd, factory.SpecialType(SpecialType.System_Boolean), notNullCheck, lengthCheck);
//temp[0]
BoundExpression firstElement = factory.ArrayAccessFirstElement(factory.Local(arrayTemp));
// NOTE: this is a fixed statement address-of in that it's the initial value of pinned local.
//&temp[0]
BoundExpression firstElementAddress = new BoundAddressOfOperator(factory.Syntax, firstElement, isFixedStatementAddressOf: true, type: new PointerTypeSymbol(arrayElementType));
BoundExpression convertedFirstElementAddress = factory.Convert(
localType,
firstElementAddress,
fixedInitializer.ElementPointerTypeConversion);
//loc = &temp[0]
BoundExpression consequenceAssignment = factory.AssignmentExpression(factory.Local(localSymbol), convertedFirstElementAddress);
//loc = null
BoundExpression alternativeAssignment = factory.AssignmentExpression(factory.Local(localSymbol), factory.Null(localType));
//(((temp = array) != null && temp.Length != 0) ? loc = &temp[0] : loc = null)
BoundStatement localInit = factory.ExpressionStatement(
new BoundConditionalOperator(factory.Syntax, condition, consequenceAssignment, alternativeAssignment, ConstantValue.NotAvailable, localType));
return AddLocalDeclarationSequencePointIfNecessary(fixedInitializer.Syntax.Parent.Parent, localSymbol, localInit);
}
示例9: InitializeFixedStatementStringLocal
private BoundStatement InitializeFixedStatementStringLocal(
LocalSymbol localSymbol,
BoundFixedLocalCollectionInitializer fixedInitializer,
SyntheticBoundNodeFactory factory,
out LocalSymbol stringTemp,
out LocalSymbol localToClear)
{
TypeSymbol localType = localSymbol.Type;
BoundExpression initializerExpr = VisitExpression(fixedInitializer.Expression);
TypeSymbol initializerType = initializerExpr.Type;
// intervening parens may have been skipped by the binder; find the declarator
VariableDeclaratorSyntax declarator = fixedInitializer.Syntax.FirstAncestorOrSelf<VariableDeclaratorSyntax>();
Debug.Assert(declarator != null);
stringTemp = factory.SynthesizedLocal(initializerType, syntax: declarator, isPinned: true, kind: SynthesizedLocalKind.FixedString);
// NOTE: we pin the string, not the pointer.
Debug.Assert(stringTemp.IsPinned);
Debug.Assert(!localSymbol.IsPinned);
BoundStatement stringTempInit = factory.Assignment(factory.Local(stringTemp), initializerExpr);
var convertedStringTemp = factory.Convert(
localType,
factory.Local(stringTemp),
fixedInitializer.ElementPointerTypeConversion);
BoundStatement localInit = AddLocalDeclarationSequencePointIfNecessary(declarator, localSymbol,
factory.Assignment(factory.Local(localSymbol), convertedStringTemp));
BoundExpression notNullCheck = MakeNullCheck(factory.Syntax, factory.Local(stringTemp), BinaryOperatorKind.NotEqual);
BoundExpression helperCall;
MethodSymbol offsetMethod;
if (TryGetWellKnownTypeMember(fixedInitializer.Syntax, WellKnownMember.System_Runtime_CompilerServices_RuntimeHelpers__get_OffsetToStringData, out offsetMethod))
{
helperCall = factory.Call(receiver: null, method: offsetMethod);
}
else
{
helperCall = new BoundBadExpression(fixedInitializer.Syntax, LookupResultKind.NotInvocable, ImmutableArray<Symbol>.Empty, ImmutableArray<BoundNode>.Empty, ErrorTypeSymbol.UnknownResultType);
}
BoundExpression addition = factory.Binary(BinaryOperatorKind.PointerAndIntAddition, localType, factory.Local(localSymbol), helperCall);
BoundStatement conditionalAdd = factory.If(notNullCheck, factory.Assignment(factory.Local(localSymbol), addition));
localToClear = stringTemp;
return factory.Block(stringTempInit, localInit, conditionalAdd);
}
示例10: HoistLocal
public void HoistLocal(LocalSymbol local, SyntheticBoundNodeFactory F)
{
if (!_hoistedLocals.Keys.Any(l => l.Name == local.Name && l.Type == local.Type))
{
_hoistedLocals.Add(local, local);
_orderedHoistedLocals.Add(local);
return;
}
// code uses "await" in two sibling catches with exception filters
// locals with same names and types may cause problems if they are lifted
// and become fields with identical signatures.
// To avoid such problems we will mangle the name of the second local.
// This will only affect debugging of this extremely rare case.
Debug.Assert(pendingCatch.SyntaxOpt.IsKind(SyntaxKind.TryStatement));
var newLocal = F.SynthesizedLocal(local.Type, pendingCatch.SyntaxOpt, kind: SynthesizedLocalKind.ExceptionFilterAwaitHoistedExceptionLocal);
_hoistedLocals.Add(local, newLocal);
_orderedHoistedLocals.Add(newLocal);
}
示例11: MethodToStateMachineRewriter
// new:
public MethodToStateMachineRewriter(
SyntheticBoundNodeFactory F,
MethodSymbol originalMethod,
FieldSymbol state,
IReadOnlySet<Symbol> hoistedVariables,
IReadOnlyDictionary<Symbol, CapturedSymbolReplacement> nonReusableLocalProxies,
SynthesizedLocalOrdinalsDispenser synthesizedLocalOrdinals,
VariableSlotAllocator slotAllocatorOpt,
int nextFreeHoistedLocalSlot,
DiagnosticBag diagnostics,
bool useFinalizerBookkeeping)
: base(slotAllocatorOpt, F.CompilationState, diagnostics)
{
Debug.Assert(F != null);
Debug.Assert(originalMethod != null);
Debug.Assert(state != null);
Debug.Assert(nonReusableLocalProxies != null);
Debug.Assert(diagnostics != null);
Debug.Assert(hoistedVariables != null);
Debug.Assert(nextFreeHoistedLocalSlot >= 0);
this.F = F;
this.stateField = state;
this.cachedState = F.SynthesizedLocal(F.SpecialType(SpecialType.System_Int32), syntax: F.Syntax, kind: SynthesizedLocalKind.StateMachineCachedState);
_useFinalizerBookkeeping = useFinalizerBookkeeping;
_hasFinalizerState = useFinalizerBookkeeping;
this.OriginalMethod = originalMethod;
_hoistedVariables = hoistedVariables;
_synthesizedLocalOrdinals = synthesizedLocalOrdinals;
_nextFreeHoistedLocalSlot = nextFreeHoistedLocalSlot;
foreach (var proxy in nonReusableLocalProxies)
{
this.proxies.Add(proxy.Key, proxy.Value);
}
}
示例12: HoistLocal
public void HoistLocal(LocalSymbol local, SyntheticBoundNodeFactory F)
{
if (!hoistedLocals.Keys.Any(l => l.Name == local.Name && l.Type == local.Type))
{
hoistedLocals.Add(local, local);
return;
}
// code uses "await" in two sibling catches with exception filters
// locals with same names and types may cause problems if they are lifted
// and become fields with identical signatures.
// To avoid such problems we will mangle the name of the second local.
// This will only affect debugging of this extremely rare case.
var newName = GeneratedNames.MakeIteratorLocalName(local.Name, hoistedLocals.Count);
var newLocal = F.SynthesizedLocal(local.Type, newName);
hoistedLocals.Add(local, newLocal);
}
示例13: AwaitCatchFrame
public AwaitCatchFrame(SyntheticBoundNodeFactory F)
{
this.pendingCaughtException = F.SynthesizedLocal(F.SpecialType(SpecialType.System_Object));
this.pendingCatch = F.SynthesizedLocal(F.SpecialType(SpecialType.System_Int32));
this.handlers = new List<BoundBlock>();
this.hoistedLocals = new Dictionary<LocalSymbol, LocalSymbol>();
}
示例14: MethodToStateMachineRewriter
// new:
public MethodToStateMachineRewriter(
SyntheticBoundNodeFactory F,
MethodSymbol originalMethod,
FieldSymbol state,
IReadOnlySet<Symbol> hoistedVariables,
IReadOnlyDictionary<Symbol, CapturedSymbolReplacement> nonReusableLocalProxies,
SynthesizedLocalOrdinalsDispenser synthesizedLocalOrdinals,
VariableSlotAllocator slotAllocatorOpt,
int nextFreeHoistedLocalSlot,
DiagnosticBag diagnostics,
bool useFinalizerBookkeeping)
: base(slotAllocatorOpt, F.CompilationState, diagnostics)
{
Debug.Assert(F != null);
Debug.Assert(originalMethod != null);
Debug.Assert(state != null);
Debug.Assert(nonReusableLocalProxies != null);
Debug.Assert(diagnostics != null);
Debug.Assert(hoistedVariables != null);
Debug.Assert(nextFreeHoistedLocalSlot >= 0);
this.F = F;
this.stateField = state;
this.cachedState = F.SynthesizedLocal(F.SpecialType(SpecialType.System_Int32), syntax: F.Syntax, kind: SynthesizedLocalKind.StateMachineCachedState);
_useFinalizerBookkeeping = useFinalizerBookkeeping;
_hasFinalizerState = useFinalizerBookkeeping;
this.OriginalMethod = originalMethod;
_hoistedVariables = hoistedVariables;
_synthesizedLocalOrdinals = synthesizedLocalOrdinals;
_nextFreeHoistedLocalSlot = nextFreeHoistedLocalSlot;
foreach (var proxy in nonReusableLocalProxies)
{
this.proxies.Add(proxy.Key, proxy.Value);
}
// create cache local for reference type "this" in Release
var thisParameter = originalMethod.ThisParameter;
CapturedSymbolReplacement thisProxy;
if ((object)thisParameter != null &&
thisParameter.Type.IsReferenceType &&
proxies.TryGetValue(thisParameter, out thisProxy) &&
F.Compilation.Options.OptimizationLevel == OptimizationLevel.Release)
{
BoundExpression thisProxyReplacement = thisProxy.Replacement(F.Syntax, frameType => F.This());
this.cachedThis = F.SynthesizedLocal(thisProxyReplacement.Type, syntax: F.Syntax, kind: SynthesizedLocalKind.FrameCache);
}
}
示例15: AddConditionSequencePoint
private static BoundExpression AddConditionSequencePoint(BoundExpression condition, SyntaxNode synthesizedVariableSyntax, SyntheticBoundNodeFactory factory)
{
if (!factory.Compilation.Options.EnableEditAndContinue)
{
return condition;
}
// The local has to be associated with a syntax that is tracked by EnC source mapping.
// At most one ConditionalBranchDiscriminator variable shall be associated with any given EnC tracked syntax node.
var local = factory.SynthesizedLocal(condition.Type, synthesizedVariableSyntax, kind: SynthesizedLocalKind.ConditionalBranchDiscriminator);
// Add hidden sequence point unless the condition is a constant expression.
// Constant expression must stay a const to not invalidate results of control flow analysis.
var valueExpression = (condition.ConstantValue == null) ?
new BoundSequencePointExpression(syntax: null, expression: factory.Local(local), type: condition.Type) :
condition;
return new BoundSequence(
condition.Syntax,
ImmutableArray.Create(local),
ImmutableArray.Create<BoundExpression>(factory.AssignmentExpression(factory.Local(local), condition)),
valueExpression,
condition.Type);
}