c-next 0.1.70 → 0.1.72
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/src/lib/__tests__/parseCHeader.mocked.test.ts +69 -54
- package/src/lib/parseCHeader.ts +56 -23
- package/src/lib/parseWithSymbols.ts +195 -53
- package/src/transpiler/Transpiler.ts +180 -63
- package/src/transpiler/logic/analysis/FunctionCallAnalyzer.ts +1 -2
- package/src/transpiler/logic/analysis/InitializationAnalyzer.ts +1 -2
- package/src/transpiler/logic/analysis/PassByValueAnalyzer.ts +51 -2
- package/src/transpiler/logic/analysis/__tests__/FunctionCallAnalyzer.test.ts +18 -12
- package/src/transpiler/logic/analysis/__tests__/InitializationAnalyzer.test.ts +9 -9
- package/src/transpiler/logic/analysis/__tests__/runAnalyzers.test.ts +5 -5
- package/src/transpiler/logic/symbols/SymbolTable.ts +729 -265
- package/src/transpiler/logic/symbols/SymbolUtils.ts +2 -2
- package/src/transpiler/logic/symbols/__tests__/SymbolTable.test.ts +415 -751
- package/src/transpiler/logic/symbols/c/__tests__/CResolver.integration.test.ts +573 -0
- package/src/transpiler/logic/symbols/c/__tests__/testHelpers.ts +20 -0
- package/src/transpiler/logic/symbols/c/collectors/EnumCollector.ts +82 -0
- package/src/transpiler/logic/symbols/c/collectors/FunctionCollector.ts +106 -0
- package/src/transpiler/logic/symbols/c/collectors/StructCollector.ts +173 -0
- package/src/transpiler/logic/symbols/c/collectors/TypedefCollector.ts +35 -0
- package/src/transpiler/logic/symbols/c/collectors/VariableCollector.ts +80 -0
- package/src/transpiler/logic/symbols/c/index.ts +333 -0
- package/src/transpiler/logic/symbols/c/utils/DeclaratorUtils.ts +269 -0
- package/src/transpiler/logic/symbols/cnext/__tests__/BitmapCollector.test.ts +50 -11
- package/src/transpiler/logic/symbols/cnext/__tests__/CNextResolver.integration.test.ts +45 -34
- package/src/transpiler/logic/symbols/cnext/__tests__/EnumCollector.test.ts +30 -13
- package/src/transpiler/logic/symbols/cnext/__tests__/FunctionCollector.test.ts +279 -64
- package/src/transpiler/logic/symbols/cnext/__tests__/RegisterCollector.test.ts +60 -13
- package/src/transpiler/logic/symbols/cnext/__tests__/ScopeCollector.test.ts +40 -37
- package/src/transpiler/logic/symbols/cnext/__tests__/StructCollector.test.ts +131 -45
- package/src/transpiler/logic/symbols/cnext/__tests__/TSymbolInfoAdapter.test.ts +223 -139
- package/src/transpiler/logic/symbols/cnext/__tests__/VariableCollector.test.ts +79 -25
- package/src/transpiler/logic/symbols/cnext/__tests__/testUtils.ts +53 -0
- package/src/transpiler/logic/symbols/cnext/adapters/TSymbolInfoAdapter.ts +83 -43
- package/src/transpiler/logic/symbols/cnext/collectors/BitmapCollector.ts +14 -13
- package/src/transpiler/logic/symbols/cnext/collectors/EnumCollector.ts +11 -10
- package/src/transpiler/logic/symbols/cnext/collectors/FunctionCollector.ts +83 -34
- package/src/transpiler/logic/symbols/cnext/collectors/RegisterCollector.ts +22 -18
- package/src/transpiler/logic/symbols/cnext/collectors/ScopeCollector.ts +53 -35
- package/src/transpiler/logic/symbols/cnext/collectors/StructCollector.ts +30 -23
- package/src/transpiler/logic/symbols/cnext/collectors/VariableCollector.ts +18 -19
- package/src/transpiler/logic/symbols/cnext/index.ts +36 -14
- package/src/transpiler/logic/symbols/cnext/types/IScopeCollectorResult.ts +2 -2
- package/src/transpiler/logic/symbols/cnext/utils/SymbolNameUtils.ts +27 -0
- package/src/transpiler/logic/symbols/cpp/__tests__/CppResolver.integration.test.ts +270 -0
- package/src/transpiler/logic/symbols/cpp/__tests__/testHelpers.ts +20 -0
- package/src/transpiler/logic/symbols/cpp/collectors/ClassCollector.ts +317 -0
- package/src/transpiler/logic/symbols/cpp/collectors/EnumCollector.ts +71 -0
- package/src/transpiler/logic/symbols/cpp/collectors/FunctionCollector.ts +155 -0
- package/src/transpiler/logic/symbols/cpp/collectors/NamespaceCollector.ts +65 -0
- package/src/transpiler/logic/symbols/cpp/collectors/TypeAliasCollector.ts +46 -0
- package/src/transpiler/logic/symbols/cpp/collectors/VariableCollector.ts +54 -0
- package/src/transpiler/logic/symbols/cpp/index.ts +366 -0
- package/src/transpiler/logic/symbols/cpp/utils/DeclaratorUtils.ts +248 -0
- package/src/transpiler/logic/symbols/shared/IExtractedParameter.ts +18 -0
- package/src/transpiler/logic/symbols/shared/ParameterExtractorUtils.ts +73 -0
- package/src/transpiler/output/codegen/CodeGenerator.ts +268 -1674
- package/src/transpiler/output/codegen/__tests__/CodeGenerator.test.ts +7 -1
- package/src/transpiler/output/codegen/assignment/AssignmentClassifier.ts +2 -1
- package/src/transpiler/output/codegen/assignment/handlers/AssignmentHandlerUtils.ts +7 -1
- package/src/transpiler/output/codegen/assignment/handlers/BitmapHandlers.ts +6 -2
- package/src/transpiler/output/codegen/assignment/handlers/RegisterHandlers.ts +2 -1
- package/src/transpiler/output/codegen/generators/declarationGenerators/ScopeGenerator.ts +21 -8
- package/src/transpiler/output/codegen/generators/declarationGenerators/ScopedRegisterGenerator.ts +3 -2
- package/src/transpiler/output/codegen/generators/expressions/CallExprUtils.ts +9 -3
- package/src/transpiler/output/codegen/generators/expressions/__tests__/CallExprGenerator.test.ts +3 -4
- package/src/transpiler/output/codegen/generators/expressions/__tests__/CallExprUtils.test.ts +4 -8
- package/src/transpiler/output/codegen/helpers/ArgumentGenerator.ts +236 -0
- package/src/transpiler/output/codegen/helpers/CppConstructorHelper.ts +3 -3
- package/src/transpiler/output/codegen/helpers/FunctionContextManager.ts +435 -0
- package/src/transpiler/output/codegen/helpers/StringOperationsHelper.ts +203 -0
- package/src/transpiler/output/codegen/helpers/SymbolLookupHelper.ts +8 -12
- package/src/transpiler/output/codegen/helpers/TypeRegistrationEngine.ts +520 -0
- package/src/transpiler/output/codegen/helpers/VariableDeclHelper.ts +735 -0
- package/src/transpiler/output/codegen/helpers/VariableDeclarationFormatter.ts +1 -1
- package/src/transpiler/output/codegen/helpers/__tests__/ArgumentGenerator.test.ts +521 -0
- package/src/transpiler/output/codegen/helpers/__tests__/CppConstructorHelper.test.ts +4 -5
- package/src/transpiler/output/codegen/helpers/__tests__/FunctionContextManager.test.ts +983 -0
- package/src/transpiler/output/codegen/helpers/__tests__/StringOperationsHelper.test.ts +269 -0
- package/src/transpiler/output/codegen/helpers/__tests__/SymbolLookupHelper.test.ts +31 -32
- package/src/transpiler/output/codegen/helpers/__tests__/TypeRegistrationEngine.test.ts +186 -0
- package/src/transpiler/output/codegen/helpers/__tests__/VariableDeclHelper.test.ts +460 -0
- package/src/transpiler/output/codegen/helpers/types/IArgumentGeneratorCallbacks.ts +32 -0
- package/src/transpiler/output/codegen/resolution/EnumTypeResolver.ts +5 -1
- package/src/transpiler/output/codegen/types/IFunctionContextCallbacks.ts +12 -0
- package/src/transpiler/output/codegen/types/IVariableFormatInput.ts +1 -1
- package/src/transpiler/output/codegen/utils/QualifiedNameGenerator.ts +114 -0
- package/src/transpiler/output/codegen/utils/__tests__/QualifiedNameGenerator.test.ts +183 -0
- package/src/transpiler/output/headers/BaseHeaderGenerator.ts +4 -4
- package/src/transpiler/output/headers/ExternalTypeHeaderBuilder.ts +7 -7
- package/src/transpiler/output/headers/HeaderGenerator.ts +9 -7
- package/src/transpiler/output/headers/HeaderGeneratorUtils.ts +19 -20
- package/src/transpiler/output/headers/__tests__/BaseHeaderGenerator.test.ts +15 -18
- package/src/transpiler/output/headers/__tests__/CHeaderGenerator.test.ts +63 -64
- package/src/transpiler/output/headers/__tests__/CppHeaderGenerator.test.ts +36 -32
- package/src/transpiler/output/headers/__tests__/ExternalTypeHeaderBuilder.test.ts +26 -26
- package/src/transpiler/output/headers/__tests__/HeaderGenerator.test.ts +87 -59
- package/src/transpiler/output/headers/__tests__/HeaderGeneratorUtils.test.ts +57 -58
- package/src/transpiler/output/headers/adapters/HeaderSymbolAdapter.ts +222 -0
- package/src/transpiler/output/headers/adapters/__tests__/HeaderSymbolAdapter.test.ts +538 -0
- package/src/transpiler/output/headers/types/IGroupedSymbols.ts +8 -8
- package/src/transpiler/output/headers/types/IHeaderSymbol.ts +62 -0
- package/src/transpiler/state/CodeGenState.ts +20 -33
- package/src/transpiler/state/SymbolRegistry.ts +181 -0
- package/src/transpiler/{types → state}/TranspilerState.ts +1 -1
- package/src/transpiler/state/__tests__/CodeGenState.test.ts +67 -59
- package/src/transpiler/state/__tests__/SymbolRegistry.test.ts +249 -0
- package/src/transpiler/{types → state}/__tests__/TranspilerState.test.ts +1 -1
- package/src/transpiler/types/ICachedFileEntry.ts +1 -1
- package/src/transpiler/types/IConflict.ts +14 -0
- package/src/transpiler/types/IPipelineInput.ts +0 -3
- package/src/transpiler/types/ISerializedSymbol.ts +11 -0
- package/src/transpiler/types/TPrimitiveKind.ts +20 -0
- package/src/transpiler/types/TType.ts +103 -0
- package/src/transpiler/types/TVisibility.ts +6 -0
- package/src/transpiler/types/symbol-kinds/TSymbolKind.ts +10 -0
- package/src/transpiler/types/symbol-kinds/TSymbolKindC.ts +12 -0
- package/src/transpiler/types/symbol-kinds/TSymbolKindCNext.ts +16 -0
- package/src/transpiler/types/symbol-kinds/TSymbolKindCpp.ts +14 -0
- package/src/transpiler/types/symbols/IBaseSymbol.ts +31 -0
- package/src/transpiler/{logic/symbols/types → types/symbols}/IBitmapFieldInfo.ts +2 -2
- package/src/transpiler/types/symbols/IBitmapSymbol.ts +21 -0
- package/src/transpiler/{logic/symbols/types → types/symbols}/IEnumSymbol.ts +5 -6
- package/src/transpiler/types/symbols/IFieldInfo.ts +26 -0
- package/src/transpiler/types/symbols/IFunctionSymbol.ts +30 -0
- package/src/transpiler/types/symbols/IParameterInfo.ts +26 -0
- package/src/transpiler/{logic/symbols/types → types/symbols}/IRegisterMemberInfo.ts +4 -4
- package/src/transpiler/types/symbols/IRegisterSymbol.ts +18 -0
- package/src/transpiler/types/symbols/IScopeSymbol.ts +32 -0
- package/src/transpiler/{logic/symbols/types → types/symbols}/IStructFieldInfo.ts +2 -1
- package/src/transpiler/types/symbols/IStructSymbol.ts +15 -0
- package/src/transpiler/types/symbols/IVariableSymbol.ts +30 -0
- package/src/transpiler/types/symbols/SymbolGuards.ts +43 -0
- package/src/transpiler/types/symbols/TAnySymbol.ts +22 -0
- package/src/transpiler/types/symbols/TSymbol.ts +32 -0
- package/src/transpiler/types/symbols/__tests__/IBaseSymbol.test.ts +56 -0
- package/src/transpiler/types/symbols/__tests__/SymbolGuards.test.ts +57 -0
- package/src/transpiler/types/symbols/c/ICBaseSymbol.ts +28 -0
- package/src/transpiler/types/symbols/c/ICEnumMemberSymbol.ts +17 -0
- package/src/transpiler/types/symbols/c/ICEnumSymbol.ts +17 -0
- package/src/transpiler/types/symbols/c/ICFieldInfo.ts +16 -0
- package/src/transpiler/types/symbols/c/ICFunctionSymbol.ts +21 -0
- package/src/transpiler/types/symbols/c/ICParameterInfo.ts +19 -0
- package/src/transpiler/types/symbols/c/ICStructSymbol.ts +21 -0
- package/src/transpiler/types/symbols/c/ICTypedefSymbol.ts +14 -0
- package/src/transpiler/types/symbols/c/ICVariableSymbol.ts +26 -0
- package/src/transpiler/types/symbols/c/TCSymbol.ts +26 -0
- package/src/transpiler/types/symbols/cpp/ICppBaseSymbol.ts +31 -0
- package/src/transpiler/types/symbols/cpp/ICppClassSymbol.ts +15 -0
- package/src/transpiler/types/symbols/cpp/ICppEnumMemberSymbol.ts +14 -0
- package/src/transpiler/types/symbols/cpp/ICppEnumSymbol.ts +14 -0
- package/src/transpiler/types/symbols/cpp/ICppFieldInfo.ts +16 -0
- package/src/transpiler/types/symbols/cpp/ICppFunctionSymbol.ts +21 -0
- package/src/transpiler/types/symbols/cpp/ICppNamespaceSymbol.ts +11 -0
- package/src/transpiler/types/symbols/cpp/ICppParameterInfo.ts +19 -0
- package/src/transpiler/types/symbols/cpp/ICppStructSymbol.ts +16 -0
- package/src/transpiler/types/symbols/cpp/ICppTypeAliasSymbol.ts +14 -0
- package/src/transpiler/types/symbols/cpp/ICppVariableSymbol.ts +23 -0
- package/src/transpiler/types/symbols/cpp/TCppSymbol.ts +30 -0
- package/src/utils/CppNamespaceUtils.ts +3 -4
- package/src/utils/FunctionUtils.ts +92 -0
- package/src/utils/ParameterUtils.ts +55 -0
- package/src/utils/PrimitiveKindUtils.ts +33 -0
- package/src/utils/ScopeUtils.ts +105 -0
- package/src/utils/TTypeUtils.ts +159 -0
- package/src/utils/TypeResolver.ts +132 -0
- package/src/utils/__tests__/CppNamespaceUtils.test.ts +92 -99
- package/src/utils/__tests__/FunctionUtils.test.ts +284 -0
- package/src/utils/__tests__/ParameterUtils.test.ts +174 -0
- package/src/utils/__tests__/PrimitiveKindUtils.test.ts +59 -0
- package/src/utils/__tests__/ScopeUtils.test.ts +53 -0
- package/src/utils/__tests__/TTypeUtils.test.ts +245 -0
- package/src/utils/__tests__/TypeResolver.test.ts +332 -0
- package/src/utils/cache/CacheManager.ts +91 -50
- package/src/utils/cache/__tests__/CacheManager.test.ts +180 -114
- package/src/transpiler/logic/symbols/AutoConstUpdater.ts +0 -93
- package/src/transpiler/logic/symbols/CSymbolCollector.ts +0 -648
- package/src/transpiler/logic/symbols/CppSymbolCollector.ts +0 -874
- package/src/transpiler/logic/symbols/SymbolCollectorContext.ts +0 -68
- package/src/transpiler/logic/symbols/__tests__/AutoConstUpdater.test.ts +0 -418
- package/src/transpiler/logic/symbols/__tests__/CSymbolCollector.test.ts +0 -685
- package/src/transpiler/logic/symbols/__tests__/CppSymbolCollector.test.ts +0 -1146
- package/src/transpiler/logic/symbols/__tests__/SymbolCollectorContext.test.ts +0 -290
- package/src/transpiler/logic/symbols/__tests__/cTestHelpers.ts +0 -43
- package/src/transpiler/logic/symbols/__tests__/cppTestHelpers.ts +0 -40
- package/src/transpiler/logic/symbols/cnext/__tests__/TSymbolAdapter.test.ts +0 -595
- package/src/transpiler/logic/symbols/cnext/adapters/TSymbolAdapter.ts +0 -345
- package/src/transpiler/logic/symbols/types/IBaseSymbol.ts +0 -27
- package/src/transpiler/logic/symbols/types/IBitmapSymbol.ts +0 -23
- package/src/transpiler/logic/symbols/types/ICollectorContext.ts +0 -19
- package/src/transpiler/logic/symbols/types/IConflict.ts +0 -20
- package/src/transpiler/logic/symbols/types/IFieldInfo.ts +0 -18
- package/src/transpiler/logic/symbols/types/IFunctionSymbol.ts +0 -25
- package/src/transpiler/logic/symbols/types/IParameterInfo.ts +0 -24
- package/src/transpiler/logic/symbols/types/IRegisterSymbol.ts +0 -20
- package/src/transpiler/logic/symbols/types/IScopeSymbol.ts +0 -19
- package/src/transpiler/logic/symbols/types/IStructSymbol.ts +0 -16
- package/src/transpiler/logic/symbols/types/IVariableSymbol.ts +0 -30
- package/src/transpiler/logic/symbols/types/TSymbol.ts +0 -36
- package/src/transpiler/logic/symbols/types/__tests__/SymbolGuards.test.ts +0 -244
- package/src/transpiler/logic/symbols/types/typeGuards.ts +0 -44
- package/src/utils/types/ESymbolKind.ts +0 -19
- package/src/utils/types/ISymbol.ts +0 -64
- /package/src/transpiler/{types → constants}/BITMAP_BACKING_TYPE.ts +0 -0
- /package/src/transpiler/{types → constants}/BITMAP_SIZE.ts +0 -0
|
@@ -0,0 +1,21 @@
|
|
|
1
|
+
import type ICppBaseSymbol from "./ICppBaseSymbol";
|
|
2
|
+
import type ICppParameterInfo from "./ICppParameterInfo";
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Symbol representing a C++ function or method.
|
|
6
|
+
*/
|
|
7
|
+
interface ICppFunctionSymbol extends ICppBaseSymbol {
|
|
8
|
+
/** Discriminator narrowed to "function" */
|
|
9
|
+
readonly kind: "function";
|
|
10
|
+
|
|
11
|
+
/** Return type as string */
|
|
12
|
+
readonly type: string;
|
|
13
|
+
|
|
14
|
+
/** Function parameters */
|
|
15
|
+
readonly parameters?: ReadonlyArray<ICppParameterInfo>;
|
|
16
|
+
|
|
17
|
+
/** Whether this is a declaration vs definition */
|
|
18
|
+
readonly isDeclaration?: boolean;
|
|
19
|
+
}
|
|
20
|
+
|
|
21
|
+
export default ICppFunctionSymbol;
|
|
@@ -0,0 +1,11 @@
|
|
|
1
|
+
import type ICppBaseSymbol from "./ICppBaseSymbol";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Symbol representing a C++ namespace.
|
|
5
|
+
*/
|
|
6
|
+
interface ICppNamespaceSymbol extends ICppBaseSymbol {
|
|
7
|
+
/** Discriminator narrowed to "namespace" */
|
|
8
|
+
readonly kind: "namespace";
|
|
9
|
+
}
|
|
10
|
+
|
|
11
|
+
export default ICppNamespaceSymbol;
|
|
@@ -0,0 +1,19 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Parameter info for C++ functions.
|
|
3
|
+
* Uses simple strings for types since C++ types pass through unchanged.
|
|
4
|
+
*/
|
|
5
|
+
interface ICppParameterInfo {
|
|
6
|
+
/** Parameter name (may be empty for prototypes) */
|
|
7
|
+
readonly name: string;
|
|
8
|
+
|
|
9
|
+
/** Parameter type as string (e.g., "int", "const std::string&") */
|
|
10
|
+
readonly type: string;
|
|
11
|
+
|
|
12
|
+
/** Whether this parameter is const */
|
|
13
|
+
readonly isConst: boolean;
|
|
14
|
+
|
|
15
|
+
/** Whether this parameter is an array */
|
|
16
|
+
readonly isArray: boolean;
|
|
17
|
+
}
|
|
18
|
+
|
|
19
|
+
export default ICppParameterInfo;
|
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
import type ICppBaseSymbol from "./ICppBaseSymbol";
|
|
2
|
+
import type ICppFieldInfo from "./ICppFieldInfo";
|
|
3
|
+
|
|
4
|
+
/**
|
|
5
|
+
* Symbol representing a C++ struct type definition.
|
|
6
|
+
* In C++, structs are very similar to classes but with different default visibility.
|
|
7
|
+
*/
|
|
8
|
+
interface ICppStructSymbol extends ICppBaseSymbol {
|
|
9
|
+
/** Discriminator narrowed to "struct" */
|
|
10
|
+
readonly kind: "struct";
|
|
11
|
+
|
|
12
|
+
/** Map of field name to field metadata (only populated if SymbolTable was provided) */
|
|
13
|
+
readonly fields?: ReadonlyMap<string, ICppFieldInfo>;
|
|
14
|
+
}
|
|
15
|
+
|
|
16
|
+
export default ICppStructSymbol;
|
|
@@ -0,0 +1,14 @@
|
|
|
1
|
+
import type ICppBaseSymbol from "./ICppBaseSymbol";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Symbol representing a C++ type alias (using X = Y).
|
|
5
|
+
*/
|
|
6
|
+
interface ICppTypeAliasSymbol extends ICppBaseSymbol {
|
|
7
|
+
/** Discriminator narrowed to "type" */
|
|
8
|
+
readonly kind: "type";
|
|
9
|
+
|
|
10
|
+
/** The underlying type being aliased (optional, may not be parsed) */
|
|
11
|
+
readonly type?: string;
|
|
12
|
+
}
|
|
13
|
+
|
|
14
|
+
export default ICppTypeAliasSymbol;
|
|
@@ -0,0 +1,23 @@
|
|
|
1
|
+
import type ICppBaseSymbol from "./ICppBaseSymbol";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Symbol representing a C++ variable.
|
|
5
|
+
*/
|
|
6
|
+
interface ICppVariableSymbol extends ICppBaseSymbol {
|
|
7
|
+
/** Discriminator narrowed to "variable" */
|
|
8
|
+
readonly kind: "variable";
|
|
9
|
+
|
|
10
|
+
/** Variable type as string */
|
|
11
|
+
readonly type: string;
|
|
12
|
+
|
|
13
|
+
/** Whether this variable is const */
|
|
14
|
+
readonly isConst?: boolean;
|
|
15
|
+
|
|
16
|
+
/** Whether this variable is an array */
|
|
17
|
+
readonly isArray?: boolean;
|
|
18
|
+
|
|
19
|
+
/** Array dimensions if this is an array */
|
|
20
|
+
readonly arrayDimensions?: ReadonlyArray<number | string>;
|
|
21
|
+
}
|
|
22
|
+
|
|
23
|
+
export default ICppVariableSymbol;
|
|
@@ -0,0 +1,30 @@
|
|
|
1
|
+
import type ICppClassSymbol from "./ICppClassSymbol";
|
|
2
|
+
import type ICppStructSymbol from "./ICppStructSymbol";
|
|
3
|
+
import type ICppNamespaceSymbol from "./ICppNamespaceSymbol";
|
|
4
|
+
import type ICppEnumSymbol from "./ICppEnumSymbol";
|
|
5
|
+
import type ICppEnumMemberSymbol from "./ICppEnumMemberSymbol";
|
|
6
|
+
import type ICppFunctionSymbol from "./ICppFunctionSymbol";
|
|
7
|
+
import type ICppVariableSymbol from "./ICppVariableSymbol";
|
|
8
|
+
import type ICppTypeAliasSymbol from "./ICppTypeAliasSymbol";
|
|
9
|
+
|
|
10
|
+
/**
|
|
11
|
+
* Discriminated union of all C++ language symbol types.
|
|
12
|
+
*
|
|
13
|
+
* Use the `kind` field to narrow to a specific symbol type:
|
|
14
|
+
* ```typescript
|
|
15
|
+
* if (symbol.kind === "class") {
|
|
16
|
+
* // TypeScript knows symbol is ICppClassSymbol here
|
|
17
|
+
* }
|
|
18
|
+
* ```
|
|
19
|
+
*/
|
|
20
|
+
type TCppSymbol =
|
|
21
|
+
| ICppClassSymbol
|
|
22
|
+
| ICppStructSymbol
|
|
23
|
+
| ICppNamespaceSymbol
|
|
24
|
+
| ICppEnumSymbol
|
|
25
|
+
| ICppEnumMemberSymbol
|
|
26
|
+
| ICppFunctionSymbol
|
|
27
|
+
| ICppVariableSymbol
|
|
28
|
+
| ICppTypeAliasSymbol;
|
|
29
|
+
|
|
30
|
+
export default TCppSymbol;
|
|
@@ -11,7 +11,6 @@
|
|
|
11
11
|
|
|
12
12
|
import SymbolTable from "../transpiler/logic/symbols/SymbolTable";
|
|
13
13
|
import ESourceLanguage from "./types/ESourceLanguage";
|
|
14
|
-
import ESymbolKind from "./types/ESymbolKind";
|
|
15
14
|
|
|
16
15
|
/**
|
|
17
16
|
* Static utility methods for C++ namespace operations
|
|
@@ -42,9 +41,9 @@ class CppNamespaceUtils {
|
|
|
42
41
|
|
|
43
42
|
// C++ namespaces, classes, and enums (enum class) need :: syntax
|
|
44
43
|
if (
|
|
45
|
-
sym.kind ===
|
|
46
|
-
sym.kind ===
|
|
47
|
-
sym.kind ===
|
|
44
|
+
sym.kind === "namespace" ||
|
|
45
|
+
sym.kind === "class" ||
|
|
46
|
+
sym.kind === "enum"
|
|
48
47
|
) {
|
|
49
48
|
return true;
|
|
50
49
|
}
|
|
@@ -0,0 +1,92 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Factory functions and utilities for IFunctionSymbol.
|
|
3
|
+
*
|
|
4
|
+
* Provides utilities for creating, inspecting, and name-mangling C-Next functions.
|
|
5
|
+
*/
|
|
6
|
+
import type IFunctionSymbol from "../transpiler/types/symbols/IFunctionSymbol";
|
|
7
|
+
import type TVisibility from "../transpiler/types/TVisibility";
|
|
8
|
+
import type IScopeSymbol from "../transpiler/types/symbols/IScopeSymbol";
|
|
9
|
+
import type IParameterInfo from "../transpiler/types/symbols/IParameterInfo";
|
|
10
|
+
import type TType from "../transpiler/types/TType";
|
|
11
|
+
import ESourceLanguage from "./types/ESourceLanguage";
|
|
12
|
+
import ScopeUtils from "./ScopeUtils";
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* Options for creating a function symbol
|
|
16
|
+
*/
|
|
17
|
+
interface IFunctionCreateOptions {
|
|
18
|
+
name: string;
|
|
19
|
+
scope: IScopeSymbol;
|
|
20
|
+
parameters: ReadonlyArray<IParameterInfo>;
|
|
21
|
+
returnType: TType;
|
|
22
|
+
visibility: TVisibility;
|
|
23
|
+
body: unknown;
|
|
24
|
+
sourceFile: string;
|
|
25
|
+
sourceLine: number;
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
class FunctionUtils {
|
|
29
|
+
// ============================================================================
|
|
30
|
+
// Factory Functions
|
|
31
|
+
// ============================================================================
|
|
32
|
+
|
|
33
|
+
/**
|
|
34
|
+
* Create a function symbol with the given properties.
|
|
35
|
+
*
|
|
36
|
+
* @param options - Function properties including bare name and scope reference
|
|
37
|
+
*/
|
|
38
|
+
static create(options: IFunctionCreateOptions): IFunctionSymbol {
|
|
39
|
+
return {
|
|
40
|
+
kind: "function",
|
|
41
|
+
name: options.name,
|
|
42
|
+
scope: options.scope,
|
|
43
|
+
parameters: options.parameters,
|
|
44
|
+
returnType: options.returnType,
|
|
45
|
+
visibility: options.visibility,
|
|
46
|
+
body: options.body,
|
|
47
|
+
sourceFile: options.sourceFile,
|
|
48
|
+
sourceLine: options.sourceLine,
|
|
49
|
+
sourceLanguage: ESourceLanguage.CNext,
|
|
50
|
+
isExported: options.visibility === "public",
|
|
51
|
+
};
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
// ============================================================================
|
|
55
|
+
// Name Mangling
|
|
56
|
+
// ============================================================================
|
|
57
|
+
|
|
58
|
+
/**
|
|
59
|
+
* Get the C-mangled name for a function.
|
|
60
|
+
*
|
|
61
|
+
* For global scope functions, returns the bare name.
|
|
62
|
+
* For scoped functions, returns "Scope_name" (e.g., "Test_fillData").
|
|
63
|
+
* For nested scopes, returns "Outer_Inner_name".
|
|
64
|
+
*/
|
|
65
|
+
static getCMangledName(func: IFunctionSymbol): string {
|
|
66
|
+
const scopePath = ScopeUtils.getScopePath(func.scope);
|
|
67
|
+
if (scopePath.length === 0) {
|
|
68
|
+
return func.name;
|
|
69
|
+
}
|
|
70
|
+
return `${scopePath.join("_")}_${func.name}`;
|
|
71
|
+
}
|
|
72
|
+
|
|
73
|
+
// ============================================================================
|
|
74
|
+
// Type Guards and Queries
|
|
75
|
+
// ============================================================================
|
|
76
|
+
|
|
77
|
+
/**
|
|
78
|
+
* Check if function has public visibility.
|
|
79
|
+
*/
|
|
80
|
+
static isPublic(func: IFunctionSymbol): boolean {
|
|
81
|
+
return func.visibility === "public";
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
/**
|
|
85
|
+
* Check if function is in the global scope.
|
|
86
|
+
*/
|
|
87
|
+
static isInGlobalScope(func: IFunctionSymbol): boolean {
|
|
88
|
+
return ScopeUtils.isGlobalScope(func.scope);
|
|
89
|
+
}
|
|
90
|
+
}
|
|
91
|
+
|
|
92
|
+
export default FunctionUtils;
|
|
@@ -0,0 +1,55 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Factory functions and type guards for IParameterInfo.
|
|
3
|
+
*
|
|
4
|
+
* Provides utilities for creating and inspecting C-Next function parameters.
|
|
5
|
+
*/
|
|
6
|
+
import type IParameterInfo from "../transpiler/types/symbols/IParameterInfo";
|
|
7
|
+
import type TType from "../transpiler/types/TType";
|
|
8
|
+
|
|
9
|
+
class ParameterUtils {
|
|
10
|
+
// ============================================================================
|
|
11
|
+
// Factory Functions
|
|
12
|
+
// ============================================================================
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* Create a parameter with the given properties.
|
|
16
|
+
*/
|
|
17
|
+
static create(options: {
|
|
18
|
+
name: string;
|
|
19
|
+
type: TType;
|
|
20
|
+
isConst: boolean;
|
|
21
|
+
isArray: boolean;
|
|
22
|
+
arrayDimensions?: ReadonlyArray<number | string>;
|
|
23
|
+
isAutoConst?: boolean;
|
|
24
|
+
}): IParameterInfo {
|
|
25
|
+
return {
|
|
26
|
+
name: options.name,
|
|
27
|
+
type: options.type,
|
|
28
|
+
isConst: options.isConst,
|
|
29
|
+
isArray: options.isArray,
|
|
30
|
+
...(options.arrayDimensions !== undefined && {
|
|
31
|
+
arrayDimensions: options.arrayDimensions,
|
|
32
|
+
}),
|
|
33
|
+
...(options.isAutoConst !== undefined && {
|
|
34
|
+
isAutoConst: options.isAutoConst,
|
|
35
|
+
}),
|
|
36
|
+
};
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
// ============================================================================
|
|
40
|
+
// Type Guards
|
|
41
|
+
// ============================================================================
|
|
42
|
+
|
|
43
|
+
/**
|
|
44
|
+
* Check if parameter has array dimensions.
|
|
45
|
+
*
|
|
46
|
+
* Returns true if arrayDimensions is defined and has at least one dimension.
|
|
47
|
+
*/
|
|
48
|
+
static isArray(param: IParameterInfo): boolean {
|
|
49
|
+
return (
|
|
50
|
+
param.arrayDimensions !== undefined && param.arrayDimensions.length > 0
|
|
51
|
+
);
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
|
|
55
|
+
export default ParameterUtils;
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
import TPrimitiveKind from "../transpiler/types/TPrimitiveKind";
|
|
2
|
+
|
|
3
|
+
/**
|
|
4
|
+
* Utility functions for working with C-Next primitive types.
|
|
5
|
+
*/
|
|
6
|
+
class PrimitiveKindUtils {
|
|
7
|
+
static readonly BIT_WIDTHS: ReadonlyMap<TPrimitiveKind, number> = new Map([
|
|
8
|
+
["bool", 1],
|
|
9
|
+
["u8", 8],
|
|
10
|
+
["i8", 8],
|
|
11
|
+
["u16", 16],
|
|
12
|
+
["i16", 16],
|
|
13
|
+
["u32", 32],
|
|
14
|
+
["i32", 32],
|
|
15
|
+
["u64", 64],
|
|
16
|
+
["i64", 64],
|
|
17
|
+
["f32", 32],
|
|
18
|
+
["f64", 64],
|
|
19
|
+
]);
|
|
20
|
+
|
|
21
|
+
static getBitWidth(kind: TPrimitiveKind): number | undefined {
|
|
22
|
+
return PrimitiveKindUtils.BIT_WIDTHS.get(kind);
|
|
23
|
+
}
|
|
24
|
+
|
|
25
|
+
static isPrimitive(type: string): type is TPrimitiveKind {
|
|
26
|
+
return (
|
|
27
|
+
PrimitiveKindUtils.BIT_WIDTHS.has(type as TPrimitiveKind) ||
|
|
28
|
+
type === "void"
|
|
29
|
+
);
|
|
30
|
+
}
|
|
31
|
+
}
|
|
32
|
+
|
|
33
|
+
export default PrimitiveKindUtils;
|
|
@@ -0,0 +1,105 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Factory functions and type guards for IScopeSymbol.
|
|
3
|
+
*
|
|
4
|
+
* Provides utilities for creating and inspecting C-Next scopes.
|
|
5
|
+
*/
|
|
6
|
+
import type IScopeSymbol from "../transpiler/types/symbols/IScopeSymbol";
|
|
7
|
+
import ESourceLanguage from "./types/ESourceLanguage";
|
|
8
|
+
|
|
9
|
+
class ScopeUtils {
|
|
10
|
+
// ============================================================================
|
|
11
|
+
// Factory Functions
|
|
12
|
+
// ============================================================================
|
|
13
|
+
|
|
14
|
+
/**
|
|
15
|
+
* Create the global scope with self-reference parent.
|
|
16
|
+
*
|
|
17
|
+
* Global scope has:
|
|
18
|
+
* - name: "" (empty string)
|
|
19
|
+
* - parent: points to itself (self-reference)
|
|
20
|
+
* - scope: points to itself (self-reference)
|
|
21
|
+
*/
|
|
22
|
+
static createGlobalScope(): IScopeSymbol {
|
|
23
|
+
// Create a mutable object first to establish self-references
|
|
24
|
+
const global: IScopeSymbol = {
|
|
25
|
+
kind: "scope",
|
|
26
|
+
name: "",
|
|
27
|
+
parent: null as unknown as IScopeSymbol, // Temporary, will be set below
|
|
28
|
+
scope: null as unknown as IScopeSymbol, // Temporary, will be set below
|
|
29
|
+
members: [],
|
|
30
|
+
functions: [],
|
|
31
|
+
variables: [],
|
|
32
|
+
memberVisibility: new Map(),
|
|
33
|
+
sourceFile: "",
|
|
34
|
+
sourceLine: 0,
|
|
35
|
+
sourceLanguage: ESourceLanguage.CNext,
|
|
36
|
+
isExported: true,
|
|
37
|
+
};
|
|
38
|
+
// Set self-references for global scope
|
|
39
|
+
(global as unknown as { parent: IScopeSymbol }).parent = global;
|
|
40
|
+
(global as unknown as { scope: IScopeSymbol }).scope = global;
|
|
41
|
+
return global;
|
|
42
|
+
}
|
|
43
|
+
|
|
44
|
+
/**
|
|
45
|
+
* Create a named scope with the given parent.
|
|
46
|
+
*
|
|
47
|
+
* Named scopes can be nested (e.g., Outer.Inner).
|
|
48
|
+
*/
|
|
49
|
+
static createScope(name: string, parent: IScopeSymbol): IScopeSymbol {
|
|
50
|
+
const scope: IScopeSymbol = {
|
|
51
|
+
kind: "scope",
|
|
52
|
+
name,
|
|
53
|
+
parent,
|
|
54
|
+
scope: parent, // Scope's containing scope is its parent
|
|
55
|
+
members: [],
|
|
56
|
+
functions: [],
|
|
57
|
+
variables: [],
|
|
58
|
+
memberVisibility: new Map(),
|
|
59
|
+
sourceFile: "",
|
|
60
|
+
sourceLine: 0,
|
|
61
|
+
sourceLanguage: ESourceLanguage.CNext,
|
|
62
|
+
isExported: true,
|
|
63
|
+
};
|
|
64
|
+
return scope;
|
|
65
|
+
}
|
|
66
|
+
|
|
67
|
+
// ============================================================================
|
|
68
|
+
// Type Guards
|
|
69
|
+
// ============================================================================
|
|
70
|
+
|
|
71
|
+
/**
|
|
72
|
+
* Check if a scope is the global scope.
|
|
73
|
+
*
|
|
74
|
+
* Global scope is identified by:
|
|
75
|
+
* - Empty name ("")
|
|
76
|
+
* - Self-referential parent (parent === scope)
|
|
77
|
+
*/
|
|
78
|
+
static isGlobalScope(scope: IScopeSymbol): boolean {
|
|
79
|
+
return scope.name === "" && scope.parent === scope;
|
|
80
|
+
}
|
|
81
|
+
|
|
82
|
+
// ============================================================================
|
|
83
|
+
// Path Utilities
|
|
84
|
+
// ============================================================================
|
|
85
|
+
|
|
86
|
+
/**
|
|
87
|
+
* Get the scope path from outermost to innermost (excluding global scope).
|
|
88
|
+
*
|
|
89
|
+
* For scope "Outer.Inner", returns ["Outer", "Inner"].
|
|
90
|
+
* For global scope, returns [].
|
|
91
|
+
*/
|
|
92
|
+
static getScopePath(scope: IScopeSymbol): string[] {
|
|
93
|
+
const path: string[] = [];
|
|
94
|
+
let current = scope;
|
|
95
|
+
|
|
96
|
+
while (!ScopeUtils.isGlobalScope(current)) {
|
|
97
|
+
path.unshift(current.name);
|
|
98
|
+
current = current.parent;
|
|
99
|
+
}
|
|
100
|
+
|
|
101
|
+
return path;
|
|
102
|
+
}
|
|
103
|
+
}
|
|
104
|
+
|
|
105
|
+
export default ScopeUtils;
|
|
@@ -0,0 +1,159 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Factory functions and type guards for TType.
|
|
3
|
+
*
|
|
4
|
+
* Provides utilities for creating and inspecting C-Next types.
|
|
5
|
+
*/
|
|
6
|
+
import type TType from "../transpiler/types/TType";
|
|
7
|
+
import type TPrimitiveKind from "../transpiler/types/TPrimitiveKind";
|
|
8
|
+
|
|
9
|
+
// Extract variant types from the discriminated union
|
|
10
|
+
type TPrimitiveType = Extract<TType, { kind: "primitive" }>;
|
|
11
|
+
type TStructType = Extract<TType, { kind: "struct" }>;
|
|
12
|
+
type TEnumType = Extract<TType, { kind: "enum" }>;
|
|
13
|
+
type TBitmapType = Extract<TType, { kind: "bitmap" }>;
|
|
14
|
+
type TArrayType = Extract<TType, { kind: "array" }>;
|
|
15
|
+
type TStringType = Extract<TType, { kind: "string" }>;
|
|
16
|
+
type TCallbackType = Extract<TType, { kind: "callback" }>;
|
|
17
|
+
type TRegisterType = Extract<TType, { kind: "register" }>;
|
|
18
|
+
type TExternalType = Extract<TType, { kind: "external" }>;
|
|
19
|
+
|
|
20
|
+
class TTypeUtils {
|
|
21
|
+
// ============================================================================
|
|
22
|
+
// Factory Functions
|
|
23
|
+
// ============================================================================
|
|
24
|
+
|
|
25
|
+
/**
|
|
26
|
+
* Create a primitive type
|
|
27
|
+
*/
|
|
28
|
+
static createPrimitive(primitive: TPrimitiveKind): TPrimitiveType {
|
|
29
|
+
return { kind: "primitive", primitive };
|
|
30
|
+
}
|
|
31
|
+
|
|
32
|
+
/**
|
|
33
|
+
* Create a struct type reference
|
|
34
|
+
*/
|
|
35
|
+
static createStruct(name: string): TStructType {
|
|
36
|
+
return { kind: "struct", name };
|
|
37
|
+
}
|
|
38
|
+
|
|
39
|
+
/**
|
|
40
|
+
* Create an enum type reference
|
|
41
|
+
*/
|
|
42
|
+
static createEnum(name: string): TEnumType {
|
|
43
|
+
return { kind: "enum", name };
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
/**
|
|
47
|
+
* Create a bitmap type reference
|
|
48
|
+
*/
|
|
49
|
+
static createBitmap(name: string, bitWidth: number): TBitmapType {
|
|
50
|
+
return { kind: "bitmap", name, bitWidth };
|
|
51
|
+
}
|
|
52
|
+
|
|
53
|
+
/**
|
|
54
|
+
* Create an array type
|
|
55
|
+
*/
|
|
56
|
+
static createArray(
|
|
57
|
+
elementType: TType,
|
|
58
|
+
dimensions: ReadonlyArray<number | string>,
|
|
59
|
+
): TArrayType {
|
|
60
|
+
return { kind: "array", elementType, dimensions };
|
|
61
|
+
}
|
|
62
|
+
|
|
63
|
+
/**
|
|
64
|
+
* Create a string type with capacity
|
|
65
|
+
*/
|
|
66
|
+
static createString(capacity: number): TStringType {
|
|
67
|
+
return { kind: "string", capacity };
|
|
68
|
+
}
|
|
69
|
+
|
|
70
|
+
/**
|
|
71
|
+
* Create a callback type reference
|
|
72
|
+
*/
|
|
73
|
+
static createCallback(name: string): TCallbackType {
|
|
74
|
+
return { kind: "callback", name };
|
|
75
|
+
}
|
|
76
|
+
|
|
77
|
+
/**
|
|
78
|
+
* Create a register type reference
|
|
79
|
+
*/
|
|
80
|
+
static createRegister(name: string): TRegisterType {
|
|
81
|
+
return { kind: "register", name };
|
|
82
|
+
}
|
|
83
|
+
|
|
84
|
+
/**
|
|
85
|
+
* Create an external type (C++ templates, etc.)
|
|
86
|
+
*/
|
|
87
|
+
static createExternal(name: string): TExternalType {
|
|
88
|
+
return { kind: "external", name };
|
|
89
|
+
}
|
|
90
|
+
|
|
91
|
+
// ============================================================================
|
|
92
|
+
// Type Guards
|
|
93
|
+
// ============================================================================
|
|
94
|
+
|
|
95
|
+
/**
|
|
96
|
+
* Check if type is a primitive
|
|
97
|
+
*/
|
|
98
|
+
static isPrimitive(t: TType): t is TPrimitiveType {
|
|
99
|
+
return t.kind === "primitive";
|
|
100
|
+
}
|
|
101
|
+
|
|
102
|
+
/**
|
|
103
|
+
* Check if type is a struct
|
|
104
|
+
*/
|
|
105
|
+
static isStruct(t: TType): t is TStructType {
|
|
106
|
+
return t.kind === "struct";
|
|
107
|
+
}
|
|
108
|
+
|
|
109
|
+
/**
|
|
110
|
+
* Check if type is an enum
|
|
111
|
+
*/
|
|
112
|
+
static isEnum(t: TType): t is TEnumType {
|
|
113
|
+
return t.kind === "enum";
|
|
114
|
+
}
|
|
115
|
+
|
|
116
|
+
/**
|
|
117
|
+
* Check if type is a bitmap
|
|
118
|
+
*/
|
|
119
|
+
static isBitmap(t: TType): t is TBitmapType {
|
|
120
|
+
return t.kind === "bitmap";
|
|
121
|
+
}
|
|
122
|
+
|
|
123
|
+
/**
|
|
124
|
+
* Check if type is an array
|
|
125
|
+
*/
|
|
126
|
+
static isArray(t: TType): t is TArrayType {
|
|
127
|
+
return t.kind === "array";
|
|
128
|
+
}
|
|
129
|
+
|
|
130
|
+
/**
|
|
131
|
+
* Check if type is a string
|
|
132
|
+
*/
|
|
133
|
+
static isString(t: TType): t is TStringType {
|
|
134
|
+
return t.kind === "string";
|
|
135
|
+
}
|
|
136
|
+
|
|
137
|
+
/**
|
|
138
|
+
* Check if type is a callback
|
|
139
|
+
*/
|
|
140
|
+
static isCallback(t: TType): t is TCallbackType {
|
|
141
|
+
return t.kind === "callback";
|
|
142
|
+
}
|
|
143
|
+
|
|
144
|
+
/**
|
|
145
|
+
* Check if type is a register
|
|
146
|
+
*/
|
|
147
|
+
static isRegister(t: TType): t is TRegisterType {
|
|
148
|
+
return t.kind === "register";
|
|
149
|
+
}
|
|
150
|
+
|
|
151
|
+
/**
|
|
152
|
+
* Check if type is external
|
|
153
|
+
*/
|
|
154
|
+
static isExternal(t: TType): t is TExternalType {
|
|
155
|
+
return t.kind === "external";
|
|
156
|
+
}
|
|
157
|
+
}
|
|
158
|
+
|
|
159
|
+
export default TTypeUtils;
|