public override void Visit(ICreateArray createArray)
 {
     if (Process(createArray))
     {
         visitor.Visit(createArray);
     }
     base.Visit(createArray);
 }
Esempio n. 2
0
        public override void TraverseChildren(ICreateArray createArray)
        {
            base.TraverseChildren(createArray);
            IArrayTypeReference arrayType;

            if (createArray.Rank == 1 && IteratorHelper.EnumerableIsEmpty(createArray.LowerBounds))
            {
                arrayType = Immutable.Vector.GetVector(createArray.ElementType, this.host.InternFactory);
            }
            else
            {
                arrayType = Immutable.Matrix.GetMatrix(createArray.ElementType, createArray.Rank, this.host.InternFactory);
            }
            ((CreateArray)createArray).Type = arrayType;
        }
Esempio n. 3
0
        private HLLocation ProcessCreateArrayExpression(ICreateArray pExpression)
        {
            if (pExpression.Rank != 1 || pExpression.Sizes.Count() != 1 || pExpression.LowerBounds.Count() > 0)
            {
                throw new NotSupportedException();
            }

            HLType     typeElement      = HLDomain.GetOrCreateType(pExpression.ElementType);
            HLLocation locationInstance = HLTemporaryLocation.Create(CreateTemporary(HLDomain.GetOrCreateType(pExpression.Type)));
            HLLocation locationSize     = ProcessExpression(pExpression.Sizes.First());

            mCurrentBlock.EmitNewArray(locationInstance.AddressOf(), locationSize, locationInstance.Type, typeElement);

            IExpression[] initializers = pExpression.Initializers.ToArray();
            for (int indexInitializer = 0; indexInitializer < initializers.Length; ++indexInitializer)
            {
                HLLocation locationInitializer  = ProcessExpression(initializers[indexInitializer]);
                HLLocation locationArrayElement = HLArrayElementLocation.Create(locationInstance, HLInt32LiteralLocation.Create(indexInitializer), typeElement);
                mCurrentBlock.EmitAssignment(locationArrayElement, locationInitializer);
            }

            return(locationInstance);
        }
Esempio n. 4
0
 /// <summary>
 /// 
 /// </summary>
 /// <param name="createArray"></param>
 public CreateArray(ICreateArray createArray)
     : base(createArray)
 {
     Contract.Requires(createArray != null);
       this.elementType = createArray.ElementType;
       this.initializers = new List<IExpression>(createArray.Initializers);
       this.lowerBounds = new List<int>(createArray.LowerBounds);
       this.rank = createArray.Rank;
       this.sizes = new List<IExpression>(createArray.Sizes);
 }
Esempio n. 5
0
 public void Visit(ICreateArray createArray)
 {
     throw new NotImplementedException();
 }
Esempio n. 6
0
 /// <summary>
 /// Performs some computation with the given array creation expression.
 /// </summary>
 /// <param name="createArray"></param>
 public virtual void Visit(ICreateArray createArray)
 {
     this.Visit((IExpression)createArray);
 }
Esempio n. 7
0
 /// <summary>
 /// Traverses the children of the array creation expression.
 /// </summary>
 public virtual void TraverseChildren(ICreateArray createArray)
 {
     Contract.Requires(createArray != null);
       this.TraverseChildren((IExpression)createArray);
       if (this.StopTraversal) return;
       this.Traverse(createArray.ElementType);
       if (this.StopTraversal) return;
       this.Traverse(createArray.Sizes);
       if (this.StopTraversal) return;
       this.Traverse(createArray.Initializers);
 }
Esempio n. 8
0
 /// <summary>
 /// Performs some computation with the given array creation expression.
 /// </summary>
 /// <param name="createArray"></param>
 public virtual void Visit(ICreateArray createArray)
 {
 }
Esempio n. 9
0
 public virtual void onASTElement(ICreateArray createArray)
 {
 }
Esempio n. 10
0
 public void Visit(ICreateArray createArray)
 {
     this.result = this.rewriter.Rewrite(createArray);
 }
Esempio n. 11
0
 /// <summary>
 /// Returns a deep copy of the given array creation expression.
 /// </summary>
 /// <param name="createArray"></param>
 public CreateArray Copy(ICreateArray createArray)
 {
     var mutableCopy = this.shallowCopier.Copy(createArray);
       this.CopyChildren((Expression)mutableCopy);
       mutableCopy.ElementType = this.Copy(mutableCopy.ElementType);
       mutableCopy.Sizes = this.Copy(mutableCopy.Sizes);
       mutableCopy.Initializers = this.Copy(mutableCopy.Initializers);
       return mutableCopy;
 }
