c-next 0.1.70 → 0.1.72

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.
Files changed (205) hide show
  1. package/package.json +1 -1
  2. package/src/lib/__tests__/parseCHeader.mocked.test.ts +69 -54
  3. package/src/lib/parseCHeader.ts +56 -23
  4. package/src/lib/parseWithSymbols.ts +195 -53
  5. package/src/transpiler/Transpiler.ts +180 -63
  6. package/src/transpiler/logic/analysis/FunctionCallAnalyzer.ts +1 -2
  7. package/src/transpiler/logic/analysis/InitializationAnalyzer.ts +1 -2
  8. package/src/transpiler/logic/analysis/PassByValueAnalyzer.ts +51 -2
  9. package/src/transpiler/logic/analysis/__tests__/FunctionCallAnalyzer.test.ts +18 -12
  10. package/src/transpiler/logic/analysis/__tests__/InitializationAnalyzer.test.ts +9 -9
  11. package/src/transpiler/logic/analysis/__tests__/runAnalyzers.test.ts +5 -5
  12. package/src/transpiler/logic/symbols/SymbolTable.ts +729 -265
  13. package/src/transpiler/logic/symbols/SymbolUtils.ts +2 -2
  14. package/src/transpiler/logic/symbols/__tests__/SymbolTable.test.ts +415 -751
  15. package/src/transpiler/logic/symbols/c/__tests__/CResolver.integration.test.ts +573 -0
  16. package/src/transpiler/logic/symbols/c/__tests__/testHelpers.ts +20 -0
  17. package/src/transpiler/logic/symbols/c/collectors/EnumCollector.ts +82 -0
  18. package/src/transpiler/logic/symbols/c/collectors/FunctionCollector.ts +106 -0
  19. package/src/transpiler/logic/symbols/c/collectors/StructCollector.ts +173 -0
  20. package/src/transpiler/logic/symbols/c/collectors/TypedefCollector.ts +35 -0
  21. package/src/transpiler/logic/symbols/c/collectors/VariableCollector.ts +80 -0
  22. package/src/transpiler/logic/symbols/c/index.ts +333 -0
  23. package/src/transpiler/logic/symbols/c/utils/DeclaratorUtils.ts +269 -0
  24. package/src/transpiler/logic/symbols/cnext/__tests__/BitmapCollector.test.ts +50 -11
  25. package/src/transpiler/logic/symbols/cnext/__tests__/CNextResolver.integration.test.ts +45 -34
  26. package/src/transpiler/logic/symbols/cnext/__tests__/EnumCollector.test.ts +30 -13
  27. package/src/transpiler/logic/symbols/cnext/__tests__/FunctionCollector.test.ts +279 -64
  28. package/src/transpiler/logic/symbols/cnext/__tests__/RegisterCollector.test.ts +60 -13
  29. package/src/transpiler/logic/symbols/cnext/__tests__/ScopeCollector.test.ts +40 -37
  30. package/src/transpiler/logic/symbols/cnext/__tests__/StructCollector.test.ts +131 -45
  31. package/src/transpiler/logic/symbols/cnext/__tests__/TSymbolInfoAdapter.test.ts +223 -139
  32. package/src/transpiler/logic/symbols/cnext/__tests__/VariableCollector.test.ts +79 -25
  33. package/src/transpiler/logic/symbols/cnext/__tests__/testUtils.ts +53 -0
  34. package/src/transpiler/logic/symbols/cnext/adapters/TSymbolInfoAdapter.ts +83 -43
  35. package/src/transpiler/logic/symbols/cnext/collectors/BitmapCollector.ts +14 -13
  36. package/src/transpiler/logic/symbols/cnext/collectors/EnumCollector.ts +11 -10
  37. package/src/transpiler/logic/symbols/cnext/collectors/FunctionCollector.ts +83 -34
  38. package/src/transpiler/logic/symbols/cnext/collectors/RegisterCollector.ts +22 -18
  39. package/src/transpiler/logic/symbols/cnext/collectors/ScopeCollector.ts +53 -35
  40. package/src/transpiler/logic/symbols/cnext/collectors/StructCollector.ts +30 -23
  41. package/src/transpiler/logic/symbols/cnext/collectors/VariableCollector.ts +18 -19
  42. package/src/transpiler/logic/symbols/cnext/index.ts +36 -14
  43. package/src/transpiler/logic/symbols/cnext/types/IScopeCollectorResult.ts +2 -2
  44. package/src/transpiler/logic/symbols/cnext/utils/SymbolNameUtils.ts +27 -0
  45. package/src/transpiler/logic/symbols/cpp/__tests__/CppResolver.integration.test.ts +270 -0
  46. package/src/transpiler/logic/symbols/cpp/__tests__/testHelpers.ts +20 -0
  47. package/src/transpiler/logic/symbols/cpp/collectors/ClassCollector.ts +317 -0
  48. package/src/transpiler/logic/symbols/cpp/collectors/EnumCollector.ts +71 -0
  49. package/src/transpiler/logic/symbols/cpp/collectors/FunctionCollector.ts +155 -0
  50. package/src/transpiler/logic/symbols/cpp/collectors/NamespaceCollector.ts +65 -0
  51. package/src/transpiler/logic/symbols/cpp/collectors/TypeAliasCollector.ts +46 -0
  52. package/src/transpiler/logic/symbols/cpp/collectors/VariableCollector.ts +54 -0
  53. package/src/transpiler/logic/symbols/cpp/index.ts +366 -0
  54. package/src/transpiler/logic/symbols/cpp/utils/DeclaratorUtils.ts +248 -0
  55. package/src/transpiler/logic/symbols/shared/IExtractedParameter.ts +18 -0
  56. package/src/transpiler/logic/symbols/shared/ParameterExtractorUtils.ts +73 -0
  57. package/src/transpiler/output/codegen/CodeGenerator.ts +268 -1674
  58. package/src/transpiler/output/codegen/__tests__/CodeGenerator.test.ts +7 -1
  59. package/src/transpiler/output/codegen/assignment/AssignmentClassifier.ts +2 -1
  60. package/src/transpiler/output/codegen/assignment/handlers/AssignmentHandlerUtils.ts +7 -1
  61. package/src/transpiler/output/codegen/assignment/handlers/BitmapHandlers.ts +6 -2
  62. package/src/transpiler/output/codegen/assignment/handlers/RegisterHandlers.ts +2 -1
  63. package/src/transpiler/output/codegen/generators/declarationGenerators/ScopeGenerator.ts +21 -8
  64. package/src/transpiler/output/codegen/generators/declarationGenerators/ScopedRegisterGenerator.ts +3 -2
  65. package/src/transpiler/output/codegen/generators/expressions/CallExprUtils.ts +9 -3
  66. package/src/transpiler/output/codegen/generators/expressions/__tests__/CallExprGenerator.test.ts +3 -4
  67. package/src/transpiler/output/codegen/generators/expressions/__tests__/CallExprUtils.test.ts +4 -8
  68. package/src/transpiler/output/codegen/helpers/ArgumentGenerator.ts +236 -0
  69. package/src/transpiler/output/codegen/helpers/CppConstructorHelper.ts +3 -3
  70. package/src/transpiler/output/codegen/helpers/FunctionContextManager.ts +435 -0
  71. package/src/transpiler/output/codegen/helpers/StringOperationsHelper.ts +203 -0
  72. package/src/transpiler/output/codegen/helpers/SymbolLookupHelper.ts +8 -12
  73. package/src/transpiler/output/codegen/helpers/TypeRegistrationEngine.ts +520 -0
  74. package/src/transpiler/output/codegen/helpers/VariableDeclHelper.ts +735 -0
  75. package/src/transpiler/output/codegen/helpers/VariableDeclarationFormatter.ts +1 -1
  76. package/src/transpiler/output/codegen/helpers/__tests__/ArgumentGenerator.test.ts +521 -0
  77. package/src/transpiler/output/codegen/helpers/__tests__/CppConstructorHelper.test.ts +4 -5
  78. package/src/transpiler/output/codegen/helpers/__tests__/FunctionContextManager.test.ts +983 -0
  79. package/src/transpiler/output/codegen/helpers/__tests__/StringOperationsHelper.test.ts +269 -0
  80. package/src/transpiler/output/codegen/helpers/__tests__/SymbolLookupHelper.test.ts +31 -32
  81. package/src/transpiler/output/codegen/helpers/__tests__/TypeRegistrationEngine.test.ts +186 -0
  82. package/src/transpiler/output/codegen/helpers/__tests__/VariableDeclHelper.test.ts +460 -0
  83. package/src/transpiler/output/codegen/helpers/types/IArgumentGeneratorCallbacks.ts +32 -0
  84. package/src/transpiler/output/codegen/resolution/EnumTypeResolver.ts +5 -1
  85. package/src/transpiler/output/codegen/types/IFunctionContextCallbacks.ts +12 -0
  86. package/src/transpiler/output/codegen/types/IVariableFormatInput.ts +1 -1
  87. package/src/transpiler/output/codegen/utils/QualifiedNameGenerator.ts +114 -0
  88. package/src/transpiler/output/codegen/utils/__tests__/QualifiedNameGenerator.test.ts +183 -0
  89. package/src/transpiler/output/headers/BaseHeaderGenerator.ts +4 -4
  90. package/src/transpiler/output/headers/ExternalTypeHeaderBuilder.ts +7 -7
  91. package/src/transpiler/output/headers/HeaderGenerator.ts +9 -7
  92. package/src/transpiler/output/headers/HeaderGeneratorUtils.ts +19 -20
  93. package/src/transpiler/output/headers/__tests__/BaseHeaderGenerator.test.ts +15 -18
  94. package/src/transpiler/output/headers/__tests__/CHeaderGenerator.test.ts +63 -64
  95. package/src/transpiler/output/headers/__tests__/CppHeaderGenerator.test.ts +36 -32
  96. package/src/transpiler/output/headers/__tests__/ExternalTypeHeaderBuilder.test.ts +26 -26
  97. package/src/transpiler/output/headers/__tests__/HeaderGenerator.test.ts +87 -59
  98. package/src/transpiler/output/headers/__tests__/HeaderGeneratorUtils.test.ts +57 -58
  99. package/src/transpiler/output/headers/adapters/HeaderSymbolAdapter.ts +222 -0
  100. package/src/transpiler/output/headers/adapters/__tests__/HeaderSymbolAdapter.test.ts +538 -0
  101. package/src/transpiler/output/headers/types/IGroupedSymbols.ts +8 -8
  102. package/src/transpiler/output/headers/types/IHeaderSymbol.ts +62 -0
  103. package/src/transpiler/state/CodeGenState.ts +20 -33
  104. package/src/transpiler/state/SymbolRegistry.ts +181 -0
  105. package/src/transpiler/{types → state}/TranspilerState.ts +1 -1
  106. package/src/transpiler/state/__tests__/CodeGenState.test.ts +67 -59
  107. package/src/transpiler/state/__tests__/SymbolRegistry.test.ts +249 -0
  108. package/src/transpiler/{types → state}/__tests__/TranspilerState.test.ts +1 -1
  109. package/src/transpiler/types/ICachedFileEntry.ts +1 -1
  110. package/src/transpiler/types/IConflict.ts +14 -0
  111. package/src/transpiler/types/IPipelineInput.ts +0 -3
  112. package/src/transpiler/types/ISerializedSymbol.ts +11 -0
  113. package/src/transpiler/types/TPrimitiveKind.ts +20 -0
  114. package/src/transpiler/types/TType.ts +103 -0
  115. package/src/transpiler/types/TVisibility.ts +6 -0
  116. package/src/transpiler/types/symbol-kinds/TSymbolKind.ts +10 -0
  117. package/src/transpiler/types/symbol-kinds/TSymbolKindC.ts +12 -0
  118. package/src/transpiler/types/symbol-kinds/TSymbolKindCNext.ts +16 -0
  119. package/src/transpiler/types/symbol-kinds/TSymbolKindCpp.ts +14 -0
  120. package/src/transpiler/types/symbols/IBaseSymbol.ts +31 -0
  121. package/src/transpiler/{logic/symbols/types → types/symbols}/IBitmapFieldInfo.ts +2 -2
  122. package/src/transpiler/types/symbols/IBitmapSymbol.ts +21 -0
  123. package/src/transpiler/{logic/symbols/types → types/symbols}/IEnumSymbol.ts +5 -6
  124. package/src/transpiler/types/symbols/IFieldInfo.ts +26 -0
  125. package/src/transpiler/types/symbols/IFunctionSymbol.ts +30 -0
  126. package/src/transpiler/types/symbols/IParameterInfo.ts +26 -0
  127. package/src/transpiler/{logic/symbols/types → types/symbols}/IRegisterMemberInfo.ts +4 -4
  128. package/src/transpiler/types/symbols/IRegisterSymbol.ts +18 -0
  129. package/src/transpiler/types/symbols/IScopeSymbol.ts +32 -0
  130. package/src/transpiler/{logic/symbols/types → types/symbols}/IStructFieldInfo.ts +2 -1
  131. package/src/transpiler/types/symbols/IStructSymbol.ts +15 -0
  132. package/src/transpiler/types/symbols/IVariableSymbol.ts +30 -0
  133. package/src/transpiler/types/symbols/SymbolGuards.ts +43 -0
  134. package/src/transpiler/types/symbols/TAnySymbol.ts +22 -0
  135. package/src/transpiler/types/symbols/TSymbol.ts +32 -0
  136. package/src/transpiler/types/symbols/__tests__/IBaseSymbol.test.ts +56 -0
  137. package/src/transpiler/types/symbols/__tests__/SymbolGuards.test.ts +57 -0
  138. package/src/transpiler/types/symbols/c/ICBaseSymbol.ts +28 -0
  139. package/src/transpiler/types/symbols/c/ICEnumMemberSymbol.ts +17 -0
  140. package/src/transpiler/types/symbols/c/ICEnumSymbol.ts +17 -0
  141. package/src/transpiler/types/symbols/c/ICFieldInfo.ts +16 -0
  142. package/src/transpiler/types/symbols/c/ICFunctionSymbol.ts +21 -0
  143. package/src/transpiler/types/symbols/c/ICParameterInfo.ts +19 -0
  144. package/src/transpiler/types/symbols/c/ICStructSymbol.ts +21 -0
  145. package/src/transpiler/types/symbols/c/ICTypedefSymbol.ts +14 -0
  146. package/src/transpiler/types/symbols/c/ICVariableSymbol.ts +26 -0
  147. package/src/transpiler/types/symbols/c/TCSymbol.ts +26 -0
  148. package/src/transpiler/types/symbols/cpp/ICppBaseSymbol.ts +31 -0
  149. package/src/transpiler/types/symbols/cpp/ICppClassSymbol.ts +15 -0
  150. package/src/transpiler/types/symbols/cpp/ICppEnumMemberSymbol.ts +14 -0
  151. package/src/transpiler/types/symbols/cpp/ICppEnumSymbol.ts +14 -0
  152. package/src/transpiler/types/symbols/cpp/ICppFieldInfo.ts +16 -0
  153. package/src/transpiler/types/symbols/cpp/ICppFunctionSymbol.ts +21 -0
  154. package/src/transpiler/types/symbols/cpp/ICppNamespaceSymbol.ts +11 -0
  155. package/src/transpiler/types/symbols/cpp/ICppParameterInfo.ts +19 -0
  156. package/src/transpiler/types/symbols/cpp/ICppStructSymbol.ts +16 -0
  157. package/src/transpiler/types/symbols/cpp/ICppTypeAliasSymbol.ts +14 -0
  158. package/src/transpiler/types/symbols/cpp/ICppVariableSymbol.ts +23 -0
  159. package/src/transpiler/types/symbols/cpp/TCppSymbol.ts +30 -0
  160. package/src/utils/CppNamespaceUtils.ts +3 -4
  161. package/src/utils/FunctionUtils.ts +92 -0
  162. package/src/utils/ParameterUtils.ts +55 -0
  163. package/src/utils/PrimitiveKindUtils.ts +33 -0
  164. package/src/utils/ScopeUtils.ts +105 -0
  165. package/src/utils/TTypeUtils.ts +159 -0
  166. package/src/utils/TypeResolver.ts +132 -0
  167. package/src/utils/__tests__/CppNamespaceUtils.test.ts +92 -99
  168. package/src/utils/__tests__/FunctionUtils.test.ts +284 -0
  169. package/src/utils/__tests__/ParameterUtils.test.ts +174 -0
  170. package/src/utils/__tests__/PrimitiveKindUtils.test.ts +59 -0
  171. package/src/utils/__tests__/ScopeUtils.test.ts +53 -0
  172. package/src/utils/__tests__/TTypeUtils.test.ts +245 -0
  173. package/src/utils/__tests__/TypeResolver.test.ts +332 -0
  174. package/src/utils/cache/CacheManager.ts +91 -50
  175. package/src/utils/cache/__tests__/CacheManager.test.ts +180 -114
  176. package/src/transpiler/logic/symbols/AutoConstUpdater.ts +0 -93
  177. package/src/transpiler/logic/symbols/CSymbolCollector.ts +0 -648
  178. package/src/transpiler/logic/symbols/CppSymbolCollector.ts +0 -874
  179. package/src/transpiler/logic/symbols/SymbolCollectorContext.ts +0 -68
  180. package/src/transpiler/logic/symbols/__tests__/AutoConstUpdater.test.ts +0 -418
  181. package/src/transpiler/logic/symbols/__tests__/CSymbolCollector.test.ts +0 -685
  182. package/src/transpiler/logic/symbols/__tests__/CppSymbolCollector.test.ts +0 -1146
  183. package/src/transpiler/logic/symbols/__tests__/SymbolCollectorContext.test.ts +0 -290
  184. package/src/transpiler/logic/symbols/__tests__/cTestHelpers.ts +0 -43
  185. package/src/transpiler/logic/symbols/__tests__/cppTestHelpers.ts +0 -40
  186. package/src/transpiler/logic/symbols/cnext/__tests__/TSymbolAdapter.test.ts +0 -595
  187. package/src/transpiler/logic/symbols/cnext/adapters/TSymbolAdapter.ts +0 -345
  188. package/src/transpiler/logic/symbols/types/IBaseSymbol.ts +0 -27
  189. package/src/transpiler/logic/symbols/types/IBitmapSymbol.ts +0 -23
  190. package/src/transpiler/logic/symbols/types/ICollectorContext.ts +0 -19
  191. package/src/transpiler/logic/symbols/types/IConflict.ts +0 -20
  192. package/src/transpiler/logic/symbols/types/IFieldInfo.ts +0 -18
  193. package/src/transpiler/logic/symbols/types/IFunctionSymbol.ts +0 -25
  194. package/src/transpiler/logic/symbols/types/IParameterInfo.ts +0 -24
  195. package/src/transpiler/logic/symbols/types/IRegisterSymbol.ts +0 -20
  196. package/src/transpiler/logic/symbols/types/IScopeSymbol.ts +0 -19
  197. package/src/transpiler/logic/symbols/types/IStructSymbol.ts +0 -16
  198. package/src/transpiler/logic/symbols/types/IVariableSymbol.ts +0 -30
  199. package/src/transpiler/logic/symbols/types/TSymbol.ts +0 -36
  200. package/src/transpiler/logic/symbols/types/__tests__/SymbolGuards.test.ts +0 -244
  201. package/src/transpiler/logic/symbols/types/typeGuards.ts +0 -44
  202. package/src/utils/types/ESymbolKind.ts +0 -19
  203. package/src/utils/types/ISymbol.ts +0 -64
  204. /package/src/transpiler/{types → constants}/BITMAP_BACKING_TYPE.ts +0 -0
  205. /package/src/transpiler/{types → constants}/BITMAP_SIZE.ts +0 -0
