Browse Source

Fix #1184: Assertion Failed in InsertMissingTokensDecorator.EndNode

pull/1198/head
Siegfried Pammer 7 years ago
parent
commit
937e990f31
  1. 40
      ICSharpCode.Decompiler/CSharp/OutputVisitor/InsertMissingTokensDecorator.cs

40
ICSharpCode.Decompiler/CSharp/OutputVisitor/InsertMissingTokensDecorator.cs

@ -37,35 +37,43 @@ namespace ICSharpCode.Decompiler.CSharp.OutputVisitor
public override void StartNode(AstNode node) public override void StartNode(AstNode node)
{ {
currentList.Add(node); // ignore whitespace: these don't need to be processed.
nodes.Push(currentList); // StartNode/EndNode is only called for them to support folding of comments.
currentList = new List<AstNode>(); if (node.NodeType != NodeType.Whitespace) {
currentList.Add(node);
nodes.Push(currentList);
currentList = new List<AstNode>();
}
base.StartNode(node); base.StartNode(node);
} }
public override void EndNode(AstNode node) public override void EndNode(AstNode node)
{ {
System.Diagnostics.Debug.Assert(currentList != null); // ignore whitespace: these don't need to be processed.
foreach (var removable in node.Children.Where(n => n is CSharpTokenNode)) { // StartNode/EndNode is only called for them to support folding of comments.
removable.Remove(); if (node.NodeType != NodeType.Whitespace) {
System.Diagnostics.Debug.Assert(currentList != null);
foreach (var removable in node.Children.Where(n => n is CSharpTokenNode)) {
removable.Remove();
}
foreach (var child in currentList) {
System.Diagnostics.Debug.Assert(child.Parent == null || node == child.Parent);
child.Remove();
node.AddChildWithExistingRole(child);
}
currentList = nodes.Pop();
} }
foreach (var child in currentList) {
System.Diagnostics.Debug.Assert(child.Parent == null || node == child.Parent);
child.Remove();
node.AddChildWithExistingRole(child);
}
currentList = nodes.Pop();
base.EndNode(node); base.EndNode(node);
} }
public override void WriteToken(Role role, string token) public override void WriteToken(Role role, string token)
{ {
CSharpTokenNode t = new CSharpTokenNode(locationProvider.Location, (TokenRole)role);
t.Role = role;
EmptyStatement node = nodes.Peek().LastOrDefault() as EmptyStatement; EmptyStatement node = nodes.Peek().LastOrDefault() as EmptyStatement;
if (node == null) if (node == null) {
CSharpTokenNode t = new CSharpTokenNode(locationProvider.Location, (TokenRole)role);
t.Role = role;
currentList.Add(t); currentList.Add(t);
else { } else {
node.Location = locationProvider.Location; node.Location = locationProvider.Location;
} }
base.WriteToken(role, token); base.WriteToken(role, token);

Loading…
Cancel
Save