(ref: UnresolvedRef, context: ResolutionContext)
| 76 | * visible at the call site. |
| 77 | */ |
| 78 | export 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 |
no test coverage detected