c-next 0.1.0

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 (72) hide show
  1. package/README.md +726 -0
  2. package/bin/cnext.js +5 -0
  3. package/grammar/C.g4 +1112 -0
  4. package/grammar/CNext.g4 +817 -0
  5. package/grammar/CPP14Lexer.g4 +282 -0
  6. package/grammar/CPP14Parser.g4 +1072 -0
  7. package/package.json +85 -0
  8. package/src/analysis/DivisionByZeroAnalyzer.ts +378 -0
  9. package/src/analysis/FunctionCallAnalyzer.ts +526 -0
  10. package/src/analysis/InitializationAnalyzer.ts +725 -0
  11. package/src/analysis/NullCheckAnalyzer.ts +427 -0
  12. package/src/analysis/types/IDivisionByZeroError.ts +25 -0
  13. package/src/analysis/types/IFunctionCallError.ts +17 -0
  14. package/src/analysis/types/IInitializationError.ts +55 -0
  15. package/src/analysis/types/INullCheckError.ts +25 -0
  16. package/src/codegen/CodeGenerator.ts +7945 -0
  17. package/src/codegen/CommentExtractor.ts +240 -0
  18. package/src/codegen/CommentFormatter.ts +155 -0
  19. package/src/codegen/HeaderGenerator.ts +265 -0
  20. package/src/codegen/TypeResolver.ts +365 -0
  21. package/src/codegen/types/ECommentType.ts +10 -0
  22. package/src/codegen/types/IComment.ts +21 -0
  23. package/src/codegen/types/ICommentError.ts +15 -0
  24. package/src/codegen/types/TOverflowBehavior.ts +6 -0
  25. package/src/codegen/types/TParameterInfo.ts +13 -0
  26. package/src/codegen/types/TTypeConstants.ts +94 -0
  27. package/src/codegen/types/TTypeInfo.ts +22 -0
  28. package/src/index.ts +518 -0
  29. package/src/lib/IncludeDiscovery.ts +131 -0
  30. package/src/lib/InputExpansion.ts +121 -0
  31. package/src/lib/PlatformIODetector.ts +162 -0
  32. package/src/lib/transpiler.ts +439 -0
  33. package/src/lib/types/ITranspileResult.ts +80 -0
  34. package/src/parser/c/grammar/C.interp +338 -0
  35. package/src/parser/c/grammar/C.tokens +229 -0
  36. package/src/parser/c/grammar/CLexer.interp +415 -0
  37. package/src/parser/c/grammar/CLexer.tokens +229 -0
  38. package/src/parser/c/grammar/CLexer.ts +750 -0
  39. package/src/parser/c/grammar/CListener.ts +976 -0
  40. package/src/parser/c/grammar/CParser.ts +9663 -0
  41. package/src/parser/c/grammar/CVisitor.ts +626 -0
  42. package/src/parser/cpp/grammar/CPP14Lexer.interp +478 -0
  43. package/src/parser/cpp/grammar/CPP14Lexer.tokens +264 -0
  44. package/src/parser/cpp/grammar/CPP14Lexer.ts +848 -0
  45. package/src/parser/cpp/grammar/CPP14Parser.interp +492 -0
  46. package/src/parser/cpp/grammar/CPP14Parser.tokens +264 -0
  47. package/src/parser/cpp/grammar/CPP14Parser.ts +19961 -0
  48. package/src/parser/cpp/grammar/CPP14ParserListener.ts +2120 -0
  49. package/src/parser/cpp/grammar/CPP14ParserVisitor.ts +1354 -0
  50. package/src/parser/grammar/CNext.interp +340 -0
  51. package/src/parser/grammar/CNext.tokens +214 -0
  52. package/src/parser/grammar/CNextLexer.interp +374 -0
  53. package/src/parser/grammar/CNextLexer.tokens +214 -0
  54. package/src/parser/grammar/CNextLexer.ts +668 -0
  55. package/src/parser/grammar/CNextListener.ts +1020 -0
  56. package/src/parser/grammar/CNextParser.ts +9239 -0
  57. package/src/parser/grammar/CNextVisitor.ts +654 -0
  58. package/src/preprocessor/Preprocessor.ts +301 -0
  59. package/src/preprocessor/ToolchainDetector.ts +225 -0
  60. package/src/preprocessor/types/IPreprocessResult.ts +39 -0
  61. package/src/preprocessor/types/IToolchain.ts +27 -0
  62. package/src/project/FileDiscovery.ts +236 -0
  63. package/src/project/Project.ts +425 -0
  64. package/src/project/types/IProjectConfig.ts +64 -0
  65. package/src/symbols/CNextSymbolCollector.ts +326 -0
  66. package/src/symbols/CSymbolCollector.ts +457 -0
  67. package/src/symbols/CppSymbolCollector.ts +362 -0
  68. package/src/symbols/SymbolTable.ts +312 -0
  69. package/src/symbols/types/IConflict.ts +20 -0
  70. package/src/types/ESourceLanguage.ts +10 -0
  71. package/src/types/ESymbolKind.ts +20 -0
  72. package/src/types/ISymbol.ts +45 -0
