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,12 +1,20 @@
|
|
|
1
1
|
/**
|
|
2
2
|
* Unit tests for SymbolTable
|
|
3
3
|
* Issue #221: Function parameters should not cause conflicts
|
|
4
|
+
* ADR-055 Phase 7: Fully typed symbol storage using TSymbol, TCSymbol, TCppSymbol
|
|
4
5
|
*/
|
|
5
6
|
import { describe, it, expect, beforeEach } from "vitest";
|
|
6
7
|
import SymbolTable from "../SymbolTable";
|
|
7
|
-
import ESymbolKind from "../../../../utils/types/ESymbolKind";
|
|
8
8
|
import ESourceLanguage from "../../../../utils/types/ESourceLanguage";
|
|
9
|
-
import
|
|
9
|
+
import TSymbol from "../../../types/symbols/TSymbol";
|
|
10
|
+
import IVariableSymbol from "../../../types/symbols/IVariableSymbol";
|
|
11
|
+
import IFunctionSymbol from "../../../types/symbols/IFunctionSymbol";
|
|
12
|
+
import IStructSymbol from "../../../types/symbols/IStructSymbol";
|
|
13
|
+
import IEnumSymbol from "../../../types/symbols/IEnumSymbol";
|
|
14
|
+
import TestScopeUtils from "../cnext/__tests__/testUtils";
|
|
15
|
+
import TTypeUtils from "../../../../utils/TTypeUtils";
|
|
16
|
+
import TCSymbol from "../../../types/symbols/c/TCSymbol";
|
|
17
|
+
import TCppSymbol from "../../../types/symbols/cpp/TCppSymbol";
|
|
10
18
|
|
|
11
19
|
describe("SymbolTable", () => {
|
|
12
20
|
let symbolTable: SymbolTable;
|
|
@@ -16,966 +24,622 @@ describe("SymbolTable", () => {
|
|
|
16
24
|
});
|
|
17
25
|
|
|
18
26
|
// ========================================================================
|
|
19
|
-
//
|
|
27
|
+
// TSymbol (C-Next) Operations
|
|
20
28
|
// ========================================================================
|
|
21
29
|
|
|
22
|
-
describe("
|
|
23
|
-
it("should add and retrieve a
|
|
24
|
-
const symbol:
|
|
30
|
+
describe("addTSymbol and getTSymbol", () => {
|
|
31
|
+
it("should add and retrieve a TSymbol by name", () => {
|
|
32
|
+
const symbol: IVariableSymbol = {
|
|
33
|
+
kind: "variable",
|
|
25
34
|
name: "myVar",
|
|
26
|
-
kind: ESymbolKind.Variable,
|
|
27
35
|
sourceFile: "test.cnx",
|
|
28
36
|
sourceLine: 1,
|
|
29
37
|
sourceLanguage: ESourceLanguage.CNext,
|
|
30
38
|
isExported: true,
|
|
39
|
+
type: TTypeUtils.createPrimitive("u32"),
|
|
40
|
+
isArray: false,
|
|
41
|
+
isConst: false,
|
|
42
|
+
isAtomic: false,
|
|
43
|
+
scope: TestScopeUtils.createMockGlobalScope(),
|
|
31
44
|
};
|
|
32
45
|
|
|
33
|
-
symbolTable.
|
|
34
|
-
const retrieved = symbolTable.
|
|
46
|
+
symbolTable.addTSymbol(symbol);
|
|
47
|
+
const retrieved = symbolTable.getTSymbol("myVar");
|
|
35
48
|
|
|
36
49
|
expect(retrieved).toBeDefined();
|
|
37
50
|
expect(retrieved?.name).toBe("myVar");
|
|
38
|
-
expect(retrieved?.kind).toBe(
|
|
51
|
+
expect(retrieved?.kind).toBe("variable");
|
|
39
52
|
});
|
|
40
53
|
|
|
41
54
|
it("should return undefined for non-existent symbol", () => {
|
|
42
|
-
const retrieved = symbolTable.
|
|
55
|
+
const retrieved = symbolTable.getTSymbol("nonExistent");
|
|
43
56
|
expect(retrieved).toBeUndefined();
|
|
44
57
|
});
|
|
45
58
|
|
|
46
59
|
it("should return first symbol when multiple exist with same name", () => {
|
|
47
|
-
symbolTable.
|
|
60
|
+
symbolTable.addTSymbol({
|
|
61
|
+
kind: "variable",
|
|
48
62
|
name: "duplicate",
|
|
49
|
-
kind: ESymbolKind.Variable,
|
|
50
63
|
sourceFile: "first.cnx",
|
|
51
64
|
sourceLine: 1,
|
|
52
65
|
sourceLanguage: ESourceLanguage.CNext,
|
|
53
66
|
isExported: true,
|
|
67
|
+
type: TTypeUtils.createPrimitive("u32"),
|
|
68
|
+
isArray: false,
|
|
69
|
+
isConst: false,
|
|
70
|
+
isAtomic: false,
|
|
71
|
+
scope: TestScopeUtils.createMockGlobalScope(),
|
|
54
72
|
});
|
|
55
73
|
|
|
56
|
-
symbolTable.
|
|
74
|
+
symbolTable.addTSymbol({
|
|
75
|
+
kind: "variable",
|
|
57
76
|
name: "duplicate",
|
|
58
|
-
kind: ESymbolKind.Variable,
|
|
59
77
|
sourceFile: "second.cnx",
|
|
60
78
|
sourceLine: 5,
|
|
61
79
|
sourceLanguage: ESourceLanguage.CNext,
|
|
62
80
|
isExported: true,
|
|
81
|
+
type: TTypeUtils.createPrimitive("u32"),
|
|
82
|
+
isArray: false,
|
|
83
|
+
isConst: false,
|
|
84
|
+
isAtomic: false,
|
|
85
|
+
scope: TestScopeUtils.createMockGlobalScope(),
|
|
63
86
|
});
|
|
64
87
|
|
|
65
|
-
const retrieved = symbolTable.
|
|
88
|
+
const retrieved = symbolTable.getTSymbol("duplicate");
|
|
66
89
|
expect(retrieved?.sourceFile).toBe("first.cnx");
|
|
67
90
|
});
|
|
68
91
|
});
|
|
69
92
|
|
|
70
|
-
describe("
|
|
71
|
-
it("should add multiple
|
|
72
|
-
const symbols:
|
|
93
|
+
describe("addTSymbols", () => {
|
|
94
|
+
it("should add multiple TSymbols at once", () => {
|
|
95
|
+
const symbols: TSymbol[] = [
|
|
73
96
|
{
|
|
97
|
+
kind: "variable",
|
|
74
98
|
name: "var1",
|
|
75
|
-
kind: ESymbolKind.Variable,
|
|
76
99
|
sourceFile: "test.cnx",
|
|
77
100
|
sourceLine: 1,
|
|
78
101
|
sourceLanguage: ESourceLanguage.CNext,
|
|
79
102
|
isExported: true,
|
|
103
|
+
type: TTypeUtils.createPrimitive("u32"),
|
|
104
|
+
isArray: false,
|
|
105
|
+
isConst: false,
|
|
106
|
+
isAtomic: false,
|
|
107
|
+
scope: TestScopeUtils.createMockGlobalScope(),
|
|
80
108
|
},
|
|
81
109
|
{
|
|
110
|
+
kind: "variable",
|
|
82
111
|
name: "var2",
|
|
83
|
-
kind: ESymbolKind.Variable,
|
|
84
112
|
sourceFile: "test.cnx",
|
|
85
113
|
sourceLine: 2,
|
|
86
114
|
sourceLanguage: ESourceLanguage.CNext,
|
|
87
115
|
isExported: true,
|
|
88
|
-
|
|
89
|
-
|
|
90
|
-
|
|
91
|
-
|
|
92
|
-
|
|
93
|
-
sourceLine: 3,
|
|
94
|
-
sourceLanguage: ESourceLanguage.CNext,
|
|
95
|
-
isExported: true,
|
|
116
|
+
type: TTypeUtils.createPrimitive("i32"),
|
|
117
|
+
isArray: false,
|
|
118
|
+
isConst: false,
|
|
119
|
+
isAtomic: false,
|
|
120
|
+
scope: TestScopeUtils.createMockGlobalScope(),
|
|
96
121
|
},
|
|
97
122
|
];
|
|
98
123
|
|
|
99
|
-
symbolTable.
|
|
124
|
+
symbolTable.addTSymbols(symbols);
|
|
100
125
|
|
|
101
|
-
expect(symbolTable.
|
|
102
|
-
expect(symbolTable.
|
|
103
|
-
expect(symbolTable.getSymbol("func1")).toBeDefined();
|
|
104
|
-
expect(symbolTable.size).toBe(3);
|
|
126
|
+
expect(symbolTable.getTSymbol("var1")).toBeDefined();
|
|
127
|
+
expect(symbolTable.getTSymbol("var2")).toBeDefined();
|
|
105
128
|
});
|
|
106
129
|
});
|
|
107
130
|
|
|
108
|
-
|
|
109
|
-
|
|
110
|
-
|
|
111
|
-
name: "exists",
|
|
112
|
-
kind: ESymbolKind.Variable,
|
|
113
|
-
sourceFile: "test.cnx",
|
|
114
|
-
sourceLine: 1,
|
|
115
|
-
sourceLanguage: ESourceLanguage.CNext,
|
|
116
|
-
isExported: true,
|
|
117
|
-
});
|
|
118
|
-
|
|
119
|
-
expect(symbolTable.hasSymbol("exists")).toBe(true);
|
|
120
|
-
});
|
|
121
|
-
|
|
122
|
-
it("should return false for non-existent symbol", () => {
|
|
123
|
-
expect(symbolTable.hasSymbol("notHere")).toBe(false);
|
|
124
|
-
});
|
|
125
|
-
});
|
|
126
|
-
|
|
127
|
-
describe("getOverloads", () => {
|
|
128
|
-
it("should return all symbols with same name", () => {
|
|
129
|
-
symbolTable.addSymbol({
|
|
130
|
-
name: "overloaded",
|
|
131
|
-
kind: ESymbolKind.Function,
|
|
132
|
-
signature: "int(int)",
|
|
133
|
-
sourceFile: "test.cpp",
|
|
134
|
-
sourceLine: 1,
|
|
135
|
-
sourceLanguage: ESourceLanguage.Cpp,
|
|
136
|
-
isExported: true,
|
|
137
|
-
});
|
|
138
|
-
|
|
139
|
-
symbolTable.addSymbol({
|
|
140
|
-
name: "overloaded",
|
|
141
|
-
kind: ESymbolKind.Function,
|
|
142
|
-
signature: "int(int, int)",
|
|
143
|
-
sourceFile: "test.cpp",
|
|
144
|
-
sourceLine: 5,
|
|
145
|
-
sourceLanguage: ESourceLanguage.Cpp,
|
|
146
|
-
isExported: true,
|
|
147
|
-
});
|
|
148
|
-
|
|
149
|
-
const overloads = symbolTable.getOverloads("overloaded");
|
|
150
|
-
expect(overloads.length).toBe(2);
|
|
151
|
-
expect(overloads[0].signature).toBe("int(int)");
|
|
152
|
-
expect(overloads[1].signature).toBe("int(int, int)");
|
|
153
|
-
});
|
|
154
|
-
|
|
155
|
-
it("should return empty array for non-existent symbol", () => {
|
|
156
|
-
const overloads = symbolTable.getOverloads("noSuchFunction");
|
|
157
|
-
expect(overloads).toEqual([]);
|
|
158
|
-
});
|
|
159
|
-
});
|
|
160
|
-
|
|
161
|
-
describe("getAllSymbols", () => {
|
|
162
|
-
it("should return all symbols in the table", () => {
|
|
163
|
-
symbolTable.addSymbol({
|
|
164
|
-
name: "a",
|
|
165
|
-
kind: ESymbolKind.Variable,
|
|
166
|
-
sourceFile: "test.cnx",
|
|
167
|
-
sourceLine: 1,
|
|
168
|
-
sourceLanguage: ESourceLanguage.CNext,
|
|
169
|
-
isExported: true,
|
|
170
|
-
});
|
|
131
|
+
// ========================================================================
|
|
132
|
+
// TCSymbol (C) Operations
|
|
133
|
+
// ========================================================================
|
|
171
134
|
|
|
172
|
-
|
|
173
|
-
|
|
174
|
-
|
|
175
|
-
|
|
176
|
-
|
|
177
|
-
|
|
135
|
+
describe("addCSymbol and getCSymbol", () => {
|
|
136
|
+
it("should add and retrieve a C symbol", () => {
|
|
137
|
+
const symbol: TCSymbol = {
|
|
138
|
+
kind: "function",
|
|
139
|
+
name: "c_function",
|
|
140
|
+
sourceFile: "test.h",
|
|
141
|
+
sourceLine: 10,
|
|
142
|
+
sourceLanguage: ESourceLanguage.C,
|
|
178
143
|
isExported: true,
|
|
179
|
-
|
|
144
|
+
type: "int",
|
|
145
|
+
parameters: [
|
|
146
|
+
{ name: "x", type: "int", isConst: false, isArray: false },
|
|
147
|
+
],
|
|
148
|
+
};
|
|
180
149
|
|
|
181
|
-
|
|
182
|
-
|
|
183
|
-
expect(all.map((s) => s.name).sort()).toEqual(["a", "b"]);
|
|
184
|
-
});
|
|
150
|
+
symbolTable.addCSymbol(symbol);
|
|
151
|
+
const retrieved = symbolTable.getCSymbol("c_function");
|
|
185
152
|
|
|
186
|
-
|
|
187
|
-
expect(
|
|
153
|
+
expect(retrieved).toBeDefined();
|
|
154
|
+
expect(retrieved?.name).toBe("c_function");
|
|
155
|
+
expect(retrieved?.kind).toBe("function");
|
|
156
|
+
expect(retrieved?.sourceLanguage).toBe(ESourceLanguage.C);
|
|
188
157
|
});
|
|
189
158
|
});
|
|
190
159
|
|
|
191
|
-
|
|
192
|
-
|
|
193
|
-
|
|
194
|
-
});
|
|
195
|
-
|
|
196
|
-
it("should return correct count including duplicates", () => {
|
|
197
|
-
symbolTable.addSymbol({
|
|
198
|
-
name: "sym1",
|
|
199
|
-
kind: ESymbolKind.Variable,
|
|
200
|
-
sourceFile: "test.cnx",
|
|
201
|
-
sourceLine: 1,
|
|
202
|
-
sourceLanguage: ESourceLanguage.CNext,
|
|
203
|
-
isExported: true,
|
|
204
|
-
});
|
|
205
|
-
|
|
206
|
-
symbolTable.addSymbol({
|
|
207
|
-
name: "sym1",
|
|
208
|
-
kind: ESymbolKind.Variable,
|
|
209
|
-
sourceFile: "test2.cnx",
|
|
210
|
-
sourceLine: 1,
|
|
211
|
-
sourceLanguage: ESourceLanguage.CNext,
|
|
212
|
-
isExported: true,
|
|
213
|
-
});
|
|
160
|
+
// ========================================================================
|
|
161
|
+
// TCppSymbol (C++) Operations
|
|
162
|
+
// ========================================================================
|
|
214
163
|
|
|
215
|
-
|
|
216
|
-
|
|
217
|
-
|
|
218
|
-
|
|
164
|
+
describe("addCppSymbol and getCppSymbol", () => {
|
|
165
|
+
it("should add and retrieve a C++ symbol", () => {
|
|
166
|
+
const symbol: TCppSymbol = {
|
|
167
|
+
kind: "class",
|
|
168
|
+
name: "MyClass",
|
|
169
|
+
sourceFile: "test.hpp",
|
|
219
170
|
sourceLine: 5,
|
|
220
|
-
sourceLanguage: ESourceLanguage.
|
|
221
|
-
isExported: true,
|
|
222
|
-
});
|
|
223
|
-
|
|
224
|
-
expect(symbolTable.size).toBe(3);
|
|
225
|
-
});
|
|
226
|
-
});
|
|
227
|
-
|
|
228
|
-
describe("clear", () => {
|
|
229
|
-
it("should remove all symbols", () => {
|
|
230
|
-
symbolTable.addSymbol({
|
|
231
|
-
name: "toBeCleared",
|
|
232
|
-
kind: ESymbolKind.Variable,
|
|
233
|
-
sourceFile: "test.cnx",
|
|
234
|
-
sourceLine: 1,
|
|
235
|
-
sourceLanguage: ESourceLanguage.CNext,
|
|
171
|
+
sourceLanguage: ESourceLanguage.Cpp,
|
|
236
172
|
isExported: true,
|
|
237
|
-
}
|
|
238
|
-
|
|
239
|
-
symbolTable.addStructField("MyStruct", "field1", "uint32_t");
|
|
240
|
-
symbolTable.markNeedsStructKeyword("CStruct");
|
|
241
|
-
symbolTable.addEnumBitWidth("MyEnum", 8);
|
|
173
|
+
};
|
|
242
174
|
|
|
243
|
-
symbolTable.
|
|
175
|
+
symbolTable.addCppSymbol(symbol);
|
|
176
|
+
const retrieved = symbolTable.getCppSymbol("MyClass");
|
|
244
177
|
|
|
245
|
-
expect(
|
|
246
|
-
expect(
|
|
247
|
-
expect(
|
|
248
|
-
|
|
249
|
-
).toBeUndefined();
|
|
250
|
-
expect(symbolTable.checkNeedsStructKeyword("CStruct")).toBe(false);
|
|
251
|
-
expect(symbolTable.getEnumBitWidth("MyEnum")).toBeUndefined();
|
|
178
|
+
expect(retrieved).toBeDefined();
|
|
179
|
+
expect(retrieved?.name).toBe("MyClass");
|
|
180
|
+
expect(retrieved?.kind).toBe("class");
|
|
181
|
+
expect(retrieved?.sourceLanguage).toBe(ESourceLanguage.Cpp);
|
|
252
182
|
});
|
|
253
183
|
});
|
|
254
184
|
|
|
255
185
|
// ========================================================================
|
|
256
|
-
//
|
|
186
|
+
// Cross-Language Operations
|
|
257
187
|
// ========================================================================
|
|
258
188
|
|
|
259
|
-
describe("
|
|
260
|
-
it("should return symbols from
|
|
261
|
-
symbolTable.
|
|
262
|
-
|
|
263
|
-
kind: ESymbolKind.Variable,
|
|
264
|
-
sourceFile: "file1.cnx",
|
|
265
|
-
sourceLine: 1,
|
|
266
|
-
sourceLanguage: ESourceLanguage.CNext,
|
|
267
|
-
isExported: true,
|
|
268
|
-
});
|
|
269
|
-
|
|
270
|
-
symbolTable.addSymbol({
|
|
271
|
-
name: "alsoInFile1",
|
|
272
|
-
kind: ESymbolKind.Function,
|
|
273
|
-
sourceFile: "file1.cnx",
|
|
274
|
-
sourceLine: 5,
|
|
275
|
-
sourceLanguage: ESourceLanguage.CNext,
|
|
276
|
-
isExported: true,
|
|
277
|
-
});
|
|
278
|
-
|
|
279
|
-
symbolTable.addSymbol({
|
|
280
|
-
name: "inFile2",
|
|
281
|
-
kind: ESymbolKind.Variable,
|
|
282
|
-
sourceFile: "file2.cnx",
|
|
283
|
-
sourceLine: 1,
|
|
284
|
-
sourceLanguage: ESourceLanguage.CNext,
|
|
285
|
-
isExported: true,
|
|
286
|
-
});
|
|
287
|
-
|
|
288
|
-
const file1Symbols = symbolTable.getSymbolsByFile("file1.cnx");
|
|
289
|
-
expect(file1Symbols.length).toBe(2);
|
|
290
|
-
expect(file1Symbols.map((s) => s.name).sort()).toEqual([
|
|
291
|
-
"alsoInFile1",
|
|
292
|
-
"inFile1",
|
|
293
|
-
]);
|
|
294
|
-
});
|
|
295
|
-
|
|
296
|
-
it("should return empty array for unknown file", () => {
|
|
297
|
-
expect(symbolTable.getSymbolsByFile("unknown.cnx")).toEqual([]);
|
|
298
|
-
});
|
|
299
|
-
});
|
|
300
|
-
|
|
301
|
-
describe("getSymbolsByLanguage", () => {
|
|
302
|
-
it("should return symbols from a specific language", () => {
|
|
303
|
-
symbolTable.addSymbol({
|
|
189
|
+
describe("getAllSymbols", () => {
|
|
190
|
+
it("should return symbols from all languages", () => {
|
|
191
|
+
symbolTable.addTSymbol({
|
|
192
|
+
kind: "variable",
|
|
304
193
|
name: "cnextVar",
|
|
305
|
-
kind: ESymbolKind.Variable,
|
|
306
194
|
sourceFile: "test.cnx",
|
|
307
195
|
sourceLine: 1,
|
|
308
196
|
sourceLanguage: ESourceLanguage.CNext,
|
|
309
197
|
isExported: true,
|
|
198
|
+
type: TTypeUtils.createPrimitive("u32"),
|
|
199
|
+
isArray: false,
|
|
200
|
+
isConst: false,
|
|
201
|
+
isAtomic: false,
|
|
202
|
+
scope: TestScopeUtils.createMockGlobalScope(),
|
|
310
203
|
});
|
|
311
204
|
|
|
312
|
-
symbolTable.
|
|
205
|
+
symbolTable.addCSymbol({
|
|
206
|
+
kind: "variable",
|
|
313
207
|
name: "cVar",
|
|
314
|
-
|
|
315
|
-
sourceFile: "test.c",
|
|
208
|
+
sourceFile: "test.h",
|
|
316
209
|
sourceLine: 1,
|
|
317
210
|
sourceLanguage: ESourceLanguage.C,
|
|
318
211
|
isExported: true,
|
|
212
|
+
type: "int",
|
|
319
213
|
});
|
|
320
214
|
|
|
321
|
-
symbolTable.
|
|
215
|
+
symbolTable.addCppSymbol({
|
|
216
|
+
kind: "variable",
|
|
322
217
|
name: "cppVar",
|
|
323
|
-
|
|
324
|
-
sourceFile: "test.cpp",
|
|
218
|
+
sourceFile: "test.hpp",
|
|
325
219
|
sourceLine: 1,
|
|
326
220
|
sourceLanguage: ESourceLanguage.Cpp,
|
|
327
221
|
isExported: true,
|
|
222
|
+
type: "int",
|
|
328
223
|
});
|
|
329
224
|
|
|
330
|
-
const
|
|
331
|
-
|
|
332
|
-
);
|
|
333
|
-
expect(cnextSymbols.length).toBe(1);
|
|
334
|
-
expect(cnextSymbols[0].name).toBe("cnextVar");
|
|
335
|
-
|
|
336
|
-
const cSymbols = symbolTable.getSymbolsByLanguage(ESourceLanguage.C);
|
|
337
|
-
expect(cSymbols.length).toBe(1);
|
|
338
|
-
expect(cSymbols[0].name).toBe("cVar");
|
|
225
|
+
const all = symbolTable.getAllSymbols();
|
|
226
|
+
expect(all.length).toBe(3);
|
|
339
227
|
});
|
|
228
|
+
});
|
|
340
229
|
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
kind:
|
|
230
|
+
describe("getOverloads", () => {
|
|
231
|
+
it("should return overloads from all languages", () => {
|
|
232
|
+
symbolTable.addTSymbol({
|
|
233
|
+
kind: "function",
|
|
234
|
+
name: "process",
|
|
345
235
|
sourceFile: "test.cnx",
|
|
346
236
|
sourceLine: 1,
|
|
347
237
|
sourceLanguage: ESourceLanguage.CNext,
|
|
348
238
|
isExported: true,
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
// ========================================================================
|
|
356
|
-
// Struct Field Operations
|
|
357
|
-
// ========================================================================
|
|
358
|
-
|
|
359
|
-
describe("struct field operations", () => {
|
|
360
|
-
it("should add and retrieve struct field type", () => {
|
|
361
|
-
symbolTable.addStructField("Point", "x", "int32_t");
|
|
362
|
-
symbolTable.addStructField("Point", "y", "int32_t");
|
|
363
|
-
|
|
364
|
-
expect(symbolTable.getStructFieldType("Point", "x")).toBe("int32_t");
|
|
365
|
-
expect(symbolTable.getStructFieldType("Point", "y")).toBe("int32_t");
|
|
366
|
-
});
|
|
239
|
+
returnType: TTypeUtils.createPrimitive("void"),
|
|
240
|
+
parameters: [],
|
|
241
|
+
scope: TestScopeUtils.createMockGlobalScope(),
|
|
242
|
+
visibility: "public",
|
|
243
|
+
body: null,
|
|
244
|
+
} as IFunctionSymbol);
|
|
367
245
|
|
|
368
|
-
|
|
369
|
-
|
|
370
|
-
|
|
371
|
-
|
|
372
|
-
expect(symbolTable.getStructFieldType("Point", "z")).toBeUndefined();
|
|
373
|
-
});
|
|
374
|
-
|
|
375
|
-
it("should add struct field with array dimensions", () => {
|
|
376
|
-
symbolTable.addStructField("Buffer", "data", "uint8_t", [256]);
|
|
377
|
-
symbolTable.addStructField("Matrix", "values", "float", [4, 4]);
|
|
378
|
-
|
|
379
|
-
const bufferField = symbolTable.getStructFieldInfo("Buffer", "data");
|
|
380
|
-
expect(bufferField?.type).toBe("uint8_t");
|
|
381
|
-
expect(bufferField?.arrayDimensions).toEqual([256]);
|
|
382
|
-
|
|
383
|
-
const matrixField = symbolTable.getStructFieldInfo("Matrix", "values");
|
|
384
|
-
expect(matrixField?.type).toBe("float");
|
|
385
|
-
expect(matrixField?.arrayDimensions).toEqual([4, 4]);
|
|
386
|
-
});
|
|
387
|
-
|
|
388
|
-
it("should get all fields for a struct", () => {
|
|
389
|
-
symbolTable.addStructField("Person", "name", "char*");
|
|
390
|
-
symbolTable.addStructField("Person", "age", "uint8_t");
|
|
391
|
-
symbolTable.addStructField("Person", "id", "uint32_t");
|
|
392
|
-
|
|
393
|
-
const fields = symbolTable.getStructFields("Person");
|
|
394
|
-
expect(fields).toBeDefined();
|
|
395
|
-
expect(fields?.size).toBe(3);
|
|
396
|
-
expect(fields?.get("name")?.type).toBe("char*");
|
|
397
|
-
expect(fields?.get("age")?.type).toBe("uint8_t");
|
|
398
|
-
});
|
|
399
|
-
|
|
400
|
-
it("should return undefined for unknown struct in getStructFields", () => {
|
|
401
|
-
expect(symbolTable.getStructFields("Unknown")).toBeUndefined();
|
|
402
|
-
});
|
|
403
|
-
|
|
404
|
-
it("should get all struct fields for serialization", () => {
|
|
405
|
-
symbolTable.addStructField("A", "x", "int");
|
|
406
|
-
symbolTable.addStructField("B", "y", "float");
|
|
407
|
-
|
|
408
|
-
const allFields = symbolTable.getAllStructFields();
|
|
409
|
-
expect(allFields.size).toBe(2);
|
|
410
|
-
expect(allFields.has("A")).toBe(true);
|
|
411
|
-
expect(allFields.has("B")).toBe(true);
|
|
412
|
-
});
|
|
413
|
-
|
|
414
|
-
it("should restore struct fields from cache", () => {
|
|
415
|
-
const cached = new Map<
|
|
416
|
-
string,
|
|
417
|
-
Map<string, { type: string; arrayDimensions?: number[] }>
|
|
418
|
-
>();
|
|
419
|
-
const pointFields = new Map();
|
|
420
|
-
pointFields.set("x", { type: "int32_t" });
|
|
421
|
-
pointFields.set("y", { type: "int32_t" });
|
|
422
|
-
cached.set("Point", pointFields);
|
|
423
|
-
|
|
424
|
-
symbolTable.restoreStructFields(cached);
|
|
425
|
-
|
|
426
|
-
expect(symbolTable.getStructFieldType("Point", "x")).toBe("int32_t");
|
|
427
|
-
expect(symbolTable.getStructFieldType("Point", "y")).toBe("int32_t");
|
|
428
|
-
});
|
|
429
|
-
|
|
430
|
-
it("should merge restored struct fields with existing", () => {
|
|
431
|
-
symbolTable.addStructField("Point", "x", "int32_t");
|
|
432
|
-
|
|
433
|
-
const cached = new Map<
|
|
434
|
-
string,
|
|
435
|
-
Map<string, { type: string; arrayDimensions?: number[] }>
|
|
436
|
-
>();
|
|
437
|
-
const pointFields = new Map();
|
|
438
|
-
pointFields.set("z", { type: "int32_t" });
|
|
439
|
-
cached.set("Point", pointFields);
|
|
440
|
-
|
|
441
|
-
symbolTable.restoreStructFields(cached);
|
|
442
|
-
|
|
443
|
-
expect(symbolTable.getStructFieldType("Point", "x")).toBe("int32_t");
|
|
444
|
-
expect(symbolTable.getStructFieldType("Point", "z")).toBe("int32_t");
|
|
445
|
-
});
|
|
446
|
-
});
|
|
447
|
-
|
|
448
|
-
describe("getStructNamesByFile", () => {
|
|
449
|
-
it("should return struct names defined in a file", () => {
|
|
450
|
-
// Add a symbol for the struct
|
|
451
|
-
symbolTable.addSymbol({
|
|
452
|
-
name: "Point",
|
|
453
|
-
kind: ESymbolKind.Struct,
|
|
454
|
-
sourceFile: "geometry.h",
|
|
455
|
-
sourceLine: 1,
|
|
456
|
-
sourceLanguage: ESourceLanguage.C,
|
|
457
|
-
isExported: true,
|
|
458
|
-
});
|
|
459
|
-
|
|
460
|
-
// Register struct fields (which marks it as having struct data)
|
|
461
|
-
symbolTable.addStructField("Point", "x", "int");
|
|
462
|
-
symbolTable.addStructField("Point", "y", "int");
|
|
463
|
-
|
|
464
|
-
const structNames = symbolTable.getStructNamesByFile("geometry.h");
|
|
465
|
-
expect(structNames).toContain("Point");
|
|
466
|
-
});
|
|
467
|
-
|
|
468
|
-
it("should return empty array for file with no structs", () => {
|
|
469
|
-
symbolTable.addSymbol({
|
|
470
|
-
name: "someVar",
|
|
471
|
-
kind: ESymbolKind.Variable,
|
|
472
|
-
sourceFile: "vars.cnx",
|
|
246
|
+
symbolTable.addCppSymbol({
|
|
247
|
+
kind: "function",
|
|
248
|
+
name: "process",
|
|
249
|
+
sourceFile: "test.hpp",
|
|
473
250
|
sourceLine: 1,
|
|
474
|
-
sourceLanguage: ESourceLanguage.
|
|
251
|
+
sourceLanguage: ESourceLanguage.Cpp,
|
|
475
252
|
isExported: true,
|
|
253
|
+
type: "void",
|
|
254
|
+
parameters: [
|
|
255
|
+
{ name: "x", type: "int", isConst: false, isArray: false },
|
|
256
|
+
],
|
|
476
257
|
});
|
|
477
258
|
|
|
478
|
-
|
|
479
|
-
|
|
480
|
-
|
|
481
|
-
it("should return empty array for unknown file", () => {
|
|
482
|
-
expect(symbolTable.getStructNamesByFile("nonexistent.cnx")).toEqual([]);
|
|
483
|
-
});
|
|
484
|
-
});
|
|
485
|
-
|
|
486
|
-
// ========================================================================
|
|
487
|
-
// Struct Keyword Tracking (Issue #196)
|
|
488
|
-
// ========================================================================
|
|
489
|
-
|
|
490
|
-
describe("struct keyword tracking", () => {
|
|
491
|
-
it("should mark and check if struct needs keyword", () => {
|
|
492
|
-
symbolTable.markNeedsStructKeyword("NamedPoint");
|
|
493
|
-
|
|
494
|
-
expect(symbolTable.checkNeedsStructKeyword("NamedPoint")).toBe(true);
|
|
495
|
-
expect(symbolTable.checkNeedsStructKeyword("OtherStruct")).toBe(false);
|
|
496
|
-
});
|
|
497
|
-
|
|
498
|
-
it("should get all structs needing keyword", () => {
|
|
499
|
-
symbolTable.markNeedsStructKeyword("Struct1");
|
|
500
|
-
symbolTable.markNeedsStructKeyword("Struct2");
|
|
501
|
-
symbolTable.markNeedsStructKeyword("Struct3");
|
|
502
|
-
|
|
503
|
-
const all = symbolTable.getAllNeedsStructKeyword();
|
|
504
|
-
expect(all.length).toBe(3);
|
|
505
|
-
expect(all.sort()).toEqual(["Struct1", "Struct2", "Struct3"]);
|
|
506
|
-
});
|
|
507
|
-
|
|
508
|
-
it("should restore struct keyword set from cache", () => {
|
|
509
|
-
symbolTable.restoreNeedsStructKeyword(["CachedStruct1", "CachedStruct2"]);
|
|
510
|
-
|
|
511
|
-
expect(symbolTable.checkNeedsStructKeyword("CachedStruct1")).toBe(true);
|
|
512
|
-
expect(symbolTable.checkNeedsStructKeyword("CachedStruct2")).toBe(true);
|
|
513
|
-
expect(symbolTable.checkNeedsStructKeyword("NotCached")).toBe(false);
|
|
514
|
-
});
|
|
515
|
-
});
|
|
516
|
-
|
|
517
|
-
// ========================================================================
|
|
518
|
-
// Enum Bit Width Tracking (Issue #208)
|
|
519
|
-
// ========================================================================
|
|
520
|
-
|
|
521
|
-
describe("enum bit width tracking", () => {
|
|
522
|
-
it("should add and get enum bit width", () => {
|
|
523
|
-
symbolTable.addEnumBitWidth("EPressureType", 8);
|
|
524
|
-
symbolTable.addEnumBitWidth("ELargeEnum", 32);
|
|
525
|
-
|
|
526
|
-
expect(symbolTable.getEnumBitWidth("EPressureType")).toBe(8);
|
|
527
|
-
expect(symbolTable.getEnumBitWidth("ELargeEnum")).toBe(32);
|
|
528
|
-
});
|
|
529
|
-
|
|
530
|
-
it("should return undefined for unknown enum", () => {
|
|
531
|
-
expect(symbolTable.getEnumBitWidth("UnknownEnum")).toBeUndefined();
|
|
532
|
-
});
|
|
533
|
-
|
|
534
|
-
it("should get all enum bit widths for serialization", () => {
|
|
535
|
-
symbolTable.addEnumBitWidth("Enum8", 8);
|
|
536
|
-
symbolTable.addEnumBitWidth("Enum16", 16);
|
|
537
|
-
|
|
538
|
-
const allWidths = symbolTable.getAllEnumBitWidths();
|
|
539
|
-
expect(allWidths.size).toBe(2);
|
|
540
|
-
expect(allWidths.get("Enum8")).toBe(8);
|
|
541
|
-
expect(allWidths.get("Enum16")).toBe(16);
|
|
542
|
-
});
|
|
543
|
-
|
|
544
|
-
it("should restore enum bit widths from cache", () => {
|
|
545
|
-
const cached = new Map<string, number>();
|
|
546
|
-
cached.set("CachedEnum1", 8);
|
|
547
|
-
cached.set("CachedEnum2", 16);
|
|
548
|
-
|
|
549
|
-
symbolTable.restoreEnumBitWidths(cached);
|
|
550
|
-
|
|
551
|
-
expect(symbolTable.getEnumBitWidth("CachedEnum1")).toBe(8);
|
|
552
|
-
expect(symbolTable.getEnumBitWidth("CachedEnum2")).toBe(16);
|
|
259
|
+
const overloads = symbolTable.getOverloads("process");
|
|
260
|
+
expect(overloads.length).toBe(2);
|
|
553
261
|
});
|
|
554
262
|
});
|
|
555
263
|
|
|
556
264
|
// ========================================================================
|
|
557
|
-
//
|
|
265
|
+
// Conflict Detection
|
|
558
266
|
// ========================================================================
|
|
559
267
|
|
|
560
268
|
describe("hasConflict", () => {
|
|
561
|
-
it("should
|
|
562
|
-
symbolTable.
|
|
563
|
-
|
|
564
|
-
|
|
565
|
-
sourceFile: "
|
|
269
|
+
it("should detect cross-language conflicts between C-Next and C", () => {
|
|
270
|
+
symbolTable.addTSymbol({
|
|
271
|
+
kind: "function",
|
|
272
|
+
name: "conflictFunc",
|
|
273
|
+
sourceFile: "test.cnx",
|
|
566
274
|
sourceLine: 1,
|
|
567
275
|
sourceLanguage: ESourceLanguage.CNext,
|
|
568
276
|
isExported: true,
|
|
569
|
-
|
|
277
|
+
returnType: TTypeUtils.createPrimitive("void"),
|
|
278
|
+
parameters: [],
|
|
279
|
+
scope: TestScopeUtils.createMockGlobalScope(),
|
|
280
|
+
visibility: "public",
|
|
281
|
+
body: null,
|
|
282
|
+
} as IFunctionSymbol);
|
|
570
283
|
|
|
571
|
-
symbolTable.
|
|
572
|
-
|
|
573
|
-
|
|
574
|
-
sourceFile: "
|
|
284
|
+
symbolTable.addCSymbol({
|
|
285
|
+
kind: "function",
|
|
286
|
+
name: "conflictFunc",
|
|
287
|
+
sourceFile: "test.h",
|
|
575
288
|
sourceLine: 1,
|
|
576
|
-
sourceLanguage: ESourceLanguage.
|
|
289
|
+
sourceLanguage: ESourceLanguage.C,
|
|
577
290
|
isExported: true,
|
|
291
|
+
type: "void",
|
|
292
|
+
parameters: [],
|
|
578
293
|
});
|
|
579
294
|
|
|
580
|
-
expect(symbolTable.hasConflict("
|
|
295
|
+
expect(symbolTable.hasConflict("conflictFunc")).toBe(true);
|
|
581
296
|
});
|
|
582
297
|
|
|
583
|
-
it("should
|
|
584
|
-
symbolTable.
|
|
585
|
-
|
|
586
|
-
|
|
587
|
-
sourceFile: "
|
|
298
|
+
it("should not detect conflict for C++ function overloads with different signatures", () => {
|
|
299
|
+
symbolTable.addCppSymbol({
|
|
300
|
+
kind: "function",
|
|
301
|
+
name: "overloaded",
|
|
302
|
+
sourceFile: "test.hpp",
|
|
588
303
|
sourceLine: 1,
|
|
589
|
-
sourceLanguage: ESourceLanguage.
|
|
304
|
+
sourceLanguage: ESourceLanguage.Cpp,
|
|
590
305
|
isExported: true,
|
|
306
|
+
type: "void",
|
|
307
|
+
parameters: [],
|
|
591
308
|
});
|
|
592
309
|
|
|
593
|
-
|
|
594
|
-
|
|
310
|
+
symbolTable.addCppSymbol({
|
|
311
|
+
kind: "function",
|
|
312
|
+
name: "overloaded",
|
|
313
|
+
sourceFile: "test.hpp",
|
|
314
|
+
sourceLine: 5,
|
|
315
|
+
sourceLanguage: ESourceLanguage.Cpp,
|
|
316
|
+
isExported: true,
|
|
317
|
+
type: "void",
|
|
318
|
+
parameters: [
|
|
319
|
+
{ name: "x", type: "int", isConst: false, isArray: false },
|
|
320
|
+
],
|
|
321
|
+
});
|
|
595
322
|
|
|
596
|
-
|
|
597
|
-
expect(symbolTable.hasConflict("doesNotExist")).toBe(false);
|
|
323
|
+
expect(symbolTable.hasConflict("overloaded")).toBe(false);
|
|
598
324
|
});
|
|
599
|
-
});
|
|
600
325
|
|
|
601
|
-
|
|
602
|
-
|
|
603
|
-
|
|
326
|
+
// Issue #817: Scope-private members should NOT conflict across scopes
|
|
327
|
+
it("should NOT detect conflict for same-named members in different scopes", () => {
|
|
328
|
+
// Create two different named scopes
|
|
329
|
+
const globalScope = TestScopeUtils.createMockGlobalScope();
|
|
330
|
+
const fooScope = TestScopeUtils.createMockScope("Foo", globalScope);
|
|
331
|
+
const barScope = TestScopeUtils.createMockScope("Bar", globalScope);
|
|
604
332
|
|
|
605
|
-
|
|
606
|
-
|
|
607
|
-
|
|
608
|
-
|
|
609
|
-
|
|
610
|
-
|
|
611
|
-
sourceFile: "file1.cnx",
|
|
612
|
-
sourceLine: 1,
|
|
333
|
+
// Add 'enabled' variable in scope Foo
|
|
334
|
+
symbolTable.addTSymbol({
|
|
335
|
+
kind: "variable",
|
|
336
|
+
name: "enabled",
|
|
337
|
+
sourceFile: "test.cnx",
|
|
338
|
+
sourceLine: 2,
|
|
613
339
|
sourceLanguage: ESourceLanguage.CNext,
|
|
614
|
-
isExported:
|
|
340
|
+
isExported: false,
|
|
341
|
+
type: TTypeUtils.createPrimitive("bool"),
|
|
342
|
+
isArray: false,
|
|
343
|
+
isConst: false,
|
|
344
|
+
isAtomic: false,
|
|
345
|
+
scope: fooScope,
|
|
615
346
|
});
|
|
616
347
|
|
|
617
|
-
|
|
618
|
-
|
|
619
|
-
kind:
|
|
620
|
-
|
|
621
|
-
|
|
348
|
+
// Add 'enabled' variable in scope Bar
|
|
349
|
+
symbolTable.addTSymbol({
|
|
350
|
+
kind: "variable",
|
|
351
|
+
name: "enabled",
|
|
352
|
+
sourceFile: "test.cnx",
|
|
353
|
+
sourceLine: 10,
|
|
622
354
|
sourceLanguage: ESourceLanguage.CNext,
|
|
623
|
-
isExported:
|
|
355
|
+
isExported: false,
|
|
356
|
+
type: TTypeUtils.createPrimitive("bool"),
|
|
357
|
+
isArray: false,
|
|
358
|
+
isConst: false,
|
|
359
|
+
isAtomic: false,
|
|
360
|
+
scope: barScope,
|
|
624
361
|
});
|
|
625
362
|
|
|
626
|
-
|
|
627
|
-
expect(
|
|
628
|
-
expect(conflicts[0].symbolName).toBe("counter");
|
|
363
|
+
// These are NOT conflicts - they generate Foo_enabled and Bar_enabled
|
|
364
|
+
expect(symbolTable.hasConflict("enabled")).toBe(false);
|
|
629
365
|
});
|
|
630
366
|
|
|
631
|
-
|
|
632
|
-
|
|
367
|
+
// Issue #817: Same-named functions in different scopes are not conflicts
|
|
368
|
+
it("should NOT detect conflict for same-named functions in different scopes", () => {
|
|
369
|
+
const globalScope = TestScopeUtils.createMockGlobalScope();
|
|
370
|
+
const fooScope = TestScopeUtils.createMockScope("Foo", globalScope);
|
|
371
|
+
const barScope = TestScopeUtils.createMockScope("Bar", globalScope);
|
|
633
372
|
|
|
634
|
-
// Add function
|
|
635
|
-
symbolTable.
|
|
636
|
-
|
|
637
|
-
|
|
638
|
-
|
|
639
|
-
|
|
640
|
-
sourceLine: 1,
|
|
373
|
+
// Add 'initialize' function in scope Foo
|
|
374
|
+
symbolTable.addTSymbol({
|
|
375
|
+
kind: "function",
|
|
376
|
+
name: "initialize",
|
|
377
|
+
sourceFile: "test.cnx",
|
|
378
|
+
sourceLine: 4,
|
|
641
379
|
sourceLanguage: ESourceLanguage.CNext,
|
|
642
380
|
isExported: true,
|
|
643
|
-
|
|
644
|
-
|
|
381
|
+
returnType: TTypeUtils.createPrimitive("void"),
|
|
382
|
+
parameters: [],
|
|
383
|
+
scope: fooScope,
|
|
384
|
+
visibility: "public",
|
|
385
|
+
body: null,
|
|
386
|
+
} as IFunctionSymbol);
|
|
645
387
|
|
|
646
|
-
// Add
|
|
647
|
-
symbolTable.
|
|
648
|
-
|
|
649
|
-
|
|
650
|
-
|
|
651
|
-
|
|
652
|
-
sourceLine: 1,
|
|
388
|
+
// Add 'initialize' function in scope Bar
|
|
389
|
+
symbolTable.addTSymbol({
|
|
390
|
+
kind: "function",
|
|
391
|
+
name: "initialize",
|
|
392
|
+
sourceFile: "test.cnx",
|
|
393
|
+
sourceLine: 12,
|
|
653
394
|
sourceLanguage: ESourceLanguage.CNext,
|
|
654
|
-
|
|
655
|
-
|
|
656
|
-
|
|
395
|
+
isExported: true,
|
|
396
|
+
returnType: TTypeUtils.createPrimitive("void"),
|
|
397
|
+
parameters: [],
|
|
398
|
+
scope: barScope,
|
|
399
|
+
visibility: "public",
|
|
400
|
+
body: null,
|
|
401
|
+
} as IFunctionSymbol);
|
|
657
402
|
|
|
658
|
-
//
|
|
659
|
-
symbolTable.
|
|
660
|
-
|
|
661
|
-
kind: ESymbolKind.Variable,
|
|
662
|
-
type: "f32",
|
|
663
|
-
sourceFile: "math.cnx",
|
|
664
|
-
sourceLine: 1,
|
|
665
|
-
sourceLanguage: ESourceLanguage.CNext,
|
|
666
|
-
parent: "Math_add",
|
|
667
|
-
isExported: false,
|
|
668
|
-
});
|
|
403
|
+
// These generate Foo_initialize and Bar_initialize - no conflict
|
|
404
|
+
expect(symbolTable.hasConflict("initialize")).toBe(false);
|
|
405
|
+
});
|
|
669
406
|
|
|
670
|
-
|
|
671
|
-
|
|
672
|
-
|
|
673
|
-
|
|
674
|
-
type: "f32",
|
|
675
|
-
sourceFile: "math.cnx",
|
|
676
|
-
sourceLine: 5,
|
|
677
|
-
sourceLanguage: ESourceLanguage.CNext,
|
|
678
|
-
isExported: true,
|
|
679
|
-
parent: "Math",
|
|
680
|
-
});
|
|
407
|
+
// True conflicts: same name in same scope should still be detected
|
|
408
|
+
it("should detect conflict for same-named symbols in same scope", () => {
|
|
409
|
+
const globalScope = TestScopeUtils.createMockGlobalScope();
|
|
410
|
+
const fooScope = TestScopeUtils.createMockScope("Foo", globalScope);
|
|
681
411
|
|
|
682
|
-
// Add
|
|
683
|
-
symbolTable.
|
|
684
|
-
|
|
685
|
-
|
|
686
|
-
|
|
687
|
-
|
|
688
|
-
sourceLine: 5,
|
|
412
|
+
// Add 'duplicate' variable in scope Foo twice
|
|
413
|
+
symbolTable.addTSymbol({
|
|
414
|
+
kind: "variable",
|
|
415
|
+
name: "duplicate",
|
|
416
|
+
sourceFile: "test.cnx",
|
|
417
|
+
sourceLine: 2,
|
|
689
418
|
sourceLanguage: ESourceLanguage.CNext,
|
|
690
|
-
parent: "Math_multiply", // Different parent function
|
|
691
419
|
isExported: false,
|
|
420
|
+
type: TTypeUtils.createPrimitive("bool"),
|
|
421
|
+
isArray: false,
|
|
422
|
+
isConst: false,
|
|
423
|
+
isAtomic: false,
|
|
424
|
+
scope: fooScope,
|
|
692
425
|
});
|
|
693
426
|
|
|
694
|
-
|
|
695
|
-
|
|
696
|
-
name: "
|
|
697
|
-
|
|
698
|
-
type: "f32",
|
|
699
|
-
sourceFile: "math.cnx",
|
|
427
|
+
symbolTable.addTSymbol({
|
|
428
|
+
kind: "variable",
|
|
429
|
+
name: "duplicate",
|
|
430
|
+
sourceFile: "test.cnx",
|
|
700
431
|
sourceLine: 5,
|
|
701
432
|
sourceLanguage: ESourceLanguage.CNext,
|
|
702
|
-
parent: "Math_multiply",
|
|
703
433
|
isExported: false,
|
|
434
|
+
type: TTypeUtils.createPrimitive("bool"),
|
|
435
|
+
isArray: false,
|
|
436
|
+
isConst: false,
|
|
437
|
+
isAtomic: false,
|
|
438
|
+
scope: fooScope,
|
|
704
439
|
});
|
|
705
440
|
|
|
706
|
-
//
|
|
707
|
-
|
|
708
|
-
expect(conflicts.length).toBe(0);
|
|
441
|
+
// Same name in SAME scope IS a conflict
|
|
442
|
+
expect(symbolTable.hasConflict("duplicate")).toBe(true);
|
|
709
443
|
});
|
|
710
444
|
|
|
711
|
-
|
|
712
|
-
|
|
713
|
-
|
|
714
|
-
|
|
715
|
-
|
|
716
|
-
|
|
445
|
+
// Global scope conflicts should still be detected
|
|
446
|
+
it("should detect conflict for same-named globals", () => {
|
|
447
|
+
const globalScope = TestScopeUtils.createMockGlobalScope();
|
|
448
|
+
|
|
449
|
+
// Add two global variables with same name
|
|
450
|
+
symbolTable.addTSymbol({
|
|
451
|
+
kind: "variable",
|
|
452
|
+
name: "globalVar",
|
|
453
|
+
sourceFile: "first.cnx",
|
|
717
454
|
sourceLine: 1,
|
|
718
455
|
sourceLanguage: ESourceLanguage.CNext,
|
|
719
456
|
isExported: true,
|
|
720
|
-
|
|
457
|
+
type: TTypeUtils.createPrimitive("u32"),
|
|
458
|
+
isArray: false,
|
|
459
|
+
isConst: false,
|
|
460
|
+
isAtomic: false,
|
|
461
|
+
scope: globalScope,
|
|
721
462
|
});
|
|
722
463
|
|
|
723
|
-
symbolTable.
|
|
724
|
-
|
|
725
|
-
|
|
726
|
-
sourceFile: "
|
|
727
|
-
sourceLine:
|
|
464
|
+
symbolTable.addTSymbol({
|
|
465
|
+
kind: "variable",
|
|
466
|
+
name: "globalVar",
|
|
467
|
+
sourceFile: "second.cnx",
|
|
468
|
+
sourceLine: 1,
|
|
728
469
|
sourceLanguage: ESourceLanguage.CNext,
|
|
729
470
|
isExported: true,
|
|
730
|
-
|
|
471
|
+
type: TTypeUtils.createPrimitive("u32"),
|
|
472
|
+
isArray: false,
|
|
473
|
+
isConst: false,
|
|
474
|
+
isAtomic: false,
|
|
475
|
+
scope: globalScope,
|
|
731
476
|
});
|
|
732
477
|
|
|
733
|
-
|
|
734
|
-
expect(
|
|
735
|
-
expect(conflicts[0].symbolName).toBe("Math_counter");
|
|
478
|
+
// Two globals with same name IS a conflict
|
|
479
|
+
expect(symbolTable.hasConflict("globalVar")).toBe(true);
|
|
736
480
|
});
|
|
481
|
+
});
|
|
737
482
|
|
|
738
|
-
|
|
739
|
-
|
|
740
|
-
|
|
741
|
-
name: "divide",
|
|
742
|
-
kind: ESymbolKind.Function,
|
|
743
|
-
type: "f32",
|
|
744
|
-
sourceFile: "math.cnx",
|
|
745
|
-
sourceLine: 10,
|
|
746
|
-
sourceLanguage: ESourceLanguage.CNext,
|
|
747
|
-
isExported: true,
|
|
748
|
-
});
|
|
749
|
-
|
|
750
|
-
symbolTable.addSymbol({
|
|
751
|
-
name: "x",
|
|
752
|
-
kind: ESymbolKind.Variable,
|
|
753
|
-
type: "f32",
|
|
754
|
-
sourceFile: "math.cnx",
|
|
755
|
-
sourceLine: 10,
|
|
756
|
-
sourceLanguage: ESourceLanguage.CNext,
|
|
757
|
-
parent: "divide",
|
|
758
|
-
isExported: false,
|
|
759
|
-
});
|
|
483
|
+
// ========================================================================
|
|
484
|
+
// Type-Safe Symbol Queries
|
|
485
|
+
// ========================================================================
|
|
760
486
|
|
|
761
|
-
|
|
762
|
-
|
|
763
|
-
|
|
764
|
-
kind:
|
|
765
|
-
|
|
766
|
-
sourceFile: "
|
|
487
|
+
describe("type-safe queries", () => {
|
|
488
|
+
it("getStructSymbols should return only struct symbols", () => {
|
|
489
|
+
symbolTable.addTSymbol({
|
|
490
|
+
kind: "struct",
|
|
491
|
+
name: "MyStruct",
|
|
492
|
+
sourceFile: "test.cnx",
|
|
767
493
|
sourceLine: 1,
|
|
768
494
|
sourceLanguage: ESourceLanguage.CNext,
|
|
769
495
|
isExported: true,
|
|
770
|
-
|
|
771
|
-
|
|
496
|
+
fields: new Map(),
|
|
497
|
+
scope: TestScopeUtils.createMockGlobalScope(),
|
|
498
|
+
} as IStructSymbol);
|
|
772
499
|
|
|
773
|
-
symbolTable.
|
|
774
|
-
|
|
775
|
-
|
|
776
|
-
|
|
777
|
-
|
|
778
|
-
sourceLine: 1,
|
|
500
|
+
symbolTable.addTSymbol({
|
|
501
|
+
kind: "variable",
|
|
502
|
+
name: "myVar",
|
|
503
|
+
sourceFile: "test.cnx",
|
|
504
|
+
sourceLine: 2,
|
|
779
505
|
sourceLanguage: ESourceLanguage.CNext,
|
|
780
|
-
|
|
781
|
-
|
|
506
|
+
isExported: true,
|
|
507
|
+
type: TTypeUtils.createPrimitive("u32"),
|
|
508
|
+
isArray: false,
|
|
509
|
+
isConst: false,
|
|
510
|
+
isAtomic: false,
|
|
511
|
+
scope: TestScopeUtils.createMockGlobalScope(),
|
|
782
512
|
});
|
|
783
513
|
|
|
784
|
-
|
|
785
|
-
|
|
786
|
-
expect(
|
|
514
|
+
const structs = symbolTable.getStructSymbols();
|
|
515
|
+
expect(structs.length).toBe(1);
|
|
516
|
+
expect(structs[0].name).toBe("MyStruct");
|
|
787
517
|
});
|
|
788
518
|
|
|
789
|
-
it("should
|
|
790
|
-
|
|
791
|
-
|
|
792
|
-
name: "
|
|
793
|
-
|
|
794
|
-
sourceFile: "module.cnx",
|
|
519
|
+
it("getEnumSymbols should return only enum symbols", () => {
|
|
520
|
+
symbolTable.addTSymbol({
|
|
521
|
+
kind: "enum",
|
|
522
|
+
name: "MyEnum",
|
|
523
|
+
sourceFile: "test.cnx",
|
|
795
524
|
sourceLine: 1,
|
|
796
525
|
sourceLanguage: ESourceLanguage.CNext,
|
|
797
526
|
isExported: true,
|
|
798
|
-
|
|
799
|
-
|
|
800
|
-
|
|
801
|
-
name: "sharedVar",
|
|
802
|
-
kind: ESymbolKind.Variable,
|
|
803
|
-
sourceFile: "legacy.c",
|
|
804
|
-
sourceLine: 10,
|
|
805
|
-
sourceLanguage: ESourceLanguage.C,
|
|
806
|
-
isExported: true,
|
|
807
|
-
});
|
|
527
|
+
members: new Map([["VALUE1", 0]]),
|
|
528
|
+
scope: TestScopeUtils.createMockGlobalScope(),
|
|
529
|
+
} as IEnumSymbol);
|
|
808
530
|
|
|
809
|
-
const
|
|
810
|
-
expect(
|
|
811
|
-
expect(
|
|
812
|
-
expect(conflicts[0].severity).toBe("error");
|
|
813
|
-
expect(conflicts[0].message).toContain("defined in multiple languages");
|
|
531
|
+
const enums = symbolTable.getEnumSymbols();
|
|
532
|
+
expect(enums.length).toBe(1);
|
|
533
|
+
expect(enums[0].name).toBe("MyEnum");
|
|
814
534
|
});
|
|
815
535
|
|
|
816
|
-
it("should
|
|
817
|
-
|
|
818
|
-
|
|
819
|
-
name: "
|
|
820
|
-
|
|
821
|
-
sourceFile: "module.cnx",
|
|
536
|
+
it("getFunctionSymbols should return only function symbols", () => {
|
|
537
|
+
symbolTable.addTSymbol({
|
|
538
|
+
kind: "function",
|
|
539
|
+
name: "myFunc",
|
|
540
|
+
sourceFile: "test.cnx",
|
|
822
541
|
sourceLine: 1,
|
|
823
542
|
sourceLanguage: ESourceLanguage.CNext,
|
|
824
543
|
isExported: true,
|
|
825
|
-
|
|
544
|
+
returnType: TTypeUtils.createPrimitive("void"),
|
|
545
|
+
parameters: [],
|
|
546
|
+
scope: TestScopeUtils.createMockGlobalScope(),
|
|
547
|
+
visibility: "public",
|
|
548
|
+
body: null,
|
|
549
|
+
} as IFunctionSymbol);
|
|
826
550
|
|
|
827
|
-
symbolTable.
|
|
828
|
-
|
|
829
|
-
|
|
830
|
-
sourceFile: "driver.cpp",
|
|
831
|
-
sourceLine: 20,
|
|
832
|
-
sourceLanguage: ESourceLanguage.Cpp,
|
|
833
|
-
isExported: true,
|
|
834
|
-
});
|
|
835
|
-
|
|
836
|
-
const conflicts = symbolTable.getConflicts();
|
|
837
|
-
expect(conflicts.length).toBe(1);
|
|
838
|
-
expect(conflicts[0].symbolName).toBe("sharedFunc");
|
|
839
|
-
expect(conflicts[0].severity).toBe("error");
|
|
551
|
+
const functions = symbolTable.getFunctionSymbols();
|
|
552
|
+
expect(functions.length).toBe(1);
|
|
553
|
+
expect(functions[0].name).toBe("myFunc");
|
|
840
554
|
});
|
|
555
|
+
});
|
|
841
556
|
|
|
842
|
-
|
|
843
|
-
|
|
844
|
-
|
|
845
|
-
name: "commonSymbol",
|
|
846
|
-
kind: ESymbolKind.Variable,
|
|
847
|
-
sourceFile: "shared.c",
|
|
848
|
-
sourceLine: 1,
|
|
849
|
-
sourceLanguage: ESourceLanguage.C,
|
|
850
|
-
isExported: true,
|
|
851
|
-
});
|
|
557
|
+
// ========================================================================
|
|
558
|
+
// Struct Field Information
|
|
559
|
+
// ========================================================================
|
|
852
560
|
|
|
853
|
-
|
|
854
|
-
|
|
855
|
-
|
|
856
|
-
|
|
857
|
-
sourceLine: 5,
|
|
858
|
-
sourceLanguage: ESourceLanguage.Cpp,
|
|
859
|
-
isExported: true,
|
|
860
|
-
});
|
|
561
|
+
describe("struct fields", () => {
|
|
562
|
+
it("should add and retrieve struct field information", () => {
|
|
563
|
+
symbolTable.addStructField("Point", "x", "int");
|
|
564
|
+
symbolTable.addStructField("Point", "y", "int");
|
|
861
565
|
|
|
862
|
-
|
|
863
|
-
expect(
|
|
566
|
+
expect(symbolTable.getStructFieldType("Point", "x")).toBe("int");
|
|
567
|
+
expect(symbolTable.getStructFieldType("Point", "y")).toBe("int");
|
|
864
568
|
});
|
|
865
569
|
|
|
866
|
-
it("should
|
|
867
|
-
|
|
868
|
-
|
|
869
|
-
|
|
870
|
-
|
|
871
|
-
sourceFile: "utils.cpp",
|
|
872
|
-
sourceLine: 1,
|
|
873
|
-
sourceLanguage: ESourceLanguage.Cpp,
|
|
874
|
-
isExported: true,
|
|
875
|
-
});
|
|
876
|
-
|
|
877
|
-
symbolTable.addSymbol({
|
|
878
|
-
name: "process",
|
|
879
|
-
kind: ESymbolKind.Function,
|
|
880
|
-
signature: "void(int, int)",
|
|
881
|
-
sourceFile: "utils.cpp",
|
|
882
|
-
sourceLine: 10,
|
|
883
|
-
sourceLanguage: ESourceLanguage.Cpp,
|
|
884
|
-
isExported: true,
|
|
885
|
-
});
|
|
570
|
+
it("should return undefined for non-existent struct or field", () => {
|
|
571
|
+
expect(
|
|
572
|
+
symbolTable.getStructFieldType("NonExistent", "x"),
|
|
573
|
+
).toBeUndefined();
|
|
574
|
+
});
|
|
886
575
|
|
|
887
|
-
|
|
888
|
-
|
|
889
|
-
|
|
890
|
-
signature: "void(float)",
|
|
891
|
-
sourceFile: "utils.cpp",
|
|
892
|
-
sourceLine: 20,
|
|
893
|
-
sourceLanguage: ESourceLanguage.Cpp,
|
|
894
|
-
isExported: true,
|
|
895
|
-
});
|
|
576
|
+
it("should get all fields for a struct", () => {
|
|
577
|
+
symbolTable.addStructField("Point", "x", "int");
|
|
578
|
+
symbolTable.addStructField("Point", "y", "int");
|
|
896
579
|
|
|
897
|
-
const
|
|
898
|
-
expect(
|
|
580
|
+
const fields = symbolTable.getStructFields("Point");
|
|
581
|
+
expect(fields?.size).toBe(2);
|
|
899
582
|
});
|
|
583
|
+
});
|
|
900
584
|
|
|
901
|
-
|
|
902
|
-
|
|
903
|
-
|
|
904
|
-
name: "externVar",
|
|
905
|
-
kind: ESymbolKind.Variable,
|
|
906
|
-
sourceFile: "header.h",
|
|
907
|
-
sourceLine: 1,
|
|
908
|
-
sourceLanguage: ESourceLanguage.C,
|
|
909
|
-
isExported: true,
|
|
910
|
-
isDeclaration: true, // extern declaration
|
|
911
|
-
});
|
|
585
|
+
// ========================================================================
|
|
586
|
+
// Needs Struct Keyword Tracking
|
|
587
|
+
// ========================================================================
|
|
912
588
|
|
|
913
|
-
|
|
914
|
-
|
|
915
|
-
|
|
916
|
-
sourceFile: "impl.c",
|
|
917
|
-
sourceLine: 10,
|
|
918
|
-
sourceLanguage: ESourceLanguage.C,
|
|
919
|
-
isExported: true,
|
|
920
|
-
isDeclaration: false, // actual definition
|
|
921
|
-
});
|
|
589
|
+
describe("needsStructKeyword", () => {
|
|
590
|
+
it("should track structs requiring struct keyword", () => {
|
|
591
|
+
symbolTable.markNeedsStructKeyword("RawStruct");
|
|
922
592
|
|
|
923
|
-
|
|
924
|
-
expect(
|
|
593
|
+
expect(symbolTable.checkNeedsStructKeyword("RawStruct")).toBe(true);
|
|
594
|
+
expect(symbolTable.checkNeedsStructKeyword("OtherStruct")).toBe(false);
|
|
925
595
|
});
|
|
596
|
+
});
|
|
926
597
|
|
|
927
|
-
|
|
928
|
-
|
|
929
|
-
|
|
930
|
-
name: "Math_calculate",
|
|
931
|
-
kind: ESymbolKind.Function,
|
|
932
|
-
type: "i32",
|
|
933
|
-
sourceFile: "math1.cnx",
|
|
934
|
-
sourceLine: 1,
|
|
935
|
-
sourceLanguage: ESourceLanguage.CNext,
|
|
936
|
-
isExported: true,
|
|
937
|
-
parent: "Math",
|
|
938
|
-
});
|
|
598
|
+
// ========================================================================
|
|
599
|
+
// Enum Bit Width Tracking
|
|
600
|
+
// ========================================================================
|
|
939
601
|
|
|
940
|
-
|
|
941
|
-
|
|
942
|
-
|
|
943
|
-
|
|
944
|
-
sourceFile: "math2.cnx",
|
|
945
|
-
sourceLine: 5,
|
|
946
|
-
sourceLanguage: ESourceLanguage.CNext,
|
|
947
|
-
isExported: true,
|
|
948
|
-
parent: "Math",
|
|
949
|
-
});
|
|
602
|
+
describe("enumBitWidth", () => {
|
|
603
|
+
it("should track enum bit widths", () => {
|
|
604
|
+
symbolTable.addEnumBitWidth("SmallEnum", 8);
|
|
605
|
+
symbolTable.addEnumBitWidth("LargeEnum", 32);
|
|
950
606
|
|
|
951
|
-
|
|
952
|
-
expect(
|
|
953
|
-
expect(
|
|
607
|
+
expect(symbolTable.getEnumBitWidth("SmallEnum")).toBe(8);
|
|
608
|
+
expect(symbolTable.getEnumBitWidth("LargeEnum")).toBe(32);
|
|
609
|
+
expect(symbolTable.getEnumBitWidth("UnknownEnum")).toBeUndefined();
|
|
954
610
|
});
|
|
611
|
+
});
|
|
612
|
+
|
|
613
|
+
// ========================================================================
|
|
614
|
+
// Clear
|
|
615
|
+
// ========================================================================
|
|
955
616
|
|
|
956
|
-
|
|
957
|
-
|
|
958
|
-
symbolTable.
|
|
959
|
-
|
|
960
|
-
|
|
961
|
-
sourceFile: "
|
|
617
|
+
describe("clear", () => {
|
|
618
|
+
it("should clear all symbols", () => {
|
|
619
|
+
symbolTable.addTSymbol({
|
|
620
|
+
kind: "variable",
|
|
621
|
+
name: "test",
|
|
622
|
+
sourceFile: "test.cnx",
|
|
962
623
|
sourceLine: 1,
|
|
963
|
-
sourceLanguage: ESourceLanguage.
|
|
624
|
+
sourceLanguage: ESourceLanguage.CNext,
|
|
964
625
|
isExported: true,
|
|
626
|
+
type: TTypeUtils.createPrimitive("u32"),
|
|
627
|
+
isArray: false,
|
|
628
|
+
isConst: false,
|
|
629
|
+
isAtomic: false,
|
|
630
|
+
scope: TestScopeUtils.createMockGlobalScope(),
|
|
965
631
|
});
|
|
966
632
|
|
|
967
|
-
symbolTable.
|
|
968
|
-
|
|
969
|
-
|
|
970
|
-
|
|
971
|
-
|
|
972
|
-
sourceLanguage: ESourceLanguage.C,
|
|
973
|
-
isExported: true,
|
|
974
|
-
});
|
|
633
|
+
symbolTable.addStructField("Point", "x", "int");
|
|
634
|
+
symbolTable.markNeedsStructKeyword("RawStruct");
|
|
635
|
+
symbolTable.addEnumBitWidth("SmallEnum", 8);
|
|
636
|
+
|
|
637
|
+
symbolTable.clear();
|
|
975
638
|
|
|
976
|
-
|
|
977
|
-
|
|
978
|
-
expect(
|
|
639
|
+
expect(symbolTable.getAllSymbols().length).toBe(0);
|
|
640
|
+
expect(symbolTable.getStructFieldType("Point", "x")).toBeUndefined();
|
|
641
|
+
expect(symbolTable.checkNeedsStructKeyword("RawStruct")).toBe(false);
|
|
642
|
+
expect(symbolTable.getEnumBitWidth("SmallEnum")).toBeUndefined();
|
|
979
643
|
});
|
|
980
644
|
});
|
|
981
645
|
});
|