Esempio n. 1
0
 /// <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;
 }
Esempio n. 2
0
 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;
 }
Esempio n. 3
0
    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;
    }
Esempio n. 4
0
 /// <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);
 }
Esempio n. 5
0
    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);
      }
    }
Esempio n. 6
0
 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);
       }
 }
Esempio n. 7
0
 /// <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);
 }
Esempio n. 8
0
 /// <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;
 }
Esempio n. 9
0
 /// <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);
 }