The invocations of the macros `names` in code (not in a directive, comment or literal), with their arguments.
(source: string, names: ReadonlySet<string>)
| 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[] }> { |
| 403 | const calls: Array<{ name: string; at: number; end: number; args: string[] }> = []; |
| 404 | for (const word of cppCodeScan(source, names).words) { |
| 405 | const open = skipBlankAndComments(source, word.end); |
| 406 | if (source[open] !== '(') continue; |
| 407 | const args: string[] = []; |
| 408 | let depth = 0; |
| 409 | let from = open + 1; |
| 410 | let close = -1; |
| 411 | for (let i = open; i < source.length; i++) { |
| 412 | const c = source[i]!; |
| 413 | if (c === '"' || c === "'") i = quotedEnd(source, i) - 1; |
| 414 | else if (c === '/' && source[i + 1] === '*') { |
| 415 | const end = source.indexOf('*/', i + 2); |
| 416 | i = end < 0 ? source.length : end + 1; |
| 417 | } else if (c === '/' && source[i + 1] === '/') { |
| 418 | const end = source.indexOf('\n', i); |
| 419 | i = end < 0 ? source.length : end - 1; |
| 420 | } else if (c === '(') depth++; |
| 421 | else if (c === ')' && --depth === 0) { |
| 422 | close = i; |
| 423 | break; |
| 424 | } else if (c === ',' && depth === 1) { |
| 425 | args.push(source.slice(from, i)); |
| 426 | from = i + 1; |
| 427 | } |
| 428 | } |
| 429 | if (close < 0) continue; |
| 430 | args.push(source.slice(from, close)); |
| 431 | calls.push({ name: word.name, at: word.at, end: close + 1, args: args.map(withoutComments) }); |
| 432 | } |
| 433 | return calls; |
| 434 | } |
| 435 | |
| 436 | function withoutComments(text: string): string { |
| 437 | return text.replace(/\/\*[\s\S]*?\*\//g, ' ').replace(/\/\/[^\n]*/g, ' '); |
no test coverage detected