public override ExprNode Validate(ExprValidationContext validationContext) { if (ChildNodes.Length != 2) { throw new ExprValidationException("BitWise node must have 2 parameters"); } var typeOne = ChildNodes[0].Forge.EvaluationType.GetBoxedType(); var typeTwo = ChildNodes[1].Forge.EvaluationType.GetBoxedType(); CheckNumericOrBoolean(typeOne); CheckNumericOrBoolean(typeTwo); if (typeOne.IsFloatingPointClass() || typeTwo.IsFloatingPointClass()) { throw new ExprValidationException( "Invalid type for bitwise " + BitWiseOpEnum.ComputeDescription + " operator"); } if (typeOne != typeTwo) { throw new ExprValidationException( "Bitwise expressions must be of the same type for bitwise " + BitWiseOpEnum.ComputeDescription + " operator"); } var computer = BitWiseOpEnum.GetComputer(typeOne); _forge = new ExprBitWiseNodeForge(this, typeOne, computer); return null; }
internal ExprBitWiseNodeForgeEval( ExprBitWiseNodeForge forge, ExprEvaluator lhs, ExprEvaluator rhs) { this.forge = forge; this.lhs = lhs; this.rhs = rhs; }
public static CodegenExpression Codegen( ExprBitWiseNodeForge forge, Type requiredType, CodegenMethodScope codegenMethodScope, ExprForgeCodegenSymbol exprSymbol, CodegenClassScope codegenClassScope, ExprNode lhs, ExprNode rhs) { var methodNode = codegenMethodScope.MakeChild( forge.EvaluationType, typeof(ExprBitWiseNodeForgeEval), codegenClassScope); var leftType = lhs.Forge.EvaluationType; var rightType = rhs.Forge.EvaluationType; var block = methodNode.Block .DeclareVar( leftType, "left", lhs.Forge.EvaluateCodegen(leftType, methodNode, exprSymbol, codegenClassScope)) .DeclareVar( rightType, "right", rhs.Forge.EvaluateCodegen(rightType, methodNode, exprSymbol, codegenClassScope)); if (leftType.CanBeNull()) { block.IfRefNullReturnNull("left"); } if (rhs.Forge.EvaluationType.CanBeNull()) { block.IfRefNullReturnNull("right"); } var primitive = forge.EvaluationType.GetPrimitiveType(); block .DeclareVar(primitive, "l", Unbox(Ref("left"), leftType)) .DeclareVar(primitive, "r", Unbox(Ref("right"), rightType)); block.MethodReturn( Cast(primitive, Op(Ref("l"), forge.ForgeRenderable.BitWiseOpEnum.ExpressionText, Ref("r")))); return LocalMethod(methodNode); }