MCPcopy Create free account
hub / github.com/FuzzAnything/PromptFuzz / extract_func_ast

Method extract_func_ast

src/execution/ast.rs:23–68  ·  view source on GitHub ↗

Extract ast for function.

(
        program: &Path,
        pch_list: Vec<PathBuf>,
        deopt: &Deopt,
        func: &str,
        use_fdp: bool,
    )

Source from the content-addressed store, hash-verified

21
22 /// Extract ast for function.
23 pub fn extract_func_ast(
24 program: &Path,
25 pch_list: Vec<PathBuf>,
26 deopt: &Deopt,
27 func: &str,
28 use_fdp: bool,
29 ) -> Result<Node> {
30 let ast_filter = format!("-ast-dump-filter={func}");
31 let include_path =
32 "-I".to_owned() + deopt.get_library_build_header_path()?.to_str().unwrap();
33
34 let mut binding = Command::new("clang++");
35 let mut cmd = binding
36 .arg("-fsyntax-only")
37 .arg("-Xclang")
38 .arg("-ast-dump=json")
39 .arg("-Xclang")
40 .arg(ast_filter)
41 .arg(include_path)
42 .arg(program);
43
44 for pch in pch_list {
45 cmd = cmd.arg("-include-pch").arg(pch);
46 }
47
48 if use_fdp {
49 let include_fdp = "-I".to_owned() + Deopt::get_fdp_path()?.to_str().unwrap();
50 cmd = cmd.arg(include_fdp);
51 }
52
53 //log::trace!("extract ast from {program:?}, cmd: {cmd:?}");
54
55 let output = cmd
56 .stdout(Stdio::piped())
57 .output()
58 .expect("failed to execute cmd.");
59 if output.status.success() {
60 let json_output = output.stdout.as_slice();
61 let node: Node = ast_dump_filter(json_output, func)?;
62 return Ok(node);
63 }
64 eyre::bail!(
65 "fail to extract from {program:?}\n, {}",
66 String::from_utf8_lossy(&output.stderr)
67 );
68 }
69
70 pub fn extract_program_ast(program: &Path) -> Result<Node> {
71 let mut binding = Command::new("clang++");

Callers

nothing calls this directly

Calls 2

ast_dump_filterFunction · 0.85

Tested by

no test coverage detected