CastExpression
using CLanguage.Compiler;
using CLanguage.Types;
using System.Runtime.CompilerServices;
namespace CLanguage.Syntax
{
[System.Runtime.CompilerServices.NullableContext(1)]
[System.Runtime.CompilerServices.Nullable(0)]
public class CastExpression : Expression
{
public TypeName TypeName { get; }
public Expression InnerExpression { get; }
public CastExpression(TypeName typeName, Expression innerExpression)
{
TypeName = typeName;
InnerExpression = innerExpression;
}
public override CType GetEvaluatedCType(EmitContext ec)
{
return ec.ResolveTypeName(TypeName) ?? CBasicType.SignedInt;
}
protected override void DoEmit(EmitContext ec)
{
CType evaluatedCType = GetEvaluatedCType(ec);
CType evaluatedCType2 = InnerExpression.GetEvaluatedCType(ec);
InnerExpression.Emit(ec);
ec.EmitCast(evaluatedCType2, evaluatedCType);
}
}
}