Beispiel #1
0
        public override void Visit(IArrayIndexer arrayIndexer)
        {
            if (arrayIndexer.Indices.Count() == 1 && Names.NameTable.ContainsKey(arrayIndexer.IndexedObject))
            {
                // the array expression, e.g.: this.array
                var arrayName = Names.NameTable[arrayIndexer.IndexedObject];
                // the contents expression, e.g.: this.array[..]
                var arrayContents = NameBuilder.FormElementsExpression(arrayName);

                // mark array indexes as compatible
                var index = arrayIndexer.Indices.First();
                if (Names.NameTable.ContainsKey(index))
                {
                    // The array reference may not have been used in a comparable way yet.
                    if (!ids.ContainsKey(arrayContents))
                    {
                        ids.Add(arrayContents, comparability.AddElement());
                    }

                    if (!collectionIndexes.ContainsKey(arrayContents))
                    {
                        collectionIndexes.Add(arrayContents, new HashSet <string>());
                    }

                    if (collectionIndexes[arrayContents].Add(Names.NameTable[index]))
                    {
                        // we haven't seen this index before, so re-mark indexes
                        Mark(collectionIndexes[arrayContents]);
                    }
                }

                PropogateTypeReference(arrayIndexer.IndexedObject, arrayIndexer);
            }
        }
 public override void Visit(IArrayIndexer arrayIndexer)
 {
     if (Process(arrayIndexer))
     {
         visitor.Visit(arrayIndexer);
     }
     base.Visit(arrayIndexer);
 }
Beispiel #3
0
        public override void TraverseChildren(IArrayIndexer arrayIndexer)
        {
            base.TraverseChildren(arrayIndexer);
            IArrayTypeReference /*?*/ arrayType = arrayIndexer.IndexedObject.Type as IArrayTypeReference;

            if (arrayType == null)
            {
                return;
            }
            ((ArrayIndexer)arrayIndexer).Type = arrayType.ElementType;
        }
Beispiel #4
0
        private HLLocation ProcessArrayIndexerExpression(IArrayIndexer pExpression)
        {
            if (pExpression.Indices.Count() != 1)
            {
                throw new NotSupportedException();
            }

            HLLocation locationInstance = ProcessExpression(pExpression.IndexedObject);
            HLLocation locationIndex    = ProcessExpression(pExpression.Indices.First());
            HLType     typeElement      = HLDomain.GetOrCreateType(pExpression.Type);

            return(HLArrayElementLocation.Create(locationInstance, locationIndex, typeElement));
        }
        public override void Visit(IArrayIndexer arrayIndexer)
        {
            if (arrayIndexer.Indices.Count() == 1 && NameTable.ContainsKey(arrayIndexer.IndexedObject))
            {
                var arrayName = NameTable[arrayIndexer.IndexedObject];
                TryAdd(arrayIndexer, FormElementsExpression(arrayName));

                // propogate instance expression information
                if (InstanceExpressionsReferredTypes.ContainsKey(arrayIndexer.IndexedObject))
                {
                    AddInstanceExpr(InstanceExpressionsReferredTypes[arrayIndexer.IndexedObject], arrayIndexer);
                }
            }
        }
Beispiel #6
0
 private HLLocation ProcessAddressableExpression(IAddressableExpression pExpression)
 {
     if (pExpression.Definition is ILocalDefinition)
     {
         return(HLLocalLocation.Create(HLDomain.GetLocal(pExpression.Definition as ILocalDefinition)));
     }
     else if (pExpression.Definition is IParameterDefinition)
     {
         return(HLParameterLocation.Create(HLDomain.GetParameter(pExpression.Definition as IParameterDefinition)));
     }
     else if (pExpression.Definition is IFieldDefinition || pExpression.Definition is IFieldReference)
     {
         IFieldDefinition definition         = pExpression.Definition is IFieldDefinition ? (IFieldDefinition)pExpression.Definition : ((IFieldReference)pExpression.Definition).ResolvedField;
         HLType           typeFieldContainer = HLDomain.GetOrCreateType(definition.Container);
         HLField          field = HLDomain.GetField(definition);
         if (field.IsStatic)
         {
             return(HLStaticFieldLocation.Create(field));
         }
         HLLocation instance = ProcessExpression(pExpression.Instance);
         return(HLFieldLocation.Create(instance, field));
     }
     else if (pExpression.Definition is IArrayIndexer)
     {
         IArrayIndexer definition = (IArrayIndexer)pExpression.Definition;
         if (definition.Indices.Count() != 1)
         {
             throw new NotSupportedException();
         }
         HLLocation locationInstance = ProcessExpression(pExpression.Instance);
         HLLocation locationIndex    = ProcessExpression(definition.Indices.First());
         HLType     typeElement      = HLDomain.GetOrCreateType(pExpression.Type);
         return(HLArrayElementLocation.Create(locationInstance, locationIndex, typeElement));
     }
     else if (pExpression.Definition is IDefaultValue)
     {
         HLType     typeDefaultValue     = HLDomain.GetOrCreateType(((IDefaultValue)pExpression.Definition).DefaultValueType);
         HLLocation locationDefaultValue = HLTemporaryLocation.Create(CreateTemporary(typeDefaultValue));
         mCurrentBlock.EmitAssignment(locationDefaultValue, HLDefaultLocation.Create(typeDefaultValue));
         return(locationDefaultValue);
     }
     throw new NotSupportedException();
 }
