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

Function scan

src/resolution/cpp-macro-visibility.ts:319–401  ·  view source on GitHub ↗
(file: string, inherited: Truth, includeLine?: number)

Source from the content-addressed store, hash-verified

317 return /^\w+$/.test(text) ? definitions.get(text)?.value : undefined;
318 };
319 const scan = (file: string, inherited: Truth, includeLine?: number): void => {
320 if (inherited === false || once.get(file) === true || cutoff !== Infinity) return;
321 if (scanning.has(file)) {
322 cuts.push(file);
323 return;
324 }
325 const seen = visits.get(file);
326 if (
327 seen && seen.inherited === inherited && seen.start === seen.end && seen.end === version &&
328 seen.cuts.every((c) => scanning.has(c))
329 ) {
330 cuts.push(...seen.cuts);
331 return;
332 }
333 const start = version;
334 const firstCut = cuts.length;
335 scanning.add(file);
336 let active: Truth = inherited;
337 const frames: Array<{ parent: Truth; taken: Truth }> = [];
338 for (const ev of summarize(file, context, cache)) {
339 const line = includeLine ?? ev.line;
340 if (cutoff === Infinity && --budget < 0) cutoff = line;
341 if (cutoff !== Infinity) break;
342 if (ev.kind === 'branch') {
343 if (ev.op === 'if' || ev.op === 'ifdef' || ev.op === 'ifndef') {
344 const known = definitions.get(ev.expression.trim())?.defined;
345 let selected = ev.op === 'if' ? condition(ev.expression) : ev.op === 'ifndef' ? not(known) : known;
346 if (selected === undefined && ev.guard) selected = true;
347 frames.push({ parent: active, taken: selected });
348 active = and(active, selected);
349 } else if (ev.op === 'endif') {
350 active = frames.pop()?.parent ?? inherited;
351 } else {
352 const frame = frames[frames.length - 1];
353 if (frame) {
354 const test = ev.op === 'else' ? true : condition(ev.expression);
355 active = and(frame.parent, and(not(frame.taken), test));
356 frame.taken = or(frame.taken, test);
357 }
358 }
359 continue;
360 }
361 if (active === false) continue;
362 if (ev.kind === 'once') {
363 const next = or(once.get(file) ?? false, active);
364 if (next !== (once.get(file) ?? false)) version++;
365 once.set(file, next);
366 continue;
367 }
368 if (ev.kind === 'include') {
369 const target = resolveInclude(file, ev.quote, ev.spec, language, context, cache);
370 if (target) scan(target, active, line);
371 continue;
372 }
373 const prior = definitions.get(ev.name);
374 const defining = ev.kind === 'define';
375 const macro = defining && ev.functionLike && !ev.wrapsItself;
376 const now = active === true ? macro : prior?.macro === macro ? macro : undefined;

Callers 1

walkTranslationUnitFunction · 0.70

Calls 12

conditionFunction · 0.85
hasMethod · 0.80
pushMethod · 0.80
summarizeFunction · 0.70
notFunction · 0.70
andFunction · 0.70
orFunction · 0.70
resolveIncludeFunction · 0.70
getMethod · 0.65
deleteMethod · 0.65
addMethod · 0.45
setMethod · 0.45

Tested by

no test coverage detected