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 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125
use joker::track::*; use joker::token::{StringLiteral, NumberLiteral}; use id::Id; use expr::Expr; use stmt::StmtListItem; use patt::Patt; #[derive(Debug, PartialEq)] pub struct DotKey { pub location: Option<Span>, pub value: String } impl TrackingRef for DotKey { fn tracking_ref(&self) -> &Option<Span> { &self.location } } impl TrackingMut for DotKey { fn tracking_mut(&mut self) -> &mut Option<Span> { &mut self.location } } impl Untrack for DotKey { fn untrack(&mut self) { self.location = None; } } #[derive(Debug, PartialEq)] pub struct Prop { pub location: Option<Span>, pub key: PropKey, pub val: PropVal } impl TrackingRef for Prop { fn tracking_ref(&self) -> &Option<Span> { &self.location } } impl TrackingMut for Prop { fn tracking_mut(&mut self) -> &mut Option<Span> { &mut self.location } } impl Untrack for Prop { fn untrack(&mut self) { self.location = None; self.key.untrack(); self.val.untrack(); } } #[derive(Debug, PartialEq)] pub enum PropKey { Id(Option<Span>, String), String(Option<Span>, StringLiteral), Number(Option<Span>, NumberLiteral) } impl TrackingRef for PropKey { fn tracking_ref(&self) -> &Option<Span> { match *self { PropKey::Id(ref location, _) | PropKey::String(ref location, _) | PropKey::Number(ref location, _) => location } } } impl TrackingMut for PropKey { fn tracking_mut(&mut self) -> &mut Option<Span> { match *self { PropKey::Id(ref mut location, _) | PropKey::String(ref mut location, _) | PropKey::Number(ref mut location, _) => location } } } impl Untrack for PropKey { fn untrack(&mut self) { *self.tracking_mut() = None; } } #[derive(Debug, PartialEq)] pub enum PropVal { Init(Expr), Get(Option<Span>, Vec<StmtListItem>), Set(Option<Span>, Patt<Id>, Vec<StmtListItem>) } impl TrackingRef for PropVal { fn tracking_ref(&self) -> &Option<Span> { match *self { PropVal::Init(ref expr) => expr.tracking_ref(), PropVal::Get(ref location, _) | PropVal::Set(ref location, _, _) => location } } } impl TrackingMut for PropVal { fn tracking_mut(&mut self) -> &mut Option<Span> { match *self { PropVal::Init(ref mut expr) => expr.tracking_mut(), PropVal::Get(ref mut location, _) | PropVal::Set(ref mut location, _, _) => location } } } impl Untrack for PropVal { fn untrack(&mut self) { match *self { PropVal::Init(ref mut expr) => { expr.untrack(); } PropVal::Get(ref mut location, ref mut stmts) => { *location = None; stmts.untrack(); } PropVal::Set(ref mut location, ref mut patt, ref mut stmts) => { *location = None; patt.untrack(); stmts.untrack(); } } } }