remove generics for now
This commit is contained in:
@@ -1,77 +0,0 @@
|
||||
using NubLang.Syntax.Parsing.Node;
|
||||
|
||||
namespace NubLang.Syntax.Generics;
|
||||
|
||||
public class GenericInstantiator
|
||||
{
|
||||
private readonly IEnumerable<SyntaxTree> _syntaxTrees;
|
||||
private readonly Queue<GenericStructQueue> _structQueue = [];
|
||||
|
||||
public GenericInstantiator(IEnumerable<SyntaxTree> syntaxTrees)
|
||||
{
|
||||
_syntaxTrees = syntaxTrees;
|
||||
}
|
||||
|
||||
public IEnumerable<SyntaxTree> Visit()
|
||||
{
|
||||
_structQueue.Clear();
|
||||
|
||||
var syntaxTrees = new List<SyntaxTree>();
|
||||
|
||||
foreach (var syntaxTree in _syntaxTrees)
|
||||
{
|
||||
var definitions = new List<DefinitionSyntax>();
|
||||
foreach (var definition in syntaxTree.Definitions)
|
||||
{
|
||||
if (definition.Parameters.Any())
|
||||
{
|
||||
switch (definition)
|
||||
{
|
||||
case StructSyntax structSyntax:
|
||||
{
|
||||
var usages = _syntaxTrees
|
||||
.SelectMany(x => x.GetDescendants())
|
||||
.OfType<CustomTypeSyntax>()
|
||||
.Where(x => x.Namespace == structSyntax.Namespace)
|
||||
.Where(x => x.Name == structSyntax.Name);
|
||||
|
||||
foreach (var usage in usages)
|
||||
{
|
||||
if (!_structQueue.Any(x => x.Type.Namespace == usage.Namespace && x.Type.Name == usage.Name))
|
||||
{
|
||||
_structQueue.Enqueue(new GenericStructQueue(structSyntax, usage, false));
|
||||
}
|
||||
}
|
||||
|
||||
break;
|
||||
}
|
||||
default:
|
||||
{
|
||||
throw new ArgumentOutOfRangeException(nameof(definition));
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
definitions.Add(definition);
|
||||
}
|
||||
}
|
||||
|
||||
while (_structQueue.TryDequeue(out var item))
|
||||
{
|
||||
definitions.Add(new StructSyntax(item.Type.Tokens, item.Struct.Namespace, [], item.Type.MangledName(), item.Struct.Fields, item.Struct.Functions));
|
||||
}
|
||||
|
||||
syntaxTrees.Add(new SyntaxTree(syntaxTree.Tokens, syntaxTree.Namespace, definitions, syntaxTree.Diagnostics));
|
||||
}
|
||||
|
||||
return syntaxTrees;
|
||||
}
|
||||
}
|
||||
|
||||
public class GenericStructQueue(StructSyntax @struct, CustomTypeSyntax type, bool created)
|
||||
{
|
||||
public StructSyntax Struct { get; init; } = @struct;
|
||||
public CustomTypeSyntax Type { get; init; } = type;
|
||||
public bool Created { get; set; } = created;
|
||||
}
|
||||
Reference in New Issue
Block a user