Exemplo n.º 1
0
        public override ResolveResult Resolve(CSharpResolver resolver)
        {
            ResolveResult lhs = left.Resolve(resolver);
            ResolveResult rhs = right.Resolve(resolver);

            return(resolver.ResolveBinaryOperator(operatorType, lhs, rhs));
        }
Exemplo n.º 2
0
        bool AreEqualConstants(ResolveResult c1, ResolveResult c2)
        {
            if (c1 == null || c2 == null || !c1.IsCompileTimeConstant || !c2.IsCompileTimeConstant)
            {
                return(false);
            }
            CSharpResolver r = new CSharpResolver(typeResolveContext);
            ResolveResult  c = r.ResolveBinaryOperator(BinaryOperatorType.Equality, c1, c2);

            return(c.IsCompileTimeConstant && (c.ConstantValue as bool?) == true);
        }
Exemplo n.º 3
0
        bool AreEqualConstants(ConstantResolveResult c1, ConstantResolveResult c2)
        {
            if (c1 == null || c2 == null)
            {
                return(false);
            }
            CSharpResolver r = new CSharpResolver(resolveVisitor.TypeResolveContext, resolveVisitor.CancellationToken);
            ResolveResult  c = r.ResolveBinaryOperator(BinaryOperatorType.Equality, c1, c2);

            return(c.IsCompileTimeConstant && (c.ConstantValue as bool?) == true);
        }
Exemplo n.º 4
0
        Value VisitConditionalOperator(OperatorResolveResult result, BinaryOperatorType bitwiseOperatorType)
        {
            Debug.Assert(result.Operands.Count == 2);
            var            lhs      = Convert(result.Operands[0]).GetPermanentReference(evalThread);
            CSharpResolver resolver = new CSharpResolver(debuggerTypeSystem);
            Value          condVal;

            if (bitwiseOperatorType == BinaryOperatorType.BitwiseAnd)
            {
                condVal = Convert(resolver.ResolveConditionFalse(lhs.ToResolveResult(context)));
            }
            else
            {
                condVal = Convert(resolver.ResolveCondition(lhs.ToResolveResult(context)));
            }
            if ((bool)condVal.PrimitiveValue)
            {
                return(lhs);
            }
            var rhs = Convert(result.Operands[1]);
            var val = resolver.ResolveBinaryOperator(bitwiseOperatorType, lhs.ToResolveResult(context), rhs.ToResolveResult(context));

            return(Convert(val));
        }
Exemplo n.º 5
0
		public override ResolveResult Resolve(CSharpResolver resolver)
		{
			ResolveResult lhs = left.Resolve(resolver);
			ResolveResult rhs = right.Resolve(resolver);
			return resolver.ResolveBinaryOperator(operatorType, lhs, rhs);
		}
Exemplo n.º 6
0
        Value VisitBinaryOperator(OperatorResolveResult result, BinaryOperatorType operatorType, bool checkForOverflow = false)
        {
            Debug.Assert(result.Operands.Count == 2);
            Debug.Assert(operatorType != BinaryOperatorType.ConditionalAnd && operatorType != BinaryOperatorType.ConditionalOr && operatorType != BinaryOperatorType.NullCoalescing);
            var lhs = Convert(result.Operands[0]).GetPermanentReference(evalThread);
            var rhs = Convert(result.Operands[1]).GetPermanentReference(evalThread);

            if (result.UserDefinedOperatorMethod != null)
            {
                return(InvokeMethod(null, result.UserDefinedOperatorMethod, lhs, rhs));
            }
            var            lhsRR    = lhs.ToResolveResult(context);
            var            rhsRR    = rhs.ToResolveResult(context);
            CSharpResolver resolver = new CSharpResolver(debuggerTypeSystem).WithCheckForOverflow(checkForOverflow);
            var            val      = resolver.ResolveBinaryOperator(operatorType, lhsRR, rhsRR);

            if (val.IsCompileTimeConstant)
            {
                return(Convert(val));
            }
            switch (operatorType)
            {
            case BinaryOperatorType.Equality:
            case BinaryOperatorType.InEquality:
                bool equality = (operatorType == BinaryOperatorType.Equality);
                if (lhsRR.Type.IsKnownType(KnownTypeCode.String) && rhsRR.Type.IsKnownType(KnownTypeCode.String))
                {
                    if (lhs.IsNull || rhs.IsNull)
                    {
                        bool bothNull = lhs.IsNull && rhs.IsNull;
                        return(Eval.CreateValue(evalThread, equality ? bothNull : !bothNull));
                    }
                    else
                    {
                        bool equal = (string)lhs.PrimitiveValue == (string)rhs.PrimitiveValue;
                        return(Eval.CreateValue(evalThread, equality ? equal : !equal));
                    }
                }
                if (lhsRR.Type.IsReferenceType != false && rhsRR.Type.IsReferenceType != false)
                {
                    // Reference comparison
                    if (lhs.IsNull || rhs.IsNull)
                    {
                        bool bothNull = lhs.IsNull && rhs.IsNull;
                        return(Eval.CreateValue(evalThread, equality ? bothNull : !bothNull));
                    }
                    else
                    {
                        bool equal = lhs.Address == rhs.Address;
                        return(Eval.CreateValue(evalThread, equality ? equal : !equal));
                    }
                }
                goto default;

            case BinaryOperatorType.Add:
                if (lhsRR.Type.IsKnownType(KnownTypeCode.String) || rhsRR.Type.IsKnownType(KnownTypeCode.String))
                {
                    var method = debuggerTypeSystem.FindType(KnownTypeCode.String)
                                 .GetMethods(m => m.Name == "Concat" && m.Parameters.Count == 2)
                                 .Single(m => m.Parameters.All(p => p.Type.IsKnownType(KnownTypeCode.Object)));
                    return(InvokeMethod(null, method, lhs, rhs));
                }
                goto default;

            default:
                throw new GetValueException("Operator {0} is not supported for {1} and {2}!", operatorType, new CSharpAmbience().ConvertType(lhsRR.Type), new CSharpAmbience().ConvertType(rhsRR.Type));
            }
        }