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
@@ -1,345 +0,0 @@
1
- /**
2
- * TSymbolAdapter - Converts TSymbol[] to ISymbol[] for backwards compatibility.
3
- *
4
- * This adapter bridges the gap between the new composable collectors (which return
5
- * rich discriminated union types) and the existing Pipeline/SymbolTable infrastructure
6
- * (which uses flat ISymbol objects).
7
- *
8
- * ADR-055 Phase 3: This enables gradual migration without breaking consumers.
9
- */
10
-
11
- import ISymbol from "../../../../../utils/types/ISymbol";
12
- import ESymbolKind from "../../../../../utils/types/ESymbolKind";
13
- import SymbolTable from "../../SymbolTable";
14
- import TSymbol from "../../types/TSymbol";
15
- import IBitmapSymbol from "../../types/IBitmapSymbol";
16
- import IEnumSymbol from "../../types/IEnumSymbol";
17
- import IStructSymbol from "../../types/IStructSymbol";
18
- import IFunctionSymbol from "../../types/IFunctionSymbol";
19
- import IVariableSymbol from "../../types/IVariableSymbol";
20
- import IRegisterSymbol from "../../types/IRegisterSymbol";
21
- import IScopeSymbol from "../../types/IScopeSymbol";
22
-
23
- /** Get minimum unsigned type width for a bit count */
24
- function getMinBitWidth(width: number): number {
25
- if (width <= 8) return 8;
26
- if (width <= 16) return 16;
27
- return 32;
28
- }
29
-
30
- /**
31
- * Adapts TSymbol[] to ISymbol[] and registers struct fields in SymbolTable.
32
- */
33
- class TSymbolAdapter {
34
- /**
35
- * Convert TSymbol[] to ISymbol[] for backwards compatibility.
36
- * Also registers struct fields in SymbolTable.
37
- *
38
- * @param symbols Array of discriminated union symbols from collectors
39
- * @param symbolTable SymbolTable for struct field registration and type resolution
40
- * @returns Array of flat ISymbol objects for Pipeline consumption
41
- */
42
- static toISymbols(symbols: TSymbol[], symbolTable: SymbolTable): ISymbol[] {
43
- const result: ISymbol[] = [];
44
-
45
- for (const symbol of symbols) {
46
- switch (symbol.kind) {
47
- case ESymbolKind.Bitmap:
48
- result.push(...TSymbolAdapter.convertBitmap(symbol));
49
- break;
50
- case ESymbolKind.Enum:
51
- result.push(...TSymbolAdapter.convertEnum(symbol));
52
- break;
53
- case ESymbolKind.Struct:
54
- result.push(TSymbolAdapter.convertStruct(symbol, symbolTable));
55
- break;
56
- case ESymbolKind.Function:
57
- result.push(...TSymbolAdapter.convertFunction(symbol));
58
- break;
59
- case ESymbolKind.Variable:
60
- result.push(TSymbolAdapter.convertVariable(symbol));
61
- break;
62
- case ESymbolKind.Register:
63
- result.push(...TSymbolAdapter.convertRegister(symbol));
64
- break;
65
- case ESymbolKind.Namespace:
66
- result.push(TSymbolAdapter.convertScope(symbol));
67
- break;
68
- }
69
- }
70
-
71
- return result;
72
- }
73
-
74
- /**
75
- * Convert an array dimension to a string for header generation.
76
- * Converts qualified enum access (e.g., "EColor.COUNT") to C-style ("EColor_COUNT").
77
- */
78
- private static resolveArrayDimension(dim: number | string): string {
79
- if (typeof dim === "number") {
80
- return String(dim);
81
- }
82
-
83
- // Qualified enum access (e.g., "EColor.COUNT") - convert dots to underscores
84
- if (dim.includes(".")) {
85
- return dim.replaceAll(".", "_");
86
- }
87
-
88
- // Pass through as-is (C macros, other identifiers)
89
- return dim;
90
- }
91
-
92
- /**
93
- * Convert IBitmapSymbol to ISymbol + BitmapField symbols.
94
- */
95
- private static convertBitmap(bitmap: IBitmapSymbol): ISymbol[] {
96
- const result: ISymbol[] = [];
97
-
98
- // Main bitmap symbol
99
- result.push({
100
- name: bitmap.name,
101
- kind: ESymbolKind.Bitmap,
102
- type: bitmap.backingType,
103
- sourceFile: bitmap.sourceFile,
104
- sourceLine: bitmap.sourceLine,
105
- sourceLanguage: bitmap.sourceLanguage,
106
- isExported: bitmap.isExported,
107
- parent: bitmap.parent,
108
- });
109
-
110
- // Expand fields to BitmapField symbols
111
- for (const [fieldName, fieldInfo] of bitmap.fields) {
112
- const width = fieldInfo.width;
113
- const bitEnd = fieldInfo.offset + width - 1;
114
- const bitRange =
115
- width === 1
116
- ? `bit ${fieldInfo.offset}`
117
- : `bits ${fieldInfo.offset}-${bitEnd}`;
118
-
119
- result.push({
120
- name: `${bitmap.name}_${fieldName}`,
121
- kind: ESymbolKind.BitmapField,
122
- type: width === 1 ? "bool" : `u${getMinBitWidth(width)}`,
123
- sourceFile: bitmap.sourceFile,
124
- sourceLine: bitmap.sourceLine,
125
- sourceLanguage: bitmap.sourceLanguage,
126
- isExported: bitmap.isExported,
127
- parent: bitmap.name,
128
- signature: `${bitRange} (${width} bit${width > 1 ? "s" : ""})`,
129
- });
130
- }
131
-
132
- return result;
133
- }
134
-
135
- /**
136
- * Convert IEnumSymbol to ISymbol + EnumMember symbols for hover support.
137
- */
138
- private static convertEnum(enumSym: IEnumSymbol): ISymbol[] {
139
- const result: ISymbol[] = [];
140
-
141
- // Main enum symbol
142
- result.push({
143
- name: enumSym.name,
144
- kind: ESymbolKind.Enum,
145
- sourceFile: enumSym.sourceFile,
146
- sourceLine: enumSym.sourceLine,
147
- sourceLanguage: enumSym.sourceLanguage,
148
- isExported: enumSym.isExported,
149
- parent: enumSym.parent,
150
- });
151
-
152
- // Create EnumMember symbols for hover/autocomplete
153
- // Note: sourceLine points to the enum declaration — IEnumSymbol.members
154
- // is Map<string, number> (name → value) with no per-member line info.
155
- for (const [memberName, memberValue] of enumSym.members) {
156
- result.push({
157
- name: memberName,
158
- kind: ESymbolKind.EnumMember,
159
- type: String(memberValue),
160
- sourceFile: enumSym.sourceFile,
161
- sourceLine: enumSym.sourceLine,
162
- sourceLanguage: enumSym.sourceLanguage,
163
- isExported: enumSym.isExported,
164
- parent: enumSym.name,
165
- });
166
- }
167
-
168
- return result;
169
- }
170
-
171
- /**
172
- * Convert IStructSymbol to ISymbol and register fields in SymbolTable.
173
- */
174
- private static convertStruct(
175
- struct: IStructSymbol,
176
- symbolTable: SymbolTable,
177
- ): ISymbol {
178
- // Register struct fields in SymbolTable for TypeResolver.isStructType()
179
- for (const [fieldName, fieldInfo] of struct.fields) {
180
- symbolTable.addStructField(
181
- struct.name,
182
- fieldName,
183
- fieldInfo.type,
184
- fieldInfo.dimensions,
185
- );
186
- }
187
-
188
- return {
189
- name: struct.name,
190
- kind: ESymbolKind.Struct,
191
- sourceFile: struct.sourceFile,
192
- sourceLine: struct.sourceLine,
193
- sourceLanguage: struct.sourceLanguage,
194
- isExported: struct.isExported,
195
- parent: struct.parent,
196
- };
197
- }
198
-
199
- /**
200
- * Convert IFunctionSymbol to ISymbol + parameter symbols for hover support.
201
- * Converts qualified enum names in parameter array dimensions.
202
- */
203
- private static convertFunction(func: IFunctionSymbol): ISymbol[] {
204
- const result: ISymbol[] = [];
205
-
206
- // Build parameter types for signature
207
- const paramTypes = func.parameters.map((p) => p.type);
208
- const signature = `${func.returnType} ${func.name}(${paramTypes.join(", ")})`;
209
-
210
- // Build parameter info for header generation
211
- const parameters = func.parameters.map((p) => ({
212
- name: p.name,
213
- type: p.type,
214
- isConst: p.isConst,
215
- isArray: p.isArray,
216
- arrayDimensions: p.arrayDimensions?.map((dim) =>
217
- TSymbolAdapter.resolveArrayDimension(dim),
218
- ),
219
- isAutoConst: p.isAutoConst,
220
- }));
221
-
222
- // Main function symbol
223
- result.push({
224
- name: func.name,
225
- kind: ESymbolKind.Function,
226
- type: func.returnType,
227
- sourceFile: func.sourceFile,
228
- sourceLine: func.sourceLine,
229
- sourceLanguage: func.sourceLanguage,
230
- isExported: func.isExported,
231
- parent: func.parent,
232
- signature,
233
- parameters,
234
- });
235
-
236
- // Create parameter symbols for hover support
237
- for (const param of func.parameters) {
238
- const displayType = param.isArray ? `${param.type}[]` : param.type;
239
-
240
- result.push({
241
- name: param.name,
242
- kind: ESymbolKind.Variable,
243
- type: displayType,
244
- sourceFile: func.sourceFile,
245
- sourceLine: func.sourceLine,
246
- sourceLanguage: func.sourceLanguage,
247
- isExported: false,
248
- parent: func.name,
249
- });
250
- }
251
-
252
- return result;
253
- }
254
-
255
- /**
256
- * Convert IVariableSymbol to ISymbol.
257
- * Converts qualified enum names in array dimensions.
258
- */
259
- private static convertVariable(variable: IVariableSymbol): ISymbol {
260
- // Convert dimensions to string dimensions
261
- const arrayDimensions = variable.arrayDimensions?.map((dim) =>
262
- TSymbolAdapter.resolveArrayDimension(dim),
263
- );
264
-
265
- // Get first dimension for legacy size field (only if numeric)
266
- const firstDim = variable.arrayDimensions?.[0];
267
- const size = typeof firstDim === "number" ? firstDim : undefined;
268
-
269
- const result: ISymbol = {
270
- name: variable.name,
271
- kind: ESymbolKind.Variable,
272
- type: variable.type,
273
- sourceFile: variable.sourceFile,
274
- sourceLine: variable.sourceLine,
275
- sourceLanguage: variable.sourceLanguage,
276
- isExported: variable.isExported,
277
- parent: variable.parent,
278
- isConst: variable.isConst,
279
- isAtomic: variable.isAtomic,
280
- isArray: variable.isArray,
281
- arrayDimensions,
282
- size,
283
- };
284
-
285
- // Issue #461: Preserve initialValue for const variables (needed for external array dimension resolution)
286
- if (variable.initialValue !== undefined) {
287
- result.initialValue = variable.initialValue;
288
- }
289
-
290
- return result;
291
- }
292
-
293
- /**
294
- * Convert IRegisterSymbol to ISymbol + RegisterMember symbols.
295
- */
296
- private static convertRegister(register: IRegisterSymbol): ISymbol[] {
297
- const result: ISymbol[] = [];
298
-
299
- // Main register symbol
300
- result.push({
301
- name: register.name,
302
- kind: ESymbolKind.Register,
303
- sourceFile: register.sourceFile,
304
- sourceLine: register.sourceLine,
305
- sourceLanguage: register.sourceLanguage,
306
- isExported: register.isExported,
307
- parent: register.parent,
308
- });
309
-
310
- // Expand members to RegisterMember symbols
311
- for (const [memberName, memberInfo] of register.members) {
312
- result.push({
313
- name: `${register.name}_${memberName}`,
314
- kind: ESymbolKind.RegisterMember,
315
- type: memberInfo.cType,
316
- sourceFile: register.sourceFile,
317
- sourceLine: register.sourceLine,
318
- sourceLanguage: register.sourceLanguage,
319
- isExported: register.isExported,
320
- parent: register.name,
321
- accessModifier: memberInfo.access,
322
- });
323
- }
324
-
325
- return result;
326
- }
327
-
328
- /**
329
- * Convert IScopeSymbol to ISymbol.
330
- * Note: Scope members are collected as separate symbols by ScopeCollector,
331
- * so we only need to convert the scope itself.
332
- */
333
- private static convertScope(scope: IScopeSymbol): ISymbol {
334
- return {
335
- name: scope.name,
336
- kind: ESymbolKind.Namespace,
337
- sourceFile: scope.sourceFile,
338
- sourceLine: scope.sourceLine,
339
- sourceLanguage: scope.sourceLanguage,
340
- isExported: scope.isExported,
341
- };
342
- }
343
- }
344
-
345
- export default TSymbolAdapter;
@@ -1,27 +0,0 @@
1
- import ESourceLanguage from "../../../../utils/types/ESourceLanguage";
2
-
3
- /**
4
- * Common fields shared by all symbol types.
5
- * Extracted from ISymbol to provide a typed base for discriminated union members.
6
- */
7
- interface IBaseSymbol {
8
- /** Symbol name (e.g., "LED_toggle", "GPIO7", "Point") */
9
- name: string;
10
-
11
- /** Parent scope/namespace name (e.g., "LED" for a member of scope LED) */
12
- parent?: string;
13
-
14
- /** Source file where the symbol is defined */
15
- sourceFile: string;
16
-
17
- /** Line number in the source file */
18
- sourceLine: number;
19
-
20
- /** Source language (CNext, C, Cpp) */
21
- sourceLanguage: ESourceLanguage;
22
-
23
- /** Whether this symbol is exported/public */
24
- isExported: boolean;
25
- }
26
-
27
- export default IBaseSymbol;
@@ -1,23 +0,0 @@
1
- import ESymbolKind from "../../../../utils/types/ESymbolKind";
2
- import IBaseSymbol from "./IBaseSymbol";
3
- import IBitmapFieldInfo from "./IBitmapFieldInfo";
4
-
5
- /**
6
- * Symbol representing a bitmap type definition.
7
- * Bitmaps provide named access to bit regions within an integer backing type.
8
- */
9
- interface IBitmapSymbol extends IBaseSymbol {
10
- /** Discriminant for type narrowing */
11
- kind: ESymbolKind.Bitmap;
12
-
13
- /** Backing integer type (e.g., "u8", "u32") */
14
- backingType: string;
15
-
16
- /** Total bit width of the bitmap */
17
- bitWidth: number;
18
-
19
- /** Map of field name to bit offset/width metadata */
20
- fields: Map<string, IBitmapFieldInfo>;
21
- }
22
-
23
- export default IBitmapSymbol;
@@ -1,19 +0,0 @@
1
- /**
2
- * Context object holding shared state for symbol collection
3
- */
4
-
5
- import ISymbol from "../../../../utils/types/ISymbol";
6
- import SymbolTable from "../SymbolTable";
7
-
8
- interface ICollectorContext {
9
- /** Source file path being parsed */
10
- sourceFile: string;
11
- /** Collected symbols */
12
- symbols: ISymbol[];
13
- /** Warnings generated during collection */
14
- warnings: string[];
15
- /** Optional symbol table for struct field registration */
16
- symbolTable: SymbolTable | null;
17
- }
18
-
19
- export default ICollectorContext;
@@ -1,20 +0,0 @@
1
- import ISymbol from "../../../../utils/types/ISymbol";
2
-
3
- /**
4
- * Represents a symbol conflict between languages
5
- */
6
- interface IConflict {
7
- /** The conflicting symbol name */
8
- symbolName: string;
9
-
10
- /** All definitions of this symbol */
11
- definitions: ISymbol[];
12
-
13
- /** Conflict severity */
14
- severity: "error" | "warning";
15
-
16
- /** Human-readable message */
17
- message: string;
18
- }
19
-
20
- export default IConflict;
@@ -1,18 +0,0 @@
1
- /**
2
- * Metadata for a struct field.
3
- */
4
- interface IFieldInfo {
5
- /** C-Next type of the field (e.g., "u32", "Point") */
6
- type: string;
7
-
8
- /** Whether this field is an array */
9
- isArray: boolean;
10
-
11
- /** Array dimensions if isArray is true (e.g., [10, 20]) */
12
- dimensions?: number[];
13
-
14
- /** Whether this field is const */
15
- isConst: boolean;
16
- }
17
-
18
- export default IFieldInfo;
@@ -1,25 +0,0 @@
1
- import ESymbolKind from "../../../../utils/types/ESymbolKind";
2
- import IBaseSymbol from "./IBaseSymbol";
3
- import IParameterInfo from "./IParameterInfo";
4
-
5
- /**
6
- * Symbol representing a function definition or declaration.
7
- */
8
- interface IFunctionSymbol extends IBaseSymbol {
9
- /** Discriminant for type narrowing */
10
- kind: ESymbolKind.Function;
11
-
12
- /** Return type (e.g., "void", "u32", "Point") */
13
- returnType: string;
14
-
15
- /** Function parameters */
16
- parameters: IParameterInfo[];
17
-
18
- /** Visibility within a scope */
19
- visibility: "public" | "private";
20
-
21
- /** Full signature for overload detection (e.g., "void foo(int, float)") */
22
- signature?: string;
23
- }
24
-
25
- export default IFunctionSymbol;
@@ -1,24 +0,0 @@
1
- /**
2
- * Metadata for a function parameter.
3
- */
4
- interface IParameterInfo {
5
- /** Parameter name */
6
- name: string;
7
-
8
- /** C-Next type (e.g., "u32", "Configuration") */
9
- type: string;
10
-
11
- /** Whether this parameter is const */
12
- isConst: boolean;
13
-
14
- /** Whether this parameter is an array */
15
- isArray: boolean;
16
-
17
- /** Array dimensions if isArray is true (e.g., ["10", "20"] or [""] for unbounded) */
18
- arrayDimensions?: string[];
19
-
20
- /** Issue #268: true if parameter should get auto-const (unmodified pointer) */
21
- isAutoConst?: boolean;
22
- }
23
-
24
- export default IParameterInfo;
@@ -1,20 +0,0 @@
1
- import ESymbolKind from "../../../../utils/types/ESymbolKind";
2
- import IBaseSymbol from "./IBaseSymbol";
3
- import IRegisterMemberInfo from "./IRegisterMemberInfo";
4
-
5
- /**
6
- * Symbol representing a register block definition.
7
- * Registers provide typed access to memory-mapped I/O locations.
8
- */
9
- interface IRegisterSymbol extends IBaseSymbol {
10
- /** Discriminant for type narrowing */
11
- kind: ESymbolKind.Register;
12
-
13
- /** Base address expression (as string, e.g., "0x40000000") */
14
- baseAddress: string;
15
-
16
- /** Map of member name to register member metadata */
17
- members: Map<string, IRegisterMemberInfo>;
18
- }
19
-
20
- export default IRegisterSymbol;
@@ -1,19 +0,0 @@
1
- import ESymbolKind from "../../../../utils/types/ESymbolKind";
2
- import IBaseSymbol from "./IBaseSymbol";
3
-
4
- /**
5
- * Symbol representing a scope (namespace) definition.
6
- * Scopes group related functions and can control member visibility.
7
- */
8
- interface IScopeSymbol extends IBaseSymbol {
9
- /** Discriminant for type narrowing */
10
- kind: ESymbolKind.Namespace;
11
-
12
- /** List of member names within this scope */
13
- members: string[];
14
-
15
- /** Visibility of each member (public or private) */
16
- memberVisibility: Map<string, "public" | "private">;
17
- }
18
-
19
- export default IScopeSymbol;
@@ -1,16 +0,0 @@
1
- import ESymbolKind from "../../../../utils/types/ESymbolKind";
2
- import IBaseSymbol from "./IBaseSymbol";
3
- import IFieldInfo from "./IFieldInfo";
4
-
5
- /**
6
- * Symbol representing a struct type definition.
7
- */
8
- interface IStructSymbol extends IBaseSymbol {
9
- /** Discriminant for type narrowing */
10
- kind: ESymbolKind.Struct;
11
-
12
- /** Map of field name to field metadata */
13
- fields: Map<string, IFieldInfo>;
14
- }
15
-
16
- export default IStructSymbol;
@@ -1,30 +0,0 @@
1
- import ESymbolKind from "../../../../utils/types/ESymbolKind";
2
- import IBaseSymbol from "./IBaseSymbol";
3
-
4
- /**
5
- * Symbol representing a variable (global, static, or extern).
6
- */
7
- interface IVariableSymbol extends IBaseSymbol {
8
- /** Discriminant for type narrowing */
9
- kind: ESymbolKind.Variable;
10
-
11
- /** C-Next type (e.g., "u32", "Point") */
12
- type: string;
13
-
14
- /** Whether this variable is const */
15
- isConst: boolean;
16
-
17
- /** Issue #468: Whether this variable is atomic (volatile in C) */
18
- isAtomic: boolean;
19
-
20
- /** Whether this variable is an array */
21
- isArray: boolean;
22
-
23
- /** Array dimensions if isArray is true - numbers for resolved dimensions, strings for macros */
24
- arrayDimensions?: (number | string)[];
25
-
26
- /** Initial value expression (as string) */
27
- initialValue?: string;
28
- }
29
-
30
- export default IVariableSymbol;
@@ -1,36 +0,0 @@
1
- import IBitmapSymbol from "./IBitmapSymbol";
2
- import IEnumSymbol from "./IEnumSymbol";
3
- import IFunctionSymbol from "./IFunctionSymbol";
4
- import IRegisterSymbol from "./IRegisterSymbol";
5
- import IScopeSymbol from "./IScopeSymbol";
6
- import IStructSymbol from "./IStructSymbol";
7
- import IVariableSymbol from "./IVariableSymbol";
8
-
9
- /**
10
- * Discriminated union of all symbol types.
11
- *
12
- * Use the `kind` field to narrow to a specific symbol type:
13
- * ```typescript
14
- * if (symbol.kind === ESymbolKind.Struct) {
15
- * // TypeScript knows symbol is IStructSymbol here
16
- * for (const [fieldName, fieldInfo] of symbol.fields) { ... }
17
- * }
18
- * ```
19
- *
20
- * Or use the type guard functions from typeGuards.ts:
21
- * ```typescript
22
- * if (isStructSymbol(symbol)) {
23
- * // TypeScript knows symbol is IStructSymbol here
24
- * }
25
- * ```
26
- */
27
- type TSymbol =
28
- | IStructSymbol
29
- | IEnumSymbol
30
- | IBitmapSymbol
31
- | IFunctionSymbol
32
- | IVariableSymbol
33
- | IScopeSymbol
34
- | IRegisterSymbol;
35
-
36
- export default TSymbol;