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

Function get_var_uninit_loc

src/ast/loc.rs:137–160  ·  view source on GitHub ↗

Get the source file offset of the begin and the end of this VarDecl. This source file range is used to delete a VarDecl.

(vd: &VarDecl, src_file: &Path)

Source from the content-addressed store, hash-verified

135/// Get the source file offset of the begin and the end of this VarDecl.
136/// This source file range is used to delete a VarDecl.
137pub fn get_var_uninit_loc(vd: &VarDecl, src_file: &Path) -> Result<(usize, usize)> {
138 if let Some(vd_loc) = get_bare_loc(&vd.loc) {
139 let vd_begin = get_sr_begin_loc(&vd.range)?;
140 let vd_end = get_sr_end_loc(&vd.range)?;
141 // if var before has other vd
142 if has_other_before_vd(vd_begin, vd_loc, src_file) {
143 let begin = get_pre_vd_begin(vd_loc, src_file)?;
144 let end = vd_end.offset + vd_end.tok_len;
145 return Ok((begin, end));
146 } else {
147 // if var after has other vd
148 if has_other_after_vd(vd_end, src_file) {
149 let begin = get_post_vd_begin(vd_loc, src_file)?;
150 let end = get_vd_end_offset(vd_end, src_file)? + 1;
151 return Ok((begin, end));
152 } else {
153 let begin = vd_begin.offset;
154 let end = get_vd_end_offset(vd_end, src_file)? + 1;
155 return Ok((begin, end));
156 }
157 }
158 }
159 eyre::bail!("cannot get loction for variable: {vd:?}")
160}
161
162pub fn get_source_code_range(sr: &SourceRange) -> Result<(usize, usize)> {
163 let begin = get_sr_begin_loc(sr)?;

Callers

nothing calls this directly

Calls 8

get_bare_locFunction · 0.85
get_sr_begin_locFunction · 0.85
get_sr_end_locFunction · 0.85
has_other_before_vdFunction · 0.85
get_pre_vd_beginFunction · 0.85
has_other_after_vdFunction · 0.85
get_post_vd_beginFunction · 0.85
get_vd_end_offsetFunction · 0.85

Tested by

no test coverage detected