Esempio n. 1
0
 protected PreresolvingDatumWriter(Schema schema, ArrayAccess arrayAccess, MapAccess mapAccess)
 {
     Schema       = schema;
     _arrayAccess = arrayAccess;
     _mapAccess   = mapAccess;
     _writer      = ResolveWriter(schema);
 }
        public bool Visit(ArrayAccess node)
        {
            if (node.SymType != null)
            {
                return(true);
            }

            node.ArrayIdent.Accept(this);
            foreach (var expression in node.AccessExpr)
            {
                expression.Accept(this);
                if (expression.SymType.GetType() != SymbolStack.SymInt.GetType())
                {
                    throw new Exception(string.Format(
                                            "({0}, {1}) semantic error: index '{2}' is not integer",
                                            expression.Token.Line, expression.Token.Line, expression.ToString()));
                }
            }

            if (node.ArrayIdent.SymType == null)
            {
                throw new Exception(string.Format(
                                        "({0}, {1}) semantic error: array type of expression '{2}' is undeclared",
                                        node.Token.Line, node.Token.Line, node.ToString()));
            }

            node.SymType  = ((SymArrayType)node.ArrayIdent.SymType).ElementSymType;
            node.IsLValue = true;
            return(true);
        }
Esempio n. 3
0
 public void Visit(ArrayAccess n)
 {
     n.Array.Accept(this);
     Helpers.Write("[");
     n.Index.Accept(this);
     Helpers.Write("]");
 }
Esempio n. 4
0
        public BitRange VisitArrayAccess(ArrayAccess acc)
        {
            var arr = acc.Array.Accept(this);
            var idx = acc.Index.Accept(this);

            return(arr | idx);
        }
Esempio n. 5
0
 protected IEncoder(Schema schema, ArrayAccess arrayAccess, MapAccess mapAccess)
 {
     Schema       = schema;
     _arrayAccess = arrayAccess;
     _mapAccess   = mapAccess;
     _writer      = ResolveWriter(schema);
 }
Esempio n. 6
0
        public bool VisitArrayAccess(ArrayAccess acc, TypeVariable tv)
        {
            MeetDataType(acc, acc.DataType);
            Expression arr;
            int        offset;

            if (fieldAccessPattern.Match(acc.Array))
            {
                arr    = fieldAccessPattern.CapturedExpression("p");
                offset = OffsetOf((Constant)fieldAccessPattern.CapturedExpression("c"));
            }
            else
            {
                arr    = acc.Array;
                offset = 0;
            }
            BinaryExpression b = acc.Index as BinaryExpression;
            int stride         = 1;

            if (b != null && (b.Operator == Operator.IMul || b.Operator == Operator.SMul || b.Operator == Operator.UMul))
            {
                Constant c = b.Right as Constant;
                if (c != null)
                {
                    stride = c.ToInt32();
                }
            }
            ArrayField(null, arr, arr.DataType.Size, offset, stride, 0, acc);
            acc.Array.Accept(this, acc.Array.TypeVariable);
            acc.Index.Accept(this, acc.Index.TypeVariable);
            return(false);
        }
        private ArrayAccess ParseArrayAccess()
        {
            var tx = _stream.Fixate();

            var id = ParseIdentifier(false);

            if (id == null)
            {
                return(null);
            }

            var t = NextToken();

            if (!t.IsDelimiter(Delimiter.BraceOpen))
            {
                _stream.Rollback(tx); // Undo brace and identifier read

                return(null);
            }

            var node = new ArrayAccess();

            node.AddChild(id);

            var expr = ParseExpression();

            node.AddChild(expr);

            t = NextToken();
            AssertDelimiter(Delimiter.BraceClose, t);

            node.PropagatePosition(t);

            return(node);
        }
