private static void FoldExpression_Binary_BoolBool_Arithmetic( ref ES_AstExpression expr, SimpleBinaryExprType op, ES_AstBooleanConstantExpression lhs, ES_AstBooleanConstantExpression rhs ) { Debug.Assert(!op.IsComparison() && !op.IsBitShift()); bool finalValue; switch (op) { // Bit ops case SimpleBinaryExprType.BitAnd: finalValue = lhs.Value & rhs.Value; break; case SimpleBinaryExprType.BitOr: finalValue = lhs.Value | rhs.Value; break; case SimpleBinaryExprType.BitXor: finalValue = lhs.Value ^ rhs.Value; break; default: return; } expr = new ES_AstBooleanConstantExpression(finalValue, expr); }
private static void FoldExpression_Binary_BoolBool_Comp( ref ES_AstExpression expr, SimpleBinaryExprType op, ES_AstBooleanConstantExpression lhs, ES_AstBooleanConstantExpression rhs ) { Debug.Assert(op.IsComparison()); bool finalValue; switch (op) { case SimpleBinaryExprType.Equals: finalValue = lhs.Value == rhs.Value; break; case SimpleBinaryExprType.NotEquals: finalValue = lhs.Value != rhs.Value; break; default: return; } expr = new ES_AstBooleanConstantExpression(finalValue, expr); }
public static ExpressionData NewFunction(ES_AstExpression expr, ES_FunctionData *func, ES_TypeInfo *funcType) { return(new ExpressionData { Expr = expr, Function = func, TypeInfo = funcType, Type = null }); }
public static ExpressionData NewType(ES_AstExpression expr, ES_TypeInfo *typeInfo) { return(new ExpressionData { Expr = expr, TypeInfo = typeInfo, Type = null, Function = null }); }
private static bool FoldConstants_EnsureCompat(ES_TypeInfo *dstType, ref ES_AstExpression expr) { if (dstType is null) { return(false); } switch (expr) { case ES_AstFloat32ConstantExpression exprFlt64: { if (dstType->TypeTag != ES_TypeTag.Float) { return(false); } var dstTypeFlt = (ES_FloatTypeData *)dstType; if (dstTypeFlt->FloatSize < ES_FloatSize.Single) { return(false); } switch (dstTypeFlt->FloatSize) { case ES_FloatSize.Single: return(true); case ES_FloatSize.Double: expr = new ES_AstFloat64ConstantExpression(exprFlt64.Value, expr); return(true); default: throw new NotImplementedException("Size not implemented."); } } case ES_AstFloat64ConstantExpression exprFlt64: { if (dstType->TypeTag != ES_TypeTag.Float) { return(false); } var dstTypeFlt = (ES_FloatTypeData *)dstType; if (dstTypeFlt->FloatSize < ES_FloatSize.Double) { return(false); } return(dstTypeFlt->FloatSize switch { ES_FloatSize.Double => true, _ => throw new NotImplementedException("Size not implemented."), }); }