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.
- package/package.json +1 -1
- package/src/lib/__tests__/parseCHeader.mocked.test.ts +69 -54
- package/src/lib/parseCHeader.ts +56 -23
- package/src/lib/parseWithSymbols.ts +195 -53
- package/src/transpiler/Transpiler.ts +180 -63
- package/src/transpiler/logic/analysis/FunctionCallAnalyzer.ts +1 -2
- package/src/transpiler/logic/analysis/InitializationAnalyzer.ts +1 -2
- package/src/transpiler/logic/analysis/PassByValueAnalyzer.ts +51 -2
- package/src/transpiler/logic/analysis/__tests__/FunctionCallAnalyzer.test.ts +18 -12
- package/src/transpiler/logic/analysis/__tests__/InitializationAnalyzer.test.ts +9 -9
- package/src/transpiler/logic/analysis/__tests__/runAnalyzers.test.ts +5 -5
- package/src/transpiler/logic/symbols/SymbolTable.ts +729 -265
- package/src/transpiler/logic/symbols/SymbolUtils.ts +2 -2
- package/src/transpiler/logic/symbols/__tests__/SymbolTable.test.ts +415 -751
- package/src/transpiler/logic/symbols/c/__tests__/CResolver.integration.test.ts +573 -0
- package/src/transpiler/logic/symbols/c/__tests__/testHelpers.ts +20 -0
- package/src/transpiler/logic/symbols/c/collectors/EnumCollector.ts +82 -0
- package/src/transpiler/logic/symbols/c/collectors/FunctionCollector.ts +106 -0
- package/src/transpiler/logic/symbols/c/collectors/StructCollector.ts +173 -0
- package/src/transpiler/logic/symbols/c/collectors/TypedefCollector.ts +35 -0
- package/src/transpiler/logic/symbols/c/collectors/VariableCollector.ts +80 -0
- package/src/transpiler/logic/symbols/c/index.ts +333 -0
- package/src/transpiler/logic/symbols/c/utils/DeclaratorUtils.ts +269 -0
- package/src/transpiler/logic/symbols/cnext/__tests__/BitmapCollector.test.ts +50 -11
- package/src/transpiler/logic/symbols/cnext/__tests__/CNextResolver.integration.test.ts +45 -34
- package/src/transpiler/logic/symbols/cnext/__tests__/EnumCollector.test.ts +30 -13
- package/src/transpiler/logic/symbols/cnext/__tests__/FunctionCollector.test.ts +279 -64
- package/src/transpiler/logic/symbols/cnext/__tests__/RegisterCollector.test.ts +60 -13
- package/src/transpiler/logic/symbols/cnext/__tests__/ScopeCollector.test.ts +40 -37
- package/src/transpiler/logic/symbols/cnext/__tests__/StructCollector.test.ts +131 -45
- package/src/transpiler/logic/symbols/cnext/__tests__/TSymbolInfoAdapter.test.ts +223 -139
- package/src/transpiler/logic/symbols/cnext/__tests__/VariableCollector.test.ts +79 -25
- package/src/transpiler/logic/symbols/cnext/__tests__/testUtils.ts +53 -0
- package/src/transpiler/logic/symbols/cnext/adapters/TSymbolInfoAdapter.ts +83 -43
- package/src/transpiler/logic/symbols/cnext/collectors/BitmapCollector.ts +14 -13
- package/src/transpiler/logic/symbols/cnext/collectors/EnumCollector.ts +11 -10
- package/src/transpiler/logic/symbols/cnext/collectors/FunctionCollector.ts +83 -34
- package/src/transpiler/logic/symbols/cnext/collectors/RegisterCollector.ts +22 -18
- package/src/transpiler/logic/symbols/cnext/collectors/ScopeCollector.ts +53 -35
- package/src/transpiler/logic/symbols/cnext/collectors/StructCollector.ts +30 -23
- package/src/transpiler/logic/symbols/cnext/collectors/VariableCollector.ts +18 -19
- package/src/transpiler/logic/symbols/cnext/index.ts +36 -14
- package/src/transpiler/logic/symbols/cnext/types/IScopeCollectorResult.ts +2 -2
- package/src/transpiler/logic/symbols/cnext/utils/SymbolNameUtils.ts +27 -0
- package/src/transpiler/logic/symbols/cpp/__tests__/CppResolver.integration.test.ts +270 -0
- package/src/transpiler/logic/symbols/cpp/__tests__/testHelpers.ts +20 -0
- package/src/transpiler/logic/symbols/cpp/collectors/ClassCollector.ts +317 -0
- package/src/transpiler/logic/symbols/cpp/collectors/EnumCollector.ts +71 -0
- package/src/transpiler/logic/symbols/cpp/collectors/FunctionCollector.ts +155 -0
- package/src/transpiler/logic/symbols/cpp/collectors/NamespaceCollector.ts +65 -0
- package/src/transpiler/logic/symbols/cpp/collectors/TypeAliasCollector.ts +46 -0
- package/src/transpiler/logic/symbols/cpp/collectors/VariableCollector.ts +54 -0
- package/src/transpiler/logic/symbols/cpp/index.ts +366 -0
- package/src/transpiler/logic/symbols/cpp/utils/DeclaratorUtils.ts +248 -0
- package/src/transpiler/logic/symbols/shared/IExtractedParameter.ts +18 -0
- package/src/transpiler/logic/symbols/shared/ParameterExtractorUtils.ts +73 -0
- package/src/transpiler/output/codegen/CodeGenerator.ts +268 -1674
- package/src/transpiler/output/codegen/__tests__/CodeGenerator.test.ts +7 -1
- package/src/transpiler/output/codegen/assignment/AssignmentClassifier.ts +2 -1
- package/src/transpiler/output/codegen/assignment/handlers/AssignmentHandlerUtils.ts +7 -1
- package/src/transpiler/output/codegen/assignment/handlers/BitmapHandlers.ts +6 -2
- package/src/transpiler/output/codegen/assignment/handlers/RegisterHandlers.ts +2 -1
- package/src/transpiler/output/codegen/generators/declarationGenerators/ScopeGenerator.ts +21 -8
- package/src/transpiler/output/codegen/generators/declarationGenerators/ScopedRegisterGenerator.ts +3 -2
- package/src/transpiler/output/codegen/generators/expressions/CallExprUtils.ts +9 -3
- package/src/transpiler/output/codegen/generators/expressions/__tests__/CallExprGenerator.test.ts +3 -4
- package/src/transpiler/output/codegen/generators/expressions/__tests__/CallExprUtils.test.ts +4 -8
- package/src/transpiler/output/codegen/helpers/ArgumentGenerator.ts +236 -0
- package/src/transpiler/output/codegen/helpers/CppConstructorHelper.ts +3 -3
- package/src/transpiler/output/codegen/helpers/FunctionContextManager.ts +435 -0
- package/src/transpiler/output/codegen/helpers/StringOperationsHelper.ts +203 -0
- package/src/transpiler/output/codegen/helpers/SymbolLookupHelper.ts +8 -12
- package/src/transpiler/output/codegen/helpers/TypeRegistrationEngine.ts +520 -0
- package/src/transpiler/output/codegen/helpers/VariableDeclHelper.ts +735 -0
- package/src/transpiler/output/codegen/helpers/VariableDeclarationFormatter.ts +1 -1
- package/src/transpiler/output/codegen/helpers/__tests__/ArgumentGenerator.test.ts +521 -0
- package/src/transpiler/output/codegen/helpers/__tests__/CppConstructorHelper.test.ts +4 -5
- package/src/transpiler/output/codegen/helpers/__tests__/FunctionContextManager.test.ts +983 -0
- package/src/transpiler/output/codegen/helpers/__tests__/StringOperationsHelper.test.ts +269 -0
- package/src/transpiler/output/codegen/helpers/__tests__/SymbolLookupHelper.test.ts +31 -32
- package/src/transpiler/output/codegen/helpers/__tests__/TypeRegistrationEngine.test.ts +186 -0
- package/src/transpiler/output/codegen/helpers/__tests__/VariableDeclHelper.test.ts +460 -0
- package/src/transpiler/output/codegen/helpers/types/IArgumentGeneratorCallbacks.ts +32 -0
- package/src/transpiler/output/codegen/resolution/EnumTypeResolver.ts +5 -1
- package/src/transpiler/output/codegen/types/IFunctionContextCallbacks.ts +12 -0
- package/src/transpiler/output/codegen/types/IVariableFormatInput.ts +1 -1
- package/src/transpiler/output/codegen/utils/QualifiedNameGenerator.ts +114 -0
- package/src/transpiler/output/codegen/utils/__tests__/QualifiedNameGenerator.test.ts +183 -0
- package/src/transpiler/output/headers/BaseHeaderGenerator.ts +4 -4
- package/src/transpiler/output/headers/ExternalTypeHeaderBuilder.ts +7 -7
- package/src/transpiler/output/headers/HeaderGenerator.ts +9 -7
- package/src/transpiler/output/headers/HeaderGeneratorUtils.ts +19 -20
- package/src/transpiler/output/headers/__tests__/BaseHeaderGenerator.test.ts +15 -18
- package/src/transpiler/output/headers/__tests__/CHeaderGenerator.test.ts +63 -64
- package/src/transpiler/output/headers/__tests__/CppHeaderGenerator.test.ts +36 -32
- package/src/transpiler/output/headers/__tests__/ExternalTypeHeaderBuilder.test.ts +26 -26
- package/src/transpiler/output/headers/__tests__/HeaderGenerator.test.ts +87 -59
- package/src/transpiler/output/headers/__tests__/HeaderGeneratorUtils.test.ts +57 -58
- package/src/transpiler/output/headers/adapters/HeaderSymbolAdapter.ts +222 -0
- package/src/transpiler/output/headers/adapters/__tests__/HeaderSymbolAdapter.test.ts +538 -0
- package/src/transpiler/output/headers/types/IGroupedSymbols.ts +8 -8
- package/src/transpiler/output/headers/types/IHeaderSymbol.ts +62 -0
- package/src/transpiler/state/CodeGenState.ts +20 -33
- package/src/transpiler/state/SymbolRegistry.ts +181 -0
- package/src/transpiler/{types → state}/TranspilerState.ts +1 -1
- package/src/transpiler/state/__tests__/CodeGenState.test.ts +67 -59
- package/src/transpiler/state/__tests__/SymbolRegistry.test.ts +249 -0
- package/src/transpiler/{types → state}/__tests__/TranspilerState.test.ts +1 -1
- package/src/transpiler/types/ICachedFileEntry.ts +1 -1
- package/src/transpiler/types/IConflict.ts +14 -0
- package/src/transpiler/types/IPipelineInput.ts +0 -3
- package/src/transpiler/types/ISerializedSymbol.ts +11 -0
- package/src/transpiler/types/TPrimitiveKind.ts +20 -0
- package/src/transpiler/types/TType.ts +103 -0
- package/src/transpiler/types/TVisibility.ts +6 -0
- package/src/transpiler/types/symbol-kinds/TSymbolKind.ts +10 -0
- package/src/transpiler/types/symbol-kinds/TSymbolKindC.ts +12 -0
- package/src/transpiler/types/symbol-kinds/TSymbolKindCNext.ts +16 -0
- package/src/transpiler/types/symbol-kinds/TSymbolKindCpp.ts +14 -0
- package/src/transpiler/types/symbols/IBaseSymbol.ts +31 -0
- package/src/transpiler/{logic/symbols/types → types/symbols}/IBitmapFieldInfo.ts +2 -2
- package/src/transpiler/types/symbols/IBitmapSymbol.ts +21 -0
- package/src/transpiler/{logic/symbols/types → types/symbols}/IEnumSymbol.ts +5 -6
- package/src/transpiler/types/symbols/IFieldInfo.ts +26 -0
- package/src/transpiler/types/symbols/IFunctionSymbol.ts +30 -0
- package/src/transpiler/types/symbols/IParameterInfo.ts +26 -0
- package/src/transpiler/{logic/symbols/types → types/symbols}/IRegisterMemberInfo.ts +4 -4
- package/src/transpiler/types/symbols/IRegisterSymbol.ts +18 -0
- package/src/transpiler/types/symbols/IScopeSymbol.ts +32 -0
- package/src/transpiler/{logic/symbols/types → types/symbols}/IStructFieldInfo.ts +2 -1
- package/src/transpiler/types/symbols/IStructSymbol.ts +15 -0
- package/src/transpiler/types/symbols/IVariableSymbol.ts +30 -0
- package/src/transpiler/types/symbols/SymbolGuards.ts +43 -0
- package/src/transpiler/types/symbols/TAnySymbol.ts +22 -0
- package/src/transpiler/types/symbols/TSymbol.ts +32 -0
- package/src/transpiler/types/symbols/__tests__/IBaseSymbol.test.ts +56 -0
- package/src/transpiler/types/symbols/__tests__/SymbolGuards.test.ts +57 -0
- package/src/transpiler/types/symbols/c/ICBaseSymbol.ts +28 -0
- package/src/transpiler/types/symbols/c/ICEnumMemberSymbol.ts +17 -0
- package/src/transpiler/types/symbols/c/ICEnumSymbol.ts +17 -0
- package/src/transpiler/types/symbols/c/ICFieldInfo.ts +16 -0
- package/src/transpiler/types/symbols/c/ICFunctionSymbol.ts +21 -0
- package/src/transpiler/types/symbols/c/ICParameterInfo.ts +19 -0
- package/src/transpiler/types/symbols/c/ICStructSymbol.ts +21 -0
- package/src/transpiler/types/symbols/c/ICTypedefSymbol.ts +14 -0
- package/src/transpiler/types/symbols/c/ICVariableSymbol.ts +26 -0
- package/src/transpiler/types/symbols/c/TCSymbol.ts +26 -0
- package/src/transpiler/types/symbols/cpp/ICppBaseSymbol.ts +31 -0
- package/src/transpiler/types/symbols/cpp/ICppClassSymbol.ts +15 -0
- package/src/transpiler/types/symbols/cpp/ICppEnumMemberSymbol.ts +14 -0
- package/src/transpiler/types/symbols/cpp/ICppEnumSymbol.ts +14 -0
- package/src/transpiler/types/symbols/cpp/ICppFieldInfo.ts +16 -0
- package/src/transpiler/types/symbols/cpp/ICppFunctionSymbol.ts +21 -0
- package/src/transpiler/types/symbols/cpp/ICppNamespaceSymbol.ts +11 -0
- package/src/transpiler/types/symbols/cpp/ICppParameterInfo.ts +19 -0
- package/src/transpiler/types/symbols/cpp/ICppStructSymbol.ts +16 -0
- package/src/transpiler/types/symbols/cpp/ICppTypeAliasSymbol.ts +14 -0
- package/src/transpiler/types/symbols/cpp/ICppVariableSymbol.ts +23 -0
- package/src/transpiler/types/symbols/cpp/TCppSymbol.ts +30 -0
- package/src/utils/CppNamespaceUtils.ts +3 -4
- package/src/utils/FunctionUtils.ts +92 -0
- package/src/utils/ParameterUtils.ts +55 -0
- package/src/utils/PrimitiveKindUtils.ts +33 -0
- package/src/utils/ScopeUtils.ts +105 -0
- package/src/utils/TTypeUtils.ts +159 -0
- package/src/utils/TypeResolver.ts +132 -0
- package/src/utils/__tests__/CppNamespaceUtils.test.ts +92 -99
- package/src/utils/__tests__/FunctionUtils.test.ts +284 -0
- package/src/utils/__tests__/ParameterUtils.test.ts +174 -0
- package/src/utils/__tests__/PrimitiveKindUtils.test.ts +59 -0
- package/src/utils/__tests__/ScopeUtils.test.ts +53 -0
- package/src/utils/__tests__/TTypeUtils.test.ts +245 -0
- package/src/utils/__tests__/TypeResolver.test.ts +332 -0
- package/src/utils/cache/CacheManager.ts +91 -50
- package/src/utils/cache/__tests__/CacheManager.test.ts +180 -114
- package/src/transpiler/logic/symbols/AutoConstUpdater.ts +0 -93
- package/src/transpiler/logic/symbols/CSymbolCollector.ts +0 -648
- package/src/transpiler/logic/symbols/CppSymbolCollector.ts +0 -874
- package/src/transpiler/logic/symbols/SymbolCollectorContext.ts +0 -68
- package/src/transpiler/logic/symbols/__tests__/AutoConstUpdater.test.ts +0 -418
- package/src/transpiler/logic/symbols/__tests__/CSymbolCollector.test.ts +0 -685
- package/src/transpiler/logic/symbols/__tests__/CppSymbolCollector.test.ts +0 -1146
- package/src/transpiler/logic/symbols/__tests__/SymbolCollectorContext.test.ts +0 -290
- package/src/transpiler/logic/symbols/__tests__/cTestHelpers.ts +0 -43
- package/src/transpiler/logic/symbols/__tests__/cppTestHelpers.ts +0 -40
- package/src/transpiler/logic/symbols/cnext/__tests__/TSymbolAdapter.test.ts +0 -595
- package/src/transpiler/logic/symbols/cnext/adapters/TSymbolAdapter.ts +0 -345
- package/src/transpiler/logic/symbols/types/IBaseSymbol.ts +0 -27
- package/src/transpiler/logic/symbols/types/IBitmapSymbol.ts +0 -23
- package/src/transpiler/logic/symbols/types/ICollectorContext.ts +0 -19
- package/src/transpiler/logic/symbols/types/IConflict.ts +0 -20
- package/src/transpiler/logic/symbols/types/IFieldInfo.ts +0 -18
- package/src/transpiler/logic/symbols/types/IFunctionSymbol.ts +0 -25
- package/src/transpiler/logic/symbols/types/IParameterInfo.ts +0 -24
- package/src/transpiler/logic/symbols/types/IRegisterSymbol.ts +0 -20
- package/src/transpiler/logic/symbols/types/IScopeSymbol.ts +0 -19
- package/src/transpiler/logic/symbols/types/IStructSymbol.ts +0 -16
- package/src/transpiler/logic/symbols/types/IVariableSymbol.ts +0 -30
- package/src/transpiler/logic/symbols/types/TSymbol.ts +0 -36
- package/src/transpiler/logic/symbols/types/__tests__/SymbolGuards.test.ts +0 -244
- package/src/transpiler/logic/symbols/types/typeGuards.ts +0 -44
- package/src/utils/types/ESymbolKind.ts +0 -19
- package/src/utils/types/ISymbol.ts +0 -64
- /package/src/transpiler/{types → constants}/BITMAP_BACKING_TYPE.ts +0 -0
- /package/src/transpiler/{types → constants}/BITMAP_SIZE.ts +0 -0
|
@@ -1,595 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Unit tests for TSymbolAdapter.
|
|
3
|
-
* Tests conversion from TSymbol discriminated union types to flat ISymbol interface.
|
|
4
|
-
*/
|
|
5
|
-
|
|
6
|
-
import { describe, expect, it, beforeEach } from "vitest";
|
|
7
|
-
import TSymbolAdapter from "../adapters/TSymbolAdapter";
|
|
8
|
-
import SymbolTable from "../../SymbolTable";
|
|
9
|
-
import ESymbolKind from "../../../../../utils/types/ESymbolKind";
|
|
10
|
-
import ESourceLanguage from "../../../../../utils/types/ESourceLanguage";
|
|
11
|
-
import IBitmapSymbol from "../../types/IBitmapSymbol";
|
|
12
|
-
import IEnumSymbol from "../../types/IEnumSymbol";
|
|
13
|
-
import IStructSymbol from "../../types/IStructSymbol";
|
|
14
|
-
import IFunctionSymbol from "../../types/IFunctionSymbol";
|
|
15
|
-
import IVariableSymbol from "../../types/IVariableSymbol";
|
|
16
|
-
import IRegisterSymbol from "../../types/IRegisterSymbol";
|
|
17
|
-
import IScopeSymbol from "../../types/IScopeSymbol";
|
|
18
|
-
|
|
19
|
-
describe("TSymbolAdapter", () => {
|
|
20
|
-
let symbolTable: SymbolTable;
|
|
21
|
-
|
|
22
|
-
beforeEach(() => {
|
|
23
|
-
symbolTable = new SymbolTable();
|
|
24
|
-
});
|
|
25
|
-
|
|
26
|
-
describe("convertBitmap", () => {
|
|
27
|
-
it("converts IBitmapSymbol to ISymbol + BitmapField symbols", () => {
|
|
28
|
-
const bitmap: IBitmapSymbol = {
|
|
29
|
-
kind: ESymbolKind.Bitmap,
|
|
30
|
-
name: "Status",
|
|
31
|
-
sourceFile: "test.cnx",
|
|
32
|
-
sourceLine: 1,
|
|
33
|
-
sourceLanguage: ESourceLanguage.CNext,
|
|
34
|
-
isExported: true,
|
|
35
|
-
backingType: "uint8_t",
|
|
36
|
-
bitWidth: 8,
|
|
37
|
-
fields: new Map([
|
|
38
|
-
["enabled", { offset: 0, width: 1 }],
|
|
39
|
-
["ready", { offset: 1, width: 1 }],
|
|
40
|
-
["error", { offset: 2, width: 1 }],
|
|
41
|
-
["reserved", { offset: 3, width: 5 }],
|
|
42
|
-
]),
|
|
43
|
-
};
|
|
44
|
-
|
|
45
|
-
const result = TSymbolAdapter.toISymbols([bitmap], symbolTable);
|
|
46
|
-
|
|
47
|
-
// Should have 1 bitmap + 4 fields = 5 symbols
|
|
48
|
-
expect(result).toHaveLength(5);
|
|
49
|
-
|
|
50
|
-
// Main bitmap symbol
|
|
51
|
-
const bitmapSym = result[0];
|
|
52
|
-
expect(bitmapSym.name).toBe("Status");
|
|
53
|
-
expect(bitmapSym.kind).toBe(ESymbolKind.Bitmap);
|
|
54
|
-
expect(bitmapSym.type).toBe("uint8_t");
|
|
55
|
-
expect(bitmapSym.isExported).toBe(true);
|
|
56
|
-
|
|
57
|
-
// Field symbols
|
|
58
|
-
const enabledField = result.find((s) => s.name === "Status_enabled");
|
|
59
|
-
expect(enabledField).toBeDefined();
|
|
60
|
-
expect(enabledField!.kind).toBe(ESymbolKind.BitmapField);
|
|
61
|
-
expect(enabledField!.type).toBe("bool");
|
|
62
|
-
expect(enabledField!.parent).toBe("Status");
|
|
63
|
-
expect(enabledField!.signature).toBe("bit 0 (1 bit)");
|
|
64
|
-
|
|
65
|
-
const reservedField = result.find((s) => s.name === "Status_reserved");
|
|
66
|
-
expect(reservedField).toBeDefined();
|
|
67
|
-
expect(reservedField!.type).toBe("u8");
|
|
68
|
-
expect(reservedField!.signature).toBe("bits 3-7 (5 bits)");
|
|
69
|
-
});
|
|
70
|
-
|
|
71
|
-
it("uses correct type for multi-bit fields", () => {
|
|
72
|
-
const bitmap: IBitmapSymbol = {
|
|
73
|
-
kind: ESymbolKind.Bitmap,
|
|
74
|
-
name: "Control",
|
|
75
|
-
sourceFile: "test.cnx",
|
|
76
|
-
sourceLine: 1,
|
|
77
|
-
sourceLanguage: ESourceLanguage.CNext,
|
|
78
|
-
isExported: true,
|
|
79
|
-
backingType: "uint32_t",
|
|
80
|
-
bitWidth: 32,
|
|
81
|
-
fields: new Map([
|
|
82
|
-
["small", { offset: 0, width: 4 }],
|
|
83
|
-
["medium", { offset: 4, width: 12 }],
|
|
84
|
-
["large", { offset: 16, width: 16 }],
|
|
85
|
-
]),
|
|
86
|
-
};
|
|
87
|
-
|
|
88
|
-
const result = TSymbolAdapter.toISymbols([bitmap], symbolTable);
|
|
89
|
-
|
|
90
|
-
const smallField = result.find((s) => s.name === "Control_small");
|
|
91
|
-
expect(smallField!.type).toBe("u8"); // <= 8 bits
|
|
92
|
-
|
|
93
|
-
const mediumField = result.find((s) => s.name === "Control_medium");
|
|
94
|
-
expect(mediumField!.type).toBe("u16"); // <= 16 bits
|
|
95
|
-
|
|
96
|
-
const largeField = result.find((s) => s.name === "Control_large");
|
|
97
|
-
expect(largeField!.type).toBe("u16"); // exactly 16 bits
|
|
98
|
-
});
|
|
99
|
-
});
|
|
100
|
-
|
|
101
|
-
describe("convertEnum", () => {
|
|
102
|
-
it("converts IEnumSymbol to ISymbol", () => {
|
|
103
|
-
const enumSym: IEnumSymbol = {
|
|
104
|
-
kind: ESymbolKind.Enum,
|
|
105
|
-
name: "Color",
|
|
106
|
-
sourceFile: "test.cnx",
|
|
107
|
-
sourceLine: 5,
|
|
108
|
-
sourceLanguage: ESourceLanguage.CNext,
|
|
109
|
-
isExported: true,
|
|
110
|
-
members: new Map([
|
|
111
|
-
["Red", 0],
|
|
112
|
-
["Green", 1],
|
|
113
|
-
["Blue", 2],
|
|
114
|
-
]),
|
|
115
|
-
};
|
|
116
|
-
|
|
117
|
-
const result = TSymbolAdapter.toISymbols([enumSym], symbolTable);
|
|
118
|
-
|
|
119
|
-
// 1 enum + 3 members
|
|
120
|
-
expect(result).toHaveLength(4);
|
|
121
|
-
expect(result[0].name).toBe("Color");
|
|
122
|
-
expect(result[0].kind).toBe(ESymbolKind.Enum);
|
|
123
|
-
expect(result[0].sourceFile).toBe("test.cnx");
|
|
124
|
-
expect(result[0].sourceLine).toBe(5);
|
|
125
|
-
expect(result[0].isExported).toBe(true);
|
|
126
|
-
|
|
127
|
-
// Enum members
|
|
128
|
-
expect(result[1].name).toBe("Red");
|
|
129
|
-
expect(result[1].kind).toBe(ESymbolKind.EnumMember);
|
|
130
|
-
expect(result[1].type).toBe("0");
|
|
131
|
-
expect(result[1].parent).toBe("Color");
|
|
132
|
-
|
|
133
|
-
expect(result[2].name).toBe("Green");
|
|
134
|
-
expect(result[2].kind).toBe(ESymbolKind.EnumMember);
|
|
135
|
-
expect(result[2].type).toBe("1");
|
|
136
|
-
|
|
137
|
-
expect(result[3].name).toBe("Blue");
|
|
138
|
-
expect(result[3].kind).toBe(ESymbolKind.EnumMember);
|
|
139
|
-
expect(result[3].type).toBe("2");
|
|
140
|
-
});
|
|
141
|
-
});
|
|
142
|
-
|
|
143
|
-
describe("convertStruct", () => {
|
|
144
|
-
it("converts IStructSymbol to ISymbol and registers fields", () => {
|
|
145
|
-
const struct: IStructSymbol = {
|
|
146
|
-
kind: ESymbolKind.Struct,
|
|
147
|
-
name: "Point",
|
|
148
|
-
sourceFile: "test.cnx",
|
|
149
|
-
sourceLine: 1,
|
|
150
|
-
sourceLanguage: ESourceLanguage.CNext,
|
|
151
|
-
isExported: true,
|
|
152
|
-
fields: new Map([
|
|
153
|
-
["x", { type: "i32", isArray: false, isConst: false }],
|
|
154
|
-
["y", { type: "i32", isArray: false, isConst: false }],
|
|
155
|
-
]),
|
|
156
|
-
};
|
|
157
|
-
|
|
158
|
-
const result = TSymbolAdapter.toISymbols([struct], symbolTable);
|
|
159
|
-
|
|
160
|
-
expect(result).toHaveLength(1);
|
|
161
|
-
expect(result[0].name).toBe("Point");
|
|
162
|
-
expect(result[0].kind).toBe(ESymbolKind.Struct);
|
|
163
|
-
|
|
164
|
-
// Verify fields were registered in SymbolTable
|
|
165
|
-
expect(symbolTable.getStructFieldType("Point", "x")).toBe("i32");
|
|
166
|
-
expect(symbolTable.getStructFieldType("Point", "y")).toBe("i32");
|
|
167
|
-
});
|
|
168
|
-
|
|
169
|
-
it("registers array fields with dimensions", () => {
|
|
170
|
-
const struct: IStructSymbol = {
|
|
171
|
-
kind: ESymbolKind.Struct,
|
|
172
|
-
name: "Buffer",
|
|
173
|
-
sourceFile: "test.cnx",
|
|
174
|
-
sourceLine: 1,
|
|
175
|
-
sourceLanguage: ESourceLanguage.CNext,
|
|
176
|
-
isExported: true,
|
|
177
|
-
fields: new Map([
|
|
178
|
-
[
|
|
179
|
-
"data",
|
|
180
|
-
{ type: "u8", isArray: true, isConst: false, dimensions: [256] },
|
|
181
|
-
],
|
|
182
|
-
]),
|
|
183
|
-
};
|
|
184
|
-
|
|
185
|
-
const result = TSymbolAdapter.toISymbols([struct], symbolTable);
|
|
186
|
-
|
|
187
|
-
expect(result).toHaveLength(1);
|
|
188
|
-
|
|
189
|
-
const fieldInfo = symbolTable.getStructFieldInfo("Buffer", "data");
|
|
190
|
-
expect(fieldInfo).toBeDefined();
|
|
191
|
-
expect(fieldInfo!.type).toBe("u8");
|
|
192
|
-
expect(fieldInfo!.arrayDimensions).toEqual([256]);
|
|
193
|
-
});
|
|
194
|
-
});
|
|
195
|
-
|
|
196
|
-
describe("convertFunction", () => {
|
|
197
|
-
it("converts IFunctionSymbol to ISymbol + parameter symbols", () => {
|
|
198
|
-
const func: IFunctionSymbol = {
|
|
199
|
-
kind: ESymbolKind.Function,
|
|
200
|
-
name: "calculate",
|
|
201
|
-
sourceFile: "test.cnx",
|
|
202
|
-
sourceLine: 10,
|
|
203
|
-
sourceLanguage: ESourceLanguage.CNext,
|
|
204
|
-
isExported: true,
|
|
205
|
-
returnType: "i32",
|
|
206
|
-
visibility: "public",
|
|
207
|
-
parameters: [
|
|
208
|
-
{ name: "a", type: "i32", isConst: false, isArray: false },
|
|
209
|
-
{ name: "b", type: "i32", isConst: true, isArray: false },
|
|
210
|
-
],
|
|
211
|
-
};
|
|
212
|
-
|
|
213
|
-
const result = TSymbolAdapter.toISymbols([func], symbolTable);
|
|
214
|
-
|
|
215
|
-
// 1 function + 2 parameter symbols
|
|
216
|
-
expect(result).toHaveLength(3);
|
|
217
|
-
|
|
218
|
-
// Function symbol
|
|
219
|
-
const funcSym = result[0];
|
|
220
|
-
expect(funcSym.name).toBe("calculate");
|
|
221
|
-
expect(funcSym.kind).toBe(ESymbolKind.Function);
|
|
222
|
-
expect(funcSym.type).toBe("i32");
|
|
223
|
-
expect(funcSym.signature).toBe("i32 calculate(i32, i32)");
|
|
224
|
-
expect(funcSym.parameters).toHaveLength(2);
|
|
225
|
-
expect(funcSym.parameters![0]).toEqual({
|
|
226
|
-
name: "a",
|
|
227
|
-
type: "i32",
|
|
228
|
-
isConst: false,
|
|
229
|
-
isArray: false,
|
|
230
|
-
arrayDimensions: undefined,
|
|
231
|
-
isAutoConst: undefined,
|
|
232
|
-
});
|
|
233
|
-
|
|
234
|
-
// Parameter symbols
|
|
235
|
-
const paramA = result.find((s) => s.name === "a");
|
|
236
|
-
expect(paramA).toBeDefined();
|
|
237
|
-
expect(paramA!.kind).toBe(ESymbolKind.Variable);
|
|
238
|
-
expect(paramA!.type).toBe("i32");
|
|
239
|
-
expect(paramA!.parent).toBe("calculate");
|
|
240
|
-
expect(paramA!.isExported).toBe(false);
|
|
241
|
-
|
|
242
|
-
const paramB = result.find((s) => s.name === "b");
|
|
243
|
-
expect(paramB).toBeDefined();
|
|
244
|
-
});
|
|
245
|
-
|
|
246
|
-
it("handles array parameters with [] type suffix", () => {
|
|
247
|
-
const func: IFunctionSymbol = {
|
|
248
|
-
kind: ESymbolKind.Function,
|
|
249
|
-
name: "processArray",
|
|
250
|
-
sourceFile: "test.cnx",
|
|
251
|
-
sourceLine: 1,
|
|
252
|
-
sourceLanguage: ESourceLanguage.CNext,
|
|
253
|
-
isExported: true,
|
|
254
|
-
returnType: "void",
|
|
255
|
-
visibility: "public",
|
|
256
|
-
parameters: [
|
|
257
|
-
{
|
|
258
|
-
name: "data",
|
|
259
|
-
type: "u8",
|
|
260
|
-
isConst: false,
|
|
261
|
-
isArray: true,
|
|
262
|
-
arrayDimensions: ["10"],
|
|
263
|
-
},
|
|
264
|
-
],
|
|
265
|
-
};
|
|
266
|
-
|
|
267
|
-
const result = TSymbolAdapter.toISymbols([func], symbolTable);
|
|
268
|
-
|
|
269
|
-
const paramData = result.find((s) => s.name === "data");
|
|
270
|
-
expect(paramData!.type).toBe("u8[]");
|
|
271
|
-
});
|
|
272
|
-
});
|
|
273
|
-
|
|
274
|
-
describe("convertVariable", () => {
|
|
275
|
-
it("converts simple variable", () => {
|
|
276
|
-
const variable: IVariableSymbol = {
|
|
277
|
-
kind: ESymbolKind.Variable,
|
|
278
|
-
name: "counter",
|
|
279
|
-
sourceFile: "test.cnx",
|
|
280
|
-
sourceLine: 1,
|
|
281
|
-
sourceLanguage: ESourceLanguage.CNext,
|
|
282
|
-
isExported: true,
|
|
283
|
-
type: "u32",
|
|
284
|
-
isConst: false,
|
|
285
|
-
isAtomic: false,
|
|
286
|
-
isArray: false,
|
|
287
|
-
};
|
|
288
|
-
|
|
289
|
-
const result = TSymbolAdapter.toISymbols([variable], symbolTable);
|
|
290
|
-
|
|
291
|
-
expect(result).toHaveLength(1);
|
|
292
|
-
expect(result[0].name).toBe("counter");
|
|
293
|
-
expect(result[0].kind).toBe(ESymbolKind.Variable);
|
|
294
|
-
expect(result[0].type).toBe("u32");
|
|
295
|
-
expect(result[0].isConst).toBe(false);
|
|
296
|
-
expect(result[0].isArray).toBe(false);
|
|
297
|
-
});
|
|
298
|
-
|
|
299
|
-
it("converts array variable with dimensions", () => {
|
|
300
|
-
const variable: IVariableSymbol = {
|
|
301
|
-
kind: ESymbolKind.Variable,
|
|
302
|
-
name: "buffer",
|
|
303
|
-
sourceFile: "test.cnx",
|
|
304
|
-
sourceLine: 1,
|
|
305
|
-
sourceLanguage: ESourceLanguage.CNext,
|
|
306
|
-
isExported: true,
|
|
307
|
-
type: "u8",
|
|
308
|
-
isConst: false,
|
|
309
|
-
isAtomic: false,
|
|
310
|
-
isArray: true,
|
|
311
|
-
arrayDimensions: [256],
|
|
312
|
-
};
|
|
313
|
-
|
|
314
|
-
const result = TSymbolAdapter.toISymbols([variable], symbolTable);
|
|
315
|
-
|
|
316
|
-
expect(result).toHaveLength(1);
|
|
317
|
-
expect(result[0].isArray).toBe(true);
|
|
318
|
-
expect(result[0].arrayDimensions).toEqual(["256"]);
|
|
319
|
-
expect(result[0].size).toBe(256);
|
|
320
|
-
});
|
|
321
|
-
|
|
322
|
-
it("converts const variable", () => {
|
|
323
|
-
const variable: IVariableSymbol = {
|
|
324
|
-
kind: ESymbolKind.Variable,
|
|
325
|
-
name: "MAX_SIZE",
|
|
326
|
-
sourceFile: "test.cnx",
|
|
327
|
-
sourceLine: 1,
|
|
328
|
-
sourceLanguage: ESourceLanguage.CNext,
|
|
329
|
-
isExported: true,
|
|
330
|
-
type: "u32",
|
|
331
|
-
isConst: true,
|
|
332
|
-
isAtomic: false,
|
|
333
|
-
isArray: false,
|
|
334
|
-
};
|
|
335
|
-
|
|
336
|
-
const result = TSymbolAdapter.toISymbols([variable], symbolTable);
|
|
337
|
-
|
|
338
|
-
expect(result[0].isConst).toBe(true);
|
|
339
|
-
});
|
|
340
|
-
});
|
|
341
|
-
|
|
342
|
-
describe("convertRegister", () => {
|
|
343
|
-
it("converts IRegisterSymbol to ISymbol + RegisterMember symbols", () => {
|
|
344
|
-
const register: IRegisterSymbol = {
|
|
345
|
-
kind: ESymbolKind.Register,
|
|
346
|
-
name: "GPIO",
|
|
347
|
-
sourceFile: "test.cnx",
|
|
348
|
-
sourceLine: 1,
|
|
349
|
-
sourceLanguage: ESourceLanguage.CNext,
|
|
350
|
-
isExported: true,
|
|
351
|
-
baseAddress: "0x40000000",
|
|
352
|
-
members: new Map([
|
|
353
|
-
["DATA", { offset: "0x00", cType: "uint32_t", access: "rw" }],
|
|
354
|
-
["DIR", { offset: "0x04", cType: "uint32_t", access: "rw" }],
|
|
355
|
-
["STATUS", { offset: "0x08", cType: "uint32_t", access: "ro" }],
|
|
356
|
-
]),
|
|
357
|
-
};
|
|
358
|
-
|
|
359
|
-
const result = TSymbolAdapter.toISymbols([register], symbolTable);
|
|
360
|
-
|
|
361
|
-
// 1 register + 3 members = 4 symbols
|
|
362
|
-
expect(result).toHaveLength(4);
|
|
363
|
-
|
|
364
|
-
// Register symbol
|
|
365
|
-
const regSym = result[0];
|
|
366
|
-
expect(regSym.name).toBe("GPIO");
|
|
367
|
-
expect(regSym.kind).toBe(ESymbolKind.Register);
|
|
368
|
-
expect(regSym.isExported).toBe(true);
|
|
369
|
-
|
|
370
|
-
// Member symbols
|
|
371
|
-
const dataMember = result.find((s) => s.name === "GPIO_DATA");
|
|
372
|
-
expect(dataMember).toBeDefined();
|
|
373
|
-
expect(dataMember!.kind).toBe(ESymbolKind.RegisterMember);
|
|
374
|
-
expect(dataMember!.type).toBe("uint32_t");
|
|
375
|
-
expect(dataMember!.parent).toBe("GPIO");
|
|
376
|
-
expect(dataMember!.accessModifier).toBe("rw");
|
|
377
|
-
|
|
378
|
-
const statusMember = result.find((s) => s.name === "GPIO_STATUS");
|
|
379
|
-
expect(statusMember!.accessModifier).toBe("ro");
|
|
380
|
-
});
|
|
381
|
-
});
|
|
382
|
-
|
|
383
|
-
describe("convertScope", () => {
|
|
384
|
-
it("converts IScopeSymbol to ISymbol", () => {
|
|
385
|
-
const scope: IScopeSymbol = {
|
|
386
|
-
kind: ESymbolKind.Namespace,
|
|
387
|
-
name: "Motor",
|
|
388
|
-
sourceFile: "test.cnx",
|
|
389
|
-
sourceLine: 1,
|
|
390
|
-
sourceLanguage: ESourceLanguage.CNext,
|
|
391
|
-
isExported: true,
|
|
392
|
-
members: ["init", "run", "stop"],
|
|
393
|
-
memberVisibility: new Map([
|
|
394
|
-
["init", "public"],
|
|
395
|
-
["run", "public"],
|
|
396
|
-
["stop", "private"],
|
|
397
|
-
]),
|
|
398
|
-
};
|
|
399
|
-
|
|
400
|
-
const result = TSymbolAdapter.toISymbols([scope], symbolTable);
|
|
401
|
-
|
|
402
|
-
expect(result).toHaveLength(1);
|
|
403
|
-
expect(result[0].name).toBe("Motor");
|
|
404
|
-
expect(result[0].kind).toBe(ESymbolKind.Namespace);
|
|
405
|
-
expect(result[0].isExported).toBe(true);
|
|
406
|
-
});
|
|
407
|
-
});
|
|
408
|
-
|
|
409
|
-
describe("mixed symbols", () => {
|
|
410
|
-
it("handles array of different symbol types", () => {
|
|
411
|
-
const symbols = [
|
|
412
|
-
{
|
|
413
|
-
kind: ESymbolKind.Struct,
|
|
414
|
-
name: "Point",
|
|
415
|
-
sourceFile: "test.cnx",
|
|
416
|
-
sourceLine: 1,
|
|
417
|
-
sourceLanguage: ESourceLanguage.CNext,
|
|
418
|
-
isExported: true,
|
|
419
|
-
fields: new Map([
|
|
420
|
-
["x", { type: "i32", isArray: false, isConst: false }],
|
|
421
|
-
]),
|
|
422
|
-
} as IStructSymbol,
|
|
423
|
-
{
|
|
424
|
-
kind: ESymbolKind.Function,
|
|
425
|
-
name: "main",
|
|
426
|
-
sourceFile: "test.cnx",
|
|
427
|
-
sourceLine: 5,
|
|
428
|
-
sourceLanguage: ESourceLanguage.CNext,
|
|
429
|
-
isExported: true,
|
|
430
|
-
returnType: "void",
|
|
431
|
-
visibility: "public",
|
|
432
|
-
parameters: [],
|
|
433
|
-
} as IFunctionSymbol,
|
|
434
|
-
{
|
|
435
|
-
kind: ESymbolKind.Variable,
|
|
436
|
-
name: "counter",
|
|
437
|
-
sourceFile: "test.cnx",
|
|
438
|
-
sourceLine: 10,
|
|
439
|
-
sourceLanguage: ESourceLanguage.CNext,
|
|
440
|
-
isExported: true,
|
|
441
|
-
type: "u32",
|
|
442
|
-
isConst: false,
|
|
443
|
-
isAtomic: false,
|
|
444
|
-
isArray: false,
|
|
445
|
-
} as IVariableSymbol,
|
|
446
|
-
];
|
|
447
|
-
|
|
448
|
-
const result = TSymbolAdapter.toISymbols(symbols, symbolTable);
|
|
449
|
-
|
|
450
|
-
// 1 struct + 1 function + 1 variable = 3 symbols
|
|
451
|
-
expect(result).toHaveLength(3);
|
|
452
|
-
|
|
453
|
-
const structSym = result.find((s) => s.name === "Point");
|
|
454
|
-
expect(structSym!.kind).toBe(ESymbolKind.Struct);
|
|
455
|
-
|
|
456
|
-
const funcSym = result.find((s) => s.name === "main");
|
|
457
|
-
expect(funcSym!.kind).toBe(ESymbolKind.Function);
|
|
458
|
-
|
|
459
|
-
const varSym = result.find((s) => s.name === "counter");
|
|
460
|
-
expect(varSym!.kind).toBe(ESymbolKind.Variable);
|
|
461
|
-
|
|
462
|
-
// Struct field should be registered
|
|
463
|
-
expect(symbolTable.getStructFieldType("Point", "x")).toBe("i32");
|
|
464
|
-
});
|
|
465
|
-
});
|
|
466
|
-
|
|
467
|
-
describe("array dimension conversion", () => {
|
|
468
|
-
it("converts qualified enum access (dots to underscores) in variable dimensions", () => {
|
|
469
|
-
const variable: IVariableSymbol = {
|
|
470
|
-
kind: ESymbolKind.Variable,
|
|
471
|
-
name: "DATA",
|
|
472
|
-
sourceFile: "test.cnx",
|
|
473
|
-
sourceLine: 10,
|
|
474
|
-
sourceLanguage: ESourceLanguage.CNext,
|
|
475
|
-
isExported: true,
|
|
476
|
-
type: "u8",
|
|
477
|
-
isConst: true,
|
|
478
|
-
isAtomic: false,
|
|
479
|
-
isArray: true,
|
|
480
|
-
arrayDimensions: ["EColor.COUNT"],
|
|
481
|
-
};
|
|
482
|
-
|
|
483
|
-
const result = TSymbolAdapter.toISymbols([variable], symbolTable);
|
|
484
|
-
|
|
485
|
-
const varSym = result.find(
|
|
486
|
-
(s) => s.kind === ESymbolKind.Variable && s.name === "DATA",
|
|
487
|
-
);
|
|
488
|
-
expect(varSym).toBeDefined();
|
|
489
|
-
expect(varSym!.arrayDimensions).toEqual(["EColor_COUNT"]);
|
|
490
|
-
});
|
|
491
|
-
|
|
492
|
-
it("converts qualified enum access in function parameter dimensions", () => {
|
|
493
|
-
const funcSym: IFunctionSymbol = {
|
|
494
|
-
kind: ESymbolKind.Function,
|
|
495
|
-
name: "process",
|
|
496
|
-
sourceFile: "test.cnx",
|
|
497
|
-
sourceLine: 5,
|
|
498
|
-
sourceLanguage: ESourceLanguage.CNext,
|
|
499
|
-
isExported: true,
|
|
500
|
-
returnType: "void",
|
|
501
|
-
visibility: "public",
|
|
502
|
-
parameters: [
|
|
503
|
-
{
|
|
504
|
-
name: "buffer",
|
|
505
|
-
type: "u8",
|
|
506
|
-
isConst: false,
|
|
507
|
-
isArray: true,
|
|
508
|
-
arrayDimensions: ["Size.MEDIUM"],
|
|
509
|
-
},
|
|
510
|
-
],
|
|
511
|
-
};
|
|
512
|
-
|
|
513
|
-
const result = TSymbolAdapter.toISymbols([funcSym], symbolTable);
|
|
514
|
-
|
|
515
|
-
const funcResult = result.find(
|
|
516
|
-
(s) => s.kind === ESymbolKind.Function && s.name === "process",
|
|
517
|
-
);
|
|
518
|
-
expect(funcResult).toBeDefined();
|
|
519
|
-
expect(funcResult!.parameters).toBeDefined();
|
|
520
|
-
expect(funcResult!.parameters![0].arrayDimensions).toEqual([
|
|
521
|
-
"Size_MEDIUM",
|
|
522
|
-
]);
|
|
523
|
-
});
|
|
524
|
-
|
|
525
|
-
it("passes through unqualified string dimensions as-is", () => {
|
|
526
|
-
const variable: IVariableSymbol = {
|
|
527
|
-
kind: ESymbolKind.Variable,
|
|
528
|
-
name: "DATA",
|
|
529
|
-
sourceFile: "test.cnx",
|
|
530
|
-
sourceLine: 10,
|
|
531
|
-
sourceLanguage: ESourceLanguage.CNext,
|
|
532
|
-
isExported: true,
|
|
533
|
-
type: "u8",
|
|
534
|
-
isConst: true,
|
|
535
|
-
isAtomic: false,
|
|
536
|
-
isArray: true,
|
|
537
|
-
arrayDimensions: ["DEVICE_COUNT"], // C macro passthrough
|
|
538
|
-
};
|
|
539
|
-
|
|
540
|
-
const result = TSymbolAdapter.toISymbols([variable], symbolTable);
|
|
541
|
-
|
|
542
|
-
const varSym = result.find(
|
|
543
|
-
(s) => s.kind === ESymbolKind.Variable && s.name === "DATA",
|
|
544
|
-
);
|
|
545
|
-
expect(varSym).toBeDefined();
|
|
546
|
-
expect(varSym!.arrayDimensions).toEqual(["DEVICE_COUNT"]);
|
|
547
|
-
});
|
|
548
|
-
|
|
549
|
-
it("preserves numeric array dimensions", () => {
|
|
550
|
-
const variable: IVariableSymbol = {
|
|
551
|
-
kind: ESymbolKind.Variable,
|
|
552
|
-
name: "DATA",
|
|
553
|
-
sourceFile: "test.cnx",
|
|
554
|
-
sourceLine: 10,
|
|
555
|
-
sourceLanguage: ESourceLanguage.CNext,
|
|
556
|
-
isExported: true,
|
|
557
|
-
type: "u8",
|
|
558
|
-
isConst: true,
|
|
559
|
-
isAtomic: false,
|
|
560
|
-
isArray: true,
|
|
561
|
-
arrayDimensions: [256],
|
|
562
|
-
};
|
|
563
|
-
|
|
564
|
-
const result = TSymbolAdapter.toISymbols([variable], symbolTable);
|
|
565
|
-
|
|
566
|
-
const varSym = result.find(
|
|
567
|
-
(s) => s.kind === ESymbolKind.Variable && s.name === "DATA",
|
|
568
|
-
);
|
|
569
|
-
expect(varSym!.arrayDimensions).toEqual(["256"]);
|
|
570
|
-
});
|
|
571
|
-
|
|
572
|
-
it("handles multi-dot qualified access (Motor.State.IDLE)", () => {
|
|
573
|
-
const variable: IVariableSymbol = {
|
|
574
|
-
kind: ESymbolKind.Variable,
|
|
575
|
-
name: "DATA",
|
|
576
|
-
sourceFile: "test.cnx",
|
|
577
|
-
sourceLine: 10,
|
|
578
|
-
sourceLanguage: ESourceLanguage.CNext,
|
|
579
|
-
isExported: true,
|
|
580
|
-
type: "u8",
|
|
581
|
-
isConst: true,
|
|
582
|
-
isAtomic: false,
|
|
583
|
-
isArray: true,
|
|
584
|
-
arrayDimensions: ["Motor.State.COUNT"],
|
|
585
|
-
};
|
|
586
|
-
|
|
587
|
-
const result = TSymbolAdapter.toISymbols([variable], symbolTable);
|
|
588
|
-
|
|
589
|
-
const varSym = result.find(
|
|
590
|
-
(s) => s.kind === ESymbolKind.Variable && s.name === "DATA",
|
|
591
|
-
);
|
|
592
|
-
expect(varSym!.arrayDimensions).toEqual(["Motor_State_COUNT"]);
|
|
593
|
-
});
|
|
594
|
-
});
|
|
595
|
-
});
|