@typecad/cuttlefish 0.1.0-alpha.1
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/LICENSE +21 -0
- package/README.md +79 -0
- package/dist/api/board-types.d.ts +1 -0
- package/dist/api/board-types.js +4 -0
- package/dist/api/capabilities.d.ts +12 -0
- package/dist/api/capabilities.js +1 -0
- package/dist/api/config.d.ts +120 -0
- package/dist/api/config.js +7 -0
- package/dist/api/index.d.ts +5 -0
- package/dist/api/index.js +2 -0
- package/dist/api/schema/builder.d.ts +14 -0
- package/dist/api/schema/builder.js +15 -0
- package/dist/api/schema/index.d.ts +2 -0
- package/dist/api/schema/index.js +1 -0
- package/dist/api/schema/types.d.ts +257 -0
- package/dist/api/schema/types.js +4 -0
- package/dist/api/shared/async-runtime-static.d.ts +8 -0
- package/dist/api/shared/async-runtime-static.js +201 -0
- package/dist/api/shared/async-types.d.ts +42 -0
- package/dist/api/shared/async-types.js +8 -0
- package/dist/api/shared/board-resolver.d.ts +12 -0
- package/dist/api/shared/board-resolver.js +7 -0
- package/dist/api/shared/cpp-type-ir.d.ts +229 -0
- package/dist/api/shared/cpp-type-ir.js +672 -0
- package/dist/api/shared/display-adapter.d.ts +12 -0
- package/dist/api/shared/display-adapter.js +145 -0
- package/dist/api/shared/display-adapters/eink-mono.d.ts +2 -0
- package/dist/api/shared/display-adapters/eink-mono.js +53 -0
- package/dist/api/shared/display-adapters/sdl.d.ts +2 -0
- package/dist/api/shared/display-adapters/sdl.js +452 -0
- package/dist/api/shared/display-adapters/ssd1309.d.ts +2 -0
- package/dist/api/shared/display-adapters/ssd1309.js +136 -0
- package/dist/api/shared/display-adapters/st7796.d.ts +2 -0
- package/dist/api/shared/display-adapters/st7796.js +132 -0
- package/dist/api/shared/display-capabilities.d.ts +45 -0
- package/dist/api/shared/display-capabilities.js +54 -0
- package/dist/api/shared/display-op-ir.d.ts +62 -0
- package/dist/api/shared/display-op-ir.js +19 -0
- package/dist/api/shared/display-profile.d.ts +265 -0
- package/dist/api/shared/display-profile.js +338 -0
- package/dist/api/shared/graphics-strategy.d.ts +29 -0
- package/dist/api/shared/graphics-strategy.js +11 -0
- package/dist/api/shared/hal-op-ir.d.ts +393 -0
- package/dist/api/shared/hal-op-ir.js +18 -0
- package/dist/api/shared/index.d.ts +26 -0
- package/dist/api/shared/index.js +21 -0
- package/dist/api/shared/ir-core.d.ts +363 -0
- package/dist/api/shared/ir-core.js +8 -0
- package/dist/api/shared/ir-declarations.d.ts +201 -0
- package/dist/api/shared/ir-declarations.js +26 -0
- package/dist/api/shared/ir.d.ts +85 -0
- package/dist/api/shared/ir.js +13 -0
- package/dist/api/shared/platform-strategy.d.ts +402 -0
- package/dist/api/shared/platform-strategy.js +14 -0
- package/dist/api/shared/polyfill-helper-registry.d.ts +11 -0
- package/dist/api/shared/polyfill-helper-registry.js +86 -0
- package/dist/api/shared/polyfill-types.d.ts +33 -0
- package/dist/api/shared/polyfill-types.js +76 -0
- package/dist/api/shared/promise-runtime.d.ts +10 -0
- package/dist/api/shared/promise-runtime.js +244 -0
- package/dist/api/shared/snprintf-types.d.ts +29 -0
- package/dist/api/shared/snprintf-types.js +8 -0
- package/dist/api/shared/string-method-registry.d.ts +53 -0
- package/dist/api/shared/string-method-registry.js +168 -0
- package/dist/api/shared/toolchain-types.d.ts +63 -0
- package/dist/api/shared/toolchain-types.js +71 -0
- package/dist/api/shared/types.d.ts +50 -0
- package/dist/api/shared/types.js +6 -0
- package/dist/ast/parse.d.ts +2 -0
- package/dist/ast/parse.js +4 -0
- package/dist/cache.d.ts +26 -0
- package/dist/cache.js +95 -0
- package/dist/cli-utils.d.ts +37 -0
- package/dist/cli-utils.js +250 -0
- package/dist/cli.d.ts +2 -0
- package/dist/cli.js +635 -0
- package/dist/config-loader.d.ts +78 -0
- package/dist/config-loader.js +508 -0
- package/dist/config-schema.d.ts +233 -0
- package/dist/config-schema.js +83 -0
- package/dist/create/board-checklist.d.ts +2 -0
- package/dist/create/board-checklist.js +52 -0
- package/dist/create/board-codegen.d.ts +9 -0
- package/dist/create/board-codegen.js +238 -0
- package/dist/create/board-generators.d.ts +12 -0
- package/dist/create/board-generators.js +652 -0
- package/dist/create/board-spec.d.ts +640 -0
- package/dist/create/board-spec.js +215 -0
- package/dist/create/eslint-rules-template.d.ts +2 -0
- package/dist/create/eslint-rules-template.js +672 -0
- package/dist/create/index.d.ts +11 -0
- package/dist/create/index.js +8 -0
- package/dist/create/init-scaffold.d.ts +27 -0
- package/dist/create/init-scaffold.js +150 -0
- package/dist/create/init-templates.d.ts +24 -0
- package/dist/create/init-templates.js +379 -0
- package/dist/create/init-wizard.d.ts +8 -0
- package/dist/create/init-wizard.js +168 -0
- package/dist/debug/breakpoint-loader.d.ts +24 -0
- package/dist/debug/breakpoint-loader.js +137 -0
- package/dist/debug/index.d.ts +3 -0
- package/dist/debug/index.js +7 -0
- package/dist/debug/preprocessor.d.ts +9 -0
- package/dist/debug/preprocessor.js +214 -0
- package/dist/debug/types.d.ts +32 -0
- package/dist/debug/types.js +6 -0
- package/dist/diagnostics/diagnostics-report.d.ts +51 -0
- package/dist/diagnostics/diagnostics-report.js +333 -0
- package/dist/diagnostics/json-schema.d.ts +138 -0
- package/dist/diagnostics/json-schema.js +27 -0
- package/dist/diagnostics/md-writer.d.ts +10 -0
- package/dist/diagnostics/md-writer.js +336 -0
- package/dist/diagnostics/mermaid-builder.d.ts +65 -0
- package/dist/diagnostics/mermaid-builder.js +681 -0
- package/dist/emit/cpp-emitter.d.ts +6 -0
- package/dist/emit/cpp-emitter.js +48 -0
- package/dist/emit/emitters/class-emitter.d.ts +2 -0
- package/dist/emit/emitters/class-emitter.js +523 -0
- package/dist/emit/emitters/emitter-context.d.ts +174 -0
- package/dist/emit/emitters/emitter-context.js +1 -0
- package/dist/emit/emitters/entrypoint-synthesizer.d.ts +2 -0
- package/dist/emit/emitters/entrypoint-synthesizer.js +175 -0
- package/dist/emit/emitters/function-emitter-impl.d.ts +19 -0
- package/dist/emit/emitters/function-emitter-impl.js +428 -0
- package/dist/emit/emitters/line-appender.d.ts +15 -0
- package/dist/emit/emitters/line-appender.js +344 -0
- package/dist/emit/emitters/namespace-emitter.d.ts +2 -0
- package/dist/emit/emitters/namespace-emitter.js +324 -0
- package/dist/emit/emitters/output-finalizer.d.ts +4 -0
- package/dist/emit/emitters/output-finalizer.js +267 -0
- package/dist/emit/emitters/setup.d.ts +3 -0
- package/dist/emit/emitters/setup.js +851 -0
- package/dist/emit/emitters/top-level-prep.d.ts +2 -0
- package/dist/emit/emitters/top-level-prep.js +706 -0
- package/dist/emit/emitters/type-decl-emitter.d.ts +2 -0
- package/dist/emit/emitters/type-decl-emitter.js +251 -0
- package/dist/emit/emitters/ui-emitter.d.ts +21 -0
- package/dist/emit/emitters/ui-emitter.js +564 -0
- package/dist/emit/enum-emitter.d.ts +1 -0
- package/dist/emit/enum-emitter.js +1 -0
- package/dist/emit/expression-renderer.d.ts +283 -0
- package/dist/emit/expression-renderer.js +1477 -0
- package/dist/emit/native-helpers-emitter.d.ts +11 -0
- package/dist/emit/native-helpers-emitter.js +34 -0
- package/dist/emit/route-hal-op.d.ts +5 -0
- package/dist/emit/route-hal-op.js +13 -0
- package/dist/emit/snprintf-helpers.d.ts +17 -0
- package/dist/emit/snprintf-helpers.js +462 -0
- package/dist/emit/statement-renderer.d.ts +189 -0
- package/dist/emit/statement-renderer.js +948 -0
- package/dist/emit/utils/async-state-machine.d.ts +42 -0
- package/dist/emit/utils/async-state-machine.js +343 -0
- package/dist/emit/utils/comment-helpers.d.ts +20 -0
- package/dist/emit/utils/comment-helpers.js +31 -0
- package/dist/emit/utils/cpp-helpers.d.ts +47 -0
- package/dist/emit/utils/cpp-helpers.js +85 -0
- package/dist/emit/utils/include-resolver.d.ts +58 -0
- package/dist/emit/utils/include-resolver.js +155 -0
- package/dist/emit/utils/index.d.ts +8 -0
- package/dist/emit/utils/index.js +12 -0
- package/dist/emit/utils/type-inference.d.ts +159 -0
- package/dist/emit/utils/type-inference.js +559 -0
- package/dist/eslint-check.d.ts +10 -0
- package/dist/eslint-check.js +102 -0
- package/dist/framework-package.d.ts +10 -0
- package/dist/framework-package.js +58 -0
- package/dist/framework-registry.d.ts +39 -0
- package/dist/framework-registry.js +30 -0
- package/dist/incremental-cache.d.ts +116 -0
- package/dist/incremental-cache.js +335 -0
- package/dist/ir/adc-range-validation.d.ts +11 -0
- package/dist/ir/adc-range-validation.js +250 -0
- package/dist/ir/ast-node-utils.d.ts +8 -0
- package/dist/ir/ast-node-utils.js +32 -0
- package/dist/ir/board-pin-utils.d.ts +13 -0
- package/dist/ir/board-pin-utils.js +65 -0
- package/dist/ir/board-resolver.d.ts +36 -0
- package/dist/ir/board-resolver.js +437 -0
- package/dist/ir/build-ir-state.d.ts +167 -0
- package/dist/ir/build-ir-state.js +306 -0
- package/dist/ir/build-ir.d.ts +2 -0
- package/dist/ir/build-ir.js +808 -0
- package/dist/ir/call-graph.d.ts +35 -0
- package/dist/ir/call-graph.js +194 -0
- package/dist/ir/compile-time-only.d.ts +2 -0
- package/dist/ir/compile-time-only.js +16 -0
- package/dist/ir/declaration-builders.d.ts +9 -0
- package/dist/ir/declaration-builders.js +608 -0
- package/dist/ir/entry-points.d.ts +30 -0
- package/dist/ir/entry-points.js +191 -0
- package/dist/ir/expression-to-ir.d.ts +5 -0
- package/dist/ir/expression-to-ir.js +2249 -0
- package/dist/ir/extract-property-chain.d.ts +10 -0
- package/dist/ir/extract-property-chain.js +30 -0
- package/dist/ir/feature-prescan.d.ts +3 -0
- package/dist/ir/feature-prescan.js +43 -0
- package/dist/ir/feature-registry.d.ts +30 -0
- package/dist/ir/feature-registry.js +816 -0
- package/dist/ir/filter.d.ts +7 -0
- package/dist/ir/filter.js +85 -0
- package/dist/ir/function-builder.d.ts +19 -0
- package/dist/ir/function-builder.js +670 -0
- package/dist/ir/hal/hal-emitter.d.ts +62 -0
- package/dist/ir/hal/hal-emitter.js +735 -0
- package/dist/ir/hal/hal-parser.d.ts +61 -0
- package/dist/ir/hal/hal-parser.js +473 -0
- package/dist/ir/hal/hal-plugins.d.ts +34 -0
- package/dist/ir/hal/hal-plugins.js +706 -0
- package/dist/ir/hal-resolver.d.ts +5 -0
- package/dist/ir/hal-resolver.js +5 -0
- package/dist/ir/heap-analysis.d.ts +8 -0
- package/dist/ir/heap-analysis.js +350 -0
- package/dist/ir/heap-array-validation.d.ts +24 -0
- package/dist/ir/heap-array-validation.js +29 -0
- package/dist/ir/identifier-collector.d.ts +18 -0
- package/dist/ir/identifier-collector.js +439 -0
- package/dist/ir/interrupt-analysis.d.ts +39 -0
- package/dist/ir/interrupt-analysis.js +467 -0
- package/dist/ir/memory-budget-validation.d.ts +10 -0
- package/dist/ir/memory-budget-validation.js +86 -0
- package/dist/ir/namespace-builder.d.ts +7 -0
- package/dist/ir/namespace-builder.js +152 -0
- package/dist/ir/ownership-analysis.d.ts +9 -0
- package/dist/ir/ownership-analysis.js +1207 -0
- package/dist/ir/peripheral-ownership.d.ts +3 -0
- package/dist/ir/peripheral-ownership.js +152 -0
- package/dist/ir/peripheral-symbols.d.ts +7 -0
- package/dist/ir/peripheral-symbols.js +57 -0
- package/dist/ir/peripheral-usage.d.ts +54 -0
- package/dist/ir/peripheral-usage.js +691 -0
- package/dist/ir/peripheral-validation.d.ts +8 -0
- package/dist/ir/peripheral-validation.js +77 -0
- package/dist/ir/pin-alias-conflict.d.ts +4 -0
- package/dist/ir/pin-alias-conflict.js +34 -0
- package/dist/ir/pin-capability-validation.d.ts +6 -0
- package/dist/ir/pin-capability-validation.js +413 -0
- package/dist/ir/pin-mode-validation.d.ts +10 -0
- package/dist/ir/pin-mode-validation.js +301 -0
- package/dist/ir/pin-safety.d.ts +11 -0
- package/dist/ir/pin-safety.js +58 -0
- package/dist/ir/program-analysis.d.ts +44 -0
- package/dist/ir/program-analysis.js +589 -0
- package/dist/ir/pulldown-validation.d.ts +7 -0
- package/dist/ir/pulldown-validation.js +49 -0
- package/dist/ir/pwm-timer-sharing.d.ts +4 -0
- package/dist/ir/pwm-timer-sharing.js +93 -0
- package/dist/ir/reachability.d.ts +68 -0
- package/dist/ir/reachability.js +224 -0
- package/dist/ir/register-decorators.d.ts +6 -0
- package/dist/ir/register-decorators.js +49 -0
- package/dist/ir/render-expr.d.ts +4 -0
- package/dist/ir/render-expr.js +127 -0
- package/dist/ir/resource-analysis.d.ts +19 -0
- package/dist/ir/resource-analysis.js +153 -0
- package/dist/ir/statement-to-ir.d.ts +23 -0
- package/dist/ir/statement-to-ir.js +349 -0
- package/dist/ir/symbol-table.d.ts +68 -0
- package/dist/ir/symbol-table.js +179 -0
- package/dist/ir/symbol-types.d.ts +56 -0
- package/dist/ir/symbol-types.js +107 -0
- package/dist/ir/timer0-pwm-timing-conflict.d.ts +4 -0
- package/dist/ir/timer0-pwm-timing-conflict.js +71 -0
- package/dist/ir/timing-validation.d.ts +7 -0
- package/dist/ir/timing-validation.js +95 -0
- package/dist/ir/transformers/array-methods.d.ts +8 -0
- package/dist/ir/transformers/array-methods.js +493 -0
- package/dist/ir/transformers/call-statement.d.ts +5 -0
- package/dist/ir/transformers/call-statement.js +758 -0
- package/dist/ir/transformers/callback-context-registry.d.ts +20 -0
- package/dist/ir/transformers/callback-context-registry.js +55 -0
- package/dist/ir/transformers/canvas-lowering.d.ts +42 -0
- package/dist/ir/transformers/canvas-lowering.js +249 -0
- package/dist/ir/transformers/control-flow.d.ts +8 -0
- package/dist/ir/transformers/control-flow.js +508 -0
- package/dist/ir/transformers/expressions.d.ts +7 -0
- package/dist/ir/transformers/expressions.js +406 -0
- package/dist/ir/transformers/hal-call-resolver.d.ts +29 -0
- package/dist/ir/transformers/hal-call-resolver.js +274 -0
- package/dist/ir/transformers/hal-emit-helpers.d.ts +14 -0
- package/dist/ir/transformers/hal-emit-helpers.js +63 -0
- package/dist/ir/transformers/namespace-methods.d.ts +20 -0
- package/dist/ir/transformers/namespace-methods.js +110 -0
- package/dist/ir/transformers/register-assignment.d.ts +5 -0
- package/dist/ir/transformers/register-assignment.js +56 -0
- package/dist/ir/transformers/ui-call-resolver.d.ts +149 -0
- package/dist/ir/transformers/ui-call-resolver.js +1136 -0
- package/dist/ir/transformers/ui-callback-lowering.d.ts +62 -0
- package/dist/ir/transformers/ui-callback-lowering.js +623 -0
- package/dist/ir/transformers/ui-mount.d.ts +20 -0
- package/dist/ir/transformers/ui-mount.js +35 -0
- package/dist/ir/transformers/ui-reactive.d.ts +68 -0
- package/dist/ir/transformers/ui-reactive.js +129 -0
- package/dist/ir/transformers/variables.d.ts +14 -0
- package/dist/ir/transformers/variables.js +1045 -0
- package/dist/ir/try-catch-validation.d.ts +26 -0
- package/dist/ir/try-catch-validation.js +128 -0
- package/dist/ir/type-resolution.d.ts +31 -0
- package/dist/ir/type-resolution.js +977 -0
- package/dist/ir/ui-element-auto-wire.d.ts +50 -0
- package/dist/ir/ui-element-auto-wire.js +218 -0
- package/dist/ir/unit-suspicion-validation.d.ts +12 -0
- package/dist/ir/unit-suspicion-validation.js +296 -0
- package/dist/ir/utils/walk-ir.d.ts +6 -0
- package/dist/ir/utils/walk-ir.js +162 -0
- package/dist/ir/validation-orchestrator.d.ts +4 -0
- package/dist/ir/validation-orchestrator.js +45 -0
- package/dist/libdef/base-class-resolver.d.ts +23 -0
- package/dist/libdef/base-class-resolver.js +50 -0
- package/dist/libdef/cpp-to-decl.d.ts +34 -0
- package/dist/libdef/cpp-to-decl.js +584 -0
- package/dist/libdef/header-parser.d.ts +53 -0
- package/dist/libdef/header-parser.js +269 -0
- package/dist/libdef/registry.d.ts +10 -0
- package/dist/libdef/registry.js +142 -0
- package/dist/mapping/peripheral-names.d.ts +23 -0
- package/dist/mapping/peripheral-names.js +63 -0
- package/dist/mapping/source-map.d.ts +46 -0
- package/dist/mapping/source-map.js +207 -0
- package/dist/orchestrator/dts-generator.d.ts +17 -0
- package/dist/orchestrator/dts-generator.js +83 -0
- package/dist/orchestrator/graph-builder.d.ts +18 -0
- package/dist/orchestrator/graph-builder.js +218 -0
- package/dist/orchestrator/semantic-facts-verifier.d.ts +38 -0
- package/dist/orchestrator/semantic-facts-verifier.js +121 -0
- package/dist/orchestrator/semantic-facts.d.ts +141 -0
- package/dist/orchestrator/semantic-facts.js +652 -0
- package/dist/orchestrator/type-checker.d.ts +39 -0
- package/dist/orchestrator/type-checker.js +760 -0
- package/dist/platform/async-runtime.d.ts +8 -0
- package/dist/platform/async-runtime.js +26 -0
- package/dist/platform/generic-strategy.d.ts +101 -0
- package/dist/platform/generic-strategy.js +289 -0
- package/dist/platform/index.d.ts +4 -0
- package/dist/platform/index.js +9 -0
- package/dist/platform/registry.d.ts +21 -0
- package/dist/platform/registry.js +42 -0
- package/dist/platform/toolchain.d.ts +4 -0
- package/dist/platform/toolchain.js +43 -0
- package/dist/preview/client.d.ts +1 -0
- package/dist/preview/client.js +137 -0
- package/dist/preview/server.d.ts +5 -0
- package/dist/preview/server.js +199 -0
- package/dist/profiler/index.d.ts +28 -0
- package/dist/profiler/index.js +28 -0
- package/dist/profiler/profiler.d.ts +95 -0
- package/dist/profiler/profiler.js +338 -0
- package/dist/profiler/types.d.ts +87 -0
- package/dist/profiler/types.js +12 -0
- package/dist/stores/display-profile-store.d.ts +16 -0
- package/dist/stores/display-profile-store.js +48 -0
- package/dist/stores/theme-store.d.ts +13 -0
- package/dist/stores/theme-store.js +30 -0
- package/dist/testing.d.ts +45 -0
- package/dist/testing.js +47 -0
- package/dist/transpile/resolution.d.ts +29 -0
- package/dist/transpile/resolution.js +282 -0
- package/dist/transpile.d.ts +3 -0
- package/dist/transpile.js +722 -0
- package/dist/types.d.ts +217 -0
- package/dist/types.js +1 -0
- package/dist/ui/ui-bridge.d.ts +4 -0
- package/dist/ui/ui-bridge.js +34 -0
- package/dist/ui-hook.d.ts +84 -0
- package/dist/ui-hook.js +45 -0
- package/dist/utils/cli.d.ts +3 -0
- package/dist/utils/cli.js +463 -0
- package/dist/utils/fs.d.ts +4 -0
- package/dist/utils/fs.js +23 -0
- package/dist/utils/logger.d.ts +2 -0
- package/dist/utils/logger.js +8 -0
- package/dist/utils/strings.d.ts +35 -0
- package/dist/utils/strings.js +142 -0
- package/dist/utils/ui.d.ts +66 -0
- package/dist/utils/ui.js +149 -0
- package/dist/watch.d.ts +35 -0
- package/dist/watch.js +111 -0
- package/package.json +127 -0
|
@@ -0,0 +1,508 @@
|
|
|
1
|
+
import ts from "typescript";
|
|
2
|
+
import { extractNodeComments, makeSourceSpan } from "../ast-node-utils.js";
|
|
3
|
+
import { resolveDeclarationType, inferExprCppType } from "../type-resolution.js";
|
|
4
|
+
import { nestedClassAliases, topLevelAliasReceivers } from "../build-ir-state.js";
|
|
5
|
+
import { parseCppType, renderCppType, isPointer, parsedIsVector, parsedElementString } from "../../api/shared/cpp-type-ir.js";
|
|
6
|
+
import { expressionToIR } from "../expression-to-ir.js";
|
|
7
|
+
import { lowerStatementList, expressionStatementToIR } from "../statement-to-ir.js";
|
|
8
|
+
import { assignmentOperatorToString, updateLocalTypeFromAssignment, extractForInKeys } from "./variables.js";
|
|
9
|
+
// Monotonic counter for synthetic for...of destructure loop variables.
|
|
10
|
+
let forOfDestructureCounter = 0;
|
|
11
|
+
/**
|
|
12
|
+
* Build per-binding extraction statements for a for...of destructure loop
|
|
13
|
+
* variable. For `for (const { x, y } of pts)` with synthetic loop var
|
|
14
|
+
* `__forof_N`, produces:
|
|
15
|
+
* { kind: var_decl, name: "x", initializer: { property-access __forof_N.x } }
|
|
16
|
+
* { kind: var_decl, name: "y", initializer: { property-access __forof_N.y } }
|
|
17
|
+
* and for array patterns `const [a, b]`, index-based extraction
|
|
18
|
+
* (`__forof_N[0]`, `__forof_N[1]`). Each binding is registered in
|
|
19
|
+
* localVariableTypes so the body sees it as a local. Used by the for...of
|
|
20
|
+
* lowerer to desugar a binding-pattern loop variable (Finding A).
|
|
21
|
+
*/
|
|
22
|
+
function buildDestructureExtractions(pattern, sourceName, sourceCppType, sourceSpan, _sourceText, _diagnostics, _functionReturnTypes, localVariableTypes) {
|
|
23
|
+
const extractions = [];
|
|
24
|
+
if (ts.isObjectBindingPattern(pattern)) {
|
|
25
|
+
for (const element of pattern.elements) {
|
|
26
|
+
if (ts.isOmittedExpression(element))
|
|
27
|
+
continue;
|
|
28
|
+
if (!ts.isIdentifier(element.name))
|
|
29
|
+
continue;
|
|
30
|
+
const bindingName = element.name.text;
|
|
31
|
+
const propertyName = element.propertyName && ts.isIdentifier(element.propertyName)
|
|
32
|
+
? element.propertyName.text
|
|
33
|
+
: bindingName;
|
|
34
|
+
const init = {
|
|
35
|
+
kind: "property-access",
|
|
36
|
+
object: { kind: "identifier", value: sourceName },
|
|
37
|
+
property: propertyName,
|
|
38
|
+
// The for...of synthetic loop var is a range-for reference (`const T&`),
|
|
39
|
+
// so member access uses `.` (not `->`). isPointer must be false here
|
|
40
|
+
// regardless of whether T is a class type.
|
|
41
|
+
isPointer: false,
|
|
42
|
+
};
|
|
43
|
+
extractions.push({
|
|
44
|
+
kind: "var_decl",
|
|
45
|
+
sourceSpan,
|
|
46
|
+
name: bindingName,
|
|
47
|
+
storage: "const",
|
|
48
|
+
cppType: "auto",
|
|
49
|
+
initializer: init,
|
|
50
|
+
});
|
|
51
|
+
localVariableTypes.set(bindingName, "auto");
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
else {
|
|
55
|
+
// Array binding pattern: index-based extraction.
|
|
56
|
+
let index = 0;
|
|
57
|
+
for (const element of pattern.elements) {
|
|
58
|
+
if (ts.isOmittedExpression(element)) {
|
|
59
|
+
index++;
|
|
60
|
+
continue;
|
|
61
|
+
}
|
|
62
|
+
if (!ts.isIdentifier(element.name)) {
|
|
63
|
+
index++;
|
|
64
|
+
continue;
|
|
65
|
+
}
|
|
66
|
+
const bindingName = element.name.text;
|
|
67
|
+
const init = {
|
|
68
|
+
kind: "element-access",
|
|
69
|
+
object: { kind: "identifier", value: sourceName },
|
|
70
|
+
index: { kind: "number", value: index },
|
|
71
|
+
};
|
|
72
|
+
extractions.push({
|
|
73
|
+
kind: "var_decl",
|
|
74
|
+
sourceSpan,
|
|
75
|
+
name: bindingName,
|
|
76
|
+
storage: "const",
|
|
77
|
+
cppType: "auto",
|
|
78
|
+
initializer: init,
|
|
79
|
+
});
|
|
80
|
+
localVariableTypes.set(bindingName, "auto");
|
|
81
|
+
index++;
|
|
82
|
+
}
|
|
83
|
+
}
|
|
84
|
+
return extractions;
|
|
85
|
+
}
|
|
86
|
+
export function forInitializerToIR(declarationList, fileName, sourceText, diagnostics, functionReturnTypes, localVariableTypes) {
|
|
87
|
+
const storage = declarationList.flags & ts.NodeFlags.Const
|
|
88
|
+
? "const"
|
|
89
|
+
: declarationList.flags & ts.NodeFlags.Let
|
|
90
|
+
? "let"
|
|
91
|
+
: "var";
|
|
92
|
+
const declaration = declarationList.declarations[0];
|
|
93
|
+
if (!declaration || !ts.isIdentifier(declaration.name)) {
|
|
94
|
+
return undefined;
|
|
95
|
+
}
|
|
96
|
+
const declarationType = resolveDeclarationType(declaration.type, declaration.initializer, functionReturnTypes, localVariableTypes, undefined, sourceText);
|
|
97
|
+
localVariableTypes.set(declaration.name.text, declarationType.resolvedType);
|
|
98
|
+
// Resolve type through nested class aliases for hoisted class names.
|
|
99
|
+
let resolvedType = declarationType.resolvedType === "void" ? "auto" : declarationType.resolvedType;
|
|
100
|
+
{
|
|
101
|
+
const ir = parseCppType(resolvedType);
|
|
102
|
+
const ptr = isPointer(ir);
|
|
103
|
+
const baseName = (() => {
|
|
104
|
+
const b = ir.kind === "pointer" ? ir.base : ir;
|
|
105
|
+
return b.kind === "named" ? b.name : renderCppType(b);
|
|
106
|
+
})();
|
|
107
|
+
if (nestedClassAliases.has(baseName)) {
|
|
108
|
+
const aliasedIr = ptr
|
|
109
|
+
? { kind: "pointer", base: parseCppType(nestedClassAliases.get(baseName)) }
|
|
110
|
+
: parseCppType(nestedClassAliases.get(baseName));
|
|
111
|
+
resolvedType = renderCppType(aliasedIr);
|
|
112
|
+
}
|
|
113
|
+
}
|
|
114
|
+
return {
|
|
115
|
+
kind: "var_decl",
|
|
116
|
+
sourceSpan: makeSourceSpan(declaration, fileName, sourceText),
|
|
117
|
+
name: declaration.name.text,
|
|
118
|
+
storage,
|
|
119
|
+
cppType: resolvedType,
|
|
120
|
+
initializer: declaration.initializer
|
|
121
|
+
? expressionToIR(declaration.initializer, sourceText, diagnostics)
|
|
122
|
+
: undefined,
|
|
123
|
+
};
|
|
124
|
+
}
|
|
125
|
+
export function incrementorToIR(expr, sourceText, diagnostics, localVariableTypes) {
|
|
126
|
+
if (ts.isPostfixUnaryExpression(expr) && ts.isIdentifier(expr.operand)) {
|
|
127
|
+
if (expr.operator === ts.SyntaxKind.PlusPlusToken || expr.operator === ts.SyntaxKind.MinusMinusToken) {
|
|
128
|
+
return {
|
|
129
|
+
kind: "update",
|
|
130
|
+
sourceSpan: makeSourceSpan(expr, "", sourceText),
|
|
131
|
+
target: expr.operand.text,
|
|
132
|
+
operator: expr.operator === ts.SyntaxKind.PlusPlusToken ? "++" : "--",
|
|
133
|
+
prefix: false,
|
|
134
|
+
};
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
if (ts.isPrefixUnaryExpression(expr) && ts.isIdentifier(expr.operand)) {
|
|
138
|
+
if (expr.operator === ts.SyntaxKind.PlusPlusToken || expr.operator === ts.SyntaxKind.MinusMinusToken) {
|
|
139
|
+
return {
|
|
140
|
+
kind: "update",
|
|
141
|
+
sourceSpan: makeSourceSpan(expr, "", sourceText),
|
|
142
|
+
target: expr.operand.text,
|
|
143
|
+
operator: expr.operator === ts.SyntaxKind.PlusPlusToken ? "++" : "--",
|
|
144
|
+
prefix: true,
|
|
145
|
+
};
|
|
146
|
+
}
|
|
147
|
+
}
|
|
148
|
+
if (ts.isBinaryExpression(expr) && ts.isIdentifier(expr.left)) {
|
|
149
|
+
const operator = assignmentOperatorToString(expr.operatorToken.kind);
|
|
150
|
+
if (operator) {
|
|
151
|
+
const valueType = inferExprCppType(expr.right, new Map(), localVariableTypes, sourceText);
|
|
152
|
+
updateLocalTypeFromAssignment(expr.left.text, operator, valueType, localVariableTypes);
|
|
153
|
+
return {
|
|
154
|
+
kind: "assign",
|
|
155
|
+
sourceSpan: makeSourceSpan(expr, "", sourceText),
|
|
156
|
+
target: expr.left.text,
|
|
157
|
+
operator,
|
|
158
|
+
value: expressionToIR(expr.right, sourceText, diagnostics),
|
|
159
|
+
};
|
|
160
|
+
}
|
|
161
|
+
}
|
|
162
|
+
return undefined;
|
|
163
|
+
}
|
|
164
|
+
export function lowerControlFlowStatement(statement, fileName, sourceText, diagnostics, functionReturnTypes, localVariableTypes, functionNameForDiagnostics, typeAliases, pointerVars = new Map()) {
|
|
165
|
+
if (ts.isReturnStatement(statement) && !statement.expression) {
|
|
166
|
+
const comments = extractNodeComments(statement, sourceText);
|
|
167
|
+
return [{
|
|
168
|
+
kind: "return",
|
|
169
|
+
sourceSpan: makeSourceSpan(statement, fileName, sourceText),
|
|
170
|
+
leadingComments: comments.leadingComments,
|
|
171
|
+
trailingComments: comments.trailingComments,
|
|
172
|
+
...(functionReturnTypes.get(functionNameForDiagnostics) ? { functionReturnType: functionReturnTypes.get(functionNameForDiagnostics) } : {}),
|
|
173
|
+
}];
|
|
174
|
+
}
|
|
175
|
+
if (ts.isReturnStatement(statement) && statement.expression) {
|
|
176
|
+
const comments = extractNodeComments(statement, sourceText);
|
|
177
|
+
return [{
|
|
178
|
+
kind: "return",
|
|
179
|
+
sourceSpan: makeSourceSpan(statement, fileName, sourceText),
|
|
180
|
+
leadingComments: comments.leadingComments,
|
|
181
|
+
trailingComments: comments.trailingComments,
|
|
182
|
+
value: expressionToIR(statement.expression, sourceText, diagnostics, pointerVars),
|
|
183
|
+
...(functionReturnTypes.get(functionNameForDiagnostics) ? { functionReturnType: functionReturnTypes.get(functionNameForDiagnostics) } : {}),
|
|
184
|
+
}];
|
|
185
|
+
}
|
|
186
|
+
if (ts.isWhileStatement(statement)) {
|
|
187
|
+
const comments = extractNodeComments(statement, sourceText);
|
|
188
|
+
const bodyStatements = lowerStatementList(ts.isBlock(statement.statement) ? statement.statement.statements : [statement.statement], fileName, sourceText, diagnostics, functionReturnTypes, localVariableTypes, functionNameForDiagnostics, typeAliases, pointerVars);
|
|
189
|
+
return [{
|
|
190
|
+
kind: "while",
|
|
191
|
+
sourceSpan: makeSourceSpan(statement, fileName, sourceText),
|
|
192
|
+
leadingComments: comments.leadingComments,
|
|
193
|
+
trailingComments: comments.trailingComments,
|
|
194
|
+
condition: expressionToIR(statement.expression, sourceText, diagnostics, pointerVars),
|
|
195
|
+
body: bodyStatements,
|
|
196
|
+
}];
|
|
197
|
+
}
|
|
198
|
+
if (ts.isIfStatement(statement)) {
|
|
199
|
+
const comments = extractNodeComments(statement, sourceText);
|
|
200
|
+
const thenStatements = lowerStatementList(ts.isBlock(statement.thenStatement) ? statement.thenStatement.statements : [statement.thenStatement], fileName, sourceText, diagnostics, functionReturnTypes, localVariableTypes, functionNameForDiagnostics, typeAliases, pointerVars);
|
|
201
|
+
let elseBranch;
|
|
202
|
+
if (statement.elseStatement) {
|
|
203
|
+
elseBranch = lowerStatementList(ts.isBlock(statement.elseStatement) ? statement.elseStatement.statements : [statement.elseStatement], fileName, sourceText, diagnostics, functionReturnTypes, localVariableTypes, functionNameForDiagnostics, typeAliases, pointerVars);
|
|
204
|
+
}
|
|
205
|
+
// Evaluate the condition. If it's a bare identifier that resolves to a
|
|
206
|
+
// HAL alias (e.g. `if (bus2)` where bus2 = I2C0.take()), the alias is a
|
|
207
|
+
// compile-time non-null reference — constant-fold to `true` so the emit
|
|
208
|
+
// layer never references the suppressed variable.
|
|
209
|
+
let condition;
|
|
210
|
+
if (ts.isIdentifier(statement.expression) && topLevelAliasReceivers.has(statement.expression.text)) {
|
|
211
|
+
condition = { kind: "boolean", value: true };
|
|
212
|
+
}
|
|
213
|
+
else {
|
|
214
|
+
condition = expressionToIR(statement.expression, sourceText, diagnostics, pointerVars);
|
|
215
|
+
}
|
|
216
|
+
return [{
|
|
217
|
+
kind: "if",
|
|
218
|
+
sourceSpan: makeSourceSpan(statement, fileName, sourceText),
|
|
219
|
+
leadingComments: comments.leadingComments,
|
|
220
|
+
trailingComments: comments.trailingComments,
|
|
221
|
+
condition,
|
|
222
|
+
thenBranch: thenStatements,
|
|
223
|
+
elseBranch,
|
|
224
|
+
}];
|
|
225
|
+
}
|
|
226
|
+
if (ts.isForStatement(statement)) {
|
|
227
|
+
const comments = extractNodeComments(statement, sourceText);
|
|
228
|
+
let initializer;
|
|
229
|
+
if (statement.initializer) {
|
|
230
|
+
if (ts.isVariableDeclarationList(statement.initializer)) {
|
|
231
|
+
initializer = forInitializerToIR(statement.initializer, fileName, sourceText, diagnostics, functionReturnTypes, localVariableTypes);
|
|
232
|
+
}
|
|
233
|
+
else if (ts.isExpressionStatement(statement.initializer)) {
|
|
234
|
+
const loweredExpr = expressionStatementToIR(statement.initializer, fileName, sourceText, diagnostics, functionReturnTypes, localVariableTypes, pointerVars);
|
|
235
|
+
initializer = loweredExpr;
|
|
236
|
+
}
|
|
237
|
+
}
|
|
238
|
+
const condition = statement.condition
|
|
239
|
+
? expressionToIR(statement.condition, sourceText, diagnostics, pointerVars)
|
|
240
|
+
: undefined;
|
|
241
|
+
let increment;
|
|
242
|
+
if (statement.incrementor) {
|
|
243
|
+
increment = incrementorToIR(statement.incrementor, sourceText, diagnostics, localVariableTypes);
|
|
244
|
+
}
|
|
245
|
+
const bodyStatements = lowerStatementList(ts.isBlock(statement.statement) ? statement.statement.statements : [statement.statement], fileName, sourceText, diagnostics, functionReturnTypes, localVariableTypes, functionNameForDiagnostics, typeAliases, pointerVars);
|
|
246
|
+
return [{
|
|
247
|
+
kind: "for",
|
|
248
|
+
sourceSpan: makeSourceSpan(statement, fileName, sourceText),
|
|
249
|
+
leadingComments: comments.leadingComments,
|
|
250
|
+
trailingComments: comments.trailingComments,
|
|
251
|
+
initializer,
|
|
252
|
+
condition,
|
|
253
|
+
increment,
|
|
254
|
+
body: bodyStatements,
|
|
255
|
+
}];
|
|
256
|
+
}
|
|
257
|
+
if (ts.isForOfStatement(statement)) {
|
|
258
|
+
const comments = extractNodeComments(statement, sourceText);
|
|
259
|
+
let variable;
|
|
260
|
+
// Detect a destructuring loop variable: `for (const { x, y } of pts)`.
|
|
261
|
+
// forInitializerToIR assumes an identifier name; a binding pattern has
|
|
262
|
+
// none, so it would crash. Desugar at the IR level: a synthetic loop var
|
|
263
|
+
// (`__forof_N`) carries the iterable element, and per-binding extraction
|
|
264
|
+
// statements are prepended to the body (destructure stress test Finding A).
|
|
265
|
+
let destructureExtractions = [];
|
|
266
|
+
let isDestructureLoopVar = false;
|
|
267
|
+
let bindingPattern;
|
|
268
|
+
if (ts.isVariableDeclarationList(statement.initializer)) {
|
|
269
|
+
const decl = statement.initializer.declarations[0];
|
|
270
|
+
if (decl && (ts.isObjectBindingPattern(decl.name) || ts.isArrayBindingPattern(decl.name))) {
|
|
271
|
+
isDestructureLoopVar = true;
|
|
272
|
+
bindingPattern = decl.name;
|
|
273
|
+
}
|
|
274
|
+
}
|
|
275
|
+
if (isDestructureLoopVar && bindingPattern) {
|
|
276
|
+
// Resolve the iterable's element type for the synthetic loop var.
|
|
277
|
+
const iterableType = inferExprCppType(statement.expression, functionReturnTypes, localVariableTypes, sourceText);
|
|
278
|
+
const elementType = iterableType && parsedIsVector(iterableType)
|
|
279
|
+
? parsedElementString(iterableType)
|
|
280
|
+
: "auto";
|
|
281
|
+
const syntheticName = `__forof_${forOfDestructureCounter++}`;
|
|
282
|
+
const forOfSpan = makeSourceSpan(statement, fileName, sourceText);
|
|
283
|
+
variable = {
|
|
284
|
+
kind: "var_decl",
|
|
285
|
+
sourceSpan: forOfSpan,
|
|
286
|
+
name: syntheticName,
|
|
287
|
+
storage: "const",
|
|
288
|
+
cppType: elementType,
|
|
289
|
+
initializer: undefined,
|
|
290
|
+
};
|
|
291
|
+
localVariableTypes.set(syntheticName, elementType);
|
|
292
|
+
// Build per-binding extraction statements.
|
|
293
|
+
destructureExtractions = buildDestructureExtractions(bindingPattern, syntheticName, elementType, forOfSpan, sourceText, diagnostics, functionReturnTypes, localVariableTypes);
|
|
294
|
+
}
|
|
295
|
+
else if (ts.isVariableDeclarationList(statement.initializer)) {
|
|
296
|
+
variable = forInitializerToIR(statement.initializer, fileName, sourceText, diagnostics, functionReturnTypes, localVariableTypes);
|
|
297
|
+
}
|
|
298
|
+
// Resolve the iterable's element type so the loop variable carries a real
|
|
299
|
+
// type (e.g. `Product*`) instead of `auto`. This must happen before
|
|
300
|
+
// lowerStatementList for the body, which binds localVariableTypes as the
|
|
301
|
+
// IrTypeScope's locals so member access (item->name) renders with `->`.
|
|
302
|
+
if (variable && variable.kind === "var_decl" && !isDestructureLoopVar) {
|
|
303
|
+
const iterableType = inferExprCppType(statement.expression, functionReturnTypes, localVariableTypes, sourceText);
|
|
304
|
+
if (iterableType && parsedIsVector(iterableType)) {
|
|
305
|
+
const elementType = parsedElementString(iterableType);
|
|
306
|
+
if (elementType && elementType !== "auto" && elementType !== "void") {
|
|
307
|
+
variable.cppType = elementType;
|
|
308
|
+
localVariableTypes.set(variable.name, elementType);
|
|
309
|
+
}
|
|
310
|
+
}
|
|
311
|
+
}
|
|
312
|
+
const bodyStatements = lowerStatementList(ts.isBlock(statement.statement) ? statement.statement.statements : [statement.statement], fileName, sourceText, diagnostics, functionReturnTypes, localVariableTypes, functionNameForDiagnostics, typeAliases, pointerVars);
|
|
313
|
+
return [{
|
|
314
|
+
kind: "for_of",
|
|
315
|
+
sourceSpan: makeSourceSpan(statement, fileName, sourceText),
|
|
316
|
+
leadingComments: comments.leadingComments,
|
|
317
|
+
trailingComments: comments.trailingComments,
|
|
318
|
+
variable: variable,
|
|
319
|
+
iterable: expressionToIR(statement.expression, sourceText, diagnostics, pointerVars),
|
|
320
|
+
body: [...destructureExtractions, ...bodyStatements],
|
|
321
|
+
}];
|
|
322
|
+
}
|
|
323
|
+
// Handle for...in loops (iterates over object keys)
|
|
324
|
+
if (ts.isForInStatement(statement)) {
|
|
325
|
+
const comments = extractNodeComments(statement, sourceText);
|
|
326
|
+
let variable;
|
|
327
|
+
if (ts.isVariableDeclarationList(statement.initializer)) {
|
|
328
|
+
variable = forInitializerToIR(statement.initializer, fileName, sourceText, diagnostics, functionReturnTypes, localVariableTypes);
|
|
329
|
+
}
|
|
330
|
+
const bodyStatements = lowerStatementList(ts.isBlock(statement.statement) ? statement.statement.statements : [statement.statement], fileName, sourceText, diagnostics, functionReturnTypes, localVariableTypes, functionNameForDiagnostics, typeAliases, pointerVars);
|
|
331
|
+
const keys = extractForInKeys(statement.expression);
|
|
332
|
+
return [{
|
|
333
|
+
kind: "for_in",
|
|
334
|
+
sourceSpan: makeSourceSpan(statement, fileName, sourceText),
|
|
335
|
+
leadingComments: comments.leadingComments,
|
|
336
|
+
trailingComments: comments.trailingComments,
|
|
337
|
+
variable: variable,
|
|
338
|
+
object: expressionToIR(statement.expression, sourceText, diagnostics, pointerVars),
|
|
339
|
+
keys,
|
|
340
|
+
body: bodyStatements,
|
|
341
|
+
}];
|
|
342
|
+
}
|
|
343
|
+
if (ts.isBreakStatement(statement)) {
|
|
344
|
+
const comments = extractNodeComments(statement, sourceText);
|
|
345
|
+
return [{
|
|
346
|
+
kind: "break",
|
|
347
|
+
sourceSpan: makeSourceSpan(statement, fileName, sourceText),
|
|
348
|
+
leadingComments: comments.leadingComments,
|
|
349
|
+
trailingComments: comments.trailingComments,
|
|
350
|
+
label: statement.label?.text,
|
|
351
|
+
}];
|
|
352
|
+
}
|
|
353
|
+
if (ts.isContinueStatement(statement)) {
|
|
354
|
+
const comments = extractNodeComments(statement, sourceText);
|
|
355
|
+
return [{
|
|
356
|
+
kind: "continue",
|
|
357
|
+
sourceSpan: makeSourceSpan(statement, fileName, sourceText),
|
|
358
|
+
leadingComments: comments.leadingComments,
|
|
359
|
+
trailingComments: comments.trailingComments,
|
|
360
|
+
label: statement.label?.text,
|
|
361
|
+
}];
|
|
362
|
+
}
|
|
363
|
+
// Handle do...while loops
|
|
364
|
+
if (ts.isDoStatement(statement)) {
|
|
365
|
+
const comments = extractNodeComments(statement, sourceText);
|
|
366
|
+
const bodyStatements = lowerStatementList(ts.isBlock(statement.statement) ? statement.statement.statements : [statement.statement], fileName, sourceText, diagnostics, functionReturnTypes, localVariableTypes, functionNameForDiagnostics, typeAliases, pointerVars);
|
|
367
|
+
return [{
|
|
368
|
+
kind: "do_while",
|
|
369
|
+
sourceSpan: makeSourceSpan(statement, fileName, sourceText),
|
|
370
|
+
leadingComments: comments.leadingComments,
|
|
371
|
+
trailingComments: comments.trailingComments,
|
|
372
|
+
condition: expressionToIR(statement.expression, sourceText, diagnostics, pointerVars),
|
|
373
|
+
body: bodyStatements,
|
|
374
|
+
}];
|
|
375
|
+
}
|
|
376
|
+
// Handle switch statements
|
|
377
|
+
if (ts.isSwitchStatement(statement)) {
|
|
378
|
+
const comments = extractNodeComments(statement, sourceText);
|
|
379
|
+
const cases = [];
|
|
380
|
+
for (const clause of statement.caseBlock.clauses) {
|
|
381
|
+
const caseComments = extractNodeComments(clause, sourceText);
|
|
382
|
+
if (ts.isDefaultClause(clause)) {
|
|
383
|
+
cases.push({
|
|
384
|
+
kind: "case",
|
|
385
|
+
sourceSpan: makeSourceSpan(clause, fileName, sourceText),
|
|
386
|
+
leadingComments: caseComments.leadingComments,
|
|
387
|
+
trailingComments: caseComments.trailingComments,
|
|
388
|
+
value: undefined, // default case has no value
|
|
389
|
+
body: lowerStatementList(clause.statements, fileName, sourceText, diagnostics, functionReturnTypes, localVariableTypes, functionNameForDiagnostics, typeAliases, pointerVars),
|
|
390
|
+
});
|
|
391
|
+
}
|
|
392
|
+
else if (ts.isCaseClause(clause)) {
|
|
393
|
+
cases.push({
|
|
394
|
+
kind: "case",
|
|
395
|
+
sourceSpan: makeSourceSpan(clause, fileName, sourceText),
|
|
396
|
+
leadingComments: caseComments.leadingComments,
|
|
397
|
+
trailingComments: caseComments.trailingComments,
|
|
398
|
+
value: expressionToIR(clause.expression, sourceText, diagnostics, pointerVars),
|
|
399
|
+
body: lowerStatementList(clause.statements, fileName, sourceText, diagnostics, functionReturnTypes, localVariableTypes, functionNameForDiagnostics, typeAliases, pointerVars),
|
|
400
|
+
});
|
|
401
|
+
}
|
|
402
|
+
}
|
|
403
|
+
return [{
|
|
404
|
+
kind: "switch",
|
|
405
|
+
sourceSpan: makeSourceSpan(statement, fileName, sourceText),
|
|
406
|
+
leadingComments: comments.leadingComments,
|
|
407
|
+
trailingComments: comments.trailingComments,
|
|
408
|
+
expression: expressionToIR(statement.expression, sourceText, diagnostics, pointerVars),
|
|
409
|
+
cases,
|
|
410
|
+
}];
|
|
411
|
+
}
|
|
412
|
+
// Handle try/catch/finally statements
|
|
413
|
+
if (ts.isTryStatement(statement)) {
|
|
414
|
+
const comments = extractNodeComments(statement, sourceText);
|
|
415
|
+
const tryBlock = lowerStatementList(statement.tryBlock.statements, fileName, sourceText, diagnostics, functionReturnTypes, localVariableTypes, functionNameForDiagnostics, typeAliases, pointerVars);
|
|
416
|
+
let catchParam;
|
|
417
|
+
let catchBlock;
|
|
418
|
+
if (statement.catchClause) {
|
|
419
|
+
if (statement.catchClause.variableDeclaration && ts.isIdentifier(statement.catchClause.variableDeclaration.name)) {
|
|
420
|
+
catchParam = statement.catchClause.variableDeclaration.name.text;
|
|
421
|
+
}
|
|
422
|
+
catchBlock = lowerStatementList(statement.catchClause.block.statements, fileName, sourceText, diagnostics, functionReturnTypes, localVariableTypes, functionNameForDiagnostics, typeAliases, pointerVars);
|
|
423
|
+
}
|
|
424
|
+
// Handle finally block
|
|
425
|
+
let finallyBlock;
|
|
426
|
+
if (statement.finallyBlock) {
|
|
427
|
+
finallyBlock = lowerStatementList(statement.finallyBlock.statements, fileName, sourceText, diagnostics, functionReturnTypes, localVariableTypes, functionNameForDiagnostics, typeAliases, pointerVars);
|
|
428
|
+
}
|
|
429
|
+
return [{
|
|
430
|
+
kind: "try",
|
|
431
|
+
sourceSpan: makeSourceSpan(statement, fileName, sourceText),
|
|
432
|
+
leadingComments: comments.leadingComments,
|
|
433
|
+
trailingComments: comments.trailingComments,
|
|
434
|
+
tryBlock,
|
|
435
|
+
catchParam,
|
|
436
|
+
catchBlock,
|
|
437
|
+
finallyBlock,
|
|
438
|
+
}];
|
|
439
|
+
}
|
|
440
|
+
// Handle throw statements
|
|
441
|
+
if (ts.isThrowStatement(statement)) {
|
|
442
|
+
const comments = extractNodeComments(statement, sourceText);
|
|
443
|
+
return [{
|
|
444
|
+
kind: "throw",
|
|
445
|
+
sourceSpan: makeSourceSpan(statement, fileName, sourceText),
|
|
446
|
+
leadingComments: comments.leadingComments,
|
|
447
|
+
trailingComments: comments.trailingComments,
|
|
448
|
+
value: expressionToIR(statement.expression, sourceText, diagnostics, pointerVars),
|
|
449
|
+
}];
|
|
450
|
+
}
|
|
451
|
+
// Handle empty statements (just semicolons) - skip them silently
|
|
452
|
+
if (ts.isEmptyStatement(statement)) {
|
|
453
|
+
return [];
|
|
454
|
+
}
|
|
455
|
+
// Handle labeled statements (e.g., label: for (...))
|
|
456
|
+
if (ts.isLabeledStatement(statement)) {
|
|
457
|
+
const comments = extractNodeComments(statement, sourceText);
|
|
458
|
+
const label = statement.label.text;
|
|
459
|
+
const bodyStatements = lowerStatementList(ts.isBlock(statement.statement) ? statement.statement.statements : [statement.statement], fileName, sourceText, diagnostics, functionReturnTypes, localVariableTypes, functionNameForDiagnostics, typeAliases, pointerVars);
|
|
460
|
+
return [{
|
|
461
|
+
kind: "labeled",
|
|
462
|
+
sourceSpan: makeSourceSpan(statement, fileName, sourceText),
|
|
463
|
+
leadingComments: comments.leadingComments,
|
|
464
|
+
trailingComments: comments.trailingComments,
|
|
465
|
+
label,
|
|
466
|
+
body: bodyStatements,
|
|
467
|
+
}];
|
|
468
|
+
}
|
|
469
|
+
// Handle standalone block statements
|
|
470
|
+
if (ts.isBlock(statement)) {
|
|
471
|
+
const comments = extractNodeComments(statement, sourceText);
|
|
472
|
+
const bodyStatements = lowerStatementList(statement.statements, fileName, sourceText, diagnostics, functionReturnTypes, localVariableTypes, functionNameForDiagnostics, typeAliases, pointerVars);
|
|
473
|
+
return [{
|
|
474
|
+
kind: "block",
|
|
475
|
+
sourceSpan: makeSourceSpan(statement, fileName, sourceText),
|
|
476
|
+
leadingComments: comments.leadingComments,
|
|
477
|
+
trailingComments: comments.trailingComments,
|
|
478
|
+
body: bodyStatements,
|
|
479
|
+
}];
|
|
480
|
+
}
|
|
481
|
+
// Local interface declarations are type-only; no runtime IR needed
|
|
482
|
+
if (ts.isInterfaceDeclaration(statement)) {
|
|
483
|
+
return [];
|
|
484
|
+
}
|
|
485
|
+
// Local type alias declarations are type-only; no runtime IR needed
|
|
486
|
+
if (ts.isTypeAliasDeclaration(statement)) {
|
|
487
|
+
return [];
|
|
488
|
+
}
|
|
489
|
+
if (ts.isDebuggerStatement(statement)) {
|
|
490
|
+
return [];
|
|
491
|
+
}
|
|
492
|
+
if (statement.kind === ts.SyntaxKind.YieldExpression || ts.isYieldExpression?.(statement)) {
|
|
493
|
+
const yieldExpr = statement;
|
|
494
|
+
const comments = extractNodeComments(statement, sourceText);
|
|
495
|
+
const value = yieldExpr.expression
|
|
496
|
+
? expressionToIR(yieldExpr.expression, sourceText, diagnostics, pointerVars)
|
|
497
|
+
: undefined;
|
|
498
|
+
return [{
|
|
499
|
+
kind: "yield",
|
|
500
|
+
sourceSpan: makeSourceSpan(statement, fileName, sourceText),
|
|
501
|
+
leadingComments: comments.leadingComments,
|
|
502
|
+
trailingComments: comments.trailingComments,
|
|
503
|
+
value,
|
|
504
|
+
isDelegate: !!yieldExpr.asteriskToken,
|
|
505
|
+
}];
|
|
506
|
+
}
|
|
507
|
+
return null;
|
|
508
|
+
}
|
|
@@ -0,0 +1,7 @@
|
|
|
1
|
+
import ts from "typescript";
|
|
2
|
+
import { Diagnostic } from "../../types.js";
|
|
3
|
+
import { StatementIR } from "../../api/index.js";
|
|
4
|
+
import { PointerTracker } from "../build-ir-state.js";
|
|
5
|
+
import { CppTypeHint } from "../type-resolution.js";
|
|
6
|
+
export { expressionToIR } from "../expression-to-ir.js";
|
|
7
|
+
export declare function expressionStatementToIR(statement: ts.ExpressionStatement, fileName: string, sourceText: string, diagnostics: Diagnostic[], functionReturnTypes: Map<string, CppTypeHint>, localVariableTypes: Map<string, CppTypeHint>, pointerVars?: PointerTracker): StatementIR | undefined;
|