Compile expr into self.insts, returning a patch on success, or an error if we run out of memory. All of the c_* methods of the compiler share the contract outlined here. The main thing that a c_* method does is mutate `self.insts` to add a list of mostly compiled instructions required to execute the given expression. `self.insts` contains MaybeInsts rather than Insts because there is some backpa
(&mut self, expr: &Hir)
| 256 | /// a list of expressions rather than just the two that we use for |
| 257 | /// an example. |
| 258 | fn c(&mut self, expr: &Hir) -> Result { |
| 259 | use prog; |
| 260 | use syntax::hir::HirKind::*; |
| 261 | |
| 262 | self.check_size()?; |
| 263 | match *expr.kind() { |
| 264 | Empty => Ok(Patch { hole: Hole::None, entry: self.insts.len() }), |
| 265 | Literal(hir::Literal::Unicode(c)) => { |
| 266 | self.c_char(c) |
| 267 | } |
| 268 | Literal(hir::Literal::Byte(b)) => { |
| 269 | assert!(self.compiled.uses_bytes()); |
| 270 | self.c_byte(b) |
| 271 | } |
| 272 | Class(hir::Class::Unicode(ref cls)) => { |
| 273 | self.c_class(cls.ranges()) |
| 274 | } |
| 275 | Class(hir::Class::Bytes(ref cls)) => { |
| 276 | if self.compiled.uses_bytes() { |
| 277 | self.c_class_bytes(cls.ranges()) |
| 278 | } else { |
| 279 | assert!(cls.is_all_ascii()); |
| 280 | let mut char_ranges = vec![]; |
| 281 | for r in cls.iter() { |
| 282 | let (s, e) = (r.start() as char, r.end() as char); |
| 283 | char_ranges.push(hir::ClassUnicodeRange::new(s, e)); |
| 284 | } |
| 285 | self.c_class(&char_ranges) |
| 286 | } |
| 287 | } |
| 288 | Anchor(hir::Anchor::StartLine) if self.compiled.is_reverse => { |
| 289 | self.byte_classes.set_range(b'\n', b'\n'); |
| 290 | self.c_empty_look(prog::EmptyLook::EndLine) |
| 291 | } |
| 292 | Anchor(hir::Anchor::StartLine) => { |
| 293 | self.byte_classes.set_range(b'\n', b'\n'); |
| 294 | self.c_empty_look(prog::EmptyLook::StartLine) |
| 295 | } |
| 296 | Anchor(hir::Anchor::EndLine) if self.compiled.is_reverse => { |
| 297 | self.byte_classes.set_range(b'\n', b'\n'); |
| 298 | self.c_empty_look(prog::EmptyLook::StartLine) |
| 299 | } |
| 300 | Anchor(hir::Anchor::EndLine) => { |
| 301 | self.byte_classes.set_range(b'\n', b'\n'); |
| 302 | self.c_empty_look(prog::EmptyLook::EndLine) |
| 303 | } |
| 304 | Anchor(hir::Anchor::StartText) if self.compiled.is_reverse => { |
| 305 | self.c_empty_look(prog::EmptyLook::EndText) |
| 306 | } |
| 307 | Anchor(hir::Anchor::StartText) => { |
| 308 | self.c_empty_look(prog::EmptyLook::StartText) |
| 309 | } |
| 310 | Anchor(hir::Anchor::EndText) if self.compiled.is_reverse => { |
| 311 | self.c_empty_look(prog::EmptyLook::StartText) |
| 312 | } |
| 313 | Anchor(hir::Anchor::EndText) => { |
| 314 | self.c_empty_look(prog::EmptyLook::EndText) |
| 315 | } |
no test coverage detected