Esempio n. 12
0
 /// <summary>
 /// Generates IL for the specified create array.
 /// </summary>
 /// <param name="createArray">The create array instance to visit.</param>
 public override void TraverseChildren(ICreateArray createArray)
 {
     IEnumerator<int> bounds = createArray.LowerBounds.GetEnumerator();
       bool hasOneOrMoreBounds = bounds.MoveNext();
       bool hasMoreBounds = hasOneOrMoreBounds;
       uint boundsEmitted = 0;
       //
       // For the case of rank > 1 the lower bounds and sizes are interleaved on the stack
       //
       foreach (IExpression size in createArray.Sizes) {
     // First the lower bound, if any
     if (hasOneOrMoreBounds) {
       if (hasMoreBounds) {
     this.EmitConstant(bounds.Current);
     hasMoreBounds = bounds.MoveNext();
       } else {
     this.generator.Emit(OperationCode.Ldc_I4_0);
     this.StackSize++;
       }
       boundsEmitted++;
     }
     this.Traverse(size);
     if (size.Type.TypeCode == PrimitiveTypeCode.Int64 || size.Type.TypeCode == PrimitiveTypeCode.UInt64)
       this.generator.Emit(OperationCode.Conv_Ovf_U);
       }
       IArrayTypeReference arrayType;
       OperationCode create;
       if (hasOneOrMoreBounds) {
     create = OperationCode.Array_Create_WithLowerBound;
     arrayType = Matrix.GetMatrix(createArray.ElementType, createArray.Rank, createArray.LowerBounds, ((IMetadataCreateArray)createArray).Sizes, this.host.InternFactory);
       } else if (createArray.Rank > 1) {
     create = OperationCode.Array_Create;
     arrayType = Matrix.GetMatrix(createArray.ElementType, createArray.Rank, this.host.InternFactory);
       } else {
     create = OperationCode.Newarr;
     arrayType = Vector.GetVector(createArray.ElementType, this.host.InternFactory);
       }
       this.generator.Emit(create, arrayType);
       this.StackSize -= (ushort)(createArray.Rank+boundsEmitted - 1);
       if (createArray.Rank == 1) {
     int i = 0;
     foreach (IExpression elemValue in createArray.Initializers) {
       this.generator.Emit(OperationCode.Dup);
       this.StackSize++;
       this.EmitConstant(i++);
       this.Traverse(elemValue);
       this.StoreVectorElement(createArray.ElementType);
     }
       } else {
     StoreInitializers(createArray, arrayType);
       }
       //TODO: initialization from compile time constant
 }
Esempio n. 13
0
 private void StoreInitializers(ICreateArray createArray, IArrayTypeReference arrayType)
 {
     var initializers = new List<IExpression>(createArray.Initializers);
       if (initializers.Count > 0) {
     var sizes = new List<IExpression>(createArray.Sizes);
     // Used to do the "reverse" mapping from offset (linear index into
     // initializer list) to the d-dimensional coordinates, where d is
     // the rank of the array.
     ulong[] dimensionStride = new ulong[sizes.Count];
     dimensionStride[sizes.Count - 1] = 1;
     for (int i = sizes.Count - 2; 0 <= i; i--) {
       var size = ((IConvertible)((ICompileTimeConstant)sizes[i + 1]).Value).ToUInt64(null);
       dimensionStride[i] = size * dimensionStride[i + 1];
     }
     for (int i = 0; i < initializers.Count; i++) {
       this.generator.Emit(OperationCode.Dup);
       this.StackSize++;
       ulong n = (ulong)i; // compute the indices that map to the offset n
       for (uint d = 0; d < createArray.Rank; d++) {
     var divisor = dimensionStride[d];
     var indexInThisDimension = n / divisor;
     n = n % divisor;
     this.EmitConstant((int)indexInThisDimension);
       }
       this.Traverse(initializers[i]);
       this.generator.Emit(OperationCode.Array_Set, arrayType);
       this.StackSize -= (ushort)(createArray.Rank + 2);
     }
       }
 }
 public override void Visit(ICreateArray createArray)
 {
     if(Process(createArray)){visitor.Visit(createArray);}
     base.Visit(createArray);
 }
