c-next 0.2.16 → 0.2.18

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 (118) hide show
  1. package/README.md +18 -2
  2. package/dist/index.js +8897 -6260
  3. package/dist/index.js.map +4 -4
  4. package/grammar/CNext.g4 +12 -0
  5. package/package.json +4 -2
  6. package/src/transpiler/Transpiler.ts +376 -48
  7. package/src/transpiler/__tests__/DualCodePaths.test.ts +1 -1
  8. package/src/transpiler/__tests__/compileCommandsDiscovery.integration.test.ts +94 -0
  9. package/src/transpiler/__tests__/externalSymbolRecovery.integration.test.ts +215 -0
  10. package/src/transpiler/logic/__tests__/detectAssemblySyntax.test.ts +116 -0
  11. package/src/transpiler/logic/analysis/FunctionCallAnalyzer.ts +65 -10
  12. package/src/transpiler/logic/analysis/InitializationAnalyzer.ts +186 -14
  13. package/src/transpiler/logic/analysis/MixedTypeCategoryAnalyzer.ts +408 -0
  14. package/src/transpiler/logic/analysis/PassByValueAnalyzer.ts +16 -97
  15. package/src/transpiler/logic/analysis/ReturnPathAnalyzer.ts +171 -0
  16. package/src/transpiler/logic/analysis/SignedShiftAnalyzer.ts +124 -12
  17. package/src/transpiler/logic/analysis/__tests__/FunctionCallAnalyzer.test.ts +200 -0
  18. package/src/transpiler/logic/analysis/__tests__/InitializationAnalyzer.test.ts +386 -1
  19. package/src/transpiler/logic/analysis/__tests__/MixedTypeCategoryAnalyzer.test.ts +346 -0
  20. package/src/transpiler/logic/analysis/__tests__/ReturnPathAnalyzer.test.ts +232 -0
  21. package/src/transpiler/logic/analysis/__tests__/SignedShiftAnalyzer.test.ts +211 -0
  22. package/src/transpiler/logic/analysis/runAnalyzers.ts +23 -2
  23. package/src/transpiler/logic/analysis/types/IMixedTypeCategoryError.ts +17 -0
  24. package/src/transpiler/logic/analysis/types/IReturnPathError.ts +12 -0
  25. package/src/transpiler/logic/detectAssemblySyntax.ts +80 -0
  26. package/src/transpiler/logic/parser/grammar/CNext.interp +4 -1
  27. package/src/transpiler/logic/parser/grammar/CNext.tokens +169 -167
  28. package/src/transpiler/logic/parser/grammar/CNextLexer.interp +4 -1
  29. package/src/transpiler/logic/parser/grammar/CNextLexer.tokens +169 -167
  30. package/src/transpiler/logic/parser/grammar/CNextLexer.ts +545 -541
  31. package/src/transpiler/logic/parser/grammar/CNextListener.ts +11 -0
  32. package/src/transpiler/logic/parser/grammar/CNextParser.ts +1318 -1178
  33. package/src/transpiler/logic/parser/grammar/CNextVisitor.ts +7 -0
  34. package/src/transpiler/logic/preprocessor/CompileCommandsReader.ts +332 -0
  35. package/src/transpiler/logic/preprocessor/ExternalDeclarationOracle.ts +202 -0
  36. package/src/transpiler/logic/preprocessor/Preprocessor.ts +24 -6
  37. package/src/transpiler/logic/preprocessor/ToolchainDetector.ts +42 -1
  38. package/src/transpiler/logic/preprocessor/__tests__/CompileCommandsReader.test.ts +216 -0
  39. package/src/transpiler/logic/preprocessor/__tests__/ExternalDeclarationOracle.test.ts +153 -0
  40. package/src/transpiler/logic/preprocessor/__tests__/Preprocessor.test.ts +43 -18
  41. package/src/transpiler/logic/preprocessor/__tests__/ToolchainDetector.crossCompiler.test.ts +75 -0
  42. package/src/transpiler/logic/preprocessor/__tests__/fixtures/oracle/dependent.h +7 -0
  43. package/src/transpiler/logic/preprocessor/__tests__/fixtures/oracle/predecessor.h +5 -0
  44. package/src/transpiler/logic/preprocessor/types/ICompileCommandsResult.ts +14 -0
  45. package/src/transpiler/logic/preprocessor/types/IPreprocessOptions.ts +17 -0
  46. package/src/transpiler/logic/symbols/SymbolTable.ts +62 -2
  47. package/src/transpiler/logic/symbols/__tests__/SymbolTable.test.ts +55 -4
  48. package/src/transpiler/logic/symbols/cnext/collectors/VariableCollector.ts +15 -2
  49. package/src/transpiler/logic/symbols/cnext/utils/TypeUtils.ts +64 -50
  50. package/src/transpiler/output/MisraSuppressionUtils.ts +52 -0
  51. package/src/transpiler/output/__tests__/MisraSuppressionUtils.test.ts +67 -0
  52. package/src/transpiler/output/codegen/CodeGenerator.ts +196 -98
  53. package/src/transpiler/output/codegen/TypeResolver.ts +148 -0
  54. package/src/transpiler/output/codegen/TypeValidator.ts +179 -81
  55. package/src/transpiler/output/codegen/__tests__/CodeGenerator.coverage.test.ts +165 -17
  56. package/src/transpiler/output/codegen/__tests__/CodeGenerator.test.ts +163 -35
  57. package/src/transpiler/output/codegen/__tests__/TrackVariableTypeHelpers.test.ts +2 -2
  58. package/src/transpiler/output/codegen/__tests__/TypeResolver.test.ts +93 -0
  59. package/src/transpiler/output/codegen/__tests__/TypeValidator.alwaysTrueLoop.test.ts +91 -0
  60. package/src/transpiler/output/codegen/__tests__/TypeValidator.test.ts +97 -14
  61. package/src/transpiler/output/codegen/assignment/AssignmentClassifier.ts +13 -0
  62. package/src/transpiler/output/codegen/assignment/AssignmentKind.ts +1 -1
  63. package/src/transpiler/output/codegen/assignment/handlers/AccessPatternHandlers.ts +20 -12
  64. package/src/transpiler/output/codegen/assignment/handlers/ArrayHandlers.ts +424 -22
  65. package/src/transpiler/output/codegen/assignment/handlers/BitAccessHandlers.ts +31 -18
  66. package/src/transpiler/output/codegen/assignment/handlers/BitmapHandlers.ts +7 -8
  67. package/src/transpiler/output/codegen/assignment/handlers/RegisterHandlers.ts +6 -8
  68. package/src/transpiler/output/codegen/assignment/handlers/RegisterUtils.ts +12 -10
  69. package/src/transpiler/output/codegen/assignment/handlers/SimpleHandler.ts +3 -7
  70. package/src/transpiler/output/codegen/assignment/handlers/SpecialHandlers.ts +7 -9
  71. package/src/transpiler/output/codegen/assignment/handlers/StringHandlers.ts +12 -10
  72. package/src/transpiler/output/codegen/assignment/handlers/__tests__/ArrayHandlers.test.ts +479 -11
  73. package/src/transpiler/output/codegen/generators/IOrchestrator.ts +3 -0
  74. package/src/transpiler/output/codegen/generators/declarationGenerators/ScopeGenerator.ts +26 -7
  75. package/src/transpiler/output/codegen/generators/declarationGenerators/__tests__/ScopeGenerator.test.ts +86 -0
  76. package/src/transpiler/output/codegen/generators/expressions/BinaryExprGenerator.ts +43 -24
  77. package/src/transpiler/output/codegen/generators/expressions/CallExprGenerator.ts +76 -58
  78. package/src/transpiler/output/codegen/generators/expressions/ExpressionGenerator.ts +9 -2
  79. package/src/transpiler/output/codegen/generators/expressions/PostfixExpressionGenerator.ts +26 -13
  80. package/src/transpiler/output/codegen/generators/expressions/__tests__/CallExprGenerator.test.ts +44 -0
  81. package/src/transpiler/output/codegen/generators/expressions/__tests__/ExpressionGenerator.test.ts +82 -1
  82. package/src/transpiler/output/codegen/generators/expressions/__tests__/PostfixExpressionGenerator.test.ts +129 -1
  83. package/src/transpiler/output/codegen/generators/statements/ControlFlowGenerator.ts +64 -8
  84. package/src/transpiler/output/codegen/generators/statements/__tests__/ControlFlowGenerator.test.ts +8 -5
  85. package/src/transpiler/output/codegen/helpers/AssignmentExpectedTypeResolver.ts +30 -2
  86. package/src/transpiler/output/codegen/helpers/ParameterInputAdapter.ts +17 -3
  87. package/src/transpiler/output/codegen/helpers/ParameterSignatureBuilder.ts +17 -4
  88. package/src/transpiler/output/codegen/helpers/StringDeclHelper.ts +240 -42
  89. package/src/transpiler/output/codegen/helpers/SymbolLookupHelper.ts +0 -21
  90. package/src/transpiler/output/codegen/helpers/TypeGenerationHelper.ts +60 -39
  91. package/src/transpiler/output/codegen/helpers/TypeRegistrationEngine.ts +170 -36
  92. package/src/transpiler/output/codegen/helpers/VariableDeclHelper.ts +37 -39
  93. package/src/transpiler/output/codegen/helpers/__tests__/AssignmentExpectedTypeResolver.test.ts +19 -0
  94. package/src/transpiler/output/codegen/helpers/__tests__/ParameterInputAdapter.test.ts +117 -0
  95. package/src/transpiler/output/codegen/helpers/__tests__/ParameterSignatureBuilder.test.ts +94 -2
  96. package/src/transpiler/output/codegen/helpers/__tests__/StringDeclHelper.test.ts +322 -9
  97. package/src/transpiler/output/codegen/helpers/__tests__/SymbolLookupHelper.test.ts +0 -64
  98. package/src/transpiler/output/codegen/helpers/__tests__/TypeRegistrationEngine.test.ts +101 -0
  99. package/src/transpiler/output/codegen/helpers/__tests__/VariableDeclHelper.test.ts +29 -5
  100. package/src/transpiler/output/codegen/subscript/SubscriptClassifier.ts +30 -11
  101. package/src/transpiler/output/codegen/subscript/TSubscriptKind.ts +1 -1
  102. package/src/transpiler/output/codegen/subscript/__tests__/SubscriptClassifier.test.ts +38 -6
  103. package/src/transpiler/output/codegen/types/ICallbackTypeInfo.ts +2 -1
  104. package/src/transpiler/output/codegen/types/IParameterInput.ts +7 -0
  105. package/src/transpiler/output/headers/BaseHeaderGenerator.ts +8 -0
  106. package/src/transpiler/output/headers/HeaderGeneratorUtils.ts +140 -24
  107. package/src/transpiler/output/headers/__tests__/HeaderGeneratorUtils.test.ts +280 -0
  108. package/src/transpiler/output/headers/generators/IHeaderTypeInput.ts +13 -0
  109. package/src/transpiler/output/headers/generators/generateStructHeader.ts +48 -28
  110. package/src/transpiler/state/CodeGenState.ts +91 -22
  111. package/src/transpiler/state/__tests__/CodeGenState.test.ts +253 -11
  112. package/src/transpiler/types/ICachedFileEntry.ts +7 -0
  113. package/src/utils/LiteralUtils.ts +23 -0
  114. package/src/utils/__tests__/LiteralUtils.test.ts +101 -0
  115. package/src/utils/cache/CacheManager.ts +13 -2
  116. package/src/utils/cache/__tests__/CacheManager.test.ts +18 -1
  117. package/src/utils/constants/TypeConstants.ts +13 -0
  118. package/src/utils/types/IParameterSymbol.ts +1 -0