Esempio n. 8
0
        private IADomain ReadTransfer(ReadStmt readStmt, IADomain domain)
        {
            var newDomain = CopyDomain(domain);

            if (domain.IsBottom())
            {
                return(newDomain);
            }

            var ident = readStmt.Left switch
            {
                VarAccess varAccess => varAccess.Left,
                ArrayAccess arrayAccess => arrayAccess.Left,
                RecordAccess recordAccess => recordAccess.Right,
            };

            if (readStmt.Left is ArrayAccess)
            {
                var ra            = readStmt.Left as ArrayAccess;
                var indexInterval = IAUtil.Arithmetic(ra.Right, domain);
                if (indexInterval.IsBottom)
                {
                    return(Bottom().GetDomain());
                }
            }

            newDomain[ident] = new Interval(ExtendedZ.NegativeInfinity(), ExtendedZ.PositiveInfinity()).ToIntervalK(_program);
            return(newDomain);
        }
        private (int Position, string Variable) _GetAccessor(ArrayAccess access)
        {
            var array = access.Expression;

            if (array.Accessors.Count == 0)
            {
                Debug.WriteLine($"unsupported amount of array accessors: {array.Accessors.Count}");
                throw new UnsupportedSyntaxException($"invalid number of dimensions for array access: {array}");
            }

            for (var i = 0; i < array.Accessors.Count; ++i)
            {
                var accessor = (array.Accessors[i] as VariableExpression)?.Name;
                if (accessor == null)
                {
                    continue;
                }

                var loopDependant = _loopDependenceAnalysis.Entry[access.Node]
                                    .Where(descriptor => descriptor.Kind is LoopDependent)
                                    .Where(descriptor => descriptor.Name.Equals(accessor))
                                    .Any();

                if (loopDependant)
                {
                    return(i, accessor);
                }
            }

            throw new UnsupportedSyntaxException($"array access does not make us of a loop dependant variable: {array}");
        }
Esempio n. 10
0
        public void InstanceIsNotEqualToCompletelyDifferent()
        {
            var access1 = new ArrayAccess(_CreateFlowNode(), _CreateArrayExpression(), true);
            var access2 = new ArrayAccess(_CreateFlowNode(), _CreateArrayExpression(), false);

            Assert.AreNotEqual(access1, access2);
        }
Esempio n. 11
0
        public DataType VisitArrayAccess(ArrayAccess acc)
        {
            DataType dtArr = acc.Array.Accept(this);
            DataType dtIdx = acc.Index.Accept(this);

            return(RecordDataType(acc.DataType, acc));
        }
Esempio n. 12
0
        public void InstanceHasNotSameHashCodeAsCompletelyDifferent()
        {
            var access1 = new ArrayAccess(_CreateFlowNode(), _CreateArrayExpression(), true);
            var access2 = new ArrayAccess(_CreateFlowNode(), _CreateArrayExpression(), false);

            Assert.AreNotEqual(access1.GetHashCode(), access2.GetHashCode());
        }
Esempio n. 13
0
        public virtual Expression VisitArrayAccess(ArrayAccess acc)
        {
            var a = acc.Array.Accept(this);
            var i = acc.Index.Accept(this);

            return(new ArrayAccess(acc.DataType, a, i));
        }
Esempio n. 14
0
 public virtual Expression VisitArrayAccess(ArrayAccess acc)
 {
     return(new ArrayAccess(
                acc.DataType,
                acc.Array.Accept(this),
                acc.Index.Accept(this)));
 }
Esempio n. 15
0
            public bool VisitArrayAccess(ArrayAccess acc)
            {
                var dead = acc.Array.Accept(this);

                dead &= acc.Index.Accept(this);
                return(dead);
            }
Esempio n. 16
0
            private List <Expression> ExtractFromArrayAccess(ArrayAccess access)
            {
                var binaryOperation = new BinaryOperation(access.InputRange, access.Lhs, access.Index);
                var result          = this.ExtractFromOperationNode(binaryOperation);

                (access.Lhs, access.Index) = (binaryOperation.LeftValue, binaryOperation.RightValue);
                return(result);
            }
