c-next 0.2.11 → 0.2.12
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.
- package/dist/index.js +6127 -5387
- package/dist/index.js.map +3 -3
- package/grammar/C.g4 +8 -1
- package/package.json +3 -2
- package/src/transpiler/Transpiler.ts +11 -3
- package/src/transpiler/logic/parser/c/grammar/C.interp +15 -3
- package/src/transpiler/logic/parser/c/grammar/C.tokens +219 -207
- package/src/transpiler/logic/parser/c/grammar/CLexer.interp +21 -3
- package/src/transpiler/logic/parser/c/grammar/CLexer.tokens +219 -207
- package/src/transpiler/logic/parser/c/grammar/CLexer.ts +643 -606
- package/src/transpiler/logic/parser/c/grammar/CParser.ts +1076 -1038
- package/src/transpiler/logic/symbols/SymbolTable.ts +128 -66
- package/src/transpiler/logic/symbols/__tests__/SymbolTable.test.ts +79 -14
- package/src/transpiler/logic/symbols/c/__tests__/CResolver.integration.test.ts +3 -3
- package/src/transpiler/logic/symbols/c/collectors/StructCollector.ts +7 -37
- package/src/transpiler/output/codegen/CodeGenerator.ts +9 -0
- package/src/transpiler/output/codegen/helpers/FunctionContextManager.ts +15 -3
- package/src/transpiler/output/codegen/helpers/ParameterInputAdapter.ts +14 -6
- package/src/transpiler/output/codegen/helpers/__tests__/ParameterInputAdapter.test.ts +1 -0
- package/src/transpiler/output/codegen/types/IFunctionContextCallbacks.ts +2 -0
- package/src/transpiler/types/ICachedFileEntry.ts +4 -0
- package/src/utils/cache/CacheManager.ts +28 -15
- package/src/utils/cache/__tests__/CacheManager.test.ts +6 -4
|
@@ -22,6 +22,10 @@ interface ICachedFileEntry {
|
|
|
22
22
|
opaqueTypes?: string[];
|
|
23
23
|
/** Issue #958: Typedef struct types with source files ([typeName, sourceFile] pairs) */
|
|
24
24
|
typedefStructTypes?: Array<[string, string]>;
|
|
25
|
+
/** Issue #958: Struct tag → typedef name aliases ([structTag, typedefName] pairs) */
|
|
26
|
+
structTagAliases?: Array<[string, string]>;
|
|
27
|
+
/** Issue #958: Struct tags that have full definitions (bodies) */
|
|
28
|
+
structTagsWithBodies?: string[];
|
|
25
29
|
}
|
|
26
30
|
|
|
27
31
|
export default ICachedFileEntry;
|
|
@@ -32,7 +32,7 @@ import ESourceLanguage from "../types/ESourceLanguage";
|
|
|
32
32
|
const defaultFs = NodeFileSystem.instance;
|
|
33
33
|
|
|
34
34
|
/** Current cache format version - increment when serialization format changes */
|
|
35
|
-
const CACHE_VERSION =
|
|
35
|
+
const CACHE_VERSION = 7; // Issue #958: Add structTagAliases, structTagsWithBodies to cache
|
|
36
36
|
|
|
37
37
|
const TRANSPILER_VERSION = packageJson.version;
|
|
38
38
|
|
|
@@ -136,6 +136,8 @@ class CacheManager {
|
|
|
136
136
|
enumBitWidth: Map<string, number>;
|
|
137
137
|
opaqueTypes: string[];
|
|
138
138
|
typedefStructTypes: Array<[string, string]>;
|
|
139
|
+
structTagAliases: Array<[string, string]>;
|
|
140
|
+
structTagsWithBodies: string[];
|
|
139
141
|
} | null {
|
|
140
142
|
if (!this.cache) return null;
|
|
141
143
|
|
|
@@ -177,6 +179,8 @@ class CacheManager {
|
|
|
177
179
|
enumBitWidth,
|
|
178
180
|
opaqueTypes: cachedEntry.opaqueTypes ?? [],
|
|
179
181
|
typedefStructTypes: cachedEntry.typedefStructTypes ?? [],
|
|
182
|
+
structTagAliases: cachedEntry.structTagAliases ?? [],
|
|
183
|
+
structTagsWithBodies: cachedEntry.structTagsWithBodies ?? [],
|
|
180
184
|
};
|
|
181
185
|
}
|
|
182
186
|
|
|
@@ -188,10 +192,14 @@ class CacheManager {
|
|
|
188
192
|
filePath: string,
|
|
189
193
|
symbols: ISerializedSymbol[],
|
|
190
194
|
structFields: Map<string, Map<string, IStructFieldInfo>>,
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
|
|
195
|
+
options?: {
|
|
196
|
+
needsStructKeyword?: string[];
|
|
197
|
+
enumBitWidth?: Map<string, number>;
|
|
198
|
+
opaqueTypes?: string[];
|
|
199
|
+
typedefStructTypes?: Array<[string, string]>;
|
|
200
|
+
structTagAliases?: Array<[string, string]>;
|
|
201
|
+
structTagsWithBodies?: string[];
|
|
202
|
+
},
|
|
195
203
|
): void {
|
|
196
204
|
if (!this.cache) return;
|
|
197
205
|
|
|
@@ -221,8 +229,8 @@ class CacheManager {
|
|
|
221
229
|
|
|
222
230
|
// Issue #208: Convert enum bit widths from Map to plain object
|
|
223
231
|
const serializedEnumBitWidth: Record<string, number> = {};
|
|
224
|
-
if (enumBitWidth) {
|
|
225
|
-
for (const [enumName, width] of enumBitWidth) {
|
|
232
|
+
if (options?.enumBitWidth) {
|
|
233
|
+
for (const [enumName, width] of options.enumBitWidth) {
|
|
226
234
|
serializedEnumBitWidth[enumName] = width;
|
|
227
235
|
}
|
|
228
236
|
}
|
|
@@ -233,10 +241,12 @@ class CacheManager {
|
|
|
233
241
|
cacheKey,
|
|
234
242
|
symbols: serializedSymbols,
|
|
235
243
|
structFields: serializedFields,
|
|
236
|
-
needsStructKeyword,
|
|
244
|
+
needsStructKeyword: options?.needsStructKeyword,
|
|
237
245
|
enumBitWidth: serializedEnumBitWidth,
|
|
238
|
-
opaqueTypes,
|
|
239
|
-
typedefStructTypes,
|
|
246
|
+
opaqueTypes: options?.opaqueTypes,
|
|
247
|
+
typedefStructTypes: options?.typedefStructTypes,
|
|
248
|
+
structTagAliases: options?.structTagAliases,
|
|
249
|
+
structTagsWithBodies: options?.structTagsWithBodies,
|
|
240
250
|
};
|
|
241
251
|
|
|
242
252
|
this.cache.setKey(filePath, entry);
|
|
@@ -280,16 +290,19 @@ class CacheManager {
|
|
|
280
290
|
// Issue #958: Extract typedef struct types (all typedef'd structs)
|
|
281
291
|
const typedefStructTypes = symbolTable.getAllTypedefStructTypes();
|
|
282
292
|
|
|
293
|
+
// Issue #958: Extract struct tag aliases and body tracking
|
|
294
|
+
const structTagAliases = symbolTable.getAllStructTagAliases();
|
|
295
|
+
const structTagsWithBodies = symbolTable.getAllStructTagsWithBodies();
|
|
296
|
+
|
|
283
297
|
// Delegate to existing setSymbols method
|
|
284
|
-
this.setSymbols(
|
|
285
|
-
filePath,
|
|
286
|
-
symbols,
|
|
287
|
-
structFields,
|
|
298
|
+
this.setSymbols(filePath, symbols, structFields, {
|
|
288
299
|
needsStructKeyword,
|
|
289
300
|
enumBitWidth,
|
|
290
301
|
opaqueTypes,
|
|
291
302
|
typedefStructTypes,
|
|
292
|
-
|
|
303
|
+
structTagAliases,
|
|
304
|
+
structTagsWithBodies,
|
|
305
|
+
});
|
|
293
306
|
}
|
|
294
307
|
|
|
295
308
|
/**
|
|
@@ -361,7 +361,9 @@ describe("CacheManager", () => {
|
|
|
361
361
|
const testFile = join(testDir, "test.h");
|
|
362
362
|
writeFileSync(testFile, "// test");
|
|
363
363
|
|
|
364
|
-
cacheManager.setSymbols(testFile, [], new Map(),
|
|
364
|
+
cacheManager.setSymbols(testFile, [], new Map(), {
|
|
365
|
+
needsStructKeyword: ["Point", "Rectangle"],
|
|
366
|
+
});
|
|
365
367
|
|
|
366
368
|
const cached = cacheManager.getSymbols(testFile);
|
|
367
369
|
expect(cached!.needsStructKeyword).toEqual(["Point", "Rectangle"]);
|
|
@@ -391,7 +393,7 @@ describe("CacheManager", () => {
|
|
|
391
393
|
enumBitWidth.set("Status", 8);
|
|
392
394
|
enumBitWidth.set("Mode", 16);
|
|
393
395
|
|
|
394
|
-
cacheManager.setSymbols(testFile, [], new Map(),
|
|
396
|
+
cacheManager.setSymbols(testFile, [], new Map(), { enumBitWidth });
|
|
395
397
|
|
|
396
398
|
const cached = cacheManager.getSymbols(testFile);
|
|
397
399
|
expect(cached!.enumBitWidth.get("Status")).toBe(8);
|
|
@@ -405,7 +407,7 @@ describe("CacheManager", () => {
|
|
|
405
407
|
const enumBitWidth = new Map<string, number>();
|
|
406
408
|
enumBitWidth.set("Priority", 32);
|
|
407
409
|
|
|
408
|
-
cacheManager.setSymbols(testFile, [], new Map(),
|
|
410
|
+
cacheManager.setSymbols(testFile, [], new Map(), { enumBitWidth });
|
|
409
411
|
await cacheManager.flush();
|
|
410
412
|
|
|
411
413
|
// Reload
|
|
@@ -1492,7 +1494,7 @@ describe("CacheManager", () => {
|
|
|
1492
1494
|
const content = mockFs.getWrittenContent("/project/.cnx/config.json");
|
|
1493
1495
|
expect(content).toBeDefined();
|
|
1494
1496
|
const newConfig = JSON.parse(content!);
|
|
1495
|
-
expect(newConfig.version).toBe(
|
|
1497
|
+
expect(newConfig.version).toBe(7); // Current CACHE_VERSION (Issue #958 structTagAliases, structTagsWithBodies)
|
|
1496
1498
|
});
|
|
1497
1499
|
|
|
1498
1500
|
it("should not cache files that do not exist in IFileSystem", async () => {
|