Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion .github/workflows/develop.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
2 changes: 1 addition & 1 deletion .github/workflows/release.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand Down
2 changes: 1 addition & 1 deletion Directory.Build.props
Original file line number Diff line number Diff line change
@@ -1,6 +1,6 @@
<Project>
<PropertyGroup>
<TargetFramework>net8.0</TargetFramework>
<TargetFramework>net9.0</TargetFramework>
<ImplicitUsings>enable</ImplicitUsings>
<Nullable>enable</Nullable>
<TreatWarningsAsErrors>true</TreatWarningsAsErrors>
Expand Down
2 changes: 1 addition & 1 deletion Readme.md
Original file line number Diff line number Diff line change
Expand Up @@ -173,7 +173,7 @@ let s = v2d as string

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

- .NET 8 SDK
- .NET 9 SDK

### Сборка
После клонирования репозитория идём в папку проекта `HydraScript`.
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,36 +5,31 @@ namespace HydraScript.Application.StaticAnalysis.Impl;

internal class FunctionWithUndefinedReturnStorage : IFunctionWithUndefinedReturnStorage
{
private readonly Dictionary<string, FunctionDeclaration> _declarations = [];
private readonly Dictionary<string, int> _keysWithOrder = [];
private readonly OrderedDictionary<string, FunctionDeclaration> _declarations = [];

public void Save(FunctionSymbol symbol, FunctionDeclaration declaration)
{
_declarations[symbol.Id] = declaration;
_keysWithOrder[symbol.Id] = _declarations.Count;
}

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<FunctionDeclaration> Flush() => _declarations
.OrderBy(kvp => _keysWithOrder[kvp.Key])
public IEnumerable<FunctionDeclaration> Flush() => _declarations.Keys.ToList()
.Select(x =>
{
_declarations.Remove(x.Key);
_keysWithOrder.Remove(x.Key);
return x.Value;
var decl = _declarations[x];
_declarations.Remove(x);
return decl;
});
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,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(
Expand All @@ -36,4 +36,66 @@ public void StorageIsEmptyAfterFlushTest()

Assert.Empty(storage.Flush());
}

[Fact]
public void StorageIsCorrectOrderTest()
{
FunctionDeclaration[] declarations = [
new FunctionDeclaration(
name: new IdentifierReference(functionName),
returnTypeValue: Substitute.For<TypeValue>(),
arguments: [],
new BlockStatement([])),

new FunctionDeclaration(
name: new IdentifierReference(functionName),
returnTypeValue: Substitute.For<TypeValue>(),
arguments: [],
new BlockStatement([])),

new FunctionDeclaration(
name: new IdentifierReference(functionName),
returnTypeValue: Substitute.For<TypeValue>(),
arguments: [],
new BlockStatement([])),

new FunctionDeclaration(
name: new IdentifierReference(functionName),
returnTypeValue: Substitute.For<TypeValue>(),
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());
}
}