MCPcopy Create free account
hub / github.com/colbymchenry/codegraph / scan_file

Function scan_file

codegraph-kernel/src/cfnptr.rs:1171–1263  ·  view source on GitHub ↗

Run the full extraction sweep for one file. `raw` is the file text exactly as the TS side read it; `structs` are the file's struct-node extents.

(raw: &str, structs: &[StructExtent])

Source from the content-addressed store, hash-verified

1169
1170/// Run the full extraction sweep for one file. `raw` is the file text exactly
1171/// as the TS side read it; `structs` are the file's struct-node extents.
1172pub fn scan_file(raw: &str, structs: &[StructExtent]) -> FileFacts {
1173 let raw_b = raw.as_bytes();
1174 let stripped = strip_c(raw_b);
1175 let s: &[u8] = &stripped;
1176
1177 let mut facts = FileFacts {
1178 fn_ptr_typedefs: Vec::new(),
1179 fn_type_typedefs: Vec::new(),
1180 structs: Vec::new(),
1181 inline_ptr: false,
1182 inline_types: Vec::new(),
1183 inline_tags: Vec::new(),
1184 init_tokens: Vec::new(),
1185 array_elems: Vec::new(),
1186 alias_names: Vec::new(),
1187 d_pairs: Vec::new(),
1188 dispatch_fields: Vec::new(),
1189 array_dispatch_names: Vec::new(),
1190 includes: Vec::new(),
1191 };
1192
1193 // Typedefs (gated like the JS sweep — purely a fast path, the scans find
1194 // nothing without the substring anyway).
1195 if contains_bytes(s, b"typedef") {
1196 scan_fnptr_typedefs(s, &mut facts.fn_ptr_typedefs);
1197 scan_fntype_typedefs(s, &mut facts.fn_type_typedefs);
1198 }
1199
1200 // Struct-node field declarations.
1201 if !structs.is_empty() {
1202 let lines = line_starts(s);
1203 for st in structs {
1204 let mut sf = StructFields { id: st.id.clone(), parsed: false, fields: Vec::new() };
1205 // sliceLinesPre: falsy startLine → '' (never parses). end_line
1206 // arrives with the TS side's `?? startLine` already applied; a
1207 // slice whose end ≤ start is empty, exactly like Array.slice.
1208 if st.start_line >= 1 {
1209 let a = (st.start_line - 1) as usize;
1210 let b = st.end_line as usize;
1211 if a < lines.len() && b > a {
1212 let body_start = lines[a];
1213 // End of line (b-1): next line start minus the `\n`, or EOF.
1214 let body_end = if b < lines.len() { lines[b] - 1 } else { s.len() };
1215 let body = &s[body_start..body_end.max(body_start)];
1216 if let Some(open) = body.iter().position(|&c| c == b'{') {
1217 if let Some(close) = match_brace(body, open) {
1218 sf.parsed = true;
1219 sf.fields = parse_struct_fields_raw(&body[open + 1..close]);
1220 }
1221 }
1222 }
1223 }
1224 facts.structs.push(sf);
1225 }
1226 }
1227
1228 // Registration filters.

Callers 2

cfnptr_scan_filesFunction · 0.85
factsFunction · 0.85

Calls 15

strip_cFunction · 0.85
contains_bytesFunction · 0.85
scan_fnptr_typedefsFunction · 0.85
scan_fntype_typedefsFunction · 0.85
match_braceFunction · 0.85
parse_struct_fields_rawFunction · 0.85
scan_inline_structsFunction · 0.85
dedup_in_orderFunction · 0.85
scan_anchoredFunction · 0.85
scan_alias_namesFunction · 0.85
scan_field_assignFunction · 0.85
scan_dispatchFunction · 0.85

Tested by

no test coverage detected