Skip to content

Commit b3233da

Browse files
committed
feat: Introduce Unit struct for semantic node visitor pattern
- Added a new `Unit` struct to represent a void return type in the semantic node visitor pattern. - Updated `LegalAcrobatics` to refine the way STC version is retrieved. - Modified `Program` to correctly display the STC version. - Refactored `PragmasExtensionsTests` to use the new `Unit` type in visitor pattern tests. - Updated `IxNodeVisitorTests` to ensure compatibility with the new visitor signature using `Unit`. - Bumped version of `@ax/stc` and related dependencies in `apax-lock.json` and `apax.yml` to 11.1.55.
1 parent 669e7d3 commit b3233da

8 files changed

Lines changed: 219 additions & 163 deletions

File tree

src/AXSharp.compiler/src/AXSharp.Compiler/Core/IxNodeVisitor.cs

Lines changed: 82 additions & 67 deletions
Large diffs are not rendered by default.
Lines changed: 42 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,42 @@
1+
// AXSharp.Compiler
2+
// Copyright (c) 2023 MTS spol. s r.o., and Contributors. All Rights Reserved.
3+
// Contributors: https://github.com/inxton/axsharp/graphs/contributors
4+
// See the LICENSE file in the repository root for more information.
5+
// https://github.com/inxton/axsharp/blob/dev/LICENSE
6+
// Third party licenses: https://github.com/inxton/axsharp/blob/master/notices.md
7+
8+
namespace AXSharp.Compiler.Core;
9+
10+
/// <summary>
11+
/// Represents a void/unit return type for the semantic node visitor pattern.
12+
/// Used as the TResult type parameter when the visitor doesn't need to return a meaningful value.
13+
/// </summary>
14+
public readonly struct Unit : IEquatable<Unit>
15+
{
16+
/// <summary>
17+
/// Gets the single value of the Unit type.
18+
/// </summary>
19+
public static readonly Unit Default = default;
20+
21+
/// <inheritdoc />
22+
public bool Equals(Unit other) => true;
23+
24+
/// <inheritdoc />
25+
public override bool Equals(object? obj) => obj is Unit;
26+
27+
/// <inheritdoc />
28+
public override int GetHashCode() => 0;
29+
30+
/// <inheritdoc />
31+
public override string ToString() => "()";
32+
33+
/// <summary>
34+
/// Determines whether two Unit values are equal (always true).
35+
/// </summary>
36+
public static bool operator ==(Unit left, Unit right) => true;
37+
38+
/// <summary>
39+
/// Determines whether two Unit values are not equal (always false).
40+
/// </summary>
41+
public static bool operator !=(Unit left, Unit right) => false;
42+
}

