@backbencher/brain 0.0.0-stage → 0.1.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/CHANGELOG.md +298 -0
- package/EMBEDDINGS.md +355 -0
- package/LICENSE +21 -0
- package/README.md +415 -2
- package/bin/bb +13 -0
- package/dist/analysis-exclusions-7ZJDXOVZ.js +35 -0
- package/dist/brain-index-health-KY7K552E.js +17 -0
- package/dist/brain-relationship-enrichment-QH7OOHUF.js +558 -0
- package/dist/brain.sql-EIM4WS4D.js +29 -0
- package/dist/chunk-2BSKD7O3.js +40 -0
- package/dist/chunk-2DE27DVC.js +1314 -0
- package/dist/chunk-2RRBMNBQ.js +322 -0
- package/dist/chunk-2RTN2DFU.js +711 -0
- package/dist/chunk-2WXYNLBA.js +29 -0
- package/dist/chunk-3CTFIJJB.js +17 -0
- package/dist/chunk-3LFTSMIV.js +174 -0
- package/dist/chunk-47HKX4AJ.js +930 -0
- package/dist/chunk-4H22TLOT.js +543 -0
- package/dist/chunk-5SD45FLC.js +818 -0
- package/dist/chunk-66A5ZFYA.js +1758 -0
- package/dist/chunk-6AIRWAO2.js +247 -0
- package/dist/chunk-6WNGD3NN.js +196 -0
- package/dist/chunk-7AN7U5IZ.js +371 -0
- package/dist/chunk-BHB7BYYI.js +626 -0
- package/dist/chunk-BQ3OVQ3P.js +125 -0
- package/dist/chunk-CW4XXSNN.js +1479 -0
- package/dist/chunk-D2Q4Y47A.js +53 -0
- package/dist/chunk-DIYAGQJL.js +34 -0
- package/dist/chunk-DYM4FQEE.js +90 -0
- package/dist/chunk-EWMWK7WN.js +75 -0
- package/dist/chunk-FVVQTSIM.js +3427 -0
- package/dist/chunk-FWSL4VG6.js +1290 -0
- package/dist/chunk-GBI7V7KY.js +69 -0
- package/dist/chunk-GEFFO6O2.js +152 -0
- package/dist/chunk-HOWAQXJO.js +236 -0
- package/dist/chunk-HQSPJDHI.js +613 -0
- package/dist/chunk-IFZNR5UJ.js +2863 -0
- package/dist/chunk-J4PMBXQQ.js +336 -0
- package/dist/chunk-KAET47ZL.js +125 -0
- package/dist/chunk-KCDECRJY.js +440 -0
- package/dist/chunk-KLK3PBTO.js +1119 -0
- package/dist/chunk-L5TDYKYK.js +76 -0
- package/dist/chunk-MLKGABMK.js +9 -0
- package/dist/chunk-OWISBAOF.js +61 -0
- package/dist/chunk-PJTNGD3Z.js +6924 -0
- package/dist/chunk-QLK6ED4Q.js +235 -0
- package/dist/chunk-R2GW4F6R.js +19 -0
- package/dist/chunk-RCMTFSEF.js +87 -0
- package/dist/chunk-RH7KC5HU.js +12050 -0
- package/dist/chunk-RM3PY6TG.js +376 -0
- package/dist/chunk-ROMM6KMC.js +433 -0
- package/dist/chunk-SK6YVHFZ.js +211 -0
- package/dist/chunk-SM7RFQRO.js +214 -0
- package/dist/chunk-UFE77L67.js +782 -0
- package/dist/chunk-UGR4QIGS.js +67 -0
- package/dist/chunk-UUNHHX4M.js +13 -0
- package/dist/chunk-V44PGPA6.js +2104 -0
- package/dist/chunk-VL52PL2T.js +71 -0
- package/dist/chunk-VURYFIHW.js +201 -0
- package/dist/chunk-XJKJYIPP.js +7436 -0
- package/dist/chunk-YI6FF2ZR.js +340 -0
- package/dist/cli/index.js +37 -0
- package/dist/config-HZAAYDP3.js +10 -0
- package/dist/content-search-642F7E5V.js +593 -0
- package/dist/database-TCTZDLE5.js +9 -0
- package/dist/doctor-GXCKSJOX.js +395 -0
- package/dist/edit-engine-KM7MPFEC.js +51 -0
- package/dist/engine-42TZFNIZ.js +11 -0
- package/dist/engine-LO6L4JLQ.js +18 -0
- package/dist/fingerprint-XDXFRWO6.js +33 -0
- package/dist/framework-intelligence-DWFCKV44.js +860 -0
- package/dist/freshness-3K6VU5OT.js +174 -0
- package/dist/graph-engine-PL5YA7BA.js +21 -0
- package/dist/graph_request-MM4REP6H.js +350 -0
- package/dist/impact_request-WDE47IZ5.js +68 -0
- package/dist/index-space-IUUN5WYV.js +15 -0
- package/dist/index-status-6BD7UBHR.js +34 -0
- package/dist/index.js +159 -0
- package/dist/instance-FO6QZRLH.js +19 -0
- package/dist/language-detection-DFCAU5DZ.js +11 -0
- package/dist/lsp/server.js +4301 -0
- package/dist/mcp/server.js +132 -0
- package/dist/onboard-DIQZV2NW.js +161 -0
- package/dist/override-companion-pass-XR7MHTP7.js +117 -0
- package/dist/parallel-indexer-4PW3AFXP.js +88 -0
- package/dist/pool-worker.js +1153 -0
- package/dist/project-health-ZS5TS2Z6.js +94 -0
- package/dist/project-index-5SDPHITE.js +57 -0
- package/dist/project-registry-DGZBIZS7.js +355 -0
- package/dist/real-bash-analyzer-SXSV67E2.js +2201 -0
- package/dist/real-c-analyzer-SY7FTZ6W.js +5942 -0
- package/dist/real-clean-analyzer-IGDHHLZK.js +3470 -0
- package/dist/real-clojure-analyzer-4OH7IWLB.js +2818 -0
- package/dist/real-cpp-analyzer-7LTDRJRJ.js +4101 -0
- package/dist/real-csharp-analyzer-KICU3TLH.js +3298 -0
- package/dist/real-css-analyzer-HPU277Q6.js +15 -0
- package/dist/real-dart-analyzer-7LZ5LCMW.js +3944 -0
- package/dist/real-elixir-analyzer-BE3MEVZO.js +2192 -0
- package/dist/real-erlang-analyzer-BZMAKYBK.js +1731 -0
- package/dist/real-fsharp-analyzer-5QLTOV3E.js +2390 -0
- package/dist/real-go-analyzer-POD7MZQR.js +4126 -0
- package/dist/real-graphql-analyzer-MAQRZ6QW.js +1442 -0
- package/dist/real-groovy-analyzer-MEWSUPMJ.js +2285 -0
- package/dist/real-haskell-analyzer-I5L2GR3Y.js +2533 -0
- package/dist/real-hcl-analyzer-DBOPXSWJ.js +725 -0
- package/dist/real-html-analyzer-O63XZLZD.js +1759 -0
- package/dist/real-java-analyzer-CHCW3EKA.js +4677 -0
- package/dist/real-javascript-analyzer-QAAJQYZE.js +14 -0
- package/dist/real-json-analyzer-UGBR7YQN.js +1640 -0
- package/dist/real-julia-analyzer-35Q4GHOZ.js +2085 -0
- package/dist/real-kotlin-analyzer-GRAYCWW2.js +3956 -0
- package/dist/real-lua-analyzer-5BAPDZDF.js +1957 -0
- package/dist/real-makefile-analyzer-YJKAHNAS.js +920 -0
- package/dist/real-markdown-analyzer-UKUQZO4F.js +1215 -0
- package/dist/real-matlab-analyzer-FVIKQZKG.js +480 -0
- package/dist/real-nim-analyzer-M7FAIABG.js +3603 -0
- package/dist/real-objective-c-analyzer-XMYQIGQI.js +1518 -0
- package/dist/real-perl-analyzer-ZLY6M2DZ.js +1865 -0
- package/dist/real-php-analyzer-KI2ZAM7X.js +9368 -0
- package/dist/real-powershell-analyzer-B3T5ZP6U.js +2915 -0
- package/dist/real-protobuf-analyzer-23OZ75XV.js +867 -0
- package/dist/real-python-analyzer-I4TIUB6D.js +4880 -0
- package/dist/real-r-analyzer-FJZJXXS6.js +2596 -0
- package/dist/real-ruby-analyzer-M3UFIVTQ.js +2429 -0
- package/dist/real-rust-analyzer-LVSONPAN.js +3359 -0
- package/dist/real-scala-analyzer-CWPI33Q2.js +3293 -0
- package/dist/real-scss-analyzer-TGRJQ7TH.js +1515 -0
- package/dist/real-solidity-analyzer-4P2VBVWA.js +2608 -0
- package/dist/real-sql-analyzer-J7DYZOZR.js +3840 -0
- package/dist/real-svelte-analyzer-NHEN2SX5.js +2532 -0
- package/dist/real-swift-analyzer-2NSYULWI.js +2311 -0
- package/dist/real-toml-analyzer-L3C66L7Q.js +929 -0
- package/dist/real-typescript-analyzer-FTC6ETRQ.js +14 -0
- package/dist/real-vb-analyzer-ORY7LAQS.js +3145 -0
- package/dist/real-vba-analyzer-JH2TTUFI.js +466 -0
- package/dist/real-vue-analyzer-OO4FUGBV.js +2680 -0
- package/dist/real-xml-analyzer-6CQVR477.js +2405 -0
- package/dist/real-yaml-analyzer-J6MQG3YX.js +3528 -0
- package/dist/real-zig-analyzer-EFKCPJNU.js +2430 -0
- package/dist/regex-search-OPTLKUN5.js +239 -0
- package/dist/rules-I453JTRC.js +152 -0
- package/dist/scoped-path-MJYWJZQX.js +11 -0
- package/dist/setup-show-Y5GB5KXA.js +15 -0
- package/dist/setup-wizard-G5YYR5T6.js +24 -0
- package/dist/symbol-search-KB4MU4SI.js +16 -0
- package/dist/taint-YOTN5X55.js +202 -0
- package/dist/taint-analyzer-N7YLZU3N.js +163 -0
- package/dist/tool-handlers-G4NAGJIH.js +72 -0
- package/dist/tool-registry-BPEJNSZG.js +17 -0
- package/dist/tool-validation-RF675A3C.js +32 -0
- package/dist/type-inference-4Y7WTMFE.js +13 -0
- package/dist/vector-binary-LMY4QGAN.js +19 -0
- package/dist/version-LXGNFO37.js +9 -0
- package/dist/wasm-NMWO3WXY.js +16 -0
- package/docs/EMBEDDINGS.md +132 -0
- package/docs/README.md +178 -0
- package/docs/data/m10-baseline.json +602 -0
- package/docs/data/m10-benchmark-baseline.json +57 -0
- package/docs/data/m10-benchmark-last-run.json +127 -0
- package/docs/data/m10-final-audit.json +215 -0
- package/docs/data/m12-final-audit.json +138 -0
- package/docs/data/m12-surface-matrix.json +50 -0
- package/docs/data/public-tools.json +1902 -0
- package/docs/indexing/DEAD-ASSETS.md +88 -0
- package/docs/indexing/INDEXER-REVIEW.md +634 -0
- package/docs/indexing/PERFORMANCE-FINDINGS.md +106 -0
- package/docs/indexing/README.md +427 -0
- package/docs/indexing/discovery-matrix.md +41 -0
- package/docs/indexing/embeddings.md +325 -0
- package/docs/indexing/environment-variables.md +77 -0
- package/docs/indexing/performance.md +323 -0
- package/docs/indexing/resume.md +345 -0
- package/docs/indexing/troubleshooting.md +391 -0
- package/docs/man/bb.1 +190 -0
- package/docs/tools/bb_analyze.md +147 -0
- package/docs/tools/bb_annotate.md +110 -0
- package/docs/tools/bb_annotations.md +106 -0
- package/docs/tools/bb_ask.md +101 -0
- package/docs/tools/bb_cross_language.md +103 -0
- package/docs/tools/bb_doc.md +169 -0
- package/docs/tools/bb_edit.md +185 -0
- package/docs/tools/bb_graph.md +169 -0
- package/docs/tools/bb_health.md +156 -0
- package/docs/tools/bb_impact.md +117 -0
- package/docs/tools/bb_index.md +108 -0
- package/docs/tools/bb_migrate.md +135 -0
- package/docs/tools/bb_patterns.md +140 -0
- package/docs/tools/bb_search.md +150 -0
- package/docs/tools/bb_security.md +100 -0
- package/docs/tools/bb_visualize.md +184 -0
- package/grammars/README.md +57 -0
- package/grammars/THIRD-PARTY-NOTICES.md +50 -0
- package/grammars/tree-sitter-c/LICENSE +21 -0
- package/grammars/tree-sitter-clojure/LICENSE.md +21 -0
- package/grammars/tree-sitter-cpp/LICENSE +21 -0
- package/grammars/tree-sitter-csharp/LICENSE +21 -0
- package/grammars/tree-sitter-css/LICENSE +21 -0
- package/grammars/tree-sitter-css/README.md +21 -0
- package/grammars/tree-sitter-dart/LICENSE +20 -0
- package/grammars/tree-sitter-dart-upstream/LICENSE +20 -0
- package/grammars/tree-sitter-dart-upstream/README.md +18 -0
- package/grammars/tree-sitter-elixir/LICENSE +176 -0
- package/grammars/tree-sitter-elixir/README.md +11 -0
- package/grammars/tree-sitter-fsharp/LICENSE +21 -0
- package/grammars/tree-sitter-fsharp/README.md +45 -0
- package/grammars/tree-sitter-graphql/LICENSE +21 -0
- package/grammars/tree-sitter-graphql/README.md +106 -0
- package/grammars/tree-sitter-groovy/LICENSE +21 -0
- package/grammars/tree-sitter-groovy/README.md +4 -0
- package/grammars/tree-sitter-haskell/LICENSE +21 -0
- package/grammars/tree-sitter-haskell/README.md +394 -0
- package/grammars/tree-sitter-hcl/CHANGELOG.md +102 -0
- package/grammars/tree-sitter-hcl/LICENSE +201 -0
- package/grammars/tree-sitter-hcl/README.md +39 -0
- package/grammars/tree-sitter-html/LICENSE +21 -0
- package/grammars/tree-sitter-html/README.md +21 -0
- package/grammars/tree-sitter-julia/LICENSE +21 -0
- package/grammars/tree-sitter-julia/README.md +24 -0
- package/grammars/tree-sitter-kotlin/LICENSE +9 -0
- package/grammars/tree-sitter-lua/LICENSE.md +21 -0
- package/grammars/tree-sitter-lua/README.md +29 -0
- package/grammars/tree-sitter-make/LICENSE +21 -0
- package/grammars/tree-sitter-matlab/LICENSE +19 -0
- package/grammars/tree-sitter-matlab/README.md +99 -0
- package/grammars/tree-sitter-nim/LICENSE +373 -0
- package/grammars/tree-sitter-nim/README.md +46 -0
- package/grammars/tree-sitter-objc/LICENSE +21 -0
- package/grammars/tree-sitter-objc/README.md +20 -0
- package/grammars/tree-sitter-perl/LICENSE +7 -0
- package/grammars/tree-sitter-perl/README.md +100 -0
- package/grammars/tree-sitter-powershell/LICENSE +21 -0
- package/grammars/tree-sitter-powershell/README.md +7 -0
- package/grammars/tree-sitter-proto/LICENSE +21 -0
- package/grammars/tree-sitter-proto/README.md +105 -0
- package/grammars/tree-sitter-r/LICENSE +9 -0
- package/grammars/tree-sitter-r/README.md +66 -0
- package/grammars/tree-sitter-ruby/LICENSE +22 -0
- package/grammars/tree-sitter-scss/LICENSE +21 -0
- package/grammars/tree-sitter-scss/README.md +17 -0
- package/grammars/tree-sitter-solidity/LICENSE +7 -0
- package/grammars/tree-sitter-sql/LICENSE +21 -0
- package/grammars/tree-sitter-typescript/LICENSE +21 -0
- package/grammars/tree-sitter-vba/LICENSE +21 -0
- package/grammars/tree-sitter-vba/README.md +738 -0
- package/grammars/tree-sitter-vbnet/LICENSE +21 -0
- package/grammars/tree-sitter-vbnet/README.md +322 -0
- package/grammars/tree-sitter-xml/LICENSE +19 -0
- package/grammars/tree-sitter-yaml/LICENSE +20 -0
- package/grammars/tree-sitter-yaml/README.md +21 -0
- package/package.json +184 -4
- package/wasm/dart.wasm +0 -0
- package/wasm/tree-sitter-bash.wasm +0 -0
- package/wasm/tree-sitter-c.wasm +0 -0
- package/wasm/tree-sitter-c_sharp.wasm +0 -0
- package/wasm/tree-sitter-clean.wasm +0 -0
- package/wasm/tree-sitter-clojure.wasm +0 -0
- package/wasm/tree-sitter-core_schema.wasm +0 -0
- package/wasm/tree-sitter-cpp.wasm +0 -0
- package/wasm/tree-sitter-css.wasm +0 -0
- package/wasm/tree-sitter-dart.wasm +0 -0
- package/wasm/tree-sitter-elisp.wasm +0 -0
- package/wasm/tree-sitter-elixir.wasm +0 -0
- package/wasm/tree-sitter-elm.wasm +0 -0
- package/wasm/tree-sitter-embedded_template.wasm +0 -0
- package/wasm/tree-sitter-erlang.wasm +0 -0
- package/wasm/tree-sitter-fsharp.wasm +0 -0
- package/wasm/tree-sitter-fsharp_signature.wasm +0 -0
- package/wasm/tree-sitter-go.wasm +0 -0
- package/wasm/tree-sitter-graphql.wasm +0 -0
- package/wasm/tree-sitter-groovy.wasm +0 -0
- package/wasm/tree-sitter-haskell.wasm +0 -0
- package/wasm/tree-sitter-hcl.wasm +0 -0
- package/wasm/tree-sitter-html.wasm +0 -0
- package/wasm/tree-sitter-java.wasm +0 -0
- package/wasm/tree-sitter-javascript.wasm +0 -0
- package/wasm/tree-sitter-json.wasm +0 -0
- package/wasm/tree-sitter-json_schema.wasm +0 -0
- package/wasm/tree-sitter-julia.wasm +0 -0
- package/wasm/tree-sitter-kotlin.wasm +0 -0
- package/wasm/tree-sitter-lua.wasm +0 -0
- package/wasm/tree-sitter-make.wasm +0 -0
- package/wasm/tree-sitter-markdown.wasm +0 -0
- package/wasm/tree-sitter-markdown_inline.wasm +0 -0
- package/wasm/tree-sitter-matlab.wasm +0 -0
- package/wasm/tree-sitter-nim.wasm +0 -0
- package/wasm/tree-sitter-objc.wasm +0 -0
- package/wasm/tree-sitter-ocaml.wasm +0 -0
- package/wasm/tree-sitter-perl.wasm +0 -0
- package/wasm/tree-sitter-php.wasm +0 -0
- package/wasm/tree-sitter-php_only.wasm +0 -0
- package/wasm/tree-sitter-powershell.wasm +0 -0
- package/wasm/tree-sitter-protobuf.wasm +0 -0
- package/wasm/tree-sitter-python.wasm +0 -0
- package/wasm/tree-sitter-ql.wasm +0 -0
- package/wasm/tree-sitter-r.wasm +0 -0
- package/wasm/tree-sitter-rescript.wasm +0 -0
- package/wasm/tree-sitter-ruby.wasm +0 -0
- package/wasm/tree-sitter-rust.wasm +0 -0
- package/wasm/tree-sitter-scala.wasm +0 -0
- package/wasm/tree-sitter-scss.wasm +0 -0
- package/wasm/tree-sitter-solidity.wasm +0 -0
- package/wasm/tree-sitter-sql.wasm +0 -0
- package/wasm/tree-sitter-svelte.wasm +0 -0
- package/wasm/tree-sitter-swift.wasm +0 -0
- package/wasm/tree-sitter-systemrdl.wasm +0 -0
- package/wasm/tree-sitter-terraform.wasm +0 -0
- package/wasm/tree-sitter-tlaplus.wasm +0 -0
- package/wasm/tree-sitter-toml.wasm +0 -0
- package/wasm/tree-sitter-tsx.wasm +0 -0
- package/wasm/tree-sitter-typescript.wasm +0 -0
- package/wasm/tree-sitter-vba.wasm +0 -0
- package/wasm/tree-sitter-vbnet.wasm +0 -0
- package/wasm/tree-sitter-vue.wasm +0 -0
- package/wasm/tree-sitter-xml.wasm +0 -0
- package/wasm/tree-sitter-yaml.wasm +0 -0
- package/wasm/tree-sitter-zig.wasm +0 -0
- package/wasm/tree-sitter.wasm +0 -0
- package/wasm/tsx.wasm +0 -0
- package/wasm/typescript.wasm +0 -0
|
@@ -0,0 +1,782 @@
|
|
|
1
|
+
import {
|
|
2
|
+
ASTEngine
|
|
3
|
+
} from "./chunk-V44PGPA6.js";
|
|
4
|
+
|
|
5
|
+
// src/ast/type-inference.ts
|
|
6
|
+
var TypeInference;
|
|
7
|
+
((TypeInference2) => {
|
|
8
|
+
let TypeKind;
|
|
9
|
+
((TypeKind2) => {
|
|
10
|
+
TypeKind2["Primitive"] = "primitive";
|
|
11
|
+
TypeKind2["Class"] = "class";
|
|
12
|
+
TypeKind2["Interface"] = "interface";
|
|
13
|
+
TypeKind2["Enum"] = "enum";
|
|
14
|
+
TypeKind2["Function"] = "function";
|
|
15
|
+
TypeKind2["Array"] = "array";
|
|
16
|
+
TypeKind2["Object"] = "object";
|
|
17
|
+
TypeKind2["Generic"] = "generic";
|
|
18
|
+
TypeKind2["Union"] = "union";
|
|
19
|
+
TypeKind2["Intersection"] = "intersection";
|
|
20
|
+
TypeKind2["Tuple"] = "tuple";
|
|
21
|
+
TypeKind2["Literal"] = "literal";
|
|
22
|
+
TypeKind2["Unknown"] = "unknown";
|
|
23
|
+
TypeKind2["Any"] = "any";
|
|
24
|
+
TypeKind2["Void"] = "void";
|
|
25
|
+
})(TypeKind = TypeInference2.TypeKind || (TypeInference2.TypeKind = {}));
|
|
26
|
+
let InferenceReason;
|
|
27
|
+
((InferenceReason2) => {
|
|
28
|
+
InferenceReason2["Declaration"] = "declaration";
|
|
29
|
+
InferenceReason2["Assignment"] = "assignment";
|
|
30
|
+
InferenceReason2["FunctionCall"] = "function_call";
|
|
31
|
+
InferenceReason2["MethodCall"] = "method_call";
|
|
32
|
+
InferenceReason2["ControlFlow"] = "control_flow";
|
|
33
|
+
InferenceReason2["GenericInstantiation"] = "generic_instantiation";
|
|
34
|
+
InferenceReason2["TypeAssertion"] = "type_assertion";
|
|
35
|
+
InferenceReason2["Destructuring"] = "destructuring";
|
|
36
|
+
InferenceReason2["Import"] = "import";
|
|
37
|
+
})(InferenceReason = TypeInference2.InferenceReason || (TypeInference2.InferenceReason = {}));
|
|
38
|
+
class InferenceContext {
|
|
39
|
+
variableTypes = /* @__PURE__ */ new Map();
|
|
40
|
+
functionTypes = /* @__PURE__ */ new Map();
|
|
41
|
+
classTypes = /* @__PURE__ */ new Map();
|
|
42
|
+
scopeStack = [];
|
|
43
|
+
language;
|
|
44
|
+
filePath;
|
|
45
|
+
constructor(language, filePath) {
|
|
46
|
+
this.language = language;
|
|
47
|
+
this.filePath = filePath;
|
|
48
|
+
this.initializeBuiltinTypes();
|
|
49
|
+
}
|
|
50
|
+
initializeBuiltinTypes() {
|
|
51
|
+
switch (this.language) {
|
|
52
|
+
case "typescript":
|
|
53
|
+
case "javascript":
|
|
54
|
+
this.initializeJavaScriptTypes();
|
|
55
|
+
break;
|
|
56
|
+
case "python":
|
|
57
|
+
this.initializePythonTypes();
|
|
58
|
+
break;
|
|
59
|
+
case "java":
|
|
60
|
+
this.initializeJavaTypes();
|
|
61
|
+
break;
|
|
62
|
+
case "rust":
|
|
63
|
+
this.initializeRustTypes();
|
|
64
|
+
break;
|
|
65
|
+
case "cpp":
|
|
66
|
+
this.initializeCppTypes();
|
|
67
|
+
break;
|
|
68
|
+
case "csharp":
|
|
69
|
+
this.initializeCSharpTypes();
|
|
70
|
+
break;
|
|
71
|
+
default:
|
|
72
|
+
this.initializeGenericTypes();
|
|
73
|
+
}
|
|
74
|
+
}
|
|
75
|
+
initializeJavaScriptTypes() {
|
|
76
|
+
const jsTypes = ["string", "number", "boolean", "object", "undefined", "null", "symbol", "bigint"];
|
|
77
|
+
jsTypes.forEach((type) => {
|
|
78
|
+
this.classTypes.set(type, {
|
|
79
|
+
name: type,
|
|
80
|
+
kind: "primitive" /* Primitive */,
|
|
81
|
+
confidence: 1,
|
|
82
|
+
inferredAt: []
|
|
83
|
+
});
|
|
84
|
+
});
|
|
85
|
+
this.classTypes.set("Array", {
|
|
86
|
+
name: "Array",
|
|
87
|
+
kind: "class" /* Class */,
|
|
88
|
+
genericArgs: [this.getUnknownType()],
|
|
89
|
+
confidence: 1,
|
|
90
|
+
inferredAt: []
|
|
91
|
+
});
|
|
92
|
+
this.classTypes.set("Promise", {
|
|
93
|
+
name: "Promise",
|
|
94
|
+
kind: "class" /* Class */,
|
|
95
|
+
genericArgs: [this.getUnknownType()],
|
|
96
|
+
confidence: 1,
|
|
97
|
+
inferredAt: []
|
|
98
|
+
});
|
|
99
|
+
}
|
|
100
|
+
initializePythonTypes() {
|
|
101
|
+
const pythonTypes = ["int", "float", "str", "bool", "list", "dict", "tuple", "set", "None"];
|
|
102
|
+
pythonTypes.forEach((type) => {
|
|
103
|
+
this.classTypes.set(type, {
|
|
104
|
+
name: type,
|
|
105
|
+
kind: type === "None" ? "literal" /* Literal */ : "primitive" /* Primitive */,
|
|
106
|
+
confidence: 1,
|
|
107
|
+
inferredAt: []
|
|
108
|
+
});
|
|
109
|
+
});
|
|
110
|
+
}
|
|
111
|
+
initializeJavaTypes() {
|
|
112
|
+
const javaTypes = ["int", "long", "double", "float", "boolean", "char", "byte", "short", "String", "Object"];
|
|
113
|
+
javaTypes.forEach((type) => {
|
|
114
|
+
this.classTypes.set(type, {
|
|
115
|
+
name: type,
|
|
116
|
+
kind: ["String", "Object"].includes(type) ? "class" /* Class */ : "primitive" /* Primitive */,
|
|
117
|
+
confidence: 1,
|
|
118
|
+
inferredAt: []
|
|
119
|
+
});
|
|
120
|
+
});
|
|
121
|
+
}
|
|
122
|
+
initializeRustTypes() {
|
|
123
|
+
const rustTypes = ["i32", "i64", "f32", "f64", "bool", "char", "str", "String", "Vec", "Option", "Result"];
|
|
124
|
+
rustTypes.forEach((type) => {
|
|
125
|
+
this.classTypes.set(type, {
|
|
126
|
+
name: type,
|
|
127
|
+
kind: ["Vec", "Option", "Result"].includes(type) ? "generic" /* Generic */ : ["String"].includes(type) ? "class" /* Class */ : "primitive" /* Primitive */,
|
|
128
|
+
confidence: 1,
|
|
129
|
+
inferredAt: []
|
|
130
|
+
});
|
|
131
|
+
});
|
|
132
|
+
}
|
|
133
|
+
initializeCppTypes() {
|
|
134
|
+
const cppTypes = ["int", "long", "double", "float", "bool", "char", "void", "std::string", "std::vector"];
|
|
135
|
+
cppTypes.forEach((type) => {
|
|
136
|
+
this.classTypes.set(type, {
|
|
137
|
+
name: type,
|
|
138
|
+
kind: type.startsWith("std::") ? "class" /* Class */ : "primitive" /* Primitive */,
|
|
139
|
+
confidence: 1,
|
|
140
|
+
inferredAt: []
|
|
141
|
+
});
|
|
142
|
+
});
|
|
143
|
+
}
|
|
144
|
+
initializeCSharpTypes() {
|
|
145
|
+
const csharpTypes = ["int", "long", "double", "float", "bool", "char", "string", "object", "decimal"];
|
|
146
|
+
csharpTypes.forEach((type) => {
|
|
147
|
+
this.classTypes.set(type, {
|
|
148
|
+
name: type,
|
|
149
|
+
kind: ["string", "object"].includes(type) ? "class" /* Class */ : "primitive" /* Primitive */,
|
|
150
|
+
confidence: 1,
|
|
151
|
+
inferredAt: []
|
|
152
|
+
});
|
|
153
|
+
});
|
|
154
|
+
}
|
|
155
|
+
initializeGenericTypes() {
|
|
156
|
+
["int", "string", "bool", "object"].forEach((type) => {
|
|
157
|
+
this.classTypes.set(type, {
|
|
158
|
+
name: type,
|
|
159
|
+
kind: "primitive" /* Primitive */,
|
|
160
|
+
confidence: 0.8,
|
|
161
|
+
inferredAt: []
|
|
162
|
+
});
|
|
163
|
+
});
|
|
164
|
+
}
|
|
165
|
+
// Type inference methods
|
|
166
|
+
inferVariableType(varName, assignmentNode, reason) {
|
|
167
|
+
const scopedName = this.getScopedName(varName);
|
|
168
|
+
const inferredType = this.analyzeExpression(assignmentNode);
|
|
169
|
+
inferredType.inferredAt.push({
|
|
170
|
+
filePath: this.filePath,
|
|
171
|
+
range: this.nodeToRange(assignmentNode),
|
|
172
|
+
reason
|
|
173
|
+
});
|
|
174
|
+
this.variableTypes.set(scopedName, inferredType);
|
|
175
|
+
return inferredType;
|
|
176
|
+
}
|
|
177
|
+
inferFunctionReturnType(funcName, bodyNode) {
|
|
178
|
+
const returnStatements = this.findReturnStatements(bodyNode);
|
|
179
|
+
if (returnStatements.length === 0) {
|
|
180
|
+
return this.getVoidType();
|
|
181
|
+
}
|
|
182
|
+
if (returnStatements.length === 1) {
|
|
183
|
+
return this.analyzeExpression(returnStatements[0]);
|
|
184
|
+
}
|
|
185
|
+
const returnTypes = returnStatements.map((stmt) => this.analyzeExpression(stmt));
|
|
186
|
+
return this.createUnionType(returnTypes);
|
|
187
|
+
}
|
|
188
|
+
inferMethodCallType(objectExpr, methodName) {
|
|
189
|
+
const objectType = this.analyzeExpression(objectExpr);
|
|
190
|
+
if (objectType.methods?.has(methodName)) {
|
|
191
|
+
return objectType.methods.get(methodName).returnType;
|
|
192
|
+
}
|
|
193
|
+
return this.inferMethodFromPatterns(objectType, methodName);
|
|
194
|
+
}
|
|
195
|
+
inferGenericInstantiation(genericType, typeArgs) {
|
|
196
|
+
return {
|
|
197
|
+
...genericType,
|
|
198
|
+
genericArgs: typeArgs,
|
|
199
|
+
confidence: Math.min(genericType.confidence, ...typeArgs.map((t) => t.confidence)),
|
|
200
|
+
inferredAt: [...genericType.inferredAt]
|
|
201
|
+
};
|
|
202
|
+
}
|
|
203
|
+
// Expression analysis
|
|
204
|
+
analyzeExpression(node) {
|
|
205
|
+
switch (node.type) {
|
|
206
|
+
case "number":
|
|
207
|
+
case "integer_literal":
|
|
208
|
+
case "float_literal":
|
|
209
|
+
return this.getNumberType();
|
|
210
|
+
case "string":
|
|
211
|
+
case "string_literal":
|
|
212
|
+
case "template_literal":
|
|
213
|
+
return this.getStringType();
|
|
214
|
+
case "boolean":
|
|
215
|
+
case "true":
|
|
216
|
+
case "false":
|
|
217
|
+
return this.getBooleanType();
|
|
218
|
+
case "null":
|
|
219
|
+
case "nil":
|
|
220
|
+
case "None":
|
|
221
|
+
return this.getNullType();
|
|
222
|
+
case "identifier":
|
|
223
|
+
case "variable":
|
|
224
|
+
return this.lookupVariableType(node.text);
|
|
225
|
+
case "call_expression":
|
|
226
|
+
case "function_call":
|
|
227
|
+
return this.analyzeFunctionCall(node);
|
|
228
|
+
case "member_expression":
|
|
229
|
+
case "field_expression":
|
|
230
|
+
return this.analyzeMemberAccess(node);
|
|
231
|
+
case "array_expression":
|
|
232
|
+
case "list_expression":
|
|
233
|
+
return this.analyzeArrayExpression(node);
|
|
234
|
+
case "object_expression":
|
|
235
|
+
case "dict_expression":
|
|
236
|
+
return this.analyzeObjectExpression(node);
|
|
237
|
+
case "binary_expression":
|
|
238
|
+
return this.analyzeBinaryExpression(node);
|
|
239
|
+
case "conditional_expression":
|
|
240
|
+
case "ternary_expression":
|
|
241
|
+
return this.analyzeConditionalExpression(node);
|
|
242
|
+
default:
|
|
243
|
+
return this.getUnknownType();
|
|
244
|
+
}
|
|
245
|
+
}
|
|
246
|
+
analyzeFunctionCall(node) {
|
|
247
|
+
const functionNode = node.childForFieldName("function") || node.childForFieldName("name");
|
|
248
|
+
if (!functionNode) return this.getUnknownType();
|
|
249
|
+
const functionName = functionNode.text;
|
|
250
|
+
if (functionNode.type === "member_expression") {
|
|
251
|
+
const objectNode = functionNode.childForFieldName("object");
|
|
252
|
+
const propertyNode = functionNode.childForFieldName("property");
|
|
253
|
+
if (objectNode && propertyNode) {
|
|
254
|
+
return this.inferMethodCallType(objectNode, propertyNode.text);
|
|
255
|
+
}
|
|
256
|
+
}
|
|
257
|
+
const signature = this.functionTypes.get(functionName);
|
|
258
|
+
if (signature) {
|
|
259
|
+
return signature.returnType;
|
|
260
|
+
}
|
|
261
|
+
if (this.isConstructorCall(functionName)) {
|
|
262
|
+
const className = this.extractClassName(functionName);
|
|
263
|
+
return this.classTypes.get(className) || this.getUnknownType();
|
|
264
|
+
}
|
|
265
|
+
return this.getUnknownType();
|
|
266
|
+
}
|
|
267
|
+
analyzeMemberAccess(node) {
|
|
268
|
+
const objectNode = node.childForFieldName("object") || node.childForFieldName("expression");
|
|
269
|
+
const propertyNode = node.childForFieldName("property") || node.childForFieldName("field");
|
|
270
|
+
if (!objectNode || !propertyNode) return this.getUnknownType();
|
|
271
|
+
const objectType = this.analyzeExpression(objectNode);
|
|
272
|
+
const propertyName = propertyNode.text;
|
|
273
|
+
if (objectType.properties?.has(propertyName)) {
|
|
274
|
+
return objectType.properties.get(propertyName);
|
|
275
|
+
}
|
|
276
|
+
if (objectType.methods?.has(propertyName)) {
|
|
277
|
+
return {
|
|
278
|
+
name: `${objectType.name}.${propertyName}`,
|
|
279
|
+
kind: "function" /* Function */,
|
|
280
|
+
confidence: objectType.confidence * 0.8,
|
|
281
|
+
inferredAt: []
|
|
282
|
+
};
|
|
283
|
+
}
|
|
284
|
+
return this.getUnknownType();
|
|
285
|
+
}
|
|
286
|
+
analyzeArrayExpression(node) {
|
|
287
|
+
const elements = this.getArrayElements(node);
|
|
288
|
+
if (elements.length === 0) {
|
|
289
|
+
return {
|
|
290
|
+
name: "Array",
|
|
291
|
+
kind: "array" /* Array */,
|
|
292
|
+
genericArgs: [this.getUnknownType()],
|
|
293
|
+
confidence: 0.9,
|
|
294
|
+
inferredAt: []
|
|
295
|
+
};
|
|
296
|
+
}
|
|
297
|
+
const elementTypes = elements.map((elem) => this.analyzeExpression(elem));
|
|
298
|
+
const elementType = this.mergeTypes(elementTypes);
|
|
299
|
+
return {
|
|
300
|
+
name: "Array",
|
|
301
|
+
kind: "array" /* Array */,
|
|
302
|
+
genericArgs: [elementType],
|
|
303
|
+
confidence: elementType.confidence * 0.9,
|
|
304
|
+
inferredAt: []
|
|
305
|
+
};
|
|
306
|
+
}
|
|
307
|
+
analyzeObjectExpression(node) {
|
|
308
|
+
const properties = /* @__PURE__ */ new Map();
|
|
309
|
+
const children = node.namedChildren;
|
|
310
|
+
for (let i = 0; i < children.length; i++) {
|
|
311
|
+
const child = children[i];
|
|
312
|
+
if (child && (child.type === "pair" || child.type === "property")) {
|
|
313
|
+
const key = this.getObjectKey(child);
|
|
314
|
+
const value = this.getObjectValue(child);
|
|
315
|
+
if (key && value) {
|
|
316
|
+
properties.set(key, this.analyzeExpression(value));
|
|
317
|
+
}
|
|
318
|
+
}
|
|
319
|
+
}
|
|
320
|
+
return {
|
|
321
|
+
name: "Object",
|
|
322
|
+
kind: "object" /* Object */,
|
|
323
|
+
properties,
|
|
324
|
+
confidence: 0.9,
|
|
325
|
+
inferredAt: []
|
|
326
|
+
};
|
|
327
|
+
}
|
|
328
|
+
analyzeBinaryExpression(node) {
|
|
329
|
+
const operator = this.getBinaryOperator(node);
|
|
330
|
+
const leftNode = node.childForFieldName("left");
|
|
331
|
+
const rightNode = node.childForFieldName("right");
|
|
332
|
+
if (!leftNode || !rightNode) return this.getUnknownType();
|
|
333
|
+
const leftType = this.analyzeExpression(leftNode);
|
|
334
|
+
const rightType = this.analyzeExpression(rightNode);
|
|
335
|
+
if (["+", "-", "*", "/", "%", "**"].includes(operator)) {
|
|
336
|
+
if (leftType.name === "string" || rightType.name === "string") {
|
|
337
|
+
return operator === "+" ? this.getStringType() : this.getUnknownType();
|
|
338
|
+
}
|
|
339
|
+
return this.getNumberType();
|
|
340
|
+
}
|
|
341
|
+
if (["<", ">", "<=", ">=", "==", "!=", "===", "!=="].includes(operator)) {
|
|
342
|
+
return this.getBooleanType();
|
|
343
|
+
}
|
|
344
|
+
if (["&&", "||"].includes(operator)) {
|
|
345
|
+
return this.mergeTypes([leftType, rightType]);
|
|
346
|
+
}
|
|
347
|
+
return this.getUnknownType();
|
|
348
|
+
}
|
|
349
|
+
analyzeConditionalExpression(node) {
|
|
350
|
+
const consequentNode = node.childForFieldName("consequence") || node.childForFieldName("then");
|
|
351
|
+
const alternateNode = node.childForFieldName("alternative") || node.childForFieldName("else");
|
|
352
|
+
if (!consequentNode || !alternateNode) return this.getUnknownType();
|
|
353
|
+
const consequentType = this.analyzeExpression(consequentNode);
|
|
354
|
+
const alternateType = this.analyzeExpression(alternateNode);
|
|
355
|
+
return this.mergeTypes([consequentType, alternateType]);
|
|
356
|
+
}
|
|
357
|
+
// Flow-sensitive analysis
|
|
358
|
+
analyzeControlFlow(node) {
|
|
359
|
+
const flowTypes = /* @__PURE__ */ new Map();
|
|
360
|
+
switch (node.type) {
|
|
361
|
+
case "if_statement":
|
|
362
|
+
return this.analyzeIfStatement(node);
|
|
363
|
+
case "while_statement":
|
|
364
|
+
case "for_statement":
|
|
365
|
+
return this.analyzeLoopStatement(node);
|
|
366
|
+
case "try_statement":
|
|
367
|
+
return this.analyzeTryStatement(node);
|
|
368
|
+
case "match_expression":
|
|
369
|
+
// Rust
|
|
370
|
+
case "switch_statement":
|
|
371
|
+
return this.analyzeMatchStatement(node);
|
|
372
|
+
}
|
|
373
|
+
return flowTypes;
|
|
374
|
+
}
|
|
375
|
+
analyzeIfStatement(node) {
|
|
376
|
+
const conditionNode = node.childForFieldName("condition");
|
|
377
|
+
const thenNode = node.childForFieldName("consequence") || node.childForFieldName("then");
|
|
378
|
+
const elseNode = node.childForFieldName("alternative") || node.childForFieldName("else");
|
|
379
|
+
const flowTypes = /* @__PURE__ */ new Map();
|
|
380
|
+
if (conditionNode) {
|
|
381
|
+
const typeGuards = this.extractTypeGuards(conditionNode);
|
|
382
|
+
typeGuards.forEach((type, variable) => {
|
|
383
|
+
flowTypes.set(variable, type);
|
|
384
|
+
});
|
|
385
|
+
}
|
|
386
|
+
return flowTypes;
|
|
387
|
+
}
|
|
388
|
+
extractTypeGuards(conditionNode) {
|
|
389
|
+
const guards = /* @__PURE__ */ new Map();
|
|
390
|
+
if (this.isTypeofCheck(conditionNode)) {
|
|
391
|
+
const variable = this.getTypeofVariable(conditionNode);
|
|
392
|
+
const typeString = this.getTypeofType(conditionNode);
|
|
393
|
+
if (variable && typeString) {
|
|
394
|
+
guards.set(variable, this.stringToType(typeString));
|
|
395
|
+
}
|
|
396
|
+
}
|
|
397
|
+
if (this.isInstanceofCheck(conditionNode)) {
|
|
398
|
+
const variable = this.getInstanceofVariable(conditionNode);
|
|
399
|
+
const className = this.getInstanceofClass(conditionNode);
|
|
400
|
+
if (variable && className) {
|
|
401
|
+
const classType = this.classTypes.get(className);
|
|
402
|
+
if (classType) {
|
|
403
|
+
guards.set(variable, classType);
|
|
404
|
+
}
|
|
405
|
+
}
|
|
406
|
+
}
|
|
407
|
+
if (this.isNullCheck(conditionNode)) {
|
|
408
|
+
const variable = this.getNullCheckVariable(conditionNode);
|
|
409
|
+
if (variable) {
|
|
410
|
+
const currentType = this.lookupVariableType(variable);
|
|
411
|
+
guards.set(variable, this.makeNonNullable(currentType));
|
|
412
|
+
}
|
|
413
|
+
}
|
|
414
|
+
return guards;
|
|
415
|
+
}
|
|
416
|
+
// Helper methods for type system
|
|
417
|
+
lookupVariableType(varName) {
|
|
418
|
+
const scopedName = this.getScopedName(varName);
|
|
419
|
+
return this.variableTypes.get(scopedName) || this.getUnknownType();
|
|
420
|
+
}
|
|
421
|
+
getScopedName(varName) {
|
|
422
|
+
if (this.scopeStack.length === 0) return varName;
|
|
423
|
+
return `${this.scopeStack.join(".")}.${varName}`;
|
|
424
|
+
}
|
|
425
|
+
mergeTypes(types) {
|
|
426
|
+
if (types.length === 0) return this.getUnknownType();
|
|
427
|
+
if (types.length === 1) return types[0];
|
|
428
|
+
const uniqueTypes = Array.from(new Set(types.map((t) => t.name)));
|
|
429
|
+
if (uniqueTypes.length === 1) {
|
|
430
|
+
return {
|
|
431
|
+
...types[0],
|
|
432
|
+
confidence: Math.max(...types.map((t) => t.confidence))
|
|
433
|
+
};
|
|
434
|
+
}
|
|
435
|
+
return this.createUnionType(types);
|
|
436
|
+
}
|
|
437
|
+
createUnionType(types) {
|
|
438
|
+
return {
|
|
439
|
+
name: types.map((t) => t.name).join(" | "),
|
|
440
|
+
kind: "union" /* Union */,
|
|
441
|
+
unionTypes: types,
|
|
442
|
+
confidence: Math.max(...types.map((t) => t.confidence)) * 0.8,
|
|
443
|
+
inferredAt: []
|
|
444
|
+
};
|
|
445
|
+
}
|
|
446
|
+
// Built-in type getters
|
|
447
|
+
getUnknownType() {
|
|
448
|
+
return { name: "unknown", kind: "unknown" /* Unknown */, confidence: 0, inferredAt: [] };
|
|
449
|
+
}
|
|
450
|
+
getVoidType() {
|
|
451
|
+
return { name: "void", kind: "void" /* Void */, confidence: 1, inferredAt: [] };
|
|
452
|
+
}
|
|
453
|
+
getStringType() {
|
|
454
|
+
return { name: "string", kind: "primitive" /* Primitive */, confidence: 1, inferredAt: [] };
|
|
455
|
+
}
|
|
456
|
+
getNumberType() {
|
|
457
|
+
return { name: "number", kind: "primitive" /* Primitive */, confidence: 1, inferredAt: [] };
|
|
458
|
+
}
|
|
459
|
+
getBooleanType() {
|
|
460
|
+
return { name: "boolean", kind: "primitive" /* Primitive */, confidence: 1, inferredAt: [] };
|
|
461
|
+
}
|
|
462
|
+
getNullType() {
|
|
463
|
+
return { name: "null", kind: "literal" /* Literal */, confidence: 1, inferredAt: [] };
|
|
464
|
+
}
|
|
465
|
+
// Utility methods for AST navigation
|
|
466
|
+
nodeToRange(node) {
|
|
467
|
+
return {
|
|
468
|
+
startLine: node.startPosition.row + 1,
|
|
469
|
+
startColumn: node.startPosition.column + 1,
|
|
470
|
+
endLine: node.endPosition.row + 1,
|
|
471
|
+
endColumn: node.endPosition.column + 1,
|
|
472
|
+
startIndex: node.startIndex,
|
|
473
|
+
endIndex: node.endIndex
|
|
474
|
+
};
|
|
475
|
+
}
|
|
476
|
+
findReturnStatements(node) {
|
|
477
|
+
const returns = [];
|
|
478
|
+
const traverse = (n) => {
|
|
479
|
+
if (n.type === "return_statement") {
|
|
480
|
+
const expression = n.childForFieldName("expression") || n.namedChild(0);
|
|
481
|
+
if (expression) returns.push(expression);
|
|
482
|
+
}
|
|
483
|
+
const children = n.namedChildren;
|
|
484
|
+
for (let i = 0; i < children.length; i++) {
|
|
485
|
+
traverse(children[i]);
|
|
486
|
+
}
|
|
487
|
+
};
|
|
488
|
+
traverse(node);
|
|
489
|
+
return returns;
|
|
490
|
+
}
|
|
491
|
+
getArrayElements(node) {
|
|
492
|
+
const elements = [];
|
|
493
|
+
const children = node.namedChildren;
|
|
494
|
+
for (let i = 0; i < children.length; i++) {
|
|
495
|
+
const child = children[i];
|
|
496
|
+
if (child) elements.push(child);
|
|
497
|
+
}
|
|
498
|
+
return elements;
|
|
499
|
+
}
|
|
500
|
+
getObjectKey(pairNode) {
|
|
501
|
+
const keyNode = pairNode.childForFieldName("key") || pairNode.childForFieldName("name");
|
|
502
|
+
return keyNode ? keyNode.text : null;
|
|
503
|
+
}
|
|
504
|
+
getObjectValue(pairNode) {
|
|
505
|
+
return pairNode.childForFieldName("value") || pairNode.childForFieldName("expression");
|
|
506
|
+
}
|
|
507
|
+
getBinaryOperator(node) {
|
|
508
|
+
for (let i = 0; i < node.childCount; i++) {
|
|
509
|
+
const child = node.child(i);
|
|
510
|
+
if (child && ["operator", "+", "-", "*", "/", "==", "!=", "<", ">"].includes(child.type)) {
|
|
511
|
+
return child.text;
|
|
512
|
+
}
|
|
513
|
+
}
|
|
514
|
+
return "";
|
|
515
|
+
}
|
|
516
|
+
isConstructorCall(functionName) {
|
|
517
|
+
return /^[A-Z]/.test(functionName) || functionName === "new";
|
|
518
|
+
}
|
|
519
|
+
extractClassName(functionName) {
|
|
520
|
+
return functionName.replace(/^new\s+/, "");
|
|
521
|
+
}
|
|
522
|
+
isTypeofCheck(node) {
|
|
523
|
+
return node.text.includes("typeof");
|
|
524
|
+
}
|
|
525
|
+
isInstanceofCheck(node) {
|
|
526
|
+
return node.text.includes("instanceof");
|
|
527
|
+
}
|
|
528
|
+
isNullCheck(node) {
|
|
529
|
+
return node.text.includes("!= null") || node.text.includes("!== undefined");
|
|
530
|
+
}
|
|
531
|
+
getTypeofVariable(node) {
|
|
532
|
+
const match = node.text.match(/typeof\s+(\w+)/);
|
|
533
|
+
return match ? match[1] : null;
|
|
534
|
+
}
|
|
535
|
+
getTypeofType(node) {
|
|
536
|
+
const match = node.text.match(/===\s*['"](\w+)['"]/);
|
|
537
|
+
return match ? match[1] : null;
|
|
538
|
+
}
|
|
539
|
+
getInstanceofVariable(node) {
|
|
540
|
+
const match = node.text.match(/(\w+)\s+instanceof/);
|
|
541
|
+
return match ? match[1] : null;
|
|
542
|
+
}
|
|
543
|
+
getInstanceofClass(node) {
|
|
544
|
+
const match = node.text.match(/instanceof\s+(\w+)/);
|
|
545
|
+
return match ? match[1] : null;
|
|
546
|
+
}
|
|
547
|
+
getNullCheckVariable(node) {
|
|
548
|
+
const match = node.text.match(/(\w+)\s*!==?\s*(null|undefined)/);
|
|
549
|
+
return match ? match[1] : null;
|
|
550
|
+
}
|
|
551
|
+
stringToType(typeString) {
|
|
552
|
+
return this.classTypes.get(typeString) || {
|
|
553
|
+
name: typeString,
|
|
554
|
+
kind: "primitive" /* Primitive */,
|
|
555
|
+
confidence: 0.9,
|
|
556
|
+
inferredAt: []
|
|
557
|
+
};
|
|
558
|
+
}
|
|
559
|
+
makeNonNullable(type) {
|
|
560
|
+
return {
|
|
561
|
+
...type,
|
|
562
|
+
nullable: false,
|
|
563
|
+
confidence: type.confidence * 0.95
|
|
564
|
+
};
|
|
565
|
+
}
|
|
566
|
+
inferMethodFromPatterns(objectType, methodName) {
|
|
567
|
+
const commonPatterns = {
|
|
568
|
+
// Array methods
|
|
569
|
+
"push": this.getNumberType(),
|
|
570
|
+
"pop": this.getUnknownType(),
|
|
571
|
+
"length": this.getNumberType(),
|
|
572
|
+
"size": this.getNumberType(),
|
|
573
|
+
"count": this.getNumberType(),
|
|
574
|
+
// String methods
|
|
575
|
+
"toString": this.getStringType(),
|
|
576
|
+
"toLowerCase": this.getStringType(),
|
|
577
|
+
"toUpperCase": this.getStringType(),
|
|
578
|
+
"substring": this.getStringType(),
|
|
579
|
+
"charAt": this.getStringType(),
|
|
580
|
+
// Boolean methods
|
|
581
|
+
"isEmpty": this.getBooleanType(),
|
|
582
|
+
"isNull": this.getBooleanType(),
|
|
583
|
+
"hasValue": this.getBooleanType()
|
|
584
|
+
};
|
|
585
|
+
return commonPatterns[methodName] || this.getUnknownType();
|
|
586
|
+
}
|
|
587
|
+
analyzeLoopStatement(node) {
|
|
588
|
+
return /* @__PURE__ */ new Map();
|
|
589
|
+
}
|
|
590
|
+
analyzeTryStatement(node) {
|
|
591
|
+
return /* @__PURE__ */ new Map();
|
|
592
|
+
}
|
|
593
|
+
analyzeMatchStatement(node) {
|
|
594
|
+
return /* @__PURE__ */ new Map();
|
|
595
|
+
}
|
|
596
|
+
// Scope management
|
|
597
|
+
enterScope(scopeName) {
|
|
598
|
+
this.scopeStack.push(scopeName);
|
|
599
|
+
}
|
|
600
|
+
exitScope() {
|
|
601
|
+
this.scopeStack.pop();
|
|
602
|
+
}
|
|
603
|
+
getCurrentScope() {
|
|
604
|
+
return this.scopeStack.join(".");
|
|
605
|
+
}
|
|
606
|
+
// Type registration for classes and functions
|
|
607
|
+
registerClass(className, classInfo) {
|
|
608
|
+
this.classTypes.set(className, classInfo);
|
|
609
|
+
}
|
|
610
|
+
registerFunction(functionName, signature) {
|
|
611
|
+
this.functionTypes.set(functionName, signature);
|
|
612
|
+
}
|
|
613
|
+
// Export current state for inter-procedural analysis
|
|
614
|
+
getTypeSnapshot() {
|
|
615
|
+
return {
|
|
616
|
+
variables: new Map(this.variableTypes),
|
|
617
|
+
functions: new Map(this.functionTypes),
|
|
618
|
+
classes: new Map(this.classTypes)
|
|
619
|
+
};
|
|
620
|
+
}
|
|
621
|
+
}
|
|
622
|
+
TypeInference2.InferenceContext = InferenceContext;
|
|
623
|
+
class TypeInferenceEngine {
|
|
624
|
+
contexts = /* @__PURE__ */ new Map();
|
|
625
|
+
createContext(filePath, language) {
|
|
626
|
+
const context = new InferenceContext(language, filePath);
|
|
627
|
+
this.contexts.set(filePath, context);
|
|
628
|
+
return context;
|
|
629
|
+
}
|
|
630
|
+
getContext(filePath) {
|
|
631
|
+
return this.contexts.get(filePath) || null;
|
|
632
|
+
}
|
|
633
|
+
inferTypesForFile(rootNode, content, filePath, language) {
|
|
634
|
+
const context = this.createContext(filePath, language);
|
|
635
|
+
const inferredTypes = /* @__PURE__ */ new Map();
|
|
636
|
+
this.traverseAndInferTypes(rootNode, context, inferredTypes);
|
|
637
|
+
return inferredTypes;
|
|
638
|
+
}
|
|
639
|
+
traverseAndInferTypes(node, context, inferredTypes) {
|
|
640
|
+
if (this.isVariableDeclaration(node)) {
|
|
641
|
+
const varName = this.getVariableName(node);
|
|
642
|
+
const initExpr = this.getVariableInitializer(node);
|
|
643
|
+
if (varName && initExpr) {
|
|
644
|
+
const inferredType = context.inferVariableType(
|
|
645
|
+
varName,
|
|
646
|
+
initExpr,
|
|
647
|
+
"declaration" /* Declaration */
|
|
648
|
+
);
|
|
649
|
+
inferredTypes.set(varName, inferredType);
|
|
650
|
+
}
|
|
651
|
+
}
|
|
652
|
+
if (this.isFunctionDeclaration(node)) {
|
|
653
|
+
const funcName = this.getFunctionName(node);
|
|
654
|
+
const bodyNode = this.getFunctionBody(node);
|
|
655
|
+
if (funcName && bodyNode) {
|
|
656
|
+
context.enterScope(funcName);
|
|
657
|
+
const returnType = context.inferFunctionReturnType(funcName, bodyNode);
|
|
658
|
+
context.exitScope();
|
|
659
|
+
inferredTypes.set(`${funcName}:return`, returnType);
|
|
660
|
+
}
|
|
661
|
+
}
|
|
662
|
+
const flowTypes = context.analyzeControlFlow(node);
|
|
663
|
+
flowTypes.forEach((type, variable) => {
|
|
664
|
+
inferredTypes.set(variable, type);
|
|
665
|
+
});
|
|
666
|
+
const children = node.namedChildren;
|
|
667
|
+
for (let i = 0; i < children.length; i++) {
|
|
668
|
+
const child = children[i];
|
|
669
|
+
if (child) {
|
|
670
|
+
this.traverseAndInferTypes(child, context, inferredTypes);
|
|
671
|
+
}
|
|
672
|
+
}
|
|
673
|
+
}
|
|
674
|
+
// Cross-file type resolution
|
|
675
|
+
resolveTypesAcrossFiles(filePaths) {
|
|
676
|
+
const globalTypes = /* @__PURE__ */ new Map();
|
|
677
|
+
filePaths.forEach((filePath) => {
|
|
678
|
+
const context = this.getContext(filePath);
|
|
679
|
+
if (context) {
|
|
680
|
+
const snapshot = context.getTypeSnapshot();
|
|
681
|
+
snapshot.classes.forEach((classInfo, className) => {
|
|
682
|
+
if (!globalTypes.has(className) || classInfo.confidence > globalTypes.get(className).confidence) {
|
|
683
|
+
globalTypes.set(className, classInfo);
|
|
684
|
+
}
|
|
685
|
+
});
|
|
686
|
+
}
|
|
687
|
+
});
|
|
688
|
+
filePaths.forEach((filePath) => {
|
|
689
|
+
const context = this.getContext(filePath);
|
|
690
|
+
if (context) {
|
|
691
|
+
globalTypes.forEach((typeInfo, typeName) => {
|
|
692
|
+
context.registerClass(typeName, typeInfo);
|
|
693
|
+
});
|
|
694
|
+
}
|
|
695
|
+
});
|
|
696
|
+
return globalTypes;
|
|
697
|
+
}
|
|
698
|
+
// Language-agnostic AST node detection
|
|
699
|
+
isVariableDeclaration(node) {
|
|
700
|
+
const varDeclarationTypes = [
|
|
701
|
+
"variable_declaration",
|
|
702
|
+
"let_declaration",
|
|
703
|
+
"const_declaration",
|
|
704
|
+
"var_declaration",
|
|
705
|
+
"local_variable_declaration",
|
|
706
|
+
"assignment_statement"
|
|
707
|
+
];
|
|
708
|
+
return varDeclarationTypes.includes(node.type);
|
|
709
|
+
}
|
|
710
|
+
isFunctionDeclaration(node) {
|
|
711
|
+
const funcDeclarationTypes = [
|
|
712
|
+
"function_declaration",
|
|
713
|
+
"function_definition",
|
|
714
|
+
"method_declaration",
|
|
715
|
+
"def",
|
|
716
|
+
"defn",
|
|
717
|
+
"fn",
|
|
718
|
+
"func"
|
|
719
|
+
];
|
|
720
|
+
return funcDeclarationTypes.includes(node.type);
|
|
721
|
+
}
|
|
722
|
+
getVariableName(node) {
|
|
723
|
+
const nameNode = node.childForFieldName("name") || node.childForFieldName("identifier") || node.childForFieldName("pattern");
|
|
724
|
+
return nameNode ? nameNode.text : null;
|
|
725
|
+
}
|
|
726
|
+
getVariableInitializer(node) {
|
|
727
|
+
return node.childForFieldName("value") || node.childForFieldName("initializer") || node.childForFieldName("expression");
|
|
728
|
+
}
|
|
729
|
+
getFunctionName(node) {
|
|
730
|
+
const nameNode = node.childForFieldName("name") || node.childForFieldName("identifier");
|
|
731
|
+
return nameNode ? nameNode.text : null;
|
|
732
|
+
}
|
|
733
|
+
getFunctionBody(node) {
|
|
734
|
+
return node.childForFieldName("body") || node.childForFieldName("block") || node.childForFieldName("compound_statement");
|
|
735
|
+
}
|
|
736
|
+
}
|
|
737
|
+
TypeInference2.TypeInferenceEngine = TypeInferenceEngine;
|
|
738
|
+
function enhanceAnalyzerWithTypeInference(analyzer, language) {
|
|
739
|
+
const engine = new TypeInferenceEngine();
|
|
740
|
+
return {
|
|
741
|
+
analyze(rootNode, content, filePath, context) {
|
|
742
|
+
const result = analyzer.analyze(rootNode, content, filePath, context);
|
|
743
|
+
const inferredTypes = engine.inferTypesForFile(rootNode, content, filePath, language);
|
|
744
|
+
result.symbols.forEach((symbol) => {
|
|
745
|
+
const typeInfo = inferredTypes.get(symbol.name);
|
|
746
|
+
if (typeInfo) {
|
|
747
|
+
symbol.metadata = {
|
|
748
|
+
...symbol.metadata,
|
|
749
|
+
inferredType: typeInfo,
|
|
750
|
+
typeConfidence: typeInfo.confidence,
|
|
751
|
+
typeInferenceReasons: typeInfo.inferredAt.map((loc) => loc.reason)
|
|
752
|
+
};
|
|
753
|
+
}
|
|
754
|
+
});
|
|
755
|
+
const typeRelationships = [];
|
|
756
|
+
inferredTypes.forEach((typeInfo, symbolName) => {
|
|
757
|
+
if (typeInfo.superTypes) {
|
|
758
|
+
typeInfo.superTypes.forEach((superType) => {
|
|
759
|
+
typeRelationships.push({
|
|
760
|
+
source: symbolName,
|
|
761
|
+
target: superType.name,
|
|
762
|
+
type: ASTEngine.RelationshipType.Extends,
|
|
763
|
+
confidence: typeInfo.confidence,
|
|
764
|
+
metadata: {
|
|
765
|
+
inferredFromTypes: true,
|
|
766
|
+
typeInference: true
|
|
767
|
+
}
|
|
768
|
+
});
|
|
769
|
+
});
|
|
770
|
+
}
|
|
771
|
+
});
|
|
772
|
+
result.relationships.push(...typeRelationships);
|
|
773
|
+
return result;
|
|
774
|
+
}
|
|
775
|
+
};
|
|
776
|
+
}
|
|
777
|
+
TypeInference2.enhanceAnalyzerWithTypeInference = enhanceAnalyzerWithTypeInference;
|
|
778
|
+
})(TypeInference || (TypeInference = {}));
|
|
779
|
+
|
|
780
|
+
export {
|
|
781
|
+
TypeInference
|
|
782
|
+
};
|