private ArrayIndexer ParseArrayIndexer(IOperation currentOperation) { uint rank = 1; IArrayTypeReference/*?*/ arrayType = currentOperation.Value as IArrayTypeReference; if (arrayType != null) rank = arrayType.Rank; ArrayIndexer result = new ArrayIndexer(); for (uint i = 0; i < rank; i++) result.Indices.Add(this.PopOperandStack()); result.Indices.Reverse(); result.IndexedObject = this.PopOperandStack(); return result; }
/// <summary> /// Visits the specified array indexer. /// </summary> /// <param name="arrayIndexer">The array indexer.</param> /// <returns></returns> protected virtual IExpression DeepCopy(ArrayIndexer arrayIndexer) { arrayIndexer.IndexedObject = this.Substitute(arrayIndexer.IndexedObject); arrayIndexer.Indices = this.DeepCopy(arrayIndexer.Indices); arrayIndexer.Type = this.Substitute(arrayIndexer.Type); return arrayIndexer; }
private ArrayIndexer ParseArrayIndexer(IOperation currentOperation, ITypeReference elementType, bool treatArrayAsSingleDimensioned = false) { Contract.Requires(currentOperation != null); Contract.Requires(elementType != null); uint rank = 1; IArrayTypeReference/*?*/ arrayType = null; if (!treatArrayAsSingleDimensioned) //then currentOperation.Value contains the type of the array, not the type of the indexed element. arrayType = currentOperation.Value as IArrayTypeReference; if (arrayType != null) rank = arrayType.Rank; ArrayIndexer result = new ArrayIndexer(); for (uint i = 0; i < rank; i++) result.Indices.Add(this.PopOperandStack()); result.Indices.Reverse(); var indexedObject = this.PopOperandStack(); result.Type = elementType; //obtained from the instruction, but could be a lossy abstraction, or null if (arrayType == null) arrayType = indexedObject.Type as IArrayTypeReference; if (arrayType != null) //rather use its element type than the caller's element type (which is derived from the operation code). result.Type = arrayType.ElementType; else arrayType = Immutable.Vector.GetVector(elementType, this.host.InternFactory); if (!TypeHelper.TypesAreEquivalent(indexedObject.Type, arrayType)) indexedObject = new Conversion() { ValueToConvert = indexedObject, TypeAfterConversion = arrayType }; Contract.Assume(indexedObject.Type is IArrayTypeReference); result.IndexedObject = indexedObject; Contract.Assume(!(result.Type is Dummy)); return result; }
/// <summary> /// Visits the specified array indexer. /// </summary> /// <param name="arrayIndexer">The array indexer.</param> public override void Visit(IArrayIndexer arrayIndexer) { ArrayIndexer mutableArrayIndexer = new ArrayIndexer(arrayIndexer); this.resultExpression = this.myCodeCopier.DeepCopy(mutableArrayIndexer); }
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> /// Rewrites the children of the given array indexer expression. /// </summary> /// <param name="arrayIndexer"></param> public virtual void RewriteChildren(ArrayIndexer arrayIndexer) { this.RewriteChildren((Expression)arrayIndexer); arrayIndexer.IndexedObject = this.Rewrite(arrayIndexer.IndexedObject); arrayIndexer.Indices = this.Rewrite(arrayIndexer.Indices); }
/// <summary> /// Visits the specified array indexer. /// </summary> /// <param name="arrayIndexer">The array indexer.</param> public override void Visit(IArrayIndexer arrayIndexer) { ArrayIndexer mutableArrayIndexer = arrayIndexer as ArrayIndexer; if (alwaysMakeACopy || mutableArrayIndexer == null) mutableArrayIndexer = new ArrayIndexer(arrayIndexer); this.resultExpression = this.myCodeMutator.Visit(mutableArrayIndexer); }
/// <summary> /// Visits the specified array indexer. /// </summary> /// <param name="arrayIndexer">The array indexer.</param> /// <returns></returns> public virtual IExpression Visit(ArrayIndexer arrayIndexer) { arrayIndexer.IndexedObject = this.Visit(arrayIndexer.IndexedObject); arrayIndexer.Indices = this.Visit(arrayIndexer.Indices); arrayIndexer.Type = this.Visit(arrayIndexer.Type); return arrayIndexer; }