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,15 @@
1
1
  /**
2
2
  * VariableCollector - Extracts variable declarations from parse trees.
3
3
  * Handles types, const modifier, arrays, and initial values.
4
+ *
5
+ * Produces TType-based IVariableSymbol 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 IVariableSymbol from "../../types/IVariableSymbol";
10
+ import IVariableSymbol from "../../../../types/symbols/IVariableSymbol";
11
+ import IScopeSymbol from "../../../../types/symbols/IScopeSymbol";
12
+ import TypeResolver from "../../../../../utils/TypeResolver";
10
13
  import ArrayInitializerUtils from "../utils/ArrayInitializerUtils";
11
14
  import TypeUtils from "../utils/TypeUtils";
12
15
  import LiteralUtils from "../../../../../utils/LiteralUtils";
@@ -102,25 +105,26 @@ class VariableCollector {
102
105
  *
103
106
  * @param ctx The variable declaration context
104
107
  * @param sourceFile Source file path
105
- * @param scopeName Optional scope name for scoped variables
108
+ * @param scope The scope this variable belongs to (IScopeSymbol)
106
109
  * @param isPublic Whether this variable is public (default true for top-level)
107
110
  * @param constValues Map of constant names to their numeric values (for resolving array dimensions)
108
- * @returns The variable symbol
111
+ * @returns The variable symbol with TType-based types and scope reference
109
112
  */
110
113
  static collect(
111
114
  ctx: Parser.VariableDeclarationContext,
112
115
  sourceFile: string,
113
- scopeName?: string,
116
+ scope: IScopeSymbol,
114
117
  isPublic: boolean = true,
115
118
  constValues?: Map<string, number>,
116
119
  ): IVariableSymbol {
117
120
  const name = ctx.IDENTIFIER().getText();
118
- const fullName = scopeName ? `${scopeName}_${name}` : name;
119
121
  const line = ctx.start?.line ?? 0;
120
122
 
121
- // Get type
123
+ // Get type string and convert to TType
122
124
  const typeCtx = ctx.type();
123
- const type = TypeUtils.getTypeName(typeCtx, scopeName);
125
+ const scopeName = scope.name === "" ? undefined : scope.name;
126
+ const typeStr = TypeUtils.getTypeName(typeCtx, scopeName);
127
+ const type = TypeResolver.resolve(typeStr);
124
128
 
125
129
  // Check for const modifier
126
130
  const isConst = ctx.constModifier() !== null;
@@ -160,28 +164,23 @@ class VariableCollector {
160
164
  // Issue #282: Capture initial value for const inlining
161
165
  const initialValue = initExpr?.getText();
162
166
 
167
+ // Build base symbol
163
168
  const symbol: IVariableSymbol = {
164
- name: fullName,
165
- parent: scopeName,
169
+ kind: "variable",
170
+ name,
171
+ scope,
166
172
  sourceFile,
167
173
  sourceLine: line,
168
174
  sourceLanguage: ESourceLanguage.CNext,
169
175
  isExported: isPublic,
170
- kind: ESymbolKind.Variable,
171
176
  type,
172
177
  isConst,
173
178
  isAtomic,
174
179
  isArray,
180
+ arrayDimensions: arrayDimensions.length > 0 ? arrayDimensions : undefined,
181
+ initialValue,
175
182
  };
176
183
 
177
- if (arrayDimensions.length > 0) {
178
- symbol.arrayDimensions = arrayDimensions;
179
- }
180
-
181
- if (initialValue !== undefined) {
182
- symbol.initialValue = initialValue;
183
- }
184
-
185
184
  return symbol;
186
185
  }
187
186
  }
@@ -1,10 +1,13 @@
1
1
  /**
2
2
  * CNextResolver - Orchestrates symbol collection from C-Next parse trees.
3
3
  * Uses two-pass collection to handle forward references (bitmaps before registers).
4
+ *
5
+ * Produces TType-based symbols with proper IScopeSymbol references.
4
6
  */
