示例#1
0
 def build_while_body(self, while_block):
     all_tail_list = []
     ast_while_node = get_ast_node(self.as_tree, while_block.end_line)
     head_returned, tail_list = self.parse(ast_while_node.body)
     self.connect_2_blocks(while_block, head_returned)
     self.link_tail_to_cur_block(tail_list, while_block)
     all_tail_list.append(while_block)
     return all_tail_list
示例#2
0
    def test_get_ast_node_given_2_assign(self):
        as_tree = ast.parse(
            ms("""\
                    a = 3
                    a = 4
                    """))

        cfg_real = Cfg()
        node = get_ast_node(as_tree, 2)

        self.assertEqual(node, as_tree.body[1])
示例#3
0
    def test_get_ast_node_given_if(self):
        as_tree = ast.parse(
            ms("""\
                    a = 3
                    if a < 3:
                        z = 2
                    a = 4
                    """))

        cfg_real = Cfg()
        node = get_ast_node(as_tree, 3)

        self.assertEqual(node, as_tree.body[1].body[0])
示例#4
0
 def build_if_body(self, if_block):
     all_tail_list = []
     ast_if_node = get_ast_node(self.as_tree, if_block.end_line)
     head_returned, tail_list = self.parse(ast_if_node.body)
     self.connect_2_blocks(if_block, head_returned)
     all_tail_list.extend(tail_list)
     head_returned, tail_list = self.parse(ast_if_node.orelse)
     if head_returned is not None:
         # has an else or elif
         self.connect_2_blocks(if_block, head_returned)
         all_tail_list.extend(tail_list)
     else:
         # no else
         # link this to the next statement
         all_tail_list.append(if_block)
     return all_tail_list
示例#5
0
    def test_get_ast_node_given_if_elif_else(self):
        as_tree = ast.parse(
            ms("""\
                    a = 3
                    if a < 3:
                        z = 2
                    elif z < 2:
                        x = 2
                    else:
                        y = 2
                    a = 4
                    """))

        cfg_real = Cfg()
        node = get_ast_node(as_tree, 5)

        self.assertEqual(node, as_tree.body[1].orelse[0].body[0])
示例#6
0
 def get_var_ast(self, block):
     for i in range(block.start_line, block.end_line + 1):
         ast_stmt = get_ast_node(self.as_tree, i)
         var_ast = VarAst(ast_stmt)
         yield var_ast.targets_var, var_ast.values_var