|
| 1 | +use serde_json::json; |
| 2 | + |
| 3 | +use crate::rustc_interface::middle::mir::BasicBlock; |
| 4 | +use crate::utils::json::ToJsonWithRepacker; |
| 5 | +use crate::utils::PlaceRepacker; |
| 6 | +use crate::DebugLines; |
| 7 | +use crate::{borrow_pcg::action::BorrowPCGAction, free_pcs::RepackOp}; |
| 8 | + |
| 9 | +#[derive(Debug)] |
| 10 | +pub struct PcgSuccessor<'tcx> { |
| 11 | + block: BasicBlock, |
| 12 | + owned_ops: Vec<RepackOp<'tcx>>, |
| 13 | + borrow_ops: Vec<BorrowPCGAction<'tcx>>, |
| 14 | +} |
| 15 | + |
| 16 | +impl<'tcx> PcgSuccessor<'tcx> { |
| 17 | + pub fn block(&self) -> BasicBlock { |
| 18 | + self.block |
| 19 | + } |
| 20 | + pub fn owned_ops(&self) -> &[RepackOp<'tcx>] { |
| 21 | + &self.owned_ops |
| 22 | + } |
| 23 | + pub fn borrow_ops(&self) -> &[BorrowPCGAction<'tcx>] { |
| 24 | + &self.borrow_ops |
| 25 | + } |
| 26 | + pub(crate) fn new( |
| 27 | + block: BasicBlock, |
| 28 | + owned_ops: Vec<RepackOp<'tcx>>, |
| 29 | + borrow_ops: Vec<BorrowPCGAction<'tcx>>, |
| 30 | + ) -> Self { |
| 31 | + Self { |
| 32 | + block, |
| 33 | + owned_ops, |
| 34 | + borrow_ops, |
| 35 | + } |
| 36 | + } |
| 37 | +} |
| 38 | + |
| 39 | +impl<'tcx> ToJsonWithRepacker<'tcx> for PcgSuccessor<'tcx> { |
| 40 | + fn to_json(&self, repacker: PlaceRepacker<'_, 'tcx>) -> serde_json::Value { |
| 41 | + json!({ |
| 42 | + "block": self.block().index(), |
| 43 | + "owned_ops": self.owned_ops().iter().map(|r| r.to_json()).collect::<Vec<_>>(), |
| 44 | + "borrow_ops": self.borrow_ops().iter().map(|a| a.to_json(repacker)).collect::<Vec<_>>(), |
| 45 | + }) |
| 46 | + } |
| 47 | +} |
| 48 | + |
| 49 | +impl<'tcx> DebugLines<PlaceRepacker<'_, 'tcx>> for PcgSuccessor<'tcx> { |
| 50 | + fn debug_lines(&self, repacker: PlaceRepacker<'_, 'tcx>) -> Vec<String> { |
| 51 | + let mut result = Vec::new(); |
| 52 | + result.push(format!("Block: {}", self.block().index())); |
| 53 | + result.extend(self.owned_ops().iter().map(|r| format!("{:?}", r))); |
| 54 | + result.extend(self.borrow_ops().iter().map(|a| a.debug_line(repacker))); |
| 55 | + result |
| 56 | + } |
| 57 | +} |
0 commit comments