Skip to content

Commit 71034ff

Browse files
committed
Merge branch 'next' of https://github.com/rubberduck-vba/Rubberduck into CleanComSafeLeakRound2
2 parents 06ae0be + cf1fdbd commit 71034ff

File tree

62 files changed

+1844
-877
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

62 files changed

+1844
-877
lines changed

Rubberduck.CodeAnalysis/CodePathAnalysis/Extensions/NodeExtensions.cs

Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22
using System;
33
using System.Collections.Generic;
44
using System.Linq;
5+
using Rubberduck.Parsing.Symbols;
56

67
namespace Rubberduck.Inspections.CodePathAnalysis.Extensions
78
{
@@ -50,5 +51,34 @@ public static INode GetFirstNode(this INode node, IEnumerable<Type> excludedType
5051

5152
return GetFirstNode(node.Children[0], excludedTypes);
5253
}
54+
55+
public static List<IdentifierReference> GetIdentifierReferences(this INode node)
56+
{
57+
var nodes = new List<IdentifierReference>();
58+
59+
var blockNodes = node.GetNodes(new[] { typeof(BlockNode) });
60+
foreach (var block in blockNodes)
61+
{
62+
INode lastNode = default;
63+
foreach (var flattenedNode in block.GetFlattenedNodes(new[] { typeof(GenericNode), typeof(BlockNode) }))
64+
{
65+
if (flattenedNode is AssignmentNode &&
66+
lastNode is AssignmentNode)
67+
{
68+
nodes.Add(lastNode.Reference);
69+
}
70+
71+
lastNode = flattenedNode;
72+
}
73+
74+
if (lastNode is AssignmentNode &&
75+
block.Children[0].GetFirstNode(new[] { typeof(GenericNode) }) is DeclarationNode)
76+
{
77+
nodes.Add(lastNode.Reference);
78+
}
79+
}
80+
81+
return nodes;
82+
}
5383
}
5484
}
Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,23 @@
1+
using System.Collections.Generic;
2+
using System.Collections.Immutable;
3+
using Antlr4.Runtime.Tree;
4+
using Rubberduck.Parsing.Symbols;
5+
6+
namespace Rubberduck.Inspections.CodePathAnalysis.Nodes
7+
{
8+
public abstract class NodeBase : INode
9+
{
10+
protected NodeBase(IParseTree tree)
11+
{
12+
Children = new List<INode>().ToImmutableList();
13+
ParseTree = tree;
14+
}
15+
16+
public int SortOrder { get; set; }
17+
public ImmutableList<INode> Children { get; set; }
18+
public INode Parent { get; set; }
19+
public IParseTree ParseTree { get; }
20+
public Declaration Declaration { get; set; }
21+
public IdentifierReference Reference { get; set; }
22+
}
23+
}

Rubberduck.CodeAnalysis/CodePathAnalysis/Nodes/INode.cs

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
using Rubberduck.Parsing.Symbols;
22
using System.Collections.Immutable;
3+
using Antlr4.Runtime.Tree;
34

45
namespace Rubberduck.Inspections.CodePathAnalysis.Nodes
56
{
@@ -8,7 +9,7 @@ public interface INode
89
int SortOrder { get; set; }
910
ImmutableList<INode> Children { get; set; }
1011
INode Parent { get; set; }
11-
12+
IParseTree ParseTree { get; }
1213
Declaration Declaration { get; set; }
1314
IdentifierReference Reference { get; set; }
1415
}
Lines changed: 3 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,9 @@
1-
using System.Collections.Generic;
2-
using System.Collections.Immutable;
3-
using Rubberduck.Parsing.Symbols;
1+
using Antlr4.Runtime.Tree;
42

53
namespace Rubberduck.Inspections.CodePathAnalysis.Nodes
64
{
7-
public class AssignmentNode : INode
5+
public class AssignmentNode : NodeBase
86
{
9-
public AssignmentNode()
10-
{
11-
Children = new List<INode>().ToImmutableList();
12-
}
13-
14-
public int SortOrder { get; set; }
15-
public ImmutableList<INode> Children { get; set; }
16-
public INode Parent { get; set; }
17-
18-
public Declaration Declaration { get; set; }
19-
public IdentifierReference Reference { get; set; }
7+
public AssignmentNode(IParseTree tree) : base(tree) { }
208
}
219
}
Lines changed: 3 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,9 @@
1-
using System.Collections.Generic;
2-
using System.Collections.Immutable;
3-
using Rubberduck.Parsing.Symbols;
1+
using Antlr4.Runtime.Tree;
42

