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

Function blankCStatementMacroCalls

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

Source from the content-addressed store, hash-verified

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

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