Beispiel #7
0
 //^ ensures this.path.Count == old(this.path.Count);
 /// <summary>
 /// Traverses the given array indexer expression.
 /// </summary>
 /// <param name="arrayIndexer"></param>
 public virtual void Visit(IArrayIndexer arrayIndexer)
 {
     if (this.stopTraversal) return;
       //^ int oldCount = this.path.Count;
       this.path.Push(arrayIndexer);
       this.Visit(arrayIndexer.IndexedObject);
       this.Visit(arrayIndexer.Indices);
       //^ 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();
 }
Beispiel #8
0
 public void Visit(IArrayIndexer arrayIndexer)
 {
     Contract.Requires(arrayIndexer != null);
       throw new NotImplementedException();
 }
Beispiel #9
0
 public void Visit(IArrayIndexer arrayIndexer)
 {
     this.traverser.Traverse(arrayIndexer);
 }
Beispiel #10
0
 /// <summary>
 /// Traverses the array indexer expression.
 /// </summary>
 public void Traverse(IArrayIndexer arrayIndexer)
 {
     Contract.Requires(arrayIndexer != null);
       if (this.preorderVisitor != null) this.preorderVisitor.Visit(arrayIndexer);
       if (this.StopTraversal) return;
       this.TraverseChildren(arrayIndexer);
       if (this.StopTraversal) return;
       if (this.postorderVisitor != null) this.postorderVisitor.Visit(arrayIndexer);
 }
        public override void TraverseChildren(IArrayIndexer arrayIndexer)
{ MethodEnter(arrayIndexer);
            base.TraverseChildren(arrayIndexer);
     MethodExit();   }
Beispiel #12
0
 /// <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);
 }
Beispiel #13
0
 /// <summary>
 /// Generates IL for the specified array indexer.
 /// </summary>
 /// <param name="arrayIndexer">The array indexer.</param>
 public override void TraverseChildren(IArrayIndexer arrayIndexer)
 {
     this.Traverse(arrayIndexer.IndexedObject);
       this.Traverse(arrayIndexer.Indices);
       IArrayTypeReference arrayType = (IArrayTypeReference)arrayIndexer.IndexedObject.Type;
       if (arrayType.IsVector)
     this.LoadVectorElement(arrayType.ElementType);
       else {
     this.generator.Emit(OperationCode.Array_Get, arrayIndexer.IndexedObject.Type);
     this.StackSize -= (ushort)IteratorHelper.EnumerableCount(arrayIndexer.Indices);
       }
 }
Beispiel #14
0
 /// <summary>
 /// Rewrites the given array indexer expression.
 /// </summary>
 /// <param name="arrayIndexer"></param>
 public virtual IExpression Rewrite(IArrayIndexer arrayIndexer)
 {
     var mutableArrayIndexer = arrayIndexer as ArrayIndexer;
       if (mutableArrayIndexer == null) return arrayIndexer;
       this.RewriteChildren(mutableArrayIndexer);
       return mutableArrayIndexer;
 }
 public override void Visit(IArrayIndexer arrayIndexer)
 {
     if(Process(arrayIndexer)){visitor.Visit(arrayIndexer);}
     base.Visit(arrayIndexer);
 }
Beispiel #16
0
        private HLLocation ProcessArrayIndexerExpression(IArrayIndexer pExpression)
        {
            if (pExpression.Indices.Count() != 1) throw new NotSupportedException();

            HLLocation locationInstance = ProcessExpression(pExpression.IndexedObject);
            HLLocation locationIndex = ProcessExpression(pExpression.Indices.First());
            HLType typeElement = HLDomain.GetOrCreateType(pExpression.Type);
            return HLArrayElementLocation.Create(locationInstance, locationIndex, typeElement);
        }
