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
|
@@ -1,874 +0,0 @@
|
|
|
1
|
-
/**
|
|
2
|
-
* C++ Symbol Collector
|
|
3
|
-
* Extracts symbols from C++ parse trees for the unified symbol table
|
|
4
|
-
*/
|
|
5
|
-
|
|
6
|
-
/* eslint-disable @typescript-eslint/no-explicit-any */
|
|
7
|
-
|
|
8
|
-
import {
|
|
9
|
-
CPP14Parser,
|
|
10
|
-
ClassSpecifierContext,
|
|
11
|
-
} from "../parser/cpp/grammar/CPP14Parser";
|
|
12
|
-
import ISymbol from "../../../utils/types/ISymbol";
|
|
13
|
-
import ESymbolKind from "../../../utils/types/ESymbolKind";
|
|
14
|
-
import ESourceLanguage from "../../../utils/types/ESourceLanguage";
|
|
15
|
-
import SymbolTable from "./SymbolTable";
|
|
16
|
-
import SymbolUtils from "./SymbolUtils";
|
|
17
|
-
import SymbolCollectorContext from "./SymbolCollectorContext";
|
|
18
|
-
import ICollectorContext from "./types/ICollectorContext";
|
|
19
|
-
|
|
20
|
-
// Import context types
|
|
21
|
-
type TranslationUnitContext = ReturnType<CPP14Parser["translationUnit"]>;
|
|
22
|
-
|
|
23
|
-
/**
|
|
24
|
-
* Collects symbols from a C++ parse tree
|
|
25
|
-
*/
|
|
26
|
-
class CppSymbolCollector {
|
|
27
|
-
private readonly ctx: ICollectorContext;
|
|
28
|
-
|
|
29
|
-
private currentNamespace: string | undefined;
|
|
30
|
-
|
|
31
|
-
constructor(sourceFile: string, symbolTable?: SymbolTable) {
|
|
32
|
-
this.ctx = SymbolCollectorContext.create(sourceFile, symbolTable);
|
|
33
|
-
}
|
|
34
|
-
|
|
35
|
-
/**
|
|
36
|
-
* Get warnings generated during symbol collection
|
|
37
|
-
*/
|
|
38
|
-
getWarnings(): string[] {
|
|
39
|
-
return SymbolCollectorContext.getWarnings(this.ctx);
|
|
40
|
-
}
|
|
41
|
-
|
|
42
|
-
// ========================================================================
|
|
43
|
-
// Symbol Creation Helpers (Issue #707: Reduce code duplication)
|
|
44
|
-
// ========================================================================
|
|
45
|
-
|
|
46
|
-
/**
|
|
47
|
-
* Add a class/struct symbol to the symbol table.
|
|
48
|
-
*/
|
|
49
|
-
private _addClassSymbol(fullName: string, line: number): void {
|
|
50
|
-
SymbolCollectorContext.addSymbol(this.ctx, {
|
|
51
|
-
name: fullName,
|
|
52
|
-
kind: ESymbolKind.Class,
|
|
53
|
-
sourceFile: this.ctx.sourceFile,
|
|
54
|
-
sourceLine: line,
|
|
55
|
-
sourceLanguage: ESourceLanguage.Cpp,
|
|
56
|
-
isExported: true,
|
|
57
|
-
parent: this.currentNamespace,
|
|
58
|
-
});
|
|
59
|
-
}
|
|
60
|
-
|
|
61
|
-
/**
|
|
62
|
-
* Add a member function symbol to the symbol table.
|
|
63
|
-
*/
|
|
64
|
-
private _addMemberFunctionSymbol(
|
|
65
|
-
className: string,
|
|
66
|
-
funcName: string,
|
|
67
|
-
returnType: string,
|
|
68
|
-
params: Array<{
|
|
69
|
-
name: string;
|
|
70
|
-
type: string;
|
|
71
|
-
isConst: boolean;
|
|
72
|
-
isArray: boolean;
|
|
73
|
-
}>,
|
|
74
|
-
line: number,
|
|
75
|
-
isDeclaration: boolean,
|
|
76
|
-
): void {
|
|
77
|
-
SymbolCollectorContext.addSymbol(this.ctx, {
|
|
78
|
-
name: `${className}::${funcName}`,
|
|
79
|
-
kind: ESymbolKind.Function,
|
|
80
|
-
type: returnType,
|
|
81
|
-
sourceFile: this.ctx.sourceFile,
|
|
82
|
-
sourceLine: line,
|
|
83
|
-
sourceLanguage: ESourceLanguage.Cpp,
|
|
84
|
-
isExported: true,
|
|
85
|
-
isDeclaration: isDeclaration || undefined,
|
|
86
|
-
parent: className,
|
|
87
|
-
parameters: params.length > 0 ? params : undefined,
|
|
88
|
-
});
|
|
89
|
-
}
|
|
90
|
-
|
|
91
|
-
/**
|
|
92
|
-
* Collect all symbols from a C++ translation unit
|
|
93
|
-
*/
|
|
94
|
-
collect(tree: TranslationUnitContext): ISymbol[] {
|
|
95
|
-
SymbolCollectorContext.reset(this.ctx);
|
|
96
|
-
this.currentNamespace = undefined;
|
|
97
|
-
|
|
98
|
-
if (!tree) {
|
|
99
|
-
return SymbolCollectorContext.getSymbols(this.ctx);
|
|
100
|
-
}
|
|
101
|
-
|
|
102
|
-
const declSeq = tree.declarationseq?.();
|
|
103
|
-
if (!declSeq) {
|
|
104
|
-
return SymbolCollectorContext.getSymbols(this.ctx);
|
|
105
|
-
}
|
|
106
|
-
|
|
107
|
-
for (const decl of declSeq.declaration()) {
|
|
108
|
-
this.collectDeclaration(decl);
|
|
109
|
-
}
|
|
110
|
-
|
|
111
|
-
return SymbolCollectorContext.getSymbols(this.ctx);
|
|
112
|
-
}
|
|
113
|
-
|
|
114
|
-
private collectDeclaration(decl: any): void {
|
|
115
|
-
const line = decl.start?.line ?? 0;
|
|
116
|
-
|
|
117
|
-
// Function definition
|
|
118
|
-
const funcDef = decl.functionDefinition?.();
|
|
119
|
-
if (funcDef) {
|
|
120
|
-
this.collectFunctionDefinition(funcDef, line);
|
|
121
|
-
return;
|
|
122
|
-
}
|
|
123
|
-
|
|
124
|
-
// Namespace definition
|
|
125
|
-
const nsDef = decl.namespaceDefinition?.();
|
|
126
|
-
if (nsDef) {
|
|
127
|
-
this.collectNamespaceDefinition(nsDef, line);
|
|
128
|
-
return;
|
|
129
|
-
}
|
|
130
|
-
|
|
131
|
-
// Template declaration
|
|
132
|
-
const templDecl = decl.templateDeclaration?.();
|
|
133
|
-
if (templDecl) {
|
|
134
|
-
// Skip template declarations for now - complex to handle
|
|
135
|
-
return;
|
|
136
|
-
}
|
|
137
|
-
|
|
138
|
-
// Block declaration (simpleDeclaration, etc.)
|
|
139
|
-
const blockDecl = decl.blockDeclaration?.();
|
|
140
|
-
if (blockDecl) {
|
|
141
|
-
this.collectBlockDeclaration(blockDecl, line);
|
|
142
|
-
}
|
|
143
|
-
}
|
|
144
|
-
|
|
145
|
-
private collectFunctionDefinition(funcDef: any, line: number): void {
|
|
146
|
-
const declarator = funcDef.declarator?.();
|
|
147
|
-
if (!declarator) return;
|
|
148
|
-
|
|
149
|
-
const name = this.extractDeclaratorName(declarator);
|
|
150
|
-
if (!name) return;
|
|
151
|
-
|
|
152
|
-
// Get return type
|
|
153
|
-
const declSpecSeq = funcDef.declSpecifierSeq?.();
|
|
154
|
-
const returnType = declSpecSeq
|
|
155
|
-
? this.extractTypeFromDeclSpecSeq(declSpecSeq)
|
|
156
|
-
: "void";
|
|
157
|
-
|
|
158
|
-
const fullName = this.currentNamespace
|
|
159
|
-
? `${this.currentNamespace}::${name}`
|
|
160
|
-
: name;
|
|
161
|
-
|
|
162
|
-
// Issue #322: Extract function parameters
|
|
163
|
-
const params = this.extractFunctionParameters(declarator);
|
|
164
|
-
|
|
165
|
-
SymbolCollectorContext.addSymbol(this.ctx, {
|
|
166
|
-
name: fullName,
|
|
167
|
-
kind: ESymbolKind.Function,
|
|
168
|
-
type: returnType,
|
|
169
|
-
sourceFile: this.ctx.sourceFile,
|
|
170
|
-
sourceLine: line,
|
|
171
|
-
sourceLanguage: ESourceLanguage.Cpp,
|
|
172
|
-
isExported: true,
|
|
173
|
-
parent: this.currentNamespace,
|
|
174
|
-
parameters: params.length > 0 ? params : undefined,
|
|
175
|
-
});
|
|
176
|
-
}
|
|
177
|
-
|
|
178
|
-
private collectNamespaceDefinition(nsDef: any, line: number): void {
|
|
179
|
-
const identifier = nsDef.Identifier?.();
|
|
180
|
-
const originalNs = nsDef.originalNamespaceName?.();
|
|
181
|
-
|
|
182
|
-
const name = identifier?.getText() ?? originalNs?.getText();
|
|
183
|
-
if (!name) return;
|
|
184
|
-
|
|
185
|
-
SymbolCollectorContext.addSymbol(this.ctx, {
|
|
186
|
-
name,
|
|
187
|
-
kind: ESymbolKind.Namespace,
|
|
188
|
-
sourceFile: this.ctx.sourceFile,
|
|
189
|
-
sourceLine: line,
|
|
190
|
-
sourceLanguage: ESourceLanguage.Cpp,
|
|
191
|
-
isExported: true,
|
|
192
|
-
});
|
|
193
|
-
|
|
194
|
-
// Process namespace body
|
|
195
|
-
const savedNamespace = this.currentNamespace;
|
|
196
|
-
this.currentNamespace = this.currentNamespace
|
|
197
|
-
? `${this.currentNamespace}::${name}`
|
|
198
|
-
: name;
|
|
199
|
-
|
|
200
|
-
const body = nsDef.declarationseq?.();
|
|
201
|
-
if (body) {
|
|
202
|
-
for (const decl of body.declaration()) {
|
|
203
|
-
this.collectDeclaration(decl);
|
|
204
|
-
}
|
|
205
|
-
}
|
|
206
|
-
|
|
207
|
-
this.currentNamespace = savedNamespace;
|
|
208
|
-
}
|
|
209
|
-
|
|
210
|
-
private collectBlockDeclaration(blockDecl: any, line: number): void {
|
|
211
|
-
// Simple declaration (variables, typedefs, class declarations)
|
|
212
|
-
const simpleDecl = blockDecl.simpleDeclaration?.();
|
|
213
|
-
if (simpleDecl) {
|
|
214
|
-
this.collectSimpleDeclaration(simpleDecl, line);
|
|
215
|
-
}
|
|
216
|
-
|
|
217
|
-
// Using declaration
|
|
218
|
-
const usingDecl = blockDecl.usingDeclaration?.();
|
|
219
|
-
if (usingDecl) {
|
|
220
|
-
// Skip using declarations for now
|
|
221
|
-
}
|
|
222
|
-
|
|
223
|
-
// Alias declaration (using X = Y)
|
|
224
|
-
const aliasDecl = blockDecl.aliasDeclaration?.();
|
|
225
|
-
if (aliasDecl) {
|
|
226
|
-
const identifier = aliasDecl.Identifier?.();
|
|
227
|
-
if (identifier) {
|
|
228
|
-
SymbolCollectorContext.addSymbol(this.ctx, {
|
|
229
|
-
name: identifier.getText(),
|
|
230
|
-
kind: ESymbolKind.Type,
|
|
231
|
-
sourceFile: this.ctx.sourceFile,
|
|
232
|
-
sourceLine: line,
|
|
233
|
-
sourceLanguage: ESourceLanguage.Cpp,
|
|
234
|
-
isExported: true,
|
|
235
|
-
parent: this.currentNamespace,
|
|
236
|
-
});
|
|
237
|
-
}
|
|
238
|
-
}
|
|
239
|
-
}
|
|
240
|
-
|
|
241
|
-
/**
|
|
242
|
-
* Process type specifiers in a declaration, collecting classes and enums.
|
|
243
|
-
* Returns anonymous class specifier if found (for typedef handling).
|
|
244
|
-
*/
|
|
245
|
-
private processTypeSpecifiers(
|
|
246
|
-
declSpecSeq: any,
|
|
247
|
-
line: number,
|
|
248
|
-
): ClassSpecifierContext | null {
|
|
249
|
-
let anonymousClassSpec: ClassSpecifierContext | null = null;
|
|
250
|
-
|
|
251
|
-
for (const spec of declSpecSeq.declSpecifier?.() ?? []) {
|
|
252
|
-
const typeSpec = spec.typeSpecifier?.();
|
|
253
|
-
if (!typeSpec) continue;
|
|
254
|
-
|
|
255
|
-
const classSpec = typeSpec.classSpecifier?.();
|
|
256
|
-
if (classSpec) {
|
|
257
|
-
const result = this.handleClassSpecInDecl(classSpec, line);
|
|
258
|
-
if (result) {
|
|
259
|
-
anonymousClassSpec = result;
|
|
260
|
-
}
|
|
261
|
-
}
|
|
262
|
-
|
|
263
|
-
const enumSpec = typeSpec.enumSpecifier?.();
|
|
264
|
-
if (enumSpec) {
|
|
265
|
-
this.collectEnumSpecifier(enumSpec, line);
|
|
266
|
-
}
|
|
267
|
-
}
|
|
268
|
-
|
|
269
|
-
return anonymousClassSpec;
|
|
270
|
-
}
|
|
271
|
-
|
|
272
|
-
/**
|
|
273
|
-
* Handle a class specifier in a declaration.
|
|
274
|
-
* Returns the class spec if it's anonymous (for typedef handling).
|
|
275
|
-
*/
|
|
276
|
-
private handleClassSpecInDecl(
|
|
277
|
-
classSpec: any,
|
|
278
|
-
line: number,
|
|
279
|
-
): ClassSpecifierContext | null {
|
|
280
|
-
const classHead = classSpec.classHead?.();
|
|
281
|
-
const classHeadName = classHead?.classHeadName?.();
|
|
282
|
-
const className = classHeadName?.className?.();
|
|
283
|
-
const identifier = className?.Identifier?.();
|
|
284
|
-
|
|
285
|
-
if (identifier?.getText()) {
|
|
286
|
-
// Named struct - collect normally
|
|
287
|
-
this.collectClassSpecifier(classSpec, line);
|
|
288
|
-
return null;
|
|
289
|
-
}
|
|
290
|
-
|
|
291
|
-
// Issue #342: Anonymous struct - return for typedef handling
|
|
292
|
-
return classSpec;
|
|
293
|
-
}
|
|
294
|
-
|
|
295
|
-
/**
|
|
296
|
-
* Issue #342: Handle typedef of anonymous struct.
|
|
297
|
-
* Returns true if handled (caller should skip normal processing).
|
|
298
|
-
*/
|
|
299
|
-
private tryCollectAnonymousTypedef(
|
|
300
|
-
anonymousClassSpec: ClassSpecifierContext,
|
|
301
|
-
fullName: string,
|
|
302
|
-
line: number,
|
|
303
|
-
): boolean {
|
|
304
|
-
if (!this.ctx.symbolTable) return false;
|
|
305
|
-
|
|
306
|
-
const memberSpec = anonymousClassSpec.memberSpecification?.();
|
|
307
|
-
if (!memberSpec) return false;
|
|
308
|
-
|
|
309
|
-
this._addClassSymbol(fullName, line);
|
|
310
|
-
this.collectClassMembers(fullName, memberSpec);
|
|
311
|
-
return true;
|
|
312
|
-
}
|
|
313
|
-
|
|
314
|
-
/**
|
|
315
|
-
* Process a single declarator (variable or function).
|
|
316
|
-
*/
|
|
317
|
-
private collectDeclarator(
|
|
318
|
-
declarator: any,
|
|
319
|
-
baseType: string,
|
|
320
|
-
line: number,
|
|
321
|
-
anonymousClassSpec: ClassSpecifierContext | null,
|
|
322
|
-
): void {
|
|
323
|
-
const name = this.extractDeclaratorName(declarator);
|
|
324
|
-
if (!name) return;
|
|
325
|
-
|
|
326
|
-
const isFunction = this.declaratorIsFunction(declarator);
|
|
327
|
-
const fullName = this.currentNamespace
|
|
328
|
-
? `${this.currentNamespace}::${name}`
|
|
329
|
-
: name;
|
|
330
|
-
|
|
331
|
-
// Issue #342: Handle anonymous struct typedef
|
|
332
|
-
if (anonymousClassSpec) {
|
|
333
|
-
if (this.tryCollectAnonymousTypedef(anonymousClassSpec, fullName, line)) {
|
|
334
|
-
return;
|
|
335
|
-
}
|
|
336
|
-
}
|
|
337
|
-
|
|
338
|
-
// Issue #322: Extract parameters for function declarations
|
|
339
|
-
const params = isFunction ? this.extractFunctionParameters(declarator) : [];
|
|
340
|
-
|
|
341
|
-
SymbolCollectorContext.addSymbol(this.ctx, {
|
|
342
|
-
name: fullName,
|
|
343
|
-
kind: isFunction ? ESymbolKind.Function : ESymbolKind.Variable,
|
|
344
|
-
type: baseType,
|
|
345
|
-
sourceFile: this.ctx.sourceFile,
|
|
346
|
-
sourceLine: line,
|
|
347
|
-
sourceLanguage: ESourceLanguage.Cpp,
|
|
348
|
-
isExported: true,
|
|
349
|
-
isDeclaration: isFunction,
|
|
350
|
-
parent: this.currentNamespace,
|
|
351
|
-
parameters: params.length > 0 ? params : undefined,
|
|
352
|
-
});
|
|
353
|
-
}
|
|
354
|
-
|
|
355
|
-
private collectSimpleDeclaration(simpleDecl: any, line: number): void {
|
|
356
|
-
const declSpecSeq = simpleDecl.declSpecifierSeq?.();
|
|
357
|
-
if (!declSpecSeq) return;
|
|
358
|
-
|
|
359
|
-
const baseType = this.extractTypeFromDeclSpecSeq(declSpecSeq);
|
|
360
|
-
const anonymousClassSpec = this.processTypeSpecifiers(declSpecSeq, line);
|
|
361
|
-
|
|
362
|
-
// Collect declarators (variables, function prototypes)
|
|
363
|
-
const initDeclList = simpleDecl.initDeclaratorList?.();
|
|
364
|
-
if (!initDeclList) return;
|
|
365
|
-
|
|
366
|
-
for (const initDecl of initDeclList.initDeclarator()) {
|
|
367
|
-
const declarator = initDecl.declarator?.();
|
|
368
|
-
if (declarator) {
|
|
369
|
-
this.collectDeclarator(declarator, baseType, line, anonymousClassSpec);
|
|
370
|
-
}
|
|
371
|
-
}
|
|
372
|
-
}
|
|
373
|
-
|
|
374
|
-
private collectClassSpecifier(classSpec: any, line: number): void {
|
|
375
|
-
const classHead = classSpec.classHead?.();
|
|
376
|
-
if (!classHead) return;
|
|
377
|
-
|
|
378
|
-
const classHeadName = classHead.classHeadName?.();
|
|
379
|
-
if (!classHeadName) return;
|
|
380
|
-
|
|
381
|
-
const className = classHeadName.className?.();
|
|
382
|
-
if (!className) return;
|
|
383
|
-
|
|
384
|
-
const identifier = className.Identifier?.();
|
|
385
|
-
const name = identifier?.getText();
|
|
386
|
-
if (!name) return;
|
|
387
|
-
|
|
388
|
-
const fullName = this.currentNamespace
|
|
389
|
-
? `${this.currentNamespace}::${name}`
|
|
390
|
-
: name;
|
|
391
|
-
|
|
392
|
-
this._addClassSymbol(fullName, line);
|
|
393
|
-
|
|
394
|
-
// Extract struct/class field information if SymbolTable is available
|
|
395
|
-
if (this.ctx.symbolTable) {
|
|
396
|
-
const memberSpec = classSpec.memberSpecification?.();
|
|
397
|
-
if (memberSpec) {
|
|
398
|
-
this.collectClassMembers(fullName, memberSpec);
|
|
399
|
-
}
|
|
400
|
-
}
|
|
401
|
-
}
|
|
402
|
-
|
|
403
|
-
/**
|
|
404
|
-
* Collect class/struct member fields
|
|
405
|
-
*/
|
|
406
|
-
private collectClassMembers(className: string, memberSpec: any): void {
|
|
407
|
-
// Iterate through member declarations
|
|
408
|
-
for (const memberDecl of memberSpec.memberdeclaration?.() ?? []) {
|
|
409
|
-
this.collectMemberDeclaration(className, memberDecl);
|
|
410
|
-
}
|
|
411
|
-
}
|
|
412
|
-
|
|
413
|
-
/**
|
|
414
|
-
* Collect a single member declaration
|
|
415
|
-
*/
|
|
416
|
-
private collectMemberDeclaration(className: string, memberDecl: any): void {
|
|
417
|
-
const line = memberDecl.start?.line ?? 0;
|
|
418
|
-
|
|
419
|
-
// Issue #322: Check for inline function definition within the class
|
|
420
|
-
const funcDef = memberDecl.functionDefinition?.();
|
|
421
|
-
if (funcDef) {
|
|
422
|
-
this._collectInlineFunctionDef(className, funcDef, line);
|
|
423
|
-
return;
|
|
424
|
-
}
|
|
425
|
-
|
|
426
|
-
// Get member declaration list (for data members and function declarations)
|
|
427
|
-
const declSpecSeq = memberDecl.declSpecifierSeq?.();
|
|
428
|
-
if (!declSpecSeq) return;
|
|
429
|
-
|
|
430
|
-
const fieldType = this.extractTypeFromDeclSpecSeq(declSpecSeq);
|
|
431
|
-
|
|
432
|
-
// Get declarator list
|
|
433
|
-
const memberDeclList = memberDecl.memberDeclaratorList?.();
|
|
434
|
-
if (!memberDeclList) return;
|
|
435
|
-
|
|
436
|
-
for (const memberDeclarator of memberDeclList.memberDeclarator?.() ?? []) {
|
|
437
|
-
this._collectMemberDeclarator(
|
|
438
|
-
className,
|
|
439
|
-
memberDeclarator,
|
|
440
|
-
fieldType,
|
|
441
|
-
line,
|
|
442
|
-
);
|
|
443
|
-
}
|
|
444
|
-
}
|
|
445
|
-
|
|
446
|
-
/**
|
|
447
|
-
* Collect an inline function definition within a class
|
|
448
|
-
*/
|
|
449
|
-
private _collectInlineFunctionDef(
|
|
450
|
-
className: string,
|
|
451
|
-
funcDef: any,
|
|
452
|
-
line: number,
|
|
453
|
-
): void {
|
|
454
|
-
const declarator = funcDef.declarator?.();
|
|
455
|
-
if (!declarator) return;
|
|
456
|
-
|
|
457
|
-
const funcName = this.extractDeclaratorName(declarator);
|
|
458
|
-
if (!funcName) return;
|
|
459
|
-
|
|
460
|
-
const declSpecSeq = funcDef.declSpecifierSeq?.();
|
|
461
|
-
const returnType = declSpecSeq
|
|
462
|
-
? this.extractTypeFromDeclSpecSeq(declSpecSeq)
|
|
463
|
-
: "void";
|
|
464
|
-
const params = this.extractFunctionParameters(declarator);
|
|
465
|
-
this._addMemberFunctionSymbol(
|
|
466
|
-
className,
|
|
467
|
-
funcName,
|
|
468
|
-
returnType,
|
|
469
|
-
params,
|
|
470
|
-
line,
|
|
471
|
-
false,
|
|
472
|
-
);
|
|
473
|
-
}
|
|
474
|
-
|
|
475
|
-
/**
|
|
476
|
-
* Collect a single member declarator (function or data field)
|
|
477
|
-
*/
|
|
478
|
-
private _collectMemberDeclarator(
|
|
479
|
-
className: string,
|
|
480
|
-
memberDeclarator: any,
|
|
481
|
-
fieldType: string,
|
|
482
|
-
line: number,
|
|
483
|
-
): void {
|
|
484
|
-
const declarator = memberDeclarator.declarator?.();
|
|
485
|
-
if (!declarator) return;
|
|
486
|
-
|
|
487
|
-
const fieldName = this.extractDeclaratorName(declarator);
|
|
488
|
-
if (!fieldName) return;
|
|
489
|
-
|
|
490
|
-
// Issue #322: Collect member functions with their parameters
|
|
491
|
-
if (this.declaratorIsFunction(declarator)) {
|
|
492
|
-
this._collectMemberFunction(
|
|
493
|
-
className,
|
|
494
|
-
fieldName,
|
|
495
|
-
declarator,
|
|
496
|
-
fieldType,
|
|
497
|
-
line,
|
|
498
|
-
);
|
|
499
|
-
return;
|
|
500
|
-
}
|
|
501
|
-
|
|
502
|
-
this._collectDataField(className, fieldName, declarator, fieldType);
|
|
503
|
-
}
|
|
504
|
-
|
|
505
|
-
/**
|
|
506
|
-
* Collect a member function declaration
|
|
507
|
-
*/
|
|
508
|
-
private _collectMemberFunction(
|
|
509
|
-
className: string,
|
|
510
|
-
funcName: string,
|
|
511
|
-
declarator: any,
|
|
512
|
-
returnType: string,
|
|
513
|
-
line: number,
|
|
514
|
-
): void {
|
|
515
|
-
const params = this.extractFunctionParameters(declarator);
|
|
516
|
-
this._addMemberFunctionSymbol(
|
|
517
|
-
className,
|
|
518
|
-
funcName,
|
|
519
|
-
returnType,
|
|
520
|
-
params,
|
|
521
|
-
line,
|
|
522
|
-
true,
|
|
523
|
-
);
|
|
524
|
-
}
|
|
525
|
-
|
|
526
|
-
/**
|
|
527
|
-
* Collect a data field declaration
|
|
528
|
-
*/
|
|
529
|
-
private _collectDataField(
|
|
530
|
-
className: string,
|
|
531
|
-
fieldName: string,
|
|
532
|
-
declarator: any,
|
|
533
|
-
fieldType: string,
|
|
534
|
-
): void {
|
|
535
|
-
// Warn if field name conflicts with C-Next reserved property names
|
|
536
|
-
if (SymbolUtils.isReservedFieldName(fieldName)) {
|
|
537
|
-
SymbolCollectorContext.addWarning(
|
|
538
|
-
this.ctx,
|
|
539
|
-
SymbolUtils.getReservedFieldWarning("C++", className, fieldName),
|
|
540
|
-
);
|
|
541
|
-
}
|
|
542
|
-
|
|
543
|
-
// Extract array dimensions if any
|
|
544
|
-
const arrayDimensions = this.extractArrayDimensions(declarator);
|
|
545
|
-
|
|
546
|
-
// Add to SymbolTable
|
|
547
|
-
this.ctx.symbolTable!.addStructField(
|
|
548
|
-
className,
|
|
549
|
-
fieldName,
|
|
550
|
-
fieldType,
|
|
551
|
-
arrayDimensions.length > 0 ? arrayDimensions : undefined,
|
|
552
|
-
);
|
|
553
|
-
}
|
|
554
|
-
|
|
555
|
-
/**
|
|
556
|
-
* Extract array dimensions from a declarator
|
|
557
|
-
*/
|
|
558
|
-
private extractArrayDimensions(declarator: any): number[] {
|
|
559
|
-
const dimensions: number[] = [];
|
|
560
|
-
|
|
561
|
-
// For C++, we need to check both pointer and no-pointer declarators
|
|
562
|
-
const ptrDecl = declarator.pointerDeclarator?.();
|
|
563
|
-
if (ptrDecl) {
|
|
564
|
-
const noPtr = ptrDecl.noPointerDeclarator?.();
|
|
565
|
-
if (noPtr) {
|
|
566
|
-
return this.extractArrayDimensionsFromNoPtr(noPtr);
|
|
567
|
-
}
|
|
568
|
-
}
|
|
569
|
-
|
|
570
|
-
const noPtr = declarator.noPointerDeclarator?.();
|
|
571
|
-
if (noPtr) {
|
|
572
|
-
return this.extractArrayDimensionsFromNoPtr(noPtr);
|
|
573
|
-
}
|
|
574
|
-
|
|
575
|
-
return dimensions;
|
|
576
|
-
}
|
|
577
|
-
|
|
578
|
-
/**
|
|
579
|
-
* Extract array dimensions from a noPointerDeclarator
|
|
580
|
-
*/
|
|
581
|
-
private extractArrayDimensionsFromNoPtr(noPtr: any): number[] {
|
|
582
|
-
// Use shared utility for regex-based extraction
|
|
583
|
-
return SymbolUtils.parseArrayDimensions(noPtr.getText());
|
|
584
|
-
}
|
|
585
|
-
|
|
586
|
-
private collectEnumSpecifier(enumSpec: any, line: number): void {
|
|
587
|
-
const enumHead = enumSpec.enumHead?.();
|
|
588
|
-
if (!enumHead) return;
|
|
589
|
-
|
|
590
|
-
const identifier = enumHead.Identifier?.();
|
|
591
|
-
if (!identifier) return;
|
|
592
|
-
|
|
593
|
-
const name = identifier.getText();
|
|
594
|
-
const fullName = this.currentNamespace
|
|
595
|
-
? `${this.currentNamespace}::${name}`
|
|
596
|
-
: name;
|
|
597
|
-
|
|
598
|
-
SymbolCollectorContext.addSymbol(this.ctx, {
|
|
599
|
-
name: fullName,
|
|
600
|
-
kind: ESymbolKind.Enum,
|
|
601
|
-
sourceFile: this.ctx.sourceFile,
|
|
602
|
-
sourceLine: line,
|
|
603
|
-
sourceLanguage: ESourceLanguage.Cpp,
|
|
604
|
-
isExported: true,
|
|
605
|
-
parent: this.currentNamespace,
|
|
606
|
-
});
|
|
607
|
-
|
|
608
|
-
// Issue #208: Extract enum backing type for typed enums (e.g., enum EPressureType : uint8_t)
|
|
609
|
-
if (this.ctx.symbolTable) {
|
|
610
|
-
const enumbase = enumHead.enumbase?.();
|
|
611
|
-
if (enumbase) {
|
|
612
|
-
const typeSpecSeq = enumbase.typeSpecifierSeq?.();
|
|
613
|
-
if (typeSpecSeq) {
|
|
614
|
-
const typeName = typeSpecSeq.getText();
|
|
615
|
-
const bitWidth = this.getTypeWidth(typeName);
|
|
616
|
-
if (bitWidth > 0) {
|
|
617
|
-
this.ctx.symbolTable.addEnumBitWidth(fullName, bitWidth);
|
|
618
|
-
}
|
|
619
|
-
}
|
|
620
|
-
}
|
|
621
|
-
}
|
|
622
|
-
}
|
|
623
|
-
|
|
624
|
-
/**
|
|
625
|
-
* Issue #208: Map C/C++ type names to their bit widths
|
|
626
|
-
* Delegates to shared utility for consistent type width mapping
|
|
627
|
-
*/
|
|
628
|
-
private getTypeWidth(typeName: string): number {
|
|
629
|
-
return SymbolUtils.getTypeWidth(typeName);
|
|
630
|
-
}
|
|
631
|
-
|
|
632
|
-
// Helper methods
|
|
633
|
-
|
|
634
|
-
private extractDeclaratorName(declarator: any): string | null {
|
|
635
|
-
// Pointer declarator -> noPointerDeclarator
|
|
636
|
-
const ptrDecl = declarator.pointerDeclarator?.();
|
|
637
|
-
if (ptrDecl) {
|
|
638
|
-
const noPtr = ptrDecl.noPointerDeclarator?.();
|
|
639
|
-
if (noPtr) {
|
|
640
|
-
return this.extractNoPointerDeclaratorName(noPtr);
|
|
641
|
-
}
|
|
642
|
-
}
|
|
643
|
-
|
|
644
|
-
// No pointer declarator
|
|
645
|
-
const noPtr = declarator.noPointerDeclarator?.();
|
|
646
|
-
if (noPtr) {
|
|
647
|
-
return this.extractNoPointerDeclaratorName(noPtr);
|
|
648
|
-
}
|
|
649
|
-
|
|
650
|
-
return null;
|
|
651
|
-
}
|
|
652
|
-
|
|
653
|
-
private extractNoPointerDeclaratorName(noPtr: any): string | null {
|
|
654
|
-
const declId = noPtr.declaratorid?.();
|
|
655
|
-
if (declId) {
|
|
656
|
-
const idExpr = declId.idExpression?.();
|
|
657
|
-
if (idExpr) {
|
|
658
|
-
const unqualId = idExpr.unqualifiedId?.();
|
|
659
|
-
if (unqualId) {
|
|
660
|
-
const identifier = unqualId.Identifier?.();
|
|
661
|
-
if (identifier) {
|
|
662
|
-
return identifier.getText();
|
|
663
|
-
}
|
|
664
|
-
}
|
|
665
|
-
}
|
|
666
|
-
}
|
|
667
|
-
|
|
668
|
-
// Recursive case
|
|
669
|
-
const innerNoPtr = noPtr.noPointerDeclarator?.();
|
|
670
|
-
if (innerNoPtr) {
|
|
671
|
-
return this.extractNoPointerDeclaratorName(innerNoPtr);
|
|
672
|
-
}
|
|
673
|
-
|
|
674
|
-
return null;
|
|
675
|
-
}
|
|
676
|
-
|
|
677
|
-
private declaratorIsFunction(declarator: any): boolean {
|
|
678
|
-
const ptrDecl = declarator.pointerDeclarator?.();
|
|
679
|
-
if (ptrDecl) {
|
|
680
|
-
const noPtr = ptrDecl.noPointerDeclarator?.();
|
|
681
|
-
if (noPtr?.parametersAndQualifiers?.()) {
|
|
682
|
-
return true;
|
|
683
|
-
}
|
|
684
|
-
}
|
|
685
|
-
|
|
686
|
-
const noPtr = declarator.noPointerDeclarator?.();
|
|
687
|
-
if (noPtr?.parametersAndQualifiers?.()) {
|
|
688
|
-
return true;
|
|
689
|
-
}
|
|
690
|
-
|
|
691
|
-
return false;
|
|
692
|
-
}
|
|
693
|
-
|
|
694
|
-
/**
|
|
695
|
-
* Issue #322: Extract function parameters from a declarator.
|
|
696
|
-
* Returns an array of parameter info objects with name, type, and pointer flag.
|
|
697
|
-
*/
|
|
698
|
-
private extractFunctionParameters(declarator: any): Array<{
|
|
699
|
-
name: string;
|
|
700
|
-
type: string;
|
|
701
|
-
isConst: boolean;
|
|
702
|
-
isArray: boolean;
|
|
703
|
-
}> {
|
|
704
|
-
const params: Array<{
|
|
705
|
-
name: string;
|
|
706
|
-
type: string;
|
|
707
|
-
isConst: boolean;
|
|
708
|
-
isArray: boolean;
|
|
709
|
-
}> = [];
|
|
710
|
-
|
|
711
|
-
// Find parametersAndQualifiers from the declarator
|
|
712
|
-
let paramsAndQuals: any = null;
|
|
713
|
-
const ptrDecl = declarator.pointerDeclarator?.();
|
|
714
|
-
if (ptrDecl) {
|
|
715
|
-
const noPtr = ptrDecl.noPointerDeclarator?.();
|
|
716
|
-
paramsAndQuals = noPtr?.parametersAndQualifiers?.();
|
|
717
|
-
}
|
|
718
|
-
if (!paramsAndQuals) {
|
|
719
|
-
const noPtr = declarator.noPointerDeclarator?.();
|
|
720
|
-
paramsAndQuals = noPtr?.parametersAndQualifiers?.();
|
|
721
|
-
}
|
|
722
|
-
if (!paramsAndQuals) {
|
|
723
|
-
return params;
|
|
724
|
-
}
|
|
725
|
-
|
|
726
|
-
// Get parameterDeclarationClause
|
|
727
|
-
const paramClause = paramsAndQuals.parameterDeclarationClause?.();
|
|
728
|
-
if (!paramClause) {
|
|
729
|
-
return params;
|
|
730
|
-
}
|
|
731
|
-
|
|
732
|
-
// Get parameterDeclarationList
|
|
733
|
-
const paramList = paramClause.parameterDeclarationList?.();
|
|
734
|
-
if (!paramList) {
|
|
735
|
-
return params;
|
|
736
|
-
}
|
|
737
|
-
|
|
738
|
-
// Iterate over parameterDeclaration entries
|
|
739
|
-
for (const paramDecl of paramList.parameterDeclaration?.() ?? []) {
|
|
740
|
-
const paramInfo = this.extractParameterInfo(paramDecl);
|
|
741
|
-
if (paramInfo) {
|
|
742
|
-
params.push(paramInfo);
|
|
743
|
-
}
|
|
744
|
-
}
|
|
745
|
-
|
|
746
|
-
return params;
|
|
747
|
-
}
|
|
748
|
-
|
|
749
|
-
/**
|
|
750
|
-
* Issue #322: Extract type and name info from a single parameter declaration.
|
|
751
|
-
*/
|
|
752
|
-
private extractParameterInfo(paramDecl: any): {
|
|
753
|
-
name: string;
|
|
754
|
-
type: string;
|
|
755
|
-
isConst: boolean;
|
|
756
|
-
isArray: boolean;
|
|
757
|
-
} | null {
|
|
758
|
-
// Get the type from declSpecifierSeq
|
|
759
|
-
const declSpecSeq = paramDecl.declSpecifierSeq?.();
|
|
760
|
-
if (!declSpecSeq) {
|
|
761
|
-
return null;
|
|
762
|
-
}
|
|
763
|
-
|
|
764
|
-
let baseType = this.extractTypeFromDeclSpecSeq(declSpecSeq);
|
|
765
|
-
let isConst = false;
|
|
766
|
-
let isPointer = false;
|
|
767
|
-
|
|
768
|
-
// Check for const qualifier
|
|
769
|
-
const declText = declSpecSeq.getText();
|
|
770
|
-
if (declText.includes("const")) {
|
|
771
|
-
isConst = true;
|
|
772
|
-
}
|
|
773
|
-
|
|
774
|
-
// Check for pointer in declarator or abstractDeclarator
|
|
775
|
-
const declarator = paramDecl.declarator?.();
|
|
776
|
-
const abstractDecl = paramDecl.abstractDeclarator?.();
|
|
777
|
-
|
|
778
|
-
if (declarator) {
|
|
779
|
-
// Check if declarator has pointer operator
|
|
780
|
-
if (this.declaratorHasPointer(declarator)) {
|
|
781
|
-
isPointer = true;
|
|
782
|
-
}
|
|
783
|
-
}
|
|
784
|
-
if (abstractDecl) {
|
|
785
|
-
// Abstract declarator (no name) - check for pointer
|
|
786
|
-
if (this.abstractDeclaratorHasPointer(abstractDecl)) {
|
|
787
|
-
isPointer = true;
|
|
788
|
-
}
|
|
789
|
-
}
|
|
790
|
-
|
|
791
|
-
// If pointer, append * to the type
|
|
792
|
-
if (isPointer) {
|
|
793
|
-
baseType = baseType + "*";
|
|
794
|
-
}
|
|
795
|
-
|
|
796
|
-
// Get parameter name (may be empty for abstract declarators)
|
|
797
|
-
let paramName = "";
|
|
798
|
-
if (declarator) {
|
|
799
|
-
const name = this.extractDeclaratorName(declarator);
|
|
800
|
-
if (name) {
|
|
801
|
-
paramName = name;
|
|
802
|
-
}
|
|
803
|
-
}
|
|
804
|
-
|
|
805
|
-
return {
|
|
806
|
-
name: paramName,
|
|
807
|
-
type: baseType,
|
|
808
|
-
isConst,
|
|
809
|
-
isArray: false, // Could be enhanced to detect arrays
|
|
810
|
-
};
|
|
811
|
-
}
|
|
812
|
-
|
|
813
|
-
/**
|
|
814
|
-
* Issue #322: Check if a declarator contains a pointer operator.
|
|
815
|
-
*/
|
|
816
|
-
private declaratorHasPointer(declarator: any): boolean {
|
|
817
|
-
const ptrDecl = declarator.pointerDeclarator?.();
|
|
818
|
-
if (ptrDecl) {
|
|
819
|
-
// Check for pointerOperator children
|
|
820
|
-
const ptrOps = ptrDecl.pointerOperator?.();
|
|
821
|
-
if (ptrOps && ptrOps.length > 0) {
|
|
822
|
-
return true;
|
|
823
|
-
}
|
|
824
|
-
// Also check getText for *
|
|
825
|
-
if (ptrDecl.getText().includes("*")) {
|
|
826
|
-
return true;
|
|
827
|
-
}
|
|
828
|
-
}
|
|
829
|
-
return false;
|
|
830
|
-
}
|
|
831
|
-
|
|
832
|
-
/**
|
|
833
|
-
* Issue #322: Check if an abstract declarator (pointer without name) contains a pointer.
|
|
834
|
-
*/
|
|
835
|
-
private abstractDeclaratorHasPointer(abstractDecl: any): boolean {
|
|
836
|
-
// Check for pointerAbstractDeclarator
|
|
837
|
-
const ptrAbstract = abstractDecl.pointerAbstractDeclarator?.();
|
|
838
|
-
if (ptrAbstract) {
|
|
839
|
-
const ptrOps = ptrAbstract.pointerOperator?.();
|
|
840
|
-
if (ptrOps && ptrOps.length > 0) {
|
|
841
|
-
return true;
|
|
842
|
-
}
|
|
843
|
-
if (ptrAbstract.getText().includes("*")) {
|
|
844
|
-
return true;
|
|
845
|
-
}
|
|
846
|
-
}
|
|
847
|
-
// Simple check for * in the text
|
|
848
|
-
if (abstractDecl.getText().includes("*")) {
|
|
849
|
-
return true;
|
|
850
|
-
}
|
|
851
|
-
return false;
|
|
852
|
-
}
|
|
853
|
-
|
|
854
|
-
private extractTypeFromDeclSpecSeq(declSpecSeq: any): string {
|
|
855
|
-
const parts: string[] = [];
|
|
856
|
-
|
|
857
|
-
for (const spec of declSpecSeq.declSpecifier?.() ?? []) {
|
|
858
|
-
const typeSpec = spec.typeSpecifier?.();
|
|
859
|
-
if (typeSpec) {
|
|
860
|
-
const trailingType = typeSpec.trailingTypeSpecifier?.();
|
|
861
|
-
if (trailingType) {
|
|
862
|
-
const simpleType = trailingType.simpleTypeSpecifier?.();
|
|
863
|
-
if (simpleType) {
|
|
864
|
-
parts.push(simpleType.getText());
|
|
865
|
-
}
|
|
866
|
-
}
|
|
867
|
-
}
|
|
868
|
-
}
|
|
869
|
-
|
|
870
|
-
return parts.join(" ") || "int";
|
|
871
|
-
}
|
|
872
|
-
}
|
|
873
|
-
|
|
874
|
-
export default CppSymbolCollector;
|