src/AXSharp.compiler/src/AXSharp.Compiler/LegalAcrobatics.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -46,7 +46,7 @@ private static void SetupAssemblyResolverLegalAcrobatics(string entryAssemblyLoc
4646

4747
AXAssemblies = axAssemblies;
4848

49-
StcVersion = AXAssemblies.FirstOrDefault()?.GetName().Version?.ToString();
49+
StcVersion = AXAssemblies.FirstOrDefault(p => p.GetName().FullName.StartsWith("AX.ST.Semantic"))?.GetName().Version?.ToString();
5050

5151

5252

src/AXSharp.compiler/src/ixc/Program.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,7 +111,7 @@ private static void DisplayInfo()
111111

112112

113113
Console.ForegroundColor = ConsoleColor.Magenta;
114-
Console.WriteLine($"Using version '> {LegalAcrobatics.StcVersion}' of stc.");
114+
Console.WriteLine($"Using version '{LegalAcrobatics.StcVersion}' of stc.");
115115
Console.ForegroundColor = originalColor;
116116

117117
if (int.Parse(GitVersionInformation.Major) < 1 || string.IsNullOrEmpty(GitVersionInformation.PreReleaseLabel))

src/AXSharp.compiler/tests/AXSharp.Compiler.CsTests/Cs/PragmasExtensionsTests.cs

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -253,7 +253,7 @@ public PragmaMock(string content)
253253

254254
public IEnumerable<ISemanticNode> ChildNodes => throw new NotImplementedException();
255255

256-
public void Accept<T>(ISemanticNodeVisitor<T> visitor, T data)
256+
public TResult Accept<TResult, TContext>(ISemanticNodeVisitor<TResult, TContext> visitor, TContext data)
257257
{
258258
throw new NotImplementedException();
259259
}

src/AXSharp.compiler/tests/AXSharp.CompilerTests/Core/IxNodeVisitorTests.cs

Lines changed: 64 additions & 64 deletions
Large diffs are not rendered by default.

src/apax/apax-lock.json

Lines changed: 27 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -7,56 +7,56 @@
77
"name": "s",
88
"version": "0.0.0",
99
"devDependencies": {
10-
"@ax/stc": "9.1.36"
10+
"@ax/stc": "11.1.55"
1111
}
1212
},
1313
"packages": {
14+
"@ax/st-docs": {
15+
"name": "@ax/st-docs",
16+
"version": "11.1.55",
17+
"integrity": "sha512-zHxPk+/FpaL/pXZqwlKDMUWmieSzMQpIPLnfs7Uer51S4gV+5xvwKrc5/9QR050ZcgzDV8MiqzJPFH+Cnz49gQ==",
18+
"resolved": "https://registry.simatic-ax.siemens.io/@ax/st-docs/-/st-docs-11.1.55.tgz",
19+
"dependencies": {}
20+
},
1421
"@ax/stc": {
1522
"name": "@ax/stc",
16-
"version": "9.1.36",
17-
"integrity": "sha512-v1crfIUg8rUVmrhtSTDoZZNub9At2iMiDgR4BK+3SA1VmhO7swGwnff0OkSoteE60kdxN+70AmKJJWlX+11WTA==",
18-
"resolved": "https://registry.simatic-ax.siemens.io/@ax/stc/-/stc-9.1.36.tgz",
23+
"version": "11.1.55",
24+
"integrity": "sha512-F24/kidxvVPkdFz1DCzk0kuLzhE21Hl/OZ53hedk4Ut+vkqtyWpk0zzqazMl+0cio8cayfW0kDGr/byyESUS2A==",
25+
"resolved": "https://registry.simatic-ax.siemens.io/@ax/stc/-/stc-11.1.55.tgz",
1926
"dependencies": {
20-
"@ax/stc-win-x64": "9.1.36",
21-
"@ax/stc-linux-x64": "9.1.36"
27+
"@ax/stc-linux-x64": "11.1.55",
28+
"@ax/stc-win-x64": "11.1.55"
2229
}
2330
},
24-
"@ax/stc-win-x64": {
25-
"name": "@ax/stc-win-x64",
26-
"version": "9.1.36",
27-
"integrity": "sha512-Ibmdf+eqfe4GzSxeZz3bxW3NStfscNDVtlmjI2enjpmSIybTak3xH4JHpQHJFkJEJqx9aMndue3GFKpPs16ovw==",
28-
"resolved": "https://registry.simatic-ax.siemens.io/@ax/stc-win-x64/-/stc-win-x64-9.1.36.tgz",
31+
"@ax/stc-linux-x64": {
32+
"name": "@ax/stc-linux-x64",
33+
"version": "11.1.55",
34+
"integrity": "sha512-HacfsylKTabNefS95J3Iu0R4D/qm374OythdVgCnVdD21qy3kZMNZCWpfJkjwW4pao1CGlA7IxPTY4ip081/Hg==",
35+
"resolved": "https://registry.simatic-ax.siemens.io/@ax/stc-linux-x64/-/stc-linux-x64-11.1.55.tgz",
2936
"os": [
30-
"win32"
37+
"linux"
3138
],
3239
"cpu": [
3340
"x64"
3441
],
3542
"dependencies": {
36-
"@ax/st-docs": "9.1.36"
43+
"@ax/st-docs": "11.1.55"
3744
}
3845
},
39-
"@ax/stc-linux-x64": {
40-
"name": "@ax/stc-linux-x64",
41-
"version": "9.1.36",
42-
"integrity": "sha512-mlOpXtZ1V2VZNFRSb8PyqhQpPZ0a2Q3m0J/d0n/s4iIIEaneUON/JtywCTAQdvQJYer5PuKDoZf/dBLlgNRuRQ==",
43-
"resolved": "https://registry.simatic-ax.siemens.io/@ax/stc-linux-x64/-/stc-linux-x64-9.1.36.tgz",
46+
"@ax/stc-win-x64": {
47+
"name": "@ax/stc-win-x64",
48+
"version": "11.1.55",
49+
"integrity": "sha512-Iqy5dWiHjz6ff3iwPhPtmr528r+F5sBiQm0CRZCGiiCMrr74GveNIlyQFdeXbVFWcgNwc8piHBXE84CbbXvftg==",
50+
"resolved": "https://registry.simatic-ax.siemens.io/@ax/stc-win-x64/-/stc-win-x64-11.1.55.tgz",
4451
"os": [
45-
"linux"
52+
"win32"
4653
],
4754
"cpu": [
4855
"x64"
4956
],
5057
"dependencies": {
51-
"@ax/st-docs": "9.1.36"
58+
"@ax/st-docs": "11.1.55"
5259
}
53-
},
54-
"@ax/st-docs": {
55-
"name": "@ax/st-docs",
56-
"version": "9.1.36",
57-
"integrity": "sha512-xxUUXzm9VSf7p0yaOKZ+kep2+JDq9eqD2ddGNhysvocLI3SZhDxF693axQpCoJA2PxhpJdut+lXSZkCgNOVIsA==",
58-
"resolved": "https://registry.simatic-ax.siemens.io/@ax/st-docs/-/st-docs-9.1.36.tgz",
59-
"dependencies": {}
6060
}
6161
},
6262
"workspaces": {}

src/apax/apax.yml

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,7 @@ version: 0.0.0
33
type: app
44
targets:
55
- "1500"
6-
- axunit-llvm
76
devDependencies:
8-
"@ax/stc": 9.1.36
7+
"@ax/stc": 11.1.55
98
installStrategy: strict
109
apaxVersion: 3.1.1

0 commit comments

Comments
 (0)