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

Function isVisibleCppMacro

src/resolution/cpp-macro-visibility.ts:78–98  ·  view source on GitHub ↗
(ref: UnresolvedRef, context: ResolutionContext)

Source from the content-addressed store, hash-verified

76 * visible at the call site.
77 */
78export function isVisibleCppMacro(ref: UnresolvedRef, context: ResolutionContext): boolean {
79 if (ref.language !== 'c' && ref.language !== 'cpp') return false;
80 if (ref.referenceKind !== 'calls' || !/^\w+$/.test(ref.referenceName)) return false;
81 // The name cache is the index's truth, invalidated with the resolver's other
82 // caches; a per-context name set would go stale between indexing batches.
83 const sameName = context.getNodesByName(ref.referenceName);
84 if (!sameName.some(isDefine)) return false;
85 if (!sameName.some((n) => !isDefine(n))) return true;
86 const cache = cacheFor(context);
87
88 const rootKey = `${ref.language}\0${ref.filePath}`;
89 let timeline = cache.roots.get(rootKey);
90 if (!timeline) {
91 timeline = walkTranslationUnit(ref.filePath, ref.language, context, cache);
92 if (cache.roots.size >= ROOT_TIMELINE_CAP) cache.roots.delete(cache.roots.keys().next().value!);
93 cache.roots.set(rootKey, timeline);
94 }
95 if (ref.line >= timeline.cutoff) return false;
96 const before = (timeline.events.get(ref.referenceName) ?? []).filter((e) => e.line <= ref.line);
97 return before.length > 0 && before[before.length - 1]!.defined === true;
98}
99
100/**
101 * Is `name` certainly defined as a macro at `line` of `file`, read as a

Callers 2

resolveOneInMethod · 0.90

Calls 8

isDefineFunction · 0.85
cacheForFunction · 0.85
walkTranslationUnitFunction · 0.85
nextMethod · 0.80
getNodesByNameMethod · 0.65
getMethod · 0.65
deleteMethod · 0.65
setMethod · 0.45

Tested by

no test coverage detected