Build a mapping from instruction index to line number. Returns -1 for indices with no line start.
(code: &bytecode::CodeObject<C>)
| 394 | /// Build a mapping from instruction index to line number. |
| 395 | /// Returns -1 for indices with no line start. |
| 396 | pub fn mark_lines<C: Constant>(code: &bytecode::CodeObject<C>) -> Vec<i32> { |
| 397 | let len = code.instructions.len(); |
| 398 | let mut line_starts = vec![-1i32; len]; |
| 399 | let mut last_line: i32 = -1; |
| 400 | |
| 401 | for (i, (loc, _)) in code.locations.iter().enumerate() { |
| 402 | if i >= len { |
| 403 | break; |
| 404 | } |
| 405 | let line = loc.line.get() as i32; |
| 406 | if line != last_line && line > 0 { |
| 407 | line_starts[i] = line; |
| 408 | last_line = line; |
| 409 | } |
| 410 | } |
| 411 | line_starts |
| 412 | } |
| 413 | |
| 414 | /// Find the first line number >= `line` that has code. |
| 415 | pub fn first_line_not_before(lines: &[i32], line: i32) -> i32 { |
no test coverage detected