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
|
@@ -6,11 +6,11 @@
|
|
|
6
6
|
|
|
7
7
|
import { describe, it, expect } from "vitest";
|
|
8
8
|
import CHeaderGenerator from "../CHeaderGenerator";
|
|
9
|
-
import
|
|
10
|
-
|
|
11
|
-
import ESourceLanguage from "../../../../utils/types/ESourceLanguage";
|
|
9
|
+
import IHeaderSymbol from "../types/IHeaderSymbol";
|
|
10
|
+
|
|
12
11
|
import IParameterSymbol from "../../../../utils/types/IParameterSymbol";
|
|
13
12
|
import SymbolTable from "../../../logic/symbols/SymbolTable";
|
|
13
|
+
import ESourceLanguage from "../../../../utils/types/ESourceLanguage";
|
|
14
14
|
|
|
15
15
|
// ============================================================================
|
|
16
16
|
// Test Helpers
|
|
@@ -21,40 +21,37 @@ function createFunctionSymbol(
|
|
|
21
21
|
returnType: string,
|
|
22
22
|
parameters: IParameterSymbol[] = [],
|
|
23
23
|
isExported = true,
|
|
24
|
-
):
|
|
24
|
+
): IHeaderSymbol {
|
|
25
25
|
return {
|
|
26
26
|
name,
|
|
27
|
-
kind:
|
|
27
|
+
kind: "function",
|
|
28
28
|
type: returnType,
|
|
29
29
|
parameters,
|
|
30
30
|
isExported,
|
|
31
31
|
sourceFile: "test.cnx",
|
|
32
32
|
sourceLine: 1,
|
|
33
|
-
sourceLanguage: ESourceLanguage.CNext,
|
|
34
33
|
};
|
|
35
34
|
}
|
|
36
35
|
|
|
37
|
-
function createStructSymbol(name: string, isExported = true):
|
|
36
|
+
function createStructSymbol(name: string, isExported = true): IHeaderSymbol {
|
|
38
37
|
return {
|
|
39
38
|
name,
|
|
40
|
-
kind:
|
|
39
|
+
kind: "struct",
|
|
41
40
|
type: name,
|
|
42
41
|
isExported,
|
|
43
42
|
sourceFile: "test.cnx",
|
|
44
43
|
sourceLine: 1,
|
|
45
|
-
sourceLanguage: ESourceLanguage.CNext,
|
|
46
44
|
};
|
|
47
45
|
}
|
|
48
46
|
|
|
49
|
-
function createEnumSymbol(name: string, isExported = true):
|
|
47
|
+
function createEnumSymbol(name: string, isExported = true): IHeaderSymbol {
|
|
50
48
|
return {
|
|
51
49
|
name,
|
|
52
|
-
kind:
|
|
50
|
+
kind: "enum",
|
|
53
51
|
type: name,
|
|
54
52
|
isExported,
|
|
55
53
|
sourceFile: "test.cnx",
|
|
56
54
|
sourceLine: 1,
|
|
57
|
-
sourceLanguage: ESourceLanguage.CNext,
|
|
58
55
|
};
|
|
59
56
|
}
|
|
60
57
|
|
|
@@ -62,15 +59,14 @@ function createVariableSymbol(
|
|
|
62
59
|
name: string,
|
|
63
60
|
type: string,
|
|
64
61
|
isExported = true,
|
|
65
|
-
):
|
|
62
|
+
): IHeaderSymbol {
|
|
66
63
|
return {
|
|
67
64
|
name,
|
|
68
|
-
kind:
|
|
65
|
+
kind: "variable",
|
|
69
66
|
type,
|
|
70
67
|
isExported,
|
|
71
68
|
sourceFile: "test.cnx",
|
|
72
69
|
sourceLine: 1,
|
|
73
|
-
sourceLanguage: ESourceLanguage.CNext,
|
|
74
70
|
};
|
|
75
71
|
}
|
|
76
72
|
|
|
@@ -97,7 +93,7 @@ describe("CHeaderGenerator", () => {
|
|
|
97
93
|
describe("generate", () => {
|
|
98
94
|
it("generates header with include guard", () => {
|
|
99
95
|
const generator = new CHeaderGenerator();
|
|
100
|
-
const symbols:
|
|
96
|
+
const symbols: IHeaderSymbol[] = [];
|
|
101
97
|
|
|
102
98
|
const result = generator.generate(symbols, "test.h");
|
|
103
99
|
|
|
@@ -108,7 +104,7 @@ describe("CHeaderGenerator", () => {
|
|
|
108
104
|
|
|
109
105
|
it("generates header with custom guard prefix", () => {
|
|
110
106
|
const generator = new CHeaderGenerator();
|
|
111
|
-
const symbols:
|
|
107
|
+
const symbols: IHeaderSymbol[] = [];
|
|
112
108
|
|
|
113
109
|
const result = generator.generate(symbols, "module.h", {
|
|
114
110
|
guardPrefix: "MY_PROJECT",
|
|
@@ -120,7 +116,7 @@ describe("CHeaderGenerator", () => {
|
|
|
120
116
|
|
|
121
117
|
it("generates extern C wrapper for C++ compatibility", () => {
|
|
122
118
|
const generator = new CHeaderGenerator();
|
|
123
|
-
const symbols:
|
|
119
|
+
const symbols: IHeaderSymbol[] = [];
|
|
124
120
|
|
|
125
121
|
const result = generator.generate(symbols, "test.h");
|
|
126
122
|
|
|
@@ -131,7 +127,9 @@ describe("CHeaderGenerator", () => {
|
|
|
131
127
|
|
|
132
128
|
it("generates function prototypes", () => {
|
|
133
129
|
const generator = new CHeaderGenerator();
|
|
134
|
-
const symbols:
|
|
130
|
+
const symbols: IHeaderSymbol[] = [
|
|
131
|
+
createFunctionSymbol("doSomething", "void"),
|
|
132
|
+
];
|
|
135
133
|
|
|
136
134
|
const result = generator.generate(symbols, "test.h");
|
|
137
135
|
|
|
@@ -140,7 +138,7 @@ describe("CHeaderGenerator", () => {
|
|
|
140
138
|
|
|
141
139
|
it("filters to exported symbols when exportedOnly is true", () => {
|
|
142
140
|
const generator = new CHeaderGenerator();
|
|
143
|
-
const symbols:
|
|
141
|
+
const symbols: IHeaderSymbol[] = [
|
|
144
142
|
createFunctionSymbol("publicFunc", "void", [], true),
|
|
145
143
|
createFunctionSymbol("privateFunc", "void", [], false),
|
|
146
144
|
];
|
|
@@ -155,7 +153,7 @@ describe("CHeaderGenerator", () => {
|
|
|
155
153
|
|
|
156
154
|
it("includes all symbols when exportedOnly is false", () => {
|
|
157
155
|
const generator = new CHeaderGenerator();
|
|
158
|
-
const symbols:
|
|
156
|
+
const symbols: IHeaderSymbol[] = [
|
|
159
157
|
createFunctionSymbol("publicFunc", "void", [], true),
|
|
160
158
|
createFunctionSymbol("privateFunc", "void", [], false),
|
|
161
159
|
];
|
|
@@ -172,7 +170,7 @@ describe("CHeaderGenerator", () => {
|
|
|
172
170
|
describe("function prototype generation", () => {
|
|
173
171
|
it("generates void function with no parameters", () => {
|
|
174
172
|
const generator = new CHeaderGenerator();
|
|
175
|
-
const symbols:
|
|
173
|
+
const symbols: IHeaderSymbol[] = [createFunctionSymbol("init", "void")];
|
|
176
174
|
|
|
177
175
|
const result = generator.generate(symbols, "test.h");
|
|
178
176
|
|
|
@@ -181,7 +179,9 @@ describe("CHeaderGenerator", () => {
|
|
|
181
179
|
|
|
182
180
|
it("generates function with return type", () => {
|
|
183
181
|
const generator = new CHeaderGenerator();
|
|
184
|
-
const symbols:
|
|
182
|
+
const symbols: IHeaderSymbol[] = [
|
|
183
|
+
createFunctionSymbol("getValue", "u32"),
|
|
184
|
+
];
|
|
185
185
|
|
|
186
186
|
const result = generator.generate(symbols, "test.h");
|
|
187
187
|
|
|
@@ -190,7 +190,7 @@ describe("CHeaderGenerator", () => {
|
|
|
190
190
|
|
|
191
191
|
it("forces main to return int", () => {
|
|
192
192
|
const generator = new CHeaderGenerator();
|
|
193
|
-
const symbols:
|
|
193
|
+
const symbols: IHeaderSymbol[] = [createFunctionSymbol("main", "u32")];
|
|
194
194
|
|
|
195
195
|
const result = generator.generate(symbols, "test.h");
|
|
196
196
|
|
|
@@ -199,7 +199,7 @@ describe("CHeaderGenerator", () => {
|
|
|
199
199
|
|
|
200
200
|
it("generates function with single parameter using pointer (C semantics)", () => {
|
|
201
201
|
const generator = new CHeaderGenerator();
|
|
202
|
-
const symbols:
|
|
202
|
+
const symbols: IHeaderSymbol[] = [
|
|
203
203
|
createFunctionSymbol("process", "void", [createParam("value", "u32")]),
|
|
204
204
|
];
|
|
205
205
|
|
|
@@ -210,7 +210,7 @@ describe("CHeaderGenerator", () => {
|
|
|
210
210
|
|
|
211
211
|
it("generates function with const parameter", () => {
|
|
212
212
|
const generator = new CHeaderGenerator();
|
|
213
|
-
const symbols:
|
|
213
|
+
const symbols: IHeaderSymbol[] = [
|
|
214
214
|
createFunctionSymbol("process", "void", [
|
|
215
215
|
createParam("value", "u32", { isConst: true }),
|
|
216
216
|
]),
|
|
@@ -223,7 +223,7 @@ describe("CHeaderGenerator", () => {
|
|
|
223
223
|
|
|
224
224
|
it("generates function with auto-const parameter", () => {
|
|
225
225
|
const generator = new CHeaderGenerator();
|
|
226
|
-
const symbols:
|
|
226
|
+
const symbols: IHeaderSymbol[] = [
|
|
227
227
|
createFunctionSymbol("process", "void", [
|
|
228
228
|
createParam("value", "u32", { isAutoConst: true }),
|
|
229
229
|
]),
|
|
@@ -236,7 +236,7 @@ describe("CHeaderGenerator", () => {
|
|
|
236
236
|
|
|
237
237
|
it("generates function with multiple parameters", () => {
|
|
238
238
|
const generator = new CHeaderGenerator();
|
|
239
|
-
const symbols:
|
|
239
|
+
const symbols: IHeaderSymbol[] = [
|
|
240
240
|
createFunctionSymbol("add", "u32", [
|
|
241
241
|
createParam("a", "u32"),
|
|
242
242
|
createParam("b", "u32"),
|
|
@@ -250,7 +250,7 @@ describe("CHeaderGenerator", () => {
|
|
|
250
250
|
|
|
251
251
|
it("uses pass-by-value for parameters in passByValueParams", () => {
|
|
252
252
|
const generator = new CHeaderGenerator();
|
|
253
|
-
const symbols:
|
|
253
|
+
const symbols: IHeaderSymbol[] = [
|
|
254
254
|
createFunctionSymbol("process", "void", [createParam("value", "u32")]),
|
|
255
255
|
];
|
|
256
256
|
const passByValueParams = new Map([["process", new Set(["value"])]]);
|
|
@@ -268,7 +268,7 @@ describe("CHeaderGenerator", () => {
|
|
|
268
268
|
|
|
269
269
|
it("uses pass-by-value for float types (f32)", () => {
|
|
270
270
|
const generator = new CHeaderGenerator();
|
|
271
|
-
const symbols:
|
|
271
|
+
const symbols: IHeaderSymbol[] = [
|
|
272
272
|
createFunctionSymbol("setFloat", "void", [createParam("value", "f32")]),
|
|
273
273
|
];
|
|
274
274
|
|
|
@@ -279,7 +279,7 @@ describe("CHeaderGenerator", () => {
|
|
|
279
279
|
|
|
280
280
|
it("uses pass-by-value for float types (f64)", () => {
|
|
281
281
|
const generator = new CHeaderGenerator();
|
|
282
|
-
const symbols:
|
|
282
|
+
const symbols: IHeaderSymbol[] = [
|
|
283
283
|
createFunctionSymbol("setDouble", "void", [
|
|
284
284
|
createParam("value", "f64"),
|
|
285
285
|
]),
|
|
@@ -292,7 +292,7 @@ describe("CHeaderGenerator", () => {
|
|
|
292
292
|
|
|
293
293
|
it("uses pass-by-value for enum types", () => {
|
|
294
294
|
const generator = new CHeaderGenerator();
|
|
295
|
-
const symbols:
|
|
295
|
+
const symbols: IHeaderSymbol[] = [
|
|
296
296
|
createFunctionSymbol("setState", "void", [
|
|
297
297
|
createParam("state", "State"),
|
|
298
298
|
]),
|
|
@@ -313,7 +313,7 @@ describe("CHeaderGenerator", () => {
|
|
|
313
313
|
|
|
314
314
|
it("uses pass-by-value for ISR type (function pointer)", () => {
|
|
315
315
|
const generator = new CHeaderGenerator();
|
|
316
|
-
const symbols:
|
|
316
|
+
const symbols: IHeaderSymbol[] = [
|
|
317
317
|
createFunctionSymbol("setHandler", "void", [
|
|
318
318
|
createParam("handler", "ISR"),
|
|
319
319
|
]),
|
|
@@ -326,7 +326,7 @@ describe("CHeaderGenerator", () => {
|
|
|
326
326
|
|
|
327
327
|
it("generates array parameter with dimensions", () => {
|
|
328
328
|
const generator = new CHeaderGenerator();
|
|
329
|
-
const symbols:
|
|
329
|
+
const symbols: IHeaderSymbol[] = [
|
|
330
330
|
createFunctionSymbol("processArray", "void", [
|
|
331
331
|
createParam("data", "u8", { isArray: true, arrayDimensions: ["10"] }),
|
|
332
332
|
]),
|
|
@@ -339,7 +339,7 @@ describe("CHeaderGenerator", () => {
|
|
|
339
339
|
|
|
340
340
|
it("generates const array parameter", () => {
|
|
341
341
|
const generator = new CHeaderGenerator();
|
|
342
|
-
const symbols:
|
|
342
|
+
const symbols: IHeaderSymbol[] = [
|
|
343
343
|
createFunctionSymbol("readArray", "void", [
|
|
344
344
|
createParam("data", "u8", {
|
|
345
345
|
isConst: true,
|
|
@@ -356,7 +356,7 @@ describe("CHeaderGenerator", () => {
|
|
|
356
356
|
|
|
357
357
|
it("generates auto-const array parameter", () => {
|
|
358
358
|
const generator = new CHeaderGenerator();
|
|
359
|
-
const symbols:
|
|
359
|
+
const symbols: IHeaderSymbol[] = [
|
|
360
360
|
createFunctionSymbol("readArray", "void", [
|
|
361
361
|
createParam("data", "u8", {
|
|
362
362
|
isAutoConst: true,
|
|
@@ -373,7 +373,7 @@ describe("CHeaderGenerator", () => {
|
|
|
373
373
|
|
|
374
374
|
it("generates string array parameter as char*", () => {
|
|
375
375
|
const generator = new CHeaderGenerator();
|
|
376
|
-
const symbols:
|
|
376
|
+
const symbols: IHeaderSymbol[] = [
|
|
377
377
|
createFunctionSymbol("processStrings", "void", [
|
|
378
378
|
createParam("strings", "string", {
|
|
379
379
|
isArray: true,
|
|
@@ -389,7 +389,7 @@ describe("CHeaderGenerator", () => {
|
|
|
389
389
|
|
|
390
390
|
it("generates multi-dimensional array parameter", () => {
|
|
391
391
|
const generator = new CHeaderGenerator();
|
|
392
|
-
const symbols:
|
|
392
|
+
const symbols: IHeaderSymbol[] = [
|
|
393
393
|
createFunctionSymbol("processMatrix", "void", [
|
|
394
394
|
createParam("matrix", "u32", {
|
|
395
395
|
isArray: true,
|
|
@@ -405,15 +405,14 @@ describe("CHeaderGenerator", () => {
|
|
|
405
405
|
|
|
406
406
|
it("generates function with no return type as void", () => {
|
|
407
407
|
const generator = new CHeaderGenerator();
|
|
408
|
-
const symbols:
|
|
408
|
+
const symbols: IHeaderSymbol[] = [
|
|
409
409
|
{
|
|
410
410
|
name: "noReturn",
|
|
411
|
-
kind:
|
|
411
|
+
kind: "function",
|
|
412
412
|
type: undefined,
|
|
413
413
|
isExported: true,
|
|
414
414
|
sourceFile: "test.cnx",
|
|
415
415
|
sourceLine: 1,
|
|
416
|
-
sourceLanguage: ESourceLanguage.CNext,
|
|
417
416
|
},
|
|
418
417
|
];
|
|
419
418
|
|
|
@@ -438,7 +437,7 @@ describe("CHeaderGenerator", () => {
|
|
|
438
437
|
];
|
|
439
438
|
|
|
440
439
|
for (const { cnx, c } of types) {
|
|
441
|
-
const symbols:
|
|
440
|
+
const symbols: IHeaderSymbol[] = [createFunctionSymbol("get", cnx)];
|
|
442
441
|
const result = generator.generate(symbols, "test.h");
|
|
443
442
|
expect(result).toContain(`${c} get(void);`);
|
|
444
443
|
}
|
|
@@ -446,7 +445,9 @@ describe("CHeaderGenerator", () => {
|
|
|
446
445
|
|
|
447
446
|
it("maps bool type", () => {
|
|
448
447
|
const generator = new CHeaderGenerator();
|
|
449
|
-
const symbols:
|
|
448
|
+
const symbols: IHeaderSymbol[] = [
|
|
449
|
+
createFunctionSymbol("isReady", "bool"),
|
|
450
|
+
];
|
|
450
451
|
|
|
451
452
|
const result = generator.generate(symbols, "test.h");
|
|
452
453
|
|
|
@@ -455,7 +456,7 @@ describe("CHeaderGenerator", () => {
|
|
|
455
456
|
|
|
456
457
|
it("maps float types", () => {
|
|
457
458
|
const generator = new CHeaderGenerator();
|
|
458
|
-
const symbols:
|
|
459
|
+
const symbols: IHeaderSymbol[] = [
|
|
459
460
|
createFunctionSymbol("getF32", "f32"),
|
|
460
461
|
createFunctionSymbol("getF64", "f64"),
|
|
461
462
|
];
|
|
@@ -470,7 +471,7 @@ describe("CHeaderGenerator", () => {
|
|
|
470
471
|
describe("C-compatible filtering", () => {
|
|
471
472
|
it("filters out C++ namespace types from forward declarations", () => {
|
|
472
473
|
const generator = new CHeaderGenerator();
|
|
473
|
-
const symbols:
|
|
474
|
+
const symbols: IHeaderSymbol[] = [
|
|
474
475
|
createFunctionSymbol("process", "void", [
|
|
475
476
|
createParam("result", "MockLib::Parse::ParseResult"),
|
|
476
477
|
]),
|
|
@@ -487,7 +488,7 @@ describe("CHeaderGenerator", () => {
|
|
|
487
488
|
|
|
488
489
|
it("filters out C++ template types from variables", () => {
|
|
489
490
|
const generator = new CHeaderGenerator();
|
|
490
|
-
const symbols:
|
|
491
|
+
const symbols: IHeaderSymbol[] = [
|
|
491
492
|
createVariableSymbol("myVector", "std::vector<int>"),
|
|
492
493
|
];
|
|
493
494
|
|
|
@@ -499,7 +500,7 @@ describe("CHeaderGenerator", () => {
|
|
|
499
500
|
|
|
500
501
|
it("generates forward declarations for C-compatible external types", () => {
|
|
501
502
|
const generator = new CHeaderGenerator();
|
|
502
|
-
const symbols:
|
|
503
|
+
const symbols: IHeaderSymbol[] = [
|
|
503
504
|
createFunctionSymbol("getConfig", "void", [
|
|
504
505
|
createParam("config", "ExternalConfig"),
|
|
505
506
|
]),
|
|
@@ -512,7 +513,7 @@ describe("CHeaderGenerator", () => {
|
|
|
512
513
|
|
|
513
514
|
it("does not forward-declare locally defined structs", () => {
|
|
514
515
|
const generator = new CHeaderGenerator();
|
|
515
|
-
const symbols:
|
|
516
|
+
const symbols: IHeaderSymbol[] = [
|
|
516
517
|
createStructSymbol("LocalStruct"),
|
|
517
518
|
createFunctionSymbol("getStruct", "void", [
|
|
518
519
|
createParam("s", "LocalStruct"),
|
|
@@ -527,7 +528,7 @@ describe("CHeaderGenerator", () => {
|
|
|
527
528
|
|
|
528
529
|
it("does not forward-declare cross-file enums", () => {
|
|
529
530
|
const generator = new CHeaderGenerator();
|
|
530
|
-
const symbols:
|
|
531
|
+
const symbols: IHeaderSymbol[] = [
|
|
531
532
|
createFunctionSymbol("setState", "void", [
|
|
532
533
|
createParam("state", "CrossFileState"),
|
|
533
534
|
]),
|
|
@@ -553,17 +554,16 @@ describe("CHeaderGenerator", () => {
|
|
|
553
554
|
const generator = new CHeaderGenerator();
|
|
554
555
|
const symbolTable = new SymbolTable();
|
|
555
556
|
// Register a C++ namespace symbol to make MyLib_MyClass appear as namespace type
|
|
556
|
-
symbolTable.
|
|
557
|
+
symbolTable.addCppSymbol({
|
|
557
558
|
name: "MyLib",
|
|
558
|
-
kind:
|
|
559
|
-
type: "namespace",
|
|
559
|
+
kind: "namespace",
|
|
560
560
|
isExported: true,
|
|
561
561
|
sourceFile: "MyLib.hpp",
|
|
562
562
|
sourceLine: 1,
|
|
563
563
|
sourceLanguage: ESourceLanguage.Cpp,
|
|
564
564
|
});
|
|
565
565
|
|
|
566
|
-
const symbols:
|
|
566
|
+
const symbols: IHeaderSymbol[] = [
|
|
567
567
|
createVariableSymbol("instance", "MyLib_MyClass"),
|
|
568
568
|
];
|
|
569
569
|
|
|
@@ -586,17 +586,16 @@ describe("CHeaderGenerator", () => {
|
|
|
586
586
|
const generator = new CHeaderGenerator();
|
|
587
587
|
const symbolTable = new SymbolTable();
|
|
588
588
|
// Register a C++ namespace symbol
|
|
589
|
-
symbolTable.
|
|
589
|
+
symbolTable.addCppSymbol({
|
|
590
590
|
name: "LibName",
|
|
591
|
-
kind:
|
|
592
|
-
type: "namespace",
|
|
591
|
+
kind: "namespace",
|
|
593
592
|
isExported: true,
|
|
594
593
|
sourceFile: "LibName.hpp",
|
|
595
594
|
sourceLine: 1,
|
|
596
595
|
sourceLanguage: ESourceLanguage.Cpp,
|
|
597
596
|
});
|
|
598
597
|
|
|
599
|
-
const symbols:
|
|
598
|
+
const symbols: IHeaderSymbol[] = [
|
|
600
599
|
createFunctionSymbol("process", "void", [
|
|
601
600
|
createParam("obj", "LibName_Object"),
|
|
602
601
|
]),
|
|
@@ -619,7 +618,7 @@ describe("CHeaderGenerator", () => {
|
|
|
619
618
|
|
|
620
619
|
it("includes external type headers when specified", () => {
|
|
621
620
|
const generator = new CHeaderGenerator();
|
|
622
|
-
const symbols:
|
|
621
|
+
const symbols: IHeaderSymbol[] = [
|
|
623
622
|
createFunctionSymbol("getConfig", "void", [
|
|
624
623
|
createParam("config", "ExternalConfig"),
|
|
625
624
|
]),
|
|
@@ -643,7 +642,7 @@ describe("CHeaderGenerator", () => {
|
|
|
643
642
|
describe("empty inputs", () => {
|
|
644
643
|
it("generates valid header with no functions", () => {
|
|
645
644
|
const generator = new CHeaderGenerator();
|
|
646
|
-
const symbols:
|
|
645
|
+
const symbols: IHeaderSymbol[] = [];
|
|
647
646
|
|
|
648
647
|
const result = generator.generate(symbols, "empty.h");
|
|
649
648
|
|
|
@@ -657,7 +656,7 @@ describe("CHeaderGenerator", () => {
|
|
|
657
656
|
describe("variable declarations", () => {
|
|
658
657
|
it("generates extern variable declarations", () => {
|
|
659
658
|
const generator = new CHeaderGenerator();
|
|
660
|
-
const symbols:
|
|
659
|
+
const symbols: IHeaderSymbol[] = [createVariableSymbol("counter", "u32")];
|
|
661
660
|
|
|
662
661
|
const result = generator.generate(symbols, "test.h");
|
|
663
662
|
|
|
@@ -668,7 +667,7 @@ describe("CHeaderGenerator", () => {
|
|
|
668
667
|
|
|
669
668
|
it("filters out variables with dot notation types", () => {
|
|
670
669
|
const generator = new CHeaderGenerator();
|
|
671
|
-
const symbols:
|
|
670
|
+
const symbols: IHeaderSymbol[] = [
|
|
672
671
|
createVariableSymbol("instance", "MyModule.Config"),
|
|
673
672
|
];
|
|
674
673
|
|
|
@@ -681,7 +680,7 @@ describe("CHeaderGenerator", () => {
|
|
|
681
680
|
describe("struct and enum sections", () => {
|
|
682
681
|
it("generates struct section with typeInput", () => {
|
|
683
682
|
const generator = new CHeaderGenerator();
|
|
684
|
-
const symbols:
|
|
683
|
+
const symbols: IHeaderSymbol[] = [createStructSymbol("Point")];
|
|
685
684
|
|
|
686
685
|
// Create field maps in the correct format
|
|
687
686
|
const pointFieldTypes = new Map<string, string>([
|
|
@@ -706,7 +705,7 @@ describe("CHeaderGenerator", () => {
|
|
|
706
705
|
|
|
707
706
|
it("generates forward declarations without typeInput", () => {
|
|
708
707
|
const generator = new CHeaderGenerator();
|
|
709
|
-
const symbols:
|
|
708
|
+
const symbols: IHeaderSymbol[] = [createStructSymbol("Point")];
|
|
710
709
|
|
|
711
710
|
const result = generator.generate(symbols, "test.h");
|
|
712
711
|
|
|
@@ -715,7 +714,7 @@ describe("CHeaderGenerator", () => {
|
|
|
715
714
|
|
|
716
715
|
it("generates enum section", () => {
|
|
717
716
|
const generator = new CHeaderGenerator();
|
|
718
|
-
const symbols:
|
|
717
|
+
const symbols: IHeaderSymbol[] = [createEnumSymbol("Status")];
|
|
719
718
|
|
|
720
719
|
const result = generator.generate(symbols, "test.h");
|
|
721
720
|
|