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

Function blankCKernelAnnotations

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

Source from the content-addressed store, hash-verified

1166 'g'
1167);
1168export function blankCKernelAnnotations(source: string): string {
1169 if (source.indexOf('__') === -1) return source;
1170 C_KERNEL_ANNOTATION_RE.lastIndex = 0;
1171 if (!C_KERNEL_ANNOTATION_RE.test(source)) return source;
1172 let out = source.replace(C_KERNEL_ANNOTATION_RE, (m) => ' '.repeat(m.length));
1173 // `container_of(ptr, struct T, member)` — the type-keyword argument is the
1174 // one call shape tree-sitter-c cannot read (a macro taking a TYPE), and it
1175 // is pervasive across the Linux tree. Blanking just the `struct`/`union`
1176 // keyword leaves `container_of(ptr, T, member)` — a plain
1177 // identifier argument the grammar parses natively. Keyed to the macro name
1178 // so no other `struct` keyword anywhere is ever touched.
1179 if (out.indexOf('container_of') !== -1) {
1180 out = out.replace(
1181 /(\bcontainer_of\s*\([^;()]*?,\s*)(struct|union)(\s+)/g,
1182 (_m, head: string, kw: string, ws: string) => head + ' '.repeat(kw.length) + ws
1183 );
1184 }
1185 return out;
1186}
1187
1188/**
1189 * 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