Пример #1
0
        public static ExpressionNode Create(ContextNode context, BinaryOperatorNodeType op, ExpressionNode left, ExpressionNode right, SequencePoint point)
        {
            if (!left.IsGettable)
            {
                ErrorCode.NotAnRValue.ReportAndThrow(left.SequencePoint, "Binary operand is not gettable");
            }

            if (!right.IsGettable)
            {
                ErrorCode.NotAnRValue.ReportAndThrow(right.SequencePoint, "Binary operand is not gettable");
            }

            ExpressionNode ret = AsOverload(context, op, left, right, point);

            if (ret == null)
            {
                ret = AsBuiltIn(context, op, left, right, point);
            }

            if (ret == null)
            {
                OperatorMismatch(point, op, left.ExpressionReturnType, right.ExpressionReturnType);
            }

            Contract.Assume(ret != null);
            return(ret);
        }
Пример #2
0
        private static ExpressionNode AsBuiltIn(ContextNode context, BinaryOperatorNodeType op, ExpressionNode left, ExpressionNode right, SequencePoint point)
        {
            var instance = new BinaryOperatorNode(point);

            instance.left  = left;
            instance.right = right;
            instance.BinaryOperatorType = op;
            bool verified = false;

            switch (op)
            {
            case BinaryOperatorNodeType.Addition:
            case BinaryOperatorNodeType.Subtraction:
            case BinaryOperatorNodeType.Multiplication:
            case BinaryOperatorNodeType.Division:
            case BinaryOperatorNodeType.Modulus:
                verified = instance.VerifyArithmetic(context);
                break;

            case BinaryOperatorNodeType.GreaterThan:
            case BinaryOperatorNodeType.LessThan:
            case BinaryOperatorNodeType.GreaterEqualThan:
            case BinaryOperatorNodeType.LessEqualThan:
            case BinaryOperatorNodeType.Equals:
            case BinaryOperatorNodeType.NotEquals:
                verified = instance.VerifyComparison(context);
                break;

            case BinaryOperatorNodeType.ShiftLeft:
            case BinaryOperatorNodeType.ShiftRight:
                verified = instance.VerifyShift(context.Parser);
                break;

            case BinaryOperatorNodeType.LogicalAnd:
            case BinaryOperatorNodeType.LogicalOr:
                verified = instance.VerifyLogical(context.Parser);
                break;

            case BinaryOperatorNodeType.BinaryAnd:
            case BinaryOperatorNodeType.BinaryOr:
            case BinaryOperatorNodeType.BinaryXor:
                verified = instance.VerifyBinary();
                break;

            default:
                ErrorCode.InvalidStructure.ReportAndThrow(point, "Binary op expected, '{0} found", op);
                return(null);   //unreachable
            }
            return(verified ? instance : null);
        }
Пример #3
0
 private static void OperatorMismatch(SequencePoint point, BinaryOperatorNodeType op, TypeReference left, TypeReference right)
 {
     ErrorCode.TypeMismatch.ReportAndThrow(point,
                                           "Unable to perform {0} on operands {1} and {2}, no built int operation or operaror overload found",
                                           op, left.FullName, right.FullName);
 }
Пример #4
0
        private static ExpressionNode AsOverload(ContextNode context, BinaryOperatorNodeType op, ExpressionNode left, ExpressionNode right, SequencePoint point)
        {
            var name = Overloads[op];

            return(AsOverload(context, name, left, right, point));
        }