public void ControlFlowExtractor_SimpleFunctionCallWithoutBlockExpression_Test()
        {
            //f(a, 2, [5, 3], 4, 5, b, a);
            BlockExpressionNode _block_expression = new BlockExpressionNode();

            _block_expression.Elements = new List <ExpressionNode> {
                Var("5"), Var("3")
            };
            FunctionCallNode _function_call = new FunctionCallNode();

            _function_call.Arguments = new List <ExpressionNode> {
                Var("a"),
                Var("2"),
                _block_expression,
                Var("4"),
                Var("5"),
                Var("b"),
                Var("a")
            };

            List <Vertex> cf_graph = new List <Vertex> (new ControlFlowExtractor().Extract(_function_call));

            Assert.AreEqual(3, cf_graph.Count);

            Assert.IsTrue(cf_graph [0].Expression is VariableUseNode);
            Assert.AreEqual("5", ((VariableUseNode)cf_graph [0].Expression).Name);
            Assert.IsTrue(cf_graph [1].Expression is VariableUseNode);
            Assert.AreEqual("3", ((VariableUseNode)cf_graph [1].Expression).Name);
            Assert.IsTrue(cf_graph [2].Expression is FunctionCallNode);
            Assert.IsTrue(((FunctionCallNode)cf_graph [2].Expression).Arguments [2] is VariableUseNode);
        }
 public override void Visit(BlockExpressionNode node)
 {
     variableSymbolTable.OpenBlock();
     functionSymbolTable.OpenBlock();
     base.Visit(node);
     variableSymbolTable.CloseBlock();
     functionSymbolTable.CloseBlock();
 }
예제 #3
0
                public override void Visit(BlockExpressionNode node)
                {
                    PushBlockScope(node);

                    base.Visit(node);

                    PopBlockScope();
                }
예제 #4
0
            public Brep.Node Build(BlockExpressionNode blockNode)
            {
                var seq = new List <Brep.Node>();

                foreach (var exp in blockNode.Elements)
                {
                    seq.Add(Build(exp as dynamic));
                }
                return(new Brep.SequenceNode(seq, null));                // TODO maybe set that jump later?
            }
예제 #5
0
        //Replace IfNodes and link sub_graph of childs
        public override SubExpressionGraph Visit(BlockExpressionNode node)
        {
            var sub_graph    = new SubExpressionGraph();
            var new_elements = new List <ExpressionNode>();

            VariableDefNode t = new VariableDefNode();

            t.ExpressionType = node.ExpressionType;
            t.Name           = "T" + temporary_counter;
            AtomNode _0 = new AtomNode(node.ExpressionType);

            _0.Value = "";
            t.Value  = _0;
            VariableUseNode t_use = new VariableUseNode();

            t_use.ExpressionType = node.ExpressionType;
            t_use.Declaration    = t;
            t_use.Name           = "T" + temporary_counter;

            if (!ReferenceEquals(node.Elements, null))
            {
                int counter = 0;
                foreach (var child in node.Elements)
                {
                    if (!ReferenceEquals(child, null))
                    {
                        var child_graph = child.Accept(this);
                        if (child_graph == null)
                        {
                            throw new Exception("SubGraph of child is null");
                        }
                        new_elements.Add(GetUpdatedExpressionNodeValue(child, child_graph));
                        if (counter == node.Elements.Count() - 1)
                        {
                            OperatorNode _temp_assing = new OperatorNode();
                            _temp_assing.Operator  = OperatorType.ASSIGN;
                            _temp_assing.Arguments = new List <ExpressionNode> {
                                t_use, child_graph.LastNode
                            };
                            child_graph.LastNode = _temp_assing;
                        }
                        child_graph = SubExpressionGraph.ConcatSubGraph(child_graph, SubExpressionGraph.CreateOneVertexSubGraph(child_graph.LastNode));
                        sub_graph   = SubExpressionGraph.ConcatSubGraph(sub_graph, child_graph);
                    }
                }
                node.Elements = new_elements;
            }

            sub_graph.ContainsExtracted = true;
            sub_graph.Temporary         = t_use;
            temporary_counter++;

            return(sub_graph);
        }
