@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,162 @@
|
|
|
1
|
+
export function walkNestedStatements(stmt, visitor) {
|
|
2
|
+
if (!stmt || typeof stmt !== "object")
|
|
3
|
+
return;
|
|
4
|
+
if ("thenBranch" in stmt && Array.isArray(stmt.thenBranch)) {
|
|
5
|
+
for (const s of stmt.thenBranch)
|
|
6
|
+
visitor(s);
|
|
7
|
+
}
|
|
8
|
+
if ("elseBranch" in stmt && Array.isArray(stmt.elseBranch)) {
|
|
9
|
+
for (const s of stmt.elseBranch)
|
|
10
|
+
visitor(s);
|
|
11
|
+
}
|
|
12
|
+
if ("body" in stmt && Array.isArray(stmt.body)) {
|
|
13
|
+
for (const s of stmt.body)
|
|
14
|
+
visitor(s);
|
|
15
|
+
}
|
|
16
|
+
if ("initializer" in stmt && stmt.initializer && typeof stmt.initializer === "object" && "sourceSpan" in stmt.initializer)
|
|
17
|
+
visitor(stmt.initializer);
|
|
18
|
+
if ("increment" in stmt && stmt.increment && typeof stmt.increment === "object" && "sourceSpan" in stmt.increment)
|
|
19
|
+
visitor(stmt.increment);
|
|
20
|
+
if ("cases" in stmt && Array.isArray(stmt.cases)) {
|
|
21
|
+
for (const c of stmt.cases) {
|
|
22
|
+
if (c.body && Array.isArray(c.body)) {
|
|
23
|
+
for (const s of c.body)
|
|
24
|
+
visitor(s);
|
|
25
|
+
}
|
|
26
|
+
}
|
|
27
|
+
}
|
|
28
|
+
if ("tryBlock" in stmt && Array.isArray(stmt.tryBlock)) {
|
|
29
|
+
for (const s of stmt.tryBlock)
|
|
30
|
+
visitor(s);
|
|
31
|
+
}
|
|
32
|
+
if ("catchBlock" in stmt && Array.isArray(stmt.catchBlock)) {
|
|
33
|
+
for (const s of stmt.catchBlock)
|
|
34
|
+
visitor(s);
|
|
35
|
+
}
|
|
36
|
+
if ("finallyBlock" in stmt && Array.isArray(stmt.finallyBlock)) {
|
|
37
|
+
for (const s of stmt.finallyBlock)
|
|
38
|
+
visitor(s);
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
export function walkStatements(stmts, visitor) {
|
|
42
|
+
for (const stmt of stmts) {
|
|
43
|
+
visitor(stmt);
|
|
44
|
+
walkNestedStatements(stmt, (s) => walkStatements([s], visitor));
|
|
45
|
+
}
|
|
46
|
+
}
|
|
47
|
+
export function walkExpressionsInExpression(expr, visitor) {
|
|
48
|
+
if (!expr || typeof expr !== "object")
|
|
49
|
+
return;
|
|
50
|
+
visitor(expr);
|
|
51
|
+
if ("args" in expr && Array.isArray(expr.args)) {
|
|
52
|
+
for (const arg of expr.args)
|
|
53
|
+
walkExpressionsInExpression(arg, visitor);
|
|
54
|
+
}
|
|
55
|
+
if ("left" in expr)
|
|
56
|
+
walkExpressionsInExpression(expr.left, visitor);
|
|
57
|
+
if ("right" in expr)
|
|
58
|
+
walkExpressionsInExpression(expr.right, visitor);
|
|
59
|
+
if ("operand" in expr)
|
|
60
|
+
walkExpressionsInExpression(expr.operand, visitor);
|
|
61
|
+
if ("condition" in expr && typeof expr.condition === "object")
|
|
62
|
+
walkExpressionsInExpression(expr.condition, visitor);
|
|
63
|
+
if ("whenTrue" in expr)
|
|
64
|
+
walkExpressionsInExpression(expr.whenTrue, visitor);
|
|
65
|
+
if ("whenFalse" in expr)
|
|
66
|
+
walkExpressionsInExpression(expr.whenFalse, visitor);
|
|
67
|
+
if ("inner" in expr)
|
|
68
|
+
walkExpressionsInExpression(expr.inner, visitor);
|
|
69
|
+
if ("object" in expr && typeof expr.object === "object" && expr.kind !== "instanceof") {
|
|
70
|
+
walkExpressionsInExpression(expr.object, visitor);
|
|
71
|
+
}
|
|
72
|
+
if ("value" in expr && expr.value && typeof expr.value === "object" && "kind" in expr.value) {
|
|
73
|
+
walkExpressionsInExpression(expr.value, visitor);
|
|
74
|
+
}
|
|
75
|
+
if ("elements" in expr && Array.isArray(expr.elements)) {
|
|
76
|
+
for (const e of expr.elements)
|
|
77
|
+
walkExpressionsInExpression(e, visitor);
|
|
78
|
+
}
|
|
79
|
+
if ("fields" in expr && Array.isArray(expr.fields)) {
|
|
80
|
+
for (const f of expr.fields)
|
|
81
|
+
walkExpressionsInExpression(f.value, visitor);
|
|
82
|
+
}
|
|
83
|
+
if ("parts" in expr && Array.isArray(expr.parts)) {
|
|
84
|
+
for (const p of expr.parts)
|
|
85
|
+
walkExpressionsInExpression(p, visitor);
|
|
86
|
+
}
|
|
87
|
+
if ("expression" in expr && typeof expr.expression === "object" && "kind" in expr.expression) {
|
|
88
|
+
walkExpressionsInExpression(expr.expression, visitor);
|
|
89
|
+
}
|
|
90
|
+
if ("statements" in expr && Array.isArray(expr.statements)) {
|
|
91
|
+
for (const s of expr.statements) {
|
|
92
|
+
if ("value" in s && s.value && typeof s.value === "object")
|
|
93
|
+
walkExpressionsInExpression(s.value, visitor);
|
|
94
|
+
if ("args" in s && Array.isArray(s.args)) {
|
|
95
|
+
for (const a of s.args)
|
|
96
|
+
walkExpressionsInExpression(a, visitor);
|
|
97
|
+
}
|
|
98
|
+
if ("initializer" in s && s.initializer)
|
|
99
|
+
walkExpressionsInExpression(s.initializer, visitor);
|
|
100
|
+
if ("condition" in s && typeof s.condition === "object")
|
|
101
|
+
walkExpressionsInExpression(s.condition, visitor);
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
}
|
|
105
|
+
export function walkExpressions(stmts, visitor) {
|
|
106
|
+
for (const stmt of stmts) {
|
|
107
|
+
if ("value" in stmt && stmt.value && typeof stmt.value === "object") {
|
|
108
|
+
walkExpressionsInExpression(stmt.value, visitor);
|
|
109
|
+
}
|
|
110
|
+
if ("condition" in stmt && typeof stmt.condition === "object") {
|
|
111
|
+
walkExpressionsInExpression(stmt.condition, visitor);
|
|
112
|
+
}
|
|
113
|
+
if ("args" in stmt && Array.isArray(stmt.args)) {
|
|
114
|
+
for (const arg of stmt.args)
|
|
115
|
+
walkExpressionsInExpression(arg, visitor);
|
|
116
|
+
}
|
|
117
|
+
if ("initializer" in stmt && stmt.initializer) {
|
|
118
|
+
walkExpressionsInExpression(stmt.initializer, visitor);
|
|
119
|
+
}
|
|
120
|
+
if ("expression" in stmt && typeof stmt.expression === "object") {
|
|
121
|
+
walkExpressionsInExpression(stmt.expression, visitor);
|
|
122
|
+
}
|
|
123
|
+
walkNestedStatements(stmt, (s) => walkExpressions([s], visitor));
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
export function walkProgramIR(program, visitor) {
|
|
127
|
+
walkStatements(program.topLevelStatements, visitor);
|
|
128
|
+
for (const fn of program.functions) {
|
|
129
|
+
walkStatements(fn.statements, visitor);
|
|
130
|
+
}
|
|
131
|
+
for (const cls of program.classes) {
|
|
132
|
+
if (cls.constructor)
|
|
133
|
+
walkStatements(cls.constructor.statements, visitor);
|
|
134
|
+
for (const method of cls.methods)
|
|
135
|
+
walkStatements(method.statements, visitor);
|
|
136
|
+
for (const getter of cls.getters)
|
|
137
|
+
walkStatements(getter.statements, visitor);
|
|
138
|
+
for (const setter of cls.setters)
|
|
139
|
+
walkStatements(setter.statements, visitor);
|
|
140
|
+
}
|
|
141
|
+
for (const ns of program.namespaces) {
|
|
142
|
+
walkNamespaceStatements(ns, visitor);
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
function walkNamespaceStatements(ns, visitor) {
|
|
146
|
+
for (const fn of ns.functions)
|
|
147
|
+
walkStatements(fn.statements, visitor);
|
|
148
|
+
for (const cls of ns.classes) {
|
|
149
|
+
if (cls.constructor)
|
|
150
|
+
walkStatements(cls.constructor.statements, visitor);
|
|
151
|
+
for (const method of cls.methods)
|
|
152
|
+
walkStatements(method.statements, visitor);
|
|
153
|
+
for (const getter of cls.getters)
|
|
154
|
+
walkStatements(getter.statements, visitor);
|
|
155
|
+
for (const setter of cls.setters)
|
|
156
|
+
walkStatements(setter.statements, visitor);
|
|
157
|
+
}
|
|
158
|
+
if (ns.children) {
|
|
159
|
+
for (const child of ns.children)
|
|
160
|
+
walkNamespaceStatements(child, visitor);
|
|
161
|
+
}
|
|
162
|
+
}
|
|
@@ -0,0 +1,4 @@
|
|
|
1
|
+
import type { Diagnostic } from "../types.js";
|
|
2
|
+
import type { ProgramIR } from "../api/index.js";
|
|
3
|
+
import type { PlatformStrategy } from "../api/shared/index.js";
|
|
4
|
+
export declare function runProgramValidations(program: ProgramIR, strategy?: PlatformStrategy): Diagnostic[];
|
|
@@ -0,0 +1,45 @@
|
|
|
1
|
+
import { resolveStrategy } from "../platform/registry.js";
|
|
2
|
+
import { hasLoadedFramework, getLoadedFramework } from "../framework-registry.js";
|
|
3
|
+
import { analyzeInterruptSafety, inferVolatileForIsrSharedVars, detectReentrancyRisk } from "./interrupt-analysis.js";
|
|
4
|
+
import { validateADCRange } from "./adc-range-validation.js";
|
|
5
|
+
import { createEmptyPeripheralUsage } from "./peripheral-usage.js";
|
|
6
|
+
import { validatePeripherals } from "./peripheral-validation.js";
|
|
7
|
+
import { analyzeResources } from "./resource-analysis.js";
|
|
8
|
+
import { validatePeripheralOwnership } from "./peripheral-ownership.js";
|
|
9
|
+
import { validatePinAliasConflicts } from "./pin-alias-conflict.js";
|
|
10
|
+
import { validatePinModeConfig } from "./pin-mode-validation.js";
|
|
11
|
+
import { validateUnsafePins } from "./pin-safety.js";
|
|
12
|
+
import { validatePulldownSupport } from "./pulldown-validation.js";
|
|
13
|
+
import { validatePWMTimerSharing } from "./pwm-timer-sharing.js";
|
|
14
|
+
import { validateTimer0PWMTimingConflict } from "./timer0-pwm-timing-conflict.js";
|
|
15
|
+
import { validateTryCatch } from "./try-catch-validation.js";
|
|
16
|
+
import { validateMemoryBudget } from "./memory-budget-validation.js";
|
|
17
|
+
import { validateBlockingDelayInLoop } from "./timing-validation.js";
|
|
18
|
+
import { validateUnitSuspicion } from "./unit-suspicion-validation.js";
|
|
19
|
+
import { validateOwnership } from "./ownership-analysis.js";
|
|
20
|
+
import { validatePinCapabilities } from "./pin-capability-validation.js";
|
|
21
|
+
export function runProgramValidations(program, strategy) {
|
|
22
|
+
const resolvedStrategy = strategy ?? (hasLoadedFramework() ? getLoadedFramework().strategy : resolveStrategy('generic'));
|
|
23
|
+
const diagnostics = [];
|
|
24
|
+
const peripheralUsage = program.peripheralUsage ?? createEmptyPeripheralUsage();
|
|
25
|
+
diagnostics.push(...validatePinCapabilities(program));
|
|
26
|
+
diagnostics.push(...validatePeripherals(peripheralUsage, program.boardConstants));
|
|
27
|
+
diagnostics.push(...validateUnsafePins(peripheralUsage, program.boardConstants));
|
|
28
|
+
diagnostics.push(...analyzeResources(program, resolvedStrategy));
|
|
29
|
+
diagnostics.push(...validatePinAliasConflicts(peripheralUsage, program.boardConstants));
|
|
30
|
+
diagnostics.push(...validatePWMTimerSharing(peripheralUsage, program.boardConstants));
|
|
31
|
+
diagnostics.push(...validateTimer0PWMTimingConflict(peripheralUsage, program.boardConstants));
|
|
32
|
+
diagnostics.push(...validatePulldownSupport(peripheralUsage, program.boardConstants));
|
|
33
|
+
diagnostics.push(...analyzeInterruptSafety(program, peripheralUsage));
|
|
34
|
+
inferVolatileForIsrSharedVars(program, diagnostics);
|
|
35
|
+
detectReentrancyRisk(program, diagnostics);
|
|
36
|
+
diagnostics.push(...validateADCRange(program, program.boardConstants));
|
|
37
|
+
diagnostics.push(...validateUnitSuspicion(program));
|
|
38
|
+
diagnostics.push(...validatePinModeConfig(program));
|
|
39
|
+
diagnostics.push(...validatePeripheralOwnership(program));
|
|
40
|
+
diagnostics.push(...validateOwnership(program));
|
|
41
|
+
diagnostics.push(...validateTryCatch(program, program.boardConstants, resolvedStrategy));
|
|
42
|
+
diagnostics.push(...validateMemoryBudget(program, program.boardConstants));
|
|
43
|
+
diagnostics.push(...validateBlockingDelayInLoop(program));
|
|
44
|
+
return diagnostics;
|
|
45
|
+
}
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Resolves a base class name to the header file that declares it.
|
|
3
|
+
*
|
|
4
|
+
* Scoped to the set of .h files under a scan root — no parent-directory
|
|
5
|
+
* climbing. See
|
|
6
|
+
* docs/superpowers/specs/2026-06-20-gen-decls-inheritance-design.md.
|
|
7
|
+
*/
|
|
8
|
+
export type ResolveResult = {
|
|
9
|
+
kind: "found";
|
|
10
|
+
headerPath: string;
|
|
11
|
+
} | {
|
|
12
|
+
kind: "external";
|
|
13
|
+
};
|
|
14
|
+
export declare class BaseClassResolver {
|
|
15
|
+
private readonly index;
|
|
16
|
+
constructor(index: Map<string, string>);
|
|
17
|
+
resolve(name: string): ResolveResult;
|
|
18
|
+
}
|
|
19
|
+
/**
|
|
20
|
+
* Walks a directory tree for .h files and builds Map<className, headerPath>.
|
|
21
|
+
* First declaration wins (deterministic). Recursive.
|
|
22
|
+
*/
|
|
23
|
+
export declare function buildClassIndex(dir: string): Map<string, string>;
|
|
@@ -0,0 +1,50 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Resolves a base class name to the header file that declares it.
|
|
3
|
+
*
|
|
4
|
+
* Scoped to the set of .h files under a scan root — no parent-directory
|
|
5
|
+
* climbing. See
|
|
6
|
+
* docs/superpowers/specs/2026-06-20-gen-decls-inheritance-design.md.
|
|
7
|
+
*/
|
|
8
|
+
import fs from "node:fs";
|
|
9
|
+
import path from "node:path";
|
|
10
|
+
import { parseHeader } from "./header-parser.js";
|
|
11
|
+
export class BaseClassResolver {
|
|
12
|
+
constructor(index) {
|
|
13
|
+
this.index = index;
|
|
14
|
+
}
|
|
15
|
+
resolve(name) {
|
|
16
|
+
const headerPath = this.index.get(name);
|
|
17
|
+
if (headerPath !== undefined) {
|
|
18
|
+
return { kind: "found", headerPath };
|
|
19
|
+
}
|
|
20
|
+
return { kind: "external" };
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
/**
|
|
24
|
+
* Walks a directory tree for .h files and builds Map<className, headerPath>.
|
|
25
|
+
* First declaration wins (deterministic). Recursive.
|
|
26
|
+
*/
|
|
27
|
+
export function buildClassIndex(dir) {
|
|
28
|
+
const index = new Map();
|
|
29
|
+
if (!fs.existsSync(dir)) {
|
|
30
|
+
return index;
|
|
31
|
+
}
|
|
32
|
+
const entries = fs.readdirSync(dir, { withFileTypes: true });
|
|
33
|
+
for (const entry of entries) {
|
|
34
|
+
const full = path.join(dir, entry.name);
|
|
35
|
+
if (entry.isDirectory()) {
|
|
36
|
+
for (const [name, hp] of buildClassIndex(full)) {
|
|
37
|
+
if (!index.has(name))
|
|
38
|
+
index.set(name, hp);
|
|
39
|
+
}
|
|
40
|
+
}
|
|
41
|
+
else if (entry.isFile() && entry.name.toLowerCase().endsWith(".h")) {
|
|
42
|
+
const content = fs.readFileSync(full, "utf8");
|
|
43
|
+
for (const cls of parseHeader(content)) {
|
|
44
|
+
if (!index.has(cls.name))
|
|
45
|
+
index.set(cls.name, full);
|
|
46
|
+
}
|
|
47
|
+
}
|
|
48
|
+
}
|
|
49
|
+
return index;
|
|
50
|
+
}
|
|
@@ -0,0 +1,34 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* C++ to TypeScript Declaration Generator
|
|
3
|
+
*
|
|
4
|
+
* Parses simple C++ class definitions and generates .d.ts declaration files
|
|
5
|
+
* for use with TypeCAD's native module support.
|
|
6
|
+
*/
|
|
7
|
+
/**
|
|
8
|
+
* Backward-compat wrapper — delegates to generateDecl so legacy callers
|
|
9
|
+
* (e.g. cli.ts) keep resolving while the richer .h/.cpp merge lives in
|
|
10
|
+
* generateDecl.
|
|
11
|
+
*/
|
|
12
|
+
export declare function generateDeclFromCpp(cppFilePath: string, outputPath?: string): string | null;
|
|
13
|
+
/**
|
|
14
|
+
* Scans a directory for .h and .cpp files and generates .d.ts files.
|
|
15
|
+
*
|
|
16
|
+
* Two passes:
|
|
17
|
+
* 1. Build a class-name → header-path index from all .h under dir.
|
|
18
|
+
* 2. For each .h (and .cpp with no sibling .h), parse + merge + emit with
|
|
19
|
+
* cross-file base resolution.
|
|
20
|
+
*/
|
|
21
|
+
export declare function generateDeclsForDirectory(dir: string, recursive?: boolean): string[];
|
|
22
|
+
/**
|
|
23
|
+
* Generates a .d.ts from a .h OR .cpp file.
|
|
24
|
+
*
|
|
25
|
+
* - For .h: parses the header; if a sibling .cpp exists, merges its
|
|
26
|
+
* impl-only methods (ClassName::method) into the header's classes.
|
|
27
|
+
* - For .cpp: if a sibling .h exists, parses the header and merges; else
|
|
28
|
+
* behaves as the legacy flattened path.
|
|
29
|
+
*
|
|
30
|
+
* Does NOT resolve cross-file base classes — bases from other headers are
|
|
31
|
+
* left as bare `extends Foo` (no import). Cross-file resolution is added in
|
|
32
|
+
* a later step for the directory-scan path.
|
|
33
|
+
*/
|
|
34
|
+
export declare function generateDecl(filePath: string, outputPath?: string): string | null;
|