...
This commit is contained in:
@@ -1,10 +1,10 @@
|
||||
namespace Compiler;
|
||||
|
||||
public sealed class TypeChecker(string fileName, List<NodeDefinition> definitions)
|
||||
public sealed class TypeChecker(string fileName, Ast ast)
|
||||
{
|
||||
public static TypedAst Check(string fileName, List<NodeDefinition> nodes, out List<Diagnostic> diagnostics)
|
||||
public static TypedAst Check(string fileName, Ast ast, out List<Diagnostic> diagnostics)
|
||||
{
|
||||
return new TypeChecker(fileName, nodes).Check(out diagnostics);
|
||||
return new TypeChecker(fileName, ast).Check(out diagnostics);
|
||||
}
|
||||
|
||||
private Scope scope = new(null);
|
||||
@@ -16,19 +16,19 @@ public sealed class TypeChecker(string fileName, List<NodeDefinition> definition
|
||||
diagnostics = [];
|
||||
|
||||
// todo(nub31): Types must be resolved better to prevent circular dependencies and independent ordering
|
||||
foreach (var structDef in definitions.OfType<NodeDefinitionStruct>())
|
||||
foreach (var structDef in ast.Structs)
|
||||
{
|
||||
var fields = structDef.Fields.Select(x => new NubTypeStruct.Field(x.Name.Ident, CheckType(x.Type))).ToList();
|
||||
structTypes.Add(structDef.Name.Ident, new NubTypeStruct(fields));
|
||||
}
|
||||
|
||||
foreach (var funcDef in definitions.OfType<NodeDefinitionFunc>())
|
||||
foreach (var funcDef in ast.Functions)
|
||||
{
|
||||
var type = new NubTypeFunc(funcDef.Parameters.Select(x => CheckType(x.Type)).ToList(), CheckType(funcDef.ReturnType));
|
||||
scope.DeclareIdentifier(funcDef.Name.Ident, type);
|
||||
}
|
||||
|
||||
foreach (var funcDef in definitions.OfType<NodeDefinitionFunc>())
|
||||
foreach (var funcDef in ast.Functions)
|
||||
{
|
||||
try
|
||||
{
|
||||
@@ -40,7 +40,7 @@ public sealed class TypeChecker(string fileName, List<NodeDefinition> definition
|
||||
}
|
||||
}
|
||||
|
||||
return new TypedAst(functions, structTypes.Values.ToList());
|
||||
return new TypedAst(structTypes.Values.ToList(), functions);
|
||||
}
|
||||
|
||||
private TypedNodeDefinitionFunc CheckDefinitionFunc(NodeDefinitionFunc definition)
|
||||
@@ -363,10 +363,10 @@ public sealed class TypeChecker(string fileName, List<NodeDefinition> definition
|
||||
}
|
||||
}
|
||||
|
||||
public sealed class TypedAst(List<TypedNodeDefinitionFunc> functions, List<NubTypeStruct> structTypes)
|
||||
public sealed class TypedAst(List<NubTypeStruct> structTypes, List<TypedNodeDefinitionFunc> functions)
|
||||
{
|
||||
public List<TypedNodeDefinitionFunc> Functions = functions;
|
||||
public List<NubTypeStruct> StructTypes = structTypes;
|
||||
public readonly List<NubTypeStruct> StructTypes = structTypes;
|
||||
public readonly List<TypedNodeDefinitionFunc> Functions = functions;
|
||||
}
|
||||
|
||||
public abstract class TypedNode(List<Token> tokens)
|
||||
|
||||
Reference in New Issue
Block a user