예제 #1
0
        public ArrayTypeSyntax GenReferenceToArrayType()
        {
            if (_type != null)
            {
                return(_type);
            }

            List <int> ranks = new List <int> {
                Rank
            };
            // int[][] => ArrayType(ArrayType(Int, 1), 1)
            // int[][,] => ArrayType(ArrayType(Int, 2), 1)
            FuzzType innerElem = ElementType;

            while (innerElem is ArrayType at)
            {
                ranks.Add(at.Rank);
                innerElem = at.ElementType;
            }

            _type = ArrayType(
                innerElem.GenReferenceTo(),
                ranks.Select(
                    r =>
                    ArrayRankSpecifier(
                        SeparatedList(
                            Enumerable.Repeat((ExpressionSyntax)OmittedArraySizeExpression(), r)))).ToSyntaxList());

            return(_type);
        }
예제 #2
0
        public FuzzType PickExistingType()
        {
            int      num  = Random.Next(_primitiveTypes.Count + _aggTypes.Count);
            FuzzType type = num < _primitiveTypes.Count
                ? (FuzzType)_primitiveTypes[num]
                : _aggTypes[num - _primitiveTypes.Count];

            return(type);
        }
예제 #3
0
        public ArrayType(FuzzType elementType, int rank = 1)
        {
            if (rank < 1)
            {
                throw new ArgumentException("Invalid rank " + rank, nameof(rank));
            }

            ElementType = elementType;
            Rank        = rank;
        }
예제 #4
0
        public FuzzType PickType()
        {
            FuzzType type  = PickExistingType();
            int      count = Options.MakeArrayCountDist.Sample(Random.Rng);

            for (int i = 0; i < count; i++)
            {
                type = type.MakeArrayType(Options.ArrayRankDist.Sample(Random.Rng));
            }

            return(type);
        }
예제 #5
0
        public FuzzType PickType(double byRefProb = 0)
        {
            FuzzType type  = PickExistingType();
            int      count = Options.MakeArrayCountDist.Sample(Random.Rng);

            for (int i = 0; i < count; i++)
            {
                type = type.MakeArrayType(Options.ArrayRankDist.Sample(Random.Rng));
            }

            if (Random.FlipCoin(byRefProb))
            {
                type = new RefType(type);
            }

            return(type);
        }
예제 #6
0
 public RefType(FuzzType innerType)
 {
     Debug.Assert(!(innerType is RefType), "Cannot create ref to ref type");
     InnerType = innerType;
 }
예제 #7
0
파일: FuzzType.cs 프로젝트: sputier/Fuzzlyn
 public bool IsConvertibleTo(FuzzType other)
 => Equals(other) || (this is PrimitiveType pt && other is PrimitiveType opt && pt.Info.IsIntegral && opt.Info.IsIntegral);