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

Function layeredHeaders

__tests__/cpp-macro-include-walk.test.ts:25–39  ·  view source on GitHub ↗

`depth` layers of two headers; each includes both headers of the next layer.

(depth: number, guard: Guard)

Source from the content-addressed store, hash-verified

23
24/** `depth` layers of two headers; each includes both headers of the next layer. */
25function layeredHeaders(depth: number, guard: Guard): Record<string, string> {
26 const files: Record<string, string> = {};
27 for (let d = 0; d < depth; d++) {
28 for (const side of ['a', 'b']) {
29 const g = `H_${d}_${side}`;
30 const open =
31 guard === 'value' ? `#ifndef ${g}\n#define ${g} 1\n` :
32 guard === 'bare' ? `#ifndef ${g}\n#define ${g}\n` :
33 `#ifdef USE_${d}\n`;
34 const next = d + 1 < depth ? `#include "h${d + 1}_a.h"\n#include "h${d + 1}_b.h"\n` : '';
35 files[`h${d}_${side}.h`] = `${open}${next}#define M_${d}_${side}(x) (x)\nint f_${d}_${side}(int);\n#endif\n`;
36 }
37 }
38 return files;
39}
40
41/** A context over in-memory files where every name is both a macro and a function. */
42function contextOver(files: Record<string, string>): ResolutionContext {

Callers 1

Calls

no outgoing calls

Tested by

no test coverage detected