The method definitions at the top level of a macro's expansion `text`, in order.
(text: string)
| 302 | |
| 303 | /** The method definitions at the top level of a macro's expansion `text`, in order. */ |
| 304 | function cppDefinitionHeads(text: string): CppDefinitionHead[] { |
| 305 | const heads: CppDefinitionHead[] = []; |
| 306 | let segment = 0; // where the current top-level declaration began |
| 307 | for (let i = 0; i < text.length; ) { |
| 308 | const c = text[i]!; |
| 309 | if (c === '"' || c === "'") { |
| 310 | i = quotedEnd(text, i); |
| 311 | continue; |
| 312 | } |
| 313 | if (c === ';' || c === '}') { |
| 314 | segment = ++i; |
| 315 | continue; |
| 316 | } |
| 317 | if (c === '{' || c === '(') { |
| 318 | // A body or group that is no definition read here (a namespace, a class, a statement). |
| 319 | const close = matching(text, i, c, c === '{' ? '}' : ')'); |
| 320 | if (close < 0) return heads; |
| 321 | if (c === '{') segment = close + 1; |
| 322 | i = close + 1; |
| 323 | continue; |
| 324 | } |
| 325 | const callable = isWordStart(text.charCodeAt(i)) || (c === ':' && text[i + 1] === ':') ? qualifiedCallableAt(text, i) : null; |
| 326 | if (!callable) { |
| 327 | const end = wordEnd(text, i); |
| 328 | i = end < 0 ? i + 1 : end; |
| 329 | continue; |
| 330 | } |
| 331 | const close = matching(text, callable.open, '(', ')'); |
| 332 | if (close < 0) return heads; |
| 333 | const open = bodyOpenAfter(text, close + 1); |
| 334 | if (open < 0) { |
| 335 | i = close + 1; |
| 336 | continue; |
| 337 | } |
| 338 | // An explicit specialization's arguments (`Read<int32_t, TYPE_INT32>`) are no part of its name. |
| 339 | const last = callable.segments[callable.segments.length - 1]!; |
| 340 | const name = last.startsWith('operator') ? last : stripCppTemplateArgs(last); |
| 341 | const receiver = stripCppTemplateArgs(callable.segments.slice(0, -1).join('::')); |
| 342 | if (receiver) { |
| 343 | heads.push({ |
| 344 | receiver, |
| 345 | name, |
| 346 | returnText: text.slice(segment, i).trim(), |
| 347 | head: text.slice(segment, open).replace(/\s+/g, ' ').trim(), |
| 348 | }); |
| 349 | } |
| 350 | const bodyClose = matching(text, open, '{', '}'); |
| 351 | if (bodyClose < 0) return heads; |
| 352 | segment = i = bodyClose + 1; |
| 353 | } |
| 354 | return heads; |
| 355 | } |
| 356 | |
| 357 | /** |
| 358 | * The macro of `name` in effect at `offset`: its last `#define` before it, |
no test coverage detected