tmp...
This commit is contained in:
@@ -244,7 +244,7 @@ public class TypeChecker
|
||||
}
|
||||
|
||||
if (uncoveredCases.Any())
|
||||
throw BasicError($"Match statement does not cover the following cases: {string.Join(", ", uncoveredCases)}", statement);
|
||||
throw BasicError($"Match statement does not cover the following cases: {string.Join(", ", uncoveredCases)}", statement);
|
||||
|
||||
return new TypedNodeStatementMatch(statement.Tokens, target, cases);
|
||||
}
|
||||
@@ -470,42 +470,54 @@ public class TypeChecker
|
||||
switch (target.Type)
|
||||
{
|
||||
case NubTypeString stringType:
|
||||
{
|
||||
switch (expression.Name.Ident)
|
||||
{
|
||||
case "length":
|
||||
return new TypedNodeExpressionStringLength(expression.Tokens, NubTypeUInt.Get(64), target);
|
||||
case "ptr":
|
||||
return new TypedNodeExpressionStringPointer(expression.Tokens, NubTypePointer.Get(NubTypeUInt.Get(8)), target);
|
||||
default:
|
||||
throw BasicError($"'{expression.Name.Ident}' is not a member of type string", expression.Name);
|
||||
switch (expression.Name.Ident)
|
||||
{
|
||||
case "length":
|
||||
return new TypedNodeExpressionStringLength(expression.Tokens, NubTypeUInt.Get(64), target);
|
||||
case "ptr":
|
||||
return new TypedNodeExpressionStringPointer(expression.Tokens, NubTypePointer.Get(NubTypeUInt.Get(8)), target);
|
||||
default:
|
||||
throw BasicError($"'{expression.Name.Ident}' is not a member of type {stringType}", expression.Name);
|
||||
}
|
||||
}
|
||||
case NubTypeArray arrayType:
|
||||
{
|
||||
switch (expression.Name.Ident)
|
||||
{
|
||||
case "count":
|
||||
return new TypedNodeExpressionArrayCount(expression.Tokens, NubTypeUInt.Get(64), target);
|
||||
case "ptr":
|
||||
return new TypedNodeExpressionArrayPointer(expression.Tokens, NubTypePointer.Get(arrayType.ElementType), target);
|
||||
default:
|
||||
throw BasicError($"'{expression.Name.Ident}' is not a member of type {arrayType}", expression.Name);
|
||||
}
|
||||
}
|
||||
}
|
||||
case NubTypeStruct structType:
|
||||
{
|
||||
if (!moduleGraph.TryResolveModule(structType.Module, out var module))
|
||||
throw BasicError($"Module '{structType.Module}' not found", expression.Target);
|
||||
{
|
||||
if (!moduleGraph.TryResolveModule(structType.Module, out var module))
|
||||
throw BasicError($"Module '{structType.Module}' not found", expression.Target);
|
||||
|
||||
if (!module.TryResolveType(structType.Name, currentModule == structType.Module, out var typeDef))
|
||||
throw BasicError($"Type '{structType.Name}' not found in module '{structType.Module}'", expression.Target);
|
||||
if (!module.TryResolveType(structType.Name, currentModule == structType.Module, out var typeDef))
|
||||
throw BasicError($"Type '{structType.Name}' not found in module '{structType.Module}'", expression.Target);
|
||||
|
||||
if (typeDef is not Module.TypeInfoStruct structDef)
|
||||
throw BasicError($"Type '{target.Type}' is not a struct", expression.Target);
|
||||
if (typeDef is not Module.TypeInfoStruct structDef)
|
||||
throw BasicError($"Type '{target.Type}' is not a struct", expression.Target);
|
||||
|
||||
var field = structDef.Fields.FirstOrDefault(x => x.Name == expression.Name.Ident);
|
||||
if (field == null)
|
||||
throw BasicError($"Struct '{target.Type}' does not have a field matching the name '{expression.Name.Ident}'", target);
|
||||
var field = structDef.Fields.FirstOrDefault(x => x.Name == expression.Name.Ident);
|
||||
if (field == null)
|
||||
throw BasicError($"Struct '{target.Type}' does not have a field matching the name '{expression.Name.Ident}'", target);
|
||||
|
||||
return new TypedNodeExpressionStructMemberAccess(expression.Tokens, field.Type, target, expression.Name);
|
||||
}
|
||||
return new TypedNodeExpressionStructMemberAccess(expression.Tokens, field.Type, target, expression.Name);
|
||||
}
|
||||
case NubTypeAnonymousStruct anonymousStructType:
|
||||
{
|
||||
var field = anonymousStructType.Fields.FirstOrDefault(x => x.Name == expression.Name.Ident);
|
||||
if (field == null)
|
||||
throw BasicError($"Struct '{target.Type}' does not have a field matching the name '{expression.Name.Ident}'", target);
|
||||
{
|
||||
var field = anonymousStructType.Fields.FirstOrDefault(x => x.Name == expression.Name.Ident);
|
||||
if (field == null)
|
||||
throw BasicError($"Struct '{target.Type}' does not have a field matching the name '{expression.Name.Ident}'", target);
|
||||
|
||||
return new TypedNodeExpressionStructMemberAccess(expression.Tokens, field.Type, target, expression.Name);
|
||||
}
|
||||
return new TypedNodeExpressionStructMemberAccess(expression.Tokens, field.Type, target, expression.Name);
|
||||
}
|
||||
default:
|
||||
throw BasicError($"{target.Type} has no member '{expression.Name.Ident}'", target);
|
||||
}
|
||||
@@ -676,6 +688,7 @@ public class TypeChecker
|
||||
NodeTypeUInt type => NubTypeUInt.Get(type.Width),
|
||||
NodeTypeString => NubTypeString.Instance,
|
||||
NodeTypeVoid => NubTypeVoid.Instance,
|
||||
NodeTypeArray type => NubTypeArray.Get(ResolveType(type.ElementType)),
|
||||
_ => throw new ArgumentOutOfRangeException(nameof(node))
|
||||
};
|
||||
}
|
||||
@@ -965,6 +978,16 @@ public class TypedNodeExpressionStringPointer(List<Token> tokens, NubType type,
|
||||
public TypedNodeExpression Target { get; } = target;
|
||||
}
|
||||
|
||||
public class TypedNodeExpressionArrayCount(List<Token> tokens, NubType type, TypedNodeExpression target) : TypedNodeExpression(tokens, type)
|
||||
{
|
||||
public TypedNodeExpression Target { get; } = target;
|
||||
}
|
||||
|
||||
public class TypedNodeExpressionArrayPointer(List<Token> tokens, NubType type, TypedNodeExpression target) : TypedNodeExpression(tokens, type)
|
||||
{
|
||||
public TypedNodeExpression Target { get; } = target;
|
||||
}
|
||||
|
||||
public class TypedNodeExpressionFuncCall(List<Token> tokens, NubType type, TypedNodeExpression target, List<TypedNodeExpression> parameters) : TypedNodeExpression(tokens, type)
|
||||
{
|
||||
public TypedNodeExpression Target { get; } = target;
|
||||
|
||||
Reference in New Issue
Block a user