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
|
@@ -25,13 +25,16 @@ import ExternalTypeHeaderBuilder from "./output/headers/ExternalTypeHeaderBuilde
|
|
|
25
25
|
import ICodeGenSymbols from "./types/ICodeGenSymbols";
|
|
26
26
|
import IncludeExtractor from "./logic/IncludeExtractor";
|
|
27
27
|
import SymbolTable from "./logic/symbols/SymbolTable";
|
|
28
|
-
import
|
|
29
|
-
import
|
|
28
|
+
import ISerializedSymbol from "./types/ISerializedSymbol";
|
|
29
|
+
import ESourceLanguage from "../utils/types/ESourceLanguage";
|
|
30
30
|
import CNextResolver from "./logic/symbols/cnext";
|
|
31
|
-
import
|
|
31
|
+
import SymbolRegistry from "./state/SymbolRegistry";
|
|
32
32
|
import TSymbolInfoAdapter from "./logic/symbols/cnext/adapters/TSymbolInfoAdapter";
|
|
33
|
-
import
|
|
34
|
-
import
|
|
33
|
+
import CResolver from "./logic/symbols/c";
|
|
34
|
+
import CppResolver from "./logic/symbols/cpp";
|
|
35
|
+
import HeaderSymbolAdapter from "./output/headers/adapters/HeaderSymbolAdapter";
|
|
36
|
+
import IHeaderSymbol from "./output/headers/types/IHeaderSymbol";
|
|
37
|
+
import TSymbol from "./types/symbols/TSymbol";
|
|
35
38
|
import Preprocessor from "./logic/preprocessor/Preprocessor";
|
|
36
39
|
|
|
37
40
|
import FileDiscovery from "./data/FileDiscovery";
|
|
@@ -50,13 +53,12 @@ import IFileResult from "./types/IFileResult";
|
|
|
50
53
|
import IPipelineFile from "./types/IPipelineFile";
|
|
51
54
|
import IPipelineInput from "./types/IPipelineInput";
|
|
52
55
|
import ITranspileError from "../lib/types/ITranspileError";
|
|
53
|
-
import TranspilerState from "./
|
|
56
|
+
import TranspilerState from "./state/TranspilerState";
|
|
54
57
|
import runAnalyzers from "./logic/analysis/runAnalyzers";
|
|
55
58
|
import ModificationAnalyzer from "./logic/analysis/ModificationAnalyzer";
|
|
56
59
|
import CacheManager from "../utils/cache/CacheManager";
|
|
57
60
|
import MapUtils from "../utils/MapUtils";
|
|
58
61
|
import detectCppSyntax from "./logic/detectCppSyntax";
|
|
59
|
-
import AutoConstUpdater from "./logic/symbols/AutoConstUpdater";
|
|
60
62
|
import TransitiveEnumCollector from "./logic/symbols/TransitiveEnumCollector";
|
|
61
63
|
|
|
62
64
|
/**
|
|
@@ -269,8 +271,8 @@ class Transpiler {
|
|
|
269
271
|
// Stage 3b: Resolve external const array dimensions
|
|
270
272
|
CodeGenState.symbolTable.resolveExternalArrayDimensions();
|
|
271
273
|
|
|
272
|
-
// Stage 4: Check for symbol conflicts
|
|
273
|
-
if (!
|
|
274
|
+
// Stage 4: Check for symbol conflicts
|
|
275
|
+
if (!this._checkSymbolConflicts(result)) {
|
|
274
276
|
return;
|
|
275
277
|
}
|
|
276
278
|
|
|
@@ -333,13 +335,11 @@ class Transpiler {
|
|
|
333
335
|
}
|
|
334
336
|
|
|
335
337
|
try {
|
|
336
|
-
// ADR-055: Use composable collectors via CNextResolver
|
|
338
|
+
// ADR-055 Phase 7: Use composable collectors via CNextResolver
|
|
337
339
|
const tSymbols = CNextResolver.resolve(tree, file.path);
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
);
|
|
342
|
-
CodeGenState.symbolTable.addSymbols(iSymbols);
|
|
340
|
+
|
|
341
|
+
// ADR-055 Phase 7: Store TSymbol directly in SymbolTable (no ISymbol conversion)
|
|
342
|
+
CodeGenState.symbolTable.addTSymbols(tSymbols);
|
|
343
343
|
|
|
344
344
|
// Issue #465: Store ICodeGenSymbols for external enum resolution in stage 5
|
|
345
345
|
const symbolInfo = TSymbolInfoAdapter.convert(tSymbols);
|
|
@@ -450,16 +450,13 @@ class Transpiler {
|
|
|
450
450
|
this._accumulateFileModifications();
|
|
451
451
|
}
|
|
452
452
|
|
|
453
|
-
//
|
|
454
|
-
const
|
|
455
|
-
|
|
456
|
-
const knownEnums =
|
|
457
|
-
this.state.getSymbolInfo(sourcePath)?.knownEnums ?? new Set<string>();
|
|
458
|
-
AutoConstUpdater.update(symbols, unmodifiedParams, knownEnums);
|
|
453
|
+
// ADR-055 Phase 7: Get TSymbols for header generation (auto-const applied during conversion)
|
|
454
|
+
const fileSymbols =
|
|
455
|
+
CodeGenState.symbolTable.getTSymbolsByFile(sourcePath);
|
|
459
456
|
|
|
460
457
|
// Generate header content
|
|
461
458
|
const headerCode = this.generateHeaderContent(
|
|
462
|
-
|
|
459
|
+
fileSymbols,
|
|
463
460
|
sourcePath,
|
|
464
461
|
this.cppDetected,
|
|
465
462
|
userIncludes,
|
|
@@ -584,7 +581,6 @@ class Transpiler {
|
|
|
584
581
|
cnextFiles: [...cnextIncludeFiles, mainFile],
|
|
585
582
|
headerFiles: allHeaders,
|
|
586
583
|
writeOutputToDisk: false,
|
|
587
|
-
skipConflictCheck: true,
|
|
588
584
|
};
|
|
589
585
|
}
|
|
590
586
|
|
|
@@ -621,6 +617,8 @@ class Transpiler {
|
|
|
621
617
|
this.state.reset();
|
|
622
618
|
// Issue #634: Reset symbol table for new run
|
|
623
619
|
CodeGenState.symbolTable.clear();
|
|
620
|
+
// Reset SymbolRegistry for new run (new IFunctionSymbol type system)
|
|
621
|
+
SymbolRegistry.reset();
|
|
624
622
|
}
|
|
625
623
|
|
|
626
624
|
/**
|
|
@@ -1057,7 +1055,8 @@ class Transpiler {
|
|
|
1057
1055
|
}
|
|
1058
1056
|
|
|
1059
1057
|
// Restore symbols, struct fields, needsStructKeyword, and enumBitWidth from cache
|
|
1060
|
-
|
|
1058
|
+
// ADR-055 Phase 7: Cache returns ISerializedSymbol[], converted to typed symbols
|
|
1059
|
+
this.restoreCachedSymbols(cached.symbols, file);
|
|
1061
1060
|
CodeGenState.symbolTable.restoreStructFields(cached.structFields);
|
|
1062
1061
|
CodeGenState.symbolTable.restoreNeedsStructKeyword(
|
|
1063
1062
|
cached.needsStructKeyword,
|
|
@@ -1070,6 +1069,78 @@ class Transpiler {
|
|
|
1070
1069
|
return true;
|
|
1071
1070
|
}
|
|
1072
1071
|
|
|
1072
|
+
/**
|
|
1073
|
+
* Restore cached symbols to the symbol table.
|
|
1074
|
+
* ADR-055 Phase 7: Converts ISerializedSymbol[] from cache to typed symbols.
|
|
1075
|
+
*/
|
|
1076
|
+
private restoreCachedSymbols(
|
|
1077
|
+
symbols: ISerializedSymbol[],
|
|
1078
|
+
_file: IDiscoveredFile,
|
|
1079
|
+
): void {
|
|
1080
|
+
for (const symbol of symbols) {
|
|
1081
|
+
// Determine which storage to use based on source language
|
|
1082
|
+
if (symbol.sourceLanguage === ESourceLanguage.CNext) {
|
|
1083
|
+
// C-Next symbols are never cached (they use TSymbol format).
|
|
1084
|
+
// If we see one here, it indicates a cache format issue - skip silently
|
|
1085
|
+
// since C-Next symbols are always re-parsed from source anyway.
|
|
1086
|
+
continue;
|
|
1087
|
+
} else if (symbol.sourceLanguage === ESourceLanguage.C) {
|
|
1088
|
+
// Convert ISymbol to TCSymbol (simplified conversion)
|
|
1089
|
+
CodeGenState.symbolTable.addCSymbol({
|
|
1090
|
+
kind: symbol.kind as
|
|
1091
|
+
| "struct"
|
|
1092
|
+
| "enum"
|
|
1093
|
+
| "function"
|
|
1094
|
+
| "variable"
|
|
1095
|
+
| "enum_member"
|
|
1096
|
+
| "typedef",
|
|
1097
|
+
name: symbol.name,
|
|
1098
|
+
sourceFile: symbol.sourceFile,
|
|
1099
|
+
sourceLine: symbol.sourceLine,
|
|
1100
|
+
sourceLanguage: ESourceLanguage.C,
|
|
1101
|
+
type: symbol.type,
|
|
1102
|
+
isExported: symbol.isExported ?? true,
|
|
1103
|
+
isDeclaration: symbol.isDeclaration,
|
|
1104
|
+
parameters: symbol.parameters?.map((p) => ({
|
|
1105
|
+
name: p.name,
|
|
1106
|
+
type: p.type,
|
|
1107
|
+
isArray: p.isArray,
|
|
1108
|
+
})),
|
|
1109
|
+
arrayDimensions: symbol.arrayDimensions?.map(String),
|
|
1110
|
+
members: undefined,
|
|
1111
|
+
isUnion: false,
|
|
1112
|
+
} as import("./types/symbols/c/TCSymbol").default);
|
|
1113
|
+
} else if (symbol.sourceLanguage === ESourceLanguage.Cpp) {
|
|
1114
|
+
// Convert ISymbol to TCppSymbol (simplified conversion)
|
|
1115
|
+
CodeGenState.symbolTable.addCppSymbol({
|
|
1116
|
+
kind: symbol.kind as
|
|
1117
|
+
| "class"
|
|
1118
|
+
| "struct"
|
|
1119
|
+
| "namespace"
|
|
1120
|
+
| "enum"
|
|
1121
|
+
| "function"
|
|
1122
|
+
| "variable"
|
|
1123
|
+
| "enum_member"
|
|
1124
|
+
| "type_alias",
|
|
1125
|
+
name: symbol.name,
|
|
1126
|
+
sourceFile: symbol.sourceFile,
|
|
1127
|
+
sourceLine: symbol.sourceLine,
|
|
1128
|
+
sourceLanguage: ESourceLanguage.Cpp,
|
|
1129
|
+
type: symbol.type,
|
|
1130
|
+
isExported: symbol.isExported ?? true,
|
|
1131
|
+
isDeclaration: symbol.isDeclaration,
|
|
1132
|
+
parent: symbol.parent,
|
|
1133
|
+
parameters: symbol.parameters?.map((p) => ({
|
|
1134
|
+
name: p.name,
|
|
1135
|
+
type: p.type,
|
|
1136
|
+
isArray: p.isArray,
|
|
1137
|
+
})),
|
|
1138
|
+
arrayDimensions: symbol.arrayDimensions?.map(String),
|
|
1139
|
+
} as import("./types/symbols/cpp/TCppSymbol").default);
|
|
1140
|
+
}
|
|
1141
|
+
}
|
|
1142
|
+
}
|
|
1143
|
+
|
|
1073
1144
|
/**
|
|
1074
1145
|
* Detect C++ mode based on file type and content.
|
|
1075
1146
|
* SonarCloud S3776: Extracted from doCollectHeaderSymbols().
|
|
@@ -1130,33 +1201,36 @@ class Transpiler {
|
|
|
1130
1201
|
|
|
1131
1202
|
/**
|
|
1132
1203
|
* Issue #208: Parse a pure C header (no C++ syntax detected)
|
|
1204
|
+
* Uses CResolver for symbol collection
|
|
1205
|
+
* ADR-055 Phase 7: Direct TCSymbol storage (no adapter conversion)
|
|
1133
1206
|
*/
|
|
1134
1207
|
private parsePureCHeader(content: string, filePath: string): void {
|
|
1135
1208
|
const { tree } = HeaderParser.parseC(content);
|
|
1136
1209
|
if (tree) {
|
|
1137
|
-
const
|
|
1210
|
+
const result = CResolver.resolve(
|
|
1211
|
+
tree,
|
|
1138
1212
|
filePath,
|
|
1139
1213
|
CodeGenState.symbolTable,
|
|
1140
1214
|
);
|
|
1141
|
-
|
|
1142
|
-
|
|
1143
|
-
CodeGenState.symbolTable.addSymbols(symbols);
|
|
1144
|
-
}
|
|
1215
|
+
// ADR-055 Phase 7: Store TCSymbol directly
|
|
1216
|
+
CodeGenState.symbolTable.addCSymbols(result.symbols);
|
|
1145
1217
|
}
|
|
1146
1218
|
}
|
|
1147
1219
|
|
|
1148
1220
|
/**
|
|
1149
|
-
* Parse a C++ header
|
|
1221
|
+
* Parse a C++ header using CppResolver
|
|
1222
|
+
* ADR-055 Phase 7: Direct TCppSymbol storage (no adapter conversion)
|
|
1150
1223
|
*/
|
|
1151
1224
|
private parseCppHeader(content: string, filePath: string): void {
|
|
1152
1225
|
const { tree } = HeaderParser.parseCpp(content);
|
|
1153
1226
|
if (tree) {
|
|
1154
|
-
const
|
|
1227
|
+
const result = CppResolver.resolve(
|
|
1228
|
+
tree,
|
|
1155
1229
|
filePath,
|
|
1156
1230
|
CodeGenState.symbolTable,
|
|
1157
1231
|
);
|
|
1158
|
-
|
|
1159
|
-
CodeGenState.symbolTable.
|
|
1232
|
+
// ADR-055 Phase 7: Store TCppSymbol directly
|
|
1233
|
+
CodeGenState.symbolTable.addCppSymbols(result.symbols);
|
|
1160
1234
|
}
|
|
1161
1235
|
}
|
|
1162
1236
|
|
|
@@ -1166,10 +1240,11 @@ class Transpiler {
|
|
|
1166
1240
|
|
|
1167
1241
|
/**
|
|
1168
1242
|
* Stage 6: Generate header file for a C-Next file
|
|
1243
|
+
* ADR-055 Phase 7: Uses TSymbol directly, converts to IHeaderSymbol for generation.
|
|
1169
1244
|
*/
|
|
1170
1245
|
private generateHeader(file: IDiscoveredFile): string | null {
|
|
1171
|
-
const
|
|
1172
|
-
const exportedSymbols =
|
|
1246
|
+
const tSymbols = CodeGenState.symbolTable.getTSymbolsByFile(file.path);
|
|
1247
|
+
const exportedSymbols = tSymbols.filter((s) => s.isExported);
|
|
1173
1248
|
|
|
1174
1249
|
if (exportedSymbols.length === 0) {
|
|
1175
1250
|
return null;
|
|
@@ -1207,8 +1282,17 @@ class Transpiler {
|
|
|
1207
1282
|
? { ...typeInput, symbolTable: CodeGenState.symbolTable }
|
|
1208
1283
|
: undefined;
|
|
1209
1284
|
|
|
1210
|
-
|
|
1285
|
+
// ADR-055 Phase 7: Convert TSymbol to IHeaderSymbol with auto-const info
|
|
1286
|
+
// Issue #817: Apply auto-const info same as generateHeaderContent() does
|
|
1287
|
+
const unmodifiedParams = this.codeGenerator.getFunctionUnmodifiedParams();
|
|
1288
|
+
const headerSymbols = this.convertToHeaderSymbols(
|
|
1211
1289
|
exportedSymbols,
|
|
1290
|
+
unmodifiedParams,
|
|
1291
|
+
allKnownEnums,
|
|
1292
|
+
);
|
|
1293
|
+
|
|
1294
|
+
const headerContent = this.headerGenerator.generate(
|
|
1295
|
+
headerSymbols,
|
|
1212
1296
|
headerName,
|
|
1213
1297
|
{
|
|
1214
1298
|
exportedOnly: true,
|
|
@@ -1270,50 +1354,35 @@ class Transpiler {
|
|
|
1270
1354
|
/**
|
|
1271
1355
|
* Generate header content for exported symbols.
|
|
1272
1356
|
* Issue #591: Extracted from transpileSource() for reduced complexity.
|
|
1357
|
+
* ADR-055 Phase 7: Works with TSymbol[], converts to IHeaderSymbol for generation.
|
|
1273
1358
|
*/
|
|
1274
1359
|
private generateHeaderContent(
|
|
1275
|
-
|
|
1360
|
+
tSymbols: TSymbol[],
|
|
1276
1361
|
sourcePath: string,
|
|
1277
1362
|
cppMode: boolean,
|
|
1278
1363
|
userIncludes: string[],
|
|
1279
1364
|
passByValueParams: Map<string, Set<string>>,
|
|
1280
1365
|
symbolInfo: ICodeGenSymbols,
|
|
1281
1366
|
): string | undefined {
|
|
1282
|
-
const exportedSymbols =
|
|
1283
|
-
(s: { isExported?: boolean }) => s.isExported,
|
|
1284
|
-
);
|
|
1367
|
+
const exportedSymbols = tSymbols.filter((s) => s.isExported);
|
|
1285
1368
|
|
|
1286
1369
|
if (exportedSymbols.length === 0) {
|
|
1287
1370
|
return undefined;
|
|
1288
1371
|
}
|
|
1289
1372
|
|
|
1373
|
+
// Convert to IHeaderSymbol with auto-const info
|
|
1374
|
+
const unmodifiedParams = this.codeGenerator.getFunctionUnmodifiedParams();
|
|
1375
|
+
const headerSymbols = this.convertToHeaderSymbols(
|
|
1376
|
+
exportedSymbols,
|
|
1377
|
+
unmodifiedParams,
|
|
1378
|
+
symbolInfo.knownEnums,
|
|
1379
|
+
);
|
|
1380
|
+
|
|
1290
1381
|
const headerName = basename(sourcePath).replace(/\.cnx$|\.cnext$/, ".h");
|
|
1291
1382
|
|
|
1292
1383
|
// Get type input from CodeGenState (for struct/enum definitions)
|
|
1293
1384
|
const typeInput = CodeGenState.symbols;
|
|
1294
1385
|
|
|
1295
|
-
// Update auto-const info on symbol parameters
|
|
1296
|
-
const unmodifiedParams = this.codeGenerator.getFunctionUnmodifiedParams();
|
|
1297
|
-
for (const symbol of symbols) {
|
|
1298
|
-
if (symbol.kind !== ESymbolKind.Function || !symbol.parameters) {
|
|
1299
|
-
continue;
|
|
1300
|
-
}
|
|
1301
|
-
const unmodified = unmodifiedParams.get(symbol.name);
|
|
1302
|
-
if (!unmodified) continue;
|
|
1303
|
-
|
|
1304
|
-
for (const param of symbol.parameters) {
|
|
1305
|
-
const isPointerParam =
|
|
1306
|
-
!param.isConst &&
|
|
1307
|
-
!param.isArray &&
|
|
1308
|
-
param.type !== "f32" &&
|
|
1309
|
-
param.type !== "f64" &&
|
|
1310
|
-
param.type !== "ISR";
|
|
1311
|
-
if (isPointerParam && unmodified.has(param.name)) {
|
|
1312
|
-
param.isAutoConst = true;
|
|
1313
|
-
}
|
|
1314
|
-
}
|
|
1315
|
-
}
|
|
1316
|
-
|
|
1317
1386
|
// Issue #497: Build mapping from external types to their C header includes
|
|
1318
1387
|
const externalTypeHeaders = ExternalTypeHeaderBuilder.build(
|
|
1319
1388
|
this.state.getAllHeaderDirectives(),
|
|
@@ -1327,7 +1396,7 @@ class Transpiler {
|
|
|
1327
1396
|
|
|
1328
1397
|
// Issue #478: Pass all known enums for cross-file type handling
|
|
1329
1398
|
return this.headerGenerator.generate(
|
|
1330
|
-
|
|
1399
|
+
headerSymbols,
|
|
1331
1400
|
headerName,
|
|
1332
1401
|
{
|
|
1333
1402
|
exportedOnly: true,
|
|
@@ -1341,6 +1410,54 @@ class Transpiler {
|
|
|
1341
1410
|
);
|
|
1342
1411
|
}
|
|
1343
1412
|
|
|
1413
|
+
/**
|
|
1414
|
+
* Convert TSymbols to IHeaderSymbols with auto-const information applied.
|
|
1415
|
+
* ADR-055 Phase 7: Replaces mutation-based auto-const updating.
|
|
1416
|
+
*/
|
|
1417
|
+
private convertToHeaderSymbols(
|
|
1418
|
+
symbols: TSymbol[],
|
|
1419
|
+
unmodifiedParams: ReadonlyMap<string, ReadonlySet<string>>,
|
|
1420
|
+
knownEnums: ReadonlySet<string>,
|
|
1421
|
+
): IHeaderSymbol[] {
|
|
1422
|
+
return symbols.map((symbol) => {
|
|
1423
|
+
const headerSymbol = HeaderSymbolAdapter.fromTSymbol(symbol);
|
|
1424
|
+
|
|
1425
|
+
// Apply auto-const to function parameters
|
|
1426
|
+
if (
|
|
1427
|
+
symbol.kind === "function" &&
|
|
1428
|
+
headerSymbol.parameters &&
|
|
1429
|
+
headerSymbol.parameters.length > 0
|
|
1430
|
+
) {
|
|
1431
|
+
const unmodified = unmodifiedParams.get(headerSymbol.name);
|
|
1432
|
+
if (unmodified) {
|
|
1433
|
+
// Create a mutable copy of parameters with auto-const applied
|
|
1434
|
+
const updatedParams = headerSymbol.parameters.map((param) => {
|
|
1435
|
+
const isPointerParam =
|
|
1436
|
+
!param.isConst &&
|
|
1437
|
+
!param.isArray &&
|
|
1438
|
+
param.type !== "f32" &&
|
|
1439
|
+
param.type !== "f64" &&
|
|
1440
|
+
param.type !== "ISR" &&
|
|
1441
|
+
!knownEnums.has(param.type ?? "");
|
|
1442
|
+
const isArrayParam = param.isArray && !param.isConst;
|
|
1443
|
+
|
|
1444
|
+
if (
|
|
1445
|
+
(isPointerParam || isArrayParam) &&
|
|
1446
|
+
unmodified.has(param.name)
|
|
1447
|
+
) {
|
|
1448
|
+
return { ...param, isAutoConst: true };
|
|
1449
|
+
}
|
|
1450
|
+
return param;
|
|
1451
|
+
});
|
|
1452
|
+
|
|
1453
|
+
return { ...headerSymbol, parameters: updatedParams };
|
|
1454
|
+
}
|
|
1455
|
+
}
|
|
1456
|
+
|
|
1457
|
+
return headerSymbol;
|
|
1458
|
+
});
|
|
1459
|
+
}
|
|
1460
|
+
|
|
1344
1461
|
// ===========================================================================
|
|
1345
1462
|
// Result Builder Helpers
|
|
1346
1463
|
// ===========================================================================
|
|
@@ -11,7 +11,6 @@ import { ParseTreeWalker } from "antlr4ng";
|
|
|
11
11
|
import { CNextListener } from "../parser/grammar/CNextListener";
|
|
12
12
|
import * as Parser from "../parser/grammar/CNextParser";
|
|
13
13
|
import SymbolTable from "../symbols/SymbolTable";
|
|
14
|
-
import ESymbolKind from "../../../utils/types/ESymbolKind";
|
|
15
14
|
import IFunctionCallError from "./types/IFunctionCallError";
|
|
16
15
|
import ParserUtils from "../../../utils/ParserUtils";
|
|
17
16
|
|
|
@@ -687,7 +686,7 @@ class FunctionCallAnalyzer {
|
|
|
687
686
|
// Accept functions from any source language:
|
|
688
687
|
// - C/C++ functions from header includes
|
|
689
688
|
// - C-Next functions from .cnx file includes
|
|
690
|
-
if (sym.kind ===
|
|
689
|
+
if (sym.kind === "function") {
|
|
691
690
|
return true;
|
|
692
691
|
}
|
|
693
692
|
}
|
|
@@ -23,7 +23,6 @@ import analyzePostfixOps from "../../../utils/PostfixAnalysisUtils";
|
|
|
23
23
|
import SymbolTable from "../symbols/SymbolTable";
|
|
24
24
|
import CodeGenState from "../../state/CodeGenState";
|
|
25
25
|
import ESourceLanguage from "../../../utils/types/ESourceLanguage";
|
|
26
|
-
import ESymbolKind from "../../../utils/types/ESymbolKind";
|
|
27
26
|
|
|
28
27
|
/**
|
|
29
28
|
* Tracks the initialization state of a variable
|
|
@@ -459,7 +458,7 @@ class InitializationAnalyzer {
|
|
|
459
458
|
for (const sym of symbols) {
|
|
460
459
|
if (sym.sourceLanguage === ESourceLanguage.Cpp) {
|
|
461
460
|
// C++ classes and structs have default constructors
|
|
462
|
-
if (sym.kind ===
|
|
461
|
+
if (sym.kind === "struct" || sym.kind === "class") {
|
|
463
462
|
return true;
|
|
464
463
|
}
|
|
465
464
|
}
|
|
@@ -19,6 +19,8 @@
|
|
|
19
19
|
|
|
20
20
|
import * as Parser from "../parser/grammar/CNextParser";
|
|
21
21
|
import CodeGenState from "../../state/CodeGenState";
|
|
22
|
+
import SymbolRegistry from "../../state/SymbolRegistry";
|
|
23
|
+
import FunctionUtils from "../../../utils/FunctionUtils";
|
|
22
24
|
import TransitiveModificationPropagator from "./helpers/TransitiveModificationPropagator";
|
|
23
25
|
import StatementExpressionCollector from "./helpers/StatementExpressionCollector";
|
|
24
26
|
import ChildStatementCollector from "./helpers/ChildStatementCollector";
|
|
@@ -480,6 +482,7 @@ class PassByValueAnalyzer {
|
|
|
480
482
|
|
|
481
483
|
/**
|
|
482
484
|
* Handle simple function calls: IDENTIFIER followed by '(' ... ')'
|
|
485
|
+
* Issue #797: Resolve bare function names to scope-qualified names when inside a scope.
|
|
483
486
|
*/
|
|
484
487
|
private static handleSimpleFunctionCall(
|
|
485
488
|
funcName: string,
|
|
@@ -492,15 +495,61 @@ class PassByValueAnalyzer {
|
|
|
492
495
|
const firstOp = postfixOps[0];
|
|
493
496
|
if (!firstOp.LPAREN()) return;
|
|
494
497
|
|
|
495
|
-
const
|
|
498
|
+
const bareCalleeName = primary.IDENTIFIER()!.getText();
|
|
499
|
+
const resolvedCalleeName = PassByValueAnalyzer.resolveCalleeNameInScope(
|
|
500
|
+
funcName,
|
|
501
|
+
bareCalleeName,
|
|
502
|
+
);
|
|
496
503
|
PassByValueAnalyzer.recordCallsFromArgList(
|
|
497
504
|
funcName,
|
|
498
505
|
paramSet,
|
|
499
|
-
|
|
506
|
+
resolvedCalleeName,
|
|
500
507
|
firstOp,
|
|
501
508
|
);
|
|
502
509
|
}
|
|
503
510
|
|
|
511
|
+
/**
|
|
512
|
+
* Issue #797: Resolve a bare function name to its scope-qualified name.
|
|
513
|
+
* When inside a scope, bare calls like `fillData()` should resolve to `Scope_fillData`.
|
|
514
|
+
*
|
|
515
|
+
* Uses SymbolRegistry for proper scope-aware resolution instead of string parsing.
|
|
516
|
+
*/
|
|
517
|
+
private static resolveCalleeNameInScope(
|
|
518
|
+
callerFuncName: string,
|
|
519
|
+
bareCalleeName: string,
|
|
520
|
+
): string {
|
|
521
|
+
// Try to resolve using SymbolRegistry (new type system)
|
|
522
|
+
const callerScope =
|
|
523
|
+
SymbolRegistry.getScopeByMangledFunctionName(callerFuncName);
|
|
524
|
+
if (callerScope) {
|
|
525
|
+
// Use SymbolRegistry.resolveFunction to find the callee in scope chain
|
|
526
|
+
const callee = SymbolRegistry.resolveFunction(
|
|
527
|
+
bareCalleeName,
|
|
528
|
+
callerScope,
|
|
529
|
+
);
|
|
530
|
+
if (callee) {
|
|
531
|
+
// Use FunctionUtils to get the C-mangled name (types layer, not output layer)
|
|
532
|
+
return FunctionUtils.getCMangledName(callee);
|
|
533
|
+
}
|
|
534
|
+
}
|
|
535
|
+
|
|
536
|
+
// Fallback to legacy string-based lookup for backward compatibility
|
|
537
|
+
// (handles functions from C headers, external functions, etc.)
|
|
538
|
+
const underscoreIndex = callerFuncName.indexOf("_");
|
|
539
|
+
if (underscoreIndex === -1) {
|
|
540
|
+
return bareCalleeName;
|
|
541
|
+
}
|
|
542
|
+
|
|
543
|
+
const scopePrefix = callerFuncName.substring(0, underscoreIndex + 1);
|
|
544
|
+
const qualifiedName = scopePrefix + bareCalleeName;
|
|
545
|
+
|
|
546
|
+
if (CodeGenState.functionParamLists.has(qualifiedName)) {
|
|
547
|
+
return qualifiedName;
|
|
548
|
+
}
|
|
549
|
+
|
|
550
|
+
return bareCalleeName;
|
|
551
|
+
}
|
|
552
|
+
|
|
504
553
|
/**
|
|
505
554
|
* Handle scope-qualified calls: Scope.method(...) or global.Scope.method(...)
|
|
506
555
|
* Track member accesses to build the mangled callee name (e.g., Storage_load)
|
|
@@ -9,7 +9,9 @@ import { CNextParser } from "../../parser/grammar/CNextParser";
|
|
|
9
9
|
import FunctionCallAnalyzer from "../FunctionCallAnalyzer";
|
|
10
10
|
import SymbolTable from "../../symbols/SymbolTable";
|
|
11
11
|
import ESourceLanguage from "../../../../utils/types/ESourceLanguage";
|
|
12
|
-
import
|
|
12
|
+
import TestScopeUtils from "../../symbols/cnext/__tests__/testUtils";
|
|
13
|
+
import TTypeUtils from "../../../../utils/TTypeUtils";
|
|
14
|
+
import type IFunctionSymbol from "../../../types/symbols/IFunctionSymbol";
|
|
13
15
|
|
|
14
16
|
/**
|
|
15
17
|
* Helper to parse C-Next code and return the AST
|
|
@@ -367,9 +369,9 @@ describe("FunctionCallAnalyzer", () => {
|
|
|
367
369
|
`;
|
|
368
370
|
const tree = parse(code);
|
|
369
371
|
const symbolTable = new SymbolTable();
|
|
370
|
-
symbolTable.
|
|
372
|
+
symbolTable.addCSymbol({
|
|
371
373
|
name: "myExternalFunc",
|
|
372
|
-
kind:
|
|
374
|
+
kind: "function",
|
|
373
375
|
sourceLanguage: ESourceLanguage.C,
|
|
374
376
|
sourceFile: "external.h",
|
|
375
377
|
sourceLine: 1,
|
|
@@ -391,9 +393,9 @@ describe("FunctionCallAnalyzer", () => {
|
|
|
391
393
|
`;
|
|
392
394
|
const tree = parse(code);
|
|
393
395
|
const symbolTable = new SymbolTable();
|
|
394
|
-
symbolTable.
|
|
396
|
+
symbolTable.addCppSymbol({
|
|
395
397
|
name: "cppHelper",
|
|
396
|
-
kind:
|
|
398
|
+
kind: "function",
|
|
397
399
|
sourceLanguage: ESourceLanguage.Cpp,
|
|
398
400
|
sourceFile: "helper.hpp",
|
|
399
401
|
sourceLine: 1,
|
|
@@ -517,9 +519,9 @@ describe("FunctionCallAnalyzer", () => {
|
|
|
517
519
|
`;
|
|
518
520
|
const tree = parse(code);
|
|
519
521
|
const symbolTable = new SymbolTable();
|
|
520
|
-
symbolTable.
|
|
522
|
+
symbolTable.addCppSymbol({
|
|
521
523
|
name: "customExternalFunc",
|
|
522
|
-
kind:
|
|
524
|
+
kind: "function",
|
|
523
525
|
sourceLanguage: ESourceLanguage.Cpp,
|
|
524
526
|
sourceFile: "custom.hpp",
|
|
525
527
|
sourceLine: 1,
|
|
@@ -626,15 +628,19 @@ describe("FunctionCallAnalyzer", () => {
|
|
|
626
628
|
`;
|
|
627
629
|
const tree = parse(code);
|
|
628
630
|
const symbolTable = new SymbolTable();
|
|
629
|
-
symbolTable.
|
|
631
|
+
symbolTable.addTSymbol({
|
|
632
|
+
kind: "function",
|
|
630
633
|
name: "cnextFunc",
|
|
631
|
-
kind: ESymbolKind.Function,
|
|
632
|
-
sourceLanguage: ESourceLanguage.CNext,
|
|
633
634
|
sourceFile: "module.cnx",
|
|
634
635
|
sourceLine: 1,
|
|
636
|
+
sourceLanguage: ESourceLanguage.CNext,
|
|
635
637
|
isExported: true,
|
|
636
|
-
|
|
637
|
-
|
|
638
|
+
returnType: TTypeUtils.createPrimitive("void"),
|
|
639
|
+
parameters: [],
|
|
640
|
+
scope: TestScopeUtils.createMockGlobalScope(),
|
|
641
|
+
visibility: "public",
|
|
642
|
+
body: null,
|
|
643
|
+
} as IFunctionSymbol);
|
|
638
644
|
|
|
639
645
|
const analyzer = new FunctionCallAnalyzer();
|
|
640
646
|
const errors = analyzer.analyze(tree, symbolTable);
|
|
@@ -10,7 +10,6 @@ import { CNextParser } from "../../parser/grammar/CNextParser";
|
|
|
10
10
|
import InitializationAnalyzer from "../InitializationAnalyzer";
|
|
11
11
|
import SymbolTable from "../../symbols/SymbolTable";
|
|
12
12
|
import CodeGenState from "../../../state/CodeGenState";
|
|
13
|
-
import ESymbolKind from "../../../../utils/types/ESymbolKind";
|
|
14
13
|
import ESourceLanguage from "../../../../utils/types/ESourceLanguage";
|
|
15
14
|
|
|
16
15
|
/**
|
|
@@ -46,9 +45,9 @@ describe("InitializationAnalyzer", () => {
|
|
|
46
45
|
const tree = parse(code);
|
|
47
46
|
|
|
48
47
|
// Set up CodeGenState with C++ class
|
|
49
|
-
CodeGenState.symbolTable.
|
|
48
|
+
CodeGenState.symbolTable.addCppSymbol({
|
|
50
49
|
name: "CppMessage",
|
|
51
|
-
kind:
|
|
50
|
+
kind: "class",
|
|
52
51
|
sourceLanguage: ESourceLanguage.Cpp,
|
|
53
52
|
sourceFile: "CppMessage.hpp",
|
|
54
53
|
sourceLine: 1,
|
|
@@ -101,9 +100,9 @@ describe("InitializationAnalyzer", () => {
|
|
|
101
100
|
const tree = parse(code);
|
|
102
101
|
|
|
103
102
|
// Set up CodeGenState with C++ struct (not class)
|
|
104
|
-
CodeGenState.symbolTable.
|
|
103
|
+
CodeGenState.symbolTable.addCppSymbol({
|
|
105
104
|
name: "CppStruct",
|
|
106
|
-
kind:
|
|
105
|
+
kind: "struct",
|
|
107
106
|
sourceLanguage: ESourceLanguage.Cpp,
|
|
108
107
|
sourceFile: "types.hpp",
|
|
109
108
|
sourceLine: 1,
|
|
@@ -131,13 +130,14 @@ describe("InitializationAnalyzer", () => {
|
|
|
131
130
|
const tree = parse(code);
|
|
132
131
|
|
|
133
132
|
// Set up CodeGenState with C struct (not C++)
|
|
134
|
-
CodeGenState.symbolTable.
|
|
133
|
+
CodeGenState.symbolTable.addCSymbol({
|
|
135
134
|
name: "CStruct",
|
|
136
|
-
kind:
|
|
135
|
+
kind: "struct",
|
|
137
136
|
sourceLanguage: ESourceLanguage.C,
|
|
138
137
|
sourceFile: "types.h",
|
|
139
138
|
sourceLine: 1,
|
|
140
139
|
isExported: true,
|
|
140
|
+
isUnion: false,
|
|
141
141
|
});
|
|
142
142
|
CodeGenState.symbolTable.addStructField("CStruct", "value", "u32");
|
|
143
143
|
|
|
@@ -836,9 +836,9 @@ describe("InitializationAnalyzer", () => {
|
|
|
836
836
|
const tree = parse(code);
|
|
837
837
|
|
|
838
838
|
const symbolTable = new SymbolTable();
|
|
839
|
-
symbolTable.
|
|
839
|
+
symbolTable.addCppSymbol({
|
|
840
840
|
name: "CppEnum",
|
|
841
|
-
kind:
|
|
841
|
+
kind: "enum",
|
|
842
842
|
sourceLanguage: ESourceLanguage.Cpp,
|
|
843
843
|
sourceFile: "types.hpp",
|
|
844
844
|
sourceLine: 1,
|
|
@@ -9,7 +9,6 @@ import { CNextParser } from "../../parser/grammar/CNextParser";
|
|
|
9
9
|
import runAnalyzers from "../runAnalyzers";
|
|
10
10
|
import SymbolTable from "../../symbols/SymbolTable";
|
|
11
11
|
import CodeGenState from "../../../state/CodeGenState";
|
|
12
|
-
import ESymbolKind from "../../../../utils/types/ESymbolKind";
|
|
13
12
|
import ESourceLanguage from "../../../../utils/types/ESourceLanguage";
|
|
14
13
|
|
|
15
14
|
/**
|
|
@@ -251,13 +250,14 @@ describe("runAnalyzers", () => {
|
|
|
251
250
|
`);
|
|
252
251
|
|
|
253
252
|
const symbolTable = new SymbolTable();
|
|
254
|
-
symbolTable.
|
|
253
|
+
symbolTable.addCSymbol({
|
|
255
254
|
name: "ExternalFunc",
|
|
256
|
-
kind:
|
|
255
|
+
kind: "function",
|
|
257
256
|
sourceLanguage: ESourceLanguage.C,
|
|
258
257
|
sourceFile: "external.h",
|
|
259
258
|
sourceLine: 1,
|
|
260
259
|
isExported: true,
|
|
260
|
+
type: "void",
|
|
261
261
|
});
|
|
262
262
|
|
|
263
263
|
const errors = runAnalyzers(tree, tokenStream, { symbolTable });
|
|
@@ -272,9 +272,9 @@ describe("runAnalyzers", () => {
|
|
|
272
272
|
`);
|
|
273
273
|
|
|
274
274
|
// Set up C++ class in CodeGenState.symbolTable
|
|
275
|
-
CodeGenState.symbolTable.
|
|
275
|
+
CodeGenState.symbolTable.addCppSymbol({
|
|
276
276
|
name: "CppMessage",
|
|
277
|
-
kind:
|
|
277
|
+
kind: "class",
|
|
278
278
|
sourceLanguage: ESourceLanguage.Cpp,
|
|
279
279
|
sourceFile: "CppMessage.hpp",
|
|
280
280
|
sourceLine: 1,
|