Remove mangledName

This commit is contained in:
nub31
2025-07-24 19:01:14 +02:00
parent ddc5228fbe
commit 1f46809c3c
2 changed files with 2 additions and 21 deletions

View File

@@ -2,26 +2,7 @@ using NubLang.Tokenization;
namespace NubLang.Parsing.Syntax; namespace NubLang.Parsing.Syntax;
public abstract record TypeSyntax(IEnumerable<Token> Tokens) : SyntaxNode(Tokens) public abstract record TypeSyntax(IEnumerable<Token> Tokens) : SyntaxNode(Tokens);
{
public string MangledName()
{
return this switch
{
VoidTypeSyntax => "void",
CStringTypeSyntax => "cstring",
StringTypeSyntax => "string",
PointerTypeSyntax ptr => $"ptr_{ptr.BaseType.MangledName()}",
ArrayTypeSyntax arr => $"arr_{arr.BaseType.MangledName()}",
BoolTypeSyntax => "bool",
CustomTypeSyntax custom => $"custom_{custom.Name}",
FloatTypeSyntax @float => $"f{@float.Width}",
FuncTypeSyntax func => $"func_{string.Join("_", func.Parameters.Select(x => x.MangledName()))}_to_{func.ReturnType.MangledName()}",
IntTypeSyntax @int => $"{(@int.Signed ? "i" : "u")}{@int.Width}",
_ => throw new NotSupportedException($"Unknown type syntax: {GetType().Name}")
};
}
}
public record FuncTypeSyntax(IEnumerable<Token> Tokens, IReadOnlyList<TypeSyntax> Parameters, TypeSyntax ReturnType) : TypeSyntax(Tokens) public record FuncTypeSyntax(IEnumerable<Token> Tokens, IReadOnlyList<TypeSyntax> Parameters, TypeSyntax ReturnType) : TypeSyntax(Tokens)
{ {

View File

@@ -576,7 +576,7 @@ public sealed class TypeChecker
ArrayTypeSyntax type => new ArrayTypeNode(CheckType(type.BaseType)), ArrayTypeSyntax type => new ArrayTypeNode(CheckType(type.BaseType)),
BoolTypeSyntax => new BoolTypeNode(), BoolTypeSyntax => new BoolTypeNode(),
CStringTypeSyntax => new CStringTypeNode(), CStringTypeSyntax => new CStringTypeNode(),
CustomTypeSyntax type => new CustomTypeNode(type.MangledName()), CustomTypeSyntax type => new CustomTypeNode(type.Name),
FloatTypeSyntax @float => new FloatTypeNode(@float.Width), FloatTypeSyntax @float => new FloatTypeNode(@float.Width),
FuncTypeSyntax type => new FuncTypeNode(type.Parameters.Select(CheckType).ToList(), CheckType(type.ReturnType)), FuncTypeSyntax type => new FuncTypeNode(type.Parameters.Select(CheckType).ToList(), CheckType(type.ReturnType)),
IntTypeSyntax @int => new IntTypeNode(@int.Signed, @int.Width), IntTypeSyntax @int => new IntTypeNode(@int.Signed, @int.Width),