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

Function scan_inline_structs

codegraph-kernel/src/cfnptr.rs:432–489  ·  view source on GitHub ↗
(s: &[u8])

Source from the content-addressed store, hash-verified

430 tags: Vec<String>,
431}
432
433fn scan_inline_structs(s: &[u8]) -> InlineScan {
434 let mut out = InlineScan { ptr: false, types: Vec::new(), tags: Vec::new() };
435 let mut last = 0;
436 // Where each keyword next stands, looked for again only once the scan has
437 // passed it. Looked for from `last` on every turn, the one a file does not
438 // use was searched for to the end of the file for each of the other: a
439 // header of twenty thousand structs and no union read itself that many times.
440 let mut next_struct = find_word(s, b"struct", 0);
441 let mut next_union = find_word(s, b"union", 0);
442 loop {
443 if next_struct.is_some_and(|at| at < last) {
444 next_struct = find_word(s, b"struct", last);
445 }
446 if next_union.is_some_and(|at| at < last) {
447 next_union = find_word(s, b"union", last);
448 }
449 let Some((t, keyword_len)) = (match (next_struct, next_union) {
450 (Some(st), Some(un)) if st < un => Some((st, 6)),
451 (Some(_), Some(un)) => Some((un, 5)),
452 (Some(st), None) => Some((st, 6)),
453 (None, Some(un)) => Some((un, 5)),
454 (None, None) => None,
455 }) else {
456 break;
457 };
458 let after_kw = t + keyword_len;
459 let ws = skip_jsws(s, after_kw);
460 if ws == after_kw || !is_word_at(s, ws) {
461 last = t + 1;
462 continue;
463 }
464 let te = word_end(s, ws);
465 let open = skip_jsws(s, te);
466 if s.get(open) != Some(&b'{') {
467 last = t + 1;
468 continue;
469 }
470 last = open + 1; // lastIndex = end of match (after `{`)
471 let Some(close) = match_brace(s, open) else { continue };
472 // vm: /^\s*(\w+)…/ on the text after `}` — only vm[1] matters here.
473 let v = skip_jsws(s, close + 1);
474 if !is_word_at(s, v) {
475 continue;
476 }
477 push_str(&mut out.tags, &s[ws..te]);
478 for f in parse_struct_fields_raw(&s[open + 1..close]) {
479 if f.name.is_empty() {
480 continue;
481 }
482 if f.ptr {
483 out.ptr = true;
484 } else if !f.ty.is_empty() {
485 out.types.push(f.ty);
486 }
487 }
488 }
489 out

Callers 1

scan_fileFunction · 0.85

Calls 9

find_wordFunction · 0.85
skip_jswsFunction · 0.85
is_word_atFunction · 0.85
match_braceFunction · 0.85
push_strFunction · 0.85
parse_struct_fields_rawFunction · 0.85
pushMethod · 0.80
word_endFunction · 0.70
getMethod · 0.65

Tested by

no test coverage detected