Esempio n. 15
0
        private HLLocation ProcessCreateArrayExpression(ICreateArray pExpression)
        {
            if (pExpression.Rank != 1 || pExpression.Sizes.Count() != 1 || pExpression.LowerBounds.Count() > 0) throw new NotSupportedException();

            HLType typeElement = HLDomain.GetOrCreateType(pExpression.ElementType);
            HLLocation locationInstance = HLTemporaryLocation.Create(CreateTemporary(HLDomain.GetOrCreateType(pExpression.Type)));
            HLLocation locationSize = ProcessExpression(pExpression.Sizes.First());
            mCurrentBlock.EmitNewArray(locationInstance.AddressOf(), locationSize, locationInstance.Type, typeElement);

            IExpression[] initializers = pExpression.Initializers.ToArray();
            for (int indexInitializer = 0; indexInitializer < initializers.Length; ++indexInitializer)
            {
                HLLocation locationInitializer = ProcessExpression(initializers[indexInitializer]);
                HLLocation locationArrayElement = HLArrayElementLocation.Create(locationInstance, HLInt32LiteralLocation.Create(indexInitializer), typeElement);
                mCurrentBlock.EmitAssignment(locationArrayElement, locationInitializer);
            }

            return locationInstance;
        }
Esempio n. 16
0
 public virtual void onASTElement(ICreateArray createArray) { }
Esempio n. 17
0
 public void Visit(ICreateArray createArray)
 {
     this.result = this.copier.Copy(createArray);
 }
Esempio n. 18
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);
 }
Esempio n. 19
0
 /// <summary>
 /// Rewrites the given array creation expression.
 /// </summary>
 /// <param name="createArray"></param>
 public virtual IExpression Rewrite(ICreateArray createArray)
 {
     var mutableCreateArray = createArray as CreateArray;
       if (mutableCreateArray == null) return createArray;
       this.RewriteChildren(mutableCreateArray);
       return mutableCreateArray;
 }
Esempio n. 20
0
 /// <summary>
 /// Returns a shallow copy of the given array creation expression.
 /// </summary>
 /// <param name="createArray"></param>
 public CreateArray Copy(ICreateArray createArray)
 {
     return new CreateArray(createArray);
 }
Esempio n. 21
0
 public override void Visit(ICreateArray createArray)
 {
     allElements.Add(new InvokInfo(Traverser, "ICreateArray", createArray));
 }
    public override void TraverseChildren(ICreateArray createArrayInstance)
    {
      Bpl.IToken cloc = createArrayInstance.Token();
      var a = this.sink.CreateFreshLocal(createArrayInstance.Type);

      Debug.Assert(createArrayInstance.Rank > 0); 
      Bpl.Expr lengthExpr = Bpl.Expr.Literal(1);
      foreach (IExpression expr in createArrayInstance.Sizes) {
        this.Traverse(expr);
        lengthExpr = Bpl.Expr.Mul(lengthExpr, TranslatedExpressions.Pop());
      }
      
      // First generate an Alloc() call
      this.StmtTraverser.StmtBuilder.Add(new Bpl.CallCmd(cloc, this.sink.AllocationMethodName, new List<Bpl.Expr>(), new List<Bpl.IdentifierExpr>(new Bpl.IdentifierExpr[] {Bpl.Expr.Ident(a)})));
      Bpl.Expr assumeExpr = Bpl.Expr.Eq(new Bpl.NAryExpr(cloc, new Bpl.FunctionCall(this.sink.Heap.ArrayLengthFunction), new List<Bpl.Expr>(new Bpl.Expr[] {Bpl.Expr.Ident(a)})), lengthExpr);
      this.StmtTraverser.StmtBuilder.Add(new Bpl.AssumeCmd(cloc, assumeExpr));
      TranslatedExpressions.Push(Bpl.Expr.Ident(a));
    }
Esempio n. 23
0
 public override void Visit(ICreateArray createArray)
 {
     NewLineAddIndent();
     AppendElementType(createArray);
     //Visit(createArray.ElementType);
     base.Visit(createArray);
 }
        public override void TraverseChildren(ICreateArray createArray)
{ MethodEnter(createArray);
            base.TraverseChildren(createArray);
     MethodExit();   }
 /// <summary>
 /// Rewrites the given array creation expression.
 /// </summary>
 /// <param name="createArray"></param>
 public virtual IExpression Rewrite(ICreateArray createArray)
 {
     return createArray;
 }
