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

Function scan_inline_structs

codegraph-kernel/src/cfnptr.rs:432–479  ·  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 loop {
437 let next_struct = find_word(s, b"struct", last);
438 let next_union = find_word(s, b"union", last);
439 let Some((t, keyword_len)) = (match (next_struct, next_union) {
440 (Some(st), Some(un)) if st < un => Some((st, 6)),
441 (Some(_), Some(un)) => Some((un, 5)),
442 (Some(st), None) => Some((st, 6)),
443 (None, Some(un)) => Some((un, 5)),
444 (None, None) => None,
445 }) else {
446 break;
447 };
448 let after_kw = t + keyword_len;
449 let ws = skip_jsws(s, after_kw);
450 if ws == after_kw || !is_word_at(s, ws) {
451 last = t + 1;
452 continue;
453 }
454 let te = word_end(s, ws);
455 let open = skip_jsws(s, te);
456 if s.get(open) != Some(&b'{') {
457 last = t + 1;
458 continue;
459 }
460 last = open + 1; // lastIndex = end of match (after `{`)
461 let Some(close) = match_brace(s, open) else { continue };
462 // vm: /^\s*(\w+)…/ on the text after `}` — only vm[1] matters here.
463 let v = skip_jsws(s, close + 1);
464 if !is_word_at(s, v) {
465 continue;
466 }
467 push_str(&mut out.tags, &s[ws..te]);
468 for f in parse_struct_fields_raw(&s[open + 1..close]) {
469 if f.name.is_empty() {
470 continue;
471 }
472 if f.ptr {
473 out.ptr = true;
474 } else if !f.ty.is_empty() {
475 out.types.push(f.ty);
476 }
477 }
478 }
479 out
480}
481
482/// matchBrace: index of the `}` matching the `{` at `open`, or None.

Callers 1

scan_fileFunction · 0.85

Calls 8

find_wordFunction · 0.85
skip_jswsFunction · 0.85
is_word_atFunction · 0.85
word_endFunction · 0.85
match_braceFunction · 0.85
push_strFunction · 0.85
parse_struct_fields_rawFunction · 0.85
getMethod · 0.65

Tested by

no test coverage detected