| 1178 | * that is a bare primitive/keyword rather than a real identifier. |
| 1179 | */ |
| 1180 | export function recoverMangledCppName(name: string): string { |
| 1181 | if (!/\s/.test(name) || name.startsWith('operator') || name.startsWith('~')) return name; |
| 1182 | if (/^\S+\s+\([A-Za-z_]\w*\)/.test(name)) return name; // `Ret (name)` idiom — leave alone |
| 1183 | const beforeParams = name.includes('(') ? name.slice(0, name.indexOf('(')) : name; |
| 1184 | const tokens = beforeParams.trim().split(/\s+/); |
| 1185 | const candidate = tokens[tokens.length - 1]; |
| 1186 | if (!candidate || !/^[A-Za-z_]\w*$/.test(candidate) || CPP_PRIMITIVE_NAMES.has(candidate)) return name; |
| 1187 | return candidate; |
| 1188 | } |
| 1189 | |
| 1190 | /** |
| 1191 | * Blank Metal Shading Language `[[attribute]]` annotations before parsing. |