Beispiel #1
0
def replace_while_with_body(codeast: c_ast.Node):
    if type(codeast) == c_ast.Compound:
        new_block_items = copy.deepcopy(codeast.block_items)
        for i in range(0, len(codeast.block_items)):
            if type(codeast.block_items[i]) == c_ast.While:
                # insert list in position i
                while_content = copy.deepcopy(
                    codeast.block_items[i].stmt.block_items)
                del new_block_items[i]
                new_block_items[i:i] = while_content

        codeast.block_items = new_block_items
Beispiel #2
0
    def try_handle_block(block: ca.Node, where: Optional[Loc]) -> None:
        if not isinstance(block, ca.Compound) or not block.block_items:
            return
        pragma = block.block_items[0]
        if not isinstance(pragma, ca.Pragma) or pragma.string != wanted_pragma:
            return

        args: List[Statement] = block.block_items[1:]
        stmts = perm.eval_statement_ast(args, seed)

        if where:
            where[0][where[1]:where[1] + 1] = stmts
        else:
            block.block_items = stmts
        raise _Done