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

Function blankCStatementMacroCalls

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

Source from the content-addressed store, hash-verified

941 'if', 'while', 'for', 'switch', 'return', 'do', 'else', 'sizeof',
942]);
943export function blankCStatementMacroCalls(source: string): string {
944 const lines = source.split('\n');
945 let changed = false;
946 const content = (l: string): string => l.replace(/\r$/, '').trim();
947 for (let i = 0; i < lines.length; i++) {
948 const line = lines[i] as string;
949 const m = /^[ \t]+([a-z_][a-z0-9_]*)[ \t]*\(/.exec(line);
950 if (!m || C_STMT_MACRO_KEYWORDS.has(m[1] as string)) continue;
951 const open = line.indexOf('(', m[0].length - 1);
952 let depth = 0;
953 let close = -1;
954 for (let k = open; k < line.length; k++) {
955 const ch = line[k];
956 if (ch === '"' || ch === "'") {
957 const quote = ch;
958 k++;
959 while (k < line.length && line[k] !== quote) {
960 if (line[k] === '\\') k++;
961 k++;
962 }
963 continue;
964 }
965 if (ch === '(') depth++;
966 else if (ch === ')') {
967 depth--;
968 if (depth === 0) {
969 close = k;
970 break;
971 }
972 }
973 }
974 let endLine = i;
975 if (close < 0) {
976 // Parens don't balance on the head line — the kernel wraps iterator
977 // macros (`hlist_for_each_entry_rcu(p, head, hlist,\n\t\t
978 // lockdep_is_held(&kprobe_mutex)) {`). Continue the same
979 // string-skipping paren scan over a few continuation lines. A `;` or
980 // a brace anywhere in the span means a real statement or compound
981 // literal — bail (missing a blank is safe; corrupting one is not).
982 if (line.indexOf(';') !== -1) continue;
983 for (let j = i + 1; j <= i + 5 && j < lines.length && close < 0; j++) {
984 const cont = lines[j] as string;
985 let bail = false;
986 for (let k = 0; k < cont.length; k++) {
987 const ch = cont[k];
988 if (ch === '"' || ch === "'") {
989 const quote = ch;
990 k++;
991 while (k < cont.length && cont[k] !== quote) {
992 if (cont[k] === '\\') k++;
993 k++;
994 }
995 continue;
996 }
997 if (ch === ';' || ch === '{' || ch === '}') {
998 bail = true;
999 break;
1000 }

Callers 2

preParseCSourceFunction · 0.85
extraction.test.tsFile · 0.85

Calls 4

contentFunction · 0.85
hasMethod · 0.80
execMethod · 0.65
joinMethod · 0.45

Tested by

no test coverage detected