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

Function restoreDirectiveLines

src/extraction/languages/c-cpp.ts:1711–1727  ·  view source on GitHub ↗

* Restore preprocessor-directive lines to their original bytes after the * blanking passes ran. The token-level blanks match on shape, not context, so * a macro name that happens to sit inside a DIRECTIVE gets blanked too — and * blanking the name position of `#define FMT_API FMT_VISIBILITY("defa

(original: string, blanked: string)

Source from the content-addressed store, hash-verified

1709 * construction and strictly reduces parse errors on both extraction arms.
1710 */
1711function restoreDirectiveLines(original: string, blanked: string): string {
1712 if (blanked === original || original.indexOf('#') === -1) return blanked;
1713 const o = original.split('\n');
1714 const b = blanked.split('\n');
1715 let changed = false;
1716 let continuation: boolean = false;
1717 for (let i = 0; i < o.length && i < b.length; i++) {
1718 const line = o[i] as string;
1719 const isDirective: boolean = continuation || /^[ \t]*#/.test(line);
1720 if (isDirective && b[i] !== line) {
1721 b[i] = line;
1722 changed = true;
1723 }
1724 continuation = isDirective && /\\\s*$/.test(line.replace(/\r$/, ''));
1725 }
1726 return changed ? b.join('\n') : blanked;
1727}
1728
1729/** Recover MSVC's COM alias only at type-definition sites. Match on a lexical
1730 * mask so comments, literals and directives cannot supply declaration evidence;

Callers 2

preParseCppSourceFunction · 0.85
preParseCSourceFunction · 0.85

Calls 1

joinMethod · 0.45

Tested by

no test coverage detected