@@ -0,0 +1,332 @@
1
+ import { describe, it, expect } from "vitest";
2
+ import TypeResolver from "../TypeResolver";
3
+ import type TType from "../../transpiler/types/TType";
4
+
5
+ describe("TypeResolver", () => {
6
+ describe("resolve - primitive types", () => {
7
+ it("resolves void", () => {
8
+ const result = TypeResolver.resolve("void");
9
+ expect(result).toEqual({ kind: "primitive", primitive: "void" });
10
+ });
11
+
12
+ it("resolves bool", () => {
13
+ const result = TypeResolver.resolve("bool");
14
+ expect(result).toEqual({ kind: "primitive", primitive: "bool" });
15
+ });
16
+
17
+ it("resolves u8", () => {
18
+ const result = TypeResolver.resolve("u8");
19
+ expect(result).toEqual({ kind: "primitive", primitive: "u8" });
20
+ });
21
+
22
+ it("resolves i8", () => {
23
+ const result = TypeResolver.resolve("i8");
24
+ expect(result).toEqual({ kind: "primitive", primitive: "i8" });
25
+ });
26
+
27
+ it("resolves u16", () => {
28
+ const result = TypeResolver.resolve("u16");
29
+ expect(result).toEqual({ kind: "primitive", primitive: "u16" });
30
+ });
31
+
32
+ it("resolves i16", () => {
33
+ const result = TypeResolver.resolve("i16");
34
+ expect(result).toEqual({ kind: "primitive", primitive: "i16" });
35
+ });
36
+
37
+ it("resolves u32", () => {
38
+ const result = TypeResolver.resolve("u32");
39
+ expect(result).toEqual({ kind: "primitive", primitive: "u32" });
40
+ });
41
+
42
+ it("resolves i32", () => {
43
+ const result = TypeResolver.resolve("i32");
44
+ expect(result).toEqual({ kind: "primitive", primitive: "i32" });
45
+ });
46
+
47
+ it("resolves u64", () => {
48
+ const result = TypeResolver.resolve("u64");
49
+ expect(result).toEqual({ kind: "primitive", primitive: "u64" });
50
+ });
51
+
52
+ it("resolves i64", () => {
53
+ const result = TypeResolver.resolve("i64");
54
+ expect(result).toEqual({ kind: "primitive", primitive: "i64" });
55
+ });
56
+
57
+ it("resolves f32", () => {
58
+ const result = TypeResolver.resolve("f32");
59
+ expect(result).toEqual({ kind: "primitive", primitive: "f32" });
60
+ });
61
+
62
+ it("resolves f64", () => {
63
+ const result = TypeResolver.resolve("f64");
64
+ expect(result).toEqual({ kind: "primitive", primitive: "f64" });
65
+ });
66
+ });
67
+
68
+ describe("resolve - string types", () => {
69
+ it("resolves string<32>", () => {
70
+ const result = TypeResolver.resolve("string<32>");
71
+ expect(result).toEqual({ kind: "string", capacity: 32 });
72
+ });
73
+
74
+ it("resolves string<64>", () => {
75
+ const result = TypeResolver.resolve("string<64>");
76
+ expect(result).toEqual({ kind: "string", capacity: 64 });
77
+ });
78
+
79
+ it("resolves string<1>", () => {
80
+ const result = TypeResolver.resolve("string<1>");
81
+ expect(result).toEqual({ kind: "string", capacity: 1 });
82
+ });
83
+
84
+ it("resolves string<256>", () => {
85
+ const result = TypeResolver.resolve("string<256>");
86
+ expect(result).toEqual({ kind: "string", capacity: 256 });
87
+ });
88
+ });
89
+
90
+ describe("resolve - array types", () => {
91
+ it("resolves u8[10]", () => {
92
+ const result = TypeResolver.resolve("u8[10]");
93
+ expect(result).toEqual({
94
+ kind: "array",
95
+ elementType: { kind: "primitive", primitive: "u8" },
96
+ dimensions: [10],
97
+ });
98
+ });
99
+
100
+ it("resolves i32[5]", () => {
101
+ const result = TypeResolver.resolve("i32[5]");
102
+ expect(result).toEqual({
103
+ kind: "array",
104
+ elementType: { kind: "primitive", primitive: "i32" },
105
+ dimensions: [5],
106
+ });
107
+ });
108
+
109
+ it("resolves f64[100]", () => {
110
+ const result = TypeResolver.resolve("f64[100]");
111
+ expect(result).toEqual({
112
+ kind: "array",
113
+ elementType: { kind: "primitive", primitive: "f64" },
114
+ dimensions: [100],
115
+ });
116
+ });
117
+
118
+ it("resolves multi-dimensional array u8[10][20]", () => {
119
+ const result = TypeResolver.resolve("u8[10][20]");
120
+ expect(result).toEqual({
121
+ kind: "array",
122
+ elementType: { kind: "primitive", primitive: "u8" },
123
+ dimensions: [10, 20],
124
+ });
125
+ });
126
+
127
+ it("resolves 3D array u32[2][3][4]", () => {
128
+ const result = TypeResolver.resolve("u32[2][3][4]");
129
+ expect(result).toEqual({
130
+ kind: "array",
131
+ elementType: { kind: "primitive", primitive: "u32" },
132
+ dimensions: [2, 3, 4],
133
+ });
134
+ });
135
+
136
+ it("resolves array with string dimension (C macro)", () => {
137
+ const result = TypeResolver.resolve("u8[BUFFER_SIZE]");
138
+ expect(result).toEqual({
139
+ kind: "array",
140
+ elementType: { kind: "primitive", primitive: "u8" },
141
+ dimensions: ["BUFFER_SIZE"],
142
+ });
143
+ });
144
+
145
+ it("resolves array with mixed dimensions", () => {
146
+ const result = TypeResolver.resolve("u8[10][ROWS]");
147
+ expect(result).toEqual({
148
+ kind: "array",
149
+ elementType: { kind: "primitive", primitive: "u8" },
150
+ dimensions: [10, "ROWS"],
151
+ });
152
+ });
153
+
154
+ it("resolves string array string<32>[10]", () => {
155
+ const result = TypeResolver.resolve("string<32>[10]");
156
+ expect(result).toEqual({
157
+ kind: "array",
158
+ elementType: { kind: "string", capacity: 32 },
159
+ dimensions: [10],
160
+ });
161
+ });
162
+ });
163
+
164
+ describe("resolve - struct types", () => {
165
+ it("resolves Point as struct", () => {
166
+ const result = TypeResolver.resolve("Point");
167
+ expect(result).toEqual({ kind: "struct", name: "Point" });
168
+ });
169
+
170
+ it("resolves Configuration as struct", () => {
171
+ const result = TypeResolver.resolve("Configuration");
172
+ expect(result).toEqual({ kind: "struct", name: "Configuration" });
173
+ });
174
+
175
+ it("resolves MyStruct as struct", () => {
176
+ const result = TypeResolver.resolve("MyStruct");
177
+ expect(result).toEqual({ kind: "struct", name: "MyStruct" });
178
+ });
179
+ });
180
+
181
+ describe("resolve - enum types", () => {
182
+ it("resolves EColor as enum (E prefix convention)", () => {
183
+ const result = TypeResolver.resolve("EColor");
184
+ expect(result).toEqual({ kind: "enum", name: "EColor" });
185
+ });
186
+
187
+ it("resolves EStatus as enum", () => {
188
+ const result = TypeResolver.resolve("EStatus");
189
+ expect(result).toEqual({ kind: "enum", name: "EStatus" });
190
+ });
191
+
192
+ it("resolves EPressureType as enum", () => {
193
+ const result = TypeResolver.resolve("EPressureType");
194
+ expect(result).toEqual({ kind: "enum", name: "EPressureType" });
195
+ });
196
+ });
197
+
198
+ describe("resolve - external types (C++ templates)", () => {
199
+ it("resolves FlexCAN_T4<CAN1>", () => {
200
+ const result = TypeResolver.resolve("FlexCAN_T4<CAN1>");
201
+ expect(result).toEqual({ kind: "external", name: "FlexCAN_T4<CAN1>" });
202
+ });
203
+
204
+ it("resolves std::vector<int>", () => {
205
+ const result = TypeResolver.resolve("std::vector<int>");
206
+ expect(result).toEqual({ kind: "external", name: "std::vector<int>" });
207
+ });
208
+
209
+ it("resolves Complex::Namespace::Type<T>", () => {
210
+ const result = TypeResolver.resolve("Complex::Namespace::Type<T>");
211
+ expect(result).toEqual({
212
+ kind: "external",
213
+ name: "Complex::Namespace::Type<T>",
214
+ });
215
+ });
216
+ });
217
+
218
+ describe("resolve - struct arrays", () => {
219
+ it("resolves Point[5]", () => {
220
+ const result = TypeResolver.resolve("Point[5]");
221
+ expect(result).toEqual({
222
+ kind: "array",
223
+ elementType: { kind: "struct", name: "Point" },
224
+ dimensions: [5],
225
+ });
226
+ });
227
+
228
+ it("resolves Configuration[10][20]", () => {
229
+ const result = TypeResolver.resolve("Configuration[10][20]");
230
+ expect(result).toEqual({
231
+ kind: "array",
232
+ elementType: { kind: "struct", name: "Configuration" },
233
+ dimensions: [10, 20],
234
+ });
235
+ });
236
+ });
237
+
238
+ describe("resolve - enum arrays", () => {
239
+ it("resolves EColor[3]", () => {
240
+ const result = TypeResolver.resolve("EColor[3]");
241
+ expect(result).toEqual({
242
+ kind: "array",
243
+ elementType: { kind: "enum", name: "EColor" },
244
+ dimensions: [3],
245
+ });
246
+ });
247
+ });
248
+
249
+ describe("resolve - edge cases", () => {
250
+ it("handles whitespace in type string", () => {
251
+ const result = TypeResolver.resolve(" u32 ");
252
+ expect(result).toEqual({ kind: "primitive", primitive: "u32" });
253
+ });
254
+
255
+ it("handles whitespace in array dimensions", () => {
256
+ const result = TypeResolver.resolve("u8[ 10 ]");
257
+ expect(result).toEqual({
258
+ kind: "array",
259
+ elementType: { kind: "primitive", primitive: "u8" },
260
+ dimensions: [10],
261
+ });
262
+ });
263
+
264
+ it("handles whitespace in string capacity", () => {
265
+ const result = TypeResolver.resolve("string< 32 >");
266
+ expect(result).toEqual({ kind: "string", capacity: 32 });
267
+ });
268
+
269
+ it("throws for empty string", () => {
270
+ expect(() => TypeResolver.resolve("")).toThrow(
271
+ "Cannot resolve empty type string",
272
+ );
273
+ });
274
+
275
+ it("throws for whitespace-only string", () => {
276
+ expect(() => TypeResolver.resolve(" ")).toThrow(
277
+ "Cannot resolve empty type string",
278
+ );
279
+ });
280
+ });
281
+
282
+ describe("getTypeName - round-trip compatibility", () => {
283
+ it("returns primitive name", () => {
284
+ const type: TType = { kind: "primitive", primitive: "u32" };
285
+ expect(TypeResolver.getTypeName(type)).toBe("u32");
286
+ });
287
+
288
+ it("returns string with capacity", () => {
289
+ const type: TType = { kind: "string", capacity: 64 };
290
+ expect(TypeResolver.getTypeName(type)).toBe("string<64>");
291
+ });
292
+
293
+ it("returns struct name", () => {
294
+ const type: TType = { kind: "struct", name: "Point" };
295
+ expect(TypeResolver.getTypeName(type)).toBe("Point");
296
+ });
297
+
298
+ it("returns enum name", () => {
299
+ const type: TType = { kind: "enum", name: "EColor" };
300
+ expect(TypeResolver.getTypeName(type)).toBe("EColor");
301
+ });
302
+
303
+ it("returns external name", () => {
304
+ const type: TType = { kind: "external", name: "FlexCAN_T4<CAN1>" };
305
+ expect(TypeResolver.getTypeName(type)).toBe("FlexCAN_T4<CAN1>");
306
+ });
307
+
308
+ it("returns array type with dimensions", () => {
309
+ const type: TType = {
310
+ kind: "array",
311
+ elementType: { kind: "primitive", primitive: "u8" },
312
+ dimensions: [10, 20],
313
+ };
314
+ expect(TypeResolver.getTypeName(type)).toBe("u8[10][20]");
315
+ });
316
+
317
+ it("returns callback name", () => {
318
+ const type: TType = { kind: "callback", name: "onClick" };
319
+ expect(TypeResolver.getTypeName(type)).toBe("onClick");
320
+ });
321
+
322
+ it("returns register name", () => {
323
+ const type: TType = { kind: "register", name: "PORTB" };
324
+ expect(TypeResolver.getTypeName(type)).toBe("PORTB");
325
+ });
326
+
327
+ it("returns bitmap name", () => {
328
+ const type: TType = { kind: "bitmap", name: "StatusFlags", bitWidth: 8 };
329
+ expect(TypeResolver.getTypeName(type)).toBe("StatusFlags");
330
+ });
331
+ });
332
+ });
@@ -15,8 +15,8 @@ import { existsSync, unlinkSync } from "node:fs";
15
15
  import { join } from "node:path";