53
namespace Rubberduck.Inspections.CodePathAnalysis.Nodes
64
{
7-
public class BlockNode : INode
5+
public class BlockNode : NodeBase
86
{
9-
public BlockNode()
10-
{
11-
Children = new List<INode>().ToImmutableList();
12-
}
13-
14-
public int SortOrder { get; set; }
15-
public ImmutableList<INode> Children { get; set; }
16-
public INode Parent { get; set; }
17-
18-
public Declaration Declaration { get; set; }
19-
public IdentifierReference Reference { get; set; }
7+
public BlockNode(IParseTree tree) : base(tree) { }
208
}
219
}
Lines changed: 3 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,9 @@
1-
using System.Collections.Generic;
2-
using System.Collections.Immutable;
3-
using Rubberduck.Parsing.Symbols;
1+
using Antlr4.Runtime.Tree;
42

53
namespace Rubberduck.Inspections.CodePathAnalysis.Nodes
64
{
7-
public class BranchNode : IBranchNode
5+
public class BranchNode : NodeBase, IBranchNode
86
{
9-
public BranchNode()
10-
{
11-
Children = new List<INode>().ToImmutableList();
12-
}
13-
14-
public int SortOrder { get; set; }
15-
public ImmutableList<INode> Children { get; set; }
16-
public INode Parent { get; set; }
17-
18-
public Declaration Declaration { get; set; }
19-
public IdentifierReference Reference { get; set; }
7+
public BranchNode(IParseTree tree) : base(tree) { }
208
}
219
}
Lines changed: 3 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,9 @@
1-
using System.Collections.Generic;
2-
using System.Collections.Immutable;
3-
using Rubberduck.Parsing.Symbols;
1+
using Antlr4.Runtime.Tree;
42

53
namespace Rubberduck.Inspections.CodePathAnalysis.Nodes
64
{
7-
public class DeclarationNode : INode
5+
public class DeclarationNode : NodeBase
86
{
9-
public DeclarationNode()
10-
{
11-
Children = new List<INode>().ToImmutableList();
12-
}
13-
14-
public int SortOrder { get; set; }
15-
public ImmutableList<INode> Children { get; set; }
16-
public INode Parent { get; set; }
17-
18-
public Declaration Declaration { get; set; }
19-
public IdentifierReference Reference { get; set; }
7+
public DeclarationNode(IParseTree tree) : base(tree) { }
208
}
219
}
Lines changed: 3 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,9 @@
1-
using System.Collections.Generic;
2-
using System.Collections.Immutable;
3-
using Rubberduck.Parsing.Symbols;
1+
using Antlr4.Runtime.Tree;
42

53
namespace Rubberduck.Inspections.CodePathAnalysis.Nodes
64
{
7-
public class GenericNode : INode
5+
public class GenericNode : NodeBase
86
{
9-
public GenericNode()
10-
{
11-
Children = new List<INode>().ToImmutableList();
12-
}
13-
14-
public int SortOrder { get; set; }
15-
public ImmutableList<INode> Children { get; set; }
16-
public INode Parent { get; set; }
17-
18-
public Declaration Declaration { get; set; }
19-
public IdentifierReference Reference { get; set; }
7+
public GenericNode(IParseTree tree) : base(tree) { }
208
}
219
}
Lines changed: 3 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,9 @@
1-
using Rubberduck.Parsing.Symbols;
2-
using System.Collections.Generic;
3-
using System.Collections.Immutable;
1+
using Antlr4.Runtime.Tree;
42

53
namespace Rubberduck.Inspections.CodePathAnalysis.Nodes
64
{
7-
public class LoopNode : ILoopNode
5+
public class LoopNode : NodeBase, ILoopNode
86
{
9-
public LoopNode()
10-
{
11-
Children = new List<INode>().ToImmutableList();
12-
}
13-
14-
public int SortOrder { get; set; }
15-
public ImmutableList<INode> Children { get; set; }
16-
public INode Parent { get; set; }
17-
18-
public Declaration Declaration { get; set; }
19-
public IdentifierReference Reference { get; set; }
7+
public LoopNode(IParseTree tree) : base(tree) { }
208
}
219
}
Lines changed: 3 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,9 @@
1-
using System.Collections.Generic;
2-
using System.Collections.Immutable;
3-
using Rubberduck.Parsing.Symbols;
1+
using Antlr4.Runtime.Tree;
42

53
namespace Rubberduck.Inspections.CodePathAnalysis.Nodes
64
{
7-
public class ReferenceNode : INode
5+
public class ReferenceNode : NodeBase
86
{
9-
public ReferenceNode()
10-
{
11-
Children = new List<INode>().ToImmutableList();
12-
}
13-
14-
public int SortOrder { get; set; }
15-
public ImmutableList<INode> Children { get; set; }
16-
public INode Parent { get; set; }
17-
18-
public Declaration Declaration { get; set; }
19-
public IdentifierReference Reference { get; set; }
7+
public ReferenceNode(IParseTree tree) : base(tree) { }
208
}
219
}

0 commit comments

Comments
 (0)