def solve(ast_str, file_path="", float_config=None):
    args = float_config or config.ConfigNamespace()
    with utilities.temp_config(MANAGER, args):
        MANAGER.reload_protocol()
        as_tree = MANAGER.build_tree(ast_str)
        MANAGER.apply_transform(as_tree)
        cfg_ir = cfg.Cfg(as_tree)
        cfg_ir.apply_transform()
        cfg_ir.convert_to_ssa()
        return loop_solver.solve(cfg_ir, as_tree, ast_str, file_path, args)
Beispiel #2
0
 def run_result_return(self, ast_str, **kwargs):
     config = self.init_solver(**kwargs)
     MANAGER.register_transform(nodes.FunctionDef, transform_init,
                                lambda x: x.name == "init")
     MANAGER.register_transform(nodes.Subscript, _infer_end_subscript,
                                is_cfg)
     with utilities.temp_config(MANAGER, config):
         as_tree = self.cov_manager.build_tree(ast_str)
         c = self.cov_manager.build_cfg(as_tree)
         df = solver.DepFinder(c, as_tree)
         df.solve_classdef()
         for cls in df.classes:
             top_level = cls.get_latest_stmt(df.entry_func)
             yield from top_level.infer_return_value(df.context)
def solve(ast_str, config=None):
    cov_config = config or ConfigNamespace()
    with utilities.temp_config(MANAGER, cov_config):
        MANAGER.reload_protocol()
        as_tree = MANAGER.build_tree(ast_str)
        MANAGER.apply_transform(as_tree)
        c = cfg.Cfg(as_tree)
        c.apply_transform()
        c.convert_to_ssa()
        c.fill_all_conditions()
        df = LineFix(c, as_tree)
        if cov_config.cover_lines:
            df.fix_selected_lines(cov_config.cover_lines)
        elif cov_config.cover_all:
            df.fix_all()
        return df.analyze_phi()
Beispiel #4
0
def solve(ast_str, cov_config=None):
    cov_config = cov_config or config.ConfigNamespace()
    with utilities.temp_config(MANAGER, cov_config):
        as_tree = MANAGER.build_tree(ast_str)
        c = MANAGER.build_cfg(as_tree)
        df = DepFinder(c, as_tree)
        df.solve_classdef()
        if cov_config.html_server:
            if not infer_server:
                MANAGER.logger.warning("SERVER", "Please install `flask` to proceed with invoking infer server")
            else:
                MANAGER.logger.info("Running html debugging server. Skipping conditions solver")
                reporter = report.CovAnalysisHtmlReport("", ast_str, as_tree)
                infer_server.run(cov_config.html_server_port, reporter, df.context)
        else:
            return df.analyze_phi(use_z3_check=True)
        df.uninitialize()
 def xtest_infer_simple(self):
     args = config.ConfigNamespace()
     with utilities.temp_config(MANAGER, args):
         ast_str = dedent("""\
                     z = 3
                     x = z * 4.5
                     x = x + 1
                     if z >= 6:     # will not flag
                         y = 60
                     elif x != 1:   # will flag
                         y = 2.5
                     else:
                         y = 3
                         if (x + 5) == 867:   # will flag
                             x = 987
                             k = y == 90   # will not flag
                     z = y == (z != 1.5)   # will flag twice
                         """)
         tree, _ = self.build_tree_cfg(ast_str)
         hr = report.HtmlReporter("", ast_str, None, tree)
         list(hr.tokenize_source())
         result = list(hr.infer(3, 4))
         pass
def run(args, output_stream=sys.stdout, error_stream=sys.stderr):
    MANAGER.config = args
    if args.verbose >= 1:
        cli.print_info(args, output_stream=output_stream)
    result = ""
    for fn in args.file_name:
        file_path = pathlib.Path(fn)
        text = file_path.read_text().expandtabs(8)
        file_path_text = file_path.resolve().as_uri()
        MANAGER.logger.info("FCF", "analyzing file: {}\n", file_path_text)
        with utilities.temp_config(MANAGER, args):
            MANAGER.reload_protocol()
            as_tree = MANAGER.build_tree(text)
            MANAGER.apply_transform(as_tree)
            cfg_ir = cfg.Cfg(as_tree)
            cfg_ir.apply_transform()
            cfg_ir.convert_to_ssa()
            for checker_mod in get_checker(args):
                result += checker_mod.solve(cfg_ir, as_tree, text,
                                            file_path_text, args)
    MANAGER.logger.info("COV", MANAGER.get_infer_statistics())
    if result:
        error_stream.write(result)
        sys.exit(1)