...
This commit is contained in:
@@ -4,48 +4,58 @@ namespace Nub.Lang.Frontend.Typing;
|
||||
|
||||
public abstract class NubType
|
||||
{
|
||||
protected NubType(string name)
|
||||
{
|
||||
Name = name;
|
||||
}
|
||||
|
||||
public string Name { get; }
|
||||
|
||||
public static bool IsCompatibleWith(NubType sourceType, NubType targetType)
|
||||
{
|
||||
return targetType.Equals(NubPrimitiveType.Any) || sourceType.Equals(targetType);
|
||||
}
|
||||
|
||||
public override bool Equals(object? obj) => obj is NubType item && Name.Equals(item.Name);
|
||||
public override int GetHashCode() => HashCode.Combine(Name);
|
||||
public override string ToString() => Name;
|
||||
|
||||
public abstract override bool Equals(object? obj);
|
||||
public abstract override int GetHashCode();
|
||||
public abstract override string ToString();
|
||||
}
|
||||
|
||||
public class NubStructType(string @namespace, string name) : NubType(name)
|
||||
public class NubStructType(string @namespace, string name) : NubType
|
||||
{
|
||||
public string Namespace { get; } = @namespace;
|
||||
public string Name { get; } = name;
|
||||
|
||||
public override bool Equals(object? obj)
|
||||
{
|
||||
return obj is NubStructType other && other.Namespace == Namespace && other.Name == Name;
|
||||
}
|
||||
|
||||
public override int GetHashCode()
|
||||
{
|
||||
return HashCode.Combine(Namespace, Name);
|
||||
}
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
return $"{Namespace}::{Name}";
|
||||
}
|
||||
}
|
||||
|
||||
public class NubPointerType(NubType baseType) : NubType("^" + baseType)
|
||||
public class NubPointerType(NubType baseType) : NubType
|
||||
{
|
||||
public NubType BaseType { get; } = baseType;
|
||||
|
||||
public override bool Equals(object? obj)
|
||||
{
|
||||
if (obj is NubPointerType other)
|
||||
{
|
||||
return BaseType.Equals(other.BaseType);
|
||||
}
|
||||
return false;
|
||||
return obj is NubPointerType other && BaseType.Equals(other.BaseType);
|
||||
}
|
||||
|
||||
public override int GetHashCode()
|
||||
{
|
||||
return HashCode.Combine(base.GetHashCode(), BaseType);
|
||||
return HashCode.Combine(BaseType);
|
||||
}
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
return "^" + BaseType;
|
||||
}
|
||||
}
|
||||
|
||||
public class NubArrayType(NubType baseType) : NubType("[]" + baseType)
|
||||
public class NubArrayType(NubType baseType) : NubType
|
||||
{
|
||||
public NubType BaseType { get; } = baseType;
|
||||
|
||||
@@ -60,11 +70,16 @@ public class NubArrayType(NubType baseType) : NubType("[]" + baseType)
|
||||
|
||||
public override int GetHashCode()
|
||||
{
|
||||
return HashCode.Combine(base.GetHashCode(), BaseType);
|
||||
return HashCode.Combine(BaseType);
|
||||
}
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
return "[]" + BaseType;
|
||||
}
|
||||
}
|
||||
|
||||
public class NubPrimitiveType(PrimitiveTypeKind kind) : NubType(KindToString(kind))
|
||||
public class NubPrimitiveType(PrimitiveTypeKind kind) : NubType
|
||||
{
|
||||
public PrimitiveTypeKind Kind { get; } = kind;
|
||||
|
||||
@@ -108,7 +123,17 @@ public class NubPrimitiveType(PrimitiveTypeKind kind) : NubType(KindToString(kin
|
||||
return kind != null;
|
||||
}
|
||||
|
||||
public static string KindToString(PrimitiveTypeKind kind)
|
||||
public override bool Equals(object? obj)
|
||||
{
|
||||
return obj is NubPrimitiveType other && other.Kind == Kind;
|
||||
}
|
||||
|
||||
public override int GetHashCode()
|
||||
{
|
||||
return HashCode.Combine(Kind);
|
||||
}
|
||||
|
||||
public override string ToString()
|
||||
{
|
||||
return kind switch
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user