@@ -0,0 +1,282 @@
1
+ // $antlr-format alignTrailingComments true, columnLimit 150, maxEmptyLinesToKeep 1, reflowComments false, useTab false
2
+ // $antlr-format allowShortRulesOnASingleLine true, allowShortBlocksOnASingleLine true, minEmptyLines 0, alignSemicolons ownLine
3
+ // $antlr-format alignColons trailing, singleLineOverrulesHangingColon true, alignLexerCommands true, alignLabels true, alignTrailers true
4
+
5
+ lexer grammar CPP14Lexer;
6
+
7
+ IntegerLiteral:
8
+ DecimalLiteral Integersuffix?
9
+ | OctalLiteral Integersuffix?
10
+ | HexadecimalLiteral Integersuffix?
11
+ | BinaryLiteral Integersuffix?
12
+ ;
13
+
14
+ CharacterLiteral: ('u' | 'U' | 'L')? '\'' Cchar+ '\'';
15
+
16
+ FloatingLiteral:
17
+ Fractionalconstant Exponentpart? Floatingsuffix?
18
+ | Digitsequence Exponentpart Floatingsuffix?
19
+ ;
20
+
21
+ StringLiteral: Encodingprefix? (Rawstring | '"' Schar* '"');
22
+
23
+ BooleanLiteral: False_ | True_;
24
+
25
+ PointerLiteral: Nullptr;
26
+
27
+ UserDefinedLiteral:
28
+ UserDefinedIntegerLiteral
29
+ | UserDefinedFloatingLiteral
30
+ | UserDefinedStringLiteral
31
+ | UserDefinedCharacterLiteral
32
+ ;
33
+
34
+ MultiLineMacro: '#' (~[\n]*? '\\' '\r'? '\n')+ ~ [\n]+ -> channel (HIDDEN);
35
+
36
+ Directive: '#' ~ [\n]* -> channel (HIDDEN);
37
+
38
+ /*Keywords*/
39
+
40
+ Alignas: 'alignas';
41
+ Alignof: 'alignof';
42
+ Asm: 'asm';
43
+ Auto: 'auto';
44
+ Bool: 'bool';
45
+ Break: 'break';
46
+ Case: 'case';
47
+ Catch: 'catch';
48
+ Char: 'char';
49
+ Char16: 'char16_t';
50
+ Char32: 'char32_t';
51
+ Class: 'class';
52
+ Const: 'const';
53
+ Constexpr: 'constexpr';
54
+ Const_cast: 'const_cast';
55
+ Continue: 'continue';
56
+ Decltype: 'decltype';
57
+ Default: 'default';
58
+ Delete: 'delete';
59
+ Do: 'do';
60
+ Double: 'double';
61
+ Dynamic_cast: 'dynamic_cast';
62
+ Else: 'else';
63
+ Enum: 'enum';
64
+ Explicit: 'explicit';
65
+ Export: 'export';
66
+ Extern: 'extern';
67
+
68
+ //DO NOT RENAME - PYTHON NEEDS True and False
69
+ False_: 'false';
70
+
71
+ Final: 'final';
72
+ Float: 'float';
73
+ For: 'for';
74
+ Friend: 'friend';
75
+ Goto: 'goto';
76
+ If: 'if';
77
+ Inline: 'inline';
78
+ Int: 'int';
79
+ Long: 'long';
80
+ Mutable: 'mutable';
81
+ Namespace: 'namespace';
82
+ New: 'new';
83
+ Noexcept: 'noexcept';
84
+ Nullptr: 'nullptr';
85
+ Operator: 'operator';
86
+ Override: 'override';
87
+ Private: 'private';
88
+ Protected: 'protected';
89
+ Public: 'public';
90
+ Register: 'register';
91
+ Reinterpret_cast: 'reinterpret_cast';
92
+ Return: 'return';
93
+ Short: 'short';
94
+ Signed: 'signed';
95
+ Sizeof: 'sizeof';
96
+ Static: 'static';
97
+ Static_assert: 'static_assert';
98
+ Static_cast: 'static_cast';
99
+ Struct: 'struct';
100
+ Switch: 'switch';
101
+ Template: 'template';
102
+ This: 'this';
103
+ Thread_local: 'thread_local';
104
+ Throw: 'throw';
105
+
106
+ //DO NOT RENAME - PYTHON NEEDS True and False
107
+ True_: 'true';
108
+
109
+ Try: 'try';
110
+ Typedef: 'typedef';
111
+ Typeid_: 'typeid';
112
+ Typename_: 'typename';
113
+ Union: 'union';
114
+ Unsigned: 'unsigned';
115
+ Using: 'using';
116
+ Virtual: 'virtual';
117
+ Void: 'void';
118
+ Volatile: 'volatile';
119
+ Wchar: 'wchar_t';
120
+ While: 'while';
121
+
122
+ /*Operators*/
123
+
124
+ LeftParen: '(';
125
+ RightParen: ')';
126
+ LeftBracket: '[';
127
+ RightBracket: ']';
128
+ LeftBrace: '{';
129
+ RightBrace: '}';
130
+ Plus: '+';
131
+ Minus: '-';
132
+ Star: '*';
133
+ Div: '/';
134
+ Mod: '%';
135
+ Caret: '^';
136
+ And: '&';
137
+ Or: '|';
138
+ Tilde: '~';
139
+ Not: '!' | 'not';
140
+ Assign: '=';
141
+ Less: '<';
142
+ Greater: '>';
143
+ PlusAssign: '+=';
144
+ MinusAssign: '-=';
145
+ StarAssign: '*=';
146
+ DivAssign: '/=';
147
+ ModAssign: '%=';
148
+ XorAssign: '^=';
149
+ AndAssign: '&=';
150
+ OrAssign: '|=';
151
+ LeftShiftAssign: '<<=';
152
+ RightShiftAssign: '>>=';
153
+ Equal: '==';
154
+ NotEqual: '!=';
155
+ LessEqual: '<=';
156
+ GreaterEqual: '>=';
157
+ AndAnd: '&&' | 'and';
158
+ OrOr: '||' | 'or';
159
+ PlusPlus: '++';
160
+ MinusMinus: '--';
161
+ Comma: ',';
162
+ ArrowStar: '->*';
163
+ Arrow: '->';
164
+ Question: '?';
165
+ Colon: ':';
166
+ Doublecolon: '::';
167
+ Semi: ';';
168
+ Dot: '.';
169
+ DotStar: '.*';
170
+ Ellipsis: '...';
171
+
172
+ fragment Hexquad: HEXADECIMALDIGIT HEXADECIMALDIGIT HEXADECIMALDIGIT HEXADECIMALDIGIT;
173
+
174
+ fragment Universalcharactername: '\\u' Hexquad | '\\U' Hexquad Hexquad;
175
+
176
+ Identifier:
177
+ Identifiernondigit (Identifiernondigit | DIGIT)*
178
+ ;
179
+
180
+ fragment Identifiernondigit: NONDIGIT | Universalcharactername;
181
+
182
+ fragment NONDIGIT: [a-zA-Z_];
183
+
184
+ fragment DIGIT: [0-9];
185
+
186
+ DecimalLiteral: NONZERODIGIT ('\''? DIGIT)*;
187
+
188
+ OctalLiteral: '0' ('\''? OCTALDIGIT)*;
189
+
190
+ HexadecimalLiteral: ('0x' | '0X') HEXADECIMALDIGIT ( '\''? HEXADECIMALDIGIT)*;
191
+
192
+ BinaryLiteral: ('0b' | '0B') BINARYDIGIT ('\''? BINARYDIGIT)*;
193
+
194
+ fragment NONZERODIGIT: [1-9];
195
+
196
+ fragment OCTALDIGIT: [0-7];
197
+
198
+ fragment HEXADECIMALDIGIT: [0-9a-fA-F];
199
+
200
+ fragment BINARYDIGIT: [01];
201
+
202
+ Integersuffix:
203
+ Unsignedsuffix Longsuffix?
204
+ | Unsignedsuffix Longlongsuffix?
205
+ | Longsuffix Unsignedsuffix?
206
+ | Longlongsuffix Unsignedsuffix?
207
+ ;
208
+
209
+ fragment Unsignedsuffix: [uU];
210
+
211
+ fragment Longsuffix: [lL];
212
+
213
+ fragment Longlongsuffix: 'll' | 'LL';
214
+
215
+ fragment Cchar: ~ ['\\\r\n] | Escapesequence | Universalcharactername;
216
+
217
+ fragment Escapesequence: Simpleescapesequence | Octalescapesequence | Hexadecimalescapesequence;
218
+
219
+ fragment Simpleescapesequence:
220
+ '\\\''
221
+ | '\\"'
222
+ | '\\?'
223
+ | '\\\\'
224
+ | '\\a'
225
+ | '\\b'
226
+ | '\\f'
227
+ | '\\n'
228
+ | '\\r'
229
+ | '\\' ('\r' '\n'? | '\n')
230
+ | '\\t'
231
+ | '\\v'
232
+ ;
233
+
234
+ fragment Octalescapesequence:
235
+ '\\' OCTALDIGIT
236
+ | '\\' OCTALDIGIT OCTALDIGIT
237
+ | '\\' OCTALDIGIT OCTALDIGIT OCTALDIGIT
238
+ ;
239
+
240
+ fragment Hexadecimalescapesequence: '\\x' HEXADECIMALDIGIT+;
241
+
242
+ fragment Fractionalconstant: Digitsequence? '.' Digitsequence | Digitsequence '.';
243
+
244
+ fragment Exponentpart: 'e' SIGN? Digitsequence | 'E' SIGN? Digitsequence;
245
+
246
+ fragment SIGN: [+-];
247
+
248
+ fragment Digitsequence: DIGIT ('\''? DIGIT)*;
249
+
250
+ fragment Floatingsuffix: [flFL];
251
+
252
+ fragment Encodingprefix: 'u8' | 'u' | 'U' | 'L';
253
+
254
+ fragment Schar: ~ ["\\\r\n] | Escapesequence | Universalcharactername;
255
+
256
+ fragment Rawstring: 'R"' ( '\\' ["()] | ~[\r\n (])*? '(' ~[)]*? ')' ( '\\' ["()] | ~[\r\n "])*? '"';
257
+
258
+ UserDefinedIntegerLiteral:
259
+ DecimalLiteral Udsuffix
260
+ | OctalLiteral Udsuffix
261
+ | HexadecimalLiteral Udsuffix
262
+ | BinaryLiteral Udsuffix
263
+ ;
264
+
265
+ UserDefinedFloatingLiteral:
266
+ Fractionalconstant Exponentpart? Udsuffix
267
+ | Digitsequence Exponentpart Udsuffix
268
+ ;
269
+
270
+ UserDefinedStringLiteral: StringLiteral Udsuffix;
271
+
272
+ UserDefinedCharacterLiteral: CharacterLiteral Udsuffix;
273
+
274
+ fragment Udsuffix: Identifier;
275
+
276
+ Whitespace: [ \t]+ -> skip;
277
+
278
+ Newline: ('\r' '\n'? | '\n') -> skip;
279
+
280
+ BlockComment: '/*' .*? '*/' -> skip;
281
+
282
+ LineComment: '//' ~ [\r\n]* -> skip;