This commit is contained in:
nub31
2025-07-09 20:04:06 +02:00
parent 22e7fedbe3
commit 3fd6eb4d81
10 changed files with 93 additions and 86 deletions

View File

@@ -34,7 +34,7 @@ public sealed class Binder
{
try
{
definitions.Add(BindTopLevel(definition));
definitions.Add(BindDefinition(definition));
}
catch (BindException e)
{
@@ -45,15 +45,15 @@ public sealed class Binder
return new BoundSyntaxTree(_syntaxTree.Namespace, definitions, diagnostics);
}
private BoundDefinition BindTopLevel(DefinitionSyntax node)
private BoundDefinition BindDefinition(DefinitionSyntax node)
{
return node switch
{
ExternFuncSyntax topLevel => BindExternFuncDefinition(topLevel),
TraitImplSyntax topLevel => BindTraitImplementation(topLevel),
TraitSyntax topLevel => BindTraitDefinition(topLevel),
LocalFuncSyntax topLevel => BindLocalFuncDefinition(topLevel),
StructSyntax topLevel => BindStruct(topLevel),
ExternFuncSyntax definition => BindExternFuncDefinition(definition),
TraitImplSyntax definition => BindTraitImplementation(definition),
TraitSyntax definition => BindTraitDefinition(definition),
LocalFuncSyntax definition => BindLocalFuncDefinition(definition),
StructSyntax definition => BindStruct(definition),
_ => throw new ArgumentOutOfRangeException(nameof(node))
};
}
@@ -403,7 +403,7 @@ public sealed class Binder
{
if (traits.Length > 1)
{
throw new BindException(Diagnostic.Error($"Trait {customType.Namespace}::{customType.Name} has multiple definitions").Build());
throw new BindException(Diagnostic.Error($"Trait {customType} has multiple definitions").Build());
}
var trait = traits[0];
@@ -413,7 +413,7 @@ public sealed class Binder
{
if (traits.Length > 1)
{
throw new BindException(Diagnostic.Error($"Trait {trait.Namespace}::{trait.Name} has multiple functions with the name {expression.Member}").Build());
throw new BindException(Diagnostic.Error($"Trait {customType} has multiple functions with the name {expression.Member}").Build());
}
var traitFunc = traitFuncs[0];
@@ -428,7 +428,7 @@ public sealed class Binder
{
if (structs.Length > 1)
{
throw new BindException(Diagnostic.Error($"Struct {customType.Namespace}::{customType.Name} has multiple definitions").Build());
throw new BindException(Diagnostic.Error($"Struct {customType} has multiple definitions").Build());
}
var @struct = structs[0];
@@ -438,7 +438,7 @@ public sealed class Binder
{
if (fields.Length > 1)
{
throw new BindException(Diagnostic.Error($"Struct {@struct.Namespace}::{@struct.Name} has multiple fields with the name {expression.Member}").Build());
throw new BindException(Diagnostic.Error($"Struct {customType} has multiple fields with the name {expression.Member}").Build());
}
var field = fields[0];
@@ -462,12 +462,12 @@ public sealed class Binder
if (structs.Length == 0)
{
throw new BindException(Diagnostic.Error($"Struct {structType.Namespace}::{structType.Name} is not defined").Build());
throw new BindException(Diagnostic.Error($"Struct {structType} is not defined").Build());
}
if (structs.Length > 1)
{
throw new BindException(Diagnostic.Error($"Struct {structType.Namespace}::{structType.Name} has multiple definitions").Build());
throw new BindException(Diagnostic.Error($"Struct {structType} has multiple definitions").Build());
}
var @struct = structs[0];
@@ -480,18 +480,18 @@ public sealed class Binder
if (fields.Length == 0)
{
throw new BindException(Diagnostic.Error($"Struct {@struct.Namespace}::{@struct.Name} does not have a field with the name {field}").Build());
throw new BindException(Diagnostic.Error($"Struct {structType} does not have a field with the name {field}").Build());
}
if (fields.Length > 1)
{
throw new BindException(Diagnostic.Error($"Struct {@struct.Namespace}::{@struct.Name} has multiple fields with the name {field}").Build());
throw new BindException(Diagnostic.Error($"Struct {structType} has multiple fields with the name {field}").Build());
}
initializers[field] = BindExpression(initializer, fields[0].Type);
}
return new BoundStructInitializer(expression.Tokens, structType, new NubCustomType(@struct.Namespace, @struct.Name), initializers);
return new BoundStructInitializer(expression.Tokens, structType, initializers);
}
private BoundUnaryExpression BindUnaryExpression(UnaryExpressionSyntax expression)