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); }
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); }
public ArrayType(FuzzType elementType, int rank = 1) { if (rank < 1) { throw new ArgumentException("Invalid rank " + rank, nameof(rank)); } ElementType = elementType; Rank = rank; }
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); }
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); }
public RefType(FuzzType innerType) { Debug.Assert(!(innerType is RefType), "Cannot create ref to ref type"); InnerType = innerType; }
public bool IsConvertibleTo(FuzzType other) => Equals(other) || (this is PrimitiveType pt && other is PrimitiveType opt && pt.Info.IsIntegral && opt.Info.IsIntegral);