Ejemplo n.º 1
0
        /// <summary>
        /// Constructs a <c>FunctionCall</c> representation of creating a new array.
        /// </summary>
        /// <param name="elementType">type of array element</param>
        /// <param name="numElements">expression representing the array length</param>
        /// <param name="sample">sample instance of the created array</param>
        /// <returns></returns>
        public static FunctionCall NewArray(Type elementType, Expression numElements, Array sample)
        {
            ArrayParams    aparams;
            TypeDescriptor arrayType;

            if (sample != null)
            {
                long numElementsLong = sample.LongLength;
                aparams   = new ArrayParams(elementType, numElementsLong);
                arrayType = TypeDescriptor.GetTypeOf(sample);
            }
            else
            {
                aparams   = new ArrayParams(elementType);
                arrayType = elementType.MakeArrayType();
            }

            return(new FunctionCall()
            {
                Callee = MakeFun(
                    new IntrinsicFunction(IntrinsicFunction.EAction.NewArray, aparams),
                    arrayType),
                Arguments = new Expression[] { numElements },
                ResultType = arrayType,
                SetResultTypeClass = EResultTypeClass.ObjectReference
            });
        }
Ejemplo n.º 2
0
        /// <summary>
        /// Constructs a <c>FunctionCall</c> representation of creating a new array.
        /// </summary>
        /// <param name="elementType">type of array element</param>
        /// <param name="numElements">expression representing the array length</param>
        /// <param name="sample">sample instance of the created array</param>
        /// <returns></returns>
        public static FunctionCall NewArray(Type elementType, Expression numElements, Array sample)
        {
            ArrayParams aparams;
            TypeDescriptor arrayType;
            if (sample != null)
            {
                long numElementsLong = sample.LongLength;
                aparams = new ArrayParams(elementType, numElementsLong);
                arrayType = TypeDescriptor.GetTypeOf(sample);
            }
            else
            {
                aparams = new ArrayParams(elementType);
                arrayType = elementType.MakeArrayType();
            }

            return new FunctionCall()
            {
                Callee = MakeFun(
                    new IntrinsicFunction(IntrinsicFunction.EAction.NewArray, aparams),
                    arrayType),
                Arguments = new Expression[] { numElements },
                ResultType = arrayType,
                SetResultTypeClass = EResultTypeClass.ObjectReference
            };
        }