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

Function blankCStatementMacroCalls

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

Source from the content-addressed store, hash-verified

2129}
2130
2131export function blankCStatementMacroCalls(source: string): string {
2132 const rawStrings = maskCppRawStrings(source);
2133 source = rawStrings.source;
2134 const lines = source.split('\n');
2135 let changed = false;
2136 let statementLines: boolean[] | null = null;
2137 const content = (l: string): string => l.replace(/\r$/, '').trim();
2138 for (let i = 0; i < lines.length; i++) {
2139 const line = lines[i] as string;
2140 // Lowercase iterator macros, or an all-caps block macro
2141 // (`ATOMIC_BLOCK(NVIC_PRIO_MAX) {`, `PG_FOREACH(reg) {` — betaflight);
2142 // a PascalCase name is left alone (a constructor, if the file is C++).
2143 const m = /^[ \t]+([a-z_][a-z0-9_]*|[A-Z_][A-Z0-9_]*)[ \t]*\(/.exec(line);
2144 if (!m || C_STMT_MACRO_KEYWORDS.has(m[1] as string)) continue;
2145 const open = line.indexOf('(', m[0].length - 1);
2146 let depth = 0;
2147 let close = -1;
2148 for (let k = open; k < line.length; k++) {
2149 const ch = line[k];
2150 if (ch === '"' || ch === "'") {
2151 const quote = ch;
2152 k++;
2153 while (k < line.length && line[k] !== quote) {
2154 if (line[k] === '\\') k++;
2155 k++;
2156 }
2157 continue;
2158 }
2159 if (ch === '(') depth++;
2160 else if (ch === ')') {
2161 depth--;
2162 if (depth === 0) {
2163 close = k;
2164 break;
2165 }
2166 }
2167 }
2168 let endLine = i;
2169 if (close < 0) {
2170 // Parens don't balance on the head line — the kernel wraps iterator
2171 // macros (`hlist_for_each_entry_rcu(p, head, hlist,\n\t\t
2172 // lockdep_is_held(&kprobe_mutex)) {`). Continue the same
2173 // string-skipping paren scan over a few continuation lines. A `;` or
2174 // a brace anywhere in the span means a real statement or compound
2175 // literal — bail (missing a blank is safe; corrupting one is not).
2176 if (line.indexOf(';') !== -1) continue;
2177 for (let j = i + 1; j <= i + 5 && j < lines.length && close < 0; j++) {
2178 const cont = lines[j] as string;
2179 let bail = false;
2180 for (let k = 0; k < cont.length; k++) {
2181 const ch = cont[k];
2182 if (ch === '"' || ch === "'") {
2183 const quote = ch;
2184 k++;
2185 while (k < cont.length && cont[k] !== quote) {
2186 if (cont[k] === '\\') k++;
2187 k++;
2188 }

Callers 3

preParseCSourceFunction · 0.85
extraction.test.tsFile · 0.85

Calls 8

maskCppRawStringsFunction · 0.85
cStatementLinesFunction · 0.85
maskCppCodeFunction · 0.85
hasMethod · 0.80
restoreMethod · 0.80
contentFunction · 0.70
execMethod · 0.65
joinMethod · 0.45

Tested by

no test coverage detected