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

Function remove_duplicate_definition

src/execution/ast.rs:185–203  ·  view source on GitHub ↗

LLMs tends to re-declare the provided API in code. Those duplicate definitions cause link error, thus those duplicated definitions need to be removed.

(program: &Path)

Source from the content-addressed store, hash-verified

183/// LLMs tends to re-declare the provided API in code.
184/// Those duplicate definitions cause link error, thus those duplicated definitions need to be removed.
185pub fn remove_duplicate_definition(program: &Path) -> Result<()> {
186 let ast = Executor::extract_program_ast(program)?;
187 let mut del_ranges = vec![];
188 for child in &ast.inner {
189 if let Clang::FunctionDecl(fd) = &child.kind {
190 let name = fd.get_name();
191 if get_func_gadget(&name).is_some() {
192 del_ranges.push(fd.range.clone());
193 }
194 }
195 }
196 let mut content = std::fs::read_to_string(program)?;
197 for sr in del_ranges.iter().rev() {
198 let (begin, end) = get_source_code_range(sr)?;
199 content.replace_range(begin..end + 1, "");
200 }
201 std::fs::write(program, content)?;
202 Ok(())
203}
204
205#[test]
206fn test_ast_dump_filter() -> Result<()> {

Callers 3

save_programMethod · 0.85
save_succ_programMethod · 0.85

Calls 4

get_func_gadgetFunction · 0.85
get_source_code_rangeFunction · 0.85
get_nameMethod · 0.45
pushMethod · 0.45

Tested by

no test coverage detected