raylib building
This commit is contained in:
@@ -11,7 +11,7 @@ public sealed class ModuleRepository
|
||||
public static ModuleRepository Create(List<SyntaxTree> syntaxTrees)
|
||||
{
|
||||
var structTypes = new Dictionary<(string module, string name), NubStructType>();
|
||||
var enumTypes = new Dictionary<(string module, string name), NubIntType>();
|
||||
var enumTypes = new Dictionary<(string module, string name), NubEnumType>();
|
||||
|
||||
foreach (var syntaxTree in syntaxTrees)
|
||||
{
|
||||
@@ -44,11 +44,27 @@ public sealed class ModuleRepository
|
||||
underlyingType ??= new NubIntType(false, 64);
|
||||
|
||||
var key = (module.NameToken.Value, enumSyntax.NameToken.Value);
|
||||
enumTypes.Add(key, underlyingType);
|
||||
|
||||
var memberValues = new Dictionary<string, ulong>();
|
||||
|
||||
ulong currentValue = 0;
|
||||
|
||||
foreach (var member in enumSyntax.Members)
|
||||
{
|
||||
if (member.ValueToken != null)
|
||||
{
|
||||
currentValue = member.ValueToken.AsU64;
|
||||
}
|
||||
|
||||
memberValues[member.NameToken.Value] = currentValue;
|
||||
currentValue++;
|
||||
}
|
||||
|
||||
enumTypes.Add(key, new NubEnumType(module.NameToken.Value, enumSyntax.NameToken.Value, underlyingType, memberValues));
|
||||
}
|
||||
}
|
||||
|
||||
// note(nub31): Since all struct types are now registered, we can safely resolve the field types
|
||||
// note(nub31): Since all struct and enum types are now registered, we can safely resolve the field types
|
||||
foreach (var syntaxTree in syntaxTrees)
|
||||
{
|
||||
var module = syntaxTree.TopLevelSyntaxNodes.OfType<ModuleSyntax>().FirstOrDefault();
|
||||
@@ -90,9 +106,7 @@ public sealed class ModuleRepository
|
||||
{
|
||||
Name = moduleDecl.NameToken.Value,
|
||||
StructTypes = structTypes.Where(x => x.Key.module == moduleDecl.NameToken.Value).Select(x => x.Value).ToList(),
|
||||
EnumTypes = enumTypes
|
||||
.Where(x => x.Key.module == moduleDecl.NameToken.Value)
|
||||
.ToDictionary(x => x.Key.name, x => x.Value),
|
||||
EnumTypes = enumTypes.Where(x => x.Key.module == moduleDecl.NameToken.Value).Select(x => x.Value).ToList(),
|
||||
FunctionPrototypes = functionPrototypes
|
||||
};
|
||||
|
||||
@@ -167,12 +181,6 @@ 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();
|
||||
@@ -183,22 +191,7 @@ public sealed class ModuleRepository
|
||||
public required string Name { get; init; }
|
||||
public required List<FuncPrototypeNode> FunctionPrototypes { get; init; } = [];
|
||||
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 required List<NubEnumType> EnumTypes { get; init; } = [];
|
||||
|
||||
public bool TryResolveFunc(IdentifierToken name, [NotNullWhen(true)] out FuncPrototypeNode? value, [NotNullWhen(false)] out Diagnostic? diagnostic)
|
||||
{
|
||||
@@ -215,31 +208,6 @@ public sealed class ModuleRepository
|
||||
return true;
|
||||
}
|
||||
|
||||
public FuncPrototypeNode ResolveFunc(IdentifierToken name)
|
||||
{
|
||||
if (!TryResolveFunc(name, out var value, out var diagnostic))
|
||||
{
|
||||
throw new CompileException(diagnostic);
|
||||
}
|
||||
|
||||
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);
|
||||
@@ -255,34 +223,9 @@ public sealed class ModuleRepository
|
||||
return true;
|
||||
}
|
||||
|
||||
public NubStructType ResolveStruct(IdentifierToken name)
|
||||
public bool TryResolveEnum(IdentifierToken name, [NotNullWhen(true)] out NubEnumType? value, [NotNullWhen(false)] out Diagnostic? diagnostic)
|
||||
{
|
||||
if (!TryResolveStruct(name, out var value, out var diagnostic))
|
||||
{
|
||||
throw new CompileException(diagnostic);
|
||||
}
|
||||
|
||||
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);
|
||||
value = EnumTypes.FirstOrDefault(x => x.Name == name.Value);
|
||||
|
||||
if (value == null)
|
||||
{
|
||||
@@ -294,15 +237,5 @@ public sealed class ModuleRepository
|
||||
diagnostic = null;
|
||||
return true;
|
||||
}
|
||||
|
||||
public NubIntType ResolveEnum(IdentifierToken name)
|
||||
{
|
||||
if (!TryResolveEnum(name, out var value, out var diagnostic))
|
||||
{
|
||||
throw new CompileException(diagnostic);
|
||||
}
|
||||
|
||||
return value;
|
||||
}
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user