Skip to content

Commit

Permalink
Update sample with the current generator output.
Browse files Browse the repository at this point in the history
  • Loading branch information
GGG-KILLER committed Jan 29, 2024
1 parent a828beb commit 85f78fb
Show file tree
Hide file tree
Showing 4 changed files with 184 additions and 4 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,38 @@
// GreenBase = global::Tsu.Trees.RedGreen.Sample.Internal.GreenNode
// RedBase = global::Tsu.Trees.RedGreen.Sample.SampleNode
// KindEnum = global::Tsu.Trees.RedGreen.Sample.SampleKind
// CreateVisitors = True
// CreateWalker = True
// CreateRewriter = True
// Root = global::Tsu.Trees.RedGreen.Sample.Internal.GreenNode
// global::Tsu.Trees.RedGreen.Sample.Internal.GreenNode
// Children:
// ExtraData:
// global::Tsu.Trees.RedGreen.Sample.SampleKind (Name = _kind, IsOptional = False, PassToBase = False)
// global::Tsu.Trees.RedGreen.Sample.Internal.ExpressionSample
// Children:
// ExtraData:
// global::Tsu.Trees.RedGreen.Sample.SampleKind (Name = _kind, IsOptional = False, PassToBase = True)
// global::Tsu.Trees.RedGreen.Sample.Internal.FunctionCallExpressionSample
// Children:
// global::Tsu.Trees.RedGreen.Sample.Internal.IdentifierExpressionSample (Name = identifier, IsOptional = False, PassToBase = False)
// global::Tsu.Trees.RedGreen.Sample.Internal.ExpressionSample (Name = firstArg, IsOptional = False, PassToBase = False)
// global::Tsu.Trees.RedGreen.Sample.Internal.ExpressionSample (Name = secondArg, IsOptional = True, PassToBase = False)
// ExtraData:
// global::Tsu.Trees.RedGreen.Sample.SampleKind (Name = _kind, IsOptional = False, PassToBase = True)
// global::Tsu.Trees.RedGreen.Sample.Internal.BinaryOperationExpressionSample
// Children:
// global::Tsu.Trees.RedGreen.Sample.Internal.ExpressionSample (Name = _left, IsOptional = False, PassToBase = False)
// global::Tsu.Trees.RedGreen.Sample.Internal.ExpressionSample (Name = _right, IsOptional = False, PassToBase = False)
// ExtraData:
// global::Tsu.Trees.RedGreen.Sample.SampleKind (Name = _kind, IsOptional = False, PassToBase = True)
// global::Tsu.Trees.RedGreen.Sample.Internal.NumericalLiteralExpressionSample
// Children:
// ExtraData:
// global::Tsu.Trees.RedGreen.Sample.SampleKind (Name = _kind, IsOptional = False, PassToBase = True)
// double (Name = _value, IsOptional = False, PassToBase = False)
// global::Tsu.Trees.RedGreen.Sample.Internal.IdentifierExpressionSample
// Children:
// ExtraData:
// global::Tsu.Trees.RedGreen.Sample.SampleKind (Name = _kind, IsOptional = False, PassToBase = True)
// string (Name = _name, IsOptional = False, PassToBase = False)
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
// <auto-generated />
Original file line number Diff line number Diff line change
@@ -0,0 +1,140 @@
// <auto-generated />

using System.Diagnostics;
using System.Diagnostics.CodeAnalysis;
using System.Linq;