16
16
  import { FlatCache, create as createFlatCache } from "flat-cache";
17
17
  import CacheKeyGenerator from "./CacheKeyGenerator";
18
- import ISymbol from "../types/ISymbol";
19
- import IStructFieldInfo from "../../transpiler/logic/symbols/types/IStructFieldInfo";
18
+ // ADR-055 Phase 7: ISymbol removed - using ISerializedSymbol directly
19
+ import IStructFieldInfo from "../../transpiler/types/symbols/IStructFieldInfo";
20
20
  import SymbolTable from "../../transpiler/logic/symbols/SymbolTable";
21
21
  import ICacheConfig from "../../transpiler/types/ICacheConfig";
22
22
  import ICachedFileEntry from "../../transpiler/types/ICachedFileEntry";
@@ -24,12 +24,15 @@ import ISerializedSymbol from "../../transpiler/types/ISerializedSymbol";
24
24
  import IFileSystem from "../../transpiler/types/IFileSystem";
25
25
  import NodeFileSystem from "../../transpiler/NodeFileSystem";
26
26
  import packageJson from "../../../package.json" with { type: "json" };
27
+ import TAnySymbol from "../../transpiler/types/symbols/TAnySymbol";
28
+ import TypeResolver from "../TypeResolver";
29
+ import ESourceLanguage from "../types/ESourceLanguage";
27
30
 
