c-next 0.1.61 → 0.1.63

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 (104) hide show
  1. package/README.md +86 -63
  2. package/grammar/CNext.g4 +3 -17
  3. package/package.json +1 -1
  4. package/src/cli/serve/ServeCommand.ts +57 -45
  5. package/src/lib/__tests__/parseCHeader.mocked.test.ts +145 -0
  6. package/src/transpiler/Transpiler.ts +603 -613
  7. package/src/transpiler/__tests__/DualCodePaths.test.ts +5 -1
  8. package/src/transpiler/__tests__/Transpiler.coverage.test.ts +2 -99
  9. package/src/transpiler/__tests__/Transpiler.test.ts +3 -26
  10. package/src/transpiler/data/IncludeTreeWalker.ts +1 -1
  11. package/src/transpiler/logic/analysis/InitializationAnalyzer.ts +23 -52
  12. package/src/transpiler/logic/parser/grammar/CNext.interp +1 -3
  13. package/src/transpiler/logic/parser/grammar/CNextListener.ts +0 -22
  14. package/src/transpiler/logic/parser/grammar/CNextParser.ts +665 -1084
  15. package/src/transpiler/logic/parser/grammar/CNextVisitor.ts +0 -14
  16. package/src/transpiler/logic/symbols/CppSymbolCollector.ts +67 -43
  17. package/src/transpiler/logic/symbols/cnext/collectors/StructCollector.ts +156 -70
  18. package/src/transpiler/logic/symbols/cnext/collectors/VariableCollector.ts +31 -6
  19. package/src/transpiler/logic/symbols/cnext/utils/TypeUtils.ts +43 -11
  20. package/src/transpiler/output/codegen/CodeGenState.ts +811 -0
  21. package/src/transpiler/output/codegen/CodeGenerator.ts +1410 -2587
  22. package/src/transpiler/output/codegen/TypeResolver.ts +193 -149
  23. package/src/transpiler/output/codegen/TypeValidator.ts +148 -370
  24. package/src/transpiler/output/codegen/__tests__/CodeGenState.test.ts +446 -0
  25. package/src/transpiler/output/codegen/__tests__/CodeGenerator.test.ts +2082 -52
  26. package/src/transpiler/output/codegen/__tests__/TrackVariableTypeHelpers.test.ts +1 -1
  27. package/src/transpiler/output/codegen/__tests__/TypeResolver.test.ts +435 -196
  28. package/src/transpiler/output/codegen/__tests__/TypeValidator.resolution.test.ts +51 -67
  29. package/src/transpiler/output/codegen/__tests__/TypeValidator.test.ts +495 -471
  30. package/src/transpiler/output/codegen/analysis/MemberChainAnalyzer.ts +227 -66
  31. package/src/transpiler/output/codegen/analysis/StringLengthCounter.ts +55 -58
  32. package/src/transpiler/output/codegen/analysis/__tests__/MemberChainAnalyzer.test.ts +288 -275
  33. package/src/transpiler/output/codegen/analysis/__tests__/StringLengthCounter.test.ts +101 -144
  34. package/src/transpiler/output/codegen/assignment/AssignmentClassifier.ts +195 -133
  35. package/src/transpiler/output/codegen/assignment/AssignmentContextBuilder.ts +24 -74
  36. package/src/transpiler/output/codegen/assignment/AssignmentKind.ts +3 -0
  37. package/src/transpiler/output/codegen/assignment/IAssignmentContext.ts +3 -0
  38. package/src/transpiler/output/codegen/assignment/__tests__/AssignmentClassifier.test.ts +290 -320
  39. package/src/transpiler/output/codegen/assignment/handlers/BitAccessHandlers.ts +42 -0
  40. package/src/transpiler/output/codegen/assignment/handlers/__tests__/BitAccessHandlers.test.ts +76 -2
  41. package/src/transpiler/output/codegen/generators/GeneratorRegistry.ts +12 -0
  42. package/src/transpiler/output/codegen/generators/IOrchestrator.ts +5 -1
  43. package/src/transpiler/output/codegen/generators/__tests__/GeneratorRegistry.test.ts +28 -1
  44. package/src/transpiler/output/codegen/generators/declarationGenerators/ArrayDimensionUtils.ts +67 -0
  45. package/src/transpiler/output/codegen/generators/declarationGenerators/RegisterGenerator.ts +11 -24
  46. package/src/transpiler/output/codegen/generators/declarationGenerators/RegisterMacroGenerator.ts +64 -0
  47. package/src/transpiler/output/codegen/generators/declarationGenerators/ScopeGenerator.ts +137 -61
  48. package/src/transpiler/output/codegen/generators/declarationGenerators/ScopedRegisterGenerator.ts +18 -27
  49. package/src/transpiler/output/codegen/generators/declarationGenerators/StructGenerator.ts +100 -23
  50. package/src/transpiler/output/codegen/generators/declarationGenerators/__tests__/ArrayDimensionUtils.test.ts +125 -0
  51. package/src/transpiler/output/codegen/generators/declarationGenerators/__tests__/ScopeGenerator.test.ts +157 -4
  52. package/src/transpiler/output/codegen/generators/expressions/PostfixExpressionGenerator.ts +5 -1
  53. package/src/transpiler/output/codegen/generators/statements/ControlFlowGenerator.ts +1 -17
  54. package/src/transpiler/output/codegen/generators/support/HelperGenerator.ts +23 -22
  55. package/src/transpiler/output/codegen/helpers/ArrayAccessHelper.ts +129 -0
  56. package/src/transpiler/output/codegen/helpers/ArrayInitHelper.ts +54 -61
  57. package/src/transpiler/output/codegen/helpers/AssignmentExpectedTypeResolver.ts +40 -44
  58. package/src/transpiler/output/codegen/helpers/AssignmentTargetExtractor.ts +17 -45
  59. package/src/transpiler/output/codegen/helpers/AssignmentValidator.ts +83 -78
  60. package/src/transpiler/output/codegen/helpers/CppModeHelper.ts +22 -30
  61. package/src/transpiler/output/codegen/helpers/EnumAssignmentValidator.ts +108 -50
  62. package/src/transpiler/output/codegen/helpers/FloatBitHelper.ts +16 -31
  63. package/src/transpiler/output/codegen/helpers/MemberSeparatorResolver.ts +10 -3
  64. package/src/transpiler/output/codegen/helpers/StringDeclHelper.ts +103 -96
  65. package/src/transpiler/output/codegen/helpers/SymbolLookupHelper.ts +44 -0
  66. package/src/transpiler/output/codegen/helpers/TypeGenerationHelper.ts +9 -0
  67. package/src/transpiler/output/codegen/helpers/__tests__/ArrayAccessHelper.test.ts +479 -0
  68. package/src/transpiler/output/codegen/helpers/__tests__/ArrayInitHelper.test.ts +58 -103
  69. package/src/transpiler/output/codegen/helpers/__tests__/AssignmentExpectedTypeResolver.test.ts +97 -40
  70. package/src/transpiler/output/codegen/helpers/__tests__/AssignmentValidator.test.ts +223 -128
  71. package/src/transpiler/output/codegen/helpers/__tests__/CppModeHelper.test.ts +68 -41
  72. package/src/transpiler/output/codegen/helpers/__tests__/EnumAssignmentValidator.test.ts +198 -47
  73. package/src/transpiler/output/codegen/helpers/__tests__/FloatBitHelper.test.ts +39 -37
  74. package/src/transpiler/output/codegen/helpers/__tests__/MemberSeparatorResolver.test.ts +1 -0
  75. package/src/transpiler/output/codegen/helpers/__tests__/StringDeclHelper.test.ts +191 -453
  76. package/src/transpiler/output/codegen/helpers/__tests__/SymbolLookupHelper.test.ts +201 -0
  77. package/src/transpiler/output/codegen/helpers/__tests__/TypeGenerationHelper.test.ts +50 -0
  78. package/src/transpiler/output/codegen/resolution/EnumTypeResolver.ts +229 -0
  79. package/src/transpiler/output/codegen/resolution/ScopeResolver.ts +60 -0
  80. package/src/transpiler/output/codegen/resolution/SizeofResolver.ts +177 -0
  81. package/src/transpiler/output/codegen/resolution/__tests__/EnumTypeResolver.test.ts +336 -0
  82. package/src/transpiler/output/codegen/resolution/__tests__/SizeofResolver.test.ts +201 -0
  83. package/src/transpiler/output/codegen/types/IArrayAccessDeps.ts +23 -0
  84. package/src/transpiler/output/codegen/types/IArrayAccessInfo.ts +26 -0
  85. package/src/transpiler/output/codegen/types/IMemberSeparatorDeps.ts +7 -0
  86. package/src/transpiler/output/codegen/utils/CodegenParserUtils.ts +98 -0
  87. package/src/transpiler/output/codegen/utils/ExpressionUnwrapper.ts +22 -22
  88. package/src/transpiler/output/codegen/utils/__tests__/CodegenParserUtils.test.ts +228 -0
  89. package/src/transpiler/types/IFileResult.ts +0 -4
  90. package/src/transpiler/types/IPipelineFile.ts +27 -0
  91. package/src/transpiler/types/IPipelineInput.ts +23 -0
  92. package/src/transpiler/types/TranspilerState.ts +1 -1
  93. package/src/utils/FormatUtils.ts +28 -2
  94. package/src/utils/MapUtils.ts +25 -0
  95. package/src/utils/PostfixAnalysisUtils.ts +48 -0
  96. package/src/utils/__tests__/FormatUtils.test.ts +42 -0
  97. package/src/utils/__tests__/MapUtils.test.ts +85 -0
  98. package/src/utils/constants/OperatorMappings.ts +19 -0
  99. package/src/transpiler/logic/StandaloneContextBuilder.ts +0 -150
  100. package/src/transpiler/logic/__tests__/StandaloneContextBuilder.test.ts +0 -647
  101. package/src/transpiler/output/codegen/types/ITypeResolverDeps.ts +0 -23
  102. package/src/transpiler/output/codegen/types/ITypeValidatorDeps.ts +0 -53
  103. package/src/transpiler/types/ITranspileContext.ts +0 -49
  104. package/src/transpiler/types/ITranspileContribution.ts +0 -32
