本文整理汇总了C#中LocalSymbol.AsImmutableOrNull方法的典型用法代码示例。如果您正苦于以下问题:C# LocalSymbol.AsImmutableOrNull方法的具体用法?C# LocalSymbol.AsImmutableOrNull怎么用?C# LocalSymbol.AsImmutableOrNull使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类LocalSymbol
的用法示例。
在下文中一共展示了LocalSymbol.AsImmutableOrNull方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: BindForOrUsingOrFixedDeclarations
protected BoundStatement BindForOrUsingOrFixedDeclarations(VariableDeclarationSyntax nodeOpt, LocalDeclarationKind localDeclarationKind, DiagnosticBag diagnostics, out ImmutableArray<LocalSymbol> locals, out ImmutableArray<BoundLocalDeclaration> declarations)
{
if (nodeOpt == null)
{
locals = ImmutableArray<LocalSymbol>.Empty;
declarations = ImmutableArray<BoundLocalDeclaration>.Empty;
return null;
}
var typeSyntax = nodeOpt.Type;
AliasSymbol alias;
bool isVar;
TypeSymbol declType = BindType(typeSyntax, diagnostics, out isVar, out alias);
Debug.Assert((object)declType != null || isVar);
var variables = nodeOpt.Variables;
int count = variables.Count;
Debug.Assert(count > 0);
if (isVar && count > 1)
{
// There are a number of ways in which a var decl can be illegal, but in these
// cases we should report an error and then keep right on going with the inference.
Error(diagnostics, ErrorCode.ERR_ImplicitlyTypedVariableMultipleDeclarator, nodeOpt);
}
var declarationArray = new BoundLocalDeclaration[count];
var localArray = new LocalSymbol[count];
for (int i = 0; i < count; i++)
{
var variableDeclarator = variables[i];
var declaration = BindVariableDeclaration(localDeclarationKind, isVar, variableDeclarator, typeSyntax, declType, alias, diagnostics);
declarationArray[i] = declaration;
localArray[i] = declaration.LocalSymbol;
}
declarations = declarationArray.AsImmutableOrNull();
locals = localArray.AsImmutableOrNull();
return (count == 1) ?
(BoundStatement)declarations[0] :
new BoundMultipleLocalDeclarations(nodeOpt, declarations);
}
示例2: RewriteMultiDimensionalArrayForEachStatement
//.........这里部分代码省略.........
TypeSymbol iterationVarType = iterationVar.Type;
// (V)a[p_0, p_1, ...]
BoundExpression iterationVarInitValue = MakeConversion(
syntax: forEachSyntax,
rewrittenOperand: new BoundArrayAccess(forEachSyntax,
expression: boundArrayVar,
indices: ImmutableArray.Create((BoundExpression[])boundPositionVar),
type: arrayType.ElementType),
conversion: node.ElementConversion,
rewrittenType: iterationVarType,
@checked: node.Checked);
// V v = (V)a[p_0, p_1, ...];
BoundStatement iterationVarDecl = MakeLocalDeclaration(forEachSyntax, iterationVar, iterationVarInitValue);
AddForEachIterationVariableSequencePoint(forEachSyntax, ref iterationVarDecl);
// { V v = (V)a[p_0, p_1, ...]; /* node.Body */ }
BoundStatement innermostLoopBody = CreateBlockDeclaringIterationVariable(iterationVar, iterationVarDecl, rewrittenBody, forEachSyntax);
// work from most-nested to least-nested
// for (int p_0 = a.GetLowerBound(0); p_0 <= q_0; p_0 = p_0 + 1)
// for (int p_1 = a.GetLowerBound(0); p_1 <= q_1; p_1 = p_1 + 1)
// ...
// { V v = (V)a[p_0, p_1, ...]; /* node.Body */ }
BoundStatement forLoop = null;
for (int dimension = rank - 1; dimension >= 0; dimension--)
{
ImmutableArray<BoundExpression> dimensionArgument = ImmutableArray.Create(
MakeLiteral(forEachSyntax,
constantValue: ConstantValue.Create(dimension, ConstantValueTypeDiscriminator.Int32),
type: intType));
// a.GetLowerBound(dimension)
BoundExpression currentDimensionLowerBound = BoundCall.Synthesized(forEachSyntax, boundArrayVar, getLowerBoundMethod, dimensionArgument);
// int p_dimension = a.GetLowerBound(dimension);
BoundStatement positionVarDecl = MakeLocalDeclaration(forEachSyntax, positionVar[dimension], currentDimensionLowerBound);
GeneratedLabelSymbol breakLabel = dimension == 0 // outermost for-loop
? node.BreakLabel // i.e. the one that break statements will jump to
: new GeneratedLabelSymbol("break"); // Should not affect emitted code since unused
// p_dimension <= q_dimension //NB: OrEqual
BoundExpression exitCondition = new BoundBinaryOperator(
syntax: forEachSyntax,
operatorKind: BinaryOperatorKind.IntLessThanOrEqual,
left: boundPositionVar[dimension],
right: boundUpperVar[dimension],
constantValueOpt: null,
methodOpt: null,
resultKind: LookupResultKind.Viable,
type: boolType);
// p_dimension = p_dimension + 1;
BoundStatement positionIncrement = MakePositionIncrement(forEachSyntax, boundPositionVar[dimension], intType);
BoundStatement body;
GeneratedLabelSymbol continueLabel;
if (forLoop == null)
{
// innermost for-loop
body = innermostLoopBody;
continueLabel = node.ContinueLabel; //i.e. the one continue statements will actually jump to
}
else
{
body = forLoop;
continueLabel = new GeneratedLabelSymbol("continue"); // Should not affect emitted code since unused
}
forLoop = RewriteForStatement(
syntax: forEachSyntax,
outerLocals: ImmutableArray.Create(positionVar[dimension]),
rewrittenInitializer: positionVarDecl,
rewrittenCondition: exitCondition,
conditionSyntaxOpt: null,
conditionSpanOpt: forEachSyntax.InKeyword.Span,
rewrittenIncrement: positionIncrement,
rewrittenBody: body,
breakLabel: breakLabel,
continueLabel: continueLabel,
hasErrors: node.HasErrors);
}
Debug.Assert(forLoop != null);
BoundStatement result = new BoundBlock(
forEachSyntax,
ImmutableArray.Create(arrayVar).Concat(upperVar.AsImmutableOrNull()),
ImmutableArray<LocalFunctionSymbol>.Empty,
ImmutableArray.Create(arrayVarDecl).Concat(upperVarDecl.AsImmutableOrNull()).Add(forLoop));
AddForEachKeywordSequencePoint(forEachSyntax, ref result);
return result;
}
示例3: ConstructFieldLikeEventAccessorBody_Regular
//.........这里部分代码省略.........
receiver: fieldReceiver,
fieldSymbol: eventSymbol.AssociatedField,
constantValueOpt: null)
{ WasCompilerGenerated = true };
BoundParameter boundParameter = new BoundParameter(syntax,
parameterSymbol: accessor.Parameters[0])
{ WasCompilerGenerated = true };
// tmp0 = _event;
BoundStatement tmp0Init = new BoundExpressionStatement(syntax,
expression: new BoundAssignmentOperator(syntax,
left: boundTmps[0],
right: boundBackingField,
type: delegateType)
{ WasCompilerGenerated = true })
{ WasCompilerGenerated = true };
// LOOP:
BoundStatement loopStart = new BoundLabelStatement(syntax,
label: loopLabel)
{ WasCompilerGenerated = true };
// tmp1 = tmp0;
BoundStatement tmp1Update = new BoundExpressionStatement(syntax,
expression: new BoundAssignmentOperator(syntax,
left: boundTmps[1],
right: boundTmps[0],
type: delegateType)
{ WasCompilerGenerated = true })
{ WasCompilerGenerated = true };
// (DelegateType)Delegate.Combine(tmp1, value)
BoundExpression delegateUpdate = BoundConversion.SynthesizedNonUserDefined(syntax,
operand: BoundCall.Synthesized(syntax,
receiverOpt: null,
method: updateMethod,
arguments: ImmutableArray.Create<BoundExpression>(boundTmps[1], boundParameter)),
kind: ConversionKind.ExplicitReference,
type: delegateType);
// tmp2 = (DelegateType)Delegate.Combine(tmp1, value);
BoundStatement tmp2Update = new BoundExpressionStatement(syntax,
expression: new BoundAssignmentOperator(syntax,
left: boundTmps[2],
right: delegateUpdate,
type: delegateType)
{ WasCompilerGenerated = true })
{ WasCompilerGenerated = true };
// Interlocked.CompareExchange<DelegateType>(ref _event, tmp2, tmp1)
BoundExpression compareExchange = BoundCall.Synthesized(syntax,
receiverOpt: null,
method: compareExchangeMethod,
arguments: ImmutableArray.Create<BoundExpression>(boundBackingField, boundTmps[2], boundTmps[1]));
// tmp0 = Interlocked.CompareExchange<DelegateType>(ref _event, tmp2, tmp1);
BoundStatement tmp0Update = new BoundExpressionStatement(syntax,
expression: new BoundAssignmentOperator(syntax,
left: boundTmps[0],
right: compareExchange,
type: delegateType)
{ WasCompilerGenerated = true })
{ WasCompilerGenerated = true };
// tmp0 == tmp1 // i.e. exit when they are equal, jump to start otherwise
BoundExpression loopExitCondition = new BoundBinaryOperator(syntax,
operatorKind: BinaryOperatorKind.ObjectEqual,
left: boundTmps[0],
right: boundTmps[1],
constantValueOpt: null,
methodOpt: null,
resultKind: LookupResultKind.Viable,
type: boolType)
{ WasCompilerGenerated = true };
// branchfalse (tmp0 == tmp1) LOOP
BoundStatement loopEnd = new BoundConditionalGoto(syntax,
condition: loopExitCondition,
jumpIfTrue: false,
label: loopLabel)
{ WasCompilerGenerated = true };
BoundStatement @return = new BoundReturnStatement(syntax,
expressionOpt: null)
{ WasCompilerGenerated = true };
return new BoundBlock(syntax,
localsOpt: tmps.AsImmutableOrNull(),
statements: ImmutableArray.Create<BoundStatement>(
tmp0Init,
loopStart,
tmp1Update,
tmp2Update,
tmp0Update,
loopEnd,
@return))
{ WasCompilerGenerated = true };
}