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

Function blankCppPointerAnnotationMacros

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

Source from the content-addressed store, hash-verified

845const CPP_POINTER_ANNOTATION_RE =
846 /([*&])\s*((?:[A-Z][A-Z0-9]*_[A-Z0-9_]*(?:\s+|(?=\*)))+)(?=\*|::|(?!(?:and|and_eq|bitand|bitor|compl|not|not_eq|or|or_eq|xor|xor_eq)\b)[A-Za-z_~])/g;
847export function blankCppPointerAnnotationMacros(source: string): string {
848 if (!/[*&]\s*[A-Z][A-Z0-9]*_/.test(source)) return source;
849 const code = maskCppCode(source);
850 const spans: Array<[number, number]> = [];
851 const re = new RegExp(CPP_POINTER_ANNOTATION_RE.source, 'g');
852 let m: RegExpExecArray | null;
853 while ((m = re.exec(code)) !== null) {
854 const run = m[2] as string;
855 const start = m.index + m[0].length - run.length;
856 // After `&`, only a name: `flags & FOO_BIT\n && ok` is an expression.
857 if (m[1] === '&' && code[start + run.length] === '*') continue;
858 // A `*` after a closing bracket or a number multiplies: `sizeof(int) * CHAR_BIT * 3`.
859 if (/(?:[)\]]|\b\d[\w.]*)\s*$/.test(code.slice(Math.max(0, m.index - 40), m.index))) continue;
860 pushCppRunTokens(spans, run, start);
861 }
862 return blankCppSpans(source, spans, code);
863}
864
865// Keywords that take a parenthesized operand: a `)` closing one of these is
866// not a parameter list, so a token after it is not a trailing attribute.

Callers 2

preParseCppSourceFunction · 0.85

Calls 4

maskCppCodeFunction · 0.85
pushCppRunTokensFunction · 0.85
blankCppSpansFunction · 0.85
execMethod · 0.65

Tested by

no test coverage detected