* The function-like `#define`s of a C++ source and its `#undef`s, in order, * read past comments and literals: a `#define` in a comment or a raw string * defines nothing.
(source: string)
| 382 | * defines nothing. |
| 383 | */ |
| 384 | function cppMacroDirectives(source: string): { macros: CppMacro[]; undefs: Array<{ name: string; at: number }> } { |
| 385 | const macros: CppMacro[] = []; |
| 386 | const undefs: Array<{ name: string; at: number }> = []; |
| 387 | for (const d of cppCodeScan(source, null).directives) { |
| 388 | const text = withoutLineComment(d.text.replace(/\\\r?\n/g, ' ').replace(/\/\*[\s\S]*?\*\//g, ' ')); |
| 389 | const define = /^#[ \t]*define[ \t]+([A-Za-z_]\w*)\(([^)]*)\)/.exec(text); |
| 390 | if (define) { |
| 391 | const params = define[2]!.split(',').map((p) => p.trim()).filter((p) => p !== ''); |
| 392 | if (!params.some((p) => p.endsWith('...'))) macros.push({ name: define[1]!, params, body: text.slice(define[0].length), at: d.at }); |
| 393 | continue; |
| 394 | } |
| 395 | const undef = /^#[ \t]*undef[ \t]+([A-Za-z_]\w*)/.exec(text); |
| 396 | if (undef) undefs.push({ name: undef[1]!, at: d.at }); |
| 397 | } |
| 398 | return { macros, undefs }; |
| 399 | } |
| 400 | |
| 401 | /** The invocations of the macros `names` in code (not in a directive, comment or literal), with their arguments. */ |
| 402 | function cppMacroInvocations(source: string, names: ReadonlySet<string>): Array<{ name: string; at: number; end: number; args: string[] }> { |
no test coverage detected