Press n or j to go to the next uncovered block, b, p or k for the previous block.
| 1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 356 357 358 359 360 361 362 363 364 365 366 367 368 369 370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387 388 389 390 391 392 393 394 395 396 397 398 399 400 401 402 403 404 405 406 407 408 409 410 411 412 413 414 415 416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472 473 474 475 476 477 478 479 480 481 482 483 484 485 486 487 488 489 490 491 492 493 494 495 496 497 498 499 500 501 502 503 504 505 506 507 508 509 510 511 512 513 514 515 516 517 518 519 520 521 522 523 524 525 526 527 528 529 530 531 532 533 534 535 536 537 538 539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554 555 556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571 572 573 574 575 576 577 578 579 580 581 582 583 584 585 586 587 588 589 590 591 592 593 594 595 596 597 598 599 600 601 602 603 604 605 606 607 608 609 610 611 612 613 614 615 616 617 618 619 620 621 622 623 624 625 626 627 628 629 630 631 632 633 634 635 636 637 638 639 640 641 642 643 644 645 646 647 648 649 650 651 652 653 654 655 656 657 658 659 660 661 662 663 664 665 666 667 668 669 670 671 672 673 674 675 676 677 678 679 680 681 682 683 684 685 686 687 688 689 690 691 692 693 694 695 696 697 698 699 700 701 702 703 704 705 706 707 708 709 710 711 712 713 714 715 716 717 718 719 720 721 722 723 724 725 726 727 728 729 730 731 | 13x 958x 958x 958x 958x 958x 958x 958x 958x 958x 958x 23x 24x 24x 23x 1x 23x 958x 23x 24x 1x 23x 982x 1632x 156x 156x 156x 239x 122x 122x 122x 122x 1632x 823x 823x 823x 945x 945x 945x 228x 259x 945x 945x 945x 945x 945x 945x 945x 1049x 1049x 1038x 1044x 331x 1044x 984x 984x 1044x 1044x 6x 1044x 104x 331x 331x 331x 331x 21x 331x 55x 1310x 1310x 1310x 1328x 984x 984x 984x 996x 1157x 1157x 1157x 1138x 1138x 1138x 1157x 1007x 131x 42x 131x 8x 2324x 1328x 1513x 1535x 22x 22x 1513x 1513x 1513x 1513x 1513x 1513x 1513x 1513x 12x 1513x 1513x 311x 311x 89x 89x 89x 89x 89x 88x 88x 81x 8x 8x 8x 1513x 354x 354x 428x 230x 198x 117x 117x 117x 81x 79x 354x 354x 354x 311x 43x 23x 23x 22x 354x 206x 206x 127x 127x 131x 131x 131x 22x 131x 1513x 428x 67x 69x 428x 114x 958x 921x 921x 921x 921x 920x 251x 251x 251x 251x 251x 251x 251x 251x 117x 921x 459x 459x 69x 69x 69x 69x | /**
* Pass-By-Value Analyzer
*
* Extracted from CodeGenerator.ts (Issue #269, #558, #566, #579)
*
* Performs three-phase analysis to determine which function parameters
* can be passed by value (as opposed to pointer):
*
* Phase 1: Collect function parameter lists and direct modifications
* Phase 2: Transitive modification propagation (via TransitiveModificationPropagator)
* Phase 3: Determine which parameters can pass by value
*
* A parameter can pass by value if:
* 1. It's a small primitive type (u8, i8, u16, i16, u32, i32, u64, i64, bool)
* 2. It's not modified (directly or transitively)
* 3. It's not an array, struct, string, or callback
* 4. It's not accessed via subscript (Issue #579)
*/
import * as Parser from "../parser/grammar/CNextParser";
import CodeGenState from "../../state/CodeGenState";
import SymbolRegistry from "../../state/SymbolRegistry";
import FunctionUtils from "../../../utils/FunctionUtils";
import TransitiveModificationPropagator from "./helpers/TransitiveModificationPropagator";
import StatementExpressionCollector from "./helpers/StatementExpressionCollector";
import ChildStatementCollector from "./helpers/ChildStatementCollector";
import AssignmentTargetExtractor from "./helpers/AssignmentTargetExtractor";
import ExpressionUtils from "../../../utils/ExpressionUtils";
/**
* Small primitive types that are eligible for pass-by-value optimization.
*/
const SMALL_PRIMITIVES = new Set([
"u8",
"i8",
"u16",
"i16",
"u32",
"i32",
"u64",
"i64",
"bool",
]);
/**
* Static analyzer for determining pass-by-value eligibility.
* All state is stored in CodeGenState - this class contains pure analysis logic.
*/
class PassByValueAnalyzer {
/**
* Main entry point: Analyze a program tree to determine pass-by-value parameters.
* Updates CodeGenState with analysis results.
*/
static analyze(tree: Parser.ProgramContext): void {
// Reset analysis state
CodeGenState.modifiedParameters.clear();
CodeGenState.passByValueParams.clear();
CodeGenState.functionCallGraph.clear();
CodeGenState.functionParamLists.clear();
// Phase 1: Collect function parameter lists and direct modifications
PassByValueAnalyzer.collectFunctionParametersAndModifications(tree);
// Issue #558: Inject cross-file data before transitive propagation
PassByValueAnalyzer.injectCrossFileModifications();
PassByValueAnalyzer.injectCrossFileParamLists();
// Phase 2: Fixed-point iteration for transitive modifications
TransitiveModificationPropagator.propagate(
CodeGenState.functionCallGraph,
CodeGenState.functionParamLists,
CodeGenState.modifiedParameters,
);
// Phase 3: Determine which parameters can pass by value
PassByValueAnalyzer.computePassByValueParams();
}
/**
* Inject cross-file modification data into modifiedParameters.
* SonarCloud S3776: Extracted from analyze().
*/
private static injectCrossFileModifications(): void {
if (!CodeGenState.pendingCrossFileModifications) return;
for (const [
funcName,
params,
] of CodeGenState.pendingCrossFileModifications) {
const existing = CodeGenState.modifiedParameters.get(funcName);
if (existing) {
for (const param of params) {
existing.add(param);
}
} else {
CodeGenState.modifiedParameters.set(funcName, new Set(params));
}
}
CodeGenState.pendingCrossFileModifications = null; // Clear after use
}
/**
* Inject cross-file parameter lists into functionParamLists.
* SonarCloud S3776: Extracted from analyze().
*/
private static injectCrossFileParamLists(): void {
if (!CodeGenState.pendingCrossFileParamLists) return;
for (const [funcName, params] of CodeGenState.pendingCrossFileParamLists) {
if (!CodeGenState.functionParamLists.has(funcName)) {
CodeGenState.functionParamLists.set(funcName, [...params]);
}
}
CodeGenState.pendingCrossFileParamLists = null; // Clear after use
}
/**
* Phase 1: Walk all functions to collect:
* - Parameter lists (for call graph resolution)
* - Direct modifications (param <- value)
* - Function calls where params are passed as arguments
*
* Exposed as public for use by CodeGenerator.analyzeModificationsOnly()
* which needs to run just this phase for cross-file analysis.
*/
static collectFunctionParametersAndModifications(
tree: Parser.ProgramContext,
): void {
for (const decl of tree.declaration()) {
// Handle scope-level functions
if (decl.scopeDeclaration()) {
const scopeDecl = decl.scopeDeclaration()!;
const scopeName = scopeDecl.IDENTIFIER().getText();
for (const member of scopeDecl.scopeMember()) {
if (member.functionDeclaration()) {
const funcDecl = member.functionDeclaration()!;
const funcName = funcDecl.IDENTIFIER().getText();
const fullName = `${scopeName}_${funcName}`;
PassByValueAnalyzer.analyzeFunctionForModifications(
fullName,
funcDecl,
);
}
}
}
// Handle top-level functions
if (decl.functionDeclaration()) {
const funcDecl = decl.functionDeclaration()!;
const name = funcDecl.IDENTIFIER().getText();
PassByValueAnalyzer.analyzeFunctionForModifications(name, funcDecl);
}
}
}
/**
* Analyze a single function for parameter modifications and call graph edges.
*/
private static analyzeFunctionForModifications(
funcName: string,
funcDecl: Parser.FunctionDeclarationContext,
): void {
// Collect parameter names
const paramNames: string[] = [];
const paramList = funcDecl.parameterList();
if (paramList) {
for (const param of paramList.parameter()) {
paramNames.push(param.IDENTIFIER().getText());
}
}
CodeGenState.functionParamLists.set(funcName, paramNames);
// Initialize modified set
CodeGenState.modifiedParameters.set(funcName, new Set());
// Issue #579: Initialize subscript access tracking
CodeGenState.subscriptAccessedParameters.set(funcName, new Set());
CodeGenState.functionCallGraph.set(funcName, []);
// Walk the function body to find modifications and calls
const block = funcDecl.block();
Eif (block) {
PassByValueAnalyzer.walkBlockForModifications(
funcName,
paramNames,
block,
);
}
}
/**
* Walk a block to find parameter modifications and function calls.
*/
private static walkBlockForModifications(
funcName: string,
paramNames: string[],
block: Parser.BlockContext,
): void {
const paramSet = new Set(paramNames);
for (const stmt of block.statement()) {
PassByValueAnalyzer.walkStatementForModifications(
funcName,
paramSet,
stmt,
);
}
}
/**
* Walk a statement recursively looking for modifications and calls.
* Issue #566: Refactored to use helper methods for expression and child collection.
*/
private static walkStatementForModifications(
funcName: string,
paramSet: Set<string>,
stmt: Parser.StatementContext,
): void {
// 1. Check for parameter modifications via assignment targets
if (stmt.assignmentStatement()) {
PassByValueAnalyzer.trackAssignmentModifications(
funcName,
paramSet,
stmt,
);
}
// 2. Walk all expressions in this statement for function calls and subscript access
for (const expr of StatementExpressionCollector.collectAll(stmt)) {
PassByValueAnalyzer.walkExpressionForCalls(funcName, paramSet, expr);
// Issue #579: Also track subscript read access on parameters
PassByValueAnalyzer.walkExpressionForSubscriptAccess(
funcName,
paramSet,
expr,
);
}
// 3. Recurse into child statements and blocks
const { statements, blocks } = ChildStatementCollector.collectAll(stmt);
for (const childStmt of statements) {
PassByValueAnalyzer.walkStatementForModifications(
funcName,
paramSet,
childStmt,
);
}
for (const block of blocks) {
PassByValueAnalyzer.walkBlockForModifications(
funcName,
[...paramSet],
block,
);
}
}
/**
* Track assignment modifications for parameter const inference.
* SonarCloud S3776: Extracted from walkStatementForModifications().
*/
private static trackAssignmentModifications(
funcName: string,
paramSet: Set<string>,
stmt: Parser.StatementContext,
): void {
const assign = stmt.assignmentStatement()!;
const target = assign.assignmentTarget();
const { baseIdentifier, hasSingleIndexSubscript } =
AssignmentTargetExtractor.extract(target);
// Issue #579: Track subscript access on parameters (for write path)
if (
hasSingleIndexSubscript &&
baseIdentifier &&
paramSet.has(baseIdentifier)
) {
CodeGenState.subscriptAccessedParameters
.get(funcName)!
.add(baseIdentifier);
}
// Track as modified parameter
if (baseIdentifier && paramSet.has(baseIdentifier)) {
CodeGenState.modifiedParameters.get(funcName)!.add(baseIdentifier);
}
}
/**
* Walk an expression tree to find function calls where parameters are passed.
* Uses recursive descent through the expression hierarchy.
*/
private static walkExpressionForCalls(
funcName: string,
paramSet: Set<string>,
expr: Parser.ExpressionContext,
): void {
// Expression -> TernaryExpression -> OrExpression -> ... -> PostfixExpression
const ternary = expr.ternaryExpression();
Eif (ternary) {
// Walk all orExpression children
for (const orExpr of ternary.orExpression()) {
PassByValueAnalyzer.walkOrExpressionForCalls(
funcName,
paramSet,
orExpr,
);
}
}
}
/**
* Issue #579: Walk an expression tree to find subscript access on parameters.
* This tracks read access like `buf[i]` where buf is a parameter.
* Parameters with subscript access must become pointers.
*/
private static walkExpressionForSubscriptAccess(
funcName: string,
paramSet: Set<string>,
expr: Parser.ExpressionContext,
): void {
const ternary = expr.ternaryExpression();
Eif (ternary) {
for (const orExpr of ternary.orExpression()) {
PassByValueAnalyzer.walkOrExpression(orExpr, (unaryExpr) => {
PassByValueAnalyzer.handleSubscriptAccess(
funcName,
paramSet,
unaryExpr,
);
});
}
}
}
/**
* Issue #579: Handle subscript access on a unary expression.
* Only tracks single-index subscript access (which could be array access).
* Two-index subscript (e.g., value[start, width]) is always bit extraction,
* so it doesn't require the parameter to become a pointer.
*/
private static handleSubscriptAccess(
funcName: string,
paramSet: Set<string>,
unaryExpr: Parser.UnaryExpressionContext,
): void {
const postfixExpr = unaryExpr.postfixExpression();
if (!postfixExpr) return;
const primary = postfixExpr.primaryExpression();
const ops = postfixExpr.postfixOp();
// Check if primary is a parameter and there's subscript access
const primaryId = primary.IDENTIFIER()?.getText();
if (!primaryId || !paramSet.has(primaryId)) {
return;
}
// Only track SINGLE-index subscript access (potential array access)
// Two-index subscript like value[0, 8] is bit extraction, not array access
const hasSingleIndexSubscript = ops.some(
(op) => op.expression().length === 1,
);
if (hasSingleIndexSubscript) {
CodeGenState.subscriptAccessedParameters.get(funcName)!.add(primaryId);
}
}
/**
* Generic walker for orExpression trees.
* Walks through the expression hierarchy and calls the handler for each unaryExpression.
* Used by both function call tracking and subscript access tracking.
*/
private static walkOrExpression(
orExpr: Parser.OrExpressionContext,
handler: (unaryExpr: Parser.UnaryExpressionContext) => void,
): void {
ExpressionUtils.collectUnaryFromOrExpr(orExpr).forEach(handler);
}
/**
* Walk an orExpression tree for function calls.
*/
private static walkOrExpressionForCalls(
funcName: string,
paramSet: Set<string>,
orExpr: Parser.OrExpressionContext,
): void {
PassByValueAnalyzer.walkOrExpression(orExpr, (unaryExpr) => {
PassByValueAnalyzer.walkUnaryExpressionForCalls(
funcName,
paramSet,
unaryExpr,
);
});
}
/**
* Walk a unaryExpression tree for function calls.
*/
private static walkUnaryExpressionForCalls(
funcName: string,
paramSet: Set<string>,
unaryExpr: Parser.UnaryExpressionContext,
): void {
// Recurse into nested unary
if (unaryExpr.unaryExpression()) {
PassByValueAnalyzer.walkUnaryExpressionForCalls(
funcName,
paramSet,
unaryExpr.unaryExpression()!,
);
return;
}
// Check postfix expression
const postfix = unaryExpr.postfixExpression();
Eif (postfix) {
PassByValueAnalyzer.walkPostfixExpressionForCalls(
funcName,
paramSet,
postfix,
);
}
}
/**
* Walk a postfixExpression for function calls.
* This is where function calls are found: primaryExpr followed by '(' args ')'
*/
private static walkPostfixExpressionForCalls(
funcName: string,
paramSet: Set<string>,
postfix: Parser.PostfixExpressionContext,
): void {
const primary = postfix.primaryExpression();
const postfixOps = postfix.postfixOp();
// Handle simple function calls: IDENTIFIER followed by '(' ... ')'
PassByValueAnalyzer.handleSimpleFunctionCall(
funcName,
paramSet,
primary,
postfixOps,
);
// Issue #365: Handle scope-qualified calls: Scope.method(...) or global.Scope.method(...)
PassByValueAnalyzer.handleScopeQualifiedCalls(
funcName,
paramSet,
primary,
postfixOps,
);
// Recurse into primary expression if it's a parenthesized expression
if (primary.expression()) {
PassByValueAnalyzer.walkExpressionForCalls(
funcName,
paramSet,
primary.expression()!,
);
}
// Walk arguments in any postfix function call ops (for nested calls)
PassByValueAnalyzer.walkPostfixOpsRecursively(
funcName,
paramSet,
postfixOps,
);
}
/**
* Handle simple function calls: IDENTIFIER followed by '(' ... ')'
* Issue #797: Resolve bare function names to scope-qualified names when inside a scope.
*/
private static handleSimpleFunctionCall(
funcName: string,
paramSet: Set<string>,
primary: Parser.PrimaryExpressionContext,
postfixOps: Parser.PostfixOpContext[],
): void {
if (!primary.IDENTIFIER() || postfixOps.length === 0) return;
const firstOp = postfixOps[0];
if (!firstOp.LPAREN()) return;
const bareCalleeName = primary.IDENTIFIER()!.getText();
const resolvedCalleeName = PassByValueAnalyzer.resolveCalleeNameInScope(
funcName,
bareCalleeName,
);
PassByValueAnalyzer.recordCallsFromArgList(
funcName,
paramSet,
resolvedCalleeName,
firstOp,
);
}
/**
* Issue #797: Resolve a bare function name to its scope-qualified name.
* When inside a scope, bare calls like `fillData()` should resolve to `Scope_fillData`.
*
* Uses SymbolRegistry for proper scope-aware resolution instead of string parsing.
*/
private static resolveCalleeNameInScope(
callerFuncName: string,
bareCalleeName: string,
): string {
// Try to resolve using SymbolRegistry (new type system)
const callerScope = SymbolRegistry.getScopeByCFunctionName(callerFuncName);
if (callerScope) {
// Use SymbolRegistry.resolveFunction to find the callee in scope chain
const callee = SymbolRegistry.resolveFunction(
bareCalleeName,
callerScope,
);
if (callee) {
// Use FunctionUtils to get the transpiled C name (types layer, not output layer)
return FunctionUtils.getTranspiledCName(callee);
}
}
// Fallback to legacy string-based lookup for backward compatibility
// (handles functions from C headers, external functions, etc.)
const underscoreIndex = callerFuncName.indexOf("_");
Eif (underscoreIndex === -1) {
return bareCalleeName;
}
const scopePrefix = callerFuncName.substring(0, underscoreIndex + 1);
const qualifiedName = scopePrefix + bareCalleeName;
if (CodeGenState.functionParamLists.has(qualifiedName)) {
return qualifiedName;
}
return bareCalleeName;
}
/**
* Handle scope-qualified calls: Scope.method(...) or global.Scope.method(...)
* Track member accesses to build the transpiled C name (e.g., Storage_load)
*/
private static handleScopeQualifiedCalls(
funcName: string,
paramSet: Set<string>,
primary: Parser.PrimaryExpressionContext,
postfixOps: Parser.PostfixOpContext[],
): void {
if (postfixOps.length === 0) return;
const memberNames = PassByValueAnalyzer.collectInitialMemberNames(
funcName,
primary,
);
for (const op of postfixOps) {
if (op.IDENTIFIER()) {
memberNames.push(op.IDENTIFIER()!.getText());
} else if (op.LPAREN() && memberNames.length >= 1) {
const calleeName = memberNames.join("_");
PassByValueAnalyzer.recordCallsFromArgList(
funcName,
paramSet,
calleeName,
op,
);
memberNames.length = 0; // Reset for potential chained calls
} else if (op.expression().length > 0) {
memberNames.length = 0; // Array subscript breaks scope chain
}
}
}
/**
* Collect initial member names from primary expression for scope resolution.
* Issue #561: When 'this' is used, resolve to the current scope name from funcName.
*/
private static collectInitialMemberNames(
funcName: string,
primary: Parser.PrimaryExpressionContext,
): string[] {
const memberNames: string[] = [];
const primaryId = primary.IDENTIFIER()?.getText();
if (primaryId && primaryId !== "global") {
memberNames.push(primaryId);
} else if (primary.THIS()) {
const scopeName = funcName.split("_")[0];
if (scopeName && scopeName !== funcName) {
memberNames.push(scopeName);
}
}
return memberNames;
}
/**
* Record function calls to the call graph from an argument list.
* Also recurses into argument expressions.
*/
private static recordCallsFromArgList(
funcName: string,
paramSet: Set<string>,
calleeName: string,
op: Parser.PostfixOpContext,
): void {
const argList = op.argumentList();
if (!argList) return;
const args = argList.expression();
for (let i = 0; i < args.length; i++) {
const arg = args[i];
const argName = ExpressionUtils.extractIdentifier(arg);
if (argName && paramSet.has(argName)) {
CodeGenState.functionCallGraph.get(funcName)!.push({
callee: calleeName,
paramIndex: i,
argParamName: argName,
});
}
PassByValueAnalyzer.walkExpressionForCalls(funcName, paramSet, arg);
}
}
/**
* Walk postfix ops recursively for nested calls and array subscripts.
*/
private static walkPostfixOpsRecursively(
funcName: string,
paramSet: Set<string>,
postfixOps: Parser.PostfixOpContext[],
): void {
for (const op of postfixOps) {
if (op.argumentList()) {
for (const argExpr of op.argumentList()!.expression()) {
PassByValueAnalyzer.walkExpressionForCalls(
funcName,
paramSet,
argExpr,
);
}
}
for (const expr of op.expression()) {
PassByValueAnalyzer.walkExpressionForCalls(funcName, paramSet, expr);
}
}
}
/**
* Phase 3: Determine which parameters can pass by value.
* A parameter passes by value if:
* 1. It's a small primitive type (u8, i8, u16, i16, u32, i32, u64, i64, bool)
* 2. It's not modified (directly or transitively)
* 3. It's not an array, struct, string, or callback
*/
private static computePassByValueParams(): void {
for (const [funcName, paramNames] of CodeGenState.functionParamLists) {
const passByValue = new Set<string>();
const modified =
CodeGenState.modifiedParameters.get(funcName) ?? new Set();
// Get function declaration to check parameter types
const funcSig = CodeGenState.functionSignatures.get(funcName);
if (funcSig) {
for (let i = 0; i < paramNames.length; i++) {
const paramName = paramNames[i];
const paramSig = funcSig.parameters[i];
Iif (!paramSig) continue;
// Check if eligible for pass-by-value:
// - Is a small primitive type
// - Not an array
// - Not modified
// - Not accessed via subscript (Issue #579)
const isSmallPrimitive = SMALL_PRIMITIVES.has(paramSig.baseType);
const isArray = paramSig.isArray ?? false;
const isModified = modified.has(paramName);
// Issue #579: Parameters with subscript access must become pointers
const hasSubscriptAccess =
CodeGenState.subscriptAccessedParameters
.get(funcName)
?.has(paramName) ?? false;
if (
isSmallPrimitive &&
!isArray &&
!isModified &&
!hasSubscriptAccess
) {
passByValue.add(paramName);
}
}
}
CodeGenState.passByValueParams.set(funcName, passByValue);
}
}
/**
* Check if a parameter should be passed by value (by name).
* Used internally during code generation.
*/
static isParameterPassByValueByName(
funcName: string,
paramName: string,
): boolean {
const passByValue = CodeGenState.passByValueParams.get(funcName);
return passByValue?.has(paramName) ?? false;
}
/**
* Issue #269: Check if a parameter should be passed by value (by index).
* Part of IOrchestrator interface - used by CallExprGenerator.
*/
static isParameterPassByValue(funcName: string, paramIndex: number): boolean {
const paramList = CodeGenState.functionParamLists.get(funcName);
Iif (!paramList || paramIndex < 0 || paramIndex >= paramList.length) {
return false;
}
const paramName = paramList[paramIndex];
return PassByValueAnalyzer.isParameterPassByValueByName(
funcName,
paramName,
);
}
}
export default PassByValueAnalyzer;
|