Parse linetable to build a boolean mask indicating which code units have NO_LOCATION (line == -1). Returns a Vec of length `num_units`.
(linetable: &[u8], num_units: usize)
| 138 | /// Parse linetable to build a boolean mask indicating which code units |
| 139 | /// have NO_LOCATION (line == -1). Returns a Vec<bool> of length `num_units`. |
| 140 | pub fn build_no_location_mask(linetable: &[u8], num_units: usize) -> Vec<bool> { |
| 141 | let mut mask = Vec::new(); |
| 142 | mask.resize(num_units, false); |
| 143 | let mut pos = 0; |
| 144 | let mut unit_idx = 0; |
| 145 | |
| 146 | while pos < linetable.len() && unit_idx < num_units { |
| 147 | let header = linetable[pos]; |
| 148 | pos += 1; |
| 149 | let code = (header >> 3) & 0xf; |
| 150 | let length = ((header & 7) + 1) as usize; |
| 151 | |
| 152 | let is_no_location = code == PyCodeLocationInfoKind::None as u8; |
| 153 | |
| 154 | // Skip payload bytes based on location kind |
| 155 | match code { |
| 156 | 0..=9 => pos += 1, // Short forms: 1 byte payload |
| 157 | 10..=12 => pos += 2, // OneLine forms: 2 bytes payload |
| 158 | 13 => { |
| 159 | // NoColumns: signed varint (line delta) |
| 160 | while pos < linetable.len() { |
| 161 | let b = linetable[pos]; |
| 162 | pos += 1; |
| 163 | if b & 0x40 == 0 { |
| 164 | break; |
| 165 | } |
| 166 | } |
| 167 | } |
| 168 | 14 => { |
| 169 | // Long form: signed varint (line delta) + 3 unsigned varints |
| 170 | // line_delta |
| 171 | while pos < linetable.len() { |
| 172 | let b = linetable[pos]; |
| 173 | pos += 1; |
| 174 | if b & 0x40 == 0 { |
| 175 | break; |
| 176 | } |
| 177 | } |
| 178 | // end_line_delta, col+1, end_col+1 |
| 179 | for _ in 0..3 { |
| 180 | while pos < linetable.len() { |
| 181 | let b = linetable[pos]; |
| 182 | pos += 1; |
| 183 | if b & 0x40 == 0 { |
| 184 | break; |
| 185 | } |
| 186 | } |
| 187 | } |
| 188 | } |
| 189 | 15 => {} // None: no payload |
| 190 | _ => {} |
| 191 | } |
| 192 | |
| 193 | for _ in 0..length { |
| 194 | if unit_idx < num_units { |
| 195 | mask[unit_idx] = is_no_location; |
| 196 | unit_idx += 1; |
| 197 | } |
no test coverage detected