This commit is contained in:
nub31
2025-07-02 17:52:20 +02:00
parent 63d2c15202
commit 6003fa2f51
3 changed files with 33 additions and 100 deletions

View File

@@ -1,5 +1,4 @@
using System.Diagnostics;
using System.Diagnostics.CodeAnalysis;
using System.Diagnostics.CodeAnalysis;
using Common;
using Syntax.Diagnostics;
using Syntax.Parsing.Node;
@@ -730,29 +729,9 @@ public static class Parser
if (TryExpectSymbol(Symbol.OpenBracket))
{
if (Peek().TryGetValue(out var token) && token is LiteralToken { Kind: LiteralKind.Integer, Value: var sizeValue })
{
Next();
ExpectSymbol(Symbol.CloseBracket);
var baseType = ParseType();
var size = int.Parse(sizeValue);
if (size > 0)
{
return new NubFixedArrayType(baseType, size);
}
else
{
throw new UnreachableException();
}
}
else
{
ExpectSymbol(Symbol.CloseBracket);
var baseType = ParseType();
return new NubArrayType(baseType);
}
ExpectSymbol(Symbol.CloseBracket);
var baseType = ParseType();
return new NubArrayType(baseType);
}
if (!Peek().TryGetValue(out var peekToken))

View File

@@ -166,24 +166,6 @@ public class NubArrayType(NubType elementType) : NubType
}
}
public class NubFixedArrayType(NubType elementType, int capacity) : NubType
{
public NubType ElementType { get; } = elementType;
public int Capacity { get; } = capacity;
public override string ToString() => $"[{Capacity}]{ElementType}";
public override bool Equals(object? obj)
{
return obj is NubFixedArrayType other && ElementType.Equals(other.ElementType) && Capacity == other.Capacity;
}
public override int GetHashCode()
{
return HashCode.Combine(ElementType, Capacity);
}
}
public class NubAnyType : NubType
{
public override string ToString() => "any";