c-next 0.1.69 → 0.1.71
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/package.json +1 -1
- package/src/lib/__tests__/parseCHeader.mocked.test.ts +69 -54
- package/src/lib/parseCHeader.ts +56 -23
- package/src/lib/parseWithSymbols.ts +195 -53
- package/src/transpiler/Transpiler.ts +173 -60
- package/src/transpiler/logic/analysis/FunctionCallAnalyzer.ts +240 -205
- package/src/transpiler/logic/analysis/InitializationAnalyzer.ts +1 -2
- package/src/transpiler/logic/analysis/PassByValueAnalyzer.ts +742 -0
- package/src/transpiler/logic/analysis/__tests__/FunctionCallAnalyzer.test.ts +102 -15
- package/src/transpiler/logic/analysis/__tests__/InitializationAnalyzer.test.ts +9 -9
- package/src/transpiler/logic/analysis/__tests__/runAnalyzers.test.ts +5 -5
- package/src/transpiler/{output/codegen → logic/analysis}/helpers/AssignmentTargetExtractor.ts +1 -1
- package/src/transpiler/{output/codegen → logic/analysis}/helpers/ChildStatementCollector.ts +1 -1
- package/src/transpiler/{output/codegen → logic/analysis}/helpers/StatementExpressionCollector.ts +1 -1
- package/src/transpiler/{output/codegen → logic/analysis}/helpers/__tests__/AssignmentTargetExtractor.test.ts +2 -2
- package/src/transpiler/{output/codegen → logic/analysis}/helpers/__tests__/ChildStatementCollector.test.ts +2 -2
- package/src/transpiler/{output/codegen → logic/analysis}/helpers/__tests__/StatementExpressionCollector.test.ts +2 -2
- package/src/transpiler/logic/symbols/SymbolTable.ts +676 -258
- package/src/transpiler/logic/symbols/SymbolUtils.ts +2 -2
- package/src/transpiler/logic/symbols/__tests__/SymbolTable.test.ts +290 -782
- package/src/transpiler/logic/symbols/c/__tests__/CResolver.integration.test.ts +573 -0
- package/src/transpiler/logic/symbols/c/__tests__/testHelpers.ts +20 -0
- package/src/transpiler/logic/symbols/c/collectors/EnumCollector.ts +82 -0
- package/src/transpiler/logic/symbols/c/collectors/FunctionCollector.ts +106 -0
- package/src/transpiler/logic/symbols/c/collectors/StructCollector.ts +173 -0
- package/src/transpiler/logic/symbols/c/collectors/TypedefCollector.ts +35 -0
- package/src/transpiler/logic/symbols/c/collectors/VariableCollector.ts +80 -0
- package/src/transpiler/logic/symbols/c/index.ts +333 -0
- package/src/transpiler/logic/symbols/c/utils/DeclaratorUtils.ts +269 -0
- package/src/transpiler/logic/symbols/cnext/__tests__/BitmapCollector.test.ts +50 -11
- package/src/transpiler/logic/symbols/cnext/__tests__/CNextResolver.integration.test.ts +45 -34
- package/src/transpiler/logic/symbols/cnext/__tests__/EnumCollector.test.ts +30 -13
- package/src/transpiler/logic/symbols/cnext/__tests__/FunctionCollector.test.ts +279 -64
- package/src/transpiler/logic/symbols/cnext/__tests__/RegisterCollector.test.ts +60 -13
- package/src/transpiler/logic/symbols/cnext/__tests__/ScopeCollector.test.ts +40 -37
- package/src/transpiler/logic/symbols/cnext/__tests__/StructCollector.test.ts +131 -45
- package/src/transpiler/logic/symbols/cnext/__tests__/TSymbolInfoAdapter.test.ts +223 -139
- package/src/transpiler/logic/symbols/cnext/__tests__/VariableCollector.test.ts +79 -25
- package/src/transpiler/logic/symbols/cnext/__tests__/testUtils.ts +53 -0
- package/src/transpiler/logic/symbols/cnext/adapters/TSymbolInfoAdapter.ts +83 -43
- package/src/transpiler/logic/symbols/cnext/collectors/BitmapCollector.ts +14 -13
- package/src/transpiler/logic/symbols/cnext/collectors/EnumCollector.ts +11 -10
- package/src/transpiler/logic/symbols/cnext/collectors/FunctionCollector.ts +83 -34
- package/src/transpiler/logic/symbols/cnext/collectors/RegisterCollector.ts +22 -18
- package/src/transpiler/logic/symbols/cnext/collectors/ScopeCollector.ts +53 -35
- package/src/transpiler/logic/symbols/cnext/collectors/StructCollector.ts +30 -23
- package/src/transpiler/logic/symbols/cnext/collectors/VariableCollector.ts +18 -19
- package/src/transpiler/logic/symbols/cnext/index.ts +36 -14
- package/src/transpiler/logic/symbols/cnext/types/IScopeCollectorResult.ts +2 -2
- package/src/transpiler/logic/symbols/cnext/utils/SymbolNameUtils.ts +27 -0
- package/src/transpiler/logic/symbols/cpp/__tests__/CppResolver.integration.test.ts +270 -0
- package/src/transpiler/logic/symbols/cpp/__tests__/testHelpers.ts +20 -0
- package/src/transpiler/logic/symbols/cpp/collectors/ClassCollector.ts +317 -0
- package/src/transpiler/logic/symbols/cpp/collectors/EnumCollector.ts +71 -0
- package/src/transpiler/logic/symbols/cpp/collectors/FunctionCollector.ts +155 -0
- package/src/transpiler/logic/symbols/cpp/collectors/NamespaceCollector.ts +65 -0
- package/src/transpiler/logic/symbols/cpp/collectors/TypeAliasCollector.ts +46 -0
- package/src/transpiler/logic/symbols/cpp/collectors/VariableCollector.ts +54 -0
- package/src/transpiler/logic/symbols/cpp/index.ts +366 -0
- package/src/transpiler/logic/symbols/cpp/utils/DeclaratorUtils.ts +248 -0
- package/src/transpiler/logic/symbols/shared/IExtractedParameter.ts +18 -0
- package/src/transpiler/logic/symbols/shared/ParameterExtractorUtils.ts +73 -0
- package/src/transpiler/output/codegen/CodeGenerator.ts +310 -2288
- package/src/transpiler/output/codegen/TypeRegistrationUtils.ts +4 -6
- package/src/transpiler/output/codegen/TypeResolver.ts +2 -2
- package/src/transpiler/output/codegen/TypeValidator.ts +5 -5
- package/src/transpiler/output/codegen/__tests__/CodeGenerator.test.ts +7 -1
- package/src/transpiler/output/codegen/__tests__/TypeRegistrationUtils.test.ts +36 -51
- package/src/transpiler/output/codegen/__tests__/TypeResolver.test.ts +20 -17
- package/src/transpiler/output/codegen/__tests__/TypeValidator.resolution.test.ts +3 -3
- package/src/transpiler/output/codegen/__tests__/TypeValidator.test.ts +1 -1
- package/src/transpiler/output/codegen/analysis/MemberChainAnalyzer.ts +1 -1
- package/src/transpiler/output/codegen/analysis/StringLengthCounter.ts +1 -1
- package/src/transpiler/output/codegen/analysis/__tests__/MemberChainAnalyzer.test.ts +9 -9
- package/src/transpiler/output/codegen/analysis/__tests__/StringLengthCounter.test.ts +12 -12
- package/src/transpiler/output/codegen/assignment/AssignmentClassifier.ts +13 -12
- package/src/transpiler/output/codegen/assignment/__tests__/AssignmentClassifier.test.ts +23 -17
- package/src/transpiler/output/codegen/assignment/handlers/ArrayHandlers.ts +2 -2
- package/src/transpiler/output/codegen/assignment/handlers/AssignmentHandlerUtils.ts +7 -1
- package/src/transpiler/output/codegen/assignment/handlers/BitAccessHandlers.ts +3 -3
- package/src/transpiler/output/codegen/assignment/handlers/BitmapHandlers.ts +9 -5
- package/src/transpiler/output/codegen/assignment/handlers/RegisterHandlers.ts +2 -1
- package/src/transpiler/output/codegen/assignment/handlers/SpecialHandlers.ts +4 -4
- package/src/transpiler/output/codegen/assignment/handlers/StringHandlers.ts +5 -5
- package/src/transpiler/output/codegen/assignment/handlers/__tests__/ArrayHandlers.test.ts +23 -25
- package/src/transpiler/output/codegen/assignment/handlers/__tests__/BitAccessHandlers.test.ts +20 -36
- package/src/transpiler/output/codegen/assignment/handlers/__tests__/BitmapHandlers.test.ts +18 -18
- package/src/transpiler/output/codegen/assignment/handlers/__tests__/SpecialHandlers.test.ts +42 -32
- package/src/transpiler/output/codegen/assignment/handlers/__tests__/handlerTestUtils.ts +5 -4
- package/src/transpiler/output/codegen/generators/declarationGenerators/ScopeGenerator.ts +21 -8
- package/src/transpiler/output/codegen/generators/declarationGenerators/ScopedRegisterGenerator.ts +3 -2
- package/src/transpiler/output/codegen/generators/expressions/CallExprGenerator.ts +14 -6
- package/src/transpiler/output/codegen/generators/expressions/CallExprUtils.ts +9 -3
- package/src/transpiler/output/codegen/generators/expressions/PostfixExpressionGenerator.ts +19 -16
- package/src/transpiler/output/codegen/generators/expressions/__tests__/CallExprGenerator.test.ts +24 -8
- package/src/transpiler/output/codegen/generators/expressions/__tests__/CallExprUtils.test.ts +4 -8
- package/src/transpiler/output/codegen/generators/expressions/__tests__/PostfixExpressionGenerator.test.ts +15 -2
- package/src/transpiler/output/codegen/helpers/ArgumentGenerator.ts +236 -0
- package/src/transpiler/output/codegen/helpers/ArrayInitHelper.ts +2 -1
- package/src/transpiler/output/codegen/helpers/AssignmentExpectedTypeResolver.ts +2 -2
- package/src/transpiler/output/codegen/helpers/AssignmentValidator.ts +3 -3
- package/src/transpiler/output/codegen/helpers/CppConstructorHelper.ts +3 -3
- package/src/transpiler/output/codegen/helpers/EnumAssignmentValidator.ts +1 -1
- package/src/transpiler/output/codegen/helpers/FunctionContextManager.ts +435 -0
- package/src/transpiler/output/codegen/helpers/StringDeclHelper.ts +2 -2
- package/src/transpiler/output/codegen/helpers/StringOperationsHelper.ts +203 -0
- package/src/transpiler/output/codegen/helpers/SymbolLookupHelper.ts +8 -12
- package/src/transpiler/output/codegen/helpers/TypeRegistrationEngine.ts +520 -0
- package/src/transpiler/output/codegen/helpers/VariableDeclHelper.ts +735 -0
- package/src/transpiler/output/codegen/helpers/VariableDeclarationFormatter.ts +1 -1
- package/src/transpiler/output/codegen/helpers/__tests__/ArgumentGenerator.test.ts +521 -0
- package/src/transpiler/output/codegen/helpers/__tests__/ArrayInitHelper.test.ts +1 -1
- package/src/transpiler/output/codegen/helpers/__tests__/AssignmentExpectedTypeResolver.test.ts +7 -7
- package/src/transpiler/output/codegen/helpers/__tests__/AssignmentValidator.test.ts +7 -7
- package/src/transpiler/output/codegen/helpers/__tests__/CppConstructorHelper.test.ts +4 -5
- package/src/transpiler/output/codegen/helpers/__tests__/EnumAssignmentValidator.test.ts +2 -2
- package/src/transpiler/output/codegen/helpers/__tests__/FunctionContextManager.test.ts +983 -0
- package/src/transpiler/output/codegen/helpers/__tests__/StringDeclHelper.test.ts +4 -4
- package/src/transpiler/output/codegen/helpers/__tests__/StringOperationsHelper.test.ts +269 -0
- package/src/transpiler/output/codegen/helpers/__tests__/SymbolLookupHelper.test.ts +31 -32
- package/src/transpiler/output/codegen/helpers/__tests__/TypeRegistrationEngine.test.ts +186 -0
- package/src/transpiler/output/codegen/helpers/__tests__/VariableDeclHelper.test.ts +460 -0
- package/src/transpiler/output/codegen/helpers/types/IArgumentGeneratorCallbacks.ts +32 -0
- package/src/transpiler/output/codegen/resolution/EnumTypeResolver.ts +7 -3
- package/src/transpiler/output/codegen/resolution/__tests__/EnumTypeResolver.test.ts +5 -5
- package/src/transpiler/output/codegen/types/IFunctionContextCallbacks.ts +12 -0
- package/src/transpiler/output/codegen/types/IVariableFormatInput.ts +1 -1
- package/src/transpiler/output/codegen/utils/QualifiedNameGenerator.ts +114 -0
- package/src/transpiler/output/codegen/utils/__tests__/QualifiedNameGenerator.test.ts +183 -0
- package/src/transpiler/output/headers/BaseHeaderGenerator.ts +4 -4
- package/src/transpiler/output/headers/ExternalTypeHeaderBuilder.ts +7 -7
- package/src/transpiler/output/headers/HeaderGenerator.ts +9 -7
- package/src/transpiler/output/headers/HeaderGeneratorUtils.ts +19 -20
- package/src/transpiler/output/headers/__tests__/BaseHeaderGenerator.test.ts +15 -18
- package/src/transpiler/output/headers/__tests__/CHeaderGenerator.test.ts +63 -64
- package/src/transpiler/output/headers/__tests__/CppHeaderGenerator.test.ts +36 -32
- package/src/transpiler/output/headers/__tests__/ExternalTypeHeaderBuilder.test.ts +26 -26
- package/src/transpiler/output/headers/__tests__/HeaderGenerator.test.ts +87 -59
- package/src/transpiler/output/headers/__tests__/HeaderGeneratorUtils.test.ts +57 -58
- package/src/transpiler/output/headers/adapters/HeaderSymbolAdapter.ts +222 -0
- package/src/transpiler/output/headers/adapters/__tests__/HeaderSymbolAdapter.test.ts +538 -0
- package/src/transpiler/output/headers/types/IGroupedSymbols.ts +8 -8
- package/src/transpiler/output/headers/types/IHeaderSymbol.ts +62 -0
- package/src/transpiler/state/CodeGenState.ts +109 -4
- package/src/transpiler/state/SymbolRegistry.ts +181 -0
- package/src/transpiler/{types → state}/TranspilerState.ts +1 -1
- package/src/transpiler/state/__tests__/CodeGenState.test.ts +277 -1
- package/src/transpiler/state/__tests__/SymbolRegistry.test.ts +249 -0
- package/src/transpiler/{types → state}/__tests__/TranspilerState.test.ts +1 -1
- package/src/transpiler/types/ICachedFileEntry.ts +1 -1
- package/src/transpiler/types/IConflict.ts +14 -0
- package/src/transpiler/types/ISerializedSymbol.ts +11 -0
- package/src/transpiler/types/TPrimitiveKind.ts +20 -0
- package/src/transpiler/types/TType.ts +103 -0
- package/src/transpiler/types/TVisibility.ts +6 -0
- package/src/transpiler/types/symbol-kinds/TSymbolKind.ts +10 -0
- package/src/transpiler/types/symbol-kinds/TSymbolKindC.ts +12 -0
- package/src/transpiler/types/symbol-kinds/TSymbolKindCNext.ts +16 -0
- package/src/transpiler/types/symbol-kinds/TSymbolKindCpp.ts +14 -0
- package/src/transpiler/types/symbols/IBaseSymbol.ts +31 -0
- package/src/transpiler/{logic/symbols/types → types/symbols}/IBitmapFieldInfo.ts +2 -2
- package/src/transpiler/types/symbols/IBitmapSymbol.ts +21 -0
- package/src/transpiler/{logic/symbols/types → types/symbols}/IEnumSymbol.ts +5 -6
- package/src/transpiler/types/symbols/IFieldInfo.ts +26 -0
- package/src/transpiler/types/symbols/IFunctionSymbol.ts +30 -0
- package/src/transpiler/types/symbols/IParameterInfo.ts +26 -0
- package/src/transpiler/{logic/symbols/types → types/symbols}/IRegisterMemberInfo.ts +4 -4
- package/src/transpiler/types/symbols/IRegisterSymbol.ts +18 -0
- package/src/transpiler/types/symbols/IScopeSymbol.ts +32 -0
- package/src/transpiler/{logic/symbols/types → types/symbols}/IStructFieldInfo.ts +2 -1
- package/src/transpiler/types/symbols/IStructSymbol.ts +15 -0
- package/src/transpiler/types/symbols/IVariableSymbol.ts +30 -0
- package/src/transpiler/types/symbols/SymbolGuards.ts +43 -0
- package/src/transpiler/types/symbols/TAnySymbol.ts +22 -0
- package/src/transpiler/types/symbols/TSymbol.ts +32 -0
- package/src/transpiler/types/symbols/__tests__/IBaseSymbol.test.ts +56 -0
- package/src/transpiler/types/symbols/__tests__/SymbolGuards.test.ts +57 -0
- package/src/transpiler/types/symbols/c/ICBaseSymbol.ts +28 -0
- package/src/transpiler/types/symbols/c/ICEnumMemberSymbol.ts +17 -0
- package/src/transpiler/types/symbols/c/ICEnumSymbol.ts +17 -0
- package/src/transpiler/types/symbols/c/ICFieldInfo.ts +16 -0
- package/src/transpiler/types/symbols/c/ICFunctionSymbol.ts +21 -0
- package/src/transpiler/types/symbols/c/ICParameterInfo.ts +19 -0
- package/src/transpiler/types/symbols/c/ICStructSymbol.ts +21 -0
- package/src/transpiler/types/symbols/c/ICTypedefSymbol.ts +14 -0
- package/src/transpiler/types/symbols/c/ICVariableSymbol.ts +26 -0
- package/src/transpiler/types/symbols/c/TCSymbol.ts +26 -0
- package/src/transpiler/types/symbols/cpp/ICppBaseSymbol.ts +31 -0
- package/src/transpiler/types/symbols/cpp/ICppClassSymbol.ts +15 -0
- package/src/transpiler/types/symbols/cpp/ICppEnumMemberSymbol.ts +14 -0
- package/src/transpiler/types/symbols/cpp/ICppEnumSymbol.ts +14 -0
- package/src/transpiler/types/symbols/cpp/ICppFieldInfo.ts +16 -0
- package/src/transpiler/types/symbols/cpp/ICppFunctionSymbol.ts +21 -0
- package/src/transpiler/types/symbols/cpp/ICppNamespaceSymbol.ts +11 -0
- package/src/transpiler/types/symbols/cpp/ICppParameterInfo.ts +19 -0
- package/src/transpiler/types/symbols/cpp/ICppStructSymbol.ts +16 -0
- package/src/transpiler/types/symbols/cpp/ICppTypeAliasSymbol.ts +14 -0
- package/src/transpiler/types/symbols/cpp/ICppVariableSymbol.ts +23 -0
- package/src/transpiler/types/symbols/cpp/TCppSymbol.ts +30 -0
- package/src/utils/CppNamespaceUtils.ts +3 -4
- package/src/utils/FunctionUtils.ts +92 -0
- package/src/utils/ParameterUtils.ts +55 -0
- package/src/utils/PrimitiveKindUtils.ts +33 -0
- package/src/utils/ScopeUtils.ts +105 -0
- package/src/utils/TTypeUtils.ts +159 -0
- package/src/utils/TypeResolver.ts +132 -0
- package/src/utils/__tests__/CppNamespaceUtils.test.ts +92 -99
- package/src/utils/__tests__/FunctionUtils.test.ts +284 -0
- package/src/utils/__tests__/ParameterUtils.test.ts +174 -0
- package/src/utils/__tests__/PrimitiveKindUtils.test.ts +59 -0
- package/src/utils/__tests__/ScopeUtils.test.ts +53 -0
- package/src/utils/__tests__/TTypeUtils.test.ts +245 -0
- package/src/utils/__tests__/TypeResolver.test.ts +332 -0
- package/src/utils/cache/CacheManager.ts +91 -50
- package/src/utils/cache/__tests__/CacheManager.test.ts +180 -114
- package/src/transpiler/logic/symbols/AutoConstUpdater.ts +0 -93
- package/src/transpiler/logic/symbols/CSymbolCollector.ts +0 -648
- package/src/transpiler/logic/symbols/CppSymbolCollector.ts +0 -874
- package/src/transpiler/logic/symbols/SymbolCollectorContext.ts +0 -68
- package/src/transpiler/logic/symbols/__tests__/AutoConstUpdater.test.ts +0 -418
- package/src/transpiler/logic/symbols/__tests__/CSymbolCollector.test.ts +0 -685
- package/src/transpiler/logic/symbols/__tests__/CppSymbolCollector.test.ts +0 -1146
- package/src/transpiler/logic/symbols/__tests__/SymbolCollectorContext.test.ts +0 -290
- package/src/transpiler/logic/symbols/__tests__/cTestHelpers.ts +0 -43
- package/src/transpiler/logic/symbols/__tests__/cppTestHelpers.ts +0 -40
- package/src/transpiler/logic/symbols/cnext/__tests__/TSymbolAdapter.test.ts +0 -595
- package/src/transpiler/logic/symbols/cnext/adapters/TSymbolAdapter.ts +0 -345
- package/src/transpiler/logic/symbols/types/IBaseSymbol.ts +0 -27
- package/src/transpiler/logic/symbols/types/IBitmapSymbol.ts +0 -23
- package/src/transpiler/logic/symbols/types/ICollectorContext.ts +0 -19
- package/src/transpiler/logic/symbols/types/IConflict.ts +0 -20
- package/src/transpiler/logic/symbols/types/IFieldInfo.ts +0 -18
- package/src/transpiler/logic/symbols/types/IFunctionSymbol.ts +0 -25
- package/src/transpiler/logic/symbols/types/IParameterInfo.ts +0 -24
- package/src/transpiler/logic/symbols/types/IRegisterSymbol.ts +0 -20
- package/src/transpiler/logic/symbols/types/IScopeSymbol.ts +0 -19
- package/src/transpiler/logic/symbols/types/IStructSymbol.ts +0 -16
- package/src/transpiler/logic/symbols/types/IVariableSymbol.ts +0 -30
- package/src/transpiler/logic/symbols/types/TSymbol.ts +0 -36
- package/src/transpiler/logic/symbols/types/__tests__/SymbolGuards.test.ts +0 -244
- package/src/transpiler/logic/symbols/types/typeGuards.ts +0 -44
- package/src/utils/types/ESymbolKind.ts +0 -19
- package/src/utils/types/ISymbol.ts +0 -64
- /package/src/transpiler/{types → constants}/BITMAP_BACKING_TYPE.ts +0 -0
- /package/src/transpiler/{types → constants}/BITMAP_SIZE.ts +0 -0
- /package/src/transpiler/{output/codegen → logic/analysis}/helpers/TransitiveModificationPropagator.ts +0 -0
- /package/src/transpiler/{output/codegen → logic/analysis}/helpers/__tests__/TransitiveModificationPropagator.test.ts +0 -0
|
@@ -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,
|
|
@@ -486,6 +488,88 @@ describe("FunctionCallAnalyzer", () => {
|
|
|
486
488
|
});
|
|
487
489
|
});
|
|
488
490
|
|
|
491
|
+
// ========================================================================
|
|
492
|
+
// Global Prefix Hints (Issue #787)
|
|
493
|
+
// ========================================================================
|
|
494
|
+
|
|
495
|
+
describe("global prefix hints", () => {
|
|
496
|
+
it("should suggest global. for stdlib function without direct include", () => {
|
|
497
|
+
// isnan is in math.h but header not included - suggest global.isnan()
|
|
498
|
+
const code = `
|
|
499
|
+
void main() {
|
|
500
|
+
f32 x <- 1.0;
|
|
501
|
+
bool result <- isnan(x);
|
|
502
|
+
}
|
|
503
|
+
`;
|
|
504
|
+
const tree = parse(code);
|
|
505
|
+
const analyzer = new FunctionCallAnalyzer();
|
|
506
|
+
const errors = analyzer.analyze(tree);
|
|
507
|
+
|
|
508
|
+
expect(errors).toHaveLength(1);
|
|
509
|
+
expect(errors[0].code).toBe("E0422");
|
|
510
|
+
expect(errors[0].message).toContain("global.isnan()");
|
|
511
|
+
});
|
|
512
|
+
|
|
513
|
+
it("should suggest global. for external func in symbol table", () => {
|
|
514
|
+
// External func exists in symbol table but not directly accessible
|
|
515
|
+
const code = `
|
|
516
|
+
void main() {
|
|
517
|
+
customExternalFunc();
|
|
518
|
+
}
|
|
519
|
+
`;
|
|
520
|
+
const tree = parse(code);
|
|
521
|
+
const symbolTable = new SymbolTable();
|
|
522
|
+
symbolTable.addCppSymbol({
|
|
523
|
+
name: "customExternalFunc",
|
|
524
|
+
kind: "function",
|
|
525
|
+
sourceLanguage: ESourceLanguage.Cpp,
|
|
526
|
+
sourceFile: "custom.hpp",
|
|
527
|
+
sourceLine: 1,
|
|
528
|
+
isExported: true,
|
|
529
|
+
type: "void",
|
|
530
|
+
});
|
|
531
|
+
|
|
532
|
+
const analyzer = new FunctionCallAnalyzer();
|
|
533
|
+
// Pass symbolTable but func requires global. prefix
|
|
534
|
+
const errors = analyzer.analyze(tree, symbolTable);
|
|
535
|
+
|
|
536
|
+
// With symbol table, external funcs are allowed (no error)
|
|
537
|
+
// This test documents current behavior - external funcs work without global.
|
|
538
|
+
expect(errors).toHaveLength(0);
|
|
539
|
+
});
|
|
540
|
+
|
|
541
|
+
it("should not suggest global. for truly unknown functions", () => {
|
|
542
|
+
const code = `
|
|
543
|
+
void main() {
|
|
544
|
+
completelyUnknownFunc();
|
|
545
|
+
}
|
|
546
|
+
`;
|
|
547
|
+
const tree = parse(code);
|
|
548
|
+
const analyzer = new FunctionCallAnalyzer();
|
|
549
|
+
const errors = analyzer.analyze(tree);
|
|
550
|
+
|
|
551
|
+
expect(errors).toHaveLength(1);
|
|
552
|
+
expect(errors[0].code).toBe("E0422");
|
|
553
|
+
expect(errors[0].message).not.toContain("global.");
|
|
554
|
+
});
|
|
555
|
+
|
|
556
|
+
it("should mention header name when stdlib function found", () => {
|
|
557
|
+
const code = `
|
|
558
|
+
void main() {
|
|
559
|
+
f64 x <- sqrt(4.0);
|
|
560
|
+
}
|
|
561
|
+
`;
|
|
562
|
+
const tree = parse(code);
|
|
563
|
+
const analyzer = new FunctionCallAnalyzer();
|
|
564
|
+
const errors = analyzer.analyze(tree);
|
|
565
|
+
|
|
566
|
+
expect(errors).toHaveLength(1);
|
|
567
|
+
expect(errors[0].code).toBe("E0422");
|
|
568
|
+
expect(errors[0].message).toContain("math.h");
|
|
569
|
+
expect(errors[0].message).toContain("global.sqrt()");
|
|
570
|
+
});
|
|
571
|
+
});
|
|
572
|
+
|
|
489
573
|
// ========================================================================
|
|
490
574
|
// Edge Cases
|
|
491
575
|
// ========================================================================
|
|
@@ -536,7 +620,7 @@ describe("FunctionCallAnalyzer", () => {
|
|
|
536
620
|
expect(doSomethingErrors).toHaveLength(0);
|
|
537
621
|
});
|
|
538
622
|
|
|
539
|
-
it("
|
|
623
|
+
it("allows cross-file C-Next functions from SymbolTable (Issue #786)", () => {
|
|
540
624
|
const code = `
|
|
541
625
|
void main() {
|
|
542
626
|
cnextFunc();
|
|
@@ -544,23 +628,26 @@ describe("FunctionCallAnalyzer", () => {
|
|
|
544
628
|
`;
|
|
545
629
|
const tree = parse(code);
|
|
546
630
|
const symbolTable = new SymbolTable();
|
|
547
|
-
symbolTable.
|
|
631
|
+
symbolTable.addTSymbol({
|
|
632
|
+
kind: "function",
|
|
548
633
|
name: "cnextFunc",
|
|
549
|
-
kind: ESymbolKind.Function,
|
|
550
|
-
sourceLanguage: ESourceLanguage.CNext,
|
|
551
634
|
sourceFile: "module.cnx",
|
|
552
635
|
sourceLine: 1,
|
|
636
|
+
sourceLanguage: ESourceLanguage.CNext,
|
|
553
637
|
isExported: true,
|
|
554
|
-
|
|
555
|
-
|
|
638
|
+
returnType: TTypeUtils.createPrimitive("void"),
|
|
639
|
+
parameters: [],
|
|
640
|
+
scope: TestScopeUtils.createMockGlobalScope(),
|
|
641
|
+
visibility: "public",
|
|
642
|
+
body: null,
|
|
643
|
+
} as IFunctionSymbol);
|
|
556
644
|
|
|
557
645
|
const analyzer = new FunctionCallAnalyzer();
|
|
558
646
|
const errors = analyzer.analyze(tree, symbolTable);
|
|
559
647
|
|
|
560
|
-
// C-Next
|
|
561
|
-
//
|
|
562
|
-
expect(errors).toHaveLength(
|
|
563
|
-
expect(errors[0].code).toBe("E0422");
|
|
648
|
+
// Issue #786: Cross-file C-Next functions from includes are now allowed
|
|
649
|
+
// without E0422 since they're defined in an included file
|
|
650
|
+
expect(errors).toHaveLength(0);
|
|
564
651
|
});
|
|
565
652
|
});
|
|
566
653
|
});
|
|
@@ -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,
|
package/src/transpiler/{output/codegen → logic/analysis}/helpers/AssignmentTargetExtractor.ts
RENAMED
|
@@ -2,7 +2,7 @@
|
|
|
2
2
|
* Helper for extracting base identifier from assignment targets.
|
|
3
3
|
* SonarCloud S3776: Extracted from walkStatementForModifications().
|
|
4
4
|
*/
|
|
5
|
-
import * as Parser from "
|
|
5
|
+
import * as Parser from "../../parser/grammar/CNextParser";
|
|
6
6
|
|
|
7
7
|
/**
|
|
8
8
|
* Result from extracting assignment target base identifier.
|
|
@@ -7,7 +7,7 @@
|
|
|
7
7
|
* Issue #566: Extracted from CodeGenerator for improved testability.
|
|
8
8
|
*/
|
|
9
9
|
|
|
10
|
-
import * as Parser from "
|
|
10
|
+
import * as Parser from "../../parser/grammar/CNextParser.js";
|
|
11
11
|
|
|
12
12
|
/**
|
|
13
13
|
* Result of collecting child statements and blocks from a statement.
|
package/src/transpiler/{output/codegen → logic/analysis}/helpers/StatementExpressionCollector.ts
RENAMED
|
@@ -8,7 +8,7 @@
|
|
|
8
8
|
* Issue #566: Extracted from CodeGenerator for improved testability.
|
|
9
9
|
*/
|
|
10
10
|
|
|
11
|
-
import * as Parser from "
|
|
11
|
+
import * as Parser from "../../parser/grammar/CNextParser.js";
|
|
12
12
|
|
|
13
13
|
class StatementExpressionCollector {
|
|
14
14
|
/**
|
|
@@ -4,9 +4,9 @@
|
|
|
4
4
|
*/
|
|
5
5
|
|
|
6
6
|
import { describe, it, expect } from "vitest";
|
|
7
|
-
import CNextSourceParser from "
|
|
7
|
+
import CNextSourceParser from "../../../parser/CNextSourceParser.js";
|
|
8
8
|
import AssignmentTargetExtractor from "../AssignmentTargetExtractor.js";
|
|
9
|
-
import * as Parser from "
|
|
9
|
+
import * as Parser from "../../../parser/grammar/CNextParser.js";
|
|
10
10
|
|
|
11
11
|
describe("AssignmentTargetExtractor", () => {
|
|
12
12
|
/**
|
|
@@ -4,9 +4,9 @@
|
|
|
4
4
|
*/
|
|
5
5
|
|
|
6
6
|
import { describe, it, expect } from "vitest";
|
|
7
|
-
import CNextSourceParser from "
|
|
7
|
+
import CNextSourceParser from "../../../parser/CNextSourceParser.js";
|
|
8
8
|
import ChildStatementCollector from "../ChildStatementCollector.js";
|
|
9
|
-
import * as Parser from "
|
|
9
|
+
import * as Parser from "../../../parser/grammar/CNextParser.js";
|
|
10
10
|
|
|
11
11
|
describe("ChildStatementCollector", () => {
|
|
12
12
|
/**
|
|
@@ -4,9 +4,9 @@
|
|
|
4
4
|
*/
|
|
5
5
|
|
|
6
6
|
import { describe, it, expect } from "vitest";
|
|
7
|
-
import CNextSourceParser from "
|
|
7
|
+
import CNextSourceParser from "../../../parser/CNextSourceParser.js";
|
|
8
8
|
import StatementExpressionCollector from "../StatementExpressionCollector.js";
|
|
9
|
-
import * as Parser from "
|
|
9
|
+
import * as Parser from "../../../parser/grammar/CNextParser.js";
|
|
10
10
|
|
|
11
11
|
describe("StatementExpressionCollector", () => {
|
|
12
12
|
/**
|