Пример #1
0
        public override object VisitBinaryOperatorExpression(BinaryOperatorExpression binaryOperatorExpression, object data)
        {
            switch (binaryOperatorExpression.Op)
            {
            case BinaryOperatorType.NullCoalescing:
                return(binaryOperatorExpression.Right.AcceptVisitor(this, data));

            case BinaryOperatorType.DivideInteger:
                return(resolver.ProjectContent.SystemTypes.Int32);

            case BinaryOperatorType.Concat:
                return(resolver.ProjectContent.SystemTypes.String);

            case BinaryOperatorType.Equality:
            case BinaryOperatorType.InEquality:
            case BinaryOperatorType.ReferenceEquality:
            case BinaryOperatorType.ReferenceInequality:
            case BinaryOperatorType.LogicalAnd:
            case BinaryOperatorType.LogicalOr:
            case BinaryOperatorType.LessThan:
            case BinaryOperatorType.LessThanOrEqual:
            case BinaryOperatorType.GreaterThan:
            case BinaryOperatorType.GreaterThanOrEqual:
                return(resolver.ProjectContent.SystemTypes.Boolean);

            default:
                return(MemberLookupHelper.GetCommonType(resolver.ProjectContent,
                                                        binaryOperatorExpression.Left.AcceptVisitor(this, data) as IReturnType,
                                                        binaryOperatorExpression.Right.AcceptVisitor(this, data) as IReturnType));
            }
        }
Пример #2
0
        public override void OnArrayLiteralExpression(ArrayLiteralExpression node)
        {
            if (node.Type != null)
            {
                MakeResult(ConvertType(node.Type));
                return;
            }
            IReturnType elementType = null;

            foreach (Expression expr in node.Items)
            {
                ClearResult();
                expr.Accept(this);
                IReturnType thisType = (resolveResult != null) ? resolveResult.ResolvedType : null;
                if (elementType == null)
                {
                    elementType = thisType;
                }
                else if (thisType != null)
                {
                    elementType = MemberLookupHelper.GetCommonType(projectContent, elementType, thisType);
                }
            }
            if (elementType == null)
            {
                elementType = ConvertVisitor.GetDefaultReturnType(projectContent);
            }
            MakeResult(new ArrayReturnType(projectContent, elementType, 1));
        }
Пример #3
0
 public override object VisitConditionalExpression(ConditionalExpression conditionalExpression, object data)
 {
     return(CreateResolveResult(MemberLookupHelper.GetCommonType(
                                    resolver.ProjectContent,
                                    ResolveType(conditionalExpression.TrueExpression),
                                    ResolveType(conditionalExpression.FalseExpression))));
 }
Пример #4
0
        public void GetCommonTypeOfNullAndString()
        {
            IReturnType res = MemberLookupHelper.GetCommonType(msc,
                                                               NullReturnType.Instance,
                                                               msc.GetClass("System.String", 0).DefaultReturnType);

            Assert.AreEqual("System.String", res.FullyQualifiedName);
        }
Пример #5
0
        public void GetCommonType()
        {
            IReturnType res = MemberLookupHelper.GetCommonType(msc,
                                                               swf.GetClass("System.Windows.Forms.ToolStripButton", 0).DefaultReturnType,
                                                               swf.GetClass("System.Windows.Forms.ToolStripSeparator", 0).DefaultReturnType);

            Assert.AreEqual("System.Windows.Forms.ToolStripItem", res.FullyQualifiedName);
        }
Пример #6
0
        public override void OnBinaryExpression(BinaryExpression node)
        {
            switch (node.Operator)
            {
            case BinaryOperatorType.GreaterThan:
            case BinaryOperatorType.GreaterThanOrEqual:
            case BinaryOperatorType.Equality:
            case BinaryOperatorType.Inequality:
            case BinaryOperatorType.LessThan:
            case BinaryOperatorType.LessThanOrEqual:
            case BinaryOperatorType.Match:
            case BinaryOperatorType.Member:
            case BinaryOperatorType.NotMatch:
            case BinaryOperatorType.NotMember:
            case BinaryOperatorType.ReferenceEquality:
            case BinaryOperatorType.ReferenceInequality:
            case BinaryOperatorType.TypeTest:
                MakeResult(projectContent.SystemTypes.Boolean);
                break;

            default:
                if (node.Left == null)
                {
                    if (node.Right == null)
                    {
                        ClearResult();
                    }
                    else
                    {
                        node.Right.Accept(this);
                    }
                    return;
                }
                else if (node.Right == null)
                {
                    node.Left.Accept(this);
                    return;
                }
                node.Left.Accept(this);
                IReturnType left = (resolveResult != null) ? resolveResult.ResolvedType : null;
                node.Right.Accept(this);
                IReturnType right = (resolveResult != null) ? resolveResult.ResolvedType : null;
                MakeResult(MemberLookupHelper.GetCommonType(projectContent, left, right));
                break;
            }
        }
Пример #7
0
        public override IReturnType ResolveReturnType()
        {
            MemberLookupHelper.Log("LambdaReturnType: ResolveReturnType");
            IReturnType result;

            if (returnExpressions.Count == 0)
            {
                result = resolver.ProjectContent.SystemTypes.Void;
            }
            else
            {
                result = returnExpressions.Select(rt => resolver.ResolveInternal(rt, ExpressionContext.Default))
                         .Select(rr => rr != null ? rr.ResolvedType : null)
                         .Aggregate((rt1, rt2) => MemberLookupHelper.GetCommonType(resolver.ProjectContent, rt1, rt2));
            }
            MemberLookupHelper.Log("LambdaReturnType: inferred " + result);
            return(result);
        }
Пример #8
0
        public override object VisitCollectionInitializerExpression(CollectionInitializerExpression collectionInitializerExpression, object data)
        {
            // used for implicitly typed arrays
            if (collectionInitializerExpression.CreateExpressions.Count == 0)
            {
                return(null);
            }
            IReturnType combinedRT = ResolveType(collectionInitializerExpression.CreateExpressions[0]);

            for (int i = 1; i < collectionInitializerExpression.CreateExpressions.Count; i++)
            {
                IReturnType rt = ResolveType(collectionInitializerExpression.CreateExpressions[i]);
                combinedRT = MemberLookupHelper.GetCommonType(resolver.ProjectContent, combinedRT, rt);
            }
            if (combinedRT == null)
            {
                return(null);
            }
            return(CreateResolveResult(new ArrayReturnType(resolver.ProjectContent, combinedRT, 1)));
        }