rapx/analysis/scan/
mod.rs

1mod statistic;
2/// NOTE: This analysis module is currently under development and is highly unstable.
3/// The #[allow(unused)] attribute is applied to suppress excessive lint warnings.
4/// Once the analysis stabilizes, this marker should be removed.
5
6#[allow(unused)]
7mod visitor;
8use crate::{
9    analysis::{scan::visitor::FnVisitor, Analysis},
10    rap_info,
11};
12use rustc_hir::def_id::LOCAL_CRATE;
13use rustc_middle::ty::TyCtxt;
14
15/// Scan Analysis - obtain basic information for crate
16pub struct ScanAnalysis<'tcx> {
17    tcx: TyCtxt<'tcx>,
18}
19
20impl<'tcx> Analysis for ScanAnalysis<'tcx> {
21    fn name(&self) -> &'static str {
22        "Scan Analysis"
23    }
24
25    fn run(&mut self) {
26        let crate_name = self.tcx.crate_name(LOCAL_CRATE);
27        let crate_type = self.tcx.crate_types()[0];
28        rap_info!("scan crate: {}", crate_name.as_str());
29        rap_info!("crate type: {}", crate_type);
30        let mut fn_visitor = FnVisitor::new(self.tcx);
31        self.tcx.hir_visit_all_item_likes_in_crate(&mut fn_visitor);
32        let stats = fn_visitor.statistic();
33        stats.info().print_log();
34    }
35
36    fn reset(&mut self) {}
37}
38
39impl<'tcx> ScanAnalysis<'tcx> {
40    pub fn new(tcx: TyCtxt<'tcx>) -> Self {
41        ScanAnalysis { tcx }
42    }
43}