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
|
@@ -18,6 +18,7 @@ import * as Parser from "../../../logic/parser/grammar/CNextParser";
|
|
|
18
18
|
import CodeGenState from "../../../state/CodeGenState";
|
|
19
19
|
import TypeResolver from "../TypeResolver";
|
|
20
20
|
import ExpressionUnwrapper from "../utils/ExpressionUnwrapper";
|
|
21
|
+
import QualifiedNameGenerator from "../utils/QualifiedNameGenerator";
|
|
21
22
|
|
|
22
23
|
/**
|
|
23
24
|
* Resolves enum types from expressions.
|
|
@@ -41,7 +42,7 @@ export default class EnumTypeResolver {
|
|
|
41
42
|
|
|
42
43
|
// Check if it's a simple identifier that's an enum variable
|
|
43
44
|
if (/^[a-zA-Z_]\w*$/.exec(text)) {
|
|
44
|
-
const typeInfo = CodeGenState.
|
|
45
|
+
const typeInfo = CodeGenState.getVariableTypeInfo(text);
|
|
45
46
|
if (typeInfo?.isEnum && typeInfo.enumTypeName) {
|
|
46
47
|
return typeInfo.enumTypeName;
|
|
47
48
|
}
|
|
@@ -146,7 +147,7 @@ export default class EnumTypeResolver {
|
|
|
146
147
|
}
|
|
147
148
|
const varName = parts[1];
|
|
148
149
|
const scopedVarName = `${CodeGenState.currentScope}_${varName}`;
|
|
149
|
-
const typeInfo = CodeGenState.
|
|
150
|
+
const typeInfo = CodeGenState.getVariableTypeInfo(scopedVarName);
|
|
150
151
|
if (typeInfo?.isEnum && typeInfo.enumTypeName) {
|
|
151
152
|
return typeInfo.enumTypeName;
|
|
152
153
|
}
|
|
@@ -162,7 +163,10 @@ export default class EnumTypeResolver {
|
|
|
162
163
|
}
|
|
163
164
|
const scopeName = parts[0];
|
|
164
165
|
const enumName = parts[1];
|
|
165
|
-
const scopedEnumName =
|
|
166
|
+
const scopedEnumName = QualifiedNameGenerator.forMember(
|
|
167
|
+
scopeName,
|
|
168
|
+
enumName,
|
|
169
|
+
);
|
|
166
170
|
return CodeGenState.isKnownEnum(scopedEnumName) ? scopedEnumName : null;
|
|
167
171
|
}
|
|
168
172
|
|
|
@@ -121,7 +121,7 @@ describe("EnumTypeResolver", () => {
|
|
|
121
121
|
CodeGenState.symbols = createMockSymbols({
|
|
122
122
|
knownEnums: new Set(["State"]),
|
|
123
123
|
});
|
|
124
|
-
CodeGenState.
|
|
124
|
+
CodeGenState.setVariableTypeInfo("currentState", {
|
|
125
125
|
baseType: "State",
|
|
126
126
|
bitWidth: 0,
|
|
127
127
|
isArray: false,
|
|
@@ -135,7 +135,7 @@ describe("EnumTypeResolver", () => {
|
|
|
135
135
|
});
|
|
136
136
|
|
|
137
137
|
it("returns null for non-enum variable", () => {
|
|
138
|
-
CodeGenState.
|
|
138
|
+
CodeGenState.setVariableTypeInfo("count", {
|
|
139
139
|
baseType: "u32",
|
|
140
140
|
bitWidth: 32,
|
|
141
141
|
isArray: false,
|
|
@@ -190,7 +190,7 @@ describe("EnumTypeResolver", () => {
|
|
|
190
190
|
CodeGenState.symbols = createMockSymbols({
|
|
191
191
|
knownEnums: new Set(["Motor_State"]),
|
|
192
192
|
});
|
|
193
|
-
CodeGenState.
|
|
193
|
+
CodeGenState.setVariableTypeInfo("Motor_current", {
|
|
194
194
|
baseType: "Motor_State",
|
|
195
195
|
bitWidth: 0,
|
|
196
196
|
isArray: false,
|
|
@@ -261,7 +261,7 @@ describe("EnumTypeResolver", () => {
|
|
|
261
261
|
CodeGenState.symbols = createMockSymbols({
|
|
262
262
|
knownEnums: new Set(["EValueId"]),
|
|
263
263
|
});
|
|
264
|
-
CodeGenState.
|
|
264
|
+
CodeGenState.setVariableTypeInfo("input", {
|
|
265
265
|
baseType: "TInput",
|
|
266
266
|
bitWidth: 0,
|
|
267
267
|
isArray: false,
|
|
@@ -280,7 +280,7 @@ describe("EnumTypeResolver", () => {
|
|
|
280
280
|
symbolTable.addStructField("TInput", "count", "u32");
|
|
281
281
|
CodeGenState.symbolTable = symbolTable;
|
|
282
282
|
CodeGenState.symbols = createMockSymbols();
|
|
283
|
-
CodeGenState.
|
|
283
|
+
CodeGenState.setVariableTypeInfo("input", {
|
|
284
284
|
baseType: "TInput",
|
|
285
285
|
bitWidth: 0,
|
|
286
286
|
isArray: false,
|
|
@@ -0,0 +1,12 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Callbacks required for parameter type resolution.
|
|
3
|
+
* Issue #793: Used by FunctionContextManager for CodeGenerator dependencies.
|
|
4
|
+
*/
|
|
5
|
+
interface IFunctionContextCallbacks {
|
|
6
|
+
/** Check if a type name is a struct type */
|
|
7
|
+
isStructType: (typeName: string) => boolean;
|
|
8
|
+
/** Resolve qualified type identifiers to a type name */
|
|
9
|
+
resolveQualifiedType: (identifiers: string[]) => string;
|
|
10
|
+
}
|
|
11
|
+
|
|
12
|
+
export default IFunctionContextCallbacks;
|
|
@@ -0,0 +1,114 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* QualifiedNameGenerator - C-style name generation for C-Next symbols
|
|
3
|
+
*
|
|
4
|
+
* Provides C-style mangled name generation for use in the output layer.
|
|
5
|
+
* Delegates to FunctionUtils.getCMangledName() for the actual implementation
|
|
6
|
+
* to avoid duplication with the types layer.
|
|
7
|
+
*
|
|
8
|
+
* Design decisions:
|
|
9
|
+
* - Lives in output layer (codegen) since it generates C output
|
|
10
|
+
* - Delegates to FunctionUtils for symbol-based name generation
|
|
11
|
+
* - Provides string-based methods for backward compatibility
|
|
12
|
+
* - Handles nested scopes: Outer.Inner.func -> Outer_Inner_func
|
|
13
|
+
* - Global scope functions keep their bare names
|
|
14
|
+
*/
|
|
15
|
+
import type IFunctionSymbol from "../../../types/symbols/IFunctionSymbol";
|
|
16
|
+
import type IScopeSymbol from "../../../types/symbols/IScopeSymbol";
|
|
17
|
+
import SymbolRegistry from "../../../state/SymbolRegistry";
|
|
18
|
+
import FunctionUtils from "../../../../utils/FunctionUtils";
|
|
19
|
+
import ScopeUtils from "../../../../utils/ScopeUtils";
|
|
20
|
+
|
|
21
|
+
class QualifiedNameGenerator {
|
|
22
|
+
// ============================================================================
|
|
23
|
+
// Symbol-based methods (preferred)
|
|
24
|
+
// ============================================================================
|
|
25
|
+
|
|
26
|
+
/**
|
|
27
|
+
* Generate the C-style mangled name for a function.
|
|
28
|
+
*
|
|
29
|
+
* For global scope functions, returns the bare name (e.g., "main").
|
|
30
|
+
* For scoped functions, returns "Scope_name" (e.g., "Test_fillData").
|
|
31
|
+
* For nested scopes, returns "Outer_Inner_name" (e.g., "Outer_Inner_deepFunc").
|
|
32
|
+
*
|
|
33
|
+
* Delegates to FunctionUtils.getCMangledName() to avoid duplication.
|
|
34
|
+
*/
|
|
35
|
+
static forFunction(func: IFunctionSymbol): string {
|
|
36
|
+
return FunctionUtils.getCMangledName(func);
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
* Get the scope path as an array of scope names (outermost first).
|
|
41
|
+
*
|
|
42
|
+
* Returns empty array for global scope.
|
|
43
|
+
* Returns ["Test"] for scope "Test".
|
|
44
|
+
* Returns ["Outer", "Inner"] for scope "Outer.Inner".
|
|
45
|
+
*
|
|
46
|
+
* Delegates to ScopeUtils.getScopePath() to avoid duplication.
|
|
47
|
+
*/
|
|
48
|
+
static getScopePath(scope: IScopeSymbol): string[] {
|
|
49
|
+
return ScopeUtils.getScopePath(scope);
|
|
50
|
+
}
|
|
51
|
+
|
|
52
|
+
// ============================================================================
|
|
53
|
+
// String-based methods (for transition - use symbol-based when possible)
|
|
54
|
+
// ============================================================================
|
|
55
|
+
|
|
56
|
+
/**
|
|
57
|
+
* Generate a qualified function name from strings.
|
|
58
|
+
*
|
|
59
|
+
* Tries to look up the function in SymbolRegistry first.
|
|
60
|
+
* Falls back to simple string concatenation if not found.
|
|
61
|
+
*
|
|
62
|
+
* @param scopeName Scope name (e.g., "Test", "Outer.Inner") or undefined for global
|
|
63
|
+
* @param funcName Bare function name (e.g., "fillData")
|
|
64
|
+
* @returns C-mangled name (e.g., "Test_fillData")
|
|
65
|
+
*/
|
|
66
|
+
static forFunctionStrings(
|
|
67
|
+
scopeName: string | undefined,
|
|
68
|
+
funcName: string,
|
|
69
|
+
): string {
|
|
70
|
+
// Try SymbolRegistry first (using getScope to avoid creating orphaned scopes)
|
|
71
|
+
if (scopeName) {
|
|
72
|
+
const scope = SymbolRegistry.getScope(scopeName);
|
|
73
|
+
if (scope) {
|
|
74
|
+
const func = SymbolRegistry.resolveFunction(funcName, scope);
|
|
75
|
+
if (func) {
|
|
76
|
+
return this.forFunction(func);
|
|
77
|
+
}
|
|
78
|
+
}
|
|
79
|
+
} else {
|
|
80
|
+
const global = SymbolRegistry.getGlobalScope();
|
|
81
|
+
const func = SymbolRegistry.resolveFunction(funcName, global);
|
|
82
|
+
if (func) {
|
|
83
|
+
return this.forFunction(func);
|
|
84
|
+
}
|
|
85
|
+
}
|
|
86
|
+
|
|
87
|
+
// Fallback to string concatenation
|
|
88
|
+
if (!scopeName) {
|
|
89
|
+
return funcName;
|
|
90
|
+
}
|
|
91
|
+
// Convert dotted scope path to underscores
|
|
92
|
+
const scopePrefix = scopeName.replaceAll(".", "_");
|
|
93
|
+
return `${scopePrefix}_${funcName}`;
|
|
94
|
+
}
|
|
95
|
+
|
|
96
|
+
/**
|
|
97
|
+
* Generate a qualified name for any scoped member (variable, enum, etc.).
|
|
98
|
+
*
|
|
99
|
+
* This is a simple string concatenation helper for non-function members.
|
|
100
|
+
*
|
|
101
|
+
* @param scopeName Scope name or undefined for global
|
|
102
|
+
* @param memberName Member name
|
|
103
|
+
* @returns C-mangled name
|
|
104
|
+
*/
|
|
105
|
+
static forMember(scopeName: string | undefined, memberName: string): string {
|
|
106
|
+
if (!scopeName) {
|
|
107
|
+
return memberName;
|
|
108
|
+
}
|
|
109
|
+
const scopePrefix = scopeName.replaceAll(".", "_");
|
|
110
|
+
return `${scopePrefix}_${memberName}`;
|
|
111
|
+
}
|
|
112
|
+
}
|
|
113
|
+
|
|
114
|
+
export default QualifiedNameGenerator;
|
|
@@ -0,0 +1,183 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Tests for QualifiedNameGenerator
|
|
3
|
+
*
|
|
4
|
+
* QualifiedNameGenerator is the ONLY place that constructs C-style mangled names
|
|
5
|
+
* like "Test_fillData" from function symbols.
|
|
6
|
+
*/
|
|
7
|
+
import { describe, it, expect, beforeEach } from "vitest";
|
|
8
|
+
import QualifiedNameGenerator from "../QualifiedNameGenerator";
|
|
9
|
+
import SymbolRegistry from "../../../../state/SymbolRegistry";
|
|
10
|
+
import FunctionUtils from "../../../../../utils/FunctionUtils";
|
|
11
|
+
import TTypeUtils from "../../../../../utils/TTypeUtils";
|
|
12
|
+
|
|
13
|
+
describe("QualifiedNameGenerator", () => {
|
|
14
|
+
beforeEach(() => {
|
|
15
|
+
SymbolRegistry.reset();
|
|
16
|
+
});
|
|
17
|
+
|
|
18
|
+
describe("forFunction", () => {
|
|
19
|
+
it("returns bare name for global scope function", () => {
|
|
20
|
+
const global = SymbolRegistry.getGlobalScope();
|
|
21
|
+
const func = FunctionUtils.create({
|
|
22
|
+
name: "main",
|
|
23
|
+
scope: global,
|
|
24
|
+
parameters: [],
|
|
25
|
+
returnType: TTypeUtils.createPrimitive("i32"),
|
|
26
|
+
visibility: "public",
|
|
27
|
+
body: null,
|
|
28
|
+
sourceFile: "main.cnx",
|
|
29
|
+
sourceLine: 1,
|
|
30
|
+
});
|
|
31
|
+
|
|
32
|
+
expect(QualifiedNameGenerator.forFunction(func)).toBe("main");
|
|
33
|
+
});
|
|
34
|
+
|
|
35
|
+
it("returns Scope_name for scoped function", () => {
|
|
36
|
+
const scope = SymbolRegistry.getOrCreateScope("Test");
|
|
37
|
+
const func = FunctionUtils.create({
|
|
38
|
+
name: "fillData",
|
|
39
|
+
scope,
|
|
40
|
+
parameters: [],
|
|
41
|
+
returnType: TTypeUtils.createPrimitive("void"),
|
|
42
|
+
visibility: "private",
|
|
43
|
+
body: null,
|
|
44
|
+
sourceFile: "test.cnx",
|
|
45
|
+
sourceLine: 1,
|
|
46
|
+
});
|
|
47
|
+
|
|
48
|
+
expect(QualifiedNameGenerator.forFunction(func)).toBe("Test_fillData");
|
|
49
|
+
});
|
|
50
|
+
|
|
51
|
+
it("returns Outer_Inner_name for nested scope function", () => {
|
|
52
|
+
const scope = SymbolRegistry.getOrCreateScope("Outer.Inner");
|
|
53
|
+
const func = FunctionUtils.create({
|
|
54
|
+
name: "deepFunc",
|
|
55
|
+
scope,
|
|
56
|
+
parameters: [],
|
|
57
|
+
returnType: TTypeUtils.createPrimitive("void"),
|
|
58
|
+
visibility: "private",
|
|
59
|
+
body: null,
|
|
60
|
+
sourceFile: "test.cnx",
|
|
61
|
+
sourceLine: 1,
|
|
62
|
+
});
|
|
63
|
+
|
|
64
|
+
expect(QualifiedNameGenerator.forFunction(func)).toBe(
|
|
65
|
+
"Outer_Inner_deepFunc",
|
|
66
|
+
);
|
|
67
|
+
});
|
|
68
|
+
|
|
69
|
+
it("returns deeply nested path for 3-level scope", () => {
|
|
70
|
+
const scope = SymbolRegistry.getOrCreateScope("A.B.C");
|
|
71
|
+
const func = FunctionUtils.create({
|
|
72
|
+
name: "veryDeep",
|
|
73
|
+
scope,
|
|
74
|
+
parameters: [],
|
|
75
|
+
returnType: TTypeUtils.createPrimitive("void"),
|
|
76
|
+
visibility: "public",
|
|
77
|
+
body: null,
|
|
78
|
+
sourceFile: "test.cnx",
|
|
79
|
+
sourceLine: 1,
|
|
80
|
+
});
|
|
81
|
+
|
|
82
|
+
expect(QualifiedNameGenerator.forFunction(func)).toBe("A_B_C_veryDeep");
|
|
83
|
+
});
|
|
84
|
+
});
|
|
85
|
+
|
|
86
|
+
describe("getScopePath", () => {
|
|
87
|
+
it("returns empty array for global scope", () => {
|
|
88
|
+
const global = SymbolRegistry.getGlobalScope();
|
|
89
|
+
expect(QualifiedNameGenerator.getScopePath(global)).toEqual([]);
|
|
90
|
+
});
|
|
91
|
+
|
|
92
|
+
it("returns single element for direct child of global", () => {
|
|
93
|
+
const scope = SymbolRegistry.getOrCreateScope("Test");
|
|
94
|
+
expect(QualifiedNameGenerator.getScopePath(scope)).toEqual(["Test"]);
|
|
95
|
+
});
|
|
96
|
+
|
|
97
|
+
it("returns full path for nested scope", () => {
|
|
98
|
+
const scope = SymbolRegistry.getOrCreateScope("A.B.C");
|
|
99
|
+
expect(QualifiedNameGenerator.getScopePath(scope)).toEqual([
|
|
100
|
+
"A",
|
|
101
|
+
"B",
|
|
102
|
+
"C",
|
|
103
|
+
]);
|
|
104
|
+
});
|
|
105
|
+
|
|
106
|
+
it("returns path in correct order (outermost first)", () => {
|
|
107
|
+
const scope = SymbolRegistry.getOrCreateScope("Outer.Middle.Inner");
|
|
108
|
+
expect(QualifiedNameGenerator.getScopePath(scope)).toEqual([
|
|
109
|
+
"Outer",
|
|
110
|
+
"Middle",
|
|
111
|
+
"Inner",
|
|
112
|
+
]);
|
|
113
|
+
});
|
|
114
|
+
});
|
|
115
|
+
|
|
116
|
+
describe("forFunctionStrings", () => {
|
|
117
|
+
it("returns bare name for undefined scope", () => {
|
|
118
|
+
expect(QualifiedNameGenerator.forFunctionStrings(undefined, "main")).toBe(
|
|
119
|
+
"main",
|
|
120
|
+
);
|
|
121
|
+
});
|
|
122
|
+
|
|
123
|
+
it("returns mangled name for simple scope", () => {
|
|
124
|
+
expect(
|
|
125
|
+
QualifiedNameGenerator.forFunctionStrings("Test", "fillData"),
|
|
126
|
+
).toBe("Test_fillData");
|
|
127
|
+
});
|
|
128
|
+
|
|
129
|
+
it("converts dotted scope to underscores", () => {
|
|
130
|
+
expect(
|
|
131
|
+
QualifiedNameGenerator.forFunctionStrings("Outer.Inner", "func"),
|
|
132
|
+
).toBe("Outer_Inner_func");
|
|
133
|
+
});
|
|
134
|
+
|
|
135
|
+
it("uses SymbolRegistry when function is registered", () => {
|
|
136
|
+
// Register a function in SymbolRegistry
|
|
137
|
+
const scope = SymbolRegistry.getOrCreateScope("Motor");
|
|
138
|
+
const func = FunctionUtils.create({
|
|
139
|
+
name: "init",
|
|
140
|
+
scope,
|
|
141
|
+
parameters: [],
|
|
142
|
+
returnType: TTypeUtils.createPrimitive("void"),
|
|
143
|
+
visibility: "public",
|
|
144
|
+
body: null,
|
|
145
|
+
sourceFile: "motor.cnx",
|
|
146
|
+
sourceLine: 1,
|
|
147
|
+
});
|
|
148
|
+
SymbolRegistry.registerFunction(func);
|
|
149
|
+
|
|
150
|
+
// forFunctionStrings should find it via SymbolRegistry
|
|
151
|
+
expect(QualifiedNameGenerator.forFunctionStrings("Motor", "init")).toBe(
|
|
152
|
+
"Motor_init",
|
|
153
|
+
);
|
|
154
|
+
});
|
|
155
|
+
|
|
156
|
+
it("falls back to string concat when function not in registry", () => {
|
|
157
|
+
// Don't register the function - should fall back to string concat
|
|
158
|
+
expect(QualifiedNameGenerator.forFunctionStrings("Unknown", "func")).toBe(
|
|
159
|
+
"Unknown_func",
|
|
160
|
+
);
|
|
161
|
+
});
|
|
162
|
+
});
|
|
163
|
+
|
|
164
|
+
describe("forMember", () => {
|
|
165
|
+
it("returns bare name for undefined scope", () => {
|
|
166
|
+
expect(QualifiedNameGenerator.forMember(undefined, "value")).toBe(
|
|
167
|
+
"value",
|
|
168
|
+
);
|
|
169
|
+
});
|
|
170
|
+
|
|
171
|
+
it("returns mangled name for simple scope", () => {
|
|
172
|
+
expect(QualifiedNameGenerator.forMember("Test", "counter")).toBe(
|
|
173
|
+
"Test_counter",
|
|
174
|
+
);
|
|
175
|
+
});
|
|
176
|
+
|
|
177
|
+
it("converts dotted scope to underscores", () => {
|
|
178
|
+
expect(QualifiedNameGenerator.forMember("Outer.Inner", "data")).toBe(
|
|
179
|
+
"Outer_Inner_data",
|
|
180
|
+
);
|
|
181
|
+
});
|
|
182
|
+
});
|
|
183
|
+
});
|
|
@@ -6,7 +6,7 @@
|
|
|
6
6
|
* determine pointer (*) vs reference (&) semantics.
|
|
7
7
|
*/
|
|
8
8
|
|
|
9
|
-
import
|
|
9
|
+
import IHeaderSymbol from "./types/IHeaderSymbol";
|
|
10
10
|
import IParameterSymbol from "../../../utils/types/IParameterSymbol";
|
|
11
11
|
import IHeaderOptions from "../codegen/types/IHeaderOptions";
|
|
12
12
|
import IHeaderTypeInput from "./generators/IHeaderTypeInput";
|
|
@@ -40,7 +40,7 @@ abstract class BaseHeaderGenerator {
|
|
|
40
40
|
* Generate a header file from symbols
|
|
41
41
|
*/
|
|
42
42
|
generate(
|
|
43
|
-
symbols:
|
|
43
|
+
symbols: IHeaderSymbol[],
|
|
44
44
|
filename: string,
|
|
45
45
|
options: IHeaderOptions = {},
|
|
46
46
|
typeInput?: IHeaderTypeInput,
|
|
@@ -128,7 +128,7 @@ abstract class BaseHeaderGenerator {
|
|
|
128
128
|
* Generate function prototypes section
|
|
129
129
|
*/
|
|
130
130
|
private generateFunctionSection(
|
|
131
|
-
functions:
|
|
131
|
+
functions: IHeaderSymbol[],
|
|
132
132
|
passByValueParams?: TPassByValueParams,
|
|
133
133
|
allKnownEnums?: ReadonlySet<string>,
|
|
134
134
|
): string[] {
|
|
@@ -155,7 +155,7 @@ abstract class BaseHeaderGenerator {
|
|
|
155
155
|
* Generate a function prototype
|
|
156
156
|
*/
|
|
157
157
|
private generateFunctionPrototype(
|
|
158
|
-
sym:
|
|
158
|
+
sym: IHeaderSymbol,
|
|
159
159
|
passByValueParams?: TPassByValueParams,
|
|
160
160
|
allKnownEnums?: ReadonlySet<string>,
|
|
161
161
|
): string | null {
|
|
@@ -5,16 +5,16 @@
|
|
|
5
5
|
* Issue #589: Extracted from Transpiler.buildExternalTypeHeaders()
|
|
6
6
|
* Issue #497: Enables header generation to include original C headers instead of
|
|
7
7
|
* generating conflicting forward declarations for types like anonymous struct typedefs.
|
|
8
|
+
* ADR-055 Phase 7: Uses TAnySymbol instead of ISymbol.
|
|
8
9
|
*/
|
|
9
10
|
|
|
10
|
-
import
|
|
11
|
-
import ISymbol from "../../../utils/types/ISymbol";
|
|
11
|
+
import TAnySymbol from "../../types/symbols/TAnySymbol";
|
|
12
12
|
|
|
13
13
|
/**
|
|
14
14
|
* Interface for accessing symbols by file path
|
|
15
15
|
*/
|
|
16
16
|
interface ISymbolSource {
|
|
17
|
-
getSymbolsByFile(filePath: string):
|
|
17
|
+
getSymbolsByFile(filePath: string): TAnySymbol[];
|
|
18
18
|
}
|
|
19
19
|
|
|
20
20
|
/**
|
|
@@ -45,10 +45,10 @@ class ExternalTypeHeaderBuilder {
|
|
|
45
45
|
// Map each struct/type/enum name to the include directive
|
|
46
46
|
for (const sym of symbols) {
|
|
47
47
|
if (
|
|
48
|
-
sym.kind ===
|
|
49
|
-
sym.kind ===
|
|
50
|
-
sym.kind ===
|
|
51
|
-
sym.kind ===
|
|
48
|
+
sym.kind === "struct" ||
|
|
49
|
+
sym.kind === "type" ||
|
|
50
|
+
sym.kind === "enum" ||
|
|
51
|
+
sym.kind === "class"
|
|
52
52
|
) {
|
|
53
53
|
// Only add if we don't already have a mapping (first include wins)
|
|
54
54
|
if (!typeHeaders.has(sym.name)) {
|
|
@@ -5,9 +5,9 @@
|
|
|
5
5
|
* Maintains backward-compatible API.
|
|
6
6
|
*/
|
|
7
7
|
|
|
8
|
-
import
|
|
9
|
-
import ESourceLanguage from "../../../utils/types/ESourceLanguage";
|
|
8
|
+
import IHeaderSymbol from "./types/IHeaderSymbol";
|
|
10
9
|
import SymbolTable from "../../logic/symbols/SymbolTable";
|
|
10
|
+
import HeaderSymbolAdapter from "./adapters/HeaderSymbolAdapter";
|
|
11
11
|
import IHeaderOptions from "../codegen/types/IHeaderOptions";
|
|
12
12
|
import IHeaderTypeInput from "./generators/IHeaderTypeInput";
|
|
13
13
|
import CHeaderGenerator from "./CHeaderGenerator";
|
|
@@ -39,7 +39,7 @@ class HeaderGenerator {
|
|
|
39
39
|
* @param allKnownEnums - All known enum names from entire compilation
|
|
40
40
|
*/
|
|
41
41
|
generate(
|
|
42
|
-
symbols:
|
|
42
|
+
symbols: IHeaderSymbol[],
|
|
43
43
|
filename: string,
|
|
44
44
|
options: IHeaderOptions = {},
|
|
45
45
|
typeInput?: IHeaderTypeInput,
|
|
@@ -66,11 +66,12 @@ class HeaderGenerator {
|
|
|
66
66
|
sourceFile: string,
|
|
67
67
|
options: IHeaderOptions = {},
|
|
68
68
|
): string {
|
|
69
|
-
const
|
|
69
|
+
const tSymbols = symbolTable.getTSymbolsByFile(sourceFile);
|
|
70
|
+
const headerSymbols = HeaderSymbolAdapter.fromTSymbols(tSymbols);
|
|
70
71
|
const basename = sourceFile.replace(/\.[^.]+$/, "");
|
|
71
72
|
const headerName = `${basename}.h`;
|
|
72
73
|
|
|
73
|
-
return this.generate(
|
|
74
|
+
return this.generate(headerSymbols, headerName, options);
|
|
74
75
|
}
|
|
75
76
|
|
|
76
77
|
/**
|
|
@@ -81,8 +82,9 @@ class HeaderGenerator {
|
|
|
81
82
|
filename: string,
|
|
82
83
|
options: IHeaderOptions = {},
|
|
83
84
|
): string {
|
|
84
|
-
const
|
|
85
|
-
|
|
85
|
+
const tSymbols = symbolTable.getAllTSymbols();
|
|
86
|
+
const headerSymbols = HeaderSymbolAdapter.fromTSymbols(tSymbols);
|
|
87
|
+
return this.generate(headerSymbols, filename, options);
|
|
86
88
|
}
|
|
87
89
|
}
|
|
88
90
|
|
|
@@ -5,8 +5,7 @@
|
|
|
5
5
|
* CHeaderGenerator and CppHeaderGenerator.
|
|
6
6
|
*/
|
|
7
7
|
|
|
8
|
-
import
|
|
9
|
-
import ESymbolKind from "../../../utils/types/ESymbolKind";
|
|
8
|
+
import IHeaderSymbol from "./types/IHeaderSymbol";
|
|
10
9
|
import SymbolTable from "../../logic/symbols/SymbolTable";
|
|
11
10
|
import CppNamespaceUtils from "../../../utils/CppNamespaceUtils";
|
|
12
11
|
import typeUtils from "./generators/mapType";
|
|
@@ -45,15 +44,15 @@ class HeaderGeneratorUtils {
|
|
|
45
44
|
/**
|
|
46
45
|
* Group symbols by their kind for organized header output
|
|
47
46
|
*/
|
|
48
|
-
static groupSymbolsByKind(symbols:
|
|
47
|
+
static groupSymbolsByKind(symbols: IHeaderSymbol[]): IGroupedSymbols {
|
|
49
48
|
return {
|
|
50
|
-
structs: symbols.filter((s) => s.kind ===
|
|
51
|
-
classes: symbols.filter((s) => s.kind ===
|
|
52
|
-
functions: symbols.filter((s) => s.kind ===
|
|
53
|
-
variables: symbols.filter((s) => s.kind ===
|
|
54
|
-
enums: symbols.filter((s) => s.kind ===
|
|
55
|
-
types: symbols.filter((s) => s.kind ===
|
|
56
|
-
bitmaps: symbols.filter((s) => s.kind ===
|
|
49
|
+
structs: symbols.filter((s) => s.kind === "struct"),
|
|
50
|
+
classes: symbols.filter((s) => s.kind === "class"),
|
|
51
|
+
functions: symbols.filter((s) => s.kind === "function"),
|
|
52
|
+
variables: symbols.filter((s) => s.kind === "variable"),
|
|
53
|
+
enums: symbols.filter((s) => s.kind === "enum"),
|
|
54
|
+
types: symbols.filter((s) => s.kind === "type"),
|
|
55
|
+
bitmaps: symbols.filter((s) => s.kind === "bitmap"),
|
|
57
56
|
};
|
|
58
57
|
}
|
|
59
58
|
|
|
@@ -112,8 +111,8 @@ class HeaderGeneratorUtils {
|
|
|
112
111
|
* - Not cross-file enums (which can't be forward-declared as structs)
|
|
113
112
|
*/
|
|
114
113
|
static collectExternalTypes(
|
|
115
|
-
functions:
|
|
116
|
-
variables:
|
|
114
|
+
functions: IHeaderSymbol[],
|
|
115
|
+
variables: IHeaderSymbol[],
|
|
117
116
|
localStructs: Set<string>,
|
|
118
117
|
localEnums: Set<string>,
|
|
119
118
|
localTypes: Set<string>,
|
|
@@ -192,9 +191,9 @@ class HeaderGeneratorUtils {
|
|
|
192
191
|
* Excludes C++ namespace types, templates, and underscore-format namespace types
|
|
193
192
|
*/
|
|
194
193
|
static filterCCompatibleVariables(
|
|
195
|
-
variables:
|
|
194
|
+
variables: IHeaderSymbol[],
|
|
196
195
|
symbolTable?: SymbolTable,
|
|
197
|
-
):
|
|
196
|
+
): IHeaderSymbol[] {
|
|
198
197
|
return variables.filter(
|
|
199
198
|
(v) =>
|
|
200
199
|
!v.type?.includes("::") &&
|
|
@@ -331,7 +330,7 @@ class HeaderGeneratorUtils {
|
|
|
331
330
|
* Generate enum section
|
|
332
331
|
*/
|
|
333
332
|
static generateEnumSection(
|
|
334
|
-
enums:
|
|
333
|
+
enums: IHeaderSymbol[],
|
|
335
334
|
typeInput?: IHeaderTypeInput,
|
|
336
335
|
): string[] {
|
|
337
336
|
if (enums.length === 0) {
|
|
@@ -354,7 +353,7 @@ class HeaderGeneratorUtils {
|
|
|
354
353
|
* Generate bitmap section
|
|
355
354
|
*/
|
|
356
355
|
static generateBitmapSection(
|
|
357
|
-
bitmaps:
|
|
356
|
+
bitmaps: IHeaderSymbol[],
|
|
358
357
|
typeInput?: IHeaderTypeInput,
|
|
359
358
|
): string[] {
|
|
360
359
|
if (bitmaps.length === 0) {
|
|
@@ -376,7 +375,7 @@ class HeaderGeneratorUtils {
|
|
|
376
375
|
/**
|
|
377
376
|
* Generate type alias section
|
|
378
377
|
*/
|
|
379
|
-
static generateTypeAliasSection(types:
|
|
378
|
+
static generateTypeAliasSection(types: IHeaderSymbol[]): string[] {
|
|
380
379
|
if (types.length === 0) {
|
|
381
380
|
return [];
|
|
382
381
|
}
|
|
@@ -396,8 +395,8 @@ class HeaderGeneratorUtils {
|
|
|
396
395
|
* Generate struct and class definitions section
|
|
397
396
|
*/
|
|
398
397
|
static generateStructSection(
|
|
399
|
-
structs:
|
|
400
|
-
classes:
|
|
398
|
+
structs: IHeaderSymbol[],
|
|
399
|
+
classes: IHeaderSymbol[],
|
|
401
400
|
typeInput?: IHeaderTypeInput,
|
|
402
401
|
): string[] {
|
|
403
402
|
if (structs.length === 0 && classes.length === 0) {
|
|
@@ -432,7 +431,7 @@ class HeaderGeneratorUtils {
|
|
|
432
431
|
*
|
|
433
432
|
* Uses VariableDeclarationFormatter for consistent formatting with CodeGenerator.
|
|
434
433
|
*/
|
|
435
|
-
static generateVariableSection(variables:
|
|
434
|
+
static generateVariableSection(variables: IHeaderSymbol[]): string[] {
|
|
436
435
|
if (variables.length === 0) {
|
|
437
436
|
return [];
|
|
438
437
|
}
|