@@ -24,97 +24,98 @@ ELSE=23
24
24
  WHILE=24
25
25
  DO=25
26
26
  FOR=26
27
- SWITCH=27
28
- CASE=28
29
- DEFAULT=29
30
- RETURN=30
31
- TRUE=31
32
- FALSE=32
33
- C_NULL=33
34
- STRING=34
35
- SIZEOF=35
36
- BITMAP8=36
37
- BITMAP16=37
38
- BITMAP24=38
39
- BITMAP32=39
40
- RW=40
41
- RO=41
42
- WO=42
43
- W1C=43
44
- W1S=44
45
- CLAMP=45
46
- WRAP=46
47
- ATOMIC=47
48
- CRITICAL=48
49
- SUFFIXED_FLOAT=49
50
- SUFFIXED_HEX=50
51
- SUFFIXED_BINARY=51
52
- SUFFIXED_DECIMAL=52
53
- U8=53
54
- U16=54
55
- U32=55
56
- U64=56
57
- I8=57
58
- I16=58
59
- I32=59
60
- I64=60
61
- F32=61
62
- F64=62
63
- BOOL=63
64
- ISR_TYPE=64
65
- LSHIFT_ASSIGN=65
66
- RSHIFT_ASSIGN=66
67
- PLUS_ASSIGN=67
68
- MINUS_ASSIGN=68
69
- STAR_ASSIGN=69
70
- SLASH_ASSIGN=70
71
- PERCENT_ASSIGN=71
72
- BITAND_ASSIGN=72
73
- BITOR_ASSIGN=73
74
- BITXOR_ASSIGN=74
75
- ASSIGN=75
76
- EQ=76
77
- NEQ=77
78
- LT=78
79
- GT=79
80
- LTE=80
81
- GTE=81
82
- PLUS=82
83
- MINUS=83
84
- STAR=84
85
- SLASH=85
86
- PERCENT=86
87
- AND=87
88
- OR=88
89
- NOT=89
90
- BITAND=90
91
- BITOR=91
92
- BITXOR=92
93
- BITNOT=93
94
- LSHIFT=94
95
- RSHIFT=95
96
- LPAREN=96
97
- RPAREN=97
98
- LBRACE=98
99
- RBRACE=99
100
- LBRACKET=100
101
- RBRACKET=101
102
- SEMI=102
103
- COMMA=103
104
- DOT=104
105
- AT=105
106
- COLON=106
107
- HEX_LITERAL=107
108
- BINARY_LITERAL=108
109
- FLOAT_LITERAL=109
110
- INTEGER_LITERAL=110
111
- STRING_LITERAL=111
112
- CHAR_LITERAL=112
113
- IDENTIFIER=113
114
- DOC_COMMENT=114
115
- LINE_COMMENT=115
116
- BLOCK_COMMENT=116
117
- WS=117
27
+ FOREVER=27
28
+ SWITCH=28
29
+ CASE=29
30
+ DEFAULT=30
31
+ RETURN=31
32
+ TRUE=32
33
+ FALSE=33
34
+ C_NULL=34
35
+ STRING=35
36
+ SIZEOF=36
37
+ BITMAP8=37
38
+ BITMAP16=38
39
+ BITMAP24=39
40
+ BITMAP32=40
41
+ RW=41
42
+ RO=42
43
+ WO=43
44
+ W1C=44
45
+ W1S=45
46
+ CLAMP=46
47
+ WRAP=47
48
+ ATOMIC=48
49
+ CRITICAL=49
50
+ SUFFIXED_FLOAT=50
51
+ SUFFIXED_HEX=51
52
+ SUFFIXED_BINARY=52
53
+ SUFFIXED_DECIMAL=53
54
+ U8=54
55
+ U16=55
56
+ U32=56
57
+ U64=57
58
+ I8=58
59
+ I16=59
60
+ I32=60
61
+ I64=61
62
+ F32=62
63
+ F64=63
64
+ BOOL=64
65
+ ISR_TYPE=65
66
+ LSHIFT_ASSIGN=66
67
+ RSHIFT_ASSIGN=67
68
+ PLUS_ASSIGN=68
69
+ MINUS_ASSIGN=69
70
+ STAR_ASSIGN=70
71
+ SLASH_ASSIGN=71
72
+ PERCENT_ASSIGN=72
73
+ BITAND_ASSIGN=73
74
+ BITOR_ASSIGN=74
75
+ BITXOR_ASSIGN=75
76
+ ASSIGN=76
77
+ EQ=77
78
+ NEQ=78
79
+ LT=79
80
+ GT=80
81
+ LTE=81
82
+ GTE=82
83
+ PLUS=83
84
+ MINUS=84
85
+ STAR=85
86
+ SLASH=86
87
+ PERCENT=87
88
+ AND=88
89
+ OR=89
90
+ NOT=90
91
+ BITAND=91
92
+ BITOR=92
93
+ BITXOR=93
94
+ BITNOT=94
95
+ LSHIFT=95
96
+ RSHIFT=96
97
+ LPAREN=97
98
+ RPAREN=98
99
+ LBRACE=99
100
+ RBRACE=100
101
+ LBRACKET=101
102
+ RBRACKET=102
103
+ SEMI=103
104
+ COMMA=104
105
+ DOT=105
106
+ AT=106
107
+ COLON=107
108
+ HEX_LITERAL=108
109
+ BINARY_LITERAL=109
110
+ FLOAT_LITERAL=110
111
+ INTEGER_LITERAL=111
112
+ STRING_LITERAL=112
113
+ CHAR_LITERAL=113
114
+ IDENTIFIER=114
115
+ DOC_COMMENT=115
116
+ LINE_COMMENT=116
117
+ BLOCK_COMMENT=117
118
+ WS=118
118
119
  '?'=1
