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

Function summarize

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

Cache syntax, never conditional truth: an included file can change its flags.

(file: string, context: ResolutionContext, cache: Cache)

Source from the content-addressed store, hash-verified

130
131/** Cache syntax, never conditional truth: an included file can change its flags. */
132function summarize(file: string, context: ResolutionContext, cache: Cache): FileEvent[] {
133 const cached = cache.summaries.get(file);
134 if (cached) return cached;
135 const events: FileEvent[] = [];
136 const lines = directiveLines(context.readFile(file) ?? '');
137 for (let i = 0; i < lines.length; i++) {
138 const text = lines[i]!;
139 const branch = text.match(/^\s*#\s*(ifdef|ifndef|if|elif|else|endif)\b(.*)$/);
140 if (branch) {
141 events.push({ kind: 'branch', op: branch[1]!, expression: branch[2]!,
142 guard: guardsItself(lines, i, branch[1]!, branch[2]!), line: i + 1 });
143 continue;
144 }
145 const directive = text.match(/^\s*#\s*(define|undef)\s+(\w+)(\(?)/);
146 if (directive) {
147 events.push({ kind: directive[1] as 'define' | 'undef', name: directive[2]!, line: i + 1,
148 functionLike: directive[3] === '(', value: text.slice(directive[0].length),
149 wrapsItself: directive[3] === '(' && callsItself(lines, i, directive[2]!) });
150 continue;
151 }
152 const include = text.match(/^\s*#\s*include\s*([<"])([^>"]+)[>"]/);
153 if (include) events.push({ kind: 'include', quote: include[1]!, spec: include[2]!, line: i + 1 });
154 if (/^\s*#\s*pragma\s+once\b/.test(text)) events.push({ kind: 'once', line: i + 1 });
155 }
156 cache.summaries.set(file, events);
157 return events;
158}
159
160/**
161 * The file's lines with comments removed — only as far as the preprocessor

Callers 1

scanFunction · 0.70

Calls 7

directiveLinesFunction · 0.85
guardsItselfFunction · 0.85
callsItselfFunction · 0.85
readFileMethod · 0.80
pushMethod · 0.80
getMethod · 0.65
setMethod · 0.45

Tested by

no test coverage detected