...
This commit is contained in:
@@ -143,7 +143,7 @@ public sealed class ModuleRepository
|
||||
}
|
||||
}
|
||||
|
||||
private ModuleRepository(Dictionary<string, Module> modules)
|
||||
public ModuleRepository(Dictionary<string, Module> modules)
|
||||
{
|
||||
_modules = modules;
|
||||
}
|
||||
@@ -167,6 +167,17 @@ public sealed class ModuleRepository
|
||||
return module != null;
|
||||
}
|
||||
|
||||
public bool TryGet(string name, [NotNullWhen(true)] out Module? module)
|
||||
{
|
||||
module = _modules.GetValueOrDefault(name);
|
||||
return module != null;
|
||||
}
|
||||
|
||||
public List<Module> GetAll()
|
||||
{
|
||||
return _modules.Values.ToList();
|
||||
}
|
||||
|
||||
public sealed class Module
|
||||
{
|
||||
public required string Name { get; init; }
|
||||
@@ -174,6 +185,21 @@ public sealed class ModuleRepository
|
||||
public required List<NubStructType> StructTypes { get; init; } = [];
|
||||
public required Dictionary<string, NubIntType> EnumTypes { get; init; } = [];
|
||||
|
||||
public bool TryResolveFunc(string name, [NotNullWhen(true)] out FuncPrototypeNode? value, [NotNullWhen(false)] out Diagnostic? diagnostic)
|
||||
{
|
||||
value = FunctionPrototypes.FirstOrDefault(x => x.NameToken.Value == name);
|
||||
|
||||
if (value == null)
|
||||
{
|
||||
value = null;
|
||||
diagnostic = Diagnostic.Error($"Func {name} not found in module {Name}").Build();
|
||||
return false;
|
||||
}
|
||||
|
||||
diagnostic = null;
|
||||
return true;
|
||||
}
|
||||
|
||||
public bool TryResolveFunc(IdentifierToken name, [NotNullWhen(true)] out FuncPrototypeNode? value, [NotNullWhen(false)] out Diagnostic? diagnostic)
|
||||
{
|
||||
value = FunctionPrototypes.FirstOrDefault(x => x.NameToken.Value == name.Value);
|
||||
@@ -199,6 +225,21 @@ public sealed class ModuleRepository
|
||||
return value;
|
||||
}
|
||||
|
||||
public bool TryResolveStruct(string name, [NotNullWhen(true)] out NubStructType? value, [NotNullWhen(false)] out Diagnostic? diagnostic)
|
||||
{
|
||||
value = StructTypes.FirstOrDefault(x => x.Name == name);
|
||||
|
||||
if (value == null)
|
||||
{
|
||||
value = null;
|
||||
diagnostic = Diagnostic.Error($"Struct {name} not found in module {Name}").Build();
|
||||
return false;
|
||||
}
|
||||
|
||||
diagnostic = null;
|
||||
return true;
|
||||
}
|
||||
|
||||
public bool TryResolveStruct(IdentifierToken name, [NotNullWhen(true)] out NubStructType? value, [NotNullWhen(false)] out Diagnostic? diagnostic)
|
||||
{
|
||||
value = StructTypes.FirstOrDefault(x => x.Name == name.Value);
|
||||
@@ -224,6 +265,21 @@ public sealed class ModuleRepository
|
||||
return value;
|
||||
}
|
||||
|
||||
public bool TryResolveEnum(string name, [NotNullWhen(true)] out NubIntType? value, [NotNullWhen(false)] out Diagnostic? diagnostic)
|
||||
{
|
||||
value = EnumTypes.GetValueOrDefault(name);
|
||||
|
||||
if (value == null)
|
||||
{
|
||||
value = null;
|
||||
diagnostic = Diagnostic.Error($"Enum {name} not found in module {Name}").Build();
|
||||
return false;
|
||||
}
|
||||
|
||||
diagnostic = null;
|
||||
return true;
|
||||
}
|
||||
|
||||
public bool TryResolveEnum(IdentifierToken name, [NotNullWhen(true)] out NubIntType? value, [NotNullWhen(false)] out Diagnostic? diagnostic)
|
||||
{
|
||||
value = EnumTypes.GetValueOrDefault(name.Value);
|
||||
|
||||
Reference in New Issue
Block a user