c-next 0.1.69 → 0.1.70
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/transpiler/logic/analysis/FunctionCallAnalyzer.ts +240 -204
- package/src/transpiler/logic/analysis/PassByValueAnalyzer.ts +693 -0
- package/src/transpiler/logic/analysis/__tests__/FunctionCallAnalyzer.test.ts +86 -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/output/codegen/CodeGenerator.ts +35 -607
- 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__/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 +11 -11
- 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/BitAccessHandlers.ts +3 -3
- package/src/transpiler/output/codegen/assignment/handlers/BitmapHandlers.ts +3 -3
- 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/expressions/CallExprGenerator.ts +14 -6
- package/src/transpiler/output/codegen/generators/expressions/PostfixExpressionGenerator.ts +19 -16
- package/src/transpiler/output/codegen/generators/expressions/__tests__/CallExprGenerator.test.ts +21 -4
- package/src/transpiler/output/codegen/generators/expressions/__tests__/PostfixExpressionGenerator.test.ts +15 -2
- 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/EnumAssignmentValidator.ts +1 -1
- package/src/transpiler/output/codegen/helpers/StringDeclHelper.ts +2 -2
- 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__/EnumAssignmentValidator.test.ts +2 -2
- package/src/transpiler/output/codegen/helpers/__tests__/StringDeclHelper.test.ts +4 -4
- package/src/transpiler/output/codegen/resolution/EnumTypeResolver.ts +2 -2
- package/src/transpiler/output/codegen/resolution/__tests__/EnumTypeResolver.test.ts +5 -5
- package/src/transpiler/state/CodeGenState.ts +122 -4
- package/src/transpiler/state/__tests__/CodeGenState.test.ts +269 -1
- /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
|
@@ -486,6 +486,88 @@ describe("FunctionCallAnalyzer", () => {
|
|
|
486
486
|
});
|
|
487
487
|
});
|
|
488
488
|
|
|
489
|
+
// ========================================================================
|
|
490
|
+
// Global Prefix Hints (Issue #787)
|
|
491
|
+
// ========================================================================
|
|
492
|
+
|
|
493
|
+
describe("global prefix hints", () => {
|
|
494
|
+
it("should suggest global. for stdlib function without direct include", () => {
|
|
495
|
+
// isnan is in math.h but header not included - suggest global.isnan()
|
|
496
|
+
const code = `
|
|
497
|
+
void main() {
|
|
498
|
+
f32 x <- 1.0;
|
|
499
|
+
bool result <- isnan(x);
|
|
500
|
+
}
|
|
501
|
+
`;
|
|
502
|
+
const tree = parse(code);
|
|
503
|
+
const analyzer = new FunctionCallAnalyzer();
|
|
504
|
+
const errors = analyzer.analyze(tree);
|
|
505
|
+
|
|
506
|
+
expect(errors).toHaveLength(1);
|
|
507
|
+
expect(errors[0].code).toBe("E0422");
|
|
508
|
+
expect(errors[0].message).toContain("global.isnan()");
|
|
509
|
+
});
|
|
510
|
+
|
|
511
|
+
it("should suggest global. for external func in symbol table", () => {
|
|
512
|
+
// External func exists in symbol table but not directly accessible
|
|
513
|
+
const code = `
|
|
514
|
+
void main() {
|
|
515
|
+
customExternalFunc();
|
|
516
|
+
}
|
|
517
|
+
`;
|
|
518
|
+
const tree = parse(code);
|
|
519
|
+
const symbolTable = new SymbolTable();
|
|
520
|
+
symbolTable.addSymbol({
|
|
521
|
+
name: "customExternalFunc",
|
|
522
|
+
kind: ESymbolKind.Function,
|
|
523
|
+
sourceLanguage: ESourceLanguage.Cpp,
|
|
524
|
+
sourceFile: "custom.hpp",
|
|
525
|
+
sourceLine: 1,
|
|
526
|
+
isExported: true,
|
|
527
|
+
type: "void",
|
|
528
|
+
});
|
|
529
|
+
|
|
530
|
+
const analyzer = new FunctionCallAnalyzer();
|
|
531
|
+
// Pass symbolTable but func requires global. prefix
|
|
532
|
+
const errors = analyzer.analyze(tree, symbolTable);
|
|
533
|
+
|
|
534
|
+
// With symbol table, external funcs are allowed (no error)
|
|
535
|
+
// This test documents current behavior - external funcs work without global.
|
|
536
|
+
expect(errors).toHaveLength(0);
|
|
537
|
+
});
|
|
538
|
+
|
|
539
|
+
it("should not suggest global. for truly unknown functions", () => {
|
|
540
|
+
const code = `
|
|
541
|
+
void main() {
|
|
542
|
+
completelyUnknownFunc();
|
|
543
|
+
}
|
|
544
|
+
`;
|
|
545
|
+
const tree = parse(code);
|
|
546
|
+
const analyzer = new FunctionCallAnalyzer();
|
|
547
|
+
const errors = analyzer.analyze(tree);
|
|
548
|
+
|
|
549
|
+
expect(errors).toHaveLength(1);
|
|
550
|
+
expect(errors[0].code).toBe("E0422");
|
|
551
|
+
expect(errors[0].message).not.toContain("global.");
|
|
552
|
+
});
|
|
553
|
+
|
|
554
|
+
it("should mention header name when stdlib function found", () => {
|
|
555
|
+
const code = `
|
|
556
|
+
void main() {
|
|
557
|
+
f64 x <- sqrt(4.0);
|
|
558
|
+
}
|
|
559
|
+
`;
|
|
560
|
+
const tree = parse(code);
|
|
561
|
+
const analyzer = new FunctionCallAnalyzer();
|
|
562
|
+
const errors = analyzer.analyze(tree);
|
|
563
|
+
|
|
564
|
+
expect(errors).toHaveLength(1);
|
|
565
|
+
expect(errors[0].code).toBe("E0422");
|
|
566
|
+
expect(errors[0].message).toContain("math.h");
|
|
567
|
+
expect(errors[0].message).toContain("global.sqrt()");
|
|
568
|
+
});
|
|
569
|
+
});
|
|
570
|
+
|
|
489
571
|
// ========================================================================
|
|
490
572
|
// Edge Cases
|
|
491
573
|
// ========================================================================
|
|
@@ -536,7 +618,7 @@ describe("FunctionCallAnalyzer", () => {
|
|
|
536
618
|
expect(doSomethingErrors).toHaveLength(0);
|
|
537
619
|
});
|
|
538
620
|
|
|
539
|
-
it("
|
|
621
|
+
it("allows cross-file C-Next functions from SymbolTable (Issue #786)", () => {
|
|
540
622
|
const code = `
|
|
541
623
|
void main() {
|
|
542
624
|
cnextFunc();
|
|
@@ -557,10 +639,9 @@ describe("FunctionCallAnalyzer", () => {
|
|
|
557
639
|
const analyzer = new FunctionCallAnalyzer();
|
|
558
640
|
const errors = analyzer.analyze(tree, symbolTable);
|
|
559
641
|
|
|
560
|
-
// C-Next
|
|
561
|
-
//
|
|
562
|
-
expect(errors).toHaveLength(
|
|
563
|
-
expect(errors[0].code).toBe("E0422");
|
|
642
|
+
// Issue #786: Cross-file C-Next functions from includes are now allowed
|
|
643
|
+
// without E0422 since they're defined in an included file
|
|
644
|
+
expect(errors).toHaveLength(0);
|
|
564
645
|
});
|
|
565
646
|
});
|
|
566
647
|
});
|
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
|
/**
|