@@ -1,53 +0,0 @@
1
- /**
2
- * Dependencies for TypeValidator - allows TypeValidator to be independent of CodeGenerator
3
- * Issue #63: Extracted dependencies for better separation of concerns
4
- */
5
- import ICodeGenSymbols from "../../../types/ICodeGenSymbols";
6
- import SymbolTable from "../../../logic/symbols/SymbolTable";
7
- import TTypeInfo from "./TTypeInfo";
8
- import TParameterInfo from "./TParameterInfo";
9
- import ICallbackTypeInfo from "./ICallbackTypeInfo";
10
- import TypeResolver from "../TypeResolver";
11
-
12
- interface ITypeValidatorDeps {
13
- /** Symbol information from C-Next source (ADR-055: ICodeGenSymbols) */
14
- symbols: ICodeGenSymbols | null;
15
-
16
- /** Symbol table for C header struct lookups */
17
- symbolTable: SymbolTable | null;
18
-
19
- /** Type registry for variable type information */
20
- typeRegistry: Map<string, TTypeInfo>;
21
-
22
- /** Type resolver for type checking operations (Issue #61) */
23
- typeResolver: TypeResolver;
24
-
25
- /** Callback type definitions for signature validation */
26
- callbackTypes: Map<string, ICallbackTypeInfo>;
27
-
28
- /** Known function names in the program */
29
- knownFunctions: Set<string>;
30
-
31
- /** Known global variable names */
32
- knownGlobals: Set<string>;
33
-
34
- /** Callback to get current scope name */
35
- getCurrentScope: () => string | null;
36
-
37
- /** Callback to get scope members map */
38
- getScopeMembers: () => Map<string, Set<string>>;
39
-
40
- /** Callback to get current function parameters */
41
- getCurrentParameters: () => Map<string, TParameterInfo>;
42
-
43
- /** Callback to get local variables in current function */
44
- getLocalVariables: () => Set<string>;
45
-
46
- /** Callback to resolve identifiers to scoped names */
47
- resolveIdentifier: (name: string) => string;
48
-
49
- /** Callback to get expression type */
50
- getExpressionType: (ctx: unknown) => string | null;
51
- }
52
-
53
- export default ITypeValidatorDeps;
@@ -1,49 +0,0 @@
1
- import ICodeGenSymbols from "./ICodeGenSymbols";
2
- import SymbolTable from "../logic/symbols/SymbolTable";
3
-
4
- /**
5
- * Cross-file context passed to transpileSource() when called from run().
6
- *
7
- * This interface encapsulates the shared state built during Stages 1-4 of
8
- * the Pipeline, allowing transpileSource() to skip redundant parsing when
9
- * operating in multi-file mode.
10
- *
11
- * When context is provided:
12
- * - Uses shared symbolTable (already populated with all symbols)
13
- * - Skips header parsing (Step 4a) and C-Next include parsing (Step 4b)
14
- * - Uses pre-collected symbolInfoByFile for transitive enum resolution
15
- * - Uses accumulatedModifications for cross-file C++ const inference
16
- *
17
- * When context is undefined (standalone mode):
18
- * - transpileSource() behaves as before (backwards compatible)
19
- */
20
- interface ITranspileContext {
21
- /** Shared symbol table populated with all symbols from Stages 2-3 */
22
- readonly symbolTable: SymbolTable;
23
-
24
- /** Per-file symbol info collected during Stage 3 for external enum resolution */
25
- readonly symbolInfoByFile: ReadonlyMap<string, ICodeGenSymbols>;
26
-
27
- /** Cross-file parameter modifications for C++ const inference (Issue #558) */
28
- readonly accumulatedModifications: ReadonlyMap<string, ReadonlySet<string>>;
29
-
30
- /** Cross-file function parameter lists for transitive propagation (Issue #558) */
31
- readonly accumulatedParamLists: ReadonlyMap<string, readonly string[]>;
32
-
33
- /** C header include directives for type headers (Issue #497) */
34
- readonly headerIncludeDirectives: ReadonlyMap<string, string>;
35
-
36
- /** Whether C++ output mode is active (Issue #211) */
37
- readonly cppMode: boolean;
38
-
39
- /** Include directories from config */
40
- readonly includeDirs: readonly string[];
41
-
42
- /** Target platform from config */
43
- readonly target: string;
44
-
45
- /** Debug mode flag from config */
46
- readonly debugMode: boolean;
47
- }
48
-
49
- export default ITranspileContext;
@@ -1,32 +0,0 @@
1
- import ICodeGenSymbols from "./ICodeGenSymbols";
2
-
3
- /**
4
- * Data contributed by transpiling a single file.
5
- *
6
- * When run() delegates to transpileSource(), each file transpilation
7
- * produces these contributions that run() accumulates:
8
- *
9
- * - symbolInfo: For header generation (Issue #220)
10
- * - passByValueParams: For header parameter optimization (Issue #280)
11
- * - userIncludes: For header include directives (Issue #424)
12
- * - modifiedParameters: For C++ const inference accumulation (Issue #558)
13
- * - functionParamLists: For C++ const inference transitive propagation
14
- */
15
- interface ITranspileContribution {
16
- /** Symbol info collected from this file (for header generation) */
17
- readonly symbolInfo: ICodeGenSymbols;
18
-
19
- /** Pass-by-value parameters: funcName -> Set of param names */
20
- readonly passByValueParams: ReadonlyMap<string, ReadonlySet<string>>;
21
-
22
- /** User .cnx includes transformed to .h (for header generation) */
23
- readonly userIncludes: readonly string[];
24
-
25
- /** Modified parameters in this file (C++ mode only) */
26
- readonly modifiedParameters?: ReadonlyMap<string, Set<string>>;
27
-
28
- /** Function parameter lists in this file (C++ mode only) */
29
- readonly functionParamLists?: ReadonlyMap<string, readonly string[]>;
30
- }
31
-
32
- export default ITranspileContribution;