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
@@ -4,12 +4,16 @@
4
4
  * Issue #522: Tests for C++ namespace type filtering
5
5
  */
6
6
 
7
+ import { describe, it, expect } from "vitest";
7
8
  import HeaderGenerator from "../HeaderGenerator";
8
- import ESymbolKind from "../../../../utils/types/ESymbolKind";
9
- import ESourceLanguage from "../../../../utils/types/ESourceLanguage";
10
- import ISymbol from "../../../../utils/types/ISymbol";
9
+
10
+ import IHeaderSymbol from "../types/IHeaderSymbol";
11
11
  import SymbolTable from "../../../logic/symbols/SymbolTable";
12
12
  import IHeaderTypeInput from "../generators/IHeaderTypeInput";
13
+ import TestScopeUtils from "../../../logic/symbols/cnext/__tests__/testUtils";
14
+ import TTypeUtils from "../../../../utils/TTypeUtils";
15
+ import type IFunctionSymbol from "../../../types/symbols/IFunctionSymbol";
16
+ import ESourceLanguage from "../../../../utils/types/ESourceLanguage";
13
17
 
14
18
  describe("HeaderGenerator", () => {
15
19
  const generator = new HeaderGenerator();
@@ -23,14 +27,13 @@ describe("HeaderGenerator", () => {
23
27
  arrayDimensions?: string[];
24
28
  isConst?: boolean;
25
29
  } = {},
26
- ): ISymbol {
30
+ ): IHeaderSymbol {
27
31
  return {
28
32
  name,
29
33
  type,
30
- kind: ESymbolKind.Variable,
34
+ kind: "variable",
31
35
  sourceFile: "test.cnx",
32
36
  sourceLine: 1,
33
- sourceLanguage: ESourceLanguage.CNext,
34
37
  isExported: true,
35
38
  isArray: options.isArray,
36
39
  arrayDimensions: options.arrayDimensions,
@@ -106,25 +109,23 @@ describe("HeaderGenerator", () => {
106
109
 
107
110
  describe("Issue #449: declaration ordering", () => {
108
111
  // Helper to create an enum symbol
109
- function makeEnumSymbol(name: string): ISymbol {
112
+ function makeEnumSymbol(name: string): IHeaderSymbol {
110
113
  return {
111
114
  name,
112
- kind: ESymbolKind.Enum,
115
+ kind: "enum",
113
116
  sourceFile: "test.cnx",
114
117
  sourceLine: 1,
115
- sourceLanguage: ESourceLanguage.CNext,
116
118
  isExported: true,
117
119
  };
118
120
  }
119
121
 
120
122
  // Helper to create a struct symbol
121
- function makeStructSymbol(name: string): ISymbol {
123
+ function makeStructSymbol(name: string): IHeaderSymbol {
122
124
  return {
123
125
  name,
124
- kind: ESymbolKind.Struct,
126
+ kind: "struct",
125
127
  sourceFile: "test.cnx",
126
128
  sourceLine: 1,
127
- sourceLanguage: ESourceLanguage.CNext,
128
129
  isExported: true,
129
130
  };
130
131
  }
@@ -201,13 +202,13 @@ describe("HeaderGenerator", () => {
201
202
  namespaceName: string,
202
203
  ): IHeaderTypeInput {
203
204
  const symbolTable = new SymbolTable();
204
- symbolTable.addSymbol({
205
+ symbolTable.addCppSymbol({
205
206
  name: namespaceName,
206
- kind: ESymbolKind.Namespace,
207
- sourceLanguage: ESourceLanguage.Cpp,
207
+ kind: "namespace",
208
208
  sourceFile: `${namespaceName}.hpp`,
209
209
  sourceLine: 1,
210
210
  isExported: false,
211
+ sourceLanguage: ESourceLanguage.Cpp,
211
212
  });
212
213
  return {
213
214
  symbolTable,
@@ -266,14 +267,13 @@ describe("HeaderGenerator", () => {
266
267
 
267
268
  describe("forward declaration filtering", () => {
268
269
  // Helper to create a function symbol that references an external type
269
- function makeFuncSymbol(name: string, paramType: string): ISymbol {
270
+ function makeFuncSymbol(name: string, paramType: string): IHeaderSymbol {
270
271
  return {
271
272
  name,
272
273
  type: "void",
273
- kind: ESymbolKind.Function,
274
+ kind: "function",
274
275
  sourceFile: "test.cnx",
275
276
  sourceLine: 1,
276
- sourceLanguage: ESourceLanguage.CNext,
277
277
  isExported: true,
278
278
  parameters: [
279
279
  { name: "param", type: paramType, isConst: false, isArray: false },
@@ -357,24 +357,32 @@ describe("HeaderGenerator", () => {
357
357
  describe("generateFromSymbolTable", () => {
358
358
  it("should generate header from symbols filtered by source file", () => {
359
359
  const symbolTable = new SymbolTable();
360
- symbolTable.addSymbol({
360
+ symbolTable.addTSymbol({
361
+ kind: "function",
361
362
  name: "myFunc",
362
- kind: ESymbolKind.Function,
363
- type: "void",
364
363
  sourceFile: "module.cnx",
365
364
  sourceLine: 1,
366
- sourceLanguage: ESourceLanguage.CNext,
367
365
  isExported: true,
368
- });
369
- symbolTable.addSymbol({
366
+ returnType: TTypeUtils.createPrimitive("void"),
367
+ parameters: [],
368
+ scope: TestScopeUtils.createMockGlobalScope(),
369
+ visibility: "public",
370
+ body: null,
371
+ sourceLanguage: ESourceLanguage.CNext,
372
+ } as IFunctionSymbol);
373
+ symbolTable.addTSymbol({
374
+ kind: "function",
370
375
  name: "otherFunc",
371
- kind: ESymbolKind.Function,
372
- type: "void",
373
376
  sourceFile: "other.cnx",
374
377
  sourceLine: 1,
375
- sourceLanguage: ESourceLanguage.CNext,
376
378
  isExported: true,
377
- });
379
+ returnType: TTypeUtils.createPrimitive("void"),
380
+ parameters: [],
381
+ scope: TestScopeUtils.createMockGlobalScope(),
382
+ visibility: "public",
383
+ body: null,
384
+ sourceLanguage: ESourceLanguage.CNext,
385
+ } as IFunctionSymbol);
378
386
 
379
387
  const header = generator.generateFromSymbolTable(
380
388
  symbolTable,
@@ -389,15 +397,19 @@ describe("HeaderGenerator", () => {
389
397
 
390
398
  it("should use correct header name from source file", () => {
391
399
  const symbolTable = new SymbolTable();
392
- symbolTable.addSymbol({
400
+ symbolTable.addTSymbol({
401
+ kind: "function",
393
402
  name: "testFunc",
394
- kind: ESymbolKind.Function,
395
- type: "void",
396
403
  sourceFile: "src/utils/helper.cnx",
397
404
  sourceLine: 1,
398
- sourceLanguage: ESourceLanguage.CNext,
399
405
  isExported: true,
400
- });
406
+ returnType: TTypeUtils.createPrimitive("void"),
407
+ parameters: [],
408
+ scope: TestScopeUtils.createMockGlobalScope(),
409
+ visibility: "public",
410
+ body: null,
411
+ sourceLanguage: ESourceLanguage.CNext,
412
+ } as IFunctionSymbol);
401
413
 
402
414
  const header = generator.generateFromSymbolTable(
403
415
  symbolTable,
@@ -413,32 +425,36 @@ describe("HeaderGenerator", () => {
413
425
  describe("generateCNextHeader", () => {
414
426
  it("should generate header only for C-Next language symbols", () => {
415
427
  const symbolTable = new SymbolTable();
416
- symbolTable.addSymbol({
428
+ symbolTable.addTSymbol({
429
+ kind: "function",
417
430
  name: "cnextFunc",
418
- kind: ESymbolKind.Function,
419
- type: "void",
420
431
  sourceFile: "module.cnx",
421
432
  sourceLine: 1,
422
- sourceLanguage: ESourceLanguage.CNext,
423
433
  isExported: true,
424
- });
425
- symbolTable.addSymbol({
434
+ returnType: TTypeUtils.createPrimitive("void"),
435
+ parameters: [],
436
+ scope: TestScopeUtils.createMockGlobalScope(),
437
+ visibility: "public",
438
+ body: null,
439
+ sourceLanguage: ESourceLanguage.CNext,
440
+ } as IFunctionSymbol);
441
+ symbolTable.addCppSymbol({
442
+ kind: "function",
426
443
  name: "cppFunc",
427
- kind: ESymbolKind.Function,
428
444
  type: "void",
429
445
  sourceFile: "module.hpp",
430
446
  sourceLine: 1,
431
- sourceLanguage: ESourceLanguage.Cpp,
432
447
  isExported: true,
448
+ sourceLanguage: ESourceLanguage.Cpp,
433
449
  });
434
- symbolTable.addSymbol({
450
+ symbolTable.addCSymbol({
451
+ kind: "function",
435
452
  name: "cFunc",
436
- kind: ESymbolKind.Function,
437
453
  type: "void",
438
454
  sourceFile: "module.h",
439
455
  sourceLine: 1,
440
- sourceLanguage: ESourceLanguage.C,
441
456
  isExported: true,
457
+ sourceLanguage: ESourceLanguage.C,
442
458
  });
443
459
 
444
460
  const header = generator.generateCNextHeader(symbolTable, "output.h");
@@ -450,15 +466,19 @@ describe("HeaderGenerator", () => {
450
466
 
451
467
  it("should use the provided filename for include guard", () => {
452
468
  const symbolTable = new SymbolTable();
453
- symbolTable.addSymbol({
469
+ symbolTable.addTSymbol({
470
+ kind: "function",
454
471
  name: "testFunc",
455
- kind: ESymbolKind.Function,
456
- type: "void",
457
472
  sourceFile: "test.cnx",
458
473
  sourceLine: 1,
459
- sourceLanguage: ESourceLanguage.CNext,
460
474
  isExported: true,
461
- });
475
+ returnType: TTypeUtils.createPrimitive("void"),
476
+ parameters: [],
477
+ scope: TestScopeUtils.createMockGlobalScope(),
478
+ visibility: "public",
479
+ body: null,
480
+ sourceLanguage: ESourceLanguage.CNext,
481
+ } as IFunctionSymbol);
462
482
 
463
483
  const header = generator.generateCNextHeader(symbolTable, "custom_api.h");
464
484
 
@@ -468,24 +488,32 @@ describe("HeaderGenerator", () => {
468
488
 
469
489
  it("should pass options through to underlying generate method", () => {
470
490
  const symbolTable = new SymbolTable();
471
- symbolTable.addSymbol({
491
+ symbolTable.addTSymbol({
492
+ kind: "function",
472
493
  name: "exportedFunc",
473
- kind: ESymbolKind.Function,
474
- type: "void",
475
494
  sourceFile: "test.cnx",
476
495
  sourceLine: 1,
477
- sourceLanguage: ESourceLanguage.CNext,
478
496
  isExported: true,
479
- });
480
- symbolTable.addSymbol({
497
+ returnType: TTypeUtils.createPrimitive("void"),
498
+ parameters: [],
499
+ scope: TestScopeUtils.createMockGlobalScope(),
500
+ visibility: "public",
501
+ body: null,
502
+ sourceLanguage: ESourceLanguage.CNext,
503
+ } as IFunctionSymbol);
504
+ symbolTable.addTSymbol({
505
+ kind: "function",
481
506
  name: "internalFunc",
482
- kind: ESymbolKind.Function,
483
- type: "void",
484
507
  sourceFile: "test.cnx",
485
508
  sourceLine: 1,
486
- sourceLanguage: ESourceLanguage.CNext,
487
509
  isExported: false,
488
- });
510
+ returnType: TTypeUtils.createPrimitive("void"),
511
+ parameters: [],
512
+ scope: TestScopeUtils.createMockGlobalScope(),
513
+ visibility: "private",
514
+ body: null,
515
+ sourceLanguage: ESourceLanguage.CNext,
516
+ } as IFunctionSymbol);
489
517
 
490
518
  const header = generator.generateCNextHeader(symbolTable, "api.h", {
491
519
  exportedOnly: true,
@@ -4,21 +4,20 @@
4
4
 
5
5
  import { describe, it, expect } from "vitest";
6
6
  import HeaderGeneratorUtils from "../HeaderGeneratorUtils";
7
- import ESymbolKind from "../../../../utils/types/ESymbolKind";
8
- import ESourceLanguage from "../../../../utils/types/ESourceLanguage";
9
- import ISymbol from "../../../../utils/types/ISymbol";
7
+
8
+ import IHeaderSymbol from "../types/IHeaderSymbol";
10
9
  import IParameterSymbol from "../../../../utils/types/IParameterSymbol";
10
+ import TSymbolKind from "../../../types/symbol-kinds/TSymbolKind";
11
11
 
12
12
  /**
13
13
  * Helper to create test symbols with required properties
14
14
  */
15
15
  function makeSymbol(
16
- partial: Partial<ISymbol> & { name: string; kind: ESymbolKind },
17
- ): ISymbol {
16
+ partial: Partial<IHeaderSymbol> & { name: string; kind: TSymbolKind },
17
+ ): IHeaderSymbol {
18
18
  return {
19
19
  sourceFile: "test.cnx",
20
20
  sourceLine: 1,
21
- sourceLanguage: ESourceLanguage.CNext,
22
21
  isExported: true,
23
22
  ...partial,
24
23
  };
@@ -68,14 +67,14 @@ describe("HeaderGeneratorUtils", () => {
68
67
 
69
68
  describe("groupSymbolsByKind", () => {
70
69
  it("groups symbols correctly", () => {
71
- const symbols: ISymbol[] = [
72
- makeSymbol({ name: "MyStruct", kind: ESymbolKind.Struct }),
73
- makeSymbol({ name: "MyEnum", kind: ESymbolKind.Enum }),
74
- makeSymbol({ name: "myFunc", kind: ESymbolKind.Function }),
75
- makeSymbol({ name: "myVar", kind: ESymbolKind.Variable }),
76
- makeSymbol({ name: "MyClass", kind: ESymbolKind.Class }),
77
- makeSymbol({ name: "MyType", kind: ESymbolKind.Type }),
78
- makeSymbol({ name: "MyBitmap", kind: ESymbolKind.Bitmap }),
70
+ const symbols: IHeaderSymbol[] = [
71
+ makeSymbol({ name: "MyStruct", kind: "struct" }),
72
+ makeSymbol({ name: "MyEnum", kind: "enum" }),
73
+ makeSymbol({ name: "myFunc", kind: "function" }),
74
+ makeSymbol({ name: "myVar", kind: "variable" }),
75
+ makeSymbol({ name: "MyClass", kind: "class" }),
76
+ makeSymbol({ name: "MyType", kind: "type" }),
77
+ makeSymbol({ name: "MyBitmap", kind: "bitmap" }),
79
78
  ];
80
79
 
81
80
  const groups = HeaderGeneratorUtils.groupSymbolsByKind(symbols);
@@ -185,15 +184,15 @@ describe("HeaderGeneratorUtils", () => {
185
184
  it("extracts local type names from grouped symbols", () => {
186
185
  const groups = {
187
186
  structs: [
188
- makeSymbol({ name: "Point", kind: ESymbolKind.Struct }),
189
- makeSymbol({ name: "Rect", kind: ESymbolKind.Struct }),
187
+ makeSymbol({ name: "Point", kind: "struct" }),
188
+ makeSymbol({ name: "Rect", kind: "struct" }),
190
189
  ],
191
- classes: [] as ISymbol[],
192
- functions: [] as ISymbol[],
193
- variables: [] as ISymbol[],
194
- enums: [makeSymbol({ name: "Color", kind: ESymbolKind.Enum })],
195
- types: [makeSymbol({ name: "Size", kind: ESymbolKind.Type })],
196
- bitmaps: [makeSymbol({ name: "Flags", kind: ESymbolKind.Bitmap })],
190
+ classes: [] as IHeaderSymbol[],
191
+ functions: [] as IHeaderSymbol[],
192
+ variables: [] as IHeaderSymbol[],
193
+ enums: [makeSymbol({ name: "Color", kind: "enum" })],
194
+ types: [makeSymbol({ name: "Size", kind: "type" })],
195
+ bitmaps: [makeSymbol({ name: "Flags", kind: "bitmap" })],
197
196
  };
198
197
 
199
198
  const localTypes = HeaderGeneratorUtils.getLocalTypeNames(groups);
@@ -240,10 +239,10 @@ describe("HeaderGeneratorUtils", () => {
240
239
 
241
240
  describe("collectExternalTypes", () => {
242
241
  it("collects types from function return types", () => {
243
- const functions: ISymbol[] = [
242
+ const functions: IHeaderSymbol[] = [
244
243
  makeSymbol({
245
244
  name: "getConfig",
246
- kind: ESymbolKind.Function,
245
+ kind: "function",
247
246
  type: "Config",
248
247
  }),
249
248
  ];
@@ -261,10 +260,10 @@ describe("HeaderGeneratorUtils", () => {
261
260
  });
262
261
 
263
262
  it("collects types from function parameters", () => {
264
- const functions: ISymbol[] = [
263
+ const functions: IHeaderSymbol[] = [
265
264
  makeSymbol({
266
265
  name: "process",
267
- kind: ESymbolKind.Function,
266
+ kind: "function",
268
267
  parameters: [makeParam({ name: "data", type: "DataPacket" })],
269
268
  }),
270
269
  ];
@@ -282,10 +281,10 @@ describe("HeaderGeneratorUtils", () => {
282
281
  });
283
282
 
284
283
  it("collects types from variables", () => {
285
- const variables: ISymbol[] = [
284
+ const variables: IHeaderSymbol[] = [
286
285
  makeSymbol({
287
286
  name: "state",
288
- kind: ESymbolKind.Variable,
287
+ kind: "variable",
289
288
  type: "SystemState",
290
289
  }),
291
290
  ];
@@ -303,10 +302,10 @@ describe("HeaderGeneratorUtils", () => {
303
302
  });
304
303
 
305
304
  it("excludes local structs", () => {
306
- const functions: ISymbol[] = [
305
+ const functions: IHeaderSymbol[] = [
307
306
  makeSymbol({
308
307
  name: "getPoint",
309
- kind: ESymbolKind.Function,
308
+ kind: "function",
310
309
  type: "Point",
311
310
  }),
312
311
  ];
@@ -324,10 +323,10 @@ describe("HeaderGeneratorUtils", () => {
324
323
  });
325
324
 
326
325
  it("excludes built-in types", () => {
327
- const functions: ISymbol[] = [
326
+ const functions: IHeaderSymbol[] = [
328
327
  makeSymbol({
329
328
  name: "getValue",
330
- kind: ESymbolKind.Function,
329
+ kind: "function",
331
330
  type: "u32",
332
331
  }),
333
332
  ];
@@ -345,10 +344,10 @@ describe("HeaderGeneratorUtils", () => {
345
344
  });
346
345
 
347
346
  it("excludes C++ namespace types", () => {
348
- const functions: ISymbol[] = [
347
+ const functions: IHeaderSymbol[] = [
349
348
  makeSymbol({
350
349
  name: "parse",
351
- kind: ESymbolKind.Function,
350
+ kind: "function",
352
351
  type: "std::string",
353
352
  }),
354
353
  ];
@@ -366,10 +365,10 @@ describe("HeaderGeneratorUtils", () => {
366
365
  });
367
366
 
368
367
  it("excludes known enums", () => {
369
- const functions: ISymbol[] = [
368
+ const functions: IHeaderSymbol[] = [
370
369
  makeSymbol({
371
370
  name: "getColor",
372
- kind: ESymbolKind.Function,
371
+ kind: "function",
373
372
  type: "Color",
374
373
  }),
375
374
  ];
@@ -444,13 +443,13 @@ describe("HeaderGeneratorUtils", () => {
444
443
 
445
444
  describe("filterCCompatibleVariables", () => {
446
445
  it("filters out C++ namespace types", () => {
447
- const variables: ISymbol[] = [
446
+ const variables: IHeaderSymbol[] = [
448
447
  makeSymbol({
449
448
  name: "a",
450
- kind: ESymbolKind.Variable,
449
+ kind: "variable",
451
450
  type: "std::string",
452
451
  }),
453
- makeSymbol({ name: "b", kind: ESymbolKind.Variable, type: "int" }),
452
+ makeSymbol({ name: "b", kind: "variable", type: "int" }),
454
453
  ];
455
454
 
456
455
  const result = HeaderGeneratorUtils.filterCCompatibleVariables(variables);
@@ -460,13 +459,13 @@ describe("HeaderGeneratorUtils", () => {
460
459
  });
461
460
 
462
461
  it("filters out C++ template types", () => {
463
- const variables: ISymbol[] = [
462
+ const variables: IHeaderSymbol[] = [
464
463
  makeSymbol({
465
464
  name: "a",
466
- kind: ESymbolKind.Variable,
465
+ kind: "variable",
467
466
  type: "vector<int>",
468
467
  }),
469
- makeSymbol({ name: "b", kind: ESymbolKind.Variable, type: "u32" }),
468
+ makeSymbol({ name: "b", kind: "variable", type: "u32" }),
470
469
  ];
471
470
 
472
471
  const result = HeaderGeneratorUtils.filterCCompatibleVariables(variables);
@@ -476,10 +475,10 @@ describe("HeaderGeneratorUtils", () => {
476
475
  });
477
476
 
478
477
  it("keeps C-Next string<N> types", () => {
479
- const variables: ISymbol[] = [
478
+ const variables: IHeaderSymbol[] = [
480
479
  makeSymbol({
481
480
  name: "name",
482
- kind: ESymbolKind.Variable,
481
+ kind: "variable",
483
482
  type: "string<32>",
484
483
  }),
485
484
  ];
@@ -589,14 +588,14 @@ describe("HeaderGeneratorUtils", () => {
589
588
  });
590
589
 
591
590
  it("generates placeholder when no typeInput", () => {
592
- const enums = [makeSymbol({ name: "Color", kind: ESymbolKind.Enum })];
591
+ const enums = [makeSymbol({ name: "Color", kind: "enum" })];
593
592
  const lines = HeaderGeneratorUtils.generateEnumSection(enums);
594
593
 
595
594
  expect(lines.some((l) => l.includes("/* Enum: Color"))).toBe(true);
596
595
  });
597
596
 
598
597
  it("includes section comment", () => {
599
- const enums = [makeSymbol({ name: "Color", kind: ESymbolKind.Enum })];
598
+ const enums = [makeSymbol({ name: "Color", kind: "enum" })];
600
599
  const lines = HeaderGeneratorUtils.generateEnumSection(enums);
601
600
 
602
601
  expect(lines).toContain("/* Enumerations */");
@@ -611,14 +610,14 @@ describe("HeaderGeneratorUtils", () => {
611
610
  });
612
611
 
613
612
  it("generates placeholder when no typeInput", () => {
614
- const bitmaps = [makeSymbol({ name: "Flags", kind: ESymbolKind.Bitmap })];
613
+ const bitmaps = [makeSymbol({ name: "Flags", kind: "bitmap" })];
615
614
  const lines = HeaderGeneratorUtils.generateBitmapSection(bitmaps);
616
615
 
617
616
  expect(lines.some((l) => l.includes("/* Bitmap: Flags"))).toBe(true);
618
617
  });
619
618
 
620
619
  it("includes section comment", () => {
621
- const bitmaps = [makeSymbol({ name: "Flags", kind: ESymbolKind.Bitmap })];
620
+ const bitmaps = [makeSymbol({ name: "Flags", kind: "bitmap" })];
622
621
  const lines = HeaderGeneratorUtils.generateBitmapSection(bitmaps);
623
622
 
624
623
  expect(lines).toContain("/* Bitmaps */");
@@ -634,8 +633,8 @@ describe("HeaderGeneratorUtils", () => {
634
633
 
635
634
  it("generates typedef for each type alias", () => {
636
635
  const types = [
637
- makeSymbol({ name: "Size", kind: ESymbolKind.Type, type: "u32" }),
638
- makeSymbol({ name: "Handle", kind: ESymbolKind.Type, type: "u64" }),
636
+ makeSymbol({ name: "Size", kind: "type", type: "u32" }),
637
+ makeSymbol({ name: "Handle", kind: "type", type: "u64" }),
639
638
  ];
640
639
  const lines = HeaderGeneratorUtils.generateTypeAliasSection(types);
641
640
 
@@ -645,8 +644,8 @@ describe("HeaderGeneratorUtils", () => {
645
644
 
646
645
  it("skips types without type property", () => {
647
646
  const types = [
648
- makeSymbol({ name: "NoType", kind: ESymbolKind.Type }),
649
- makeSymbol({ name: "WithType", kind: ESymbolKind.Type, type: "i32" }),
647
+ makeSymbol({ name: "NoType", kind: "type" }),
648
+ makeSymbol({ name: "WithType", kind: "type", type: "i32" }),
650
649
  ];
651
650
  const lines = HeaderGeneratorUtils.generateTypeAliasSection(types);
652
651
 
@@ -663,8 +662,8 @@ describe("HeaderGeneratorUtils", () => {
663
662
  });
664
663
 
665
664
  it("generates forward declarations when no typeInput", () => {
666
- const structs = [makeSymbol({ name: "Point", kind: ESymbolKind.Struct })];
667
- const classes = [makeSymbol({ name: "Shape", kind: ESymbolKind.Class })];
665
+ const structs = [makeSymbol({ name: "Point", kind: "struct" })];
666
+ const classes = [makeSymbol({ name: "Shape", kind: "class" })];
668
667
  const lines = HeaderGeneratorUtils.generateStructSection(
669
668
  structs,
670
669
  classes,
@@ -687,7 +686,7 @@ describe("HeaderGeneratorUtils", () => {
687
686
  const variables = [
688
687
  makeSymbol({
689
688
  name: "counter",
690
- kind: ESymbolKind.Variable,
689
+ kind: "variable",
691
690
  type: "u32",
692
691
  }),
693
692
  ];
@@ -700,7 +699,7 @@ describe("HeaderGeneratorUtils", () => {
700
699
  const variables = [
701
700
  makeSymbol({
702
701
  name: "VERSION",
703
- kind: ESymbolKind.Variable,
702
+ kind: "variable",
704
703
  type: "u32",
705
704
  isConst: true,
706
705
  }),
@@ -714,7 +713,7 @@ describe("HeaderGeneratorUtils", () => {
714
713
  const variables = [
715
714
  makeSymbol({
716
715
  name: "flag",
717
- kind: ESymbolKind.Variable,
716
+ kind: "variable",
718
717
  type: "bool",
719
718
  isAtomic: true,
720
719
  }),
@@ -728,7 +727,7 @@ describe("HeaderGeneratorUtils", () => {
728
727
  const variables = [
729
728
  makeSymbol({
730
729
  name: "buffer",
731
- kind: ESymbolKind.Variable,
730
+ kind: "variable",
732
731
  type: "u8",
733
732
  isArray: true,
734
733
  arrayDimensions: ["64"],