Get begin location of function body, where suitable to insert any VarDecl.
(&self)
| 303 | |
| 304 | /// Get begin location of function body, where suitable to insert any VarDecl. |
| 305 | pub fn get_function_body_begin_loc(&self) -> Result<usize> { |
| 306 | let mut worklist = WorkList::new(); |
| 307 | worklist.push(&self.ast); |
| 308 | while !worklist.empty() { |
| 309 | let curr = worklist.pop(); |
| 310 | if let Clang::CompoundStmt(cs) = &curr.kind { |
| 311 | let begin = get_sr_begin_loc(&cs.range)?; |
| 312 | let begin_loc = begin.offset + begin.tok_len; |
| 313 | return Ok(begin_loc); |
| 314 | } |
| 315 | worklist.push_childs(curr.get_childs()); |
| 316 | } |
| 317 | eyre::bail!("Cannot found suitable location to insert vardecl") |
| 318 | } |
| 319 | |
| 320 | /// get this var node in the updated ast. |
| 321 | pub fn get_var_node(&self, node: &Node) -> Result<&Node> { |
no test coverage detected