本文整理汇总了C#中Microsoft.CodeAnalysis.CSharp.SyntheticBoundNodeFactory.Local方法的典型用法代码示例。如果您正苦于以下问题:C# SyntheticBoundNodeFactory.Local方法的具体用法?C# SyntheticBoundNodeFactory.Local怎么用?C# SyntheticBoundNodeFactory.Local使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Microsoft.CodeAnalysis.CSharp.SyntheticBoundNodeFactory
的用法示例。
在下文中一共展示了SyntheticBoundNodeFactory.Local方法的4个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: 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);
}
示例2: AddAnalysisPoint
private BoundStatement AddAnalysisPoint(SyntaxNode syntaxForSpan, FileLinePositionSpan span, SyntheticBoundNodeFactory statementFactory)
{
// Add an entry in the spans array.
int spansIndex = _spansBuilder.Count;
_spansBuilder.Add(new SourceSpan(GetSourceDocument(syntaxForSpan, span), span.StartLinePosition.Line, span.StartLinePosition.Character, span.EndLinePosition.Line, span.EndLinePosition.Character));
// Generate "_payload[pointIndex] = true".
BoundArrayAccess payloadCell = statementFactory.ArrayAccess(statementFactory.Local(_methodPayload), statementFactory.Literal(spansIndex));
return statementFactory.Assignment(payloadCell, statementFactory.Literal(true));
}
示例3: 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);
}
示例4: 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);
}