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