Skip to content

Commit

Permalink
Merge branch 'feature/red-green-v2'
Browse files Browse the repository at this point in the history
  • Loading branch information
GGG-KILLER committed Feb 2, 2024
2 parents dfc39e3 + 2521208 commit d2603ff
Show file tree
Hide file tree
Showing 85 changed files with 6,273 additions and 1,977 deletions.
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
namespace Tsu.Trees.RedGreen;

/// <summary>
/// Marks this field as a green list of nodes of the specified type.
/// </summary>
[global::System.AttributeUsage(AttributeTargets.Field, Inherited = false, AllowMultiple = false)]
internal sealed class GreenListAttribute(global::System.Type elementType) : global::System.Attribute
{
/// <summary>
/// The type of element in this List.
/// </summary>
public global::System.Type ElementType { get; } = elementType;
}
Original file line number Diff line number Diff line change
Expand Up @@ -7,8 +7,8 @@
/// The kinds this node could have.
/// This should be the value on the enum (e.g.: SyntaxKind.ClassDeclarationSyntax)
/// </param>
[AttributeUsage(AttributeTargets.Class, Inherited = false, AllowMultiple = false)]
internal sealed class GreenNodeAttribute(params object[] kinds) : Attribute
[global::System.AttributeUsage(AttributeTargets.Class, Inherited = false, AllowMultiple = false)]
internal sealed class GreenNodeAttribute(params object[] kinds) : global::System.Attribute
{
/// <summary>
/// This node's Kind.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -3,8 +3,8 @@
/// <summary>
/// An attribute that marks the given class as the base class for all nodes in a green node tree.
/// </summary>
[AttributeUsage(AttributeTargets.Class, Inherited = false, AllowMultiple = false)]
internal sealed class GreenTreeRootAttribute(Type redBase, string suffix, Type kindEnum) : Attribute
[global::System.AttributeUsage(AttributeTargets.Class, Inherited = false, AllowMultiple = false)]
internal sealed class GreenTreeRootAttribute(Type redBase, string suffix, Type kindEnum) : global::System.Attribute
{
/// <summary>
/// The suffix for nodes in this tree.
Expand All @@ -14,12 +14,12 @@ internal sealed class GreenTreeRootAttribute(Type redBase, string suffix, Type k
/// <summary>
/// The base node type for all nodes in the red tree.
/// </summary>
public Type RedBase { get; } = redBase;
public global::System.Type RedBase { get; } = redBase;

/// <summary>
/// The enum type that contains the definitions for the node kinds.
/// </summary>
public Type KindEnum { get; } = kindEnum;
public global::System.Type KindEnum { get; } = kindEnum;

/// <summary>
/// Whether to create base visitor implementations for this tree.
Expand All @@ -36,6 +36,12 @@ internal sealed class GreenTreeRootAttribute(Type redBase, string suffix, Type k
/// </summary>
public bool CreateRewriter { get; set; }

/// <summary>
/// Whether to generate list types and infrastructure for this tree.
/// This implies in having roslyn MIT-licensed code being added to your project.
/// </summary>
public bool CreateLists { get; set; }

/// <summary>
/// Whether to generate a file with only comments dumping the entire tree structure.
/// </summary>
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
namespace Tsu.Trees.RedGreen;

/// <summary>
/// Enabled configuring a child node's properties
/// </summary>
[global::System.AttributeUsage(AttributeTargets.Field, Inherited = false, AllowMultiple = false)]
internal sealed class NodeComponentAttribute() : global::System.Attribute
{
/// <summary>
/// Allows the order that this child appears in prefix order (and by consequence, constructors, factories and update methods).
/// </summary>
public int Order { get; set; }
}

This file was deleted.

This file was deleted.

Original file line number Diff line number Diff line change
@@ -0,0 +1,89 @@
// 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
// Kinds:
// Children:
// ExtraData:
// global::Tsu.Trees.RedGreen.Sample.SampleKind (IsList = False, Name = _kind, IsOptional = False, PassToBase = False, Order = 0)
// Descendants:
// global::Tsu.Trees.RedGreen.Sample.Internal.ExpressionSample
// Kinds:
// Children:
// ExtraData:
// global::Tsu.Trees.RedGreen.Sample.SampleKind (IsList = False, Name = _kind, IsOptional = False, PassToBase = True, Order = 0)
// Descendants:
// global::Tsu.Trees.RedGreen.Sample.Internal.FunctionCallExpressionSample
// Kinds:
// Tsu.Trees.RedGreen.Sample.SampleKind.FunctionCallExpression (IsNull = False, Type = global::Tsu.Trees.RedGreen.Sample.SampleKind, Value = 9)
// Children:
// global::Tsu.Trees.RedGreen.Sample.Internal.IdentifierExpressionSample (IsList = False, Name = _identifier, IsOptional = False, PassToBase = False, Order = 1)
// global::Tsu.Trees.RedGreen.Sample.Internal.ExpressionSample (IsList = True, Name = _args, IsOptional = False, PassToBase = False, Order = 2)
// ExtraData:
// global::Tsu.Trees.RedGreen.Sample.SampleKind (IsList = False, Name = _kind, IsOptional = False, PassToBase = True, Order = 0)
// Descendants:
// global::Tsu.Trees.RedGreen.Sample.Internal.BinaryOperationExpressionSample
// Kinds:
// Tsu.Trees.RedGreen.Sample.SampleKind.AdditionExpression (IsNull = False, Type = global::Tsu.Trees.RedGreen.Sample.SampleKind, Value = 5)
// Tsu.Trees.RedGreen.Sample.SampleKind.DivisionExpression (IsNull = False, Type = global::Tsu.Trees.RedGreen.Sample.SampleKind, Value = 8)
// Tsu.Trees.RedGreen.Sample.SampleKind.MultiplicationExpression (IsNull = False, Type = global::Tsu.Trees.RedGreen.Sample.SampleKind, Value = 7)
// Tsu.Trees.RedGreen.Sample.SampleKind.SubtractionExpression (IsNull = False, Type = global::Tsu.Trees.RedGreen.Sample.SampleKind, Value = 6)
// Children:
// global::Tsu.Trees.RedGreen.Sample.Internal.ExpressionSample (IsList = False, Name = _left, IsOptional = False, PassToBase = False, Order = 1)
// global::Tsu.Trees.RedGreen.Sample.Internal.ExpressionSample (IsList = False, Name = _right, IsOptional = False, PassToBase = False, Order = 2)
// ExtraData:
// global::Tsu.Trees.RedGreen.Sample.SampleKind (IsList = False, Name = _kind, IsOptional = False, PassToBase = True, Order = 0)
// Descendants:
// global::Tsu.Trees.RedGreen.Sample.Internal.NumericalLiteralExpressionSample
// Kinds:
// Tsu.Trees.RedGreen.Sample.SampleKind.NumericalLiteralExpression (IsNull = False, Type = global::Tsu.Trees.RedGreen.Sample.SampleKind, Value = 4)
// Children:
// ExtraData:
// global::Tsu.Trees.RedGreen.Sample.SampleKind (IsList = False, Name = _kind, IsOptional = False, PassToBase = True, Order = 0)
// double (IsList = False, Name = _value, IsOptional = False, PassToBase = False, Order = 1)
// Descendants:
// global::Tsu.Trees.RedGreen.Sample.Internal.IdentifierExpressionSample
// Kinds:
// Tsu.Trees.RedGreen.Sample.SampleKind.IdentifierExpression (IsNull = False, Type = global::Tsu.Trees.RedGreen.Sample.SampleKind, Value = 3)
// Children:
// ExtraData:
// global::Tsu.Trees.RedGreen.Sample.SampleKind (IsList = False, Name = _kind, IsOptional = False, PassToBase = True, Order = 0)
// string (IsList = False, Name = _name, IsOptional = False, PassToBase = False, Order = 1)
// Descendants:
// global::Tsu.Trees.RedGreen.Sample.Internal.StatementSample
// Kinds:
// Children:
// global::Tsu.Trees.RedGreen.Sample.Internal.SemicolonTokenSample (IsList = False, Name = _semicolon, IsOptional = False, PassToBase = False, Order = -1)
// ExtraData:
// global::Tsu.Trees.RedGreen.Sample.SampleKind (IsList = False, Name = _kind, IsOptional = False, PassToBase = True, Order = 0)
// Descendants:
// global::Tsu.Trees.RedGreen.Sample.Internal.ExpressionStatementSample
// Kinds:
// Tsu.Trees.RedGreen.Sample.SampleKind.ExpressionStatement (IsNull = False, Type = global::Tsu.Trees.RedGreen.Sample.SampleKind, Value = 11)
// Children:
// global::Tsu.Trees.RedGreen.Sample.Internal.ExpressionSample (IsList = False, Name = _expression, IsOptional = False, PassToBase = False, Order = 1)
// global::Tsu.Trees.RedGreen.Sample.Internal.SemicolonTokenSample (IsList = False, Name = _semicolon, IsOptional = False, PassToBase = True, Order = -1)
// ExtraData:
// global::Tsu.Trees.RedGreen.Sample.SampleKind (IsList = False, Name = _kind, IsOptional = False, PassToBase = True, Order = 0)
// Descendants:
// global::Tsu.Trees.RedGreen.Sample.Internal.AssignmentStatement
// Kinds:
// Tsu.Trees.RedGreen.Sample.SampleKind.AssignmentStatement (IsNull = False, Type = global::Tsu.Trees.RedGreen.Sample.SampleKind, Value = 10)
// Children:
// global::Tsu.Trees.RedGreen.Sample.Internal.IdentifierExpressionSample (IsList = False, Name = _identifier, IsOptional = False, PassToBase = False, Order = 1)
// global::Tsu.Trees.RedGreen.Sample.Internal.ExpressionSample (IsList = False, Name = _value, IsOptional = False, PassToBase = False, Order = 2)
// global::Tsu.Trees.RedGreen.Sample.Internal.SemicolonTokenSample (IsList = False, Name = _semicolon, IsOptional = False, PassToBase = True, Order = -1)
// ExtraData:
// global::Tsu.Trees.RedGreen.Sample.SampleKind (IsList = False, Name = _kind, IsOptional = False, PassToBase = True, Order = 0)
// Descendants:
// global::Tsu.Trees.RedGreen.Sample.Internal.SemicolonTokenSample
// Kinds:
// Tsu.Trees.RedGreen.Sample.SampleKind.SemicolonToken (IsNull = False, Type = global::Tsu.Trees.RedGreen.Sample.SampleKind, Value = 2)
// Children:
// ExtraData:
// global::Tsu.Trees.RedGreen.Sample.SampleKind (IsList = False, Name = _kind, IsOptional = False, PassToBase = True, Order = 0)
// Descendants:
Original file line number Diff line number Diff line change
@@ -0,0 +1,95 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// Modified by the Tsu (https://github.com/GGG-KILLER/Tsu) project for embedding into other projects.
// <auto-generated />

#nullable enable

namespace Tsu.Trees.RedGreen.Sample.Internal
{
internal partial struct ChildSampleList
{
internal struct Enumerator
{
private readonly global::Tsu.Trees.RedGreen.Sample.Internal.GreenNode? _node;
private int _childIndex;
private global::Tsu.Trees.RedGreen.Sample.Internal.GreenNode? _list;
private int _listIndex;
private global::Tsu.Trees.RedGreen.Sample.Internal.GreenNode? _currentChild;

internal Enumerator(global::Tsu.Trees.RedGreen.Sample.Internal.GreenNode? node)
{
_node = node;
_childIndex = -1;
_listIndex = -1;
_list = null;
_currentChild = null;
}

public bool MoveNext()
{
if (_node != null)
{
if (_list != null)
{
_listIndex++;

if (_listIndex < _list.SlotCount)
{
_currentChild = _list.GetSlot(_listIndex);
return true;
}

_list = null;
_listIndex = -1;
}

while (true)
{
_childIndex++;

if (_childIndex == _node.SlotCount)
{
break;
}

var child = _node.GetSlot(_childIndex);
if (child == null)
{
continue;
}

if (child.Kind == global::Tsu.Trees.RedGreen.Sample.Internal.GreenNode.ListKind)
{
_list = child;
_listIndex++;

if (_listIndex < _list.SlotCount)
{
_currentChild = _list.GetSlot(_listIndex);
return true;
}
else
{
_list = null;
_listIndex = -1;
continue;
}
}
else
{
_currentChild = child;
}

return true;
}
}

_currentChild = null;
return false;
}

public global::Tsu.Trees.RedGreen.Sample.Internal.GreenNode Current => _currentChild!;
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,98 @@
// Licensed to the .NET Foundation under one or more agreements.
// The .NET Foundation licenses this file to you under the MIT license.
// Modified by the Tsu (https://github.com/GGG-KILLER/Tsu) project for embedding into other projects.
// <auto-generated />

#nullable enable

namespace Tsu.Trees.RedGreen.Sample.Internal
{
internal partial struct ChildSampleList
{
internal partial struct Reversed
{
internal struct Enumerator
{
private readonly global::Tsu.Trees.RedGreen.Sample.Internal.GreenNode? _node;
private int _childIndex;
private global::Tsu.Trees.RedGreen.Sample.Internal.GreenNode? _list;
private int _listIndex;
private global::Tsu.Trees.RedGreen.Sample.Internal.GreenNode? _currentChild;

internal Enumerator(global::Tsu.Trees.RedGreen.Sample.Internal.GreenNode? node)
{
if (node != null)
{
_node = node;
_childIndex = node.SlotCount;
_listIndex = -1;
}
else
{
_node = null;
_childIndex = 0;
_listIndex = -1;
}

_list = null;
_currentChild = null;
}

public bool MoveNext()
{
if (_node != null)
{
if (_list != null)
{
if (--_listIndex >= 0)
{
_currentChild = _list.GetSlot(_listIndex);
return true;
}

_list = null;
_listIndex = -1;
}

while (--_childIndex >= 0)
{
var child = _node.GetSlot(_childIndex);
if (child == null)
{
continue;
}

if (child.IsList)
{
_list = child;
_listIndex = _list.SlotCount;
if (--_listIndex >= 0)
{
_currentChild = _list.GetSlot(_listIndex);
return true;
}
else
{
_list = null;
_listIndex = -1;
continue;
}
}
else
{
_currentChild = child;
}

return true;
}
}

_currentChild = null;
return false;
}

public global::Tsu.Trees.RedGreen.Sample.Internal.GreenNode Current => _currentChild!;
}
}
}
}
Loading

0 comments on commit d2603ff

Please sign in to comment.