1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59
use std::fmt::{Debug, Error, Formatter}; use std::ops::Deref; use std::sync::Arc; use crate::atn::ATN; use crate::dfa::DFA; use crate::prediction_context::PredictionContext; use crate::prediction_context::PredictionContextCache; pub trait IATNSimulator { fn shared_context_cache(&self) -> &PredictionContextCache; fn atn(&self) -> &ATN; fn decision_to_dfa(&self) -> &Vec<DFA>; } pub struct BaseATNSimulator { pub atn: Arc<ATN>, pub shared_context_cache: Arc<PredictionContextCache>, pub decision_to_dfa: Arc<Vec<DFA>>, } impl Debug for BaseATNSimulator { fn fmt(&self, f: &mut Formatter<'_>) -> Result<(), Error> { f.write_str("BaseATNSimulator { .. }") } } impl BaseATNSimulator { pub fn new_base_atnsimulator( atn: Arc<ATN>, decision_to_dfa: Arc<Vec<DFA>>, shared_context_cache: Arc<PredictionContextCache>, ) -> BaseATNSimulator { BaseATNSimulator { atn, shared_context_cache, decision_to_dfa, } } fn get_cached_context(&self, _context: Box<PredictionContext>) -> &PredictionContext { unimplemented!() } } impl IATNSimulator for BaseATNSimulator { fn shared_context_cache(&self) -> &PredictionContextCache { self.shared_context_cache.deref() } fn atn(&self) -> &ATN { self.atn.as_ref() } fn decision_to_dfa(&self) -> &Vec<DFA> { self.decision_to_dfa.as_ref() } }