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

Function restoreDirectiveLines

src/extraction/languages/c-cpp.ts:772–788  ·  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

770 * construction and strictly reduces parse errors on both extraction arms.
771 */
772function restoreDirectiveLines(original: string, blanked: string): string {
773 if (blanked === original || original.indexOf('#') === -1) return blanked;
774 const o = original.split('\n');
775 const b = blanked.split('\n');
776 let changed = false;
777 let continuation: boolean = false;
778 for (let i = 0; i < o.length && i < b.length; i++) {
779 const line = o[i] as string;
780 const isDirective: boolean = continuation || /^[ \t]*#/.test(line);
781 if (isDirective && b[i] !== line) {
782 b[i] = line;
783 changed = true;
784 }
785 continuation = isDirective && /\\\s*$/.test(line.replace(/\r$/, ''));
786 }
787 return changed ? b.join('\n') : blanked;
788}
789
790/** C/C++ source pre-processing before tree-sitter: recover macro-annotated class
791 * definitions, macro-prefixed function definitions, macro-prefixed members, and

Callers 2

preParseCppSourceFunction · 0.85
preParseCSourceFunction · 0.85

Calls 1

joinMethod · 0.45

Tested by

no test coverage detected