28
31
  /** Default file system instance (singleton for performance) */
29
32
  const defaultFs = NodeFileSystem.instance;
30
33
 
31
34
  /** Current cache format version - increment when serialization format changes */
32
- const CACHE_VERSION = 3; // ADR-055 Phase 4: cacheKey replaces mtime
35
+ const CACHE_VERSION = 4; // ADR-055 Phase 7: TAnySymbol replaces ISymbol
33
36
 
34
37
  const TRANSPILER_VERSION = packageJson.version;
35
38
 
@@ -124,9 +127,10 @@ class CacheManager {
124
127
 
125
128
  /**
126
129
  * Get cached symbols and struct fields for a file
130
+ * ADR-055 Phase 7: Returns ISerializedSymbol[] directly (no ISymbol intermediate)
127
131
  */
128
132
  getSymbols(filePath: string): {
129
- symbols: ISymbol[];
133
+ symbols: ISerializedSymbol[];
130
134
  structFields: Map<string, Map<string, IStructFieldInfo>>;
131
135
  needsStructKeyword: string[];
132
136
  enumBitWidth: Map<string, number>;
@@ -139,8 +143,8 @@ class CacheManager {
139
143
  }
140
144
  const cachedEntry = entry as ICachedFileEntry;
141
145
 
142
- // Deserialize symbols
143
- const symbols = cachedEntry.symbols.map((s) => this.deserializeSymbol(s));
146
+ // ADR-055 Phase 7: Return serialized symbols directly
147
+ const symbols = cachedEntry.symbols;
144
148
 
145
149
  // Convert struct fields from plain objects to Maps
146
150
  const structFields = new Map<string, Map<string, IStructFieldInfo>>();
@@ -174,10 +178,11 @@ class CacheManager {
174
178
 
175
179
  /**
176
180
  * Store symbols and struct fields for a file
181
+ * ADR-055 Phase 7: Takes ISerializedSymbol[] directly
177
182
  */
178
183
  setSymbols(
179
184
  filePath: string,
180
- symbols: ISymbol[],
185
+ symbols: ISerializedSymbol[],
181
186
  structFields: Map<string, Map<string, IStructFieldInfo>>,
182
187
  needsStructKeyword?: string[],
183
188
  enumBitWidth?: Map<string, number>,
@@ -193,8 +198,8 @@ class CacheManager {
193
198
  return;
194
199
  }
195
200
 
196
- // Serialize symbols
197
- const serializedSymbols = symbols.map((s) => this.serializeSymbol(s));
201
+ // ADR-055 Phase 7: symbols are already serialized
202
+ const serializedSymbols = symbols;
198
203
 
199
204
  // Convert struct fields from Maps to plain objects
200
205
  const serializedFields: Record<
@@ -242,8 +247,9 @@ class CacheManager {
242
247
  * @param symbolTable - SymbolTable containing all parsed symbols
243
248
  */
244
249
  setSymbolsFromTable(filePath: string, symbolTable: SymbolTable): void {
245
- // Extract symbols for this file
246
- const symbols = symbolTable.getSymbolsByFile(filePath);
250
+ // ADR-055 Phase 7: Serialize TAnySymbol directly to ISerializedSymbol
251
+ const typedSymbols = symbolTable.getSymbolsByFile(filePath);
252
+ const symbols = typedSymbols.map((s) => this.serializeTypedSymbol(s));
247
253
 
248
254
  // Extract struct fields for structs defined in this file
249
255
  const structFields = this.extractStructFieldsForFile(filePath, symbolTable);
@@ -475,60 +481,95 @@ class CacheManager {
475
481
  }
476
482
 
477
483
  /**
478
- * Serialize an ISymbol to JSON-safe format
484
+ * ADR-055 Phase 7: Serialize TAnySymbol directly to ISerializedSymbol.
485
+ * No intermediate ISymbol format.
479
486
  */
480
- private serializeSymbol(symbol: ISymbol): ISerializedSymbol {
487
+ private serializeTypedSymbol(symbol: TAnySymbol): ISerializedSymbol {
481
488
  const serialized: ISerializedSymbol = {
482
489
  name: symbol.name,
483
- kind: symbol.kind, // Already a string from enum
490
+ kind: symbol.kind,
484
491
  sourceFile: symbol.sourceFile,
485
492
  sourceLine: symbol.sourceLine,
486
- sourceLanguage: symbol.sourceLanguage, // Already a string from enum
493
+ sourceLanguage: symbol.sourceLanguage,
487
494
  isExported: symbol.isExported,
488
495
  };
489
496
 
490
- // Add optional fields only if present
491
- if (symbol.type !== undefined) serialized.type = symbol.type;
492
- if (symbol.isDeclaration !== undefined)
493
- serialized.isDeclaration = symbol.isDeclaration;
494
- if (symbol.signature !== undefined) serialized.signature = symbol.signature;
495
- if (symbol.parent !== undefined) serialized.parent = symbol.parent;
496
- if (symbol.accessModifier !== undefined)
497
- serialized.accessModifier = symbol.accessModifier;
498
- if (symbol.size !== undefined) serialized.size = symbol.size;
499
- if (symbol.parameters !== undefined)
500
- serialized.parameters = symbol.parameters;
497
+ this.addTypeFieldToSerialized(symbol, serialized);
498
+ this.addVariableFieldsToSerialized(symbol, serialized);
499
+ this.addFunctionFieldsToSerialized(symbol, serialized);
501
500
 
502
501
  return serialized;
503
502
  }
504
503
 
505
504
  /**
506
- * Deserialize a symbol from JSON format back to ISymbol
505
+ * Add type field to ISerializedSymbol, converting TType to string for C-Next symbols.
507
506
  */
508
- private deserializeSymbol(serialized: ISerializedSymbol): ISymbol {
509
- const symbol: ISymbol = {
510
- name: serialized.name,
511
- kind: serialized.kind as ISymbol["kind"], // Cast string back to enum
512
- sourceFile: serialized.sourceFile,
513
- sourceLine: serialized.sourceLine,
514
- sourceLanguage: serialized.sourceLanguage as ISymbol["sourceLanguage"],
515
- isExported: serialized.isExported,
516
- };
507
+ private addTypeFieldToSerialized(
508
+ symbol: TAnySymbol,
509
+ serialized: ISerializedSymbol,
510
+ ): void {
511
+ if (!("type" in symbol) || symbol.type === undefined) {
512
+ return;
513
+ }
514
+ const isCNextWithTType =
515
+ symbol.sourceLanguage === ESourceLanguage.CNext &&
516
+ typeof symbol.type !== "string";
517
+ serialized.type = isCNextWithTType
518
+ ? TypeResolver.getTypeName(symbol.type)
519
+ : (symbol.type as string);
520
+ }
521
+
522
+ /**
523
+ * Add variable-specific fields to ISerializedSymbol.
524
+ */
525
+ private addVariableFieldsToSerialized(
526
+ symbol: TAnySymbol,
527
+ serialized: ISerializedSymbol,
528
+ ): void {
529
+ if (symbol.kind !== "variable") {
530
+ return;
531
+ }
532
+ if ("isConst" in symbol && symbol.isConst !== undefined) {
533
+ serialized.isConst = symbol.isConst;
534
+ }
535
+ if ("isAtomic" in symbol && symbol.isAtomic !== undefined) {
536
+ serialized.isAtomic = symbol.isAtomic;
537
+ }
538
+ if ("isArray" in symbol && symbol.isArray !== undefined) {
539
+ serialized.isArray = symbol.isArray;
540
+ }
541
+ if ("arrayDimensions" in symbol && symbol.arrayDimensions) {
542
+ serialized.arrayDimensions = symbol.arrayDimensions.map(String);
543
+ }
544
+ if ("initialValue" in symbol && symbol.initialValue !== undefined) {
545
+ serialized.initialValue = symbol.initialValue;
546
+ }
547
+ }
517
548
 
518
- // Add optional fields only if present
519
- if (serialized.type !== undefined) symbol.type = serialized.type;
520
- if (serialized.isDeclaration !== undefined)
521
- symbol.isDeclaration = serialized.isDeclaration;
522
- if (serialized.signature !== undefined)
523
- symbol.signature = serialized.signature;
524
- if (serialized.parent !== undefined) symbol.parent = serialized.parent;
525
- if (serialized.accessModifier !== undefined)
526
- symbol.accessModifier = serialized.accessModifier;
527
- if (serialized.size !== undefined) symbol.size = serialized.size;
528
- if (serialized.parameters !== undefined)
529
- symbol.parameters = serialized.parameters;
530
-
531
- return symbol;
549
+ /**
550
+ * Add function-specific fields to ISerializedSymbol.
551
+ */
552
+ private addFunctionFieldsToSerialized(
553
+ symbol: TAnySymbol,
554
+ serialized: ISerializedSymbol,
555
+ ): void {
556
+ if (symbol.kind !== "function") {
557
+ return;
558
+ }
559
+ if ("returnType" in symbol && symbol.returnType !== undefined) {
560
+ serialized.type = TypeResolver.getTypeName(symbol.returnType);
561
+ }
562
+ if ("parameters" in symbol && symbol.parameters) {
563
+ serialized.parameters = symbol.parameters.map((p) => ({
564
+ name: p.name,
565
+ type:
566
+ typeof p.type === "string"
567
+ ? p.type
568
+ : TypeResolver.getTypeName(p.type),
569
+ isConst: p.isConst,
570
+ isArray: p.isArray,
571
+ }));
572
+ }
532
573
  }
533
574
  }
534
575