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,68 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* SymbolCollectorContext
|
|
3
|
-
* Shared context for C and C++ symbol collectors using composition.
|
|
4
|
-
*
|
|
5
|
-
* Extracted from CSymbolCollector and CppSymbolCollector to reduce duplication.
|
|
6
|
-
*/
|
|
7
|
-
|
|
8
|
-
import ICollectorContext from "./types/ICollectorContext";
|
|
9
|
-
import ISymbol from "../../../utils/types/ISymbol";
|
|
10
|
-
import SymbolTable from "./SymbolTable";
|
|
11
|
-
|
|
12
|
-
/**
|
|
13
|
-
* Factory and utilities for symbol collector context
|
|
14
|
-
*/
|
|
15
|
-
class SymbolCollectorContext {
|
|
16
|
-
/**
|
|
17
|
-
* Create a new collector context
|
|
18
|
-
*/
|
|
19
|
-
static create(
|
|
20
|
-
sourceFile: string,
|
|
21
|
-
symbolTable?: SymbolTable,
|
|
22
|
-
): ICollectorContext {
|
|
23
|
-
return {
|
|
24
|
-
sourceFile,
|
|
25
|
-
symbols: [],
|
|
26
|
-
warnings: [],
|
|
27
|
-
symbolTable: symbolTable ?? null,
|
|
28
|
-
};
|
|
29
|
-
}
|
|
30
|
-
|
|
31
|
-
/**
|
|
32
|
-
* Reset context for reuse (clears symbols and warnings)
|
|
33
|
-
*/
|
|
34
|
-
static reset(ctx: ICollectorContext): void {
|
|
35
|
-
ctx.symbols = [];
|
|
36
|
-
ctx.warnings = [];
|
|
37
|
-
}
|
|
38
|
-
|
|
39
|
-
/**
|
|
40
|
-
* Get collected symbols
|
|
41
|
-
*/
|
|
42
|
-
static getSymbols(ctx: ICollectorContext): ISymbol[] {
|
|
43
|
-
return ctx.symbols;
|
|
44
|
-
}
|
|
45
|
-
|
|
46
|
-
/**
|
|
47
|
-
* Get warnings generated during collection
|
|
48
|
-
*/
|
|
49
|
-
static getWarnings(ctx: ICollectorContext): string[] {
|
|
50
|
-
return ctx.warnings;
|
|
51
|
-
}
|
|
52
|
-
|
|
53
|
-
/**
|
|
54
|
-
* Add a symbol to the context
|
|
55
|
-
*/
|
|
56
|
-
static addSymbol(ctx: ICollectorContext, symbol: ISymbol): void {
|
|
57
|
-
ctx.symbols.push(symbol);
|
|
58
|
-
}
|
|
59
|
-
|
|
60
|
-
/**
|
|
61
|
-
* Add a warning to the context
|
|
62
|
-
*/
|
|
63
|
-
static addWarning(ctx: ICollectorContext, message: string): void {
|
|
64
|
-
ctx.warnings.push(message);
|
|
65
|
-
}
|
|
66
|
-
}
|
|
67
|
-
|
|
68
|
-
export default SymbolCollectorContext;
|
|
@@ -1,418 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* Unit tests for AutoConstUpdater.
|
|
3
|
-
* Issue #588: Extracted from Transpiler to logic layer.
|
|
4
|
-
*/
|
|
5
|
-
|
|
6
|
-
import { describe, expect, it } from "vitest";
|
|
7
|
-
import AutoConstUpdater from "../AutoConstUpdater";
|
|
8
|
-
import ISymbol from "../../../../utils/types/ISymbol";
|
|
9
|
-
import ESymbolKind from "../../../../utils/types/ESymbolKind";
|
|
10
|
-
import ESourceLanguage from "../../../../utils/types/ESourceLanguage";
|
|
11
|
-
|
|
12
|
-
describe("AutoConstUpdater", () => {
|
|
13
|
-
// Helper to create a function symbol with parameters
|
|
14
|
-
function createFunctionSymbol(
|
|
15
|
-
name: string,
|
|
16
|
-
parameters: NonNullable<ISymbol["parameters"]>,
|
|
17
|
-
): ISymbol {
|
|
18
|
-
return {
|
|
19
|
-
name,
|
|
20
|
-
kind: ESymbolKind.Function,
|
|
21
|
-
sourceFile: "/test/file.cnx",
|
|
22
|
-
sourceLine: 1,
|
|
23
|
-
sourceLanguage: ESourceLanguage.CNext,
|
|
24
|
-
isExported: true,
|
|
25
|
-
parameters,
|
|
26
|
-
};
|
|
27
|
-
}
|
|
28
|
-
|
|
29
|
-
describe("update", () => {
|
|
30
|
-
it("should mark unmodified struct parameters as auto-const", () => {
|
|
31
|
-
const symbols: ISymbol[] = [
|
|
32
|
-
createFunctionSymbol("processData", [
|
|
33
|
-
{ name: "data", type: "DataPacket", isConst: false, isArray: false },
|
|
34
|
-
]),
|
|
35
|
-
];
|
|
36
|
-
const unmodifiedParams = new Map<string, Set<string>>([
|
|
37
|
-
["processData", new Set(["data"])],
|
|
38
|
-
]);
|
|
39
|
-
const knownEnums = new Set<string>();
|
|
40
|
-
|
|
41
|
-
AutoConstUpdater.update(symbols, unmodifiedParams, knownEnums);
|
|
42
|
-
|
|
43
|
-
expect(symbols[0].parameters![0].isAutoConst).toBe(true);
|
|
44
|
-
});
|
|
45
|
-
|
|
46
|
-
it("should not mark modified parameters as auto-const", () => {
|
|
47
|
-
const symbols: ISymbol[] = [
|
|
48
|
-
createFunctionSymbol("modifyData", [
|
|
49
|
-
{ name: "data", type: "DataPacket", isConst: false, isArray: false },
|
|
50
|
-
]),
|
|
51
|
-
];
|
|
52
|
-
// Empty set means all parameters were modified
|
|
53
|
-
const unmodifiedParams = new Map<string, Set<string>>([
|
|
54
|
-
["modifyData", new Set<string>()],
|
|
55
|
-
]);
|
|
56
|
-
const knownEnums = new Set<string>();
|
|
57
|
-
|
|
58
|
-
AutoConstUpdater.update(symbols, unmodifiedParams, knownEnums);
|
|
59
|
-
|
|
60
|
-
expect(symbols[0].parameters![0].isAutoConst).toBeUndefined();
|
|
61
|
-
});
|
|
62
|
-
|
|
63
|
-
it("should not mark f32 parameters as auto-const (primitive type)", () => {
|
|
64
|
-
const symbols: ISymbol[] = [
|
|
65
|
-
createFunctionSymbol("processFloat", [
|
|
66
|
-
{ name: "value", type: "f32", isConst: false, isArray: false },
|
|
67
|
-
]),
|
|
68
|
-
];
|
|
69
|
-
const unmodifiedParams = new Map<string, Set<string>>([
|
|
70
|
-
["processFloat", new Set(["value"])],
|
|
71
|
-
]);
|
|
72
|
-
const knownEnums = new Set<string>();
|
|
73
|
-
|
|
74
|
-
AutoConstUpdater.update(symbols, unmodifiedParams, knownEnums);
|
|
75
|
-
|
|
76
|
-
expect(symbols[0].parameters![0].isAutoConst).toBeUndefined();
|
|
77
|
-
});
|
|
78
|
-
|
|
79
|
-
it("should not mark f64 parameters as auto-const (primitive type)", () => {
|
|
80
|
-
const symbols: ISymbol[] = [
|
|
81
|
-
createFunctionSymbol("processDouble", [
|
|
82
|
-
{ name: "value", type: "f64", isConst: false, isArray: false },
|
|
83
|
-
]),
|
|
84
|
-
];
|
|
85
|
-
const unmodifiedParams = new Map<string, Set<string>>([
|
|
86
|
-
["processDouble", new Set(["value"])],
|
|
87
|
-
]);
|
|
88
|
-
const knownEnums = new Set<string>();
|
|
89
|
-
|
|
90
|
-
AutoConstUpdater.update(symbols, unmodifiedParams, knownEnums);
|
|
91
|
-
|
|
92
|
-
expect(symbols[0].parameters![0].isAutoConst).toBeUndefined();
|
|
93
|
-
});
|
|
94
|
-
|
|
95
|
-
it("should not mark ISR parameters as auto-const", () => {
|
|
96
|
-
const symbols: ISymbol[] = [
|
|
97
|
-
createFunctionSymbol("handleInterrupt", [
|
|
98
|
-
{ name: "handler", type: "ISR", isConst: false, isArray: false },
|
|
99
|
-
]),
|
|
100
|
-
];
|
|
101
|
-
const unmodifiedParams = new Map<string, Set<string>>([
|
|
102
|
-
["handleInterrupt", new Set(["handler"])],
|
|
103
|
-
]);
|
|
104
|
-
const knownEnums = new Set<string>();
|
|
105
|
-
|
|
106
|
-
AutoConstUpdater.update(symbols, unmodifiedParams, knownEnums);
|
|
107
|
-
|
|
108
|
-
expect(symbols[0].parameters![0].isAutoConst).toBeUndefined();
|
|
109
|
-
});
|
|
110
|
-
|
|
111
|
-
it("should not mark enum parameters as auto-const", () => {
|
|
112
|
-
const symbols: ISymbol[] = [
|
|
113
|
-
createFunctionSymbol("setStatus", [
|
|
114
|
-
{ name: "status", type: "Status", isConst: false, isArray: false },
|
|
115
|
-
]),
|
|
116
|
-
];
|
|
117
|
-
const unmodifiedParams = new Map<string, Set<string>>([
|
|
118
|
-
["setStatus", new Set(["status"])],
|
|
119
|
-
]);
|
|
120
|
-
const knownEnums = new Set<string>(["Status"]);
|
|
121
|
-
|
|
122
|
-
AutoConstUpdater.update(symbols, unmodifiedParams, knownEnums);
|
|
123
|
-
|
|
124
|
-
expect(symbols[0].parameters![0].isAutoConst).toBeUndefined();
|
|
125
|
-
});
|
|
126
|
-
|
|
127
|
-
it("should not mark already-const parameters", () => {
|
|
128
|
-
const symbols: ISymbol[] = [
|
|
129
|
-
createFunctionSymbol("readData", [
|
|
130
|
-
{ name: "data", type: "DataPacket", isConst: true, isArray: false },
|
|
131
|
-
]),
|
|
132
|
-
];
|
|
133
|
-
const unmodifiedParams = new Map<string, Set<string>>([
|
|
134
|
-
["readData", new Set(["data"])],
|
|
135
|
-
]);
|
|
136
|
-
const knownEnums = new Set<string>();
|
|
137
|
-
|
|
138
|
-
AutoConstUpdater.update(symbols, unmodifiedParams, knownEnums);
|
|
139
|
-
|
|
140
|
-
// Should not have isAutoConst since it's already explicitly const
|
|
141
|
-
expect(symbols[0].parameters![0].isAutoConst).toBeUndefined();
|
|
142
|
-
});
|
|
143
|
-
|
|
144
|
-
it("should mark unmodified array parameters as auto-const", () => {
|
|
145
|
-
const symbols: ISymbol[] = [
|
|
146
|
-
createFunctionSymbol("readBuffer", [
|
|
147
|
-
{ name: "buffer", type: "u8", isConst: false, isArray: true },
|
|
148
|
-
]),
|
|
149
|
-
];
|
|
150
|
-
const unmodifiedParams = new Map<string, Set<string>>([
|
|
151
|
-
["readBuffer", new Set(["buffer"])],
|
|
152
|
-
]);
|
|
153
|
-
const knownEnums = new Set<string>();
|
|
154
|
-
|
|
155
|
-
AutoConstUpdater.update(symbols, unmodifiedParams, knownEnums);
|
|
156
|
-
|
|
157
|
-
expect(symbols[0].parameters![0].isAutoConst).toBe(true);
|
|
158
|
-
});
|
|
159
|
-
|
|
160
|
-
it("should not mark const array parameters as auto-const", () => {
|
|
161
|
-
const symbols: ISymbol[] = [
|
|
162
|
-
createFunctionSymbol("readBuffer", [
|
|
163
|
-
{ name: "buffer", type: "u8", isConst: true, isArray: true },
|
|
164
|
-
]),
|
|
165
|
-
];
|
|
166
|
-
const unmodifiedParams = new Map<string, Set<string>>([
|
|
167
|
-
["readBuffer", new Set(["buffer"])],
|
|
168
|
-
]);
|
|
169
|
-
const knownEnums = new Set<string>();
|
|
170
|
-
|
|
171
|
-
AutoConstUpdater.update(symbols, unmodifiedParams, knownEnums);
|
|
172
|
-
|
|
173
|
-
expect(symbols[0].parameters![0].isAutoConst).toBeUndefined();
|
|
174
|
-
});
|
|
175
|
-
|
|
176
|
-
it("should skip non-function symbols", () => {
|
|
177
|
-
const symbols: ISymbol[] = [
|
|
178
|
-
{
|
|
179
|
-
name: "counter",
|
|
180
|
-
kind: ESymbolKind.Variable,
|
|
181
|
-
sourceFile: "/test/file.cnx",
|
|
182
|
-
sourceLine: 1,
|
|
183
|
-
sourceLanguage: ESourceLanguage.CNext,
|
|
184
|
-
isExported: true,
|
|
185
|
-
},
|
|
186
|
-
];
|
|
187
|
-
const unmodifiedParams = new Map<string, Set<string>>();
|
|
188
|
-
const knownEnums = new Set<string>();
|
|
189
|
-
|
|
190
|
-
// Should not throw - symbol remains unchanged
|
|
191
|
-
AutoConstUpdater.update(symbols, unmodifiedParams, knownEnums);
|
|
192
|
-
expect(symbols[0].kind).toBe(ESymbolKind.Variable);
|
|
193
|
-
});
|
|
194
|
-
|
|
195
|
-
it("should skip functions without parameters", () => {
|
|
196
|
-
const symbols: ISymbol[] = [
|
|
197
|
-
{
|
|
198
|
-
name: "init",
|
|
199
|
-
kind: ESymbolKind.Function,
|
|
200
|
-
sourceFile: "/test/file.cnx",
|
|
201
|
-
sourceLine: 1,
|
|
202
|
-
sourceLanguage: ESourceLanguage.CNext,
|
|
203
|
-
isExported: true,
|
|
204
|
-
// No parameters
|
|
205
|
-
},
|
|
206
|
-
];
|
|
207
|
-
const unmodifiedParams = new Map<string, Set<string>>([
|
|
208
|
-
["init", new Set<string>()],
|
|
209
|
-
]);
|
|
210
|
-
const knownEnums = new Set<string>();
|
|
211
|
-
|
|
212
|
-
// Should not throw - function remains unchanged
|
|
213
|
-
AutoConstUpdater.update(symbols, unmodifiedParams, knownEnums);
|
|
214
|
-
expect(symbols[0].parameters).toBeUndefined();
|
|
215
|
-
});
|
|
216
|
-
|
|
217
|
-
it("should skip functions not in unmodifiedParams map", () => {
|
|
218
|
-
const symbols: ISymbol[] = [
|
|
219
|
-
createFunctionSymbol("unknownFunc", [
|
|
220
|
-
{ name: "data", type: "DataPacket", isConst: false, isArray: false },
|
|
221
|
-
]),
|
|
222
|
-
];
|
|
223
|
-
// Function not in map
|
|
224
|
-
const unmodifiedParams = new Map<string, Set<string>>();
|
|
225
|
-
const knownEnums = new Set<string>();
|
|
226
|
-
|
|
227
|
-
AutoConstUpdater.update(symbols, unmodifiedParams, knownEnums);
|
|
228
|
-
|
|
229
|
-
expect(symbols[0].parameters![0].isAutoConst).toBeUndefined();
|
|
230
|
-
});
|
|
231
|
-
|
|
232
|
-
it("should handle multiple parameters with mixed modifications", () => {
|
|
233
|
-
const symbols: ISymbol[] = [
|
|
234
|
-
createFunctionSymbol("processMultiple", [
|
|
235
|
-
{ name: "input", type: "DataPacket", isConst: false, isArray: false },
|
|
236
|
-
{ name: "output", type: "Result", isConst: false, isArray: false },
|
|
237
|
-
{ name: "count", type: "i32", isConst: false, isArray: false },
|
|
238
|
-
]),
|
|
239
|
-
];
|
|
240
|
-
// Only "input" is unmodified
|
|
241
|
-
const unmodifiedParams = new Map<string, Set<string>>([
|
|
242
|
-
["processMultiple", new Set(["input"])],
|
|
243
|
-
]);
|
|
244
|
-
const knownEnums = new Set<string>();
|
|
245
|
-
|
|
246
|
-
AutoConstUpdater.update(symbols, unmodifiedParams, knownEnums);
|
|
247
|
-
|
|
248
|
-
expect(symbols[0].parameters![0].isAutoConst).toBe(true); // input - unmodified struct
|
|
249
|
-
expect(symbols[0].parameters![1].isAutoConst).toBeUndefined(); // output - modified
|
|
250
|
-
expect(symbols[0].parameters![2].isAutoConst).toBeUndefined(); // count - modified
|
|
251
|
-
});
|
|
252
|
-
|
|
253
|
-
it("should handle multiple functions", () => {
|
|
254
|
-
const symbols: ISymbol[] = [
|
|
255
|
-
createFunctionSymbol("func1", [
|
|
256
|
-
{ name: "a", type: "StructA", isConst: false, isArray: false },
|
|
257
|
-
]),
|
|
258
|
-
createFunctionSymbol("func2", [
|
|
259
|
-
{ name: "b", type: "StructB", isConst: false, isArray: false },
|
|
260
|
-
]),
|
|
261
|
-
];
|
|
262
|
-
const unmodifiedParams = new Map<string, Set<string>>([
|
|
263
|
-
["func1", new Set(["a"])],
|
|
264
|
-
["func2", new Set<string>()], // b is modified
|
|
265
|
-
]);
|
|
266
|
-
const knownEnums = new Set<string>();
|
|
267
|
-
|
|
268
|
-
AutoConstUpdater.update(symbols, unmodifiedParams, knownEnums);
|
|
269
|
-
|
|
270
|
-
expect(symbols[0].parameters![0].isAutoConst).toBe(true); // func1.a
|
|
271
|
-
expect(symbols[1].parameters![0].isAutoConst).toBeUndefined(); // func2.b
|
|
272
|
-
});
|
|
273
|
-
});
|
|
274
|
-
|
|
275
|
-
describe("shouldMarkAutoConst", () => {
|
|
276
|
-
it("should return true for unmodified struct parameter", () => {
|
|
277
|
-
const param = {
|
|
278
|
-
name: "data",
|
|
279
|
-
type: "DataPacket",
|
|
280
|
-
isConst: false,
|
|
281
|
-
isArray: false,
|
|
282
|
-
};
|
|
283
|
-
const unmodified = new Set(["data"]);
|
|
284
|
-
const knownEnums = new Set<string>();
|
|
285
|
-
|
|
286
|
-
const result = AutoConstUpdater.shouldMarkAutoConst(
|
|
287
|
-
param,
|
|
288
|
-
unmodified,
|
|
289
|
-
knownEnums,
|
|
290
|
-
);
|
|
291
|
-
|
|
292
|
-
expect(result).toBe(true);
|
|
293
|
-
});
|
|
294
|
-
|
|
295
|
-
it("should return false for modified parameter", () => {
|
|
296
|
-
const param = {
|
|
297
|
-
name: "data",
|
|
298
|
-
type: "DataPacket",
|
|
299
|
-
isConst: false,
|
|
300
|
-
isArray: false,
|
|
301
|
-
};
|
|
302
|
-
const unmodified = new Set<string>(); // Empty = all modified
|
|
303
|
-
const knownEnums = new Set<string>();
|
|
304
|
-
|
|
305
|
-
const result = AutoConstUpdater.shouldMarkAutoConst(
|
|
306
|
-
param,
|
|
307
|
-
unmodified,
|
|
308
|
-
knownEnums,
|
|
309
|
-
);
|
|
310
|
-
|
|
311
|
-
expect(result).toBe(false);
|
|
312
|
-
});
|
|
313
|
-
|
|
314
|
-
it("should return false for already-const parameter", () => {
|
|
315
|
-
const param = {
|
|
316
|
-
name: "data",
|
|
317
|
-
type: "DataPacket",
|
|
318
|
-
isConst: true,
|
|
319
|
-
isArray: false,
|
|
320
|
-
};
|
|
321
|
-
const unmodified = new Set(["data"]);
|
|
322
|
-
const knownEnums = new Set<string>();
|
|
323
|
-
|
|
324
|
-
const result = AutoConstUpdater.shouldMarkAutoConst(
|
|
325
|
-
param,
|
|
326
|
-
unmodified,
|
|
327
|
-
knownEnums,
|
|
328
|
-
);
|
|
329
|
-
|
|
330
|
-
expect(result).toBe(false);
|
|
331
|
-
});
|
|
332
|
-
|
|
333
|
-
it("should return true for unmodified non-const array parameter", () => {
|
|
334
|
-
const param = {
|
|
335
|
-
name: "buffer",
|
|
336
|
-
type: "u8",
|
|
337
|
-
isConst: false,
|
|
338
|
-
isArray: true,
|
|
339
|
-
};
|
|
340
|
-
const unmodified = new Set(["buffer"]);
|
|
341
|
-
const knownEnums = new Set<string>();
|
|
342
|
-
|
|
343
|
-
const result = AutoConstUpdater.shouldMarkAutoConst(
|
|
344
|
-
param,
|
|
345
|
-
unmodified,
|
|
346
|
-
knownEnums,
|
|
347
|
-
);
|
|
348
|
-
|
|
349
|
-
expect(result).toBe(true);
|
|
350
|
-
});
|
|
351
|
-
|
|
352
|
-
it("should return false for f32 type", () => {
|
|
353
|
-
const param = { name: "x", type: "f32", isConst: false, isArray: false };
|
|
354
|
-
const unmodified = new Set(["x"]);
|
|
355
|
-
const knownEnums = new Set<string>();
|
|
356
|
-
|
|
357
|
-
const result = AutoConstUpdater.shouldMarkAutoConst(
|
|
358
|
-
param,
|
|
359
|
-
unmodified,
|
|
360
|
-
knownEnums,
|
|
361
|
-
);
|
|
362
|
-
|
|
363
|
-
expect(result).toBe(false);
|
|
364
|
-
});
|
|
365
|
-
|
|
366
|
-
it("should return false for f64 type", () => {
|
|
367
|
-
const param = { name: "x", type: "f64", isConst: false, isArray: false };
|
|
368
|
-
const unmodified = new Set(["x"]);
|
|
369
|
-
const knownEnums = new Set<string>();
|
|
370
|
-
|
|
371
|
-
const result = AutoConstUpdater.shouldMarkAutoConst(
|
|
372
|
-
param,
|
|
373
|
-
unmodified,
|
|
374
|
-
knownEnums,
|
|
375
|
-
);
|
|
376
|
-
|
|
377
|
-
expect(result).toBe(false);
|
|
378
|
-
});
|
|
379
|
-
|
|
380
|
-
it("should return false for ISR type", () => {
|
|
381
|
-
const param = {
|
|
382
|
-
name: "handler",
|
|
383
|
-
type: "ISR",
|
|
384
|
-
isConst: false,
|
|
385
|
-
isArray: false,
|
|
386
|
-
};
|
|
387
|
-
const unmodified = new Set(["handler"]);
|
|
388
|
-
const knownEnums = new Set<string>();
|
|
389
|
-
|
|
390
|
-
const result = AutoConstUpdater.shouldMarkAutoConst(
|
|
391
|
-
param,
|
|
392
|
-
unmodified,
|
|
393
|
-
knownEnums,
|
|
394
|
-
);
|
|
395
|
-
|
|
396
|
-
expect(result).toBe(false);
|
|
397
|
-
});
|
|
398
|
-
|
|
399
|
-
it("should return false for enum type", () => {
|
|
400
|
-
const param = {
|
|
401
|
-
name: "status",
|
|
402
|
-
type: "Status",
|
|
403
|
-
isConst: false,
|
|
404
|
-
isArray: false,
|
|
405
|
-
};
|
|
406
|
-
const unmodified = new Set(["status"]);
|
|
407
|
-
const knownEnums = new Set(["Status"]);
|
|
408
|
-
|
|
409
|
-
const result = AutoConstUpdater.shouldMarkAutoConst(
|
|
410
|
-
param,
|
|
411
|
-
unmodified,
|
|
412
|
-
knownEnums,
|
|
413
|
-
);
|
|
414
|
-
|
|
415
|
-
expect(result).toBe(false);
|
|
416
|
-
});
|
|
417
|
-
});
|
|
418
|
-
});
|