MCPcopy Index your code
hub / github.com/Rust-API/Rust-API-Bypass-Checker / new

Method new

src/analysis/global_context.rs:108–310  ·  view source on GitHub ↗
(
        session: &'compilation Session,
        tcx: TyCtxt<'tcx>,
        analysis_options: AnalysisOption,
    )

Source from the content-addressed store, hash-verified

106
107impl<'tcx, 'compilation> GlobalContext<'tcx, 'compilation> {
108 pub fn new(
109 session: &'compilation Session,
110 tcx: TyCtxt<'tcx>,
111 analysis_options: AnalysisOption,
112 ) -> Option<Self> {
113 // ------------------------------------------------------------
114 // Phase 0: 枚举所有本地 MIR 函数(Fn/AssocFn)
115 // ------------------------------------------------------------
116
117 let mut all_entries: HashMap<LocalDefId, FuncInfo> = HashMap::new();
118
119 for &local_def_id in tcx.mir_keys(()).iter() {
120 let def_id = local_def_id.to_def_id();
121 let def_kind = tcx.def_kind(def_id);
122
123 if def_kind == DefKind::Fn || def_kind == DefKind::AssocFn {
124 let def_id_index = def_id.index.as_u32();
125 let def_path = tcx.def_path_str(def_id);
126
127 let is_builtin_derive: bool = match def_kind {
128 DefKind::Fn => false,
129 DefKind::AssocFn => {
130 if let Some(impl_id) = tcx.impl_of_method(def_id) {
131 tcx.is_builtin_derived(impl_id)
132 } else {
133 false
134 }
135 }
136 _ => false,
137 };
138
139 let info = FuncInfo {
140 def_id,
141 def_id_index,
142 def_kind,
143 func_name: def_path,
144 is_builtin_derive,
145 callees: Vec::new(),
146 api_count: 0,
147 api_vec: Vec::new(),
148 };
149 all_entries.insert(local_def_id, info);
150 }
151 }
152
153 // show_all_entries: 展示然后结束, 或者无分析项
154 if analysis_options.show_all_entries || all_entries.is_empty() {
155 for (_, info) in &all_entries {
156 info!("{:?}", info);
157 }
158 info!("The total function number: {}", &all_entries.len());
159 return None;
160 }
161
162
163 // entry_point:bin 有 main 就用 main;否则随便选一个占位(lib crate 常见)
164 // let entry_point = if let Some((entry_local, _entry_type)) = tcx.entry_fn(()) {
165 // entry_local

Callers

nothing calls this directly

Calls 6

pushMethod · 0.80
insertMethod · 0.45
is_emptyMethod · 0.45
into_iterMethod · 0.45
getMethod · 0.45
containsMethod · 0.45

Tested by

no test coverage detected