Skip to content

Commit

Permalink
Add the models that will be used in the source generator.
Browse files Browse the repository at this point in the history
  • Loading branch information
GGG-KILLER committed Jan 28, 2024
1 parent dbb5429 commit 63b73e7
Show file tree
Hide file tree
Showing 5 changed files with 177 additions and 0 deletions.
25 changes: 25 additions & 0 deletions Tsu.Trees.RedGreen/sourcegen/Model/Child.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
// Copyright © 2024 GGG KILLER <[email protected]>
//
// Permission is hereby granted, free of charge, to any person obtaining a copy of this software
// and associated documentation files (the “Software”), to deal in the Software without
// restriction, including without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom
// the Software is furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in all copies or
// substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING
// BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

using Microsoft.CodeAnalysis;

namespace Tsu.Trees.RedGreen.SourceGenerator.Model;

internal sealed record Child(
INamedTypeSymbol TypeSymbol,
string Name
);
49 changes: 49 additions & 0 deletions Tsu.Trees.RedGreen/sourcegen/Model/Node.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,49 @@
// Copyright © 2024 GGG KILLER <[email protected]>
//
// Permission is hereby granted, free of charge, to any person obtaining a copy of this software
// and associated documentation files (the “Software”), to deal in the Software without
// restriction, including without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom
// the Software is furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in all copies or
// substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING
// BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

using System.Collections.Immutable;
using Microsoft.CodeAnalysis;

namespace Tsu.Trees.RedGreen.SourceGenerator.Model;

internal sealed record Node(
INamedTypeSymbol TypeSymbol,
ImmutableArray<Node> Descendants,
ImmutableArray<Child> Children,
ImmutableArray<IParameterSymbol> ExtraData
)
{
public bool Equals(Node? other) =>
other is not null
&& SymbolEqualityComparer.Default.Equals(TypeSymbol, other.TypeSymbol)
&& Descendants.SequenceEqual(other.Descendants)
&& Children.SequenceEqual(other.Children)
&& ExtraData.SequenceEqual(other.ExtraData, SymbolEqualityComparer.Default.Equals);

public override int GetHashCode()
{
var hash = new HashCode();
hash.Add(TypeSymbol, SymbolEqualityComparer.Default);
foreach (var node in Descendants)
hash.Add(node);
foreach (var child in Children)
hash.Add(child);
foreach (var data in ExtraData)
hash.Add(data, SymbolEqualityComparer.Default);
return hash.ToHashCode();
}
}
44 changes: 44 additions & 0 deletions Tsu.Trees.RedGreen/sourcegen/Model/NodeInfo.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
// Copyright © 2024 GGG KILLER <[email protected]>
//
// Permission is hereby granted, free of charge, to any person obtaining a copy of this software
// and associated documentation files (the “Software”), to deal in the Software without
// restriction, including without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom
// the Software is furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in all copies or
// substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING
// BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

using System.Collections.Immutable;
using Microsoft.CodeAnalysis;

namespace Tsu.Trees.RedGreen.SourceGenerator.Model;

internal sealed record NodeInfo(
INamedTypeSymbol? BaseType,
INamedTypeSymbol NodeType,
ImmutableArray<TypedConstant> Kinds
)
{
public bool Equals(NodeInfo? other) =>
other is not null
&& SymbolEqualityComparer.Default.Equals(BaseType, other.BaseType)
&& SymbolEqualityComparer.Default.Equals(NodeType, other.NodeType)
&& Kinds.SequenceEqual(other.Kinds);

public override int GetHashCode()
{
var hash = new HashCode();
hash.Add(BaseType, SymbolEqualityComparer.Default);
hash.Add(NodeType, SymbolEqualityComparer.Default);
foreach (var kind in Kinds)
hash.Add(kind);
return hash.ToHashCode();
}
}
29 changes: 29 additions & 0 deletions Tsu.Trees.RedGreen/sourcegen/Model/Tree.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
// Copyright © 2024 GGG KILLER <[email protected]>
//
// Permission is hereby granted, free of charge, to any person obtaining a copy of this software
// and associated documentation files (the “Software”), to deal in the Software without
// restriction, including without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom
// the Software is furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in all copies or
// substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING
// BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

using Microsoft.CodeAnalysis;

namespace Tsu.Trees.RedGreen.SourceGenerator.Model;

internal sealed record Tree(
Node Root,
string Suffix,
INamedTypeSymbol KindEnum,
bool CreateVisitors,
bool CreateWalker,
bool CreateRewriter
);
30 changes: 30 additions & 0 deletions Tsu.Trees.RedGreen/sourcegen/Model/TreeInfo.cs
Original file line number Diff line number Diff line change
@@ -0,0 +1,30 @@
// Copyright © 2024 GGG KILLER <[email protected]>
//
// Permission is hereby granted, free of charge, to any person obtaining a copy of this software
// and associated documentation files (the “Software”), to deal in the Software without
// restriction, including without limitation the rights to use, copy, modify, merge, publish,
// distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom
// the Software is furnished to do so, subject to the following conditions:
//
// The above copyright notice and this permission notice shall be included in all copies or
// substantial portions of the Software.
//
// THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING
// BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
// NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM,
// DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING
// FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

using Microsoft.CodeAnalysis;

namespace Tsu.Trees.RedGreen.SourceGenerator.Model;

internal sealed record TreeInfo(
INamedTypeSymbol GreenBase,
INamedTypeSymbol RedBase,
INamedTypeSymbol KindEnum,
string Suffix,
bool CreateVisitors,
bool CreateWalker,
bool CreateRewriter
);

0 comments on commit 63b73e7

Please sign in to comment.