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

Function bodyOpenAfter

src/extraction/languages/cpp-macro-methods.ts:264–302  ·  view source on GitHub ↗

* After a definition's parameter list (from `i`): the offset of its body's * `{`, past the qualifiers it may write (`const`, `noexcept(…)`, `override`, * `&&`, an attribute, an attribute macro, a trailing return type). -1 for * anything else: a declaration (`;`), `= default`, a constructor's * i

(text: string, i: number)

Source from the content-addressed store, hash-verified

262 * initializer list.
263 */
264function bodyOpenAfter(text: string, i: number): number {
265 let j = skipBlank(text, i);
266 for (;;) {
267 const c = text[j];
268 if (c === '{') return j;
269 if (c === '&') {
270 j = skipBlank(text, j + (text[j + 1] === '&' ? 2 : 1));
271 continue;
272 }
273 if (text.startsWith('[[', j)) {
274 const close = text.indexOf(']]', j + 2);
275 if (close < 0) return -1;
276 j = skipBlank(text, close + 2);
277 continue;
278 }
279 if (text.startsWith('->', j)) {
280 // A trailing return type runs to the body.
281 let depth = 0;
282 for (let k = j + 2; k < text.length; k++) {
283 const d = text[k];
284 if (d === '(' || d === '<' || d === '[') depth++;
285 else if (d === ')' || d === '>' || d === ']') depth--;
286 else if (d === '{' && depth <= 0) return k;
287 else if (d === ';' && depth <= 0) return -1;
288 }
289 return -1;
290 }
291 const end = wordEnd(text, j);
292 if (end < 0) return -1;
293 const word = text.slice(j, end);
294 if (!/^(?:const|volatile|override|final|noexcept|throw|[A-Z][A-Z0-9]*_[A-Z0-9_]*)$/.test(word)) return -1;
295 j = skipBlank(text, end);
296 if (text[j] === '(' && word !== 'const' && word !== 'volatile' && word !== 'override' && word !== 'final') {
297 const close = matching(text, j, '(', ')');
298 if (close < 0) return -1;
299 j = skipBlank(text, close + 1);
300 }
301 }
302}
303
304/** The method definitions at the top level of a macro's expansion `text`, in order. */
305function cppDefinitionHeads(text: string): CppDefinitionHead[] {

Callers 1

cppDefinitionHeadsFunction · 0.85

Calls 3

skipBlankFunction · 0.70
wordEndFunction · 0.70
matchingFunction · 0.70

Tested by

no test coverage detected