| 347 | * that is a bare primitive/keyword rather than a real identifier. |
| 348 | */ |
| 349 | export function recoverMangledCppName(name: string): string { |
| 350 | if (!/\s/.test(name) || name.startsWith('operator') || name.startsWith('~')) return name; |
| 351 | if (/^\S+\s+\([A-Za-z_]\w*\)/.test(name)) return name; // `Ret (name)` idiom — leave alone |
| 352 | const beforeParams = name.includes('(') ? name.slice(0, name.indexOf('(')) : name; |
| 353 | const tokens = beforeParams.trim().split(/\s+/); |
| 354 | const candidate = tokens[tokens.length - 1]; |
| 355 | if (!candidate || !/^[A-Za-z_]\w*$/.test(candidate) || CPP_PRIMITIVE_NAMES.has(candidate)) return name; |
| 356 | return candidate; |
| 357 | } |
| 358 | |
| 359 | /** C/C++ source pre-processing before tree-sitter: recover both macro-annotated |
| 360 | * class definitions and macro-prefixed function definitions. Offset-preserving. */ |