c-next 0.1.62 → 0.1.63
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/README.md +86 -63
- package/package.json +1 -1
- package/src/transpiler/Transpiler.ts +3 -2
- package/src/transpiler/__tests__/DualCodePaths.test.ts +1 -1
- package/src/transpiler/__tests__/Transpiler.coverage.test.ts +1 -1
- package/src/transpiler/__tests__/Transpiler.test.ts +0 -23
- package/src/transpiler/logic/symbols/cnext/collectors/StructCollector.ts +156 -70
- package/src/transpiler/logic/symbols/cnext/collectors/VariableCollector.ts +31 -6
- package/src/transpiler/logic/symbols/cnext/utils/TypeUtils.ts +43 -11
- package/src/transpiler/output/codegen/CodeGenState.ts +811 -0
- package/src/transpiler/output/codegen/CodeGenerator.ts +817 -1377
- package/src/transpiler/output/codegen/TypeResolver.ts +193 -149
- package/src/transpiler/output/codegen/TypeValidator.ts +148 -370
- package/src/transpiler/output/codegen/__tests__/CodeGenState.test.ts +446 -0
- package/src/transpiler/output/codegen/__tests__/CodeGenerator.test.ts +326 -60
- package/src/transpiler/output/codegen/__tests__/TrackVariableTypeHelpers.test.ts +1 -1
- package/src/transpiler/output/codegen/__tests__/TypeResolver.test.ts +435 -196
- package/src/transpiler/output/codegen/__tests__/TypeValidator.resolution.test.ts +51 -67
- package/src/transpiler/output/codegen/__tests__/TypeValidator.test.ts +495 -471
- package/src/transpiler/output/codegen/analysis/MemberChainAnalyzer.ts +39 -43
- package/src/transpiler/output/codegen/analysis/StringLengthCounter.ts +52 -55
- package/src/transpiler/output/codegen/analysis/__tests__/MemberChainAnalyzer.test.ts +122 -62
- package/src/transpiler/output/codegen/analysis/__tests__/StringLengthCounter.test.ts +101 -144
- package/src/transpiler/output/codegen/assignment/AssignmentClassifier.ts +143 -126
- package/src/transpiler/output/codegen/assignment/__tests__/AssignmentClassifier.test.ts +287 -320
- package/src/transpiler/output/codegen/generators/GeneratorRegistry.ts +12 -0
- package/src/transpiler/output/codegen/generators/__tests__/GeneratorRegistry.test.ts +28 -1
- package/src/transpiler/output/codegen/generators/declarationGenerators/ArrayDimensionUtils.ts +67 -0
- package/src/transpiler/output/codegen/generators/declarationGenerators/ScopeGenerator.ts +121 -51
- package/src/transpiler/output/codegen/generators/declarationGenerators/StructGenerator.ts +100 -23
- package/src/transpiler/output/codegen/generators/declarationGenerators/__tests__/ArrayDimensionUtils.test.ts +125 -0
- package/src/transpiler/output/codegen/generators/declarationGenerators/__tests__/ScopeGenerator.test.ts +157 -4
- package/src/transpiler/output/codegen/generators/support/HelperGenerator.ts +23 -22
- package/src/transpiler/output/codegen/helpers/ArrayInitHelper.ts +54 -61
- package/src/transpiler/output/codegen/helpers/AssignmentExpectedTypeResolver.ts +21 -30
- package/src/transpiler/output/codegen/helpers/AssignmentValidator.ts +56 -53
- package/src/transpiler/output/codegen/helpers/CppModeHelper.ts +22 -30
- package/src/transpiler/output/codegen/helpers/EnumAssignmentValidator.ts +108 -50
- package/src/transpiler/output/codegen/helpers/FloatBitHelper.ts +16 -31
- package/src/transpiler/output/codegen/helpers/StringDeclHelper.ts +103 -96
- package/src/transpiler/output/codegen/helpers/TypeGenerationHelper.ts +9 -0
- package/src/transpiler/output/codegen/helpers/__tests__/ArrayInitHelper.test.ts +58 -103
- package/src/transpiler/output/codegen/helpers/__tests__/AssignmentExpectedTypeResolver.test.ts +97 -40
- package/src/transpiler/output/codegen/helpers/__tests__/AssignmentValidator.test.ts +223 -128
- package/src/transpiler/output/codegen/helpers/__tests__/CppModeHelper.test.ts +68 -41
- package/src/transpiler/output/codegen/helpers/__tests__/EnumAssignmentValidator.test.ts +198 -47
- package/src/transpiler/output/codegen/helpers/__tests__/FloatBitHelper.test.ts +39 -37
- package/src/transpiler/output/codegen/helpers/__tests__/StringDeclHelper.test.ts +191 -453
- package/src/transpiler/output/codegen/resolution/EnumTypeResolver.ts +229 -0
- package/src/transpiler/output/codegen/resolution/ScopeResolver.ts +60 -0
- package/src/transpiler/output/codegen/resolution/SizeofResolver.ts +177 -0
- package/src/transpiler/output/codegen/resolution/__tests__/EnumTypeResolver.test.ts +336 -0
- package/src/transpiler/output/codegen/resolution/__tests__/SizeofResolver.test.ts +201 -0
- package/src/transpiler/output/codegen/types/ITypeResolverDeps.ts +0 -23
- package/src/transpiler/output/codegen/types/ITypeValidatorDeps.ts +0 -53
|
@@ -2,50 +2,37 @@
|
|
|
2
2
|
* Unit tests for FloatBitHelper
|
|
3
3
|
*
|
|
4
4
|
* Issue #644: Tests for the extracted float bit write helper.
|
|
5
|
+
* Migrated to use CodeGenState instead of constructor DI.
|
|
5
6
|
*/
|
|
6
7
|
|
|
7
8
|
import { describe, it, expect, beforeEach, vi } from "vitest";
|
|
8
9
|
import FloatBitHelper from "../FloatBitHelper.js";
|
|
10
|
+
import CodeGenState from "../../CodeGenState.js";
|
|
9
11
|
import type TTypeInfo from "../../types/TTypeInfo.js";
|
|
10
12
|
import type TIncludeHeader from "../../generators/TIncludeHeader.js";
|
|
11
13
|
|
|
12
|
-
/**
|
|
13
|
-
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
}
|
|
17
|
-
|
|
18
|
-
/** Test-local copy of IFloatBitHelperDeps interface */
|
|
19
|
-
interface IFloatBitHelperDeps {
|
|
20
|
-
cppMode: boolean;
|
|
21
|
-
state: IFloatBitState;
|
|
14
|
+
/**
|
|
15
|
+
* Callback types for code generation operations.
|
|
16
|
+
*/
|
|
17
|
+
interface IFloatBitCallbacks {
|
|
22
18
|
generateBitMask: (width: string, is64Bit?: boolean) => string;
|
|
23
19
|
foldBooleanToInt: (expr: string) => string;
|
|
24
20
|
requireInclude: (header: TIncludeHeader) => void;
|
|
25
21
|
}
|
|
26
22
|
|
|
27
23
|
describe("FloatBitHelper", () => {
|
|
28
|
-
let
|
|
29
|
-
let deps: IFloatBitHelperDeps;
|
|
30
|
-
let helper: FloatBitHelper;
|
|
24
|
+
let callbacks: IFloatBitCallbacks;
|
|
31
25
|
|
|
32
26
|
beforeEach(() => {
|
|
33
|
-
|
|
34
|
-
floatBitShadows: new Set<string>(),
|
|
35
|
-
floatShadowCurrent: new Set<string>(),
|
|
36
|
-
};
|
|
27
|
+
CodeGenState.reset();
|
|
37
28
|
|
|
38
|
-
|
|
39
|
-
cppMode: false,
|
|
40
|
-
state,
|
|
29
|
+
callbacks = {
|
|
41
30
|
generateBitMask: vi.fn((width, _is64Bit) => `((1U << ${width}) - 1)`),
|
|
42
31
|
foldBooleanToInt: vi.fn((expr) =>
|
|
43
32
|
expr === "true" ? "1" : expr === "false" ? "0" : expr,
|
|
44
33
|
),
|
|
45
34
|
requireInclude: vi.fn(),
|
|
46
35
|
};
|
|
47
|
-
|
|
48
|
-
helper = new FloatBitHelper(deps);
|
|
49
36
|
});
|
|
50
37
|
|
|
51
38
|
describe("generateFloatBitWrite", () => {
|
|
@@ -57,16 +44,17 @@ describe("FloatBitHelper", () => {
|
|
|
57
44
|
isArray: false,
|
|
58
45
|
};
|
|
59
46
|
|
|
60
|
-
const result =
|
|
47
|
+
const result = FloatBitHelper.generateFloatBitWrite(
|
|
61
48
|
"myVar",
|
|
62
49
|
typeInfo,
|
|
63
50
|
"3",
|
|
64
51
|
null,
|
|
65
52
|
"true",
|
|
53
|
+
callbacks,
|
|
66
54
|
);
|
|
67
55
|
|
|
68
56
|
expect(result).toBeNull();
|
|
69
|
-
expect(
|
|
57
|
+
expect(callbacks.requireInclude).not.toHaveBeenCalled();
|
|
70
58
|
});
|
|
71
59
|
|
|
72
60
|
it("generates single bit write for f32", () => {
|
|
@@ -77,20 +65,23 @@ describe("FloatBitHelper", () => {
|
|
|
77
65
|
isArray: false,
|
|
78
66
|
};
|
|
79
67
|
|
|
80
|
-
const result =
|
|
68
|
+
const result = FloatBitHelper.generateFloatBitWrite(
|
|
81
69
|
"myFloat",
|
|
82
70
|
typeInfo,
|
|
83
71
|
"3",
|
|
84
72
|
null,
|
|
85
73
|
"true",
|
|
74
|
+
callbacks,
|
|
86
75
|
);
|
|
87
76
|
|
|
88
77
|
expect(result).toContain("uint32_t __bits_myFloat;");
|
|
89
78
|
expect(result).toContain("memcpy(&__bits_myFloat, &myFloat");
|
|
90
79
|
expect(result).toContain("& ~(1U << 3)");
|
|
91
80
|
expect(result).toContain("memcpy(&myFloat, &__bits_myFloat");
|
|
92
|
-
expect(
|
|
93
|
-
expect(
|
|
81
|
+
expect(callbacks.requireInclude).toHaveBeenCalledWith("string");
|
|
82
|
+
expect(callbacks.requireInclude).toHaveBeenCalledWith(
|
|
83
|
+
"float_static_assert",
|
|
84
|
+
);
|
|
94
85
|
});
|
|
95
86
|
|
|
96
87
|
it("generates single bit write for f64", () => {
|
|
@@ -101,12 +92,13 @@ describe("FloatBitHelper", () => {
|
|
|
101
92
|
isArray: false,
|
|
102
93
|
};
|
|
103
94
|
|
|
104
|
-
const result =
|
|
95
|
+
const result = FloatBitHelper.generateFloatBitWrite(
|
|
105
96
|
"myDouble",
|
|
106
97
|
typeInfo,
|
|
107
98
|
"5",
|
|
108
99
|
null,
|
|
109
100
|
"false",
|
|
101
|
+
callbacks,
|
|
110
102
|
);
|
|
111
103
|
|
|
112
104
|
expect(result).toContain("uint64_t __bits_myDouble;");
|
|
@@ -121,16 +113,17 @@ describe("FloatBitHelper", () => {
|
|
|
121
113
|
isArray: false,
|
|
122
114
|
};
|
|
123
115
|
|
|
124
|
-
const result =
|
|
116
|
+
const result = FloatBitHelper.generateFloatBitWrite(
|
|
125
117
|
"myFloat",
|
|
126
118
|
typeInfo,
|
|
127
119
|
"0",
|
|
128
120
|
"8",
|
|
129
121
|
"value",
|
|
122
|
+
callbacks,
|
|
130
123
|
);
|
|
131
124
|
|
|
132
125
|
expect(result).toContain("uint32_t __bits_myFloat;");
|
|
133
|
-
expect(
|
|
126
|
+
expect(callbacks.generateBitMask).toHaveBeenCalledWith("8", false);
|
|
134
127
|
});
|
|
135
128
|
|
|
136
129
|
it("skips declaration when shadow already exists", () => {
|
|
@@ -142,14 +135,15 @@ describe("FloatBitHelper", () => {
|
|
|
142
135
|
};
|
|
143
136
|
|
|
144
137
|
// Pre-declare the shadow
|
|
145
|
-
|
|
138
|
+
CodeGenState.floatBitShadows.add("__bits_myFloat");
|
|
146
139
|
|
|
147
|
-
const result =
|
|
140
|
+
const result = FloatBitHelper.generateFloatBitWrite(
|
|
148
141
|
"myFloat",
|
|
149
142
|
typeInfo,
|
|
150
143
|
"3",
|
|
151
144
|
null,
|
|
152
145
|
"true",
|
|
146
|
+
callbacks,
|
|
153
147
|
);
|
|
154
148
|
|
|
155
149
|
expect(result).not.toContain("uint32_t __bits_myFloat;");
|
|
@@ -165,15 +159,16 @@ describe("FloatBitHelper", () => {
|
|
|
165
159
|
};
|
|
166
160
|
|
|
167
161
|
// Pre-declare and mark as current
|
|
168
|
-
|
|
169
|
-
|
|
162
|
+
CodeGenState.floatBitShadows.add("__bits_myFloat");
|
|
163
|
+
CodeGenState.floatShadowCurrent.add("__bits_myFloat");
|
|
170
164
|
|
|
171
|
-
const result =
|
|
165
|
+
const result = FloatBitHelper.generateFloatBitWrite(
|
|
172
166
|
"myFloat",
|
|
173
167
|
typeInfo,
|
|
174
168
|
"3",
|
|
175
169
|
null,
|
|
176
170
|
"true",
|
|
171
|
+
callbacks,
|
|
177
172
|
);
|
|
178
173
|
|
|
179
174
|
expect(result).not.toContain("uint32_t __bits_myFloat;");
|
|
@@ -190,9 +185,16 @@ describe("FloatBitHelper", () => {
|
|
|
190
185
|
isArray: false,
|
|
191
186
|
};
|
|
192
187
|
|
|
193
|
-
|
|
188
|
+
FloatBitHelper.generateFloatBitWrite(
|
|
189
|
+
"myFloat",
|
|
190
|
+
typeInfo,
|
|
191
|
+
"3",
|
|
192
|
+
null,
|
|
193
|
+
"true",
|
|
194
|
+
callbacks,
|
|
195
|
+
);
|
|
194
196
|
|
|
195
|
-
expect(
|
|
197
|
+
expect(CodeGenState.floatShadowCurrent.has("__bits_myFloat")).toBe(true);
|
|
196
198
|
});
|
|
197
199
|
});
|
|
198
200
|
});
|