c-next 0.1.69 → 0.1.71

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 (247) 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 +173 -60
  6. package/src/transpiler/logic/analysis/FunctionCallAnalyzer.ts +240 -205
  7. package/src/transpiler/logic/analysis/InitializationAnalyzer.ts +1 -2
  8. package/src/transpiler/logic/analysis/PassByValueAnalyzer.ts +742 -0
  9. package/src/transpiler/logic/analysis/__tests__/FunctionCallAnalyzer.test.ts +102 -15
  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/{output/codegen → logic/analysis}/helpers/AssignmentTargetExtractor.ts +1 -1
  13. package/src/transpiler/{output/codegen → logic/analysis}/helpers/ChildStatementCollector.ts +1 -1
  14. package/src/transpiler/{output/codegen → logic/analysis}/helpers/StatementExpressionCollector.ts +1 -1
  15. package/src/transpiler/{output/codegen → logic/analysis}/helpers/__tests__/AssignmentTargetExtractor.test.ts +2 -2
  16. package/src/transpiler/{output/codegen → logic/analysis}/helpers/__tests__/ChildStatementCollector.test.ts +2 -2
  17. package/src/transpiler/{output/codegen → logic/analysis}/helpers/__tests__/StatementExpressionCollector.test.ts +2 -2
  18. package/src/transpiler/logic/symbols/SymbolTable.ts +676 -258
  19. package/src/transpiler/logic/symbols/SymbolUtils.ts +2 -2
  20. package/src/transpiler/logic/symbols/__tests__/SymbolTable.test.ts +290 -782
  21. package/src/transpiler/logic/symbols/c/__tests__/CResolver.integration.test.ts +573 -0
  22. package/src/transpiler/logic/symbols/c/__tests__/testHelpers.ts +20 -0
  23. package/src/transpiler/logic/symbols/c/collectors/EnumCollector.ts +82 -0
  24. package/src/transpiler/logic/symbols/c/collectors/FunctionCollector.ts +106 -0
  25. package/src/transpiler/logic/symbols/c/collectors/StructCollector.ts +173 -0
  26. package/src/transpiler/logic/symbols/c/collectors/TypedefCollector.ts +35 -0
  27. package/src/transpiler/logic/symbols/c/collectors/VariableCollector.ts +80 -0
  28. package/src/transpiler/logic/symbols/c/index.ts +333 -0
  29. package/src/transpiler/logic/symbols/c/utils/DeclaratorUtils.ts +269 -0
  30. package/src/transpiler/logic/symbols/cnext/__tests__/BitmapCollector.test.ts +50 -11
  31. package/src/transpiler/logic/symbols/cnext/__tests__/CNextResolver.integration.test.ts +45 -34
  32. package/src/transpiler/logic/symbols/cnext/__tests__/EnumCollector.test.ts +30 -13
  33. package/src/transpiler/logic/symbols/cnext/__tests__/FunctionCollector.test.ts +279 -64
  34. package/src/transpiler/logic/symbols/cnext/__tests__/RegisterCollector.test.ts +60 -13
  35. package/src/transpiler/logic/symbols/cnext/__tests__/ScopeCollector.test.ts +40 -37
  36. package/src/transpiler/logic/symbols/cnext/__tests__/StructCollector.test.ts +131 -45
  37. package/src/transpiler/logic/symbols/cnext/__tests__/TSymbolInfoAdapter.test.ts +223 -139
  38. package/src/transpiler/logic/symbols/cnext/__tests__/VariableCollector.test.ts +79 -25
  39. package/src/transpiler/logic/symbols/cnext/__tests__/testUtils.ts +53 -0
  40. package/src/transpiler/logic/symbols/cnext/adapters/TSymbolInfoAdapter.ts +83 -43
  41. package/src/transpiler/logic/symbols/cnext/collectors/BitmapCollector.ts +14 -13
  42. package/src/transpiler/logic/symbols/cnext/collectors/EnumCollector.ts +11 -10
  43. package/src/transpiler/logic/symbols/cnext/collectors/FunctionCollector.ts +83 -34
  44. package/src/transpiler/logic/symbols/cnext/collectors/RegisterCollector.ts +22 -18
  45. package/src/transpiler/logic/symbols/cnext/collectors/ScopeCollector.ts +53 -35
  46. package/src/transpiler/logic/symbols/cnext/collectors/StructCollector.ts +30 -23
  47. package/src/transpiler/logic/symbols/cnext/collectors/VariableCollector.ts +18 -19
  48. package/src/transpiler/logic/symbols/cnext/index.ts +36 -14
  49. package/src/transpiler/logic/symbols/cnext/types/IScopeCollectorResult.ts +2 -2
  50. package/src/transpiler/logic/symbols/cnext/utils/SymbolNameUtils.ts +27 -0
  51. package/src/transpiler/logic/symbols/cpp/__tests__/CppResolver.integration.test.ts +270 -0
  52. package/src/transpiler/logic/symbols/cpp/__tests__/testHelpers.ts +20 -0
  53. package/src/transpiler/logic/symbols/cpp/collectors/ClassCollector.ts +317 -0
  54. package/src/transpiler/logic/symbols/cpp/collectors/EnumCollector.ts +71 -0
  55. package/src/transpiler/logic/symbols/cpp/collectors/FunctionCollector.ts +155 -0
  56. package/src/transpiler/logic/symbols/cpp/collectors/NamespaceCollector.ts +65 -0
  57. package/src/transpiler/logic/symbols/cpp/collectors/TypeAliasCollector.ts +46 -0
  58. package/src/transpiler/logic/symbols/cpp/collectors/VariableCollector.ts +54 -0
  59. package/src/transpiler/logic/symbols/cpp/index.ts +366 -0
  60. package/src/transpiler/logic/symbols/cpp/utils/DeclaratorUtils.ts +248 -0
  61. package/src/transpiler/logic/symbols/shared/IExtractedParameter.ts +18 -0
  62. package/src/transpiler/logic/symbols/shared/ParameterExtractorUtils.ts +73 -0
  63. package/src/transpiler/output/codegen/CodeGenerator.ts +310 -2288
  64. package/src/transpiler/output/codegen/TypeRegistrationUtils.ts +4 -6
  65. package/src/transpiler/output/codegen/TypeResolver.ts +2 -2
  66. package/src/transpiler/output/codegen/TypeValidator.ts +5 -5
  67. package/src/transpiler/output/codegen/__tests__/CodeGenerator.test.ts +7 -1
  68. package/src/transpiler/output/codegen/__tests__/TypeRegistrationUtils.test.ts +36 -51
  69. package/src/transpiler/output/codegen/__tests__/TypeResolver.test.ts +20 -17
  70. package/src/transpiler/output/codegen/__tests__/TypeValidator.resolution.test.ts +3 -3
  71. package/src/transpiler/output/codegen/__tests__/TypeValidator.test.ts +1 -1
  72. package/src/transpiler/output/codegen/analysis/MemberChainAnalyzer.ts +1 -1
  73. package/src/transpiler/output/codegen/analysis/StringLengthCounter.ts +1 -1
  74. package/src/transpiler/output/codegen/analysis/__tests__/MemberChainAnalyzer.test.ts +9 -9
  75. package/src/transpiler/output/codegen/analysis/__tests__/StringLengthCounter.test.ts +12 -12
  76. package/src/transpiler/output/codegen/assignment/AssignmentClassifier.ts +13 -12
  77. package/src/transpiler/output/codegen/assignment/__tests__/AssignmentClassifier.test.ts +23 -17
  78. package/src/transpiler/output/codegen/assignment/handlers/ArrayHandlers.ts +2 -2
  79. package/src/transpiler/output/codegen/assignment/handlers/AssignmentHandlerUtils.ts +7 -1
  80. package/src/transpiler/output/codegen/assignment/handlers/BitAccessHandlers.ts +3 -3
  81. package/src/transpiler/output/codegen/assignment/handlers/BitmapHandlers.ts +9 -5
  82. package/src/transpiler/output/codegen/assignment/handlers/RegisterHandlers.ts +2 -1
  83. package/src/transpiler/output/codegen/assignment/handlers/SpecialHandlers.ts +4 -4
  84. package/src/transpiler/output/codegen/assignment/handlers/StringHandlers.ts +5 -5
  85. package/src/transpiler/output/codegen/assignment/handlers/__tests__/ArrayHandlers.test.ts +23 -25
  86. package/src/transpiler/output/codegen/assignment/handlers/__tests__/BitAccessHandlers.test.ts +20 -36
  87. package/src/transpiler/output/codegen/assignment/handlers/__tests__/BitmapHandlers.test.ts +18 -18
  88. package/src/transpiler/output/codegen/assignment/handlers/__tests__/SpecialHandlers.test.ts +42 -32
  89. package/src/transpiler/output/codegen/assignment/handlers/__tests__/handlerTestUtils.ts +5 -4
  90. package/src/transpiler/output/codegen/generators/declarationGenerators/ScopeGenerator.ts +21 -8
  91. package/src/transpiler/output/codegen/generators/declarationGenerators/ScopedRegisterGenerator.ts +3 -2
  92. package/src/transpiler/output/codegen/generators/expressions/CallExprGenerator.ts +14 -6
  93. package/src/transpiler/output/codegen/generators/expressions/CallExprUtils.ts +9 -3
  94. package/src/transpiler/output/codegen/generators/expressions/PostfixExpressionGenerator.ts +19 -16
  95. package/src/transpiler/output/codegen/generators/expressions/__tests__/CallExprGenerator.test.ts +24 -8
  96. package/src/transpiler/output/codegen/generators/expressions/__tests__/CallExprUtils.test.ts +4 -8
  97. package/src/transpiler/output/codegen/generators/expressions/__tests__/PostfixExpressionGenerator.test.ts +15 -2
  98. package/src/transpiler/output/codegen/helpers/ArgumentGenerator.ts +236 -0
  99. package/src/transpiler/output/codegen/helpers/ArrayInitHelper.ts +2 -1
  100. package/src/transpiler/output/codegen/helpers/AssignmentExpectedTypeResolver.ts +2 -2
  101. package/src/transpiler/output/codegen/helpers/AssignmentValidator.ts +3 -3
  102. package/src/transpiler/output/codegen/helpers/CppConstructorHelper.ts +3 -3
  103. package/src/transpiler/output/codegen/helpers/EnumAssignmentValidator.ts +1 -1
  104. package/src/transpiler/output/codegen/helpers/FunctionContextManager.ts +435 -0
  105. package/src/transpiler/output/codegen/helpers/StringDeclHelper.ts +2 -2
  106. package/src/transpiler/output/codegen/helpers/StringOperationsHelper.ts +203 -0
  107. package/src/transpiler/output/codegen/helpers/SymbolLookupHelper.ts +8 -12
  108. package/src/transpiler/output/codegen/helpers/TypeRegistrationEngine.ts +520 -0
  109. package/src/transpiler/output/codegen/helpers/VariableDeclHelper.ts +735 -0
  110. package/src/transpiler/output/codegen/helpers/VariableDeclarationFormatter.ts +1 -1
  111. package/src/transpiler/output/codegen/helpers/__tests__/ArgumentGenerator.test.ts +521 -0
  112. package/src/transpiler/output/codegen/helpers/__tests__/ArrayInitHelper.test.ts +1 -1
  113. package/src/transpiler/output/codegen/helpers/__tests__/AssignmentExpectedTypeResolver.test.ts +7 -7
  114. package/src/transpiler/output/codegen/helpers/__tests__/AssignmentValidator.test.ts +7 -7
  115. package/src/transpiler/output/codegen/helpers/__tests__/CppConstructorHelper.test.ts +4 -5
  116. package/src/transpiler/output/codegen/helpers/__tests__/EnumAssignmentValidator.test.ts +2 -2
  117. package/src/transpiler/output/codegen/helpers/__tests__/FunctionContextManager.test.ts +983 -0
  118. package/src/transpiler/output/codegen/helpers/__tests__/StringDeclHelper.test.ts +4 -4
  119. package/src/transpiler/output/codegen/helpers/__tests__/StringOperationsHelper.test.ts +269 -0
  120. package/src/transpiler/output/codegen/helpers/__tests__/SymbolLookupHelper.test.ts +31 -32
  121. package/src/transpiler/output/codegen/helpers/__tests__/TypeRegistrationEngine.test.ts +186 -0
  122. package/src/transpiler/output/codegen/helpers/__tests__/VariableDeclHelper.test.ts +460 -0
  123. package/src/transpiler/output/codegen/helpers/types/IArgumentGeneratorCallbacks.ts +32 -0
  124. package/src/transpiler/output/codegen/resolution/EnumTypeResolver.ts +7 -3
  125. package/src/transpiler/output/codegen/resolution/__tests__/EnumTypeResolver.test.ts +5 -5
  126. package/src/transpiler/output/codegen/types/IFunctionContextCallbacks.ts +12 -0
  127. package/src/transpiler/output/codegen/types/IVariableFormatInput.ts +1 -1
  128. package/src/transpiler/output/codegen/utils/QualifiedNameGenerator.ts +114 -0
  129. package/src/transpiler/output/codegen/utils/__tests__/QualifiedNameGenerator.test.ts +183 -0
  130. package/src/transpiler/output/headers/BaseHeaderGenerator.ts +4 -4
  131. package/src/transpiler/output/headers/ExternalTypeHeaderBuilder.ts +7 -7
  132. package/src/transpiler/output/headers/HeaderGenerator.ts +9 -7
  133. package/src/transpiler/output/headers/HeaderGeneratorUtils.ts +19 -20
  134. package/src/transpiler/output/headers/__tests__/BaseHeaderGenerator.test.ts +15 -18
  135. package/src/transpiler/output/headers/__tests__/CHeaderGenerator.test.ts +63 -64
  136. package/src/transpiler/output/headers/__tests__/CppHeaderGenerator.test.ts +36 -32
  137. package/src/transpiler/output/headers/__tests__/ExternalTypeHeaderBuilder.test.ts +26 -26
  138. package/src/transpiler/output/headers/__tests__/HeaderGenerator.test.ts +87 -59
  139. package/src/transpiler/output/headers/__tests__/HeaderGeneratorUtils.test.ts +57 -58
  140. package/src/transpiler/output/headers/adapters/HeaderSymbolAdapter.ts +222 -0
  141. package/src/transpiler/output/headers/adapters/__tests__/HeaderSymbolAdapter.test.ts +538 -0
  142. package/src/transpiler/output/headers/types/IGroupedSymbols.ts +8 -8
  143. package/src/transpiler/output/headers/types/IHeaderSymbol.ts +62 -0
  144. package/src/transpiler/state/CodeGenState.ts +109 -4
  145. package/src/transpiler/state/SymbolRegistry.ts +181 -0
  146. package/src/transpiler/{types → state}/TranspilerState.ts +1 -1
  147. package/src/transpiler/state/__tests__/CodeGenState.test.ts +277 -1
  148. package/src/transpiler/state/__tests__/SymbolRegistry.test.ts +249 -0
  149. package/src/transpiler/{types → state}/__tests__/TranspilerState.test.ts +1 -1
  150. package/src/transpiler/types/ICachedFileEntry.ts +1 -1
  151. package/src/transpiler/types/IConflict.ts +14 -0
  152. package/src/transpiler/types/ISerializedSymbol.ts +11 -0
  153. package/src/transpiler/types/TPrimitiveKind.ts +20 -0
  154. package/src/transpiler/types/TType.ts +103 -0
  155. package/src/transpiler/types/TVisibility.ts +6 -0
  156. package/src/transpiler/types/symbol-kinds/TSymbolKind.ts +10 -0
  157. package/src/transpiler/types/symbol-kinds/TSymbolKindC.ts +12 -0
  158. package/src/transpiler/types/symbol-kinds/TSymbolKindCNext.ts +16 -0
  159. package/src/transpiler/types/symbol-kinds/TSymbolKindCpp.ts +14 -0
  160. package/src/transpiler/types/symbols/IBaseSymbol.ts +31 -0
  161. package/src/transpiler/{logic/symbols/types → types/symbols}/IBitmapFieldInfo.ts +2 -2
  162. package/src/transpiler/types/symbols/IBitmapSymbol.ts +21 -0
  163. package/src/transpiler/{logic/symbols/types → types/symbols}/IEnumSymbol.ts +5 -6
  164. package/src/transpiler/types/symbols/IFieldInfo.ts +26 -0
  165. package/src/transpiler/types/symbols/IFunctionSymbol.ts +30 -0
  166. package/src/transpiler/types/symbols/IParameterInfo.ts +26 -0
  167. package/src/transpiler/{logic/symbols/types → types/symbols}/IRegisterMemberInfo.ts +4 -4
  168. package/src/transpiler/types/symbols/IRegisterSymbol.ts +18 -0
  169. package/src/transpiler/types/symbols/IScopeSymbol.ts +32 -0
  170. package/src/transpiler/{logic/symbols/types → types/symbols}/IStructFieldInfo.ts +2 -1
  171. package/src/transpiler/types/symbols/IStructSymbol.ts +15 -0
  172. package/src/transpiler/types/symbols/IVariableSymbol.ts +30 -0
  173. package/src/transpiler/types/symbols/SymbolGuards.ts +43 -0
  174. package/src/transpiler/types/symbols/TAnySymbol.ts +22 -0
  175. package/src/transpiler/types/symbols/TSymbol.ts +32 -0
  176. package/src/transpiler/types/symbols/__tests__/IBaseSymbol.test.ts +56 -0
  177. package/src/transpiler/types/symbols/__tests__/SymbolGuards.test.ts +57 -0
  178. package/src/transpiler/types/symbols/c/ICBaseSymbol.ts +28 -0
  179. package/src/transpiler/types/symbols/c/ICEnumMemberSymbol.ts +17 -0
  180. package/src/transpiler/types/symbols/c/ICEnumSymbol.ts +17 -0
  181. package/src/transpiler/types/symbols/c/ICFieldInfo.ts +16 -0
  182. package/src/transpiler/types/symbols/c/ICFunctionSymbol.ts +21 -0
  183. package/src/transpiler/types/symbols/c/ICParameterInfo.ts +19 -0
  184. package/src/transpiler/types/symbols/c/ICStructSymbol.ts +21 -0
  185. package/src/transpiler/types/symbols/c/ICTypedefSymbol.ts +14 -0
  186. package/src/transpiler/types/symbols/c/ICVariableSymbol.ts +26 -0
  187. package/src/transpiler/types/symbols/c/TCSymbol.ts +26 -0
  188. package/src/transpiler/types/symbols/cpp/ICppBaseSymbol.ts +31 -0
  189. package/src/transpiler/types/symbols/cpp/ICppClassSymbol.ts +15 -0
  190. package/src/transpiler/types/symbols/cpp/ICppEnumMemberSymbol.ts +14 -0
  191. package/src/transpiler/types/symbols/cpp/ICppEnumSymbol.ts +14 -0
  192. package/src/transpiler/types/symbols/cpp/ICppFieldInfo.ts +16 -0
  193. package/src/transpiler/types/symbols/cpp/ICppFunctionSymbol.ts +21 -0
  194. package/src/transpiler/types/symbols/cpp/ICppNamespaceSymbol.ts +11 -0
  195. package/src/transpiler/types/symbols/cpp/ICppParameterInfo.ts +19 -0
  196. package/src/transpiler/types/symbols/cpp/ICppStructSymbol.ts +16 -0
  197. package/src/transpiler/types/symbols/cpp/ICppTypeAliasSymbol.ts +14 -0
  198. package/src/transpiler/types/symbols/cpp/ICppVariableSymbol.ts +23 -0
  199. package/src/transpiler/types/symbols/cpp/TCppSymbol.ts +30 -0
  200. package/src/utils/CppNamespaceUtils.ts +3 -4
  201. package/src/utils/FunctionUtils.ts +92 -0
  202. package/src/utils/ParameterUtils.ts +55 -0
  203. package/src/utils/PrimitiveKindUtils.ts +33 -0
  204. package/src/utils/ScopeUtils.ts +105 -0
  205. package/src/utils/TTypeUtils.ts +159 -0
  206. package/src/utils/TypeResolver.ts +132 -0
  207. package/src/utils/__tests__/CppNamespaceUtils.test.ts +92 -99
  208. package/src/utils/__tests__/FunctionUtils.test.ts +284 -0
  209. package/src/utils/__tests__/ParameterUtils.test.ts +174 -0
  210. package/src/utils/__tests__/PrimitiveKindUtils.test.ts +59 -0
  211. package/src/utils/__tests__/ScopeUtils.test.ts +53 -0
  212. package/src/utils/__tests__/TTypeUtils.test.ts +245 -0
  213. package/src/utils/__tests__/TypeResolver.test.ts +332 -0
  214. package/src/utils/cache/CacheManager.ts +91 -50
  215. package/src/utils/cache/__tests__/CacheManager.test.ts +180 -114
  216. package/src/transpiler/logic/symbols/AutoConstUpdater.ts +0 -93
  217. package/src/transpiler/logic/symbols/CSymbolCollector.ts +0 -648
  218. package/src/transpiler/logic/symbols/CppSymbolCollector.ts +0 -874
  219. package/src/transpiler/logic/symbols/SymbolCollectorContext.ts +0 -68
  220. package/src/transpiler/logic/symbols/__tests__/AutoConstUpdater.test.ts +0 -418
  221. package/src/transpiler/logic/symbols/__tests__/CSymbolCollector.test.ts +0 -685
  222. package/src/transpiler/logic/symbols/__tests__/CppSymbolCollector.test.ts +0 -1146
  223. package/src/transpiler/logic/symbols/__tests__/SymbolCollectorContext.test.ts +0 -290
  224. package/src/transpiler/logic/symbols/__tests__/cTestHelpers.ts +0 -43
  225. package/src/transpiler/logic/symbols/__tests__/cppTestHelpers.ts +0 -40
  226. package/src/transpiler/logic/symbols/cnext/__tests__/TSymbolAdapter.test.ts +0 -595
  227. package/src/transpiler/logic/symbols/cnext/adapters/TSymbolAdapter.ts +0 -345
  228. package/src/transpiler/logic/symbols/types/IBaseSymbol.ts +0 -27
  229. package/src/transpiler/logic/symbols/types/IBitmapSymbol.ts +0 -23
  230. package/src/transpiler/logic/symbols/types/ICollectorContext.ts +0 -19
  231. package/src/transpiler/logic/symbols/types/IConflict.ts +0 -20
  232. package/src/transpiler/logic/symbols/types/IFieldInfo.ts +0 -18
  233. package/src/transpiler/logic/symbols/types/IFunctionSymbol.ts +0 -25
  234. package/src/transpiler/logic/symbols/types/IParameterInfo.ts +0 -24
  235. package/src/transpiler/logic/symbols/types/IRegisterSymbol.ts +0 -20
  236. package/src/transpiler/logic/symbols/types/IScopeSymbol.ts +0 -19
  237. package/src/transpiler/logic/symbols/types/IStructSymbol.ts +0 -16
  238. package/src/transpiler/logic/symbols/types/IVariableSymbol.ts +0 -30
  239. package/src/transpiler/logic/symbols/types/TSymbol.ts +0 -36
  240. package/src/transpiler/logic/symbols/types/__tests__/SymbolGuards.test.ts +0 -244
  241. package/src/transpiler/logic/symbols/types/typeGuards.ts +0 -44
  242. package/src/utils/types/ESymbolKind.ts +0 -19
  243. package/src/utils/types/ISymbol.ts +0 -64
  244. /package/src/transpiler/{types → constants}/BITMAP_BACKING_TYPE.ts +0 -0
  245. /package/src/transpiler/{types → constants}/BITMAP_SIZE.ts +0 -0
  246. /package/src/transpiler/{output/codegen → logic/analysis}/helpers/TransitiveModificationPropagator.ts +0 -0
  247. /package/src/transpiler/{output/codegen → logic/analysis}/helpers/__tests__/TransitiveModificationPropagator.test.ts +0 -0