Esempio n. 17
0
        public void InstanceIsNotEqualToOtherWithDifferentExpression()
        {
            var node    = _CreateFlowNode();
            var access1 = new ArrayAccess(node, _CreateArrayExpression(), false);
            var access2 = new ArrayAccess(node, _CreateArrayExpression(), false);

            Assert.AreNotEqual(access1, access2);
        }
Esempio n. 18
0
        public void InstanceIsNotEqualToOtherWithDifferentNode()
        {
            var expression = _CreateArrayExpression();
            var access1    = new ArrayAccess(_CreateFlowNode(), expression, true);
            var access2    = new ArrayAccess(_CreateFlowNode(), expression, true);

            Assert.AreNotEqual(access1, access2);
        }
Esempio n. 19
0
 public override bool Visit(ArrayAccess node)
 {
     Visit((LvalueExpression)node);
     TraversePrint(node.lvalue);
     TraversePrint(node.acessors);
     TraversePrint(node.array);
     return(true);
 }
Esempio n. 20
0
        public void InstanceHasNotSameHashCodeAsOtherWithDifferenExpression()
        {
            var node    = _CreateFlowNode();
            var access1 = new ArrayAccess(node, _CreateArrayExpression(), false);
            var access2 = new ArrayAccess(node, _CreateArrayExpression(), false);

            Assert.AreNotEqual(access1.GetHashCode(), access2.GetHashCode());
        }
Esempio n. 21
0
 public void EqbArrayAccess()
 {
     ArrayAccess e = new ArrayAccess(PrimitiveType.Real32, new Identifier("a", PrimitiveType.Ptr32, null), new Identifier("i", PrimitiveType.Int32, null));
     e.Accept(eqb);
     Assert.AreEqual("T_3", e.TypeVariable.ToString());
     Assert.AreEqual("T_1", e.Array.TypeVariable.ToString());
     Assert.AreEqual("T_2", e.Index.TypeVariable.ToString());
 }
Esempio n. 22
0
		public void EqbArrayAccess()
		{
            ArrayAccess e = new ArrayAccess(PrimitiveType.Real32, new Identifier("a", PrimitiveType.Pointer32, null), new Identifier("i", PrimitiveType.Int32, null));
			e.Accept(eqb);
			Assert.AreEqual("T_3", e.TypeVariable.ToString());
			Assert.AreEqual("T_1", e.Array.TypeVariable.ToString());
			Assert.AreEqual("T_2", e.Index.TypeVariable.ToString());
		}
Esempio n. 23
0
        public Result VisitArrayAccess(ArrayAccess acc)
        {
            var a      = acc.Array.Accept(this).PropagatedExpression;
            var i      = acc.Index.Accept(this).PropagatedExpression;
            var newAcc = new ArrayAccess(acc.DataType, a, i);

            return(SimplifyExpression(newAcc));
        }
Esempio n. 24
0
 public virtual T Visit(ArrayAccess node)
 {
     Visit((LvalueExpression)node);
     traverse(node.lvalue);
     traverse(node.acessors);
     traverse(node.array);
     return(DefaultReturnValue());
 }
Esempio n. 25
0
        public void InstanceHasSameHashCodeAsOtherWithSameInformation()
        {
            var expression = _CreateArrayExpression();
            var node       = _CreateFlowNode();
            var access1    = new ArrayAccess(node, expression, true);
            var access2    = new ArrayAccess(node, expression, true);

            Assert.AreEqual(access1.GetHashCode(), access2.GetHashCode());
        }
Esempio n. 26
0
        public void InstancesHaveNotSameHashCodeIfOneIsWritingAndOtherNot()
        {
            var expression = _CreateArrayExpression();
            var node       = _CreateFlowNode();
            var access1    = new ArrayAccess(node, expression, false);
            var access2    = new ArrayAccess(node, expression, true);

            Assert.AreNotEqual(access1.GetHashCode(), access2.GetHashCode());
        }
Esempio n. 27
0
        public void InstanceIsEqualToOtherWithSameInformation()
        {
            var expression = _CreateArrayExpression();
            var node       = _CreateFlowNode();
            var access1    = new ArrayAccess(node, expression, true);
            var access2    = new ArrayAccess(node, expression, true);

            Assert.AreEqual(access1, access2);
        }
