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

Function blankCDesignatedMacroArgs

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

Source from the content-addressed store, hash-verified

2738 * point, so both the wasm and kernel C arms see the same bytes.
2739 */
2740export function blankCDesignatedMacroArgs(source: string): string {
2741 if (source.indexOf('=') === -1) return source;
2742 const rawStrings = maskCppRawStrings(source);
2743 source = rawStrings.source;
2744 let out: string[] | null = null;
2745 const re = /^[ \t]*([A-Z_][A-Z0-9_]*)\s*\(/gm;
2746 let m: RegExpExecArray | null;
2747 while ((m = re.exec(source))) {
2748 const open = m.index + m[0].length - 1;
2749 let depth = 1;
2750 let i = open + 1;
2751 for (; i < source.length && depth > 0; i++) {
2752 const c = source[i];
2753 if (c === '(') depth++;
2754 else if (c === ')') depth--;
2755 }
2756 if (depth !== 0) continue;
2757 const close = i - 1;
2758 const args = source.slice(open + 1, close);
2759 // A designator at argument depth: `.name =` or `[index] =`.
2760 if (!/(^|[,{(\s])(\.[A-Za-z_]\w*|\[[^\]]+\])\s*=[^=]/.test(args)) continue;
2761 if (!/^\s*;/.test(source.slice(close + 1))) continue;
2762 out ??= source.split('');
2763 for (let k = open + 1; k < close; k++) if (out[k] !== '\n') out[k] = ' ';
2764 re.lastIndex = close;
2765 }
2766 return rawStrings.restore(out ? out.join('') : source);
2767}
2768
2769/**
2770 * Open up a `#if … #elif … #else … #endif` group whose branches are not

Callers 3

preParseCSourceFunction · 0.85
extraction.test.tsFile · 0.85

Calls 4

maskCppRawStringsFunction · 0.85
restoreMethod · 0.80
execMethod · 0.65
joinMethod · 0.45

Tested by

no test coverage detected