d6bdd08002
the typechecker project can collect all the top level types from a file, which is pretty cool I think (except for pointers, those aren't implemented yet...)
24 lines
810 B
C#
24 lines
810 B
C#
namespace meowlang.typechecker;
|
|
|
|
public record EnumTypeDescription : TypeDescription
|
|
{
|
|
private readonly List<(string Name, TypeId? Type)> _members;
|
|
private readonly Dictionary<string, TypeId?> _memberMap;
|
|
|
|
public Dictionary<string, TypeId?> DebugGetMembers => _memberMap;
|
|
|
|
public EnumTypeDescription(List<(string Name, TypeId? Type)> members)
|
|
{
|
|
_members = members;
|
|
_memberMap = members.ToDictionary(x => x.Name, x => x.Type);
|
|
}
|
|
|
|
public IReadOnlyList<string> MemberNames => _members.Select(x => x.Name).ToList();
|
|
|
|
public TypeId? GetTypeForMember(string name)
|
|
{
|
|
return _memberMap.TryGetValue(name, out var value) ? value : throw new UnknownEnumMemberException(name);
|
|
}
|
|
|
|
public bool HasMember(string name) => _memberMap.ContainsKey(name);
|
|
}; |