@@ -1,12 +1,14 @@
1
1
  /**
2
2
  * EnumCollector - Extracts enum type declarations from parse trees.
3
3
  * ADR-017: Enums provide named integer constants with auto-increment support.
4
+ *
5
+ * Produces TType-based IEnumSymbol with proper IScopeSymbol references.
4
6
  */
5
7
 
6
8
  import * as Parser from "../../../parser/grammar/CNextParser";
7
9
  import ESourceLanguage from "../../../../../utils/types/ESourceLanguage";
8
- import ESymbolKind from "../../../../../utils/types/ESymbolKind";
9
- import IEnumSymbol from "../../types/IEnumSymbol";
10
+ import IEnumSymbol from "../../../../types/symbols/IEnumSymbol";
11
+ import IScopeSymbol from "../../../../types/symbols/IScopeSymbol";
10
12
  import ExpressionEvaluator from "../utils/ExpressionEvaluator";
11
13
 
12
14
  class EnumCollector {
@@ -15,17 +17,16 @@ class EnumCollector {
15
17
  *
16
18
  * @param ctx The enum declaration context
17
19
  * @param sourceFile Source file path
18
- * @param scopeName Optional scope name for nested enums
19
- * @returns The enum symbol
20
+ * @param scope The scope this enum belongs to (IScopeSymbol)
21
+ * @returns The enum symbol with proper scope reference
20
22
  * @throws Error if any member has a negative value
21
23
  */
22
24
  static collect(
23
25
  ctx: Parser.EnumDeclarationContext,
24
26
  sourceFile: string,
25
- scopeName?: string,
27
+ scope: IScopeSymbol,
26
28
  ): IEnumSymbol {
27
29
  const name = ctx.IDENTIFIER().getText();
28
- const fullName = scopeName ? `${scopeName}_${name}` : name;
29
30
  const line = ctx.start?.line ?? 0;
30
31
 
31
32
  // Collect member values with auto-increment
@@ -42,7 +43,7 @@ class EnumCollector {
42
43
 
43
44
  if (value < 0) {
44
45
  throw new Error(
45
- `Error: Negative values not allowed in enum (found ${value} in ${fullName}.${memberName})`,
46
+ `Error: Negative values not allowed in enum (found ${value} in ${name}.${memberName})`,
46
47
  );
47
48
  }
48
49
 
@@ -54,13 +55,13 @@ class EnumCollector {
54
55
  }
55
56
 
56
57
  return {
57
- name: fullName,
58
- parent: scopeName,
58
+ kind: "enum",
59
+ name,
60
+ scope,
59
61
  sourceFile,
60
62
  sourceLine: line,
61
63
  sourceLanguage: ESourceLanguage.CNext,
62
64
  isExported: true,
63
- kind: ESymbolKind.Enum,
64
65
  members,
65
66
  };
66
67
  }
@@ -1,14 +1,18 @@
1
1
  /**
2
2
  * FunctionCollector - Extracts function declarations from parse trees.
3
3
  * Handles return types, parameters, visibility, and signature generation.
4
+ *
5
+ * Produces TType-based IFunctionSymbol with proper IScopeSymbol references.
4
6
  */
5
7
 
6
8
  import * as Parser from "../../../parser/grammar/CNextParser";
7
9
  import ESourceLanguage from "../../../../../utils/types/ESourceLanguage";
8
- import ESymbolKind from "../../../../../utils/types/ESymbolKind";
9
- import IFunctionSymbol from "../../types/IFunctionSymbol";
10
- import IParameterInfo from "../../types/IParameterInfo";
10
+ import IFunctionSymbol from "../../../../types/symbols/IFunctionSymbol";
11
+ import IParameterInfo from "../../../../types/symbols/IParameterInfo";
12
+ import IScopeSymbol from "../../../../types/symbols/IScopeSymbol";
13
+ import TypeResolver from "../../../../../utils/TypeResolver";
11
14
  import TypeUtils from "../utils/TypeUtils";
15
+ import SymbolRegistry from "../../../../state/SymbolRegistry";
12
16
 
13
17
  class FunctionCollector {
14
18
  /**
@@ -16,49 +20,89 @@ class FunctionCollector {
16
20
  *
17
21
  * @param ctx The function declaration context
18
22
  * @param sourceFile Source file path
19
- * @param scopeName Optional scope name for nested functions
23
+ * @param scope The scope this function belongs to (IScopeSymbol)
24
+ * @param body AST reference for the function body
20
25
  * @param visibility Visibility for scope functions (default "private")
21
- * @returns The function symbol
26
+ * @returns The function symbol with TType-based types and scope reference
22
27
  */
23
28
  static collect(
24
29
  ctx: Parser.FunctionDeclarationContext,
25
30
  sourceFile: string,
26
- scopeName?: string,
31
+ scope: IScopeSymbol,
32
+ body: Parser.BlockContext | null,
27
33
  visibility: "public" | "private" = "private",
28
34
  ): IFunctionSymbol {
29
35
  const name = ctx.IDENTIFIER().getText();
30
- const fullName = scopeName ? `${scopeName}_${name}` : name;
31
36
  const line = ctx.start?.line ?? 0;
32
37
 
33
- // Get return type
38
+ // Get return type string and convert to TType
34
39
  const returnTypeCtx = ctx.type();
35
- const returnType = TypeUtils.getTypeName(returnTypeCtx, scopeName);
40
+ const scopeName = scope.name === "" ? undefined : scope.name;
41
+ const returnTypeStr = TypeUtils.getTypeName(returnTypeCtx, scopeName);
42
+ const returnType = TypeResolver.resolve(returnTypeStr);
36
43
 
37
- // Collect parameters
44
+ // Collect parameters with TType
38
45
  const params = ctx.parameterList()?.parameter() ?? [];
39
46
  const parameters = FunctionCollector.collectParameters(params, scopeName);
40
47
 
41
- // Generate signature for overload detection
42
- const paramTypes = parameters.map((p) => p.type);
43
- const signature = `${returnType} ${fullName}(${paramTypes.join(", ")})`;
44
-
45
48
  return {
46
- name: fullName,
47
- parent: scopeName,
49
+ kind: "function",
50
+ name,
51
+ scope,
52
+ parameters,
53
+ returnType,
54
+ visibility,
55
+ body,
48
56
  sourceFile,
49
57
  sourceLine: line,
50
58
  sourceLanguage: ESourceLanguage.CNext,
51
59
  isExported: visibility === "public",
52
- kind: ESymbolKind.Function,
53
- returnType,
54
- parameters,
55
- visibility,
56
- signature,
57
60
  };
58
61
  }
59
62
 
63
+ /**
64
+ * Collect a function declaration and register it in SymbolRegistry.
65
+ *
66
+ * This method:
67
+ * 1. Gets or creates the appropriate scope in SymbolRegistry
68
+ * 2. Collects the function with TType-based types
69
+ * 3. Registers the function in that scope
70
+ *
71
+ * @param ctx The function declaration context
72
+ * @param sourceFile Source file path
73
+ * @param scopeName Optional scope name for nested functions
74
+ * @param body AST reference for the function body
75
+ * @param visibility Visibility for scope functions (default "private")
76
+ * @returns The function symbol
77
+ */
78
+ static collectAndRegister(
79
+ ctx: Parser.FunctionDeclarationContext,
80
+ sourceFile: string,
81
+ scopeName: string | undefined,
82
+ body: Parser.BlockContext,
83
+ visibility: "public" | "private" = "private",
84
+ ): IFunctionSymbol {
85
+ // 1. Get or create the scope in SymbolRegistry
86
+ const scope = SymbolRegistry.getOrCreateScope(scopeName ?? "");
87
+
88
+ // 2. Collect function with TType-based types and scope reference
89
+ const symbol = FunctionCollector.collect(
90
+ ctx,
91
+ sourceFile,
92
+ scope,
93
+ body,
94
+ visibility,
95
+ );
96
+
97
+ // 3. Register in SymbolRegistry
98
+ SymbolRegistry.registerFunction(symbol);
99
+
100
+ return symbol;
101
+ }
102
+
60
103
  /**
61
104
  * Extract parameter information from parameter contexts.
105
+ * Converts type strings to TType.
62
106
  */
63
107
  private static collectParameters(
64
108
  params: Parser.ParameterContext[],
@@ -67,34 +111,39 @@ class FunctionCollector {
67
111
  return params.map((p) => {
68
112
  const name = p.IDENTIFIER().getText();
69
113
  const typeCtx = p.type();
70
- const type = TypeUtils.getTypeName(typeCtx, scopeName);
114
+ const typeStr = TypeUtils.getTypeName(typeCtx, scopeName);
115
+ const type = TypeResolver.resolve(typeStr);
71
116
  const isConst = p.constModifier() !== null;
72
117
 
73
118
  // Check for C-Next style array type (u8[8] param, u8[4][4] param, u8[] param)
74
119
  const arrayTypeCtx = typeCtx.arrayType();
75
- const hasArrayType = arrayTypeCtx !== null;
120
+ const isArray = arrayTypeCtx !== null;
76
121
 
77
122
  // Extract array dimensions from arrayType syntax (supports multi-dimensional)
78
- const arrayDimensions: string[] = [];
79
- if (hasArrayType) {
123
+ const arrayDimensions: (number | string)[] = [];
124
+ if (isArray) {
80
125
  for (const dim of arrayTypeCtx.arrayTypeDimension()) {
81
126
  const sizeExpr = dim.expression();
82
- arrayDimensions.push(sizeExpr ? sizeExpr.getText() : "");
127
+ if (sizeExpr) {
128
+ const dimStr = sizeExpr.getText();
129
+ const dimNum = Number.parseInt(dimStr, 10);
130
+ // Convert numeric strings to numbers, keep others as strings
131
+ arrayDimensions.push(Number.isNaN(dimNum) ? dimStr : dimNum);
132
+ } else {
133
+ // Unbounded array dimension
134
+ arrayDimensions.push("");
135
+ }
83
136
  }
84
137
  }
85
138
 
86
- const paramInfo: IParameterInfo = {
139
+ return {
87
140
  name,
88
141
  type,
89
142
  isConst,
90
- isArray: hasArrayType,
143
+ isArray,
144
+ arrayDimensions:
145
+ arrayDimensions.length > 0 ? arrayDimensions : undefined,
91
146
  };
92
-
93
- if (arrayDimensions.length > 0) {
94
- paramInfo.arrayDimensions = arrayDimensions;
95
- }
96
-
97
- return paramInfo;
98
147
  });
99
148
  }
100
149
  }
@@ -1,13 +1,15 @@
1
1
  /**
2
2
  * RegisterCollector - Extracts register block declarations from parse trees.
3
3
  * Registers provide typed access to memory-mapped I/O locations.
4
+ *
5
+ * Produces TType-based IRegisterSymbol with proper IScopeSymbol references.
4
6
  */
5
7
 
6
8
  import * as Parser from "../../../parser/grammar/CNextParser";
7
9
  import ESourceLanguage from "../../../../../utils/types/ESourceLanguage";
8
- import ESymbolKind from "../../../../../utils/types/ESymbolKind";
9
- import IRegisterSymbol from "../../types/IRegisterSymbol";
10
- import IRegisterMemberInfo from "../../types/IRegisterMemberInfo";
10
+ import IRegisterSymbol from "../../../../types/symbols/IRegisterSymbol";
11
+ import IRegisterMemberInfo from "../../../../types/symbols/IRegisterMemberInfo";
12
+ import IScopeSymbol from "../../../../types/symbols/IScopeSymbol";
11
13
  import TypeUtils from "../utils/TypeUtils";
12
14
 
13
15
  /** Access mode type for register members */
@@ -20,18 +22,18 @@ class RegisterCollector {
20
22
  * @param ctx The register declaration context
21
23
  * @param sourceFile Source file path
22
24
  * @param knownBitmaps Set of known bitmap type names for reference resolution
23
- * @param scopeName Optional scope name for nested registers
24
- * @returns The register symbol
25
+ * @param scope The scope this register belongs to (IScopeSymbol)
26
+ * @returns The register symbol with proper scope reference
25
27
  */
26
28
  static collect(
27
29
  ctx: Parser.RegisterDeclarationContext,
28
30
  sourceFile: string,
29
31
  knownBitmaps: Set<string>,
30
- scopeName?: string,
32
+ scope: IScopeSymbol,
31
33
  ): IRegisterSymbol {
32
34
  const name = ctx.IDENTIFIER().getText();
33
- const fullName = scopeName ? `${scopeName}_${name}` : name;
34
35
  const line = ctx.start?.line ?? 0;
36
+ const scopeName = scope.name === "" ? undefined : scope.name;
35
37
 
36
38
  // Get base address
37
39
  const baseAddress = ctx.expression().getText();
@@ -48,32 +50,34 @@ class RegisterCollector {
48
50
  const typeName = TypeUtils.getTypeName(member.type(), scopeName);
49
51
  const cType = TypeUtils.cnextTypeToCType(typeName);
50
52
 
51
- const memberInfo: IRegisterMemberInfo = {
52
- offset,
53
- cType,
54
- access: accessMod,
55
- };
56
-
57
53
  // Check if member type is a bitmap
58
54
  // Try both scoped name and plain name for bitmap lookup
59
55
  const scopedTypeName = scopeName ? `${scopeName}_${typeName}` : typeName;
56
+ let bitmapType: string | undefined;
60
57
  if (knownBitmaps.has(scopedTypeName)) {
61
- memberInfo.bitmapType = scopedTypeName;
58
+ bitmapType = scopedTypeName;
62
59
  } else if (knownBitmaps.has(typeName)) {
63
- memberInfo.bitmapType = typeName;
60
+ bitmapType = typeName;
64
61
  }
65
62
 
63
+ const memberInfo: IRegisterMemberInfo = {
64
+ offset,
65
+ cType,
66
+ access: accessMod,
67
+ bitmapType,
68
+ };
69
+
66
70
  members.set(memberName, memberInfo);
67
71
  }
68
72
 
69
73
  return {
70
- name: fullName,
71
- parent: scopeName,
74
+ kind: "register",
75
+ name,
76
+ scope,
72
77
  sourceFile,
73
78
  sourceLine: line,
74
79
  sourceLanguage: ESourceLanguage.CNext,
75
80
  isExported: true,
76
- kind: ESymbolKind.Register,
77
81
  baseAddress,
78
82
  members,
79
83
  };
@@ -1,14 +1,17 @@
1
1
  /**
2
2
  * ScopeCollector - Extracts scope declarations and their nested members.
3
3
  * ADR-016: Scopes group related functions and control member visibility.
4
+ *
5
+ * Produces TType-based symbols with proper IScopeSymbol references.
6
+ * Uses SymbolRegistry for scope management.
4
7
  */
5
8
 
6
9
  import * as Parser from "../../../parser/grammar/CNextParser";
7
10
  import ESourceLanguage from "../../../../../utils/types/ESourceLanguage";
8
- import ESymbolKind from "../../../../../utils/types/ESymbolKind";
9
- import IScopeSymbol from "../../types/IScopeSymbol";
10
- import TSymbol from "../../types/TSymbol";
11
+ import TSymbol from "../../../../types/symbols/TSymbol";
12
+ import TVisibility from "../../../../types/TVisibility";
11
13
  import IScopeCollectorResult from "../types/IScopeCollectorResult";
14
+ import SymbolRegistry from "../../../../state/SymbolRegistry";
12
15
  import BitmapCollector from "./BitmapCollector";
13
16
  import EnumCollector from "./EnumCollector";
14
17
  import StructCollector from "./StructCollector";
@@ -20,6 +23,13 @@ class ScopeCollector {
20
23
  /**
21
24
  * Collect a scope declaration and all its nested members.
22
25
  *
26
+ * Uses SymbolRegistry to get/create the scope, ensuring proper scope
27
+ * references in all member symbols.
28
+ *
29
+ * **Side-effect**: This method calls SymbolRegistry.getOrCreateScope(),
30
+ * which creates the scope in global state if it doesn't exist. Tests
31
+ * should call SymbolRegistry.reset() in beforeEach to ensure isolation.
32
+ *
23
33
  * @param ctx The scope declaration context
24
34
  * @param sourceFile Source file path
25
35
  * @param knownBitmaps Set of known bitmap type names for register resolution
@@ -35,28 +45,47 @@ class ScopeCollector {
35
45
  const scopeName = ctx.IDENTIFIER().getText();
36
46
  const line = ctx.start?.line ?? 0;
37
47
 
38
- const memberNames: string[] = [];
39
- const memberVisibility = new Map<string, "public" | "private">();
48
+ // Get or create the scope via SymbolRegistry
49
+ const scope = SymbolRegistry.getOrCreateScope(scopeName);
50
+
51
+ // Update scope metadata (cast to mutable for initialization)
52
+ const mutableScope = scope as {
53
+ sourceFile: string;
54
+ sourceLine: number;
55
+ sourceLanguage: ESourceLanguage;
56
+ isExported: boolean;
57
+ };
58
+ mutableScope.sourceFile = sourceFile;
59
+ mutableScope.sourceLine = line;
60
+ mutableScope.sourceLanguage = ESourceLanguage.CNext;
61
+ mutableScope.isExported = true;
62
+
63
+ // Cast readonly collections to mutable (scope is being populated)
64
+ const memberVisibility = scope.memberVisibility as unknown as Map<
65
+ string,
66
+ TVisibility
67
+ >;
68
+ const members = scope.members as unknown as string[];
40
69
  const memberSymbols: TSymbol[] = [];
41
70
 
42
71
  for (const member of ctx.scopeMember()) {
43
72
  // ADR-016: Extract visibility (private by default)
44
73
  const visibilityMod = member.visibilityModifier();
45
- const visibility: "public" | "private" =
46
- (visibilityMod?.getText() as "public" | "private") ?? "private";
74
+ const visibility: TVisibility =
75
+ (visibilityMod?.getText() as TVisibility) ?? "private";
47
76
  const isPublic = visibility === "public";
48
77
 
49
78
  // Handle variable declarations
50
79
  if (member.variableDeclaration()) {
51
80
  const varDecl = member.variableDeclaration()!;
52
81
  const varName = varDecl.IDENTIFIER().getText();
53
- memberNames.push(varName);
54
82
  memberVisibility.set(varName, visibility);
83
+ members.push(varName);
55
84
 
56
85
  const varSymbol = VariableCollector.collect(
57
86
  varDecl,
58
87
  sourceFile,
59
- scopeName,
88
+ scope,
60
89
  isPublic,
61
90
  constValues,
62
91
  );
@@ -67,13 +96,16 @@ class ScopeCollector {
67
96
  if (member.functionDeclaration()) {
68
97
  const funcDecl = member.functionDeclaration()!;
69
98
  const funcName = funcDecl.IDENTIFIER().getText();
70
- memberNames.push(funcName);
71
99
  memberVisibility.set(funcName, visibility);
100
+ members.push(funcName);
72
101
 
73
- const funcSymbol = FunctionCollector.collect(
102
+ // Use collectAndRegister to populate both memberSymbols and SymbolRegistry
103
+ const body = funcDecl.block();
104
+ const funcSymbol = FunctionCollector.collectAndRegister(
74
105
  funcDecl,
75
106
  sourceFile,
76
107
  scopeName,
108
+ body,
77
109
  visibility,
78
110
  );
79
111
  memberSymbols.push(funcSymbol);
@@ -83,14 +115,10 @@ class ScopeCollector {
83
115
  if (member.enumDeclaration()) {
84
116
  const enumDecl = member.enumDeclaration()!;
85
117
  const enumName = enumDecl.IDENTIFIER().getText();
86
- memberNames.push(enumName);
87
118
  memberVisibility.set(enumName, visibility);
119
+ members.push(enumName);
88
120
 
89
- const enumSymbol = EnumCollector.collect(
90
- enumDecl,
91
- sourceFile,
92
- scopeName,
93
- );
121
+ const enumSymbol = EnumCollector.collect(enumDecl, sourceFile, scope);
94
122
  memberSymbols.push(enumSymbol);
95
123
  }
96
124
 
@@ -98,13 +126,13 @@ class ScopeCollector {
98
126
  if (member.bitmapDeclaration()) {
99
127
  const bitmapDecl = member.bitmapDeclaration()!;
100
128
  const bitmapName = bitmapDecl.IDENTIFIER().getText();
101
- memberNames.push(bitmapName);
102
129
  memberVisibility.set(bitmapName, visibility);
130
+ members.push(bitmapName);
103
131
 
104
132
  const bitmapSymbol = BitmapCollector.collect(
105
133
  bitmapDecl,
106
134
  sourceFile,
107
- scopeName,
135
+ scope,
108
136
  );
109
137
  memberSymbols.push(bitmapSymbol);
110
138
  }
@@ -113,13 +141,14 @@ class ScopeCollector {
113
141
  if (member.structDeclaration()) {
114
142
  const structDecl = member.structDeclaration()!;
115
143
  const structName = structDecl.IDENTIFIER().getText();
116
- memberNames.push(structName);
117
144
  memberVisibility.set(structName, visibility);
145
+ members.push(structName);
118
146
 
119
147
  const structSymbol = StructCollector.collect(
120
148
  structDecl,
121
149
  sourceFile,
122
- scopeName,
150
+ scope,
151
+ constValues,
123
152
  );
124
153
  memberSymbols.push(structSymbol);
125
154
  }
@@ -128,31 +157,20 @@ class ScopeCollector {
128
157
  if (member.registerDeclaration()) {
129
158
  const regDecl = member.registerDeclaration()!;
130
159
  const regName = regDecl.IDENTIFIER().getText();
131
- memberNames.push(regName);
132
160
  memberVisibility.set(regName, visibility);
161
+ members.push(regName);
133
162
 
134
163
  const regSymbol = RegisterCollector.collect(
135
164
  regDecl,
136
165
  sourceFile,
137
166
  knownBitmaps,
138
- scopeName,
167
+ scope,
139
168
  );
140
169
  memberSymbols.push(regSymbol);
141
170
  }
142
171
  }
143
172
 
144
- const scopeSymbol: IScopeSymbol = {
145
- name: scopeName,
146
- sourceFile,
147
- sourceLine: line,
148
- sourceLanguage: ESourceLanguage.CNext,
149
- isExported: true,
150
- kind: ESymbolKind.Namespace,
151
- members: memberNames,
152
- memberVisibility,
153
- };
154
-
155
- return { scopeSymbol, memberSymbols };
173
+ return { scopeSymbol: scope, memberSymbols };
156
174
  }
157
175
  }
158
176
 
@@ -1,13 +1,16 @@
1
1
  /**
2
2
  * StructCollector - Extracts struct type declarations from parse trees.
3
3
  * Handles fields with types, arrays, and const modifiers.
4
+ *
5
+ * Produces TType-based IStructSymbol with proper IScopeSymbol references.
4
6
  */
5
7
 
6
8
  import * as Parser from "../../../parser/grammar/CNextParser";
7
9
  import ESourceLanguage from "../../../../../utils/types/ESourceLanguage";
8
- import ESymbolKind from "../../../../../utils/types/ESymbolKind";
9
- import IStructSymbol from "../../types/IStructSymbol";
10
- import IFieldInfo from "../../types/IFieldInfo";
10
+ import IStructSymbol from "../../../../types/symbols/IStructSymbol";
11
+ import IFieldInfo from "../../../../types/symbols/IFieldInfo";
12
+ import IScopeSymbol from "../../../../types/symbols/IScopeSymbol";
13
+ import TypeResolver from "../../../../../utils/TypeResolver";
11
14
  import TypeUtils from "../utils/TypeUtils";
12
15
  import LiteralUtils from "../../../../../utils/LiteralUtils";
13
16
 
@@ -51,7 +54,7 @@ function processArrayTypeSyntax(
51
54
  function processStringField(
52
55
  stringCtx: Parser.StringTypeContext,
53
56
  arrayDims: Parser.ArrayDimensionContext[],
54
- dimensions: number[],
57
+ dimensions: (number | string)[],
55
58
  constValues?: Map<string, number>,
56
59
  ): boolean {
57
60
  const intLiteral = stringCtx.INTEGER_LITERAL();
@@ -94,7 +97,7 @@ function tryResolveExpressionDimension(
94
97
  */
95
98
  function parseArrayDimensions(
96
99
  arrayDims: Parser.ArrayDimensionContext[],
97
- dimensions: number[],
100
+ dimensions: (number | string)[],
98
101
  constValues?: Map<string, number>,
99
102
  ): void {
100
103
  for (const dim of arrayDims) {
@@ -114,58 +117,65 @@ class StructCollector {
114
117
  *
115
118
  * @param ctx The struct declaration context
116
119
  * @param sourceFile Source file path
117
- * @param scopeName Optional scope name for nested structs
120
+ * @param scope The scope this struct belongs to (IScopeSymbol)
118
121
  * @param constValues Map of constant names to their numeric values (for resolving array dimensions)
119
- * @returns The struct symbol
122
+ * @returns The struct symbol with TType-based types and scope reference
120
123
  */
121
124
  static collect(
122
125
  ctx: Parser.StructDeclarationContext,
123
126
  sourceFile: string,
124
- scopeName?: string,
127
+ scope: IScopeSymbol,
125
128
  constValues?: Map<string, number>,
126
129
  ): IStructSymbol {
127
130
  const name = ctx.IDENTIFIER().getText();
128
- const fullName = scopeName ? `${scopeName}_${name}` : name;
129
131
  const line = ctx.start?.line ?? 0;
132
+ const scopeName = scope.name === "" ? undefined : scope.name;
130
133
 
131
134
  const fields = new Map<string, IFieldInfo>();
132
135
 
133
136
  for (const member of ctx.structMember()) {
137
+ const fieldName = member.IDENTIFIER().getText();
134
138
  const fieldInfo = StructCollector.collectField(
135
139
  member,
140
+ fieldName,
136
141
  scopeName,
137
142
  constValues,
138
143
  );
139
- fields.set(member.IDENTIFIER().getText(), fieldInfo);
144
+ fields.set(fieldName, fieldInfo);
140
145
  }
141
146
 
142
147
  return {
143
- name: fullName,
144
- parent: scopeName,
148
+ kind: "struct",
149
+ name,
150
+ scope,
145
151
  sourceFile,
146
152
  sourceLine: line,
147
153
  sourceLanguage: ESourceLanguage.CNext,
148
154
  isExported: true,
149
- kind: ESymbolKind.Struct,
150
155
  fields,
151
156
  };
152
157
  }
153
158
 
154
159
  /**
155
160
  * Collect a single struct field and return its IFieldInfo.
161
+ * Now includes name and TType-based type.
156
162
  */
157
163
  private static collectField(
158
164
  member: Parser.StructMemberContext,
165
+ fieldName: string,
159
166
  scopeName?: string,
160
167
  constValues?: Map<string, number>,
161
168
  ): IFieldInfo {
162
169
  const typeCtx = member.type();
163
- const fieldType = TypeUtils.getTypeName(typeCtx, scopeName);
170
+ const fieldTypeStr = TypeUtils.getTypeName(typeCtx, scopeName);
171
+ const fieldType = TypeResolver.resolve(fieldTypeStr);
164
172
  // Note: C-Next struct members don't have const modifier in grammar
165
173
  const isConst = false;
174
+ // C-Next struct members don't have atomic modifier
175
+ const isAtomic = false;
166
176
 
167
177
  const arrayDims = member.arrayDimension();
168
- const dimensions: number[] = [];
178
+ const dimensions: (number | string)[] = [];
169
179
  let isArray = false;
170
180
 
171
181
  // Check for C-Next style arrayType syntax: Item[3] items -> typeCtx.arrayType()
@@ -200,17 +210,14 @@ class StructCollector {
200
210
  parseArrayDimensions(arrayDims, dimensions, constValues);
201
211
  }
202
212
 
203
- const fieldInfo: IFieldInfo = {
213
+ return {
214
+ name: fieldName,
204
215
  type: fieldType,
205
- isArray,
206
216
  isConst,
217
+ isAtomic,
218
+ isArray,
219
+ dimensions: dimensions.length > 0 ? dimensions : undefined,
207
220
  };
208
-
209
- if (dimensions.length > 0) {
210
- fieldInfo.dimensions = dimensions;
211
- }
212
-
213
- return fieldInfo;
214
221
  }
215
222
  }
216
223