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

Function directiveLines

src/resolution/cpp-macro-visibility.ts:168–215  ·  view source on GitHub ↗
(source: string)

Source from the content-addressed store, hash-verified

166 * touches every header of a translation unit, vendor trees included.
167 */
168export function directiveLines(source: string): string[] {
169 const out: string[] = [];
170 let inBlock = false;
171 for (const raw of maskCppRawStrings(source).source.split(/\r?\n/)) {
172 let text = raw;
173 if (inBlock) {
174 const end = text.indexOf('*/');
175 if (end < 0) {
176 out.push('');
177 continue;
178 }
179 text = text.slice(end + 2);
180 inBlock = false;
181 }
182 const directive = /^\s*#/.test(text);
183 let kept = '';
184 let quote = '';
185 for (let i = 0; i < text.length; i++) {
186 const c = text[i]!;
187 if (quote) {
188 if (c === '\\') i++;
189 else if (c === quote) quote = '';
190 continue;
191 }
192 if (c === '"' || c === "'") {
193 quote = c;
194 continue;
195 }
196 if (c === '/' && text[i + 1] === '/') {
197 kept = text.slice(0, i);
198 break;
199 }
200 if (c === '/' && text[i + 1] === '*') {
201 const end = text.indexOf('*/', i + 2);
202 if (end < 0) {
203 inBlock = true;
204 kept = text.slice(0, i);
205 break;
206 }
207 text = text.slice(0, i) + ' ' + text.slice(end + 2);
208 i--;
209 continue;
210 }
211 }
212 out.push(directive ? kept || text : raw);
213 }
214 return out;
215}
216
217/** Does the body of the `#define NAME(` at `index` (continuation lines included) call `NAME`? */
218function callsItself(lines: string[], index: number, name: string): boolean {

Callers 3

directivesOfFunction · 0.90
cMacroRenameFunction · 0.90
summarizeFunction · 0.85

Calls 2

maskCppRawStringsFunction · 0.90
pushMethod · 0.80

Tested by

no test coverage detected