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

Function restoreDirectiveLines

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

760 * construction and strictly reduces parse errors on both extraction arms.
761 */
762function restoreDirectiveLines(original: string, blanked: string): string {
763 if (blanked === original || original.indexOf('#') === -1) return blanked;
764 const o = original.split('\n');
765 const b = blanked.split('\n');
766 let changed = false;
767 let continuation: boolean = false;
768 for (let i = 0; i < o.length && i < b.length; i++) {
769 const line = o[i] as string;
770 const isDirective: boolean = continuation || /^[ \t]*#/.test(line);
771 if (isDirective && b[i] !== line) {
772 b[i] = line;
773 changed = true;
774 }
775 continuation = isDirective && /\\\s*$/.test(line.replace(/\r$/, ''));
776 }
777 return changed ? b.join('\n') : blanked;
778}
779
780/** C/C++ source pre-processing before tree-sitter: recover macro-annotated class
781 * 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