Skip to content
体验新版
项目
组织
正在加载...
登录
切换导航
打开侧边栏
lwm1986
roslyn
提交
155a75ca
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,发现更多精彩内容 >>
提交
155a75ca
编写于
8月 18, 2014
作者:
A
AlekseyTs
浏览文件
操作
浏览文件
下载
电子邮件补丁
差异文件
Avoid stack overflow on long binary expressions. (changeset 1319674)
上级
9a748926
变更
4
显示空白变更内容
内联
并排
Showing
4 changed file
with
84 addition
and
9 deletion
+84
-9
Src/Compilers/CSharp/Portable/Binder/Binder_Operators.cs
Src/Compilers/CSharp/Portable/Binder/Binder_Operators.cs
+1
-1
Src/Compilers/CSharp/Portable/Binder/LocalScopeBinder.cs
Src/Compilers/CSharp/Portable/Binder/LocalScopeBinder.cs
+37
-2
Src/Compilers/CSharp/Portable/Compilation/MemberSemanticModel.NodeMapBuilder.cs
...ortable/Compilation/MemberSemanticModel.NodeMapBuilder.cs
+44
-1
Src/Compilers/CSharp/Portable/Symbols/Source/SourceMemberContainerSymbol_ImplementationChecks.cs
...ource/SourceMemberContainerSymbol_ImplementationChecks.cs
+2
-5
未找到文件。
Src/Compilers/CSharp/Portable/Binder/Binder_Operators.cs
浏览文件 @
155a75ca
...
...
@@ -363,7 +363,7 @@ private static bool IsLegalDynamicOperand(BoundExpression operand)
hasErrors
:
hasError
);
}
pr
ivate
static
bool
IsSimpleBinaryOperator
(
SyntaxKind
kind
)
pr
otected
static
bool
IsSimpleBinaryOperator
(
SyntaxKind
kind
)
{
// We deliberately exclude &&, ||, ??, etc.
switch
(
kind
)
...
...
Src/Compilers/CSharp/Portable/Binder/LocalScopeBinder.cs
浏览文件 @
155a75ca
...
...
@@ -395,6 +395,41 @@ public override void VisitIfStatement(IfStatementSyntax node)
{
return
;
}
public
override
void
VisitBinaryExpression
(
BinaryExpressionSyntax
node
)
{
if
(!
IsSimpleBinaryOperator
(
node
.
Kind
))
{
base
.
VisitBinaryExpression
(
node
);
return
;
}
// The simple binary operators are left-associative, and expressions of the form
// a + b + c + d .... are relatively common in machine-generated code. The parser can handle
// creating a deep-on-the-left syntax tree no problem, and then we promptly blow the stack during
// semantic analysis. Here we build an explicit stack to handle the left-hand recursion.
var
operands
=
ArrayBuilder
<
ExpressionSyntax
>.
GetInstance
();
ExpressionSyntax
current
=
node
;
do
{
var
binOp
=
(
BinaryExpressionSyntax
)
current
;
operands
.
Push
(
binOp
.
Right
);
current
=
binOp
.
Left
;
}
while
(
IsSimpleBinaryOperator
(
current
.
Kind
));
Visit
(
current
);
while
(
operands
.
Count
>
0
)
{
Visit
(
operands
.
Pop
());
}
operands
.
Free
();
}
}
protected
void
BuildLabels
(
SyntaxList
<
StatementSyntax
>
statements
,
ref
ArrayBuilder
<
LabelSymbol
>
labels
)
...
...
Src/Compilers/CSharp/Portable/Compilation/MemberSemanticModel.NodeMapBuilder.cs
浏览文件 @
155a75ca
...
...
@@ -6,6 +6,7 @@
using
System.Globalization
;
using
Microsoft.CodeAnalysis.Collections
;
using
Microsoft.CodeAnalysis.CSharp.Syntax
;
using
Roslyn.Utilities
;
namespace
Microsoft.CodeAnalysis.CSharp
{
...
...
@@ -177,7 +178,44 @@ public override BoundNode Visit(BoundNode node)
map
.
Add
(
current
.
Syntax
,
current
);
}
// In machine-generated code we frequently end up with binary operator trees that are deep on the left,
// such as a + b + c + d ...
// To avoid blowing the call stack, we build an explicit stack to handle the left-hand recursion.
var
binOp
=
current
as
BoundBinaryOperator
;
if
(
binOp
!=
null
)
{
var
stack
=
ArrayBuilder
<
BoundExpression
>.
GetInstance
();
stack
.
Push
(
binOp
.
Right
);
current
=
binOp
.
Left
;
binOp
=
current
as
BoundBinaryOperator
;
while
(
binOp
!=
null
)
{
if
(
ShouldAddNode
(
binOp
))
{
map
.
Add
(
binOp
.
Syntax
,
binOp
);
}
stack
.
Push
(
binOp
.
Right
);
current
=
binOp
.
Left
;
binOp
=
current
as
BoundBinaryOperator
;
}
Visit
(
current
);
while
(
stack
.
Count
>
0
)
{
Visit
(
stack
.
Pop
());
}
stack
.
Free
();
}
else
{
base
.
Visit
(
current
);
}
return
null
;
}
...
...
@@ -209,6 +247,11 @@ public override BoundNode VisitQueryClause(BoundQueryClause node)
VisitUnoptimizedForm
(
node
);
return
null
;
}
public
override
BoundNode
VisitBinaryOperator
(
BoundBinaryOperator
node
)
{
throw
ExceptionUtilities
.
Unreachable
;
}
}
}
}
Src/Compilers/CSharp/Portable/Symbols/Source/SourceMemberContainerSymbol_ImplementationChecks.cs
浏览文件 @
155a75ca
...
...
@@ -1009,13 +1009,10 @@ private SynthesizedExplicitImplementationForwardingMethod SynthesizeInterfaceMem
MethodSymbol
implementingMethod
=
(
MethodSymbol
)
implementingMember
;
//explicit implementations are always respected by the CLR
foreach
(
MethodSymbol
implemented
in
implementingMethod
.
ExplicitInterfaceImplementations
)
{
if
(
implemented
==
interfaceMethod
)
if
(
implementingMethod
.
ExplicitInterfaceImplementations
.
Contains
(
interfaceMethod
))
{
return
null
;
}
}
MethodSymbol
implementingMethodOriginalDefinition
=
implementingMethod
.
OriginalDefinition
;
...
...
编辑
预览
Markdown
is supported
0%
请重试
或
添加新附件
.
添加附件
取消
You are about to add
0
people
to the discussion. Proceed with caution.
先完成此消息的编辑!
取消
想要评论请
注册
或
登录