remove refs
This commit is contained in:
@@ -605,16 +605,6 @@ public class DereferenceNode(List<Token> tokens, NubType type, ExpressionNode ta
|
||||
}
|
||||
}
|
||||
|
||||
public class RefDereferenceNode(List<Token> tokens, NubType type, ExpressionNode target) : LValueExpressionNode(tokens, type)
|
||||
{
|
||||
public ExpressionNode Target { get; } = target;
|
||||
|
||||
public override IEnumerable<Node> Children()
|
||||
{
|
||||
yield return Target;
|
||||
}
|
||||
}
|
||||
|
||||
public class SizeNode(List<Token> tokens, NubType TargetType) : RValueExpressionNode(tokens, new NubIntType(false, 64))
|
||||
{
|
||||
public NubType TargetType { get; } = TargetType;
|
||||
@@ -635,19 +625,6 @@ public class CastNode(List<Token> tokens, NubType type, ExpressionNode value) :
|
||||
}
|
||||
}
|
||||
|
||||
public class RefStructInitializerNode(List<Token> tokens, NubType type, Dictionary<IdentifierToken, ExpressionNode> initializers) : RValueExpressionNode(tokens, type)
|
||||
{
|
||||
public Dictionary<IdentifierToken, ExpressionNode> Initializers { get; } = initializers;
|
||||
|
||||
public override IEnumerable<Node> Children()
|
||||
{
|
||||
foreach (var initializer in Initializers)
|
||||
{
|
||||
yield return initializer.Value;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public class EnumReferenceIntermediateNode(List<Token> tokens, IdentifierToken moduleToken, IdentifierToken nameToken) : IntermediateExpression(tokens)
|
||||
{
|
||||
public IdentifierToken ModuleToken { get; } = moduleToken;
|
||||
|
||||
@@ -57,15 +57,6 @@ public sealed class NubPointerType(NubType baseType) : NubType
|
||||
public override int GetHashCode() => HashCode.Combine(typeof(NubPointerType), BaseType);
|
||||
}
|
||||
|
||||
public class NubRefType(NubType baseType) : NubType
|
||||
{
|
||||
public NubType BaseType { get; } = baseType;
|
||||
|
||||
public override string ToString() => "&" + BaseType;
|
||||
public override bool Equals(NubType? other) => other is NubRefType;
|
||||
public override int GetHashCode() => HashCode.Combine(typeof(NubRefType));
|
||||
}
|
||||
|
||||
public class NubFuncType(List<NubType> parameters, NubType returnType) : NubType
|
||||
{
|
||||
public List<NubType> Parameters { get; } = parameters;
|
||||
|
||||
@@ -796,16 +796,18 @@ public sealed class TypeChecker
|
||||
}
|
||||
}
|
||||
|
||||
private ExpressionNode CheckDereference(DereferenceSyntax expression, NubType? _)
|
||||
private DereferenceNode CheckDereference(DereferenceSyntax expression, NubType? _)
|
||||
{
|
||||
var target = CheckExpression(expression.Target);
|
||||
|
||||
return target.Type switch
|
||||
if (target.Type is not NubPointerType pointerType)
|
||||
{
|
||||
NubPointerType pointerType => new DereferenceNode(expression.Tokens, pointerType.BaseType, target),
|
||||
NubRefType refType => new RefDereferenceNode(expression.Tokens, refType.BaseType, target),
|
||||
_ => throw new CompileException(Diagnostic.Error($"Cannot dereference non-pointer type {target.Type}").At(expression).Build())
|
||||
};
|
||||
throw new CompileException(Diagnostic
|
||||
.Error($"Cannot dereference non-pointer type {target.Type}")
|
||||
.At(expression)
|
||||
.Build());
|
||||
}
|
||||
|
||||
return new DereferenceNode(expression.Tokens, pointerType.BaseType, target);
|
||||
}
|
||||
|
||||
private FuncCallNode CheckFuncCall(FuncCallSyntax expression, NubType? _)
|
||||
@@ -1090,7 +1092,7 @@ public sealed class TypeChecker
|
||||
throw new UnreachableException();
|
||||
}
|
||||
|
||||
private ExpressionNode CheckStructInitializer(StructInitializerSyntax expression, NubType? expectedType)
|
||||
private StructInitializerNode CheckStructInitializer(StructInitializerSyntax expression, NubType? expectedType)
|
||||
{
|
||||
NubStructType? structType = null;
|
||||
|
||||
@@ -1104,14 +1106,10 @@ public sealed class TypeChecker
|
||||
|
||||
structType = checkedStructType;
|
||||
}
|
||||
else
|
||||
|
||||
if (expectedType is NubStructType expectedStructType)
|
||||
{
|
||||
structType = expectedType switch
|
||||
{
|
||||
NubStructType expectedStructType => expectedStructType,
|
||||
NubRefType { BaseType: NubStructType expectedStructType } => expectedStructType,
|
||||
_ => structType
|
||||
};
|
||||
structType ??= expectedStructType;
|
||||
}
|
||||
|
||||
if (structType == null)
|
||||
@@ -1154,14 +1152,7 @@ public sealed class TypeChecker
|
||||
.Build());
|
||||
}
|
||||
|
||||
if (expectedType is NubRefType refType && refType.BaseType == structType)
|
||||
{
|
||||
return new RefStructInitializerNode(expression.Tokens, refType, initializers);
|
||||
}
|
||||
else
|
||||
{
|
||||
return new StructInitializerNode(expression.Tokens, structType, initializers);
|
||||
}
|
||||
return new StructInitializerNode(expression.Tokens, structType, initializers);
|
||||
}
|
||||
|
||||
private BlockNode CheckBlock(BlockSyntax node)
|
||||
|
||||
@@ -26,7 +26,6 @@ public class TypeResolver
|
||||
SliceTypeSyntax slice => new NubSliceType(ResolveType(slice.BaseType, currentModule)),
|
||||
ConstArrayTypeSyntax arr => new NubConstArrayType(ResolveType(arr.BaseType, currentModule), arr.Size),
|
||||
PointerTypeSyntax ptr => new NubPointerType(ResolveType(ptr.BaseType, currentModule)),
|
||||
RefTypeSyntax r => new NubRefType(ResolveType(r.BaseType, currentModule)),
|
||||
StringTypeSyntax => new NubStringType(),
|
||||
CustomTypeSyntax c => ResolveCustomType(c, currentModule),
|
||||
VoidTypeSyntax => new NubVoidType(),
|
||||
|
||||
Reference in New Issue
Block a user