public override void Visit(ICreateArray createArray) { if (Process(createArray)) { visitor.Visit(createArray); } base.Visit(createArray); }
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; }
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); }
/// <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); }
public void Visit(ICreateArray createArray) { throw new NotImplementedException(); }
/// <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); }
/// <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); }
/// <summary> /// Performs some computation with the given array creation expression. /// </summary> /// <param name="createArray"></param> public virtual void Visit(ICreateArray createArray) { }
public virtual void onASTElement(ICreateArray createArray) { }
public void Visit(ICreateArray createArray) { this.result = this.rewriter.Rewrite(createArray); }
/// <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; }
/// <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 }
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); }
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; }
public void Visit(ICreateArray createArray) { this.result = this.copier.Copy(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); }
/// <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; }
/// <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); }
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)); }
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; }
/// <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); }
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; }
public void Visit(ICreateArray createArray) { this.traverser.Traverse(createArray); }
/// <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; }
public void Visit(ICreateArray createArray) { Contract.Requires(createArray != null); throw new NotImplementedException(); }
/// <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); }
//^ 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(); }
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("}"); } }
/// <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); }
/// <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); }