Esempio n. 26
0
 /// <summary>
 /// Traverses the array creation expression.
 /// </summary>
 public void Traverse(ICreateArray createArray)
 {
     Contract.Requires(createArray != null);
       if (this.preorderVisitor != null) this.preorderVisitor.Visit(createArray);
       if (this.StopTraversal) return;
       this.TraverseChildren(createArray);
       if (this.StopTraversal) return;
       if (this.postorderVisitor != null) this.postorderVisitor.Visit(createArray);
 }
Esempio n. 27
0
    public override void TraverseChildren(ICreateArray createArray) {
      base.TraverseChildren(createArray);
      IArrayTypeReference arrayType;
      if (createArray.Rank == 1 && IteratorHelper.EnumerableIsEmpty(createArray.LowerBounds))
        arrayType = Immutable.Vector.GetVector(createArray.ElementType, this.host.InternFactory);
      else
        arrayType = Immutable.Matrix.GetMatrix(createArray.ElementType, createArray.Rank, this.host.InternFactory);
      ((CreateArray)createArray).Type = arrayType;

    }
Esempio n. 28
0
 public void Visit(ICreateArray createArray)
 {
     this.traverser.Traverse(createArray);
 }
Esempio n. 29
0
    /// <summary>
    /// Returns a deep copy of the given array creation expression.
    /// </summary>
    /// <param name="createArray"></param>
    public CreateArray Copy(ICreateArray createArray) {
      Contract.Requires(createArray != null);
      Contract.Ensures(Contract.Result<CreateArray>() != null);

      var mutableCopy = this.shallowCopier.Copy(createArray);
      this.CopyChildren((Expression)mutableCopy);
      mutableCopy.ElementType = this.Copy(mutableCopy.ElementType);
      mutableCopy.Sizes = this.Copy(mutableCopy.Sizes);
      mutableCopy.Initializers = this.Copy(mutableCopy.Initializers);
      return mutableCopy;
    }
Esempio n. 30
0
 public void Visit(ICreateArray createArray)
 {
     Contract.Requires(createArray != null);
       throw new NotImplementedException();
 }
Esempio n. 31
0
    /// <summary>
    /// Returns a shallow copy of the given array creation expression.
    /// </summary>
    /// <param name="createArray"></param>
    public CreateArray Copy(ICreateArray createArray) {
      Contract.Requires(createArray != null);
      Contract.Ensures(Contract.Result<CreateArray>() != null);

      return new CreateArray(createArray);
    }
Esempio n. 32
0
 //^ ensures this.path.Count == old(this.path.Count);
 /// <summary>
 /// Traverses the given array creation expression.
 /// </summary>
 /// <param name="createArray"></param>
 public virtual void Visit(ICreateArray createArray)
 {
     if (this.stopTraversal) return;
       //^ int oldCount = this.path.Count;
       this.path.Push(createArray);
       this.Visit(createArray.Sizes);
       this.Visit(createArray.Initializers);
       //^ assume this.path.Count == oldCount+1; //True because all of the virtual methods of this class promise not to decrease this.path.Count.
       this.path.Pop();
 }
 /// <summary>
 /// Performs some computation with the given array creation expression.
 /// </summary>
 /// <param name="createArray"></param>
 public virtual void Visit(ICreateArray createArray)
 {
 }
 public override void TraverseChildren(ICreateArray createArray) {
   this.sourceEmitterOutput.Write("new ");
   this.PrintTypeReference(createArray.ElementType);
   this.sourceEmitterOutput.Write("[");
   this.Traverse(createArray.Sizes);
   this.sourceEmitterOutput.Write("]");
   if (IteratorHelper.EnumerableIsNotEmpty(createArray.Initializers)) {
     this.sourceEmitterOutput.Write(" {");
     this.Traverse(createArray.Initializers);
     this.sourceEmitterOutput.Write("}");
   }
 }
Esempio n. 35
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. 36
0
 public override void TraverseChildren(ICreateArray createArray)
 {
     MethodEnter(createArray);
     base.TraverseChildren(createArray);
     MethodExit();
 }
Esempio n. 37
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 (mutableCreateArray == null) {
       this.resultExpression = createArray;
       return;
     }
     this.resultExpression = this.myCodeMutator.Visit(mutableCreateArray);
 }