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

Function scan_file

codegraph-kernel/src/cfnptr.rs:1181–1273  ·  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

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