This commit is contained in:
nub31
2025-09-11 22:03:30 +02:00
parent 2af3782e32
commit 9c2975d45f
6 changed files with 42 additions and 21 deletions

View File

@@ -21,8 +21,6 @@ public class ModuleSignature
foreach (var def in syntaxTree.Definitions)
{
// if (!def.Exported) continue;
switch (def)
{
case FuncSyntax funcDef:
@@ -31,7 +29,7 @@ public class ModuleSignature
var returnType = TypeResolver.ResolveType(funcDef.Signature.ReturnType, modules);
var type = new FuncTypeNode(parameters, returnType, funcDef.ExternSymbol);
module._functions.Add(funcDef.Name, type);
module._functions.Add(funcDef.Name, new ModuleMember<FuncTypeNode>(type, def.Exported));
break;
}
case InterfaceSyntax interfaceDef:
@@ -46,7 +44,7 @@ public class ModuleSignature
}
var type = new InterfaceTypeNode(moduleName, interfaceDef.Name, functions);
module._interfaces.Add(type);
module._interfaces.Add(new ModuleMember<InterfaceTypeNode>(type, def.Exported));
break;
}
case StructSyntax structDef:
@@ -83,7 +81,7 @@ public class ModuleSignature
}
var type = new StructTypeNode(moduleName, structDef.Name, fields, functions, interfaceImplementations);
module._structs.Add(type);
module._structs.Add(new ModuleMember<StructTypeNode>(type, def.Exported));
break;
}
default:
@@ -97,11 +95,27 @@ public class ModuleSignature
return modules;
}
private readonly List<StructTypeNode> _structs = [];
private readonly List<InterfaceTypeNode> _interfaces = [];
private readonly Dictionary<string, FuncTypeNode> _functions = [];
private class ModuleMember<T>
{
public ModuleMember(T value, bool exported)
{
Value = value;
Exported = exported;
}
public IReadOnlyList<StructTypeNode> StructTypes => _structs;
public IReadOnlyList<InterfaceTypeNode> InterfaceTypes => _interfaces;
public IReadOnlyDictionary<string, FuncTypeNode> Functions => _functions;
public T Value { get; set; }
public bool Exported { get; set; }
}
private readonly List<ModuleMember<StructTypeNode>> _structs = [];
private readonly List<ModuleMember<InterfaceTypeNode>> _interfaces = [];
private readonly Dictionary<string, ModuleMember<FuncTypeNode>> _functions = [];
public IReadOnlyList<StructTypeNode> ExportedStructTypes => _structs.Where(x => x.Exported).Select(x => x.Value).ToList();
public IReadOnlyList<InterfaceTypeNode> ExportedInterfaceTypes => _interfaces.Where(x => x.Exported).Select(x => x.Value).ToList();
public IReadOnlyDictionary<string, FuncTypeNode> ExportedFunctions => _functions.Where(x => x.Value.Exported).ToDictionary(x => x.Key, x => x.Value.Value);
public IReadOnlyList<StructTypeNode> AllStructTypes => _structs.Select(x => x.Value).ToList();
public IReadOnlyList<InterfaceTypeNode> AllInterfaceTypes => _interfaces.Select(x => x.Value).ToList();
public IReadOnlyDictionary<string, FuncTypeNode> AllFunctions => _functions.ToDictionary(x => x.Key, x => x.Value.Value);
}

View File

@@ -347,7 +347,7 @@ public sealed class TypeChecker
// Second, look in the current module for a function matching the identifier
var module = _moduleSignatures[_syntaxTree.Metadata.ModuleName];
if (module.Functions.TryGetValue(expression.Name, out var function))
if (module.AllFunctions.TryGetValue(expression.Name, out var function))
{
return new FuncIdentifierNode(function, _syntaxTree.Metadata.ModuleName, expression.Name);
}