@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,155 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Include resolution utilities for C++ code emission.
|
|
3
|
+
* Handles import resolution, SDK detection, and header normalization.
|
|
4
|
+
* Extracted from cpp-emitter.ts
|
|
5
|
+
*/
|
|
6
|
+
import path from "node:path";
|
|
7
|
+
import fs from "node:fs";
|
|
8
|
+
/**
|
|
9
|
+
* Checks if a module specifier resolves to a TypeCAD SDK path.
|
|
10
|
+
* Cuttlefish SDK files (code/core/*, code/board-*, @typecad/* packages) are
|
|
11
|
+
* type-level only and should produce no C++ output or #include directives.
|
|
12
|
+
*
|
|
13
|
+
* @param moduleSpecifier The import specifier (e.g., "@typecad/hal" or "./pins")
|
|
14
|
+
* @param fromFile The file path from which the import originates
|
|
15
|
+
* @returns true if this is a TypeCAD SDK import
|
|
16
|
+
*/
|
|
17
|
+
export function isCuttlefishSDKImport(moduleSpecifier, fromFile) {
|
|
18
|
+
// All @typecad/* package imports — including the `@typecad/hal` virtual
|
|
19
|
+
// import, which resolves to the board package — are type-level only and must
|
|
20
|
+
// not emit a C++ #include. Compare case-insensitively so the documented
|
|
21
|
+
// mixed-case form is treated identically.
|
|
22
|
+
const spec = moduleSpecifier.toLowerCase();
|
|
23
|
+
if (spec.startsWith("@typecad/")) {
|
|
24
|
+
return true;
|
|
25
|
+
}
|
|
26
|
+
// Check for relative imports to code/core or code/board-* paths
|
|
27
|
+
if (!moduleSpecifier.startsWith(".")) {
|
|
28
|
+
return false;
|
|
29
|
+
}
|
|
30
|
+
const basePath = path.resolve(path.dirname(fromFile), moduleSpecifier);
|
|
31
|
+
const candidates = [
|
|
32
|
+
basePath,
|
|
33
|
+
`${basePath}.ts`,
|
|
34
|
+
`${basePath}.tsx`,
|
|
35
|
+
path.join(basePath, "index.ts"),
|
|
36
|
+
path.join(basePath, "index.tsx"),
|
|
37
|
+
];
|
|
38
|
+
for (const candidate of candidates) {
|
|
39
|
+
if (fs.existsSync(candidate)) {
|
|
40
|
+
const normalized = candidate.replace(/\\/g, "/");
|
|
41
|
+
if (/\/code\/core\//.test(normalized) || /\/code\/board-/.test(normalized)) {
|
|
42
|
+
return true;
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
}
|
|
46
|
+
return false;
|
|
47
|
+
}
|
|
48
|
+
/**
|
|
49
|
+
* Normalizes an include path to proper C++ include format.
|
|
50
|
+
*
|
|
51
|
+
* @param include The include path (e.g., "Arduino.h" or "<vector>")
|
|
52
|
+
* @returns Properly formatted include (e.g., "<Arduino.h>" or "<vector>")
|
|
53
|
+
*/
|
|
54
|
+
export function normalizeInclude(include) {
|
|
55
|
+
if (include.startsWith("<") || include.startsWith("\"")) {
|
|
56
|
+
return include;
|
|
57
|
+
}
|
|
58
|
+
return `<${include}>`;
|
|
59
|
+
}
|
|
60
|
+
/**
|
|
61
|
+
* Deduplicates an array while preserving order.
|
|
62
|
+
*
|
|
63
|
+
* @param items The array to deduplicate
|
|
64
|
+
* @returns A new array with duplicates removed
|
|
65
|
+
*/
|
|
66
|
+
export function dedupe(items) {
|
|
67
|
+
return [...new Set(items)];
|
|
68
|
+
}
|
|
69
|
+
/**
|
|
70
|
+
* Resolves an import to a local header file if it's from a transpiled npm package.
|
|
71
|
+
*
|
|
72
|
+
* @param moduleSpecifier The import specifier
|
|
73
|
+
* @param npmPackages Map of source paths to npm package info
|
|
74
|
+
* @param fromFilePath The file path from which the import originates
|
|
75
|
+
* @returns Information about the resolved include
|
|
76
|
+
*/
|
|
77
|
+
export function resolveTranspiledModuleInclude(moduleSpecifier, npmPackages, fromFilePath) {
|
|
78
|
+
if (!npmPackages || npmPackages.size === 0) {
|
|
79
|
+
return { include: "", isTranspiled: false };
|
|
80
|
+
}
|
|
81
|
+
if (moduleSpecifier.startsWith(".")) {
|
|
82
|
+
const normalizedSpecifier = moduleSpecifier.endsWith(".js")
|
|
83
|
+
? `${moduleSpecifier.slice(0, -3)}.ts`
|
|
84
|
+
: moduleSpecifier.endsWith(".mjs")
|
|
85
|
+
? `${moduleSpecifier.slice(0, -4)}.ts`
|
|
86
|
+
: moduleSpecifier;
|
|
87
|
+
const basePath = path.resolve(path.dirname(fromFilePath), normalizedSpecifier);
|
|
88
|
+
const candidates = [
|
|
89
|
+
basePath,
|
|
90
|
+
`${basePath}.ts`,
|
|
91
|
+
`${basePath}.tsx`,
|
|
92
|
+
path.join(basePath, "index.ts"),
|
|
93
|
+
path.join(basePath, "index.tsx"),
|
|
94
|
+
].map((candidate) => path.resolve(candidate));
|
|
95
|
+
for (const candidate of candidates) {
|
|
96
|
+
const pkg = npmPackages.get(candidate);
|
|
97
|
+
if (!pkg) {
|
|
98
|
+
continue;
|
|
99
|
+
}
|
|
100
|
+
const currentPkg = npmPackages.get(path.resolve(fromFilePath));
|
|
101
|
+
let headerName = `${pkg.moduleKey}.h`;
|
|
102
|
+
if (currentPkg) {
|
|
103
|
+
const currentDir = path.posix.dirname(currentPkg.moduleKey.replace(/\\/g, "/"));
|
|
104
|
+
const targetPath = `${pkg.moduleKey.replace(/\\/g, "/")}.h`;
|
|
105
|
+
let relativeHeader = path.posix.relative(currentDir, targetPath);
|
|
106
|
+
if (!relativeHeader.startsWith(".")) {
|
|
107
|
+
relativeHeader = `./${relativeHeader}`;
|
|
108
|
+
}
|
|
109
|
+
headerName = relativeHeader;
|
|
110
|
+
}
|
|
111
|
+
return { include: `"${headerName}"`, isTranspiled: true };
|
|
112
|
+
}
|
|
113
|
+
return { include: "", isTranspiled: false };
|
|
114
|
+
}
|
|
115
|
+
// Parse the module specifier to get package name and subpath
|
|
116
|
+
const parts = moduleSpecifier.split("/");
|
|
117
|
+
let packageName;
|
|
118
|
+
let subpath;
|
|
119
|
+
if (moduleSpecifier.startsWith("@")) {
|
|
120
|
+
packageName = parts.length > 1 ? `${parts[0]}/${parts[1]}` : parts[0];
|
|
121
|
+
subpath = parts.length > 2 ? parts.slice(2).join("/") : "";
|
|
122
|
+
}
|
|
123
|
+
else {
|
|
124
|
+
packageName = parts[0];
|
|
125
|
+
subpath = parts.length > 1 ? parts.slice(1).join("/") : "";
|
|
126
|
+
}
|
|
127
|
+
// Look for a matching npm package in our transpiled modules
|
|
128
|
+
// The npmPackages map is keyed by source path, so we need to iterate
|
|
129
|
+
for (const [sourcePath, pkg] of npmPackages) {
|
|
130
|
+
// Match by package name (e.g., "@typecad/hal" or "cuttlefish-implementation")
|
|
131
|
+
if (pkg.packageName === packageName) {
|
|
132
|
+
// Use the moduleKey from the package info, which is already computed
|
|
133
|
+
const headerName = `${pkg.moduleKey}.h`;
|
|
134
|
+
return { include: `"${headerName}"`, isTranspiled: true };
|
|
135
|
+
}
|
|
136
|
+
}
|
|
137
|
+
return { include: "", isTranspiled: false };
|
|
138
|
+
}
|
|
139
|
+
/**
|
|
140
|
+
* Applies a symbol map to a callee string.
|
|
141
|
+
* Transforms root identifiers according to the mapping.
|
|
142
|
+
*
|
|
143
|
+
* @param callee The original callee (e.g., "console.log" or "myFunc")
|
|
144
|
+
* @param symbolMap Map of original names to transformed names
|
|
145
|
+
* @returns The transformed callee
|
|
146
|
+
*/
|
|
147
|
+
export function applySymbolMap(callee, symbolMap) {
|
|
148
|
+
const firstDot = callee.indexOf(".");
|
|
149
|
+
if (firstDot === -1) {
|
|
150
|
+
return symbolMap[callee] ?? callee;
|
|
151
|
+
}
|
|
152
|
+
const root = callee.slice(0, firstDot);
|
|
153
|
+
const rest = callee.slice(firstDot);
|
|
154
|
+
return `${symbolMap[root] ?? root}${rest}`;
|
|
155
|
+
}
|
|
@@ -0,0 +1,8 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Emitter utilities barrel export.
|
|
3
|
+
* Re-exports all utility functions for C++ code emission.
|
|
4
|
+
*/
|
|
5
|
+
export { inferObjectFieldType, collectNestedStructDefs, hasArrayInObjectLiteral, hasThrowStatements, hasStdMathCalls, hasConsoleCalls, isConsoleCall, getConsoleMethod, isRuntimeExpression, statementRequiresRuntime, collectPointerVarTypes, collectExpressionIdentifiers, } from "./type-inference.js";
|
|
6
|
+
export { toPascalCaseLocal, generateAsyncTaskClass, type AsyncTaskClassResult, } from "./async-state-machine.js";
|
|
7
|
+
export { isCuttlefishSDKImport, normalizeInclude, dedupe, resolveTranspiledModuleInclude, applySymbolMap, } from "./include-resolver.js";
|
|
8
|
+
export { normalizeComment, emitCommentLines, } from "./comment-helpers.js";
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Emitter utilities barrel export.
|
|
3
|
+
* Re-exports all utility functions for C++ code emission.
|
|
4
|
+
*/
|
|
5
|
+
// Type inference utilities
|
|
6
|
+
export { inferObjectFieldType, collectNestedStructDefs, hasArrayInObjectLiteral, hasThrowStatements, hasStdMathCalls, hasConsoleCalls, isConsoleCall, getConsoleMethod, isRuntimeExpression, statementRequiresRuntime, collectPointerVarTypes, collectExpressionIdentifiers, } from "./type-inference.js";
|
|
7
|
+
// Async state machine utilities
|
|
8
|
+
export { toPascalCaseLocal, generateAsyncTaskClass, } from "./async-state-machine.js";
|
|
9
|
+
// Include resolution utilities
|
|
10
|
+
export { isCuttlefishSDKImport, normalizeInclude, dedupe, resolveTranspiledModuleInclude, applySymbolMap, } from "./include-resolver.js";
|
|
11
|
+
// Comment handling utilities
|
|
12
|
+
export { normalizeComment, emitCommentLines, } from "./comment-helpers.js";
|
|
@@ -0,0 +1,159 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Type inference utilities for C++ code emission.
|
|
3
|
+
* Pure functions with no side effects - extracted from cpp-emitter.ts
|
|
4
|
+
*/
|
|
5
|
+
import type { ExpressionIR, StatementIR, PlatformStrategy } from "../../api/index.js";
|
|
6
|
+
/**
|
|
7
|
+
* Infers the C++ type for an object field based on its initializer value.
|
|
8
|
+
*
|
|
9
|
+
* @param value The expression to infer type for
|
|
10
|
+
* @param pointerVarTypes Map of variable names to their pointer types (e.g., "sensor" -> "Sensor*")
|
|
11
|
+
* @param knownFunctionReturnTypes Map of function names to their return types
|
|
12
|
+
* @param knownObjectTypes Map of object names to their types
|
|
13
|
+
* @param knownObjectFieldTypes Map of object names to their field type maps
|
|
14
|
+
* @param largeEnumNames Set of enum names with values outside 16-bit int range
|
|
15
|
+
* @param resolvePinType Optional callback to resolve pin types from the platform strategy
|
|
16
|
+
* @returns The inferred C++ type string
|
|
17
|
+
*/
|
|
18
|
+
export declare function inferObjectFieldType(value: ExpressionIR, pointerVarTypes?: Map<string, string>, knownFunctionReturnTypes?: Map<string, string>, knownObjectTypes?: Map<string, string>, knownObjectFieldTypes?: Map<string, Map<string, string>>, largeEnumNames?: Set<string>, parentName?: string, fieldName?: string, defaultIntType?: string, resolvePinType?: (objectName: string, fieldName: string) => string | undefined): string;
|
|
19
|
+
/**
|
|
20
|
+
* Recursively collects nested struct definitions from an object ExpressionIR.
|
|
21
|
+
* Returns an array of struct definitions ordered from deepest to shallowest,
|
|
22
|
+
* so that inner structs are defined before outer structs that reference them.
|
|
23
|
+
*
|
|
24
|
+
* @param objExpr The object ExpressionIR to scan for nested objects
|
|
25
|
+
* @param parentName The variable/struct name prefix for generating struct type names
|
|
26
|
+
* @param pointerVarTypes Optional pointer variable type map
|
|
27
|
+
* @param knownFunctionReturnTypes Optional function return type map
|
|
28
|
+
* @param knownObjectTypes Optional object type map
|
|
29
|
+
* @param knownObjectFieldTypes Optional object field type map
|
|
30
|
+
* @param largeEnumNames Optional large enum names set
|
|
31
|
+
*/
|
|
32
|
+
export declare function collectNestedStructDefs(objExpr: Extract<ExpressionIR, {
|
|
33
|
+
kind: "object";
|
|
34
|
+
}>, parentName: string, pointerVarTypes?: Map<string, string>, knownFunctionReturnTypes?: Map<string, string>, knownObjectTypes?: Map<string, string>, knownObjectFieldTypes?: Map<string, Map<string, string>>, largeEnumNames?: Set<string>): {
|
|
35
|
+
structName: string;
|
|
36
|
+
fields: {
|
|
37
|
+
type: string;
|
|
38
|
+
name: string;
|
|
39
|
+
}[];
|
|
40
|
+
}[];
|
|
41
|
+
/**
|
|
42
|
+
* Checks if a program contains array literals inside object literals.
|
|
43
|
+
* This affects whether std::vector needs to be included.
|
|
44
|
+
*
|
|
45
|
+
* @param program The program IR to analyze
|
|
46
|
+
* @returns true if arrays in object literals are found
|
|
47
|
+
*/
|
|
48
|
+
export declare function hasArrayInObjectLiteral(program: {
|
|
49
|
+
topLevelStatements: StatementIR[];
|
|
50
|
+
functions: Array<{
|
|
51
|
+
statements: StatementIR[];
|
|
52
|
+
}>;
|
|
53
|
+
classes: Array<{
|
|
54
|
+
fields: Array<{
|
|
55
|
+
initializer?: ExpressionIR;
|
|
56
|
+
}>;
|
|
57
|
+
methods: Array<{
|
|
58
|
+
statements: StatementIR[];
|
|
59
|
+
}>;
|
|
60
|
+
constructor?: {
|
|
61
|
+
statements: StatementIR[];
|
|
62
|
+
};
|
|
63
|
+
}>;
|
|
64
|
+
}): boolean;
|
|
65
|
+
/**
|
|
66
|
+
* Checks if a program contains throw statements.
|
|
67
|
+
* This affects whether <stdexcept> needs to be included.
|
|
68
|
+
*
|
|
69
|
+
* @param program The program IR to analyze
|
|
70
|
+
* @returns true if throw statements are found
|
|
71
|
+
*/
|
|
72
|
+
export declare function hasThrowStatements(program: {
|
|
73
|
+
topLevelStatements: StatementIR[];
|
|
74
|
+
functions: Array<{
|
|
75
|
+
statements: StatementIR[];
|
|
76
|
+
}>;
|
|
77
|
+
classes: Array<{
|
|
78
|
+
methods: Array<{
|
|
79
|
+
statements: StatementIR[];
|
|
80
|
+
}>;
|
|
81
|
+
constructor?: {
|
|
82
|
+
statements: StatementIR[];
|
|
83
|
+
};
|
|
84
|
+
}>;
|
|
85
|
+
}): boolean;
|
|
86
|
+
/**
|
|
87
|
+
* Checks if a program contains std::math function calls.
|
|
88
|
+
* This affects whether <cmath> or <math.h> needs to be included.
|
|
89
|
+
*
|
|
90
|
+
* @param program The program IR to analyze
|
|
91
|
+
* @returns true if math calls are found
|
|
92
|
+
*/
|
|
93
|
+
export declare function hasStdMathCalls(program: {
|
|
94
|
+
topLevelStatements: StatementIR[];
|
|
95
|
+
functions: Array<{
|
|
96
|
+
statements: StatementIR[];
|
|
97
|
+
}>;
|
|
98
|
+
classes: Array<{
|
|
99
|
+
methods: Array<{
|
|
100
|
+
statements: StatementIR[];
|
|
101
|
+
}>;
|
|
102
|
+
constructor?: {
|
|
103
|
+
statements: StatementIR[];
|
|
104
|
+
};
|
|
105
|
+
}>;
|
|
106
|
+
}): boolean;
|
|
107
|
+
/**
|
|
108
|
+
* Checks if a program contains console.* calls (console.log, console.error, etc.)
|
|
109
|
+
*
|
|
110
|
+
* @param program The program IR to analyze
|
|
111
|
+
* @returns true if console calls are found
|
|
112
|
+
*/
|
|
113
|
+
export declare function hasConsoleCalls(program: {
|
|
114
|
+
topLevelStatements: StatementIR[];
|
|
115
|
+
functions: Array<{
|
|
116
|
+
statements: StatementIR[];
|
|
117
|
+
}>;
|
|
118
|
+
classes: Array<{
|
|
119
|
+
methods: Array<{
|
|
120
|
+
statements: StatementIR[];
|
|
121
|
+
}>;
|
|
122
|
+
constructor?: {
|
|
123
|
+
statements: StatementIR[];
|
|
124
|
+
};
|
|
125
|
+
}>;
|
|
126
|
+
}, strategy?: PlatformStrategy): boolean;
|
|
127
|
+
/**
|
|
128
|
+
* Checks if a callee is a console method call (e.g., "console.log", "console.error")
|
|
129
|
+
*/
|
|
130
|
+
export declare function isConsoleCall(callee: string, strategy?: PlatformStrategy): boolean;
|
|
131
|
+
/**
|
|
132
|
+
* Gets the console method name from a callee (e.g., "log" from "console.log")
|
|
133
|
+
*/
|
|
134
|
+
export declare function getConsoleMethod(callee: string): string;
|
|
135
|
+
/**
|
|
136
|
+
* Checks if an expression requires runtime execution (cannot be evaluated at global scope in C++).
|
|
137
|
+
* Compile-time expressions can be placed at global scope; runtime expressions must go in setup()/main().
|
|
138
|
+
*
|
|
139
|
+
* @param expr The expression to check
|
|
140
|
+
* @returns true if the expression requires runtime execution
|
|
141
|
+
*/
|
|
142
|
+
export declare function collectExpressionIdentifiers(expr: ExpressionIR): Set<string>;
|
|
143
|
+
export declare function isRuntimeExpression(expr: ExpressionIR): boolean;
|
|
144
|
+
/**
|
|
145
|
+
* Checks if a statement requires runtime execution.
|
|
146
|
+
*
|
|
147
|
+
* @param statement The statement to check
|
|
148
|
+
* @returns true if the statement requires runtime execution
|
|
149
|
+
*/
|
|
150
|
+
export declare function statementRequiresRuntime(statement: StatementIR): boolean;
|
|
151
|
+
/**
|
|
152
|
+
* Collects pointer variable types from program statements.
|
|
153
|
+
* Variables initialized with 'new ClassName()' get type 'ClassName*'.
|
|
154
|
+
*
|
|
155
|
+
* @param statements The statements to analyze
|
|
156
|
+
* @param classNameMap Optional map for transforming simple class names to fully qualified names
|
|
157
|
+
* @returns Map of variable names to their pointer types
|
|
158
|
+
*/
|
|
159
|
+
export declare function collectPointerVarTypes(statements: StatementIR[], classNameMap?: Map<string, string>): Map<string, string>;
|