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

Function blankCppPointerAnnotationMacros

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

Source from the content-addressed store, hash-verified

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