Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
lwm1986
roslyn
提交
31ed9905
R
roslyn
项目概览
lwm1986
/
roslyn
与 Fork 源项目一致
从无法访问的项目Fork
通知
1
Star
0
Fork
0
代码
文件
提交
分支
Tags
贡献者
分支图
Diff
Issue
0
列表
看板
标记
里程碑
合并请求
0
DevOps
流水线
流水线任务
计划
Wiki
0
Wiki
分析
仓库
DevOps
项目成员
Pages
R
roslyn
项目概览
项目概览
详情
发布
仓库
仓库
文件
提交
分支
标签
贡献者
分支图
比较
Issue
0
Issue
0
列表
看板
标记
里程碑
合并请求
0
合并请求
0
Pages
DevOps
DevOps
流水线
流水线任务
计划
分析
分析
仓库分析
DevOps
Wiki
0
Wiki
成员
成员
收起侧边栏
关闭侧边栏
动态
分支图
创建新Issue
流水线任务
提交
Issue看板
体验新版 GitCode,发现更多精彩内容 >>
提交
31ed9905
编写于
10月 07, 2015
作者:
C
Charles Stoner
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Allow 'await' at start of statement in Script
上级
71a48400
变更
3
显示空白变更内容
内联
并排
Showing
3 changed file
with
43 addition
and
26 deletion
+43
-26
src/Compilers/CSharp/Portable/Parser/LanguageParser.cs
src/Compilers/CSharp/Portable/Parser/LanguageParser.cs
+8
-8
src/Compilers/CSharp/Portable/Parser/SyntaxParser.cs
src/Compilers/CSharp/Portable/Parser/SyntaxParser.cs
+3
-3
src/Compilers/CSharp/Test/Emit/CodeGen/CodeGenAsyncTests.cs
src/Compilers/CSharp/Test/Emit/CodeGen/CodeGenAsyncTests.cs
+32
-15
未找到文件。
src/Compilers/CSharp/Portable/Parser/LanguageParser.cs
浏览文件 @
31ed9905
...
...
@@ -428,7 +428,7 @@ private NamespaceDeclarationSyntax ParseNamespaceDeclaration()
Debug
.
Assert
(
this
.
CurrentToken
.
Kind
==
SyntaxKind
.
NamespaceKeyword
);
var
namespaceToken
=
this
.
EatToken
(
SyntaxKind
.
NamespaceKeyword
);
if
(
IsScript
||
Is
Interactive
)
if
(
IsScript
Or
Interactive
)
{
namespaceToken
=
this
.
AddError
(
namespaceToken
,
ErrorCode
.
ERR_NamespaceNotAllowedInScript
);
}
...
...
@@ -592,7 +592,7 @@ private void ParseNamespaceBody(ref SyntaxToken openBrace, ref NamespaceBodyBuil
Debug
.
Assert
(!
IsInAsync
);
bool
isGlobal
=
openBrace
==
null
;
bool
isGlobalScript
=
isGlobal
&&
this
.
IsScript
;
bool
isGlobalScript
=
isGlobal
&&
this
.
IsScript
OrInteractive
;
var
saveTerm
=
_termState
;
_termState
|=
TerminatorState
.
IsNamespaceMemberStartOrStop
;
...
...
@@ -629,7 +629,7 @@ private void ParseNamespaceBody(ref SyntaxToken openBrace, ref NamespaceBodyBuil
var
token
=
this
.
EatToken
();
token
=
this
.
AddError
(
token
,
IsScript
?
ErrorCode
.
ERR_GlobalDefinitionOrStatementExpected
:
ErrorCode
.
ERR_EOFExpected
);
IsScript
OrInteractive
?
ErrorCode
.
ERR_GlobalDefinitionOrStatementExpected
:
ErrorCode
.
ERR_EOFExpected
);
this
.
AddSkippedNamespaceText
(
ref
openBrace
,
ref
body
,
ref
initialBadNodes
,
token
);
reportUnexpectedToken
=
true
;
...
...
@@ -738,7 +738,7 @@ private void ParseNamespaceBody(ref SyntaxToken openBrace, ref NamespaceBodyBuil
if
(
reportUnexpectedToken
&&
!
skippedToken
.
ContainsDiagnostics
)
{
skippedToken
=
this
.
AddError
(
skippedToken
,
IsScript
?
ErrorCode
.
ERR_GlobalDefinitionOrStatementExpected
:
ErrorCode
.
ERR_EOFExpected
);
IsScript
OrInteractive
?
ErrorCode
.
ERR_GlobalDefinitionOrStatementExpected
:
ErrorCode
.
ERR_EOFExpected
);
// do not report the error multiple times for subsequent tokens:
reportUnexpectedToken
=
false
;
...
...
@@ -2230,7 +2230,7 @@ private MemberDeclarationSyntax ParseMemberDeclarationOrStatement(SyntaxKind par
cancellationToken
.
ThrowIfCancellationRequested
();
bool
isGlobalScript
=
parentKind
==
SyntaxKind
.
CompilationUnit
&&
this
.
IsScript
;
bool
isGlobalScript
=
parentKind
==
SyntaxKind
.
CompilationUnit
&&
this
.
IsScript
OrInteractive
;
bool
acceptStatement
=
isGlobalScript
;
// don't reuse members if they were previously declared under a different type keyword kind
...
...
@@ -2498,7 +2498,7 @@ private MemberDeclarationSyntax ParseMemberDeclarationOrStatement(SyntaxKind par
return
incompleteMember
;
}
else
if
(
parentKind
==
SyntaxKind
.
NamespaceDeclaration
||
parentKind
==
SyntaxKind
.
CompilationUnit
&&
!
IsScript
)
parentKind
==
SyntaxKind
.
CompilationUnit
&&
!
IsScript
OrInteractive
)
{
return
this
.
AddErrorToLastToken
(
incompleteMember
,
ErrorCode
.
ERR_NamespaceUnexpected
);
}
...
...
@@ -4520,7 +4520,7 @@ private void ParseVariableDeclarators(TypeSyntax type, VariableFlags flags, Sepa
// the reported errors should take into consideration whether or not one expects them in the current context.
bool
variableDeclarationsExpected
=
parentKind
!=
SyntaxKind
.
NamespaceDeclaration
&&
(
parentKind
!=
SyntaxKind
.
CompilationUnit
||
IsScript
);
(
parentKind
!=
SyntaxKind
.
CompilationUnit
||
IsScript
OrInteractive
);
ParseVariableDeclarators
(
type
,
flags
,
variables
,
variableDeclarationsExpected
);
}
...
...
@@ -8231,7 +8231,7 @@ private static bool IsExpectedAssignmentOperator(SyntaxKind kind)
private
bool
IsPossibleAwaitExpressionStatement
()
{
return
(
this
.
IsInteractive
||
this
.
IsInAsync
)
&&
this
.
CurrentToken
.
ContextualKind
==
SyntaxKind
.
AwaitKeyword
;
return
(
this
.
Is
ScriptOr
Interactive
||
this
.
IsInAsync
)
&&
this
.
CurrentToken
.
ContextualKind
==
SyntaxKind
.
AwaitKeyword
;
}
private
bool
IsAwaitExpression
()
...
...
src/Compilers/CSharp/Portable/Parser/SyntaxParser.cs
浏览文件 @
31ed9905
...
...
@@ -191,11 +191,11 @@ public bool IsInteractive
}
/// <summary>
/// Script
- global statements and member declarations allowed, but not expressions
.
/// Script
or interactive - global statements, member declarations, and expressions allowed
.
/// </summary>
public
bool
IsScript
public
bool
IsScript
OrInteractive
{
get
{
return
Options
.
Kind
!=
SourceCodeKind
.
Regular
;
}
get
{
return
(
Options
.
Kind
==
SourceCodeKind
.
Script
)
||
(
Options
.
Kind
==
SourceCodeKind
.
Interactive
)
;
}
}
protected
LexerMode
Mode
...
...
src/Compilers/CSharp/Test/Emit/CodeGen/CodeGenAsyncTests.cs
浏览文件 @
31ed9905
...
...
@@ -3605,7 +3605,6 @@ public static Task<T> GetValue<T>()
CompileAndVerify
(
comp
.
WithOptions
(
TestOptions
.
ReleaseExe
),
expectedOutput
:
"0"
);
}
[
Fact
]
public
void
AwaitInScriptExpression
()
{
...
...
@@ -3615,6 +3614,15 @@ public void AwaitInScriptExpression()
compilation
.
VerifyDiagnostics
();
}
[
Fact
]
public
void
AwaitInScriptGlobalStatement
()
{
var
source
=
@"await System.Threading.Tasks.Task.FromResult(4);"
;
var
compilation
=
CreateCompilationWithMscorlib45
(
source
,
parseOptions
:
TestOptions
.
Script
,
options
:
TestOptions
.
DebugExe
);
compilation
.
VerifyDiagnostics
();
}
[
Fact
]
public
void
AwaitInScriptDeclaration
()
{
...
...
@@ -3641,6 +3649,16 @@ public void AwaitInInteractiveExpression()
s1
.
VerifyDiagnostics
();
}
[
Fact
]
public
void
AwaitInInteractiveGlobalStatement
()
{
var
references
=
new
[]
{
MscorlibRef_v4_0_30316_17626
,
SystemCoreRef
};
var
source0
=
@"await System.Threading.Tasks.Task.FromResult(5);"
;
var
s0
=
CSharpCompilation
.
CreateSubmission
(
"s0.dll"
,
SyntaxFactory
.
ParseSyntaxTree
(
source0
,
options
:
TestOptions
.
Interactive
),
references
);
s0
.
VerifyDiagnostics
();
}
[
Fact
]
public
void
AwaitInInteractiveDeclaration
()
{
...
...
@@ -3731,7 +3749,6 @@ static void M(int input)
}
catch (Exception)
{
}
}
}
...
...
@@ -3775,7 +3792,7 @@ public void SwitchOnAwaitedValueString()
using System;
class Program
{
{
static void Main()
{
M(0).Wait();
...
...
@@ -3792,7 +3809,7 @@ static async Task M(int input)
return;
}
}
}
}
"
;
var
comp
=
CreateCompilation
(
source
,
options
:
TestOptions
.
DebugExe
);
CompileAndVerify
(
comp
);
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录