/// <summary> /// Visits the specified create array. /// </summary> /// <param name="createArray">The create array.</param> /// <returns></returns> protected virtual IExpression DeepCopy(CreateArray createArray) { createArray.ElementType = this.Substitute(createArray.ElementType); createArray.Sizes = this.DeepCopy(createArray.Sizes); createArray.Initializers = this.DeepCopy(createArray.Initializers); createArray.Type = this.Substitute(createArray.Type); return createArray; }
private Expression ParseArrayCreate(IOperation currentOperation) { IArrayTypeReference arrayType = (IArrayTypeReference)currentOperation.Value; CreateArray result = new CreateArray(); result.ElementType = arrayType.ElementType; result.Rank = arrayType.Rank; result.Type = arrayType; if (currentOperation.OperationCode == OperationCode.Array_Create_WithLowerBound) { for (uint i = 0; i < arrayType.Rank; i++) result.LowerBounds.Add(ConvertToInt(this.PopOperandStack())); result.LowerBounds.Reverse(); } for (uint i = 0; i < arrayType.Rank; i++) result.Sizes.Add(this.PopOperandStack()); result.Sizes.Reverse(); return result; }
private int ComputeFlatIndex(ArrayIndexer arrayIndexer, CreateArray createArray) { Contract.Requires(arrayIndexer != null); Contract.Requires(createArray != null); var n = arrayIndexer.Indices.Count; if (n == 1) { var indexValue = arrayIndexer.Indices[0] as CompileTimeConstant; if (indexValue == null || !(indexValue.Value is int)) return -1; return (int)indexValue.Value; } var result = 0; for (int i = 0; i < n; i++) { var targetIndexValue = arrayIndexer.Indices[i] as CompileTimeConstant; if (targetIndexValue == null || !(targetIndexValue.Value is int)) return -1; if (i > 0) { if (i >= createArray.Sizes.Count) return -1; var sizeConst = createArray.Sizes[i] as CompileTimeConstant; if (sizeConst == null || !(sizeConst.Value is int)) return -1; result *= (int)sizeConst.Value; } if (i < createArray.LowerBounds.Count) result -= createArray.LowerBounds[i]; result += (int)targetIndexValue.Value; } return result; }
/// <summary> /// Visits the specified create array. /// </summary> /// <param name="createArray">The create array.</param> public override void Visit(ICreateArray createArray) { CreateArray mutableCreateArray = new CreateArray(createArray); this.resultExpression = this.myCodeCopier.DeepCopy(mutableCreateArray); }
static void AddSizesAndArrayInitializers(CreateArray createArray, IFieldDefinition initialValueField) { Contract.Requires(createArray != null); Contract.Requires(initialValueField != null); Contract.Requires(initialValueField.IsMapped); List<ulong> sizes = new List<ulong>(); foreach (IExpression expr in createArray.Sizes) { IMetadataConstant mdc = expr as IMetadataConstant; if (mdc == null) return; sizes.Add(ConvertToUlong(mdc)); } ITypeReference elemType = createArray.ElementType; MemoryStream memoryStream = new MemoryStream(new List<byte>(initialValueField.FieldMapping.Data).ToArray()); BinaryReader reader = new BinaryReader(memoryStream, Encoding.Unicode); ulong flatSize = 1; foreach (ulong dimensionSize in sizes) flatSize *= dimensionSize; while (flatSize-- > 0) { CompileTimeConstant cc = new CompileTimeConstant(); cc.Value = ReadValue(elemType.TypeCode, reader); cc.Type = elemType; createArray.Initializers.Add(cc); } }
private static void AddArrayInitializers(CreateArray createArray, IFieldDefinition initialValueField, ulong[] sizes) { ITypeReference elemType = createArray.ElementType; MemoryStream memoryStream = new MemoryStream(new List<byte>(initialValueField.FieldMapping.Data).ToArray()); BinaryReader reader = new BinaryReader(memoryStream, Encoding.Unicode); ulong flatSize = 1; foreach (ulong dimensionSize in sizes) flatSize *= dimensionSize; while (flatSize-- > 0) { CompileTimeConstant cc = new CompileTimeConstant(); cc.Value = ReadValue(elemType.TypeCode, reader); cc.Type = elemType; createArray.Initializers.Add(cc); } }
/// <summary> /// Rewrites the children of the given array creation expression. /// </summary> public virtual void RewriteChildren(CreateArray createArray) { this.RewriteChildren((Expression)createArray); createArray.ElementType = this.Rewrite(createArray.ElementType); createArray.Sizes = this.Rewrite(createArray.Sizes); createArray.Initializers = this.Rewrite(createArray.Initializers); }
/// <summary> /// Visits the specified create array. /// </summary> /// <param name="createArray">The create array.</param> /// <returns></returns> public virtual IExpression Visit(CreateArray createArray) { createArray.ElementType = this.Visit(createArray.ElementType); createArray.Sizes = this.Visit(createArray.Sizes); createArray.Initializers = this.Visit(createArray.Initializers); createArray.Type = this.Visit(createArray.Type); return createArray; }
/// <summary> /// Visits the specified create array. /// </summary> /// <param name="createArray">The create array.</param> public override void Visit(ICreateArray createArray) { CreateArray mutableCreateArray = createArray as CreateArray; if (alwaysMakeACopy || mutableCreateArray == null) mutableCreateArray = new CreateArray(createArray); this.resultExpression = this.myCodeMutator.Visit(mutableCreateArray); }