From 63b73e7738f68a4605017dc3fb5ce6228bbc8808 Mon Sep 17 00:00:00 2001 From: GGG Date: Sun, 28 Jan 2024 04:34:44 -0300 Subject: [PATCH] Add the models that will be used in the source generator. --- Tsu.Trees.RedGreen/sourcegen/Model/Child.cs | 25 ++++++++++ Tsu.Trees.RedGreen/sourcegen/Model/Node.cs | 49 +++++++++++++++++++ .../sourcegen/Model/NodeInfo.cs | 44 +++++++++++++++++ Tsu.Trees.RedGreen/sourcegen/Model/Tree.cs | 29 +++++++++++ .../sourcegen/Model/TreeInfo.cs | 30 ++++++++++++ 5 files changed, 177 insertions(+) create mode 100644 Tsu.Trees.RedGreen/sourcegen/Model/Child.cs create mode 100644 Tsu.Trees.RedGreen/sourcegen/Model/Node.cs create mode 100644 Tsu.Trees.RedGreen/sourcegen/Model/NodeInfo.cs create mode 100644 Tsu.Trees.RedGreen/sourcegen/Model/Tree.cs create mode 100644 Tsu.Trees.RedGreen/sourcegen/Model/TreeInfo.cs diff --git a/Tsu.Trees.RedGreen/sourcegen/Model/Child.cs b/Tsu.Trees.RedGreen/sourcegen/Model/Child.cs new file mode 100644 index 0000000..61a111f --- /dev/null +++ b/Tsu.Trees.RedGreen/sourcegen/Model/Child.cs @@ -0,0 +1,25 @@ +// Copyright © 2024 GGG KILLER +// +// 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 +); \ No newline at end of file diff --git a/Tsu.Trees.RedGreen/sourcegen/Model/Node.cs b/Tsu.Trees.RedGreen/sourcegen/Model/Node.cs new file mode 100644 index 0000000..a521e2f --- /dev/null +++ b/Tsu.Trees.RedGreen/sourcegen/Model/Node.cs @@ -0,0 +1,49 @@ +// Copyright © 2024 GGG KILLER +// +// 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 Descendants, + ImmutableArray Children, + ImmutableArray 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(); + } +} diff --git a/Tsu.Trees.RedGreen/sourcegen/Model/NodeInfo.cs b/Tsu.Trees.RedGreen/sourcegen/Model/NodeInfo.cs new file mode 100644 index 0000000..1453be1 --- /dev/null +++ b/Tsu.Trees.RedGreen/sourcegen/Model/NodeInfo.cs @@ -0,0 +1,44 @@ +// Copyright © 2024 GGG KILLER +// +// 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 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(); + } +} \ No newline at end of file diff --git a/Tsu.Trees.RedGreen/sourcegen/Model/Tree.cs b/Tsu.Trees.RedGreen/sourcegen/Model/Tree.cs new file mode 100644 index 0000000..6d5e51d --- /dev/null +++ b/Tsu.Trees.RedGreen/sourcegen/Model/Tree.cs @@ -0,0 +1,29 @@ +// Copyright © 2024 GGG KILLER +// +// 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 +); \ No newline at end of file diff --git a/Tsu.Trees.RedGreen/sourcegen/Model/TreeInfo.cs b/Tsu.Trees.RedGreen/sourcegen/Model/TreeInfo.cs new file mode 100644 index 0000000..9e7ac09 --- /dev/null +++ b/Tsu.Trees.RedGreen/sourcegen/Model/TreeInfo.cs @@ -0,0 +1,30 @@ +// Copyright © 2024 GGG KILLER +// +// 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 +); \ No newline at end of file