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

Method extract_header_ast

src/execution/ast.rs:95–119  ·  view source on GitHub ↗
(header: &Path, deopt: &Deopt)

Source from the content-addressed store, hash-verified

93 }
94
95 pub fn extract_header_ast(header: &Path, deopt: &Deopt) -> Result<Node> {
96 let include_path =
97 "-I".to_owned() + deopt.get_library_build_header_path()?.to_str().unwrap();
98 let mut binding = Command::new("clang++");
99 let binding = binding
100 .arg("-fsyntax-only")
101 .arg("-Xclang")
102 .arg("-ast-dump=json")
103 .arg(include_path)
104 .arg(header);
105 let output = binding
106 .stdout(Stdio::piped())
107 .output()
108 .expect("failed to execute cmd.");
109 if output.status.success() {
110 let json_output = output.stdout.as_slice();
111 let node: Node = serde_json::from_slice(json_output)
112 .with_context(|| eyre::eyre!("fail to extract ast from {header:?}"))?;
113 return Ok(node);
114 }
115 eyre::bail!(
116 "fail to extract ast from {header:?}\n cmd:{binding:?}\n {}",
117 String::from_utf8_lossy(&output.stderr)
118 );
119 }
120}
121
122/// Filter the ast and only retain the node with function name as `func`.

Callers

nothing calls this directly

Calls 1

Tested by

no test coverage detected