...
This commit is contained in:
@@ -4,42 +4,34 @@ namespace NubLang.Modules;
|
||||
|
||||
public class Module
|
||||
{
|
||||
private readonly List<ModuleStruct> _structs = [];
|
||||
private readonly List<StructTemplateSyntax> _structTemplates = [];
|
||||
private readonly List<ModuleFunction> _functions = [];
|
||||
private readonly List<DefinitionSyntax> _definitions = [];
|
||||
|
||||
public void RegisterStruct(bool exported, string name, List<ModuleStructField> fields, List<ModuleStructFunction> functions)
|
||||
public void Register(DefinitionSyntax definition)
|
||||
{
|
||||
_structs.Add(new ModuleStruct(exported, name, fields, functions));
|
||||
_definitions.Add(definition);
|
||||
}
|
||||
|
||||
public void RegisterStructTemplate(StructTemplateSyntax structTemplate)
|
||||
public List<StructSyntax> Structs(bool includePrivate)
|
||||
{
|
||||
_structTemplates.Add(structTemplate);
|
||||
return _definitions
|
||||
.OfType<StructSyntax>()
|
||||
.Where(x => x.Exported || includePrivate)
|
||||
.ToList();
|
||||
}
|
||||
|
||||
public void RegisterFunction(bool exported, string name, string? externSymbol, List<ModuleFunctionParameter> parameters, TypeSyntax returnType)
|
||||
public List<StructTemplateSyntax> StructTemplates(bool includePrivate)
|
||||
{
|
||||
_functions.Add(new ModuleFunction(exported, name, externSymbol, parameters, returnType));
|
||||
return _definitions
|
||||
.OfType<StructTemplateSyntax>()
|
||||
.Where(x => x.Exported || includePrivate)
|
||||
.ToList();
|
||||
}
|
||||
|
||||
public List<ModuleStruct> StructTypes(bool includePrivate)
|
||||
public List<FuncSyntax> Functions(bool includePrivate)
|
||||
{
|
||||
return _structs.Where(x => x.Exported || includePrivate).ToList();
|
||||
return _definitions
|
||||
.OfType<FuncSyntax>()
|
||||
.Where(x => x.Exported || includePrivate)
|
||||
.ToList();
|
||||
}
|
||||
|
||||
public List<ModuleFunction> Functions(bool includePrivate)
|
||||
{
|
||||
return _functions.Where(x => x.Exported || includePrivate).ToList();
|
||||
}
|
||||
}
|
||||
|
||||
public record ModuleStructField(string Name, TypeSyntax Type, bool HasDefaultValue);
|
||||
|
||||
public record ModuleStructFunction(string Name, string? Hook, List<ModuleFunctionParameter> Parameters, TypeSyntax ReturnType);
|
||||
|
||||
public record ModuleStruct(bool Exported, string Name, List<ModuleStructField> Fields, List<ModuleStructFunction> Functions);
|
||||
|
||||
public record ModuleFunctionParameter(string Name, TypeSyntax Type);
|
||||
|
||||
public record ModuleFunction(bool Exported, string Name, string? ExternSymbol, List<ModuleFunctionParameter> Parameters, TypeSyntax ReturnType);
|
||||
}
|
||||
Reference in New Issue
Block a user