Skip to content

Commit

Permalink
Add DominatorTreeNodeAdorner, change ControlFlowRegion.Parent propert…
Browse files Browse the repository at this point in the history
…y type to IScopeControlFlowRegion
  • Loading branch information
Washi1337 committed Jan 13, 2025
1 parent 21a333f commit 313ee9c
Show file tree
Hide file tree
Showing 4 changed files with 38 additions and 10 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,28 @@
using System.Collections.Generic;
using Echo.ControlFlow.Serialization.Dot;
using Echo.Graphing;
using Echo.Graphing.Serialization.Dot;

namespace Echo.ControlFlow.Analysis.Domination;

public class DominatorTreeNodeAdorner<TInstruction> : IDotNodeAdorner

Check warning on line 8 in src/Core/Echo.ControlFlow/Analysis/Domination/DominatorTreeNodeAdorner.cs

View workflow job for this annotation

GitHub Actions / build

Missing XML comment for publicly visible type or member 'DominatorTreeNodeAdorner<TInstruction>'

Check warning on line 8 in src/Core/Echo.ControlFlow/Analysis/Domination/DominatorTreeNodeAdorner.cs

View workflow job for this annotation

GitHub Actions / build

Missing XML comment for publicly visible type or member 'DominatorTreeNodeAdorner<TInstruction>'
where TInstruction : notnull
{
public DominatorTreeNodeAdorner()

Check warning on line 11 in src/Core/Echo.ControlFlow/Analysis/Domination/DominatorTreeNodeAdorner.cs

View workflow job for this annotation

GitHub Actions / build

Missing XML comment for publicly visible type or member 'DominatorTreeNodeAdorner<TInstruction>.DominatorTreeNodeAdorner()'

Check warning on line 11 in src/Core/Echo.ControlFlow/Analysis/Domination/DominatorTreeNodeAdorner.cs

View workflow job for this annotation

GitHub Actions / build

Missing XML comment for publicly visible type or member 'DominatorTreeNodeAdorner<TInstruction>.DominatorTreeNodeAdorner()'
: this(new ControlFlowNodeAdorner<TInstruction>())
{
}

public DominatorTreeNodeAdorner(IDotNodeAdorner nodeAdorner)

Check warning on line 16 in src/Core/Echo.ControlFlow/Analysis/Domination/DominatorTreeNodeAdorner.cs

View workflow job for this annotation

GitHub Actions / build

Missing XML comment for publicly visible type or member 'DominatorTreeNodeAdorner<TInstruction>.DominatorTreeNodeAdorner(IDotNodeAdorner)'

Check warning on line 16 in src/Core/Echo.ControlFlow/Analysis/Domination/DominatorTreeNodeAdorner.cs

View workflow job for this annotation

GitHub Actions / build

Missing XML comment for publicly visible type or member 'DominatorTreeNodeAdorner<TInstruction>.DominatorTreeNodeAdorner(IDotNodeAdorner)'
{
NodeAdorner = nodeAdorner;
}

public IDotNodeAdorner NodeAdorner { get; set; }

Check warning on line 21 in src/Core/Echo.ControlFlow/Analysis/Domination/DominatorTreeNodeAdorner.cs

View workflow job for this annotation

GitHub Actions / build

Missing XML comment for publicly visible type or member 'DominatorTreeNodeAdorner<TInstruction>.NodeAdorner'

Check warning on line 21 in src/Core/Echo.ControlFlow/Analysis/Domination/DominatorTreeNodeAdorner.cs

View workflow job for this annotation

GitHub Actions / build

Missing XML comment for publicly visible type or member 'DominatorTreeNodeAdorner<TInstruction>.NodeAdorner'

/// <inheritdoc />
public IDictionary<string, string>? GetNodeAttributes(INode node, long id)
{
return NodeAdorner.GetNodeAttributes(((DominatorTreeNode<TInstruction>) node).OriginalNode, id);
}
}
6 changes: 3 additions & 3 deletions src/Core/Echo.ControlFlow/Collections/RegionNodeCollection.cs
Original file line number Diff line number Diff line change
Expand Up @@ -8,20 +8,20 @@
namespace Echo.ControlFlow.Collections
{
/// <summary>
/// Represents a collection of nodes that are put into a control flow region.
/// Represents a collection of nodes that are put into a control flow region.
/// </summary>
/// <typeparam name="TInstruction">The type of data that each node in the graph stores.</typeparam>
[DebuggerDisplay("Count = {" + nameof(Count) + "}")]
public class RegionNodeCollection<TInstruction> : Collection<ControlFlowNode<TInstruction>>
where TInstruction : notnull
{
private readonly IControlFlowRegion<TInstruction> _owner;
private readonly IScopeControlFlowRegion<TInstruction> _owner;

/// <summary>
/// Creates a new instance of the <see cref="RegionNodeCollection{TInstruction}"/> class.
/// </summary>
/// <param name="owner">The region owning the collection of nodes.</param>
public RegionNodeCollection(IControlFlowRegion<TInstruction> owner)
public RegionNodeCollection(IScopeControlFlowRegion<TInstruction> owner)
{
_owner = owner ?? throw new ArgumentNullException(nameof(owner));
}
Expand Down
8 changes: 4 additions & 4 deletions src/Core/Echo.ControlFlow/ControlFlowNode.cs
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,7 @@ public ControlFlowGraph<TInstruction>? ParentGraph
{
get
{
var region = ParentRegion;
var region = (IControlFlowRegion<TInstruction>?) ParentRegion;
while (true)
{
switch (region)
Expand All @@ -91,7 +91,7 @@ public ControlFlowGraph<TInstruction>? ParentGraph
/// <summary>
/// Gets the graph region that contains this node, or <c>null</c> if the node is not added to any graph yet.
/// </summary>
public IControlFlowRegion<TInstruction>? ParentRegion
public IScopeControlFlowRegion<TInstruction>? ParentRegion
{
get;
internal set;
Expand Down Expand Up @@ -517,8 +517,8 @@ public void MoveToRegion(ScopeRegion<TInstruction> region)
/// <returns>The regions this node is situated in, starting with the inner-most regions.</returns>
public IEnumerable<IControlFlowRegion<TInstruction>> GetSituatedRegions()
{
var parentRegion = ParentRegion;
while (parentRegion is {})
var parentRegion = (IControlFlowRegion<TInstruction>?) ParentRegion;
while (parentRegion is not null)
{
yield return parentRegion;
parentRegion = parentRegion.ParentRegion;
Expand Down
6 changes: 3 additions & 3 deletions src/Core/Echo/Graphing/Serialization/Dot/DotWriter.cs
Original file line number Diff line number Diff line change
Expand Up @@ -12,10 +12,10 @@ public class DotWriter
{
private static readonly IDictionary<char, string> EscapedCharacters = new Dictionary<char, string>
{
['\r'] = "\\\r",
['\n'] = "\\\n",
['\r'] = "\\r",
['\n'] = "\\n",
['"'] = "\\\"",
['\t'] = "\\\t",
['\t'] = "\\t",
};

/// <summary>
Expand Down

0 comments on commit 313ee9c

Please sign in to comment.