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,317 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* ClassCollector - Extracts class/struct definitions from C++ parse trees.
|
|
3
|
+
*
|
|
4
|
+
* Handles class members including data fields and member functions.
|
|
5
|
+
* Produces ICppClassSymbol instances with optional field information.
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
9
|
+
|
|
10
|
+
import ESourceLanguage from "../../../../../utils/types/ESourceLanguage";
|
|
11
|
+
import ICppClassSymbol from "../../../../types/symbols/cpp/ICppClassSymbol";
|
|
12
|
+
import ICppFunctionSymbol from "../../../../types/symbols/cpp/ICppFunctionSymbol";
|
|
13
|
+
import ICppFieldInfo from "../../../../types/symbols/cpp/ICppFieldInfo";
|
|
14
|
+
import SymbolTable from "../../SymbolTable";
|
|
15
|
+
import SymbolUtils from "../../SymbolUtils";
|
|
16
|
+
import DeclaratorUtils from "../utils/DeclaratorUtils";
|
|
17
|
+
import FunctionCollector from "./FunctionCollector";
|
|
18
|
+
|
|
19
|
+
/**
|
|
20
|
+
* Result of collecting a class, including the class symbol and any member function symbols.
|
|
21
|
+
*/
|
|
22
|
+
interface IClassCollectorResult {
|
|
23
|
+
classSymbol: ICppClassSymbol;
|
|
24
|
+
memberFunctions: ICppFunctionSymbol[];
|
|
25
|
+
warnings: string[];
|
|
26
|
+
}
|
|
27
|
+
|
|
28
|
+
/**
|
|
29
|
+
* Internal context for member collection.
|
|
30
|
+
*/
|
|
31
|
+
interface IMemberCollectionContext {
|
|
32
|
+
readonly className: string;
|
|
33
|
+
readonly sourceFile: string;
|
|
34
|
+
readonly symbolTable: SymbolTable | null;
|
|
35
|
+
readonly fields: Map<string, ICppFieldInfo> | undefined;
|
|
36
|
+
readonly memberFunctions: ICppFunctionSymbol[];
|
|
37
|
+
readonly warnings: string[];
|
|
38
|
+
}
|
|
39
|
+
|
|
40
|
+
class ClassCollector {
|
|
41
|
+
/**
|
|
42
|
+
* Collect a class specifier and return an ICppClassSymbol with member functions.
|
|
43
|
+
*
|
|
44
|
+
* @param classSpec The class specifier context
|
|
45
|
+
* @param sourceFile Source file path
|
|
46
|
+
* @param line Line number
|
|
47
|
+
* @param currentNamespace Optional current namespace
|
|
48
|
+
* @param symbolTable Optional symbol table for storing field info
|
|
49
|
+
* @returns The class symbol with member functions, or null if no name
|
|
50
|
+
*/
|
|
51
|
+
static collect(
|
|
52
|
+
classSpec: any,
|
|
53
|
+
sourceFile: string,
|
|
54
|
+
line: number,
|
|
55
|
+
currentNamespace?: string,
|
|
56
|
+
symbolTable?: SymbolTable | null,
|
|
57
|
+
): IClassCollectorResult | null {
|
|
58
|
+
const classHead = classSpec.classHead?.();
|
|
59
|
+
if (!classHead) return null;
|
|
60
|
+
|
|
61
|
+
const classHeadName = classHead.classHeadName?.();
|
|
62
|
+
if (!classHeadName) return null;
|
|
63
|
+
|
|
64
|
+
const className = classHeadName.className?.();
|
|
65
|
+
if (!className) return null;
|
|
66
|
+
|
|
67
|
+
const identifier = className.Identifier?.();
|
|
68
|
+
const name = identifier?.getText();
|
|
69
|
+
if (!name) return null;
|
|
70
|
+
|
|
71
|
+
const fullName = currentNamespace ? `${currentNamespace}::${name}` : name;
|
|
72
|
+
|
|
73
|
+
const memberFunctions: ICppFunctionSymbol[] = [];
|
|
74
|
+
const warnings: string[] = [];
|
|
75
|
+
const fields: Map<string, ICppFieldInfo> | undefined = symbolTable
|
|
76
|
+
? new Map()
|
|
77
|
+
: undefined;
|
|
78
|
+
|
|
79
|
+
// Extract class members
|
|
80
|
+
const memberSpec = classSpec.memberSpecification?.();
|
|
81
|
+
if (memberSpec) {
|
|
82
|
+
const ctx: IMemberCollectionContext = {
|
|
83
|
+
className: fullName,
|
|
84
|
+
sourceFile,
|
|
85
|
+
symbolTable: symbolTable ?? null,
|
|
86
|
+
fields,
|
|
87
|
+
memberFunctions,
|
|
88
|
+
warnings,
|
|
89
|
+
};
|
|
90
|
+
ClassCollector._collectClassMembers(ctx, memberSpec);
|
|
91
|
+
}
|
|
92
|
+
|
|
93
|
+
const classSymbol: ICppClassSymbol = {
|
|
94
|
+
kind: "class",
|
|
95
|
+
name: fullName,
|
|
96
|
+
sourceFile,
|
|
97
|
+
sourceLine: line,
|
|
98
|
+
sourceLanguage: ESourceLanguage.Cpp,
|
|
99
|
+
isExported: true,
|
|
100
|
+
parent: currentNamespace,
|
|
101
|
+
fields: fields && fields.size > 0 ? fields : undefined,
|
|
102
|
+
};
|
|
103
|
+
|
|
104
|
+
return { classSymbol, memberFunctions, warnings };
|
|
105
|
+
}
|
|
106
|
+
|
|
107
|
+
/**
|
|
108
|
+
* Collect an anonymous class from a typedef.
|
|
109
|
+
*
|
|
110
|
+
* @param classSpec The class specifier context (anonymous)
|
|
111
|
+
* @param typedefName The typedef name to use as the class name
|
|
112
|
+
* @param sourceFile Source file path
|
|
113
|
+
* @param line Line number
|
|
114
|
+
* @param symbolTable Symbol table for storing field info
|
|
115
|
+
* @returns The class symbol result, or null on error
|
|
116
|
+
*/
|
|
117
|
+
static collectAnonymousTypedef(
|
|
118
|
+
classSpec: any,
|
|
119
|
+
typedefName: string,
|
|
120
|
+
sourceFile: string,
|
|
121
|
+
line: number,
|
|
122
|
+
symbolTable: SymbolTable,
|
|
123
|
+
): IClassCollectorResult | null {
|
|
124
|
+
const memberSpec = classSpec.memberSpecification?.();
|
|
125
|
+
if (!memberSpec) return null;
|
|
126
|
+
|
|
127
|
+
const memberFunctions: ICppFunctionSymbol[] = [];
|
|
128
|
+
const warnings: string[] = [];
|
|
129
|
+
const fields = new Map<string, ICppFieldInfo>();
|
|
130
|
+
|
|
131
|
+
const ctx: IMemberCollectionContext = {
|
|
132
|
+
className: typedefName,
|
|
133
|
+
sourceFile,
|
|
134
|
+
symbolTable,
|
|
135
|
+
fields,
|
|
136
|
+
memberFunctions,
|
|
137
|
+
warnings,
|
|
138
|
+
};
|
|
139
|
+
ClassCollector._collectClassMembers(ctx, memberSpec);
|
|
140
|
+
|
|
141
|
+
const classSymbol: ICppClassSymbol = {
|
|
142
|
+
kind: "class",
|
|
143
|
+
name: typedefName,
|
|
144
|
+
sourceFile,
|
|
145
|
+
sourceLine: line,
|
|
146
|
+
sourceLanguage: ESourceLanguage.Cpp,
|
|
147
|
+
isExported: true,
|
|
148
|
+
fields: fields.size > 0 ? fields : undefined,
|
|
149
|
+
};
|
|
150
|
+
|
|
151
|
+
return { classSymbol, memberFunctions, warnings };
|
|
152
|
+
}
|
|
153
|
+
|
|
154
|
+
/**
|
|
155
|
+
* Collect class members (data fields and member functions).
|
|
156
|
+
*/
|
|
157
|
+
private static _collectClassMembers(
|
|
158
|
+
ctx: IMemberCollectionContext,
|
|
159
|
+
memberSpec: any,
|
|
160
|
+
): void {
|
|
161
|
+
for (const memberDecl of memberSpec.memberdeclaration?.() ?? []) {
|
|
162
|
+
ClassCollector._collectMemberDeclaration(memberDecl, ctx);
|
|
163
|
+
}
|
|
164
|
+
}
|
|
165
|
+
|
|
166
|
+
/**
|
|
167
|
+
* Collect a single member declaration.
|
|
168
|
+
*/
|
|
169
|
+
private static _collectMemberDeclaration(
|
|
170
|
+
memberDecl: any,
|
|
171
|
+
ctx: IMemberCollectionContext,
|
|
172
|
+
): void {
|
|
173
|
+
const line = memberDecl.start?.line ?? 0;
|
|
174
|
+
|
|
175
|
+
// Check for inline function definition within the class
|
|
176
|
+
const funcDef = memberDecl.functionDefinition?.();
|
|
177
|
+
if (funcDef) {
|
|
178
|
+
ClassCollector._collectInlineFunctionDef(
|
|
179
|
+
ctx.className,
|
|
180
|
+
funcDef,
|
|
181
|
+
ctx.sourceFile,
|
|
182
|
+
line,
|
|
183
|
+
ctx.memberFunctions,
|
|
184
|
+
);
|
|
185
|
+
return;
|
|
186
|
+
}
|
|
187
|
+
|
|
188
|
+
// Get member declaration list (for data members and function declarations)
|
|
189
|
+
const declSpecSeq = memberDecl.declSpecifierSeq?.();
|
|
190
|
+
if (!declSpecSeq) return;
|
|
191
|
+
|
|
192
|
+
const fieldType = DeclaratorUtils.extractTypeFromDeclSpecSeq(declSpecSeq);
|
|
193
|
+
|
|
194
|
+
// Get declarator list
|
|
195
|
+
const memberDeclList = memberDecl.memberDeclaratorList?.();
|
|
196
|
+
if (!memberDeclList) return;
|
|
197
|
+
|
|
198
|
+
for (const memberDeclarator of memberDeclList.memberDeclarator?.() ?? []) {
|
|
199
|
+
ClassCollector._collectMemberDeclarator(
|
|
200
|
+
memberDeclarator,
|
|
201
|
+
fieldType,
|
|
202
|
+
line,
|
|
203
|
+
ctx,
|
|
204
|
+
);
|
|
205
|
+
}
|
|
206
|
+
}
|
|
207
|
+
|
|
208
|
+
/**
|
|
209
|
+
* Collect an inline function definition within a class.
|
|
210
|
+
*/
|
|
211
|
+
private static _collectInlineFunctionDef(
|
|
212
|
+
className: string,
|
|
213
|
+
funcDef: any,
|
|
214
|
+
sourceFile: string,
|
|
215
|
+
line: number,
|
|
216
|
+
memberFunctions: ICppFunctionSymbol[],
|
|
217
|
+
): void {
|
|
218
|
+
const declarator = funcDef.declarator?.();
|
|
219
|
+
if (!declarator) return;
|
|
220
|
+
|
|
221
|
+
const funcName = DeclaratorUtils.extractDeclaratorName(declarator);
|
|
222
|
+
if (!funcName) return;
|
|
223
|
+
|
|
224
|
+
const declSpecSeq = funcDef.declSpecifierSeq?.();
|
|
225
|
+
const returnType = declSpecSeq
|
|
226
|
+
? DeclaratorUtils.extractTypeFromDeclSpecSeq(declSpecSeq)
|
|
227
|
+
: "void";
|
|
228
|
+
|
|
229
|
+
const symbol = FunctionCollector.collectMemberFunction(
|
|
230
|
+
className,
|
|
231
|
+
funcName,
|
|
232
|
+
declarator,
|
|
233
|
+
returnType,
|
|
234
|
+
sourceFile,
|
|
235
|
+
line,
|
|
236
|
+
false, // not a declaration, it's a definition
|
|
237
|
+
);
|
|
238
|
+
memberFunctions.push(symbol);
|
|
239
|
+
}
|
|
240
|
+
|
|
241
|
+
/**
|
|
242
|
+
* Collect a single member declarator (function or data field).
|
|
243
|
+
*/
|
|
244
|
+
private static _collectMemberDeclarator(
|
|
245
|
+
memberDeclarator: any,
|
|
246
|
+
fieldType: string,
|
|
247
|
+
line: number,
|
|
248
|
+
ctx: IMemberCollectionContext,
|
|
249
|
+
): void {
|
|
250
|
+
const declarator = memberDeclarator.declarator?.();
|
|
251
|
+
if (!declarator) return;
|
|
252
|
+
|
|
253
|
+
const fieldName = DeclaratorUtils.extractDeclaratorName(declarator);
|
|
254
|
+
if (!fieldName) return;
|
|
255
|
+
|
|
256
|
+
// Check if this is a member function
|
|
257
|
+
if (DeclaratorUtils.declaratorIsFunction(declarator)) {
|
|
258
|
+
const symbol = FunctionCollector.collectMemberFunction(
|
|
259
|
+
ctx.className,
|
|
260
|
+
fieldName,
|
|
261
|
+
declarator,
|
|
262
|
+
fieldType,
|
|
263
|
+
ctx.sourceFile,
|
|
264
|
+
line,
|
|
265
|
+
true, // declaration
|
|
266
|
+
);
|
|
267
|
+
ctx.memberFunctions.push(symbol);
|
|
268
|
+
return;
|
|
269
|
+
}
|
|
270
|
+
|
|
271
|
+
// Data field
|
|
272
|
+
ClassCollector._collectDataField(fieldName, declarator, fieldType, ctx);
|
|
273
|
+
}
|
|
274
|
+
|
|
275
|
+
/**
|
|
276
|
+
* Collect a data field declaration.
|
|
277
|
+
*/
|
|
278
|
+
private static _collectDataField(
|
|
279
|
+
fieldName: string,
|
|
280
|
+
declarator: any,
|
|
281
|
+
fieldType: string,
|
|
282
|
+
ctx: IMemberCollectionContext,
|
|
283
|
+
): void {
|
|
284
|
+
// Warn if field name conflicts with C-Next reserved property names
|
|
285
|
+
if (SymbolUtils.isReservedFieldName(fieldName)) {
|
|
286
|
+
ctx.warnings.push(
|
|
287
|
+
SymbolUtils.getReservedFieldWarning("C++", ctx.className, fieldName),
|
|
288
|
+
);
|
|
289
|
+
}
|
|
290
|
+
|
|
291
|
+
// Extract array dimensions if any
|
|
292
|
+
const arrayDimensions = DeclaratorUtils.extractArrayDimensions(declarator);
|
|
293
|
+
|
|
294
|
+
// Add to SymbolTable if provided
|
|
295
|
+
if (ctx.symbolTable) {
|
|
296
|
+
ctx.symbolTable.addStructField(
|
|
297
|
+
ctx.className,
|
|
298
|
+
fieldName,
|
|
299
|
+
fieldType,
|
|
300
|
+
arrayDimensions.length > 0 ? arrayDimensions : undefined,
|
|
301
|
+
);
|
|
302
|
+
}
|
|
303
|
+
|
|
304
|
+
// Add to fields map if provided
|
|
305
|
+
if (ctx.fields) {
|
|
306
|
+
const fieldInfo: ICppFieldInfo = {
|
|
307
|
+
name: fieldName,
|
|
308
|
+
type: fieldType,
|
|
309
|
+
arrayDimensions:
|
|
310
|
+
arrayDimensions.length > 0 ? arrayDimensions : undefined,
|
|
311
|
+
};
|
|
312
|
+
ctx.fields.set(fieldName, fieldInfo);
|
|
313
|
+
}
|
|
314
|
+
}
|
|
315
|
+
}
|
|
316
|
+
|
|
317
|
+
export default ClassCollector;
|
|
@@ -0,0 +1,71 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* EnumCollector - Extracts enum declarations from C++ parse trees.
|
|
3
|
+
*
|
|
4
|
+
* Produces ICppEnumSymbol instances with optional bit width for typed enums.
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
8
|
+
|
|
9
|
+
import ESourceLanguage from "../../../../../utils/types/ESourceLanguage";
|
|
10
|
+
import ICppEnumSymbol from "../../../../types/symbols/cpp/ICppEnumSymbol";
|
|
11
|
+
import SymbolTable from "../../SymbolTable";
|
|
12
|
+
import SymbolUtils from "../../SymbolUtils";
|
|
13
|
+
|
|
14
|
+
class EnumCollector {
|
|
15
|
+
/**
|
|
16
|
+
* Collect an enum specifier and return an ICppEnumSymbol.
|
|
17
|
+
*
|
|
18
|
+
* @param enumSpec The enum specifier context
|
|
19
|
+
* @param sourceFile Source file path
|
|
20
|
+
* @param line Line number
|
|
21
|
+
* @param currentNamespace Optional current namespace
|
|
22
|
+
* @param symbolTable Optional symbol table for storing bit width
|
|
23
|
+
* @returns The enum symbol or null if no name
|
|
24
|
+
*/
|
|
25
|
+
static collect(
|
|
26
|
+
enumSpec: any,
|
|
27
|
+
sourceFile: string,
|
|
28
|
+
line: number,
|
|
29
|
+
currentNamespace?: string,
|
|
30
|
+
symbolTable?: SymbolTable | null,
|
|
31
|
+
): ICppEnumSymbol | null {
|
|
32
|
+
const enumHead = enumSpec.enumHead?.();
|
|
33
|
+
if (!enumHead) return null;
|
|
34
|
+
|
|
35
|
+
const identifier = enumHead.Identifier?.();
|
|
36
|
+
if (!identifier) return null;
|
|
37
|
+
|
|
38
|
+
const name = identifier.getText();
|
|
39
|
+
const fullName = currentNamespace ? `${currentNamespace}::${name}` : name;
|
|
40
|
+
|
|
41
|
+
// Extract bit width for typed enums (e.g., enum EPressureType : uint8_t)
|
|
42
|
+
let bitWidth: number | undefined;
|
|
43
|
+
if (symbolTable) {
|
|
44
|
+
const enumbase = enumHead.enumbase?.();
|
|
45
|
+
if (enumbase) {
|
|
46
|
+
const typeSpecSeq = enumbase.typeSpecifierSeq?.();
|
|
47
|
+
if (typeSpecSeq) {
|
|
48
|
+
const typeName = typeSpecSeq.getText();
|
|
49
|
+
const width = SymbolUtils.getTypeWidth(typeName);
|
|
50
|
+
if (width > 0) {
|
|
51
|
+
symbolTable.addEnumBitWidth(fullName, width);
|
|
52
|
+
bitWidth = width;
|
|
53
|
+
}
|
|
54
|
+
}
|
|
55
|
+
}
|
|
56
|
+
}
|
|
57
|
+
|
|
58
|
+
return {
|
|
59
|
+
kind: "enum",
|
|
60
|
+
name: fullName,
|
|
61
|
+
sourceFile,
|
|
62
|
+
sourceLine: line,
|
|
63
|
+
sourceLanguage: ESourceLanguage.Cpp,
|
|
64
|
+
isExported: true,
|
|
65
|
+
parent: currentNamespace,
|
|
66
|
+
bitWidth,
|
|
67
|
+
};
|
|
68
|
+
}
|
|
69
|
+
}
|
|
70
|
+
|
|
71
|
+
export default EnumCollector;
|
|
@@ -0,0 +1,155 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* FunctionCollector - Extracts function definitions and declarations from C++ parse trees.
|
|
3
|
+
*
|
|
4
|
+
* Produces ICppFunctionSymbol instances with parameters.
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
8
|
+
|
|
9
|
+
import ESourceLanguage from "../../../../../utils/types/ESourceLanguage";
|
|
10
|
+
import ICppFunctionSymbol from "../../../../types/symbols/cpp/ICppFunctionSymbol";
|
|
11
|
+
import ICppParameterInfo from "../../../../types/symbols/cpp/ICppParameterInfo";
|
|
12
|
+
import DeclaratorUtils from "../utils/DeclaratorUtils";
|
|
13
|
+
import IExtractedParameter from "../../shared/IExtractedParameter";
|
|
14
|
+
|
|
15
|
+
class FunctionCollector {
|
|
16
|
+
/**
|
|
17
|
+
* Map extracted parameters to ICppParameterInfo array.
|
|
18
|
+
*/
|
|
19
|
+
private static _mapParameters(
|
|
20
|
+
extracted: IExtractedParameter[],
|
|
21
|
+
): ICppParameterInfo[] {
|
|
22
|
+
return extracted.map((p) => ({
|
|
23
|
+
name: p.name,
|
|
24
|
+
type: p.type,
|
|
25
|
+
isConst: p.isConst,
|
|
26
|
+
isArray: p.isArray,
|
|
27
|
+
}));
|
|
28
|
+
}
|
|
29
|
+
|
|
30
|
+
/**
|
|
31
|
+
* Collect a function definition and return an ICppFunctionSymbol.
|
|
32
|
+
*
|
|
33
|
+
* @param funcDef The function definition context
|
|
34
|
+
* @param sourceFile Source file path
|
|
35
|
+
* @param line Line number
|
|
36
|
+
* @param currentNamespace Optional current namespace
|
|
37
|
+
* @returns The function symbol or null if no name
|
|
38
|
+
*/
|
|
39
|
+
static collectDefinition(
|
|
40
|
+
funcDef: any,
|
|
41
|
+
sourceFile: string,
|
|
42
|
+
line: number,
|
|
43
|
+
currentNamespace?: string,
|
|
44
|
+
): ICppFunctionSymbol | null {
|
|
45
|
+
const declarator = funcDef.declarator?.();
|
|
46
|
+
if (!declarator) return null;
|
|
47
|
+
|
|
48
|
+
const name = DeclaratorUtils.extractDeclaratorName(declarator);
|
|
49
|
+
if (!name) return null;
|
|
50
|
+
|
|
51
|
+
// Get return type
|
|
52
|
+
const declSpecSeq = funcDef.declSpecifierSeq?.();
|
|
53
|
+
const returnType = declSpecSeq
|
|
54
|
+
? DeclaratorUtils.extractTypeFromDeclSpecSeq(declSpecSeq)
|
|
55
|
+
: "void";
|
|
56
|
+
|
|
57
|
+
const fullName = currentNamespace ? `${currentNamespace}::${name}` : name;
|
|
58
|
+
const params = FunctionCollector._mapParameters(
|
|
59
|
+
DeclaratorUtils.extractFunctionParameters(declarator),
|
|
60
|
+
);
|
|
61
|
+
|
|
62
|
+
return {
|
|
63
|
+
kind: "function",
|
|
64
|
+
name: fullName,
|
|
65
|
+
type: returnType,
|
|
66
|
+
sourceFile,
|
|
67
|
+
sourceLine: line,
|
|
68
|
+
sourceLanguage: ESourceLanguage.Cpp,
|
|
69
|
+
isExported: true,
|
|
70
|
+
parent: currentNamespace,
|
|
71
|
+
parameters: params.length > 0 ? params : undefined,
|
|
72
|
+
isDeclaration: false,
|
|
73
|
+
};
|
|
74
|
+
}
|
|
75
|
+
|
|
76
|
+
/**
|
|
77
|
+
* Collect a function declaration (prototype) and return an ICppFunctionSymbol.
|
|
78
|
+
*
|
|
79
|
+
* @param declarator The function declarator context
|
|
80
|
+
* @param baseType The return type string
|
|
81
|
+
* @param sourceFile Source file path
|
|
82
|
+
* @param line Line number
|
|
83
|
+
* @param currentNamespace Optional current namespace
|
|
84
|
+
* @returns The function symbol or null if no name
|
|
85
|
+
*/
|
|
86
|
+
static collectDeclaration(
|
|
87
|
+
declarator: any,
|
|
88
|
+
baseType: string,
|
|
89
|
+
sourceFile: string,
|
|
90
|
+
line: number,
|
|
91
|
+
currentNamespace?: string,
|
|
92
|
+
): ICppFunctionSymbol | null {
|
|
93
|
+
const name = DeclaratorUtils.extractDeclaratorName(declarator);
|
|
94
|
+
if (!name) return null;
|
|
95
|
+
|
|
96
|
+
const fullName = currentNamespace ? `${currentNamespace}::${name}` : name;
|
|
97
|
+
const params = FunctionCollector._mapParameters(
|
|
98
|
+
DeclaratorUtils.extractFunctionParameters(declarator),
|
|
99
|
+
);
|
|
100
|
+
|
|
101
|
+
return {
|
|
102
|
+
kind: "function",
|
|
103
|
+
name: fullName,
|
|
104
|
+
type: baseType,
|
|
105
|
+
sourceFile,
|
|
106
|
+
sourceLine: line,
|
|
107
|
+
sourceLanguage: ESourceLanguage.Cpp,
|
|
108
|
+
isExported: true,
|
|
109
|
+
parent: currentNamespace,
|
|
110
|
+
parameters: params.length > 0 ? params : undefined,
|
|
111
|
+
isDeclaration: true,
|
|
112
|
+
};
|
|
113
|
+
}
|
|
114
|
+
|
|
115
|
+
/**
|
|
116
|
+
* Collect a member function (method) and return an ICppFunctionSymbol.
|
|
117
|
+
*
|
|
118
|
+
* @param className The class this method belongs to
|
|
119
|
+
* @param funcName The method name
|
|
120
|
+
* @param declarator The function declarator context
|
|
121
|
+
* @param returnType The return type string
|
|
122
|
+
* @param sourceFile Source file path
|
|
123
|
+
* @param line Line number
|
|
124
|
+
* @param isDeclaration Whether this is a declaration (vs inline definition)
|
|
125
|
+
* @returns The function symbol
|
|
126
|
+
*/
|
|
127
|
+
static collectMemberFunction(
|
|
128
|
+
className: string,
|
|
129
|
+
funcName: string,
|
|
130
|
+
declarator: any,
|
|
131
|
+
returnType: string,
|
|
132
|
+
sourceFile: string,
|
|
133
|
+
line: number,
|
|
134
|
+
isDeclaration: boolean,
|
|
135
|
+
): ICppFunctionSymbol {
|
|
136
|
+
const params = FunctionCollector._mapParameters(
|
|
137
|
+
DeclaratorUtils.extractFunctionParameters(declarator),
|
|
138
|
+
);
|
|
139
|
+
|
|
140
|
+
return {
|
|
141
|
+
kind: "function",
|
|
142
|
+
name: `${className}::${funcName}`,
|
|
143
|
+
type: returnType,
|
|
144
|
+
sourceFile,
|
|
145
|
+
sourceLine: line,
|
|
146
|
+
sourceLanguage: ESourceLanguage.Cpp,
|
|
147
|
+
isExported: true,
|
|
148
|
+
parent: className,
|
|
149
|
+
parameters: params.length > 0 ? params : undefined,
|
|
150
|
+
isDeclaration: isDeclaration || undefined,
|
|
151
|
+
};
|
|
152
|
+
}
|
|
153
|
+
}
|
|
154
|
+
|
|
155
|
+
export default FunctionCollector;
|
|
@@ -0,0 +1,65 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* NamespaceCollector - Extracts namespace declarations from C++ parse trees.
|
|
3
|
+
*
|
|
4
|
+
* Produces ICppNamespaceSymbol instances.
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
8
|
+
|
|
9
|
+
import ESourceLanguage from "../../../../../utils/types/ESourceLanguage";
|
|
10
|
+
import ICppNamespaceSymbol from "../../../../types/symbols/cpp/ICppNamespaceSymbol";
|
|
11
|
+
|
|
12
|
+
class NamespaceCollector {
|
|
13
|
+
/**
|
|
14
|
+
* Collect a namespace definition and return an ICppNamespaceSymbol.
|
|
15
|
+
*
|
|
16
|
+
* @param nsDef The namespace definition context
|
|
17
|
+
* @param sourceFile Source file path
|
|
18
|
+
* @param line Line number
|
|
19
|
+
* @param currentNamespace Optional parent namespace name
|
|
20
|
+
* @returns The namespace symbol
|
|
21
|
+
*/
|
|
22
|
+
static collect(
|
|
23
|
+
nsDef: any,
|
|
24
|
+
sourceFile: string,
|
|
25
|
+
line: number,
|
|
26
|
+
currentNamespace?: string,
|
|
27
|
+
): ICppNamespaceSymbol | null {
|
|
28
|
+
const identifier = nsDef.Identifier?.();
|
|
29
|
+
const originalNs = nsDef.originalNamespaceName?.();
|
|
30
|
+
|
|
31
|
+
const name = identifier?.getText() ?? originalNs?.getText();
|
|
32
|
+
if (!name) return null;
|
|
33
|
+
|
|
34
|
+
// Use full qualified name for nested namespaces
|
|
35
|
+
const fullName = currentNamespace ? `${currentNamespace}::${name}` : name;
|
|
36
|
+
|
|
37
|
+
return {
|
|
38
|
+
kind: "namespace",
|
|
39
|
+
name: fullName,
|
|
40
|
+
sourceFile,
|
|
41
|
+
sourceLine: line,
|
|
42
|
+
sourceLanguage: ESourceLanguage.Cpp,
|
|
43
|
+
isExported: true,
|
|
44
|
+
parent: currentNamespace,
|
|
45
|
+
};
|
|
46
|
+
}
|
|
47
|
+
|
|
48
|
+
/**
|
|
49
|
+
* Get the full namespace name after processing this namespace definition.
|
|
50
|
+
*/
|
|
51
|
+
static getFullNamespaceName(
|
|
52
|
+
nsDef: any,
|
|
53
|
+
currentNamespace?: string,
|
|
54
|
+
): string | undefined {
|
|
55
|
+
const identifier = nsDef.Identifier?.();
|
|
56
|
+
const originalNs = nsDef.originalNamespaceName?.();
|
|
57
|
+
|
|
58
|
+
const name = identifier?.getText() ?? originalNs?.getText();
|
|
59
|
+
if (!name) return currentNamespace;
|
|
60
|
+
|
|
61
|
+
return currentNamespace ? `${currentNamespace}::${name}` : name;
|
|
62
|
+
}
|
|
63
|
+
}
|
|
64
|
+
|
|
65
|
+
export default NamespaceCollector;
|
|
@@ -0,0 +1,46 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* TypeAliasCollector - Extracts type alias declarations from C++ parse trees.
|
|
3
|
+
*
|
|
4
|
+
* Handles C++ using declarations (using X = Y).
|
|
5
|
+
* Produces ICppTypeAliasSymbol instances.
|
|
6
|
+
*/
|
|
7
|
+
|
|
8
|
+
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
9
|
+
|
|
10
|
+
import ESourceLanguage from "../../../../../utils/types/ESourceLanguage";
|
|
11
|
+
import ICppTypeAliasSymbol from "../../../../types/symbols/cpp/ICppTypeAliasSymbol";
|
|
12
|
+
|
|
13
|
+
class TypeAliasCollector {
|
|
14
|
+
/**
|
|
15
|
+
* Collect an alias declaration (using X = Y) and return an ICppTypeAliasSymbol.
|
|
16
|
+
*
|
|
17
|
+
* @param aliasDecl The alias declaration context
|
|
18
|
+
* @param sourceFile Source file path
|
|
19
|
+
* @param line Line number
|
|
20
|
+
* @param currentNamespace Optional current namespace
|
|
21
|
+
* @returns The type alias symbol or null if no name
|
|
22
|
+
*/
|
|
23
|
+
static collect(
|
|
24
|
+
aliasDecl: any,
|
|
25
|
+
sourceFile: string,
|
|
26
|
+
line: number,
|
|
27
|
+
currentNamespace?: string,
|
|
28
|
+
): ICppTypeAliasSymbol | null {
|
|
29
|
+
const identifier = aliasDecl.Identifier?.();
|
|
30
|
+
if (!identifier) return null;
|
|
31
|
+
|
|
32
|
+
const name = identifier.getText();
|
|
33
|
+
|
|
34
|
+
return {
|
|
35
|
+
kind: "type",
|
|
36
|
+
name,
|
|
37
|
+
sourceFile,
|
|
38
|
+
sourceLine: line,
|
|
39
|
+
sourceLanguage: ESourceLanguage.Cpp,
|
|
40
|
+
isExported: true,
|
|
41
|
+
parent: currentNamespace,
|
|
42
|
+
};
|
|
43
|
+
}
|
|
44
|
+
}
|
|
45
|
+
|
|
46
|
+
export default TypeAliasCollector;
|
|
@@ -0,0 +1,54 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* VariableCollector - Extracts variable declarations from C++ parse trees.
|
|
3
|
+
*
|
|
4
|
+
* Produces ICppVariableSymbol instances.
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
8
|
+
|
|
9
|
+
import ESourceLanguage from "../../../../../utils/types/ESourceLanguage";
|
|
10
|
+
import ICppVariableSymbol from "../../../../types/symbols/cpp/ICppVariableSymbol";
|
|
11
|
+
import DeclaratorUtils from "../utils/DeclaratorUtils";
|
|
12
|
+
|
|
13
|
+
class VariableCollector {
|
|
14
|
+
/**
|
|
15
|
+
* Collect a variable declaration and return an ICppVariableSymbol.
|
|
16
|
+
*
|
|
17
|
+
* @param declarator The declarator context
|
|
18
|
+
* @param baseType The variable type string
|
|
19
|
+
* @param sourceFile Source file path
|
|
20
|
+
* @param line Line number
|
|
21
|
+
* @param currentNamespace Optional current namespace
|
|
22
|
+
* @returns The variable symbol or null if no name
|
|
23
|
+
*/
|
|
24
|
+
static collect(
|
|
25
|
+
declarator: any,
|
|
26
|
+
baseType: string,
|
|
27
|
+
sourceFile: string,
|
|
28
|
+
line: number,
|
|
29
|
+
currentNamespace?: string,
|
|
30
|
+
): ICppVariableSymbol | null {
|
|
31
|
+
const name = DeclaratorUtils.extractDeclaratorName(declarator);
|
|
32
|
+
if (!name) return null;
|
|
33
|
+
|
|
34
|
+
const fullName = currentNamespace ? `${currentNamespace}::${name}` : name;
|
|
35
|
+
|
|
36
|
+
// Extract array dimensions
|
|
37
|
+
const arrayDimensions = DeclaratorUtils.extractArrayDimensions(declarator);
|
|
38
|
+
|
|
39
|
+
return {
|
|
40
|
+
kind: "variable",
|
|
41
|
+
name: fullName,
|
|
42
|
+
type: baseType,
|
|
43
|
+
sourceFile,
|
|
44
|
+
sourceLine: line,
|
|
45
|
+
sourceLanguage: ESourceLanguage.Cpp,
|
|
46
|
+
isExported: true,
|
|
47
|
+
parent: currentNamespace,
|
|
48
|
+
isArray: arrayDimensions.length > 0 ? true : undefined,
|
|
49
|
+
arrayDimensions: arrayDimensions.length > 0 ? arrayDimensions : undefined,
|
|
50
|
+
};
|
|
51
|
+
}
|
|
52
|
+
}
|
|
53
|
+
|
|
54
|
+
export default VariableCollector;
|