Skip to content

Commit 7aad345

Browse files
authored
Feature/Перейти на OrderedDictionary в FunctionWithUndefinedReturnStorage (.NET 9+) (#121)
1 parent 3cbc9eb commit 7aad345

File tree

6 files changed

+72
-15
lines changed

6 files changed

+72
-15
lines changed

.github/workflows/develop.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@ jobs:
2727
- name: Setup .NET
2828
uses: actions/setup-dotnet@v4
2929
with:
30-
dotnet-version: 8.0.x
30+
dotnet-version: 9.0.x
3131
- name: Setup GitVersion
3232
uses: gittools/actions/gitversion/[email protected]
3333
with:

.github/workflows/release.yml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ jobs:
6161
- name: Setup .NET
6262
uses: actions/setup-dotnet@v4
6363
with:
64-
dotnet-version: 8.0.x
64+
dotnet-version: 9.0.x
6565
- name: Setup GitReleaseManager
6666
uses: gittools/actions/gitreleasemanager/[email protected]
6767
with:

Directory.Build.props

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
<Project>
22
<PropertyGroup>
3-
<TargetFramework>net8.0</TargetFramework>
3+
<TargetFramework>net9.0</TargetFramework>
44
<ImplicitUsings>enable</ImplicitUsings>
55
<Nullable>enable</Nullable>
66
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>

Readme.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,7 @@ let s = v2d as string
173173

174174
### Требования
175175

176-
- .NET 8 SDK
176+
- .NET 9 SDK
177177

178178
### Сборка
179179
После клонирования репозитория идём в папку проекта `HydraScript`.

src/Application/HydraScript.Application.StaticAnalysis/Impl/FunctionWithUndefinedReturnStorage.cs

Lines changed: 5 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -5,36 +5,31 @@ namespace HydraScript.Application.StaticAnalysis.Impl;
55

66
internal class FunctionWithUndefinedReturnStorage : IFunctionWithUndefinedReturnStorage
77
{
8-
private readonly Dictionary<string, FunctionDeclaration> _declarations = [];
9-
private readonly Dictionary<string, int> _keysWithOrder = [];
8+
private readonly OrderedDictionary<string, FunctionDeclaration> _declarations = [];
109

1110
public void Save(FunctionSymbol symbol, FunctionDeclaration declaration)
1211
{
1312
_declarations[symbol.Id] = declaration;
14-
_keysWithOrder[symbol.Id] = _declarations.Count;
1513
}
1614

1715
public FunctionDeclaration Get(FunctionSymbol symbol)
1816
{
1917
if (!_declarations.Remove(symbol.Id, out var declaration))
2018
throw new InvalidOperationException(message: "Cannot get function that has not been saved");
2119

22-
_keysWithOrder.Remove(symbol.Id);
2320
return declaration;
2421
}
2522

2623
public void RemoveIfPresent(FunctionSymbol symbol)
2724
{
2825
_declarations.Remove(symbol.Id);
29-
_keysWithOrder.Remove(symbol.Id);
3026
}
3127

32-
public IEnumerable<FunctionDeclaration> Flush() => _declarations
33-
.OrderBy(kvp => _keysWithOrder[kvp.Key])
28+
public IEnumerable<FunctionDeclaration> Flush() => _declarations.Keys.ToList()
3429
.Select(x =>
3530
{
36-
_declarations.Remove(x.Key);
37-
_keysWithOrder.Remove(x.Key);
38-
return x.Value;
31+
var decl = _declarations[x];
32+
_declarations.Remove(x);
33+
return decl;
3934
});
4035
}

tests/HydraScript.Tests/Unit/IR/FunctionWithUndefinedReturnStorageTests.cs

Lines changed: 63 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,10 @@ namespace HydraScript.Tests.Unit.IR;
1111

1212
public class FunctionWithUndefinedReturnStorageTests
1313
{
14+
const string functionName = nameof(functionName);
1415
[Fact]
1516
public void StorageIsEmptyAfterFlushTest()
1617
{
17-
const string functionName = nameof(functionName);
1818
IFunctionWithUndefinedReturnStorage storage = new FunctionWithUndefinedReturnStorage();
1919

2020
var symbol = new FunctionSymbol(
@@ -36,4 +36,66 @@ public void StorageIsEmptyAfterFlushTest()
3636

3737
Assert.Empty(storage.Flush());
3838
}
39+
40+
[Fact]
41+
public void StorageIsCorrectOrderTest()
42+
{
43+
FunctionDeclaration[] declarations = [
44+
new FunctionDeclaration(
45+
name: new IdentifierReference(functionName),
46+
returnTypeValue: Substitute.For<TypeValue>(),
47+
arguments: [],
48+
new BlockStatement([])),
49+
50+
new FunctionDeclaration(
51+
name: new IdentifierReference(functionName),
52+
returnTypeValue: Substitute.For<TypeValue>(),
53+
arguments: [],
54+
new BlockStatement([])),
55+
56+
new FunctionDeclaration(
57+
name: new IdentifierReference(functionName),
58+
returnTypeValue: Substitute.For<TypeValue>(),
59+
arguments: [],
60+
new BlockStatement([])),
61+
62+
new FunctionDeclaration(
63+
name: new IdentifierReference(functionName),
64+
returnTypeValue: Substitute.For<TypeValue>(),
65+
arguments: [],
66+
new BlockStatement([]))
67+
];
68+
69+
IFunctionWithUndefinedReturnStorage storage = new FunctionWithUndefinedReturnStorage();
70+
71+
var removable = new FunctionSymbol(
72+
id: "key2",
73+
parameters: [],
74+
"undefined",
75+
isEmpty: false);
76+
77+
storage.Save(new FunctionSymbol(
78+
id: "key1",
79+
parameters: [],
80+
"undefined",
81+
isEmpty: false), declaration: declarations[0]);
82+
83+
storage.Save(removable, declaration: declarations[1]);
84+
85+
storage.Save(new FunctionSymbol(
86+
id: "key3",
87+
parameters: [],
88+
"undefined",
89+
isEmpty: false), declaration: declarations[2]);
90+
91+
storage.Save(new FunctionSymbol(
92+
id: "key4",
93+
parameters: [],
94+
"undefined",
95+
isEmpty: false), declaration: declarations[3]);
96+
97+
storage.RemoveIfPresent(removable);
98+
99+
Assert.Equal([declarations[0], declarations[2], declarations[3]], storage.Flush());
100+
}
39101
}

0 commit comments

Comments
 (0)