@colbymchenry/codegraph-win32-x64 1.2.0 → 1.3.0
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/lib/dist/bin/codegraph.d.ts +1 -1
- package/lib/dist/bin/codegraph.d.ts.map +1 -1
- package/lib/dist/bin/codegraph.js +232 -61
- package/lib/dist/bin/codegraph.js.map +1 -1
- package/lib/dist/bin/command-supervision.d.ts.map +1 -1
- package/lib/dist/bin/command-supervision.js +4 -1
- package/lib/dist/bin/command-supervision.js.map +1 -1
- package/lib/dist/db/migrations.d.ts +1 -1
- package/lib/dist/db/migrations.d.ts.map +1 -1
- package/lib/dist/db/migrations.js +19 -1
- package/lib/dist/db/migrations.js.map +1 -1
- package/lib/dist/db/queries.d.ts +51 -0
- package/lib/dist/db/queries.d.ts.map +1 -1
- package/lib/dist/db/queries.js +141 -0
- package/lib/dist/db/queries.js.map +1 -1
- package/lib/dist/db/schema.sql +19 -0
- package/lib/dist/directory.d.ts +9 -5
- package/lib/dist/directory.d.ts.map +1 -1
- package/lib/dist/directory.js +210 -19
- package/lib/dist/directory.js.map +1 -1
- package/lib/dist/extraction/cfml-extractor.d.ts +107 -0
- package/lib/dist/extraction/cfml-extractor.d.ts.map +1 -0
- package/lib/dist/extraction/cfml-extractor.js +494 -0
- package/lib/dist/extraction/cfml-extractor.js.map +1 -0
- package/lib/dist/extraction/grammars.d.ts +9 -0
- package/lib/dist/extraction/grammars.d.ts.map +1 -1
- package/lib/dist/extraction/grammars.js +115 -3
- package/lib/dist/extraction/grammars.js.map +1 -1
- package/lib/dist/extraction/index.d.ts +46 -1
- package/lib/dist/extraction/index.d.ts.map +1 -1
- package/lib/dist/extraction/index.js +254 -3
- package/lib/dist/extraction/index.js.map +1 -1
- package/lib/dist/extraction/languages/arkts.d.ts +3 -0
- package/lib/dist/extraction/languages/arkts.d.ts.map +1 -0
- package/lib/dist/extraction/languages/arkts.js +127 -0
- package/lib/dist/extraction/languages/arkts.js.map +1 -0
- package/lib/dist/extraction/languages/c-cpp.d.ts +42 -0
- package/lib/dist/extraction/languages/c-cpp.d.ts.map +1 -1
- package/lib/dist/extraction/languages/c-cpp.js +369 -4
- package/lib/dist/extraction/languages/c-cpp.js.map +1 -1
- package/lib/dist/extraction/languages/cfquery.d.ts +12 -0
- package/lib/dist/extraction/languages/cfquery.d.ts.map +1 -0
- package/lib/dist/extraction/languages/cfquery.js +28 -0
- package/lib/dist/extraction/languages/cfquery.js.map +1 -0
- package/lib/dist/extraction/languages/cfscript.d.ts +3 -0
- package/lib/dist/extraction/languages/cfscript.d.ts.map +1 -0
- package/lib/dist/extraction/languages/cfscript.js +73 -0
- package/lib/dist/extraction/languages/cfscript.js.map +1 -0
- package/lib/dist/extraction/languages/cobol.d.ts +33 -0
- package/lib/dist/extraction/languages/cobol.d.ts.map +1 -0
- package/lib/dist/extraction/languages/cobol.js +499 -0
- package/lib/dist/extraction/languages/cobol.js.map +1 -0
- package/lib/dist/extraction/languages/erlang.d.ts +3 -0
- package/lib/dist/extraction/languages/erlang.d.ts.map +1 -0
- package/lib/dist/extraction/languages/erlang.js +350 -0
- package/lib/dist/extraction/languages/erlang.js.map +1 -0
- package/lib/dist/extraction/languages/index.d.ts.map +1 -1
- package/lib/dist/extraction/languages/index.js +18 -0
- package/lib/dist/extraction/languages/index.js.map +1 -1
- package/lib/dist/extraction/languages/nix.d.ts +3 -0
- package/lib/dist/extraction/languages/nix.d.ts.map +1 -0
- package/lib/dist/extraction/languages/nix.js +294 -0
- package/lib/dist/extraction/languages/nix.js.map +1 -0
- package/lib/dist/extraction/languages/solidity.d.ts +3 -0
- package/lib/dist/extraction/languages/solidity.d.ts.map +1 -0
- package/lib/dist/extraction/languages/solidity.js +293 -0
- package/lib/dist/extraction/languages/solidity.js.map +1 -0
- package/lib/dist/extraction/languages/terraform.d.ts +3 -0
- package/lib/dist/extraction/languages/terraform.d.ts.map +1 -0
- package/lib/dist/extraction/languages/terraform.js +641 -0
- package/lib/dist/extraction/languages/terraform.js.map +1 -0
- package/lib/dist/extraction/languages/vbnet.d.ts +11 -0
- package/lib/dist/extraction/languages/vbnet.d.ts.map +1 -0
- package/lib/dist/extraction/languages/vbnet.js +141 -0
- package/lib/dist/extraction/languages/vbnet.js.map +1 -0
- package/lib/dist/extraction/mybatis-extractor.d.ts +30 -10
- package/lib/dist/extraction/mybatis-extractor.d.ts.map +1 -1
- package/lib/dist/extraction/mybatis-extractor.js +140 -38
- package/lib/dist/extraction/mybatis-extractor.js.map +1 -1
- package/lib/dist/extraction/tree-sitter-helpers.d.ts.map +1 -1
- package/lib/dist/extraction/tree-sitter-helpers.js +1 -0
- package/lib/dist/extraction/tree-sitter-helpers.js.map +1 -1
- package/lib/dist/extraction/tree-sitter-types.d.ts +3 -1
- package/lib/dist/extraction/tree-sitter-types.d.ts.map +1 -1
- package/lib/dist/extraction/tree-sitter.d.ts +38 -0
- package/lib/dist/extraction/tree-sitter.d.ts.map +1 -1
- package/lib/dist/extraction/tree-sitter.js +753 -10
- package/lib/dist/extraction/tree-sitter.js.map +1 -1
- package/lib/dist/extraction/wasm/tree-sitter-arkts.wasm +0 -0
- package/lib/dist/extraction/wasm/tree-sitter-cfml.wasm +0 -0
- package/lib/dist/extraction/wasm/tree-sitter-cfquery.wasm +0 -0
- package/lib/dist/extraction/wasm/tree-sitter-cfscript.wasm +0 -0
- package/lib/dist/extraction/wasm/tree-sitter-cobol.wasm +0 -0
- package/lib/dist/extraction/wasm/tree-sitter-erlang.wasm +0 -0
- package/lib/dist/extraction/wasm/tree-sitter-nix.wasm +0 -0
- package/lib/dist/extraction/wasm/tree-sitter-terraform.wasm +0 -0
- package/lib/dist/extraction/wasm/tree-sitter-vbnet.wasm +0 -0
- package/lib/dist/index.d.ts +63 -1
- package/lib/dist/index.d.ts.map +1 -1
- package/lib/dist/index.js +306 -2
- package/lib/dist/index.js.map +1 -1
- package/lib/dist/installer/index.d.ts.map +1 -1
- package/lib/dist/installer/index.js +3 -1
- package/lib/dist/installer/index.js.map +1 -1
- package/lib/dist/mcp/daemon.d.ts +25 -3
- package/lib/dist/mcp/daemon.d.ts.map +1 -1
- package/lib/dist/mcp/daemon.js +39 -7
- package/lib/dist/mcp/daemon.js.map +1 -1
- package/lib/dist/mcp/dynamic-boundaries.d.ts.map +1 -1
- package/lib/dist/mcp/dynamic-boundaries.js +2 -1
- package/lib/dist/mcp/dynamic-boundaries.js.map +1 -1
- package/lib/dist/mcp/early-ppid.d.ts +26 -0
- package/lib/dist/mcp/early-ppid.d.ts.map +1 -0
- package/lib/dist/mcp/early-ppid.js +29 -0
- package/lib/dist/mcp/early-ppid.js.map +1 -0
- package/lib/dist/mcp/index.d.ts.map +1 -1
- package/lib/dist/mcp/index.js +21 -4
- package/lib/dist/mcp/index.js.map +1 -1
- package/lib/dist/mcp/proxy.d.ts.map +1 -1
- package/lib/dist/mcp/proxy.js +21 -3
- package/lib/dist/mcp/proxy.js.map +1 -1
- package/lib/dist/mcp/startup-handshake.d.ts +44 -0
- package/lib/dist/mcp/startup-handshake.d.ts.map +1 -0
- package/lib/dist/mcp/startup-handshake.js +73 -0
- package/lib/dist/mcp/startup-handshake.js.map +1 -0
- package/lib/dist/mcp/tools.d.ts +22 -0
- package/lib/dist/mcp/tools.d.ts.map +1 -1
- package/lib/dist/mcp/tools.js +74 -9
- package/lib/dist/mcp/tools.js.map +1 -1
- package/lib/dist/project-config.d.ts +38 -0
- package/lib/dist/project-config.d.ts.map +1 -1
- package/lib/dist/project-config.js +101 -2
- package/lib/dist/project-config.js.map +1 -1
- package/lib/dist/resolution/callback-synthesizer.d.ts.map +1 -1
- package/lib/dist/resolution/callback-synthesizer.js +672 -0
- package/lib/dist/resolution/callback-synthesizer.js.map +1 -1
- package/lib/dist/resolution/frameworks/cics.d.ts +20 -0
- package/lib/dist/resolution/frameworks/cics.d.ts.map +1 -0
- package/lib/dist/resolution/frameworks/cics.js +90 -0
- package/lib/dist/resolution/frameworks/cics.js.map +1 -0
- package/lib/dist/resolution/frameworks/index.d.ts.map +1 -1
- package/lib/dist/resolution/frameworks/index.js +6 -0
- package/lib/dist/resolution/frameworks/index.js.map +1 -1
- package/lib/dist/resolution/frameworks/java.d.ts.map +1 -1
- package/lib/dist/resolution/frameworks/java.js +14 -6
- package/lib/dist/resolution/frameworks/java.js.map +1 -1
- package/lib/dist/resolution/frameworks/terraform.d.ts +38 -0
- package/lib/dist/resolution/frameworks/terraform.d.ts.map +1 -0
- package/lib/dist/resolution/frameworks/terraform.js +277 -0
- package/lib/dist/resolution/frameworks/terraform.js.map +1 -0
- package/lib/dist/resolution/import-resolver.d.ts +7 -0
- package/lib/dist/resolution/import-resolver.d.ts.map +1 -1
- package/lib/dist/resolution/import-resolver.js +129 -4
- package/lib/dist/resolution/import-resolver.js.map +1 -1
- package/lib/dist/resolution/index.d.ts +39 -6
- package/lib/dist/resolution/index.d.ts.map +1 -1
- package/lib/dist/resolution/index.js +287 -50
- package/lib/dist/resolution/index.js.map +1 -1
- package/lib/dist/resolution/name-matcher.d.ts +0 -3
- package/lib/dist/resolution/name-matcher.d.ts.map +1 -1
- package/lib/dist/resolution/name-matcher.js +225 -33
- package/lib/dist/resolution/name-matcher.js.map +1 -1
- package/lib/dist/resolution/strip-comments.d.ts +1 -1
- package/lib/dist/resolution/strip-comments.d.ts.map +1 -1
- package/lib/dist/resolution/strip-comments.js +49 -0
- package/lib/dist/resolution/strip-comments.js.map +1 -1
- package/lib/dist/resolution/types.d.ts +20 -0
- package/lib/dist/resolution/types.d.ts.map +1 -1
- package/lib/dist/resolution/workspace-packages.d.ts +10 -0
- package/lib/dist/resolution/workspace-packages.d.ts.map +1 -1
- package/lib/dist/resolution/workspace-packages.js +142 -4
- package/lib/dist/resolution/workspace-packages.js.map +1 -1
- package/lib/dist/search/identifier-segments.d.ts +60 -0
- package/lib/dist/search/identifier-segments.d.ts.map +1 -0
- package/lib/dist/search/identifier-segments.js +176 -0
- package/lib/dist/search/identifier-segments.js.map +1 -0
- package/lib/dist/sync/git-hooks.d.ts.map +1 -1
- package/lib/dist/sync/git-hooks.js +2 -0
- package/lib/dist/sync/git-hooks.js.map +1 -1
- package/lib/dist/sync/watcher.d.ts +10 -5
- package/lib/dist/sync/watcher.d.ts.map +1 -1
- package/lib/dist/sync/watcher.js +51 -14
- package/lib/dist/sync/watcher.js.map +1 -1
- package/lib/dist/sync/worktree.d.ts.map +1 -1
- package/lib/dist/sync/worktree.js +5 -0
- package/lib/dist/sync/worktree.js.map +1 -1
- package/lib/dist/types.d.ts +19 -1
- package/lib/dist/types.d.ts.map +1 -1
- package/lib/dist/types.js +10 -0
- package/lib/dist/types.js.map +1 -1
- package/lib/node_modules/.package-lock.json +1 -1
- package/lib/package.json +1 -1
- package/package.json +1 -1
- package/lib/dist/reasoning/config.d.ts +0 -45
- package/lib/dist/reasoning/config.d.ts.map +0 -1
- package/lib/dist/reasoning/config.js +0 -171
- package/lib/dist/reasoning/config.js.map +0 -1
- package/lib/dist/reasoning/credentials.d.ts +0 -5
- package/lib/dist/reasoning/credentials.d.ts.map +0 -1
- package/lib/dist/reasoning/credentials.js +0 -83
- package/lib/dist/reasoning/credentials.js.map +0 -1
- package/lib/dist/reasoning/login.d.ts +0 -21
- package/lib/dist/reasoning/login.d.ts.map +0 -1
- package/lib/dist/reasoning/login.js +0 -85
- package/lib/dist/reasoning/login.js.map +0 -1
- package/lib/dist/reasoning/reasoner.d.ts +0 -43
- package/lib/dist/reasoning/reasoner.d.ts.map +0 -1
- package/lib/dist/reasoning/reasoner.js +0 -308
- package/lib/dist/reasoning/reasoner.js.map +0 -1
|
@@ -0,0 +1,127 @@
|
|
|
1
|
+
"use strict";
|
|
2
|
+
Object.defineProperty(exports, "__esModule", { value: true });
|
|
3
|
+
exports.arktsExtractor = void 0;
|
|
4
|
+
const typescript_1 = require("./typescript");
|
|
5
|
+
/**
|
|
6
|
+
* ArkTS (HarmonyOS / OpenHarmony, `.ets`) — a TypeScript superset whose
|
|
7
|
+
* headline feature is declarative UI: an `@Component struct` with a `build()`
|
|
8
|
+
* method describing the view tree, `@State`/`@Prop`/`@Link` reactive
|
|
9
|
+
* properties, and global `@Builder`/`@Extend`/`@Styles` functions.
|
|
10
|
+
*
|
|
11
|
+
* The vendored grammar (harmony-contrib/tree-sitter-arkts) extends
|
|
12
|
+
* tree-sitter-javascript exactly the way tree-sitter-typescript does, so every
|
|
13
|
+
* TS node type — and therefore the whole typescriptExtractor — applies
|
|
14
|
+
* verbatim. ArkTS-specific shapes it adds:
|
|
15
|
+
*
|
|
16
|
+
* - `struct_declaration` / `struct_body` — the `@Component struct`. Same
|
|
17
|
+
* `name:`/`body:` fields as class_declaration; members are ordinary
|
|
18
|
+
* `method_definition` / `public_field_definition` nodes, so struct members
|
|
19
|
+
* extract through the standard class-member paths.
|
|
20
|
+
* - `arkui_component_expression` — a build()-DSL component instantiation
|
|
21
|
+
* (`Column() { … }`). Carries a `function:` field (the component), an
|
|
22
|
+
* optional `children:` block, and — unlike TS — the CHAINED ATTRIBUTES as
|
|
23
|
+
* repeated `property:`/`arguments:` field pairs on the SAME node
|
|
24
|
+
* (`Text(x).fontSize(16).opacity(0.6)` is ONE node, not nested calls).
|
|
25
|
+
* Handled by the arkts branch in extractCall (tree-sitter.ts).
|
|
26
|
+
* - Decorators on functions (`@Builder function F() {}`) — invalid in TS,
|
|
27
|
+
* first-class here (a `decorator:` field on function_declaration), so the
|
|
28
|
+
* core's existing extractDecoratorsFor path captures them.
|
|
29
|
+
*/
|
|
30
|
+
/** Reactive/state decorators that make a member worth flagging (searchable). */
|
|
31
|
+
const DECORATED_MEMBER_TYPES = new Set([
|
|
32
|
+
'struct_declaration',
|
|
33
|
+
'public_field_definition',
|
|
34
|
+
'method_definition',
|
|
35
|
+
'function_declaration',
|
|
36
|
+
]);
|
|
37
|
+
/**
|
|
38
|
+
* Collect decorator names for a declaration from BOTH positions the grammar
|
|
39
|
+
* produces: direct `decorator` children (`@Entry @Component struct X`,
|
|
40
|
+
* `@State count` on a field) and preceding `decorator` siblings (`@Builder`
|
|
41
|
+
* before a method_definition inside struct_body; `@Component` on the
|
|
42
|
+
* export_statement wrapping `export struct X`). The backwards sibling walk
|
|
43
|
+
* stops at the first non-decorator so an earlier declaration's decorators
|
|
44
|
+
* never leak in (mirrors extractDecoratorsFor's sibling pass).
|
|
45
|
+
*/
|
|
46
|
+
function collectDecoratorNames(node) {
|
|
47
|
+
const names = [];
|
|
48
|
+
const nameOf = (dec) => {
|
|
49
|
+
for (let i = 0; i < dec.namedChildCount; i++) {
|
|
50
|
+
const child = dec.namedChild(i);
|
|
51
|
+
if (!child)
|
|
52
|
+
continue;
|
|
53
|
+
if (child.type === 'identifier')
|
|
54
|
+
return child.text;
|
|
55
|
+
if (child.type === 'call_expression') {
|
|
56
|
+
// `@StorageLink('theme')` / `@Extend(Text)` — the decorator name is
|
|
57
|
+
// the callee.
|
|
58
|
+
const fn = child.childForFieldName('function');
|
|
59
|
+
if (fn?.type === 'identifier')
|
|
60
|
+
return fn.text;
|
|
61
|
+
}
|
|
62
|
+
}
|
|
63
|
+
return undefined;
|
|
64
|
+
};
|
|
65
|
+
for (let i = 0; i < node.namedChildCount; i++) {
|
|
66
|
+
const child = node.namedChild(i);
|
|
67
|
+
if (child?.type === 'decorator') {
|
|
68
|
+
const n = nameOf(child);
|
|
69
|
+
if (n)
|
|
70
|
+
names.push(n);
|
|
71
|
+
}
|
|
72
|
+
}
|
|
73
|
+
const parent = node.parent;
|
|
74
|
+
if (parent) {
|
|
75
|
+
// Find this node among the parent's named children by start offset
|
|
76
|
+
// (wrapper identity is not stable across navigation), then walk backwards.
|
|
77
|
+
const start = node.startIndex;
|
|
78
|
+
let idx = -1;
|
|
79
|
+
for (let i = 0; i < parent.namedChildCount; i++) {
|
|
80
|
+
const sib = parent.namedChild(i);
|
|
81
|
+
if (sib && sib.startIndex === start) {
|
|
82
|
+
idx = i;
|
|
83
|
+
break;
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
for (let i = idx - 1; i >= 0; i--) {
|
|
87
|
+
const sib = parent.namedChild(i);
|
|
88
|
+
if (!sib || sib.type !== 'decorator')
|
|
89
|
+
break;
|
|
90
|
+
const n = nameOf(sib);
|
|
91
|
+
if (n)
|
|
92
|
+
names.unshift(n);
|
|
93
|
+
}
|
|
94
|
+
}
|
|
95
|
+
return names.length > 0 ? names : undefined;
|
|
96
|
+
}
|
|
97
|
+
exports.arktsExtractor = {
|
|
98
|
+
...typescript_1.typescriptExtractor,
|
|
99
|
+
// `@Component struct X { … }` — extractStruct handles it (kind `struct`,
|
|
100
|
+
// members extracted like class members, `this.m()` resolution and the
|
|
101
|
+
// class/struct containment gates in the name-matcher all apply as-is). The
|
|
102
|
+
// component-ness is preserved on the node's decorators (`Component`,
|
|
103
|
+
// `Entry`, `CustomDialog`, `Reusable`), captured by extractModifiers below.
|
|
104
|
+
structTypes: ['struct_declaration'],
|
|
105
|
+
// build()-DSL component instantiations are call sites: `TodoRow({...})`
|
|
106
|
+
// inside a parent's build() is the parent→child component edge, resolved by
|
|
107
|
+
// the ordinary call pipeline against the child's struct node. The arkts
|
|
108
|
+
// branch in extractCall also lifts each chained `.attr(...)` (emitted
|
|
109
|
+
// dot-prefixed so it can ONLY resolve to `@Extend`/`@Styles`/`@Builder`
|
|
110
|
+
// attribute helpers — see matchReference) and `.onXxx(this.handler)`
|
|
111
|
+
// method-reference bindings. `leading_dot_expression` is the detached-chain
|
|
112
|
+
// shape the grammar produces when a nested component's chain starts on the
|
|
113
|
+
// line after its closing `}` inside arkui_children.
|
|
114
|
+
callTypes: ['call_expression', 'arkui_component_expression', 'leading_dot_expression'],
|
|
115
|
+
// Surface ArkTS decorators on the node's `decorators` list (searchable, and
|
|
116
|
+
// the hook a future ArkUI state→build synthesizer keys off). Core paths
|
|
117
|
+
// already emit `decorates` REFERENCES for classes/methods/properties/
|
|
118
|
+
// functions; this hook is what puts the names on struct nodes too —
|
|
119
|
+
// extractStruct has no extractDecoratorsFor call, and node.decorators is
|
|
120
|
+
// only populated via extractModifiers (see createNode).
|
|
121
|
+
extractModifiers: (node) => {
|
|
122
|
+
if (!DECORATED_MEMBER_TYPES.has(node.type))
|
|
123
|
+
return undefined;
|
|
124
|
+
return collectDecoratorNames(node);
|
|
125
|
+
},
|
|
126
|
+
};
|
|
127
|
+
//# sourceMappingURL=arkts.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"arkts.js","sourceRoot":"","sources":["../../../src/extraction/languages/arkts.ts"],"names":[],"mappings":";;;AACA,6CAAmD;AAGnD;;;;;;;;;;;;;;;;;;;;;;;;GAwBG;AAEH,gFAAgF;AAChF,MAAM,sBAAsB,GAAG,IAAI,GAAG,CAAC;IACrC,oBAAoB;IACpB,yBAAyB;IACzB,mBAAmB;IACnB,sBAAsB;CACvB,CAAC,CAAC;AAEH;;;;;;;;GAQG;AACH,SAAS,qBAAqB,CAAC,IAAgB;IAC7C,MAAM,KAAK,GAAa,EAAE,CAAC;IAC3B,MAAM,MAAM,GAAG,CAAC,GAAe,EAAsB,EAAE;QACrD,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,GAAG,CAAC,eAAe,EAAE,CAAC,EAAE,EAAE,CAAC;YAC7C,MAAM,KAAK,GAAG,GAAG,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC;YAChC,IAAI,CAAC,KAAK;gBAAE,SAAS;YACrB,IAAI,KAAK,CAAC,IAAI,KAAK,YAAY;gBAAE,OAAO,KAAK,CAAC,IAAI,CAAC;YACnD,IAAI,KAAK,CAAC,IAAI,KAAK,iBAAiB,EAAE,CAAC;gBACrC,oEAAoE;gBACpE,cAAc;gBACd,MAAM,EAAE,GAAG,KAAK,CAAC,iBAAiB,CAAC,UAAU,CAAC,CAAC;gBAC/C,IAAI,EAAE,EAAE,IAAI,KAAK,YAAY;oBAAE,OAAO,EAAE,CAAC,IAAI,CAAC;YAChD,CAAC;QACH,CAAC;QACD,OAAO,SAAS,CAAC;IACnB,CAAC,CAAC;IAEF,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,IAAI,CAAC,eAAe,EAAE,CAAC,EAAE,EAAE,CAAC;QAC9C,MAAM,KAAK,GAAG,IAAI,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC;QACjC,IAAI,KAAK,EAAE,IAAI,KAAK,WAAW,EAAE,CAAC;YAChC,MAAM,CAAC,GAAG,MAAM,CAAC,KAAK,CAAC,CAAC;YACxB,IAAI,CAAC;gBAAE,KAAK,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC;QACvB,CAAC;IACH,CAAC;IAED,MAAM,MAAM,GAAG,IAAI,CAAC,MAAM,CAAC;IAC3B,IAAI,MAAM,EAAE,CAAC;QACX,mEAAmE;QACnE,2EAA2E;QAC3E,MAAM,KAAK,GAAG,IAAI,CAAC,UAAU,CAAC;QAC9B,IAAI,GAAG,GAAG,CAAC,CAAC,CAAC;QACb,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,MAAM,CAAC,eAAe,EAAE,CAAC,EAAE,EAAE,CAAC;YAChD,MAAM,GAAG,GAAG,MAAM,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC;YACjC,IAAI,GAAG,IAAI,GAAG,CAAC,UAAU,KAAK,KAAK,EAAE,CAAC;gBACpC,GAAG,GAAG,CAAC,CAAC;gBACR,MAAM;YACR,CAAC;QACH,CAAC;QACD,KAAK,IAAI,CAAC,GAAG,GAAG,GAAG,CAAC,EAAE,CAAC,IAAI,CAAC,EAAE,CAAC,EAAE,EAAE,CAAC;YAClC,MAAM,GAAG,GAAG,MAAM,CAAC,UAAU,CAAC,CAAC,CAAC,CAAC;YACjC,IAAI,CAAC,GAAG,IAAI,GAAG,CAAC,IAAI,KAAK,WAAW;gBAAE,MAAM;YAC5C,MAAM,CAAC,GAAG,MAAM,CAAC,GAAG,CAAC,CAAC;YACtB,IAAI,CAAC;gBAAE,KAAK,CAAC,OAAO,CAAC,CAAC,CAAC,CAAC;QAC1B,CAAC;IACH,CAAC;IAED,OAAO,KAAK,CAAC,MAAM,GAAG,CAAC,CAAC,CAAC,CAAC,KAAK,CAAC,CAAC,CAAC,SAAS,CAAC;AAC9C,CAAC;AAEY,QAAA,cAAc,GAAsB;IAC/C,GAAG,gCAAmB;IAEtB,yEAAyE;IACzE,sEAAsE;IACtE,2EAA2E;IAC3E,qEAAqE;IACrE,4EAA4E;IAC5E,WAAW,EAAE,CAAC,oBAAoB,CAAC;IAEnC,wEAAwE;IACxE,4EAA4E;IAC5E,wEAAwE;IACxE,sEAAsE;IACtE,wEAAwE;IACxE,qEAAqE;IACrE,4EAA4E;IAC5E,2EAA2E;IAC3E,oDAAoD;IACpD,SAAS,EAAE,CAAC,iBAAiB,EAAE,4BAA4B,EAAE,wBAAwB,CAAC;IAEtF,4EAA4E;IAC5E,wEAAwE;IACxE,sEAAsE;IACtE,oEAAoE;IACpE,yEAAyE;IACzE,wDAAwD;IACxD,gBAAgB,EAAE,CAAC,IAAI,EAAE,EAAE;QACzB,IAAI,CAAC,sBAAsB,CAAC,GAAG,CAAC,IAAI,CAAC,IAAI,CAAC;YAAE,OAAO,SAAS,CAAC;QAC7D,OAAO,qBAAqB,CAAC,IAAI,CAAC,CAAC;IACrC,CAAC;CACF,CAAC"}
|
|
@@ -64,5 +64,47 @@ export declare function blankCppInlineMacros(source: string): string;
|
|
|
64
64
|
* that is a bare primitive/keyword rather than a real identifier.
|
|
65
65
|
*/
|
|
66
66
|
export declare function recoverMangledCppName(name: string): string;
|
|
67
|
+
export declare function blankMetalAttributes(source: string): string;
|
|
68
|
+
/**
|
|
69
|
+
* Blank annotation-style macro invocations that decorate a declaration but carry
|
|
70
|
+
* NO terminating semicolon — the pervasive Unreal-Engine reflection markup
|
|
71
|
+
* (`UPROPERTY(...)`, `UFUNCTION(...)`, `UCLASS(...)`, `GENERATED_BODY()`,
|
|
72
|
+
* `UE_DEPRECATED_FORGAME(...)`, `DECLARE_DELEGATE_*(...)`, …) that sits on its
|
|
73
|
+
* own line right before a member/type. tree-sitter's C++ grammar doesn't know
|
|
74
|
+
* these are macros, so each one drops into error recovery; in a big reflected
|
|
75
|
+
* class (`CharacterMovementComponent.h` has ~240 of them) the errors accumulate
|
|
76
|
+
* until the enclosing `class_specifier` can't close and collapses into an ERROR
|
|
77
|
+
* node — the whole class definition, its members, and its `extends` edges vanish
|
|
78
|
+
* from the graph. Neither `blankCppExportMacros` (class-header export macros) nor
|
|
79
|
+
* `blankCppInlineMacros` (return-type inline specifiers) touches these in-body
|
|
80
|
+
* markup macros. Replacing each with equal-length spaces preserves every byte
|
|
81
|
+
* offset (so line/column stay exact) and the class then parses normally.
|
|
82
|
+
*
|
|
83
|
+
* Deliberately name-list-FREE — UE alone has hundreds of such macros and projects
|
|
84
|
+
* add their own — so it keys on structure, not a curated list, matched tightly to
|
|
85
|
+
* avoid touching legitimate C++:
|
|
86
|
+
* - the macro must be the FIRST non-whitespace token on its line (`^[ \t]*`),
|
|
87
|
+
* which is where declaration markup lives — so a macro used inside an
|
|
88
|
+
* expression or condition (`if (CHECK(x))`, `x = MACRO(a) + b`) is never
|
|
89
|
+
* matched (it isn't line-leading);
|
|
90
|
+
* - the name must be ALL-CAPS (`[A-Z][A-Z0-9_]{2,}`), since ordinary
|
|
91
|
+
* function/type names called at line start are lower/mixed case;
|
|
92
|
+
* - the char after the balanced `(...)` must START A DECLARATION — a letter,
|
|
93
|
+
* `_`, `~` (destructor), or `#` (a following directive). Declaration markup is
|
|
94
|
+
* always followed by the thing it decorates (`UPROPERTY(...)\n float X;`,
|
|
95
|
+
* `UE_DEPRECATED(...) UPROPERTY(...)`), whereas a statement call is followed by
|
|
96
|
+
* `;` (`FOO(x);`), an init-list item by `,`/`{`, and an expression fragment by
|
|
97
|
+
* an operator (`MAKE(a) + 1`) — all rejected. String/char literals inside the
|
|
98
|
+
* args are skipped so an embedded `)` can't mis-close the balance.
|
|
99
|
+
*
|
|
100
|
+
* C++-only (wired into cppExtractor). A blanked macro inside a block comment is
|
|
101
|
+
* harmless (comments don't parse), and the rare line-leading no-semicolon
|
|
102
|
+
* ALL-CAPS call that isn't markup only loses that one annotation, never a whole
|
|
103
|
+
* class.
|
|
104
|
+
*/
|
|
105
|
+
export declare function blankCppAnnotationMacroCalls(source: string): string;
|
|
106
|
+
export declare function blankCppApiPrefixMacros(source: string): string;
|
|
107
|
+
export declare function blankCppInlineAnnotationMacros(source: string): string;
|
|
108
|
+
export declare function blankCudaConstructs(source: string): string;
|
|
67
109
|
export declare const cppExtractor: LanguageExtractor;
|
|
68
110
|
//# sourceMappingURL=c-cpp.d.ts.map
|
|
@@ -1 +1 @@
|
|
|
1
|
-
{"version":3,"file":"c-cpp.d.ts","sourceRoot":"","sources":["../../../src/extraction/languages/c-cpp.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,sBAAsB,CAAC;
|
|
1
|
+
{"version":3,"file":"c-cpp.d.ts","sourceRoot":"","sources":["../../../src/extraction/languages/c-cpp.ts"],"names":[],"mappings":"AAEA,OAAO,KAAK,EAAE,iBAAiB,EAAE,MAAM,sBAAsB,CAAC;AAwG9D;;;;;;GAMG;AACH,wBAAgB,sBAAsB,CAAC,GAAG,EAAE,MAAM,GAAG,MAAM,GAAG,SAAS,CAkBtE;AAED;;;;;;;;;;;;;;GAcG;AACH,wBAAgB,oBAAoB,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAUzD;AAaD,eAAO,MAAM,UAAU,EAAE,iBAuDxB,CAAC;AAoCF;;;;;;;;;;;;;;;;;;;;;GAqBG;AACH,wBAAgB,oBAAoB,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,CAM3D;AA8ED,wBAAgB,oBAAoB,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,CAG3D;AAWD;;;;;;;;;;;;;;GAcG;AACH,wBAAgB,qBAAqB,CAAC,IAAI,EAAE,MAAM,GAAG,MAAM,CAQ1D;AAyBD,wBAAgB,oBAAoB,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,CAG3D;AAED;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;GAoCG;AACH,wBAAgB,4BAA4B,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,CAwCnE;AA4BD,wBAAgB,uBAAuB,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,CAG9D;AAuBD,wBAAgB,8BAA8B,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,CAiCrE;AAiDD,wBAAgB,mBAAmB,CAAC,MAAM,EAAE,MAAM,GAAG,MAAM,CAmB1D;AA2CD,eAAO,MAAM,YAAY,EAAE,iBAsF1B,CAAC"}
|
|
@@ -6,6 +6,11 @@ exports.stripCppTemplateArgs = stripCppTemplateArgs;
|
|
|
6
6
|
exports.blankCppExportMacros = blankCppExportMacros;
|
|
7
7
|
exports.blankCppInlineMacros = blankCppInlineMacros;
|
|
8
8
|
exports.recoverMangledCppName = recoverMangledCppName;
|
|
9
|
+
exports.blankMetalAttributes = blankMetalAttributes;
|
|
10
|
+
exports.blankCppAnnotationMacroCalls = blankCppAnnotationMacroCalls;
|
|
11
|
+
exports.blankCppApiPrefixMacros = blankCppApiPrefixMacros;
|
|
12
|
+
exports.blankCppInlineAnnotationMacros = blankCppInlineAnnotationMacros;
|
|
13
|
+
exports.blankCudaConstructs = blankCudaConstructs;
|
|
9
14
|
const tree_sitter_helpers_1 = require("../tree-sitter-helpers");
|
|
10
15
|
/**
|
|
11
16
|
* Find the function NAME's `qualified_identifier` (`Foo::bar`) inside a
|
|
@@ -32,7 +37,60 @@ function findDeclaratorQualifiedId(declarator) {
|
|
|
32
37
|
}
|
|
33
38
|
return undefined;
|
|
34
39
|
}
|
|
40
|
+
/**
|
|
41
|
+
* Recover the real function name from the macro-definition idiom
|
|
42
|
+
* `MACRO_NAME(real_name, typed args…) { body }` — flash-attention's
|
|
43
|
+
* `DEFINE_FLASH_FORWARD_KERNEL(flash_fwd_kernel, bool Is_dropout, …) { … }`
|
|
44
|
+
* being the motivating case: tree-sitter parses the invocation as a
|
|
45
|
+
* function_definition NAMED after the macro, so every such kernel shared one
|
|
46
|
+
* name (`DEFINE_FLASH_FORWARD_KERNEL`) and the launch sites' calls to the real
|
|
47
|
+
* names (`flash_fwd_kernel<…><<<…>>>`) could never resolve.
|
|
48
|
+
*
|
|
49
|
+
* Deliberately narrow so name-in-first-arg is unambiguous — ALL of:
|
|
50
|
+
* - the parsed name is macro-shaped: ALL-CAPS with at least one underscore
|
|
51
|
+
* (`TEST` never matches; K&R C definitions have lowercase names);
|
|
52
|
+
* - the first "parameter" is a LONE identifier (no type, no declarator)
|
|
53
|
+
* containing a lowercase letter — the name being defined;
|
|
54
|
+
* - at least one more parameter follows and NONE of them is another lone
|
|
55
|
+
* identifier — a second bare arg means the first isn't the name (gtest's
|
|
56
|
+
* `TEST_F(Fixture, Name)`, `PYBIND11_MODULE(ext, m)`,
|
|
57
|
+
* google-benchmark's `BENCHMARK_DEFINE_F(Fix, name)` all bail here).
|
|
58
|
+
*/
|
|
59
|
+
function recoverCppMacroDefinedName(node, source) {
|
|
60
|
+
if (node.type !== 'function_definition')
|
|
61
|
+
return undefined;
|
|
62
|
+
const declarator = (0, tree_sitter_helpers_1.getChildByField)(node, 'declarator');
|
|
63
|
+
if (declarator?.type !== 'function_declarator')
|
|
64
|
+
return undefined;
|
|
65
|
+
const inner = (0, tree_sitter_helpers_1.getChildByField)(declarator, 'declarator');
|
|
66
|
+
if (inner?.type !== 'identifier')
|
|
67
|
+
return undefined;
|
|
68
|
+
const macroName = (0, tree_sitter_helpers_1.getNodeText)(inner, source);
|
|
69
|
+
if (!/^[A-Z][A-Z0-9]*(?:_[A-Z0-9]+)+$/.test(macroName))
|
|
70
|
+
return undefined;
|
|
71
|
+
const params = (0, tree_sitter_helpers_1.getChildByField)(declarator, 'parameters');
|
|
72
|
+
if (!params || params.namedChildCount < 2)
|
|
73
|
+
return undefined;
|
|
74
|
+
const loneIdentText = (p) => p.type === 'parameter_declaration' &&
|
|
75
|
+
p.namedChildCount === 1 &&
|
|
76
|
+
p.namedChild(0)?.type === 'type_identifier'
|
|
77
|
+
? (0, tree_sitter_helpers_1.getNodeText)(p.namedChild(0), source)
|
|
78
|
+
: null;
|
|
79
|
+
const first = params.namedChild(0);
|
|
80
|
+
const name = first ? loneIdentText(first) : null;
|
|
81
|
+
if (!name || !/[a-z]/.test(name))
|
|
82
|
+
return undefined;
|
|
83
|
+
for (let i = 1; i < params.namedChildCount; i++) {
|
|
84
|
+
const p = params.namedChild(i);
|
|
85
|
+
if (p && loneIdentText(p) !== null)
|
|
86
|
+
return undefined;
|
|
87
|
+
}
|
|
88
|
+
return name;
|
|
89
|
+
}
|
|
35
90
|
function extractCppQualifiedMethodName(node, source) {
|
|
91
|
+
const macroDefined = recoverCppMacroDefinedName(node, source);
|
|
92
|
+
if (macroDefined)
|
|
93
|
+
return macroDefined;
|
|
36
94
|
const declarator = (0, tree_sitter_helpers_1.getChildByField)(node, 'declarator');
|
|
37
95
|
if (!declarator)
|
|
38
96
|
return undefined;
|
|
@@ -139,6 +197,8 @@ function extractCppReturnType(node, source) {
|
|
|
139
197
|
return normalizeCppReturnType((0, tree_sitter_helpers_1.getNodeText)(typeNode, source));
|
|
140
198
|
}
|
|
141
199
|
exports.cExtractor = {
|
|
200
|
+
// CUDA in C-detected headers (content-gated blank; see preParseCSource).
|
|
201
|
+
preParse: preParseCSource,
|
|
142
202
|
// Universal net: recover a real name from any macro-mangled function name.
|
|
143
203
|
recoverMangledName: recoverMangledCppName,
|
|
144
204
|
functionTypes: ['function_definition'],
|
|
@@ -369,10 +429,315 @@ function recoverMangledCppName(name) {
|
|
|
369
429
|
return name;
|
|
370
430
|
return candidate;
|
|
371
431
|
}
|
|
372
|
-
/**
|
|
373
|
-
*
|
|
374
|
-
|
|
375
|
-
|
|
432
|
+
/**
|
|
433
|
+
* Blank Metal Shading Language `[[attribute]]` annotations before parsing.
|
|
434
|
+
* MSL (≈ C++14) puts attributes AFTER the declarator — `float4 position
|
|
435
|
+
* [[position]];`, `constant Uniforms &u [[buffer(0)]]` — a position
|
|
436
|
+
* tree-sitter-cpp can't reconcile: a struct field with a trailing attribute
|
|
437
|
+
* misparses into a shape that emits a spurious `extends` reference from the
|
|
438
|
+
* struct to the field's *type* (`VertexIn extends float3`), which becomes a
|
|
439
|
+
* wrong inheritance edge whenever the repo defines that type itself (simd
|
|
440
|
+
* typedefs in a shared ShaderTypes.h are common). Replacing the attribute with
|
|
441
|
+
* equal-length spaces preserves every byte offset and lets fields and
|
|
442
|
+
* parameters parse as ordinary declarations, mirroring the macro blanks above.
|
|
443
|
+
*
|
|
444
|
+
* Matched tightly to the attribute shape — `[[ident]]`, `[[ident(args)]]`, and
|
|
445
|
+
* comma-separated lists (`[[buffer(0), raster_order_group(0)]]`) — so a
|
|
446
|
+
* subscripted lambda call (`arr[[]{ … }()]`, the only other way `[[` appears in
|
|
447
|
+
* C++-family source) can never match: after `[[` a lambda continues with `]`,
|
|
448
|
+
* never an identifier followed by `]]`. Applied ONLY to `.metal` files — in
|
|
449
|
+
* regular C++ the pre-declarator attribute position (`[[nodiscard]] int f()`)
|
|
450
|
+
* is legal syntax the grammar parses natively, and blanking it would be pure
|
|
451
|
+
* blast radius. (#1121)
|
|
452
|
+
*/
|
|
453
|
+
const METAL_ATTRIBUTE_RE = /\[\[\s*[A-Za-z_]\w*(?:\s*\([^()\n]*\))?(?:\s*,\s*[A-Za-z_]\w*(?:\s*\([^()\n]*\))?)*\s*\]\]/g;
|
|
454
|
+
function blankMetalAttributes(source) {
|
|
455
|
+
if (source.indexOf('[[') === -1)
|
|
456
|
+
return source;
|
|
457
|
+
return source.replace(METAL_ATTRIBUTE_RE, (m) => ' '.repeat(m.length));
|
|
458
|
+
}
|
|
459
|
+
/**
|
|
460
|
+
* Blank annotation-style macro invocations that decorate a declaration but carry
|
|
461
|
+
* NO terminating semicolon — the pervasive Unreal-Engine reflection markup
|
|
462
|
+
* (`UPROPERTY(...)`, `UFUNCTION(...)`, `UCLASS(...)`, `GENERATED_BODY()`,
|
|
463
|
+
* `UE_DEPRECATED_FORGAME(...)`, `DECLARE_DELEGATE_*(...)`, …) that sits on its
|
|
464
|
+
* own line right before a member/type. tree-sitter's C++ grammar doesn't know
|
|
465
|
+
* these are macros, so each one drops into error recovery; in a big reflected
|
|
466
|
+
* class (`CharacterMovementComponent.h` has ~240 of them) the errors accumulate
|
|
467
|
+
* until the enclosing `class_specifier` can't close and collapses into an ERROR
|
|
468
|
+
* node — the whole class definition, its members, and its `extends` edges vanish
|
|
469
|
+
* from the graph. Neither `blankCppExportMacros` (class-header export macros) nor
|
|
470
|
+
* `blankCppInlineMacros` (return-type inline specifiers) touches these in-body
|
|
471
|
+
* markup macros. Replacing each with equal-length spaces preserves every byte
|
|
472
|
+
* offset (so line/column stay exact) and the class then parses normally.
|
|
473
|
+
*
|
|
474
|
+
* Deliberately name-list-FREE — UE alone has hundreds of such macros and projects
|
|
475
|
+
* add their own — so it keys on structure, not a curated list, matched tightly to
|
|
476
|
+
* avoid touching legitimate C++:
|
|
477
|
+
* - the macro must be the FIRST non-whitespace token on its line (`^[ \t]*`),
|
|
478
|
+
* which is where declaration markup lives — so a macro used inside an
|
|
479
|
+
* expression or condition (`if (CHECK(x))`, `x = MACRO(a) + b`) is never
|
|
480
|
+
* matched (it isn't line-leading);
|
|
481
|
+
* - the name must be ALL-CAPS (`[A-Z][A-Z0-9_]{2,}`), since ordinary
|
|
482
|
+
* function/type names called at line start are lower/mixed case;
|
|
483
|
+
* - the char after the balanced `(...)` must START A DECLARATION — a letter,
|
|
484
|
+
* `_`, `~` (destructor), or `#` (a following directive). Declaration markup is
|
|
485
|
+
* always followed by the thing it decorates (`UPROPERTY(...)\n float X;`,
|
|
486
|
+
* `UE_DEPRECATED(...) UPROPERTY(...)`), whereas a statement call is followed by
|
|
487
|
+
* `;` (`FOO(x);`), an init-list item by `,`/`{`, and an expression fragment by
|
|
488
|
+
* an operator (`MAKE(a) + 1`) — all rejected. String/char literals inside the
|
|
489
|
+
* args are skipped so an embedded `)` can't mis-close the balance.
|
|
490
|
+
*
|
|
491
|
+
* C++-only (wired into cppExtractor). A blanked macro inside a block comment is
|
|
492
|
+
* harmless (comments don't parse), and the rare line-leading no-semicolon
|
|
493
|
+
* ALL-CAPS call that isn't markup only loses that one annotation, never a whole
|
|
494
|
+
* class.
|
|
495
|
+
*/
|
|
496
|
+
function blankCppAnnotationMacroCalls(source) {
|
|
497
|
+
if (!/^[ \t]*[A-Z][A-Z0-9_]{2,}\s*\(/m.test(source))
|
|
498
|
+
return source;
|
|
499
|
+
const chars = source.split('');
|
|
500
|
+
const re = /^([ \t]*)([A-Z][A-Z0-9_]{2,})(\s*)\(/gm;
|
|
501
|
+
let m;
|
|
502
|
+
while ((m = re.exec(source)) !== null) {
|
|
503
|
+
const macroStart = m.index + (m[1] ?? '').length; // skip leading indent
|
|
504
|
+
let i = m.index + m[0].length - 1; // index of the opening '('
|
|
505
|
+
let depth = 0;
|
|
506
|
+
let end = -1;
|
|
507
|
+
for (; i < source.length; i++) {
|
|
508
|
+
const c = source[i];
|
|
509
|
+
if (c === '"' || c === "'") {
|
|
510
|
+
const quote = c;
|
|
511
|
+
i++;
|
|
512
|
+
while (i < source.length && source[i] !== quote) {
|
|
513
|
+
if (source[i] === '\\')
|
|
514
|
+
i++;
|
|
515
|
+
i++;
|
|
516
|
+
}
|
|
517
|
+
continue;
|
|
518
|
+
}
|
|
519
|
+
if (c === '(')
|
|
520
|
+
depth++;
|
|
521
|
+
else if (c === ')') {
|
|
522
|
+
depth--;
|
|
523
|
+
if (depth === 0) {
|
|
524
|
+
end = i + 1;
|
|
525
|
+
break;
|
|
526
|
+
}
|
|
527
|
+
}
|
|
528
|
+
}
|
|
529
|
+
if (end < 0)
|
|
530
|
+
continue;
|
|
531
|
+
let j = end;
|
|
532
|
+
while (j < source.length && /\s/.test(source[j]))
|
|
533
|
+
j++;
|
|
534
|
+
const after = source[j];
|
|
535
|
+
// Only markup is followed by the declaration it decorates; a statement call
|
|
536
|
+
// (`;`), init-list item (`,`/`{`), or expression fragment (operator) is not.
|
|
537
|
+
if (!after || !/[A-Za-z_~#]/.test(after))
|
|
538
|
+
continue;
|
|
539
|
+
for (let k = macroStart; k < end; k++) {
|
|
540
|
+
if (chars[k] !== '\n' && chars[k] !== '\r')
|
|
541
|
+
chars[k] = ' ';
|
|
542
|
+
}
|
|
543
|
+
re.lastIndex = end;
|
|
544
|
+
}
|
|
545
|
+
return chars.join('');
|
|
546
|
+
}
|
|
547
|
+
/**
|
|
548
|
+
* Blank an export/visibility macro sitting in front of a *member* or *method*
|
|
549
|
+
* declaration inside a class/namespace (`ENGINE_API virtual void Tick(…)`,
|
|
550
|
+
* `static ENGINE_API void AddReferencedObjects(…)`, `UE_API FVector GetVel()
|
|
551
|
+
* const`), before parsing. `blankCppExportMacros` only recovers the macro in a
|
|
552
|
+
* `class MACRO Name` *header*; the very same macro also prefixes almost every
|
|
553
|
+
* exported member of a big Unreal-Engine class, and tree-sitter — not knowing
|
|
554
|
+
* it's a macro — reads `MACRO <return-type> <name>(` as an extra type token and
|
|
555
|
+
* drops each such declaration into error recovery. In a heavily-exported header
|
|
556
|
+
* (`Actor.h`, `World.h`, …) hundreds of these accumulate: the return types pile
|
|
557
|
+
* up as orphan ERROR tokens and, combined with other markup, can still tip the
|
|
558
|
+
* enclosing class into collapse. Replacing the macro with equal-length spaces
|
|
559
|
+
* preserves every byte offset (line/column stay exact) and each member parses
|
|
560
|
+
* as an ordinary declaration.
|
|
561
|
+
*
|
|
562
|
+
* Matched tightly so it can't touch the same token used as a value
|
|
563
|
+
* (`int x = SOME_API;`, `if (mode == FOO_API)`): the token must be ALL-CAPS AND
|
|
564
|
+
* end in the conventional visibility-macro suffix `_API` / `_EXPORT` / `_ABI`
|
|
565
|
+
* (Unreal `*_API`, Qt/Boost `*_EXPORT`, LLVM `*_ABI`) — ordinary identifiers
|
|
566
|
+
* effectively never carry these suffixes — and must be immediately followed by
|
|
567
|
+
* whitespace then a declaration token (`\s+[A-Za-z_]`: a type, `virtual`,
|
|
568
|
+
* `static`, or the name). A value use is instead followed by `;`, `)`, `,`,
|
|
569
|
+
* `=`, `::`, or an operator, all of which fail the look-ahead. C++-only (wired
|
|
570
|
+
* into cppExtractor).
|
|
571
|
+
*/
|
|
572
|
+
const CPP_API_PREFIX_RE = /\b[A-Z][A-Z0-9_]*(?:_API|_EXPORT|_ABI)\b(?=\s+[A-Za-z_])/g;
|
|
573
|
+
function blankCppApiPrefixMacros(source) {
|
|
574
|
+
if (!/_(?:API|EXPORT|ABI)\b/.test(source))
|
|
575
|
+
return source;
|
|
576
|
+
return source.replace(CPP_API_PREFIX_RE, (m) => ' '.repeat(m.length));
|
|
577
|
+
}
|
|
578
|
+
/**
|
|
579
|
+
* Blank an Unreal-Engine annotation macro that appears MID-LINE (not
|
|
580
|
+
* line-leading, so `blankCppAnnotationMacroCalls` never sees it) inside a
|
|
581
|
+
* declaration: an enum value's `UMETA(DisplayName="…")`, a parameter's
|
|
582
|
+
* `UPARAM(ref)`, or a deprecation tag wedged into a `using`/member declaration
|
|
583
|
+
* (`using FOnNetTick UE_DEPRECATED(5.5, "…") = TMulticastDelegate<void(float)>;`
|
|
584
|
+
* in `World.h`, which otherwise collapses `UWorld`). tree-sitter can't reconcile
|
|
585
|
+
* these embedded macro calls and drops into error recovery, and a mid-line one
|
|
586
|
+
* inside a big enum or a class-scope `using` can cascade into the whole enum /
|
|
587
|
+
* class being lost. Replacing the entire `MACRO(...)` (balanced parens, string
|
|
588
|
+
* literals skipped so an embedded `)` can't mis-close) with equal-length spaces
|
|
589
|
+
* preserves every byte offset and the declaration parses normally.
|
|
590
|
+
*
|
|
591
|
+
* Keyed on an explicit UE-only name list (`UMETA`, `UPARAM`, and the
|
|
592
|
+
* `UE_DEPRECATED*` family) — these identifiers are exclusive to Unreal's
|
|
593
|
+
* reflection layer and appear in no standard-C++ or other-library code, so
|
|
594
|
+
* blanking them is zero-risk to non-UE sources. (The line-LEADING forms of
|
|
595
|
+
* `UE_DEPRECATED(...)` are already handled by `blankCppAnnotationMacroCalls`;
|
|
596
|
+
* this covers the mid-line forms it structurally can't.) C++-only.
|
|
597
|
+
*/
|
|
598
|
+
const CPP_INLINE_ANNOTATION_RE = /\b(?:UMETA|UPARAM|UE_DEPRECATED\w*)\s*\(/g;
|
|
599
|
+
function blankCppInlineAnnotationMacros(source) {
|
|
600
|
+
if (!/\b(?:UMETA|UPARAM|UE_DEPRECATED)/.test(source))
|
|
601
|
+
return source;
|
|
602
|
+
const chars = source.split('');
|
|
603
|
+
const re = new RegExp(CPP_INLINE_ANNOTATION_RE.source, 'g');
|
|
604
|
+
let m;
|
|
605
|
+
while ((m = re.exec(source)) !== null) {
|
|
606
|
+
let i = m.index + m[0].length - 1; // index of the opening '('
|
|
607
|
+
let depth = 0;
|
|
608
|
+
let end = -1;
|
|
609
|
+
for (; i < source.length; i++) {
|
|
610
|
+
const c = source[i];
|
|
611
|
+
if (c === '"' || c === "'") {
|
|
612
|
+
const quote = c;
|
|
613
|
+
i++;
|
|
614
|
+
while (i < source.length && source[i] !== quote) {
|
|
615
|
+
if (source[i] === '\\')
|
|
616
|
+
i++;
|
|
617
|
+
i++;
|
|
618
|
+
}
|
|
619
|
+
continue;
|
|
620
|
+
}
|
|
621
|
+
if (c === '(')
|
|
622
|
+
depth++;
|
|
623
|
+
else if (c === ')') {
|
|
624
|
+
depth--;
|
|
625
|
+
if (depth === 0) {
|
|
626
|
+
end = i + 1;
|
|
627
|
+
break;
|
|
628
|
+
}
|
|
629
|
+
}
|
|
630
|
+
}
|
|
631
|
+
if (end < 0)
|
|
632
|
+
continue;
|
|
633
|
+
for (let k = m.index; k < end; k++) {
|
|
634
|
+
if (chars[k] !== '\n' && chars[k] !== '\r')
|
|
635
|
+
chars[k] = ' ';
|
|
636
|
+
}
|
|
637
|
+
re.lastIndex = end;
|
|
638
|
+
}
|
|
639
|
+
return chars.join('');
|
|
640
|
+
}
|
|
641
|
+
/**
|
|
642
|
+
* Blank CUDA-specific constructs before parsing `.cu`/`.cuh` files (parsed with
|
|
643
|
+
* the C++ grammar). Three shapes tree-sitter-cpp can't reconcile, each replaced
|
|
644
|
+
* with equal-length whitespace so every byte offset survives (#387):
|
|
645
|
+
*
|
|
646
|
+
* 1. Execution-space / storage specifiers: in `__global__ void step(…)` or
|
|
647
|
+
* `__shared__ float tile[256]` the specifier parses as the declaration's
|
|
648
|
+
* TYPE and shunts the real return/value type into an ERROR node — mangling
|
|
649
|
+
* signatures and, for `__shared__` arrays, the declared name itself. Blanked
|
|
650
|
+
* unconditionally (no following-token lookahead) so extended lambdas
|
|
651
|
+
* (`[=] __device__ (int i) { … }`) recover too. `__restrict__` is deliberately
|
|
652
|
+
* absent: the grammar already parses it natively as a type_qualifier.
|
|
653
|
+
* 2. `__launch_bounds__(…)` between specifier and declarator — same misparse.
|
|
654
|
+
* The parenthesized form is blanked first; a bare leftover token is caught
|
|
655
|
+
* by the specifier list.
|
|
656
|
+
* 3. Kernel-launch configs `step<<<grid, block, smem, stream>>>(args)`: the
|
|
657
|
+
* chevrons lex as shift operators around an empty-named template, so no
|
|
658
|
+
* call_expression exists and the host→kernel call edge — the main reason to
|
|
659
|
+
* index CUDA at all — is lost. Blanking the `<<<…>>>` span leaves
|
|
660
|
+
* `step (args)`, a plain call the grammar
|
|
661
|
+
* parses natively (templated launches `k<T, 256><<<…>>>(…)` included).
|
|
662
|
+
*
|
|
663
|
+
* The launch-config match is deliberately bounded — statement/brace characters
|
|
664
|
+
* excluded, span capped, newlines preserved by the replacer — so a stray `<<<`
|
|
665
|
+
* (a committed merge-conflict marker, a string literal) can never blank a run
|
|
666
|
+
* of real code: an unmatched launch degrades to the status quo for that call
|
|
667
|
+
* site (no call edge), never to corruption. Applied to `.cu`/`.cuh` files and —
|
|
668
|
+
* because much real CUDA lives in extension-less headers (cutlass launches the
|
|
669
|
+
* majority of its kernels from `.h`; flash-attention's launch templates are
|
|
670
|
+
* `.h`; llm.c keeps device helpers in C-detected `.h`) — to any C/C++-family
|
|
671
|
+
* file whose CONTENT carries a strong CUDA marker (`looksLikeCudaSource`).
|
|
672
|
+
* Unlike Metal's `[[attribute]]` (legal C++ syntax elsewhere, hence Metal's
|
|
673
|
+
* strict extension gate), no CUDA marker is valid C++ anywhere: `<<<` isn't
|
|
674
|
+
* legal syntax and the dunder specifiers are implementation-reserved names no
|
|
675
|
+
* real codebase defines — so a content-triggered blank on a non-CUDA file can
|
|
676
|
+
* only ever whitespace tokens inside comments or strings, which parse the same.
|
|
677
|
+
*/
|
|
678
|
+
const CUDA_LAUNCH_BOUNDS_RE = /\b__launch_bounds__\s*\([^()\n]*\)/g;
|
|
679
|
+
const CUDA_SPECIFIER_RE = /\b__(?:global|device|host|constant|shared|managed|grid_constant|forceinline|noinline|launch_bounds)__\b/g;
|
|
680
|
+
// `;` stays excluded (launch configs are expressions; a stray `<<<` spanning
|
|
681
|
+
// real statements always crosses one) and the span is capped. Braces are
|
|
682
|
+
// allowed through the regex — `k<<<dim3{1,1,1}, dim3{256,1,1}>>>(…)` is a real
|
|
683
|
+
// launch shape — but the replacer only blanks a BALANCED match: a merge
|
|
684
|
+
// conflict's `<<<<<<< … >>>>>>>` region that dodges every `;` still opens
|
|
685
|
+
// braces it never closes, so it fails the balance check and stays untouched.
|
|
686
|
+
const CUDA_LAUNCH_CONFIG_RE = /<<<[^;]{0,400}?>>>/g;
|
|
687
|
+
function blankCudaConstructs(source) {
|
|
688
|
+
let out = source;
|
|
689
|
+
if (out.indexOf('__') !== -1) {
|
|
690
|
+
out = out
|
|
691
|
+
.replace(CUDA_LAUNCH_BOUNDS_RE, (m) => ' '.repeat(m.length))
|
|
692
|
+
.replace(CUDA_SPECIFIER_RE, (m) => ' '.repeat(m.length));
|
|
693
|
+
}
|
|
694
|
+
if (out.indexOf('<<<') !== -1) {
|
|
695
|
+
out = out.replace(CUDA_LAUNCH_CONFIG_RE, (m) => {
|
|
696
|
+
let depth = 0;
|
|
697
|
+
for (let i = 0; i < m.length; i++) {
|
|
698
|
+
const ch = m.charCodeAt(i);
|
|
699
|
+
if (ch === 0x7b /* { */)
|
|
700
|
+
depth++;
|
|
701
|
+
else if (ch === 0x7d /* } */ && --depth < 0)
|
|
702
|
+
return m;
|
|
703
|
+
}
|
|
704
|
+
return depth === 0 ? m.replace(/[^\n]/g, ' ') : m;
|
|
705
|
+
});
|
|
706
|
+
}
|
|
707
|
+
return out;
|
|
708
|
+
}
|
|
709
|
+
/** Strong content markers for CUDA source in files without a CUDA extension
|
|
710
|
+
* (headers). The dunders are execution-space specifiers that only nvcc defines;
|
|
711
|
+
* `cudaStream_t` is the runtime's stream handle, pervasive in launcher headers
|
|
712
|
+
* that themselves declare no kernel. Deliberately excludes weak markers (`dim3`,
|
|
713
|
+
* `<<<`) that could plausibly appear in non-CUDA text. */
|
|
714
|
+
function looksLikeCudaSource(source) {
|
|
715
|
+
return (source.indexOf('__global__') !== -1 ||
|
|
716
|
+
source.indexOf('__device__') !== -1 ||
|
|
717
|
+
source.indexOf('__constant__') !== -1 ||
|
|
718
|
+
source.indexOf('cudaStream_t') !== -1);
|
|
719
|
+
}
|
|
720
|
+
/** C/C++ source pre-processing before tree-sitter: recover macro-annotated class
|
|
721
|
+
* definitions, macro-prefixed function definitions, macro-prefixed members, and
|
|
722
|
+
* macro-decorated members (Unreal-Engine reflection markup) — plus the non-C++
|
|
723
|
+
* surface of the dialects parsed with the C++ grammar: `.metal` MSL attribute
|
|
724
|
+
* annotations, and CUDA specifiers + launch syntax (by `.cu`/`.cuh` extension
|
|
725
|
+
* or by content, for CUDA living in `.h`/`.hpp` headers). Offset-preserving. */
|
|
726
|
+
function preParseCppSource(source, filePath) {
|
|
727
|
+
const blanked = blankCppAnnotationMacroCalls(blankCppInlineAnnotationMacros(blankCppApiPrefixMacros(blankCppInlineMacros(blankCppExportMacros(source)))));
|
|
728
|
+
const lower = filePath ? filePath.toLowerCase() : '';
|
|
729
|
+
if (lower.endsWith('.metal'))
|
|
730
|
+
return blankMetalAttributes(blanked);
|
|
731
|
+
if (lower.endsWith('.cu') || lower.endsWith('.cuh') || looksLikeCudaSource(source)) {
|
|
732
|
+
return blankCudaConstructs(blanked);
|
|
733
|
+
}
|
|
734
|
+
return blanked;
|
|
735
|
+
}
|
|
736
|
+
/** C source pre-processing: C-detected headers in CUDA projects (llm.c keeps
|
|
737
|
+
* `__device__` helpers and kernel prototypes in plain `.h`) get the same
|
|
738
|
+
* content-gated CUDA blank as C++. */
|
|
739
|
+
function preParseCSource(source) {
|
|
740
|
+
return looksLikeCudaSource(source) ? blankCudaConstructs(source) : source;
|
|
376
741
|
}
|
|
377
742
|
exports.cppExtractor = {
|
|
378
743
|
// Recover macro-annotated class/struct definitions (`class MYMODULE_API Foo : Base`,
|