本文整理汇总了C#中Microsoft.CodeAnalysis.CSharp.BoundBlock.Update方法的典型用法代码示例。如果您正苦于以下问题:C# BoundBlock.Update方法的具体用法?C# BoundBlock.Update怎么用?C# BoundBlock.Update使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类Microsoft.CodeAnalysis.CSharp.BoundBlock
的用法示例。
在下文中一共展示了BoundBlock.Update方法的5个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的C#代码示例。
示例1: VisitBlock
public override BoundNode VisitBlock(BoundBlock node)
{
if (node.WasCompilerGenerated || !this.generateDebugInfo)
{
return node.Update(node.LocalsOpt, VisitList(node.Statements));
}
BlockSyntax syntax = node.Syntax as BlockSyntax;
Debug.Assert(syntax != null);
var builder = ArrayBuilder<BoundStatement>.GetInstance();
var oBspan = syntax.OpenBraceToken.Span;
builder.Add(new BoundSequencePointWithSpan(syntax, null, oBspan));
for (int i = 0; i < node.Statements.Length; i++)
{
var stmt = (BoundStatement)Visit(node.Statements[i]);
if (stmt != null) builder.Add(stmt);
}
// no need to mark "}" on the outermost block
// as it cannot leave it normally. The block will have "return" at the end.
if (syntax.Parent == null || !(syntax.Parent.IsAnonymousFunction() || syntax.Parent is BaseMethodDeclarationSyntax))
{
var cBspan = syntax.CloseBraceToken.Span;
builder.Add(new BoundSequencePointWithSpan(syntax, null, cBspan));
}
return new BoundBlock(syntax, node.LocalsOpt, builder.ToImmutableAndFree(), node.HasErrors);
}
示例2: 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()));
}
示例3: VisitBlock
public override BoundNode VisitBlock(BoundBlock node)
{
if (!this.Instrument || (node != _rootStatement && (node.WasCompilerGenerated || node.Syntax.Kind() != SyntaxKind.Block)))
{
return node.Update(node.Locals, node.LocalFunctions, VisitList(node.Statements));
}
var builder = ArrayBuilder<BoundStatement>.GetInstance();
for (int i = 0; i < node.Statements.Length; i++)
{
var stmt = (BoundStatement)Visit(node.Statements[i]);
if (stmt != null) builder.Add(stmt);
}
LocalSymbol synthesizedLocal;
BoundStatement prologue = _instrumenter.CreateBlockPrologue(node, out synthesizedLocal);
if (prologue != null)
{
builder.Insert(0, prologue);
}
BoundStatement epilogue = _instrumenter.CreateBlockEpilogue(node);
if (epilogue != null)
{
builder.Add(epilogue);
}
return new BoundBlock(node.Syntax, synthesizedLocal == null ? node.Locals : node.Locals.Add(synthesizedLocal), node.LocalFunctions, builder.ToImmutableAndFree(), node.HasErrors);
}
示例4: AppendImplicitReturn
private static BoundBlock AppendImplicitReturn(BoundBlock body, MethodSymbol method, CSharpSyntaxNode syntax, bool originalBodyNested)
{
if (originalBodyNested)
{
var statements = body.Statements;
int n = statements.Length;
var builder = ArrayBuilder<BoundStatement>.GetInstance(n);
builder.AddRange(statements, n - 1);
builder.Add(AppendImplicitReturn((BoundBlock)statements[n - 1], method, syntax));
return body.Update(body.Locals, ImmutableArray<LocalFunctionSymbol>.Empty, builder.ToImmutableAndFree());
}
else
{
return AppendImplicitReturn(body, method, syntax);
}
}
示例5: AppendImplicitReturn
// insert the implicit "return" statement at the end of the method body
// Normally, we wouldn't bother attaching syntax trees to compiler-generated nodes, but these
// ones are going to have sequence points.
internal static BoundBlock AppendImplicitReturn(BoundBlock body, MethodSymbol method, CSharpSyntaxNode syntax = null)
{
Debug.Assert(body != null);
Debug.Assert(method != null);
if (syntax == null)
{
syntax = body.Syntax;
}
Debug.Assert(body.WasCompilerGenerated || syntax.IsKind(SyntaxKind.Block) || syntax.IsKind(SyntaxKind.ArrowExpressionClause));
BoundStatement ret = method.IsIterator
? (BoundStatement)BoundYieldBreakStatement.Synthesized(syntax)
: BoundReturnStatement.Synthesized(syntax, null);
// Implicitly added return for async method does not need sequence points since lowering would add one.
if (syntax.IsKind(SyntaxKind.Block) && !method.IsAsync)
{
var blockSyntax = (BlockSyntax)syntax;
ret = new BoundSequencePointWithSpan(
blockSyntax,
ret,
blockSyntax.CloseBraceToken.Span)
{ WasCompilerGenerated = true };
}
return body.Update(body.Locals, body.Statements.Add(ret));
}