48 lines
1.6 KiB
C#
48 lines
1.6 KiB
C#
using NubLang.Parsing.Syntax;
|
|
|
|
namespace NubLang.Modules;
|
|
|
|
public class Module
|
|
{
|
|
private readonly List<ModuleStructType> _structs = [];
|
|
private readonly List<ModuleInterfaceType> _interfaces = [];
|
|
private readonly List<ModuleFuncType> _functions = [];
|
|
|
|
public void RegisterStruct(bool exported, string name, IReadOnlyList<ModuleStructTypeField> fields)
|
|
{
|
|
_structs.Add(new ModuleStructType(exported, name, fields));
|
|
}
|
|
|
|
public void RegisterInterface(bool exported, string name)
|
|
{
|
|
_interfaces.Add(new ModuleInterfaceType(exported, name));
|
|
}
|
|
|
|
public void RegisterFunction(bool exported, string name, string? externSymbol, FuncTypeSyntax type)
|
|
{
|
|
_functions.Add(new ModuleFuncType(exported, name, externSymbol, type));
|
|
}
|
|
|
|
public IReadOnlyList<ModuleStructType> StructTypes(bool includePrivate)
|
|
{
|
|
return _structs.Where(x => x.Exported || includePrivate).ToList();
|
|
}
|
|
|
|
public IReadOnlyList<ModuleInterfaceType> InterfaceTypes(bool includePrivate)
|
|
{
|
|
return _interfaces.Where(x => x.Exported || includePrivate).ToList();
|
|
}
|
|
|
|
public IReadOnlyList<ModuleFuncType> Functions(bool includePrivate)
|
|
{
|
|
return _functions.Where(x => x.Exported || includePrivate).ToList();
|
|
}
|
|
}
|
|
|
|
public record ModuleStructTypeField(string Name, TypeSyntax Type, bool HasDefaultValue);
|
|
|
|
public record ModuleStructType(bool Exported, string Name, IReadOnlyList<ModuleStructTypeField> Fields);
|
|
|
|
public record ModuleInterfaceType(bool Exported, string Name);
|
|
|
|
public record ModuleFuncType(bool Exported, string Name, string? ExternSymbol, FuncTypeSyntax FuncType); |