namespace Tsu.Trees.RedGreen.Sample.Internal
{
abstract partial class GreenNode : global::Tsu.Trees.RedGreen.Internal.IGreenNode<global::Tsu.Trees.RedGreen.Sample.Internal.GreenNode, global::Tsu.Trees.RedGreen.Sample.SampleNode, global::Tsu.Trees.RedGreen.Sample.SampleKind>
{
private readonly global::Tsu.Trees.RedGreen.Sample.SampleKind _kind;
private byte _slotCount;

protected GreenNode(global::Tsu.Trees.RedGreen.Sample.SampleKind kind)
{
this._kind = kind;
}

public global::Tsu.Trees.RedGreen.Sample.SampleKind Kind => this._kind;

public int SlotCount
{
get
{
int count = this._slotCount;
if (count == byte.MaxValue)
count = this.GetSlotCount();
return count;
}
protected set => _slotCount = (byte) value;
}

public abstract global::Tsu.Trees.RedGreen.Sample.Internal.GreenNode? GetSlot(int slot);

public global::Tsu.Trees.RedGreen.Sample.Internal.GreenNode GetRequiredSlot(int slot)
{
var node = this.GetSlot(slot);
Debug.Assert((object)node != null)
return node;
}

protected virtual int GetSlotCount() => _slotCount;

public global::System.Collections.Generic.IEnumerable<global::Tsu.Trees.RedGreen.Sample.Internal.GreenNode> ChildNodes()
{
var count = this.SlotCount;
for (var slot = 0; slot < count; slot++)
yield return this.GetRequiredSlot(slot);
}

public global::System.Collections.Generic.IEnumerable<global::Tsu.Trees.RedGreen.Sample.Internal.GreenNode> EnumerateDescendants()
{
var stack = new Stack<global::Tsu.Trees.RedGreen.Sample.Internal.GreenNode>(24);
stack.Push(this);

while (stack.Count > 0)
{
var current = stack.Pop();

yield return current;

foreach (var child in current.ChildNodes().Reverse())
{
stack.Push(child);
}
}
}

public virtual bool IsEquivalentTo([NotNullWhen(true)] global::Tsu.Trees.RedGreen.Sample.Internal.GreenNode? other)
{
if (this == other) return true;
if (other == null) return false;
if (this.Kind != other.Kind) return false;
var n = this.SlotCount;
if (n != other.SlotCount) return false;

for (int i = 0; i < n; i++)
{
var thisChild = this.GetSlot(i);
var otherChild = other.GetSlot(i);
if (thisChild != null && otherChild != null && !thisChild.IsEquivalentTo(otherChild))
{
return false;
}
}

return true;
}

public global::Tsu.Trees.RedGreen.Sample.SampleNode CreateRed() => this.CreateRed(null);
public abstract global::Tsu.Trees.RedGreen.Sample.SampleNode CreateRed(global::Tsu.Trees.RedGreen.Sample.SampleNode? parent);
}

abstract partial class ExpressionSample : global::Tsu.Trees.RedGreen.Sample.Internal.GreenNode
{
protected ExpressionSample(global::Tsu.Trees.RedGreen.Sample.SampleKind kind) : base(kind)
{
}
}

partial class IdentifierExpressionSample : global::Tsu.Trees.RedGreen.Sample.Internal.ExpressionSample
{
internal IdentifierExpressionSample(global::Tsu.Trees.RedGreen.Sample.SampleKind kind, string name) : base(kind)
{
this.SlotCount = 0;
this._name = name;
}
}

partial class NumericalLiteralExpressionSample : global::Tsu.Trees.RedGreen.Sample.Internal.ExpressionSample
{
internal NumericalLiteralExpressionSample(global::Tsu.Trees.RedGreen.Sample.SampleKind kind, double value) : base(kind)
{
this.SlotCount = 0;
this._value = value;
}
}

partial class BinaryOperationExpressionSample : global::Tsu.Trees.RedGreen.Sample.Internal.ExpressionSample
{
internal BinaryOperationExpressionSample(global::Tsu.Trees.RedGreen.Sample.SampleKind kind, global::Tsu.Trees.RedGreen.Sample.Internal.ExpressionSample left, global::Tsu.Trees.RedGreen.Sample.Internal.ExpressionSample right) : base(kind)
{
this.SlotCount = 2;
this._left = left;
this._right = right;
}
}

partial class FunctionCallExpressionSample : global::Tsu.Trees.RedGreen.Sample.Internal.ExpressionSample
{
internal FunctionCallExpressionSample(global::Tsu.Trees.RedGreen.Sample.SampleKind kind, global::Tsu.Trees.RedGreen.Sample.Internal.IdentifierExpressionSample identifier, global::Tsu.Trees.RedGreen.Sample.Internal.ExpressionSample firstArg, global::Tsu.Trees.RedGreen.Sample.Internal.ExpressionSample secondArg) : base(kind)
{
this.SlotCount = 3;
this.identifier = identifier;
this.firstArg = firstArg;
this.secondArg = secondArg;
}
}
}

9 changes: 5 additions & 4 deletions Tsu.Trees.RedGreen/sample/Tree.cs
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ public abstract partial class SampleNode

}
}

namespace Tsu.Trees.RedGreen.Sample.Internal
{
[GreenTreeRoot(typeof(SampleNode), "Sample", typeof(SampleKind), CreateRewriter = true, CreateVisitors = true, CreateWalker = true)]
Expand All @@ -34,20 +35,20 @@ internal abstract partial class ExpressionSample : GreenNode
[GreenNode(SampleKind.IdentifierExpression)]
internal sealed partial class IdentifierExpressionSample : ExpressionSample
{
private readonly string name;
private readonly string _name;
}

[GreenNode(SampleKind.NumericalLiteralExpression)]
internal sealed partial class NumericalLiteralExpressionSample : ExpressionSample
{
private readonly double value;
private readonly double _value;
}

[GreenNode(SampleKind.AdditionExpression, SampleKind.DivisionExpression, SampleKind.MultiplicationExpression, SampleKind.SubtractionExpression)]
internal sealed partial class BinaryOperationExpressionSample : ExpressionSample
{
private readonly ExpressionSample left;
private readonly ExpressionSample right;
private readonly ExpressionSample _left;
private readonly ExpressionSample _right;
}

[GreenNode(SampleKind.FunctionCallExpression)]
Expand Down

0 comments on commit 85f78fb

Please sign in to comment.