Esempio n. 28
0
        public void InstanceIsNotEqualIfOneIsWritingAndOtherNot()
        {
            var expression = _CreateArrayExpression();
            var node       = _CreateFlowNode();
            var access1    = new ArrayAccess(node, expression, false);
            var access2    = new ArrayAccess(node, expression, true);

            Assert.AreNotEqual(access1, access2);
        }
Esempio n. 29
0
        public void VisitArrayAccess(ArrayAccess acc)
        {
            int prec = SetPrecedence(PrecedenceArrayAccess);

            acc.Array.Accept(this);
            ResetPresedence(prec);
            writer.Write("[");
            WriteExpression(acc.Index);
            writer.Write("]");
        }
Esempio n. 30
0
 public override Expression VisitArrayAccess(ArrayAccess acc)
 {
     if (acc.Array is BinaryExpression bin &&
         bin.Operator == Operator.IAdd &&
         bin.Right is Constant c)
     {
         // (x + C)[...]
         var arrayPtr = Rewrite(bin.Left, false);
         var index    = Rewrite(acc.Index, false);
         return(RewriteComplexExpression(arrayPtr, index, c.ToInt32(), true));
     }
Esempio n. 31
0
        public Expression VisitArrayAccess(ArrayAccess acc)
        {
            var arr = acc.Array.Accept(this);
            var idx = acc.Index.Accept(this);

            if (arr is InvalidConstant || idx is InvalidConstant)
            {
                return(InvalidConstant.Create(acc.DataType));
            }
            return(new ArrayAccess(acc.DataType, arr, idx));
        }
Esempio n. 32
0
		public virtual void VisitArrayAccess(ArrayAccess acc)
		{
			acc.Index.Accept(this);
			acc.Array.Accept(this);
		}
 public override Expression VisitArrayAccess(ArrayAccess acc)
 {
     BinaryExpression bin;
     Constant c;
     if (acc.Array.As(out bin) &&
         bin.Operator == Operator.IAdd &&
         bin.Right.As(out c))
     {
         // (x + C)[...]
         var arrayPtr = Rewrite(bin.Left, false);
         var index = Rewrite(acc.Index, false);
         return RewriteComplexExpression(arrayPtr, index, c.ToInt32(), true);
     }
     else
     {
         // (x)[...]
         var arrayPtr = Rewrite(acc.Array, false);
         var index = Rewrite(acc.Index, false);
         return RewriteComplexExpression(arrayPtr, index, 0, true);
     }
 }
Esempio n. 34
0
 public void VisitArrayAccess(ArrayAccess access)
 {
     handler.MemAccessTrait(basePointer, access, access.DataType.Size, eField, 0);
 }
Esempio n. 35
0
		public override void VisitArrayAccess(ArrayAccess acc)
		{
			acc.Array.Accept(this);
			acc.Index.Accept(this);
			EnsureTypeVariable(acc);
		}
Esempio n. 36
0
 void BODY_ARRAYACCESS(out pBaseLangObject outObj, pBaseLangObject parent)
 {
     var obj = new ArrayAccess(parent); outObj = obj; pBaseLangObject blo;
     Expect(12);
     VALUE(out blo, obj);
     obj.addChild(blo);
     Expect(13);
 }
Esempio n. 37
0
		public void VisitArrayAccess(ArrayAccess acc)
		{
			int prec = SetPrecedence(PrecedenceArrayAccess);
			acc.Array.Accept(this);
			ResetPresedence(prec);
			writer.Write("[");
			WriteExpression(acc.Index);
			writer.Write("]");
		}
Esempio n. 38
0
 public override Expression VisitArrayAccess(ArrayAccess acc)
 {
     var tmr = new TypedMemoryExpressionRewriter(prog);
     return tmr.RewriteArrayAccess(acc.TypeVariable, acc.Array, acc.Index);
 }