Exemple #1
0
 public void VisitSlice(SliceNode node)
 {
     UpdateLine(node);
     node.Array.Accept(this);
     node.Start.Accept(this);
     node.End.Accept(this);
     asm.Slice();
 }
 //write type the same as in array node and check if Left and Right have int type
 public override void Visit(SliceNode node)
 {
     base.Visit(node);
     if (!NamedTypeNode.IntType().Equals(node.Left.ExpressionType, false))
     {
         throw new TypeCheckException("Left is not int value.");
     }
     if (!NamedTypeNode.IntType().Equals(node.Right.ExpressionType, false))
     {
         throw new TypeCheckException("Right is not int value.");
     }
     node.ExpressionType = node.Array.ExpressionType;
     ((ArrayTypeNode)node.ExpressionType).IsFixedSize = false;
 }
        public override void Visit(SliceNode node)
        {
            base.Visit(node);

            if (!ReferenceEquals(node.Array, null))
            {
                node.Array.Accept(this);
            }

            if (node.HasLeft)
            {
                node.Left.Accept(this);
            }

            if (node.HasRight)
            {
                node.Right.Accept(this);
            }
        }
Exemple #4
0
        //Update and return subgraph with SliceNode
        public override SubExpressionGraph Visit(SliceNode node)
        {
            var sub_graph = new SubExpressionGraph();

            if (node.HasLeft)
            {
                node.Left = ProcessSingleNode(node.Left, ref sub_graph);
            }

            if (node.HasRight)
            {
                node.Right = ProcessSingleNode(node.Right, ref sub_graph);
            }

            if (!ReferenceEquals(node.Array, null))
            {
                ProcessSingleNode(node.Array, ref sub_graph);
            }

            sub_graph.LastNode = node;

            return(sub_graph);
        }
Exemple #5
0
        private ExpressionNode ParseBrackets()
        {
            var ret = ParseAtom();

            while (Accept(TokenType.LBRACK, TokenType.PERIOD, TokenType.LPAREN))
            {
                var zero   = new IntNode(Position(), 0);
                var length = new BinaryNode(Position(), BinaryOP.SUB, new UnaryNode(Position(), UnaryOP.LENGTH, ret), new IntNode(Position(), 1));

                var pos = Position();

                if (Accept(TokenType.LBRACK))
                {
                    Next();

                    if (Accept(TokenType.COLON))
                    {
                        Next();

                        if (Accept(TokenType.RBRACK))
                        {
                            Next();
                            ret = new SliceNode(pos, ret, zero, length);
                        }
                        else
                        {
                            var end = ParseExpression();

                            Expect(TokenType.RBRACK);
                            Next();

                            ret = new SliceNode(pos, ret, zero, end);
                        }
                    }
                    else
                    {
                        var start = ParseExpression();

                        if (Accept(TokenType.COLON))
                        {
                            Next();

                            if (Accept(TokenType.RBRACK))
                            {
                                Next();
                                ret = new SliceNode(pos, ret, start, length);
                            }
                            else
                            {
                                var end = ParseExpression();

                                Expect(TokenType.RBRACK);
                                Next();

                                ret = new SliceNode(pos, ret, start, end);
                            }
                        }
                        else
                        {
                            Expect(TokenType.RBRACK);
                            Next();

                            ret = new IndexNode(pos, ret, start);
                        }
                    }
                }
                else if (Accept(TokenType.PERIOD))
                {
                    Next();
                    ret = new IndexNode(Position(-1), ret, new StringNode(Position(), ParseIdent().Value));
                }
                else if (Accept(TokenType.LPAREN))
                {
                    Next();

                    var call = new CallNode(pos, ret);

                    while (More() && !Accept(TokenType.RPAREN))
                    {
                        call.Arguments.Add(ParseExpression());

                        if (Accept(TokenType.COMMA))
                        {
                            ExpectNot(TokenType.RPAREN);
                            Next();
                        }
                        else
                        {
                            Expect(TokenType.RPAREN);
                        }
                    }

                    Expect(TokenType.RPAREN);
                    Next();

                    ret = call;
                }
                else
                {
                    Unexpected();
                }
            }

            return(ret);
        }
Exemple #6
0
 public virtual T Visit(SliceNode node)
 {
     return(Visit(node as ExpressionNode));
 }
 public virtual void Visit(SliceNode node)
 {
     Visit(node as ExpressionNode);
 }
Exemple #8
0
 private bool HasSideEffects(SliceNode node)
 {
     return(false);
 }
Exemple #9
0
 public void VisitSlice(SliceNode node)
 {
     VisitSliceHandler(node);
 }
Exemple #10
0
        public void SliceNodesAreConstantIfTheArrayStartAndEndAreConstant()
        {
            subject = new SliceNode(new SourcePosition(2, 4), new StringNode(new SourcePosition(2, 5), "foo"), new IntNode(new SourcePosition(2, 6), 1), new IntNode(new SourcePosition(2, 6), 2));

            Assert.AreEqual(subject.IsConstant(), true);
        }
Exemple #11
0
 public SliceNodeTests()
 {
     subject = new SliceNode(new SourcePosition(2, 4), new IdentNode(new SourcePosition(2, 5), "foo"), new IntNode(new SourcePosition(2, 6), 42), new IntNode(new SourcePosition(2, 6), 21));
 }