119
120
  'scope'=11
120
121
  'struct'=12
@@ -132,79 +133,80 @@ WS=117
132
133
  'while'=24
133
134
  'do'=25
134
135
  'for'=26
135
- 'switch'=27
136
- 'case'=28
137
- 'default'=29
138
- 'return'=30
139
- 'true'=31
140
- 'false'=32
141
- 'NULL'=33
142
- 'string'=34
143
- 'sizeof'=35
144
- 'bitmap8'=36
145
- 'bitmap16'=37
146
- 'bitmap24'=38
147
- 'bitmap32'=39
148
- 'rw'=40
149
- 'ro'=41
150
- 'wo'=42
151
- 'w1c'=43
152
- 'w1s'=44
153
- 'clamp'=45
154
- 'wrap'=46
155
- 'atomic'=47
156
- 'critical'=48
157
- 'u8'=53
158
- 'u16'=54
159
- 'u32'=55
160
- 'u64'=56
161
- 'i8'=57
162
- 'i16'=58
163
- 'i32'=59
164
- 'i64'=60
165
- 'f32'=61
166
- 'f64'=62
167
- 'bool'=63
168
- 'ISR'=64
169
- '<<<-'=65
170
- '>><-'=66
171
- '+<-'=67
172
- '-<-'=68
173
- '*<-'=69
174
- '/<-'=70
175
- '%<-'=71
176
- '&<-'=72
177
- '|<-'=73
178
- '^<-'=74
179
- '<-'=75
180
- '='=76
181
- '!='=77
182
- '<'=78
183
- '>'=79
184
- '<='=80
185
- '>='=81
186
- '+'=82
187
- '-'=83
188
- '*'=84
189
- '/'=85
190
- '%'=86
191
- '&&'=87
192
- '||'=88
193
- '!'=89
194
- '&'=90
195
- '|'=91
196
- '^'=92
197
- '~'=93
198
- '<<'=94
199
- '>>'=95
200
- '('=96
201
- ')'=97
202
- '{'=98
203
- '}'=99
204
- '['=100
205
- ']'=101
206
- ';'=102
207
- ','=103
208
- '.'=104
209
- '@'=105
210
- ':'=106
136
+ 'forever'=27
137
+ 'switch'=28
138
+ 'case'=29
139
+ 'default'=30
140
+ 'return'=31
141
+ 'true'=32
142
+ 'false'=33
143
+ 'NULL'=34
144
+ 'string'=35
145
+ 'sizeof'=36
146
+ 'bitmap8'=37
147
+ 'bitmap16'=38
148
+ 'bitmap24'=39
149
+ 'bitmap32'=40
150
+ 'rw'=41
151
+ 'ro'=42
152
+ 'wo'=43
153
+ 'w1c'=44
154
+ 'w1s'=45
155
+ 'clamp'=46
156
+ 'wrap'=47
157
+ 'atomic'=48
158
+ 'critical'=49
159
+ 'u8'=54
160
+ 'u16'=55
161
+ 'u32'=56
162
+ 'u64'=57
163
+ 'i8'=58
164
+ 'i16'=59
165
+ 'i32'=60
166
+ 'i64'=61
167
+ 'f32'=62
168
+ 'f64'=63
169
+ 'bool'=64
170
+ 'ISR'=65
171
+ '<<<-'=66
172
+ '>><-'=67
173
+ '+<-'=68
174
+ '-<-'=69
175
+ '*<-'=70
176
+ '/<-'=71
177
+ '%<-'=72
178
+ '&<-'=73
179
+ '|<-'=74
180
+ '^<-'=75
181
+ '<-'=76
182
+ '='=77
183
+ '!='=78
184
+ '<'=79
185
+ '>'=80
186
+ '<='=81
187
+ '>='=82
188
+ '+'=83
189
+ '-'=84
190
+ '*'=85
191
+ '/'=86
192
+ '%'=87
193
+ '&&'=88
194
+ '||'=89
195
+ '!'=90
196
+ '&'=91
197
+ '|'=92
198
+ '^'=93
199
+ '~'=94
200
+ '<<'=95
201
+ '>>'=96
202
+ '('=97
203
+ ')'=98
204
+ '{'=99
205
+ '}'=100
206
+ '['=101
207
+ ']'=102
208
+ ';'=103
209
+ ','=104
210
+ '.'=105
211
+ '@'=106
212
+ ':'=107