MCPcopy Create free account
hub / github.com/colbymchenry/codegraph / guardsItself

Function guardsItself

src/resolution/cpp-macro-visibility.ts:234–246  ·  view source on GitHub ↗

* 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)

Source from the content-addressed store, hash-verified

232 * build overrides on the command line, so it stays unknown.
233 */
234function 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
248function resolveInclude(
249 file: string,

Callers 1

summarizeFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected