@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,251 @@
|
|
|
1
|
+
import { emitCommentLines, isRuntimeExpression } from "../utils/index.js";
|
|
2
|
+
import { appendSourceLine, appendHeaderLine, appendRenderedStatement } from "./line-appender.js";
|
|
3
|
+
import { escapeCppKeyword } from "../../utils/strings.js";
|
|
4
|
+
import { isStringEnum } from "../../api/shared/index.js";
|
|
5
|
+
import { resolveEnumValues, narrowestEnumUnderlying } from "../utils/cpp-helpers.js";
|
|
6
|
+
export function emitTypeDeclarations(ctx) {
|
|
7
|
+
const { program, strategy, effectiveEmitMode, reservedNames, emittedTopLevelStatements, topLevelScope } = ctx;
|
|
8
|
+
const normalizeCppTypeForTarget = (cppType) => strategy.normalizeCppType(cppType);
|
|
9
|
+
// Split-mode header include + forward declarations
|
|
10
|
+
if (effectiveEmitMode === "split") {
|
|
11
|
+
appendSourceLine(ctx, `#include \"${ctx.baseName}.h\"`);
|
|
12
|
+
}
|
|
13
|
+
if (effectiveEmitMode === "split" && program.classes.length > 0) {
|
|
14
|
+
for (const classDef of program.classes) {
|
|
15
|
+
if (classDef.typeParameters && classDef.typeParameters.length > 0) {
|
|
16
|
+
const templateParams = classDef.typeParameters.map((p) => `typename ${p}`).join(", ");
|
|
17
|
+
appendHeaderLine(ctx, `template<${templateParams}> class ${classDef.name};`);
|
|
18
|
+
}
|
|
19
|
+
else {
|
|
20
|
+
appendHeaderLine(ctx, `class ${classDef.name};`);
|
|
21
|
+
}
|
|
22
|
+
}
|
|
23
|
+
appendHeaderLine(ctx, "");
|
|
24
|
+
}
|
|
25
|
+
if (effectiveEmitMode !== "split" && program.classes.length > 0) {
|
|
26
|
+
for (const classDef of program.classes) {
|
|
27
|
+
if (classDef.typeParameters && classDef.typeParameters.length > 0) {
|
|
28
|
+
const templateParams = classDef.typeParameters.map((p) => `typename ${p}`).join(", ");
|
|
29
|
+
appendSourceLine(ctx, `template<${templateParams}> class ${classDef.name};`);
|
|
30
|
+
}
|
|
31
|
+
else {
|
|
32
|
+
appendSourceLine(ctx, `class ${classDef.name};`);
|
|
33
|
+
}
|
|
34
|
+
}
|
|
35
|
+
appendSourceLine(ctx, "");
|
|
36
|
+
}
|
|
37
|
+
// Emit register-mapped structs
|
|
38
|
+
for (const reg of program.registerClasses ?? []) {
|
|
39
|
+
const addrHex = '0x' + reg.address.toString(16).toUpperCase().replace(/^0X/, '');
|
|
40
|
+
emitCommentLines(reg.leadingComments, "", (line) => appendSourceLine(ctx, line));
|
|
41
|
+
appendSourceLine(ctx, `volatile uint32_t* const ${reg.name} = reinterpret_cast<volatile uint32_t*>(${addrHex});`);
|
|
42
|
+
emitCommentLines(reg.trailingComments, "", (line) => appendSourceLine(ctx, line));
|
|
43
|
+
}
|
|
44
|
+
if ((program.registerClasses?.length ?? 0) > 0) {
|
|
45
|
+
appendSourceLine(ctx, "");
|
|
46
|
+
}
|
|
47
|
+
// Emit enums
|
|
48
|
+
const apiReservedEnums = strategy.apiReservedEnumNames();
|
|
49
|
+
for (const enumDef of program.enums) {
|
|
50
|
+
const appendLine = effectiveEmitMode === "split" ? appendHeaderLine : appendSourceLine;
|
|
51
|
+
emitCommentLines(enumDef.leadingComments, "", (line) => appendLine(ctx, line));
|
|
52
|
+
// String enums are lowered to a namespace of `constexpr const char*`
|
|
53
|
+
// constants so member access yields a `const char*`. This makes `===`
|
|
54
|
+
// comparisons against string literals and string concatenation behave
|
|
55
|
+
// like TypeScript (see isStringEnum). Mixed enums fall through to the
|
|
56
|
+
// numeric `enum class` path below.
|
|
57
|
+
if (isStringEnum(enumDef)) {
|
|
58
|
+
appendLine(ctx, `namespace ${enumDef.name} {`);
|
|
59
|
+
for (const member of enumDef.members) {
|
|
60
|
+
const memberName = ctx.reservedNames.has(member.name)
|
|
61
|
+
? `_${member.name}`
|
|
62
|
+
: member.name;
|
|
63
|
+
const renamed = strategy.renameEnumMember(enumDef.name, memberName);
|
|
64
|
+
// value is a string (guaranteed by isStringEnum); escape for C++ literal
|
|
65
|
+
const escaped = String(member.value).replace(/\\/g, "\\\\").replace(/"/g, '\\"');
|
|
66
|
+
appendLine(ctx, ` constexpr const char* ${renamed} = "${escaped}";`);
|
|
67
|
+
}
|
|
68
|
+
appendLine(ctx, "}");
|
|
69
|
+
emitCommentLines(enumDef.trailingComments, "", (line) => appendLine(ctx, line));
|
|
70
|
+
appendLine(ctx, "");
|
|
71
|
+
continue;
|
|
72
|
+
}
|
|
73
|
+
const enumKeyword = "enum class";
|
|
74
|
+
const underlyingType = narrowestEnumUnderlying(resolveEnumValues(enumDef.members), strategy.needsLargeEnumUnderlying());
|
|
75
|
+
const guard = apiReservedEnums.has(enumDef.name) ? strategy.enumApiGuard(enumDef.name) : undefined;
|
|
76
|
+
if (guard) {
|
|
77
|
+
appendLine(ctx, guard.open);
|
|
78
|
+
}
|
|
79
|
+
appendLine(ctx, `${enumKeyword} ${enumDef.name}${underlyingType} {`);
|
|
80
|
+
let autoValue = 0;
|
|
81
|
+
for (let i = 0; i < enumDef.members.length; i++) {
|
|
82
|
+
const member = enumDef.members[i];
|
|
83
|
+
let valueSuffix;
|
|
84
|
+
if (typeof member.value === "number") {
|
|
85
|
+
valueSuffix = ` = ${member.value}`;
|
|
86
|
+
autoValue = member.value + 1;
|
|
87
|
+
}
|
|
88
|
+
else if (typeof member.value === "string") {
|
|
89
|
+
valueSuffix = ` = ${autoValue}`;
|
|
90
|
+
autoValue++;
|
|
91
|
+
}
|
|
92
|
+
else {
|
|
93
|
+
valueSuffix = "";
|
|
94
|
+
autoValue++;
|
|
95
|
+
}
|
|
96
|
+
const commaSuffix = i < enumDef.members.length - 1 ? "," : "";
|
|
97
|
+
const memberName = ctx.reservedNames.has(member.name)
|
|
98
|
+
? `_${member.name}`
|
|
99
|
+
: member.name;
|
|
100
|
+
appendLine(ctx, ` ${memberName}${valueSuffix}${commaSuffix}`);
|
|
101
|
+
}
|
|
102
|
+
appendLine(ctx, "};");
|
|
103
|
+
if (guard) {
|
|
104
|
+
appendLine(ctx, guard.close);
|
|
105
|
+
}
|
|
106
|
+
emitCommentLines(enumDef.trailingComments, "", (line) => appendLine(ctx, line));
|
|
107
|
+
appendLine(ctx, "");
|
|
108
|
+
}
|
|
109
|
+
// Emit interfaces as C++ structs BEFORE type aliases — an alias may
|
|
110
|
+
// reference an interface (`using EntryPatch = Entry;`), so the struct must
|
|
111
|
+
// be declared first (demo #10 fix A: alias-to-user-type ordering).
|
|
112
|
+
for (const iface of program.interfaces) {
|
|
113
|
+
const appendLine = effectiveEmitMode === "split" ? appendHeaderLine : appendSourceLine;
|
|
114
|
+
emitCommentLines(iface.leadingComments, "", (line) => appendLine(ctx, line));
|
|
115
|
+
if (iface.fields.length > 0 || iface.indexSignature) {
|
|
116
|
+
if (iface.parentScope) {
|
|
117
|
+
appendLine(ctx, `namespace ${iface.parentScope} {`);
|
|
118
|
+
ctx.interfaceNamespaceMap.set(iface.name, iface.parentScope);
|
|
119
|
+
}
|
|
120
|
+
const typeParams = new Set();
|
|
121
|
+
for (const field of iface.fields) {
|
|
122
|
+
if (/^[A-Z]$/.test(field.cppType)) {
|
|
123
|
+
typeParams.add(field.cppType);
|
|
124
|
+
}
|
|
125
|
+
}
|
|
126
|
+
if (typeParams.size > 0) {
|
|
127
|
+
appendLine(ctx, `template<typename ${Array.from(typeParams).join(", typename ")}>`);
|
|
128
|
+
}
|
|
129
|
+
appendLine(ctx, `struct ${iface.name} {`);
|
|
130
|
+
for (const field of iface.fields) {
|
|
131
|
+
const fieldType = normalizeCppTypeForTarget(field.cppType);
|
|
132
|
+
// Escape the field name with the SAME function class-field declarations
|
|
133
|
+
// and field accesses use (escapeCppKeyword over reservedNames), so an
|
|
134
|
+
// interface/struct field named like an Arduino macro (`min`/`max`) is
|
|
135
|
+
// declared `min_`/`max_` to MATCH the renamed accesses (`s.min_`).
|
|
136
|
+
// Previously interface fields used the bare name while declarations
|
|
137
|
+
// (escapeCppKeyword → suffix `_`) and accesses (escapeFinalMemberName)
|
|
138
|
+
// disagreed, so `struct Stats { int32_t min; }` was accessed as
|
|
139
|
+
// `s.min_` → g++ "has no member named 'min_'". Demo #33 Finding D.
|
|
140
|
+
const safeFieldName = escapeCppKeyword(field.name, reservedNames);
|
|
141
|
+
appendLine(ctx, ` ${fieldType} ${safeFieldName};`);
|
|
142
|
+
}
|
|
143
|
+
if (iface.indexSignature) {
|
|
144
|
+
const keyType = normalizeCppTypeForTarget(iface.indexSignature.keyType);
|
|
145
|
+
const valueType = normalizeCppTypeForTarget(iface.indexSignature.valueType);
|
|
146
|
+
appendLine(ctx, ` std::map<${keyType}, ${valueType}> data;`);
|
|
147
|
+
}
|
|
148
|
+
appendLine(ctx, "};");
|
|
149
|
+
if (iface.parentScope) {
|
|
150
|
+
appendLine(ctx, "}");
|
|
151
|
+
}
|
|
152
|
+
}
|
|
153
|
+
emitCommentLines(iface.trailingComments, "", (line) => appendLine(ctx, line));
|
|
154
|
+
appendLine(ctx, "");
|
|
155
|
+
}
|
|
156
|
+
// Emit type aliases (after interfaces, so alias-to-struct refs resolve).
|
|
157
|
+
for (const typeAlias of program.typeAliases) {
|
|
158
|
+
const appendLine = effectiveEmitMode === "split" ? appendHeaderLine : appendSourceLine;
|
|
159
|
+
emitCommentLines(typeAlias.leadingComments, "", (line) => appendLine(ctx, line));
|
|
160
|
+
if (typeAlias.variantStructs && typeAlias.variantStructs.length > 0) {
|
|
161
|
+
for (const variant of typeAlias.variantStructs) {
|
|
162
|
+
appendLine(ctx, `struct ${variant.name} {`);
|
|
163
|
+
for (const field of variant.fields) {
|
|
164
|
+
const fieldType = normalizeCppTypeForTarget(field.cppType);
|
|
165
|
+
appendLine(ctx, ` ${fieldType} ${field.name};`);
|
|
166
|
+
}
|
|
167
|
+
appendLine(ctx, "};");
|
|
168
|
+
}
|
|
169
|
+
appendLine(ctx, `using ${typeAlias.name} = ${normalizeCppTypeForTarget(typeAlias.cppType)};`);
|
|
170
|
+
emitCommentLines(typeAlias.trailingComments, "", (line) => appendLine(ctx, line));
|
|
171
|
+
appendLine(ctx, "");
|
|
172
|
+
continue;
|
|
173
|
+
}
|
|
174
|
+
if (typeAlias.structFields && typeAlias.structFields.length > 0) {
|
|
175
|
+
if (typeAlias.typeParameters && typeAlias.typeParameters.length > 0) {
|
|
176
|
+
appendLine(ctx, `template<typename ${typeAlias.typeParameters.join(", typename ")}>`);
|
|
177
|
+
}
|
|
178
|
+
appendLine(ctx, `struct ${typeAlias.name} {`);
|
|
179
|
+
for (const field of typeAlias.structFields) {
|
|
180
|
+
const fieldType = normalizeCppTypeForTarget(field.cppType);
|
|
181
|
+
appendLine(ctx, ` ${fieldType} ${field.name};`);
|
|
182
|
+
}
|
|
183
|
+
appendLine(ctx, "};");
|
|
184
|
+
emitCommentLines(typeAlias.trailingComments, "", (line) => appendLine(ctx, line));
|
|
185
|
+
appendLine(ctx, "");
|
|
186
|
+
continue;
|
|
187
|
+
}
|
|
188
|
+
const cppType = normalizeCppTypeForTarget(typeAlias.cppType);
|
|
189
|
+
if (cppType === "auto")
|
|
190
|
+
continue;
|
|
191
|
+
if (strategy.shouldSkipTypeAlias(cppType))
|
|
192
|
+
continue;
|
|
193
|
+
appendLine(ctx, `using ${typeAlias.name} = ${cppType};`);
|
|
194
|
+
emitCommentLines(typeAlias.trailingComments, "", (line) => appendLine(ctx, line));
|
|
195
|
+
appendLine(ctx, "");
|
|
196
|
+
}
|
|
197
|
+
// Emit top-level constant declarations BEFORE classes
|
|
198
|
+
for (const statement of emittedTopLevelStatements) {
|
|
199
|
+
if (statement.kind === "var_decl" && statement.initializer && isRuntimeExpression(statement.initializer)) {
|
|
200
|
+
continue;
|
|
201
|
+
}
|
|
202
|
+
appendRenderedStatement(ctx, statement, "", topLevelScope);
|
|
203
|
+
}
|
|
204
|
+
if (emittedTopLevelStatements.some(s => s.kind === "var_decl" &&
|
|
205
|
+
!(s.initializer && isRuntimeExpression(s.initializer)))) {
|
|
206
|
+
appendSourceLine(ctx, "");
|
|
207
|
+
}
|
|
208
|
+
// In split mode, emit extern declarations for exported top-level variables
|
|
209
|
+
if (effectiveEmitMode === "split") {
|
|
210
|
+
const platformReservedNames = strategy.reservedNames();
|
|
211
|
+
const crossModuleVarTypes = ctx.options.crossModuleVariableTypes;
|
|
212
|
+
let emitted = false;
|
|
213
|
+
for (const statement of emittedTopLevelStatements) {
|
|
214
|
+
if (statement.kind !== "var_decl")
|
|
215
|
+
continue;
|
|
216
|
+
if (statement.initializer && isRuntimeExpression(statement.initializer))
|
|
217
|
+
continue;
|
|
218
|
+
let cppType = strategy.normalizeCppType(statement.cppType);
|
|
219
|
+
if (cppType === "auto" && crossModuleVarTypes) {
|
|
220
|
+
const resolved = crossModuleVarTypes.get(statement.name);
|
|
221
|
+
if (resolved)
|
|
222
|
+
cppType = strategy.normalizeCppType(resolved);
|
|
223
|
+
}
|
|
224
|
+
const isConst = statement.storage === "const";
|
|
225
|
+
const constPrefix = isConst ? "const " : "";
|
|
226
|
+
const varName = escapeCppKeyword(statement.name, platformReservedNames);
|
|
227
|
+
// Array-typed top-level consts (e.g. `export const ARR: T[] = [...]`)
|
|
228
|
+
// lower with cppType "auto" and a `{ kind: "array", elementType }`
|
|
229
|
+
// initializer. They emit as C-style arrays (`T name[] = {...}`), so the
|
|
230
|
+
// matching extern is `extern const T name[];` — not a scalar extern and
|
|
231
|
+
// not a std::vector extern. Without this, cross-file consumers fail with
|
|
232
|
+
// "was not declared in this scope" (the definition lives in the .cpp
|
|
233
|
+
// only). Mirror renderVarDecl's element-type fallback for "auto".
|
|
234
|
+
if (cppType === "auto" && statement.initializer && statement.initializer.kind === "array") {
|
|
235
|
+
const elemType = statement.initializer.elementType && statement.initializer.elementType !== "auto"
|
|
236
|
+
? strategy.normalizeCppType(statement.initializer.elementType)
|
|
237
|
+
: strategy.defaultNumericType();
|
|
238
|
+
appendHeaderLine(ctx, `extern ${constPrefix}${elemType} ${varName}[];`);
|
|
239
|
+
emitted = true;
|
|
240
|
+
continue;
|
|
241
|
+
}
|
|
242
|
+
if (cppType === "auto")
|
|
243
|
+
continue;
|
|
244
|
+
appendHeaderLine(ctx, `extern ${constPrefix}${cppType} ${varName};`);
|
|
245
|
+
emitted = true;
|
|
246
|
+
}
|
|
247
|
+
if (emitted) {
|
|
248
|
+
appendHeaderLine(ctx, "");
|
|
249
|
+
}
|
|
250
|
+
}
|
|
251
|
+
}
|
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import type { EmitterContext } from "./emitter-context.js";
|
|
2
|
+
export interface TouchPollInput {
|
|
3
|
+
library?: string;
|
|
4
|
+
minPressure: number;
|
|
5
|
+
calibration: {
|
|
6
|
+
xMin: number;
|
|
7
|
+
xMax: number;
|
|
8
|
+
yMin: number;
|
|
9
|
+
yMax: number;
|
|
10
|
+
};
|
|
11
|
+
profile: {
|
|
12
|
+
width: number;
|
|
13
|
+
height: number;
|
|
14
|
+
nativeWidth?: number;
|
|
15
|
+
nativeHeight?: number;
|
|
16
|
+
rotation: number;
|
|
17
|
+
};
|
|
18
|
+
}
|
|
19
|
+
/** Generate the ui_poll_touch() body, or null for the no-touch path. */
|
|
20
|
+
export declare function generateTouchPollBody(input: TouchPollInput): string | null;
|
|
21
|
+
export declare function emitUIRuntime(ctx: EmitterContext): void;
|