Beispiel #17
0
 /// <summary>
 /// 
 /// </summary>
 /// <param name="arrayIndexer"></param>
 public ArrayIndexer(IArrayIndexer arrayIndexer)
     : base(arrayIndexer)
 {
     Contract.Requires(arrayIndexer != null);
       this.indexedObject = arrayIndexer.IndexedObject;
       this.indices = new List<IExpression>(arrayIndexer.Indices);
 }
Beispiel #18
0
 public void Visit(IArrayIndexer arrayIndexer)
 {
     this.result = this.copier.Copy(arrayIndexer);
 }
 public virtual void onASTElement(IArrayIndexer arrayIndexer) { }
      public override IExpression Rewrite(IArrayIndexer arrayIndexer) {
        if (ExpressionTraverser.IsAtomicInstance(arrayIndexer.IndexedObject)) return arrayIndexer;

        // arrayIndexer == AI(inst, [index]), i.e., inst[index0, index1,...]
        // return { loc := e; [assert loc != null;] | AI(BE(null,loc), [index]) }
        //   where e is the rewritten array instance

        var e = base.Rewrite(arrayIndexer.IndexedObject);

        var loc = new LocalDefinition() {
          Name = this.host.NameTable.GetNameFor("_loc" + this.sink.LocalCounter.ToString()),
          Type = e.Type
        };
        var locDecl = new LocalDeclarationStatement() {
          InitialValue = e,
          LocalVariable = loc,
        };
        return new BlockExpression() {
          BlockStatement = new BlockStatement() {
            Statements = new List<IStatement> { locDecl },
          },
          Expression = new ArrayIndexer() {
            IndexedObject = new BoundExpression() {
              Definition = loc,
              Instance = null,
              Type = loc.Type,
            },
            Indices = new List<IExpression>(arrayIndexer.Indices),
            Type = arrayIndexer.Type,
          },
        };
      }
Beispiel #21
0
 /// <summary>
 /// Returns a shallow copy of the given array indexer expression.
 /// </summary>
 /// <param name="arrayIndexer"></param>
 public ArrayIndexer Copy(IArrayIndexer arrayIndexer)
 {
     return new ArrayIndexer(arrayIndexer);
 }
Beispiel #22
0
 public void Visit(IArrayIndexer arrayIndexer)
 {
     this.result = this.rewriter.Rewrite(arrayIndexer);
 }
    public override void TraverseChildren(IArrayIndexer arrayIndexer) {

      //if (!IsAtomicInstance(arrayIndexer.IndexedObject)) {
      //  // Simplify the BE so that all nested dereferences and method calls are broken up into separate assignments to locals.
      //  var se = ExpressionSimplifier.Simplify(this.sink, arrayIndexer);
      //  this.Traverse(se);
      //  return;
      //}

      this.Traverse(arrayIndexer.IndexedObject);
      Bpl.Expr arrayExpr = TranslatedExpressions.Pop();

      var be = arrayIndexer.IndexedObject as IBoundExpression;
      if (be != null && be.Instance != null) {
        var l = this.sink.CreateFreshLocal(be.Type);
        var lhs = Bpl.Expr.Ident(l);
        var cmd = Bpl.Cmd.SimpleAssign(arrayIndexer.Token(), lhs, arrayExpr);
        this.StmtTraverser.StmtBuilder.Add(cmd);
        arrayExpr = lhs;
      }

      this.Traverse(arrayIndexer.Indices);
      int count = arrayIndexer.Indices.Count();
      Bpl.Expr[] indexExprs = new Bpl.Expr[count];
      for (int i = count; i > 0; i--) {
        indexExprs[i - 1] = TranslatedExpressions.Pop();
      }
      Bpl.Expr indexExpr;
      if (indexExprs.Length == 1) {
        indexExpr = indexExprs[0];
      }
      else {
        Bpl.Function f = this.sink.FindOrCreateNaryIntFunction(indexExprs.Length);
        indexExpr = new Bpl.NAryExpr(arrayIndexer.Token(), new Bpl.FunctionCall(f), new List<Bpl.Expr>(indexExprs));
      }

      AssertOrAssumeNonNull(arrayIndexer.Token(), arrayExpr);
      this.TranslatedExpressions.Push(this.sink.Heap.ReadHeap(arrayExpr, indexExpr, AccessType.Array, this.sink.CciTypeToBoogie(arrayIndexer.Type)));
    }
Beispiel #24
0
 public override void Visit(IArrayIndexer arrayIndexer)
 {
     allElements.Add(new InvokInfo(Traverser, "IArrayIndexer", arrayIndexer));
 }
Beispiel #25
0
 public virtual void onASTElement(IArrayIndexer arrayIndexer)
 {
 }
 /// <summary>
 /// Rewrites the given array indexer expression.
 /// </summary>
 /// <param name="arrayIndexer"></param>
 public virtual IExpression Rewrite(IArrayIndexer arrayIndexer)
 {
     return arrayIndexer;
 }
