Ejemplo n.º 1
0
        public bool Equals(ArrayType other)
        {
            if (ReferenceEquals(null, other)) return false;
            if (ReferenceEquals(this, other)) return true;

            if ( !base.Equals(other) || !Equals(other.Type.ResolveType(), Type.ResolveType()) || other.Dimensions.Count != Dimensions.Count) return false;

            // Check that dimensions are all equals
            return !Dimensions.Where((t, i) => t != other.Dimensions[i]).Any();
        }
Ejemplo n.º 2
0
 public virtual void Visit(ArrayType arrayType)
 {
     VisitDynamic(arrayType.Type);
     WriteRankSpecifiers(arrayType.Dimensions);
 }
 /// <summary>
 /// Visits the specified type.
 /// </summary>
 /// <param name="type">the type.</param>
 public override void Visit(ArrayType type)
 {
     var dimensions = type.Dimensions;
     if (dimensions.Count != 1)
         throw new NotSupportedException();
     /*
     var expressionEvaluator = new ExpressionEvaluator();
     if (dimensions.All(x => !(x is EmptyExpression)))
     {
         var expressionResult = expressionEvaluator.Evaluate(dimensions[0]);
         if (expressionResult.HasErrors)
             throw new InvalidOperationException();
         Write(expressionResult.Value.ToString());
     }
     */
     VisitDynamic(type.Type);
     Write("[]");
     ProcessInitialValueStatus = true;
     IsArrayStatus = true;
 }
Ejemplo n.º 4
0
        protected virtual ArrayType Visit(ArrayType arrayType)
        {
            Visit((Node)arrayType);

            // Process only if there is non-literal expressions
            if (arrayType.TypeInference.TargetType == null
                && arrayType.Dimensions.Any(x => !(x is LiteralExpression || x is EmptyExpression)))
            {
                // Try to evaluate each dimension into a Literal expression (i.e. float4[3 * 2] should become float4[6])
                var evaluator = new ExpressionEvaluator();
                var results = arrayType.Dimensions.Select(evaluator.Evaluate).ToArray();

                if (results.Any(x => x.HasErrors))
                {
                    foreach (var result in results.Where(x => x.HasErrors))
                        result.CopyTo(ParsingResult);
                }
                else
                {
                    arrayType.TypeInference.TargetType = new ArrayType(arrayType.Type, results.Select(x => new LiteralExpression(Convert.ToInt32(x.Value))).ToArray());
                }
            }

            return arrayType;
        }
Ejemplo n.º 5
0
        /// <summary>
        /// Find the type of the expression
        /// </summary>
        /// <param name="indexerExpression">the indexer expression</param>
        protected virtual void ProcessIndexerExpression(IndexerExpression indexerExpression)
        {
            TypeBase type = null;
            var targetType = indexerExpression.Target.TypeInference.TargetType;

            if (targetType is ArrayType)
            {
                var arrayType = (ArrayType)targetType;
                if (arrayType.Dimensions.Count == 1)
                {
                    type = arrayType.Type.ResolveType();
                }
                else
                {
                    var dimensions = new List<Expression>(arrayType.Dimensions);
                    dimensions.RemoveAt(0);
                    type = new ArrayType(arrayType.Type, dimensions.ToArray());
                }
            }
            else if (targetType is VectorType)
            {
                type = ((VectorType)targetType).Type.ResolveType();
            }
            else if (targetType is MatrixType)
            {
                type = new VectorType((ScalarType)((MatrixType)targetType).Type.ResolveType(), ((MatrixType)targetType).ColumnCount);
            }
            else if (targetType is ClassType)
            {
                // This is for buffers<type>, especially in compute shaders
                // TODO: check all the cases
                var classType = (ClassType)targetType;
                if (classType.GenericArguments.Count > 0)
                    type = classType.GenericArguments[0];
            }

            indexerExpression.TypeInference.TargetType = type;
            if (type == null)
                Error(MessageCode.ErrorIndexerType, indexerExpression.Span, indexerExpression);
        }