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
|
@@ -246,7 +246,7 @@ describe("StringDeclHelper", () => {
|
|
|
246
246
|
expect(result.handled).toBe(true);
|
|
247
247
|
expect(result.code).toBe('const char greeting[6] = "Hello";');
|
|
248
248
|
expect(requireStringInclude).toHaveBeenCalled();
|
|
249
|
-
expect(CodeGenState.
|
|
249
|
+
expect(CodeGenState.getVariableTypeInfo("greeting")).toMatchObject({
|
|
250
250
|
baseType: "char",
|
|
251
251
|
isString: true,
|
|
252
252
|
stringCapacity: 5,
|
|
@@ -821,9 +821,9 @@ describe("StringDeclHelper", () => {
|
|
|
821
821
|
expect(result.handled).toBe(true);
|
|
822
822
|
expect(result.code).toContain("[2]"); // Inferred size
|
|
823
823
|
expect(result.code).toContain("[11]"); // capacity + 1
|
|
824
|
-
expect(
|
|
825
|
-
|
|
826
|
-
]);
|
|
824
|
+
expect(
|
|
825
|
+
CodeGenState.getVariableTypeInfo("labels")?.arrayDimensions,
|
|
826
|
+
).toEqual([2, 11]);
|
|
827
827
|
});
|
|
828
828
|
|
|
829
829
|
it("generates string array without initializer (zero-init)", () => {
|
|
@@ -0,0 +1,269 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Unit tests for StringOperationsHelper
|
|
3
|
+
*
|
|
4
|
+
* Tests string operation detection and extraction.
|
|
5
|
+
*/
|
|
6
|
+
|
|
7
|
+
import { describe, it, expect, beforeEach } from "vitest";
|
|
8
|
+
import StringOperationsHelper from "../StringOperationsHelper.js";
|
|
9
|
+
import CodeGenState from "../../../../state/CodeGenState.js";
|
|
10
|
+
import CNextSourceParser from "../../../../logic/parser/CNextSourceParser.js";
|
|
11
|
+
import * as Parser from "../../../../logic/parser/grammar/CNextParser.js";
|
|
12
|
+
|
|
13
|
+
/**
|
|
14
|
+
* Helper to parse an expression from source code.
|
|
15
|
+
*/
|
|
16
|
+
function parseExpression(source: string): Parser.ExpressionContext {
|
|
17
|
+
// Wrap expression in a variable declaration to get valid syntax
|
|
18
|
+
const fullSource = `u8 x <- ${source};`;
|
|
19
|
+
const result = CNextSourceParser.parse(fullSource);
|
|
20
|
+
const decl = result.tree.declaration(0);
|
|
21
|
+
const varDecl = decl?.variableDeclaration();
|
|
22
|
+
const expr = varDecl?.expression();
|
|
23
|
+
if (!expr) {
|
|
24
|
+
throw new Error(`Failed to parse expression from: ${source}`);
|
|
25
|
+
}
|
|
26
|
+
return expr;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
describe("StringOperationsHelper", () => {
|
|
30
|
+
beforeEach(() => {
|
|
31
|
+
CodeGenState.reset();
|
|
32
|
+
});
|
|
33
|
+
|
|
34
|
+
// ========================================================================
|
|
35
|
+
// getStringExprCapacity
|
|
36
|
+
// ========================================================================
|
|
37
|
+
|
|
38
|
+
describe("getStringExprCapacity", () => {
|
|
39
|
+
it("returns literal length for string literal", () => {
|
|
40
|
+
const capacity = StringOperationsHelper.getStringExprCapacity('"hello"');
|
|
41
|
+
expect(capacity).toBe(5);
|
|
42
|
+
});
|
|
43
|
+
|
|
44
|
+
it("returns literal length for empty string", () => {
|
|
45
|
+
const capacity = StringOperationsHelper.getStringExprCapacity('""');
|
|
46
|
+
expect(capacity).toBe(0);
|
|
47
|
+
});
|
|
48
|
+
|
|
49
|
+
it("returns null for non-string expression", () => {
|
|
50
|
+
const capacity = StringOperationsHelper.getStringExprCapacity("123");
|
|
51
|
+
expect(capacity).toBeNull();
|
|
52
|
+
});
|
|
53
|
+
|
|
54
|
+
it("returns capacity from type registry for string variable", () => {
|
|
55
|
+
CodeGenState.setVariableTypeInfo("myStr", {
|
|
56
|
+
baseType: "char",
|
|
57
|
+
bitWidth: 8,
|
|
58
|
+
isArray: true,
|
|
59
|
+
arrayDimensions: [33],
|
|
60
|
+
isConst: false,
|
|
61
|
+
isString: true,
|
|
62
|
+
stringCapacity: 32,
|
|
63
|
+
});
|
|
64
|
+
|
|
65
|
+
const capacity = StringOperationsHelper.getStringExprCapacity("myStr");
|
|
66
|
+
expect(capacity).toBe(32);
|
|
67
|
+
});
|
|
68
|
+
|
|
69
|
+
it("returns null for non-string variable", () => {
|
|
70
|
+
CodeGenState.setVariableTypeInfo("myInt", {
|
|
71
|
+
baseType: "u32",
|
|
72
|
+
bitWidth: 32,
|
|
73
|
+
isArray: false,
|
|
74
|
+
arrayDimensions: [],
|
|
75
|
+
isConst: false,
|
|
76
|
+
});
|
|
77
|
+
|
|
78
|
+
const capacity = StringOperationsHelper.getStringExprCapacity("myInt");
|
|
79
|
+
expect(capacity).toBeNull();
|
|
80
|
+
});
|
|
81
|
+
|
|
82
|
+
it("returns null for unknown variable", () => {
|
|
83
|
+
const capacity =
|
|
84
|
+
StringOperationsHelper.getStringExprCapacity("unknownVar");
|
|
85
|
+
expect(capacity).toBeNull();
|
|
86
|
+
});
|
|
87
|
+
|
|
88
|
+
it("returns null for complex expression", () => {
|
|
89
|
+
const capacity = StringOperationsHelper.getStringExprCapacity("a + b");
|
|
90
|
+
expect(capacity).toBeNull();
|
|
91
|
+
});
|
|
92
|
+
});
|
|
93
|
+
|
|
94
|
+
// ========================================================================
|
|
95
|
+
// getStringConcatOperands
|
|
96
|
+
// ========================================================================
|
|
97
|
+
|
|
98
|
+
describe("getStringConcatOperands", () => {
|
|
99
|
+
beforeEach(() => {
|
|
100
|
+
// Set up string variables for concatenation tests
|
|
101
|
+
CodeGenState.setVariableTypeInfo("str1", {
|
|
102
|
+
baseType: "char",
|
|
103
|
+
bitWidth: 8,
|
|
104
|
+
isArray: true,
|
|
105
|
+
arrayDimensions: [33],
|
|
106
|
+
isConst: false,
|
|
107
|
+
isString: true,
|
|
108
|
+
stringCapacity: 32,
|
|
109
|
+
});
|
|
110
|
+
CodeGenState.setVariableTypeInfo("str2", {
|
|
111
|
+
baseType: "char",
|
|
112
|
+
bitWidth: 8,
|
|
113
|
+
isArray: true,
|
|
114
|
+
arrayDimensions: [17],
|
|
115
|
+
isConst: false,
|
|
116
|
+
isString: true,
|
|
117
|
+
stringCapacity: 16,
|
|
118
|
+
});
|
|
119
|
+
});
|
|
120
|
+
|
|
121
|
+
it("returns operands for string variable concatenation", () => {
|
|
122
|
+
const expr = parseExpression("str1 + str2");
|
|
123
|
+
const result = StringOperationsHelper.getStringConcatOperands(expr);
|
|
124
|
+
|
|
125
|
+
expect(result).not.toBeNull();
|
|
126
|
+
expect(result!.left).toBe("str1");
|
|
127
|
+
expect(result!.right).toBe("str2");
|
|
128
|
+
expect(result!.leftCapacity).toBe(32);
|
|
129
|
+
expect(result!.rightCapacity).toBe(16);
|
|
130
|
+
});
|
|
131
|
+
|
|
132
|
+
it("returns operands for string literal concatenation", () => {
|
|
133
|
+
const expr = parseExpression('"hello" + "world"');
|
|
134
|
+
const result = StringOperationsHelper.getStringConcatOperands(expr);
|
|
135
|
+
|
|
136
|
+
expect(result).not.toBeNull();
|
|
137
|
+
expect(result!.left).toBe('"hello"');
|
|
138
|
+
expect(result!.right).toBe('"world"');
|
|
139
|
+
expect(result!.leftCapacity).toBe(5);
|
|
140
|
+
expect(result!.rightCapacity).toBe(5);
|
|
141
|
+
});
|
|
142
|
+
|
|
143
|
+
it("returns null for integer addition", () => {
|
|
144
|
+
const expr = parseExpression("1 + 2");
|
|
145
|
+
const result = StringOperationsHelper.getStringConcatOperands(expr);
|
|
146
|
+
expect(result).toBeNull();
|
|
147
|
+
});
|
|
148
|
+
|
|
149
|
+
it("returns null for subtraction", () => {
|
|
150
|
+
const expr = parseExpression("str1 - str2");
|
|
151
|
+
const result = StringOperationsHelper.getStringConcatOperands(expr);
|
|
152
|
+
expect(result).toBeNull();
|
|
153
|
+
});
|
|
154
|
+
|
|
155
|
+
it("returns null for mixed string/non-string", () => {
|
|
156
|
+
const expr = parseExpression("str1 + 5");
|
|
157
|
+
const result = StringOperationsHelper.getStringConcatOperands(expr);
|
|
158
|
+
expect(result).toBeNull();
|
|
159
|
+
});
|
|
160
|
+
|
|
161
|
+
it("returns null for more than 2 operands", () => {
|
|
162
|
+
// This expression has 3 operands at the additive level
|
|
163
|
+
const expr = parseExpression("str1 + str2 + str1");
|
|
164
|
+
const result = StringOperationsHelper.getStringConcatOperands(expr);
|
|
165
|
+
// With 3 operands, it should return null (simple concat only)
|
|
166
|
+
expect(result).toBeNull();
|
|
167
|
+
});
|
|
168
|
+
|
|
169
|
+
it("handles string literal containing hyphen correctly", () => {
|
|
170
|
+
// Regression test: ensure hyphen in string literal doesn't
|
|
171
|
+
// falsely trigger subtraction detection
|
|
172
|
+
const expr = parseExpression('str1 + "hello-world"');
|
|
173
|
+
const result = StringOperationsHelper.getStringConcatOperands(expr);
|
|
174
|
+
|
|
175
|
+
expect(result).not.toBeNull();
|
|
176
|
+
expect(result!.left).toBe("str1");
|
|
177
|
+
expect(result!.right).toBe('"hello-world"');
|
|
178
|
+
expect(result!.leftCapacity).toBe(32);
|
|
179
|
+
expect(result!.rightCapacity).toBe(11); // "hello-world" is 11 chars
|
|
180
|
+
});
|
|
181
|
+
});
|
|
182
|
+
|
|
183
|
+
// ========================================================================
|
|
184
|
+
// getSubstringOperands
|
|
185
|
+
// ========================================================================
|
|
186
|
+
|
|
187
|
+
describe("getSubstringOperands", () => {
|
|
188
|
+
beforeEach(() => {
|
|
189
|
+
CodeGenState.setVariableTypeInfo("myStr", {
|
|
190
|
+
baseType: "char",
|
|
191
|
+
bitWidth: 8,
|
|
192
|
+
isArray: true,
|
|
193
|
+
arrayDimensions: [65],
|
|
194
|
+
isConst: false,
|
|
195
|
+
isString: true,
|
|
196
|
+
stringCapacity: 64,
|
|
197
|
+
});
|
|
198
|
+
});
|
|
199
|
+
|
|
200
|
+
it("returns operands for substring [start, length] pattern", () => {
|
|
201
|
+
const expr = parseExpression("myStr[0, 5]");
|
|
202
|
+
const result = StringOperationsHelper.getSubstringOperands(expr, {
|
|
203
|
+
generateExpression: (ctx) => ctx.getText(),
|
|
204
|
+
});
|
|
205
|
+
|
|
206
|
+
expect(result).not.toBeNull();
|
|
207
|
+
expect(result!.source).toBe("myStr");
|
|
208
|
+
expect(result!.start).toBe("0");
|
|
209
|
+
expect(result!.length).toBe("5");
|
|
210
|
+
expect(result!.sourceCapacity).toBe(64);
|
|
211
|
+
});
|
|
212
|
+
|
|
213
|
+
it("returns operands for single-char access [index] pattern", () => {
|
|
214
|
+
const expr = parseExpression("myStr[3]");
|
|
215
|
+
const result = StringOperationsHelper.getSubstringOperands(expr, {
|
|
216
|
+
generateExpression: (ctx) => ctx.getText(),
|
|
217
|
+
});
|
|
218
|
+
|
|
219
|
+
expect(result).not.toBeNull();
|
|
220
|
+
expect(result!.source).toBe("myStr");
|
|
221
|
+
expect(result!.start).toBe("3");
|
|
222
|
+
expect(result!.length).toBe("1");
|
|
223
|
+
expect(result!.sourceCapacity).toBe(64);
|
|
224
|
+
});
|
|
225
|
+
|
|
226
|
+
it("returns null for non-string variable", () => {
|
|
227
|
+
CodeGenState.setVariableTypeInfo("myArray", {
|
|
228
|
+
baseType: "u8",
|
|
229
|
+
bitWidth: 8,
|
|
230
|
+
isArray: true,
|
|
231
|
+
arrayDimensions: [10],
|
|
232
|
+
isConst: false,
|
|
233
|
+
});
|
|
234
|
+
|
|
235
|
+
const expr = parseExpression("myArray[0, 5]");
|
|
236
|
+
const result = StringOperationsHelper.getSubstringOperands(expr, {
|
|
237
|
+
generateExpression: (ctx) => ctx.getText(),
|
|
238
|
+
});
|
|
239
|
+
expect(result).toBeNull();
|
|
240
|
+
});
|
|
241
|
+
|
|
242
|
+
it("returns null for unknown variable", () => {
|
|
243
|
+
const expr = parseExpression("unknown[0, 5]");
|
|
244
|
+
const result = StringOperationsHelper.getSubstringOperands(expr, {
|
|
245
|
+
generateExpression: (ctx) => ctx.getText(),
|
|
246
|
+
});
|
|
247
|
+
expect(result).toBeNull();
|
|
248
|
+
});
|
|
249
|
+
|
|
250
|
+
it("returns null for function call expression", () => {
|
|
251
|
+
const expr = parseExpression("getStr()[0, 5]");
|
|
252
|
+
const result = StringOperationsHelper.getSubstringOperands(expr, {
|
|
253
|
+
generateExpression: (ctx) => ctx.getText(),
|
|
254
|
+
});
|
|
255
|
+
expect(result).toBeNull();
|
|
256
|
+
});
|
|
257
|
+
|
|
258
|
+
it("uses callback to generate expression code", () => {
|
|
259
|
+
const expr = parseExpression("myStr[idx, len]");
|
|
260
|
+
const result = StringOperationsHelper.getSubstringOperands(expr, {
|
|
261
|
+
generateExpression: (ctx) => `generated_${ctx.getText()}`,
|
|
262
|
+
});
|
|
263
|
+
|
|
264
|
+
expect(result).not.toBeNull();
|
|
265
|
+
expect(result!.start).toBe("generated_idx");
|
|
266
|
+
expect(result!.length).toBe("generated_len");
|
|
267
|
+
});
|
|
268
|
+
});
|
|
269
|
+
});
|
|
@@ -1,6 +1,5 @@
|
|
|
1
1
|
import { describe, it, expect } from "vitest";
|
|
2
2
|
import SymbolLookupHelper from "../SymbolLookupHelper.js";
|
|
3
|
-
import ESymbolKind from "../../../../../utils/types/ESymbolKind.js";
|
|
4
3
|
import ESourceLanguage from "../../../../../utils/types/ESourceLanguage.js";
|
|
5
4
|
|
|
6
5
|
describe("SymbolLookupHelper", () => {
|
|
@@ -10,7 +9,7 @@ describe("SymbolLookupHelper", () => {
|
|
|
10
9
|
SymbolLookupHelper.hasSymbolWithKindAndLanguage(
|
|
11
10
|
null,
|
|
12
11
|
"test",
|
|
13
|
-
|
|
12
|
+
"function",
|
|
14
13
|
[ESourceLanguage.C],
|
|
15
14
|
),
|
|
16
15
|
).toBe(false);
|
|
@@ -21,7 +20,7 @@ describe("SymbolLookupHelper", () => {
|
|
|
21
20
|
SymbolLookupHelper.hasSymbolWithKindAndLanguage(
|
|
22
21
|
undefined,
|
|
23
22
|
"test",
|
|
24
|
-
|
|
23
|
+
"function",
|
|
25
24
|
[ESourceLanguage.C],
|
|
26
25
|
),
|
|
27
26
|
).toBe(false);
|
|
@@ -35,7 +34,7 @@ describe("SymbolLookupHelper", () => {
|
|
|
35
34
|
SymbolLookupHelper.hasSymbolWithKindAndLanguage(
|
|
36
35
|
mockTable,
|
|
37
36
|
"test",
|
|
38
|
-
|
|
37
|
+
"function",
|
|
39
38
|
[ESourceLanguage.C],
|
|
40
39
|
),
|
|
41
40
|
).toBe(false);
|
|
@@ -44,14 +43,14 @@ describe("SymbolLookupHelper", () => {
|
|
|
44
43
|
it("returns false when kind doesn't match", () => {
|
|
45
44
|
const mockTable = {
|
|
46
45
|
getOverloads: () => [
|
|
47
|
-
{ kind:
|
|
46
|
+
{ kind: "variable" as const, sourceLanguage: ESourceLanguage.C },
|
|
48
47
|
],
|
|
49
48
|
};
|
|
50
49
|
expect(
|
|
51
50
|
SymbolLookupHelper.hasSymbolWithKindAndLanguage(
|
|
52
51
|
mockTable,
|
|
53
52
|
"test",
|
|
54
|
-
|
|
53
|
+
"function",
|
|
55
54
|
[ESourceLanguage.C],
|
|
56
55
|
),
|
|
57
56
|
).toBe(false);
|
|
@@ -60,14 +59,14 @@ describe("SymbolLookupHelper", () => {
|
|
|
60
59
|
it("returns false when language doesn't match", () => {
|
|
61
60
|
const mockTable = {
|
|
62
61
|
getOverloads: () => [
|
|
63
|
-
{ kind:
|
|
62
|
+
{ kind: "function" as const, sourceLanguage: ESourceLanguage.CNext },
|
|
64
63
|
],
|
|
65
64
|
};
|
|
66
65
|
expect(
|
|
67
66
|
SymbolLookupHelper.hasSymbolWithKindAndLanguage(
|
|
68
67
|
mockTable,
|
|
69
68
|
"test",
|
|
70
|
-
|
|
69
|
+
"function",
|
|
71
70
|
[ESourceLanguage.C],
|
|
72
71
|
),
|
|
73
72
|
).toBe(false);
|
|
@@ -76,14 +75,14 @@ describe("SymbolLookupHelper", () => {
|
|
|
76
75
|
it("returns true when matching symbol found", () => {
|
|
77
76
|
const mockTable = {
|
|
78
77
|
getOverloads: () => [
|
|
79
|
-
{ kind:
|
|
78
|
+
{ kind: "function" as const, sourceLanguage: ESourceLanguage.C },
|
|
80
79
|
],
|
|
81
80
|
};
|
|
82
81
|
expect(
|
|
83
82
|
SymbolLookupHelper.hasSymbolWithKindAndLanguage(
|
|
84
83
|
mockTable,
|
|
85
84
|
"test",
|
|
86
|
-
|
|
85
|
+
"function",
|
|
87
86
|
[ESourceLanguage.C],
|
|
88
87
|
),
|
|
89
88
|
).toBe(true);
|
|
@@ -92,14 +91,14 @@ describe("SymbolLookupHelper", () => {
|
|
|
92
91
|
it("returns true when any language in list matches", () => {
|
|
93
92
|
const mockTable = {
|
|
94
93
|
getOverloads: () => [
|
|
95
|
-
{ kind:
|
|
94
|
+
{ kind: "function" as const, sourceLanguage: ESourceLanguage.Cpp },
|
|
96
95
|
],
|
|
97
96
|
};
|
|
98
97
|
expect(
|
|
99
98
|
SymbolLookupHelper.hasSymbolWithKindAndLanguage(
|
|
100
99
|
mockTable,
|
|
101
100
|
"test",
|
|
102
|
-
|
|
101
|
+
"function",
|
|
103
102
|
[ESourceLanguage.C, ESourceLanguage.Cpp],
|
|
104
103
|
),
|
|
105
104
|
).toBe(true);
|
|
@@ -114,7 +113,7 @@ describe("SymbolLookupHelper", () => {
|
|
|
114
113
|
it("returns true for C++ enum", () => {
|
|
115
114
|
const mockTable = {
|
|
116
115
|
getOverloads: () => [
|
|
117
|
-
{ kind:
|
|
116
|
+
{ kind: "enum" as const, sourceLanguage: ESourceLanguage.Cpp },
|
|
118
117
|
],
|
|
119
118
|
};
|
|
120
119
|
expect(SymbolLookupHelper.isCppEnumClass(mockTable, "MyEnum")).toBe(true);
|
|
@@ -123,7 +122,7 @@ describe("SymbolLookupHelper", () => {
|
|
|
123
122
|
it("returns false for C enum", () => {
|
|
124
123
|
const mockTable = {
|
|
125
124
|
getOverloads: () => [
|
|
126
|
-
{ kind:
|
|
125
|
+
{ kind: "enum" as const, sourceLanguage: ESourceLanguage.C },
|
|
127
126
|
],
|
|
128
127
|
};
|
|
129
128
|
expect(SymbolLookupHelper.isCppEnumClass(mockTable, "MyEnum")).toBe(
|
|
@@ -142,7 +141,7 @@ describe("SymbolLookupHelper", () => {
|
|
|
142
141
|
it("returns true for C function", () => {
|
|
143
142
|
const mockTable = {
|
|
144
143
|
getOverloads: () => [
|
|
145
|
-
{ kind:
|
|
144
|
+
{ kind: "function" as const, sourceLanguage: ESourceLanguage.C },
|
|
146
145
|
],
|
|
147
146
|
};
|
|
148
147
|
expect(SymbolLookupHelper.isExternalCFunction(mockTable, "myFunc")).toBe(
|
|
@@ -153,7 +152,7 @@ describe("SymbolLookupHelper", () => {
|
|
|
153
152
|
it("returns true for C++ function", () => {
|
|
154
153
|
const mockTable = {
|
|
155
154
|
getOverloads: () => [
|
|
156
|
-
{ kind:
|
|
155
|
+
{ kind: "function" as const, sourceLanguage: ESourceLanguage.Cpp },
|
|
157
156
|
],
|
|
158
157
|
};
|
|
159
158
|
expect(SymbolLookupHelper.isExternalCFunction(mockTable, "myFunc")).toBe(
|
|
@@ -164,7 +163,7 @@ describe("SymbolLookupHelper", () => {
|
|
|
164
163
|
it("returns false for C-Next function", () => {
|
|
165
164
|
const mockTable = {
|
|
166
165
|
getOverloads: () => [
|
|
167
|
-
{ kind:
|
|
166
|
+
{ kind: "function" as const, sourceLanguage: ESourceLanguage.CNext },
|
|
168
167
|
],
|
|
169
168
|
};
|
|
170
169
|
expect(SymbolLookupHelper.isExternalCFunction(mockTable, "myFunc")).toBe(
|
|
@@ -186,7 +185,7 @@ describe("SymbolLookupHelper", () => {
|
|
|
186
185
|
const mockTable = {
|
|
187
186
|
getOverloads: () => [
|
|
188
187
|
{
|
|
189
|
-
kind:
|
|
188
|
+
kind: "namespace" as const,
|
|
190
189
|
sourceLanguage: ESourceLanguage.CNext,
|
|
191
190
|
},
|
|
192
191
|
],
|
|
@@ -197,7 +196,7 @@ describe("SymbolLookupHelper", () => {
|
|
|
197
196
|
it("returns false when no namespace symbol", () => {
|
|
198
197
|
const mockTable = {
|
|
199
198
|
getOverloads: () => [
|
|
200
|
-
{ kind:
|
|
199
|
+
{ kind: "function" as const, sourceLanguage: ESourceLanguage.CNext },
|
|
201
200
|
],
|
|
202
201
|
};
|
|
203
202
|
expect(SymbolLookupHelper.isNamespace(mockTable, "MyNS")).toBe(false);
|
|
@@ -216,7 +215,7 @@ describe("SymbolLookupHelper", () => {
|
|
|
216
215
|
it("returns true for C++ struct", () => {
|
|
217
216
|
const mockTable = {
|
|
218
217
|
getOverloads: () => [
|
|
219
|
-
{ kind:
|
|
218
|
+
{ kind: "struct" as const, sourceLanguage: ESourceLanguage.Cpp },
|
|
220
219
|
],
|
|
221
220
|
};
|
|
222
221
|
expect(SymbolLookupHelper.isCppType(mockTable, "MyStruct")).toBe(true);
|
|
@@ -225,7 +224,7 @@ describe("SymbolLookupHelper", () => {
|
|
|
225
224
|
it("returns true for C++ class", () => {
|
|
226
225
|
const mockTable = {
|
|
227
226
|
getOverloads: () => [
|
|
228
|
-
{ kind:
|
|
227
|
+
{ kind: "class" as const, sourceLanguage: ESourceLanguage.Cpp },
|
|
229
228
|
],
|
|
230
229
|
};
|
|
231
230
|
expect(SymbolLookupHelper.isCppType(mockTable, "MyClass")).toBe(true);
|
|
@@ -234,7 +233,7 @@ describe("SymbolLookupHelper", () => {
|
|
|
234
233
|
it("returns true for C++ type alias", () => {
|
|
235
234
|
const mockTable = {
|
|
236
235
|
getOverloads: () => [
|
|
237
|
-
{ kind:
|
|
236
|
+
{ kind: "type" as const, sourceLanguage: ESourceLanguage.Cpp },
|
|
238
237
|
],
|
|
239
238
|
};
|
|
240
239
|
expect(SymbolLookupHelper.isCppType(mockTable, "MyType")).toBe(true);
|
|
@@ -243,7 +242,7 @@ describe("SymbolLookupHelper", () => {
|
|
|
243
242
|
it("returns false for C struct", () => {
|
|
244
243
|
const mockTable = {
|
|
245
244
|
getOverloads: () => [
|
|
246
|
-
{ kind:
|
|
245
|
+
{ kind: "struct" as const, sourceLanguage: ESourceLanguage.C },
|
|
247
246
|
],
|
|
248
247
|
};
|
|
249
248
|
expect(SymbolLookupHelper.isCppType(mockTable, "MyStruct")).toBe(false);
|
|
@@ -252,7 +251,7 @@ describe("SymbolLookupHelper", () => {
|
|
|
252
251
|
it("returns false for C++ function", () => {
|
|
253
252
|
const mockTable = {
|
|
254
253
|
getOverloads: () => [
|
|
255
|
-
{ kind:
|
|
254
|
+
{ kind: "function" as const, sourceLanguage: ESourceLanguage.Cpp },
|
|
256
255
|
],
|
|
257
256
|
};
|
|
258
257
|
expect(SymbolLookupHelper.isCppType(mockTable, "myFunc")).toBe(false);
|
|
@@ -261,7 +260,7 @@ describe("SymbolLookupHelper", () => {
|
|
|
261
260
|
it("returns false for C++ enum", () => {
|
|
262
261
|
const mockTable = {
|
|
263
262
|
getOverloads: () => [
|
|
264
|
-
{ kind:
|
|
263
|
+
{ kind: "enum" as const, sourceLanguage: ESourceLanguage.Cpp },
|
|
265
264
|
],
|
|
266
265
|
};
|
|
267
266
|
expect(SymbolLookupHelper.isCppType(mockTable, "MyEnum")).toBe(false);
|
|
@@ -282,7 +281,7 @@ describe("SymbolLookupHelper", () => {
|
|
|
282
281
|
it("returns true for C-Next function", () => {
|
|
283
282
|
const mockTable = {
|
|
284
283
|
getOverloads: () => [
|
|
285
|
-
{ kind:
|
|
284
|
+
{ kind: "function" as const, sourceLanguage: ESourceLanguage.CNext },
|
|
286
285
|
],
|
|
287
286
|
};
|
|
288
287
|
expect(SymbolLookupHelper.isCNextFunction(mockTable, "myFunc")).toBe(
|
|
@@ -293,7 +292,7 @@ describe("SymbolLookupHelper", () => {
|
|
|
293
292
|
it("returns false for C function", () => {
|
|
294
293
|
const mockTable = {
|
|
295
294
|
getOverloads: () => [
|
|
296
|
-
{ kind:
|
|
295
|
+
{ kind: "function" as const, sourceLanguage: ESourceLanguage.C },
|
|
297
296
|
],
|
|
298
297
|
};
|
|
299
298
|
expect(SymbolLookupHelper.isCNextFunction(mockTable, "myFunc")).toBe(
|
|
@@ -304,7 +303,7 @@ describe("SymbolLookupHelper", () => {
|
|
|
304
303
|
it("returns false for C++ function", () => {
|
|
305
304
|
const mockTable = {
|
|
306
305
|
getOverloads: () => [
|
|
307
|
-
{ kind:
|
|
306
|
+
{ kind: "function" as const, sourceLanguage: ESourceLanguage.Cpp },
|
|
308
307
|
],
|
|
309
308
|
};
|
|
310
309
|
expect(SymbolLookupHelper.isCNextFunction(mockTable, "myFunc")).toBe(
|
|
@@ -315,7 +314,7 @@ describe("SymbolLookupHelper", () => {
|
|
|
315
314
|
it("returns false for C-Next struct", () => {
|
|
316
315
|
const mockTable = {
|
|
317
316
|
getOverloads: () => [
|
|
318
|
-
{ kind:
|
|
317
|
+
{ kind: "struct" as const, sourceLanguage: ESourceLanguage.CNext },
|
|
319
318
|
],
|
|
320
319
|
};
|
|
321
320
|
expect(SymbolLookupHelper.isCNextFunction(mockTable, "MyStruct")).toBe(
|
|
@@ -339,7 +338,7 @@ describe("SymbolLookupHelper", () => {
|
|
|
339
338
|
it("returns true when in symbol table as C-Next function", () => {
|
|
340
339
|
const mockTable = {
|
|
341
340
|
getOverloads: () => [
|
|
342
|
-
{ kind:
|
|
341
|
+
{ kind: "function" as const, sourceLanguage: ESourceLanguage.CNext },
|
|
343
342
|
],
|
|
344
343
|
};
|
|
345
344
|
expect(
|
|
@@ -374,7 +373,7 @@ describe("SymbolLookupHelper", () => {
|
|
|
374
373
|
const knownFunctions = new Set(["myFunc"]);
|
|
375
374
|
const mockTable = {
|
|
376
375
|
getOverloads: () => [
|
|
377
|
-
{ kind:
|
|
376
|
+
{ kind: "function" as const, sourceLanguage: ESourceLanguage.C },
|
|
378
377
|
],
|
|
379
378
|
};
|
|
380
379
|
expect(
|
|
@@ -399,7 +398,7 @@ describe("SymbolLookupHelper", () => {
|
|
|
399
398
|
const mockTable = {
|
|
400
399
|
getOverloads: () => [
|
|
401
400
|
{
|
|
402
|
-
kind:
|
|
401
|
+
kind: "namespace" as const,
|
|
403
402
|
sourceLanguage: ESourceLanguage.CNext,
|
|
404
403
|
},
|
|
405
404
|
],
|