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
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
* Unit tests for CodeGenerator - the main transpiler component.
|
|
3
3
|
* Tests the IOrchestrator interface and internal methods.
|
|
4
4
|
*/
|
|
5
|
-
import { describe, it, expect } from "vitest";
|
|
5
|
+
import { describe, it, expect, beforeEach } from "vitest";
|
|
6
6
|
import CodeGenerator from "../CodeGenerator";
|
|
7
7
|
import CNextSourceParser from "../../../logic/parser/CNextSourceParser";
|
|
8
8
|
import * as Parser from "../../../logic/parser/grammar/CNextParser";
|
|
@@ -12,6 +12,7 @@ import TSymbolInfoAdapter from "../../../logic/symbols/cnext/adapters/TSymbolInf
|
|
|
12
12
|
import ICodeGenSymbols from "../../../types/ICodeGenSymbols";
|
|
13
13
|
import TParameterInfo from "../types/TParameterInfo";
|
|
14
14
|
import CodeGenState from "../../../state/CodeGenState";
|
|
15
|
+
import SymbolRegistry from "../../../state/SymbolRegistry";
|
|
15
16
|
|
|
16
17
|
/**
|
|
17
18
|
* Helper to parse C-Next source and return tree + generator ready for testing.
|
|
@@ -51,6 +52,11 @@ function createMinimalGenerator(source: string): CodeGenerator {
|
|
|
51
52
|
}
|
|
52
53
|
|
|
53
54
|
describe("CodeGenerator", () => {
|
|
55
|
+
// Reset SymbolRegistry before each test to prevent state pollution
|
|
56
|
+
beforeEach(() => {
|
|
57
|
+
SymbolRegistry.reset();
|
|
58
|
+
});
|
|
59
|
+
|
|
54
60
|
describe("generate()", () => {
|
|
55
61
|
it("should generate basic C code from empty program", () => {
|
|
56
62
|
const source = "";
|
|
@@ -13,6 +13,7 @@ import CodeGenState from "../../../state/CodeGenState";
|
|
|
13
13
|
import SubscriptClassifier from "../subscript/SubscriptClassifier";
|
|
14
14
|
import TTypeInfo from "../types/TTypeInfo";
|
|
15
15
|
import TypeCheckUtils from "../../../../utils/TypeCheckUtils";
|
|
16
|
+
import QualifiedNameGenerator from "../utils/QualifiedNameGenerator";
|
|
16
17
|
|
|
17
18
|
/**
|
|
18
19
|
* Classifies assignment statements by analyzing their structure.
|
|
@@ -227,7 +228,7 @@ class AssignmentClassifier {
|
|
|
227
228
|
return null;
|
|
228
229
|
}
|
|
229
230
|
|
|
230
|
-
const fullRegName =
|
|
231
|
+
const fullRegName = QualifiedNameGenerator.forMember(scopeName, ids[1]);
|
|
231
232
|
if (!CodeGenState.symbols!.knownRegisters.has(fullRegName)) {
|
|
232
233
|
return null;
|
|
233
234
|
}
|
|
@@ -6,6 +6,7 @@
|
|
|
6
6
|
*/
|
|
7
7
|
|
|
8
8
|
import IRegisterNameResult from "./IRegisterNameResult";
|
|
9
|
+
import QualifiedNameGenerator from "../../utils/QualifiedNameGenerator";
|
|
9
10
|
|
|
10
11
|
/**
|
|
11
12
|
* Validate that 'this' is being used within a scope context.
|
|
@@ -79,7 +80,12 @@ function buildScopedRegisterName(
|
|
|
79
80
|
scopeName: string,
|
|
80
81
|
parts: readonly string[],
|
|
81
82
|
): string {
|
|
82
|
-
|
|
83
|
+
// Build the name progressively: Scope_Part1_Part2_...
|
|
84
|
+
let result = scopeName;
|
|
85
|
+
for (const part of parts) {
|
|
86
|
+
result = QualifiedNameGenerator.forMember(result, part);
|
|
87
|
+
}
|
|
88
|
+
return result;
|
|
83
89
|
}
|
|
84
90
|
|
|
85
91
|
/**
|
|
@@ -16,6 +16,7 @@ import TAssignmentHandler from "./TAssignmentHandler";
|
|
|
16
16
|
import CodeGenState from "../../../../state/CodeGenState";
|
|
17
17
|
import TypeValidator from "../../TypeValidator";
|
|
18
18
|
import type ICodeGenApi from "../../types/ICodeGenApi";
|
|
19
|
+
import QualifiedNameGenerator from "../../utils/QualifiedNameGenerator";
|
|
19
20
|
|
|
20
21
|
/** Get typed generator reference */
|
|
21
22
|
function gen(): ICodeGenApi {
|
|
@@ -211,8 +212,11 @@ function handleScopedRegisterMemberBitmapField(
|
|
|
211
212
|
gen().validateCrossScopeVisibility(scopeName, regName);
|
|
212
213
|
}
|
|
213
214
|
|
|
214
|
-
const fullRegName =
|
|
215
|
-
const fullRegMember =
|
|
215
|
+
const fullRegName = QualifiedNameGenerator.forMember(scopeName, regName);
|
|
216
|
+
const fullRegMember = QualifiedNameGenerator.forMember(
|
|
217
|
+
fullRegName,
|
|
218
|
+
memberName,
|
|
219
|
+
);
|
|
216
220
|
const bitmapType =
|
|
217
221
|
CodeGenState.symbols!.registerMemberTypes.get(fullRegMember)!;
|
|
218
222
|
|
|
@@ -16,6 +16,7 @@ import RegisterUtils from "./RegisterUtils";
|
|
|
16
16
|
import AssignmentHandlerUtils from "./AssignmentHandlerUtils";
|
|
17
17
|
import CodeGenState from "../../../../state/CodeGenState";
|
|
18
18
|
import type ICodeGenApi from "../../types/ICodeGenApi";
|
|
19
|
+
import QualifiedNameGenerator from "../../utils/QualifiedNameGenerator";
|
|
19
20
|
|
|
20
21
|
/** Get typed generator reference */
|
|
21
22
|
function gen(): ICodeGenApi {
|
|
@@ -166,7 +167,7 @@ function handleScopedRegisterBitRange(ctx: IAssignmentContext): string {
|
|
|
166
167
|
scopeName,
|
|
167
168
|
parts,
|
|
168
169
|
);
|
|
169
|
-
const scopedRegName =
|
|
170
|
+
const scopedRegName = QualifiedNameGenerator.forMember(scopeName, parts[0]);
|
|
170
171
|
|
|
171
172
|
const accessMod = CodeGenState.symbols!.registerMemberAccess.get(regName);
|
|
172
173
|
const isWriteOnly = RegisterUtils.isWriteOnlyRegister(accessMod);
|
|
@@ -23,6 +23,7 @@ import TGeneratorFn from "../TGeneratorFn";
|
|
|
23
23
|
import generateScopedRegister from "./ScopedRegisterGenerator";
|
|
24
24
|
import BitmapCommentUtils from "./BitmapCommentUtils";
|
|
25
25
|
import ArrayDimensionUtils from "./ArrayDimensionUtils";
|
|
26
|
+
import QualifiedNameGenerator from "../../utils/QualifiedNameGenerator";
|
|
26
27
|
|
|
27
28
|
/**
|
|
28
29
|
* Generate initializer expression for a variable declaration.
|
|
@@ -48,7 +49,7 @@ function getScopedName(
|
|
|
48
49
|
scopeName: string,
|
|
49
50
|
): { name: string; fullName: string } {
|
|
50
51
|
const name = node.IDENTIFIER().getText();
|
|
51
|
-
return { name, fullName:
|
|
52
|
+
return { name, fullName: QualifiedNameGenerator.forMember(scopeName, name) };
|
|
52
53
|
}
|
|
53
54
|
|
|
54
55
|
/**
|
|
@@ -66,7 +67,7 @@ function resolveConstructorArgs(
|
|
|
66
67
|
for (const argNode of argIdentifiers) {
|
|
67
68
|
const argName = argNode.getText();
|
|
68
69
|
// Arguments must be resolved with scope prefix
|
|
69
|
-
const scopedArgName =
|
|
70
|
+
const scopedArgName = QualifiedNameGenerator.forMember(scopeName, argName);
|
|
70
71
|
|
|
71
72
|
// Check if it's const using orchestrator
|
|
72
73
|
if (!orchestrator.isConstValue(scopedArgName)) {
|
|
@@ -146,7 +147,7 @@ function generateConstructorVariable(
|
|
|
146
147
|
): string {
|
|
147
148
|
// ADR-016: All scope variables are emitted at file scope
|
|
148
149
|
const type = orchestrator.generateType(varDecl.type());
|
|
149
|
-
const fullName =
|
|
150
|
+
const fullName = QualifiedNameGenerator.forMember(scopeName, varName);
|
|
150
151
|
const prefix = isPrivate ? "static " : "";
|
|
151
152
|
|
|
152
153
|
// Validate and resolve constructor arguments
|
|
@@ -180,7 +181,7 @@ function generateRegularVariable(
|
|
|
180
181
|
|
|
181
182
|
// ADR-016: All scope variables are emitted at file scope (static-like persistence)
|
|
182
183
|
const type = orchestrator.generateType(varDecl.type());
|
|
183
|
-
const fullName =
|
|
184
|
+
const fullName = QualifiedNameGenerator.forMember(scopeName, varName);
|
|
184
185
|
// Issue #282: Add 'const' modifier for const variables
|
|
185
186
|
const constPrefix = isConst ? "const " : "";
|
|
186
187
|
const prefix = isPrivate ? "static " : "";
|
|
@@ -216,7 +217,11 @@ function generateScopeFunction(
|
|
|
216
217
|
): string[] {
|
|
217
218
|
const returnType = orchestrator.generateType(funcDecl.type());
|
|
218
219
|
const funcName = funcDecl.IDENTIFIER().getText();
|
|
219
|
-
|
|
220
|
+
// Use QualifiedNameGenerator for consistent C-style name generation
|
|
221
|
+
const fullName = QualifiedNameGenerator.forFunctionStrings(
|
|
222
|
+
scopeName,
|
|
223
|
+
funcName,
|
|
224
|
+
);
|
|
220
225
|
const prefix = isPrivate ? "static " : "";
|
|
221
226
|
|
|
222
227
|
// Issue #269: Set current function name for pass-by-value lookup
|
|
@@ -274,7 +279,11 @@ function generateEnumMembersFromAST(
|
|
|
274
279
|
for (let i = 0; i < members.length; i++) {
|
|
275
280
|
const member = members[i];
|
|
276
281
|
const memberName = member.IDENTIFIER().getText();
|
|
277
|
-
|
|
282
|
+
// Enum members use the full enum name as their "scope"
|
|
283
|
+
const fullMemberName = QualifiedNameGenerator.forMember(
|
|
284
|
+
fullName,
|
|
285
|
+
memberName,
|
|
286
|
+
);
|
|
278
287
|
|
|
279
288
|
if (member.expression()) {
|
|
280
289
|
const constValue = orchestrator.tryEvaluateConstant(member.expression()!);
|
|
@@ -421,7 +430,11 @@ function generateScopedEnumInline(
|
|
|
421
430
|
const memberEntries = Array.from(symbolMembers.entries());
|
|
422
431
|
for (let i = 0; i < memberEntries.length; i++) {
|
|
423
432
|
const [memberName, value] = memberEntries[i];
|
|
424
|
-
|
|
433
|
+
// Enum members use the full enum name as their "scope"
|
|
434
|
+
const fullMemberName = QualifiedNameGenerator.forMember(
|
|
435
|
+
fullName,
|
|
436
|
+
memberName,
|
|
437
|
+
);
|
|
425
438
|
const comma = i < memberEntries.length - 1 ? "," : "";
|
|
426
439
|
lines.push(` ${fullMemberName} = ${value}${comma}`);
|
|
427
440
|
}
|
|
@@ -500,7 +513,7 @@ function generateScopedBitmapInline(
|
|
|
500
513
|
input: IGeneratorInput,
|
|
501
514
|
): string {
|
|
502
515
|
const name = node.IDENTIFIER().getText();
|
|
503
|
-
const fullName =
|
|
516
|
+
const fullName = QualifiedNameGenerator.forMember(scopeName, name);
|
|
504
517
|
const backingType = _getBitmapBackingType(fullName, node, input);
|
|
505
518
|
|
|
506
519
|
const lines: string[] = [];
|
package/src/transpiler/output/codegen/generators/declarationGenerators/ScopedRegisterGenerator.ts
CHANGED
|
@@ -14,6 +14,7 @@ import IGeneratorState from "../IGeneratorState";
|
|
|
14
14
|
import IGeneratorOutput from "../IGeneratorOutput";
|
|
15
15
|
import IOrchestrator from "../IOrchestrator";
|
|
16
16
|
import generateRegisterMacros from "./RegisterMacroGenerator";
|
|
17
|
+
import QualifiedNameGenerator from "../../utils/QualifiedNameGenerator";
|
|
17
18
|
|
|
18
19
|
/**
|
|
19
20
|
* Generate register macros with scope prefix.
|
|
@@ -26,12 +27,12 @@ const generateScopedRegister = (
|
|
|
26
27
|
orchestrator: IOrchestrator,
|
|
27
28
|
): IGeneratorOutput => {
|
|
28
29
|
const name = node.IDENTIFIER().getText();
|
|
29
|
-
const fullName =
|
|
30
|
+
const fullName = QualifiedNameGenerator.forMember(scopeName, name); // Teensy4_GPIO7
|
|
30
31
|
const baseAddress = orchestrator.generateExpression(node.expression());
|
|
31
32
|
|
|
32
33
|
// Type resolver for scoped bitmaps (e.g., GPIO7Pins -> Teensy4_GPIO7Pins)
|
|
33
34
|
const resolveType = (regType: string): string | undefined => {
|
|
34
|
-
const scopedTypeName =
|
|
35
|
+
const scopedTypeName = QualifiedNameGenerator.forMember(scopeName, regType);
|
|
35
36
|
return input.symbols?.knownBitmaps.has(scopedTypeName)
|
|
36
37
|
? scopedTypeName
|
|
37
38
|
: undefined;
|
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
import TYPE_MAP from "../../types/TYPE_MAP";
|
|
6
6
|
import IFunctionSignature from "../../types/IFunctionSignature";
|
|
7
7
|
import SymbolTable from "../../../../logic/symbols/SymbolTable";
|
|
8
|
-
import
|
|
8
|
+
import TypeResolver from "../../../../../utils/TypeResolver";
|
|
9
9
|
|
|
10
10
|
/**
|
|
11
11
|
* Issue #315: Small primitive types that are always passed by value.
|
|
@@ -88,12 +88,18 @@ class CallExprUtils {
|
|
|
88
88
|
if (symbolTable) {
|
|
89
89
|
const symbols = symbolTable.getOverloads(funcName);
|
|
90
90
|
for (const sym of symbols) {
|
|
91
|
-
if (sym.kind ===
|
|
91
|
+
if (sym.kind === "function" && sym.parameters?.[paramIndex]) {
|
|
92
92
|
const p = sym.parameters[paramIndex];
|
|
93
|
+
// Convert TType to string for C-Next symbols, use string directly for C/C++
|
|
94
|
+
const paramType = p.type;
|
|
95
|
+
const baseType =
|
|
96
|
+
typeof paramType === "string"
|
|
97
|
+
? paramType
|
|
98
|
+
: TypeResolver.getTypeName(paramType);
|
|
93
99
|
return {
|
|
94
100
|
param: {
|
|
95
101
|
name: p.name,
|
|
96
|
-
baseType
|
|
102
|
+
baseType,
|
|
97
103
|
isConst: p.isConst,
|
|
98
104
|
isArray: p.isArray,
|
|
99
105
|
},
|
package/src/transpiler/output/codegen/generators/expressions/__tests__/CallExprGenerator.test.ts
CHANGED
|
@@ -4,7 +4,6 @@ import IGeneratorInput from "../../IGeneratorInput";
|
|
|
4
4
|
import IGeneratorState from "../../IGeneratorState";
|
|
5
5
|
import IOrchestrator from "../../IOrchestrator";
|
|
6
6
|
import * as Parser from "../../../../../logic/parser/grammar/CNextParser";
|
|
7
|
-
import ESymbolKind from "../../../../../../utils/types/ESymbolKind";
|
|
8
7
|
import CodeGenState from "../../../../../state/CodeGenState";
|
|
9
8
|
import TTypeInfo from "../../../types/TTypeInfo";
|
|
10
9
|
|
|
@@ -777,7 +776,7 @@ describe("CallExprGenerator", () => {
|
|
|
777
776
|
const symbolTable = {
|
|
778
777
|
getOverloads: vi.fn(() => [
|
|
779
778
|
{
|
|
780
|
-
kind:
|
|
779
|
+
kind: "function",
|
|
781
780
|
parameters: [
|
|
782
781
|
{ name: "val", type: "u32", isConst: false, isArray: false },
|
|
783
782
|
],
|
|
@@ -814,7 +813,7 @@ describe("CallExprGenerator", () => {
|
|
|
814
813
|
const symbolTable = {
|
|
815
814
|
getOverloads: vi.fn(() => [
|
|
816
815
|
{
|
|
817
|
-
kind:
|
|
816
|
+
kind: "function",
|
|
818
817
|
parameters: [
|
|
819
818
|
{ name: "f", type: "u8", isConst: false, isArray: false },
|
|
820
819
|
],
|
|
@@ -848,7 +847,7 @@ describe("CallExprGenerator", () => {
|
|
|
848
847
|
const argCtx = createMockArgListContext(argExprs);
|
|
849
848
|
const symbolTable = {
|
|
850
849
|
getOverloads: vi.fn(() => [
|
|
851
|
-
{ kind:
|
|
850
|
+
{ kind: "variable", parameters: undefined },
|
|
852
851
|
]),
|
|
853
852
|
};
|
|
854
853
|
const input = createMockInput({
|
package/src/transpiler/output/codegen/generators/expressions/__tests__/CallExprUtils.test.ts
CHANGED
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { describe, it, expect, vi } from "vitest";
|
|
2
2
|
import CallExprUtils from "../CallExprUtils";
|
|
3
|
-
import ESymbolKind from "../../../../../../utils/types/ESymbolKind";
|
|
4
3
|
|
|
5
4
|
describe("CallExprUtils", () => {
|
|
6
5
|
describe("mapTypeToCType", () => {
|
|
@@ -166,7 +165,7 @@ describe("CallExprUtils", () => {
|
|
|
166
165
|
const symbolTable = {
|
|
167
166
|
getOverloads: vi.fn(() => [
|
|
168
167
|
{
|
|
169
|
-
kind:
|
|
168
|
+
kind: "function",
|
|
170
169
|
parameters: [
|
|
171
170
|
{ name: "val", type: "i32", isConst: true, isArray: false },
|
|
172
171
|
],
|
|
@@ -193,10 +192,7 @@ describe("CallExprUtils", () => {
|
|
|
193
192
|
|
|
194
193
|
it("skips non-function symbols in SymbolTable", () => {
|
|
195
194
|
const symbolTable = {
|
|
196
|
-
getOverloads: vi.fn(() => [
|
|
197
|
-
{ kind: ESymbolKind.Variable },
|
|
198
|
-
{ kind: ESymbolKind.Struct },
|
|
199
|
-
]),
|
|
195
|
+
getOverloads: vi.fn(() => [{ kind: "variable" }, { kind: "struct" }]),
|
|
200
196
|
};
|
|
201
197
|
|
|
202
198
|
const result = CallExprUtils.resolveTargetParam(
|
|
@@ -214,7 +210,7 @@ describe("CallExprUtils", () => {
|
|
|
214
210
|
const symbolTable = {
|
|
215
211
|
getOverloads: vi.fn(() => [
|
|
216
212
|
{
|
|
217
|
-
kind:
|
|
213
|
+
kind: "function",
|
|
218
214
|
parameters: [
|
|
219
215
|
{ name: "a", type: "u8", isConst: false, isArray: false },
|
|
220
216
|
],
|
|
@@ -243,7 +239,7 @@ describe("CallExprUtils", () => {
|
|
|
243
239
|
const symbolTable = {
|
|
244
240
|
getOverloads: vi.fn(() => [
|
|
245
241
|
{
|
|
246
|
-
kind:
|
|
242
|
+
kind: "function",
|
|
247
243
|
parameters: [
|
|
248
244
|
{ name: "remote", type: "i64", isConst: true, isArray: false },
|
|
249
245
|
],
|
|
@@ -0,0 +1,236 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* ArgumentGenerator - Generates function arguments with proper ADR-006 semantics
|
|
3
|
+
*
|
|
4
|
+
* Issue #794: Extracted from CodeGenerator to reduce file size.
|
|
5
|
+
* Uses CodeGenState for state access and callbacks for CodeGenerator methods.
|
|
6
|
+
*
|
|
7
|
+
* Handles argument generation patterns:
|
|
8
|
+
* - Local variables get & (address-of) in C mode
|
|
9
|
+
* - Member access (cursor.x) gets & (address-of)
|
|
10
|
+
* - Array access (arr[i]) gets & (address-of)
|
|
11
|
+
* - Parameters are passed as-is (already pointers)
|
|
12
|
+
* - Arrays are passed as-is (naturally decay to pointers)
|
|
13
|
+
* - Literals use compound literals for pointer params: &(type){value}
|
|
14
|
+
* - Complex expressions are passed as-is
|
|
15
|
+
*/
|
|
16
|
+
|
|
17
|
+
import * as Parser from "../../../logic/parser/grammar/CNextParser.js";
|
|
18
|
+
import CodeGenState from "../../../state/CodeGenState.js";
|
|
19
|
+
import CppModeHelper from "./CppModeHelper.js";
|
|
20
|
+
import TYPE_MAP from "../types/TYPE_MAP.js";
|
|
21
|
+
import IArgumentGeneratorCallbacks from "./types/IArgumentGeneratorCallbacks.js";
|
|
22
|
+
|
|
23
|
+
/**
|
|
24
|
+
* Generates function arguments with proper pass-by-reference semantics.
|
|
25
|
+
*/
|
|
26
|
+
class ArgumentGenerator {
|
|
27
|
+
/**
|
|
28
|
+
* Handle simple identifier argument (parameter, local array, scope member, or variable).
|
|
29
|
+
* This is a pure function that only reads from CodeGenState.
|
|
30
|
+
*/
|
|
31
|
+
static handleIdentifierArg(id: string): string {
|
|
32
|
+
// Parameters are already pointers
|
|
33
|
+
if (CodeGenState.currentParameters.get(id)) {
|
|
34
|
+
return id;
|
|
35
|
+
}
|
|
36
|
+
|
|
37
|
+
// Local arrays decay to pointers
|
|
38
|
+
if (CodeGenState.localArrays.has(id)) {
|
|
39
|
+
return id;
|
|
40
|
+
}
|
|
41
|
+
|
|
42
|
+
// Global arrays also decay to pointers (check typeRegistry)
|
|
43
|
+
// But NOT strings - strings need & (they're char arrays but passed by reference)
|
|
44
|
+
const typeInfo = CodeGenState.getVariableTypeInfo(id);
|
|
45
|
+
if (typeInfo?.isArray && !typeInfo.isString) {
|
|
46
|
+
return id;
|
|
47
|
+
}
|
|
48
|
+
|
|
49
|
+
// Scope member - may need prefixing
|
|
50
|
+
if (CodeGenState.currentScope) {
|
|
51
|
+
const members = CodeGenState.getScopeMembers(CodeGenState.currentScope);
|
|
52
|
+
if (members?.has(id)) {
|
|
53
|
+
const scopedName = `${CodeGenState.currentScope}_${id}`;
|
|
54
|
+
return CppModeHelper.maybeAddressOf(scopedName);
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
// Local variable - add & (except in C++ mode)
|
|
59
|
+
return CppModeHelper.maybeAddressOf(id);
|
|
60
|
+
}
|
|
61
|
+
|
|
62
|
+
/**
|
|
63
|
+
* Handle rvalue argument (literals or complex expressions).
|
|
64
|
+
*/
|
|
65
|
+
static handleRvalueArg(
|
|
66
|
+
ctx: Parser.ExpressionContext,
|
|
67
|
+
targetParamBaseType: string | undefined,
|
|
68
|
+
callbacks: IArgumentGeneratorCallbacks,
|
|
69
|
+
): string {
|
|
70
|
+
if (!targetParamBaseType) {
|
|
71
|
+
return callbacks.generateExpression(ctx);
|
|
72
|
+
}
|
|
73
|
+
|
|
74
|
+
const cType = TYPE_MAP[targetParamBaseType];
|
|
75
|
+
if (!cType || cType === "void") {
|
|
76
|
+
return callbacks.generateExpression(ctx);
|
|
77
|
+
}
|
|
78
|
+
|
|
79
|
+
const value = callbacks.generateExpression(ctx);
|
|
80
|
+
|
|
81
|
+
// C++ mode: rvalues can bind to const T&
|
|
82
|
+
if (CodeGenState.cppMode) {
|
|
83
|
+
return value;
|
|
84
|
+
}
|
|
85
|
+
|
|
86
|
+
// C mode: Use compound literal syntax
|
|
87
|
+
return `&(${cType}){${value}}`;
|
|
88
|
+
}
|
|
89
|
+
|
|
90
|
+
/**
|
|
91
|
+
* Create temp variable for C++ member conversion.
|
|
92
|
+
*/
|
|
93
|
+
static createCppMemberConversionTemp(
|
|
94
|
+
ctx: Parser.ExpressionContext,
|
|
95
|
+
targetParamBaseType: string,
|
|
96
|
+
callbacks: IArgumentGeneratorCallbacks,
|
|
97
|
+
): string {
|
|
98
|
+
const cType = TYPE_MAP[targetParamBaseType] || "uint8_t";
|
|
99
|
+
const value = callbacks.generateExpression(ctx);
|
|
100
|
+
const tempName = `_cnx_tmp_${CodeGenState.tempVarCounter++}`;
|
|
101
|
+
const castExpr = CppModeHelper.cast(cType, value);
|
|
102
|
+
CodeGenState.pendingTempDeclarations.push(
|
|
103
|
+
`${cType} ${tempName} = ${castExpr};`,
|
|
104
|
+
);
|
|
105
|
+
return CppModeHelper.maybeAddressOf(tempName);
|
|
106
|
+
}
|
|
107
|
+
|
|
108
|
+
/**
|
|
109
|
+
* Maybe cast string subscript access for integer pointer parameters.
|
|
110
|
+
*/
|
|
111
|
+
static maybeCastStringSubscript(
|
|
112
|
+
ctx: Parser.ExpressionContext,
|
|
113
|
+
expr: string,
|
|
114
|
+
targetParamBaseType: string | undefined,
|
|
115
|
+
callbacks: IArgumentGeneratorCallbacks,
|
|
116
|
+
): string {
|
|
117
|
+
if (!targetParamBaseType || !callbacks.isStringSubscriptAccess(ctx)) {
|
|
118
|
+
return expr;
|
|
119
|
+
}
|
|
120
|
+
|
|
121
|
+
const cType = TYPE_MAP[targetParamBaseType];
|
|
122
|
+
if (cType && !["float", "double", "bool", "void"].includes(cType)) {
|
|
123
|
+
return CppModeHelper.reinterpretCast(`${cType}*`, expr);
|
|
124
|
+
}
|
|
125
|
+
|
|
126
|
+
return expr;
|
|
127
|
+
}
|
|
128
|
+
|
|
129
|
+
/**
|
|
130
|
+
* Handle member access argument - may need special handling for arrays or C++ conversions.
|
|
131
|
+
* Returns null if default lvalue handling should be used.
|
|
132
|
+
*/
|
|
133
|
+
static handleMemberAccessArg(
|
|
134
|
+
ctx: Parser.ExpressionContext,
|
|
135
|
+
targetParamBaseType: string | undefined,
|
|
136
|
+
callbacks: IArgumentGeneratorCallbacks,
|
|
137
|
+
): string | null {
|
|
138
|
+
const arrayStatus = callbacks.getMemberAccessArrayStatus(ctx);
|
|
139
|
+
|
|
140
|
+
// Array member - no address-of needed
|
|
141
|
+
if (arrayStatus === "array") {
|
|
142
|
+
return callbacks.generateExpression(ctx);
|
|
143
|
+
}
|
|
144
|
+
|
|
145
|
+
// C++ mode may need temp variable for type conversion
|
|
146
|
+
if (
|
|
147
|
+
arrayStatus === "not-array" &&
|
|
148
|
+
targetParamBaseType &&
|
|
149
|
+
callbacks.needsCppMemberConversion(ctx, targetParamBaseType)
|
|
150
|
+
) {
|
|
151
|
+
return ArgumentGenerator.createCppMemberConversionTemp(
|
|
152
|
+
ctx,
|
|
153
|
+
targetParamBaseType,
|
|
154
|
+
callbacks,
|
|
155
|
+
);
|
|
156
|
+
}
|
|
157
|
+
|
|
158
|
+
return null; // Fall through to default lvalue handling
|
|
159
|
+
}
|
|
160
|
+
|
|
161
|
+
/**
|
|
162
|
+
* Handle lvalue argument (member access or array access).
|
|
163
|
+
*/
|
|
164
|
+
static handleLvalueArg(
|
|
165
|
+
ctx: Parser.ExpressionContext,
|
|
166
|
+
lvalueType: "member" | "array",
|
|
167
|
+
targetParamBaseType: string | undefined,
|
|
168
|
+
callbacks: IArgumentGeneratorCallbacks,
|
|
169
|
+
): string {
|
|
170
|
+
// Member access to array field - arrays decay to pointers
|
|
171
|
+
if (lvalueType === "member") {
|
|
172
|
+
const memberResult = ArgumentGenerator.handleMemberAccessArg(
|
|
173
|
+
ctx,
|
|
174
|
+
targetParamBaseType,
|
|
175
|
+
callbacks,
|
|
176
|
+
);
|
|
177
|
+
if (memberResult) return memberResult;
|
|
178
|
+
}
|
|
179
|
+
|
|
180
|
+
// Generate expression with address-of
|
|
181
|
+
const generatedExpr = callbacks.generateExpression(ctx);
|
|
182
|
+
const expr = CppModeHelper.maybeAddressOf(generatedExpr);
|
|
183
|
+
|
|
184
|
+
// String subscript access may need cast
|
|
185
|
+
if (lvalueType === "array") {
|
|
186
|
+
return ArgumentGenerator.maybeCastStringSubscript(
|
|
187
|
+
ctx,
|
|
188
|
+
expr,
|
|
189
|
+
targetParamBaseType,
|
|
190
|
+
callbacks,
|
|
191
|
+
);
|
|
192
|
+
}
|
|
193
|
+
|
|
194
|
+
return expr;
|
|
195
|
+
}
|
|
196
|
+
|
|
197
|
+
/**
|
|
198
|
+
* Main entry point: Generate a function argument with proper ADR-006 semantics.
|
|
199
|
+
*
|
|
200
|
+
* @param ctx - The expression context
|
|
201
|
+
* @param simpleId - The simple identifier if known (optimization to avoid re-parsing)
|
|
202
|
+
* @param targetParamBaseType - The target parameter's base type
|
|
203
|
+
* @param callbacks - Callbacks to CodeGenerator methods
|
|
204
|
+
*/
|
|
205
|
+
static generateArg(
|
|
206
|
+
ctx: Parser.ExpressionContext,
|
|
207
|
+
simpleId: string | null,
|
|
208
|
+
targetParamBaseType: string | undefined,
|
|
209
|
+
callbacks: IArgumentGeneratorCallbacks,
|
|
210
|
+
): string {
|
|
211
|
+
// Handle simple identifiers
|
|
212
|
+
if (simpleId) {
|
|
213
|
+
return ArgumentGenerator.handleIdentifierArg(simpleId);
|
|
214
|
+
}
|
|
215
|
+
|
|
216
|
+
// Check if expression is an lvalue
|
|
217
|
+
const lvalueType = callbacks.getLvalueType(ctx);
|
|
218
|
+
if (lvalueType) {
|
|
219
|
+
return ArgumentGenerator.handleLvalueArg(
|
|
220
|
+
ctx,
|
|
221
|
+
lvalueType,
|
|
222
|
+
targetParamBaseType,
|
|
223
|
+
callbacks,
|
|
224
|
+
);
|
|
225
|
+
}
|
|
226
|
+
|
|
227
|
+
// Handle rvalue (literals or complex expressions)
|
|
228
|
+
return ArgumentGenerator.handleRvalueArg(
|
|
229
|
+
ctx,
|
|
230
|
+
targetParamBaseType,
|
|
231
|
+
callbacks,
|
|
232
|
+
);
|
|
233
|
+
}
|
|
234
|
+
}
|
|
235
|
+
|
|
236
|
+
export default ArgumentGenerator;
|
|
@@ -6,13 +6,13 @@
|
|
|
6
6
|
* so designated initializers { .field = value } don't work with them.
|
|
7
7
|
*/
|
|
8
8
|
|
|
9
|
-
import
|
|
9
|
+
import TSymbolKind from "../../../types/symbol-kinds/TSymbolKind.js";
|
|
10
10
|
|
|
11
11
|
/**
|
|
12
12
|
* Symbol lookup interface for constructor detection
|
|
13
13
|
*/
|
|
14
14
|
interface ISymbolLookup {
|
|
15
|
-
getSymbol(name: string): { kind:
|
|
15
|
+
getSymbol(name: string): { kind: TSymbolKind } | undefined;
|
|
16
16
|
}
|
|
17
17
|
|
|
18
18
|
class CppConstructorHelper {
|
|
@@ -68,7 +68,7 @@ class CppConstructorHelper {
|
|
|
68
68
|
);
|
|
69
69
|
|
|
70
70
|
const constructorSymbol = symbolTable.getSymbol(constructorName);
|
|
71
|
-
return constructorSymbol?.kind ===
|
|
71
|
+
return constructorSymbol?.kind === "function";
|
|
72
72
|
}
|
|
73
73
|
}
|
|
74
74
|
|