* The include-guard idiom: `#ifndef X_H` (or `#if !defined(X_H)`) whose next * directive is `#define X_H`. Nothing in the file defines the guard before * the test, so this is the first inclusion and the guarded body is active. * The same shape around a fallback function-like macro (`#ifndef MIN`
(lines: string[], index: number, op: string, expression: string)
| 232 | * build overrides on the command line, so it stays unknown. |
| 233 | */ |
| 234 | function guardsItself(lines: string[], index: number, op: string, expression: string): boolean { |
| 235 | const name = |
| 236 | op === 'ifndef' |
| 237 | ? expression.trim() |
| 238 | : expression.match(/^\s*!\s*defined\s*(?:\(\s*(\w+)\s*\)|(\w+))\s*$/)?.slice(1).find(Boolean); |
| 239 | if (!name || !/^\w+$/.test(name)) return false; |
| 240 | for (let j = index + 1; j < lines.length; j++) { |
| 241 | const text = lines[j]!; |
| 242 | if (!/^\s*#/.test(text)) continue; |
| 243 | return new RegExp(`^\\s*#\\s*define\\s+${name}(?:\\s*$|\\()`).test(text); |
| 244 | } |
| 245 | return false; |
| 246 | } |
| 247 | |
| 248 | function resolveInclude( |
| 249 | file: string, |