Beispiel #27
0
 /// <summary>
 /// Performs some computation with the given array indexer expression.
 /// </summary>
 /// <param name="arrayIndexer"></param>
 public virtual void Visit(IArrayIndexer arrayIndexer)
 {
 }
 public override void TraverseChildren(IArrayIndexer arrayIndexer) {
   base.TraverseChildren(arrayIndexer);
   IArrayTypeReference/*?*/ arrayType = arrayIndexer.IndexedObject.Type as IArrayTypeReference;
   if (arrayType == null) return;
   ((ArrayIndexer)arrayIndexer).Type = arrayType.ElementType;
 }
Beispiel #29
0
 /// <summary>
 /// Traverses the children of the array indexer expression.
 /// </summary>
 public virtual void TraverseChildren(IArrayIndexer arrayIndexer)
 {
     Contract.Requires(arrayIndexer != null);
       this.TraverseChildren((IExpression)arrayIndexer);
       if (this.StopTraversal) return;
       this.Traverse(arrayIndexer.IndexedObject);
       if (this.StopTraversal) return;
       this.Traverse(arrayIndexer.Indices);
 }
Beispiel #30
0
    /// <summary>
    /// Returns a deep copy of the given array indexer expression.
    /// </summary>
    /// <param name="arrayIndexer"></param>
    public ArrayIndexer Copy(IArrayIndexer arrayIndexer) {
      Contract.Requires(arrayIndexer != null);
      Contract.Ensures(Contract.Result<ArrayIndexer>() != null);

      var mutableCopy = this.shallowCopier.Copy(arrayIndexer);
      this.CopyChildren((Expression)mutableCopy);
      mutableCopy.IndexedObject = this.Copy(mutableCopy.IndexedObject);
      mutableCopy.Indices = this.Copy(mutableCopy.Indices);
      return mutableCopy;
    }
Beispiel #31
0
 /// <summary>
 /// Performs some computation with the given array indexer expression.
 /// </summary>
 /// <param name="arrayIndexer"></param>
 public virtual void Visit(IArrayIndexer arrayIndexer)
 {
     this.Visit((IExpression)arrayIndexer);
 }
Beispiel #32
0
    /// <summary>
    /// Returns a shallow copy of the given array indexer expression.
    /// </summary>
    /// <param name="arrayIndexer"></param>
    public ArrayIndexer Copy(IArrayIndexer arrayIndexer) {
      Contract.Requires(arrayIndexer != null);
      Contract.Ensures(Contract.Result<ArrayIndexer>() != null);

      return new ArrayIndexer(arrayIndexer);
    }
Beispiel #33
0
 public void Visit(IArrayIndexer arrayIndexer)
 {
     throw new NotImplementedException();
 }
 /// <summary>
 /// Performs some computation with the given array indexer expression.
 /// </summary>
 /// <param name="arrayIndexer"></param>
 public virtual void Visit(IArrayIndexer arrayIndexer)
 {
 }
 public override void Visit(IArrayIndexer arrayIndexer) {
   this.Visit(arrayIndexer.IndexedObject);
   this.Visit(arrayIndexer.Indices);
   //TODO            
 }
Beispiel #36
0
 /// <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);
 }
 public override void TraverseChildren(IArrayIndexer arrayIndexer) {
   this.Traverse(arrayIndexer.IndexedObject);
   this.sourceEmitterOutput.Write("[");
   this.Traverse(arrayIndexer.Indices);
   this.sourceEmitterOutput.Write("]");
 }
Beispiel #38
0
 /// <summary>
 /// Returns a deep copy of the given array indexer expression.
 /// </summary>
 /// <param name="arrayIndexer"></param>
 public ArrayIndexer Copy(IArrayIndexer arrayIndexer)
 {
     var mutableCopy = this.shallowCopier.Copy(arrayIndexer);
       this.CopyChildren((Expression)mutableCopy);
       mutableCopy.IndexedObject = this.Copy(mutableCopy.IndexedObject);
       mutableCopy.Indices = this.Copy(mutableCopy.Indices);
       return mutableCopy;
 }
Beispiel #39
0
 public override void TraverseChildren(IArrayIndexer arrayIndexer)
 {
     MethodEnter(arrayIndexer);
     base.TraverseChildren(arrayIndexer);
     MethodExit();
 }
Beispiel #40
0
 /// <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 (mutableArrayIndexer == null) return;
     this.resultExpression = this.myCodeMutator.Visit(mutableArrayIndexer);
 }