提交 8ea9ab66 编写于 作者: C Charles Stoner

Merge pull request #3991 from cston/Await

Incorporate PR feedback from #3813
......@@ -187,7 +187,7 @@ internal struct ProcessedFieldInitializers
else
{
var collisionDetector = new LocalScopeBinder(parentBinder);
boundInitializer = BindGlobalStatement(collisionDetector, (StatementSyntax)initializerNode, diagnostics,
boundInitializer = BindGlobalStatement(collisionDetector, scriptInitializer, (StatementSyntax)initializerNode, diagnostics,
isLast: i == initializers.Length - 1 && j == siblingInitializers.Length - 1);
}
......@@ -196,7 +196,12 @@ internal struct ProcessedFieldInitializers
}
}
private static BoundInitializer BindGlobalStatement(Binder binder, StatementSyntax statementNode, DiagnosticBag diagnostics, bool isLast)
private static BoundInitializer BindGlobalStatement(
Binder binder,
SynthesizedInteractiveInitializerMethod scriptInitializer,
StatementSyntax statementNode,
DiagnosticBag diagnostics,
bool isLast)
{
BoundStatement boundStatement = binder.BindStatement(statementNode, diagnostics);
......@@ -207,7 +212,7 @@ private static BoundInitializer BindGlobalStatement(Binder binder, StatementSynt
var expression = ((BoundExpressionStatement)boundStatement).Expression;
if ((object)expression.Type == null || expression.Type.SpecialType != SpecialType.System_Void)
{
var submissionResultType = binder.Compilation.GetSubmissionInitializer().ResultType;
var submissionResultType = scriptInitializer.ResultType;
expression = binder.GenerateConversionForAssignment(submissionResultType, expression, diagnostics);
boundStatement = new BoundExpressionStatement(boundStatement.Syntax, expression, expression.HasErrors);
}
......
......@@ -194,33 +194,33 @@ private static MethodSymbol GetEntryPoint(CSharpCompilation compilation, PEModul
Debug.Assert(!entryPointAndDiagnostics.Diagnostics.IsDefault);
diagnostics.AddRange(entryPointAndDiagnostics.Diagnostics);
var entryPoint = entryPointAndDiagnostics.MethodSymbol as SynthesizedEntryPointSymbol;
if ((object)entryPoint != null)
{
if (moduleBeingBuilt != null && !hasDeclarationErrors && !diagnostics.HasAnyErrors())
{
var body = entryPoint.CreateBody();
const int methodOrdinal = -1;
var emittedBody = GenerateMethodBody(
moduleBeingBuilt,
entryPoint,
methodOrdinal,
body,
ImmutableArray<LambdaDebugInfo>.Empty,
ImmutableArray<ClosureDebugInfo>.Empty,
stateMachineTypeOpt: null,
variableSlotAllocatorOpt: null,
diagnostics: diagnostics,
debugDocumentProvider: null,
importChainOpt: null,
emittingPdb: false);
moduleBeingBuilt.SetMethodBody(entryPoint, emittedBody);
}
}
Debug.Assert((object)entryPointAndDiagnostics.MethodSymbol != null || entryPointAndDiagnostics.Diagnostics.HasAnyErrors() || !compilation.Options.Errors.IsDefaultOrEmpty);
return entryPointAndDiagnostics.MethodSymbol;
var entryPoint = entryPointAndDiagnostics.MethodSymbol;
var synthesizedEntryPoint = entryPoint as SynthesizedEntryPointSymbol;
if (((object)synthesizedEntryPoint != null) &&
(moduleBeingBuilt != null) &&
!hasDeclarationErrors &&
!diagnostics.HasAnyErrors())
{
var body = synthesizedEntryPoint.CreateBody();
const int methodOrdinal = -1;
var emittedBody = GenerateMethodBody(
moduleBeingBuilt,
synthesizedEntryPoint,
methodOrdinal,
body,
ImmutableArray<LambdaDebugInfo>.Empty,
ImmutableArray<ClosureDebugInfo>.Empty,
stateMachineTypeOpt: null,
variableSlotAllocatorOpt: null,
diagnostics: diagnostics,
debugDocumentProvider: null,
importChainOpt: null,
emittingPdb: false);
moduleBeingBuilt.SetMethodBody(synthesizedEntryPoint, emittedBody);
}
Debug.Assert((object)entryPoint != null || entryPointAndDiagnostics.Diagnostics.HasAnyErrors() || !compilation.Options.Errors.IsDefaultOrEmpty);
return entryPoint;
}
private void WaitForWorkers()
......
......@@ -76,7 +76,7 @@ Namespace Microsoft.CodeAnalysis.VisualBasic
Friend Shared Sub BindFieldAndPropertyInitializers(
symbol As SourceMemberContainerTypeSymbol,
initializers As ImmutableArray(Of ImmutableArray(Of FieldOrPropertyInitializer)),
scriptInitializerOpt As MethodSymbol,
scriptInitializerOpt As SynthesizedInteractiveInitializerMethod,
ByRef processedFieldInitializers As ProcessedFieldOrPropertyInitializers,
diagnostics As DiagnosticBag
)
......@@ -122,7 +122,7 @@ Namespace Microsoft.CodeAnalysis.VisualBasic
If initializer.FieldsOrProperty.IsDefault Then
' use the binder of the Script class for global statements
Dim isLast = (i = initializers.Length - 1 AndAlso j = siblingInitializers.Length - 1)
boundInitializers.Add(parentBinder.BindGlobalStatement(DirectCast(initializerNode, StatementSyntax), diagnostics, isLast))
boundInitializers.Add(parentBinder.BindGlobalStatement(scriptInitializerOpt, DirectCast(initializerNode, StatementSyntax), diagnostics, isLast))
Continue For
End If
......@@ -195,14 +195,19 @@ Namespace Microsoft.CodeAnalysis.VisualBasic
boundInitializers.ToImmutableAndFree())
End Sub
Private Function BindGlobalStatement(statementNode As StatementSyntax, diagnostics As DiagnosticBag, isLast As Boolean) As BoundInitializer
Private Function BindGlobalStatement(
scriptInitializerOpt As SynthesizedInteractiveInitializerMethod,
statementNode As StatementSyntax,
diagnostics As DiagnosticBag,
isLast As Boolean) As BoundInitializer
Dim boundStatement As BoundStatement = Me.BindStatement(statementNode, diagnostics)
If Me.Compilation.IsSubmission AndAlso isLast AndAlso boundStatement.Kind = BoundKind.ExpressionStatement AndAlso Not boundStatement.HasErrors Then
' insert an implicit conversion to the submission return type (if needed):
Dim expression = (DirectCast(boundStatement, BoundExpressionStatement)).Expression
If expression.Type Is Nothing OrElse expression.Type.SpecialType <> SpecialType.System_Void Then
Dim submissionReturnType = Compilation.GetSubmissionInitializer().ResultType
Dim submissionReturnType = scriptInitializerOpt.ResultType
expression = ApplyImplicitConversion(expression.Syntax, submissionReturnType, expression, diagnostics)
boundStatement = New BoundExpressionStatement(boundStatement.Syntax, expression, expression.HasErrors)
End If
......
......@@ -267,30 +267,29 @@ Namespace Microsoft.CodeAnalysis.VisualBasic
Debug.Assert(Not entryPointAndDiagnostics.Diagnostics.IsDefault)
diagnostics.AddRange(entryPointAndDiagnostics.Diagnostics)
Dim entryPoint = TryCast(entryPointAndDiagnostics.MethodSymbol, SynthesizedEntryPointSymbol)
If entryPoint IsNot Nothing Then
If moduleBeingBuilt IsNot Nothing AndAlso Not diagnostics.HasAnyErrors Then
Dim compilationState = New TypeCompilationState(compilation, moduleBeingBuilt, initializeComponentOpt:=Nothing)
Dim body = entryPoint.CreateBody()
Dim emittedBody = GenerateMethodBody(moduleBeingBuilt,
entryPoint,
methodOrdinal:=DebugId.UndefinedOrdinal,
block:=body,
lambdaDebugInfo:=ImmutableArray(Of LambdaDebugInfo).Empty,
closureDebugInfo:=ImmutableArray(Of ClosureDebugInfo).Empty,
stateMachineTypeOpt:=Nothing,
variableSlotAllocatorOpt:=Nothing,
debugDocumentProvider:=Nothing,
diagnostics:=diagnostics,
emittingPdb:=False)
moduleBeingBuilt.SetMethodBody(entryPoint, emittedBody)
End If
Dim entryPoint = entryPointAndDiagnostics.MethodSymbol
Dim synthesizedEntryPoint = TryCast(entryPoint, SynthesizedEntryPointSymbol)
If synthesizedEntryPoint IsNot Nothing AndAlso
moduleBeingBuilt IsNot Nothing AndAlso
Not diagnostics.HasAnyErrors Then
Dim compilationState = New TypeCompilationState(compilation, moduleBeingBuilt, initializeComponentOpt:=Nothing)
Dim body = synthesizedEntryPoint.CreateBody()
Dim emittedBody = GenerateMethodBody(moduleBeingBuilt,
synthesizedEntryPoint,
methodOrdinal:=DebugId.UndefinedOrdinal,
block:=body,
lambdaDebugInfo:=ImmutableArray(Of LambdaDebugInfo).Empty,
closureDebugInfo:=ImmutableArray(Of ClosureDebugInfo).Empty,
stateMachineTypeOpt:=Nothing,
variableSlotAllocatorOpt:=Nothing,
debugDocumentProvider:=Nothing,
diagnostics:=diagnostics,
emittingPdb:=False)
moduleBeingBuilt.SetMethodBody(synthesizedEntryPoint, emittedBody)
End If
Debug.Assert(entryPointAndDiagnostics.MethodSymbol IsNot Nothing OrElse entryPointAndDiagnostics.Diagnostics.HasAnyErrors() OrElse Not compilation.Options.Errors.IsDefaultOrEmpty)
Return entryPointAndDiagnostics.MethodSymbol
Debug.Assert(entryPoint IsNot Nothing OrElse entryPointAndDiagnostics.Diagnostics.HasAnyErrors() OrElse Not compilation.Options.Errors.IsDefaultOrEmpty)
Return entryPoint
End Function
Private Sub WaitForWorkers()
......
......@@ -143,13 +143,6 @@ public object Execute(string code)
public T Execute<T>(string code)
{
var value = this.ExecuteAsync<T>(code, CancellationToken.None);
if (value == null)
{
// ReturnValue will be null if there are errors or
// if there is no executable code in submission.
return default(T);
}
return value.Result;
}
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册