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

Function blankCKernelAnnotations

src/extraction/languages/c-cpp.ts:2365–2383  ·  view source on GitHub ↗
(source: string)

Source from the content-addressed store, hash-verified

2363 'g'
2364);
2365export function blankCKernelAnnotations(source: string): string {
2366 if (source.indexOf('__') === -1) return source;
2367 C_KERNEL_ANNOTATION_RE.lastIndex = 0;
2368 if (!C_KERNEL_ANNOTATION_RE.test(source)) return source;
2369 let out = source.replace(C_KERNEL_ANNOTATION_RE, (m) => ' '.repeat(m.length));
2370 // `container_of(ptr, struct T, member)` — the type-keyword argument is the
2371 // one call shape tree-sitter-c cannot read (a macro taking a TYPE), and it
2372 // is pervasive across the Linux tree. Blanking just the `struct`/`union`
2373 // keyword leaves `container_of(ptr, T, member)` — a plain
2374 // identifier argument the grammar parses natively. Keyed to the macro name
2375 // so no other `struct` keyword anywhere is ever touched.
2376 if (out.indexOf('container_of') !== -1) {
2377 out = out.replace(
2378 /(\bcontainer_of\s*\([^;()]*?,\s*)(struct|union)(\s+)/g,
2379 (_m, head: string, kw: string, ws: string) => head + ' '.repeat(kw.length) + ws
2380 );
2381 }
2382 return out;
2383}
2384
2385/**
2386 * Blank the PARAMETERIZED sparse/compiler annotations whole — name AND

Callers 2

preParseCSourceFunction · 0.85
extraction.test.tsFile · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected