c-next 0.1.69 → 0.1.71
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 +173 -60
- package/src/transpiler/logic/analysis/FunctionCallAnalyzer.ts +240 -205
- package/src/transpiler/logic/analysis/InitializationAnalyzer.ts +1 -2
- package/src/transpiler/logic/analysis/PassByValueAnalyzer.ts +742 -0
- package/src/transpiler/logic/analysis/__tests__/FunctionCallAnalyzer.test.ts +102 -15
- 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/{output/codegen → logic/analysis}/helpers/AssignmentTargetExtractor.ts +1 -1
- package/src/transpiler/{output/codegen → logic/analysis}/helpers/ChildStatementCollector.ts +1 -1
- package/src/transpiler/{output/codegen → logic/analysis}/helpers/StatementExpressionCollector.ts +1 -1
- package/src/transpiler/{output/codegen → logic/analysis}/helpers/__tests__/AssignmentTargetExtractor.test.ts +2 -2
- package/src/transpiler/{output/codegen → logic/analysis}/helpers/__tests__/ChildStatementCollector.test.ts +2 -2
- package/src/transpiler/{output/codegen → logic/analysis}/helpers/__tests__/StatementExpressionCollector.test.ts +2 -2
- package/src/transpiler/logic/symbols/SymbolTable.ts +676 -258
- package/src/transpiler/logic/symbols/SymbolUtils.ts +2 -2
- package/src/transpiler/logic/symbols/__tests__/SymbolTable.test.ts +290 -782
- 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 +310 -2288
- package/src/transpiler/output/codegen/TypeRegistrationUtils.ts +4 -6
- package/src/transpiler/output/codegen/TypeResolver.ts +2 -2
- package/src/transpiler/output/codegen/TypeValidator.ts +5 -5
- package/src/transpiler/output/codegen/__tests__/CodeGenerator.test.ts +7 -1
- package/src/transpiler/output/codegen/__tests__/TypeRegistrationUtils.test.ts +36 -51
- package/src/transpiler/output/codegen/__tests__/TypeResolver.test.ts +20 -17
- package/src/transpiler/output/codegen/__tests__/TypeValidator.resolution.test.ts +3 -3
- package/src/transpiler/output/codegen/__tests__/TypeValidator.test.ts +1 -1
- package/src/transpiler/output/codegen/analysis/MemberChainAnalyzer.ts +1 -1
- package/src/transpiler/output/codegen/analysis/StringLengthCounter.ts +1 -1
- package/src/transpiler/output/codegen/analysis/__tests__/MemberChainAnalyzer.test.ts +9 -9
- package/src/transpiler/output/codegen/analysis/__tests__/StringLengthCounter.test.ts +12 -12
- package/src/transpiler/output/codegen/assignment/AssignmentClassifier.ts +13 -12
- package/src/transpiler/output/codegen/assignment/__tests__/AssignmentClassifier.test.ts +23 -17
- package/src/transpiler/output/codegen/assignment/handlers/ArrayHandlers.ts +2 -2
- package/src/transpiler/output/codegen/assignment/handlers/AssignmentHandlerUtils.ts +7 -1
- package/src/transpiler/output/codegen/assignment/handlers/BitAccessHandlers.ts +3 -3
- package/src/transpiler/output/codegen/assignment/handlers/BitmapHandlers.ts +9 -5
- package/src/transpiler/output/codegen/assignment/handlers/RegisterHandlers.ts +2 -1
- package/src/transpiler/output/codegen/assignment/handlers/SpecialHandlers.ts +4 -4
- package/src/transpiler/output/codegen/assignment/handlers/StringHandlers.ts +5 -5
- package/src/transpiler/output/codegen/assignment/handlers/__tests__/ArrayHandlers.test.ts +23 -25
- package/src/transpiler/output/codegen/assignment/handlers/__tests__/BitAccessHandlers.test.ts +20 -36
- package/src/transpiler/output/codegen/assignment/handlers/__tests__/BitmapHandlers.test.ts +18 -18
- package/src/transpiler/output/codegen/assignment/handlers/__tests__/SpecialHandlers.test.ts +42 -32
- package/src/transpiler/output/codegen/assignment/handlers/__tests__/handlerTestUtils.ts +5 -4
- 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/CallExprGenerator.ts +14 -6
- package/src/transpiler/output/codegen/generators/expressions/CallExprUtils.ts +9 -3
- package/src/transpiler/output/codegen/generators/expressions/PostfixExpressionGenerator.ts +19 -16
- package/src/transpiler/output/codegen/generators/expressions/__tests__/CallExprGenerator.test.ts +24 -8
- package/src/transpiler/output/codegen/generators/expressions/__tests__/CallExprUtils.test.ts +4 -8
- package/src/transpiler/output/codegen/generators/expressions/__tests__/PostfixExpressionGenerator.test.ts +15 -2
- package/src/transpiler/output/codegen/helpers/ArgumentGenerator.ts +236 -0
- package/src/transpiler/output/codegen/helpers/ArrayInitHelper.ts +2 -1
- package/src/transpiler/output/codegen/helpers/AssignmentExpectedTypeResolver.ts +2 -2
- package/src/transpiler/output/codegen/helpers/AssignmentValidator.ts +3 -3
- package/src/transpiler/output/codegen/helpers/CppConstructorHelper.ts +3 -3
- package/src/transpiler/output/codegen/helpers/EnumAssignmentValidator.ts +1 -1
- package/src/transpiler/output/codegen/helpers/FunctionContextManager.ts +435 -0
- package/src/transpiler/output/codegen/helpers/StringDeclHelper.ts +2 -2
- 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__/ArrayInitHelper.test.ts +1 -1
- package/src/transpiler/output/codegen/helpers/__tests__/AssignmentExpectedTypeResolver.test.ts +7 -7
- package/src/transpiler/output/codegen/helpers/__tests__/AssignmentValidator.test.ts +7 -7
- package/src/transpiler/output/codegen/helpers/__tests__/CppConstructorHelper.test.ts +4 -5
- package/src/transpiler/output/codegen/helpers/__tests__/EnumAssignmentValidator.test.ts +2 -2
- package/src/transpiler/output/codegen/helpers/__tests__/FunctionContextManager.test.ts +983 -0
- package/src/transpiler/output/codegen/helpers/__tests__/StringDeclHelper.test.ts +4 -4
- 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 +7 -3
- package/src/transpiler/output/codegen/resolution/__tests__/EnumTypeResolver.test.ts +5 -5
- 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 +109 -4
- 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 +277 -1
- 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/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
- /package/src/transpiler/{output/codegen → logic/analysis}/helpers/TransitiveModificationPropagator.ts +0 -0
- /package/src/transpiler/{output/codegen → logic/analysis}/helpers/__tests__/TransitiveModificationPropagator.test.ts +0 -0
|
@@ -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;
|
|
@@ -134,9 +134,10 @@ class ArrayInitHelper {
|
|
|
134
134
|
}
|
|
135
135
|
|
|
136
136
|
// Update type registry with inferred size for .length support
|
|
137
|
-
const existingType = CodeGenState.
|
|
137
|
+
const existingType = CodeGenState.getVariableTypeInfo(name);
|
|
138
138
|
if (existingType) {
|
|
139
139
|
existingType.arrayDimensions = [CodeGenState.lastArrayInitCount];
|
|
140
|
+
CodeGenState.setVariableTypeInfo(name, existingType);
|
|
140
141
|
}
|
|
141
142
|
|
|
142
143
|
return `[${CodeGenState.lastArrayInitCount}]`;
|
|
@@ -77,7 +77,7 @@ class AssignmentExpectedTypeResolver {
|
|
|
77
77
|
* Resolve expected type for a simple identifier target.
|
|
78
78
|
*/
|
|
79
79
|
private static resolveForSimpleIdentifier(id: string): IExpectedTypeResult {
|
|
80
|
-
const typeInfo = CodeGenState.
|
|
80
|
+
const typeInfo = CodeGenState.getVariableTypeInfo(id);
|
|
81
81
|
if (!typeInfo) {
|
|
82
82
|
return { expectedType: null, assignmentContext: null };
|
|
83
83
|
}
|
|
@@ -107,7 +107,7 @@ class AssignmentExpectedTypeResolver {
|
|
|
107
107
|
}
|
|
108
108
|
|
|
109
109
|
const rootName = identifiers[0];
|
|
110
|
-
const rootTypeInfo = CodeGenState.
|
|
110
|
+
const rootTypeInfo = CodeGenState.getVariableTypeInfo(rootName);
|
|
111
111
|
|
|
112
112
|
if (!rootTypeInfo || !CodeGenState.isKnownStruct(rootTypeInfo.baseType)) {
|
|
113
113
|
return { expectedType: null, assignmentContext: null };
|
|
@@ -120,7 +120,7 @@ class AssignmentValidator {
|
|
|
120
120
|
const shadowName = `__bits_${id}`;
|
|
121
121
|
CodeGenState.floatShadowCurrent.delete(shadowName);
|
|
122
122
|
|
|
123
|
-
const targetTypeInfo = CodeGenState.
|
|
123
|
+
const targetTypeInfo = CodeGenState.getVariableTypeInfo(id);
|
|
124
124
|
if (!targetTypeInfo) {
|
|
125
125
|
return;
|
|
126
126
|
}
|
|
@@ -172,7 +172,7 @@ class AssignmentValidator {
|
|
|
172
172
|
}
|
|
173
173
|
|
|
174
174
|
// ADR-036: Compile-time bounds checking
|
|
175
|
-
const typeInfo = CodeGenState.
|
|
175
|
+
const typeInfo = CodeGenState.getVariableTypeInfo(arrayName);
|
|
176
176
|
if (typeInfo?.isArray && typeInfo.arrayDimensions) {
|
|
177
177
|
TypeValidator.checkArrayBounds(
|
|
178
178
|
arrayName,
|
|
@@ -217,7 +217,7 @@ class AssignmentValidator {
|
|
|
217
217
|
}
|
|
218
218
|
|
|
219
219
|
// ADR-029: Validate callback field assignments with nominal typing
|
|
220
|
-
const rootTypeInfo = CodeGenState.
|
|
220
|
+
const rootTypeInfo = CodeGenState.getVariableTypeInfo(rootName);
|
|
221
221
|
if (rootTypeInfo && CodeGenState.isKnownStruct(rootTypeInfo.baseType)) {
|
|
222
222
|
const structType = rootTypeInfo.baseType;
|
|
223
223
|
const callbackFieldKey = `${structType}.${memberName}`;
|
|
@@ -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
|
|
|
@@ -78,7 +78,7 @@ class EnumAssignmentValidator {
|
|
|
78
78
|
|
|
79
79
|
// Check if it's a variable of primitive integer type
|
|
80
80
|
if (/^[a-zA-Z_]\w*$/.exec(text)) {
|
|
81
|
-
const typeInfo = CodeGenState.
|
|
81
|
+
const typeInfo = CodeGenState.getVariableTypeInfo(text);
|
|
82
82
|
if (
|
|
83
83
|
typeInfo &&
|
|
84
84
|
!typeInfo.isEnum &&
|