Beispiel #1
0
        public Expression VisitBinaryExpression(BinaryExpression binExp)
        {
            Expression   left    = binExp.Left;
            Expression   right   = binExp.Right;
            TypeVariable tvLeft  = left.TypeVariable;
            TypeVariable tvRight = right.TypeVariable;

            if (!tvLeft.DataType.IsComplex)
            {
                if (!tvRight.DataType.IsComplex)
                {
                    throw new NotImplementedException(string.Format("Neither subexpression is complex in {0}: [[{1}]] and [[{2}]]",
                                                                    binExp,
                                                                    tvLeft.DataType,
                                                                    tvRight.DataType));
                }
                return(VisitBinaryExpression(binExp.Commute()));
            }
            else if (tvRight.DataType.IsComplex)
            {
                throw new TypeInferenceException("Both subexpressions are complex in {0}. Left type: {1}, right type {2}",
                                                 binExp, tvLeft.DataType, tvRight.DataType);
            }

            var ter = new TypedExpressionRewriter(prog);
            ComplexExpressionBuilder ceb;
            Constant cLeft = left as Constant;

            if (cLeft != null)
            {
                binExp.Right = binExp.Right.Accept(ter);
                if (basePointer == null)
                {
                    basePointer = globals;
                }
                ceb = new ComplexExpressionBuilder(
                    dtResult,
                    basePointer.TypeVariable.DataType,
                    basePointer.TypeVariable.OriginalDataType,
                    null,
                    basePointer,
                    binExp.Right,
                    StructureField.ToOffset(cLeft));
            }
            else
            {
                var binLeft  = binExp.Left.Accept(ter);
                var binRight = binExp.Right.Accept(ter);
                var cRight   = binRight as Constant;
                ceb = new ComplexExpressionBuilder(
                    binExp.DataType,
                    tvLeft.DataType,
                    tvLeft.OriginalDataType,
                    basePointer,
                    binLeft,
                    cRight != null ? null : binRight,
                    StructureField.ToOffset(binRight as Constant));
            }
            ceb.Dereferenced = true;
            return(ceb.BuildComplex());
        }