예제 #6
0
        //type is the last one element, if don't have set void
        public override void Visit(BlockExpressionNode node)
        {
            base.Visit(node);
            TypeNode last_element_type = NamedTypeNode.VoidType();

            foreach (var element in node.Elements)
            {
                last_element_type = element.ExpressionType;
            }
            node.ExpressionType = last_element_type;
        }
 public override void Visit(BlockExpressionNode node)
 {
     base.Visit(node);
     node.Elements = ReplaceChangedNodes(node.Elements);
     foreach (var expression in node.Elements)
     {
         OneJumpVertex next_vertex = new OneJumpVertex(null, expression);
         graph_vertex.Add(next_vertex);
         AddNextJump(next_vertex);
         nodes_to_next_jmp.Add(next_vertex);
     }
 }
        public override void Visit(BlockExpressionNode node)
        {
            base.Visit(node);

            if (!ReferenceEquals(node.Elements, null))
            {
                foreach (var child in node.Elements)
                {
                    if (!ReferenceEquals(child, null))
                    {
                        child.Accept(this);
                    }
                }
            }
        }
        public void ControlFlowExtractor_SimpleWhileInBlockExrpession_Test()
        {
            //[
            //a-while(a<3){a+1}else{a+3}+5;
            //a*2;
            //]

            OperatorNode a_less_3 = MakeOperator(OperatorType.LESS, Var("a"), Var("3"));
            OperatorNode a_plus_1 = Utils.Add(Var("a"), Var("1"));
            OperatorNode a_plus_5 = Utils.Add(Var("a"), Var("5"));
            WhileNode    _while   = new WhileNode();

            _while.Condition = a_less_3;
            _while.Body      = a_plus_1;
            _while.Else      = a_plus_5;
            OperatorNode _first_statement = Utils.Sub(Var("a"), Utils.Add(_while, Var("5")));

            OperatorNode _second_statement = MakeOperator(OperatorType.MUL, Var("a"), Var("2"));

            BlockExpressionNode _while_block = new BlockExpressionNode();

            _while_block.Elements = new List <ExpressionNode> {
                _first_statement, _second_statement
            };

            List <Vertex> cf_graph = new List <Vertex> (new ControlFlowExtractor().Extract(_while_block));

            Assert.AreEqual(6, cf_graph.Count);

            Assert.IsTrue(cf_graph [0].Expression is OperatorNode);
            Assert.IsTrue(cf_graph [1].Expression is OperatorNode);
            Assert.IsTrue(cf_graph [2].Expression is OperatorNode);
            Assert.IsTrue(cf_graph [3].Expression is VariableUseNode);
            Assert.IsTrue(cf_graph [4].Expression is OperatorNode);
            Assert.AreEqual(OperatorType.MINUS, ((OperatorNode)cf_graph [4].Expression).Operator);
            Assert.IsTrue(cf_graph [5].Expression is OperatorNode);
            Assert.AreEqual(OperatorType.MUL, ((OperatorNode)cf_graph [5].Expression).Operator);

            Assert.IsTrue(cf_graph [0] is ConditionalJumpVertex);
        }
        public void ControlFlowExtractor_SimpleIfInBlockExpression_Test()
        {
            //[
            //a+2;
            //a+(if(a>3){a+2;}else{a+5;})+5;
            //]

            OperatorNode first_statement = Utils.Add(Var("a"), Var("2"));
            OperatorNode _a_gret_3       = MakeOperator(OperatorType.GREATER, Var("a"), Var("3"));
            OperatorNode _a_plus_2       = Utils.Add(Var("a"), Var("2"));
            OperatorNode _a_plus_5       = Utils.Add(Var("a"), Var("5"));
            IfNode       _if             = new IfNode();

            _if.Condition = _a_gret_3;
            _if.Then      = _a_plus_2;
            _if.Else      = _a_plus_5;
            OperatorNode        second_statement = Utils.Add(Var("a"), Utils.Add(_if, Var("5")));
            BlockExpressionNode _if_block        = new BlockExpressionNode();

            _if_block.Elements = new List <ExpressionNode> {
                first_statement, second_statement
            };

            List <Vertex> cf_graph = new List <Vertex> (new ControlFlowExtractor().Extract(_if_block));

            Assert.AreEqual(6, cf_graph.Count);

            Assert.IsTrue(cf_graph [0].Expression is OperatorNode);
            Assert.IsTrue(cf_graph [1].Expression is OperatorNode);
            Assert.IsTrue(cf_graph [2].Expression is OperatorNode);
            Assert.IsTrue(cf_graph [3].Expression is OperatorNode);
            Assert.IsTrue(cf_graph [4].Expression is VariableUseNode);
            Assert.IsTrue(cf_graph [5].Expression is OperatorNode);

            Assert.IsTrue(cf_graph [1] is ConditionalJumpVertex);
        }
예제 #11
0
 public virtual void Visit(BlockExpressionNode node)
 {
     Visit(node as ExpressionNode);
 }
예제 #12
0
 private bool HasSideEffects(BlockExpressionNode node)
 {
     return(false);
 }
예제 #13
0
 public void Descend(BlockExpressionNode block)
 {
     _depths.Add(block, _depth++);
 }
예제 #14
0
 public virtual T Visit(BlockExpressionNode node)
 {
     return(Visit(node as ExpressionNode));
 }
예제 #15
0
 internal static FunctionDefinitionNode FunctionDef(string name, IEnumerable <VariableDeclNode> parameters, NamedTypeNode type, BlockExpressionNode body)
 {
     return(new FunctionDefinitionNode {
         Name = name,
         Parameters = parameters,
         ResultType = type,
         Body = body
     });
 }
예제 #16
0
 public int GetDepth(BlockExpressionNode block)
 {
     return(_depths[block]);
 }
예제 #17
0
 void PushBlockScope(BlockExpressionNode node)
 {
     _scope = new BlockScope(_scope, node);
     _scope.Function !.Descend(node);
 }
예제 #18
0
 public BlockScope(Scope previous, BlockExpressionNode node)
     : base(previous)
 {
     Node = node;
 }