find the source code locations range of the ParamVarDecls of function specified with name of fd_name. The range starts from the declaration of the first Param and ends with the end of the last Param.
(&self, fd_name: &str, src_file: &Path)
| 94 | /// find the source code locations range of the ParamVarDecls of function specified with name of fd_name. |
| 95 | /// The range starts from the declaration of the first Param and ends with the end of the last Param. |
| 96 | pub fn get_fd_param_loc(&self, fd_name: &str, src_file: &Path) -> Result<(usize, usize)> { |
| 97 | if let Some(fd_node) = self.find_fd(fd_name) { |
| 98 | if let Clang::FunctionDecl(fd) = &fd_node.kind { |
| 99 | if fd.has_params(fd_node) { |
| 100 | let params = fd.get_params(fd_node); |
| 101 | let first_param = *params.first().unwrap(); |
| 102 | let last_param = *params.last().unwrap(); |
| 103 | let begin = get_sr_begin_loc(&first_param.range)?; |
| 104 | let end = get_sr_end_loc(&last_param.range)?; |
| 105 | let begin_loc = begin.offset; |
| 106 | let end_loc = end.offset + end.tok_len; |
| 107 | return Ok((begin_loc, end_loc)); |
| 108 | } else { |
| 109 | // no params: return locs of "()" or "(void)" |
| 110 | let begin = fd.loc.clone(); |
| 111 | let begin_loc = get_bare_loc(&begin) |
| 112 | .ok_or_else(|| eyre::eyre!("cannot get ParamLoction from: {fd:?}"))?; |
| 113 | let begin_offset = begin_loc.offset + begin_loc.tok_len; |
| 114 | let ty = &std::fs::read_to_string(src_file)?[begin_offset..]; |
| 115 | let ty_len = ty.find(')').unwrap() - ty.find('(').unwrap() - 1; |
| 116 | let begin_loc = begin_offset + 1; |
| 117 | let end_loc = begin_loc + ty_len; |
| 118 | return Ok((begin_loc, end_loc)); |
| 119 | } |
| 120 | } |
| 121 | } |
| 122 | eyre::bail!("cannot find a fd with name: {fd_name:?}") |
| 123 | } |
| 124 | |
| 125 | pub fn find_vardecl(&self, var_name: &str) -> Option<&Node> { |
| 126 | let mut worklist = WorkList::new(); |
no test coverage detected