5
7
 
6
8
  import * as Parser from "../../parser/grammar/CNextParser";
7
- import TSymbol from "../types/TSymbol";
9
+ import TSymbol from "../../../types/symbols/TSymbol";
10
+ import SymbolRegistry from "../../../state/SymbolRegistry";
8
11
  import LiteralUtils from "../../../../utils/LiteralUtils";
9
12
  import BitmapCollector from "./collectors/BitmapCollector";
10
13
  import EnumCollector from "./collectors/EnumCollector";
@@ -149,12 +152,19 @@ class CNextResolver {
149
152
  knownBitmaps: Set<string>,
150
153
  constValues: Map<string, number>,
151
154
  ): void {
155
+ const globalScope = SymbolRegistry.getGlobalScope();
156
+
152
157
  for (const decl of tree.declaration()) {
153
158
  // Top-level bitmaps
154
159
  if (decl.bitmapDeclaration()) {
155
160
  const bitmapCtx = decl.bitmapDeclaration()!;
156
- const symbol = BitmapCollector.collect(bitmapCtx, sourceFile);
161
+ const symbol = BitmapCollector.collect(
162
+ bitmapCtx,
163
+ sourceFile,
164
+ globalScope,
165
+ );
157
166
  symbols.push(symbol);
167
+ // Use mangled name (global bitmaps have no scope prefix)
158
168
  knownBitmaps.add(symbol.name);
159
169
  }
160
170
 
@@ -183,17 +193,16 @@ class CNextResolver {
183
193
  constValues: Map<string, number>,
184
194
  ): void {
185
195
  const scopeName = scopeDecl.IDENTIFIER().getText();
196
+ const scope = SymbolRegistry.getOrCreateScope(scopeName);
186
197
 
187
198
  for (const member of scopeDecl.scopeMember()) {
188
199
  if (member.bitmapDeclaration()) {
189
200
  const bitmapCtx = member.bitmapDeclaration()!;
190
- const symbol = BitmapCollector.collect(
191
- bitmapCtx,
192
- sourceFile,
193
- scopeName,
194
- );
201
+ const symbol = BitmapCollector.collect(bitmapCtx, sourceFile, scope);
195
202
  symbols.push(symbol);
196
- knownBitmaps.add(symbol.name);
203
+ // Use mangled name (e.g., "Timer_ControlBits") for scoped bitmaps
204
+ const mangledName = `${scopeName}_${symbol.name}`;
205
+ knownBitmaps.add(mangledName);
197
206
  }
198
207
 
199
208
  // Collect structs early so they're available as types
@@ -202,7 +211,7 @@ class CNextResolver {
202
211
  const symbol = StructCollector.collect(
203
212
  structCtx,
204
213
  sourceFile,
205
- scopeName,
214
+ scope,
206
215
  constValues,
207
216
  );
208
217
  symbols.push(symbol);
@@ -247,6 +256,8 @@ class CNextResolver {
247
256
  knownBitmaps: Set<string>,
248
257
  constValues: Map<string, number>,
249
258
  ): void {
259
+ const globalScope = SymbolRegistry.getGlobalScope();
260
+
250
261
  // Scopes (ScopeCollector handles nested members)
251
262
  if (decl.scopeDeclaration()) {
252
263
  CNextResolver._collectScopeDeclaration(
@@ -264,7 +275,7 @@ class CNextResolver {
264
275
  const symbol = StructCollector.collect(
265
276
  decl.structDeclaration()!,
266
277
  sourceFile,
267
- undefined,
278
+ globalScope,
268
279
  constValues,
269
280
  );
270
281
  symbols.push(symbol);
@@ -273,7 +284,11 @@ class CNextResolver {
273
284
 
274
285
  // Top-level enums
275
286
  if (decl.enumDeclaration()) {
276
- const symbol = EnumCollector.collect(decl.enumDeclaration()!, sourceFile);
287
+ const symbol = EnumCollector.collect(
288
+ decl.enumDeclaration()!,
289
+ sourceFile,
290
+ globalScope,
291
+ );
277
292
  symbols.push(symbol);
278
293
  return;
279
294
  }
@@ -284,6 +299,7 @@ class CNextResolver {
284
299
  decl.registerDeclaration()!,
285
300
  sourceFile,
286
301
  knownBitmaps,
302
+ globalScope,
287
303
  );
288
304
  symbols.push(symbol);
289
305
  return;
@@ -291,9 +307,15 @@ class CNextResolver {
291
307
 
292
308
  // Top-level functions
293
309
  if (decl.functionDeclaration()) {
294
- const symbol = FunctionCollector.collect(
295
- decl.functionDeclaration()!,
310
+ const funcDecl = decl.functionDeclaration()!;
311
+ const body = funcDecl.block();
312
+ // Use collectAndRegister to populate both old symbols and SymbolRegistry
313
+ const symbol = FunctionCollector.collectAndRegister(
314
+ funcDecl,
296
315
  sourceFile,
316
+ undefined, // global scope name (empty string)
317
+ body,
318
+ "private", // default visibility for global functions
297
319
  );
298
320
  symbols.push(symbol);
299
321
  return;
@@ -304,7 +326,7 @@ class CNextResolver {
304
326
  const symbol = VariableCollector.collect(
305
327
  decl.variableDeclaration()!,
306
328
  sourceFile,
307
- undefined,
329
+ globalScope,
308
330
  true,
309
331
  constValues,
310
332
  );
@@ -3,8 +3,8 @@
3
3
  * Contains both the scope symbol itself and all nested member symbols.
4
4
  */
5
5
 
6
- import IScopeSymbol from "../../types/IScopeSymbol";
7
- import TSymbol from "../../types/TSymbol";
6
+ import IScopeSymbol from "../../../../types/symbols/IScopeSymbol";
7
+ import TSymbol from "../../../../types/symbols/TSymbol";
8
8
 
9
9
  interface IScopeCollectorResult {
10
10
  scopeSymbol: IScopeSymbol;
@@ -0,0 +1,27 @@
1
+ /**
2
+ * Utility functions for symbol name manipulation.
3
+ */
4
+
5
+ /**
6
+ * Get the C-mangled name for a symbol (e.g., "Geometry_Point" for Point in Geometry scope).
7
+ * Works with any symbol that has a name and scope reference.
8
+ *
9
+ * @param symbol Object with name and scope.name properties
10
+ * @returns The mangled name (e.g., "Motor_init") or bare name if global scope
11
+ */
12
+ function getMangledName(symbol: {
13
+ name: string;
14
+ scope: { name: string };
15
+ }): string {
16
+ const scopeName = symbol.scope.name;
17
+ if (scopeName === "") {
18
+ return symbol.name;
19
+ }
20
+ return `${scopeName}_${symbol.name}`;
21
+ }
22
+
23
+ class SymbolNameUtils {
24
+ static readonly getMangledName = getMangledName;
25
+ }
26
+
27
+ export default SymbolNameUtils;
@@ -0,0 +1,270 @@
1
+ /**
2
+ * Integration tests for CppResolver.
3
+ * Verifies that the resolver correctly extracts symbols from C++ parse trees.
4
+ */
5
+
6
+ import { describe, it, expect, beforeEach } from "vitest";
7
+ import CppResolver from "../index";
8
+ import SymbolTable from "../../SymbolTable";
9
+ import TestHelpers from "./testHelpers";
10
+
11
+ describe("CppResolver", () => {
12
+ let symbolTable: SymbolTable;
13
+
14
+ beforeEach(() => {
15
+ symbolTable = new SymbolTable();
16
+ });
17
+
18
+ describe("namespace collection", () => {
19
+ it("collects a simple namespace", () => {
20
+ const source = `namespace MyNamespace { }`;
21
+ const tree = TestHelpers.parseCpp(source);
22
+ expect(tree).not.toBeNull();
23
+ const result = CppResolver.resolve(tree!, "test.hpp", symbolTable);
24
+
25
+ expect(result.symbols).toHaveLength(1);
26
+ expect(result.symbols[0]).toMatchObject({
27
+ kind: "namespace",
28
+ name: "MyNamespace",
29
+ sourceFile: "test.hpp",
30
+ });
31
+ });
32
+
33
+ it("collects nested namespaces", () => {
34
+ const source = `namespace Outer { namespace Inner { } }`;
35
+ const tree = TestHelpers.parseCpp(source);
36
+ expect(tree).not.toBeNull();
37
+ const result = CppResolver.resolve(tree!, "test.hpp", symbolTable);
38
+
39
+ expect(result.symbols).toHaveLength(2);
40
+ expect(result.symbols[0].name).toBe("Outer");
41
+ expect(result.symbols[1].name).toBe("Outer::Inner");
42
+ });
43
+ });
44
+
45
+ describe("class collection", () => {
46
+ it("collects a simple class", () => {
47
+ const source = `class MyClass { };`;
48
+ const tree = TestHelpers.parseCpp(source);
49
+ expect(tree).not.toBeNull();
50
+ const result = CppResolver.resolve(tree!, "test.hpp", symbolTable);
51
+
52
+ expect(result.symbols).toHaveLength(1);
53
+ expect(result.symbols[0]).toMatchObject({
54
+ kind: "class",
55
+ name: "MyClass",
56
+ sourceFile: "test.hpp",
57
+ });
58
+ });
59
+
60
+ it("collects a class with fields", () => {
61
+ const source = `class Point { int x; int y; };`;
62
+ const tree = TestHelpers.parseCpp(source);
63
+ expect(tree).not.toBeNull();
64
+ const result = CppResolver.resolve(tree!, "test.hpp", symbolTable);
65
+
66
+ expect(result.symbols).toHaveLength(1);
67
+ const classSymbol = result.symbols[0];
68
+ expect(classSymbol.kind).toBe("class");
69
+
70
+ // Verify fields are stored in symbol table
71
+ const xType = symbolTable.getStructFieldType("Point", "x");
72
+ expect(xType).toBe("int");
73
+
74
+ const yType = symbolTable.getStructFieldType("Point", "y");
75
+ expect(yType).toBe("int");
76
+ });
77
+
78
+ it("collects class in namespace", () => {
79
+ const source = `namespace NS { class MyClass { }; }`;
80
+ const tree = TestHelpers.parseCpp(source);
81
+ expect(tree).not.toBeNull();
82
+ const result = CppResolver.resolve(tree!, "test.hpp", symbolTable);
83
+
84
+ const classSymbol = result.symbols.find((s) => s.kind === "class");
85
+ expect(classSymbol).toBeDefined();
86
+ expect(classSymbol!.name).toBe("NS::MyClass");
87
+ expect(classSymbol!.parent).toBe("NS");
88
+ });
89
+
90
+ it("collects member functions", () => {
91
+ const source = `class MyClass { void doSomething(); int getValue(); };`;
92
+ const tree = TestHelpers.parseCpp(source);
93
+ expect(tree).not.toBeNull();
94
+ const result = CppResolver.resolve(tree!, "test.hpp", symbolTable);
95
+
96
+ const funcSymbols = result.symbols.filter((s) => s.kind === "function");
97
+ expect(funcSymbols).toHaveLength(2);
98
+ expect(funcSymbols[0].name).toBe("MyClass::doSomething");
99
+ expect(funcSymbols[1].name).toBe("MyClass::getValue");
100
+ });
101
+
102
+ it("collects inline member function definitions", () => {
103
+ const source = `class MyClass { void inline_func() { } };`;
104
+ const tree = TestHelpers.parseCpp(source);
105
+ expect(tree).not.toBeNull();
106
+ const result = CppResolver.resolve(tree!, "test.hpp", symbolTable);
107
+
108
+ const funcSymbol = result.symbols.find((s) => s.kind === "function");
109
+ expect(funcSymbol).toBeDefined();
110
+ expect(funcSymbol!.name).toBe("MyClass::inline_func");
111
+ });
112
+ });
113
+
114
+ describe("enum collection", () => {
115
+ it("collects a simple enum", () => {
116
+ const source = `enum Color { RED, GREEN, BLUE };`;
117
+ const tree = TestHelpers.parseCpp(source);
118
+ expect(tree).not.toBeNull();
119
+ const result = CppResolver.resolve(tree!, "test.hpp", symbolTable);
120
+
121
+ expect(result.symbols).toHaveLength(1);
122
+ expect(result.symbols[0]).toMatchObject({
123
+ kind: "enum",
124
+ name: "Color",
125
+ sourceFile: "test.hpp",
126
+ });
127
+ });
128
+
129
+ it("collects typed enum with bit width", () => {
130
+ const source = `enum class EPressureType : uint8_t { PSIA, PSIG };`;
131
+ const tree = TestHelpers.parseCpp(source);
132
+ expect(tree).not.toBeNull();
133
+ const result = CppResolver.resolve(tree!, "test.hpp", symbolTable);
134
+
135
+ const enumSymbol = result.symbols.find((s) => s.kind === "enum");
136
+ expect(enumSymbol).toBeDefined();
137
+ expect(enumSymbol!.name).toBe("EPressureType");
138
+
139
+ // Check that bit width was stored in symbol table
140
+ const bitWidth = symbolTable.getEnumBitWidth("EPressureType");
141
+ expect(bitWidth).toBe(8);
142
+ });
143
+ });
144
+
145
+ describe("function collection", () => {
146
+ it("collects a free function definition", () => {
147
+ const source = `void myFunction() { }`;
148
+ const tree = TestHelpers.parseCpp(source);
149
+ expect(tree).not.toBeNull();
150
+ const result = CppResolver.resolve(tree!, "test.hpp", symbolTable);
151
+
152
+ expect(result.symbols).toHaveLength(1);
153
+ expect(result.symbols[0]).toMatchObject({
154
+ kind: "function",
155
+ name: "myFunction",
156
+ type: "void",
157
+ });
158
+ });
159
+
160
+ it("collects function with parameters", () => {
161
+ const source = `int add(int a, int b) { return a + b; }`;
162
+ const tree = TestHelpers.parseCpp(source);
163
+ expect(tree).not.toBeNull();
164
+ const result = CppResolver.resolve(tree!, "test.hpp", symbolTable);
165
+
166
+ const funcSymbol = result.symbols[0];
167
+ expect(funcSymbol.kind).toBe("function");
168
+ if (funcSymbol.kind === "function") {
169
+ expect(funcSymbol.parameters).toHaveLength(2);
170
+ expect(funcSymbol.parameters![0].name).toBe("a");
171
+ expect(funcSymbol.parameters![0].type).toBe("int");
172
+ }
173
+ });
174
+
175
+ it("collects function declaration (prototype)", () => {
176
+ const source = `int myFunc(int x);`;
177
+ const tree = TestHelpers.parseCpp(source);
178
+ expect(tree).not.toBeNull();
179
+ const result = CppResolver.resolve(tree!, "test.hpp", symbolTable);
180
+
181
+ const funcSymbol = result.symbols[0];
182
+ expect(funcSymbol.kind).toBe("function");
183
+ if (funcSymbol.kind === "function") {
184
+ expect(funcSymbol.isDeclaration).toBe(true);
185
+ }
186
+ });
187
+
188
+ it("collects function in namespace", () => {
189
+ const source = `namespace NS { void foo() { } }`;
190
+ const tree = TestHelpers.parseCpp(source);
191
+ expect(tree).not.toBeNull();
192
+ const result = CppResolver.resolve(tree!, "test.hpp", symbolTable);
193
+
194
+ const funcSymbol = result.symbols.find((s) => s.kind === "function");
195
+ expect(funcSymbol).toBeDefined();
196
+ expect(funcSymbol!.name).toBe("NS::foo");
197
+ });
198
+ });
199
+
200
+ describe("variable collection", () => {
201
+ it("collects a global variable", () => {
202
+ const source = `int globalVar;`;
203
+ const tree = TestHelpers.parseCpp(source);
204
+ expect(tree).not.toBeNull();
205
+ const result = CppResolver.resolve(tree!, "test.hpp", symbolTable);
206
+
207
+ expect(result.symbols).toHaveLength(1);
208
+ expect(result.symbols[0]).toMatchObject({
209
+ kind: "variable",
210
+ name: "globalVar",
211
+ type: "int",
212
+ });
213
+ });
214
+
215
+ it("collects array variable", () => {
216
+ const source = `int buffer[32];`;
217
+ const tree = TestHelpers.parseCpp(source);
218
+ expect(tree).not.toBeNull();
219
+ const result = CppResolver.resolve(tree!, "test.hpp", symbolTable);
220
+
221
+ const varSymbol = result.symbols[0];
222
+ expect(varSymbol.kind).toBe("variable");
223
+ if (varSymbol.kind === "variable") {
224
+ expect(varSymbol.isArray).toBe(true);
225
+ expect(varSymbol.arrayDimensions).toEqual([32]);
226
+ }
227
+ });
228
+ });
229
+
230
+ describe("type alias collection", () => {
231
+ it("collects a using alias", () => {
232
+ const source = `using MyInt = int;`;
233
+ const tree = TestHelpers.parseCpp(source);
234
+ expect(tree).not.toBeNull();
235
+ const result = CppResolver.resolve(tree!, "test.hpp", symbolTable);
236
+
237
+ expect(result.symbols).toHaveLength(1);
238
+ expect(result.symbols[0]).toMatchObject({
239
+ kind: "type",
240
+ name: "MyInt",
241
+ });
242
+ });
243
+ });
244
+
245
+ describe("anonymous struct typedef", () => {
246
+ it("collects anonymous struct with typedef name", () => {
247
+ const source = `struct { int x; int y; } Point;`;
248
+ const tree = TestHelpers.parseCpp(source);
249
+ expect(tree).not.toBeNull();
250
+ const result = CppResolver.resolve(tree!, "test.hpp", symbolTable);
251
+
252
+ const classSymbol = result.symbols.find((s) => s.kind === "class");
253
+ expect(classSymbol).toBeDefined();
254
+ expect(classSymbol!.name).toBe("Point");
255
+ });
256
+ });
257
+
258
+ describe("warnings", () => {
259
+ it("warns about reserved field names", () => {
260
+ const source = `class MyStruct { int length; };`;
261
+ const tree = TestHelpers.parseCpp(source);
262
+ expect(tree).not.toBeNull();
263
+ const result = CppResolver.resolve(tree!, "test.hpp", symbolTable);
264
+
265
+ expect(result.warnings).toHaveLength(1);
266
+ expect(result.warnings[0]).toContain("length");
267
+ expect(result.warnings[0]).toContain("MyStruct");
268
+ });
269
+ });
270
+ });
@@ -0,0 +1,20 @@
1
+ /**
2
+ * Test helpers for C++ collector tests.
3
+ */
4
+
5
+ import HeaderParser from "../../../parser/HeaderParser";
6
+ import { TranslationUnitContext } from "../../../parser/cpp/grammar/CPP14Parser";
7
+
8
+ /**
9
+ * Parse C++ source code and return the translation unit context.
10
+ */
11
+ function parseCpp(source: string): TranslationUnitContext | null {
12
+ const result = HeaderParser.parseCpp(source);
13
+ return result.tree;
14
+ }
15
+
16
+ class TestHelpers {
17
+ static readonly parseCpp = parseCpp;
18
+ }
19
+
20
+ export default TestHelpers;