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

Function scan_file

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

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