提交 37e8a94a 编写于 作者: T Ty Overby 提交者: GitHub

added a local-functionsless constructor for BoundBlock (#13408)

上级 48a14c14
......@@ -755,9 +755,7 @@ internal BoundStatement WrapWithVariablesIfAny(CSharpSyntaxNode scopeDesignator,
return statement;
}
return new BoundBlock(statement.Syntax, locals,
ImmutableArray<LocalFunctionSymbol>.Empty,
ImmutableArray.Create(statement))
return new BoundBlock(statement.Syntax, locals, ImmutableArray.Create(statement))
{ WasCompilerGenerated = true };
}
......
......@@ -3606,7 +3606,7 @@ internal BoundBlock CreateBlockFromExpression(CSharpSyntaxNode node, ImmutableAr
}
// Need to attach the tree for when we generate sequence points.
return new BoundBlock(node, locals, ImmutableArray<LocalFunctionSymbol>.Empty, ImmutableArray.Create(statement)) { WasCompilerGenerated = node.Kind() != SyntaxKind.ArrowExpressionClause };
return new BoundBlock(node, locals, ImmutableArray.Create(statement)) { WasCompilerGenerated = node.Kind() != SyntaxKind.ArrowExpressionClause };
}
/// <summary>
......
......@@ -502,21 +502,24 @@ public BoundGotoStatement(SyntaxNode syntax, LabelSymbol label, bool hasErrors =
internal partial class BoundBlock
{
public BoundBlock(SyntaxNode syntax, ImmutableArray<LocalSymbol> locals, ImmutableArray<BoundStatement> statements, bool hasErrors = false): this(syntax, locals, ImmutableArray<LocalFunctionSymbol>.Empty, statements, hasErrors)
{
}
public static BoundBlock SynthesizedNoLocals(SyntaxNode syntax, BoundStatement statement)
{
return new BoundBlock(syntax, ImmutableArray<LocalSymbol>.Empty, ImmutableArray<LocalFunctionSymbol>.Empty,
ImmutableArray.Create(statement))
return new BoundBlock(syntax, ImmutableArray<LocalSymbol>.Empty, ImmutableArray.Create(statement))
{ WasCompilerGenerated = true };
}
public static BoundBlock SynthesizedNoLocals(SyntaxNode syntax, ImmutableArray<BoundStatement> statements)
{
return new BoundBlock(syntax, ImmutableArray<LocalSymbol>.Empty, ImmutableArray<LocalFunctionSymbol>.Empty, statements) { WasCompilerGenerated = true };
return new BoundBlock(syntax, ImmutableArray<LocalSymbol>.Empty, statements) { WasCompilerGenerated = true };
}
public static BoundBlock SynthesizedNoLocals(SyntaxNode syntax, params BoundStatement[] statements)
{
return new BoundBlock(syntax, ImmutableArray<LocalSymbol>.Empty, ImmutableArray<LocalFunctionSymbol>.Empty, statements.AsImmutableOrNull()) { WasCompilerGenerated = true };
return new BoundBlock(syntax, ImmutableArray<LocalSymbol>.Empty, statements.AsImmutableOrNull()) { WasCompilerGenerated = true };
}
}
......
......@@ -498,7 +498,6 @@ internal static BoundBlock ConstructFieldLikeEventAccessorBody_Regular(SourceEve
return new BoundBlock(syntax,
locals: tmps.AsImmutable(),
localFunctions: ImmutableArray<LocalFunctionSymbol>.Empty,
statements: ImmutableArray.Create<BoundStatement>(
tmp0Init,
loopStart,
......@@ -542,7 +541,6 @@ internal static BoundBlock ConstructDestructorBody(MethodSymbol method, BoundBlo
return new BoundBlock(
syntax,
ImmutableArray<LocalSymbol>.Empty,
ImmutableArray<LocalFunctionSymbol>.Empty,
ImmutableArray.Create<BoundStatement>(
new BoundTryStatement(
syntax,
......@@ -551,7 +549,6 @@ internal static BoundBlock ConstructDestructorBody(MethodSymbol method, BoundBlo
new BoundBlock(
syntax,
ImmutableArray<LocalSymbol>.Empty,
ImmutableArray<LocalFunctionSymbol>.Empty,
ImmutableArray.Create<BoundStatement>(
baseFinalizeCall)
)
......
......@@ -854,7 +854,7 @@ public override object VisitField(FieldSymbol symbol, TypeCompilationState argum
if (methodSymbol.IsScriptConstructor)
{
body = new BoundBlock(methodSymbol.GetNonNullSyntaxNode(), ImmutableArray<LocalSymbol>.Empty, ImmutableArray<LocalFunctionSymbol>.Empty, ImmutableArray<BoundStatement>.Empty) { WasCompilerGenerated = true };
body = new BoundBlock(methodSymbol.GetNonNullSyntaxNode(), ImmutableArray<LocalSymbol>.Empty, ImmutableArray<BoundStatement>.Empty) { WasCompilerGenerated = true };
}
else if (methodSymbol.IsScriptInitializer)
{
......
......@@ -58,7 +58,7 @@ internal class FlowAnalysisPass
var trailingExpression = new BoundDefaultOperator(method.GetNonNullSyntaxNode(), submissionResultType);
var newStatements = block.Statements.Add(new BoundReturnStatement(trailingExpression.Syntax, RefKind.None, trailingExpression));
block = new BoundBlock(block.Syntax, ImmutableArray<LocalSymbol>.Empty, ImmutableArray<LocalFunctionSymbol>.Empty, newStatements) { WasCompilerGenerated = true };
block = new BoundBlock(block.Syntax, ImmutableArray<LocalSymbol>.Empty, newStatements) { WasCompilerGenerated = true };
#if DEBUG
// It should not be necessary to repeat analysis after adding this node, because adding a trailing
// return in cases where one was missing should never produce different Diagnostics.
......
......@@ -267,7 +267,7 @@ private BoundStatement AddStatementsIfNeeded(BoundStatement body)
if (_addedLocals != null)
{
_addedStatements.Add(body);
body = new BoundBlock(body.Syntax, _addedLocals.ToImmutableAndFree(), ImmutableArray<LocalFunctionSymbol>.Empty, _addedStatements.ToImmutableAndFree()) { WasCompilerGenerated = true };
body = new BoundBlock(body.Syntax, _addedLocals.ToImmutableAndFree(), _addedStatements.ToImmutableAndFree()) { WasCompilerGenerated = true };
_addedLocals = null;
_addedStatements = null;
}
......@@ -1046,7 +1046,7 @@ public override BoundNode VisitStatementList(BoundStatementList node)
newStatements.Add((BoundStatement)this.Visit(s));
}
return new BoundBlock(node.Syntax, newLocals.ToImmutableAndFree(), ImmutableArray<LocalFunctionSymbol>.Empty, newStatements.ToImmutableAndFree(), node.HasErrors);
return new BoundBlock(node.Syntax, newLocals.ToImmutableAndFree(), newStatements.ToImmutableAndFree(), node.HasErrors);
});
}
else
......@@ -1067,7 +1067,7 @@ public override BoundNode VisitSwitchStatement(BoundSwitchStatement node)
InsertAndFreePrologue(newStatements, prologue);
newStatements.Add((BoundStatement)base.VisitSwitchStatement(node));
return new BoundBlock(node.Syntax, newLocals.ToImmutableAndFree(), ImmutableArray<LocalFunctionSymbol>.Empty, newStatements.ToImmutableAndFree(), node.HasErrors);
return new BoundBlock(node.Syntax, newLocals.ToImmutableAndFree(), newStatements.ToImmutableAndFree(), node.HasErrors);
});
}
else
......
......@@ -44,7 +44,7 @@ public override BoundNode VisitBlock(BoundBlock node)
public override BoundNode VisitNoOpStatement(BoundNoOpStatement node)
{
return (node.WasCompilerGenerated || !this.Instrument)
? new BoundBlock(node.Syntax, ImmutableArray<LocalSymbol>.Empty, ImmutableArray<LocalFunctionSymbol>.Empty, ImmutableArray<BoundStatement>.Empty)
? new BoundBlock(node.Syntax, ImmutableArray<LocalSymbol>.Empty, ImmutableArray<BoundStatement>.Empty)
: _instrumenter.InstrumentNoOpStatement(node, node);
}
}
......
......@@ -209,7 +209,6 @@ private BoundStatement RewriteEnumeratorForEachStatement(BoundForEachStatement n
finallyBlockOpt = new BoundBlock(forEachSyntax,
locals: ImmutableArray<LocalSymbol>.Empty,
localFunctions: ImmutableArray<LocalFunctionSymbol>.Empty,
statements: ImmutableArray.Create<BoundStatement>(disposeStmt));
}
else
......@@ -261,7 +260,6 @@ private BoundStatement RewriteEnumeratorForEachStatement(BoundForEachStatement n
// if (d != null) d.Dispose();
finallyBlockOpt = new BoundBlock(forEachSyntax,
locals: ImmutableArray.Create<LocalSymbol>(disposableVar),
localFunctions: ImmutableArray<LocalFunctionSymbol>.Empty,
statements: ImmutableArray.Create<BoundStatement>(disposableVarDecl, ifStmt));
}
......@@ -277,7 +275,6 @@ private BoundStatement RewriteEnumeratorForEachStatement(BoundForEachStatement n
BoundStatement tryFinally = new BoundTryStatement(forEachSyntax,
tryBlock: new BoundBlock(forEachSyntax,
locals: ImmutableArray<LocalSymbol>.Empty,
localFunctions: ImmutableArray<LocalFunctionSymbol>.Empty,
statements: ImmutableArray.Create<BoundStatement>(whileLoop)),
catchBlocks: ImmutableArray<BoundCatchBlock>.Empty,
finallyBlockOpt: finallyBlockOpt);
......@@ -288,7 +285,6 @@ private BoundStatement RewriteEnumeratorForEachStatement(BoundForEachStatement n
result = new BoundBlock(
syntax: forEachSyntax,
locals: ImmutableArray.Create(enumeratorVar),
localFunctions: ImmutableArray<LocalFunctionSymbol>.Empty,
statements: ImmutableArray.Create<BoundStatement>(enumeratorVarDecl, tryFinally));
}
else
......@@ -301,7 +297,6 @@ private BoundStatement RewriteEnumeratorForEachStatement(BoundForEachStatement n
result = new BoundBlock(
syntax: forEachSyntax,
locals: ImmutableArray.Create(enumeratorVar),
localFunctions: ImmutableArray<LocalFunctionSymbol>.Empty,
statements: ImmutableArray.Create<BoundStatement>(enumeratorVarDecl, whileLoop));
}
......@@ -549,7 +544,6 @@ private BoundStatement RewriteStringForEachStatement(BoundForEachStatement node)
return new BoundBlock(
forEachSyntax,
locals: iterationVariables,
localFunctions: ImmutableArray<LocalFunctionSymbol>.Empty,
statements: ImmutableArray.Create(iteratorVariableInitialization, rewrittenBody));
}
......@@ -865,7 +859,6 @@ private BoundStatement RewriteMultiDimensionalArrayForEachStatement(BoundForEach
BoundStatement result = new BoundBlock(
forEachSyntax,
ImmutableArray.Create(arrayVar).Concat(upperVar.AsImmutableOrNull()),
ImmutableArray<LocalFunctionSymbol>.Empty,
ImmutableArray.Create(arrayVarDecl).Concat(upperVarDecl.AsImmutableOrNull()).Add(forLoop));
InstrumentForEachStatement(node, ref result);
......
......@@ -168,7 +168,7 @@ public override BoundNode VisitForStatement(BoundForStatement node)
statementBuilder.Add(new BoundLabelStatement(syntax, breakLabel));
var statements = statementBuilder.ToImmutableAndFree();
return new BoundBlock(syntax, outerLocals, ImmutableArray<LocalFunctionSymbol>.Empty, statements, hasErrors);
return new BoundBlock(syntax, outerLocals, statements, hasErrors);
}
}
}
......@@ -120,7 +120,6 @@ public override BoundNode VisitLockStatement(BoundLockStatement node)
return new BoundBlock(
lockSyntax,
ImmutableArray.Create(boundLockTemp.LocalSymbol, boundLockTakenTemp.LocalSymbol),
ImmutableArray<LocalFunctionSymbol>.Empty,
ImmutableArray.Create(
InstrumentLockTargetCapture(node, boundLockTempInit),
boundLockTakenTempInit,
......@@ -171,7 +170,6 @@ public override BoundNode VisitLockStatement(BoundLockStatement node)
return new BoundBlock(
lockSyntax,
ImmutableArray.Create(boundLockTemp.LocalSymbol),
ImmutableArray<LocalFunctionSymbol>.Empty,
ImmutableArray.Create(
InstrumentLockTargetCapture(node, boundLockTempInit),
enterCall,
......
......@@ -184,7 +184,6 @@ public override BoundNode VisitSwitchStatement(BoundSwitchStatement node)
return new BoundBlock(
syntax,
locals: (object)tempLocal == null ? ImmutableArray<LocalSymbol>.Empty : ImmutableArray.Create<LocalSymbol>(tempLocal),
localFunctions: ImmutableArray<LocalFunctionSymbol>.Empty,
statements: statementBuilder.ToImmutableAndFree());
}
......
......@@ -56,7 +56,6 @@ public override BoundNode VisitUsingStatement(BoundUsingStatement node)
return new BoundBlock(
usingSyntax,
node.Locals,
ImmutableArray<LocalFunctionSymbol>.Empty,
ImmutableArray.Create<BoundStatement>(result));
}
}
......@@ -142,7 +141,6 @@ private BoundBlock RewriteExpressionUsingStatement(BoundUsingStatement node, Bou
return new BoundBlock(
syntax: usingSyntax,
locals: node.Locals.Add(boundTemp.LocalSymbol),
localFunctions: ImmutableArray<LocalFunctionSymbol>.Empty,
statements: ImmutableArray.Create<BoundStatement>(expressionStatement, tryFinally));
}
......@@ -192,7 +190,6 @@ private BoundBlock RewriteDeclarationUsingStatement(SyntaxNode usingSyntax, Boun
return new BoundBlock(
syntax: usingSyntax,
locals: ImmutableArray.Create<LocalSymbol>(boundTemp.LocalSymbol), //localSymbol will be declared by an enclosing block
localFunctions: ImmutableArray<LocalFunctionSymbol>.Empty,
statements: ImmutableArray.Create<BoundStatement>(
rewrittenDeclaration,
new BoundExpressionStatement(declarationSyntax, tempAssignment),
......
......@@ -408,7 +408,7 @@ public BoundBlock Block(ImmutableArray<LocalSymbol> locals, params BoundStatemen
public BoundBlock Block(ImmutableArray<LocalSymbol> locals, ImmutableArray<BoundStatement> statements)
{
return new BoundBlock(Syntax, locals, ImmutableArray<LocalFunctionSymbol>.Empty, statements) { WasCompilerGenerated = true };
return new BoundBlock(Syntax, locals, statements) { WasCompilerGenerated = true };
}
public BoundBlock Block(ImmutableArray<LocalSymbol> locals, ImmutableArray<LocalFunctionSymbol> localFunctions, params BoundStatement[] statements)
......
......@@ -377,7 +377,6 @@ internal override BoundBlock CreateBody()
return new BoundBlock(syntax,
ImmutableArray.Create<LocalSymbol>(scriptLocal.LocalSymbol),
ImmutableArray<LocalFunctionSymbol>.Empty,
ImmutableArray.Create<BoundStatement>(
// var script = new Script();
new BoundExpressionStatement(
......@@ -497,7 +496,6 @@ internal override BoundBlock CreateBody()
return new BoundBlock(syntax,
ImmutableArray.Create<LocalSymbol>(submissionLocal.LocalSymbol),
ImmutableArray<LocalFunctionSymbol>.Empty,
ImmutableArray.Create<BoundStatement>(submissionAssignment, returnStatement))
{ WasCompilerGenerated = true };
}
......
......@@ -18,7 +18,6 @@ internal EEConstructorSymbol(NamedTypeSymbol containingType)
internal override void GenerateMethodBody(TypeCompilationState compilationState, DiagnosticBag diagnostics)
{
var noLocals = ImmutableArray<LocalSymbol>.Empty;
var noLocalFunctions = ImmutableArray<LocalFunctionSymbol>.Empty;
var initializerInvocation = MethodCompiler.BindConstructorInitializer(this, diagnostics, compilationState.Compilation);
var syntax = initializerInvocation.Syntax;
......@@ -26,7 +25,6 @@ internal override void GenerateMethodBody(TypeCompilationState compilationState,
new BoundBlock(
syntax,
noLocals,
noLocalFunctions,
ImmutableArray.Create<BoundStatement>(
new BoundExpressionStatement(syntax, initializerInvocation),
new BoundReturnStatement(syntax, RefKind.None, null))));
......
......@@ -492,7 +492,7 @@ internal override void GenerateMethodBody(TypeCompilationState compilationState,
}
localsSet.Free();
body = new BoundBlock(syntax, localsBuilder.ToImmutableAndFree(), ImmutableArray<LocalFunctionSymbol>.Empty, statementsBuilder.ToImmutableAndFree()) { WasCompilerGenerated = true };
body = new BoundBlock(syntax, localsBuilder.ToImmutableAndFree(), statementsBuilder.ToImmutableAndFree()) { WasCompilerGenerated = true };
Debug.Assert(!diagnostics.HasAnyErrors());
Debug.Assert(!body.HasErrors);
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册