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::analysis::{Analysis, scan::visitor::FnVisitor};
9use rustc_hir::def_id::LOCAL_CRATE;
10use rustc_middle::ty::TyCtxt;
11
12/// Scan Analysis - obtain basic information for crate
13pub struct ScanAnalysis<'tcx> {
14    tcx: TyCtxt<'tcx>,
15}
16
17impl<'tcx> Analysis for ScanAnalysis<'tcx> {
18    fn name(&self) -> &'static str {
19        "Scan Analysis"
20    }
21
22    fn run(&mut self) {
23        let crate_name = self.tcx.crate_name(LOCAL_CRATE);
24        let crate_type = self.tcx.crate_types()[0];
25        rap_info!("scan crate: {}", crate_name.as_str());
26        rap_info!("crate type: {}", crate_type);
27        let mut fn_visitor = FnVisitor::new(self.tcx);
28        self.tcx.hir_visit_all_item_likes_in_crate(&mut fn_visitor);
29        let stats = fn_visitor.statistic();
30        stats.info().print_log();
31    }
32
33    fn reset(&mut self) {}
34}
35
36impl<'tcx> ScanAnalysis<'tcx> {
37    pub fn new(tcx: TyCtxt<'tcx>) -> Self {
38        ScanAnalysis { tcx }
39    }
40}