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
|
@@ -38,7 +38,7 @@ describe("StringLengthCounter", () => {
|
|
|
38
38
|
|
|
39
39
|
describe("countExpression", () => {
|
|
40
40
|
it("counts single .length access on string variable", () => {
|
|
41
|
-
CodeGenState.
|
|
41
|
+
CodeGenState.setVariableTypeInfo("myStr", {
|
|
42
42
|
baseType: "char",
|
|
43
43
|
bitWidth: 8,
|
|
44
44
|
isArray: false,
|
|
@@ -54,7 +54,7 @@ describe("StringLengthCounter", () => {
|
|
|
54
54
|
});
|
|
55
55
|
|
|
56
56
|
it("counts multiple .length accesses on same variable", () => {
|
|
57
|
-
CodeGenState.
|
|
57
|
+
CodeGenState.setVariableTypeInfo("str", {
|
|
58
58
|
baseType: "char",
|
|
59
59
|
bitWidth: 8,
|
|
60
60
|
isArray: false,
|
|
@@ -71,7 +71,7 @@ describe("StringLengthCounter", () => {
|
|
|
71
71
|
});
|
|
72
72
|
|
|
73
73
|
it("counts .length accesses on different string variables", () => {
|
|
74
|
-
CodeGenState.
|
|
74
|
+
CodeGenState.setVariableTypeInfo("a", {
|
|
75
75
|
baseType: "char",
|
|
76
76
|
bitWidth: 8,
|
|
77
77
|
isArray: false,
|
|
@@ -79,7 +79,7 @@ describe("StringLengthCounter", () => {
|
|
|
79
79
|
isString: true,
|
|
80
80
|
stringCapacity: 16,
|
|
81
81
|
});
|
|
82
|
-
CodeGenState.
|
|
82
|
+
CodeGenState.setVariableTypeInfo("b", {
|
|
83
83
|
baseType: "char",
|
|
84
84
|
bitWidth: 8,
|
|
85
85
|
isArray: false,
|
|
@@ -96,7 +96,7 @@ describe("StringLengthCounter", () => {
|
|
|
96
96
|
});
|
|
97
97
|
|
|
98
98
|
it("ignores .length on non-string variables", () => {
|
|
99
|
-
CodeGenState.
|
|
99
|
+
CodeGenState.setVariableTypeInfo("arr", {
|
|
100
100
|
baseType: "u8",
|
|
101
101
|
bitWidth: 8,
|
|
102
102
|
isArray: true,
|
|
@@ -111,7 +111,7 @@ describe("StringLengthCounter", () => {
|
|
|
111
111
|
});
|
|
112
112
|
|
|
113
113
|
it("ignores other member accesses", () => {
|
|
114
|
-
CodeGenState.
|
|
114
|
+
CodeGenState.setVariableTypeInfo("obj", {
|
|
115
115
|
baseType: "MyStruct",
|
|
116
116
|
bitWidth: 32,
|
|
117
117
|
isArray: false,
|
|
@@ -135,7 +135,7 @@ describe("StringLengthCounter", () => {
|
|
|
135
135
|
|
|
136
136
|
describe("countBlock", () => {
|
|
137
137
|
it("counts .length accesses across multiple statements", () => {
|
|
138
|
-
CodeGenState.
|
|
138
|
+
CodeGenState.setVariableTypeInfo("msg", {
|
|
139
139
|
baseType: "char",
|
|
140
140
|
bitWidth: 8,
|
|
141
141
|
isArray: false,
|
|
@@ -154,7 +154,7 @@ describe("StringLengthCounter", () => {
|
|
|
154
154
|
});
|
|
155
155
|
|
|
156
156
|
it("counts .length in assignment statements", () => {
|
|
157
|
-
CodeGenState.
|
|
157
|
+
CodeGenState.setVariableTypeInfo("text", {
|
|
158
158
|
baseType: "char",
|
|
159
159
|
bitWidth: 8,
|
|
160
160
|
isArray: false,
|
|
@@ -175,7 +175,7 @@ describe("StringLengthCounter", () => {
|
|
|
175
175
|
|
|
176
176
|
describe("countBlockInto", () => {
|
|
177
177
|
it("adds counts to existing map", () => {
|
|
178
|
-
CodeGenState.
|
|
178
|
+
CodeGenState.setVariableTypeInfo("s1", {
|
|
179
179
|
baseType: "char",
|
|
180
180
|
bitWidth: 8,
|
|
181
181
|
isArray: false,
|
|
@@ -183,7 +183,7 @@ describe("StringLengthCounter", () => {
|
|
|
183
183
|
isString: true,
|
|
184
184
|
stringCapacity: 32,
|
|
185
185
|
});
|
|
186
|
-
CodeGenState.
|
|
186
|
+
CodeGenState.setVariableTypeInfo("s2", {
|
|
187
187
|
baseType: "char",
|
|
188
188
|
bitWidth: 8,
|
|
189
189
|
isArray: false,
|
|
@@ -209,7 +209,7 @@ describe("StringLengthCounter", () => {
|
|
|
209
209
|
|
|
210
210
|
describe("nested expressions", () => {
|
|
211
211
|
it("counts .length in ternary expressions", () => {
|
|
212
|
-
CodeGenState.
|
|
212
|
+
CodeGenState.setVariableTypeInfo("str", {
|
|
213
213
|
baseType: "char",
|
|
214
214
|
bitWidth: 8,
|
|
215
215
|
isArray: false,
|
|
@@ -225,7 +225,7 @@ describe("StringLengthCounter", () => {
|
|
|
225
225
|
});
|
|
226
226
|
|
|
227
227
|
it("counts .length in comparison expressions", () => {
|
|
228
|
-
CodeGenState.
|
|
228
|
+
CodeGenState.setVariableTypeInfo("name", {
|
|
229
229
|
baseType: "char",
|
|
230
230
|
bitWidth: 8,
|
|
231
231
|
isArray: false,
|
|
@@ -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.
|
|
@@ -144,7 +145,7 @@ class AssignmentClassifier {
|
|
|
144
145
|
varName: string,
|
|
145
146
|
fieldName: string,
|
|
146
147
|
): AssignmentKind | null {
|
|
147
|
-
const typeInfo = CodeGenState.
|
|
148
|
+
const typeInfo = CodeGenState.getVariableTypeInfo(varName);
|
|
148
149
|
if (!typeInfo?.isBitmap || !typeInfo.bitmapTypeName) {
|
|
149
150
|
return null;
|
|
150
151
|
}
|
|
@@ -189,7 +190,7 @@ class AssignmentClassifier {
|
|
|
189
190
|
}
|
|
190
191
|
|
|
191
192
|
// Check if struct member bitmap field: struct.bitmapMember.field
|
|
192
|
-
const structTypeInfo = CodeGenState.
|
|
193
|
+
const structTypeInfo = CodeGenState.getVariableTypeInfo(firstName);
|
|
193
194
|
if (
|
|
194
195
|
!structTypeInfo ||
|
|
195
196
|
!CodeGenState.isKnownStruct(structTypeInfo.baseType)
|
|
@@ -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
|
}
|
|
@@ -270,7 +271,7 @@ class AssignmentClassifier {
|
|
|
270
271
|
|
|
271
272
|
const ids = ctx.identifiers;
|
|
272
273
|
const firstId = ids[0];
|
|
273
|
-
const typeInfo = CodeGenState.
|
|
274
|
+
const typeInfo = CodeGenState.getVariableTypeInfo(firstId);
|
|
274
275
|
|
|
275
276
|
// Check for bit range through struct chain: devices[0].control[0, 4]
|
|
276
277
|
// Detected by last subscript having 2 expressions (start, width)
|
|
@@ -494,7 +495,7 @@ class AssignmentClassifier {
|
|
|
494
495
|
}
|
|
495
496
|
|
|
496
497
|
const name = ctx.identifiers[0];
|
|
497
|
-
const typeInfo = CodeGenState.
|
|
498
|
+
const typeInfo = CodeGenState.getVariableTypeInfo(name) ?? null;
|
|
498
499
|
|
|
499
500
|
// Use shared classifier for array vs bit access decision
|
|
500
501
|
// Use lastSubscriptExprCount to distinguish [0][0] (two ops, each 1 expr)
|
|
@@ -558,16 +559,16 @@ class AssignmentClassifier {
|
|
|
558
559
|
let typeInfo;
|
|
559
560
|
if (ctx.isSimpleIdentifier) {
|
|
560
561
|
const id = ctx.identifiers[0];
|
|
561
|
-
typeInfo = CodeGenState.
|
|
562
|
+
typeInfo = CodeGenState.getVariableTypeInfo(id);
|
|
562
563
|
} else if (ctx.isSimpleThisAccess && CodeGenState.currentScope) {
|
|
563
564
|
// this.member pattern: lookup using scoped name
|
|
564
565
|
const memberName = ctx.identifiers[0];
|
|
565
566
|
const scopedName = `${CodeGenState.currentScope}_${memberName}`;
|
|
566
|
-
typeInfo = CodeGenState.
|
|
567
|
+
typeInfo = CodeGenState.getVariableTypeInfo(scopedName);
|
|
567
568
|
} else if (ctx.isSimpleGlobalAccess) {
|
|
568
569
|
// global.member pattern: lookup using direct name
|
|
569
570
|
const memberName = ctx.identifiers[0];
|
|
570
|
-
typeInfo = CodeGenState.
|
|
571
|
+
typeInfo = CodeGenState.getVariableTypeInfo(memberName);
|
|
571
572
|
} else {
|
|
572
573
|
return null;
|
|
573
574
|
}
|
|
@@ -604,7 +605,7 @@ class AssignmentClassifier {
|
|
|
604
605
|
): AssignmentKind | null {
|
|
605
606
|
if (!ctx.isSimpleIdentifier) return null;
|
|
606
607
|
const id = ctx.identifiers[0];
|
|
607
|
-
const typeInfo = CodeGenState.
|
|
608
|
+
const typeInfo = CodeGenState.getVariableTypeInfo(id);
|
|
608
609
|
return AssignmentClassifier.isSimpleStringType(typeInfo)
|
|
609
610
|
? AssignmentKind.STRING_SIMPLE
|
|
610
611
|
: null;
|
|
@@ -619,7 +620,7 @@ class AssignmentClassifier {
|
|
|
619
620
|
if (!ctx.isSimpleThisAccess || !CodeGenState.currentScope) return null;
|
|
620
621
|
const memberName = ctx.identifiers[0];
|
|
621
622
|
const scopedName = `${CodeGenState.currentScope}_${memberName}`;
|
|
622
|
-
const typeInfo = CodeGenState.
|
|
623
|
+
const typeInfo = CodeGenState.getVariableTypeInfo(scopedName);
|
|
623
624
|
return AssignmentClassifier.isSimpleStringType(typeInfo)
|
|
624
625
|
? AssignmentKind.STRING_THIS_MEMBER
|
|
625
626
|
: null;
|
|
@@ -633,7 +634,7 @@ class AssignmentClassifier {
|
|
|
633
634
|
): AssignmentKind | null {
|
|
634
635
|
if (!ctx.isSimpleGlobalAccess) return null;
|
|
635
636
|
const id = ctx.identifiers[0];
|
|
636
|
-
const typeInfo = CodeGenState.
|
|
637
|
+
const typeInfo = CodeGenState.getVariableTypeInfo(id);
|
|
637
638
|
return AssignmentClassifier.isSimpleStringType(typeInfo)
|
|
638
639
|
? AssignmentKind.STRING_GLOBAL
|
|
639
640
|
: null;
|
|
@@ -644,7 +645,7 @@ class AssignmentClassifier {
|
|
|
644
645
|
* Returns the base struct type if valid, null if not a known struct.
|
|
645
646
|
*/
|
|
646
647
|
private static _resolveStructType(structName: string): string | null {
|
|
647
|
-
const structTypeInfo = CodeGenState.
|
|
648
|
+
const structTypeInfo = CodeGenState.getVariableTypeInfo(structName);
|
|
648
649
|
if (
|
|
649
650
|
!structTypeInfo ||
|
|
650
651
|
!CodeGenState.isKnownStruct(structTypeInfo.baseType)
|
|
@@ -148,7 +148,7 @@ describe("AssignmentClassifier - Bitmap Fields", () => {
|
|
|
148
148
|
["StatusFlags", new Map([["Running", { offset: 0, width: 1 }]])],
|
|
149
149
|
]);
|
|
150
150
|
setupSymbols({ bitmapFields });
|
|
151
|
-
CodeGenState.
|
|
151
|
+
CodeGenState.setVariableTypeInfo(
|
|
152
152
|
"flags",
|
|
153
153
|
createTypeInfo({ isBitmap: true, bitmapTypeName: "StatusFlags" }),
|
|
154
154
|
);
|
|
@@ -169,7 +169,7 @@ describe("AssignmentClassifier - Bitmap Fields", () => {
|
|
|
169
169
|
["StatusFlags", new Map([["Mode", { offset: 4, width: 4 }]])],
|
|
170
170
|
]);
|
|
171
171
|
setupSymbols({ bitmapFields });
|
|
172
|
-
CodeGenState.
|
|
172
|
+
CodeGenState.setVariableTypeInfo(
|
|
173
173
|
"flags",
|
|
174
174
|
createTypeInfo({ isBitmap: true, bitmapTypeName: "StatusFlags" }),
|
|
175
175
|
);
|
|
@@ -213,7 +213,7 @@ describe("AssignmentClassifier - Bitmap Fields", () => {
|
|
|
213
213
|
["Device", new Map([["flags", "DeviceFlags"]])],
|
|
214
214
|
]);
|
|
215
215
|
setupSymbols({ bitmapFields, knownStructs, structFields });
|
|
216
|
-
CodeGenState.
|
|
216
|
+
CodeGenState.setVariableTypeInfo(
|
|
217
217
|
"device",
|
|
218
218
|
createTypeInfo({ baseType: "Device" }),
|
|
219
219
|
);
|
|
@@ -240,7 +240,10 @@ describe("AssignmentClassifier - Integer Bit Access", () => {
|
|
|
240
240
|
});
|
|
241
241
|
|
|
242
242
|
it("classifies single bit access on integer", () => {
|
|
243
|
-
CodeGenState.
|
|
243
|
+
CodeGenState.setVariableTypeInfo(
|
|
244
|
+
"flags",
|
|
245
|
+
createTypeInfo({ baseType: "u8" }),
|
|
246
|
+
);
|
|
244
247
|
|
|
245
248
|
const ctx = createMockContext({
|
|
246
249
|
identifiers: ["flags"],
|
|
@@ -253,7 +256,10 @@ describe("AssignmentClassifier - Integer Bit Access", () => {
|
|
|
253
256
|
});
|
|
254
257
|
|
|
255
258
|
it("classifies bit range access on integer", () => {
|
|
256
|
-
CodeGenState.
|
|
259
|
+
CodeGenState.setVariableTypeInfo(
|
|
260
|
+
"flags",
|
|
261
|
+
createTypeInfo({ baseType: "u32" }),
|
|
262
|
+
);
|
|
257
263
|
|
|
258
264
|
const ctx = createMockContext({
|
|
259
265
|
identifiers: ["flags"],
|
|
@@ -282,7 +288,7 @@ describe("AssignmentClassifier - Array Access", () => {
|
|
|
282
288
|
});
|
|
283
289
|
|
|
284
290
|
it("classifies simple array element", () => {
|
|
285
|
-
CodeGenState.
|
|
291
|
+
CodeGenState.setVariableTypeInfo(
|
|
286
292
|
"arr",
|
|
287
293
|
createTypeInfo({
|
|
288
294
|
isArray: true,
|
|
@@ -303,7 +309,7 @@ describe("AssignmentClassifier - Array Access", () => {
|
|
|
303
309
|
});
|
|
304
310
|
|
|
305
311
|
it("classifies array slice", () => {
|
|
306
|
-
CodeGenState.
|
|
312
|
+
CodeGenState.setVariableTypeInfo(
|
|
307
313
|
"buffer",
|
|
308
314
|
createTypeInfo({
|
|
309
315
|
isArray: true,
|
|
@@ -336,7 +342,7 @@ describe("AssignmentClassifier - String Assignments", () => {
|
|
|
336
342
|
});
|
|
337
343
|
|
|
338
344
|
it("classifies simple string variable", () => {
|
|
339
|
-
CodeGenState.
|
|
345
|
+
CodeGenState.setVariableTypeInfo(
|
|
340
346
|
"name",
|
|
341
347
|
createTypeInfo({
|
|
342
348
|
baseType: "string<32>",
|
|
@@ -348,7 +354,7 @@ describe("AssignmentClassifier - String Assignments", () => {
|
|
|
348
354
|
const ctx = createMockContext({
|
|
349
355
|
identifiers: ["name"],
|
|
350
356
|
isSimpleIdentifier: true,
|
|
351
|
-
firstIdTypeInfo: CodeGenState.
|
|
357
|
+
firstIdTypeInfo: CodeGenState.getVariableTypeInfo("name")!,
|
|
352
358
|
});
|
|
353
359
|
|
|
354
360
|
expect(AssignmentClassifier.classify(ctx)).toBe(
|
|
@@ -362,7 +368,7 @@ describe("AssignmentClassifier - String Assignments", () => {
|
|
|
362
368
|
["Person", new Map([["name", "string<64>"]])],
|
|
363
369
|
]);
|
|
364
370
|
setupSymbols({ knownStructs, structFields });
|
|
365
|
-
CodeGenState.
|
|
371
|
+
CodeGenState.setVariableTypeInfo(
|
|
366
372
|
"person",
|
|
367
373
|
createTypeInfo({ baseType: "Person" }),
|
|
368
374
|
);
|
|
@@ -389,7 +395,7 @@ describe("AssignmentClassifier - Special Compound", () => {
|
|
|
389
395
|
});
|
|
390
396
|
|
|
391
397
|
it("classifies atomic RMW", () => {
|
|
392
|
-
CodeGenState.
|
|
398
|
+
CodeGenState.setVariableTypeInfo(
|
|
393
399
|
"counter",
|
|
394
400
|
createTypeInfo({
|
|
395
401
|
baseType: "u32",
|
|
@@ -408,7 +414,7 @@ describe("AssignmentClassifier - Special Compound", () => {
|
|
|
408
414
|
});
|
|
409
415
|
|
|
410
416
|
it("classifies overflow clamp", () => {
|
|
411
|
-
CodeGenState.
|
|
417
|
+
CodeGenState.setVariableTypeInfo(
|
|
412
418
|
"saturated",
|
|
413
419
|
createTypeInfo({
|
|
414
420
|
baseType: "u8",
|
|
@@ -429,7 +435,7 @@ describe("AssignmentClassifier - Special Compound", () => {
|
|
|
429
435
|
});
|
|
430
436
|
|
|
431
437
|
it("does not classify float as overflow clamp", () => {
|
|
432
|
-
CodeGenState.
|
|
438
|
+
CodeGenState.setVariableTypeInfo(
|
|
433
439
|
"value",
|
|
434
440
|
createTypeInfo({
|
|
435
441
|
baseType: "f32",
|
|
@@ -648,7 +654,7 @@ describe("AssignmentClassifier - Bitmap Array Element Field", () => {
|
|
|
648
654
|
["StatusFlags", new Map([["Active", { offset: 0, width: 1 }]])],
|
|
649
655
|
]);
|
|
650
656
|
setupSymbols({ bitmapFields });
|
|
651
|
-
CodeGenState.
|
|
657
|
+
CodeGenState.setVariableTypeInfo(
|
|
652
658
|
"flagsArr",
|
|
653
659
|
createTypeInfo({
|
|
654
660
|
isBitmap: true,
|
|
@@ -682,7 +688,7 @@ describe("AssignmentClassifier - Multi-dim Array Bit Indexing", () => {
|
|
|
682
688
|
});
|
|
683
689
|
|
|
684
690
|
it("classifies matrix[i][j][bit] as ARRAY_ELEMENT_BIT", () => {
|
|
685
|
-
CodeGenState.
|
|
691
|
+
CodeGenState.setVariableTypeInfo(
|
|
686
692
|
"matrix",
|
|
687
693
|
createTypeInfo({
|
|
688
694
|
baseType: "u32",
|
|
@@ -709,7 +715,7 @@ describe("AssignmentClassifier - Multi-dim Array Bit Indexing", () => {
|
|
|
709
715
|
});
|
|
710
716
|
|
|
711
717
|
it("classifies matrix[i][j] as MULTI_DIM_ARRAY_ELEMENT", () => {
|
|
712
|
-
CodeGenState.
|
|
718
|
+
CodeGenState.setVariableTypeInfo(
|
|
713
719
|
"matrix",
|
|
714
720
|
createTypeInfo({
|
|
715
721
|
baseType: "u32",
|
|
@@ -875,7 +881,7 @@ describe("AssignmentClassifier - Member Chain", () => {
|
|
|
875
881
|
const knownStructs = new Set(["Config"]);
|
|
876
882
|
const structFields = new Map([["Config", new Map([["items", "Item"]])]]);
|
|
877
883
|
setupSymbols({ knownStructs, structFields });
|
|
878
|
-
CodeGenState.
|
|
884
|
+
CodeGenState.setVariableTypeInfo(
|
|
879
885
|
"config",
|
|
880
886
|
createTypeInfo({ baseType: "Config" }),
|
|
881
887
|
);
|
|
@@ -37,7 +37,7 @@ function handleArrayElement(ctx: IAssignmentContext): string {
|
|
|
37
37
|
function handleMultiDimArrayElement(ctx: IAssignmentContext): string {
|
|
38
38
|
// Use resolvedBaseIdentifier for type lookup (includes scope prefix)
|
|
39
39
|
// e.g., "ArrayBug_data" instead of "data"
|
|
40
|
-
const typeInfo = CodeGenState.
|
|
40
|
+
const typeInfo = CodeGenState.getVariableTypeInfo(ctx.resolvedBaseIdentifier);
|
|
41
41
|
|
|
42
42
|
// ADR-036: Compile-time bounds checking for constant indices
|
|
43
43
|
if (typeInfo?.arrayDimensions) {
|
|
@@ -71,7 +71,7 @@ function handleArraySlice(ctx: IAssignmentContext): string {
|
|
|
71
71
|
|
|
72
72
|
// Use resolvedBaseIdentifier for type lookup (includes scope prefix)
|
|
73
73
|
const name = ctx.resolvedBaseIdentifier;
|
|
74
|
-
const typeInfo = CodeGenState.
|
|
74
|
+
const typeInfo = CodeGenState.getVariableTypeInfo(name);
|
|
75
75
|
|
|
76
76
|
// Get line number for error messages
|
|
77
77
|
const line = ctx.subscripts[0].start?.line ?? 0;
|
|
@@ -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
|
/**
|
|
@@ -42,7 +42,7 @@ function handleIntegerBit(ctx: IAssignmentContext): string {
|
|
|
42
42
|
// e.g., "ArrayBug_flags" instead of "flags"
|
|
43
43
|
const name = ctx.resolvedBaseIdentifier;
|
|
44
44
|
const bitIndex = gen().generateExpression(ctx.subscripts[0]);
|
|
45
|
-
const typeInfo = CodeGenState.
|
|
45
|
+
const typeInfo = CodeGenState.getVariableTypeInfo(name);
|
|
46
46
|
|
|
47
47
|
// Check for float bit indexing
|
|
48
48
|
if (typeInfo) {
|
|
@@ -79,7 +79,7 @@ function handleIntegerBitRange(ctx: IAssignmentContext): string {
|
|
|
79
79
|
const name = ctx.resolvedBaseIdentifier;
|
|
80
80
|
const start = gen().generateExpression(ctx.subscripts[0]);
|
|
81
81
|
const width = gen().generateExpression(ctx.subscripts[1]);
|
|
82
|
-
const typeInfo = CodeGenState.
|
|
82
|
+
const typeInfo = CodeGenState.getVariableTypeInfo(name);
|
|
83
83
|
|
|
84
84
|
// Check for float bit indexing
|
|
85
85
|
if (typeInfo) {
|
|
@@ -138,7 +138,7 @@ function handleArrayElementBit(ctx: IAssignmentContext): string {
|
|
|
138
138
|
|
|
139
139
|
// Use resolvedBaseIdentifier for type lookup and code generation
|
|
140
140
|
const arrayName = ctx.resolvedBaseIdentifier;
|
|
141
|
-
const typeInfo = CodeGenState.
|
|
141
|
+
const typeInfo = CodeGenState.getVariableTypeInfo(arrayName);
|
|
142
142
|
|
|
143
143
|
if (!typeInfo?.arrayDimensions) {
|
|
144
144
|
// Use raw identifier in error message for clarity
|
|
@@ -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 {
|
|
@@ -109,7 +110,7 @@ function generateWriteOnlyBitmapWrite(
|
|
|
109
110
|
function handleBitmapFieldSingleBit(ctx: IAssignmentContext): string {
|
|
110
111
|
const varName = ctx.identifiers[0];
|
|
111
112
|
const fieldName = ctx.identifiers[1];
|
|
112
|
-
const typeInfo = CodeGenState.
|
|
113
|
+
const typeInfo = CodeGenState.getVariableTypeInfo(varName);
|
|
113
114
|
const bitmapType = typeInfo!.bitmapTypeName!;
|
|
114
115
|
|
|
115
116
|
const fieldInfo = getBitmapFieldInfo(bitmapType, fieldName, ctx);
|
|
@@ -130,7 +131,7 @@ function handleBitmapFieldMultiBit(ctx: IAssignmentContext): string {
|
|
|
130
131
|
function handleBitmapArrayElementField(ctx: IAssignmentContext): string {
|
|
131
132
|
const arrayName = ctx.identifiers[0];
|
|
132
133
|
const fieldName = ctx.identifiers[1];
|
|
133
|
-
const typeInfo = CodeGenState.
|
|
134
|
+
const typeInfo = CodeGenState.getVariableTypeInfo(arrayName);
|
|
134
135
|
const bitmapType = typeInfo!.bitmapTypeName!;
|
|
135
136
|
|
|
136
137
|
const fieldInfo = getBitmapFieldInfo(bitmapType, fieldName, ctx);
|
|
@@ -148,7 +149,7 @@ function handleStructMemberBitmapField(ctx: IAssignmentContext): string {
|
|
|
148
149
|
const memberName = ctx.identifiers[1];
|
|
149
150
|
const fieldName = ctx.identifiers[2];
|
|
150
151
|
|
|
151
|
-
const structTypeInfo = CodeGenState.
|
|
152
|
+
const structTypeInfo = CodeGenState.getVariableTypeInfo(structName);
|
|
152
153
|
const memberInfo = CodeGenState.getMemberTypeInfo(
|
|
153
154
|
structTypeInfo!.baseType,
|
|
154
155
|
memberName,
|
|
@@ -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);
|
|
@@ -36,22 +36,22 @@ function getTargetTypeInfo(ctx: IAssignmentContext): {
|
|
|
36
36
|
|
|
37
37
|
// Simple identifier
|
|
38
38
|
if (ctx.isSimpleIdentifier) {
|
|
39
|
-
return { typeInfo: CodeGenState.
|
|
39
|
+
return { typeInfo: CodeGenState.getVariableTypeInfo(id) };
|
|
40
40
|
}
|
|
41
41
|
|
|
42
42
|
// this.member: lookup using scoped name
|
|
43
43
|
if (ctx.isSimpleThisAccess && CodeGenState.currentScope) {
|
|
44
44
|
const scopedName = `${CodeGenState.currentScope}_${id}`;
|
|
45
|
-
return { typeInfo: CodeGenState.
|
|
45
|
+
return { typeInfo: CodeGenState.getVariableTypeInfo(scopedName) };
|
|
46
46
|
}
|
|
47
47
|
|
|
48
48
|
// global.member: lookup using direct name
|
|
49
49
|
if (ctx.isSimpleGlobalAccess) {
|
|
50
|
-
return { typeInfo: CodeGenState.
|
|
50
|
+
return { typeInfo: CodeGenState.getVariableTypeInfo(id) };
|
|
51
51
|
}
|
|
52
52
|
|
|
53
53
|
// Fallback to direct lookup
|
|
54
|
-
return { typeInfo: CodeGenState.
|
|
54
|
+
return { typeInfo: CodeGenState.getVariableTypeInfo(id) };
|
|
55
55
|
}
|
|
56
56
|
|
|
57
57
|
/**
|
|
@@ -42,7 +42,7 @@ function handleSimpleStringAssignment(ctx: IAssignmentContext): string {
|
|
|
42
42
|
validateNotCompound(ctx);
|
|
43
43
|
|
|
44
44
|
const id = ctx.identifiers[0];
|
|
45
|
-
const typeInfo = CodeGenState.
|
|
45
|
+
const typeInfo = CodeGenState.getVariableTypeInfo(id);
|
|
46
46
|
const capacity = typeInfo!.stringCapacity!;
|
|
47
47
|
|
|
48
48
|
CodeGenState.needsString = true;
|
|
@@ -57,7 +57,7 @@ function handleSimpleStringAssignment(ctx: IAssignmentContext): string {
|
|
|
57
57
|
* Shared helper for struct field string handlers.
|
|
58
58
|
*/
|
|
59
59
|
function getStructFieldType(structName: string, fieldName: string): string {
|
|
60
|
-
const structTypeInfo = CodeGenState.
|
|
60
|
+
const structTypeInfo = CodeGenState.getVariableTypeInfo(structName);
|
|
61
61
|
const structType = structTypeInfo!.baseType;
|
|
62
62
|
const structFields = CodeGenState.symbols!.structFields.get(structType);
|
|
63
63
|
return structFields!.get(fieldName)!;
|
|
@@ -69,7 +69,7 @@ function getStructFieldType(structName: string, fieldName: string): string {
|
|
|
69
69
|
* Shared helper for struct field handlers.
|
|
70
70
|
*/
|
|
71
71
|
function getStructType(structName: string): string {
|
|
72
|
-
const structTypeInfo = CodeGenState.
|
|
72
|
+
const structTypeInfo = CodeGenState.getVariableTypeInfo(structName);
|
|
73
73
|
return structTypeInfo!.baseType;
|
|
74
74
|
}
|
|
75
75
|
|
|
@@ -85,7 +85,7 @@ function handleStringThisMember(ctx: IAssignmentContext): string {
|
|
|
85
85
|
|
|
86
86
|
const memberName = ctx.identifiers[0];
|
|
87
87
|
const scopedName = `${CodeGenState.currentScope}_${memberName}`;
|
|
88
|
-
const typeInfo = CodeGenState.
|
|
88
|
+
const typeInfo = CodeGenState.getVariableTypeInfo(scopedName);
|
|
89
89
|
const capacity = typeInfo!.stringCapacity!;
|
|
90
90
|
|
|
91
91
|
CodeGenState.needsString = true;
|
|
@@ -123,7 +123,7 @@ function handleStringArrayElement(ctx: IAssignmentContext): string {
|
|
|
123
123
|
validateNotCompound(ctx);
|
|
124
124
|
|
|
125
125
|
const name = ctx.identifiers[0];
|
|
126
|
-
const typeInfo = CodeGenState.
|
|
126
|
+
const typeInfo = CodeGenState.getVariableTypeInfo(name);
|
|
127
127
|
const capacity = typeInfo!.stringCapacity!;
|
|
128
128
|
|
|
129
129
|
CodeGenState.needsString = true;
|