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

Function cppMacroDirectives

src/extraction/languages/cpp-macro-methods.ts:385–400  ·  view source on GitHub ↗

* The function-like `#define`s of a C++ source and its `#undef`s, in order, * read past comments and literals: a `#define` in a comment or a raw string * defines nothing.

(source: string)

Source from the content-addressed store, hash-verified

383 * defines nothing.
384 */
385function cppMacroDirectives(source: string): { macros: CppMacro[]; undefs: Array<{ name: string; at: number }> } {
386 const macros: CppMacro[] = [];
387 const undefs: Array<{ name: string; at: number }> = [];
388 for (const d of cppCodeScan(source, null).directives) {
389 const text = withoutLineComment(d.text.replace(/\\\r?\n/g, ' ').replace(/\/\*[\s\S]*?\*\//g, ' '));
390 const define = /^#[ \t]*define[ \t]+([A-Za-z_]\w*)\(([^)]*)\)/.exec(text);
391 if (define) {
392 const params = define[2]!.split(',').map((p) => p.trim()).filter((p) => p !== '');
393 if (!params.some((p) => p.endsWith('...'))) macros.push({ name: define[1]!, params, body: text.slice(define[0].length), at: d.at });
394 continue;
395 }
396 const undef = /^#[ \t]*undef[ \t]+([A-Za-z_]\w*)/.exec(text);
397 if (undef) undefs.push({ name: undef[1]!, at: d.at });
398 }
399 return { macros, undefs };
400}
401
402/** The invocations of the macros `names` in code (not in a directive, comment or literal), with their arguments. */
403function cppMacroInvocations(source: string, names: ReadonlySet<string>): Array<{ name: string; at: number; end: number; args: string[] }> {

Callers 1

cppMacroMethodsFunction · 0.85

Calls 5

cppCodeScanFunction · 0.85
withoutLineCommentFunction · 0.85
mapMethod · 0.80
pushMethod · 0.80
execMethod · 0.65

Tested by

no test coverage detected