提交 b0e251b1 编写于 作者: M Matt Warren

Add stack check to syntax walkers too.

上级 362986fc
......@@ -2727,6 +2727,7 @@ override Microsoft.CodeAnalysis.CSharp.CSharpSyntaxTree.OptionsCore.get -> Micro
override Microsoft.CodeAnalysis.CSharp.CSharpSyntaxTree.TryGetRootCore(out Microsoft.CodeAnalysis.SyntaxNode root) -> bool
override Microsoft.CodeAnalysis.CSharp.CSharpSyntaxTree.WithChangedText(Microsoft.CodeAnalysis.Text.SourceText newText) -> Microsoft.CodeAnalysis.SyntaxTree
override Microsoft.CodeAnalysis.CSharp.CSharpSyntaxWalker.DefaultVisit(Microsoft.CodeAnalysis.SyntaxNode node) -> void
override Microsoft.CodeAnalysis.CSharp.CSharpSyntaxWalker.Visit(Microsoft.CodeAnalysis.SyntaxNode node) -> void
override Microsoft.CodeAnalysis.CSharp.Conversion.Equals(object obj) -> bool
override Microsoft.CodeAnalysis.CSharp.Conversion.GetHashCode() -> int
override Microsoft.CodeAnalysis.CSharp.Conversion.ToString() -> string
......
......@@ -27,7 +27,6 @@ public virtual bool VisitIntoStructuredTrivia
get { return _visitIntoStructuredTrivia; }
}
private const int MaxUncheckedRecursionDepth = Syntax.InternalSyntax.LanguageParser.MaxUncheckedRecursionDepth;
private int _recursionDepth;
public override SyntaxNode Visit(SyntaxNode node)
......@@ -35,7 +34,7 @@ public override SyntaxNode Visit(SyntaxNode node)
if (node != null)
{
_recursionDepth++;
if (_recursionDepth > MaxUncheckedRecursionDepth)
if (_recursionDepth > Syntax.InternalSyntax.LanguageParser.MaxUncheckedRecursionDepth)
{
PortableShim.RuntimeHelpers.EnsureSufficientExecutionStack();
}
......
......@@ -4,6 +4,7 @@
using Microsoft.CodeAnalysis.CSharp.Symbols;
using Microsoft.CodeAnalysis.CSharp.Syntax;
using Microsoft.CodeAnalysis.Text;
using Roslyn.Utilities;
namespace Microsoft.CodeAnalysis.CSharp
{
......@@ -20,6 +21,24 @@ protected CSharpSyntaxWalker(SyntaxWalkerDepth depth = SyntaxWalkerDepth.Node)
this.Depth = depth;
}
private int _recursionDepth;
public override void Visit(SyntaxNode node)
{
if (node != null)
{
_recursionDepth++;
if (_recursionDepth > Syntax.InternalSyntax.LanguageParser.MaxUncheckedRecursionDepth)
{
PortableShim.RuntimeHelpers.EnsureSufficientExecutionStack();
}
((CSharpSyntaxNode)node).Accept(this);
_recursionDepth--;
}
}
public override void DefaultVisit(SyntaxNode node)
{
var childCnt = node.ChildNodesAndTokens().Count;
......
......@@ -4697,6 +4697,7 @@ Overrides Microsoft.CodeAnalysis.VisualBasic.VisualBasicSyntaxTree.OptionsCore()
Overrides Microsoft.CodeAnalysis.VisualBasic.VisualBasicSyntaxTree.TryGetRootCore(ByRef root As Microsoft.CodeAnalysis.SyntaxNode) -> Boolean
Overrides Microsoft.CodeAnalysis.VisualBasic.VisualBasicSyntaxTree.WithChangedText(newText As Microsoft.CodeAnalysis.Text.SourceText) -> Microsoft.CodeAnalysis.SyntaxTree
Overrides Microsoft.CodeAnalysis.VisualBasic.VisualBasicSyntaxWalker.DefaultVisit(node As Microsoft.CodeAnalysis.SyntaxNode) -> Void
Overrides Microsoft.CodeAnalysis.VisualBasic.VisualBasicSyntaxWalker.Visit(node As Microsoft.CodeAnalysis.SyntaxNode) -> Void
ReadOnly Microsoft.CodeAnalysis.VisualBasic.AggregateClauseSymbolInfo.Select1 -> Microsoft.CodeAnalysis.SymbolInfo
ReadOnly Microsoft.CodeAnalysis.VisualBasic.AggregateClauseSymbolInfo.Select2 -> Microsoft.CodeAnalysis.SymbolInfo
ReadOnly Microsoft.CodeAnalysis.VisualBasic.CollectionRangeVariableSymbolInfo.AsClauseConversion -> Microsoft.CodeAnalysis.SymbolInfo
......@@ -29,14 +29,13 @@ Namespace Microsoft.CodeAnalysis.VisualBasic
End Get
End Property
Private Const MaxUncheckedRecursionDepth As Integer = Syntax.InternalSyntax.Parser.MaxUncheckedRecursionDepth
Private _recursionDepth As Integer
Public Overrides Function Visit(node As SyntaxNode) As SyntaxNode
If node IsNot Nothing Then
_recursionDepth += 1
If _recursionDepth > MaxUncheckedRecursionDepth Then
If _recursionDepth > Syntax.InternalSyntax.Parser.MaxUncheckedRecursionDepth Then
PortableShim.RuntimeHelpers.EnsureSufficientExecutionStack()
End If
......
......@@ -18,6 +18,22 @@ Namespace Microsoft.CodeAnalysis.VisualBasic
Me.Depth = depth
End Sub
Private _recursionDepth As Integer
Public Overrides Sub Visit(node As SyntaxNode)
If node IsNot Nothing Then
_recursionDepth += 1
If _recursionDepth > Syntax.InternalSyntax.Parser.MaxUncheckedRecursionDepth Then
PortableShim.RuntimeHelpers.EnsureSufficientExecutionStack()
End If
DirectCast(node, VisualBasicSyntaxNode).Accept(Me)
_recursionDepth -= 1
End If
End Sub
Public Overrides Sub DefaultVisit(node As SyntaxNode)
Dim list = node.ChildNodesAndTokens()
Dim childCnt = list.Count
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册