From 98af0beebe102392fcbf346533804b1f788ed605 Mon Sep 17 00:00:00 2001 From: hw2cb Date: Fri, 31 Jan 2025 00:41:34 +0300 Subject: [PATCH 1/6] =?UTF-8?q?=D0=BF=D0=B5=D1=80=D0=B5=D1=85=D0=BE=D0=B4?= =?UTF-8?q?=20=D0=BD=D0=B0=20OrderedDictionary?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- Directory.Build.props | 2 +- .../Impl/FunctionWithUndefinedReturnStorage.cs | 8 +------- 2 files changed, 2 insertions(+), 8 deletions(-) diff --git a/Directory.Build.props b/Directory.Build.props index 8b943f64..0740392c 100644 --- a/Directory.Build.props +++ b/Directory.Build.props @@ -1,6 +1,6 @@ - net8.0 + net9.0 enable enable true diff --git a/src/Application/HydraScript.Application.StaticAnalysis/Impl/FunctionWithUndefinedReturnStorage.cs b/src/Application/HydraScript.Application.StaticAnalysis/Impl/FunctionWithUndefinedReturnStorage.cs index 4de6ff44..7e9af3ba 100644 --- a/src/Application/HydraScript.Application.StaticAnalysis/Impl/FunctionWithUndefinedReturnStorage.cs +++ b/src/Application/HydraScript.Application.StaticAnalysis/Impl/FunctionWithUndefinedReturnStorage.cs @@ -5,13 +5,11 @@ namespace HydraScript.Application.StaticAnalysis.Impl; internal class FunctionWithUndefinedReturnStorage : IFunctionWithUndefinedReturnStorage { - private readonly Dictionary _declarations = []; - private readonly Dictionary _keysWithOrder = []; + private readonly OrderedDictionary _declarations = []; public void Save(FunctionSymbol symbol, FunctionDeclaration declaration) { _declarations[symbol.Id] = declaration; - _keysWithOrder[symbol.Id] = _declarations.Count; } public FunctionDeclaration Get(FunctionSymbol symbol) @@ -19,22 +17,18 @@ public FunctionDeclaration Get(FunctionSymbol symbol) if (!_declarations.Remove(symbol.Id, out var declaration)) throw new InvalidOperationException(message: "Cannot get function that has not been saved"); - _keysWithOrder.Remove(symbol.Id); return declaration; } public void RemoveIfPresent(FunctionSymbol symbol) { _declarations.Remove(symbol.Id); - _keysWithOrder.Remove(symbol.Id); } public IEnumerable Flush() => _declarations - .OrderBy(kvp => _keysWithOrder[kvp.Key]) .Select(x => { _declarations.Remove(x.Key); - _keysWithOrder.Remove(x.Key); return x.Value; }); } \ No newline at end of file From ab52469eabbb282362df88f3af603c3df15ae5e8 Mon Sep 17 00:00:00 2001 From: hw2cb Date: Fri, 31 Jan 2025 21:47:59 +0300 Subject: [PATCH 2/6] =?UTF-8?q?=D0=BE=D0=B1=D0=BD=D0=BE=D0=B2=D0=BB=D0=B5?= =?UTF-8?q?=D0=BD=D1=8B=20workflow=20=D0=B8=20readme=20=D0=BD=D0=B0=209=20?= =?UTF-8?q?NET?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .github/workflows/develop.yml | 2 +- .github/workflows/release.yml | 2 +- Readme.md | 2 +- 3 files changed, 3 insertions(+), 3 deletions(-) diff --git a/.github/workflows/develop.yml b/.github/workflows/develop.yml index 28509c3d..ab1adb7d 100644 --- a/.github/workflows/develop.yml +++ b/.github/workflows/develop.yml @@ -27,7 +27,7 @@ jobs: - name: Setup .NET uses: actions/setup-dotnet@v4 with: - dotnet-version: 8.0.x + dotnet-version: 9.0.x - name: Setup GitVersion uses: gittools/actions/gitversion/setup@v3.0.0 with: diff --git a/.github/workflows/release.yml b/.github/workflows/release.yml index a6032768..527a96af 100644 --- a/.github/workflows/release.yml +++ b/.github/workflows/release.yml @@ -61,7 +61,7 @@ jobs: - name: Setup .NET uses: actions/setup-dotnet@v4 with: - dotnet-version: 8.0.x + dotnet-version: 9.0.x - name: Setup GitReleaseManager uses: gittools/actions/gitreleasemanager/setup@v3.0.0 with: diff --git a/Readme.md b/Readme.md index 1c2f3225..b13025ba 100644 --- a/Readme.md +++ b/Readme.md @@ -173,7 +173,7 @@ let s = v2d as string ### Требования -- .NET 8 SDK +- .NET 9 SDK ### Сборка После клонирования репозитория идём в папку проекта `HydraScript`. From 75bad60eb65fc671aae090cf72ba7a1541238774 Mon Sep 17 00:00:00 2001 From: hw2cb Date: Sat, 1 Feb 2025 00:09:59 +0300 Subject: [PATCH 3/6] =?UTF-8?q?=D0=B4=D0=BE=D0=B1=D0=B0=D0=B2=D0=BB=D0=B5?= =?UTF-8?q?=D0=BD=20=D1=82=D0=B5=D1=81=D1=82=20=D0=B4=D0=BB=D1=8F=20=D1=81?= =?UTF-8?q?=D0=BE=D1=85=D1=80=D0=B0=D0=BD=D0=B5=D0=BD=D0=B8=D1=8F=20=D0=BF?= =?UTF-8?q?=D0=BE=D1=80=D1=8F=D0=B4=D0=BA=D0=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- ...FunctionWithUndefinedReturnStorageTests.cs | 65 ++++++++++++++++++- 1 file changed, 64 insertions(+), 1 deletion(-) diff --git a/tests/HydraScript.Tests/Unit/IR/FunctionWithUndefinedReturnStorageTests.cs b/tests/HydraScript.Tests/Unit/IR/FunctionWithUndefinedReturnStorageTests.cs index d374898a..0d5c68ff 100644 --- a/tests/HydraScript.Tests/Unit/IR/FunctionWithUndefinedReturnStorageTests.cs +++ b/tests/HydraScript.Tests/Unit/IR/FunctionWithUndefinedReturnStorageTests.cs @@ -1,6 +1,7 @@ using HydraScript.Application.StaticAnalysis; using HydraScript.Application.StaticAnalysis.Impl; using HydraScript.Domain.FrontEnd.Parser.Impl.Ast.Nodes.Declarations; +using HydraScript.Domain.IR; using HydraScript.Domain.IR.Impl.Symbols; using Xunit; using BlockStatement = HydraScript.Domain.FrontEnd.Parser.Impl.Ast.Nodes.Statements.BlockStatement; @@ -11,10 +12,10 @@ namespace HydraScript.Tests.Unit.IR; public class FunctionWithUndefinedReturnStorageTests { + const string functionName = nameof(functionName); [Fact] public void StorageIsEmptyAfterFlushTest() { - const string functionName = nameof(functionName); IFunctionWithUndefinedReturnStorage storage = new FunctionWithUndefinedReturnStorage(); var symbol = new FunctionSymbol( @@ -36,4 +37,66 @@ public void StorageIsEmptyAfterFlushTest() Assert.Empty(storage.Flush()); } + + [Fact] + public void StorageIsCorrectOrderTest() + { + FunctionDeclaration[] declarations = [ + new FunctionDeclaration( + name: new IdentifierReference(functionName), + returnTypeValue: Substitute.For(), + arguments: [], + new BlockStatement([])), + + new FunctionDeclaration( + name: new IdentifierReference(functionName), + returnTypeValue: Substitute.For(), + arguments: [], + new BlockStatement([])), + + new FunctionDeclaration( + name: new IdentifierReference(functionName), + returnTypeValue: Substitute.For(), + arguments: [], + new BlockStatement([])), + + new FunctionDeclaration( + name: new IdentifierReference(functionName), + returnTypeValue: Substitute.For(), + arguments: [], + new BlockStatement([])) + ]; + + IFunctionWithUndefinedReturnStorage storage = new FunctionWithUndefinedReturnStorage(); + + var removable = new FunctionSymbol( + id: "key2", + parameters: [], + "undefined", + isEmpty: false); + + storage.Save(new FunctionSymbol( + id: "key1", + parameters: [], + "undefined", + isEmpty: false), declaration: declarations[0]); + + storage.Save(removable, declaration: declarations[1]); + + storage.Save(new FunctionSymbol( + id: "key3", + parameters: [], + "undefined", + isEmpty: false), declaration: declarations[2]); + + storage.Save(new FunctionSymbol( + id: "key4", + parameters: [], + "undefined", + isEmpty: false), declaration: declarations[3]); + + storage.RemoveIfPresent(removable); + + Assert.Equal([declarations[0], declarations[2], declarations[3]], storage.Flush()); + } } \ No newline at end of file From 24e7093c55727603a73132c1d835d63718183779 Mon Sep 17 00:00:00 2001 From: hw2cb Date: Sat, 1 Feb 2025 00:25:14 +0300 Subject: [PATCH 4/6] =?UTF-8?q?=D1=84=D0=B8=D0=BA=D1=81=20=D0=BC=D0=B5?= =?UTF-8?q?=D1=82=D0=BE=D0=B4=D0=B0=20flush?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Impl/FunctionWithUndefinedReturnStorage.cs | 8 ++------ .../OrderedDictionaryExtensions.cs | 15 +++++++++++++++ 2 files changed, 17 insertions(+), 6 deletions(-) create mode 100644 src/Application/HydraScript.Application.StaticAnalysis/OrderedDictionaryExtensions.cs diff --git a/src/Application/HydraScript.Application.StaticAnalysis/Impl/FunctionWithUndefinedReturnStorage.cs b/src/Application/HydraScript.Application.StaticAnalysis/Impl/FunctionWithUndefinedReturnStorage.cs index 7e9af3ba..f0914216 100644 --- a/src/Application/HydraScript.Application.StaticAnalysis/Impl/FunctionWithUndefinedReturnStorage.cs +++ b/src/Application/HydraScript.Application.StaticAnalysis/Impl/FunctionWithUndefinedReturnStorage.cs @@ -25,10 +25,6 @@ public void RemoveIfPresent(FunctionSymbol symbol) _declarations.Remove(symbol.Id); } - public IEnumerable Flush() => _declarations - .Select(x => - { - _declarations.Remove(x.Key); - return x.Value; - }); + public IEnumerable Flush() => _declarations.Keys.ToList() + .Select(x => _declarations.Extract(x)); } \ No newline at end of file diff --git a/src/Application/HydraScript.Application.StaticAnalysis/OrderedDictionaryExtensions.cs b/src/Application/HydraScript.Application.StaticAnalysis/OrderedDictionaryExtensions.cs new file mode 100644 index 00000000..db103c1a --- /dev/null +++ b/src/Application/HydraScript.Application.StaticAnalysis/OrderedDictionaryExtensions.cs @@ -0,0 +1,15 @@ + +namespace HydraScript.Application.StaticAnalysis +{ + internal static class OrderedDictionaryExtensions + { + public static TValue Extract( + this OrderedDictionary dict, + TKey key) where TKey: notnull + { + var value = dict[key]; + dict.Remove(key); + return value; + } + } +} From 2760f8213bfab07b3a286033b4e2c988d623ee32 Mon Sep 17 00:00:00 2001 From: hw2cb Date: Sat, 1 Feb 2025 00:33:59 +0300 Subject: [PATCH 5/6] =?UTF-8?q?=D1=83=D0=B4=D0=B0=D0=BB=D0=B8=D0=BB=20usin?= =?UTF-8?q?g?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Unit/IR/FunctionWithUndefinedReturnStorageTests.cs | 1 - 1 file changed, 1 deletion(-) diff --git a/tests/HydraScript.Tests/Unit/IR/FunctionWithUndefinedReturnStorageTests.cs b/tests/HydraScript.Tests/Unit/IR/FunctionWithUndefinedReturnStorageTests.cs index 0d5c68ff..9c8f7a7a 100644 --- a/tests/HydraScript.Tests/Unit/IR/FunctionWithUndefinedReturnStorageTests.cs +++ b/tests/HydraScript.Tests/Unit/IR/FunctionWithUndefinedReturnStorageTests.cs @@ -1,7 +1,6 @@ using HydraScript.Application.StaticAnalysis; using HydraScript.Application.StaticAnalysis.Impl; using HydraScript.Domain.FrontEnd.Parser.Impl.Ast.Nodes.Declarations; -using HydraScript.Domain.IR; using HydraScript.Domain.IR.Impl.Symbols; using Xunit; using BlockStatement = HydraScript.Domain.FrontEnd.Parser.Impl.Ast.Nodes.Statements.BlockStatement; From b931f614cd8dbad69438a3fbc362deaca5905eb1 Mon Sep 17 00:00:00 2001 From: hw2cb Date: Sat, 1 Feb 2025 13:56:24 +0300 Subject: [PATCH 6/6] =?UTF-8?q?=D1=83=D0=B1=D1=80=D0=B0=D0=BB=20=D0=BC?= =?UTF-8?q?=D0=B5=D1=82=D0=BE=D0=B4=20=D1=80=D0=B0=D1=81=D1=88=D0=B8=D1=80?= =?UTF-8?q?=D0=B5=D0=BD=D0=B8=D1=8F=20Extract=20=D0=B4=D0=BB=D1=8F=20Order?= =?UTF-8?q?edDict?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../Impl/FunctionWithUndefinedReturnStorage.cs | 7 ++++++- .../OrderedDictionaryExtensions.cs | 15 --------------- 2 files changed, 6 insertions(+), 16 deletions(-) delete mode 100644 src/Application/HydraScript.Application.StaticAnalysis/OrderedDictionaryExtensions.cs diff --git a/src/Application/HydraScript.Application.StaticAnalysis/Impl/FunctionWithUndefinedReturnStorage.cs b/src/Application/HydraScript.Application.StaticAnalysis/Impl/FunctionWithUndefinedReturnStorage.cs index f0914216..b76cfac4 100644 --- a/src/Application/HydraScript.Application.StaticAnalysis/Impl/FunctionWithUndefinedReturnStorage.cs +++ b/src/Application/HydraScript.Application.StaticAnalysis/Impl/FunctionWithUndefinedReturnStorage.cs @@ -26,5 +26,10 @@ public void RemoveIfPresent(FunctionSymbol symbol) } public IEnumerable Flush() => _declarations.Keys.ToList() - .Select(x => _declarations.Extract(x)); + .Select(x => + { + var decl = _declarations[x]; + _declarations.Remove(x); + return decl; + }); } \ No newline at end of file diff --git a/src/Application/HydraScript.Application.StaticAnalysis/OrderedDictionaryExtensions.cs b/src/Application/HydraScript.Application.StaticAnalysis/OrderedDictionaryExtensions.cs deleted file mode 100644 index db103c1a..00000000 --- a/src/Application/HydraScript.Application.StaticAnalysis/OrderedDictionaryExtensions.cs +++ /dev/null @@ -1,15 +0,0 @@ - -namespace HydraScript.Application.StaticAnalysis -{ - internal static class OrderedDictionaryExtensions - { - public static TValue Extract( - this OrderedDictionary dict, - TKey key) where TKey: notnull - { - var value = dict[key]; - dict.Remove(key); - return value; - } - } -}